Commit 79d87671 authored by Seth Howell's avatar Seth Howell Committed by Jim Harris
Browse files

nvmf: add spdk_nvmf_get_tgt function



This function will allow applications (and RPCs)
to obtain an spdk_nvmf_tgt pointer by name.

Change-Id: I82792e06a819e06d9fddb5429830008653d92cd1
Signed-off-by: default avatarSeth Howell <seth.howell@intel.com>
Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/465349


Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarChangpeng Liu <changpeng.liu@intel.com>
Reviewed-by: default avatarBroadcom SPDK FC-NVMe CI <spdk-ci.pdl@broadcom.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
parent 0eb4e6d5
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -8,6 +8,11 @@ The `spdk_nvmf_tgt_create` function now accepts an object of type `spdk_nvmf_tar
as its only parameter. This new structure contains the max_subsystems parameter previously
passed into that function.

A new public API function `spdk_nvmf_get_tgt` has been added which allows users to
retrieve a pointer to an `spdk_nvmf_tgt` object by supplying its name. In the special
case where an RPC or application only creates a single target, this function can accept
a null name parameter and will return the only available target.

### nvme

Added `no_shn_notification` to NVMe controller initialization options, users can enable
+14 −0
Original line number Diff line number Diff line
@@ -136,6 +136,20 @@ void spdk_nvmf_tgt_destroy(struct spdk_nvmf_tgt *tgt,
			   spdk_nvmf_tgt_destroy_done_fn cb_fn,
			   void *cb_arg);

/**
 * Get a pointer to an NVMe-oF target.
 *
 * In order to support some legacy applications and RPC methods that may rely on the
 * concept that there is only one target, the name parameter can be passed as NULL.
 * If there is only one available target, that target will be returned.
 * Otherwise, name is a required parameter.
 *
 * \param name The name provided when the target was created.
 *
 * \return The target with the given name, or NULL if no match was found.
 */
struct spdk_nvmf_tgt *spdk_nvmf_get_tgt(const char *name);

/**
 * Write NVMe-oF target configuration into provided JSON context.
 * \param w JSON write context
+28 −0
Original line number Diff line number Diff line
@@ -320,6 +320,34 @@ spdk_nvmf_tgt_destroy(struct spdk_nvmf_tgt *tgt,
	spdk_io_device_unregister(tgt, spdk_nvmf_tgt_destroy_cb);
}

struct spdk_nvmf_tgt *
spdk_nvmf_get_tgt(const char *name)
{
	struct spdk_nvmf_tgt *tgt;
	uint32_t num_targets = 0;

	TAILQ_FOREACH(tgt, &g_nvmf_tgts, link) {
		if (name) {
			if (!strncmp(tgt->name, name, strlen(tgt->name))) {
				return tgt;
			}
		}
		num_targets++;
	}

	/*
	 * special case. If there is only one target and
	 * no name was specified, return the only available
	 * target. If there is more than one target, name must
	 * be specified.
	 */
	if (!name && num_targets == 1) {
		return TAILQ_FIRST(&g_nvmf_tgts);
	}

	return NULL;
}

static void
spdk_nvmf_write_subsystem_config_json(struct spdk_json_write_ctx *w,
				      struct spdk_nvmf_subsystem *subsystem)