vfs: prevent remount read-only if pending removes
authorMiklos Szeredi <mszeredi@suse.cz>
Mon, 21 Nov 2011 11:11:33 +0000 (12:11 +0100)
committerAl Viro <viro@zeniv.linux.org.uk>
Sat, 7 Jan 2012 04:20:13 +0000 (23:20 -0500)
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 <toshi.okajima@jp.fujitsu.com>
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>
fs/file_table.c
fs/namespace.c
fs/super.c
include/linux/fs.h

index c322794f7360c2065edc871a0fa91f2333ed6423..20002e39754ddc91ee92517c9b38f8215f004afa 100644 (file)
@@ -474,29 +474,6 @@ void file_sb_list_del(struct file *file)
 
 #endif
 
-int fs_may_remount_ro(struct super_block *sb)
-{
-       struct file *file;
-       /* Check that no files are currently opened for writing. */
-       lg_global_lock(files_lglock);
-       do_file_list_for_each_entry(sb, file) {
-               struct inode *inode = file->f_path.dentry->d_inode;
-
-               /* File with pending delete? */
-               if (inode->i_nlink == 0)
-                       goto too_bad;
-
-               /* Writeable file? */
-               if (S_ISREG(inode->i_mode) && (file->f_mode & FMODE_WRITE))
-                       goto too_bad;
-       } while_file_list_for_each_entry;
-       lg_global_unlock(files_lglock);
-       return 1; /* Tis' cool bro. */
-too_bad:
-       lg_global_unlock(files_lglock);
-       return 0;
-}
-
 /**
  *     mark_files_ro - mark all files read-only
  *     @sb: superblock in question
index 98ebc78b21ab7cc1678f8f40da3b9343e22d5111..7e6f2c9dc7c40d53424d88effabb237026d57a84 100644 (file)
@@ -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();
index 6acc02237e3e03964402eb767d19e2ff49b8112f..de41e1e46f0970b3c262fb577e0b6f332c6a59e5 100644 (file)
@@ -729,10 +729,6 @@ int do_remount_sb(struct super_block *sb, int flags, void *data, int force)
                        retval = sb_prepare_remount_readonly(sb);
                        if (retval)
                                return retval;
-
-                       retval = -EBUSY;
-                       if (!fs_may_remount_ro(sb))
-                               goto cancel_readonly;
                }
        }
 
index 8ac40921f5acd6586af6deab47bd08bbc5f1a56a..7aacf31418fed291df3591c07ef252a26aa4c62c 100644 (file)
@@ -2150,8 +2150,6 @@ extern const struct file_operations read_pipefifo_fops;
 extern const struct file_operations write_pipefifo_fops;
 extern const struct file_operations rdwr_pipefifo_fops;
 
-extern int fs_may_remount_ro(struct super_block *);
-
 #ifdef CONFIG_BLOCK
 /*
  * return READ, READA, or WRITE