diff --git a/app/nvmf_tgt/conf.c b/app/nvmf_tgt/conf.c index 74ccbd24a..b8f8cdef4 100644 --- a/app/nvmf_tgt/conf.c +++ b/app/nvmf_tgt/conf.c @@ -59,7 +59,7 @@ #define ACCEPT_TIMEOUT_US 1000 /* 1ms */ struct spdk_nvmf_probe_ctx { - struct spdk_nvmf_subsystem *subsystem; + struct nvmf_tgt_subsystem *app_subsystem; bool any; bool found; struct spdk_pci_addr pci_addr; @@ -361,13 +361,13 @@ attach_cb(void *cb_ctx, const struct spdk_nvme_probe_info *probe_info, char path[MAX_STRING_LEN]; int numa_node = -1; - SPDK_NOTICELOG("Attaching NVMe device %p at %x:%x:%x.%x to subsystem %p\n", + SPDK_NOTICELOG("Attaching NVMe device %p at %x:%x:%x.%x to subsystem %s\n", ctrlr, probe_info->pci_addr.domain, probe_info->pci_addr.bus, probe_info->pci_addr.dev, probe_info->pci_addr.func, - ctx->subsystem); + spdk_nvmf_subsystem_get_nqn(ctx->app_subsystem->subsystem)); snprintf(path, sizeof(path), "/sys/bus/pci/devices/%04x:%02x:%02x.%1u/numa_node", probe_info->pci_addr.domain, @@ -378,15 +378,15 @@ attach_cb(void *cb_ctx, const struct spdk_nvme_probe_info *probe_info, numa_node = spdk_get_numa_node_value(path); if (numa_node >= 0) { /* Running subsystem and NVMe device is on the same socket or not */ - if (rte_lcore_to_socket_id(ctx->subsystem->lcore) != (unsigned)numa_node) { + if (rte_lcore_to_socket_id(ctx->app_subsystem->lcore) != (unsigned)numa_node) { SPDK_WARNLOG("Subsystem %s is configured to run on a CPU core belonging " "to a different NUMA node than the associated NVMe device. " "This may result in reduced performance.\n", - ctx->subsystem->subnqn); + spdk_nvmf_subsystem_get_nqn(ctx->app_subsystem->subsystem)); } } - rc = nvmf_subsystem_add_ctrlr(ctx->subsystem, ctrlr, &probe_info->pci_addr); + rc = nvmf_subsystem_add_ctrlr(ctx->app_subsystem->subsystem, ctrlr, &probe_info->pci_addr); if (rc < 0) { SPDK_ERRLOG("Failed to add controller to subsystem\n"); } @@ -506,11 +506,11 @@ spdk_nvmf_parse_subsystem(struct spdk_conf_section *sp) numa_node = spdk_get_ifaddr_numa_node(traddr); if (numa_node >= 0) { - if (rte_lcore_to_socket_id(subsystem->lcore) != (unsigned)numa_node) { + if (rte_lcore_to_socket_id(app_subsys->lcore) != (unsigned)numa_node) { SPDK_WARNLOG("Subsystem %s is configured to run on a CPU core belonging " "to a different NUMA node than the associated NIC. " "This may result in reduced performance.\n", - subsystem->subnqn); + spdk_nvmf_subsystem_get_nqn(app_subsys->subsystem)); } } spdk_nvmf_subsystem_add_listener(subsystem, transport, traddr, trsvcid); @@ -542,7 +542,7 @@ spdk_nvmf_parse_subsystem(struct spdk_conf_section *sp) return -1; } - ctx.subsystem = subsystem; + ctx.app_subsystem = app_subsys; ctx.found = false; if (strcmp(bdf, "*") == 0) { ctx.any = true; @@ -740,7 +740,7 @@ spdk_nvmf_parse_subsystem_for_rpc(const char *name, return -1; } - ctx.subsystem = subsystem; + ctx.app_subsystem = app_subsys; ctx.found = false; if (strcmp(bdf, "*") == 0) { ctx.any = true; diff --git a/app/nvmf_tgt/nvmf_rpc.c b/app/nvmf_tgt/nvmf_rpc.c index 711e8e755..13b28f5fc 100644 --- a/app/nvmf_tgt/nvmf_rpc.c +++ b/app/nvmf_tgt/nvmf_rpc.c @@ -56,17 +56,17 @@ dump_nvmf_subsystem(struct spdk_json_write_ctx *w, struct nvmf_tgt_subsystem *tg spdk_json_write_int32(w, tgt_subsystem->lcore); spdk_json_write_name(w, "nqn"); - spdk_json_write_string(w, subsystem->subnqn); - if (subsystem->subtype == SPDK_NVMF_SUBTYPE_NVME) { + spdk_json_write_string(w, spdk_nvmf_subsystem_get_nqn(subsystem)); + if (spdk_nvmf_subsystem_get_type(subsystem) == SPDK_NVMF_SUBTYPE_NVME) { spdk_json_write_name(w, "mode"); - if (subsystem->mode == NVMF_SUBSYSTEM_MODE_DIRECT) { + if (spdk_nvmf_subsystem_get_mode(subsystem) == NVMF_SUBSYSTEM_MODE_DIRECT) { spdk_json_write_string(w, "direct"); } else { spdk_json_write_string(w, "virtual"); } } spdk_json_write_name(w, "subtype"); - if (subsystem->subtype == SPDK_NVMF_SUBTYPE_NVME) { + if (spdk_nvmf_subsystem_get_type(subsystem) == SPDK_NVMF_SUBTYPE_NVME) { spdk_json_write_string(w, "NVMe"); } else { spdk_json_write_string(w, "Discovery"); @@ -98,8 +98,8 @@ dump_nvmf_subsystem(struct spdk_json_write_ctx *w, struct nvmf_tgt_subsystem *tg } spdk_json_write_array_end(w); - if (subsystem->subtype == SPDK_NVMF_SUBTYPE_NVME) { - if (subsystem->mode == NVMF_SUBSYSTEM_MODE_DIRECT) { + if (spdk_nvmf_subsystem_get_type(subsystem) == SPDK_NVMF_SUBTYPE_NVME) { + if (spdk_nvmf_subsystem_get_mode(subsystem) == NVMF_SUBSYSTEM_MODE_DIRECT) { char pci_str[20]; snprintf(pci_str, sizeof(pci_str), "%04x:%02x:%02x.%x", diff --git a/app/nvmf_tgt/nvmf_tgt.c b/app/nvmf_tgt/nvmf_tgt.c index 5637743d2..8394d91b9 100644 --- a/app/nvmf_tgt/nvmf_tgt.c +++ b/app/nvmf_tgt/nvmf_tgt.c @@ -87,8 +87,8 @@ nvmf_tgt_delete_subsystem(struct nvmf_tgt_subsystem *app_subsys) struct spdk_event *event; int i; - if (subsystem->subtype == SPDK_NVMF_SUBTYPE_NVME && - subsystem->mode == NVMF_SUBSYSTEM_MODE_VIRTUAL) { + if (spdk_nvmf_subsystem_get_type(subsystem) == SPDK_NVMF_SUBTYPE_NVME && + spdk_nvmf_subsystem_get_mode(subsystem) == NVMF_SUBSYSTEM_MODE_VIRTUAL) { for (i = 0; i < subsystem->dev.virt.ns_count; i++) { spdk_put_io_channel(subsystem->dev.virt.ch[i]); subsystem->dev.virt.ch[i] = NULL; diff --git a/include/spdk/nvmf.h b/include/spdk/nvmf.h index e08eb6c99..72614bf7f 100644 --- a/include/spdk/nvmf.h +++ b/include/spdk/nvmf.h @@ -158,8 +158,8 @@ struct spdk_nvmf_subsystem { TAILQ_ENTRY(spdk_nvmf_subsystem) entries; }; -struct spdk_nvmf_subsystem *spdk_nvmf_create_subsystem(const char *name, - enum spdk_nvmf_subtype subtype, +struct spdk_nvmf_subsystem *spdk_nvmf_create_subsystem(const char *nqn, + enum spdk_nvmf_subtype type, enum spdk_nvmf_subsystem_mode mode, void *cb_ctx, spdk_nvmf_subsystem_connect_fn connect_cb, @@ -190,6 +190,10 @@ spdk_nvmf_subsystem_add_ns(struct spdk_nvmf_subsystem *subsystem, struct spdk_bd int spdk_nvmf_subsystem_set_sn(struct spdk_nvmf_subsystem *subsystem, const char *sn); +const char *spdk_nvmf_subsystem_get_nqn(struct spdk_nvmf_subsystem *subsystem); +enum spdk_nvmf_subtype spdk_nvmf_subsystem_get_type(struct spdk_nvmf_subsystem *subsystem); +enum spdk_nvmf_subsystem_mode spdk_nvmf_subsystem_get_mode(struct spdk_nvmf_subsystem *subsystem); + const struct spdk_nvmf_transport *spdk_nvmf_transport_get(const char *name); const char *spdk_nvmf_transport_get_name(const struct spdk_nvmf_transport *transport); diff --git a/lib/nvmf/subsystem.c b/lib/nvmf/subsystem.c index 49e5c815f..48e794a85 100644 --- a/lib/nvmf/subsystem.c +++ b/lib/nvmf/subsystem.c @@ -117,8 +117,8 @@ spdk_nvmf_valid_nqn(const char *nqn) } struct spdk_nvmf_subsystem * -spdk_nvmf_create_subsystem(const char *name, - enum spdk_nvmf_subtype subtype, +spdk_nvmf_create_subsystem(const char *nqn, + enum spdk_nvmf_subtype type, enum spdk_nvmf_subsystem_mode mode, void *cb_ctx, spdk_nvmf_subsystem_connect_fn connect_cb, @@ -126,7 +126,7 @@ spdk_nvmf_create_subsystem(const char *name, { struct spdk_nvmf_subsystem *subsystem; - if (!spdk_nvmf_valid_nqn(name)) { + if (!spdk_nvmf_valid_nqn(nqn)) { return NULL; } @@ -135,12 +135,12 @@ spdk_nvmf_create_subsystem(const char *name, return NULL; } - subsystem->subtype = subtype; + subsystem->subtype = type; subsystem->mode = mode; subsystem->cb_ctx = cb_ctx; subsystem->connect_cb = connect_cb; subsystem->disconnect_cb = disconnect_cb; - snprintf(subsystem->subnqn, sizeof(subsystem->subnqn), "%s", name); + snprintf(subsystem->subnqn, sizeof(subsystem->subnqn), "%s", nqn); TAILQ_INIT(&subsystem->listen_addrs); TAILQ_INIT(&subsystem->hosts); TAILQ_INIT(&subsystem->sessions); @@ -338,3 +338,27 @@ spdk_nvmf_subsystem_set_sn(struct spdk_nvmf_subsystem *subsystem, const char *sn return 0; } + +const char * +spdk_nvmf_subsystem_get_nqn(struct spdk_nvmf_subsystem *subsystem) +{ + return subsystem->subnqn; +} + +/* Workaround for astyle formatting bug */ +typedef enum spdk_nvmf_subtype nvmf_subtype_t; + +nvmf_subtype_t +spdk_nvmf_subsystem_get_type(struct spdk_nvmf_subsystem *subsystem) +{ + return subsystem->subtype; +} + +/* Workaround for astyle formatting bug */ +typedef enum spdk_nvmf_subsystem_mode nvmf_mode_t; + +nvmf_mode_t +spdk_nvmf_subsystem_get_mode(struct spdk_nvmf_subsystem *subsystem) +{ + return subsystem->mode; +} diff --git a/lib/nvmf/transport.h b/lib/nvmf/transport.h index c6fe22ae1..cd4661ba0 100644 --- a/lib/nvmf/transport.h +++ b/lib/nvmf/transport.h @@ -38,6 +38,8 @@ #include "spdk/nvmf.h" +struct spdk_nvmf_listen_addr; + struct spdk_nvmf_transport { /** * Name of the transport. diff --git a/lib/nvmf/virtual.c b/lib/nvmf/virtual.c index 6e87c2120..4538ccc35 100644 --- a/lib/nvmf/virtual.c +++ b/lib/nvmf/virtual.c @@ -76,7 +76,7 @@ static void nvmf_virtual_set_dsm(struct spdk_nvmf_session *session) } SPDK_TRACELOG(SPDK_TRACE_NVMF, "All devices in Subsystem %s support unmap - enabling DSM\n", - session->subsys->subnqn); + spdk_nvmf_subsystem_get_nqn(session->subsys)); session->vcdata.oncs.dsm = 1; }