ftl: Use global bdev NVMe controllers list for FTL bdevs
This will make possible to make some NVMe bdev related functionalities to be common for NVMe and FTL bdevs. Signed-off-by: Maciej Szwed <maciej.szwed@intel.com> Change-Id: Iafc2acc3ac54deb762bc7205180f41d5befbb42b Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/443552 Reviewed-by: Jim Harris <james.r.harris@intel.com> Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com> Reviewed-by: Wojciech Malikowski <wojciech.malikowski@intel.com> Reviewed-by: Ben Walker <benjamin.walker@intel.com> Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
This commit is contained in:
parent
b91f8c88d4
commit
d5565d6bd4
@ -44,23 +44,14 @@
|
||||
#include "spdk_internal/log.h"
|
||||
|
||||
#include "bdev_ftl.h"
|
||||
#include "common.h"
|
||||
|
||||
#define FTL_COMPLETION_RING_SIZE 4096
|
||||
|
||||
struct ftl_bdev_ctrlr {
|
||||
struct spdk_nvme_ctrlr *ctrlr;
|
||||
|
||||
struct spdk_nvme_transport_id trid;
|
||||
|
||||
size_t ref_cnt;
|
||||
|
||||
LIST_ENTRY(ftl_bdev_ctrlr) list_entry;
|
||||
};
|
||||
|
||||
struct ftl_bdev {
|
||||
struct spdk_bdev bdev;
|
||||
|
||||
struct ftl_bdev_ctrlr *ctrlr;
|
||||
struct nvme_bdev_ctrlr *ctrlr;
|
||||
|
||||
struct spdk_ftl_dev *dev;
|
||||
|
||||
@ -98,8 +89,6 @@ struct ftl_bdev_io {
|
||||
typedef void (*bdev_ftl_finish_fn)(void);
|
||||
|
||||
static LIST_HEAD(, ftl_bdev) g_ftl_bdevs = LIST_HEAD_INITIALIZER(g_ftl_bdevs);
|
||||
static LIST_HEAD(, ftl_bdev_ctrlr) g_ftl_bdev_ctrlrs =
|
||||
LIST_HEAD_INITIALIZER(g_ftl_bdev_ctrlrs);
|
||||
static bdev_ftl_finish_fn g_finish_cb;
|
||||
static size_t g_num_conf_bdevs;
|
||||
static size_t g_num_init_bdevs;
|
||||
@ -125,30 +114,16 @@ static struct spdk_bdev_module g_ftl_if = {
|
||||
|
||||
SPDK_BDEV_MODULE_REGISTER(ftl, &g_ftl_if)
|
||||
|
||||
static struct ftl_bdev_ctrlr *
|
||||
bdev_ftl_ctrlr_find(const struct spdk_nvme_transport_id *trid)
|
||||
{
|
||||
struct ftl_bdev_ctrlr *ftl_ctrlr = NULL;
|
||||
|
||||
LIST_FOREACH(ftl_ctrlr, &g_ftl_bdev_ctrlrs, list_entry) {
|
||||
if (!spdk_nvme_transport_id_compare(&ftl_ctrlr->trid, trid)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return ftl_ctrlr;
|
||||
}
|
||||
|
||||
static struct ftl_bdev_ctrlr *
|
||||
static struct nvme_bdev_ctrlr *
|
||||
bdev_ftl_add_ctrlr(struct spdk_nvme_ctrlr *ctrlr, const struct spdk_nvme_transport_id *trid)
|
||||
{
|
||||
struct ftl_bdev_ctrlr *ftl_ctrlr = NULL;
|
||||
struct nvme_bdev_ctrlr *ftl_ctrlr = NULL;
|
||||
|
||||
pthread_mutex_lock(&g_ftl_bdev_lock);
|
||||
pthread_mutex_lock(&g_bdev_nvme_mutex);
|
||||
|
||||
ftl_ctrlr = bdev_ftl_ctrlr_find(trid);
|
||||
ftl_ctrlr = nvme_bdev_ctrlr_get(trid);
|
||||
if (ftl_ctrlr) {
|
||||
ftl_ctrlr->ref_cnt++;
|
||||
ftl_ctrlr->ref++;
|
||||
} else {
|
||||
ftl_ctrlr = calloc(1, sizeof(*ftl_ctrlr));
|
||||
if (!ftl_ctrlr) {
|
||||
@ -157,31 +132,31 @@ bdev_ftl_add_ctrlr(struct spdk_nvme_ctrlr *ctrlr, const struct spdk_nvme_transpo
|
||||
|
||||
ftl_ctrlr->ctrlr = ctrlr;
|
||||
ftl_ctrlr->trid = *trid;
|
||||
ftl_ctrlr->ref_cnt = 1;
|
||||
ftl_ctrlr->ref = 1;
|
||||
|
||||
LIST_INSERT_HEAD(&g_ftl_bdev_ctrlrs, ftl_ctrlr, list_entry);
|
||||
TAILQ_INSERT_HEAD(&g_nvme_bdev_ctrlrs, ftl_ctrlr, tailq);
|
||||
}
|
||||
out:
|
||||
pthread_mutex_unlock(&g_ftl_bdev_lock);
|
||||
pthread_mutex_unlock(&g_bdev_nvme_mutex);
|
||||
return ftl_ctrlr;
|
||||
}
|
||||
|
||||
static void
|
||||
bdev_ftl_remove_ctrlr(struct ftl_bdev_ctrlr *ctrlr)
|
||||
bdev_ftl_remove_ctrlr(struct nvme_bdev_ctrlr *ctrlr)
|
||||
{
|
||||
pthread_mutex_lock(&g_ftl_bdev_lock);
|
||||
pthread_mutex_lock(&g_bdev_nvme_mutex);
|
||||
|
||||
if (--ctrlr->ref_cnt == 0) {
|
||||
if (--ctrlr->ref == 0) {
|
||||
if (spdk_nvme_detach(ctrlr->ctrlr)) {
|
||||
SPDK_ERRLOG("Failed to detach the controller\n");
|
||||
goto out;
|
||||
}
|
||||
|
||||
LIST_REMOVE(ctrlr, list_entry);
|
||||
TAILQ_REMOVE(&g_nvme_bdev_ctrlrs, ctrlr, tailq);
|
||||
free(ctrlr);
|
||||
}
|
||||
out:
|
||||
pthread_mutex_unlock(&g_ftl_bdev_lock);
|
||||
pthread_mutex_unlock(&g_bdev_nvme_mutex);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -693,7 +668,7 @@ bdev_ftl_create(struct spdk_nvme_ctrlr *ctrlr, const struct spdk_nvme_transport_
|
||||
const struct spdk_uuid *uuid, ftl_bdev_init_fn cb, void *cb_arg)
|
||||
{
|
||||
struct ftl_bdev *ftl_bdev = NULL;
|
||||
struct ftl_bdev_ctrlr *ftl_ctrlr;
|
||||
struct nvme_bdev_ctrlr *ftl_ctrlr;
|
||||
struct spdk_ftl_dev_init_opts opts = {};
|
||||
int rc;
|
||||
|
||||
@ -852,24 +827,24 @@ error:
|
||||
int
|
||||
bdev_ftl_init_bdev(struct ftl_bdev_init_opts *opts, ftl_bdev_init_fn cb, void *cb_arg)
|
||||
{
|
||||
struct ftl_bdev_ctrlr *ftl_ctrlr;
|
||||
struct nvme_bdev_ctrlr *ftl_ctrlr;
|
||||
struct spdk_nvme_ctrlr *ctrlr;
|
||||
|
||||
assert(opts != NULL);
|
||||
assert(cb != NULL);
|
||||
|
||||
pthread_mutex_lock(&g_ftl_bdev_lock);
|
||||
pthread_mutex_lock(&g_bdev_nvme_mutex);
|
||||
|
||||
/* Check already attached controllers first */
|
||||
LIST_FOREACH(ftl_ctrlr, &g_ftl_bdev_ctrlrs, list_entry) {
|
||||
TAILQ_FOREACH(ftl_ctrlr, &g_nvme_bdev_ctrlrs, tailq) {
|
||||
if (!spdk_nvme_transport_id_compare(&ftl_ctrlr->trid, &opts->trid)) {
|
||||
pthread_mutex_unlock(&g_ftl_bdev_lock);
|
||||
pthread_mutex_unlock(&g_bdev_nvme_mutex);
|
||||
return bdev_ftl_create(ftl_ctrlr->ctrlr, &ftl_ctrlr->trid, opts->name,
|
||||
&opts->range, opts->mode, &opts->uuid, cb, cb_arg);
|
||||
}
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&g_ftl_bdev_lock);
|
||||
pthread_mutex_unlock(&g_bdev_nvme_mutex);
|
||||
|
||||
ctrlr = spdk_nvme_connect(&opts->trid, NULL, 0);
|
||||
if (!ctrlr) {
|
||||
|
@ -116,7 +116,6 @@ static bool g_nvme_hotplug_enabled = false;
|
||||
static struct spdk_thread *g_bdev_nvme_init_thread;
|
||||
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 void nvme_ctrlr_create_bdevs(struct nvme_bdev_ctrlr *nvme_bdev_ctrlr);
|
||||
static int bdev_nvme_library_init(void);
|
||||
|
@ -35,6 +35,7 @@
|
||||
#include "common.h"
|
||||
|
||||
struct nvme_bdev_ctrlrs g_nvme_bdev_ctrlrs = TAILQ_HEAD_INITIALIZER(g_nvme_bdev_ctrlrs);
|
||||
pthread_mutex_t g_bdev_nvme_mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
|
||||
struct nvme_bdev_ctrlr *
|
||||
nvme_bdev_ctrlr_get(const struct spdk_nvme_transport_id *trid)
|
||||
|
@ -39,6 +39,7 @@
|
||||
|
||||
TAILQ_HEAD(nvme_bdev_ctrlrs, nvme_bdev_ctrlr);
|
||||
extern struct nvme_bdev_ctrlrs g_nvme_bdev_ctrlrs;
|
||||
extern pthread_mutex_t g_bdev_nvme_mutex;
|
||||
|
||||
#define NVME_MAX_CONTROLLERS 1024
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user