linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Arne Jansen <sensille@gmx.net>
To: chris.mason@oracle.com, linux-btrfs@vger.kernel.org
Cc: andi@firstfloor.org
Subject: [PATCH] Btrfs scrub: revised locking scheme
Date: Thu, 17 Mar 2011 19:56:55 +0100	[thread overview]
Message-ID: <1300388215-10930-1-git-send-email-sensille@gmx.net> (raw)

This patch removes unnecessary mutex locks around
scrubs_running.

Signed-off-by: Arne Jansen <sensille@gmx.net>
---
 fs/btrfs/scrub.c |   12 +++---------
 1 files changed, 3 insertions(+), 9 deletions(-)

diff --git a/fs/btrfs/scrub.c b/fs/btrfs/scrub.c
index ee7671f..85a4d4b 100644
--- a/fs/btrfs/scrub.c
+++ b/fs/btrfs/scrub.c
@@ -249,10 +249,10 @@ static void scrub_recheck_error(struct scrub_bio *sbio, int ix)
 	 * while we're in here we do not want the transaction to commit.
 	 * To prevent it, we increment scrubs_running. scrub_pause will
 	 * have to wait until we're finished
+	 * we can safely increment scrubs_running here, because we're
+	 * in the context of the original bio which is still marked in_flight
 	 */
-	mutex_lock(&fs_info->scrub_lock);
 	atomic_inc(&fs_info->scrubs_running);
-	mutex_unlock(&fs_info->scrub_lock);
 
 	fixup = kzalloc(sizeof(*fixup), GFP_NOFS);
 	if (!fixup)
@@ -311,9 +311,7 @@ malloc_error:
 	spin_lock(&sdev->stat_lock);
 	++sdev->stat.malloc_errors;
 	spin_unlock(&sdev->stat_lock);
-	mutex_lock(&fs_info->scrub_lock);
 	atomic_dec(&fs_info->scrubs_running);
-	mutex_unlock(&fs_info->scrub_lock);
 	wake_up(&fs_info->scrub_pause_wait);
 }
 
@@ -371,9 +369,7 @@ static void scrub_fixup_worker(scrub_work_t *work)
 	__free_page(fixup->bio->bi_io_vec[0].bv_page);
 	bio_put(fixup->bio);
 
-	mutex_lock(&fs_info->scrub_lock);
 	atomic_dec(&fs_info->scrubs_running);
-	mutex_unlock(&fs_info->scrub_lock);
 	wake_up(&fs_info->scrub_pause_wait);
 
 	kfree(fixup);
@@ -1328,7 +1324,7 @@ int btrfs_scrub_dev(struct btrfs_root *root, u64 devid, u64 start, u64 end,
 
 	mutex_lock(&root->fs_info->fs_devices->device_list_mutex);
 	dev = btrfs_find_device(root, devid, NULL, NULL);
-	if (!dev || dev->missing) {
+	if (!dev || dev->missing || !dev->in_fs_metadata) {
 		mutex_unlock(&root->fs_info->fs_devices->device_list_mutex);
 		scrub_workers_put(root);
 		return -ENODEV;
@@ -1361,9 +1357,7 @@ int btrfs_scrub_dev(struct btrfs_root *root, u64 devid, u64 start, u64 end,
 
 	wait_event(sdev->list_wait, atomic_read(&sdev->in_flight) == 0);
 
-	mutex_lock(&fs_info->scrub_lock);
 	atomic_dec(&fs_info->scrubs_running);
-	mutex_unlock(&fs_info->scrub_lock);
 	wake_up(&fs_info->scrub_pause_wait);
 
 	if (progress)
-- 
1.7.3.4


                 reply	other threads:[~2011-03-17 18:56 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=1300388215-10930-1-git-send-email-sensille@gmx.net \
    --to=sensille@gmx.net \
    --cc=andi@firstfloor.org \
    --cc=chris.mason@oracle.com \
    --cc=linux-btrfs@vger.kernel.org \
    /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).