diff mbox

[02/10] Btrfs: don't write any data into a readonly device when scrub

Message ID 1406173035-29478-2-git-send-email-miaox@cn.fujitsu.com (mailing list archive)
State Accepted
Headers show

Commit Message

Miao Xie July 24, 2014, 3:37 a.m. UTC
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>
---
 fs/btrfs/scrub.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

Comments

David Sterba July 24, 2014, 1:19 p.m. UTC | #1
On Thu, Jul 24, 2014 at 11:37:07AM +0800, Miao Xie wrote:
> 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>

One minor comment below.

> @@ -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 (!is_dev_replace && !readonly && !dev->writeable) {

You can define 'name' within the block.

> +		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;
> +	}
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Anand Jain July 25, 2014, 9:39 a.m. UTC | #2
On 07/24/2014 11:37 AM, Miao Xie wrote:
> We should not write data into a readonly device especially seed device when
> doing scrub, skip those devices.

Reviewed-by: Anand Jain <anand.jain@oracle.com>
> Signed-off-by: Miao Xie <miaox@cn.fujitsu.com>
> ---
>   fs/btrfs/scrub.c | 11 +++++++++++
>   1 file changed, 11 insertions(+)
>
> diff --git a/fs/btrfs/scrub.c b/fs/btrfs/scrub.c
> index b6d198f..23d3f6e 100644
> --- a/fs/btrfs/scrub.c
> +++ b/fs/btrfs/scrub.c
> @@ -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;
> @@ -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) {

  just reading the commit message would ask question what
  about readonly scrub anyway. Nice readonly scrub case
  is taken care as well.


> +		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);
>
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/fs/btrfs/scrub.c b/fs/btrfs/scrub.c
index b6d198f..23d3f6e 100644
--- a/fs/btrfs/scrub.c
+++ b/fs/btrfs/scrub.c
@@ -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;
@@ -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);