Commit 8d3fdcab authored by Ankit Kumar's avatar Ankit Kumar Committed by Tomasz Zawadzki
Browse files

nvmf: cleanup maximum number of subsystem namespace remanent code



The capability to change maximum number of namespaces a subsystem can
contain was removed. Now during poll_group_update_subsystem we can only
allocate namespace information for the subsystem poll group. Remove
remanent code from the time that change was made.
Cleanup the subsystem add namespace API.

Fixes: af07b82f ("nvmf: The maximum number of namespaces")

Change-Id: Ia64579f8ee30175363d4ab36199bb78e45fac554
Signed-off-by: default avatarAnkit Kumar <ankit.kumar@samsung.com>
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/23401


Community-CI: Mellanox Build Bot
Reviewed-by: default avatarJim Harris <jim.harris@samsung.com>
Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarBen Walker <ben@nvidia.com>
parent 6ee9cd25
Loading
Loading
Loading
Loading
+6 −52
Original line number Diff line number Diff line
@@ -1459,7 +1459,6 @@ poll_group_update_subsystem(struct spdk_nvmf_poll_group *group,
			    struct spdk_nvmf_subsystem *subsystem)
{
	struct spdk_nvmf_subsystem_poll_group *sgroup;
	uint32_t new_num_ns, old_num_ns;
	uint32_t i, j;
	struct spdk_nvmf_ns *ns;
	struct spdk_nvmf_registrant *reg, *tmp;
@@ -1476,61 +1475,16 @@ poll_group_update_subsystem(struct spdk_nvmf_poll_group *group,
	sgroup = &group->sgroups[subsystem->id];

	/* Make sure the array of namespace information is the correct size */
	new_num_ns = subsystem->max_nsid;
	old_num_ns = sgroup->num_ns;

	ns_changed = false;

	if (old_num_ns == 0) {
		if (new_num_ns > 0) {
	if (sgroup->num_ns == 0 && subsystem->max_nsid > 0) {
		/* First allocation */
			sgroup->ns_info = calloc(new_num_ns, sizeof(struct spdk_nvmf_subsystem_pg_ns_info));
		sgroup->ns_info = calloc(subsystem->max_nsid, sizeof(struct spdk_nvmf_subsystem_pg_ns_info));
		if (!sgroup->ns_info) {
			return -ENOMEM;
		}
		sgroup->num_ns = subsystem->max_nsid;
	}
	} else if (new_num_ns > old_num_ns) {
		void *buf;

		/* Make the array larger */
		buf = realloc(sgroup->ns_info, new_num_ns * sizeof(struct spdk_nvmf_subsystem_pg_ns_info));
		if (!buf) {
			return -ENOMEM;
		}

		sgroup->ns_info = buf;

		/* Null out the new namespace information slots */
		for (i = old_num_ns; i < new_num_ns; i++) {
			memset(&sgroup->ns_info[i], 0, sizeof(struct spdk_nvmf_subsystem_pg_ns_info));
		}
	} else if (new_num_ns < old_num_ns) {
		void *buf;

		/* Free the extra I/O channels */
		for (i = new_num_ns; i < old_num_ns; i++) {
			ns_info = &sgroup->ns_info[i];

			if (ns_info->channel) {
				spdk_put_io_channel(ns_info->channel);
				ns_info->channel = NULL;
			}
		}

		/* Make the array smaller */
		if (new_num_ns > 0) {
			buf = realloc(sgroup->ns_info, new_num_ns * sizeof(struct spdk_nvmf_subsystem_pg_ns_info));
			if (!buf) {
				return -ENOMEM;
			}
			sgroup->ns_info = buf;
		} else {
			free(sgroup->ns_info);
			sgroup->ns_info = NULL;
		}
	}

	sgroup->num_ns = new_num_ns;
	ns_changed = false;

	/* Detect bdevs that were added or removed */
	for (i = 0; i < sgroup->num_ns; i++) {
+9 −6
Original line number Diff line number Diff line
@@ -2015,26 +2015,29 @@ spdk_nvmf_subsystem_add_ns_ext(struct spdk_nvmf_subsystem *subsystem, const char
		/*
		 * NSID not specified - find a free index.
		 *
		 * If no free slots are found, opts.nsid will be subsystem->max_nsid + 1, which will
		 * expand max_nsid if possible.
		 * If no free slots are found, return error.
		 */
		for (opts.nsid = 1; opts.nsid <= subsystem->max_nsid; opts.nsid++) {
			if (_nvmf_subsystem_get_ns(subsystem, opts.nsid) == NULL) {
				break;
			}
		}
	}

	if (_nvmf_subsystem_get_ns(subsystem, opts.nsid)) {
		SPDK_ERRLOG("Requested NSID %" PRIu32 " already in use\n", opts.nsid);
		if (opts.nsid > subsystem->max_nsid) {
			SPDK_ERRLOG("No free namespace slot available in the subsystem\n");
			return 0;
		}
	}

	if (opts.nsid > subsystem->max_nsid) {
		SPDK_ERRLOG("NSID greater than maximum not allowed\n");
		return 0;
	}

	if (_nvmf_subsystem_get_ns(subsystem, opts.nsid)) {
		SPDK_ERRLOG("Requested NSID %" PRIu32 " already in use\n", opts.nsid);
		return 0;
	}

	if (opts.anagrpid == 0) {
		opts.anagrpid = opts.nsid;
	}