aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMiklos Szeredi2011-11-21 05:11:31 -0600
committerAl Viro2012-01-06 22:20:12 -0600
commit4ed5e82fe77f4147cf386327c9a63a2dd7eff518 (patch)
treef4eaeefaf5d293014457892ac31f878eece07331 /fs/namespace.c
parent39f7c4db1d2d9e2e2a90abdf34811783089d217d (diff)
downloadkernel-omap-4ed5e82fe77f4147cf386327c9a63a2dd7eff518.tar.gz
kernel-omap-4ed5e82fe77f4147cf386327c9a63a2dd7eff518.tar.xz
kernel-omap-4ed5e82fe77f4147cf386327c9a63a2dd7eff518.zip
vfs: protect remounting superblock read-only
Currently remouting superblock read-only is racy in a major way. With the per mount read-only infrastructure it is now possible to prevent most races, which this patch attempts. Before starting the remount read-only, iterate through all mounts belonging to the superblock and if none of them have any pending writes, set sb->s_readonly_remount. This indicates that remount is in progress and no further write requests are allowed. If the remount succeeds set MS_RDONLY and reset s_readonly_remount. If the remounting is unsuccessful just reset s_readonly_remount. This can result in transient EROFS errors, despite the fact the remount failed. Unfortunately hodling off writes is difficult as remount itself may touch the filesystem (e.g. through load_nls()) which would deadlock. A later patch deals with delayed writes due to nlink going to zero. Signed-off-by: Miklos Szeredi <mszeredi@suse.cz> Tested-by: Toshiyuki Okajima <toshi.okajima@jp.fujitsu.com> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Diffstat (limited to 'fs/namespace.c')
-rw-r--r--fs/namespace.c40
1 files changed, 39 insertions, 1 deletions
diff --git a/fs/namespace.c b/fs/namespace.c
index 145217b088d1..98ebc78b21ab 100644
--- a/fs/namespace.c
+++ b/fs/namespace.c
@@ -273,6 +273,15 @@ static unsigned int mnt_get_writers(struct mount *mnt)
273#endif 273#endif
274} 274}
275 275
276static int mnt_is_readonly(struct vfsmount *mnt)
277{
278 if (mnt->mnt_sb->s_readonly_remount)
279 return 1;
280 /* Order wrt setting s_flags/s_readonly_remount in do_remount() */
281 smp_rmb();
282 return __mnt_is_readonly(mnt);
283}
284
276/* 285/*
277 * Most r/o checks on a fs are for operations that take 286 * Most r/o checks on a fs are for operations that take
278 * discrete amounts of time, like a write() or unlink(). 287 * discrete amounts of time, like a write() or unlink().
@@ -312,7 +321,7 @@ int mnt_want_write(struct vfsmount *m)
312 * MNT_WRITE_HOLD is cleared. 321 * MNT_WRITE_HOLD is cleared.
313 */ 322 */
314 smp_rmb(); 323 smp_rmb();
315 if (__mnt_is_readonly(m)) { 324 if (mnt_is_readonly(m)) {
316 mnt_dec_writers(mnt); 325 mnt_dec_writers(mnt);
317 ret = -EROFS; 326 ret = -EROFS;
318 goto out; 327 goto out;
@@ -435,6 +444,35 @@ static void __mnt_unmake_readonly(struct mount *mnt)
435 br_write_unlock(vfsmount_lock); 444 br_write_unlock(vfsmount_lock);
436} 445}
437 446
447int sb_prepare_remount_readonly(struct super_block *sb)
448{
449 struct mount *mnt;
450 int err = 0;
451
452 br_write_lock(vfsmount_lock);
453 list_for_each_entry(mnt, &sb->s_mounts, mnt_instance) {
454 if (!(mnt->mnt.mnt_flags & MNT_READONLY)) {
455 mnt->mnt.mnt_flags |= MNT_WRITE_HOLD;
456 smp_mb();
457 if (mnt_get_writers(mnt) > 0) {
458 err = -EBUSY;
459 break;
460 }
461 }
462 }
463 if (!err) {
464 sb->s_readonly_remount = 1;
465 smp_wmb();
466 }
467 list_for_each_entry(mnt, &sb->s_mounts, mnt_instance) {
468 if (mnt->mnt.mnt_flags & MNT_WRITE_HOLD)
469 mnt->mnt.mnt_flags &= ~MNT_WRITE_HOLD;
470 }
471 br_write_unlock(vfsmount_lock);
472
473 return err;
474}
475
438static void free_vfsmnt(struct mount *mnt) 476static void free_vfsmnt(struct mount *mnt)
439{ 477{
440 kfree(mnt->mnt_devname); 478 kfree(mnt->mnt_devname);