]> git.baikalelectronics.ru Git - kernel.git/commitdiff
btrfs: init root block_rsv at init root time
authorJosef Bacik <josef@toxicpanda.com>
Fri, 5 Nov 2021 20:45:44 +0000 (16:45 -0400)
committerDavid Sterba <dsterba@suse.com>
Mon, 3 Jan 2022 14:09:48 +0000 (15:09 +0100)
In the future we're going to have multiple csum and extent root trees,
so init the roots block_rsv at setup_root time based on their root key
objectid.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/block-rsv.c
fs/btrfs/block-rsv.h
fs/btrfs/disk-io.c

index 9d162b5adfd817e290bcbb4cf5289012111c2817..454f3c629dd8c402bcda4e18cfd6e64f30f1dc75 100644 (file)
@@ -412,6 +412,29 @@ void btrfs_update_global_block_rsv(struct btrfs_fs_info *fs_info)
        spin_unlock(&sinfo->lock);
 }
 
+void btrfs_init_root_block_rsv(struct btrfs_root *root)
+{
+       struct btrfs_fs_info *fs_info = root->fs_info;
+
+       switch (root->root_key.objectid) {
+       case BTRFS_CSUM_TREE_OBJECTID:
+       case BTRFS_EXTENT_TREE_OBJECTID:
+               root->block_rsv = &fs_info->delayed_refs_rsv;
+               break;
+       case BTRFS_ROOT_TREE_OBJECTID:
+       case BTRFS_DEV_TREE_OBJECTID:
+       case BTRFS_QUOTA_TREE_OBJECTID:
+               root->block_rsv = &fs_info->global_block_rsv;
+               break;
+       case BTRFS_CHUNK_TREE_OBJECTID:
+               root->block_rsv = &fs_info->chunk_block_rsv;
+               break;
+       default:
+               root->block_rsv = NULL;
+               break;
+       }
+}
+
 void btrfs_init_global_block_rsv(struct btrfs_fs_info *fs_info)
 {
        struct btrfs_space_info *space_info;
@@ -426,22 +449,6 @@ void btrfs_init_global_block_rsv(struct btrfs_fs_info *fs_info)
        fs_info->delayed_block_rsv.space_info = space_info;
        fs_info->delayed_refs_rsv.space_info = space_info;
 
-       /*
-        * Our various recovery options can leave us with NULL roots, so check
-        * here and just bail before we go dereferencing NULLs everywhere.
-        */
-       if (!fs_info->extent_root || !fs_info->csum_root ||
-           !fs_info->dev_root || !fs_info->chunk_root || !fs_info->tree_root)
-               return;
-
-       fs_info->extent_root->block_rsv = &fs_info->delayed_refs_rsv;
-       fs_info->csum_root->block_rsv = &fs_info->delayed_refs_rsv;
-       fs_info->dev_root->block_rsv = &fs_info->global_block_rsv;
-       fs_info->tree_root->block_rsv = &fs_info->global_block_rsv;
-       if (fs_info->quota_root)
-               fs_info->quota_root->block_rsv = &fs_info->global_block_rsv;
-       fs_info->chunk_root->block_rsv = &fs_info->chunk_block_rsv;
-
        btrfs_update_global_block_rsv(fs_info);
 }
 
index 07d61c2c5d28cd4bd0ab00ae101b74764909631c..3b67ff08d4348abff32a15dfbc9cf216950b4be2 100644 (file)
@@ -50,6 +50,7 @@ struct btrfs_block_rsv {
 };
 
 void btrfs_init_block_rsv(struct btrfs_block_rsv *rsv, unsigned short type);
+void btrfs_init_root_block_rsv(struct btrfs_root *root);
 struct btrfs_block_rsv *btrfs_alloc_block_rsv(struct btrfs_fs_info *fs_info,
                                              unsigned short type);
 void btrfs_init_metadata_block_rsv(struct btrfs_fs_info *fs_info,
index edf837ddbfea76a4d94f84cd846f64088737f9ca..ff5ec8218501a828c1197a2e6e9eee48fd86b9c1 100644 (file)
@@ -1140,7 +1140,12 @@ static void __setup_root(struct btrfs_root *root, struct btrfs_fs_info *fs_info,
                         u64 objectid)
 {
        bool dummy = test_bit(BTRFS_FS_STATE_DUMMY_FS_INFO, &fs_info->fs_state);
+
+       memset(&root->root_key, 0, sizeof(root->root_key));
+       memset(&root->root_item, 0, sizeof(root->root_item));
+       memset(&root->defrag_progress, 0, sizeof(root->defrag_progress));
        root->fs_info = fs_info;
+       root->root_key.objectid = objectid;
        root->node = NULL;
        root->commit_root = NULL;
        root->state = 0;
@@ -1151,7 +1156,8 @@ static void __setup_root(struct btrfs_root *root, struct btrfs_fs_info *fs_info,
        root->nr_ordered_extents = 0;
        root->inode_tree = RB_ROOT;
        INIT_RADIX_TREE(&root->delayed_nodes_tree, GFP_ATOMIC);
-       root->block_rsv = NULL;
+
+       btrfs_init_root_block_rsv(root);
 
        INIT_LIST_HEAD(&root->dirty_list);
        INIT_LIST_HEAD(&root->root_list);
@@ -1189,6 +1195,7 @@ static void __setup_root(struct btrfs_root *root, struct btrfs_fs_info *fs_info,
        root->log_transid = 0;
        root->log_transid_committed = -1;
        root->last_log_commit = 0;
+       root->anon_dev = 0;
        if (!dummy) {
                extent_io_tree_init(fs_info, &root->dirty_log_pages,
                                    IO_TREE_ROOT_DIRTY_LOG_PAGES, NULL);
@@ -1196,12 +1203,6 @@ static void __setup_root(struct btrfs_root *root, struct btrfs_fs_info *fs_info,
                                    IO_TREE_LOG_CSUM_RANGE, NULL);
        }
 
-       memset(&root->root_key, 0, sizeof(root->root_key));
-       memset(&root->root_item, 0, sizeof(root->root_item));
-       memset(&root->defrag_progress, 0, sizeof(root->defrag_progress));
-       root->root_key.objectid = objectid;
-       root->anon_dev = 0;
-
        spin_lock_init(&root->root_item_lock);
        btrfs_qgroup_init_swapped_blocks(&root->swapped_blocks);
 #ifdef CONFIG_BTRFS_DEBUG