btrfs: change root to fs_info for btrfs_reserve_metadata_bytes
authorJosef Bacik <josef@toxicpanda.com>
Tue, 9 Nov 2021 15:12:07 +0000 (10:12 -0500)
committerDavid Sterba <dsterba@suse.com>
Mon, 3 Jan 2022 14:09:45 +0000 (15:09 +0100)
We used to need the root for btrfs_reserve_metadata_bytes to check the
orphan cleanup state, but we no longer need that, we simply need the
fs_info.  Change btrfs_reserve_metadata_bytes() to use the fs_info, and
change both btrfs_block_rsv_refill() and btrfs_block_rsv_add() to do the
same as they simply call btrfs_reserve_metadata_bytes() and then
manipulate the block_rsv that is being used.

Reviewed-by: Nikolay Borisov <nborisov@suse.com>
Signed-off-by: Josef Bacik <josef@toxicpanda.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
13 files changed:
fs/btrfs/block-group.c
fs/btrfs/block-rsv.c
fs/btrfs/block-rsv.h
fs/btrfs/delalloc-space.c
fs/btrfs/delayed-inode.c
fs/btrfs/delayed-ref.c
fs/btrfs/inode.c
fs/btrfs/props.c
fs/btrfs/relocation.c
fs/btrfs/root-tree.c
fs/btrfs/space-info.c
fs/btrfs/space-info.h
fs/btrfs/transaction.c

index 6ab864655090dc72c112fa6712d495808ca2ff8b..d56fc1b8bb99bf366ddf03eb99fb9f1ae3eac2c2 100644 (file)
@@ -3790,7 +3790,7 @@ static void reserve_chunk_space(struct btrfs_trans_handle *trans,
        }
 
        if (!ret) {
-               ret = btrfs_block_rsv_add(fs_info->chunk_root,
+               ret = btrfs_block_rsv_add(fs_info,
                                          &fs_info->chunk_block_rsv,
                                          bytes, BTRFS_RESERVE_NO_FLUSH);
                if (!ret)
index 04a6226e0388860024a1bf2f751e727bf68b6616..9d162b5adfd817e290bcbb4cf5289012111c2817 100644 (file)
@@ -208,7 +208,7 @@ void btrfs_free_block_rsv(struct btrfs_fs_info *fs_info,
        kfree(rsv);
 }
 
-int btrfs_block_rsv_add(struct btrfs_root *root,
+int btrfs_block_rsv_add(struct btrfs_fs_info *fs_info,
                        struct btrfs_block_rsv *block_rsv, u64 num_bytes,
                        enum btrfs_reserve_flush_enum flush)
 {
@@ -217,7 +217,7 @@ int btrfs_block_rsv_add(struct btrfs_root *root,
        if (num_bytes == 0)
                return 0;
 
-       ret = btrfs_reserve_metadata_bytes(root, block_rsv, num_bytes, flush);
+       ret = btrfs_reserve_metadata_bytes(fs_info, block_rsv, num_bytes, flush);
        if (!ret)
                btrfs_block_rsv_add_bytes(block_rsv, num_bytes, true);
 
@@ -241,7 +241,7 @@ int btrfs_block_rsv_check(struct btrfs_block_rsv *block_rsv, int min_factor)
        return ret;
 }
 
-int btrfs_block_rsv_refill(struct btrfs_root *root,
+int btrfs_block_rsv_refill(struct btrfs_fs_info *fs_info,
                           struct btrfs_block_rsv *block_rsv, u64 min_reserved,
                           enum btrfs_reserve_flush_enum flush)
 {
@@ -262,7 +262,7 @@ int btrfs_block_rsv_refill(struct btrfs_root *root,
        if (!ret)
                return 0;
 
-       ret = btrfs_reserve_metadata_bytes(root, block_rsv, num_bytes, flush);
+       ret = btrfs_reserve_metadata_bytes(fs_info, block_rsv, num_bytes, flush);
        if (!ret) {
                btrfs_block_rsv_add_bytes(block_rsv, num_bytes, false);
                return 0;
@@ -523,7 +523,7 @@ again:
                                block_rsv->type, ret);
        }
 try_reserve:
-       ret = btrfs_reserve_metadata_bytes(root, block_rsv, blocksize,
+       ret = btrfs_reserve_metadata_bytes(fs_info, block_rsv, blocksize,
                                           BTRFS_RESERVE_NO_FLUSH);
        if (!ret)
                return block_rsv;
index 0b6ae5302837c07977a4286985dea4ff80a7c072..07d61c2c5d28cd4bd0ab00ae101b74764909631c 100644 (file)
@@ -57,11 +57,11 @@ void btrfs_init_metadata_block_rsv(struct btrfs_fs_info *fs_info,
                                   unsigned short type);
 void btrfs_free_block_rsv(struct btrfs_fs_info *fs_info,
                          struct btrfs_block_rsv *rsv);
-int btrfs_block_rsv_add(struct btrfs_root *root,
+int btrfs_block_rsv_add(struct btrfs_fs_info *fs_info,
                        struct btrfs_block_rsv *block_rsv, u64 num_bytes,
                        enum btrfs_reserve_flush_enum flush);
 int btrfs_block_rsv_check(struct btrfs_block_rsv *block_rsv, int min_factor);
-int btrfs_block_rsv_refill(struct btrfs_root *root,
+int btrfs_block_rsv_refill(struct btrfs_fs_info *fs_info,
                           struct btrfs_block_rsv *block_rsv, u64 min_reserved,
                           enum btrfs_reserve_flush_enum flush);
 int btrfs_block_rsv_migrate(struct btrfs_block_rsv *src_rsv,
index 40c4d6ba3fb9a79d639f5b8d8de2cb018c8904be..fb46a28f50659f431d2b325d6548b411795ff30c 100644 (file)
@@ -334,7 +334,7 @@ int btrfs_delalloc_reserve_metadata(struct btrfs_inode *inode, u64 num_bytes)
        ret = btrfs_qgroup_reserve_meta_prealloc(root, qgroup_reserve, true);
        if (ret)
                return ret;
-       ret = btrfs_reserve_metadata_bytes(root, block_rsv, meta_reserve, flush);
+       ret = btrfs_reserve_metadata_bytes(fs_info, block_rsv, meta_reserve, flush);
        if (ret) {
                btrfs_qgroup_free_meta_prealloc(root, qgroup_reserve);
                return ret;
index e164766dcc3844a2f27901d6c954f72c894677c0..6f134f2c5e68424c19c649e47748294b86267144 100644 (file)
@@ -629,7 +629,7 @@ static int btrfs_delayed_inode_reserve_metadata(
                                          BTRFS_QGROUP_RSV_META_PREALLOC, true);
                if (ret < 0)
                        return ret;
-               ret = btrfs_block_rsv_add(root, dst_rsv, num_bytes,
+               ret = btrfs_block_rsv_add(fs_info, dst_rsv, num_bytes,
                                          BTRFS_RESERVE_NO_FLUSH);
                /* NO_FLUSH could only fail with -ENOSPC */
                ASSERT(ret == 0 || ret == -ENOSPC);
index cca7e85e32dd6aae06a890c3c86f7a765ead33a4..da9d20813147d0beea52d71cfa6fbe476ef8acfe 100644 (file)
@@ -191,8 +191,7 @@ int btrfs_delayed_refs_rsv_refill(struct btrfs_fs_info *fs_info,
        if (!num_bytes)
                return 0;
 
-       ret = btrfs_reserve_metadata_bytes(fs_info->extent_root, block_rsv,
-                                          num_bytes, flush);
+       ret = btrfs_reserve_metadata_bytes(fs_info, block_rsv, num_bytes, flush);
        if (ret)
                return ret;
        btrfs_block_rsv_add_bytes(block_rsv, num_bytes, 0);
index b4ef478e0de3e2029123defe90aa825dc2e012d7..91f7ed27e421755004cfabe680b2d9df1e7afb54 100644 (file)
@@ -5539,10 +5539,10 @@ static struct btrfs_trans_handle *evict_refill_and_join(struct btrfs_root *root,
         * if we fail to make this reservation we can re-try without the
         * delayed_refs_extra so we can make some forward progress.
         */
-       ret = btrfs_block_rsv_refill(root, rsv, rsv->size + delayed_refs_extra,
+       ret = btrfs_block_rsv_refill(fs_info, rsv, rsv->size + delayed_refs_extra,
                                     BTRFS_RESERVE_FLUSH_EVICT);
        if (ret) {
-               ret = btrfs_block_rsv_refill(root, rsv, rsv->size,
+               ret = btrfs_block_rsv_refill(fs_info, rsv, rsv->size,
                                             BTRFS_RESERVE_FLUSH_EVICT);
                if (ret) {
                        btrfs_warn(fs_info,
index a978676aa62794bbc5874261dde3deae3b23582b..1a6d2d5b4b3332d615adbe35eaa6393e66050268 100644 (file)
@@ -377,8 +377,9 @@ static int inherit_props(struct btrfs_trans_handle *trans,
                 */
                if (need_reserve) {
                        num_bytes = btrfs_calc_insert_metadata_size(fs_info, 1);
-                       ret = btrfs_block_rsv_add(root, trans->block_rsv,
-                                       num_bytes, BTRFS_RESERVE_NO_FLUSH);
+                       ret = btrfs_block_rsv_add(fs_info, trans->block_rsv,
+                                                 num_bytes,
+                                                 BTRFS_RESERVE_NO_FLUSH);
                        if (ret)
                                return ret;
                }
index ee0a0efc7efdfb58c2e82c2d91a163e99ff33315..a455a1ead0d6dd6adcd4abe31ba61a416c205290 100644 (file)
@@ -1736,7 +1736,8 @@ static noinline_for_stack int merge_reloc_root(struct reloc_control *rc,
        memset(&next_key, 0, sizeof(next_key));
 
        while (1) {
-               ret = btrfs_block_rsv_refill(root, rc->block_rsv, min_reserved,
+               ret = btrfs_block_rsv_refill(fs_info, rc->block_rsv,
+                                            min_reserved,
                                             BTRFS_RESERVE_FLUSH_LIMIT);
                if (ret)
                        goto out;
@@ -1855,7 +1856,7 @@ int prepare_to_merge(struct reloc_control *rc, int err)
 again:
        if (!err) {
                num_bytes = rc->merging_rsv_size;
-               ret = btrfs_block_rsv_add(root, rc->block_rsv, num_bytes,
+               ret = btrfs_block_rsv_add(fs_info, rc->block_rsv, num_bytes,
                                          BTRFS_RESERVE_FLUSH_ALL);
                if (ret)
                        err = ret;
@@ -2323,8 +2324,8 @@ static int reserve_metadata_space(struct btrfs_trans_handle *trans,
         * If we get an enospc just kick back -EAGAIN so we know to drop the
         * transaction and try to refill when we can flush all the things.
         */
-       ret = btrfs_block_rsv_refill(root, rc->block_rsv, num_bytes,
-                               BTRFS_RESERVE_FLUSH_LIMIT);
+       ret = btrfs_block_rsv_refill(fs_info, rc->block_rsv, num_bytes,
+                                    BTRFS_RESERVE_FLUSH_LIMIT);
        if (ret) {
                tmp = fs_info->nodesize * RELOCATION_RESERVED_NODES;
                while (tmp <= rc->reserved_bytes)
@@ -3550,7 +3551,7 @@ int prepare_to_relocate(struct reloc_control *rc)
        rc->reserved_bytes = 0;
        rc->block_rsv->size = rc->extent_root->fs_info->nodesize *
                              RELOCATION_RESERVED_NODES;
-       ret = btrfs_block_rsv_refill(rc->extent_root,
+       ret = btrfs_block_rsv_refill(rc->extent_root->fs_info,
                                     rc->block_rsv, rc->block_rsv->size,
                                     BTRFS_RESERVE_FLUSH_ALL);
        if (ret)
@@ -3598,9 +3599,9 @@ static noinline_for_stack int relocate_block_group(struct reloc_control *rc)
 
        while (1) {
                rc->reserved_bytes = 0;
-               ret = btrfs_block_rsv_refill(rc->extent_root,
-                                       rc->block_rsv, rc->block_rsv->size,
-                                       BTRFS_RESERVE_FLUSH_ALL);
+               ret = btrfs_block_rsv_refill(fs_info, rc->block_rsv,
+                                            rc->block_rsv->size,
+                                            BTRFS_RESERVE_FLUSH_ALL);
                if (ret) {
                        err = ret;
                        break;
index 3297368aa359598b25e51ff661a3e97db40f1025..3d68d2dcd83e3e10f2696892b9c3ea819a53a8a3 100644 (file)
@@ -502,7 +502,7 @@ int btrfs_subvolume_reserve_metadata(struct btrfs_root *root,
        num_bytes = btrfs_calc_insert_metadata_size(fs_info, items);
        rsv->space_info = btrfs_find_space_info(fs_info,
                                            BTRFS_BLOCK_GROUP_METADATA);
-       ret = btrfs_block_rsv_add(root, rsv, num_bytes,
+       ret = btrfs_block_rsv_add(fs_info, rsv, num_bytes,
                                  BTRFS_RESERVE_FLUSH_ALL);
 
        if (ret == -ENOSPC && use_global_rsv)
index d277c7111b95439db50d2fb9ed17e6977b7e4c5b..dc4b4b0372d12ed60c042b986027ae76eabd16f6 100644 (file)
@@ -1600,12 +1600,11 @@ static int __reserve_bytes(struct btrfs_fs_info *fs_info,
  * regain reservations will be made and this will fail if there is not enough
  * space already.
  */
-int btrfs_reserve_metadata_bytes(struct btrfs_root *root,
+int btrfs_reserve_metadata_bytes(struct btrfs_fs_info *fs_info,
                                 struct btrfs_block_rsv *block_rsv,
                                 u64 orig_bytes,
                                 enum btrfs_reserve_flush_enum flush)
 {
-       struct btrfs_fs_info *fs_info = root->fs_info;
        int ret;
 
        ret = __reserve_bytes(fs_info, block_rsv->space_info, orig_bytes, flush);
index cb5056472e798dc590f7c8c3e3f0e2b78100548a..d841fed7349237b1a60bed327401944310a3e3a0 100644 (file)
@@ -123,7 +123,7 @@ void btrfs_clear_space_info_full(struct btrfs_fs_info *info);
 void btrfs_dump_space_info(struct btrfs_fs_info *fs_info,
                           struct btrfs_space_info *info, u64 bytes,
                           int dump_block_groups);
-int btrfs_reserve_metadata_bytes(struct btrfs_root *root,
+int btrfs_reserve_metadata_bytes(struct btrfs_fs_info *fs_info,
                                 struct btrfs_block_rsv *block_rsv,
                                 u64 orig_bytes,
                                 enum btrfs_reserve_flush_enum flush);
index eb1c916d48848be68c409dad06865472bdf3fcd6..8b6a90fafcd41b2d27d4c1b4f927fe44b3d49fb4 100644 (file)
@@ -634,7 +634,7 @@ start_transaction(struct btrfs_root *root, unsigned int num_items,
                        reloc_reserved = true;
                }
 
-               ret = btrfs_block_rsv_add(root, rsv, num_bytes, flush);
+               ret = btrfs_block_rsv_add(fs_info, rsv, num_bytes, flush);
                if (ret)
                        goto reserve_fail;
                if (delayed_refs_bytes) {
@@ -1597,7 +1597,7 @@ static noinline int create_pending_snapshot(struct btrfs_trans_handle *trans,
        btrfs_reloc_pre_snapshot(pending, &to_reserve);
 
        if (to_reserve > 0) {
-               pending->error = btrfs_block_rsv_add(root,
+               pending->error = btrfs_block_rsv_add(fs_info,
                                                     &pending->block_rsv,
                                                     to_reserve,
                                                     BTRFS_RESERVE_NO_FLUSH);