From patchwork Wed May 4 09:32:26 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Sterba X-Patchwork-Id: 9011761 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 0F137BF29F for ; Wed, 4 May 2016 09:32:53 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 3AF1620392 for ; Wed, 4 May 2016 09:32:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2FC0120384 for ; Wed, 4 May 2016 09:32:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757190AbcEDJcs (ORCPT ); Wed, 4 May 2016 05:32:48 -0400 Received: from mx2.suse.de ([195.135.220.15]:36499 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757087AbcEDJcr (ORCPT ); Wed, 4 May 2016 05:32:47 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id C012EABB4 for ; Wed, 4 May 2016 09:32:45 +0000 (UTC) Received: by ds.suse.cz (Postfix, from userid 10065) id AA1FCDAB68; Wed, 4 May 2016 11:32:29 +0200 (CEST) From: David Sterba To: linux-btrfs@vger.kernel.org Cc: David Sterba , David Sterba Subject: [PATCH] btrfs: ioctl: reorder exclusive op check in RM_DEV Date: Wed, 4 May 2016 11:32:26 +0200 Message-Id: <1462354346-17654-1-git-send-email-dsterba@suse.com> X-Mailer: git-send-email 2.7.1 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Spam-Status: No, score=-9.0 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: David Sterba Move the op exclusivity check before the other code (same as in ADD_DEV). Signed-off-by: David Sterba --- 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; }