bdev/ftl: Remove NVMe dependencies
This patch changes FTL bdev to vritual bdev. Change-Id: I7b96af56053874b670a76b910a846837396119d9 Signed-off-by: Wojciech Malikowski <wojciech.malikowski@intel.com> Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/479703 Community-CI: Broadcom SPDK FC-NVMe CI <spdk-ci.pdl@broadcom.com> Tested-by: SPDK CI Jenkins <sys_sgci@intel.com> Reviewed-by: Tomasz Zawadzki <tomasz.zawadzki@intel.com> Reviewed-by: Jim Harris <james.r.harris@intel.com> Reviewed-by: Konrad Sztyber <konrad.sztyber@intel.com>
This commit is contained in:
parent
843f296e2e
commit
e2e6254651
@ -123,15 +123,15 @@ DEPDIRS-bdev_split := $(BDEV_DEPS_CONF)
|
||||
DEPDIRS-bdev_compress := $(BDEV_DEPS_THREAD) reduce
|
||||
DEPDIRS-bdev_delay := $(BDEV_DEPS_THREAD)
|
||||
DEPDIRS-bdev_zone_block := $(BDEV_DEPS_THREAD)
|
||||
ifeq ($(OS),Linux)
|
||||
DEPDIRS-bdev_ftl := $(BDEV_DEPS_THREAD) ftl
|
||||
endif
|
||||
|
||||
DEPDIRS-bdev_aio := $(BDEV_DEPS_CONF_THREAD)
|
||||
DEPDIRS-bdev_crypto := $(BDEV_DEPS_CONF_THREAD)
|
||||
DEPDIRS-bdev_iscsi := $(BDEV_DEPS_CONF_THREAD)
|
||||
DEPDIRS-bdev_null := $(BDEV_DEPS_CONF_THREAD)
|
||||
DEPDIRS-bdev_nvme = $(BDEV_DEPS_CONF_THREAD) nvme
|
||||
ifeq ($(OS),Linux)
|
||||
DEPDIRS-bdev_nvme += ftl
|
||||
endif
|
||||
DEPDIRS-bdev_ocf := $(BDEV_DEPS_CONF_THREAD)
|
||||
DEPDIRS-bdev_passthru := $(BDEV_DEPS_CONF_THREAD)
|
||||
DEPDIRS-bdev_pmem := $(BDEV_DEPS_CONF_THREAD)
|
||||
|
@ -55,7 +55,7 @@ SYS_LIBS += -libverbs -lrdmacm
|
||||
endif
|
||||
|
||||
ifeq ($(OS),Linux)
|
||||
BLOCKDEV_MODULES_LIST += ftl
|
||||
BLOCKDEV_MODULES_LIST += bdev_ftl ftl
|
||||
BLOCKDEV_MODULES_LIST += bdev_aio
|
||||
SYS_LIBS += -laio
|
||||
ifeq ($(CONFIG_VIRTIO),y)
|
||||
|
@ -45,7 +45,7 @@ DIRS-$(CONFIG_REDUCE) += compress
|
||||
DIRS-$(CONFIG_URING) += uring
|
||||
|
||||
ifeq ($(OS),Linux)
|
||||
DIRS-y += aio
|
||||
DIRS-y += aio ftl
|
||||
DIRS-$(CONFIG_ISCSI_INITIATOR) += iscsi
|
||||
DIRS-$(CONFIG_VIRTIO) += virtio
|
||||
DIRS-$(CONFIG_PMDK) += pmem
|
||||
|
40
module/bdev/ftl/Makefile
Normal file
40
module/bdev/ftl/Makefile
Normal file
@ -0,0 +1,40 @@
|
||||
#
|
||||
# BSD LICENSE
|
||||
#
|
||||
# Copyright (c) Intel Corporation.
|
||||
# All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions
|
||||
# are met:
|
||||
#
|
||||
# * Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
# * Redistributions in binary form must reproduce the above copyright
|
||||
# notice, this list of conditions and the following disclaimer in
|
||||
# the documentation and/or other materials provided with the
|
||||
# distribution.
|
||||
# * Neither the name of Intel Corporation nor the names of its
|
||||
# contributors may be used to endorse or promote products derived
|
||||
# from this software without specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#
|
||||
|
||||
SPDK_ROOT_DIR := $(abspath $(CURDIR)/../../..)
|
||||
include $(SPDK_ROOT_DIR)/mk/spdk.common.mk
|
||||
|
||||
C_SRCS += bdev_ftl.c bdev_ftl_rpc.c
|
||||
LIBNAME = bdev_ftl
|
||||
|
||||
include $(SPDK_ROOT_DIR)/mk/spdk.lib.mk
|
@ -43,27 +43,23 @@
|
||||
#include "spdk/string.h"
|
||||
#include "spdk/ftl.h"
|
||||
#include "spdk_internal/log.h"
|
||||
#include "spdk/nvme_ocssd.h"
|
||||
|
||||
#include "bdev_ftl.h"
|
||||
#include "common.h"
|
||||
|
||||
#define FTL_COMPLETION_RING_SIZE 4096
|
||||
|
||||
struct ftl_bdev {
|
||||
struct spdk_bdev bdev;
|
||||
|
||||
struct nvme_bdev_ctrlr *ctrlr;
|
||||
|
||||
struct spdk_ftl_dev *dev;
|
||||
|
||||
struct spdk_bdev_desc *base_bdev_desc;
|
||||
|
||||
struct spdk_bdev_desc *cache_bdev_desc;
|
||||
|
||||
ftl_bdev_init_fn init_cb;
|
||||
|
||||
void *init_arg;
|
||||
|
||||
LIST_ENTRY(ftl_bdev) list_entry;
|
||||
};
|
||||
|
||||
struct ftl_io_channel {
|
||||
@ -86,8 +82,6 @@ struct ftl_bdev_io {
|
||||
struct spdk_ring *ring;
|
||||
|
||||
int status;
|
||||
|
||||
struct spdk_thread *orig_thread;
|
||||
};
|
||||
|
||||
struct ftl_deferred_init {
|
||||
@ -96,17 +90,8 @@ struct ftl_deferred_init {
|
||||
LIST_ENTRY(ftl_deferred_init) entry;
|
||||
};
|
||||
|
||||
typedef void (*bdev_ftl_finish_fn)(void);
|
||||
|
||||
static LIST_HEAD(, ftl_bdev) g_ftl_bdevs = LIST_HEAD_INITIALIZER(g_ftl_bdevs);
|
||||
static size_t g_num_conf_bdevs;
|
||||
static size_t g_num_init_bdevs;
|
||||
static pthread_mutex_t g_ftl_bdev_lock;
|
||||
static LIST_HEAD(, ftl_deferred_init) g_deferred_init;
|
||||
|
||||
static int bdev_ftl_initialize(void);
|
||||
static void bdev_ftl_finish(void);
|
||||
static void bdev_ftl_examine(struct spdk_bdev *);
|
||||
|
||||
static int
|
||||
bdev_ftl_get_ctx_size(void)
|
||||
@ -116,69 +101,18 @@ bdev_ftl_get_ctx_size(void)
|
||||
|
||||
static struct spdk_bdev_module g_ftl_if = {
|
||||
.name = "ftl",
|
||||
.async_init = true,
|
||||
.async_fini = false,
|
||||
.module_init = bdev_ftl_initialize,
|
||||
.module_fini = bdev_ftl_finish,
|
||||
.examine_disk = bdev_ftl_examine,
|
||||
.get_ctx_size = bdev_ftl_get_ctx_size,
|
||||
};
|
||||
|
||||
SPDK_BDEV_MODULE_REGISTER(ftl, &g_ftl_if)
|
||||
|
||||
static struct nvme_bdev_ctrlr *
|
||||
bdev_ftl_add_ctrlr(struct spdk_nvme_ctrlr *ctrlr, const struct spdk_nvme_transport_id *trid)
|
||||
{
|
||||
struct nvme_bdev_ctrlr *ftl_ctrlr = NULL;
|
||||
|
||||
pthread_mutex_lock(&g_bdev_nvme_mutex);
|
||||
|
||||
ftl_ctrlr = nvme_bdev_ctrlr_get(trid);
|
||||
if (ftl_ctrlr) {
|
||||
ftl_ctrlr->ref++;
|
||||
} else {
|
||||
ftl_ctrlr = calloc(1, sizeof(*ftl_ctrlr));
|
||||
if (!ftl_ctrlr) {
|
||||
goto out;
|
||||
}
|
||||
|
||||
ftl_ctrlr->ctrlr = ctrlr;
|
||||
ftl_ctrlr->trid = *trid;
|
||||
ftl_ctrlr->ref = 1;
|
||||
ftl_ctrlr->ftl_managed = true;
|
||||
|
||||
ftl_ctrlr->name = spdk_sprintf_alloc("NVMe_%s", trid->traddr);
|
||||
if (!ftl_ctrlr->name) {
|
||||
SPDK_ERRLOG("Unable to allocate memory for bdev controller name.\n");
|
||||
free(ftl_ctrlr);
|
||||
ftl_ctrlr = NULL;
|
||||
goto out;
|
||||
}
|
||||
|
||||
TAILQ_INSERT_HEAD(&g_nvme_bdev_ctrlrs, ftl_ctrlr, tailq);
|
||||
}
|
||||
out:
|
||||
pthread_mutex_unlock(&g_bdev_nvme_mutex);
|
||||
return ftl_ctrlr;
|
||||
}
|
||||
|
||||
static void
|
||||
bdev_ftl_remove_ctrlr(struct nvme_bdev_ctrlr *ctrlr)
|
||||
bdev_ftl_close(struct spdk_bdev_desc *bdev_desc)
|
||||
{
|
||||
pthread_mutex_lock(&g_bdev_nvme_mutex);
|
||||
|
||||
if (--ctrlr->ref == 0) {
|
||||
if (spdk_nvme_detach(ctrlr->ctrlr)) {
|
||||
SPDK_ERRLOG("Failed to detach the controller\n");
|
||||
goto out;
|
||||
}
|
||||
|
||||
TAILQ_REMOVE(&g_nvme_bdev_ctrlrs, ctrlr, tailq);
|
||||
free(ctrlr->name);
|
||||
free(ctrlr);
|
||||
}
|
||||
out:
|
||||
pthread_mutex_unlock(&g_bdev_nvme_mutex);
|
||||
spdk_bdev_module_release_bdev(spdk_bdev_desc_get_bdev(bdev_desc));
|
||||
spdk_bdev_close(bdev_desc);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -186,17 +120,11 @@ bdev_ftl_free_cb(struct spdk_ftl_dev *dev, void *ctx, int status)
|
||||
{
|
||||
struct ftl_bdev *ftl_bdev = ctx;
|
||||
|
||||
pthread_mutex_lock(&g_ftl_bdev_lock);
|
||||
LIST_REMOVE(ftl_bdev, list_entry);
|
||||
pthread_mutex_unlock(&g_ftl_bdev_lock);
|
||||
|
||||
spdk_io_device_unregister(ftl_bdev, NULL);
|
||||
|
||||
bdev_ftl_remove_ctrlr(ftl_bdev->ctrlr);
|
||||
bdev_ftl_close(ftl_bdev->base_bdev_desc);
|
||||
|
||||
if (ftl_bdev->cache_bdev_desc) {
|
||||
spdk_bdev_module_release_bdev(spdk_bdev_desc_get_bdev(ftl_bdev->cache_bdev_desc));
|
||||
spdk_bdev_close(ftl_bdev->cache_bdev_desc);
|
||||
bdev_ftl_close(ftl_bdev->cache_bdev_desc);
|
||||
}
|
||||
|
||||
spdk_bdev_destruct_done(&ftl_bdev->bdev, status);
|
||||
@ -254,7 +182,6 @@ bdev_ftl_fill_bio(struct ftl_bdev *ftl_bdev, struct spdk_io_channel *ch,
|
||||
|
||||
memset(io, 0, sizeof(*io));
|
||||
|
||||
io->orig_thread = spdk_io_channel_get_thread(ch);
|
||||
io->status = SPDK_BDEV_IO_STATUS_SUCCESS;
|
||||
io->ring = ioch->ring;
|
||||
io->bdev = ftl_bdev;
|
||||
@ -402,16 +329,12 @@ static void
|
||||
_bdev_ftl_write_config_info(struct ftl_bdev *ftl_bdev, struct spdk_json_write_ctx *w)
|
||||
{
|
||||
struct spdk_ftl_attrs attrs;
|
||||
const char *trtype_str, *cache_bdev;
|
||||
const char *cache_bdev, *base_bdev;
|
||||
|
||||
spdk_ftl_dev_get_attrs(ftl_bdev->dev, &attrs);
|
||||
|
||||
trtype_str = spdk_nvme_transport_id_trtype_str(ftl_bdev->ctrlr->trid.trtype);
|
||||
if (trtype_str) {
|
||||
spdk_json_write_named_string(w, "trtype", trtype_str);
|
||||
}
|
||||
|
||||
spdk_json_write_named_string(w, "traddr", ftl_bdev->ctrlr->trid.traddr);
|
||||
base_bdev = spdk_bdev_get_name(spdk_bdev_desc_get_bdev(ftl_bdev->base_bdev_desc));
|
||||
spdk_json_write_named_string(w, "base_bdev", base_bdev);
|
||||
|
||||
if (ftl_bdev->cache_bdev_desc) {
|
||||
cache_bdev = spdk_bdev_get_name(spdk_bdev_desc_get_bdev(ftl_bdev->cache_bdev_desc));
|
||||
@ -485,105 +408,6 @@ static const struct spdk_bdev_fn_table ftl_fn_table = {
|
||||
.dump_info_json = bdev_ftl_dump_info_json,
|
||||
};
|
||||
|
||||
static int
|
||||
bdev_ftl_defer_init(struct ftl_bdev_init_opts *opts)
|
||||
{
|
||||
struct ftl_deferred_init *init;
|
||||
|
||||
init = calloc(1, sizeof(*init));
|
||||
if (!init) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
init->opts = *opts;
|
||||
LIST_INSERT_HEAD(&g_deferred_init, init, entry);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
bdev_ftl_read_bdev_config(struct spdk_conf_section *sp,
|
||||
struct ftl_bdev_init_opts *opts,
|
||||
size_t *num_bdevs)
|
||||
{
|
||||
const char *val, *trid;
|
||||
int i, rc = 0, num_deferred = 0;
|
||||
|
||||
*num_bdevs = 0;
|
||||
|
||||
for (i = 0; i < FTL_MAX_BDEVS; i++, opts++) {
|
||||
trid = val = spdk_conf_section_get_nmval(sp, "TransportID", i, 0);
|
||||
if (!val) {
|
||||
break;
|
||||
}
|
||||
|
||||
rc = spdk_nvme_transport_id_parse(&opts->trid, val);
|
||||
if (rc < 0) {
|
||||
SPDK_ERRLOG("Unable to parse TransportID: %s\n", trid);
|
||||
rc = -1;
|
||||
break;
|
||||
}
|
||||
|
||||
if (opts->trid.trtype != SPDK_NVME_TRANSPORT_PCIE) {
|
||||
SPDK_ERRLOG("Unsupported transport type for TransportID: %s\n", trid);
|
||||
continue;
|
||||
}
|
||||
|
||||
val = spdk_conf_section_get_nmval(sp, "TransportID", i, 1);
|
||||
if (!val) {
|
||||
SPDK_ERRLOG("No name provided for TransportID: %s\n", trid);
|
||||
rc = -1;
|
||||
break;
|
||||
}
|
||||
|
||||
opts->name = val;
|
||||
|
||||
val = spdk_conf_section_get_nmval(sp, "TransportID", i, 2);
|
||||
if (!val) {
|
||||
SPDK_ERRLOG("No UUID provided for TransportID: %s\n", trid);
|
||||
rc = -1;
|
||||
break;
|
||||
}
|
||||
|
||||
rc = spdk_uuid_parse(&opts->uuid, val);
|
||||
if (rc < 0) {
|
||||
SPDK_ERRLOG("Failed to parse uuid: %s for TransportID: %s\n", val, trid);
|
||||
rc = -1;
|
||||
break;
|
||||
}
|
||||
|
||||
if (spdk_mem_all_zero(&opts->uuid, sizeof(opts->uuid))) {
|
||||
opts->mode = SPDK_FTL_MODE_CREATE;
|
||||
} else {
|
||||
opts->mode = 0;
|
||||
}
|
||||
|
||||
val = spdk_conf_section_get_nmval(sp, "TransportID", i, 3);
|
||||
if (!val) {
|
||||
continue;
|
||||
}
|
||||
|
||||
opts->cache_bdev = val;
|
||||
if (!spdk_bdev_get_by_name(val)) {
|
||||
SPDK_INFOLOG(SPDK_LOG_BDEV_FTL, "Deferring bdev %s initialization\n", opts->name);
|
||||
|
||||
if (bdev_ftl_defer_init(opts)) {
|
||||
SPDK_ERRLOG("Unable to initialize bdev %s\n", opts->name);
|
||||
rc = -1;
|
||||
break;
|
||||
}
|
||||
|
||||
num_deferred++;
|
||||
}
|
||||
}
|
||||
|
||||
if (!rc) {
|
||||
*num_bdevs = i - num_deferred;
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
static int
|
||||
bdev_ftl_poll(void *arg)
|
||||
{
|
||||
@ -635,9 +459,9 @@ bdev_ftl_io_channel_destroy_cb(void *io_device, void *ctx_buf)
|
||||
}
|
||||
|
||||
static void
|
||||
bdev_ftl_cache_removed_cb(void *ctx)
|
||||
bdev_ftl_bdev_removed_cb(void *ctx)
|
||||
{
|
||||
assert(0 && "Removed cached bdev\n");
|
||||
assert(0 && "Removed dependent bdev\n");
|
||||
}
|
||||
|
||||
static void
|
||||
@ -685,21 +509,16 @@ bdev_ftl_create_cb(struct spdk_ftl_dev *dev, void *ctx, int status)
|
||||
info.name = ftl_bdev->bdev.name;
|
||||
info.uuid = ftl_bdev->bdev.uuid;
|
||||
|
||||
pthread_mutex_lock(&g_ftl_bdev_lock);
|
||||
LIST_INSERT_HEAD(&g_ftl_bdevs, ftl_bdev, list_entry);
|
||||
pthread_mutex_unlock(&g_ftl_bdev_lock);
|
||||
|
||||
init_cb(&info, init_arg, 0);
|
||||
return;
|
||||
|
||||
error_unregister:
|
||||
spdk_io_device_unregister(ftl_bdev, NULL);
|
||||
error_dev:
|
||||
bdev_ftl_remove_ctrlr(ftl_bdev->ctrlr);
|
||||
bdev_ftl_close(ftl_bdev->base_bdev_desc);
|
||||
|
||||
if (ftl_bdev->cache_bdev_desc) {
|
||||
spdk_bdev_module_release_bdev(spdk_bdev_desc_get_bdev(ftl_bdev->cache_bdev_desc));
|
||||
spdk_bdev_close(ftl_bdev->cache_bdev_desc);
|
||||
bdev_ftl_close(ftl_bdev->cache_bdev_desc);
|
||||
}
|
||||
|
||||
free(ftl_bdev->bdev.name);
|
||||
@ -709,64 +528,79 @@ error_dev:
|
||||
}
|
||||
|
||||
static int
|
||||
bdev_ftl_create(struct spdk_nvme_ctrlr *ctrlr, const struct ftl_bdev_init_opts *bdev_opts,
|
||||
ftl_bdev_init_fn cb, void *cb_arg)
|
||||
bdev_ftl_init_dependent_bdev(struct ftl_bdev *ftl_bdev, const char *bdev_name,
|
||||
struct spdk_bdev_desc **bdev_desc)
|
||||
{
|
||||
struct spdk_bdev *bdev = NULL;
|
||||
|
||||
bdev = spdk_bdev_get_by_name(bdev_name);
|
||||
if (!bdev) {
|
||||
SPDK_ERRLOG("Unable to find bdev: %s\n", bdev_name);
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
if (spdk_bdev_open(bdev, true, bdev_ftl_bdev_removed_cb,
|
||||
ftl_bdev, bdev_desc)) {
|
||||
SPDK_ERRLOG("Unable to open bdev: %s\n", bdev_name);
|
||||
return -EPERM;
|
||||
}
|
||||
|
||||
if (spdk_bdev_module_claim_bdev(bdev, *bdev_desc, &g_ftl_if)) {
|
||||
SPDK_ERRLOG("Unable to claim bdev %s\n", bdev_name);
|
||||
spdk_bdev_close(*bdev_desc);
|
||||
return -EPERM;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
bdev_ftl_create_bdev(const struct ftl_bdev_init_opts *bdev_opts,
|
||||
ftl_bdev_init_fn cb, void *cb_arg)
|
||||
{
|
||||
struct ftl_bdev *ftl_bdev = NULL;
|
||||
struct spdk_bdev *cache_bdev = NULL;
|
||||
struct nvme_bdev_ctrlr *ftl_ctrlr;
|
||||
struct spdk_ftl_dev_init_opts opts = {};
|
||||
int rc;
|
||||
|
||||
ftl_ctrlr = bdev_ftl_add_ctrlr(ctrlr, &bdev_opts->trid);
|
||||
if (!ftl_ctrlr) {
|
||||
spdk_nvme_detach(ctrlr);
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
ftl_bdev = calloc(1, sizeof(*ftl_bdev));
|
||||
if (!ftl_bdev) {
|
||||
SPDK_ERRLOG("Could not allocate ftl_bdev\n");
|
||||
rc = -ENOMEM;
|
||||
goto error_ctrlr;
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
ftl_bdev->bdev.name = strdup(bdev_opts->name);
|
||||
if (!ftl_bdev->bdev.name) {
|
||||
rc = -ENOMEM;
|
||||
goto error_ctrlr;
|
||||
goto error_bdev;
|
||||
}
|
||||
|
||||
rc = bdev_ftl_init_dependent_bdev(ftl_bdev, bdev_opts->base_bdev,
|
||||
&ftl_bdev->base_bdev_desc);
|
||||
if (rc) {
|
||||
goto error_name;
|
||||
}
|
||||
|
||||
if (!spdk_bdev_is_zoned(spdk_bdev_desc_get_bdev(ftl_bdev->base_bdev_desc))) {
|
||||
SPDK_ERRLOG("Bdev dosen't support zone capabilities: %s\n", bdev_opts->base_bdev);
|
||||
rc = -EINVAL;
|
||||
goto error_cache;
|
||||
}
|
||||
|
||||
if (bdev_opts->cache_bdev) {
|
||||
cache_bdev = spdk_bdev_get_by_name(bdev_opts->cache_bdev);
|
||||
if (!cache_bdev) {
|
||||
SPDK_ERRLOG("Unable to find bdev: %s\n", bdev_opts->cache_bdev);
|
||||
rc = -ENOENT;
|
||||
goto error_name;
|
||||
}
|
||||
|
||||
if (spdk_bdev_open(cache_bdev, true, bdev_ftl_cache_removed_cb,
|
||||
ftl_bdev, &ftl_bdev->cache_bdev_desc)) {
|
||||
SPDK_ERRLOG("Unable to open cache bdev: %s\n", bdev_opts->cache_bdev);
|
||||
rc = -EPERM;
|
||||
goto error_name;
|
||||
}
|
||||
|
||||
if (spdk_bdev_module_claim_bdev(cache_bdev, ftl_bdev->cache_bdev_desc, &g_ftl_if)) {
|
||||
SPDK_ERRLOG("Unable to claim cache bdev %s\n", bdev_opts->cache_bdev);
|
||||
spdk_bdev_close(ftl_bdev->cache_bdev_desc);
|
||||
rc = -EPERM;
|
||||
goto error_name;
|
||||
rc = bdev_ftl_init_dependent_bdev(ftl_bdev, bdev_opts->cache_bdev,
|
||||
&ftl_bdev->cache_bdev_desc);
|
||||
if (rc) {
|
||||
goto error_cache;
|
||||
}
|
||||
}
|
||||
|
||||
ftl_bdev->ctrlr = ftl_ctrlr;
|
||||
ftl_bdev->init_cb = cb;
|
||||
ftl_bdev->init_arg = cb_arg;
|
||||
|
||||
opts.mode = bdev_opts->mode;
|
||||
opts.uuid = bdev_opts->uuid;
|
||||
opts.name = ftl_bdev->bdev.name;
|
||||
opts.base_bdev_desc = ftl_bdev->base_bdev_desc;
|
||||
opts.cache_bdev_desc = ftl_bdev->cache_bdev_desc;
|
||||
opts.conf = &bdev_opts->ftl_conf;
|
||||
|
||||
@ -783,203 +617,41 @@ bdev_ftl_create(struct spdk_nvme_ctrlr *ctrlr, const struct ftl_bdev_init_opts *
|
||||
|
||||
error_cache:
|
||||
if (ftl_bdev->cache_bdev_desc) {
|
||||
spdk_bdev_module_release_bdev(cache_bdev);
|
||||
spdk_bdev_close(ftl_bdev->cache_bdev_desc);
|
||||
bdev_ftl_close(ftl_bdev->cache_bdev_desc);
|
||||
}
|
||||
if (ftl_bdev->base_bdev_desc) {
|
||||
bdev_ftl_close(ftl_bdev->base_bdev_desc);
|
||||
}
|
||||
error_name:
|
||||
free(ftl_bdev->bdev.name);
|
||||
error_ctrlr:
|
||||
bdev_ftl_remove_ctrlr(ftl_ctrlr);
|
||||
error_bdev:
|
||||
free(ftl_bdev);
|
||||
return rc;
|
||||
}
|
||||
|
||||
static void
|
||||
bdev_ftl_bdev_init_done(void)
|
||||
{
|
||||
pthread_mutex_lock(&g_ftl_bdev_lock);
|
||||
|
||||
if (++g_num_init_bdevs != g_num_conf_bdevs) {
|
||||
pthread_mutex_unlock(&g_ftl_bdev_lock);
|
||||
return;
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&g_ftl_bdev_lock);
|
||||
|
||||
spdk_bdev_module_init_done(&g_ftl_if);
|
||||
}
|
||||
|
||||
static void
|
||||
bdev_ftl_init_cb(const struct ftl_bdev_info *info, void *ctx, int status)
|
||||
{
|
||||
struct ftl_deferred_init *opts;
|
||||
|
||||
if (status) {
|
||||
SPDK_ERRLOG("Failed to initialize FTL bdev\n");
|
||||
}
|
||||
|
||||
LIST_FOREACH(opts, &g_deferred_init, entry) {
|
||||
if (!strcmp(opts->opts.name, info->name)) {
|
||||
spdk_bdev_module_examine_done(&g_ftl_if);
|
||||
LIST_REMOVE(opts, entry);
|
||||
free(opts);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
bdev_ftl_bdev_init_done();
|
||||
}
|
||||
|
||||
static int
|
||||
bdev_ftl_initialize(void)
|
||||
{
|
||||
pthread_mutexattr_t attr;
|
||||
struct spdk_conf_section *sp;
|
||||
struct ftl_bdev_init_opts *opts = NULL;
|
||||
struct ftl_deferred_init *defer_opts;
|
||||
size_t i;
|
||||
|
||||
int rc = 0;
|
||||
|
||||
if (pthread_mutexattr_init(&attr)) {
|
||||
SPDK_ERRLOG("Mutex initialization failed\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE)) {
|
||||
SPDK_ERRLOG("Mutex initialization failed\n");
|
||||
rc = -1;
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (pthread_mutex_init(&g_ftl_bdev_lock, &attr)) {
|
||||
SPDK_ERRLOG("Mutex initialization failed\n");
|
||||
rc = -1;
|
||||
goto out;
|
||||
}
|
||||
|
||||
sp = spdk_conf_find_section(NULL, "Ftl");
|
||||
if (!sp) {
|
||||
goto out;
|
||||
}
|
||||
|
||||
opts = calloc(FTL_MAX_BDEVS, sizeof(*opts));
|
||||
if (!opts) {
|
||||
SPDK_ERRLOG("Failed to allocate bdev init opts\n");
|
||||
goto out;
|
||||
}
|
||||
|
||||
spdk_ftl_conf_init_defaults(&opts->ftl_conf);
|
||||
|
||||
if (bdev_ftl_read_bdev_config(sp, opts, &g_num_conf_bdevs)) {
|
||||
goto out;
|
||||
}
|
||||
|
||||
for (i = 0; i < g_num_conf_bdevs; ++i) {
|
||||
bool defer_init = false;
|
||||
|
||||
LIST_FOREACH(defer_opts, &g_deferred_init, entry) {
|
||||
if (!strcmp(defer_opts->opts.name, opts[i].name)) {
|
||||
defer_init = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!defer_init && bdev_ftl_init_bdev(&opts[i], bdev_ftl_init_cb, NULL)) {
|
||||
SPDK_ERRLOG("Failed to create bdev '%s'\n", opts[i].name);
|
||||
bdev_ftl_bdev_init_done();
|
||||
}
|
||||
}
|
||||
|
||||
out:
|
||||
if (g_num_conf_bdevs == 0) {
|
||||
spdk_bdev_module_init_done(&g_ftl_if);
|
||||
}
|
||||
|
||||
free(opts);
|
||||
pthread_mutexattr_destroy(&attr);
|
||||
return rc;
|
||||
}
|
||||
|
||||
int
|
||||
bdev_ftl_init_bdev(struct ftl_bdev_init_opts *opts, ftl_bdev_init_fn cb, void *cb_arg)
|
||||
{
|
||||
struct nvme_bdev_ctrlr *ftl_ctrlr;
|
||||
struct spdk_nvme_ctrlr *ctrlr;
|
||||
|
||||
assert(opts != NULL);
|
||||
assert(cb != NULL);
|
||||
|
||||
pthread_mutex_lock(&g_bdev_nvme_mutex);
|
||||
|
||||
/* Check already attached controllers first */
|
||||
TAILQ_FOREACH(ftl_ctrlr, &g_nvme_bdev_ctrlrs, tailq) {
|
||||
if (!spdk_nvme_transport_id_compare(&ftl_ctrlr->trid, &opts->trid)) {
|
||||
pthread_mutex_unlock(&g_bdev_nvme_mutex);
|
||||
return bdev_ftl_create(ftl_ctrlr->ctrlr, opts, cb, cb_arg);
|
||||
}
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&g_bdev_nvme_mutex);
|
||||
|
||||
ctrlr = spdk_nvme_connect(&opts->trid, NULL, 0);
|
||||
if (!ctrlr) {
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
if (!spdk_nvme_ctrlr_is_ocssd_supported(ctrlr)) {
|
||||
spdk_nvme_detach(ctrlr);
|
||||
return -EPERM;
|
||||
}
|
||||
|
||||
return bdev_ftl_create(ctrlr, opts, cb, cb_arg);
|
||||
}
|
||||
|
||||
static void
|
||||
bdev_ftl_examine(struct spdk_bdev *bdev)
|
||||
{
|
||||
struct ftl_deferred_init *opts;
|
||||
|
||||
LIST_FOREACH(opts, &g_deferred_init, entry) {
|
||||
if (spdk_bdev_get_by_name(opts->opts.cache_bdev) == bdev) {
|
||||
if (bdev_ftl_init_bdev(&opts->opts, bdev_ftl_init_cb, NULL)) {
|
||||
SPDK_ERRLOG("Unable to initialize bdev '%s'\n", opts->opts.name);
|
||||
LIST_REMOVE(opts, entry);
|
||||
free(opts);
|
||||
break;
|
||||
}
|
||||
|
||||
/* spdk_bdev_module_examine_done will be called by bdev_ftl_init_cb */
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
spdk_bdev_module_examine_done(&g_ftl_if);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
bdev_ftl_delete_bdev(const char *name, spdk_bdev_unregister_cb cb_fn, void *cb_arg)
|
||||
{
|
||||
struct ftl_bdev *ftl_bdev, *tmp;
|
||||
struct spdk_bdev *bdev;
|
||||
|
||||
pthread_mutex_lock(&g_ftl_bdev_lock);
|
||||
|
||||
LIST_FOREACH_SAFE(ftl_bdev, &g_ftl_bdevs, list_entry, tmp) {
|
||||
if (strcmp(ftl_bdev->bdev.name, name) == 0) {
|
||||
pthread_mutex_unlock(&g_ftl_bdev_lock);
|
||||
spdk_bdev_unregister(&ftl_bdev->bdev, cb_fn, cb_arg);
|
||||
return;
|
||||
}
|
||||
bdev = spdk_bdev_get_by_name(name);
|
||||
if (bdev) {
|
||||
spdk_bdev_unregister(bdev, cb_fn, cb_arg);
|
||||
return;
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&g_ftl_bdev_lock);
|
||||
cb_fn(cb_arg, -ENODEV);
|
||||
}
|
||||
|
||||
static void
|
||||
bdev_ftl_finish(void)
|
||||
{
|
||||
assert(LIST_EMPTY(&g_ftl_bdevs));
|
||||
}
|
||||
|
||||
SPDK_LOG_REGISTER_COMPONENT("bdev_ftl", SPDK_LOG_BDEV_FTL)
|
@ -35,13 +35,9 @@
|
||||
#define SPDK_BDEV_FTL_H
|
||||
|
||||
#include "spdk/stdinc.h"
|
||||
#include "spdk/nvme.h"
|
||||
#include "spdk/bdev_module.h"
|
||||
#include "spdk/ftl.h"
|
||||
|
||||
#define FTL_MAX_CONTROLLERS 64
|
||||
#define FTL_MAX_BDEVS (FTL_MAX_CONTROLLERS * 128)
|
||||
|
||||
struct spdk_bdev;
|
||||
struct spdk_uuid;
|
||||
|
||||
@ -51,10 +47,10 @@ struct ftl_bdev_info {
|
||||
};
|
||||
|
||||
struct ftl_bdev_init_opts {
|
||||
/* NVMe controller's transport ID */
|
||||
struct spdk_nvme_transport_id trid;
|
||||
/* Bdev's name */
|
||||
const char *name;
|
||||
/* Base bdev's name */
|
||||
const char *base_bdev;
|
||||
/* Write buffer bdev's name */
|
||||
const char *cache_bdev;
|
||||
/* Bdev's mode */
|
||||
@ -67,8 +63,8 @@ struct ftl_bdev_init_opts {
|
||||
|
||||
typedef void (*ftl_bdev_init_fn)(const struct ftl_bdev_info *, void *, int);
|
||||
|
||||
int bdev_ftl_init_bdev(struct ftl_bdev_init_opts *opts, ftl_bdev_init_fn cb,
|
||||
void *cb_arg);
|
||||
int bdev_ftl_create_bdev(const struct ftl_bdev_init_opts *bdev_opts,
|
||||
ftl_bdev_init_fn cb, void *cb_arg);
|
||||
void bdev_ftl_delete_bdev(const char *name, spdk_bdev_unregister_cb cb_fn, void *cb_arg);
|
||||
|
||||
#endif /* SPDK_BDEV_FTL_H */
|
@ -41,8 +41,7 @@
|
||||
|
||||
struct rpc_bdev_ftl_create {
|
||||
char *name;
|
||||
char *trtype;
|
||||
char *traddr;
|
||||
char *base_bdev;
|
||||
char *uuid;
|
||||
char *cache_bdev;
|
||||
struct spdk_ftl_conf ftl_conf;
|
||||
@ -52,16 +51,14 @@ static void
|
||||
free_rpc_bdev_ftl_create(struct rpc_bdev_ftl_create *req)
|
||||
{
|
||||
free(req->name);
|
||||
free(req->trtype);
|
||||
free(req->traddr);
|
||||
free(req->base_bdev);
|
||||
free(req->uuid);
|
||||
free(req->cache_bdev);
|
||||
}
|
||||
|
||||
static const struct spdk_json_object_decoder rpc_bdev_ftl_create_decoders[] = {
|
||||
{"name", offsetof(struct rpc_bdev_ftl_create, name), spdk_json_decode_string},
|
||||
{"trtype", offsetof(struct rpc_bdev_ftl_create, trtype), spdk_json_decode_string},
|
||||
{"traddr", offsetof(struct rpc_bdev_ftl_create, traddr), spdk_json_decode_string},
|
||||
{"base_bdev", offsetof(struct rpc_bdev_ftl_create, base_bdev), spdk_json_decode_string},
|
||||
{"uuid", offsetof(struct rpc_bdev_ftl_create, uuid), spdk_json_decode_string, true},
|
||||
{"cache", offsetof(struct rpc_bdev_ftl_create, cache_bdev), spdk_json_decode_string, true},
|
||||
{
|
||||
@ -171,28 +168,10 @@ spdk_rpc_bdev_ftl_create(struct spdk_jsonrpc_request *request,
|
||||
|
||||
opts.name = req.name;
|
||||
opts.mode = SPDK_FTL_MODE_CREATE;
|
||||
opts.base_bdev = req.base_bdev;
|
||||
opts.cache_bdev = req.cache_bdev;
|
||||
opts.ftl_conf = req.ftl_conf;
|
||||
|
||||
/* Parse trtype */
|
||||
rc = spdk_nvme_transport_id_parse_trtype(&opts.trid.trtype, req.trtype);
|
||||
if (rc) {
|
||||
spdk_jsonrpc_send_error_response_fmt(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
|
||||
"Failed to parse trtype: %s, rc: %s",
|
||||
req.trtype, spdk_strerror(-rc));
|
||||
goto invalid;
|
||||
}
|
||||
|
||||
if (opts.trid.trtype != SPDK_NVME_TRANSPORT_PCIE) {
|
||||
spdk_jsonrpc_send_error_response_fmt(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
|
||||
"Invalid trtype: %s. Only PCIe is supported",
|
||||
req.trtype);
|
||||
goto invalid;
|
||||
}
|
||||
|
||||
/* Parse traddr */
|
||||
snprintf(opts.trid.traddr, sizeof(opts.trid.traddr), "%s", req.traddr);
|
||||
|
||||
if (req.uuid) {
|
||||
if (spdk_uuid_parse(&opts.uuid, req.uuid) < 0) {
|
||||
spdk_jsonrpc_send_error_response_fmt(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
|
||||
@ -206,7 +185,7 @@ spdk_rpc_bdev_ftl_create(struct spdk_jsonrpc_request *request,
|
||||
}
|
||||
}
|
||||
|
||||
rc = bdev_ftl_init_bdev(&opts, _spdk_rpc_bdev_ftl_create_cb, request);
|
||||
rc = bdev_ftl_create_bdev(&opts, _spdk_rpc_bdev_ftl_create_cb, request);
|
||||
if (rc) {
|
||||
spdk_jsonrpc_send_error_response_fmt(request, SPDK_JSONRPC_ERROR_INTERNAL_ERROR,
|
||||
"Failed to create FTL bdev: %s",
|
@ -38,7 +38,7 @@ C_SRCS = bdev_nvme.c bdev_nvme_rpc.c nvme_rpc.c common.c bdev_ocssd.c bdev_ocssd
|
||||
C_SRCS-$(CONFIG_NVME_CUSE) += bdev_nvme_cuse_rpc.c
|
||||
|
||||
ifeq ($(OS),Linux)
|
||||
C_SRCS += bdev_ftl.c bdev_ftl_rpc.c vbdev_opal.c vbdev_opal_rpc.c
|
||||
C_SRCS += vbdev_opal.c vbdev_opal_rpc.c
|
||||
endif
|
||||
LIBNAME = bdev_nvme
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user