nvmf: add namespaces individually in construct
This will allow us to specify individual namespace options in upcoming patches. Change-Id: Id3301a2313a1d7cbafac1f8a5bcd8d73eae4cd47 Signed-off-by: Daniel Verkamp <daniel.verkamp@intel.com> Reviewed-on: https://review.gerrithub.io/399522 Reviewed-by: Jim Harris <james.r.harris@intel.com> Tested-by: SPDK Automated Test System <sys_sgsw@intel.com> Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
This commit is contained in:
parent
250d342bc1
commit
119ccada0a
@ -156,8 +156,6 @@ spdk_nvmf_parse_subsystem(struct spdk_conf_section *sp)
|
||||
char *hosts[MAX_HOSTS];
|
||||
bool allow_any_host;
|
||||
const char *sn;
|
||||
size_t num_ns;
|
||||
struct spdk_nvmf_ns_params ns_list[MAX_NAMESPACES] = {};
|
||||
struct spdk_nvmf_subsystem *subsystem;
|
||||
|
||||
nqn = spdk_conf_section_get_val(sp, "NQN");
|
||||
@ -235,15 +233,36 @@ spdk_nvmf_parse_subsystem(struct spdk_conf_section *sp)
|
||||
|
||||
sn = spdk_conf_section_get_val(sp, "SN");
|
||||
|
||||
num_ns = 0;
|
||||
for (i = 0; i < SPDK_COUNTOF(ns_list); i++) {
|
||||
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;
|
||||
char *nsid_str;
|
||||
|
||||
ns_list[i].bdev_name = spdk_conf_section_get_nmval(sp, "Namespace", i, 0);
|
||||
if (!ns_list[i].bdev_name) {
|
||||
bdev_name = spdk_conf_section_get_nmval(sp, "Namespace", i, 0);
|
||||
if (!bdev_name) {
|
||||
break;
|
||||
}
|
||||
|
||||
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));
|
||||
|
||||
nsid_str = spdk_conf_section_get_nmval(sp, "Namespace", i, 1);
|
||||
if (nsid_str) {
|
||||
char *end;
|
||||
@ -251,24 +270,26 @@ spdk_nvmf_parse_subsystem(struct spdk_conf_section *sp)
|
||||
|
||||
if (*end != '\0' || nsid_ul == 0 || nsid_ul >= UINT32_MAX) {
|
||||
SPDK_ERRLOG("Invalid NSID %s\n", nsid_str);
|
||||
return -1;
|
||||
spdk_nvmf_subsystem_destroy(subsystem);
|
||||
subsystem = NULL;
|
||||
goto done;
|
||||
}
|
||||
|
||||
ns_list[i].nsid = (uint32_t)nsid_ul;
|
||||
} else {
|
||||
/* Automatically assign the next available NSID. */
|
||||
ns_list[i].nsid = 0;
|
||||
ns_opts.nsid = (uint32_t)nsid_ul;
|
||||
}
|
||||
|
||||
num_ns++;
|
||||
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;
|
||||
}
|
||||
|
||||
SPDK_NOTICELOG("Attaching block device %s to subsystem %s\n",
|
||||
spdk_bdev_get_name(bdev), spdk_nvmf_subsystem_get_nqn(subsystem));
|
||||
}
|
||||
|
||||
subsystem = spdk_nvmf_construct_subsystem(nqn,
|
||||
num_listen_addrs, listen_addrs,
|
||||
num_hosts, hosts, allow_any_host,
|
||||
sn,
|
||||
num_ns, ns_list);
|
||||
|
||||
done:
|
||||
for (i = 0; i < MAX_LISTEN_ADDRESSES; i++) {
|
||||
free(listen_addrs_str[i]);
|
||||
}
|
||||
@ -319,12 +340,10 @@ struct spdk_nvmf_subsystem *
|
||||
spdk_nvmf_construct_subsystem(const char *name,
|
||||
int num_listen_addresses, struct rpc_listen_address *addresses,
|
||||
int num_hosts, char *hosts[], bool allow_any_host,
|
||||
const char *sn, size_t num_ns, struct spdk_nvmf_ns_params *ns_list)
|
||||
const char *sn)
|
||||
{
|
||||
struct spdk_nvmf_subsystem *subsystem;
|
||||
int i, rc;
|
||||
size_t j;
|
||||
struct spdk_bdev *bdev;
|
||||
|
||||
if (name == NULL) {
|
||||
SPDK_ERRLOG("No NQN specified for subsystem\n");
|
||||
@ -341,7 +360,7 @@ struct spdk_nvmf_subsystem *
|
||||
return NULL;
|
||||
}
|
||||
|
||||
subsystem = nvmf_tgt_create_subsystem(name, SPDK_NVMF_SUBTYPE_NVME, num_ns);
|
||||
subsystem = nvmf_tgt_create_subsystem(name, SPDK_NVMF_SUBTYPE_NVME, 0);
|
||||
if (subsystem == NULL) {
|
||||
SPDK_ERRLOG("Subsystem creation failed\n");
|
||||
return NULL;
|
||||
@ -391,33 +410,6 @@ struct spdk_nvmf_subsystem *
|
||||
goto error;
|
||||
}
|
||||
|
||||
for (j = 0; j < num_ns; j++) {
|
||||
struct spdk_nvmf_ns_params *ns_params = &ns_list[j];
|
||||
struct spdk_nvmf_ns_opts ns_opts;
|
||||
|
||||
if (!ns_params->bdev_name) {
|
||||
SPDK_ERRLOG("Namespace missing bdev name\n");
|
||||
goto error;
|
||||
}
|
||||
|
||||
bdev = spdk_bdev_get_by_name(ns_params->bdev_name);
|
||||
if (bdev == NULL) {
|
||||
SPDK_ERRLOG("Could not find namespace bdev '%s'\n", ns_params->bdev_name);
|
||||
goto error;
|
||||
}
|
||||
|
||||
spdk_nvmf_ns_opts_get_defaults(&ns_opts, sizeof(ns_opts));
|
||||
ns_opts.nsid = ns_params->nsid;
|
||||
|
||||
if (spdk_nvmf_subsystem_add_ns(subsystem, bdev, &ns_opts, sizeof(ns_opts)) == 0) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
SPDK_NOTICELOG("Attaching block device %s to subsystem %s\n",
|
||||
spdk_bdev_get_name(bdev), spdk_nvmf_subsystem_get_nqn(subsystem));
|
||||
|
||||
}
|
||||
|
||||
return subsystem;
|
||||
|
||||
error:
|
||||
|
@ -268,6 +268,10 @@ decode_rpc_hosts(const struct spdk_json_val *val, void *out)
|
||||
}
|
||||
|
||||
|
||||
struct spdk_nvmf_ns_params {
|
||||
char *bdev_name;
|
||||
uint32_t nsid;
|
||||
};
|
||||
|
||||
struct rpc_namespaces {
|
||||
size_t num_ns;
|
||||
@ -419,6 +423,8 @@ spdk_rpc_construct_nvmf_subsystem(struct spdk_jsonrpc_request *request,
|
||||
{
|
||||
struct rpc_subsystem req = {};
|
||||
struct spdk_nvmf_subsystem *subsystem;
|
||||
size_t i;
|
||||
|
||||
req.core = -1; /* Explicitly set the core as the uninitialized value */
|
||||
|
||||
if (spdk_json_decode_object(params, rpc_subsystem_decoders,
|
||||
@ -456,14 +462,34 @@ spdk_rpc_construct_nvmf_subsystem(struct spdk_jsonrpc_request *request,
|
||||
req.listen_addresses.num_listen_address,
|
||||
req.listen_addresses.addresses,
|
||||
req.hosts.num_hosts, req.hosts.hosts, req.allow_any_host,
|
||||
req.serial_number,
|
||||
req.namespaces.num_ns, req.namespaces.ns_params);
|
||||
req.serial_number);
|
||||
if (!subsystem) {
|
||||
goto invalid;
|
||||
}
|
||||
|
||||
free_rpc_subsystem(&req);
|
||||
for (i = 0; i < req.namespaces.num_ns; i++) {
|
||||
struct spdk_nvmf_ns_params *ns_params = &req.namespaces.ns_params[i];
|
||||
struct spdk_bdev *bdev;
|
||||
struct spdk_nvmf_ns_opts ns_opts;
|
||||
|
||||
bdev = spdk_bdev_get_by_name(ns_params->bdev_name);
|
||||
if (bdev == NULL) {
|
||||
SPDK_ERRLOG("Could not find namespace bdev '%s'\n", ns_params->bdev_name);
|
||||
spdk_nvmf_subsystem_destroy(subsystem);
|
||||
goto invalid;
|
||||
}
|
||||
|
||||
spdk_nvmf_ns_opts_get_defaults(&ns_opts, sizeof(ns_opts));
|
||||
ns_opts.nsid = ns_params->nsid;
|
||||
|
||||
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);
|
||||
goto invalid;
|
||||
}
|
||||
}
|
||||
|
||||
free_rpc_subsystem(&req);
|
||||
|
||||
spdk_nvmf_subsystem_start(subsystem,
|
||||
spdk_rpc_nvmf_subsystem_started,
|
||||
|
@ -83,15 +83,10 @@ int spdk_nvmf_parse_conf(void);
|
||||
struct spdk_nvmf_subsystem *nvmf_tgt_create_subsystem(const char *name,
|
||||
enum spdk_nvmf_subtype subtype, uint32_t num_ns);
|
||||
|
||||
struct spdk_nvmf_ns_params {
|
||||
char *bdev_name;
|
||||
uint32_t nsid;
|
||||
};
|
||||
|
||||
struct spdk_nvmf_subsystem *spdk_nvmf_construct_subsystem(const char *name,
|
||||
int num_listen_addresses, struct rpc_listen_address *addresses,
|
||||
int num_hosts, char *hosts[], bool allow_any_host,
|
||||
const char *sn, size_t num_ns, struct spdk_nvmf_ns_params *ns_list);
|
||||
const char *sn);
|
||||
|
||||
int spdk_nvmf_tgt_start(struct spdk_app_opts *opts);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user