]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/commitdiff
btrfs: introduce btrfs_is_data_reloc_root
authorJohannes Thumshirn <johannes.thumshirn@wdc.com>
Thu, 18 Nov 2021 08:58:13 +0000 (17:58 +0900)
committerAndrea Righi <andrea.righi@canonical.com>
Tue, 7 Dec 2021 06:33:50 +0000 (07:33 +0100)
BugLink: https://bugs.launchpad.net/bugs/1951820
commit 37f00a6d2e9c97d6e7b5c3d47c49b714c3d0b99f upstream

There are several places in our codebase where we check if a root is the
root of the data reloc tree and subsequent patches will introduce more.

Factor out the check into a small helper function instead of open coding
it multiple times.

Reviewed-by: Naohiro Aota <naohiro.aota@wdc.com>
Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Paolo Pisati <paolo.pisati@canonical.com>
fs/btrfs/ctree.h
fs/btrfs/disk-io.c
fs/btrfs/extent-tree.c
fs/btrfs/inode.c
fs/btrfs/relocation.c

index c0cebcf745cefdbe94ac83f3605acc380ef18a5c..5b990881052c645ef60b26c8720fd1a711ea7b8b 100644 (file)
@@ -3842,6 +3842,11 @@ static inline bool btrfs_is_zoned(const struct btrfs_fs_info *fs_info)
        return fs_info->zoned != 0;
 }
 
+static inline bool btrfs_is_data_reloc_root(const struct btrfs_root *root)
+{
+       return root->root_key.objectid == BTRFS_DATA_RELOC_TREE_OBJECTID;
+}
+
 /*
  * We use page status Private2 to indicate there is an ordered extent with
  * unfinished IO.
index 6965ed081346281fdc950e985c7012d4dcd32408..f63d8a7e6daeecf6a3bbe3e9d9caa1e6e14f7fa9 100644 (file)
@@ -1500,7 +1500,7 @@ static int btrfs_init_fs_root(struct btrfs_root *root, dev_t anon_dev)
                goto fail;
 
        if (root->root_key.objectid != BTRFS_TREE_LOG_OBJECTID &&
-           root->root_key.objectid != BTRFS_DATA_RELOC_TREE_OBJECTID) {
+           !btrfs_is_data_reloc_root(root)) {
                set_bit(BTRFS_ROOT_SHAREABLE, &root->state);
                btrfs_check_and_init_root_item(&root->root_item);
        }
index 0ab456cb4bf801fc9f6f89623100ea182964b8f4..45e020c9fdc9b7f39efd7103fa459b4ffe98e048 100644 (file)
@@ -2376,7 +2376,7 @@ int btrfs_cross_ref_exist(struct btrfs_root *root, u64 objectid, u64 offset,
 
 out:
        btrfs_free_path(path);
-       if (root->root_key.objectid == BTRFS_DATA_RELOC_TREE_OBJECTID)
+       if (btrfs_is_data_reloc_root(root))
                WARN_ON(ret > 0);
        return ret;
 }
index 7c096ab9bb5eb259b53af05a2d681da26216c3e8..85663bccde8a8cbbdac15d805f6125ba6eb4cdfa 100644 (file)
@@ -1151,7 +1151,7 @@ static noinline int cow_file_range(struct btrfs_inode *inode,
         * fails during the stage where it updates the bytenr of file extent
         * items.
         */
-       if (root->root_key.objectid == BTRFS_DATA_RELOC_TREE_OBJECTID)
+       if (btrfs_is_data_reloc_root(root))
                min_alloc_size = num_bytes;
        else
                min_alloc_size = fs_info->sectorsize;
@@ -1187,8 +1187,7 @@ static noinline int cow_file_range(struct btrfs_inode *inode,
                if (ret)
                        goto out_drop_extent_cache;
 
-               if (root->root_key.objectid ==
-                   BTRFS_DATA_RELOC_TREE_OBJECTID) {
+               if (btrfs_is_data_reloc_root(root)) {
                        ret = btrfs_reloc_clone_csums(inode, start,
                                                      cur_alloc_size);
                        /*
@@ -1504,8 +1503,7 @@ static int fallback_to_cow(struct btrfs_inode *inode, struct page *locked_page,
                           int *page_started, unsigned long *nr_written)
 {
        const bool is_space_ino = btrfs_is_free_space_inode(inode);
-       const bool is_reloc_ino = (inode->root->root_key.objectid ==
-                                  BTRFS_DATA_RELOC_TREE_OBJECTID);
+       const bool is_reloc_ino = btrfs_is_data_reloc_root(inode->root);
        const u64 range_bytes = end + 1 - start;
        struct extent_io_tree *io_tree = &inode->io_tree;
        u64 range_start = start;
@@ -1867,8 +1865,7 @@ out_check:
                        btrfs_dec_nocow_writers(fs_info, disk_bytenr);
                nocow = false;
 
-               if (root->root_key.objectid ==
-                   BTRFS_DATA_RELOC_TREE_OBJECTID)
+               if (btrfs_is_data_reloc_root(root))
                        /*
                         * Error handled later, as we must prevent
                         * extent_clear_unlock_delalloc() in error handler
@@ -2207,7 +2204,7 @@ void btrfs_clear_delalloc_extent(struct inode *vfs_inode,
                if (btrfs_is_testing(fs_info))
                        return;
 
-               if (root->root_key.objectid != BTRFS_DATA_RELOC_TREE_OBJECTID &&
+               if (!btrfs_is_data_reloc_root(root) &&
                    do_list && !(state->state & EXTENT_NORESERVE) &&
                    (*bits & EXTENT_CLEAR_DATA_RESV))
                        btrfs_free_reserved_data_space_noquota(fs_info, len);
@@ -2532,7 +2529,7 @@ blk_status_t btrfs_submit_data_bio(struct inode *inode, struct bio *bio,
                goto mapit;
        } else if (async && !skip_sum) {
                /* csum items have already been cloned */
-               if (root->root_key.objectid == BTRFS_DATA_RELOC_TREE_OBJECTID)
+               if (btrfs_is_data_reloc_root(root))
                        goto mapit;
                /* we're doing a write, do the async checksumming */
                ret = btrfs_wq_submit_bio(inode, bio, mirror_num, bio_flags,
@@ -3304,7 +3301,7 @@ unsigned int btrfs_verify_data_csum(struct btrfs_io_bio *io_bio, u32 bio_offset,
                u64 file_offset = pg_off + page_offset(page);
                int ret;
 
-               if (root->root_key.objectid == BTRFS_DATA_RELOC_TREE_OBJECTID &&
+               if (btrfs_is_data_reloc_root(root) &&
                    test_range_bit(io_tree, file_offset,
                                   file_offset + sectorsize - 1,
                                   EXTENT_NODATASUM, 1, NULL)) {
@@ -4005,7 +4002,7 @@ noinline int btrfs_update_inode(struct btrfs_trans_handle *trans,
         * without delay
         */
        if (!btrfs_is_free_space_inode(inode)
-           && root->root_key.objectid != BTRFS_DATA_RELOC_TREE_OBJECTID
+           && !btrfs_is_data_reloc_root(root)
            && !test_bit(BTRFS_FS_LOG_RECOVERING, &fs_info->flags)) {
                btrfs_update_root_times(trans, root);
 
index 914d403b4415dd647d16a48fec47c6fc817c141e..2e4f109723afd2bb00c2f925a6fd5576cbae8f86 100644 (file)
@@ -4386,8 +4386,7 @@ int btrfs_reloc_cow_block(struct btrfs_trans_handle *trans,
        if (!rc)
                return 0;
 
-       BUG_ON(rc->stage == UPDATE_DATA_PTRS &&
-              root->root_key.objectid == BTRFS_DATA_RELOC_TREE_OBJECTID);
+       BUG_ON(rc->stage == UPDATE_DATA_PTRS && btrfs_is_data_reloc_root(root));
 
        level = btrfs_header_level(buf);
        if (btrfs_header_generation(buf) <=