]> git.hungrycats.org Git - linux/commitdiff
btrfs: don't save block group root into super block
authorQu Wenruo <wqu@suse.com>
Tue, 9 Aug 2022 05:02:17 +0000 (13:02 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 12 Jan 2023 11:00:44 +0000 (12:00 +0100)
[ Upstream commit 14033b08a02916e85ffc5397e4ac15337359f3ae ]

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 <wqu@suse.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
Stable-dep-of: 2ba48b20049b ("btrfs: fix compat_ro checks against remount")
Signed-off-by: Sasha Levin <sashal@kernel.org>
fs/btrfs/block-rsv.c
fs/btrfs/ctree.h
fs/btrfs/disk-io.c
fs/btrfs/transaction.c

index 06be0644dd37651ca3afcfe93d7586f4bfc094ae..6ce704d3bdd27db2b2f375976a862f651c2387b8 100644 (file)
@@ -424,6 +424,7 @@ void btrfs_init_root_block_rsv(struct btrfs_root *root)
        case BTRFS_CSUM_TREE_OBJECTID:
        case BTRFS_EXTENT_TREE_OBJECTID:
        case BTRFS_FREE_SPACE_TREE_OBJECTID:
+       case BTRFS_BLOCK_GROUP_TREE_OBJECTID:
                root->block_rsv = &fs_info->delayed_refs_rsv;
                break;
        case BTRFS_ROOT_TREE_OBJECTID:
index bad06add93d7ee75faffc4a1dd34ae9cb8eb0ed7..6b1a8b295970ff48dca13e78e1202f1cbb575f1d 100644 (file)
@@ -280,14 +280,9 @@ struct btrfs_super_block {
        /* the UUID written into btree blocks */
        u8 metadata_uuid[BTRFS_FSID_SIZE];
 
-       /* Extent tree v2 */
-       __le64 block_group_root;
-       __le64 block_group_root_generation;
-       u8 block_group_root_level;
-
        /* future expansion */
-       u8 reserved8[7];
-       __le64 reserved[25];
+       u8 reserved8[8];
+       __le64 reserved[27];
        u8 sys_chunk_array[BTRFS_SYSTEM_CHUNK_ARRAY_SIZE];
        struct btrfs_root_backup super_roots[BTRFS_NUM_BACKUP_ROOTS];
 
@@ -2391,17 +2386,6 @@ BTRFS_SETGET_STACK_FUNCS(backup_bytes_used, struct btrfs_root_backup,
 BTRFS_SETGET_STACK_FUNCS(backup_num_devices, struct btrfs_root_backup,
                   num_devices, 64);
 
-/*
- * For extent tree v2 we overload the extent root with the block group root, as
- * we will have multiple extent roots.
- */
-BTRFS_SETGET_STACK_FUNCS(backup_block_group_root, struct btrfs_root_backup,
-                        extent_root, 64);
-BTRFS_SETGET_STACK_FUNCS(backup_block_group_root_gen, struct btrfs_root_backup,
-                        extent_root_gen, 64);
-BTRFS_SETGET_STACK_FUNCS(backup_block_group_root_level,
-                        struct btrfs_root_backup, extent_root_level, 8);
-
 /* struct btrfs_balance_item */
 BTRFS_SETGET_FUNCS(balance_flags, struct btrfs_balance_item, flags, 64);
 
@@ -2534,13 +2518,6 @@ BTRFS_SETGET_STACK_FUNCS(super_cache_generation, struct btrfs_super_block,
 BTRFS_SETGET_STACK_FUNCS(super_magic, struct btrfs_super_block, magic, 64);
 BTRFS_SETGET_STACK_FUNCS(super_uuid_tree_generation, struct btrfs_super_block,
                         uuid_tree_generation, 64);
-BTRFS_SETGET_STACK_FUNCS(super_block_group_root, struct btrfs_super_block,
-                        block_group_root, 64);
-BTRFS_SETGET_STACK_FUNCS(super_block_group_root_generation,
-                        struct btrfs_super_block,
-                        block_group_root_generation, 64);
-BTRFS_SETGET_STACK_FUNCS(super_block_group_root_level, struct btrfs_super_block,
-                        block_group_root_level, 8);
 
 int btrfs_super_csum_size(const struct btrfs_super_block *s);
 const char *btrfs_super_csum_name(u16 csum_type);
index c72074a234d2650bd643581e9de75adfa8d375bb..a4f78a347a1fd3a05c3475d7172092c0e0f9f299 100644 (file)
@@ -1524,6 +1524,9 @@ static struct btrfs_root *btrfs_get_global_root(struct btrfs_fs_info *fs_info,
        if (objectid == BTRFS_UUID_TREE_OBJECTID)
                return btrfs_grab_root(fs_info->uuid_root) ?
                        fs_info->uuid_root : ERR_PTR(-ENOENT);
+       if (objectid == BTRFS_BLOCK_GROUP_TREE_OBJECTID)
+               return btrfs_grab_root(fs_info->block_group_root) ?
+                       fs_info->block_group_root : ERR_PTR(-ENOENT);
        if (objectid == BTRFS_FREE_SPACE_TREE_OBJECTID) {
                struct btrfs_root *root = btrfs_global_root(fs_info, &key);
 
@@ -1980,14 +1983,7 @@ static void backup_super_roots(struct btrfs_fs_info *info)
        btrfs_set_backup_chunk_root_level(root_backup,
                               btrfs_header_level(info->chunk_root->node));
 
-       if (btrfs_fs_incompat(info, EXTENT_TREE_V2)) {
-               btrfs_set_backup_block_group_root(root_backup,
-                                       info->block_group_root->node->start);
-               btrfs_set_backup_block_group_root_gen(root_backup,
-                       btrfs_header_generation(info->block_group_root->node));
-               btrfs_set_backup_block_group_root_level(root_backup,
-                       btrfs_header_level(info->block_group_root->node));
-       } else {
+       if (!btrfs_fs_incompat(info, EXTENT_TREE_V2)) {
                struct btrfs_root *extent_root = btrfs_extent_root(info, 0);
                struct btrfs_root *csum_root = btrfs_csum_root(info, 0);
 
@@ -2529,10 +2525,24 @@ static int btrfs_read_roots(struct btrfs_fs_info *fs_info)
        if (ret)
                return ret;
 
-       location.objectid = BTRFS_DEV_TREE_OBJECTID;
        location.type = BTRFS_ROOT_ITEM_KEY;
        location.offset = 0;
 
+       if (btrfs_fs_incompat(fs_info, EXTENT_TREE_V2)) {
+               location.objectid = BTRFS_BLOCK_GROUP_TREE_OBJECTID;
+               root = btrfs_read_tree_root(tree_root, &location);
+               if (IS_ERR(root)) {
+                       if (!btrfs_test_opt(fs_info, IGNOREBADROOTS)) {
+                               ret = PTR_ERR(root);
+                               goto out;
+                       }
+               } else {
+                       set_bit(BTRFS_ROOT_TRACK_DIRTY, &root->state);
+                       fs_info->block_group_root = root;
+               }
+       }
+
+       location.objectid = BTRFS_DEV_TREE_OBJECTID;
        root = btrfs_read_tree_root(tree_root, &location);
        if (IS_ERR(root)) {
                if (!btrfs_test_opt(fs_info, IGNOREBADROOTS)) {
@@ -2862,17 +2872,7 @@ static int load_important_roots(struct btrfs_fs_info *fs_info)
                btrfs_warn(fs_info, "couldn't read tree root");
                return ret;
        }
-
-       if (!btrfs_fs_incompat(fs_info, EXTENT_TREE_V2))
-               return 0;
-
-       bytenr = btrfs_super_block_group_root(sb);
-       gen = btrfs_super_block_group_root_generation(sb);
-       level = btrfs_super_block_group_root_level(sb);
-       ret = load_super_root(fs_info->block_group_root, bytenr, gen, level);
-       if (ret)
-               btrfs_warn(fs_info, "couldn't read block group root");
-       return ret;
+       return 0;
 }
 
 static int __cold init_tree_roots(struct btrfs_fs_info *fs_info)
index 0bec10740ad3921ec878ed0368d9425a32843eac..8fab3b2749571022002c5ec7f0513b164a7cebad 100644 (file)
@@ -1912,14 +1912,6 @@ static void update_super_roots(struct btrfs_fs_info *fs_info)
                super->cache_generation = 0;
        if (test_bit(BTRFS_FS_UPDATE_UUID_TREE_GEN, &fs_info->flags))
                super->uuid_tree_generation = root_item->generation;
-
-       if (btrfs_fs_incompat(fs_info, EXTENT_TREE_V2)) {
-               root_item = &fs_info->block_group_root->root_item;
-
-               super->block_group_root = root_item->bytenr;
-               super->block_group_root_generation = root_item->generation;
-               super->block_group_root_level = root_item->level;
-       }
 }
 
 int btrfs_transaction_in_commit(struct btrfs_fs_info *info)