diff options
author | Liu Bo <liubo2009@cn.fujitsu.com> | 2012-06-29 05:58:49 -0400 |
---|---|---|
committer | Chris Mason <chris.mason@fusionio.com> | 2012-07-23 16:27:58 -0400 |
commit | b9ca0664dc806ba70587f6f3202b60dc736cd6e5 (patch) | |
tree | fd40828d3af0ba3b16e1e9231c406d6a6b1bace4 /fs/btrfs/ioctl.c | |
parent | e54bfa31044d602a57d4e190f6d1c3763ea76bfe (diff) |
Btrfs: do not set subvolume flags in readonly mode
$ 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>
Diffstat (limited to 'fs/btrfs/ioctl.c')
-rw-r--r-- | fs/btrfs/ioctl.c | 42 |
1 files changed, 28 insertions, 14 deletions
diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c index 13ed1c9534cc..17facea6a51c 100644 --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c | |||
@@ -1521,29 +1521,40 @@ static noinline int btrfs_ioctl_subvol_setflags(struct file *file, | |||
1521 | u64 flags; | 1521 | u64 flags; |
1522 | int ret = 0; | 1522 | int ret = 0; |
1523 | 1523 | ||
1524 | if (root->fs_info->sb->s_flags & MS_RDONLY) | 1524 | ret = mnt_want_write_file(file); |
1525 | return -EROFS; | 1525 | if (ret) |
1526 | goto out; | ||
1526 | 1527 | ||
1527 | if (btrfs_ino(inode) != BTRFS_FIRST_FREE_OBJECTID) | 1528 | if (btrfs_ino(inode) != BTRFS_FIRST_FREE_OBJECTID) { |
1528 | return -EINVAL; | 1529 | ret = -EINVAL; |
1530 | goto out_drop_write; | ||
1531 | } | ||
1529 | 1532 | ||
1530 | if (copy_from_user(&flags, arg, sizeof(flags))) | 1533 | if (copy_from_user(&flags, arg, sizeof(flags))) { |
1531 | return -EFAULT; | 1534 | ret = -EFAULT; |
1535 | goto out_drop_write; | ||
1536 | } | ||
1532 | 1537 | ||
1533 | if (flags & BTRFS_SUBVOL_CREATE_ASYNC) | 1538 | if (flags & BTRFS_SUBVOL_CREATE_ASYNC) { |
1534 | return -EINVAL; | 1539 | ret = -EINVAL; |
1540 | goto out_drop_write; | ||
1541 | } | ||
1535 | 1542 | ||
1536 | if (flags & ~BTRFS_SUBVOL_RDONLY) | 1543 | if (flags & ~BTRFS_SUBVOL_RDONLY) { |
1537 | return -EOPNOTSUPP; | 1544 | ret = -EOPNOTSUPP; |
1545 | goto out_drop_write; | ||
1546 | } | ||
1538 | 1547 | ||
1539 | if (!inode_owner_or_capable(inode)) | 1548 | if (!inode_owner_or_capable(inode)) { |
1540 | return -EACCES; | 1549 | ret = -EACCES; |
1550 | goto out_drop_write; | ||
1551 | } | ||
1541 | 1552 | ||
1542 | down_write(&root->fs_info->subvol_sem); | 1553 | down_write(&root->fs_info->subvol_sem); |
1543 | 1554 | ||
1544 | /* nothing to do */ | 1555 | /* nothing to do */ |
1545 | if (!!(flags & BTRFS_SUBVOL_RDONLY) == btrfs_root_readonly(root)) | 1556 | if (!!(flags & BTRFS_SUBVOL_RDONLY) == btrfs_root_readonly(root)) |
1546 | goto out; | 1557 | goto out_drop_sem; |
1547 | 1558 | ||
1548 | root_flags = btrfs_root_flags(&root->root_item); | 1559 | root_flags = btrfs_root_flags(&root->root_item); |
1549 | if (flags & BTRFS_SUBVOL_RDONLY) | 1560 | if (flags & BTRFS_SUBVOL_RDONLY) |
@@ -1566,8 +1577,11 @@ static noinline int btrfs_ioctl_subvol_setflags(struct file *file, | |||
1566 | out_reset: | 1577 | out_reset: |
1567 | if (ret) | 1578 | if (ret) |
1568 | btrfs_set_root_flags(&root->root_item, root_flags); | 1579 | btrfs_set_root_flags(&root->root_item, root_flags); |
1569 | out: | 1580 | out_drop_sem: |
1570 | up_write(&root->fs_info->subvol_sem); | 1581 | up_write(&root->fs_info->subvol_sem); |
1582 | out_drop_write: | ||
1583 | mnt_drop_write_file(file); | ||
1584 | out: | ||
1571 | return ret; | 1585 | return ret; |
1572 | } | 1586 | } |
1573 | 1587 | ||