Commit 72d72f50 authored by Daniel Verkamp's avatar Daniel Verkamp
Browse files

nvmf: add hosts after creating subsystem



Remove the array of allowed hosts from the parameters of
spdk_nvmf_construct_subsystem() and add the hosts individually now that
we have the capability to add them after subsystem creation.

Change-Id: I8b05e44d6a254f8d5848975e4bcfb7847e2cf4f3
Signed-off-by: default avatarDaniel Verkamp <daniel.verkamp@intel.com>
Reviewed-on: https://review.gerrithub.io/403377


Tested-by: default avatarSPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: default avatarChangpeng Liu <changpeng.liu@intel.com>
Reviewed-by: default avatarShuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
parent 333e9299
Loading
Loading
Loading
Loading
+14 −28
Original line number Diff line number Diff line
@@ -41,7 +41,6 @@
#include "spdk/string.h"
#include "spdk/util.h"

#define MAX_HOSTS 255
#define MAX_NAMESPACES 255

#define ACCEPT_TIMEOUT_US		10000 /* 10ms */
@@ -146,8 +145,6 @@ spdk_nvmf_parse_subsystem(struct spdk_conf_section *sp)
	size_t i;
	int ret;
	int lcore;
	int num_hosts;
	char *hosts[MAX_HOSTS];
	bool allow_any_host;
	const char *sn;
	struct spdk_nvmf_subsystem *subsystem;
@@ -180,21 +177,9 @@ spdk_nvmf_parse_subsystem(struct spdk_conf_section *sp)
		SPDK_NOTICELOG("Please remove Core from your configuration file. Ignoring it and continuing.\n");
	}

	/* Parse Host sections */
	for (i = 0; i < MAX_HOSTS; i++) {
		hosts[i] = spdk_conf_section_get_nval(sp, "Host", i);
		if (!hosts[i]) {
			break;
		}
	}
	num_hosts = i;

	allow_any_host = spdk_conf_section_get_boolval(sp, "AllowAnyHost", false);

	sn = spdk_conf_section_get_val(sp, "SN");

	subsystem = spdk_nvmf_construct_subsystem(nqn,
			num_hosts, hosts, allow_any_host,
			sn);

	if (subsystem == NULL) {
@@ -304,6 +289,20 @@ spdk_nvmf_parse_subsystem(struct spdk_conf_section *sp)
		spdk_nvmf_subsystem_add_listener(subsystem, &trid);
	}

	/* Parse Host sections */
	for (i = 0; ; i++) {
		const char *host = spdk_conf_section_get_nval(sp, "Host", i);

		if (!host) {
			break;
		}

		spdk_nvmf_subsystem_add_host(subsystem, host);
	}

	allow_any_host = spdk_conf_section_get_boolval(sp, "AllowAnyHost", false);
	spdk_nvmf_subsystem_set_allow_any_host(subsystem, allow_any_host);

done:
	return (subsystem != NULL);
}
@@ -349,34 +348,21 @@ spdk_nvmf_parse_conf(void)

struct spdk_nvmf_subsystem *
	spdk_nvmf_construct_subsystem(const char *name,
			      int num_hosts, char *hosts[], bool allow_any_host,
			      const char *sn)
{
	struct spdk_nvmf_subsystem *subsystem;
	int i;

	if (name == NULL) {
		SPDK_ERRLOG("No NQN specified for subsystem\n");
		return NULL;
	}

	if (num_hosts > MAX_HOSTS) {
		SPDK_ERRLOG("invalid hosts number\n");
		return NULL;
	}

	subsystem = nvmf_tgt_create_subsystem(name, SPDK_NVMF_SUBTYPE_NVME, 0);
	if (subsystem == NULL) {
		SPDK_ERRLOG("Subsystem creation failed\n");
		return NULL;
	}

	/* Parse Host sections */
	for (i = 0; i < num_hosts; i++) {
		spdk_nvmf_subsystem_add_host(subsystem, hosts[i]);
	}
	spdk_nvmf_subsystem_set_allow_any_host(subsystem, allow_any_host);

	if (sn == NULL) {
		SPDK_ERRLOG("Subsystem %s: missing serial number\n", name);
		goto error;
+0 −1
Original line number Diff line number Diff line
@@ -78,7 +78,6 @@ struct spdk_nvmf_subsystem *nvmf_tgt_create_subsystem(const char *name,
		enum spdk_nvmf_subtype subtype, uint32_t num_ns);

struct spdk_nvmf_subsystem *spdk_nvmf_construct_subsystem(const char *name,
		int num_hosts, char *hosts[], bool allow_any_host,
		const char *sn);

#endif
+6 −1
Original line number Diff line number Diff line
@@ -606,12 +606,17 @@ spdk_rpc_construct_nvmf_subsystem(struct spdk_jsonrpc_request *request,
	}

	subsystem = spdk_nvmf_construct_subsystem(req.nqn,
			req.hosts.num_hosts, req.hosts.hosts, req.allow_any_host,
			req.serial_number);
	if (!subsystem) {
		goto invalid;
	}

	for (i = 0; i < req.hosts.num_hosts; i++) {
		spdk_nvmf_subsystem_add_host(subsystem, req.hosts.hosts[i]);
	}

	spdk_nvmf_subsystem_set_allow_any_host(subsystem, req.allow_any_host);

	for (i = 0; i < req.listen_addresses.num_listen_address; i++) {
		struct rpc_listen_address *addr = &req.listen_addresses.addresses[i];
		struct spdk_nvme_transport_id trid = {0};