diff --git a/lib/bdev/nvme/bdev_nvme.c b/lib/bdev/nvme/bdev_nvme.c index fd5da8cd9..47cfedf12 100644 --- a/lib/bdev/nvme/bdev_nvme.c +++ b/lib/bdev/nvme/bdev_nvme.c @@ -34,6 +34,7 @@ #include "spdk/stdinc.h" #include "bdev_nvme.h" +#include "common.h" #include "spdk/config.h" #include "spdk/conf.h" @@ -117,9 +118,6 @@ static struct spdk_poller *g_hotplug_poller; static char *g_nvme_hostnqn = NULL; static pthread_mutex_t g_bdev_nvme_mutex = PTHREAD_MUTEX_INITIALIZER; -static TAILQ_HEAD(, nvme_bdev_ctrlr) g_nvme_bdev_ctrlrs = TAILQ_HEAD_INITIALIZER( - g_nvme_bdev_ctrlrs); - static void nvme_ctrlr_create_bdevs(struct nvme_bdev_ctrlr *nvme_bdev_ctrlr); static int bdev_nvme_library_init(void); static void bdev_nvme_library_fini(void); @@ -829,38 +827,6 @@ hotplug_probe_cb(void *cb_ctx, const struct spdk_nvme_transport_id *trid, return true; } -static struct nvme_bdev_ctrlr * -nvme_ctrlr_get(const struct spdk_nvme_transport_id *trid) -{ - struct nvme_bdev_ctrlr *nvme_bdev_ctrlr; - - TAILQ_FOREACH(nvme_bdev_ctrlr, &g_nvme_bdev_ctrlrs, tailq) { - if (spdk_nvme_transport_id_compare(trid, &nvme_bdev_ctrlr->trid) == 0) { - return nvme_bdev_ctrlr; - } - } - - return NULL; -} - -static struct nvme_bdev_ctrlr * -nvme_ctrlr_get_by_name(const char *name) -{ - struct nvme_bdev_ctrlr *nvme_bdev_ctrlr; - - if (name == NULL) { - return NULL; - } - - TAILQ_FOREACH(nvme_bdev_ctrlr, &g_nvme_bdev_ctrlrs, tailq) { - if (strcmp(name, nvme_bdev_ctrlr->name) == 0) { - return nvme_bdev_ctrlr; - } - } - - return NULL; -} - static bool probe_cb(void *cb_ctx, const struct spdk_nvme_transport_id *trid, struct spdk_nvme_ctrlr_opts *opts) @@ -869,7 +835,7 @@ probe_cb(void *cb_ctx, const struct spdk_nvme_transport_id *trid, SPDK_DEBUGLOG(SPDK_LOG_BDEV_NVME, "Probing device %s\n", trid->traddr); - if (nvme_ctrlr_get(trid)) { + if (nvme_bdev_ctrlr_get(trid)) { SPDK_ERRLOG("A controller with the provided trid (traddr: %s) already exists.\n", trid->traddr); return false; @@ -1229,12 +1195,12 @@ spdk_bdev_nvme_create(struct spdk_nvme_transport_id *trid, size_t j; struct nvme_probe_skip_entry *entry, *tmp; - if (nvme_ctrlr_get(trid) != NULL) { + if (nvme_bdev_ctrlr_get(trid) != NULL) { SPDK_ERRLOG("A controller with the provided trid (traddr: %s) already exists.\n", trid->traddr); return -1; } - if (nvme_ctrlr_get_by_name(base_name)) { + if (nvme_bdev_ctrlr_get_by_name(base_name)) { SPDK_ERRLOG("A controller with the provided name (%s) already exists.\n", base_name); return -1; } @@ -1274,7 +1240,7 @@ spdk_bdev_nvme_create(struct spdk_nvme_transport_id *trid, return -1; } - nvme_bdev_ctrlr = nvme_ctrlr_get(trid); + nvme_bdev_ctrlr = nvme_bdev_ctrlr_get(trid); if (!nvme_bdev_ctrlr) { SPDK_ERRLOG("Failed to find new NVMe controller\n"); return -1; @@ -1317,7 +1283,7 @@ spdk_bdev_nvme_delete(const char *name) return -EINVAL; } - nvme_bdev_ctrlr = nvme_ctrlr_get_by_name(name); + nvme_bdev_ctrlr = nvme_bdev_ctrlr_get_by_name(name); if (nvme_bdev_ctrlr == NULL) { SPDK_ERRLOG("Failed to find NVMe controller\n"); return -ENODEV; @@ -1471,7 +1437,7 @@ bdev_nvme_library_init(void) struct spdk_nvme_ctrlr *ctrlr; struct spdk_nvme_ctrlr_opts opts; - if (nvme_ctrlr_get(&probe_ctx->trids[i])) { + if (nvme_bdev_ctrlr_get(&probe_ctx->trids[i])) { SPDK_ERRLOG("A controller with the provided trid (traddr: %s) already exists.\n", probe_ctx->trids[i].traddr); rc = -1; @@ -1527,7 +1493,7 @@ bdev_nvme_library_init(void) continue; } - if (!nvme_ctrlr_get(&probe_ctx->trids[i])) { + if (!nvme_bdev_ctrlr_get(&probe_ctx->trids[i])) { SPDK_ERRLOG("NVMe SSD \"%s\" could not be found.\n", probe_ctx->trids[i].traddr); SPDK_ERRLOG("Check PCIe BDF and that it is attached to UIO/VFIO driver.\n"); } diff --git a/lib/bdev/nvme/bdev_nvme.h b/lib/bdev/nvme/bdev_nvme.h index 39e0bd928..3753020b9 100644 --- a/lib/bdev/nvme/bdev_nvme.h +++ b/lib/bdev/nvme/bdev_nvme.h @@ -40,8 +40,6 @@ #include "spdk/nvme.h" #include "spdk/bdev_module.h" -#define NVME_MAX_CONTROLLERS 1024 - enum spdk_bdev_timeout_action { SPDK_BDEV_NVME_TIMEOUT_ACTION_NONE = 0, SPDK_BDEV_NVME_TIMEOUT_ACTION_RESET, @@ -55,41 +53,6 @@ struct spdk_bdev_nvme_opts { uint64_t nvme_adminq_poll_period_us; }; -struct nvme_bdev_ctrlr { - /** - * points to pinned, physically contiguous memory region; - * contains 4KB IDENTIFY structure for controller which is - * target for CONTROLLER IDENTIFY command during initialization - */ - struct spdk_nvme_ctrlr *ctrlr; - struct spdk_nvme_transport_id trid; - char *name; - int ref; - bool destruct; - /** - * PI check flags. This flags is set to NVMe controllers created only - * through construct_nvme_bdev RPC or .INI config file. Hot added - * NVMe controllers are not included. - */ - uint32_t prchk_flags; - uint32_t num_ns; - /** Array of bdevs indexed by nsid - 1 */ - struct nvme_bdev *bdevs; - - struct spdk_poller *adminq_timer_poller; - - /** linked list pointer for device list */ - TAILQ_ENTRY(nvme_bdev_ctrlr) tailq; -}; - -struct nvme_bdev { - struct spdk_bdev disk; - struct nvme_bdev_ctrlr *nvme_bdev_ctrlr; - uint32_t id; - bool active; - struct spdk_nvme_ns *ns; -}; - void spdk_bdev_nvme_dump_trid_json(struct spdk_nvme_transport_id *trid, struct spdk_json_write_ctx *w); diff --git a/lib/bdev/nvme/bdev_nvme_rpc.c b/lib/bdev/nvme/bdev_nvme_rpc.c index 15835b8e5..b042fcac4 100644 --- a/lib/bdev/nvme/bdev_nvme_rpc.c +++ b/lib/bdev/nvme/bdev_nvme_rpc.c @@ -34,6 +34,7 @@ #include "spdk/stdinc.h" #include "bdev_nvme.h" +#include "common.h" #include "spdk/string.h" #include "spdk/rpc.h" diff --git a/lib/bdev/nvme/common.c b/lib/bdev/nvme/common.c index d65da1694..01301de40 100644 --- a/lib/bdev/nvme/common.c +++ b/lib/bdev/nvme/common.c @@ -30,3 +30,40 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ + +#include "spdk/env.h" +#include "common.h" + +struct nvme_bdev_ctrlrs g_nvme_bdev_ctrlrs = TAILQ_HEAD_INITIALIZER(g_nvme_bdev_ctrlrs); + +struct nvme_bdev_ctrlr * +nvme_bdev_ctrlr_get(const struct spdk_nvme_transport_id *trid) +{ + struct nvme_bdev_ctrlr *nvme_bdev_ctrlr; + + TAILQ_FOREACH(nvme_bdev_ctrlr, &g_nvme_bdev_ctrlrs, tailq) { + if (spdk_nvme_transport_id_compare(trid, &nvme_bdev_ctrlr->trid) == 0) { + return nvme_bdev_ctrlr; + } + } + + return NULL; +} + +struct nvme_bdev_ctrlr * +nvme_bdev_ctrlr_get_by_name(const char *name) +{ + struct nvme_bdev_ctrlr *nvme_bdev_ctrlr; + + if (name == NULL) { + return NULL; + } + + TAILQ_FOREACH(nvme_bdev_ctrlr, &g_nvme_bdev_ctrlrs, tailq) { + if (strcmp(name, nvme_bdev_ctrlr->name) == 0) { + return nvme_bdev_ctrlr; + } + } + + return NULL; +} diff --git a/lib/bdev/nvme/common.h b/lib/bdev/nvme/common.h index 861083791..3a6bd55ac 100644 --- a/lib/bdev/nvme/common.h +++ b/lib/bdev/nvme/common.h @@ -34,4 +34,50 @@ #ifndef SPDK_COMMON_BDEV_NVME_H #define SPDK_COMMON_BDEV_NVME_H +#include "spdk/nvme.h" +#include "spdk/bdev_module.h" + +TAILQ_HEAD(nvme_bdev_ctrlrs, nvme_bdev_ctrlr); +extern struct nvme_bdev_ctrlrs g_nvme_bdev_ctrlrs; + +#define NVME_MAX_CONTROLLERS 1024 + +struct nvme_bdev_ctrlr { + /** + * points to pinned, physically contiguous memory region; + * contains 4KB IDENTIFY structure for controller which is + * target for CONTROLLER IDENTIFY command during initialization + */ + struct spdk_nvme_ctrlr *ctrlr; + struct spdk_nvme_transport_id trid; + char *name; + int ref; + bool destruct; + /** + * PI check flags. This flags is set to NVMe controllers created only + * through construct_nvme_bdev RPC or .INI config file. Hot added + * NVMe controllers are not included. + */ + uint32_t prchk_flags; + uint32_t num_ns; + /** Array of bdevs indexed by nsid - 1 */ + struct nvme_bdev *bdevs; + + struct spdk_poller *adminq_timer_poller; + + /** linked list pointer for device list */ + TAILQ_ENTRY(nvme_bdev_ctrlr) tailq; +}; + +struct nvme_bdev { + struct spdk_bdev disk; + struct nvme_bdev_ctrlr *nvme_bdev_ctrlr; + uint32_t id; + bool active; + struct spdk_nvme_ns *ns; +}; + +struct nvme_bdev_ctrlr *nvme_bdev_ctrlr_get(const struct spdk_nvme_transport_id *trid); +struct nvme_bdev_ctrlr *nvme_bdev_ctrlr_get_by_name(const char *name); + #endif /* SPDK_COMMON_BDEV_NVME_H */ diff --git a/lib/bdev/nvme/nvme_rpc.c b/lib/bdev/nvme/nvme_rpc.c index d1724909a..23fa524dc 100644 --- a/lib/bdev/nvme/nvme_rpc.c +++ b/lib/bdev/nvme/nvme_rpc.c @@ -39,6 +39,7 @@ #include "spdk_internal/log.h" #include "bdev_nvme.h" +#include "common.h" #include "spdk/base64.h" enum spdk_nvme_rpc_type {