From: Tsutomu Itoh <t-itoh@jp.fujitsu.com>
To: Liu Bo <liubo2009@cn.fujitsu.com>
Cc: linux-btrfs@vger.kernel.org
Subject: Re: [PATCH 4/4] Btrfs: do not set subvolume flags in readonly mode
Date: Fri, 22 Jun 2012 08:57:50 +0900 [thread overview]
Message-ID: <4FE3B4FE.2040202@jp.fujitsu.com> (raw)
In-Reply-To: <1340279297-3964-4-git-send-email-liubo2009@cn.fujitsu.com>
(2012/06/21 20:48), Liu Bo wrote:
> $ mkfs.btrfs /dev/sdb7
> $ btrfstune -S1 /dev/sdb7
> $ mount /dev/sdb7 /mnt/btrfs
> mount: block device /dev/sdb7 is write-protected, mounting read-only
> $ btrfs dev add /dev/sdb8 /mnt/btrfs/
>
> Now we get a btrfs in which mnt flags has readonly but sb flags does
> not. So for those ioctls that only check sb flags with MS_RDONLY, it
> is going to be a problem.
> Setting subvolume flags is such an ioctl, we should use mnt_want_write_file()
> to check RO flags.
>
> Signed-off-by: Liu Bo <liubo2009@cn.fujitsu.com>
> ---
> fs/btrfs/ioctl.c | 27 ++++++++++++++++++---------
> 1 files changed, 18 insertions(+), 9 deletions(-)
>
> diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
> index df4c04d..ae29737 100644
> --- a/fs/btrfs/ioctl.c
> +++ b/fs/btrfs/ioctl.c
> @@ -1519,29 +1519,35 @@ static noinline int btrfs_ioctl_subvol_setflags(struct file *file,
> u64 flags;
> int ret = 0;
>
> - if (root->fs_info->sb->s_flags & MS_RDONLY)
> - return -EROFS;
> + ret = mnt_want_write_file(file);
> + if (ret)
> + goto out;
>
> + ret = -EINVAL;
> if (btrfs_ino(inode) != BTRFS_FIRST_FREE_OBJECTID)
> - return -EINVAL;
> + goto out_drop_write;
>
> + ret = -EFAULT;
> if (copy_from_user(&flags, arg, sizeof(flags)))
> - return -EFAULT;
> + goto out_drop_write;
>
> + ret = -EINVAL;
> if (flags & BTRFS_SUBVOL_CREATE_ASYNC)
> - return -EINVAL;
> + goto out_drop_write;
>
> + ret = -EOPNOTSUPP;
> if (flags & ~BTRFS_SUBVOL_RDONLY)
> - return -EOPNOTSUPP;
> + goto out_drop_write;
>
> + ret = -EACCES;
> if (!inode_owner_or_capable(inode))
> - return -EACCES;
> + goto out_drop_write;
I think that
if (!inode_owner_or_capable(inode)) {
ret = -EACCES;
goto out_drop_write;
}
is better than
ret = -EACCES;
if (!inode_owner_or_capable(inode))
goto out_drop_write;
Thanks,
Tsutomu
>
> down_write(&root->fs_info->subvol_sem);
>
> /* nothing to do */
> if (!!(flags & BTRFS_SUBVOL_RDONLY) == btrfs_root_readonly(root))
> - goto out;
> + goto out_drop_sem;
>
> root_flags = btrfs_root_flags(&root->root_item);
> if (flags & BTRFS_SUBVOL_RDONLY)
> @@ -1564,8 +1570,11 @@ static noinline int btrfs_ioctl_subvol_setflags(struct file *file,
> out_reset:
> if (ret)
> btrfs_set_root_flags(&root->root_item, root_flags);
> -out:
> +out_drop_sem:
> up_write(&root->fs_info->subvol_sem);
> +out_drop_write:
> + mnt_drop_write_file(file);
> +out:
> return ret;
> }
>
>
prev parent reply other threads:[~2012-06-21 23:58 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-06-21 11:48 [PATCH 1/4] Btrfs: check write access to mount earlier while creating snapshots Liu Bo
2012-06-21 11:48 ` [PATCH 2/4] Btrfs: remove redundant r/o check for superblock Liu Bo
2012-06-21 11:48 ` [PATCH 3/4] Btrfs: use mnt_want_write_file instead of mnt_want_write Liu Bo
2012-06-21 11:48 ` [PATCH 4/4] Btrfs: do not set subvolume flags in readonly mode Liu Bo
2012-06-21 23:57 ` Tsutomu Itoh [this message]
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=4FE3B4FE.2040202@jp.fujitsu.com \
--to=t-itoh@jp.fujitsu.com \
--cc=linux-btrfs@vger.kernel.org \
--cc=liubo2009@cn.fujitsu.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).