lib/nvmf: add helper functions for future RPCs.

Functions added in this patch:
spdk_nvmf_tgt_get_name - get human readable name from target.
spdk_nvmf_get_first_tgt - start iterating over global list of targets
spdk_nvmf_get_next_tgt - get next target in iteration

These functions will facilitate the following RPC

nvmf_get_targets - get the names of all active NVMe-oF targets.

In this series, I will also add two more RPCs, nvmf_create_target, and
nvmf_destroy_target, as wrappers around the create and destroy
functions. Since all of these changes are pretty minor and closely
related, I will just do one big changelog entry at the end.

Change-Id: Ia9f1248fbf9726fa3889998a169211fb25e724f2
Signed-off-by: Seth Howell <seth.howell@intel.com>
Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/468386
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Alexey Marchuk <alexeymar@mellanox.com>
Reviewed-by: Paul Luse <paul.e.luse@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Reviewed-by: Changpeng Liu <changpeng.liu@intel.com>
This commit is contained in:
Seth Howell 2019-09-13 11:09:07 -07:00 committed by Jim Harris
parent c1f6def98a
commit a52cb577b7
2 changed files with 47 additions and 0 deletions

View File

@ -136,6 +136,15 @@ void spdk_nvmf_tgt_destroy(struct spdk_nvmf_tgt *tgt,
spdk_nvmf_tgt_destroy_done_fn cb_fn,
void *cb_arg);
/**
* Get the name of an NVMe-oF target.
*
* \param tgt The target from which to get the name.
*
* \return The name of the target as a null terminated string.
*/
const char *spdk_nvmf_tgt_get_name(struct spdk_nvmf_tgt *tgt);
/**
* Get a pointer to an NVMe-oF target.
*
@ -150,6 +159,26 @@ void spdk_nvmf_tgt_destroy(struct spdk_nvmf_tgt *tgt,
*/
struct spdk_nvmf_tgt *spdk_nvmf_get_tgt(const char *name);
/**
* Get the pointer to the first NVMe-oF target.
*
* Combined with spdk_nvmf_get_next_tgt to iterate over all available targets.
*
* \return The first NVMe-oF target.
*/
struct spdk_nvmf_tgt *spdk_nvmf_get_first_tgt(void);
/**
* Get the pointer to the first NVMe-oF target.
*
* Combined with spdk_nvmf_get_first_tgt to iterate over all available targets.
*
* \param prev A pointer to the last NVMe-oF target.
*
* \return The first NVMe-oF target.
*/
struct spdk_nvmf_tgt *spdk_nvmf_get_next_tgt(struct spdk_nvmf_tgt *prev);
/**
* Write NVMe-oF target configuration into provided JSON context.
* \param w JSON write context

View File

@ -314,6 +314,12 @@ spdk_nvmf_tgt_destroy(struct spdk_nvmf_tgt *tgt,
spdk_io_device_unregister(tgt, spdk_nvmf_tgt_destroy_cb);
}
const char *
spdk_nvmf_tgt_get_name(struct spdk_nvmf_tgt *tgt)
{
return tgt->name;
}
struct spdk_nvmf_tgt *
spdk_nvmf_get_tgt(const char *name)
{
@ -342,6 +348,18 @@ spdk_nvmf_get_tgt(const char *name)
return NULL;
}
struct spdk_nvmf_tgt *
spdk_nvmf_get_first_tgt(void)
{
return TAILQ_FIRST(&g_nvmf_tgts);
}
struct spdk_nvmf_tgt *
spdk_nvmf_get_next_tgt(struct spdk_nvmf_tgt *prev)
{
return TAILQ_NEXT(prev, link);
}
static void
spdk_nvmf_write_subsystem_config_json(struct spdk_json_write_ctx *w,
struct spdk_nvmf_subsystem *subsystem)