All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] btrfs: ioctl: reorder exclusive op check in RM_DEV
@ 2016-05-04  9:32 David Sterba
  2016-05-04  9:51 ` Filipe Manana
  2016-05-04 12:10 ` [PATCH v2] " David Sterba
  0 siblings, 2 replies; 3+ messages in thread
From: David Sterba @ 2016-05-04  9:32 UTC (permalink / raw)
  To: linux-btrfs; +Cc: David Sterba, David Sterba

From: David Sterba <dsterba@suse.cz>

Move the op exclusivity check before the other code (same as in
ADD_DEV).

Signed-off-by: David Sterba <dsterba@suse.com>
---
 fs/btrfs/ioctl.c | 23 +++++++++++------------
 1 file changed, 11 insertions(+), 12 deletions(-)

diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
index e3239272fa61..45beb6dd8417 100644
--- a/fs/btrfs/ioctl.c
+++ b/fs/btrfs/ioctl.c
@@ -2680,32 +2680,31 @@ static long btrfs_ioctl_rm_dev(struct file *file, void __user *arg)
 	if (ret)
 		return ret;
 
+	if (atomic_xchg(&root->fs_info->mutually_exclusive_operation_running,
+			1)) {
+		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);
-		goto err_drop;
+		goto out_drop_write;
 	}
 
 	vol_args->name[BTRFS_PATH_NAME_MAX] = '\0';
-
-	if (atomic_xchg(&root->fs_info->mutually_exclusive_operation_running,
-			1)) {
-		ret = BTRFS_ERROR_DEV_EXCL_RUN_IN_PROGRESS;
-		goto out;
-	}
-
 	mutex_lock(&root->fs_info->volume_mutex);
 	ret = btrfs_rm_device(root, vol_args->name);
 	mutex_unlock(&root->fs_info->volume_mutex);
-	atomic_set(&root->fs_info->mutually_exclusive_operation_running, 0);
 
 	if (!ret)
 		btrfs_info(root->fs_info, "disk deleted %s",vol_args->name);
-
-out:
 	kfree(vol_args);
-err_drop:
+out:
+	atomic_set(&root->fs_info->mutually_exclusive_operation_running, 0);
+out_drop_write:
 	mnt_drop_write_file(file);
+
 	return ret;
 }
 
-- 
2.7.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] btrfs: ioctl: reorder exclusive op check in RM_DEV
  2016-05-04  9:32 [PATCH] btrfs: ioctl: reorder exclusive op check in RM_DEV David Sterba
@ 2016-05-04  9:51 ` Filipe Manana
  2016-05-04 12:10 ` [PATCH v2] " David Sterba
  1 sibling, 0 replies; 3+ messages in thread
From: Filipe Manana @ 2016-05-04  9:51 UTC (permalink / raw)
  To: David Sterba; +Cc: linux-btrfs, David Sterba

On Wed, May 4, 2016 at 10:32 AM, David Sterba <dsterba@suse.com> wrote:
> From: David Sterba <dsterba@suse.cz>
>
> Move the op exclusivity check before the other code (same as in
> ADD_DEV).
>
> Signed-off-by: David Sterba <dsterba@suse.com>
> ---
>  fs/btrfs/ioctl.c | 23 +++++++++++------------
>  1 file changed, 11 insertions(+), 12 deletions(-)
>
> diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
> index e3239272fa61..45beb6dd8417 100644
> --- a/fs/btrfs/ioctl.c
> +++ b/fs/btrfs/ioctl.c
> @@ -2680,32 +2680,31 @@ static long btrfs_ioctl_rm_dev(struct file *file, void __user *arg)
>         if (ret)
>                 return ret;
>
> +       if (atomic_xchg(&root->fs_info->mutually_exclusive_operation_running,
> +                       1)) {
> +               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);
> -               goto err_drop;
> +               goto out_drop_write;

goto out, otherwise
root->fs_info->mutually_exclusive_operation_running remains with value
1 forever...

>         }
>
>         vol_args->name[BTRFS_PATH_NAME_MAX] = '\0';
> -
> -       if (atomic_xchg(&root->fs_info->mutually_exclusive_operation_running,
> -                       1)) {
> -               ret = BTRFS_ERROR_DEV_EXCL_RUN_IN_PROGRESS;
> -               goto out;
> -       }
> -
>         mutex_lock(&root->fs_info->volume_mutex);
>         ret = btrfs_rm_device(root, vol_args->name);
>         mutex_unlock(&root->fs_info->volume_mutex);
> -       atomic_set(&root->fs_info->mutually_exclusive_operation_running, 0);
>
>         if (!ret)
>                 btrfs_info(root->fs_info, "disk deleted %s",vol_args->name);
> -
> -out:
>         kfree(vol_args);
> -err_drop:
> +out:
> +       atomic_set(&root->fs_info->mutually_exclusive_operation_running, 0);
> +out_drop_write:
>         mnt_drop_write_file(file);
> +
>         return ret;
>  }
>
> --
> 2.7.1
>
> --
> 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



-- 
Filipe David Manana,

"Reasonable men adapt themselves to the world.
 Unreasonable men adapt the world to themselves.
 That's why all progress depends on unreasonable men."

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH v2] btrfs: ioctl: reorder exclusive op check in RM_DEV
  2016-05-04  9:32 [PATCH] btrfs: ioctl: reorder exclusive op check in RM_DEV David Sterba
  2016-05-04  9:51 ` Filipe Manana
@ 2016-05-04 12:10 ` David Sterba
  1 sibling, 0 replies; 3+ messages in thread
From: David Sterba @ 2016-05-04 12:10 UTC (permalink / raw)
  To: linux-btrfs; +Cc: fdmanana, David Sterba, David Sterba

From: David Sterba <dsterba@suse.cz>

Move the op exclusivity check before the other code (same as in
ADD_DEV).

Signed-off-by: David Sterba <dsterba@suse.com>
---
 fs/btrfs/ioctl.c | 23 +++++++++++------------
 1 file changed, 11 insertions(+), 12 deletions(-)

diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
index 5a23806ae418..70e9687f1d59 100644
--- a/fs/btrfs/ioctl.c
+++ b/fs/btrfs/ioctl.c
@@ -2680,32 +2680,31 @@ static long btrfs_ioctl_rm_dev(struct file *file, void __user *arg)
 	if (ret)
 		return ret;
 
-	vol_args = memdup_user(arg, sizeof(*vol_args));
-	if (IS_ERR(vol_args)) {
-		ret = PTR_ERR(vol_args);
-		goto err_drop;
-	}
-
-	vol_args->name[BTRFS_PATH_NAME_MAX] = '\0';
-
 	if (atomic_xchg(&root->fs_info->mutually_exclusive_operation_running,
 			1)) {
 		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);
 		goto out;
 	}
 
+	vol_args->name[BTRFS_PATH_NAME_MAX] = '\0';
 	mutex_lock(&root->fs_info->volume_mutex);
 	ret = btrfs_rm_device(root, vol_args->name);
 	mutex_unlock(&root->fs_info->volume_mutex);
-	atomic_set(&root->fs_info->mutually_exclusive_operation_running, 0);
 
 	if (!ret)
 		btrfs_info(root->fs_info, "disk deleted %s",vol_args->name);
-
-out:
 	kfree(vol_args);
-err_drop:
+out:
+	atomic_set(&root->fs_info->mutually_exclusive_operation_running, 0);
+out_drop_write:
 	mnt_drop_write_file(file);
+
 	return ret;
 }
 
-- 
2.7.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2016-05-04 12:11 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-05-04  9:32 [PATCH] btrfs: ioctl: reorder exclusive op check in RM_DEV David Sterba
2016-05-04  9:51 ` Filipe Manana
2016-05-04 12:10 ` [PATCH v2] " David Sterba

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.