cuse: refactor retrieving cuse_device to separate function
This patch adds nvme_cuse_get_cuse_ctrlr_device() and
nvme_cuse_get_cuse_ns_device that returns
struct cuse_device of a given nvme controller or namespace.
Similar iteration was used in two places so they were
replaced accordingly.
Next patch will add third.
Signed-off-by: Tomasz Zawadzki <tomasz.zawadzki@intel.com>
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/1918 (master)
(cherry picked from commit 15a5018067
)
Change-Id: I25ada843a59c632fe330263a65456d25c5ccf4cc
Signed-off-by: Tomasz Zawadzki <tomasz.zawadzki@intel.com>
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/2155
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
This commit is contained in:
parent
930d91f479
commit
d42b332ae6
@ -877,10 +877,10 @@ err2:
|
|||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static struct cuse_device *
|
||||||
nvme_cuse_stop(struct spdk_nvme_ctrlr *ctrlr)
|
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) {
|
TAILQ_FOREACH(ctrlr_device, &g_ctrlr_ctx_head, tailq) {
|
||||||
if (ctrlr_device->ctrlr == ctrlr) {
|
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) {
|
if (!ctrlr_device) {
|
||||||
SPDK_ERRLOG("Cannot find associated CUSE device\n");
|
SPDK_ERRLOG("Cannot find associated CUSE device\n");
|
||||||
return;
|
return;
|
||||||
@ -932,16 +961,7 @@ spdk_nvme_cuse_get_ctrlr_name(struct spdk_nvme_ctrlr *ctrlr)
|
|||||||
{
|
{
|
||||||
struct cuse_device *ctrlr_device;
|
struct cuse_device *ctrlr_device;
|
||||||
|
|
||||||
if (TAILQ_EMPTY(&g_ctrlr_ctx_head)) {
|
ctrlr_device = nvme_cuse_get_cuse_ctrlr_device(ctrlr);
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
TAILQ_FOREACH(ctrlr_device, &g_ctrlr_ctx_head, tailq) {
|
|
||||||
if (ctrlr_device->ctrlr == ctrlr) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!ctrlr_device) {
|
if (!ctrlr_device) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -953,28 +973,8 @@ char *
|
|||||||
spdk_nvme_cuse_get_ns_name(struct spdk_nvme_ctrlr *ctrlr, uint32_t nsid)
|
spdk_nvme_cuse_get_ns_name(struct spdk_nvme_ctrlr *ctrlr, uint32_t nsid)
|
||||||
{
|
{
|
||||||
struct cuse_device *ns_device;
|
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) {
|
if (!ns_device) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user