linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ilya Dryomov <idryomov@gmail.com>
To: linux-btrfs@vger.kernel.org
Cc: Chris Mason <chris.mason@fusionio.com>,
	Stefan Behrens <sbehrens@giantdisaster.de>,
	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	[thread overview]
Message-ID: <1358695352-7140-6-git-send-email-idryomov@gmail.com> (raw)
In-Reply-To: <1358695352-7140-1-git-send-email-idryomov@gmail.com>

Operation-specific check (whether subvol is readonly or not) should go
after the mutual exclusiveness check.

Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
---
 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;
 }
 
-- 
1.7.9.1


  parent reply	other threads:[~2013-01-20 15:22 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-01-20 15:22 [PATCH 0/5] Mutually exclusive ops fixes Ilya Dryomov
2013-01-20 15:22 ` [PATCH 1/5] Btrfs: bring back balance pause/resume logic Ilya Dryomov
2013-01-20 15:22 ` [PATCH 2/5] Btrfs: fix "mutually exclusive op is running" error code Ilya Dryomov
2013-01-20 15:22 ` [PATCH 3/5] Btrfs: fix unlock order in btrfs_ioctl_resize Ilya Dryomov
2013-01-20 15:22 ` [PATCH 4/5] Btrfs: fix unlock order in btrfs_ioctl_rm_dev Ilya Dryomov
2013-01-20 15:22 ` Ilya Dryomov [this message]
2013-01-20 15:28 ` [PATCH 0/5] Mutually exclusive ops fixes Ilya Dryomov
2013-01-21 12:25 ` David Sterba

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1358695352-7140-6-git-send-email-idryomov@gmail.com \
    --to=idryomov@gmail.com \
    --cc=chris.mason@fusionio.com \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=sbehrens@giantdisaster.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).