From 726ac67c555e288097d47906fbf6e36988c889f5 Mon Sep 17 00:00:00 2001 From: Niklas Cassel Date: Thu, 17 Sep 2020 13:16:10 +0000 Subject: [PATCH] nvme: use the most appropriate is_active() function There are two different is_active() functions. spdk_nvme_ctrlr_is_active_ns() which iterates through the active_ns_list, and spdk_nvme_ns_is_active(), which simply checks the nsdata. There is an event callback that refreshes active_ns_list when a relevant events has occured. In nvme_ns_construct(), nvme_ctrlr_identify_ns() has just been called, so we know that nsdata is as fresh as possible. Hence, there is no reason to iterate through a less fresh active_ns_list. Since we know that the nvme_ctrlr_identify_ns() call was done through the same controller, we also know that the active/inactive is from the perspective of the correct controller, so that is not a reason to use the less efficient is_active() function. Signed-off-by: Niklas Cassel Change-Id: I185f59b53e16e70163e33a3909f4b55ebf631cc4 Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/4293 Reviewed-by: Jim Harris Reviewed-by: Changpeng Liu Tested-by: SPDK CI Jenkins --- lib/nvme/nvme_ns.c | 2 +- test/unit/lib/nvme/nvme_ns.c/nvme_ns_ut.c | 3 --- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/lib/nvme/nvme_ns.c b/lib/nvme/nvme_ns.c index 0d2c3bacf..749b26592 100644 --- a/lib/nvme/nvme_ns.c +++ b/lib/nvme/nvme_ns.c @@ -413,7 +413,7 @@ int nvme_ns_construct(struct spdk_nvme_ns *ns, uint32_t id, } /* skip Identify NS ID Descriptor List for inactive NS */ - if (!spdk_nvme_ctrlr_is_active_ns(ctrlr, id)) { + if (!spdk_nvme_ns_is_active(ns)) { return 0; } diff --git a/test/unit/lib/nvme/nvme_ns.c/nvme_ns_ut.c b/test/unit/lib/nvme/nvme_ns.c/nvme_ns_ut.c index 954af366d..e642779a9 100644 --- a/test/unit/lib/nvme/nvme_ns.c/nvme_ns_ut.c +++ b/test/unit/lib/nvme/nvme_ns.c/nvme_ns_ut.c @@ -46,9 +46,6 @@ DEFINE_STUB(nvme_wait_for_completion_robust_lock, int, struct nvme_completion_poll_status *status, pthread_mutex_t *robust_mutex), 0); -DEFINE_STUB(spdk_nvme_ctrlr_is_active_ns, bool, - (struct spdk_nvme_ctrlr *ctrlr, uint32_t nsid), 1); - int nvme_ctrlr_cmd_identify(struct spdk_nvme_ctrlr *ctrlr, uint8_t cns, uint16_t cntid, uint32_t nsid, void *payload, size_t payload_size,