Skip to content

Commit 5d68da3

Browse files
Miao Xiemasoncl
authored andcommitted
Btrfs: don't write any data into a readonly device when scrub
We should not write data into a readonly device especially seed device when doing scrub, skip those devices. Signed-off-by: Miao Xie <[email protected]> Reviewed-by: David Sterba <[email protected]> Signed-off-by: Chris Mason <[email protected]>
1 parent ff61d17 commit 5d68da3

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

fs/btrfs/scrub.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2904,6 +2904,7 @@ int btrfs_scrub_dev(struct btrfs_fs_info *fs_info, u64 devid, u64 start,
29042904
struct scrub_ctx *sctx;
29052905
int ret;
29062906
struct btrfs_device *dev;
2907+
struct rcu_string *name;
29072908

29082909
if (btrfs_fs_closing(fs_info))
29092910
return -EINVAL;
@@ -2965,6 +2966,16 @@ int btrfs_scrub_dev(struct btrfs_fs_info *fs_info, u64 devid, u64 start,
29652966
return -ENODEV;
29662967
}
29672968

2969+
if (!is_dev_replace && !readonly && !dev->writeable) {
2970+
mutex_unlock(&fs_info->fs_devices->device_list_mutex);
2971+
rcu_read_lock();
2972+
name = rcu_dereference(dev->name);
2973+
btrfs_err(fs_info, "scrub: device %s is not writable",
2974+
name->str);
2975+
rcu_read_unlock();
2976+
return -EROFS;
2977+
}
2978+
29682979
mutex_lock(&fs_info->scrub_lock);
29692980
if (!dev->in_fs_metadata || dev->is_tgtdev_for_dev_replace) {
29702981
mutex_unlock(&fs_info->scrub_lock);

0 commit comments

Comments
 (0)