Re: [RFC PATCH v4 3/6] Btrfs: push EXCL_OP set into btrfs_rm_device()

2018-05-28 Thread David Sterba
On Thu, May 24, 2018 at 02:41:27PM -0700, Omar Sandoval wrote:
> From: Omar Sandoval 
> 
> btrfs_ioctl_rm_dev() and btrfs_ioctl_rm_dev_v2() both manipulate this
> bit. Let's move it into the common btrfs_rm_device(), which also makes
> the following change to deal with swap files easier.

I'd rather keep it in both places as it's clear where the EXCL_OP
context starts in the ioctl handlers, not in some helper function.
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [RFC PATCH v4 3/6] Btrfs: push EXCL_OP set into btrfs_rm_device()

2018-05-25 Thread Nikolay Borisov


On 25.05.2018 00:41, Omar Sandoval wrote:
> From: Omar Sandoval 
> 
> btrfs_ioctl_rm_dev() and btrfs_ioctl_rm_dev_v2() both manipulate this
> bit. Let's move it into the common btrfs_rm_device(), which also makes
> the following change to deal with swap files easier.
> 
> Signed-off-by: Omar Sandoval 

Reviewed-by: Nikolay Borisov 
> ---
>  fs/btrfs/ioctl.c   | 13 -
>  fs/btrfs/volumes.c |  4 
>  2 files changed, 4 insertions(+), 13 deletions(-)
> 
> diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
> index 9af3be96099f..82be4a94334b 100644
> --- a/fs/btrfs/ioctl.c
> +++ b/fs/btrfs/ioctl.c
> @@ -3091,18 +3091,12 @@ static long btrfs_ioctl_rm_dev_v2(struct file *file, 
> void __user *arg)
>   goto out;
>   }
>  
> - if (test_and_set_bit(BTRFS_FS_EXCL_OP, _info->flags)) {
> - ret = BTRFS_ERROR_DEV_EXCL_RUN_IN_PROGRESS;
> - goto out;
> - }
> -
>   if (vol_args->flags & BTRFS_DEVICE_SPEC_BY_ID) {
>   ret = btrfs_rm_device(fs_info, NULL, vol_args->devid);
>   } else {
>   vol_args->name[BTRFS_SUBVOL_NAME_MAX] = '\0';
>   ret = btrfs_rm_device(fs_info, vol_args->name, 0);
>   }
> - clear_bit(BTRFS_FS_EXCL_OP, _info->flags);
>  
>   if (!ret) {
>   if (vol_args->flags & BTRFS_DEVICE_SPEC_BY_ID)
> @@ -3133,11 +3127,6 @@ static long btrfs_ioctl_rm_dev(struct file *file, void 
> __user *arg)
>   if (ret)
>   return ret;
>  
> - if (test_and_set_bit(BTRFS_FS_EXCL_OP, _info->flags)) {
> - ret = BTRFS_ERROR_DEV_EXCL_RUN_IN_PROGRESS;
> - goto out_drop_write;
> - }
> -
>   vol_args = memdup_user(arg, sizeof(*vol_args));
>   if (IS_ERR(vol_args)) {
>   ret = PTR_ERR(vol_args);
> @@ -3151,8 +3140,6 @@ static long btrfs_ioctl_rm_dev(struct file *file, void 
> __user *arg)
>   btrfs_info(fs_info, "disk deleted %s", vol_args->name);
>   kfree(vol_args);
>  out:
> - clear_bit(BTRFS_FS_EXCL_OP, _info->flags);
> -out_drop_write:
>   mnt_drop_write_file(file);
>  
>   return ret;
> diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
> index b6757b53c297..9cfac177214f 100644
> --- a/fs/btrfs/volumes.c
> +++ b/fs/btrfs/volumes.c
> @@ -1951,6 +1951,9 @@ int btrfs_rm_device(struct btrfs_fs_info *fs_info, 
> const char *device_path,
>   u64 num_devices;
>   int ret = 0;
>  
> + if (test_and_set_bit(BTRFS_FS_EXCL_OP, _info->flags))
> + return BTRFS_ERROR_DEV_EXCL_RUN_IN_PROGRESS;
> +
>   mutex_lock(_mutex);
>  
>   num_devices = fs_devices->num_devices;
> @@ -2069,6 +2072,7 @@ int btrfs_rm_device(struct btrfs_fs_info *fs_info, 
> const char *device_path,
>  
>  out:
>   mutex_unlock(_mutex);
> + clear_bit(BTRFS_FS_EXCL_OP, _info->flags);
>   return ret;
>  
>  error_undo:
> 
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[RFC PATCH v4 3/6] Btrfs: push EXCL_OP set into btrfs_rm_device()

2018-05-24 Thread Omar Sandoval
From: Omar Sandoval 

btrfs_ioctl_rm_dev() and btrfs_ioctl_rm_dev_v2() both manipulate this
bit. Let's move it into the common btrfs_rm_device(), which also makes
the following change to deal with swap files easier.

Signed-off-by: Omar Sandoval 
---
 fs/btrfs/ioctl.c   | 13 -
 fs/btrfs/volumes.c |  4 
 2 files changed, 4 insertions(+), 13 deletions(-)

diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
index 9af3be96099f..82be4a94334b 100644
--- a/fs/btrfs/ioctl.c
+++ b/fs/btrfs/ioctl.c
@@ -3091,18 +3091,12 @@ static long btrfs_ioctl_rm_dev_v2(struct file *file, 
void __user *arg)
goto out;
}
 
-   if (test_and_set_bit(BTRFS_FS_EXCL_OP, _info->flags)) {
-   ret = BTRFS_ERROR_DEV_EXCL_RUN_IN_PROGRESS;
-   goto out;
-   }
-
if (vol_args->flags & BTRFS_DEVICE_SPEC_BY_ID) {
ret = btrfs_rm_device(fs_info, NULL, vol_args->devid);
} else {
vol_args->name[BTRFS_SUBVOL_NAME_MAX] = '\0';
ret = btrfs_rm_device(fs_info, vol_args->name, 0);
}
-   clear_bit(BTRFS_FS_EXCL_OP, _info->flags);
 
if (!ret) {
if (vol_args->flags & BTRFS_DEVICE_SPEC_BY_ID)
@@ -3133,11 +3127,6 @@ static long btrfs_ioctl_rm_dev(struct file *file, void 
__user *arg)
if (ret)
return ret;
 
-   if (test_and_set_bit(BTRFS_FS_EXCL_OP, _info->flags)) {
-   ret = BTRFS_ERROR_DEV_EXCL_RUN_IN_PROGRESS;
-   goto out_drop_write;
-   }
-
vol_args = memdup_user(arg, sizeof(*vol_args));
if (IS_ERR(vol_args)) {
ret = PTR_ERR(vol_args);
@@ -3151,8 +3140,6 @@ static long btrfs_ioctl_rm_dev(struct file *file, void 
__user *arg)
btrfs_info(fs_info, "disk deleted %s", vol_args->name);
kfree(vol_args);
 out:
-   clear_bit(BTRFS_FS_EXCL_OP, _info->flags);
-out_drop_write:
mnt_drop_write_file(file);
 
return ret;
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index b6757b53c297..9cfac177214f 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -1951,6 +1951,9 @@ int btrfs_rm_device(struct btrfs_fs_info *fs_info, const 
char *device_path,
u64 num_devices;
int ret = 0;
 
+   if (test_and_set_bit(BTRFS_FS_EXCL_OP, _info->flags))
+   return BTRFS_ERROR_DEV_EXCL_RUN_IN_PROGRESS;
+
mutex_lock(_mutex);
 
num_devices = fs_devices->num_devices;
@@ -2069,6 +2072,7 @@ int btrfs_rm_device(struct btrfs_fs_info *fs_info, const 
char *device_path,
 
 out:
mutex_unlock(_mutex);
+   clear_bit(BTRFS_FS_EXCL_OP, _info->flags);
return ret;
 
 error_undo:
-- 
2.17.0

--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html