From: Miao Xie <miaoxie@huawei.com>
To: Qu Wenruo <quwenruo@cn.fujitsu.com>, <linux-btrfs@vger.kernel.org>
Cc: linux-fsdevel <linux-fsdevel@vger.kernel.org>
Subject: Re: [PATCH RESEND v4 6/8] vfs: Add get_vfsmount_sb() function to get vfsmount from a given sb.
Date: Fri, 30 Jan 2015 08:52:44 +0800 [thread overview]
Message-ID: <54CAD5DC.2060603@huawei.com> (raw)
In-Reply-To: <1422498281-20493-7-git-send-email-quwenruo@cn.fujitsu.com>
On Thu, 29 Jan 2015 10:24:39 +0800, Qu Wenruo wrote:
> There are sysfs interfaces in some fs, only btrfs yet, which will modify
> on-disk data.
> Unlike normal file operation routine we can use mnt_want_write_file() to
> protect the operation, change through sysfs won't to be binded to any file
> in the filesystem.
> So we can only extract the first vfsmount of a superblock and pass it to
> mnt_want_write() to do the protection.
This method is wrong, becasue one fs may be mounted on the multi places
at the same time, someone is R/O, someone is R/W, you may get a R/O and
fail to get the write permission.
I think you do label/feature change by sysfs interface by the following way
btrfs_sysfs_change_XXXX()
{
/* Use trylock to avoid the race with umount */
if(!mutex_trylock(&sb->s_umount))
return -EBUSY;
check R/O and FREEZE
mutex_unlock(&sb->s_umount);
}
Thanks
Miao
>
> Cc: linux-fsdevel <linux-fsdevel@vger.kernel.org>
> Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
> ---
> fs/namespace.c | 25 +++++++++++++++++++++++++
> include/linux/mount.h | 1 +
> 2 files changed, 26 insertions(+)
>
> diff --git a/fs/namespace.c b/fs/namespace.c
> index cd1e968..5a16a62 100644
> --- a/fs/namespace.c
> +++ b/fs/namespace.c
> @@ -1105,6 +1105,31 @@ struct vfsmount *mntget(struct vfsmount *mnt)
> }
> EXPORT_SYMBOL(mntget);
>
> +/*
> + * get a vfsmount from a given sb
> + *
> + * This is especially used for case where change fs' sysfs interface
> + * will lead to a write, e.g. Change label through sysfs in btrfs.
> + * So vfs can get a vfsmount and then use mnt_want_write() to protect.
> + */
> +struct vfsmount *get_vfsmount_sb(struct super_block *sb)
> +{
> + struct vfsmount *ret_vfs = NULL;
> + struct mount *mnt;
> + int ret = 0;
> +
> + lock_mount_hash();
> + if (list_empty(&sb->s_mounts))
> + goto out;
> + mnt = list_entry(sb->s_mounts.next, struct mount, mnt_instance);
> + ret_vfs = &mnt->mnt;
> + ret_vfs = mntget(ret_vfs);
> +out:
> + unlock_mount_hash();
> + return ret_vfs;
> +}
> +EXPORT_SYMBOL(get_vfsmount_sb);
> +
> struct vfsmount *mnt_clone_internal(struct path *path)
> {
> struct mount *p;
> diff --git a/include/linux/mount.h b/include/linux/mount.h
> index c2c561d..cf1b0f5 100644
> --- a/include/linux/mount.h
> +++ b/include/linux/mount.h
> @@ -79,6 +79,7 @@ extern void mnt_drop_write_file(struct file *file);
> extern void mntput(struct vfsmount *mnt);
> extern struct vfsmount *mntget(struct vfsmount *mnt);
> extern struct vfsmount *mnt_clone_internal(struct path *path);
> +extern struct vfsmount *get_vfsmount_sb(struct super_block *sb);
> extern int __mnt_is_readonly(struct vfsmount *mnt);
>
> struct path;
>
next prev parent reply other threads:[~2015-01-30 0:55 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <1422498281-20493-1-git-send-email-quwenruo@cn.fujitsu.com>
2015-01-29 2:24 ` [PATCH RESEND v4 6/8] vfs: Add get_vfsmount_sb() function to get vfsmount from a given sb Qu Wenruo
2015-01-29 12:37 ` David Sterba
2015-01-29 15:23 ` Al Viro
2015-01-30 1:11 ` Qu Wenruo
2015-01-30 2:09 ` Al Viro
2015-01-30 2:20 ` Qu Wenruo
2015-01-30 0:52 ` Miao Xie [this message]
2015-01-30 1:44 ` Qu Wenruo
2015-01-30 2:02 ` Qu Wenruo
2015-01-30 3:22 ` Miao Xie
2015-01-30 3:30 ` Qu Wenruo
2015-01-30 2:14 ` Al Viro
2015-01-30 4:14 ` Miao Xie
2015-01-30 4:37 ` Al Viro
2015-01-30 5:34 ` Miao Xie
2015-01-30 6:15 ` Al Viro
2015-01-30 5:30 ` 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=54CAD5DC.2060603@huawei.com \
--to=miaoxie@huawei.com \
--cc=linux-btrfs@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=quwenruo@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).