Commit 3cbed2ed authored by Ben Walker's avatar Ben Walker Committed by Jim Harris
Browse files

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: default avatarBen Walker <benjamin.walker@intel.com>
parent f1017d77
Loading
Loading
Loading
Loading
+10 −10
Original line number Diff line number Diff line
@@ -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;
+6 −6
Original line number Diff line number Diff line
@@ -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",
+2 −2
Original line number Diff line number Diff line
@@ -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;
+6 −2
Original line number Diff line number Diff line
@@ -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);

+29 −5
Original line number Diff line number Diff line
@@ -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;
}
Loading