]> git.proxmox.com Git - mirror_ubuntu-kernels.git/commitdiff
Btrfs: do not set subvolume flags in readonly mode
authorLiu Bo <liubo2009@cn.fujitsu.com>
Fri, 29 Jun 2012 09:58:49 +0000 (03:58 -0600)
committerChris Mason <chris.mason@fusionio.com>
Mon, 23 Jul 2012 20:27:58 +0000 (16:27 -0400)
$ mkfs.btrfs /dev/sdb7
$ btrfstune -S1 /dev/sdb7
$ mount /dev/sdb7 /mnt/btrfs
mount: block device /dev/sdb7 is write-protected, mounting read-only
$ btrfs dev add /dev/sdb8 /mnt/btrfs/

Now we get a btrfs in which mnt flags has readonly but sb flags does
not.  So for those ioctls that only check sb flags with MS_RDONLY, it
is going to be a problem.
Setting subvolume flags is such an ioctl, we should use mnt_want_write_file()
to check RO flags.

Signed-off-by: Liu Bo <liubo2009@cn.fujitsu.com>
fs/btrfs/ioctl.c

index 13ed1c9534cc672a9682a776c0a161bace2aa5e3..17facea6a51c8428878dffe52a9910b825fb8fd8 100644 (file)
@@ -1521,29 +1521,40 @@ static noinline int btrfs_ioctl_subvol_setflags(struct file *file,
        u64 flags;
        int ret = 0;
 
-       if (root->fs_info->sb->s_flags & MS_RDONLY)
-               return -EROFS;
+       ret = mnt_want_write_file(file);
+       if (ret)
+               goto out;
 
-       if (btrfs_ino(inode) != BTRFS_FIRST_FREE_OBJECTID)
-               return -EINVAL;
+       if (btrfs_ino(inode) != BTRFS_FIRST_FREE_OBJECTID) {
+               ret = -EINVAL;
+               goto out_drop_write;
+       }
 
-       if (copy_from_user(&flags, arg, sizeof(flags)))
-               return -EFAULT;
+       if (copy_from_user(&flags, arg, sizeof(flags))) {
+               ret = -EFAULT;
+               goto out_drop_write;
+       }
 
-       if (flags & BTRFS_SUBVOL_CREATE_ASYNC)
-               return -EINVAL;
+       if (flags & BTRFS_SUBVOL_CREATE_ASYNC) {
+               ret = -EINVAL;
+               goto out_drop_write;
+       }
 
-       if (flags & ~BTRFS_SUBVOL_RDONLY)
-               return -EOPNOTSUPP;
+       if (flags & ~BTRFS_SUBVOL_RDONLY) {
+               ret = -EOPNOTSUPP;
+               goto out_drop_write;
+       }
 
-       if (!inode_owner_or_capable(inode))
-               return -EACCES;
+       if (!inode_owner_or_capable(inode)) {
+               ret = -EACCES;
+               goto out_drop_write;
+       }
 
        down_write(&root->fs_info->subvol_sem);
 
        /* nothing to do */
        if (!!(flags & BTRFS_SUBVOL_RDONLY) == btrfs_root_readonly(root))
-               goto out;
+               goto out_drop_sem;
 
        root_flags = btrfs_root_flags(&root->root_item);
        if (flags & BTRFS_SUBVOL_RDONLY)
@@ -1566,8 +1577,11 @@ static noinline int btrfs_ioctl_subvol_setflags(struct file *file,
 out_reset:
        if (ret)
                btrfs_set_root_flags(&root->root_item, root_flags);
-out:
+out_drop_sem:
        up_write(&root->fs_info->subvol_sem);
+out_drop_write:
+       mnt_drop_write_file(file);
+out:
        return ret;
 }