Skip to content

Commit aeb935a

Browse files
adam900710kdave
authored andcommitted
btrfs: don't set SHAREABLE flag for data reloc tree
SHAREABLE flag is set for subvolumes because users can create snapshot for subvolumes, thus sharing tree blocks of them. But data reloc tree is not exposed to user space, as it's only an internal tree for data relocation, thus it doesn't need the full path replacement handling at all. This patch will make data reloc tree a non-shareable tree, and add btrfs_fs_info::data_reloc_root for data reloc tree, so relocation code can grab it from fs_info directly. This would slightly improve tree relocation, as now data reloc tree can go through regular COW routine to get relocated, without bothering the complex tree reloc tree routine. Signed-off-by: Qu Wenruo <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent 82028e0 commit aeb935a

File tree

3 files changed

+23
-12
lines changed

3 files changed

+23
-12
lines changed

fs/btrfs/ctree.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,7 @@ struct btrfs_fs_info {
582582
struct btrfs_root *quota_root;
583583
struct btrfs_root *uuid_root;
584584
struct btrfs_root *free_space_root;
585+
struct btrfs_root *data_reloc_root;
585586

586587
/* the log root tree is a directory of all the other log roots */
587588
struct btrfs_root *log_root_tree;

fs/btrfs/disk-io.c

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1417,7 +1417,8 @@ static int btrfs_init_fs_root(struct btrfs_root *root)
14171417
if (ret)
14181418
goto fail;
14191419

1420-
if (root->root_key.objectid != BTRFS_TREE_LOG_OBJECTID) {
1420+
if (root->root_key.objectid != BTRFS_TREE_LOG_OBJECTID &&
1421+
root->root_key.objectid != BTRFS_DATA_RELOC_TREE_OBJECTID) {
14211422
set_bit(BTRFS_ROOT_SHAREABLE, &root->state);
14221423
btrfs_check_and_init_root_item(&root->root_item);
14231424
}
@@ -1523,6 +1524,7 @@ void btrfs_free_fs_info(struct btrfs_fs_info *fs_info)
15231524
btrfs_put_root(fs_info->uuid_root);
15241525
btrfs_put_root(fs_info->free_space_root);
15251526
btrfs_put_root(fs_info->fs_root);
1527+
btrfs_put_root(fs_info->data_reloc_root);
15261528
btrfs_check_leaked_roots(fs_info);
15271529
btrfs_extent_buffer_leak_debug_check(fs_info);
15281530
kfree(fs_info->super_copy);
@@ -1979,6 +1981,7 @@ static void free_root_pointers(struct btrfs_fs_info *info, bool free_chunk_root)
19791981
free_root_extent_buffers(info->quota_root);
19801982
free_root_extent_buffers(info->uuid_root);
19811983
free_root_extent_buffers(info->fs_root);
1984+
free_root_extent_buffers(info->data_reloc_root);
19821985
if (free_chunk_root)
19831986
free_root_extent_buffers(info->chunk_root);
19841987
free_root_extent_buffers(info->free_space_root);
@@ -2285,6 +2288,19 @@ static int btrfs_read_roots(struct btrfs_fs_info *fs_info)
22852288
set_bit(BTRFS_ROOT_TRACK_DIRTY, &root->state);
22862289
fs_info->csum_root = root;
22872290

2291+
/*
2292+
* This tree can share blocks with some other fs tree during relocation
2293+
* and we need a proper setup by btrfs_get_fs_root
2294+
*/
2295+
location.objectid = BTRFS_DATA_RELOC_TREE_OBJECTID;
2296+
root = btrfs_get_fs_root(tree_root->fs_info, &location, true);
2297+
if (IS_ERR(root)) {
2298+
ret = PTR_ERR(root);
2299+
goto out;
2300+
}
2301+
set_bit(BTRFS_ROOT_TRACK_DIRTY, &root->state);
2302+
fs_info->data_reloc_root = root;
2303+
22882304
location.objectid = BTRFS_QUOTA_TREE_OBJECTID;
22892305
root = btrfs_read_tree_root(tree_root, &location);
22902306
if (!IS_ERR(root)) {

fs/btrfs/relocation.c

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3476,10 +3476,7 @@ struct inode *create_reloc_inode(struct btrfs_fs_info *fs_info,
34763476
u64 objectid;
34773477
int err = 0;
34783478

3479-
root = read_fs_root(fs_info, BTRFS_DATA_RELOC_TREE_OBJECTID);
3480-
if (IS_ERR(root))
3481-
return ERR_CAST(root);
3482-
3479+
root = btrfs_grab_root(fs_info->data_reloc_root);
34833480
trans = btrfs_start_transaction(root, 6);
34843481
if (IS_ERR(trans)) {
34853482
btrfs_put_root(root);
@@ -3871,13 +3868,10 @@ int btrfs_recover_relocation(struct btrfs_root *root)
38713868

38723869
if (err == 0) {
38733870
/* cleanup orphan inode in data relocation tree */
3874-
fs_root = read_fs_root(fs_info, BTRFS_DATA_RELOC_TREE_OBJECTID);
3875-
if (IS_ERR(fs_root)) {
3876-
err = PTR_ERR(fs_root);
3877-
} else {
3878-
err = btrfs_orphan_cleanup(fs_root);
3879-
btrfs_put_root(fs_root);
3880-
}
3871+
fs_root = btrfs_grab_root(fs_info->data_reloc_root);
3872+
ASSERT(fs_root);
3873+
err = btrfs_orphan_cleanup(fs_root);
3874+
btrfs_put_root(fs_root);
38813875
}
38823876
return err;
38833877
}

0 commit comments

Comments
 (0)