btrfs: Move may_destroy_subvol() from ioctl.c to inode.c
authorMisono Tomohiro <misono.tomohiro@jp.fujitsu.com>
Wed, 18 Apr 2018 02:34:13 +0000 (11:34 +0900)
committerDavid Sterba <dsterba@suse.com>
Mon, 28 May 2018 16:07:18 +0000 (18:07 +0200)
This is a preparation work to refactor btrfs_ioctl_snap_destroy()
and to allow rmdir(2) to delete an empty subvolume.

Signed-off-by: Tomohiro Misono <misono.tomohiro@jp.fujitsu.com>
Reviewed-by: David Sterba <dsterba@suse.com>
[ minor update of the function comment ]
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/ctree.h
fs/btrfs/inode.c
fs/btrfs/ioctl.c

index 15e3417..fe7e517 100644 (file)
@@ -3197,6 +3197,7 @@ int btrfs_unlink_subvol(struct btrfs_trans_handle *trans,
                        struct btrfs_root *root,
                        struct inode *dir, u64 objectid,
                        const char *name, int name_len);
+noinline int may_destroy_subvol(struct btrfs_root *root);
 int btrfs_truncate_block(struct inode *inode, loff_t from, loff_t len,
                        int front);
 int btrfs_truncate_inode_items(struct btrfs_trans_handle *trans,
index f444798..1e51ca4 100644 (file)
@@ -4326,6 +4326,61 @@ out:
        return ret;
 }
 
+/*
+ * Helper to check if the subvolume references other subvolumes or if it's
+ * default.
+ */
+noinline int may_destroy_subvol(struct btrfs_root *root)
+{
+       struct btrfs_fs_info *fs_info = root->fs_info;
+       struct btrfs_path *path;
+       struct btrfs_dir_item *di;
+       struct btrfs_key key;
+       u64 dir_id;
+       int ret;
+
+       path = btrfs_alloc_path();
+       if (!path)
+               return -ENOMEM;
+
+       /* Make sure this root isn't set as the default subvol */
+       dir_id = btrfs_super_root_dir(fs_info->super_copy);
+       di = btrfs_lookup_dir_item(NULL, fs_info->tree_root, path,
+                                  dir_id, "default", 7, 0);
+       if (di && !IS_ERR(di)) {
+               btrfs_dir_item_key_to_cpu(path->nodes[0], di, &key);
+               if (key.objectid == root->root_key.objectid) {
+                       ret = -EPERM;
+                       btrfs_err(fs_info,
+                                 "deleting default subvolume %llu is not allowed",
+                                 key.objectid);
+                       goto out;
+               }
+               btrfs_release_path(path);
+       }
+
+       key.objectid = root->root_key.objectid;
+       key.type = BTRFS_ROOT_REF_KEY;
+       key.offset = (u64)-1;
+
+       ret = btrfs_search_slot(NULL, fs_info->tree_root, &key, path, 0, 0);
+       if (ret < 0)
+               goto out;
+       BUG_ON(ret == 0);
+
+       ret = 0;
+       if (path->slots[0] > 0) {
+               path->slots[0]--;
+               btrfs_item_key_to_cpu(path->nodes[0], &key, path->slots[0]);
+               if (key.objectid == root->root_key.objectid &&
+                   key.type == BTRFS_ROOT_REF_KEY)
+                       ret = -ENOTEMPTY;
+       }
+out:
+       btrfs_free_path(path);
+       return ret;
+}
+
 static int btrfs_rmdir(struct inode *dir, struct dentry *dentry)
 {
        struct inode *inode = d_inode(dentry);
index 61a5821..592ef10 100644 (file)
@@ -1832,60 +1832,6 @@ out:
        return ret;
 }
 
-/*
- * helper to check if the subvolume references other subvolumes
- */
-static noinline int may_destroy_subvol(struct btrfs_root *root)
-{
-       struct btrfs_fs_info *fs_info = root->fs_info;
-       struct btrfs_path *path;
-       struct btrfs_dir_item *di;
-       struct btrfs_key key;
-       u64 dir_id;
-       int ret;
-
-       path = btrfs_alloc_path();
-       if (!path)
-               return -ENOMEM;
-
-       /* Make sure this root isn't set as the default subvol */
-       dir_id = btrfs_super_root_dir(fs_info->super_copy);
-       di = btrfs_lookup_dir_item(NULL, fs_info->tree_root, path,
-                                  dir_id, "default", 7, 0);
-       if (di && !IS_ERR(di)) {
-               btrfs_dir_item_key_to_cpu(path->nodes[0], di, &key);
-               if (key.objectid == root->root_key.objectid) {
-                       ret = -EPERM;
-                       btrfs_err(fs_info,
-                                 "deleting default subvolume %llu is not allowed",
-                                 key.objectid);
-                       goto out;
-               }
-               btrfs_release_path(path);
-       }
-
-       key.objectid = root->root_key.objectid;
-       key.type = BTRFS_ROOT_REF_KEY;
-       key.offset = (u64)-1;
-
-       ret = btrfs_search_slot(NULL, fs_info->tree_root, &key, path, 0, 0);
-       if (ret < 0)
-               goto out;
-       BUG_ON(ret == 0);
-
-       ret = 0;
-       if (path->slots[0] > 0) {
-               path->slots[0]--;
-               btrfs_item_key_to_cpu(path->nodes[0], &key, path->slots[0]);
-               if (key.objectid == root->root_key.objectid &&
-                   key.type == BTRFS_ROOT_REF_KEY)
-                       ret = -ENOTEMPTY;
-       }
-out:
-       btrfs_free_path(path);
-       return ret;
-}
-
 static noinline int key_in_sk(struct btrfs_key *key,
                              struct btrfs_ioctl_search_key *sk)
 {