2018-04-04 01:23:33 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2018-01-06 03:51:12 +08:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2017 Oracle. All rights reserved.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/types.h>
|
|
|
|
#include "btrfs-tests.h"
|
|
|
|
#include "../ctree.h"
|
|
|
|
|
|
|
|
static void free_extent_map_tree(struct extent_map_tree *em_tree)
|
|
|
|
{
|
|
|
|
struct extent_map *em;
|
|
|
|
struct rb_node *node;
|
|
|
|
|
2018-08-23 03:51:52 +08:00
|
|
|
while (!RB_EMPTY_ROOT(&em_tree->map.rb_root)) {
|
|
|
|
node = rb_first_cached(&em_tree->map);
|
2018-01-06 03:51:12 +08:00
|
|
|
em = rb_entry(node, struct extent_map, rb_node);
|
|
|
|
remove_extent_mapping(em_tree, em);
|
|
|
|
|
|
|
|
#ifdef CONFIG_BTRFS_DEBUG
|
|
|
|
if (refcount_read(&em->refs) != 1) {
|
2018-05-17 06:00:42 +08:00
|
|
|
test_err(
|
|
|
|
"em leak: em (start 0x%llx len 0x%llx block_start 0x%llx block_len 0x%llx) refs %d",
|
2018-01-06 03:51:12 +08:00
|
|
|
em->start, em->len, em->block_start,
|
|
|
|
em->block_len, refcount_read(&em->refs));
|
|
|
|
|
|
|
|
refcount_set(&em->refs, 1);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
free_extent_map(em);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Test scenario:
|
|
|
|
*
|
|
|
|
* Suppose that no extent map has been loaded into memory yet, there is a file
|
|
|
|
* extent [0, 16K), followed by another file extent [16K, 20K), two dio reads
|
|
|
|
* are entering btrfs_get_extent() concurrently, t1 is reading [8K, 16K), t2 is
|
|
|
|
* reading [0, 8K)
|
|
|
|
*
|
|
|
|
* t1 t2
|
|
|
|
* btrfs_get_extent() btrfs_get_extent()
|
|
|
|
* -> lookup_extent_mapping() ->lookup_extent_mapping()
|
|
|
|
* -> add_extent_mapping(0, 16K)
|
|
|
|
* -> return em
|
|
|
|
* ->add_extent_mapping(0, 16K)
|
|
|
|
* -> #handle -EEXIST
|
|
|
|
*/
|
2019-03-16 01:06:16 +08:00
|
|
|
static int test_case_1(struct btrfs_fs_info *fs_info,
|
2018-04-04 03:55:17 +08:00
|
|
|
struct extent_map_tree *em_tree)
|
2018-01-06 03:51:12 +08:00
|
|
|
{
|
|
|
|
struct extent_map *em;
|
|
|
|
u64 start = 0;
|
|
|
|
u64 len = SZ_8K;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
em = alloc_extent_map();
|
2019-03-16 00:28:46 +08:00
|
|
|
if (!em) {
|
|
|
|
test_std_err(TEST_ALLOC_EXTENT_MAP);
|
2019-03-16 01:06:16 +08:00
|
|
|
return -ENOMEM;
|
2019-03-16 00:28:46 +08:00
|
|
|
}
|
2018-01-06 03:51:12 +08:00
|
|
|
|
|
|
|
/* Add [0, 16K) */
|
|
|
|
em->start = 0;
|
|
|
|
em->len = SZ_16K;
|
|
|
|
em->block_start = 0;
|
|
|
|
em->block_len = SZ_16K;
|
|
|
|
ret = add_extent_mapping(em_tree, em, 0);
|
2019-03-16 01:41:06 +08:00
|
|
|
if (ret < 0) {
|
|
|
|
test_err("cannot add extent range [0, 16K)");
|
|
|
|
goto out;
|
|
|
|
}
|
2018-01-06 03:51:12 +08:00
|
|
|
free_extent_map(em);
|
|
|
|
|
|
|
|
/* Add [16K, 20K) following [0, 16K) */
|
|
|
|
em = alloc_extent_map();
|
2019-03-16 01:06:16 +08:00
|
|
|
if (!em) {
|
2019-03-16 00:28:46 +08:00
|
|
|
test_std_err(TEST_ALLOC_EXTENT_MAP);
|
2019-03-16 01:06:16 +08:00
|
|
|
ret = -ENOMEM;
|
2018-01-06 03:51:12 +08:00
|
|
|
goto out;
|
2019-03-16 01:06:16 +08:00
|
|
|
}
|
2018-01-06 03:51:12 +08:00
|
|
|
|
|
|
|
em->start = SZ_16K;
|
|
|
|
em->len = SZ_4K;
|
|
|
|
em->block_start = SZ_32K; /* avoid merging */
|
|
|
|
em->block_len = SZ_4K;
|
|
|
|
ret = add_extent_mapping(em_tree, em, 0);
|
2019-03-16 01:41:06 +08:00
|
|
|
if (ret < 0) {
|
|
|
|
test_err("cannot add extent range [16K, 20K)");
|
|
|
|
goto out;
|
|
|
|
}
|
2018-01-06 03:51:12 +08:00
|
|
|
free_extent_map(em);
|
|
|
|
|
|
|
|
em = alloc_extent_map();
|
2019-03-16 01:06:16 +08:00
|
|
|
if (!em) {
|
2019-03-16 00:28:46 +08:00
|
|
|
test_std_err(TEST_ALLOC_EXTENT_MAP);
|
2019-03-16 01:06:16 +08:00
|
|
|
ret = -ENOMEM;
|
2018-01-06 03:51:12 +08:00
|
|
|
goto out;
|
2019-03-16 01:06:16 +08:00
|
|
|
}
|
2018-01-06 03:51:12 +08:00
|
|
|
|
|
|
|
/* Add [0, 8K), should return [0, 16K) instead. */
|
|
|
|
em->start = start;
|
|
|
|
em->len = len;
|
|
|
|
em->block_start = start;
|
|
|
|
em->block_len = len;
|
2018-04-04 03:45:57 +08:00
|
|
|
ret = btrfs_add_extent_mapping(fs_info, em_tree, &em, em->start, em->len);
|
2019-03-16 01:41:06 +08:00
|
|
|
if (ret) {
|
2018-05-17 06:00:42 +08:00
|
|
|
test_err("case1 [%llu %llu]: ret %d", start, start + len, ret);
|
2019-03-16 01:41:06 +08:00
|
|
|
goto out;
|
|
|
|
}
|
2018-01-06 03:51:12 +08:00
|
|
|
if (em &&
|
|
|
|
(em->start != 0 || extent_map_end(em) != SZ_16K ||
|
2019-03-16 01:41:06 +08:00
|
|
|
em->block_start != 0 || em->block_len != SZ_16K)) {
|
2018-05-17 06:00:42 +08:00
|
|
|
test_err(
|
|
|
|
"case1 [%llu %llu]: ret %d return a wrong em (start %llu len %llu block_start %llu block_len %llu",
|
2018-01-06 03:51:12 +08:00
|
|
|
start, start + len, ret, em->start, em->len,
|
|
|
|
em->block_start, em->block_len);
|
2019-03-16 01:41:06 +08:00
|
|
|
ret = -EINVAL;
|
|
|
|
}
|
2018-01-06 03:51:12 +08:00
|
|
|
free_extent_map(em);
|
|
|
|
out:
|
|
|
|
free_extent_map_tree(em_tree);
|
2019-03-16 01:06:16 +08:00
|
|
|
|
|
|
|
return ret;
|
2018-01-06 03:51:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Test scenario:
|
|
|
|
*
|
|
|
|
* Reading the inline ending up with EEXIST, ie. read an inline
|
|
|
|
* extent and discard page cache and read it again.
|
|
|
|
*/
|
2019-03-16 01:06:16 +08:00
|
|
|
static int test_case_2(struct btrfs_fs_info *fs_info,
|
2018-04-04 03:55:17 +08:00
|
|
|
struct extent_map_tree *em_tree)
|
2018-01-06 03:51:12 +08:00
|
|
|
{
|
|
|
|
struct extent_map *em;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
em = alloc_extent_map();
|
2019-03-16 00:28:46 +08:00
|
|
|
if (!em) {
|
|
|
|
test_std_err(TEST_ALLOC_EXTENT_MAP);
|
2019-03-16 01:06:16 +08:00
|
|
|
return -ENOMEM;
|
2019-03-16 00:28:46 +08:00
|
|
|
}
|
2018-01-06 03:51:12 +08:00
|
|
|
|
|
|
|
/* Add [0, 1K) */
|
|
|
|
em->start = 0;
|
|
|
|
em->len = SZ_1K;
|
|
|
|
em->block_start = EXTENT_MAP_INLINE;
|
|
|
|
em->block_len = (u64)-1;
|
|
|
|
ret = add_extent_mapping(em_tree, em, 0);
|
2019-03-16 01:41:06 +08:00
|
|
|
if (ret < 0) {
|
|
|
|
test_err("cannot add extent range [0, 1K)");
|
|
|
|
goto out;
|
|
|
|
}
|
2018-01-06 03:51:12 +08:00
|
|
|
free_extent_map(em);
|
|
|
|
|
2019-03-18 21:19:33 +08:00
|
|
|
/* Add [4K, 8K) following [0, 1K) */
|
2018-01-06 03:51:12 +08:00
|
|
|
em = alloc_extent_map();
|
2019-03-16 01:06:16 +08:00
|
|
|
if (!em) {
|
2019-03-16 00:28:46 +08:00
|
|
|
test_std_err(TEST_ALLOC_EXTENT_MAP);
|
2019-03-16 01:06:16 +08:00
|
|
|
ret = -ENOMEM;
|
2018-01-06 03:51:12 +08:00
|
|
|
goto out;
|
2019-03-16 01:06:16 +08:00
|
|
|
}
|
2018-01-06 03:51:12 +08:00
|
|
|
|
|
|
|
em->start = SZ_4K;
|
|
|
|
em->len = SZ_4K;
|
|
|
|
em->block_start = SZ_4K;
|
|
|
|
em->block_len = SZ_4K;
|
|
|
|
ret = add_extent_mapping(em_tree, em, 0);
|
2019-03-16 01:41:06 +08:00
|
|
|
if (ret < 0) {
|
|
|
|
test_err("cannot add extent range [4K, 8K)");
|
|
|
|
goto out;
|
|
|
|
}
|
2018-01-06 03:51:12 +08:00
|
|
|
free_extent_map(em);
|
|
|
|
|
|
|
|
em = alloc_extent_map();
|
2019-03-16 01:06:16 +08:00
|
|
|
if (!em) {
|
2019-03-16 00:28:46 +08:00
|
|
|
test_std_err(TEST_ALLOC_EXTENT_MAP);
|
2019-03-16 01:06:16 +08:00
|
|
|
ret = -ENOMEM;
|
2018-01-06 03:51:12 +08:00
|
|
|
goto out;
|
2019-03-16 01:06:16 +08:00
|
|
|
}
|
2018-01-06 03:51:12 +08:00
|
|
|
|
|
|
|
/* Add [0, 1K) */
|
|
|
|
em->start = 0;
|
|
|
|
em->len = SZ_1K;
|
|
|
|
em->block_start = EXTENT_MAP_INLINE;
|
|
|
|
em->block_len = (u64)-1;
|
2018-04-04 03:45:57 +08:00
|
|
|
ret = btrfs_add_extent_mapping(fs_info, em_tree, &em, em->start, em->len);
|
2019-03-16 01:41:06 +08:00
|
|
|
if (ret) {
|
2018-05-17 06:00:42 +08:00
|
|
|
test_err("case2 [0 1K]: ret %d", ret);
|
2019-03-16 01:41:06 +08:00
|
|
|
goto out;
|
|
|
|
}
|
2018-01-06 03:51:12 +08:00
|
|
|
if (em &&
|
|
|
|
(em->start != 0 || extent_map_end(em) != SZ_1K ||
|
2019-03-16 01:41:06 +08:00
|
|
|
em->block_start != EXTENT_MAP_INLINE || em->block_len != (u64)-1)) {
|
2018-05-17 06:00:42 +08:00
|
|
|
test_err(
|
|
|
|
"case2 [0 1K]: ret %d return a wrong em (start %llu len %llu block_start %llu block_len %llu",
|
2018-01-06 03:51:12 +08:00
|
|
|
ret, em->start, em->len, em->block_start,
|
|
|
|
em->block_len);
|
2019-03-16 01:41:06 +08:00
|
|
|
ret = -EINVAL;
|
|
|
|
}
|
2018-01-06 03:51:12 +08:00
|
|
|
free_extent_map(em);
|
|
|
|
out:
|
|
|
|
free_extent_map_tree(em_tree);
|
2019-03-16 01:06:16 +08:00
|
|
|
|
|
|
|
return ret;
|
2018-01-06 03:51:12 +08:00
|
|
|
}
|
|
|
|
|
2019-03-16 01:06:16 +08:00
|
|
|
static int __test_case_3(struct btrfs_fs_info *fs_info,
|
2018-04-04 03:55:17 +08:00
|
|
|
struct extent_map_tree *em_tree, u64 start)
|
2018-01-06 03:51:13 +08:00
|
|
|
{
|
|
|
|
struct extent_map *em;
|
|
|
|
u64 len = SZ_4K;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
em = alloc_extent_map();
|
2019-03-16 00:28:46 +08:00
|
|
|
if (!em) {
|
|
|
|
test_std_err(TEST_ALLOC_EXTENT_MAP);
|
2019-03-16 01:06:16 +08:00
|
|
|
return -ENOMEM;
|
2019-03-16 00:28:46 +08:00
|
|
|
}
|
2018-01-06 03:51:13 +08:00
|
|
|
|
|
|
|
/* Add [4K, 8K) */
|
|
|
|
em->start = SZ_4K;
|
|
|
|
em->len = SZ_4K;
|
|
|
|
em->block_start = SZ_4K;
|
|
|
|
em->block_len = SZ_4K;
|
|
|
|
ret = add_extent_mapping(em_tree, em, 0);
|
2019-03-16 01:41:06 +08:00
|
|
|
if (ret < 0) {
|
|
|
|
test_err("cannot add extent range [4K, 8K)");
|
|
|
|
goto out;
|
|
|
|
}
|
2018-01-06 03:51:13 +08:00
|
|
|
free_extent_map(em);
|
|
|
|
|
|
|
|
em = alloc_extent_map();
|
2019-03-16 01:06:16 +08:00
|
|
|
if (!em) {
|
2019-03-16 00:28:46 +08:00
|
|
|
test_std_err(TEST_ALLOC_EXTENT_MAP);
|
2019-03-16 01:06:16 +08:00
|
|
|
ret = -ENOMEM;
|
2018-01-06 03:51:13 +08:00
|
|
|
goto out;
|
2019-03-16 01:06:16 +08:00
|
|
|
}
|
2018-01-06 03:51:13 +08:00
|
|
|
|
|
|
|
/* Add [0, 16K) */
|
|
|
|
em->start = 0;
|
|
|
|
em->len = SZ_16K;
|
|
|
|
em->block_start = 0;
|
|
|
|
em->block_len = SZ_16K;
|
2018-04-04 03:45:57 +08:00
|
|
|
ret = btrfs_add_extent_mapping(fs_info, em_tree, &em, start, len);
|
2019-03-16 01:41:06 +08:00
|
|
|
if (ret) {
|
2018-05-17 06:00:42 +08:00
|
|
|
test_err("case3 [0x%llx 0x%llx): ret %d",
|
2018-01-06 03:51:13 +08:00
|
|
|
start, start + len, ret);
|
2019-03-16 01:41:06 +08:00
|
|
|
goto out;
|
|
|
|
}
|
2018-01-06 03:51:13 +08:00
|
|
|
/*
|
|
|
|
* Since bytes within em are contiguous, em->block_start is identical to
|
|
|
|
* em->start.
|
|
|
|
*/
|
|
|
|
if (em &&
|
|
|
|
(start < em->start || start + len > extent_map_end(em) ||
|
2019-03-16 01:41:06 +08:00
|
|
|
em->start != em->block_start || em->len != em->block_len)) {
|
2018-05-17 06:00:42 +08:00
|
|
|
test_err(
|
|
|
|
"case3 [0x%llx 0x%llx): ret %d em (start 0x%llx len 0x%llx block_start 0x%llx block_len 0x%llx)",
|
2018-01-06 03:51:13 +08:00
|
|
|
start, start + len, ret, em->start, em->len,
|
|
|
|
em->block_start, em->block_len);
|
2019-03-16 01:41:06 +08:00
|
|
|
ret = -EINVAL;
|
|
|
|
}
|
2018-01-06 03:51:13 +08:00
|
|
|
free_extent_map(em);
|
|
|
|
out:
|
|
|
|
free_extent_map_tree(em_tree);
|
2019-03-16 01:06:16 +08:00
|
|
|
|
|
|
|
return ret;
|
2018-01-06 03:51:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Test scenario:
|
|
|
|
*
|
|
|
|
* Suppose that no extent map has been loaded into memory yet.
|
|
|
|
* There is a file extent [0, 16K), two jobs are running concurrently
|
|
|
|
* against it, t1 is buffered writing to [4K, 8K) and t2 is doing dio
|
|
|
|
* read from [0, 4K) or [8K, 12K) or [12K, 16K).
|
|
|
|
*
|
|
|
|
* t1 goes ahead of t2 and adds em [4K, 8K) into tree.
|
|
|
|
*
|
|
|
|
* t1 t2
|
|
|
|
* cow_file_range() btrfs_get_extent()
|
|
|
|
* -> lookup_extent_mapping()
|
|
|
|
* -> add_extent_mapping()
|
|
|
|
* -> add_extent_mapping()
|
|
|
|
*/
|
2019-03-18 22:05:27 +08:00
|
|
|
static int test_case_3(struct btrfs_fs_info *fs_info,
|
2018-04-04 03:55:17 +08:00
|
|
|
struct extent_map_tree *em_tree)
|
2018-01-06 03:51:13 +08:00
|
|
|
{
|
2019-03-18 22:05:27 +08:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = __test_case_3(fs_info, em_tree, 0);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
ret = __test_case_3(fs_info, em_tree, SZ_8K);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
2019-03-18 21:14:35 +08:00
|
|
|
ret = __test_case_3(fs_info, em_tree, (12 * SZ_1K));
|
2019-03-18 22:05:27 +08:00
|
|
|
|
|
|
|
return ret;
|
2018-01-06 03:51:13 +08:00
|
|
|
}
|
|
|
|
|
2019-03-16 01:06:16 +08:00
|
|
|
static int __test_case_4(struct btrfs_fs_info *fs_info,
|
2018-04-04 03:55:17 +08:00
|
|
|
struct extent_map_tree *em_tree, u64 start)
|
2018-01-06 03:51:14 +08:00
|
|
|
{
|
|
|
|
struct extent_map *em;
|
|
|
|
u64 len = SZ_4K;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
em = alloc_extent_map();
|
2019-03-16 00:28:46 +08:00
|
|
|
if (!em) {
|
|
|
|
test_std_err(TEST_ALLOC_EXTENT_MAP);
|
2019-03-16 01:06:16 +08:00
|
|
|
return -ENOMEM;
|
2019-03-16 00:28:46 +08:00
|
|
|
}
|
2018-01-06 03:51:14 +08:00
|
|
|
|
|
|
|
/* Add [0K, 8K) */
|
|
|
|
em->start = 0;
|
|
|
|
em->len = SZ_8K;
|
|
|
|
em->block_start = 0;
|
|
|
|
em->block_len = SZ_8K;
|
|
|
|
ret = add_extent_mapping(em_tree, em, 0);
|
2019-03-16 01:41:06 +08:00
|
|
|
if (ret < 0) {
|
|
|
|
test_err("cannot add extent range [0, 8K)");
|
|
|
|
goto out;
|
|
|
|
}
|
2018-01-06 03:51:14 +08:00
|
|
|
free_extent_map(em);
|
|
|
|
|
|
|
|
em = alloc_extent_map();
|
2019-03-16 01:06:16 +08:00
|
|
|
if (!em) {
|
2019-03-16 00:28:46 +08:00
|
|
|
test_std_err(TEST_ALLOC_EXTENT_MAP);
|
2019-03-16 01:06:16 +08:00
|
|
|
ret = -ENOMEM;
|
2018-01-06 03:51:14 +08:00
|
|
|
goto out;
|
2019-03-16 01:06:16 +08:00
|
|
|
}
|
2018-01-06 03:51:14 +08:00
|
|
|
|
2019-03-18 21:19:33 +08:00
|
|
|
/* Add [8K, 32K) */
|
2018-01-06 03:51:14 +08:00
|
|
|
em->start = SZ_8K;
|
2019-03-18 21:14:35 +08:00
|
|
|
em->len = 24 * SZ_1K;
|
2018-01-06 03:51:14 +08:00
|
|
|
em->block_start = SZ_16K; /* avoid merging */
|
2019-03-18 21:14:35 +08:00
|
|
|
em->block_len = 24 * SZ_1K;
|
2018-01-06 03:51:14 +08:00
|
|
|
ret = add_extent_mapping(em_tree, em, 0);
|
2019-03-16 01:41:06 +08:00
|
|
|
if (ret < 0) {
|
|
|
|
test_err("cannot add extent range [8K, 32K)");
|
|
|
|
goto out;
|
|
|
|
}
|
2018-01-06 03:51:14 +08:00
|
|
|
free_extent_map(em);
|
|
|
|
|
|
|
|
em = alloc_extent_map();
|
2019-03-16 01:06:16 +08:00
|
|
|
if (!em) {
|
2019-03-16 00:28:46 +08:00
|
|
|
test_std_err(TEST_ALLOC_EXTENT_MAP);
|
2019-03-16 01:06:16 +08:00
|
|
|
ret = -ENOMEM;
|
2018-01-06 03:51:14 +08:00
|
|
|
goto out;
|
2019-03-16 01:06:16 +08:00
|
|
|
}
|
2018-01-06 03:51:14 +08:00
|
|
|
/* Add [0K, 32K) */
|
|
|
|
em->start = 0;
|
|
|
|
em->len = SZ_32K;
|
|
|
|
em->block_start = 0;
|
|
|
|
em->block_len = SZ_32K;
|
2018-04-04 03:45:57 +08:00
|
|
|
ret = btrfs_add_extent_mapping(fs_info, em_tree, &em, start, len);
|
2019-03-16 01:41:06 +08:00
|
|
|
if (ret) {
|
2018-05-17 06:00:42 +08:00
|
|
|
test_err("case4 [0x%llx 0x%llx): ret %d",
|
2018-01-06 03:51:14 +08:00
|
|
|
start, len, ret);
|
2019-03-16 01:41:06 +08:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
if (em && (start < em->start || start + len > extent_map_end(em))) {
|
2018-05-17 06:00:42 +08:00
|
|
|
test_err(
|
|
|
|
"case4 [0x%llx 0x%llx): ret %d, added wrong em (start 0x%llx len 0x%llx block_start 0x%llx block_len 0x%llx)",
|
2018-01-06 03:51:14 +08:00
|
|
|
start, len, ret, em->start, em->len, em->block_start,
|
|
|
|
em->block_len);
|
2019-03-16 01:41:06 +08:00
|
|
|
ret = -EINVAL;
|
|
|
|
}
|
2018-01-06 03:51:14 +08:00
|
|
|
free_extent_map(em);
|
|
|
|
out:
|
|
|
|
free_extent_map_tree(em_tree);
|
2019-03-16 01:06:16 +08:00
|
|
|
|
|
|
|
return ret;
|
2018-01-06 03:51:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Test scenario:
|
|
|
|
*
|
|
|
|
* Suppose that no extent map has been loaded into memory yet.
|
|
|
|
* There is a file extent [0, 32K), two jobs are running concurrently
|
|
|
|
* against it, t1 is doing dio write to [8K, 32K) and t2 is doing dio
|
|
|
|
* read from [0, 4K) or [4K, 8K).
|
|
|
|
*
|
|
|
|
* t1 goes ahead of t2 and splits em [0, 32K) to em [0K, 8K) and [8K 32K).
|
|
|
|
*
|
|
|
|
* t1 t2
|
|
|
|
* btrfs_get_blocks_direct() btrfs_get_blocks_direct()
|
|
|
|
* -> btrfs_get_extent() -> btrfs_get_extent()
|
|
|
|
* -> lookup_extent_mapping()
|
|
|
|
* -> add_extent_mapping() -> lookup_extent_mapping()
|
|
|
|
* # load [0, 32K)
|
|
|
|
* -> btrfs_new_extent_direct()
|
|
|
|
* -> btrfs_drop_extent_cache()
|
|
|
|
* # split [0, 32K)
|
|
|
|
* -> add_extent_mapping()
|
|
|
|
* # add [8K, 32K)
|
|
|
|
* -> add_extent_mapping()
|
|
|
|
* # handle -EEXIST when adding
|
|
|
|
* # [0, 32K)
|
|
|
|
*/
|
2019-03-18 22:05:27 +08:00
|
|
|
static int test_case_4(struct btrfs_fs_info *fs_info,
|
2018-04-04 03:55:17 +08:00
|
|
|
struct extent_map_tree *em_tree)
|
2018-01-06 03:51:14 +08:00
|
|
|
{
|
2019-03-18 22:05:27 +08:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = __test_case_4(fs_info, em_tree, 0);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
ret = __test_case_4(fs_info, em_tree, SZ_4K);
|
|
|
|
|
|
|
|
return ret;
|
2018-01-06 03:51:14 +08:00
|
|
|
}
|
|
|
|
|
2018-01-09 07:06:32 +08:00
|
|
|
int btrfs_test_extent_map(void)
|
2018-01-06 03:51:12 +08:00
|
|
|
{
|
2018-04-04 03:55:17 +08:00
|
|
|
struct btrfs_fs_info *fs_info = NULL;
|
2018-01-06 03:51:12 +08:00
|
|
|
struct extent_map_tree *em_tree;
|
2019-03-16 01:06:16 +08:00
|
|
|
int ret = 0;
|
2018-01-06 03:51:12 +08:00
|
|
|
|
2018-05-17 06:00:44 +08:00
|
|
|
test_msg("running extent_map tests");
|
2018-01-06 03:51:12 +08:00
|
|
|
|
2018-04-04 03:55:17 +08:00
|
|
|
/*
|
|
|
|
* Note: the fs_info is not set up completely, we only need
|
|
|
|
* fs_info::fsid for the tracepoint.
|
|
|
|
*/
|
|
|
|
fs_info = btrfs_alloc_dummy_fs_info(PAGE_SIZE, PAGE_SIZE);
|
|
|
|
if (!fs_info) {
|
2019-03-16 00:28:46 +08:00
|
|
|
test_std_err(TEST_ALLOC_FS_INFO);
|
2018-04-04 03:55:17 +08:00
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
2018-01-06 03:51:12 +08:00
|
|
|
em_tree = kzalloc(sizeof(*em_tree), GFP_KERNEL);
|
2019-03-16 01:06:16 +08:00
|
|
|
if (!em_tree) {
|
|
|
|
ret = -ENOMEM;
|
2018-04-04 03:55:17 +08:00
|
|
|
goto out;
|
2019-03-16 01:06:16 +08:00
|
|
|
}
|
2018-01-06 03:51:12 +08:00
|
|
|
|
|
|
|
extent_map_tree_init(em_tree);
|
|
|
|
|
2019-03-18 22:05:27 +08:00
|
|
|
ret = test_case_1(fs_info, em_tree);
|
|
|
|
if (ret)
|
|
|
|
goto out;
|
|
|
|
ret = test_case_2(fs_info, em_tree);
|
|
|
|
if (ret)
|
|
|
|
goto out;
|
|
|
|
ret = test_case_3(fs_info, em_tree);
|
|
|
|
if (ret)
|
|
|
|
goto out;
|
|
|
|
ret = test_case_4(fs_info, em_tree);
|
2018-01-06 03:51:12 +08:00
|
|
|
|
2018-04-04 03:55:17 +08:00
|
|
|
out:
|
2019-03-18 22:05:27 +08:00
|
|
|
kfree(em_tree);
|
2018-04-04 03:55:17 +08:00
|
|
|
btrfs_free_dummy_fs_info(fs_info);
|
|
|
|
|
2019-03-16 01:06:16 +08:00
|
|
|
return ret;
|
2018-01-06 03:51:12 +08:00
|
|
|
}
|