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)