提交 3f556f78 编写于 作者: D David Sterba

btrfs: unify extent buffer allocation api

Make the extent buffer allocation interface consistent.  Cloned eb will
set a valid fs_info.  For dummy eb, we can drop the length parameter and
set it from fs_info.

The built-in sanity checks may pass a NULL fs_info that's queried for
nodesize, but we know it's 4096.
Signed-off-by: NDavid Sterba <dsterba@suse.cz>
上级 23d79d81
...@@ -1363,8 +1363,7 @@ tree_mod_log_rewind(struct btrfs_fs_info *fs_info, struct btrfs_path *path, ...@@ -1363,8 +1363,7 @@ tree_mod_log_rewind(struct btrfs_fs_info *fs_info, struct btrfs_path *path,
if (tm->op == MOD_LOG_KEY_REMOVE_WHILE_FREEING) { if (tm->op == MOD_LOG_KEY_REMOVE_WHILE_FREEING) {
BUG_ON(tm->slot != 0); BUG_ON(tm->slot != 0);
eb_rewin = alloc_dummy_extent_buffer(eb->start, eb_rewin = alloc_dummy_extent_buffer(fs_info, eb->start);
fs_info->tree_root->nodesize);
if (!eb_rewin) { if (!eb_rewin) {
btrfs_tree_read_unlock_blocking(eb); btrfs_tree_read_unlock_blocking(eb);
free_extent_buffer(eb); free_extent_buffer(eb);
...@@ -1444,7 +1443,7 @@ get_old_root(struct btrfs_root *root, u64 time_seq) ...@@ -1444,7 +1443,7 @@ get_old_root(struct btrfs_root *root, u64 time_seq)
} else if (old_root) { } else if (old_root) {
btrfs_tree_read_unlock(eb_root); btrfs_tree_read_unlock(eb_root);
free_extent_buffer(eb_root); free_extent_buffer(eb_root);
eb = alloc_dummy_extent_buffer(logical, root->nodesize); eb = alloc_dummy_extent_buffer(root->fs_info, logical);
} else { } else {
btrfs_set_lock_blocking_rw(eb_root, BTRFS_READ_LOCK); btrfs_set_lock_blocking_rw(eb_root, BTRFS_READ_LOCK);
eb = btrfs_clone_extent_buffer(eb_root); eb = btrfs_clone_extent_buffer(eb_root);
......
...@@ -4643,7 +4643,7 @@ struct extent_buffer *btrfs_clone_extent_buffer(struct extent_buffer *src) ...@@ -4643,7 +4643,7 @@ struct extent_buffer *btrfs_clone_extent_buffer(struct extent_buffer *src)
struct extent_buffer *new; struct extent_buffer *new;
unsigned long num_pages = num_extent_pages(src->start, src->len); unsigned long num_pages = num_extent_pages(src->start, src->len);
new = __alloc_extent_buffer(NULL, src->start, src->len); new = __alloc_extent_buffer(src->fs_info, src->start, src->len);
if (new == NULL) if (new == NULL)
return NULL; return NULL;
...@@ -4666,13 +4666,26 @@ struct extent_buffer *btrfs_clone_extent_buffer(struct extent_buffer *src) ...@@ -4666,13 +4666,26 @@ struct extent_buffer *btrfs_clone_extent_buffer(struct extent_buffer *src)
return new; return new;
} }
struct extent_buffer *alloc_dummy_extent_buffer(u64 start, unsigned long len) struct extent_buffer *alloc_dummy_extent_buffer(struct btrfs_fs_info *fs_info,
u64 start)
{ {
struct extent_buffer *eb; struct extent_buffer *eb;
unsigned long num_pages = num_extent_pages(0, len); unsigned long len;
unsigned long num_pages;
unsigned long i; unsigned long i;
eb = __alloc_extent_buffer(NULL, start, len); if (!fs_info) {
/*
* Called only from tests that don't always have a fs_info
* available, but we know that nodesize is 4096
*/
len = 4096;
} else {
len = fs_info->tree_root->nodesize;
}
num_pages = num_extent_pages(0, len);
eb = __alloc_extent_buffer(fs_info, start, len);
if (!eb) if (!eb)
return NULL; return NULL;
...@@ -4770,7 +4783,7 @@ struct extent_buffer *alloc_test_extent_buffer(struct btrfs_fs_info *fs_info, ...@@ -4770,7 +4783,7 @@ struct extent_buffer *alloc_test_extent_buffer(struct btrfs_fs_info *fs_info,
eb = find_extent_buffer(fs_info, start); eb = find_extent_buffer(fs_info, start);
if (eb) if (eb)
return eb; return eb;
eb = alloc_dummy_extent_buffer(start, len); eb = alloc_dummy_extent_buffer(fs_info, start);
if (!eb) if (!eb)
return NULL; return NULL;
eb->fs_info = fs_info; eb->fs_info = fs_info;
......
...@@ -263,7 +263,8 @@ void set_page_extent_mapped(struct page *page); ...@@ -263,7 +263,8 @@ void set_page_extent_mapped(struct page *page);
struct extent_buffer *alloc_extent_buffer(struct btrfs_fs_info *fs_info, struct extent_buffer *alloc_extent_buffer(struct btrfs_fs_info *fs_info,
u64 start, unsigned long len); u64 start, unsigned long len);
struct extent_buffer *alloc_dummy_extent_buffer(u64 start, unsigned long len); struct extent_buffer *alloc_dummy_extent_buffer(struct btrfs_fs_info *fs_info,
u64 start);
struct extent_buffer *btrfs_clone_extent_buffer(struct extent_buffer *src); struct extent_buffer *btrfs_clone_extent_buffer(struct extent_buffer *src);
struct extent_buffer *find_extent_buffer(struct btrfs_fs_info *fs_info, struct extent_buffer *find_extent_buffer(struct btrfs_fs_info *fs_info,
u64 start); u64 start);
......
...@@ -53,7 +53,7 @@ static int test_btrfs_split_item(void) ...@@ -53,7 +53,7 @@ static int test_btrfs_split_item(void)
return -ENOMEM; return -ENOMEM;
} }
path->nodes[0] = eb = alloc_dummy_extent_buffer(0, 4096); path->nodes[0] = eb = alloc_dummy_extent_buffer(NULL, 4096);
if (!eb) { if (!eb) {
test_msg("Could not allocate dummy buffer\n"); test_msg("Could not allocate dummy buffer\n");
ret = -ENOMEM; ret = -ENOMEM;
......
...@@ -255,7 +255,7 @@ static noinline int test_btrfs_get_extent(void) ...@@ -255,7 +255,7 @@ static noinline int test_btrfs_get_extent(void)
goto out; goto out;
} }
root->node = alloc_dummy_extent_buffer(0, 4096); root->node = alloc_dummy_extent_buffer(NULL, 4096);
if (!root->node) { if (!root->node) {
test_msg("Couldn't allocate dummy buffer\n"); test_msg("Couldn't allocate dummy buffer\n");
goto out; goto out;
...@@ -843,7 +843,7 @@ static int test_hole_first(void) ...@@ -843,7 +843,7 @@ static int test_hole_first(void)
goto out; goto out;
} }
root->node = alloc_dummy_extent_buffer(0, 4096); root->node = alloc_dummy_extent_buffer(NULL, 4096);
if (!root->node) { if (!root->node) {
test_msg("Couldn't allocate dummy buffer\n"); test_msg("Couldn't allocate dummy buffer\n");
goto out; goto out;
......
...@@ -404,6 +404,16 @@ int btrfs_test_qgroups(void) ...@@ -404,6 +404,16 @@ int btrfs_test_qgroups(void)
ret = -ENOMEM; ret = -ENOMEM;
goto out; goto out;
} }
/* We are using this root as our extent root */
root->fs_info->extent_root = root;
/*
* Some of the paths we test assume we have a filled out fs_info, so we
* just need to add the root in there so we don't panic.
*/
root->fs_info->tree_root = root;
root->fs_info->quota_root = root;
root->fs_info->quota_enabled = 1;
/* /*
* Can't use bytenr 0, some things freak out * Can't use bytenr 0, some things freak out
...@@ -448,17 +458,6 @@ int btrfs_test_qgroups(void) ...@@ -448,17 +458,6 @@ int btrfs_test_qgroups(void)
goto out; goto out;
} }
/* We are using this root as our extent root */
root->fs_info->extent_root = root;
/*
* Some of the paths we test assume we have a filled out fs_info, so we
* just need to addt he root in there so we don't panic.
*/
root->fs_info->tree_root = root;
root->fs_info->quota_root = root;
root->fs_info->quota_enabled = 1;
test_msg("Running qgroup tests\n"); test_msg("Running qgroup tests\n");
ret = test_no_shared_qgroup(root); ret = test_no_shared_qgroup(root);
if (ret) if (ret)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册