From patchwork Sun Jan 20 15:22:32 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilya Dryomov X-Patchwork-Id: 2008261 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id 371D9DF223 for ; Sun, 20 Jan 2013 15:22:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752324Ab3ATPWv (ORCPT ); Sun, 20 Jan 2013 10:22:51 -0500 Received: from mail-ea0-f180.google.com ([209.85.215.180]:56947 "EHLO mail-ea0-f180.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752312Ab3ATPWu (ORCPT ); Sun, 20 Jan 2013 10:22:50 -0500 Received: by mail-ea0-f180.google.com with SMTP id c1so1983381eaa.25 for ; Sun, 20 Jan 2013 07:22:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references; bh=bvIua/v7zKlRT/ATIqvsxtIHfPSKvltFd3xj0ci49Lo=; b=mTZT8Ce1Mu+b4sKhiEOSF76LGaWyGtt1KZ68zOgIM++Z/220cNkGwFhRnSX6D/fSnN NIk8DVXMMcRwzuwK31KgARDeNfIagRFAO1b3HI1RsBKmCePiiY5Ue/8e6+fNVU8odNI9 j37jvKXI+9xMt5Wu/84I8+PsdGAmQjVX2OuVyuu3A2VyO7snErHubxJ91/7jMXl9nEyx VojLcaL16b8Uvy6VplyGWzfC6MP5BiSYtkLO903e17cC+bWGU8baj2OZRWqhNm+aeMST dWaPI9Ce/dtqAKuwz/qc2PlyXt46S8oAG8KTqULprMZfMggz6BvjF4XjiUG7cRRLMZ0Y ZckQ== X-Received: by 10.14.215.197 with SMTP id e45mr50316736eep.0.1358695368930; Sun, 20 Jan 2013 07:22:48 -0800 (PST) Received: from localhost ([109.110.76.247]) by mx.google.com with ESMTPS id w44sm17826829eep.6.2013.01.20.07.22.47 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Sun, 20 Jan 2013 07:22:48 -0800 (PST) From: Ilya Dryomov To: linux-btrfs@vger.kernel.org Cc: Chris Mason , Stefan Behrens , idryomov@gmail.com Subject: [PATCH 5/5] Btrfs: reorder locks and sanity checks in btrfs_ioctl_defrag Date: Sun, 20 Jan 2013 17:22:32 +0200 Message-Id: <1358695352-7140-6-git-send-email-idryomov@gmail.com> X-Mailer: git-send-email 1.7.9.1 In-Reply-To: <1358695352-7140-1-git-send-email-idryomov@gmail.com> References: <1358695352-7140-1-git-send-email-idryomov@gmail.com> Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Operation-specific check (whether subvol is readonly or not) should go after the mutual exclusiveness check. Signed-off-by: Ilya Dryomov --- fs/btrfs/ioctl.c | 17 +++++++++-------- 1 files changed, 9 insertions(+), 8 deletions(-) diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c index 9c079dd..f198d5d 100644 --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c @@ -2187,19 +2187,20 @@ static int btrfs_ioctl_defrag(struct file *file, void __user *argp) struct btrfs_ioctl_defrag_range_args *range; int ret; - if (btrfs_root_readonly(root)) - return -EROFS; + ret = mnt_want_write_file(file); + if (ret) + return ret; if (atomic_xchg(&root->fs_info->mutually_exclusive_operation_running, 1)) { pr_info("btrfs: dev add/delete/balance/replace/resize operation in progress\n"); + mnt_drop_write_file(file); return -EINVAL; } - ret = mnt_want_write_file(file); - if (ret) { - atomic_set(&root->fs_info->mutually_exclusive_operation_running, - 0); - return ret; + + if (btrfs_root_readonly(root)) { + ret = -EROFS; + goto out; } switch (inode->i_mode & S_IFMT) { @@ -2251,8 +2252,8 @@ static int btrfs_ioctl_defrag(struct file *file, void __user *argp) ret = -EINVAL; } out: - mnt_drop_write_file(file); atomic_set(&root->fs_info->mutually_exclusive_operation_running, 0); + mnt_drop_write_file(file); return ret; }