From 0ac5050624765ebb06625c647b4f5f6939e34997 Mon Sep 17 00:00:00 2001 From: Seth Howell Date: Thu, 15 Aug 2019 09:52:20 -0700 Subject: [PATCH] lib/nvmf: add a global list of targets As part of moving the nvmf rpc code to the library, we will need to make it more inclusive of use cases outside of the example spdk nvmf_tgt application. That application only supports a single nvmf target structure. As such, many of the RPCs have this assumption built into them. In order to enable the multi-target use case, we need to configure a way to translate between user supplied RPCs and actual target objects in the library. Change-Id: I5d3745afe9c2ca1c33f6e1a1bcc2b8bb3196ccd6 Signed-off-by: Seth Howell Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/465329 Tested-by: SPDK CI Jenkins Reviewed-by: Jim Harris Reviewed-by: Shuhei Matsumoto Reviewed-by: Ben Walker Reviewed-by: Paul Luse --- lib/nvmf/nvmf.c | 6 ++++++ lib/nvmf/nvmf_internal.h | 2 ++ 2 files changed, 8 insertions(+) diff --git a/lib/nvmf/nvmf.c b/lib/nvmf/nvmf.c index b0c628dbf..5859ddd4a 100644 --- a/lib/nvmf/nvmf.c +++ b/lib/nvmf/nvmf.c @@ -51,6 +51,8 @@ SPDK_LOG_REGISTER_COMPONENT("nvmf", SPDK_LOG_NVMF) #define SPDK_NVMF_DEFAULT_MAX_SUBSYSTEMS 1024 +static TAILQ_HEAD(, spdk_nvmf_tgt) g_nvmf_tgts = TAILQ_HEAD_INITIALIZER(g_nvmf_tgts); + typedef void (*nvmf_qpair_disconnect_cpl)(void *ctx, int status); static void spdk_nvmf_tgt_destroy_poll_group(void *io_device, void *ctx_buf); @@ -243,6 +245,8 @@ spdk_nvmf_tgt_create(uint32_t max_subsystems) return NULL; } + TAILQ_INSERT_HEAD(&g_nvmf_tgts, tgt, link); + spdk_io_device_register(tgt, spdk_nvmf_tgt_create_poll_group, spdk_nvmf_tgt_destroy_poll_group, @@ -297,6 +301,8 @@ spdk_nvmf_tgt_destroy(struct spdk_nvmf_tgt *tgt, tgt->destroy_cb_fn = cb_fn; tgt->destroy_cb_arg = cb_arg; + TAILQ_REMOVE(&g_nvmf_tgts, tgt, link); + spdk_io_device_unregister(tgt, spdk_nvmf_tgt_destroy_cb); } diff --git a/lib/nvmf/nvmf_internal.h b/lib/nvmf/nvmf_internal.h index 200583031..a74d9b3ce 100644 --- a/lib/nvmf/nvmf_internal.h +++ b/lib/nvmf/nvmf_internal.h @@ -87,6 +87,8 @@ struct spdk_nvmf_tgt { spdk_nvmf_tgt_destroy_done_fn *destroy_cb_fn; void *destroy_cb_arg; + + TAILQ_ENTRY(spdk_nvmf_tgt) link; }; struct spdk_nvmf_host {