From 93b53c0268dab8d20381dfec732c55bcaefe7bd6 Mon Sep 17 00:00:00 2001 From: Mike Gerdts Date: Fri, 28 Oct 2022 11:09:06 -0500 Subject: [PATCH] bdev: call bdev_ok_to_examine() once per examine This calls bdev_ok_to_examine() once per bdev_examine(). Prior to this commit, bdev_ok_to_examine() may be called up to twice per bdev module. The results returned by bdev_ok_to_examine() could be affected by: 1. g_bdev_opts.bdev_auto_examime changing 2. spdk_bdev_examine() being called on a particular bdev 3. An alias being added for an existing bdev It's not clear that anything good comes from racing in conditions 1 and 3. In condition 2, spdk_bdev_examine() calls bdev_examine(), so any required examine_config() and examine_disk() calls are still made, just now with less of a race with the previous invocation of spdk_examine_confg(). Signed-off-by: Mike Gerdts Change-Id: I496fc44fd74693837d6b449d7fa60f58f9dbf36f Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/15284 Tested-by: SPDK CI Jenkins Reviewed-by: Jim Harris Reviewed-by: Shuhei Matsumoto Community-CI: Mellanox Build Bot --- lib/bdev/bdev.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/bdev/bdev.c b/lib/bdev/bdev.c index 80e642531..1bf922e71 100644 --- a/lib/bdev/bdev.c +++ b/lib/bdev/bdev.c @@ -646,8 +646,12 @@ bdev_examine(struct spdk_bdev *bdev) struct spdk_bdev_module *module; uint32_t action; + if (!bdev_ok_to_examine(bdev)) { + return; + } + TAILQ_FOREACH(module, &g_bdev_mgr.bdev_modules, internal.tailq) { - if (module->examine_config && bdev_ok_to_examine(bdev)) { + if (module->examine_config) { spdk_spin_lock(&module->internal.spinlock); action = module->internal.action_in_progress; module->internal.action_in_progress++; @@ -661,7 +665,7 @@ bdev_examine(struct spdk_bdev *bdev) } module = bdev->internal.claim_module; - if (module != NULL && bdev_ok_to_examine(bdev)) { + if (module != NULL) { if (module->examine_disk) { spdk_spin_lock(&module->internal.spinlock); module->internal.action_in_progress++; @@ -672,7 +676,7 @@ bdev_examine(struct spdk_bdev *bdev) } TAILQ_FOREACH(module, &g_bdev_mgr.bdev_modules, internal.tailq) { - if (module->examine_disk && bdev_ok_to_examine(bdev)) { + if (module->examine_disk) { spdk_spin_lock(&module->internal.spinlock); module->internal.action_in_progress++; spdk_spin_unlock(&module->internal.spinlock);