Skip to content

Commit

Permalink
Btrfs: don't write any data into a readonly device when scrub
Browse files Browse the repository at this point in the history
We should not write data into a readonly device especially seed device when
doing scrub, skip those devices.

Signed-off-by: Miao Xie <miaox@cn.fujitsu.com>
Reviewed-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <clm@fb.com>
  • Loading branch information
Miao Xie authored and Chris Mason committed Aug 19, 2014
1 parent ff61d17 commit 5d68da3
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions fs/btrfs/scrub.c
Original file line number Diff line number Diff line change
Expand Up @@ -2904,6 +2904,7 @@ int btrfs_scrub_dev(struct btrfs_fs_info *fs_info, u64 devid, u64 start,
struct scrub_ctx *sctx;
int ret;
struct btrfs_device *dev;
struct rcu_string *name;

if (btrfs_fs_closing(fs_info))
return -EINVAL;
Expand Down Expand Up @@ -2965,6 +2966,16 @@ int btrfs_scrub_dev(struct btrfs_fs_info *fs_info, u64 devid, u64 start,
return -ENODEV;
}

if (!is_dev_replace && !readonly && !dev->writeable) {
mutex_unlock(&fs_info->fs_devices->device_list_mutex);
rcu_read_lock();
name = rcu_dereference(dev->name);
btrfs_err(fs_info, "scrub: device %s is not writable",
name->str);
rcu_read_unlock();
return -EROFS;
}

mutex_lock(&fs_info->scrub_lock);
if (!dev->in_fs_metadata || dev->is_tgtdev_for_dev_replace) {
mutex_unlock(&fs_info->scrub_lock);
Expand Down

0 comments on commit 5d68da3

Please sign in to comment.