2018-10-29 14:35:27 +00:00
|
|
|
/*-
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "spdk/stdinc.h"
|
|
|
|
#include "spdk/bdev.h"
|
|
|
|
#include "spdk/conf.h"
|
|
|
|
#include "spdk/env.h"
|
2020-03-03 09:20:43 +00:00
|
|
|
#include "spdk/thread.h"
|
2018-10-29 14:35:27 +00:00
|
|
|
#include "spdk/json.h"
|
|
|
|
#include "spdk/string.h"
|
|
|
|
#include "spdk/likely.h"
|
|
|
|
#include "spdk/util.h"
|
2019-03-22 08:21:30 +00:00
|
|
|
#include "spdk/string.h"
|
2018-10-29 14:35:27 +00:00
|
|
|
#include "spdk/ftl.h"
|
|
|
|
#include "spdk_internal/log.h"
|
|
|
|
|
|
|
|
#include "bdev_ftl.h"
|
|
|
|
|
|
|
|
struct ftl_bdev {
|
|
|
|
struct spdk_bdev bdev;
|
|
|
|
|
|
|
|
struct spdk_ftl_dev *dev;
|
|
|
|
|
|
|
|
ftl_bdev_init_fn init_cb;
|
|
|
|
|
|
|
|
void *init_arg;
|
|
|
|
};
|
|
|
|
|
2019-03-20 08:36:02 +00:00
|
|
|
struct ftl_deferred_init {
|
|
|
|
struct ftl_bdev_init_opts opts;
|
|
|
|
|
|
|
|
LIST_ENTRY(ftl_deferred_init) entry;
|
|
|
|
};
|
|
|
|
|
2019-10-15 12:14:49 +00:00
|
|
|
static LIST_HEAD(, ftl_deferred_init) g_deferred_init = LIST_HEAD_INITIALIZER(g_deferred_init);
|
|
|
|
|
2018-10-29 14:35:27 +00:00
|
|
|
static int bdev_ftl_initialize(void);
|
|
|
|
static void bdev_ftl_finish(void);
|
2019-10-15 12:14:49 +00:00
|
|
|
static void bdev_ftl_examine(struct spdk_bdev *bdev);
|
2018-10-29 14:35:27 +00:00
|
|
|
|
|
|
|
static struct spdk_bdev_module g_ftl_if = {
|
|
|
|
.name = "ftl",
|
|
|
|
.module_init = bdev_ftl_initialize,
|
|
|
|
.module_fini = bdev_ftl_finish,
|
2019-10-15 12:14:49 +00:00
|
|
|
.examine_disk = bdev_ftl_examine,
|
2018-10-29 14:35:27 +00:00
|
|
|
};
|
|
|
|
|
2019-02-05 10:46:48 +00:00
|
|
|
SPDK_BDEV_MODULE_REGISTER(ftl, &g_ftl_if)
|
2018-10-29 14:35:27 +00:00
|
|
|
|
|
|
|
static void
|
2019-06-24 13:46:26 +00:00
|
|
|
bdev_ftl_free_cb(struct spdk_ftl_dev *dev, void *ctx, int status)
|
2018-10-29 14:35:27 +00:00
|
|
|
{
|
|
|
|
struct ftl_bdev *ftl_bdev = ctx;
|
|
|
|
|
|
|
|
spdk_bdev_destruct_done(&ftl_bdev->bdev, status);
|
|
|
|
free(ftl_bdev->bdev.name);
|
|
|
|
free(ftl_bdev);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
bdev_ftl_destruct(void *ctx)
|
|
|
|
{
|
|
|
|
struct ftl_bdev *ftl_bdev = ctx;
|
|
|
|
spdk_ftl_dev_free(ftl_bdev->dev, bdev_ftl_free_cb, ftl_bdev);
|
|
|
|
|
|
|
|
/* return 1 to indicate that the destruction is asynchronous */
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2020-02-06 15:37:09 +00:00
|
|
|
bdev_ftl_cb(void *arg, int rc)
|
2018-10-29 14:35:27 +00:00
|
|
|
{
|
2020-02-06 15:37:09 +00:00
|
|
|
struct spdk_bdev_io *bdev_io = arg;
|
2018-10-29 14:35:27 +00:00
|
|
|
enum spdk_bdev_io_status status;
|
|
|
|
|
|
|
|
switch (rc) {
|
|
|
|
case 0:
|
|
|
|
status = SPDK_BDEV_IO_STATUS_SUCCESS;
|
|
|
|
break;
|
|
|
|
case -ENOMEM:
|
|
|
|
status = SPDK_BDEV_IO_STATUS_NOMEM;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
status = SPDK_BDEV_IO_STATUS_FAILED;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2020-02-06 15:37:09 +00:00
|
|
|
spdk_bdev_io_complete(bdev_io, status);
|
2018-10-29 14:35:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2020-02-06 15:37:09 +00:00
|
|
|
bdev_ftl_get_buf_cb(struct spdk_io_channel *ch, struct spdk_bdev_io *bdev_io,
|
|
|
|
bool success)
|
2018-10-29 14:35:27 +00:00
|
|
|
{
|
2020-02-06 15:37:09 +00:00
|
|
|
struct ftl_bdev *ftl_bdev;
|
2018-10-29 14:35:27 +00:00
|
|
|
int rc;
|
|
|
|
|
2020-02-06 15:37:09 +00:00
|
|
|
ftl_bdev = bdev_io->bdev->ctxt;
|
2018-10-29 14:35:27 +00:00
|
|
|
|
2019-02-25 01:43:13 +00:00
|
|
|
if (!success) {
|
2020-02-06 15:37:09 +00:00
|
|
|
spdk_bdev_io_complete(bdev_io, SPDK_BDEV_IO_STATUS_FAILED);
|
2019-02-25 01:43:13 +00:00
|
|
|
return;
|
|
|
|
}
|
bdev: Not assert but pass completion status to spdk_bdev_io_get_buf_cb
When the specified buffer size to spdk_bdev_io_get_buf() is greater
than the permitted maximum, spdk_bdev_io_get_buf() asserts simply and
doesn't call the specified callback function.
SPDK SCSI library doesn't allocate read buffer and specifies
expected read buffer size, and expects that it is allocated by
spdk_bdev_io_get_buf().
Bdev perf tool also doesn't allocate read buffer and specifies
expected read buffer size, and expects that it is allocated by
spdk_bdev_io_get_buf().
When we support DIF insert and strip in iSCSI target, the read
buffer size iSCSI initiator requests and the read buffer size iSCSI target
requests will become different.
Even after that, iSCSI initiator and iSCSI target will negotiate correctly
not to cause buffer overflow in spdk_bdev_io_get_buf(), but if iSCSI
initiator ignores the result of negotiation, iSCSI initiator can request
read buffer size larger than the permitted maximum, and can cause
failure in iSCSI target. This is very flagile and should be avoided.
This patch do the following
- Add the completion status of spdk_bdev_io_get_buf() to
spdk_bdev_io_get_buf_cb(),
- spdk_bdev_io_get_buf() calls spdk_bdev_io_get_buf_cb() by setting
success to false, and return.
- spdk_bdev_io_get_buf_cb() in each bdev module calls assert if success
is false.
Subsequent patches will process the case that success is false
in spdk_bdev_io_get_buf_cb().
Change-Id: I76429a86e18a69aa085a353ac94743296d270b82
Signed-off-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Reviewed-on: https://review.gerrithub.io/c/446045
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
Reviewed-by: Changpeng Liu <changpeng.liu@intel.com>
Reviewed-by: Ziye Yang <ziye.yang@intel.com>
Reviewed-by: Darek Stojaczyk <dariusz.stojaczyk@intel.com>
2019-02-25 00:34:28 +00:00
|
|
|
|
2020-02-06 15:37:09 +00:00
|
|
|
rc = spdk_ftl_read(ftl_bdev->dev,
|
|
|
|
ch,
|
|
|
|
bdev_io->u.bdev.offset_blocks,
|
|
|
|
bdev_io->u.bdev.num_blocks,
|
|
|
|
bdev_io->u.bdev.iovs, bdev_io->u.bdev.iovcnt, bdev_ftl_cb, bdev_io);
|
2018-10-29 14:35:27 +00:00
|
|
|
|
|
|
|
if (spdk_unlikely(rc != 0)) {
|
2020-02-06 15:37:09 +00:00
|
|
|
spdk_bdev_io_complete(bdev_io, rc);
|
2018-10-29 14:35:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
_bdev_ftl_submit_request(struct spdk_io_channel *ch, struct spdk_bdev_io *bdev_io)
|
|
|
|
{
|
|
|
|
struct ftl_bdev *ftl_bdev = (struct ftl_bdev *)bdev_io->bdev->ctxt;
|
|
|
|
|
|
|
|
switch (bdev_io->type) {
|
|
|
|
case SPDK_BDEV_IO_TYPE_READ:
|
|
|
|
spdk_bdev_io_get_buf(bdev_io, bdev_ftl_get_buf_cb,
|
|
|
|
bdev_io->u.bdev.num_blocks * bdev_io->bdev->blocklen);
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
case SPDK_BDEV_IO_TYPE_WRITE:
|
2020-02-06 15:37:09 +00:00
|
|
|
return spdk_ftl_write(ftl_bdev->dev, ch, bdev_io->u.bdev.offset_blocks,
|
|
|
|
bdev_io->u.bdev.num_blocks, bdev_io->u.bdev.iovs,
|
|
|
|
bdev_io->u.bdev.iovcnt, bdev_ftl_cb, bdev_io);
|
2018-10-29 14:35:27 +00:00
|
|
|
|
|
|
|
case SPDK_BDEV_IO_TYPE_FLUSH:
|
2020-02-06 15:37:09 +00:00
|
|
|
return spdk_ftl_flush(ftl_bdev->dev, bdev_ftl_cb, bdev_io);
|
2018-10-29 14:35:27 +00:00
|
|
|
|
|
|
|
case SPDK_BDEV_IO_TYPE_WRITE_ZEROES:
|
|
|
|
case SPDK_BDEV_IO_TYPE_RESET:
|
|
|
|
case SPDK_BDEV_IO_TYPE_UNMAP:
|
|
|
|
default:
|
|
|
|
return -ENOTSUP;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
bdev_ftl_submit_request(struct spdk_io_channel *ch, struct spdk_bdev_io *bdev_io)
|
|
|
|
{
|
|
|
|
int rc = _bdev_ftl_submit_request(ch, bdev_io);
|
|
|
|
|
|
|
|
if (spdk_unlikely(rc != 0)) {
|
2020-02-06 15:37:09 +00:00
|
|
|
spdk_bdev_io_complete(bdev_io, rc);
|
2018-10-29 14:35:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
|
|
|
bdev_ftl_io_type_supported(void *ctx, enum spdk_bdev_io_type io_type)
|
|
|
|
{
|
|
|
|
switch (io_type) {
|
|
|
|
case SPDK_BDEV_IO_TYPE_READ:
|
|
|
|
case SPDK_BDEV_IO_TYPE_WRITE:
|
|
|
|
case SPDK_BDEV_IO_TYPE_FLUSH:
|
|
|
|
return true;
|
|
|
|
case SPDK_BDEV_IO_TYPE_WRITE_ZEROES:
|
|
|
|
case SPDK_BDEV_IO_TYPE_RESET:
|
|
|
|
case SPDK_BDEV_IO_TYPE_UNMAP:
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct spdk_io_channel *
|
|
|
|
bdev_ftl_get_io_channel(void *ctx)
|
|
|
|
{
|
|
|
|
struct ftl_bdev *ftl_bdev = ctx;
|
|
|
|
|
2020-02-06 15:37:09 +00:00
|
|
|
return spdk_get_io_channel(ftl_bdev->dev);
|
2018-10-29 14:35:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-06-04 09:34:02 +00:00
|
|
|
_bdev_ftl_write_config_info(struct ftl_bdev *ftl_bdev, struct spdk_json_write_ctx *w)
|
2018-10-29 14:35:27 +00:00
|
|
|
{
|
2020-01-13 13:52:47 +00:00
|
|
|
struct spdk_ftl_attrs attrs = {};
|
2019-01-28 13:12:21 +00:00
|
|
|
|
|
|
|
spdk_ftl_dev_get_attrs(ftl_bdev->dev, &attrs);
|
|
|
|
|
2020-01-13 13:52:47 +00:00
|
|
|
spdk_json_write_named_string(w, "base_bdev", attrs.base_bdev);
|
2019-01-28 13:12:21 +00:00
|
|
|
|
2020-01-13 13:52:47 +00:00
|
|
|
if (attrs.cache_bdev) {
|
|
|
|
spdk_json_write_named_string(w, "cache", attrs.cache_bdev);
|
2019-03-15 16:37:44 +00:00
|
|
|
}
|
2019-06-04 09:34:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
bdev_ftl_write_config_json(struct spdk_bdev *bdev, struct spdk_json_write_ctx *w)
|
|
|
|
{
|
|
|
|
struct ftl_bdev *ftl_bdev = bdev->ctxt;
|
|
|
|
struct spdk_ftl_attrs attrs;
|
2019-07-04 11:37:23 +00:00
|
|
|
struct spdk_ftl_conf *conf = &attrs.conf;
|
2019-06-04 09:34:02 +00:00
|
|
|
char uuid[SPDK_UUID_STRING_LEN];
|
|
|
|
|
|
|
|
spdk_ftl_dev_get_attrs(ftl_bdev->dev, &attrs);
|
|
|
|
|
|
|
|
spdk_json_write_object_begin(w);
|
|
|
|
|
2019-08-21 09:03:04 +00:00
|
|
|
spdk_json_write_named_string(w, "method", "bdev_ftl_create");
|
2019-06-04 09:34:02 +00:00
|
|
|
|
|
|
|
spdk_json_write_named_object_begin(w, "params");
|
|
|
|
spdk_json_write_named_string(w, "name", ftl_bdev->bdev.name);
|
2019-01-28 13:12:21 +00:00
|
|
|
|
2019-07-04 11:37:23 +00:00
|
|
|
spdk_json_write_named_bool(w, "allow_open_bands", conf->allow_open_bands);
|
|
|
|
spdk_json_write_named_uint64(w, "overprovisioning", conf->lba_rsvd);
|
|
|
|
spdk_json_write_named_uint64(w, "limit_crit", conf->limits[SPDK_FTL_LIMIT_CRIT].limit);
|
|
|
|
spdk_json_write_named_uint64(w, "limit_crit_threshold", conf->limits[SPDK_FTL_LIMIT_CRIT].thld);
|
|
|
|
spdk_json_write_named_uint64(w, "limit_high", conf->limits[SPDK_FTL_LIMIT_HIGH].limit);
|
|
|
|
spdk_json_write_named_uint64(w, "limit_high_threshold", conf->limits[SPDK_FTL_LIMIT_HIGH].thld);
|
|
|
|
spdk_json_write_named_uint64(w, "limit_low", conf->limits[SPDK_FTL_LIMIT_LOW].limit);
|
|
|
|
spdk_json_write_named_uint64(w, "limit_low_threshold", conf->limits[SPDK_FTL_LIMIT_LOW].thld);
|
|
|
|
spdk_json_write_named_uint64(w, "limit_start", conf->limits[SPDK_FTL_LIMIT_START].limit);
|
|
|
|
spdk_json_write_named_uint64(w, "limit_start_threshold", conf->limits[SPDK_FTL_LIMIT_START].thld);
|
2020-02-12 14:11:25 +00:00
|
|
|
if (conf->l2p_path) {
|
|
|
|
spdk_json_write_named_string(w, "l2p_path", conf->l2p_path);
|
|
|
|
}
|
2019-05-29 09:21:02 +00:00
|
|
|
|
2019-06-04 09:34:02 +00:00
|
|
|
spdk_uuid_fmt_lower(uuid, sizeof(uuid), &attrs.uuid);
|
|
|
|
spdk_json_write_named_string(w, "uuid", uuid);
|
|
|
|
|
|
|
|
_bdev_ftl_write_config_info(ftl_bdev, w);
|
|
|
|
|
|
|
|
spdk_json_write_object_end(w);
|
2019-01-28 13:12:21 +00:00
|
|
|
spdk_json_write_object_end(w);
|
2019-06-04 09:34:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
bdev_ftl_dump_info_json(void *ctx, struct spdk_json_write_ctx *w)
|
|
|
|
{
|
|
|
|
struct ftl_bdev *ftl_bdev = ctx;
|
|
|
|
struct spdk_ftl_attrs attrs;
|
|
|
|
|
|
|
|
spdk_ftl_dev_get_attrs(ftl_bdev->dev, &attrs);
|
|
|
|
|
|
|
|
spdk_json_write_named_object_begin(w, "ftl");
|
|
|
|
|
|
|
|
_bdev_ftl_write_config_info(ftl_bdev, w);
|
2019-09-04 13:44:28 +00:00
|
|
|
spdk_json_write_named_string_fmt(w, "num_zones", "%zu", attrs.num_zones);
|
|
|
|
spdk_json_write_named_string_fmt(w, "zone_size", "%zu", attrs.zone_size);
|
2019-06-04 09:34:02 +00:00
|
|
|
|
|
|
|
/* ftl */
|
2019-03-15 16:37:44 +00:00
|
|
|
spdk_json_write_object_end(w);
|
2019-06-04 09:34:02 +00:00
|
|
|
|
|
|
|
return 0;
|
2018-10-29 14:35:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static const struct spdk_bdev_fn_table ftl_fn_table = {
|
|
|
|
.destruct = bdev_ftl_destruct,
|
|
|
|
.submit_request = bdev_ftl_submit_request,
|
|
|
|
.io_type_supported = bdev_ftl_io_type_supported,
|
|
|
|
.get_io_channel = bdev_ftl_get_io_channel,
|
|
|
|
.write_config_json = bdev_ftl_write_config_json,
|
2019-06-04 09:34:02 +00:00
|
|
|
.dump_info_json = bdev_ftl_dump_info_json,
|
2018-10-29 14:35:27 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
bdev_ftl_create_cb(struct spdk_ftl_dev *dev, void *ctx, int status)
|
|
|
|
{
|
|
|
|
struct ftl_bdev *ftl_bdev = ctx;
|
|
|
|
struct ftl_bdev_info info = {};
|
|
|
|
struct spdk_ftl_attrs attrs;
|
|
|
|
ftl_bdev_init_fn init_cb = ftl_bdev->init_cb;
|
|
|
|
void *init_arg = ftl_bdev->init_arg;
|
|
|
|
int rc = -ENODEV;
|
|
|
|
|
|
|
|
if (status) {
|
|
|
|
SPDK_ERRLOG("Failed to create FTL device (%d)\n", status);
|
|
|
|
rc = status;
|
2020-02-06 15:37:09 +00:00
|
|
|
goto error;
|
2018-10-29 14:35:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
spdk_ftl_dev_get_attrs(dev, &attrs);
|
|
|
|
|
|
|
|
ftl_bdev->dev = dev;
|
|
|
|
ftl_bdev->bdev.product_name = "FTL disk";
|
|
|
|
ftl_bdev->bdev.write_cache = 0;
|
2019-10-24 14:36:42 +00:00
|
|
|
ftl_bdev->bdev.blocklen = attrs.block_size;
|
|
|
|
ftl_bdev->bdev.blockcnt = attrs.num_blocks;
|
2018-10-29 14:35:27 +00:00
|
|
|
ftl_bdev->bdev.uuid = attrs.uuid;
|
|
|
|
|
|
|
|
SPDK_DEBUGLOG(SPDK_LOG_BDEV_FTL, "Creating bdev %s:\n", ftl_bdev->bdev.name);
|
2019-10-24 14:36:42 +00:00
|
|
|
SPDK_DEBUGLOG(SPDK_LOG_BDEV_FTL, "\tblock_len:\t%zu\n", attrs.block_size);
|
|
|
|
SPDK_DEBUGLOG(SPDK_LOG_BDEV_FTL, "\tnum_blocks:\t%"PRIu64"\n", attrs.num_blocks);
|
2018-10-29 14:35:27 +00:00
|
|
|
|
|
|
|
ftl_bdev->bdev.ctxt = ftl_bdev;
|
|
|
|
ftl_bdev->bdev.fn_table = &ftl_fn_table;
|
|
|
|
ftl_bdev->bdev.module = &g_ftl_if;
|
|
|
|
|
|
|
|
if (spdk_bdev_register(&ftl_bdev->bdev)) {
|
2020-02-06 15:37:09 +00:00
|
|
|
goto error;
|
2018-10-29 14:35:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
info.name = ftl_bdev->bdev.name;
|
|
|
|
info.uuid = ftl_bdev->bdev.uuid;
|
|
|
|
|
|
|
|
init_cb(&info, init_arg, 0);
|
|
|
|
return;
|
|
|
|
|
2020-02-06 15:37:09 +00:00
|
|
|
error:
|
2018-10-29 14:35:27 +00:00
|
|
|
free(ftl_bdev->bdev.name);
|
|
|
|
free(ftl_bdev);
|
|
|
|
|
|
|
|
init_cb(NULL, init_arg, rc);
|
|
|
|
}
|
|
|
|
|
2019-10-15 12:14:49 +00:00
|
|
|
static void
|
|
|
|
bdev_ftl_defer_free(struct ftl_deferred_init *init)
|
|
|
|
{
|
|
|
|
free((char *)init->opts.name);
|
|
|
|
free((char *)init->opts.base_bdev);
|
|
|
|
free((char *)init->opts.cache_bdev);
|
|
|
|
free(init);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
bdev_ftl_defer_init(const struct ftl_bdev_init_opts *opts)
|
|
|
|
{
|
|
|
|
struct ftl_deferred_init *init;
|
|
|
|
|
|
|
|
init = calloc(1, sizeof(*init));
|
|
|
|
if (!init) {
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
init->opts.mode = opts->mode;
|
|
|
|
init->opts.uuid = opts->uuid;
|
|
|
|
init->opts.ftl_conf = opts->ftl_conf;
|
|
|
|
|
|
|
|
init->opts.name = strdup(opts->name);
|
|
|
|
if (!init->opts.name) {
|
|
|
|
SPDK_ERRLOG("Could not allocate bdev name\n");
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
init->opts.base_bdev = strdup(opts->base_bdev);
|
|
|
|
if (!init->opts.base_bdev) {
|
|
|
|
SPDK_ERRLOG("Could not allocate base bdev name\n");
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (opts->cache_bdev) {
|
|
|
|
init->opts.cache_bdev = strdup(opts->cache_bdev);
|
|
|
|
if (!init->opts.cache_bdev) {
|
|
|
|
SPDK_ERRLOG("Could not allocate cache bdev name\n");
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
LIST_INSERT_HEAD(&g_deferred_init, init, entry);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
error:
|
|
|
|
bdev_ftl_defer_free(init);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
2020-01-08 15:30:35 +00:00
|
|
|
int
|
|
|
|
bdev_ftl_create_bdev(const struct ftl_bdev_init_opts *bdev_opts,
|
|
|
|
ftl_bdev_init_fn cb, void *cb_arg)
|
2018-10-29 14:35:27 +00:00
|
|
|
{
|
|
|
|
struct ftl_bdev *ftl_bdev = NULL;
|
|
|
|
struct spdk_ftl_dev_init_opts opts = {};
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
ftl_bdev = calloc(1, sizeof(*ftl_bdev));
|
|
|
|
if (!ftl_bdev) {
|
|
|
|
SPDK_ERRLOG("Could not allocate ftl_bdev\n");
|
2020-01-08 15:30:35 +00:00
|
|
|
return -ENOMEM;
|
2018-10-29 14:35:27 +00:00
|
|
|
}
|
|
|
|
|
2019-03-28 08:47:56 +00:00
|
|
|
ftl_bdev->bdev.name = strdup(bdev_opts->name);
|
2018-10-29 14:35:27 +00:00
|
|
|
if (!ftl_bdev->bdev.name) {
|
|
|
|
rc = -ENOMEM;
|
2020-01-08 15:30:35 +00:00
|
|
|
goto error_bdev;
|
2018-10-29 14:35:27 +00:00
|
|
|
}
|
|
|
|
|
2019-10-15 12:14:49 +00:00
|
|
|
if (spdk_bdev_get_by_name(bdev_opts->base_bdev) == NULL ||
|
|
|
|
(bdev_opts->cache_bdev && spdk_bdev_get_by_name(bdev_opts->cache_bdev) == NULL)) {
|
|
|
|
rc = bdev_ftl_defer_init(bdev_opts);
|
|
|
|
if (rc == 0) {
|
|
|
|
rc = -ENODEV;
|
|
|
|
}
|
|
|
|
goto error_name;
|
|
|
|
}
|
|
|
|
|
2018-10-29 14:35:27 +00:00
|
|
|
ftl_bdev->init_cb = cb;
|
|
|
|
ftl_bdev->init_arg = cb_arg;
|
|
|
|
|
2019-03-28 08:47:56 +00:00
|
|
|
opts.mode = bdev_opts->mode;
|
|
|
|
opts.uuid = bdev_opts->uuid;
|
2018-10-29 14:35:27 +00:00
|
|
|
opts.name = ftl_bdev->bdev.name;
|
2020-01-13 13:52:47 +00:00
|
|
|
opts.base_bdev = bdev_opts->base_bdev;
|
|
|
|
opts.cache_bdev = bdev_opts->cache_bdev;
|
2019-06-28 08:16:46 +00:00
|
|
|
opts.conf = &bdev_opts->ftl_conf;
|
2019-03-28 08:47:56 +00:00
|
|
|
|
2018-10-29 14:35:27 +00:00
|
|
|
/* TODO: set threads based on config */
|
2019-10-21 15:11:37 +00:00
|
|
|
opts.core_thread = spdk_get_thread();
|
2018-10-29 14:35:27 +00:00
|
|
|
|
|
|
|
rc = spdk_ftl_dev_init(&opts, bdev_ftl_create_cb, ftl_bdev);
|
|
|
|
if (rc) {
|
|
|
|
SPDK_ERRLOG("Could not create FTL device\n");
|
2020-01-13 13:52:47 +00:00
|
|
|
goto error_name;
|
2018-10-29 14:35:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
error_name:
|
|
|
|
free(ftl_bdev->bdev.name);
|
2020-01-08 15:30:35 +00:00
|
|
|
error_bdev:
|
2018-10-29 14:35:27 +00:00
|
|
|
free(ftl_bdev);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2019-10-25 07:31:14 +00:00
|
|
|
static int
|
|
|
|
bdev_ftl_initialize(void)
|
2018-10-29 14:35:27 +00:00
|
|
|
{
|
2020-01-08 15:30:35 +00:00
|
|
|
return 0;
|
2019-03-20 08:36:02 +00:00
|
|
|
}
|
|
|
|
|
2018-10-29 14:35:27 +00:00
|
|
|
void
|
|
|
|
bdev_ftl_delete_bdev(const char *name, spdk_bdev_unregister_cb cb_fn, void *cb_arg)
|
|
|
|
{
|
2020-01-08 15:30:35 +00:00
|
|
|
struct spdk_bdev *bdev;
|
2018-10-29 14:35:27 +00:00
|
|
|
|
2020-01-08 15:30:35 +00:00
|
|
|
bdev = spdk_bdev_get_by_name(name);
|
|
|
|
if (bdev) {
|
|
|
|
spdk_bdev_unregister(bdev, cb_fn, cb_arg);
|
|
|
|
return;
|
2018-10-29 14:35:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
cb_fn(cb_arg, -ENODEV);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
bdev_ftl_finish(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2019-10-15 12:14:49 +00:00
|
|
|
static void
|
|
|
|
bdev_ftl_create_defered_cb(const struct ftl_bdev_info *info, void *ctx, int status)
|
|
|
|
{
|
|
|
|
struct ftl_deferred_init *opts = ctx;
|
|
|
|
|
|
|
|
if (status) {
|
|
|
|
SPDK_ERRLOG("Failed to initialize FTL bdev '%s'\n", opts->opts.name);
|
|
|
|
}
|
|
|
|
|
|
|
|
bdev_ftl_defer_free(opts);
|
|
|
|
|
|
|
|
spdk_bdev_module_examine_done(&g_ftl_if);
|
|
|
|
}
|
|
|
|
|
|
|
|
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.base_bdev) == NULL) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (opts->opts.cache_bdev && spdk_bdev_get_by_name(opts->opts.base_bdev) == NULL) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
LIST_REMOVE(opts, entry);
|
|
|
|
|
|
|
|
/* spdk_bdev_module_examine_done will be called by bdev_ftl_create_defered_cb */
|
|
|
|
if (bdev_ftl_create_bdev(&opts->opts, bdev_ftl_create_defered_cb, opts)) {
|
|
|
|
SPDK_ERRLOG("Failed to initialize FTL bdev '%s'\n", opts->opts.name);
|
|
|
|
bdev_ftl_defer_free(opts);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
spdk_bdev_module_examine_done(&g_ftl_if);
|
|
|
|
}
|
|
|
|
|
2018-10-29 14:35:27 +00:00
|
|
|
SPDK_LOG_REGISTER_COMPONENT("bdev_ftl", SPDK_LOG_BDEV_FTL)
|