2016-06-06 21:44:30 +00:00
|
|
|
/*-
|
|
|
|
* BSD LICENSE
|
|
|
|
*
|
|
|
|
* Copyright (c) Intel Corporation.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
*
|
|
|
|
* * Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* * Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in
|
|
|
|
* the documentation and/or other materials provided with the
|
|
|
|
* distribution.
|
|
|
|
* * Neither the name of Intel Corporation nor the names of its
|
|
|
|
* contributors may be used to endorse or promote products derived
|
|
|
|
* from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2017-05-02 18:18:25 +00:00
|
|
|
#include "spdk/stdinc.h"
|
2016-06-06 21:44:30 +00:00
|
|
|
|
2016-07-15 17:42:46 +00:00
|
|
|
#include <rte_config.h>
|
|
|
|
#include <rte_lcore.h>
|
|
|
|
|
2016-08-23 16:46:41 +00:00
|
|
|
#include "nvmf_tgt.h"
|
2016-09-19 17:01:52 +00:00
|
|
|
|
2016-06-06 21:44:30 +00:00
|
|
|
#include "spdk/conf.h"
|
|
|
|
#include "spdk/log.h"
|
2016-08-15 01:16:49 +00:00
|
|
|
#include "spdk/bdev.h"
|
2016-09-19 17:01:52 +00:00
|
|
|
#include "spdk/nvme.h"
|
|
|
|
#include "spdk/nvmf.h"
|
2017-02-01 17:16:20 +00:00
|
|
|
#include "spdk/string.h"
|
2017-02-02 17:07:12 +00:00
|
|
|
#include "spdk/util.h"
|
2016-06-06 21:44:30 +00:00
|
|
|
|
2016-07-15 21:16:59 +00:00
|
|
|
#define MAX_LISTEN_ADDRESSES 255
|
|
|
|
#define MAX_HOSTS 255
|
2016-06-06 21:44:30 +00:00
|
|
|
#define PORTNUMSTRLEN 32
|
2016-09-19 17:01:52 +00:00
|
|
|
#define SPDK_NVMF_DEFAULT_SIN_PORT ((uint16_t)4420)
|
2016-06-06 21:44:30 +00:00
|
|
|
|
2016-11-25 01:46:49 +00:00
|
|
|
#define ACCEPT_TIMEOUT_US 10000 /* 10ms */
|
2016-09-12 17:44:58 +00:00
|
|
|
|
2016-07-21 18:24:17 +00:00
|
|
|
struct spdk_nvmf_probe_ctx {
|
2016-10-10 17:25:01 +00:00
|
|
|
struct nvmf_tgt_subsystem *app_subsystem;
|
2016-07-21 18:24:17 +00:00
|
|
|
bool any;
|
2016-07-28 20:38:05 +00:00
|
|
|
bool found;
|
2017-02-06 05:52:09 +00:00
|
|
|
struct spdk_nvme_transport_id trid;
|
2016-07-21 18:24:17 +00:00
|
|
|
};
|
|
|
|
|
2016-08-24 01:43:51 +00:00
|
|
|
#define MAX_STRING_LEN 255
|
|
|
|
|
2016-07-18 22:19:55 +00:00
|
|
|
#define SPDK_NVMF_CONFIG_QUEUES_PER_SESSION_DEFAULT 4
|
|
|
|
#define SPDK_NVMF_CONFIG_QUEUES_PER_SESSION_MIN 2
|
|
|
|
#define SPDK_NVMF_CONFIG_QUEUES_PER_SESSION_MAX 1024
|
|
|
|
|
2016-07-21 22:10:09 +00:00
|
|
|
#define SPDK_NVMF_CONFIG_QUEUE_DEPTH_DEFAULT 128
|
|
|
|
#define SPDK_NVMF_CONFIG_QUEUE_DEPTH_MIN 16
|
|
|
|
#define SPDK_NVMF_CONFIG_QUEUE_DEPTH_MAX 1024
|
|
|
|
|
2016-07-28 17:23:52 +00:00
|
|
|
#define SPDK_NVMF_CONFIG_IN_CAPSULE_DATA_SIZE_DEFAULT 4096
|
2016-07-25 21:22:58 +00:00
|
|
|
#define SPDK_NVMF_CONFIG_IN_CAPSULE_DATA_SIZE_MIN 4096
|
|
|
|
#define SPDK_NVMF_CONFIG_IN_CAPSULE_DATA_SIZE_MAX 131072
|
|
|
|
|
|
|
|
#define SPDK_NVMF_CONFIG_MAX_IO_SIZE_DEFAULT 131072
|
|
|
|
#define SPDK_NVMF_CONFIG_MAX_IO_SIZE_MIN 4096
|
|
|
|
#define SPDK_NVMF_CONFIG_MAX_IO_SIZE_MAX 131072
|
|
|
|
|
2016-08-16 16:35:59 +00:00
|
|
|
struct spdk_nvmf_tgt_conf g_spdk_nvmf_tgt_conf;
|
2017-03-28 16:30:52 +00:00
|
|
|
static int32_t g_last_core = -1;
|
2016-08-16 16:35:59 +00:00
|
|
|
|
2016-08-24 01:43:51 +00:00
|
|
|
static int
|
2017-02-02 16:44:26 +00:00
|
|
|
spdk_get_numa_node_value(const char *path)
|
2016-08-24 01:43:51 +00:00
|
|
|
{
|
|
|
|
FILE *fd;
|
|
|
|
int numa_node = -1;
|
|
|
|
char buf[MAX_STRING_LEN];
|
|
|
|
|
|
|
|
fd = fopen(path, "r");
|
|
|
|
if (!fd) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fgets(buf, sizeof(buf), fd) != NULL) {
|
|
|
|
numa_node = strtoul(buf, NULL, 10);
|
|
|
|
}
|
|
|
|
fclose(fd);
|
|
|
|
|
|
|
|
return numa_node;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2017-02-02 16:44:26 +00:00
|
|
|
spdk_get_ifaddr_numa_node(const char *if_addr)
|
2016-08-24 01:43:51 +00:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
struct ifaddrs *ifaddrs, *ifa;
|
|
|
|
struct sockaddr_in addr, addr_in;
|
|
|
|
char path[MAX_STRING_LEN];
|
|
|
|
int numa_node = -1;
|
|
|
|
|
|
|
|
addr_in.sin_addr.s_addr = inet_addr(if_addr);
|
|
|
|
|
|
|
|
ret = getifaddrs(&ifaddrs);
|
|
|
|
if (ret < 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
for (ifa = ifaddrs; ifa != NULL; ifa = ifa->ifa_next) {
|
|
|
|
addr = *(struct sockaddr_in *)ifa->ifa_addr;
|
|
|
|
if ((uint32_t)addr_in.sin_addr.s_addr != (uint32_t)addr.sin_addr.s_addr) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
snprintf(path, MAX_STRING_LEN, "/sys/class/net/%s/device/numa_node", ifa->ifa_name);
|
|
|
|
numa_node = spdk_get_numa_node_value(path);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
freeifaddrs(ifaddrs);
|
|
|
|
|
|
|
|
return numa_node;
|
|
|
|
}
|
|
|
|
|
2016-07-22 00:36:23 +00:00
|
|
|
static int
|
|
|
|
spdk_add_nvmf_discovery_subsystem(void)
|
|
|
|
{
|
2016-08-25 22:00:50 +00:00
|
|
|
struct nvmf_tgt_subsystem *app_subsys;
|
2016-07-22 00:36:23 +00:00
|
|
|
|
2016-11-14 20:37:52 +00:00
|
|
|
app_subsys = nvmf_tgt_create_subsystem(SPDK_NVMF_DISCOVERY_NQN, SPDK_NVMF_SUBTYPE_DISCOVERY,
|
2016-09-19 17:01:52 +00:00
|
|
|
NVMF_SUBSYSTEM_MODE_DIRECT,
|
2016-08-25 22:00:50 +00:00
|
|
|
rte_get_master_lcore());
|
|
|
|
if (app_subsys == NULL) {
|
2016-07-22 00:36:23 +00:00
|
|
|
SPDK_ERRLOG("Failed creating discovery nvmf library subsystem\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2016-10-13 00:21:26 +00:00
|
|
|
nvmf_tgt_start_subsystem(app_subsys);
|
|
|
|
|
2016-07-22 00:36:23 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-06-06 21:44:30 +00:00
|
|
|
static int
|
|
|
|
spdk_nvmf_parse_nvmf_tgt(void)
|
|
|
|
{
|
|
|
|
struct spdk_conf_section *sp;
|
|
|
|
int max_queue_depth;
|
2016-07-18 22:17:32 +00:00
|
|
|
int max_queues_per_sess;
|
2016-07-25 21:22:58 +00:00
|
|
|
int in_capsule_data_size;
|
|
|
|
int max_io_size;
|
2016-08-16 06:22:51 +00:00
|
|
|
int acceptor_lcore;
|
2016-09-12 17:44:58 +00:00
|
|
|
int acceptor_poll_rate;
|
2016-06-06 21:44:30 +00:00
|
|
|
int rc;
|
|
|
|
|
|
|
|
sp = spdk_conf_find_section(NULL, "Nvmf");
|
|
|
|
if (sp == NULL) {
|
|
|
|
SPDK_ERRLOG("No Nvmf section in configuration file.\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
max_queue_depth = spdk_conf_section_get_intval(sp, "MaxQueueDepth");
|
|
|
|
if (max_queue_depth < 0) {
|
2016-07-21 22:10:09 +00:00
|
|
|
max_queue_depth = SPDK_NVMF_CONFIG_QUEUE_DEPTH_DEFAULT;
|
2016-06-06 21:44:30 +00:00
|
|
|
}
|
2017-02-02 17:07:12 +00:00
|
|
|
max_queue_depth = spdk_max(max_queue_depth, SPDK_NVMF_CONFIG_QUEUE_DEPTH_MIN);
|
|
|
|
max_queue_depth = spdk_min(max_queue_depth, SPDK_NVMF_CONFIG_QUEUE_DEPTH_MAX);
|
2016-06-06 21:44:30 +00:00
|
|
|
|
2016-07-18 22:17:32 +00:00
|
|
|
max_queues_per_sess = spdk_conf_section_get_intval(sp, "MaxQueuesPerSession");
|
2016-07-21 22:10:09 +00:00
|
|
|
if (max_queues_per_sess < 0) {
|
|
|
|
max_queues_per_sess = SPDK_NVMF_CONFIG_QUEUES_PER_SESSION_DEFAULT;
|
|
|
|
}
|
2017-02-02 17:07:12 +00:00
|
|
|
max_queues_per_sess = spdk_max(max_queues_per_sess, SPDK_NVMF_CONFIG_QUEUES_PER_SESSION_MIN);
|
|
|
|
max_queues_per_sess = spdk_min(max_queues_per_sess, SPDK_NVMF_CONFIG_QUEUES_PER_SESSION_MAX);
|
2016-06-06 21:44:30 +00:00
|
|
|
|
2016-07-25 21:22:58 +00:00
|
|
|
in_capsule_data_size = spdk_conf_section_get_intval(sp, "InCapsuleDataSize");
|
|
|
|
if (in_capsule_data_size < 0) {
|
|
|
|
in_capsule_data_size = SPDK_NVMF_CONFIG_IN_CAPSULE_DATA_SIZE_DEFAULT;
|
|
|
|
} else if ((in_capsule_data_size % 16) != 0) {
|
|
|
|
SPDK_ERRLOG("InCapsuleDataSize must be a multiple of 16\n");
|
|
|
|
return -1;
|
|
|
|
}
|
2017-02-02 17:07:12 +00:00
|
|
|
in_capsule_data_size = spdk_max(in_capsule_data_size, SPDK_NVMF_CONFIG_IN_CAPSULE_DATA_SIZE_MIN);
|
|
|
|
in_capsule_data_size = spdk_min(in_capsule_data_size, SPDK_NVMF_CONFIG_IN_CAPSULE_DATA_SIZE_MAX);
|
2016-07-25 21:22:58 +00:00
|
|
|
|
|
|
|
max_io_size = spdk_conf_section_get_intval(sp, "MaxIOSize");
|
|
|
|
if (max_io_size < 0) {
|
|
|
|
max_io_size = SPDK_NVMF_CONFIG_MAX_IO_SIZE_DEFAULT;
|
|
|
|
} else if ((max_io_size % 4096) != 0) {
|
|
|
|
SPDK_ERRLOG("MaxIOSize must be a multiple of 4096\n");
|
|
|
|
return -1;
|
|
|
|
}
|
2017-02-02 17:07:12 +00:00
|
|
|
max_io_size = spdk_max(max_io_size, SPDK_NVMF_CONFIG_MAX_IO_SIZE_MIN);
|
|
|
|
max_io_size = spdk_min(max_io_size, SPDK_NVMF_CONFIG_MAX_IO_SIZE_MAX);
|
2016-07-25 21:22:58 +00:00
|
|
|
|
2016-08-16 06:22:51 +00:00
|
|
|
acceptor_lcore = spdk_conf_section_get_intval(sp, "AcceptorCore");
|
|
|
|
if (acceptor_lcore < 0) {
|
|
|
|
acceptor_lcore = rte_lcore_id();
|
|
|
|
}
|
2016-08-16 16:35:59 +00:00
|
|
|
g_spdk_nvmf_tgt_conf.acceptor_lcore = acceptor_lcore;
|
2016-08-16 06:22:51 +00:00
|
|
|
|
2016-09-12 17:44:58 +00:00
|
|
|
acceptor_poll_rate = spdk_conf_section_get_intval(sp, "AcceptorPollRate");
|
|
|
|
if (acceptor_poll_rate < 0) {
|
|
|
|
acceptor_poll_rate = ACCEPT_TIMEOUT_US;
|
|
|
|
}
|
|
|
|
g_spdk_nvmf_tgt_conf.acceptor_poll_rate = acceptor_poll_rate;
|
|
|
|
|
2016-10-10 22:05:37 +00:00
|
|
|
rc = spdk_nvmf_tgt_init(max_queue_depth, max_queues_per_sess, in_capsule_data_size, max_io_size);
|
2016-07-22 00:36:23 +00:00
|
|
|
if (rc != 0) {
|
2016-10-10 22:05:37 +00:00
|
|
|
SPDK_ERRLOG("spdk_nvmf_tgt_init() failed\n");
|
2016-07-22 00:36:23 +00:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
rc = spdk_add_nvmf_discovery_subsystem();
|
|
|
|
if (rc != 0) {
|
|
|
|
SPDK_ERRLOG("spdk_add_nvmf_discovery_subsystem failed\n");
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2016-06-06 21:44:30 +00:00
|
|
|
}
|
|
|
|
|
2016-07-21 18:24:17 +00:00
|
|
|
static bool
|
2016-12-09 22:09:28 +00:00
|
|
|
probe_cb(void *cb_ctx, const struct spdk_nvme_transport_id *trid,
|
2016-10-31 23:55:14 +00:00
|
|
|
struct spdk_nvme_ctrlr_opts *opts)
|
2016-07-11 23:11:03 +00:00
|
|
|
{
|
2016-07-21 18:24:17 +00:00
|
|
|
struct spdk_nvmf_probe_ctx *ctx = cb_ctx;
|
2016-07-11 23:11:03 +00:00
|
|
|
|
2016-07-28 20:38:05 +00:00
|
|
|
if (ctx->any && !ctx->found) {
|
|
|
|
ctx->found = true;
|
2016-07-21 18:24:17 +00:00
|
|
|
return true;
|
2016-07-11 23:11:03 +00:00
|
|
|
}
|
|
|
|
|
2017-02-06 05:52:09 +00:00
|
|
|
if (strcmp(trid->traddr, ctx->trid.traddr) == 0) {
|
2016-08-08 22:57:49 +00:00
|
|
|
ctx->found = true;
|
|
|
|
return true;
|
2016-07-11 23:11:03 +00:00
|
|
|
}
|
|
|
|
|
2016-07-21 18:24:17 +00:00
|
|
|
return false;
|
|
|
|
}
|
2016-07-11 23:11:03 +00:00
|
|
|
|
2016-07-21 18:24:17 +00:00
|
|
|
static void
|
2016-12-09 22:09:28 +00:00
|
|
|
attach_cb(void *cb_ctx, const struct spdk_nvme_transport_id *trid,
|
2016-10-31 23:55:14 +00:00
|
|
|
struct spdk_nvme_ctrlr *ctrlr, const struct spdk_nvme_ctrlr_opts *opts)
|
2016-07-21 18:24:17 +00:00
|
|
|
{
|
|
|
|
struct spdk_nvmf_probe_ctx *ctx = cb_ctx;
|
|
|
|
int rc;
|
2016-08-24 01:43:51 +00:00
|
|
|
int numa_node = -1;
|
2016-12-09 21:23:55 +00:00
|
|
|
struct spdk_pci_addr pci_addr;
|
2017-01-31 00:39:23 +00:00
|
|
|
struct spdk_pci_device *pci_dev;
|
2016-12-09 21:23:55 +00:00
|
|
|
|
2016-12-09 22:09:28 +00:00
|
|
|
spdk_pci_addr_parse(&pci_addr, trid->traddr);
|
nvmf: make sure nvmf target workable when it run as secondary porcess.
This patch do the following optimization:
1 when the nvmf target run as secondary process, the nvme probe will
not call the probe callback function, which will skip the step to
set up the ctx->found, so we set up it when we call attach callback.
2 when the nvmf target run as secondary process, every time when we try
to probe one device, it will iterate all the attached devices and call
the attach callback, for nvmf target, it will cause the overwrite of
the nvme controller for the nvmf subsystem, so we need to compare the
attached deivce with the device which we try to attach, if they are not
the same one, just return.
Change-Id: I606ba75b1dab7fd1b1e4e1cfcf63248a506725d1
Signed-off-by: cunyinch <cunyin.chang@intel.com>
Reviewed-on: https://review.gerrithub.io/362807
Tested-by: SPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
2017-05-26 23:41:41 +00:00
|
|
|
if (ctx->trid.traddr[0] != '\0' && strcmp(trid->traddr, ctx->trid.traddr)) {
|
|
|
|
SPDK_WARNLOG("Attached device is not expected\n");
|
|
|
|
return;
|
|
|
|
}
|
2016-12-09 21:23:55 +00:00
|
|
|
SPDK_NOTICELOG("Attaching NVMe device %p at %s to subsystem %s\n",
|
2016-10-31 23:55:14 +00:00
|
|
|
ctrlr,
|
2016-12-09 22:09:28 +00:00
|
|
|
trid->traddr,
|
2016-10-10 17:25:01 +00:00
|
|
|
spdk_nvmf_subsystem_get_nqn(ctx->app_subsystem->subsystem));
|
2016-07-28 05:50:39 +00:00
|
|
|
|
2017-01-31 00:39:23 +00:00
|
|
|
pci_dev = spdk_pci_get_device(&pci_addr);
|
|
|
|
if (pci_dev) {
|
|
|
|
numa_node = spdk_pci_device_get_socket_id(pci_dev);
|
|
|
|
}
|
2016-08-24 01:43:51 +00:00
|
|
|
if (numa_node >= 0) {
|
|
|
|
/* Running subsystem and NVMe device is on the same socket or not */
|
2017-03-27 19:59:40 +00:00
|
|
|
if (spdk_env_get_socket_id(ctx->app_subsystem->lcore) != (unsigned)numa_node) {
|
2016-11-23 14:57:16 +00:00
|
|
|
SPDK_WARNLOG("Subsystem %s is configured to run on a CPU core %u belonging "
|
2016-08-24 01:43:51 +00:00
|
|
|
"to a different NUMA node than the associated NVMe device. "
|
|
|
|
"This may result in reduced performance.\n",
|
2016-11-23 14:57:16 +00:00
|
|
|
spdk_nvmf_subsystem_get_nqn(ctx->app_subsystem->subsystem),
|
|
|
|
ctx->app_subsystem->lcore);
|
|
|
|
SPDK_WARNLOG("The NVMe device is on socket %u\n", numa_node);
|
|
|
|
SPDK_WARNLOG("The Subsystem is on socket %u\n",
|
2017-03-27 19:59:40 +00:00
|
|
|
spdk_env_get_socket_id(ctx->app_subsystem->lcore));
|
2016-08-24 01:43:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-09 21:23:55 +00:00
|
|
|
rc = nvmf_subsystem_add_ctrlr(ctx->app_subsystem->subsystem, ctrlr, &pci_addr);
|
2016-07-21 18:24:17 +00:00
|
|
|
if (rc < 0) {
|
|
|
|
SPDK_ERRLOG("Failed to add controller to subsystem\n");
|
2016-07-11 23:11:03 +00:00
|
|
|
}
|
nvmf: make sure nvmf target workable when it run as secondary porcess.
This patch do the following optimization:
1 when the nvmf target run as secondary process, the nvme probe will
not call the probe callback function, which will skip the step to
set up the ctx->found, so we set up it when we call attach callback.
2 when the nvmf target run as secondary process, every time when we try
to probe one device, it will iterate all the attached devices and call
the attach callback, for nvmf target, it will cause the overwrite of
the nvme controller for the nvmf subsystem, so we need to compare the
attached deivce with the device which we try to attach, if they are not
the same one, just return.
Change-Id: I606ba75b1dab7fd1b1e4e1cfcf63248a506725d1
Signed-off-by: cunyinch <cunyin.chang@intel.com>
Reviewed-on: https://review.gerrithub.io/362807
Tested-by: SPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
2017-05-26 23:41:41 +00:00
|
|
|
ctx->found = true;
|
2016-07-11 23:11:03 +00:00
|
|
|
}
|
|
|
|
|
2016-07-15 20:03:29 +00:00
|
|
|
static int
|
|
|
|
spdk_nvmf_allocate_lcore(uint64_t mask, uint32_t lcore)
|
|
|
|
{
|
|
|
|
uint32_t end;
|
|
|
|
|
|
|
|
if (lcore == 0) {
|
|
|
|
end = 0;
|
|
|
|
} else {
|
|
|
|
end = lcore - 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
do {
|
|
|
|
if (((mask >> lcore) & 1U) == 1U) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
lcore = (lcore + 1) % 64;
|
|
|
|
} while (lcore != end);
|
|
|
|
|
|
|
|
return lcore;
|
|
|
|
}
|
|
|
|
|
2016-07-11 22:12:11 +00:00
|
|
|
static int
|
|
|
|
spdk_nvmf_parse_subsystem(struct spdk_conf_section *sp)
|
|
|
|
{
|
2016-09-19 17:01:52 +00:00
|
|
|
const char *nqn, *mode_str;
|
2016-07-11 22:12:11 +00:00
|
|
|
int i, ret;
|
2017-01-30 19:41:59 +00:00
|
|
|
int lcore;
|
|
|
|
int num_listen_addrs;
|
|
|
|
struct rpc_listen_address listen_addrs[MAX_LISTEN_ADDRESSES];
|
2017-03-09 12:57:53 +00:00
|
|
|
char *listen_addrs_str[MAX_LISTEN_ADDRESSES] = {};
|
2017-01-30 19:41:59 +00:00
|
|
|
int num_hosts;
|
|
|
|
char *hosts[MAX_HOSTS];
|
|
|
|
const char *bdf;
|
|
|
|
const char *sn;
|
|
|
|
int num_devs;
|
|
|
|
char *devs[MAX_VIRTUAL_NAMESPACE];
|
2016-07-11 22:12:11 +00:00
|
|
|
|
|
|
|
nqn = spdk_conf_section_get_val(sp, "NQN");
|
2016-09-19 17:01:52 +00:00
|
|
|
mode_str = spdk_conf_section_get_val(sp, "Mode");
|
2017-01-30 19:41:59 +00:00
|
|
|
lcore = spdk_conf_section_get_intval(sp, "Core");
|
2016-07-20 09:54:53 +00:00
|
|
|
|
2016-07-15 21:16:59 +00:00
|
|
|
/* Parse Listen sections */
|
2017-01-30 19:41:59 +00:00
|
|
|
num_listen_addrs = 0;
|
2016-07-15 21:16:59 +00:00
|
|
|
for (i = 0; i < MAX_LISTEN_ADDRESSES; i++) {
|
2017-03-01 04:26:48 +00:00
|
|
|
listen_addrs[num_listen_addrs].transport =
|
|
|
|
spdk_conf_section_get_nmval(sp, "Listen", i, 0);
|
2017-03-09 12:57:53 +00:00
|
|
|
if (!listen_addrs[num_listen_addrs].transport) {
|
|
|
|
break;
|
|
|
|
}
|
2016-07-11 22:12:11 +00:00
|
|
|
|
2017-03-09 12:57:53 +00:00
|
|
|
listen_addrs_str[i] = spdk_conf_section_get_nmval(sp, "Listen", i, 1);
|
|
|
|
if (!listen_addrs_str[i]) {
|
2016-07-11 22:12:11 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2017-03-09 12:57:53 +00:00
|
|
|
listen_addrs_str[i] = strdup(listen_addrs_str[i]);
|
2017-02-01 17:16:20 +00:00
|
|
|
|
2017-03-09 12:57:53 +00:00
|
|
|
ret = spdk_parse_ip_addr(listen_addrs_str[i], &listen_addrs[num_listen_addrs].traddr,
|
2017-03-01 04:26:48 +00:00
|
|
|
&listen_addrs[num_listen_addrs].trsvcid);
|
2016-07-11 22:12:11 +00:00
|
|
|
if (ret < 0) {
|
2017-03-09 12:57:53 +00:00
|
|
|
SPDK_ERRLOG("Unable to parse listen address '%s'\n", listen_addrs_str[i]);
|
|
|
|
free(listen_addrs_str[i]);
|
|
|
|
listen_addrs_str[i] = NULL;
|
2016-07-15 21:16:59 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2017-01-30 19:41:59 +00:00
|
|
|
num_listen_addrs++;
|
2016-07-15 21:16:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Parse Host sections */
|
|
|
|
for (i = 0; i < MAX_HOSTS; i++) {
|
2017-01-30 19:41:59 +00:00
|
|
|
hosts[i] = spdk_conf_section_get_nval(sp, "Host", i);
|
|
|
|
if (!hosts[i]) {
|
2016-07-15 21:16:59 +00:00
|
|
|
break;
|
2016-07-11 22:12:11 +00:00
|
|
|
}
|
|
|
|
}
|
2017-02-24 23:07:02 +00:00
|
|
|
num_hosts = i;
|
2016-07-11 22:12:11 +00:00
|
|
|
|
2017-01-30 19:41:59 +00:00
|
|
|
bdf = spdk_conf_section_get_val(sp, "NVMe");
|
|
|
|
sn = spdk_conf_section_get_val(sp, "SN");
|
2016-08-15 01:16:49 +00:00
|
|
|
|
2017-01-30 19:41:59 +00:00
|
|
|
num_devs = 0;
|
|
|
|
for (i = 0; i < MAX_VIRTUAL_NAMESPACE; i++) {
|
|
|
|
devs[i] = spdk_conf_section_get_nmval(sp, "Namespace", i, 0);
|
|
|
|
if (!devs[i]) {
|
|
|
|
break;
|
2016-08-15 01:16:49 +00:00
|
|
|
}
|
|
|
|
|
2017-01-30 19:41:59 +00:00
|
|
|
num_devs++;
|
2016-08-01 06:02:59 +00:00
|
|
|
}
|
2016-10-13 00:21:26 +00:00
|
|
|
|
2017-03-01 03:28:49 +00:00
|
|
|
ret = spdk_nvmf_construct_subsystem(nqn, mode_str, lcore,
|
|
|
|
num_listen_addrs, listen_addrs,
|
|
|
|
num_hosts, hosts,
|
|
|
|
bdf, sn,
|
|
|
|
num_devs, devs);
|
|
|
|
|
2017-03-09 12:57:53 +00:00
|
|
|
for (i = 0; i < MAX_LISTEN_ADDRESSES; i++) {
|
|
|
|
free(listen_addrs_str[i]);
|
2017-03-01 03:28:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
2016-07-11 22:12:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
spdk_nvmf_parse_subsystems(void)
|
|
|
|
{
|
|
|
|
int rc = 0;
|
|
|
|
struct spdk_conf_section *sp;
|
|
|
|
|
|
|
|
sp = spdk_conf_first_section(NULL);
|
|
|
|
while (sp != NULL) {
|
|
|
|
if (spdk_conf_section_match_prefix(sp, "Subsystem")) {
|
|
|
|
rc = spdk_nvmf_parse_subsystem(sp);
|
|
|
|
if (rc < 0) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
sp = spdk_conf_next_section(sp);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-06-06 21:44:30 +00:00
|
|
|
int
|
|
|
|
spdk_nvmf_parse_conf(void)
|
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
/* NVMf section */
|
|
|
|
rc = spdk_nvmf_parse_nvmf_tgt();
|
|
|
|
if (rc < 0) {
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2016-07-11 22:12:11 +00:00
|
|
|
/* Subsystem sections */
|
|
|
|
rc = spdk_nvmf_parse_subsystems();
|
|
|
|
if (rc < 0) {
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2016-06-06 21:44:30 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2016-09-13 02:52:21 +00:00
|
|
|
|
|
|
|
int
|
2017-02-21 04:49:59 +00:00
|
|
|
spdk_nvmf_construct_subsystem(const char *name,
|
|
|
|
const char *mode_str, int32_t lcore,
|
|
|
|
int num_listen_addresses, struct rpc_listen_address *addresses,
|
|
|
|
int num_hosts, char *hosts[], const char *bdf,
|
|
|
|
const char *sn, int num_devs, char *dev_list[])
|
2016-09-13 02:52:21 +00:00
|
|
|
{
|
|
|
|
struct spdk_nvmf_subsystem *subsystem;
|
|
|
|
struct nvmf_tgt_subsystem *app_subsys;
|
2017-02-20 04:49:39 +00:00
|
|
|
struct spdk_nvmf_listen_addr *listen_addr;
|
2016-09-19 17:01:52 +00:00
|
|
|
enum spdk_nvmf_subsystem_mode mode;
|
2016-10-31 23:29:52 +00:00
|
|
|
int i;
|
2016-09-13 02:52:21 +00:00
|
|
|
uint64_t mask;
|
|
|
|
|
|
|
|
if (name == NULL) {
|
2016-11-14 20:37:52 +00:00
|
|
|
SPDK_ERRLOG("No NQN specified for subsystem\n");
|
2016-09-13 02:52:21 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (num_listen_addresses > MAX_LISTEN_ADDRESSES) {
|
|
|
|
SPDK_ERRLOG("invalid listen adresses number\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (num_hosts > MAX_HOSTS) {
|
|
|
|
SPDK_ERRLOG("invalid hosts number\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2017-01-24 04:52:23 +00:00
|
|
|
if (lcore < 0) {
|
2017-03-28 16:30:52 +00:00
|
|
|
lcore = ++g_last_core;
|
2017-01-24 04:52:23 +00:00
|
|
|
}
|
|
|
|
|
2016-09-13 02:52:21 +00:00
|
|
|
/* Determine which core to assign to the subsystem */
|
|
|
|
mask = spdk_app_get_core_mask();
|
|
|
|
lcore = spdk_nvmf_allocate_lcore(mask, lcore);
|
2017-03-28 16:30:52 +00:00
|
|
|
g_last_core = lcore;
|
2016-09-13 02:52:21 +00:00
|
|
|
|
2016-09-19 17:01:52 +00:00
|
|
|
/* Determine the mode the subsysem will operate in */
|
|
|
|
if (mode_str == NULL) {
|
2016-11-14 20:37:52 +00:00
|
|
|
SPDK_ERRLOG("No Mode specified for Subsystem %s\n", name);
|
2016-09-13 02:52:21 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2016-09-19 17:01:52 +00:00
|
|
|
if (strcasecmp(mode_str, "Direct") == 0) {
|
|
|
|
mode = NVMF_SUBSYSTEM_MODE_DIRECT;
|
|
|
|
} else if (strcasecmp(mode_str, "Virtual") == 0) {
|
|
|
|
mode = NVMF_SUBSYSTEM_MODE_VIRTUAL;
|
|
|
|
} else {
|
|
|
|
SPDK_ERRLOG("Invalid Subsystem mode: %s\n", mode_str);
|
2016-09-13 02:52:21 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2016-11-14 20:37:52 +00:00
|
|
|
app_subsys = nvmf_tgt_create_subsystem(name, SPDK_NVMF_SUBTYPE_NVME,
|
2016-09-19 17:01:52 +00:00
|
|
|
mode, lcore);
|
|
|
|
if (app_subsys == NULL) {
|
|
|
|
SPDK_ERRLOG("Subsystem creation failed\n");
|
2016-09-13 02:52:21 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2016-09-19 17:01:52 +00:00
|
|
|
subsystem = app_subsys->subsystem;
|
2016-09-13 02:52:21 +00:00
|
|
|
|
|
|
|
/* Parse Listen sections */
|
|
|
|
for (i = 0; i < num_listen_addresses; i++) {
|
2017-01-30 19:40:52 +00:00
|
|
|
int nic_numa_node = spdk_get_ifaddr_numa_node(addresses[i].traddr);
|
2017-03-27 19:59:40 +00:00
|
|
|
unsigned subsys_numa_node = spdk_env_get_socket_id(app_subsys->lcore);
|
2017-01-30 19:40:52 +00:00
|
|
|
|
|
|
|
if (nic_numa_node >= 0) {
|
|
|
|
if (subsys_numa_node != (unsigned)nic_numa_node) {
|
|
|
|
SPDK_WARNLOG("Subsystem %s is configured to run on a CPU core %d belonging "
|
|
|
|
"to a different NUMA node than the associated NIC. "
|
|
|
|
"This may result in reduced performance.\n",
|
|
|
|
name, lcore);
|
|
|
|
SPDK_WARNLOG("The NIC is on socket %d\n", nic_numa_node);
|
|
|
|
SPDK_WARNLOG("The Subsystem is on socket %u\n",
|
|
|
|
subsys_numa_node);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-20 04:49:39 +00:00
|
|
|
listen_addr = spdk_nvmf_tgt_listen(addresses[i].transport,
|
|
|
|
addresses[i].traddr, addresses[i].trsvcid);
|
2017-03-22 22:32:49 +00:00
|
|
|
if (listen_addr == NULL) {
|
|
|
|
SPDK_ERRLOG("Failed to listen on transport %s, traddr %s, trsvcid %s\n",
|
|
|
|
addresses[i].transport,
|
|
|
|
addresses[i].traddr,
|
|
|
|
addresses[i].trsvcid);
|
|
|
|
goto error;
|
|
|
|
}
|
2017-02-20 04:49:39 +00:00
|
|
|
spdk_nvmf_subsystem_add_listener(subsystem, listen_addr);
|
2016-09-13 02:52:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Parse Host sections */
|
|
|
|
for (i = 0; i < num_hosts; i++) {
|
2016-10-10 22:58:29 +00:00
|
|
|
spdk_nvmf_subsystem_add_host(subsystem, hosts[i]);
|
2016-09-13 02:52:21 +00:00
|
|
|
}
|
|
|
|
|
2016-09-19 17:01:52 +00:00
|
|
|
if (mode == NVMF_SUBSYSTEM_MODE_DIRECT) {
|
2016-09-13 02:52:21 +00:00
|
|
|
struct spdk_nvmf_probe_ctx ctx = { 0 };
|
2017-02-06 05:52:09 +00:00
|
|
|
struct spdk_nvme_transport_id trid = {};
|
|
|
|
struct spdk_pci_addr pci_addr = {};
|
2016-09-13 02:52:21 +00:00
|
|
|
|
|
|
|
if (bdf == NULL) {
|
2016-11-14 20:37:52 +00:00
|
|
|
SPDK_ERRLOG("Subsystem %s: missing NVMe directive\n", name);
|
2016-11-18 08:16:37 +00:00
|
|
|
goto error;
|
2016-09-13 02:52:21 +00:00
|
|
|
}
|
|
|
|
|
2016-10-10 22:18:35 +00:00
|
|
|
if (num_devs != 0) {
|
2016-11-14 20:37:52 +00:00
|
|
|
SPDK_ERRLOG("Subsystem %s: Namespaces not allowed for Direct mode\n", name);
|
2016-11-18 08:16:37 +00:00
|
|
|
goto error;
|
2016-10-10 22:18:35 +00:00
|
|
|
}
|
|
|
|
|
2017-02-06 05:52:09 +00:00
|
|
|
trid.trtype = SPDK_NVME_TRANSPORT_PCIE;
|
2016-10-10 17:25:01 +00:00
|
|
|
ctx.app_subsystem = app_subsys;
|
2016-09-13 02:52:21 +00:00
|
|
|
ctx.found = false;
|
|
|
|
if (strcmp(bdf, "*") == 0) {
|
|
|
|
ctx.any = true;
|
|
|
|
} else {
|
2017-02-06 05:52:09 +00:00
|
|
|
if (spdk_pci_addr_parse(&pci_addr, bdf) < 0) {
|
2016-09-13 02:52:21 +00:00
|
|
|
SPDK_ERRLOG("Invalid format for NVMe BDF: %s\n", bdf);
|
2016-11-18 08:16:37 +00:00
|
|
|
goto error;
|
2016-09-13 02:52:21 +00:00
|
|
|
}
|
|
|
|
ctx.any = false;
|
2017-02-06 05:52:09 +00:00
|
|
|
spdk_pci_addr_fmt(trid.traddr, sizeof(trid.traddr), &pci_addr);
|
|
|
|
ctx.trid = trid;
|
2016-09-13 02:52:21 +00:00
|
|
|
}
|
|
|
|
|
2017-02-06 05:52:09 +00:00
|
|
|
if (spdk_nvme_probe(&trid, &ctx, probe_cb, attach_cb, NULL)) {
|
2016-09-13 02:52:21 +00:00
|
|
|
SPDK_ERRLOG("One or more controllers failed in spdk_nvme_probe()\n");
|
|
|
|
}
|
2016-10-10 23:04:24 +00:00
|
|
|
|
|
|
|
if (!ctx.found) {
|
|
|
|
SPDK_ERRLOG("Could not find NVMe controller at PCI address %04x:%02x:%02x.%x\n",
|
2017-02-06 05:52:09 +00:00
|
|
|
pci_addr.domain, pci_addr.bus, pci_addr.dev, pci_addr.func);
|
2016-11-18 08:16:37 +00:00
|
|
|
goto error;
|
2016-10-10 23:04:24 +00:00
|
|
|
}
|
2016-09-13 02:52:21 +00:00
|
|
|
} else {
|
|
|
|
struct spdk_bdev *bdev;
|
|
|
|
const char *namespace;
|
|
|
|
|
|
|
|
if (sn == NULL) {
|
2016-11-14 20:37:52 +00:00
|
|
|
SPDK_ERRLOG("Subsystem %s: missing serial number\n", name);
|
2016-11-18 08:16:37 +00:00
|
|
|
goto error;
|
2016-09-13 02:52:21 +00:00
|
|
|
}
|
|
|
|
|
2017-05-31 23:46:17 +00:00
|
|
|
if (spdk_nvmf_subsystem_set_sn(subsystem, sn)) {
|
|
|
|
SPDK_ERRLOG("Subsystem %s: invalid serial number '%s'\n", name, sn);
|
|
|
|
goto error;
|
|
|
|
}
|
2016-09-13 02:52:21 +00:00
|
|
|
|
|
|
|
for (i = 0; i < num_devs; i++) {
|
|
|
|
namespace = dev_list[i];
|
|
|
|
if (!namespace) {
|
|
|
|
SPDK_ERRLOG("Namespace %d: missing block device\n", i);
|
2016-11-18 08:16:37 +00:00
|
|
|
goto error;
|
2016-09-13 02:52:21 +00:00
|
|
|
}
|
|
|
|
bdev = spdk_bdev_get_by_name(namespace);
|
2017-01-18 18:02:38 +00:00
|
|
|
if (bdev == NULL) {
|
|
|
|
SPDK_ERRLOG("Could not find namespace bdev '%s'\n", namespace);
|
|
|
|
goto error;
|
|
|
|
}
|
2016-09-13 02:52:21 +00:00
|
|
|
if (spdk_nvmf_subsystem_add_ns(subsystem, bdev)) {
|
2016-11-18 08:16:37 +00:00
|
|
|
goto error;
|
2016-09-13 02:52:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SPDK_NOTICELOG("Attaching block device %s to subsystem %s\n",
|
2017-05-31 23:36:34 +00:00
|
|
|
spdk_bdev_get_name(bdev), spdk_nvmf_subsystem_get_nqn(subsystem));
|
2016-09-13 02:52:21 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-13 00:21:26 +00:00
|
|
|
nvmf_tgt_start_subsystem(app_subsys);
|
|
|
|
|
2016-09-13 02:52:21 +00:00
|
|
|
return 0;
|
2016-11-18 08:16:37 +00:00
|
|
|
|
|
|
|
error:
|
|
|
|
spdk_nvmf_delete_subsystem(app_subsys->subsystem);
|
|
|
|
app_subsys->subsystem = NULL;
|
|
|
|
return -1;
|
2016-09-13 02:52:21 +00:00
|
|
|
}
|