From patchwork Thu Mar 17 18:56:55 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arne Jansen X-Patchwork-Id: 641901 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id p2HIux8I013258 for ; Thu, 17 Mar 2011 18:56:59 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755182Ab1CQS45 (ORCPT ); Thu, 17 Mar 2011 14:56:57 -0400 Received: from mort.rzone.de ([81.169.144.234]:44103 "EHLO mort.rzone.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755068Ab1CQS44 (ORCPT ); Thu, 17 Mar 2011 14:56:56 -0400 Received: from gargravarr.store (gargravarr.store [192.168.42.236]) by mort.rzone.de (Postfix) with ESMTP id 59372E0F; Thu, 17 Mar 2011 19:56:55 +0100 (MET) Received: by gargravarr.store (Postfix, from userid 32466) id 4D9ECC075; Thu, 17 Mar 2011 19:56:55 +0100 (CET) From: Arne Jansen 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 Message-Id: <1300388215-10930-1-git-send-email-sensille@gmx.net> X-Mailer: git-send-email 1.7.3.4 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Thu, 17 Mar 2011 18:56:59 +0000 (UTC) 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)