linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC] vfs: avoid sb->s_umount lock while changing bind-mount flags
@ 2013-09-16 17:42 Aditya Kali
  2013-09-17  2:40 ` Al Viro
  0 siblings, 1 reply; 7+ messages in thread
From: Aditya Kali @ 2013-09-16 17:42 UTC (permalink / raw)
  To: viro, linux-fsdevel, linux-kernel; +Cc: anatol, Aditya Kali

During remount of a bind mount (mount -o remount,bind,ro,... /mnt/mntpt),
we currently take down_write(&sb->s_umount). This causes the remount
operation to get blocked behind writes occuring on device (possibly
mounted somewhere else). We have observed that simply trying to change
the bind-mount from read-write to read-only can take several seconds
becuase writeback is in progress. Looking at the code it seems to me that
we need s_umount lock only around the do_remount_sb() call.
vfsmount_lock seems enough to protect the flag change on the mount.
So this patch fixes the locking so that changing of flags can happen
outside the down_write(&sb->s_umount).

I wanted to get comments if I am violating any assumption around this code.
Another thing that I was curious about was if we need the
{lock|unlock}_mount(path) around this code. Please advise.

Signed-off-by: Aditya Kali <adityakali@google.com>
---
 fs/namespace.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/fs/namespace.c b/fs/namespace.c
index da5c494..4b9c839 100644
--- a/fs/namespace.c
+++ b/fs/namespace.c
@@ -1838,20 +1838,21 @@ static int do_remount(struct path *path, int flags, int mnt_flags,
 	if (err)
 		return err;
 
-	down_write(&sb->s_umount);
 	if (flags & MS_BIND)
 		err = change_mount_flags(path->mnt, flags);
 	else if (!capable(CAP_SYS_ADMIN))
 		err = -EPERM;
-	else
+	else {
+		down_write(&sb->s_umount);
 		err = do_remount_sb(sb, flags, data, 0);
+		up_write(&sb->s_umount);
+	}
 	if (!err) {
 		br_write_lock(&vfsmount_lock);
 		mnt_flags |= mnt->mnt.mnt_flags & MNT_PROPAGATION_MASK;
 		mnt->mnt.mnt_flags = mnt_flags;
 		br_write_unlock(&vfsmount_lock);
 	}
-	up_write(&sb->s_umount);
 	if (!err) {
 		br_write_lock(&vfsmount_lock);
 		touch_mnt_namespace(mnt->mnt_ns);
-- 
1.8.4

^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2013-09-30 21:44 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-09-16 17:42 [RFC] vfs: avoid sb->s_umount lock while changing bind-mount flags Aditya Kali
2013-09-17  2:40 ` Al Viro
2013-09-19 20:13   ` Aditya Kali
2013-09-30 17:54     ` Aditya Kali
2013-09-30 18:13       ` Aditya Kali
2013-09-30 20:03         ` Al Viro
2013-09-30 21:44           ` Aditya Kali

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).