btrfs: move the subvolume reservation stuff out of extent-tree.c
authorJosef Bacik <josef@toxicpanda.com>
Wed, 19 Jun 2019 19:12:01 +0000 (15:12 -0400)
committerDavid Sterba <dsterba@suse.com>
Thu, 4 Jul 2019 15:26:18 +0000 (17:26 +0200)
This is just two functions, put it in root-tree.c since it involves root
items.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/extent-tree.c
fs/btrfs/root-tree.c

index 9870310a861b639592984fd1efc8cb7673930979..d3b58e388535e704d7f0c4c961c2f068f19d1856 100644 (file)
@@ -4105,60 +4105,6 @@ out:
        return ret;
 }
 
-/*
- * btrfs_subvolume_reserve_metadata() - reserve space for subvolume operation
- * root: the root of the parent directory
- * rsv: block reservation
- * items: the number of items that we need do reservation
- * use_global_rsv: allow fallback to the global block reservation
- *
- * This function is used to reserve the space for snapshot/subvolume
- * creation and deletion. Those operations are different with the
- * common file/directory operations, they change two fs/file trees
- * and root tree, the number of items that the qgroup reserves is
- * different with the free space reservation. So we can not use
- * the space reservation mechanism in start_transaction().
- */
-int btrfs_subvolume_reserve_metadata(struct btrfs_root *root,
-                                    struct btrfs_block_rsv *rsv, int items,
-                                    bool use_global_rsv)
-{
-       u64 qgroup_num_bytes = 0;
-       u64 num_bytes;
-       int ret;
-       struct btrfs_fs_info *fs_info = root->fs_info;
-       struct btrfs_block_rsv *global_rsv = &fs_info->global_block_rsv;
-
-       if (test_bit(BTRFS_FS_QUOTA_ENABLED, &fs_info->flags)) {
-               /* One for parent inode, two for dir entries */
-               qgroup_num_bytes = 3 * fs_info->nodesize;
-               ret = btrfs_qgroup_reserve_meta_prealloc(root,
-                               qgroup_num_bytes, true);
-               if (ret)
-                       return ret;
-       }
-
-       num_bytes = btrfs_calc_trans_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,
-                                 BTRFS_RESERVE_FLUSH_ALL);
-
-       if (ret == -ENOSPC && use_global_rsv)
-               ret = btrfs_block_rsv_migrate(global_rsv, rsv, num_bytes, true);
-
-       if (ret && qgroup_num_bytes)
-               btrfs_qgroup_free_meta_prealloc(root, qgroup_num_bytes);
-
-       return ret;
-}
-
-void btrfs_subvolume_release_metadata(struct btrfs_fs_info *fs_info,
-                                     struct btrfs_block_rsv *rsv)
-{
-       btrfs_block_rsv_release(fs_info, rsv, (u64)-1);
-}
-
 static int update_block_group(struct btrfs_trans_handle *trans,
                              u64 bytenr, u64 num_bytes, int alloc)
 {
index 22124122728cd856564d36f04331e65d043ce188..47733fb55df7f08da167777451ded39ba8eecff9 100644 (file)
@@ -9,6 +9,8 @@
 #include "transaction.h"
 #include "disk-io.h"
 #include "print-tree.h"
+#include "qgroup.h"
+#include "space-info.h"
 
 /*
  * Read a root item from the tree. In case we detect a root item smaller then
@@ -497,3 +499,57 @@ void btrfs_update_root_times(struct btrfs_trans_handle *trans,
        btrfs_set_stack_timespec_nsec(&item->ctime, ct.tv_nsec);
        spin_unlock(&root->root_item_lock);
 }
+
+/*
+ * btrfs_subvolume_reserve_metadata() - reserve space for subvolume operation
+ * root: the root of the parent directory
+ * rsv: block reservation
+ * items: the number of items that we need do reservation
+ * use_global_rsv: allow fallback to the global block reservation
+ *
+ * This function is used to reserve the space for snapshot/subvolume
+ * creation and deletion. Those operations are different with the
+ * common file/directory operations, they change two fs/file trees
+ * and root tree, the number of items that the qgroup reserves is
+ * different with the free space reservation. So we can not use
+ * the space reservation mechanism in start_transaction().
+ */
+int btrfs_subvolume_reserve_metadata(struct btrfs_root *root,
+                                    struct btrfs_block_rsv *rsv, int items,
+                                    bool use_global_rsv)
+{
+       u64 qgroup_num_bytes = 0;
+       u64 num_bytes;
+       int ret;
+       struct btrfs_fs_info *fs_info = root->fs_info;
+       struct btrfs_block_rsv *global_rsv = &fs_info->global_block_rsv;
+
+       if (test_bit(BTRFS_FS_QUOTA_ENABLED, &fs_info->flags)) {
+               /* One for parent inode, two for dir entries */
+               qgroup_num_bytes = 3 * fs_info->nodesize;
+               ret = btrfs_qgroup_reserve_meta_prealloc(root,
+                               qgroup_num_bytes, true);
+               if (ret)
+                       return ret;
+       }
+
+       num_bytes = btrfs_calc_trans_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,
+                                 BTRFS_RESERVE_FLUSH_ALL);
+
+       if (ret == -ENOSPC && use_global_rsv)
+               ret = btrfs_block_rsv_migrate(global_rsv, rsv, num_bytes, true);
+
+       if (ret && qgroup_num_bytes)
+               btrfs_qgroup_free_meta_prealloc(root, qgroup_num_bytes);
+
+       return ret;
+}
+
+void btrfs_subvolume_release_metadata(struct btrfs_fs_info *fs_info,
+                                     struct btrfs_block_rsv *rsv)
+{
+       btrfs_block_rsv_release(fs_info, rsv, (u64)-1);
+}