nvmf: Add some accessors for subsystem data

This is a step toward abstracting away the definition
of the subsystem.

Change-Id: I88b2aa107b27152620f51a1ca2a153792b4c85e9
Signed-off-by: Ben Walker <benjamin.walker@intel.com>
This commit is contained in:
Ben Walker 2016-10-10 10:25:01 -07:00 committed by Jim Harris
parent f1017d7769
commit 3cbed2ed86
7 changed files with 56 additions and 26 deletions

View File

@ -59,7 +59,7 @@
#define ACCEPT_TIMEOUT_US 1000 /* 1ms */ #define ACCEPT_TIMEOUT_US 1000 /* 1ms */
struct spdk_nvmf_probe_ctx { struct spdk_nvmf_probe_ctx {
struct spdk_nvmf_subsystem *subsystem; struct nvmf_tgt_subsystem *app_subsystem;
bool any; bool any;
bool found; bool found;
struct spdk_pci_addr pci_addr; 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]; char path[MAX_STRING_LEN];
int numa_node = -1; 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, ctrlr,
probe_info->pci_addr.domain, probe_info->pci_addr.domain,
probe_info->pci_addr.bus, probe_info->pci_addr.bus,
probe_info->pci_addr.dev, probe_info->pci_addr.dev,
probe_info->pci_addr.func, 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", snprintf(path, sizeof(path), "/sys/bus/pci/devices/%04x:%02x:%02x.%1u/numa_node",
probe_info->pci_addr.domain, 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); numa_node = spdk_get_numa_node_value(path);
if (numa_node >= 0) { if (numa_node >= 0) {
/* Running subsystem and NVMe device is on the same socket or not */ /* 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 " SPDK_WARNLOG("Subsystem %s is configured to run on a CPU core belonging "
"to a different NUMA node than the associated NVMe device. " "to a different NUMA node than the associated NVMe device. "
"This may result in reduced performance.\n", "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) { if (rc < 0) {
SPDK_ERRLOG("Failed to add controller to subsystem\n"); 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); numa_node = spdk_get_ifaddr_numa_node(traddr);
if (numa_node >= 0) { 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 " SPDK_WARNLOG("Subsystem %s is configured to run on a CPU core belonging "
"to a different NUMA node than the associated NIC. " "to a different NUMA node than the associated NIC. "
"This may result in reduced performance.\n", "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); spdk_nvmf_subsystem_add_listener(subsystem, transport, traddr, trsvcid);
@ -542,7 +542,7 @@ spdk_nvmf_parse_subsystem(struct spdk_conf_section *sp)
return -1; return -1;
} }
ctx.subsystem = subsystem; ctx.app_subsystem = app_subsys;
ctx.found = false; ctx.found = false;
if (strcmp(bdf, "*") == 0) { if (strcmp(bdf, "*") == 0) {
ctx.any = true; ctx.any = true;
@ -740,7 +740,7 @@ spdk_nvmf_parse_subsystem_for_rpc(const char *name,
return -1; return -1;
} }
ctx.subsystem = subsystem; ctx.app_subsystem = app_subsys;
ctx.found = false; ctx.found = false;
if (strcmp(bdf, "*") == 0) { if (strcmp(bdf, "*") == 0) {
ctx.any = true; ctx.any = true;

View File

@ -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_int32(w, tgt_subsystem->lcore);
spdk_json_write_name(w, "nqn"); spdk_json_write_name(w, "nqn");
spdk_json_write_string(w, subsystem->subnqn); spdk_json_write_string(w, spdk_nvmf_subsystem_get_nqn(subsystem));
if (subsystem->subtype == SPDK_NVMF_SUBTYPE_NVME) { if (spdk_nvmf_subsystem_get_type(subsystem) == SPDK_NVMF_SUBTYPE_NVME) {
spdk_json_write_name(w, "mode"); 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"); spdk_json_write_string(w, "direct");
} else { } else {
spdk_json_write_string(w, "virtual"); spdk_json_write_string(w, "virtual");
} }
} }
spdk_json_write_name(w, "subtype"); 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"); spdk_json_write_string(w, "NVMe");
} else { } else {
spdk_json_write_string(w, "Discovery"); 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); spdk_json_write_array_end(w);
if (subsystem->subtype == SPDK_NVMF_SUBTYPE_NVME) { if (spdk_nvmf_subsystem_get_type(subsystem) == SPDK_NVMF_SUBTYPE_NVME) {
if (subsystem->mode == NVMF_SUBSYSTEM_MODE_DIRECT) { if (spdk_nvmf_subsystem_get_mode(subsystem) == NVMF_SUBSYSTEM_MODE_DIRECT) {
char pci_str[20]; char pci_str[20];
snprintf(pci_str, sizeof(pci_str), "%04x:%02x:%02x.%x", snprintf(pci_str, sizeof(pci_str), "%04x:%02x:%02x.%x",

View File

@ -87,8 +87,8 @@ nvmf_tgt_delete_subsystem(struct nvmf_tgt_subsystem *app_subsys)
struct spdk_event *event; struct spdk_event *event;
int i; int i;
if (subsystem->subtype == SPDK_NVMF_SUBTYPE_NVME && if (spdk_nvmf_subsystem_get_type(subsystem) == SPDK_NVMF_SUBTYPE_NVME &&
subsystem->mode == NVMF_SUBSYSTEM_MODE_VIRTUAL) { spdk_nvmf_subsystem_get_mode(subsystem) == NVMF_SUBSYSTEM_MODE_VIRTUAL) {
for (i = 0; i < subsystem->dev.virt.ns_count; i++) { for (i = 0; i < subsystem->dev.virt.ns_count; i++) {
spdk_put_io_channel(subsystem->dev.virt.ch[i]); spdk_put_io_channel(subsystem->dev.virt.ch[i]);
subsystem->dev.virt.ch[i] = NULL; subsystem->dev.virt.ch[i] = NULL;

View File

@ -158,8 +158,8 @@ struct spdk_nvmf_subsystem {
TAILQ_ENTRY(spdk_nvmf_subsystem) entries; TAILQ_ENTRY(spdk_nvmf_subsystem) entries;
}; };
struct spdk_nvmf_subsystem *spdk_nvmf_create_subsystem(const char *name, struct spdk_nvmf_subsystem *spdk_nvmf_create_subsystem(const char *nqn,
enum spdk_nvmf_subtype subtype, enum spdk_nvmf_subtype type,
enum spdk_nvmf_subsystem_mode mode, enum spdk_nvmf_subsystem_mode mode,
void *cb_ctx, void *cb_ctx,
spdk_nvmf_subsystem_connect_fn connect_cb, 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); 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 struct spdk_nvmf_transport *spdk_nvmf_transport_get(const char *name);
const char *spdk_nvmf_transport_get_name(const struct spdk_nvmf_transport *transport); const char *spdk_nvmf_transport_get_name(const struct spdk_nvmf_transport *transport);

View File

@ -117,8 +117,8 @@ spdk_nvmf_valid_nqn(const char *nqn)
} }
struct spdk_nvmf_subsystem * struct spdk_nvmf_subsystem *
spdk_nvmf_create_subsystem(const char *name, spdk_nvmf_create_subsystem(const char *nqn,
enum spdk_nvmf_subtype subtype, enum spdk_nvmf_subtype type,
enum spdk_nvmf_subsystem_mode mode, enum spdk_nvmf_subsystem_mode mode,
void *cb_ctx, void *cb_ctx,
spdk_nvmf_subsystem_connect_fn connect_cb, spdk_nvmf_subsystem_connect_fn connect_cb,
@ -126,7 +126,7 @@ spdk_nvmf_create_subsystem(const char *name,
{ {
struct spdk_nvmf_subsystem *subsystem; struct spdk_nvmf_subsystem *subsystem;
if (!spdk_nvmf_valid_nqn(name)) { if (!spdk_nvmf_valid_nqn(nqn)) {
return NULL; return NULL;
} }
@ -135,12 +135,12 @@ spdk_nvmf_create_subsystem(const char *name,
return NULL; return NULL;
} }
subsystem->subtype = subtype; subsystem->subtype = type;
subsystem->mode = mode; subsystem->mode = mode;
subsystem->cb_ctx = cb_ctx; subsystem->cb_ctx = cb_ctx;
subsystem->connect_cb = connect_cb; subsystem->connect_cb = connect_cb;
subsystem->disconnect_cb = disconnect_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->listen_addrs);
TAILQ_INIT(&subsystem->hosts); TAILQ_INIT(&subsystem->hosts);
TAILQ_INIT(&subsystem->sessions); TAILQ_INIT(&subsystem->sessions);
@ -338,3 +338,27 @@ spdk_nvmf_subsystem_set_sn(struct spdk_nvmf_subsystem *subsystem, const char *sn
return 0; 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;
}

View File

@ -38,6 +38,8 @@
#include "spdk/nvmf.h" #include "spdk/nvmf.h"
struct spdk_nvmf_listen_addr;
struct spdk_nvmf_transport { struct spdk_nvmf_transport {
/** /**
* Name of the transport. * Name of the transport.

View File

@ -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", 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; session->vcdata.oncs.dsm = 1;
} }