From a52cb577b7dc1fc3cb290537a3ee56bbc99d9ce1 Mon Sep 17 00:00:00 2001 From: Seth Howell Date: Fri, 13 Sep 2019 11:09:07 -0700 Subject: [PATCH] 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 Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/468386 Tested-by: SPDK CI Jenkins Reviewed-by: Alexey Marchuk Reviewed-by: Paul Luse Reviewed-by: Ben Walker Reviewed-by: Shuhei Matsumoto Reviewed-by: Changpeng Liu --- include/spdk/nvmf.h | 29 +++++++++++++++++++++++++++++ lib/nvmf/nvmf.c | 18 ++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/include/spdk/nvmf.h b/include/spdk/nvmf.h index 17f060212a..ec9222889c 100644 --- a/include/spdk/nvmf.h +++ b/include/spdk/nvmf.h @@ -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 diff --git a/lib/nvmf/nvmf.c b/lib/nvmf/nvmf.c index 77b705fec5..42b7d91797 100644 --- a/lib/nvmf/nvmf.c +++ b/lib/nvmf/nvmf.c @@ -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)