Commit bbb651e4 authored by Stefan Behrens's avatar Stefan Behrens Committed by Chris Mason

Btrfs: don't allow the replace procedure on read only filesystems

If you start the replace procedure on a read only filesystem, at
the end the procedure fails to write the updated dev_items to the
chunk tree. The problem is that this error is not indicated except
for a WARN_ON(). If the user now thinks that everything was done
as expected and destroys the source device (with mkfs or with a
hammer). The next mount fails with "failed to read chunk root" and
the filesystem is gone.

This commit adds code to fail the attempt to start the replace
procedure if the filesystem is mounted read-only.
Signed-off-by: default avatarStefan Behrens <sbehrens@giantdisaster.de>
Cc: <stable@vger.kernel.org> # 3.10+
Signed-off-by: default avatarJosef Bacik <jbacik@fusionio.com>
Signed-off-by: default avatarChris Mason <chris.mason@fusionio.com>
parent 68b823ef
...@@ -3670,6 +3670,9 @@ static long btrfs_ioctl_dev_replace(struct btrfs_root *root, void __user *arg) ...@@ -3670,6 +3670,9 @@ static long btrfs_ioctl_dev_replace(struct btrfs_root *root, void __user *arg)
switch (p->cmd) { switch (p->cmd) {
case BTRFS_IOCTL_DEV_REPLACE_CMD_START: case BTRFS_IOCTL_DEV_REPLACE_CMD_START:
if (root->fs_info->sb->s_flags & MS_RDONLY)
return -EROFS;
if (atomic_xchg( if (atomic_xchg(
&root->fs_info->mutually_exclusive_operation_running, &root->fs_info->mutually_exclusive_operation_running,
1)) { 1)) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment