]> git.baikalelectronics.ru Git - kernel.git/commitdiff
btrfs: stop accessing ->csum_root directly
authorJosef Bacik <josef@toxicpanda.com>
Fri, 5 Nov 2021 20:45:48 +0000 (16:45 -0400)
committerDavid Sterba <dsterba@suse.com>
Mon, 3 Jan 2022 14:09:49 +0000 (15:09 +0100)
We are going to have multiple csum roots in the future, so convert all
users of ->csum_root to btrfs_csum_root() and rename ->csum_root to
->_csum_root so we can easily find remaining users in the future.

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/ctree.h
fs/btrfs/disk-io.c
fs/btrfs/disk-io.h
fs/btrfs/extent-tree.c
fs/btrfs/file-item.c
fs/btrfs/inode.c
fs/btrfs/relocation.c
fs/btrfs/scrub.c
fs/btrfs/tree-log.c

index b216c4c7292a36b7ecccfc4f2b9296cf4216fe2e..21ac60ec19f6c5bdee685829991cb0ece6dad501 100644 (file)
@@ -353,6 +353,7 @@ void btrfs_update_global_block_rsv(struct btrfs_fs_info *fs_info)
        struct btrfs_block_rsv *block_rsv = &fs_info->global_block_rsv;
        struct btrfs_space_info *sinfo = block_rsv->space_info;
        struct btrfs_root *extent_root = btrfs_extent_root(fs_info, 0);
+       struct btrfs_root *csum_root = btrfs_csum_root(fs_info, 0);
        u64 num_bytes;
        unsigned min_items;
 
@@ -362,7 +363,7 @@ void btrfs_update_global_block_rsv(struct btrfs_fs_info *fs_info)
         * it to a minimal amount for safety.
         */
        num_bytes = btrfs_root_used(&extent_root->root_item) +
-               btrfs_root_used(&fs_info->csum_root->root_item) +
+               btrfs_root_used(&csum_root->root_item) +
                btrfs_root_used(&fs_info->tree_root->root_item);
 
        /*
@@ -476,8 +477,9 @@ static struct btrfs_block_rsv *get_block_rsv(
        struct btrfs_block_rsv *block_rsv = NULL;
 
        if (test_bit(BTRFS_ROOT_SHAREABLE, &root->state) ||
-           (root == fs_info->csum_root && trans->adding_csums) ||
-           (root == fs_info->uuid_root))
+           (root == fs_info->uuid_root) ||
+           (trans->adding_csums &&
+            root->root_key.objectid == BTRFS_CSUM_TREE_OBJECTID))
                block_rsv = trans->block_rsv;
 
        if (!block_rsv)
index 1d4cdd1d153cc8172d190a380437232d0be56d89..5a6d53649eee1c0b445eddb44604cf944d275812 100644 (file)
@@ -628,7 +628,7 @@ struct btrfs_fs_info {
        struct btrfs_root *chunk_root;
        struct btrfs_root *dev_root;
        struct btrfs_root *fs_root;
-       struct btrfs_root *csum_root;
+       struct btrfs_root *_csum_root;
        struct btrfs_root *quota_root;
        struct btrfs_root *uuid_root;
        struct btrfs_root *free_space_root;
index 19cea74a848f02d02321c464d4434e900ed1a4fd..4b4a8dae0b1c536b4a655e479c2f0e8960a6ad6d 100644 (file)
@@ -1563,7 +1563,7 @@ static struct btrfs_root *btrfs_get_global_root(struct btrfs_fs_info *fs_info,
        if (objectid == BTRFS_DEV_TREE_OBJECTID)
                return btrfs_grab_root(fs_info->dev_root);
        if (objectid == BTRFS_CSUM_TREE_OBJECTID)
-               return btrfs_grab_root(fs_info->csum_root);
+               return btrfs_grab_root(fs_info->_csum_root);
        if (objectid == BTRFS_QUOTA_TREE_OBJECTID)
                return btrfs_grab_root(fs_info->quota_root) ?
                        fs_info->quota_root : ERR_PTR(-ENOENT);
@@ -1634,7 +1634,7 @@ void btrfs_free_fs_info(struct btrfs_fs_info *fs_info)
        btrfs_put_root(fs_info->tree_root);
        btrfs_put_root(fs_info->chunk_root);
        btrfs_put_root(fs_info->dev_root);
-       btrfs_put_root(fs_info->csum_root);
+       btrfs_put_root(fs_info->_csum_root);
        btrfs_put_root(fs_info->quota_root);
        btrfs_put_root(fs_info->uuid_root);
        btrfs_put_root(fs_info->free_space_root);
@@ -2009,6 +2009,7 @@ static void backup_super_roots(struct btrfs_fs_info *info)
        const int next_backup = info->backup_root_index;
        struct btrfs_root_backup *root_backup;
        struct btrfs_root *extent_root = btrfs_extent_root(info, 0);
+       struct btrfs_root *csum_root = btrfs_csum_root(info, 0);
 
        root_backup = info->super_for_commit->super_roots + next_backup;
 
@@ -2058,11 +2059,11 @@ static void backup_super_roots(struct btrfs_fs_info *info)
        btrfs_set_backup_dev_root_level(root_backup,
                                       btrfs_header_level(info->dev_root->node));
 
-       btrfs_set_backup_csum_root(root_backup, info->csum_root->node->start);
+       btrfs_set_backup_csum_root(root_backup, csum_root->node->start);
        btrfs_set_backup_csum_root_gen(root_backup,
-                              btrfs_header_generation(info->csum_root->node));
+                                      btrfs_header_generation(csum_root->node));
        btrfs_set_backup_csum_root_level(root_backup,
-                              btrfs_header_level(info->csum_root->node));
+                                        btrfs_header_level(csum_root->node));
 
        btrfs_set_backup_total_bytes(root_backup,
                             btrfs_super_total_bytes(info->super_copy));
@@ -2168,7 +2169,7 @@ static void free_root_pointers(struct btrfs_fs_info *info, bool free_chunk_root)
 
        free_root_extent_buffers(info->dev_root);
        free_root_extent_buffers(info->_extent_root);
-       free_root_extent_buffers(info->csum_root);
+       free_root_extent_buffers(info->_csum_root);
        free_root_extent_buffers(info->quota_root);
        free_root_extent_buffers(info->uuid_root);
        free_root_extent_buffers(info->fs_root);
@@ -2488,7 +2489,7 @@ static int btrfs_read_roots(struct btrfs_fs_info *fs_info)
                        }
                } else {
                        set_bit(BTRFS_ROOT_TRACK_DIRTY, &root->state);
-                       fs_info->csum_root = root;
+                       fs_info->_csum_root = root;
                }
        } else {
                set_bit(BTRFS_FS_STATE_NO_CSUMS, &fs_info->fs_state);
index e2824c6ada720e06197e99cdb5404289786ea940..a4d1788acd2462200d63868f87a6814a8a08c11a 100644 (file)
@@ -109,6 +109,12 @@ static inline struct btrfs_root *btrfs_extent_root(struct btrfs_fs_info *fs_info
        return fs_info->_extent_root;
 }
 
+static inline struct btrfs_root *btrfs_csum_root(struct btrfs_fs_info *fs_info,
+                                                u64 bytenr)
+{
+       return fs_info->_csum_root;
+}
+
 static inline struct btrfs_root *btrfs_block_group_root(struct btrfs_fs_info *fs_info)
 {
        return btrfs_extent_root(fs_info, 0);
index 8e5dcb9928f5b43c138fb6d432270ed2efd73cc2..c17caa954dd51e39d1f1f075fa8eca83dfa1c314 100644 (file)
@@ -1851,8 +1851,11 @@ static int cleanup_ref_head(struct btrfs_trans_handle *trans,
        if (head->must_insert_reserved) {
                btrfs_pin_extent(trans, head->bytenr, head->num_bytes, 1);
                if (head->is_data) {
-                       ret = btrfs_del_csums(trans, fs_info->csum_root,
-                                             head->bytenr, head->num_bytes);
+                       struct btrfs_root *csum_root;
+
+                       csum_root = btrfs_csum_root(fs_info, head->bytenr);
+                       ret = btrfs_del_csums(trans, csum_root, head->bytenr,
+                                             head->num_bytes);
                }
        }
 
@@ -3188,7 +3191,9 @@ static int __btrfs_free_extent(struct btrfs_trans_handle *trans,
                btrfs_release_path(path);
 
                if (is_data) {
-                       ret = btrfs_del_csums(trans, info->csum_root, bytenr,
+                       struct btrfs_root *csum_root;
+                       csum_root = btrfs_csum_root(info, bytenr);
+                       ret = btrfs_del_csums(trans, csum_root, bytenr,
                                              num_bytes);
                        if (ret) {
                                btrfs_abort_transaction(trans, ret);
index 2517b0050b9916689839a4ef50433d8f34f94118..90c5c38836ab397efd100f1ac721660349d88018 100644 (file)
@@ -257,6 +257,7 @@ static int search_csum_tree(struct btrfs_fs_info *fs_info,
                            struct btrfs_path *path, u64 disk_bytenr,
                            u64 len, u8 *dst)
 {
+       struct btrfs_root *csum_root;
        struct btrfs_csum_item *item = NULL;
        struct btrfs_key key;
        const u32 sectorsize = fs_info->sectorsize;
@@ -285,7 +286,8 @@ static int search_csum_tree(struct btrfs_fs_info *fs_info,
 
        /* Current item doesn't contain the desired range, search again */
        btrfs_release_path(path);
-       item = btrfs_lookup_csum(NULL, fs_info->csum_root, path, disk_bytenr, 0);
+       csum_root = btrfs_csum_root(fs_info, disk_bytenr);
+       item = btrfs_lookup_csum(NULL, csum_root, path, disk_bytenr, 0);
        if (IS_ERR(item)) {
                ret = PTR_ERR(item);
                goto out;
index 2ea28f8a4a43875680cb74f8db1fe46d66675ad8..504cf090fc889d4e1f4e7736d454dc75a5dff2ca 100644 (file)
@@ -1530,11 +1530,12 @@ static noinline int run_delalloc_zoned(struct btrfs_inode *inode,
 static noinline int csum_exist_in_range(struct btrfs_fs_info *fs_info,
                                        u64 bytenr, u64 num_bytes)
 {
-       int ret;
+       struct btrfs_root *csum_root = btrfs_csum_root(fs_info, bytenr);
        struct btrfs_ordered_sum *sums;
+       int ret;
        LIST_HEAD(list);
 
-       ret = btrfs_lookup_csums_range(fs_info->csum_root, bytenr,
+       ret = btrfs_lookup_csums_range(csum_root, bytenr,
                                       bytenr + num_bytes - 1, &list, 0);
        if (ret == 0 && list_empty(&list))
                return 0;
@@ -2584,11 +2585,15 @@ static int add_pending_csums(struct btrfs_trans_handle *trans,
                             struct list_head *list)
 {
        struct btrfs_ordered_sum *sum;
+       struct btrfs_root *csum_root = NULL;
        int ret;
 
        list_for_each_entry(sum, list, list) {
                trans->adding_csums = true;
-               ret = btrfs_csum_file_blocks(trans, trans->fs_info->csum_root, sum);
+               if (!csum_root)
+                       csum_root = btrfs_csum_root(trans->fs_info,
+                                                   sum->bytenr);
+               ret = btrfs_csum_file_blocks(trans, csum_root, sum);
                trans->adding_csums = false;
                if (ret)
                        return ret;
index 681fb2544a059751556e31e68d25b6024dd9fad4..831c55708c88b13bcbe91c41435c5b415208988c 100644 (file)
@@ -4306,6 +4306,7 @@ out:
 int btrfs_reloc_clone_csums(struct btrfs_inode *inode, u64 file_pos, u64 len)
 {
        struct btrfs_fs_info *fs_info = inode->root->fs_info;
+       struct btrfs_root *csum_root;
        struct btrfs_ordered_sum *sums;
        struct btrfs_ordered_extent *ordered;
        int ret;
@@ -4317,7 +4318,8 @@ int btrfs_reloc_clone_csums(struct btrfs_inode *inode, u64 file_pos, u64 len)
        BUG_ON(ordered->file_offset != file_pos || ordered->num_bytes != len);
 
        disk_bytenr = file_pos + inode->index_cnt;
-       ret = btrfs_lookup_csums_range(fs_info->csum_root, disk_bytenr,
+       csum_root = btrfs_csum_root(fs_info, disk_bytenr);
+       ret = btrfs_lookup_csums_range(csum_root, disk_bytenr,
                                       disk_bytenr + len - 1, &list, 0);
        if (ret)
                goto out;
index a0017351e5585ad7bd314f5cc1de2d5608d22bdf..15a123e671080b6cc56180a0a1af8078bc51b21a 100644 (file)
@@ -2898,7 +2898,7 @@ static noinline_for_stack int scrub_raid56_parity(struct scrub_ctx *sctx,
 {
        struct btrfs_fs_info *fs_info = sctx->fs_info;
        struct btrfs_root *root = btrfs_extent_root(fs_info, logic_start);
-       struct btrfs_root *csum_root = fs_info->csum_root;
+       struct btrfs_root *csum_root;
        struct btrfs_extent_item *extent;
        struct btrfs_io_context *bioc = NULL;
        u64 flags;
@@ -3060,6 +3060,7 @@ again:
                        extent_dev = bioc->stripes[0].dev;
                        btrfs_put_bioc(bioc);
 
+                       csum_root = btrfs_csum_root(fs_info, extent_logical);
                        ret = btrfs_lookup_csums_range(csum_root,
                                                extent_logical,
                                                extent_logical + extent_len - 1,
@@ -3169,7 +3170,7 @@ static noinline_for_stack int scrub_stripe(struct scrub_ctx *sctx,
        struct btrfs_path *path, *ppath;
        struct btrfs_fs_info *fs_info = sctx->fs_info;
        struct btrfs_root *root;
-       struct btrfs_root *csum_root = fs_info->csum_root;
+       struct btrfs_root *csum_root;
        struct btrfs_extent_item *extent;
        struct blk_plug plug;
        u64 flags;
@@ -3273,6 +3274,8 @@ static noinline_for_stack int scrub_stripe(struct scrub_ctx *sctx,
        key_end.offset = (u64)-1;
        reada1 = btrfs_reada_add(root, &key, &key_end);
 
+       csum_root = btrfs_csum_root(fs_info, logical);
+
        if (cache->flags & BTRFS_BLOCK_GROUP_DATA) {
                key.objectid = BTRFS_EXTENT_CSUM_OBJECTID;
                key.type = BTRFS_EXTENT_CSUM_KEY;
index 9165486b554e0e1a5930cd7db2fce930e91935e3..7c4634ac511e866f249f3ca9f929a9603bb70c8c 100644 (file)
@@ -872,17 +872,21 @@ static noinline int replay_one_extent(struct btrfs_trans_handle *trans,
                         */
                        while (!list_empty(&ordered_sums)) {
                                struct btrfs_ordered_sum *sums;
+                               struct btrfs_root *csum_root;
+
                                sums = list_entry(ordered_sums.next,
                                                struct btrfs_ordered_sum,
                                                list);
+                               csum_root = btrfs_csum_root(fs_info,
+                                                           sums->bytenr);
                                if (!ret)
-                                       ret = btrfs_del_csums(trans,
-                                                             fs_info->csum_root,
+                                       ret = btrfs_del_csums(trans, csum_root,
                                                              sums->bytenr,
                                                              sums->len);
                                if (!ret)
                                        ret = btrfs_csum_file_blocks(trans,
-                                               fs_info->csum_root, sums);
+                                                                    csum_root,
+                                                                    sums);
                                list_del(&sums->list);
                                kfree(sums);
                        }
@@ -4340,6 +4344,7 @@ static noinline int copy_items(struct btrfs_trans_handle *trans,
 
                        found_type = btrfs_file_extent_type(src, extent);
                        if (found_type == BTRFS_FILE_EXTENT_REG) {
+                               struct btrfs_root *csum_root;
                                u64 ds, dl, cs, cl;
                                ds = btrfs_file_extent_disk_bytenr(src,
                                                                extent);
@@ -4358,8 +4363,8 @@ static noinline int copy_items(struct btrfs_trans_handle *trans,
                                        cl = dl;
                                }
 
-                               ret = btrfs_lookup_csums_range(
-                                               fs_info->csum_root,
+                               csum_root = btrfs_csum_root(fs_info, ds);
+                               ret = btrfs_lookup_csums_range(csum_root,
                                                ds + cs, ds + cs + cl - 1,
                                                &ordered_sums, 0);
                                if (ret)
@@ -4411,6 +4416,7 @@ static int log_extent_csums(struct btrfs_trans_handle *trans,
                            struct btrfs_log_ctx *ctx)
 {
        struct btrfs_ordered_extent *ordered;
+       struct btrfs_root *csum_root;
        u64 csum_offset;
        u64 csum_len;
        u64 mod_start = em->mod_start;
@@ -4491,7 +4497,8 @@ static int log_extent_csums(struct btrfs_trans_handle *trans,
        }
 
        /* block start is already adjusted for the file extent offset. */
-       ret = btrfs_lookup_csums_range(trans->fs_info->csum_root,
+       csum_root = btrfs_csum_root(trans->fs_info, em->block_start);
+       ret = btrfs_lookup_csums_range(csum_root,
                                       em->block_start + csum_offset,
                                       em->block_start + csum_offset +
                                       csum_len - 1, &ordered_sums, 0);