From: Anand Jain <anand.jain@oracle.com>
To: linux-btrfs@vger.kernel.org
Subject: [PATCH v2 1/3] btrfs: scrub: maintain the unlock order in scrub thread
Date: Thu, 29 Nov 2018 17:25:11 +0800 [thread overview]
Message-ID: <1543483513-16724-2-git-send-email-anand.jain@oracle.com> (raw)
In-Reply-To: <1543483513-16724-1-git-send-email-anand.jain@oracle.com>
The device_list_mutex and scrub_lock creates a nested locks in
btrfs_scrub_dev().
During lock the order is device_list_mutex and then scrub_lock, and during
unlock, the order is device_list_mutex and then scrub_lock.
Fix this to the lock order of scrub_lock and then device_list_mutex.
Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
v1->v2: change the order of lock acquire first scrub_lock and then
device_list_mutex, which matches with the order of unlock.
The extra line which are now in the scrub_lock are ok to be
under the scrub_lock.
fs/btrfs/scrub.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/fs/btrfs/scrub.c b/fs/btrfs/scrub.c
index 902819d3cf41..a9d6fc3b01d4 100644
--- a/fs/btrfs/scrub.c
+++ b/fs/btrfs/scrub.c
@@ -3813,28 +3813,29 @@ int btrfs_scrub_dev(struct btrfs_fs_info *fs_info, u64 devid, u64 start,
return -EINVAL;
}
-
+ mutex_lock(&fs_info->scrub_lock);
mutex_lock(&fs_info->fs_devices->device_list_mutex);
dev = btrfs_find_device(fs_info, devid, NULL, NULL);
if (!dev || (test_bit(BTRFS_DEV_STATE_MISSING, &dev->dev_state) &&
!is_dev_replace)) {
mutex_unlock(&fs_info->fs_devices->device_list_mutex);
+ mutex_unlock(&fs_info->scrub_lock);
return -ENODEV;
}
if (!is_dev_replace && !readonly &&
!test_bit(BTRFS_DEV_STATE_WRITEABLE, &dev->dev_state)) {
mutex_unlock(&fs_info->fs_devices->device_list_mutex);
+ mutex_unlock(&fs_info->scrub_lock);
btrfs_err_in_rcu(fs_info, "scrub: device %s is not writable",
rcu_str_deref(dev->name));
return -EROFS;
}
- mutex_lock(&fs_info->scrub_lock);
if (!test_bit(BTRFS_DEV_STATE_IN_FS_METADATA, &dev->dev_state) ||
test_bit(BTRFS_DEV_STATE_REPLACE_TGT, &dev->dev_state)) {
- mutex_unlock(&fs_info->scrub_lock);
mutex_unlock(&fs_info->fs_devices->device_list_mutex);
+ mutex_unlock(&fs_info->scrub_lock);
return -EIO;
}
@@ -3843,23 +3844,23 @@ int btrfs_scrub_dev(struct btrfs_fs_info *fs_info, u64 devid, u64 start,
(!is_dev_replace &&
btrfs_dev_replace_is_ongoing(&fs_info->dev_replace))) {
btrfs_dev_replace_read_unlock(&fs_info->dev_replace);
- mutex_unlock(&fs_info->scrub_lock);
mutex_unlock(&fs_info->fs_devices->device_list_mutex);
+ mutex_unlock(&fs_info->scrub_lock);
return -EINPROGRESS;
}
btrfs_dev_replace_read_unlock(&fs_info->dev_replace);
ret = scrub_workers_get(fs_info, is_dev_replace);
if (ret) {
- mutex_unlock(&fs_info->scrub_lock);
mutex_unlock(&fs_info->fs_devices->device_list_mutex);
+ mutex_unlock(&fs_info->scrub_lock);
return ret;
}
sctx = scrub_setup_ctx(dev, is_dev_replace);
if (IS_ERR(sctx)) {
- mutex_unlock(&fs_info->scrub_lock);
mutex_unlock(&fs_info->fs_devices->device_list_mutex);
+ mutex_unlock(&fs_info->scrub_lock);
scrub_workers_put(fs_info);
return PTR_ERR(sctx);
}
--
1.8.3.1
next prev parent reply other threads:[~2018-11-29 9:25 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-11-29 9:25 [PATCH v2 0/3] btrfs: scrub: fix scrub_lock Anand Jain
2018-11-29 9:25 ` Anand Jain [this message]
2018-11-29 10:36 ` [PATCH v2 1/3] btrfs: scrub: maintain the unlock order in scrub thread Filipe Manana
2018-11-30 1:00 ` Anand Jain
2018-11-29 9:25 ` [PATCH v2 2/3] btrfs: scrub: fix circular locking dependency warning Anand Jain
2018-11-29 9:25 ` [PATCH v2 3/3] btrfs: scrub: add scrub_lock lockdep check in scrub_workers_get Anand Jain
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=1543483513-16724-2-git-send-email-anand.jain@oracle.com \
--to=anand.jain@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).