From: Marcos Paulo de Souza <marcos.souza.org@gmail.com>
To: linux-kernel@vger.kernel.org
Cc: dsterba@suse.com, linux-btrfs@vger.kernel.org,
Marcos Paulo de Souza <mpdesouza@suse.com>,
wqu@suse.com, Chris Mason <clm@fb.com>,
Josef Bacik <josef@toxicpanda.com>
Subject: [PATCH 1/2] btrfs: ioctl: Move the subvolume deleter code into a new function
Date: Sat, 11 Jan 2020 01:39:41 -0300 [thread overview]
Message-ID: <20200111043942.15366-2-marcos.souza.org@gmail.com> (raw)
In-Reply-To: <20200111043942.15366-1-marcos.souza.org@gmail.com>
From: Marcos Paulo de Souza <mpdesouza@suse.com>
This new function will be used by the next patch.
Signed-off-by: Marcos Paulo de Souza <mpdesouza@suse.com>
---
fs/btrfs/ioctl.c | 66 ++++++++++++++++++++++++++++--------------------
1 file changed, 39 insertions(+), 27 deletions(-)
diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
index 0fa1c386d020..dcceae4c5d28 100644
--- a/fs/btrfs/ioctl.c
+++ b/fs/btrfs/ioctl.c
@@ -2835,44 +2835,27 @@ static int btrfs_ioctl_get_subvol_rootref(struct file *file, void __user *argp)
return ret;
}
-static noinline int btrfs_ioctl_snap_destroy(struct file *file,
- void __user *arg)
+static noinline int btrfs_subvolume_deleter(struct file *file,
+ struct dentry *parent, const char *subvol_name,
+ size_t namelen)
{
- struct dentry *parent = file->f_path.dentry;
- struct btrfs_fs_info *fs_info = btrfs_sb(parent->d_sb);
struct dentry *dentry;
- struct inode *dir = d_inode(parent);
+ struct btrfs_root *dest;
struct inode *inode;
+ struct inode *dir = d_inode(parent);
struct btrfs_root *root = BTRFS_I(dir)->root;
- struct btrfs_root *dest = NULL;
- struct btrfs_ioctl_vol_args *vol_args;
- int namelen;
+ struct btrfs_fs_info *fs_info = root->fs_info;
int err = 0;
- if (!S_ISDIR(dir->i_mode))
- return -ENOTDIR;
-
- vol_args = memdup_user(arg, sizeof(*vol_args));
- if (IS_ERR(vol_args))
- return PTR_ERR(vol_args);
-
- vol_args->name[BTRFS_PATH_NAME_MAX] = '\0';
- namelen = strlen(vol_args->name);
- if (strchr(vol_args->name, '/') ||
- strncmp(vol_args->name, "..", namelen) == 0) {
- err = -EINVAL;
- goto out;
- }
-
err = mnt_want_write_file(file);
if (err)
- goto out;
-
+ return err;
err = down_write_killable_nested(&dir->i_rwsem, I_MUTEX_PARENT);
if (err == -EINTR)
goto out_drop_write;
- dentry = lookup_one_len(vol_args->name, parent, namelen);
+
+ dentry = lookup_one_len(subvol_name, parent, namelen);
if (IS_ERR(dentry)) {
err = PTR_ERR(dentry);
goto out_unlock_dir;
@@ -2880,7 +2863,7 @@ static noinline int btrfs_ioctl_snap_destroy(struct file *file,
if (d_really_is_negative(dentry)) {
err = -ENOENT;
- goto out_dput;
+ goto out_unlock_dir;
}
inode = d_inode(dentry);
@@ -2943,6 +2926,35 @@ static noinline int btrfs_ioctl_snap_destroy(struct file *file,
inode_unlock(dir);
out_drop_write:
mnt_drop_write_file(file);
+
+ return err;
+}
+
+static noinline int btrfs_ioctl_snap_destroy(struct file *file,
+ void __user *arg)
+{
+ struct dentry *parent = file->f_path.dentry;
+ struct inode *dir = d_inode(parent);
+ struct btrfs_ioctl_vol_args *vol_args;
+ int namelen;
+ int err = 0;
+
+ if (!S_ISDIR(dir->i_mode))
+ return -ENOTDIR;
+
+ vol_args = memdup_user(arg, sizeof(*vol_args));
+ if (IS_ERR(vol_args))
+ return PTR_ERR(vol_args);
+
+ vol_args->name[BTRFS_PATH_NAME_MAX] = '\0';
+ namelen = strlen(vol_args->name);
+ if (strchr(vol_args->name, '/') ||
+ strncmp(vol_args->name, "..", namelen) == 0) {
+ err = -EINVAL;
+ goto out;
+ }
+
+ err = btrfs_subvolume_deleter(file, parent, vol_args->name, namelen);
out:
kfree(vol_args);
return err;
--
2.24.0
next prev parent reply other threads:[~2020-01-11 4:42 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-01-11 4:39 [PATCH 0/2] fs: btrfs: Introduce deleting subvolume by subvolid Marcos Paulo de Souza
2020-01-11 4:39 ` Marcos Paulo de Souza [this message]
2020-01-11 4:39 ` [PATCH 2/2] btrfs: Introduce new BTRFS_IOC_SNAP_DESTROY_V2 ioctl Marcos Paulo de Souza
2020-01-13 17:37 ` Josef Bacik
2020-01-14 2:31 ` Marcos Paulo de Souza
2020-01-14 2:40 ` Josef Bacik
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200111043942.15366-2-marcos.souza.org@gmail.com \
--to=marcos.souza.org@gmail.com \
--cc=clm@fb.com \
--cc=dsterba@suse.com \
--cc=josef@toxicpanda.com \
--cc=linux-btrfs@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mpdesouza@suse.com \
--cc=wqu@suse.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®