diff --git a/lib/nvme/nvme_cuse.c b/lib/nvme/nvme_cuse.c index 9e3ae0227..404c4b7f0 100644 --- a/lib/nvme/nvme_cuse.c +++ b/lib/nvme/nvme_cuse.c @@ -877,10 +877,10 @@ err2: return rv; } -static void -nvme_cuse_stop(struct spdk_nvme_ctrlr *ctrlr) +static struct cuse_device * +nvme_cuse_get_cuse_ctrlr_device(struct spdk_nvme_ctrlr *ctrlr) { - struct cuse_device *ctrlr_device; + struct cuse_device *ctrlr_device = NULL; TAILQ_FOREACH(ctrlr_device, &g_ctrlr_ctx_head, tailq) { if (ctrlr_device->ctrlr == ctrlr) { @@ -888,6 +888,35 @@ nvme_cuse_stop(struct spdk_nvme_ctrlr *ctrlr) } } + return ctrlr_device; +} + +static struct cuse_device * +nvme_cuse_get_cuse_ns_device(struct spdk_nvme_ctrlr *ctrlr, uint32_t nsid) +{ + struct cuse_device *ctrlr_device = NULL; + struct cuse_device *ns_device = NULL; + + ctrlr_device = nvme_cuse_get_cuse_ctrlr_device(ctrlr); + if (!ctrlr_device) { + return NULL; + } + + TAILQ_FOREACH(ns_device, &ctrlr_device->ns_devices, tailq) { + if (ns_device->nsid == nsid) { + break; + } + } + + return ns_device; +} + +static void +nvme_cuse_stop(struct spdk_nvme_ctrlr *ctrlr) +{ + struct cuse_device *ctrlr_device; + + ctrlr_device = nvme_cuse_get_cuse_ctrlr_device(ctrlr); if (!ctrlr_device) { SPDK_ERRLOG("Cannot find associated CUSE device\n"); return; @@ -932,16 +961,7 @@ spdk_nvme_cuse_get_ctrlr_name(struct spdk_nvme_ctrlr *ctrlr) { struct cuse_device *ctrlr_device; - if (TAILQ_EMPTY(&g_ctrlr_ctx_head)) { - return NULL; - } - - TAILQ_FOREACH(ctrlr_device, &g_ctrlr_ctx_head, tailq) { - if (ctrlr_device->ctrlr == ctrlr) { - break; - } - } - + ctrlr_device = nvme_cuse_get_cuse_ctrlr_device(ctrlr); if (!ctrlr_device) { return NULL; } @@ -953,28 +973,8 @@ char * spdk_nvme_cuse_get_ns_name(struct spdk_nvme_ctrlr *ctrlr, uint32_t nsid) { struct cuse_device *ns_device; - struct cuse_device *ctrlr_device; - - if (TAILQ_EMPTY(&g_ctrlr_ctx_head)) { - return NULL; - } - - TAILQ_FOREACH(ctrlr_device, &g_ctrlr_ctx_head, tailq) { - if (ctrlr_device->ctrlr == ctrlr) { - break; - } - } - - if (!ctrlr_device) { - return NULL; - } - - TAILQ_FOREACH(ns_device, &ctrlr_device->ns_devices, tailq) { - if (ns_device->nsid == nsid) { - break; - } - } + ns_device = nvme_cuse_get_cuse_ns_device(ctrlr, nsid); if (!ns_device) { return NULL; }