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-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
|
2017-08-24 20:15:30 +00:00
|
|
|
#define MAX_NAMESPACES 255
|
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 {
|
2017-11-20 18:36:36 +00:00
|
|
|
struct spdk_nvmf_subsystem *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-08-16 16:35:59 +00:00
|
|
|
struct spdk_nvmf_tgt_conf g_spdk_nvmf_tgt_conf;
|
2016-08-24 01:43:51 +00:00
|
|
|
|
2016-07-22 00:36:23 +00:00
|
|
|
static int
|
|
|
|
spdk_add_nvmf_discovery_subsystem(void)
|
|
|
|
{
|
2017-11-20 18:36:36 +00:00
|
|
|
struct spdk_nvmf_subsystem *subsystem;
|
2016-07-22 00:36:23 +00:00
|
|
|
|
2017-11-20 18:36:36 +00:00
|
|
|
subsystem = nvmf_tgt_create_subsystem(SPDK_NVMF_DISCOVERY_NQN, SPDK_NVMF_SUBTYPE_DISCOVERY, 0);
|
|
|
|
if (subsystem == NULL) {
|
2016-07-22 00:36:23 +00:00
|
|
|
SPDK_ERRLOG("Failed creating discovery nvmf library subsystem\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2017-11-20 18:36:36 +00:00
|
|
|
spdk_nvmf_subsystem_set_allow_any_host(subsystem, true);
|
2016-10-13 00:21:26 +00:00
|
|
|
|
2016-07-22 00:36:23 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-10-26 04:35:36 +00:00
|
|
|
static void
|
|
|
|
spdk_nvmf_read_config_file_params(struct spdk_conf_section *sp,
|
|
|
|
struct spdk_nvmf_tgt_opts *opts)
|
2016-06-06 21:44:30 +00:00
|
|
|
{
|
|
|
|
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-09-12 17:44:58 +00:00
|
|
|
int acceptor_poll_rate;
|
2017-08-17 20:39:27 +00:00
|
|
|
|
2016-06-06 21:44:30 +00:00
|
|
|
max_queue_depth = spdk_conf_section_get_intval(sp, "MaxQueueDepth");
|
2017-08-17 20:39:27 +00:00
|
|
|
if (max_queue_depth >= 0) {
|
2017-10-26 04:35:36 +00:00
|
|
|
opts->max_queue_depth = max_queue_depth;
|
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");
|
2017-08-17 20:39:27 +00:00
|
|
|
if (max_queues_per_sess >= 0) {
|
2017-10-26 04:35:36 +00:00
|
|
|
opts->max_qpairs_per_ctrlr = max_queues_per_sess;
|
2016-07-21 22:10:09 +00:00
|
|
|
}
|
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");
|
2017-08-17 20:39:27 +00:00
|
|
|
if (in_capsule_data_size >= 0) {
|
2017-10-26 04:35:36 +00:00
|
|
|
opts->in_capsule_data_size = in_capsule_data_size;
|
2016-07-25 21:22:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
max_io_size = spdk_conf_section_get_intval(sp, "MaxIOSize");
|
2017-08-17 20:39:27 +00:00
|
|
|
if (max_io_size >= 0) {
|
2017-10-26 04:35:36 +00:00
|
|
|
opts->max_io_size = max_io_size;
|
2016-07-25 21:22:58 +00:00
|
|
|
}
|
|
|
|
|
2016-09-12 17:44:58 +00:00
|
|
|
acceptor_poll_rate = spdk_conf_section_get_intval(sp, "AcceptorPollRate");
|
2017-10-26 04:35:36 +00:00
|
|
|
if (acceptor_poll_rate >= 0) {
|
|
|
|
g_spdk_nvmf_tgt_conf.acceptor_poll_rate = acceptor_poll_rate;
|
2016-09-12 17:44:58 +00:00
|
|
|
}
|
2017-10-26 04:35:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
spdk_nvmf_parse_nvmf_tgt(void)
|
|
|
|
{
|
|
|
|
struct spdk_conf_section *sp;
|
|
|
|
struct spdk_nvmf_tgt_opts opts;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
spdk_nvmf_tgt_opts_init(&opts);
|
|
|
|
g_spdk_nvmf_tgt_conf.acceptor_poll_rate = ACCEPT_TIMEOUT_US;
|
2017-10-26 03:32:58 +00:00
|
|
|
|
|
|
|
sp = spdk_conf_find_section(NULL, "Nvmf");
|
|
|
|
if (sp != NULL) {
|
|
|
|
spdk_nvmf_read_config_file_params(sp, &opts);
|
|
|
|
}
|
2016-09-12 17:44:58 +00:00
|
|
|
|
2017-11-01 23:24:18 +00:00
|
|
|
g_tgt.tgt = spdk_nvmf_tgt_create(&opts);
|
|
|
|
if (!g_tgt.tgt) {
|
2017-08-18 22:38:33 +00:00
|
|
|
SPDK_ERRLOG("spdk_nvmf_tgt_create() failed\n");
|
|
|
|
return -1;
|
2016-07-22 00:36:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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-11 22:12:11 +00:00
|
|
|
static int
|
|
|
|
spdk_nvmf_parse_subsystem(struct spdk_conf_section *sp)
|
|
|
|
{
|
2017-06-27 18:26:19 +00:00
|
|
|
const char *nqn, *mode;
|
2017-08-24 20:15:30 +00:00
|
|
|
size_t i;
|
|
|
|
int ret;
|
2017-01-30 19:41:59 +00:00
|
|
|
int lcore;
|
|
|
|
int num_listen_addrs;
|
2017-08-01 16:36:33 +00:00
|
|
|
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];
|
2017-08-30 20:21:12 +00:00
|
|
|
bool allow_any_host;
|
2017-01-30 19:41:59 +00:00
|
|
|
const char *sn;
|
2017-12-19 23:39:04 +00:00
|
|
|
struct spdk_nvmf_subsystem *subsystem;
|
2016-07-11 22:12:11 +00:00
|
|
|
|
|
|
|
nqn = spdk_conf_section_get_val(sp, "NQN");
|
2017-06-27 18:26:19 +00:00
|
|
|
mode = 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
|
|
|
|
2017-06-27 18:26:19 +00:00
|
|
|
/* Mode is no longer a valid parameter, but print out a nice
|
|
|
|
* message if it exists to inform users.
|
|
|
|
*/
|
|
|
|
if (mode) {
|
|
|
|
SPDK_NOTICELOG("Mode present in the [Subsystem] section of the config file.\n"
|
|
|
|
"Mode was removed as a valid parameter.\n");
|
2017-08-08 21:08:45 +00:00
|
|
|
if (strcasecmp(mode, "Virtual") == 0) {
|
2017-06-27 18:26:19 +00:00
|
|
|
SPDK_NOTICELOG("Your mode value is 'Virtual' which is now the only possible mode.\n"
|
|
|
|
"Your configuration file will work as expected.\n");
|
|
|
|
} else {
|
|
|
|
SPDK_NOTICELOG("Please remove Mode from your configuration file.\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-20 18:36:36 +00:00
|
|
|
/* Core is no longer a valid parameter, but print out a nice
|
|
|
|
* message if it exists to inform users.
|
|
|
|
*/
|
|
|
|
if (lcore >= 0) {
|
|
|
|
SPDK_NOTICELOG("Core present in the [Subsystem] section of the config file.\n"
|
|
|
|
"Core was removed as an option. Subsystems can now run on all available cores.\n");
|
|
|
|
SPDK_NOTICELOG("Please remove Core from your configuration file. Ignoring it and continuing.\n");
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2018-01-25 23:43:10 +00:00
|
|
|
if (strchr(listen_addrs[num_listen_addrs].traddr, ':')) {
|
|
|
|
listen_addrs[num_listen_addrs].adrfam = "IPv6";
|
|
|
|
} else {
|
|
|
|
listen_addrs[num_listen_addrs].adrfam = "IPv4";
|
|
|
|
}
|
|
|
|
|
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-08-30 20:21:12 +00:00
|
|
|
allow_any_host = spdk_conf_section_get_boolval(sp, "AllowAnyHost", false);
|
|
|
|
|
2017-01-30 19:41:59 +00:00
|
|
|
sn = spdk_conf_section_get_val(sp, "SN");
|
2016-08-15 01:16:49 +00:00
|
|
|
|
2018-02-12 22:46:36 +00:00
|
|
|
subsystem = spdk_nvmf_construct_subsystem(nqn,
|
|
|
|
num_listen_addrs, listen_addrs,
|
|
|
|
num_hosts, hosts, allow_any_host,
|
|
|
|
sn);
|
|
|
|
|
|
|
|
if (subsystem == NULL) {
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; ; i++) {
|
|
|
|
struct spdk_nvmf_ns_opts ns_opts;
|
|
|
|
struct spdk_bdev *bdev;
|
|
|
|
const char *bdev_name;
|
2017-08-30 23:55:48 +00:00
|
|
|
char *nsid_str;
|
|
|
|
|
2018-02-12 22:46:36 +00:00
|
|
|
bdev_name = spdk_conf_section_get_nmval(sp, "Namespace", i, 0);
|
|
|
|
if (!bdev_name) {
|
2017-01-30 19:41:59 +00:00
|
|
|
break;
|
2016-08-15 01:16:49 +00:00
|
|
|
}
|
|
|
|
|
2018-02-12 22:46:36 +00:00
|
|
|
bdev = spdk_bdev_get_by_name(bdev_name);
|
|
|
|
if (bdev == NULL) {
|
|
|
|
SPDK_ERRLOG("Could not find namespace bdev '%s'\n", bdev_name);
|
|
|
|
spdk_nvmf_subsystem_destroy(subsystem);
|
|
|
|
subsystem = NULL;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
spdk_nvmf_ns_opts_get_defaults(&ns_opts, sizeof(ns_opts));
|
|
|
|
|
2017-08-30 23:55:48 +00:00
|
|
|
nsid_str = spdk_conf_section_get_nmval(sp, "Namespace", i, 1);
|
|
|
|
if (nsid_str) {
|
|
|
|
char *end;
|
|
|
|
unsigned long nsid_ul = strtoul(nsid_str, &end, 0);
|
|
|
|
|
|
|
|
if (*end != '\0' || nsid_ul == 0 || nsid_ul >= UINT32_MAX) {
|
|
|
|
SPDK_ERRLOG("Invalid NSID %s\n", nsid_str);
|
2018-02-12 22:46:36 +00:00
|
|
|
spdk_nvmf_subsystem_destroy(subsystem);
|
|
|
|
subsystem = NULL;
|
|
|
|
goto done;
|
2017-08-30 23:55:48 +00:00
|
|
|
}
|
|
|
|
|
2018-02-12 22:46:36 +00:00
|
|
|
ns_opts.nsid = (uint32_t)nsid_ul;
|
2017-08-30 23:55:48 +00:00
|
|
|
}
|
|
|
|
|
2018-02-12 22:46:36 +00:00
|
|
|
if (spdk_nvmf_subsystem_add_ns(subsystem, bdev, &ns_opts, sizeof(ns_opts)) == 0) {
|
|
|
|
SPDK_ERRLOG("Unable to add namespace\n");
|
|
|
|
spdk_nvmf_subsystem_destroy(subsystem);
|
|
|
|
subsystem = NULL;
|
|
|
|
goto done;
|
|
|
|
}
|
2016-10-13 00:21:26 +00:00
|
|
|
|
2018-02-12 22:46:36 +00:00
|
|
|
SPDK_NOTICELOG("Attaching block device %s to subsystem %s\n",
|
|
|
|
spdk_bdev_get_name(bdev), spdk_nvmf_subsystem_get_nqn(subsystem));
|
|
|
|
}
|
2017-03-01 03:28:49 +00:00
|
|
|
|
2018-02-12 22:46:36 +00:00
|
|
|
done:
|
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
|
|
|
}
|
|
|
|
|
2017-12-19 23:39:04 +00:00
|
|
|
return (subsystem != NULL);
|
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
|
|
|
|
2017-12-19 23:39:04 +00:00
|
|
|
struct spdk_nvmf_subsystem *
|
|
|
|
spdk_nvmf_construct_subsystem(const char *name,
|
2017-02-21 04:49:59 +00:00
|
|
|
int num_listen_addresses, struct rpc_listen_address *addresses,
|
2017-08-30 20:21:12 +00:00
|
|
|
int num_hosts, char *hosts[], bool allow_any_host,
|
2018-02-12 22:46:36 +00:00
|
|
|
const char *sn)
|
2016-09-13 02:52:21 +00:00
|
|
|
{
|
|
|
|
struct spdk_nvmf_subsystem *subsystem;
|
2017-08-23 17:23:44 +00:00
|
|
|
int i, rc;
|
2016-09-13 02:52:21 +00:00
|
|
|
|
|
|
|
if (name == NULL) {
|
2016-11-14 20:37:52 +00:00
|
|
|
SPDK_ERRLOG("No NQN specified for subsystem\n");
|
2017-12-19 23:39:04 +00:00
|
|
|
return NULL;
|
2016-09-13 02:52:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (num_listen_addresses > MAX_LISTEN_ADDRESSES) {
|
|
|
|
SPDK_ERRLOG("invalid listen adresses number\n");
|
2017-12-19 23:39:04 +00:00
|
|
|
return NULL;
|
2016-09-13 02:52:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (num_hosts > MAX_HOSTS) {
|
|
|
|
SPDK_ERRLOG("invalid hosts number\n");
|
2017-12-19 23:39:04 +00:00
|
|
|
return NULL;
|
2016-09-13 02:52:21 +00:00
|
|
|
}
|
|
|
|
|
2018-02-12 22:46:36 +00:00
|
|
|
subsystem = nvmf_tgt_create_subsystem(name, SPDK_NVMF_SUBTYPE_NVME, 0);
|
2017-11-20 18:36:36 +00:00
|
|
|
if (subsystem == NULL) {
|
2016-09-19 17:01:52 +00:00
|
|
|
SPDK_ERRLOG("Subsystem creation failed\n");
|
2017-12-19 23:39:04 +00:00
|
|
|
return NULL;
|
2016-09-13 02:52:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Parse Listen sections */
|
|
|
|
for (i = 0; i < num_listen_addresses; i++) {
|
2017-07-13 20:13:05 +00:00
|
|
|
struct spdk_nvme_transport_id trid = {};
|
2017-01-30 19:40:52 +00:00
|
|
|
|
2017-07-13 20:13:05 +00:00
|
|
|
if (spdk_nvme_transport_id_parse_trtype(&trid.trtype, addresses[i].transport)) {
|
2017-06-28 18:07:41 +00:00
|
|
|
SPDK_ERRLOG("Missing listen address transport type\n");
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2017-07-13 20:13:05 +00:00
|
|
|
if (spdk_nvme_transport_id_parse_adrfam(&trid.adrfam, addresses[i].adrfam)) {
|
|
|
|
trid.adrfam = SPDK_NVMF_ADRFAM_IPV4;
|
2017-06-28 20:13:11 +00:00
|
|
|
}
|
|
|
|
|
2017-07-13 20:13:05 +00:00
|
|
|
snprintf(trid.traddr, sizeof(trid.traddr), "%s", addresses[i].traddr);
|
|
|
|
snprintf(trid.trsvcid, sizeof(trid.trsvcid), "%s", addresses[i].trsvcid);
|
2017-06-28 20:13:11 +00:00
|
|
|
|
2017-11-01 23:24:18 +00:00
|
|
|
rc = spdk_nvmf_tgt_listen(g_tgt.tgt, &trid);
|
2017-08-23 17:23:44 +00:00
|
|
|
if (rc) {
|
2017-06-28 20:13:11 +00:00
|
|
|
SPDK_ERRLOG("Failed to listen on transport %s, adrfam %s, traddr %s, trsvcid %s\n",
|
2017-03-22 22:32:49 +00:00
|
|
|
addresses[i].transport,
|
2017-07-13 20:13:05 +00:00
|
|
|
addresses[i].adrfam,
|
2017-03-22 22:32:49 +00:00
|
|
|
addresses[i].traddr,
|
|
|
|
addresses[i].trsvcid);
|
|
|
|
goto error;
|
|
|
|
}
|
2017-08-23 17:23:44 +00:00
|
|
|
spdk_nvmf_subsystem_add_listener(subsystem, &trid);
|
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
|
|
|
}
|
2017-08-30 20:21:12 +00:00
|
|
|
spdk_nvmf_subsystem_set_allow_any_host(subsystem, allow_any_host);
|
2016-09-13 02:52:21 +00:00
|
|
|
|
2017-06-27 18:26:19 +00:00
|
|
|
if (sn == NULL) {
|
|
|
|
SPDK_ERRLOG("Subsystem %s: missing serial number\n", name);
|
|
|
|
goto error;
|
|
|
|
}
|
2016-09-13 02:52:21 +00:00
|
|
|
|
2017-06-27 18:26:19 +00:00
|
|
|
if (spdk_nvmf_subsystem_set_sn(subsystem, sn)) {
|
|
|
|
SPDK_ERRLOG("Subsystem %s: invalid serial number '%s'\n", name, sn);
|
|
|
|
goto error;
|
|
|
|
}
|
2016-10-10 23:04:24 +00:00
|
|
|
|
2017-12-19 23:39:04 +00:00
|
|
|
return subsystem;
|
2016-11-18 08:16:37 +00:00
|
|
|
|
|
|
|
error:
|
2017-12-19 23:39:04 +00:00
|
|
|
spdk_nvmf_subsystem_destroy(subsystem);
|
|
|
|
return NULL;
|
2016-09-13 02:52:21 +00:00
|
|
|
}
|