linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Qu Wenruo <quwenruo@cn.fujitsu.com>
To: Omar Sandoval <osandov@osandov.com>, Chris Mason <clm@fb.com>,
	Josef Bacik <jbacik@fb.com>, David Sterba <dsterba@suse.cz>,
	<linux-btrfs@vger.kernel.org>
Cc: <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v2 4/6] Btrfs: fail on mismatched subvol and subvolid mount options
Date: Fri, 10 Apr 2015 08:39:53 +0800	[thread overview]
Message-ID: <55271BD9.7020903@cn.fujitsu.com> (raw)
In-Reply-To: <40c40f7f26acb30eea471b8c7b7bc01cce74be4d.1428614837.git.osandov@osandov.com>



-------- Original Message  --------
Subject: [PATCH v2 4/6] Btrfs: fail on mismatched subvol and subvolid 
mount options
From: Omar Sandoval <osandov@osandov.com>
To: Chris Mason <clm@fb.com>, Josef Bacik <jbacik@fb.com>, David Sterba 
<dsterba@suse.cz>, <linux-btrfs@vger.kernel.org>
Date: 2015年04月10日 05:34

> There's nothing to stop a user from passing both subvol= and subvolid=
> to mount, but if they don't refer to the same subvolume, someone is
> going to be surprised at some point. Error out on this case, but allow
> users to pass in both if they do match (which they could, for example,
> get out of /proc/mounts).
Not sure should we do this extra check, as later mount options override 
previous mount option.

I previous tried to do such thing for mount option like inode/noinode, 
but was rejected for that reason.

So not sure such error-out behavior is OK or not.
Maybe only taking the latest subvol/subvolid is a better choice?

Thanks,
Qu
>
> Signed-off-by: Omar Sandoval <osandov@osandov.com>
> ---
>   fs/btrfs/super.c | 32 ++++++++++++++++++++++++--------
>   1 file changed, 24 insertions(+), 8 deletions(-)
>
> diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
> index ab100e5..20b470d 100644
> --- a/fs/btrfs/super.c
> +++ b/fs/btrfs/super.c
> @@ -1163,8 +1163,9 @@ static char *setup_root_args(char *args)
>   	return buf;
>   }
>
> -static struct dentry *mount_subvol(const char *subvol_name, int flags,
> -				   const char *device_name, char *data)
> +static struct dentry *mount_subvol(const char *subvol_name, u64 subvol_objectid,
> +				   int flags, const char *device_name,
> +				   char *data)
>   {
>   	struct dentry *root;
>   	struct vfsmount *mnt = NULL;
> @@ -1210,12 +1211,26 @@ static struct dentry *mount_subvol(const char *subvol_name, int flags,
>   	/* mount_subtree() drops our reference on the vfsmount. */
>   	mnt = NULL;
>
> -	if (!IS_ERR(root) && !is_subvolume_inode(root->d_inode)) {
> +	if (!IS_ERR(root)) {
>   		struct super_block *s = root->d_sb;
> -		dput(root);
> -		root = ERR_PTR(-EINVAL);
> -		deactivate_locked_super(s);
> -		pr_err("BTRFS: '%s' is not a valid subvolume\n", subvol_name);
> +		u64 root_objectid = BTRFS_I(root->d_inode)->root->root_key.objectid;
> +
> +		ret = 0;
> +		if (!is_subvolume_inode(root->d_inode)) {
> +			pr_err("BTRFS: '%s' is not a valid subvolume\n",
> +			       subvol_name);
> +			ret = -EINVAL;
> +		}
> +		if (subvol_objectid && root_objectid != subvol_objectid) {
> +			pr_err("BTRFS: subvol '%s' does not match subvolid %llu\n",
> +			       subvol_name, subvol_objectid);
> +			ret = -EINVAL;
> +		}
> +		if (ret) {
> +			dput(root);
> +			root = ERR_PTR(ret);
> +			deactivate_locked_super(s);
> +		}
>   	}
>
>   out:
> @@ -1308,7 +1323,8 @@ static struct dentry *btrfs_mount(struct file_system_type *fs_type, int flags,
>
>   	if (subvol_name) {
>   		/* mount_subvol() will free subvol_name. */
> -		return mount_subvol(subvol_name, flags, device_name, data);
> +		return mount_subvol(subvol_name, subvol_objectid, flags,
> +				    device_name, data);
>   	}
>
>   	security_init_mnt_opts(&new_sec_opts);
>

  reply	other threads:[~2015-04-10  0:39 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-09 21:34 [PATCH v2 0/6] Btrfs: show subvolume name and ID in /proc/mounts Omar Sandoval
2015-04-09 21:34 ` [PATCH v2 1/6] Btrfs: lock superblock before remounting for rw subvol Omar Sandoval
2015-05-11 16:07   ` David Sterba
2015-04-09 21:34 ` [PATCH v2 2/6] Btrfs: remove all subvol options before mounting top-level Omar Sandoval
2015-05-11 16:08   ` David Sterba
2015-04-09 21:34 ` [PATCH v2 3/6] Btrfs: clean up error handling in mount_subvol() Omar Sandoval
2015-05-11 16:08   ` David Sterba
2015-04-09 21:34 ` [PATCH v2 4/6] Btrfs: fail on mismatched subvol and subvolid mount options Omar Sandoval
2015-04-10  0:39   ` Qu Wenruo [this message]
2015-04-14 15:07     ` David Sterba
2015-05-11 16:09   ` David Sterba
2015-04-09 21:34 ` [PATCH v2 5/6] Btrfs: unify subvol= and subvolid= mounting Omar Sandoval
2015-05-11 15:37   ` David Sterba
2015-05-11 21:15     ` Omar Sandoval
2015-05-11 16:10   ` David Sterba
2015-04-09 21:34 ` [PATCH v2 6/6] Btrfs: show subvol= and subvolid= in /proc/mounts Omar Sandoval
2015-05-11 16:10   ` David Sterba
2015-05-11  9:42 ` [PATCH v2 0/6] Btrfs: show subvolume name and ID " Omar Sandoval
2015-05-11 14:51   ` David Sterba
2015-05-11 21:20     ` Omar Sandoval
2015-05-12  0:46   ` Qu Wenruo

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=55271BD9.7020903@cn.fujitsu.com \
    --to=quwenruo@cn.fujitsu.com \
    --cc=clm@fb.com \
    --cc=dsterba@suse.cz \
    --cc=jbacik@fb.com \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=osandov@osandov.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;
as well as URLs for NNTP newsgroup(s).