From 8e8b87964bc8dc5c14b6543fc933b7725f07d3ac Mon Sep 17 00:00:00 2001 From: Miklos Szeredi Date: Mon, 21 Nov 2011 12:11:33 +0100 Subject: vfs: prevent remount read-only if pending removes If there are any inodes on the super block that have been unlinked (i_nlink == 0) but have not yet been deleted then prevent the remounting the super block read-only. Reported-by: Toshiyuki Okajima Signed-off-by: Miklos Szeredi Tested-by: Toshiyuki Okajima Signed-off-by: Al Viro --- fs/namespace.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'fs/namespace.c') diff --git a/fs/namespace.c b/fs/namespace.c index 98ebc78b21ab..7e6f2c9dc7c4 100644 --- a/fs/namespace.c +++ b/fs/namespace.c @@ -449,6 +449,10 @@ int sb_prepare_remount_readonly(struct super_block *sb) struct mount *mnt; int err = 0; + /* Racy optimization. Recheck the counter under MNT_WRITE_HOLD */ + if (atomic_long_read(&sb->s_remove_count)) + return -EBUSY; + br_write_lock(vfsmount_lock); list_for_each_entry(mnt, &sb->s_mounts, mnt_instance) { if (!(mnt->mnt.mnt_flags & MNT_READONLY)) { @@ -460,6 +464,9 @@ int sb_prepare_remount_readonly(struct super_block *sb) } } } + if (!err && atomic_long_read(&sb->s_remove_count)) + err = -EBUSY; + if (!err) { sb->s_readonly_remount = 1; smp_wmb(); -- cgit v1.2.3