From 45d8309e52ac620eb1802f25c9261315fa41c98e Mon Sep 17 00:00:00 2001 From: Shuhei Matsumoto Date: Mon, 29 Mar 2021 19:57:37 +0900 Subject: [PATCH] bdev/nvme: Factor out deleting secondary trid into a helper function Factor out deleting secondary trid from bdev_nvme_delete() into a helper function bdev_nvme_delete_secondary_trid(). This will make the following changes simpler. Besides, fix a typo, the case should be not 1B but 2B. Signed-off-by: Shuhei Matsumoto Change-Id: Iba21efa0d8036ed15d2743a2548df05e866089d6 Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/7123 Community-CI: Broadcom CI Community-CI: Mellanox Build Bot Tested-by: SPDK CI Jenkins Reviewed-by: Jim Harris Reviewed-by: Ben Walker Reviewed-by: Paul Luse Reviewed-by: Aleksey Marchuk --- module/bdev/nvme/bdev_nvme.c | 37 ++++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/module/bdev/nvme/bdev_nvme.c b/module/bdev/nvme/bdev_nvme.c index 86e2b16a5..a0cfc05ee 100644 --- a/module/bdev/nvme/bdev_nvme.c +++ b/module/bdev/nvme/bdev_nvme.c @@ -2356,11 +2356,32 @@ bdev_nvme_create(struct spdk_nvme_transport_id *trid, return 0; } +static int +bdev_nvme_delete_secondary_trid(struct nvme_bdev_ctrlr *nvme_bdev_ctrlr, + const struct spdk_nvme_transport_id *trid) +{ + struct nvme_bdev_ctrlr_trid *ctrlr_trid, *tmp_trid; + + if (!spdk_nvme_transport_id_compare(trid, nvme_bdev_ctrlr->connected_trid)) { + return -EBUSY; + } + + TAILQ_FOREACH_SAFE(ctrlr_trid, &nvme_bdev_ctrlr->trids, link, tmp_trid) { + if (!spdk_nvme_transport_id_compare(&ctrlr_trid->trid, trid)) { + TAILQ_REMOVE(&nvme_bdev_ctrlr->trids, ctrlr_trid, link); + free(ctrlr_trid); + return 0; + } + } + + return -ENXIO; +} + int bdev_nvme_delete(const char *name, const struct spdk_nvme_transport_id *trid) { struct nvme_bdev_ctrlr *nvme_bdev_ctrlr; - struct nvme_bdev_ctrlr_trid *ctrlr_trid, *tmp_trid; + struct nvme_bdev_ctrlr_trid *ctrlr_trid; if (name == NULL) { return -EINVAL; @@ -2386,20 +2407,12 @@ bdev_nvme_delete(const char *name, const struct spdk_nvme_transport_id *trid) return _bdev_nvme_delete(nvme_bdev_ctrlr, false); } - /* case 1B: there is an alternative path. */ + /* case 2B: there is an alternative path. */ return bdev_nvme_failover(nvme_bdev_ctrlr, true); } - /* case 3: We are not using the specified path. */ - TAILQ_FOREACH_SAFE(ctrlr_trid, &nvme_bdev_ctrlr->trids, link, tmp_trid) { - if (!spdk_nvme_transport_id_compare(&ctrlr_trid->trid, trid)) { - TAILQ_REMOVE(&nvme_bdev_ctrlr->trids, ctrlr_trid, link); - free(ctrlr_trid); - return 0; - } - } - /* case 3A: The address isn't even in the registered list. */ - return -ENXIO; + /* case 3: We are not using the specified path. */ + return bdev_nvme_delete_secondary_trid(nvme_bdev_ctrlr, trid); } static int