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: Seth Howell <seth.howell@intel.com>
Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/465349
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Changpeng Liu <changpeng.liu@intel.com>
Reviewed-by: Broadcom SPDK FC-NVMe CI <spdk-ci.pdl@broadcom.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
This commit is contained in:
Seth Howell 2019-08-15 11:32:11 -07:00 committed by Jim Harris
parent 0eb4e6d5ed
commit 79d876716c
3 changed files with 47 additions and 0 deletions

View File

@ -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 as its only parameter. This new structure contains the max_subsystems parameter previously
passed into that function. 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 ### nvme
Added `no_shn_notification` to NVMe controller initialization options, users can enable Added `no_shn_notification` to NVMe controller initialization options, users can enable

View File

@ -136,6 +136,20 @@ void spdk_nvmf_tgt_destroy(struct spdk_nvmf_tgt *tgt,
spdk_nvmf_tgt_destroy_done_fn cb_fn, spdk_nvmf_tgt_destroy_done_fn cb_fn,
void *cb_arg); 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. * Write NVMe-oF target configuration into provided JSON context.
* \param w JSON write context * \param w JSON write context

View File

@ -320,6 +320,34 @@ spdk_nvmf_tgt_destroy(struct spdk_nvmf_tgt *tgt,
spdk_io_device_unregister(tgt, spdk_nvmf_tgt_destroy_cb); 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 static void
spdk_nvmf_write_subsystem_config_json(struct spdk_json_write_ctx *w, spdk_nvmf_write_subsystem_config_json(struct spdk_json_write_ctx *w,
struct spdk_nvmf_subsystem *subsystem) struct spdk_nvmf_subsystem *subsystem)