Skip to content

Commit 14033b0

Browse files
adam900710kdave
authored andcommitted
btrfs: don't save block group root into super block
The extent tree v2 needs a new root for storing all block group items, the whole feature hasn't been finished yet so we can afford to do some changes. My initial proposal years ago just added a new tree rootid, and load it from tree root, just like what we did for quota/free space tree/uuid/extent roots. But the extent tree v2 patches introduced a completely new way to store block group tree root into super block which is arguably wasteful. Currently there are only 3 trees stored in super blocks, and they all have their valid reasons: - Chunk root Needed for bootstrap. - Tree root Really the entry point for all trees. - Log root This is special as log root has to be updated out of existing transaction mechanism. There is not even any reason to put block group root into super blocks, the block group tree is updated at the same time as the old extent tree, no need for extra bootstrap/out-of-transaction update. So just move block group root from super block into tree root. Signed-off-by: Qu Wenruo <[email protected]> Reviewed-by: David Sterba <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent 81d5d61 commit 14033b0

File tree

4 files changed

+23
-53
lines changed

4 files changed

+23
-53
lines changed

fs/btrfs/block-rsv.c

+1
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,7 @@ void btrfs_init_root_block_rsv(struct btrfs_root *root)
424424
case BTRFS_CSUM_TREE_OBJECTID:
425425
case BTRFS_EXTENT_TREE_OBJECTID:
426426
case BTRFS_FREE_SPACE_TREE_OBJECTID:
427+
case BTRFS_BLOCK_GROUP_TREE_OBJECTID:
427428
root->block_rsv = &fs_info->delayed_refs_rsv;
428429
break;
429430
case BTRFS_ROOT_TREE_OBJECTID:

fs/btrfs/ctree.h

+2-25
Original file line numberDiff line numberDiff line change
@@ -280,14 +280,9 @@ struct btrfs_super_block {
280280
/* the UUID written into btree blocks */
281281
u8 metadata_uuid[BTRFS_FSID_SIZE];
282282

283-
/* Extent tree v2 */
284-
__le64 block_group_root;
285-
__le64 block_group_root_generation;
286-
u8 block_group_root_level;
287-
288283
/* future expansion */
289-
u8 reserved8[7];
290-
__le64 reserved[25];
284+
u8 reserved8[8];
285+
__le64 reserved[27];
291286
u8 sys_chunk_array[BTRFS_SYSTEM_CHUNK_ARRAY_SIZE];
292287
struct btrfs_root_backup super_roots[BTRFS_NUM_BACKUP_ROOTS];
293288

@@ -2477,17 +2472,6 @@ BTRFS_SETGET_STACK_FUNCS(backup_bytes_used, struct btrfs_root_backup,
24772472
BTRFS_SETGET_STACK_FUNCS(backup_num_devices, struct btrfs_root_backup,
24782473
num_devices, 64);
24792474

2480-
/*
2481-
* For extent tree v2 we overload the extent root with the block group root, as
2482-
* we will have multiple extent roots.
2483-
*/
2484-
BTRFS_SETGET_STACK_FUNCS(backup_block_group_root, struct btrfs_root_backup,
2485-
extent_root, 64);
2486-
BTRFS_SETGET_STACK_FUNCS(backup_block_group_root_gen, struct btrfs_root_backup,
2487-
extent_root_gen, 64);
2488-
BTRFS_SETGET_STACK_FUNCS(backup_block_group_root_level,
2489-
struct btrfs_root_backup, extent_root_level, 8);
2490-
24912475
/* struct btrfs_balance_item */
24922476
BTRFS_SETGET_FUNCS(balance_flags, struct btrfs_balance_item, flags, 64);
24932477

@@ -2620,13 +2604,6 @@ BTRFS_SETGET_STACK_FUNCS(super_cache_generation, struct btrfs_super_block,
26202604
BTRFS_SETGET_STACK_FUNCS(super_magic, struct btrfs_super_block, magic, 64);
26212605
BTRFS_SETGET_STACK_FUNCS(super_uuid_tree_generation, struct btrfs_super_block,
26222606
uuid_tree_generation, 64);
2623-
BTRFS_SETGET_STACK_FUNCS(super_block_group_root, struct btrfs_super_block,
2624-
block_group_root, 64);
2625-
BTRFS_SETGET_STACK_FUNCS(super_block_group_root_generation,
2626-
struct btrfs_super_block,
2627-
block_group_root_generation, 64);
2628-
BTRFS_SETGET_STACK_FUNCS(super_block_group_root_level, struct btrfs_super_block,
2629-
block_group_root_level, 8);
26302607

26312608
int btrfs_super_csum_size(const struct btrfs_super_block *s);
26322609
const char *btrfs_super_csum_name(u16 csum_type);

fs/btrfs/disk-io.c

+20-20
Original file line numberDiff line numberDiff line change
@@ -1522,6 +1522,9 @@ static struct btrfs_root *btrfs_get_global_root(struct btrfs_fs_info *fs_info,
15221522
if (objectid == BTRFS_UUID_TREE_OBJECTID)
15231523
return btrfs_grab_root(fs_info->uuid_root) ?
15241524
fs_info->uuid_root : ERR_PTR(-ENOENT);
1525+
if (objectid == BTRFS_BLOCK_GROUP_TREE_OBJECTID)
1526+
return btrfs_grab_root(fs_info->block_group_root) ?
1527+
fs_info->block_group_root : ERR_PTR(-ENOENT);
15251528
if (objectid == BTRFS_FREE_SPACE_TREE_OBJECTID) {
15261529
struct btrfs_root *root = btrfs_global_root(fs_info, &key);
15271530

@@ -1978,14 +1981,7 @@ static void backup_super_roots(struct btrfs_fs_info *info)
19781981
btrfs_set_backup_chunk_root_level(root_backup,
19791982
btrfs_header_level(info->chunk_root->node));
19801983

1981-
if (btrfs_fs_incompat(info, EXTENT_TREE_V2)) {
1982-
btrfs_set_backup_block_group_root(root_backup,
1983-
info->block_group_root->node->start);
1984-
btrfs_set_backup_block_group_root_gen(root_backup,
1985-
btrfs_header_generation(info->block_group_root->node));
1986-
btrfs_set_backup_block_group_root_level(root_backup,
1987-
btrfs_header_level(info->block_group_root->node));
1988-
} else {
1984+
if (!btrfs_fs_incompat(info, EXTENT_TREE_V2)) {
19891985
struct btrfs_root *extent_root = btrfs_extent_root(info, 0);
19901986
struct btrfs_root *csum_root = btrfs_csum_root(info, 0);
19911987

@@ -2527,10 +2523,24 @@ static int btrfs_read_roots(struct btrfs_fs_info *fs_info)
25272523
if (ret)
25282524
return ret;
25292525

2530-
location.objectid = BTRFS_DEV_TREE_OBJECTID;
25312526
location.type = BTRFS_ROOT_ITEM_KEY;
25322527
location.offset = 0;
25332528

2529+
if (btrfs_fs_incompat(fs_info, EXTENT_TREE_V2)) {
2530+
location.objectid = BTRFS_BLOCK_GROUP_TREE_OBJECTID;
2531+
root = btrfs_read_tree_root(tree_root, &location);
2532+
if (IS_ERR(root)) {
2533+
if (!btrfs_test_opt(fs_info, IGNOREBADROOTS)) {
2534+
ret = PTR_ERR(root);
2535+
goto out;
2536+
}
2537+
} else {
2538+
set_bit(BTRFS_ROOT_TRACK_DIRTY, &root->state);
2539+
fs_info->block_group_root = root;
2540+
}
2541+
}
2542+
2543+
location.objectid = BTRFS_DEV_TREE_OBJECTID;
25342544
root = btrfs_read_tree_root(tree_root, &location);
25352545
if (IS_ERR(root)) {
25362546
if (!btrfs_test_opt(fs_info, IGNOREBADROOTS)) {
@@ -2858,17 +2868,7 @@ static int load_important_roots(struct btrfs_fs_info *fs_info)
28582868
btrfs_warn(fs_info, "couldn't read tree root");
28592869
return ret;
28602870
}
2861-
2862-
if (!btrfs_fs_incompat(fs_info, EXTENT_TREE_V2))
2863-
return 0;
2864-
2865-
bytenr = btrfs_super_block_group_root(sb);
2866-
gen = btrfs_super_block_group_root_generation(sb);
2867-
level = btrfs_super_block_group_root_level(sb);
2868-
ret = load_super_root(fs_info->block_group_root, bytenr, gen, level);
2869-
if (ret)
2870-
btrfs_warn(fs_info, "couldn't read block group root");
2871-
return ret;
2871+
return 0;
28722872
}
28732873

28742874
static int __cold init_tree_roots(struct btrfs_fs_info *fs_info)

fs/btrfs/transaction.c

-8
Original file line numberDiff line numberDiff line change
@@ -1894,14 +1894,6 @@ static void update_super_roots(struct btrfs_fs_info *fs_info)
18941894
super->cache_generation = 0;
18951895
if (test_bit(BTRFS_FS_UPDATE_UUID_TREE_GEN, &fs_info->flags))
18961896
super->uuid_tree_generation = root_item->generation;
1897-
1898-
if (btrfs_fs_incompat(fs_info, EXTENT_TREE_V2)) {
1899-
root_item = &fs_info->block_group_root->root_item;
1900-
1901-
super->block_group_root = root_item->bytenr;
1902-
super->block_group_root_generation = root_item->generation;
1903-
super->block_group_root_level = root_item->level;
1904-
}
19051897
}
19061898

19071899
int btrfs_transaction_in_commit(struct btrfs_fs_info *info)

0 commit comments

Comments
 (0)