2016-07-20 18:16:23 +00:00
|
|
|
/*-
|
|
|
|
* BSD LICENSE
|
|
|
|
*
|
2019-10-09 06:40:31 +00:00
|
|
|
* Copyright (c) Intel Corporation. All rights reserved.
|
|
|
|
* Copyright (c) 2019 Mellanox Technologies LTD. All rights reserved.
|
2016-07-20 18:16:23 +00:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2017-05-02 18:18:25 +00:00
|
|
|
#include "spdk/stdinc.h"
|
2016-07-20 18:16:23 +00:00
|
|
|
|
2017-07-13 04:08:53 +00:00
|
|
|
#include "bdev_nvme.h"
|
2019-09-20 12:16:08 +00:00
|
|
|
#include "bdev_ocssd.h"
|
2016-07-20 18:16:23 +00:00
|
|
|
|
2018-09-27 19:38:15 +00:00
|
|
|
#include "spdk/config.h"
|
2016-08-22 22:23:38 +00:00
|
|
|
#include "spdk/endian.h"
|
2016-07-20 18:16:23 +00:00
|
|
|
#include "spdk/bdev.h"
|
2016-11-18 17:22:58 +00:00
|
|
|
#include "spdk/json.h"
|
2016-07-20 18:16:23 +00:00
|
|
|
#include "spdk/nvme.h"
|
2019-03-08 14:28:17 +00:00
|
|
|
#include "spdk/nvme_ocssd.h"
|
2018-06-11 20:32:15 +00:00
|
|
|
#include "spdk/thread.h"
|
2016-12-05 20:59:39 +00:00
|
|
|
#include "spdk/string.h"
|
2017-09-19 17:59:58 +00:00
|
|
|
#include "spdk/util.h"
|
2016-07-20 18:16:23 +00:00
|
|
|
|
2018-05-23 21:01:03 +00:00
|
|
|
#include "spdk/bdev_module.h"
|
2020-10-06 16:16:26 +00:00
|
|
|
#include "spdk/log.h"
|
2016-11-07 22:10:28 +00:00
|
|
|
|
2019-11-18 16:59:36 +00:00
|
|
|
#define SPDK_BDEV_NVME_DEFAULT_DELAY_CMD_SUBMIT true
|
2020-11-27 16:10:36 +00:00
|
|
|
#define SPDK_BDEV_NVME_DEFAULT_KEEP_ALIVE_TIMEOUT_IN_MS (10000)
|
2019-11-18 16:59:36 +00:00
|
|
|
|
2018-04-05 15:43:55 +00:00
|
|
|
static int bdev_nvme_config_json(struct spdk_json_write_ctx *w);
|
2016-07-20 18:16:23 +00:00
|
|
|
|
2017-02-28 17:51:25 +00:00
|
|
|
struct nvme_bdev_io {
|
2016-10-04 14:39:27 +00:00
|
|
|
/** array of iovecs to transfer. */
|
|
|
|
struct iovec *iovs;
|
|
|
|
|
|
|
|
/** Number of iovecs in iovs array. */
|
|
|
|
int iovcnt;
|
|
|
|
|
|
|
|
/** Current iovec position. */
|
|
|
|
int iovpos;
|
|
|
|
|
|
|
|
/** Offset in current iovec. */
|
|
|
|
uint32_t iov_offset;
|
2017-05-13 20:12:13 +00:00
|
|
|
|
2020-01-16 10:10:53 +00:00
|
|
|
/** array of iovecs to transfer. */
|
|
|
|
struct iovec *fused_iovs;
|
|
|
|
|
|
|
|
/** Number of iovecs in iovs array. */
|
|
|
|
int fused_iovcnt;
|
|
|
|
|
|
|
|
/** Current iovec position. */
|
|
|
|
int fused_iovpos;
|
|
|
|
|
|
|
|
/** Offset in current iovec. */
|
|
|
|
uint32_t fused_iov_offset;
|
|
|
|
|
2020-01-15 10:05:18 +00:00
|
|
|
/** Saved status for admin passthru completion event, PI error verification, or intermediate compare-and-write status */
|
2017-05-13 20:12:13 +00:00
|
|
|
struct spdk_nvme_cpl cpl;
|
|
|
|
|
2017-06-15 20:51:31 +00:00
|
|
|
/** Originating thread */
|
|
|
|
struct spdk_thread *orig_thread;
|
2019-12-20 11:29:48 +00:00
|
|
|
|
2020-01-15 10:05:18 +00:00
|
|
|
/** Keeps track if first of fused commands was submitted */
|
2019-12-20 11:29:48 +00:00
|
|
|
bool first_fused_submitted;
|
2016-07-20 18:16:23 +00:00
|
|
|
};
|
|
|
|
|
2017-01-25 23:05:09 +00:00
|
|
|
struct nvme_probe_ctx {
|
2017-01-25 23:36:40 +00:00
|
|
|
size_t count;
|
|
|
|
struct spdk_nvme_transport_id trids[NVME_MAX_CONTROLLERS];
|
2018-12-04 22:09:31 +00:00
|
|
|
struct spdk_nvme_host_id hostids[NVME_MAX_CONTROLLERS];
|
2017-03-01 20:35:59 +00:00
|
|
|
const char *names[NVME_MAX_CONTROLLERS];
|
2019-02-10 08:20:40 +00:00
|
|
|
uint32_t prchk_flags[NVME_MAX_CONTROLLERS];
|
2018-06-19 22:00:54 +00:00
|
|
|
const char *hostnqn;
|
2017-01-25 23:05:09 +00:00
|
|
|
};
|
|
|
|
|
2019-02-13 05:08:22 +00:00
|
|
|
struct nvme_probe_skip_entry {
|
|
|
|
struct spdk_nvme_transport_id trid;
|
|
|
|
TAILQ_ENTRY(nvme_probe_skip_entry) tailq;
|
|
|
|
};
|
|
|
|
/* All the controllers deleted by users via RPC are skipped by hotplug monitor */
|
|
|
|
static TAILQ_HEAD(, nvme_probe_skip_entry) g_skipped_nvme_ctrlrs = TAILQ_HEAD_INITIALIZER(
|
|
|
|
g_skipped_nvme_ctrlrs);
|
|
|
|
|
2018-07-09 21:04:33 +00:00
|
|
|
static struct spdk_bdev_nvme_opts g_opts = {
|
|
|
|
.action_on_timeout = SPDK_BDEV_NVME_TIMEOUT_ACTION_NONE,
|
|
|
|
.timeout_us = 0,
|
2020-11-27 16:10:36 +00:00
|
|
|
.keep_alive_timeout_ms = SPDK_BDEV_NVME_DEFAULT_KEEP_ALIVE_TIMEOUT_IN_MS,
|
2019-08-08 04:31:28 +00:00
|
|
|
.retry_count = 4,
|
2019-09-03 03:48:49 +00:00
|
|
|
.arbitration_burst = 0,
|
|
|
|
.low_priority_weight = 0,
|
|
|
|
.medium_priority_weight = 0,
|
|
|
|
.high_priority_weight = 0,
|
2020-03-20 11:18:05 +00:00
|
|
|
.nvme_adminq_poll_period_us = 10000ULL,
|
2019-03-11 22:26:53 +00:00
|
|
|
.nvme_ioq_poll_period_us = 0,
|
2019-07-10 05:13:31 +00:00
|
|
|
.io_queue_requests = 0,
|
2019-11-18 16:59:36 +00:00
|
|
|
.delay_cmd_submit = SPDK_BDEV_NVME_DEFAULT_DELAY_CMD_SUBMIT,
|
2017-03-30 19:49:52 +00:00
|
|
|
};
|
|
|
|
|
2018-07-12 12:26:19 +00:00
|
|
|
#define NVME_HOTPLUG_POLL_PERIOD_MAX 10000000ULL
|
|
|
|
#define NVME_HOTPLUG_POLL_PERIOD_DEFAULT 100000ULL
|
2018-07-09 21:04:33 +00:00
|
|
|
|
2017-03-16 15:33:27 +00:00
|
|
|
static int g_hot_insert_nvme_controller_index = 0;
|
2018-07-12 12:26:19 +00:00
|
|
|
static uint64_t g_nvme_hotplug_poll_period_us = NVME_HOTPLUG_POLL_PERIOD_DEFAULT;
|
2018-07-09 21:04:33 +00:00
|
|
|
static bool g_nvme_hotplug_enabled = false;
|
2018-07-12 12:26:19 +00:00
|
|
|
static struct spdk_thread *g_bdev_nvme_init_thread;
|
2017-11-17 21:49:36 +00:00
|
|
|
static struct spdk_poller *g_hotplug_poller;
|
2020-12-18 13:10:56 +00:00
|
|
|
static struct spdk_poller *g_hotplug_probe_poller;
|
2019-03-05 07:32:34 +00:00
|
|
|
static struct spdk_nvme_probe_ctx *g_hotplug_probe_ctx;
|
2016-07-20 18:16:23 +00:00
|
|
|
|
2019-11-26 16:55:40 +00:00
|
|
|
static void nvme_ctrlr_populate_namespaces(struct nvme_bdev_ctrlr *nvme_bdev_ctrlr,
|
|
|
|
struct nvme_async_probe_ctx *ctx);
|
2021-03-01 22:39:39 +00:00
|
|
|
static void nvme_ctrlr_populate_namespaces_done(struct nvme_bdev_ctrlr *nvme_bdev_ctrlr,
|
|
|
|
struct nvme_async_probe_ctx *ctx);
|
2017-07-13 17:36:19 +00:00
|
|
|
static int bdev_nvme_library_init(void);
|
2017-02-28 17:51:25 +00:00
|
|
|
static void bdev_nvme_library_fini(void);
|
2020-11-23 04:48:51 +00:00
|
|
|
static int bdev_nvme_readv(struct spdk_nvme_ns *ns, struct spdk_nvme_qpair *qpair,
|
2019-02-05 01:47:25 +00:00
|
|
|
struct nvme_bdev_io *bio,
|
2020-09-23 20:37:27 +00:00
|
|
|
struct iovec *iov, int iovcnt, void *md, uint64_t lba_count, uint64_t lba,
|
|
|
|
uint32_t flags);
|
2020-11-23 04:48:51 +00:00
|
|
|
static int bdev_nvme_no_pi_readv(struct spdk_nvme_ns *ns, struct spdk_nvme_qpair *qpair,
|
2019-02-08 05:42:18 +00:00
|
|
|
struct nvme_bdev_io *bio,
|
2019-04-16 08:17:08 +00:00
|
|
|
struct iovec *iov, int iovcnt, void *md, uint64_t lba_count, uint64_t lba);
|
2020-11-23 04:48:51 +00:00
|
|
|
static int bdev_nvme_writev(struct spdk_nvme_ns *ns, struct spdk_nvme_qpair *qpair,
|
2019-02-05 01:47:25 +00:00
|
|
|
struct nvme_bdev_io *bio,
|
2020-09-23 20:37:27 +00:00
|
|
|
struct iovec *iov, int iovcnt, void *md, uint64_t lba_count, uint64_t lba,
|
|
|
|
uint32_t flags);
|
2020-11-23 04:48:51 +00:00
|
|
|
static int bdev_nvme_comparev(struct spdk_nvme_ns *ns, struct spdk_nvme_qpair *qpair,
|
2019-12-13 08:40:54 +00:00
|
|
|
struct nvme_bdev_io *bio,
|
2020-09-23 20:37:27 +00:00
|
|
|
struct iovec *iov, int iovcnt, void *md, uint64_t lba_count, uint64_t lba,
|
|
|
|
uint32_t flags);
|
2020-11-23 04:48:51 +00:00
|
|
|
static int bdev_nvme_comparev_and_writev(struct spdk_nvme_ns *ns,
|
|
|
|
struct spdk_nvme_qpair *qpair,
|
2020-01-16 10:10:53 +00:00
|
|
|
struct nvme_bdev_io *bio, struct iovec *cmp_iov, int cmp_iovcnt, struct iovec *write_iov,
|
2020-09-23 20:37:27 +00:00
|
|
|
int write_iovcnt, void *md, uint64_t lba_count, uint64_t lba,
|
|
|
|
uint32_t flags);
|
2020-11-23 06:43:41 +00:00
|
|
|
static int bdev_nvme_admin_passthru(struct nvme_io_channel *nvme_ch,
|
2017-06-15 20:51:31 +00:00
|
|
|
struct nvme_bdev_io *bio,
|
2017-05-13 20:12:13 +00:00
|
|
|
struct spdk_nvme_cmd *cmd, void *buf, size_t nbytes);
|
2020-11-23 04:48:51 +00:00
|
|
|
static int bdev_nvme_io_passthru(struct spdk_nvme_ns *ns, struct spdk_nvme_qpair *qpair,
|
2017-06-05 18:02:09 +00:00
|
|
|
struct nvme_bdev_io *bio,
|
|
|
|
struct spdk_nvme_cmd *cmd, void *buf, size_t nbytes);
|
2020-11-23 04:48:51 +00:00
|
|
|
static int bdev_nvme_io_passthru_md(struct spdk_nvme_ns *ns, struct spdk_nvme_qpair *qpair,
|
2017-11-14 06:33:11 +00:00
|
|
|
struct nvme_bdev_io *bio,
|
|
|
|
struct spdk_nvme_cmd *cmd, void *buf, size_t nbytes, void *md_buf, size_t md_len);
|
2020-11-23 06:43:41 +00:00
|
|
|
static int bdev_nvme_abort(struct nvme_io_channel *nvme_ch,
|
2020-07-08 08:03:49 +00:00
|
|
|
struct nvme_bdev_io *bio, struct nvme_bdev_io *bio_to_abort);
|
2020-11-23 06:43:41 +00:00
|
|
|
static int bdev_nvme_reset(struct nvme_io_channel *nvme_ch, struct nvme_bdev_io *bio);
|
2020-10-24 13:43:55 +00:00
|
|
|
static int bdev_nvme_failover(struct nvme_bdev_ctrlr *nvme_bdev_ctrlr, bool remove);
|
2020-12-07 15:42:00 +00:00
|
|
|
static void remove_cb(void *cb_ctx, struct spdk_nvme_ctrlr *ctrlr);
|
2016-07-20 18:16:23 +00:00
|
|
|
|
2019-11-26 18:11:29 +00:00
|
|
|
typedef void (*populate_namespace_fn)(struct nvme_bdev_ctrlr *nvme_bdev_ctrlr,
|
|
|
|
struct nvme_bdev_ns *nvme_ns, struct nvme_async_probe_ctx *ctx);
|
|
|
|
static void nvme_ctrlr_populate_standard_namespace(struct nvme_bdev_ctrlr *nvme_bdev_ctrlr,
|
2019-11-26 16:55:40 +00:00
|
|
|
struct nvme_bdev_ns *nvme_ns, struct nvme_async_probe_ctx *ctx);
|
2019-11-25 20:16:24 +00:00
|
|
|
|
|
|
|
static populate_namespace_fn g_populate_namespace_fn[] = {
|
|
|
|
NULL,
|
|
|
|
nvme_ctrlr_populate_standard_namespace,
|
2019-09-20 12:16:08 +00:00
|
|
|
bdev_ocssd_populate_namespace,
|
2019-11-25 20:16:24 +00:00
|
|
|
};
|
|
|
|
|
2020-11-25 14:52:16 +00:00
|
|
|
typedef void (*depopulate_namespace_fn)(struct nvme_bdev_ns *nvme_ns);
|
|
|
|
static void nvme_ctrlr_depopulate_standard_namespace(struct nvme_bdev_ns *nvme_ns);
|
2019-11-25 20:16:24 +00:00
|
|
|
|
|
|
|
static depopulate_namespace_fn g_depopulate_namespace_fn[] = {
|
|
|
|
NULL,
|
|
|
|
nvme_ctrlr_depopulate_standard_namespace,
|
2019-09-20 12:16:08 +00:00
|
|
|
bdev_ocssd_depopulate_namespace,
|
2019-11-25 20:16:24 +00:00
|
|
|
};
|
|
|
|
|
2020-11-25 14:52:16 +00:00
|
|
|
typedef void (*config_json_namespace_fn)(struct spdk_json_write_ctx *w,
|
|
|
|
struct nvme_bdev_ns *nvme_ns);
|
2019-12-10 09:27:02 +00:00
|
|
|
static void nvme_ctrlr_config_json_standard_namespace(struct spdk_json_write_ctx *w,
|
2020-11-25 14:52:16 +00:00
|
|
|
struct nvme_bdev_ns *nvme_ns);
|
2019-12-10 09:27:02 +00:00
|
|
|
|
|
|
|
static config_json_namespace_fn g_config_json_namespace_fn[] = {
|
|
|
|
NULL,
|
|
|
|
nvme_ctrlr_config_json_standard_namespace,
|
2019-09-20 12:57:56 +00:00
|
|
|
bdev_ocssd_namespace_config_json,
|
2019-12-10 09:27:02 +00:00
|
|
|
};
|
|
|
|
|
2018-07-05 07:46:48 +00:00
|
|
|
struct spdk_nvme_qpair *
|
2020-05-10 07:46:07 +00:00
|
|
|
bdev_nvme_get_io_qpair(struct spdk_io_channel *ctrlr_io_ch)
|
2018-07-05 07:46:48 +00:00
|
|
|
{
|
|
|
|
struct nvme_io_channel *nvme_ch;
|
|
|
|
|
2021-03-17 01:18:36 +00:00
|
|
|
assert(ctrlr_io_ch != NULL);
|
|
|
|
|
|
|
|
nvme_ch = spdk_io_channel_get_ctx(ctrlr_io_ch);
|
2018-07-05 07:46:48 +00:00
|
|
|
|
|
|
|
return nvme_ch->qpair;
|
|
|
|
}
|
|
|
|
|
2016-07-20 18:16:23 +00:00
|
|
|
static int
|
2017-02-28 17:51:25 +00:00
|
|
|
bdev_nvme_get_ctx_size(void)
|
2016-07-20 18:16:23 +00:00
|
|
|
{
|
2017-02-28 17:51:25 +00:00
|
|
|
return sizeof(struct nvme_bdev_io);
|
2016-07-20 18:16:23 +00:00
|
|
|
}
|
|
|
|
|
2018-03-09 22:20:21 +00:00
|
|
|
static struct spdk_bdev_module nvme_if = {
|
2018-03-06 18:52:46 +00:00
|
|
|
.name = "nvme",
|
2020-03-05 10:45:00 +00:00
|
|
|
.async_fini = true,
|
2018-03-06 18:52:46 +00:00
|
|
|
.module_init = bdev_nvme_library_init,
|
|
|
|
.module_fini = bdev_nvme_library_fini,
|
2018-04-05 15:43:55 +00:00
|
|
|
.config_json = bdev_nvme_config_json,
|
2018-03-06 18:52:46 +00:00
|
|
|
.get_ctx_size = bdev_nvme_get_ctx_size,
|
|
|
|
|
|
|
|
};
|
2019-02-05 10:46:48 +00:00
|
|
|
SPDK_BDEV_MODULE_REGISTER(nvme, &nvme_if)
|
2016-07-20 18:16:23 +00:00
|
|
|
|
2020-02-07 00:20:35 +00:00
|
|
|
static void
|
|
|
|
bdev_nvme_disconnected_qpair_cb(struct spdk_nvme_qpair *qpair, void *poll_group_ctx)
|
|
|
|
{
|
2020-12-22 11:34:00 +00:00
|
|
|
int rc;
|
|
|
|
|
|
|
|
SPDK_DEBUGLOG(bdev_nvme, "qpair %p is disconnected, attempting reconnect.\n", qpair);
|
2020-02-07 00:20:35 +00:00
|
|
|
/*
|
|
|
|
* Currently, just try to reconnect indefinitely. If we are doing a reset, the reset will
|
|
|
|
* reconnect a qpair and we will stop getting a callback for this one.
|
|
|
|
*/
|
2020-12-22 11:34:00 +00:00
|
|
|
rc = spdk_nvme_ctrlr_reconnect_io_qpair(qpair);
|
|
|
|
if (rc != 0) {
|
|
|
|
SPDK_WARNLOG("Failed to reconnect to qpair %p, errno %d\n", qpair, -rc);
|
|
|
|
}
|
2020-02-07 00:20:35 +00:00
|
|
|
}
|
|
|
|
|
2018-03-13 00:16:47 +00:00
|
|
|
static int
|
2017-02-28 17:51:25 +00:00
|
|
|
bdev_nvme_poll(void *arg)
|
2016-09-16 19:53:32 +00:00
|
|
|
{
|
2020-02-07 00:20:35 +00:00
|
|
|
struct nvme_bdev_poll_group *group = arg;
|
|
|
|
int64_t num_completions;
|
2016-09-16 19:53:32 +00:00
|
|
|
|
2020-02-07 00:20:35 +00:00
|
|
|
if (group->collect_spin_stat && group->start_ticks == 0) {
|
|
|
|
group->start_ticks = spdk_get_ticks();
|
2017-06-15 16:59:02 +00:00
|
|
|
}
|
|
|
|
|
2020-02-07 00:20:35 +00:00
|
|
|
num_completions = spdk_nvme_poll_group_process_completions(group->group, 0,
|
|
|
|
bdev_nvme_disconnected_qpair_cb);
|
|
|
|
if (group->collect_spin_stat) {
|
2017-06-15 16:59:02 +00:00
|
|
|
if (num_completions > 0) {
|
2020-02-07 00:20:35 +00:00
|
|
|
if (group->end_ticks != 0) {
|
|
|
|
group->spin_ticks += (group->end_ticks - group->start_ticks);
|
|
|
|
group->end_ticks = 0;
|
2017-06-15 16:59:02 +00:00
|
|
|
}
|
2020-02-07 00:20:35 +00:00
|
|
|
group->start_ticks = 0;
|
2017-06-15 16:59:02 +00:00
|
|
|
} else {
|
2020-02-07 00:20:35 +00:00
|
|
|
group->end_ticks = spdk_get_ticks();
|
2017-06-15 16:59:02 +00:00
|
|
|
}
|
2017-06-08 18:49:22 +00:00
|
|
|
}
|
2018-03-13 00:16:47 +00:00
|
|
|
|
2020-05-04 09:51:27 +00:00
|
|
|
return num_completions > 0 ? SPDK_POLLER_BUSY : SPDK_POLLER_IDLE;
|
2016-09-16 19:53:32 +00:00
|
|
|
}
|
|
|
|
|
2018-03-13 00:16:47 +00:00
|
|
|
static int
|
2017-02-28 17:51:25 +00:00
|
|
|
bdev_nvme_poll_adminq(void *arg)
|
2017-01-13 19:58:23 +00:00
|
|
|
{
|
2019-11-08 22:22:37 +00:00
|
|
|
int32_t rc;
|
2020-07-14 23:28:56 +00:00
|
|
|
struct nvme_bdev_ctrlr *nvme_bdev_ctrlr = arg;
|
2017-01-13 19:58:23 +00:00
|
|
|
|
2020-07-14 23:28:56 +00:00
|
|
|
assert(nvme_bdev_ctrlr != NULL);
|
2019-11-08 22:22:37 +00:00
|
|
|
|
2020-07-14 23:28:56 +00:00
|
|
|
rc = spdk_nvme_ctrlr_process_admin_completions(nvme_bdev_ctrlr->ctrlr);
|
2019-11-08 22:22:37 +00:00
|
|
|
if (rc < 0) {
|
2020-10-24 13:43:55 +00:00
|
|
|
bdev_nvme_failover(nvme_bdev_ctrlr, false);
|
2019-11-08 22:22:37 +00:00
|
|
|
}
|
|
|
|
|
2020-05-04 09:51:27 +00:00
|
|
|
return rc == 0 ? SPDK_POLLER_IDLE : SPDK_POLLER_BUSY;
|
2017-01-13 19:58:23 +00:00
|
|
|
}
|
|
|
|
|
2016-07-20 18:16:23 +00:00
|
|
|
static int
|
2017-04-04 21:10:00 +00:00
|
|
|
bdev_nvme_destruct(void *ctx)
|
2016-07-20 18:16:23 +00:00
|
|
|
{
|
2017-04-04 21:10:00 +00:00
|
|
|
struct nvme_bdev *nvme_disk = ctx;
|
2021-01-04 07:50:15 +00:00
|
|
|
struct nvme_bdev_ns *nvme_ns = nvme_disk->nvme_ns;
|
2017-03-01 01:23:53 +00:00
|
|
|
|
2021-02-17 16:07:25 +00:00
|
|
|
nvme_ns->bdev = NULL;
|
2021-01-04 07:50:15 +00:00
|
|
|
|
|
|
|
nvme_bdev_ns_detach(nvme_ns);
|
2019-10-01 08:18:44 +00:00
|
|
|
|
2017-06-02 17:25:43 +00:00
|
|
|
free(nvme_disk->disk.name);
|
2019-10-14 12:35:11 +00:00
|
|
|
free(nvme_disk);
|
2017-03-01 01:23:53 +00:00
|
|
|
|
2016-07-20 18:16:23 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2020-11-23 04:48:51 +00:00
|
|
|
bdev_nvme_flush(struct spdk_nvme_ns *ns, struct spdk_nvme_qpair *qpair,
|
2020-11-23 04:25:16 +00:00
|
|
|
struct nvme_bdev_io *bio, uint64_t offset, uint64_t nbytes)
|
2016-07-20 18:16:23 +00:00
|
|
|
{
|
|
|
|
spdk_bdev_io_complete(spdk_bdev_io_from_ctx(bio), SPDK_BDEV_IO_STATUS_SUCCESS);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-11-13 12:06:52 +00:00
|
|
|
static int
|
2020-12-08 21:51:00 +00:00
|
|
|
bdev_nvme_create_qpair(struct nvme_io_channel *nvme_ch)
|
2020-11-13 12:06:52 +00:00
|
|
|
{
|
2020-12-08 21:51:00 +00:00
|
|
|
struct spdk_nvme_ctrlr *ctrlr = nvme_ch->ctrlr->ctrlr;
|
2020-11-13 12:06:52 +00:00
|
|
|
struct spdk_nvme_io_qpair_opts opts;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
spdk_nvme_ctrlr_get_default_io_qpair_opts(ctrlr, &opts, sizeof(opts));
|
|
|
|
opts.delay_cmd_submit = g_opts.delay_cmd_submit;
|
|
|
|
opts.create_only = true;
|
|
|
|
opts.io_queue_requests = spdk_max(g_opts.io_queue_requests, opts.io_queue_requests);
|
|
|
|
g_opts.io_queue_requests = opts.io_queue_requests;
|
|
|
|
|
|
|
|
nvme_ch->qpair = spdk_nvme_ctrlr_alloc_io_qpair(ctrlr, &opts, sizeof(opts));
|
|
|
|
if (nvme_ch->qpair == NULL) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
assert(nvme_ch->group != NULL);
|
|
|
|
|
|
|
|
rc = spdk_nvme_poll_group_add(nvme_ch->group->group, nvme_ch->qpair);
|
|
|
|
if (rc != 0) {
|
|
|
|
SPDK_ERRLOG("Unable to begin polling on NVMe Channel.\n");
|
2020-12-22 04:28:01 +00:00
|
|
|
goto err;
|
2020-11-13 12:06:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
rc = spdk_nvme_ctrlr_connect_io_qpair(ctrlr, nvme_ch->qpair);
|
|
|
|
if (rc != 0) {
|
|
|
|
SPDK_ERRLOG("Unable to connect I/O qpair.\n");
|
2020-12-22 04:28:01 +00:00
|
|
|
goto err;
|
2020-11-13 12:06:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
2020-12-22 04:28:01 +00:00
|
|
|
err:
|
2020-12-08 21:51:00 +00:00
|
|
|
spdk_nvme_ctrlr_free_io_qpair(nvme_ch->qpair);
|
|
|
|
|
2020-11-13 12:06:52 +00:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2020-12-17 09:52:14 +00:00
|
|
|
static void
|
2021-03-05 04:10:53 +00:00
|
|
|
_bdev_nvme_check_pending_destruct(struct spdk_io_channel_iter *i, int status)
|
2020-12-17 09:52:14 +00:00
|
|
|
{
|
|
|
|
struct nvme_bdev_ctrlr *nvme_bdev_ctrlr = spdk_io_channel_iter_get_io_device(i);
|
|
|
|
|
2021-03-05 04:10:53 +00:00
|
|
|
pthread_mutex_lock(&nvme_bdev_ctrlr->mutex);
|
|
|
|
if (nvme_bdev_ctrlr->destruct_after_reset) {
|
|
|
|
assert(nvme_bdev_ctrlr->ref == 0 && nvme_bdev_ctrlr->destruct);
|
|
|
|
pthread_mutex_unlock(&nvme_bdev_ctrlr->mutex);
|
|
|
|
|
|
|
|
spdk_thread_send_msg(nvme_bdev_ctrlr->thread, nvme_bdev_ctrlr_do_destruct,
|
|
|
|
nvme_bdev_ctrlr);
|
|
|
|
} else {
|
|
|
|
pthread_mutex_unlock(&nvme_bdev_ctrlr->mutex);
|
|
|
|
}
|
2020-12-17 09:52:14 +00:00
|
|
|
}
|
|
|
|
|
2019-11-08 21:26:09 +00:00
|
|
|
static void
|
|
|
|
_bdev_nvme_complete_pending_resets(struct spdk_io_channel_iter *i)
|
|
|
|
{
|
|
|
|
struct spdk_io_channel *_ch = spdk_io_channel_iter_get_channel(i);
|
|
|
|
struct nvme_io_channel *nvme_ch = spdk_io_channel_get_ctx(_ch);
|
|
|
|
struct spdk_bdev_io *bdev_io;
|
|
|
|
enum spdk_bdev_io_status status = SPDK_BDEV_IO_STATUS_SUCCESS;
|
|
|
|
|
|
|
|
/* A NULL ctx means success. */
|
|
|
|
if (spdk_io_channel_iter_get_ctx(i) != NULL) {
|
|
|
|
status = SPDK_BDEV_IO_STATUS_FAILED;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (!TAILQ_EMPTY(&nvme_ch->pending_resets)) {
|
|
|
|
bdev_io = TAILQ_FIRST(&nvme_ch->pending_resets);
|
|
|
|
TAILQ_REMOVE(&nvme_ch->pending_resets, bdev_io, module_link);
|
|
|
|
spdk_bdev_io_complete(bdev_io, status);
|
|
|
|
}
|
|
|
|
|
|
|
|
spdk_for_each_channel_continue(i, 0);
|
|
|
|
}
|
|
|
|
|
2019-11-08 17:56:11 +00:00
|
|
|
static void
|
|
|
|
_bdev_nvme_reset_complete(struct nvme_bdev_ctrlr *nvme_bdev_ctrlr, int rc)
|
|
|
|
{
|
2019-11-08 21:26:09 +00:00
|
|
|
/* we are using the for_each_channel cb_arg like a return code here. */
|
|
|
|
/* If it's zero, we succeeded, otherwise, the reset failed. */
|
|
|
|
void *cb_arg = NULL;
|
2020-12-22 12:50:29 +00:00
|
|
|
struct nvme_bdev_ctrlr_trid *curr_trid;
|
2019-11-08 21:26:09 +00:00
|
|
|
|
2019-11-08 17:56:11 +00:00
|
|
|
if (rc) {
|
2019-11-08 21:26:09 +00:00
|
|
|
cb_arg = (void *)0x1;
|
2019-11-08 17:56:11 +00:00
|
|
|
SPDK_ERRLOG("Resetting controller failed.\n");
|
|
|
|
} else {
|
|
|
|
SPDK_NOTICELOG("Resetting controller successful.\n");
|
|
|
|
}
|
2019-11-08 21:26:09 +00:00
|
|
|
|
2021-03-03 17:23:21 +00:00
|
|
|
pthread_mutex_lock(&nvme_bdev_ctrlr->mutex);
|
2020-03-12 17:39:27 +00:00
|
|
|
nvme_bdev_ctrlr->resetting = false;
|
2020-06-12 23:35:47 +00:00
|
|
|
nvme_bdev_ctrlr->failover_in_progress = false;
|
2020-12-22 12:50:29 +00:00
|
|
|
|
|
|
|
curr_trid = TAILQ_FIRST(&nvme_bdev_ctrlr->trids);
|
|
|
|
assert(curr_trid != NULL);
|
|
|
|
assert(&curr_trid->trid == nvme_bdev_ctrlr->connected_trid);
|
|
|
|
|
|
|
|
curr_trid->is_failed = cb_arg != NULL ? true : false;
|
|
|
|
|
2020-12-17 09:52:14 +00:00
|
|
|
if (nvme_bdev_ctrlr->ref == 0 && nvme_bdev_ctrlr->destruct) {
|
|
|
|
/* Destruct ctrlr after clearing pending resets. */
|
2021-03-05 04:10:53 +00:00
|
|
|
nvme_bdev_ctrlr->destruct_after_reset = true;
|
2020-12-17 09:52:14 +00:00
|
|
|
}
|
|
|
|
|
2021-03-03 17:23:21 +00:00
|
|
|
pthread_mutex_unlock(&nvme_bdev_ctrlr->mutex);
|
|
|
|
|
2019-11-08 21:26:09 +00:00
|
|
|
/* Make sure we clear any pending resets before returning. */
|
|
|
|
spdk_for_each_channel(nvme_bdev_ctrlr,
|
|
|
|
_bdev_nvme_complete_pending_resets,
|
2020-12-17 09:52:14 +00:00
|
|
|
cb_arg,
|
2021-03-05 04:10:53 +00:00
|
|
|
_bdev_nvme_check_pending_destruct);
|
2019-11-08 17:56:11 +00:00
|
|
|
}
|
|
|
|
|
2017-06-08 18:49:22 +00:00
|
|
|
static void
|
2019-11-15 16:31:22 +00:00
|
|
|
_bdev_nvme_reset_create_qpairs_done(struct spdk_io_channel_iter *i, int status)
|
2017-06-08 18:49:22 +00:00
|
|
|
{
|
2019-11-08 17:56:11 +00:00
|
|
|
struct nvme_bdev_ctrlr *nvme_bdev_ctrlr = spdk_io_channel_iter_get_io_device(i);
|
2020-11-02 13:51:03 +00:00
|
|
|
struct nvme_bdev_io *bio = spdk_io_channel_iter_get_ctx(i);
|
2017-11-16 07:42:37 +00:00
|
|
|
int rc = SPDK_BDEV_IO_STATUS_SUCCESS;
|
2017-12-11 22:14:19 +00:00
|
|
|
|
2017-11-16 07:42:37 +00:00
|
|
|
if (status) {
|
|
|
|
rc = SPDK_BDEV_IO_STATUS_FAILED;
|
|
|
|
}
|
2020-11-02 13:51:03 +00:00
|
|
|
if (bio) {
|
|
|
|
spdk_bdev_io_complete(spdk_bdev_io_from_ctx(bio), rc);
|
2019-11-08 17:56:11 +00:00
|
|
|
}
|
|
|
|
_bdev_nvme_reset_complete(nvme_bdev_ctrlr, status);
|
2017-06-08 18:49:22 +00:00
|
|
|
}
|
|
|
|
|
2017-12-11 22:14:19 +00:00
|
|
|
static void
|
|
|
|
_bdev_nvme_reset_create_qpair(struct spdk_io_channel_iter *i)
|
2017-06-08 18:49:22 +00:00
|
|
|
{
|
2017-12-11 22:14:19 +00:00
|
|
|
struct spdk_io_channel *_ch = spdk_io_channel_iter_get_channel(i);
|
|
|
|
struct nvme_io_channel *nvme_ch = spdk_io_channel_get_ctx(_ch);
|
2020-11-13 12:06:52 +00:00
|
|
|
int rc;
|
2020-02-07 00:20:35 +00:00
|
|
|
|
2020-12-08 21:51:00 +00:00
|
|
|
rc = bdev_nvme_create_qpair(nvme_ch);
|
2020-02-07 00:20:35 +00:00
|
|
|
|
2020-11-13 12:06:52 +00:00
|
|
|
spdk_for_each_channel_continue(i, rc);
|
2017-06-08 18:49:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2020-11-02 14:00:35 +00:00
|
|
|
_bdev_nvme_reset_ctrlr(struct spdk_io_channel_iter *i, int status)
|
2016-07-20 18:16:23 +00:00
|
|
|
{
|
2019-10-15 11:03:36 +00:00
|
|
|
struct nvme_bdev_ctrlr *nvme_bdev_ctrlr = spdk_io_channel_iter_get_io_device(i);
|
2017-12-11 22:14:19 +00:00
|
|
|
struct nvme_bdev_io *bio = spdk_io_channel_iter_get_ctx(i);
|
2016-07-20 18:16:23 +00:00
|
|
|
int rc;
|
|
|
|
|
2017-11-16 07:42:37 +00:00
|
|
|
if (status) {
|
2020-11-02 13:51:03 +00:00
|
|
|
rc = status;
|
|
|
|
goto err;
|
2017-11-16 07:42:37 +00:00
|
|
|
}
|
|
|
|
|
2019-10-15 11:03:36 +00:00
|
|
|
rc = spdk_nvme_ctrlr_reset(nvme_bdev_ctrlr->ctrlr);
|
2016-07-20 18:16:23 +00:00
|
|
|
if (rc != 0) {
|
2020-11-02 13:51:03 +00:00
|
|
|
goto err;
|
2016-07-20 18:16:23 +00:00
|
|
|
}
|
|
|
|
|
2017-06-08 18:49:22 +00:00
|
|
|
/* Recreate all of the I/O queue pairs */
|
2019-10-15 11:03:36 +00:00
|
|
|
spdk_for_each_channel(nvme_bdev_ctrlr,
|
2017-06-08 18:49:22 +00:00
|
|
|
_bdev_nvme_reset_create_qpair,
|
2017-12-11 22:14:19 +00:00
|
|
|
bio,
|
2019-11-15 16:31:22 +00:00
|
|
|
_bdev_nvme_reset_create_qpairs_done);
|
2020-11-02 13:51:03 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
err:
|
|
|
|
if (bio) {
|
|
|
|
spdk_bdev_io_complete(spdk_bdev_io_from_ctx(bio), SPDK_BDEV_IO_STATUS_FAILED);
|
|
|
|
}
|
|
|
|
_bdev_nvme_reset_complete(nvme_bdev_ctrlr, rc);
|
2017-06-08 18:49:22 +00:00
|
|
|
}
|
|
|
|
|
2017-12-11 22:14:19 +00:00
|
|
|
static void
|
|
|
|
_bdev_nvme_reset_destroy_qpair(struct spdk_io_channel_iter *i)
|
2017-06-08 18:49:22 +00:00
|
|
|
{
|
2017-12-11 22:14:19 +00:00
|
|
|
struct spdk_io_channel *ch = spdk_io_channel_iter_get_channel(i);
|
2017-06-08 18:49:22 +00:00
|
|
|
struct nvme_io_channel *nvme_ch = spdk_io_channel_get_ctx(ch);
|
2017-11-16 07:42:37 +00:00
|
|
|
int rc;
|
|
|
|
|
|
|
|
rc = spdk_nvme_ctrlr_free_io_qpair(nvme_ch->qpair);
|
|
|
|
if (!rc) {
|
|
|
|
nvme_ch->qpair = NULL;
|
|
|
|
}
|
2017-06-08 18:49:22 +00:00
|
|
|
|
2017-12-11 22:14:19 +00:00
|
|
|
spdk_for_each_channel_continue(i, rc);
|
2017-06-08 18:49:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2020-11-02 14:21:21 +00:00
|
|
|
_bdev_nvme_reset(struct nvme_bdev_ctrlr *nvme_bdev_ctrlr, void *ctx)
|
2017-06-08 18:49:22 +00:00
|
|
|
{
|
2021-03-03 17:23:21 +00:00
|
|
|
pthread_mutex_lock(&nvme_bdev_ctrlr->mutex);
|
2020-03-12 17:42:25 +00:00
|
|
|
if (nvme_bdev_ctrlr->destruct) {
|
2021-03-03 17:23:21 +00:00
|
|
|
pthread_mutex_unlock(&nvme_bdev_ctrlr->mutex);
|
2020-11-02 14:21:21 +00:00
|
|
|
return -EBUSY;
|
2020-03-12 17:42:25 +00:00
|
|
|
}
|
|
|
|
|
2020-10-03 19:55:22 +00:00
|
|
|
if (nvme_bdev_ctrlr->resetting) {
|
2021-03-03 17:23:21 +00:00
|
|
|
pthread_mutex_unlock(&nvme_bdev_ctrlr->mutex);
|
2019-11-08 21:26:09 +00:00
|
|
|
SPDK_NOTICELOG("Unable to perform reset, already in progress.\n");
|
2020-11-02 14:21:21 +00:00
|
|
|
return -EAGAIN;
|
2020-10-22 17:39:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nvme_bdev_ctrlr->resetting = true;
|
|
|
|
|
2021-03-03 17:23:21 +00:00
|
|
|
pthread_mutex_unlock(&nvme_bdev_ctrlr->mutex);
|
|
|
|
|
2020-10-22 17:39:05 +00:00
|
|
|
/* First, delete all NVMe I/O queue pairs. */
|
|
|
|
spdk_for_each_channel(nvme_bdev_ctrlr,
|
|
|
|
_bdev_nvme_reset_destroy_qpair,
|
2020-11-02 14:21:21 +00:00
|
|
|
ctx,
|
2020-11-02 14:00:35 +00:00
|
|
|
_bdev_nvme_reset_ctrlr);
|
2020-10-22 17:39:05 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-11-02 14:21:21 +00:00
|
|
|
static int
|
2020-11-23 06:43:41 +00:00
|
|
|
bdev_nvme_reset(struct nvme_io_channel *nvme_ch, struct nvme_bdev_io *bio)
|
2020-11-02 14:21:21 +00:00
|
|
|
{
|
2020-11-02 14:27:19 +00:00
|
|
|
struct spdk_bdev_io *bdev_io = spdk_bdev_io_from_ctx(bio);
|
2020-11-02 14:21:21 +00:00
|
|
|
int rc;
|
|
|
|
|
2020-11-23 06:43:41 +00:00
|
|
|
rc = _bdev_nvme_reset(nvme_ch->ctrlr, bio);
|
2020-11-02 14:21:21 +00:00
|
|
|
if (rc == -EBUSY) {
|
|
|
|
/* Don't bother resetting if the controller is in the process of being destructed. */
|
2020-11-02 14:27:19 +00:00
|
|
|
spdk_bdev_io_complete(bdev_io, SPDK_BDEV_IO_STATUS_FAILED);
|
2020-11-02 14:21:21 +00:00
|
|
|
return 0;
|
|
|
|
} else if (rc == -EAGAIN) {
|
|
|
|
/*
|
|
|
|
* Reset call is queued only if it is from the app framework. This is on purpose so that
|
|
|
|
* we don't interfere with the app framework reset strategy. i.e. we are deferring to the
|
|
|
|
* upper level. If they are in the middle of a reset, we won't try to schedule another one.
|
|
|
|
*/
|
2020-11-02 14:27:19 +00:00
|
|
|
TAILQ_INSERT_TAIL(&nvme_ch->pending_resets, bdev_io, module_link);
|
2020-11-02 14:21:21 +00:00
|
|
|
return 0;
|
|
|
|
} else {
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-22 17:39:05 +00:00
|
|
|
static int
|
2020-10-24 13:43:55 +00:00
|
|
|
bdev_nvme_failover(struct nvme_bdev_ctrlr *nvme_bdev_ctrlr, bool remove)
|
2020-10-22 17:39:05 +00:00
|
|
|
{
|
|
|
|
struct nvme_bdev_ctrlr_trid *curr_trid = NULL, *next_trid = NULL;
|
|
|
|
int rc = 0;
|
|
|
|
|
2021-03-03 17:23:21 +00:00
|
|
|
pthread_mutex_lock(&nvme_bdev_ctrlr->mutex);
|
2020-10-22 17:39:05 +00:00
|
|
|
if (nvme_bdev_ctrlr->destruct) {
|
2021-03-03 17:23:21 +00:00
|
|
|
pthread_mutex_unlock(&nvme_bdev_ctrlr->mutex);
|
2020-10-22 17:39:05 +00:00
|
|
|
/* Don't bother resetting if the controller is in the process of being destructed. */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
curr_trid = TAILQ_FIRST(&nvme_bdev_ctrlr->trids);
|
|
|
|
assert(curr_trid);
|
|
|
|
assert(&curr_trid->trid == nvme_bdev_ctrlr->connected_trid);
|
|
|
|
next_trid = TAILQ_NEXT(curr_trid, link);
|
|
|
|
|
|
|
|
if (nvme_bdev_ctrlr->resetting) {
|
|
|
|
if (next_trid && !nvme_bdev_ctrlr->failover_in_progress) {
|
|
|
|
rc = -EAGAIN;
|
|
|
|
}
|
2021-03-03 17:23:21 +00:00
|
|
|
pthread_mutex_unlock(&nvme_bdev_ctrlr->mutex);
|
2020-10-22 17:39:05 +00:00
|
|
|
SPDK_NOTICELOG("Unable to perform reset, already in progress.\n");
|
2020-06-12 23:35:47 +00:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2020-10-03 19:55:22 +00:00
|
|
|
nvme_bdev_ctrlr->resetting = true;
|
2020-12-22 12:50:29 +00:00
|
|
|
curr_trid->is_failed = true;
|
|
|
|
|
2020-10-22 17:39:05 +00:00
|
|
|
if (next_trid) {
|
2020-12-22 07:35:03 +00:00
|
|
|
assert(curr_trid->trid.trtype != SPDK_NVME_TRANSPORT_PCIE);
|
|
|
|
|
|
|
|
SPDK_NOTICELOG("Start failover from %s:%s to %s:%s\n", curr_trid->trid.traddr,
|
|
|
|
curr_trid->trid.trsvcid, next_trid->trid.traddr, next_trid->trid.trsvcid);
|
|
|
|
|
2020-10-03 19:55:22 +00:00
|
|
|
nvme_bdev_ctrlr->failover_in_progress = true;
|
2020-06-12 23:35:47 +00:00
|
|
|
spdk_nvme_ctrlr_fail(nvme_bdev_ctrlr->ctrlr);
|
|
|
|
nvme_bdev_ctrlr->connected_trid = &next_trid->trid;
|
|
|
|
rc = spdk_nvme_ctrlr_set_trid(nvme_bdev_ctrlr->ctrlr, &next_trid->trid);
|
|
|
|
assert(rc == 0);
|
2020-10-03 19:55:22 +00:00
|
|
|
TAILQ_REMOVE(&nvme_bdev_ctrlr->trids, curr_trid, link);
|
2020-10-24 13:43:55 +00:00
|
|
|
if (!remove) {
|
|
|
|
/** Shuffle the old trid to the end of the list and use the new one.
|
|
|
|
* Allows for round robin through multiple connections.
|
|
|
|
*/
|
|
|
|
TAILQ_INSERT_TAIL(&nvme_bdev_ctrlr->trids, curr_trid, link);
|
|
|
|
} else {
|
|
|
|
free(curr_trid);
|
|
|
|
}
|
2019-11-08 21:26:09 +00:00
|
|
|
}
|
|
|
|
|
2021-03-03 17:23:21 +00:00
|
|
|
pthread_mutex_unlock(&nvme_bdev_ctrlr->mutex);
|
|
|
|
|
2017-06-08 18:49:22 +00:00
|
|
|
/* First, delete all NVMe I/O queue pairs. */
|
2019-11-08 18:04:06 +00:00
|
|
|
spdk_for_each_channel(nvme_bdev_ctrlr,
|
2017-06-08 18:49:22 +00:00
|
|
|
_bdev_nvme_reset_destroy_qpair,
|
2020-10-22 17:39:05 +00:00
|
|
|
NULL,
|
2020-11-02 14:00:35 +00:00
|
|
|
_bdev_nvme_reset_ctrlr);
|
2017-06-08 18:49:22 +00:00
|
|
|
|
|
|
|
return 0;
|
2016-07-20 18:16:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2020-11-23 04:48:51 +00:00
|
|
|
bdev_nvme_unmap(struct spdk_nvme_ns *ns, struct spdk_nvme_qpair *qpair,
|
2017-02-28 17:51:25 +00:00
|
|
|
struct nvme_bdev_io *bio,
|
2017-08-29 00:15:53 +00:00
|
|
|
uint64_t offset_blocks,
|
|
|
|
uint64_t num_blocks);
|
2016-07-20 18:16:23 +00:00
|
|
|
|
2017-02-28 17:51:25 +00:00
|
|
|
static void
|
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
|
|
|
bdev_nvme_get_buf_cb(struct spdk_io_channel *ch, struct spdk_bdev_io *bdev_io,
|
|
|
|
bool success)
|
2016-07-20 18:16:23 +00:00
|
|
|
{
|
2020-11-23 04:09:54 +00:00
|
|
|
struct spdk_bdev *bdev = bdev_io->bdev;
|
|
|
|
struct nvme_bdev *nbdev = (struct nvme_bdev *)bdev->ctxt;
|
2020-09-23 22:10:47 +00:00
|
|
|
struct nvme_io_channel *nvme_ch = spdk_io_channel_get_ctx(ch);
|
2021-01-10 15:13:56 +00:00
|
|
|
struct nvme_bdev_ns *nvme_ns;
|
|
|
|
struct spdk_nvme_qpair *qpair;
|
2016-07-20 18:16:23 +00:00
|
|
|
int ret;
|
|
|
|
|
2019-02-25 01:43:13 +00:00
|
|
|
if (!success) {
|
|
|
|
spdk_bdev_io_complete(bdev_io, SPDK_BDEV_IO_STATUS_FAILED);
|
|
|
|
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
|
|
|
|
2021-01-10 15:13:56 +00:00
|
|
|
if (spdk_unlikely(!bdev_nvme_find_io_path(nbdev, nvme_ch, &nvme_ns, &qpair))) {
|
|
|
|
spdk_bdev_io_complete(bdev_io, SPDK_BDEV_IO_STATUS_FAILED);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = bdev_nvme_readv(nvme_ns->ns,
|
|
|
|
qpair,
|
2017-02-28 17:51:25 +00:00
|
|
|
(struct nvme_bdev_io *)bdev_io->driver_ctx,
|
2017-09-20 13:10:17 +00:00
|
|
|
bdev_io->u.bdev.iovs,
|
|
|
|
bdev_io->u.bdev.iovcnt,
|
2019-04-16 08:17:08 +00:00
|
|
|
bdev_io->u.bdev.md_buf,
|
2017-09-20 13:10:17 +00:00
|
|
|
bdev_io->u.bdev.num_blocks,
|
2020-09-23 20:37:27 +00:00
|
|
|
bdev_io->u.bdev.offset_blocks,
|
2020-11-23 04:09:54 +00:00
|
|
|
bdev->dif_check_flags);
|
2016-07-20 18:16:23 +00:00
|
|
|
|
bdev: add ENOMEM handling
At very high queue depths, bdev modules may not have enough
internal resources to track all of the incoming I/O. For example,
we allocate a finite number of nvme_request objects per allocated
queue pair. Currently if these resources are exhausted, the
bdev module will return failure (with no indication why) which
gets propagated all the way back to the application.
So instead, add SPDK_BDEV_IO_STATUS_NOMEM to allow bdev modules
to indicate this type of failure. Also add handling for this
status type in the generic bdev layer, involving queuing these
I/O for later retry after other I/O on the failing channel have
completed.
This does place an expectation on the bdev module that these
internal resources are allocated per io_channel. Otherwise we
cannot guarantee forward progress solely on reception of
completions. For example, without this guarantee, a bdev
module could theoretically return ENOMEM even if there were
no I/O oustanding for that io_channel. nvme, aio, rbd,
virtio and null drivers comply with this expectation already.
malloc only complies though when not using copy offload.
This patch will fix malloc w/ copy engine to at least
return ENOMEM when no copy descriptors are available. If the
condition above occurs, I/O waiting for resources will get
failed as part of a subsequent reset which matches the
behavior it has today.
Signed-off-by: Jim Harris <james.r.harris@intel.com>
Change-Id: Iea7cd51a611af8abe882794d0b2361fdbb74e84e
Reviewed-on: https://review.gerrithub.io/378853
Tested-by: SPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: Daniel Verkamp <daniel.verkamp@intel.com>
Reviewed-by: Changpeng Liu <changpeng.liu@intel.com>
2017-09-15 20:47:17 +00:00
|
|
|
if (spdk_likely(ret == 0)) {
|
|
|
|
return;
|
|
|
|
} else if (ret == -ENOMEM) {
|
|
|
|
spdk_bdev_io_complete(bdev_io, SPDK_BDEV_IO_STATUS_NOMEM);
|
|
|
|
} else {
|
2016-07-20 18:16:23 +00:00
|
|
|
spdk_bdev_io_complete(bdev_io, SPDK_BDEV_IO_STATUS_FAILED);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-28 17:51:25 +00:00
|
|
|
static int
|
2017-05-04 20:18:03 +00:00
|
|
|
_bdev_nvme_submit_request(struct spdk_io_channel *ch, struct spdk_bdev_io *bdev_io)
|
2016-07-20 18:16:23 +00:00
|
|
|
{
|
2017-06-08 18:49:22 +00:00
|
|
|
struct nvme_io_channel *nvme_ch = spdk_io_channel_get_ctx(ch);
|
2020-11-23 04:09:54 +00:00
|
|
|
struct spdk_bdev *bdev = bdev_io->bdev;
|
|
|
|
struct nvme_bdev *nbdev = (struct nvme_bdev *)bdev->ctxt;
|
2019-05-16 09:58:41 +00:00
|
|
|
struct nvme_bdev_io *nbdev_io = (struct nvme_bdev_io *)bdev_io->driver_ctx;
|
2020-07-08 08:03:49 +00:00
|
|
|
struct nvme_bdev_io *nbdev_io_to_abort;
|
2021-01-10 15:13:56 +00:00
|
|
|
struct nvme_bdev_ns *nvme_ns;
|
|
|
|
struct spdk_nvme_qpair *qpair;
|
2019-05-16 09:58:41 +00:00
|
|
|
|
2021-01-10 15:13:56 +00:00
|
|
|
if (spdk_unlikely(!bdev_nvme_find_io_path(nbdev, nvme_ch, &nvme_ns, &qpair))) {
|
2017-06-08 18:49:22 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2016-07-20 18:16:23 +00:00
|
|
|
switch (bdev_io->type) {
|
|
|
|
case SPDK_BDEV_IO_TYPE_READ:
|
2020-09-18 17:38:27 +00:00
|
|
|
if (bdev_io->u.bdev.iovs && bdev_io->u.bdev.iovs[0].iov_base) {
|
2021-01-10 15:13:56 +00:00
|
|
|
return bdev_nvme_readv(nvme_ns->ns,
|
|
|
|
qpair,
|
2020-12-13 13:22:54 +00:00
|
|
|
nbdev_io,
|
|
|
|
bdev_io->u.bdev.iovs,
|
|
|
|
bdev_io->u.bdev.iovcnt,
|
|
|
|
bdev_io->u.bdev.md_buf,
|
|
|
|
bdev_io->u.bdev.num_blocks,
|
|
|
|
bdev_io->u.bdev.offset_blocks,
|
|
|
|
bdev->dif_check_flags);
|
2020-09-18 17:38:27 +00:00
|
|
|
} else {
|
|
|
|
spdk_bdev_io_get_buf(bdev_io, bdev_nvme_get_buf_cb,
|
2020-11-23 04:09:54 +00:00
|
|
|
bdev_io->u.bdev.num_blocks * bdev->blocklen);
|
2020-12-13 13:22:54 +00:00
|
|
|
return 0;
|
2020-09-18 17:38:27 +00:00
|
|
|
}
|
2016-07-20 18:16:23 +00:00
|
|
|
|
|
|
|
case SPDK_BDEV_IO_TYPE_WRITE:
|
2021-01-10 15:13:56 +00:00
|
|
|
return bdev_nvme_writev(nvme_ns->ns,
|
|
|
|
qpair,
|
2019-05-16 09:58:41 +00:00
|
|
|
nbdev_io,
|
2017-09-20 13:10:17 +00:00
|
|
|
bdev_io->u.bdev.iovs,
|
|
|
|
bdev_io->u.bdev.iovcnt,
|
2019-04-16 08:17:08 +00:00
|
|
|
bdev_io->u.bdev.md_buf,
|
2017-09-20 13:10:17 +00:00
|
|
|
bdev_io->u.bdev.num_blocks,
|
2020-09-23 20:37:27 +00:00
|
|
|
bdev_io->u.bdev.offset_blocks,
|
2020-11-23 04:09:54 +00:00
|
|
|
bdev->dif_check_flags);
|
2016-07-20 18:16:23 +00:00
|
|
|
|
2019-12-13 08:40:54 +00:00
|
|
|
case SPDK_BDEV_IO_TYPE_COMPARE:
|
2021-01-10 15:13:56 +00:00
|
|
|
return bdev_nvme_comparev(nvme_ns->ns,
|
|
|
|
qpair,
|
2019-12-13 08:40:54 +00:00
|
|
|
nbdev_io,
|
|
|
|
bdev_io->u.bdev.iovs,
|
|
|
|
bdev_io->u.bdev.iovcnt,
|
|
|
|
bdev_io->u.bdev.md_buf,
|
|
|
|
bdev_io->u.bdev.num_blocks,
|
2020-09-23 20:37:27 +00:00
|
|
|
bdev_io->u.bdev.offset_blocks,
|
2020-11-23 04:09:54 +00:00
|
|
|
bdev->dif_check_flags);
|
2019-12-13 08:40:54 +00:00
|
|
|
|
2019-12-20 11:29:48 +00:00
|
|
|
case SPDK_BDEV_IO_TYPE_COMPARE_AND_WRITE:
|
2021-01-10 15:13:56 +00:00
|
|
|
return bdev_nvme_comparev_and_writev(nvme_ns->ns,
|
|
|
|
qpair,
|
2019-12-20 11:29:48 +00:00
|
|
|
nbdev_io,
|
|
|
|
bdev_io->u.bdev.iovs,
|
|
|
|
bdev_io->u.bdev.iovcnt,
|
2020-01-16 10:10:53 +00:00
|
|
|
bdev_io->u.bdev.fused_iovs,
|
|
|
|
bdev_io->u.bdev.fused_iovcnt,
|
2019-12-20 11:29:48 +00:00
|
|
|
bdev_io->u.bdev.md_buf,
|
|
|
|
bdev_io->u.bdev.num_blocks,
|
2020-09-23 20:37:27 +00:00
|
|
|
bdev_io->u.bdev.offset_blocks,
|
2020-11-23 04:09:54 +00:00
|
|
|
bdev->dif_check_flags);
|
2019-12-20 11:29:48 +00:00
|
|
|
|
2017-07-28 20:01:14 +00:00
|
|
|
case SPDK_BDEV_IO_TYPE_WRITE_ZEROES:
|
2021-01-10 15:13:56 +00:00
|
|
|
return bdev_nvme_unmap(nvme_ns->ns,
|
|
|
|
qpair,
|
2019-05-16 09:58:41 +00:00
|
|
|
nbdev_io,
|
2017-09-20 13:10:17 +00:00
|
|
|
bdev_io->u.bdev.offset_blocks,
|
|
|
|
bdev_io->u.bdev.num_blocks);
|
2017-07-28 20:01:14 +00:00
|
|
|
|
2016-07-20 18:16:23 +00:00
|
|
|
case SPDK_BDEV_IO_TYPE_UNMAP:
|
2021-01-10 15:13:56 +00:00
|
|
|
return bdev_nvme_unmap(nvme_ns->ns,
|
|
|
|
qpair,
|
2019-05-16 09:58:41 +00:00
|
|
|
nbdev_io,
|
2017-09-20 13:10:17 +00:00
|
|
|
bdev_io->u.bdev.offset_blocks,
|
|
|
|
bdev_io->u.bdev.num_blocks);
|
2016-07-20 18:16:23 +00:00
|
|
|
|
|
|
|
case SPDK_BDEV_IO_TYPE_RESET:
|
2020-11-23 06:43:41 +00:00
|
|
|
return bdev_nvme_reset(nvme_ch, nbdev_io);
|
2016-07-20 18:16:23 +00:00
|
|
|
|
|
|
|
case SPDK_BDEV_IO_TYPE_FLUSH:
|
2021-01-10 15:13:56 +00:00
|
|
|
return bdev_nvme_flush(nvme_ns->ns,
|
|
|
|
qpair,
|
2019-05-16 09:58:41 +00:00
|
|
|
nbdev_io,
|
2017-09-20 13:10:17 +00:00
|
|
|
bdev_io->u.bdev.offset_blocks,
|
|
|
|
bdev_io->u.bdev.num_blocks);
|
2016-07-20 18:16:23 +00:00
|
|
|
|
2017-05-13 20:12:13 +00:00
|
|
|
case SPDK_BDEV_IO_TYPE_NVME_ADMIN:
|
2020-11-23 06:43:41 +00:00
|
|
|
return bdev_nvme_admin_passthru(nvme_ch,
|
2019-05-16 09:58:41 +00:00
|
|
|
nbdev_io,
|
2017-05-13 20:12:13 +00:00
|
|
|
&bdev_io->u.nvme_passthru.cmd,
|
|
|
|
bdev_io->u.nvme_passthru.buf,
|
|
|
|
bdev_io->u.nvme_passthru.nbytes);
|
|
|
|
|
2017-06-05 18:02:09 +00:00
|
|
|
case SPDK_BDEV_IO_TYPE_NVME_IO:
|
2021-01-10 15:13:56 +00:00
|
|
|
return bdev_nvme_io_passthru(nvme_ns->ns,
|
|
|
|
qpair,
|
2019-05-16 09:58:41 +00:00
|
|
|
nbdev_io,
|
2017-06-05 18:02:09 +00:00
|
|
|
&bdev_io->u.nvme_passthru.cmd,
|
|
|
|
bdev_io->u.nvme_passthru.buf,
|
|
|
|
bdev_io->u.nvme_passthru.nbytes);
|
|
|
|
|
2017-11-14 06:33:11 +00:00
|
|
|
case SPDK_BDEV_IO_TYPE_NVME_IO_MD:
|
2021-01-10 15:13:56 +00:00
|
|
|
return bdev_nvme_io_passthru_md(nvme_ns->ns,
|
|
|
|
qpair,
|
2019-05-16 09:58:41 +00:00
|
|
|
nbdev_io,
|
2017-11-14 06:33:11 +00:00
|
|
|
&bdev_io->u.nvme_passthru.cmd,
|
|
|
|
bdev_io->u.nvme_passthru.buf,
|
|
|
|
bdev_io->u.nvme_passthru.nbytes,
|
|
|
|
bdev_io->u.nvme_passthru.md_buf,
|
|
|
|
bdev_io->u.nvme_passthru.md_len);
|
|
|
|
|
2020-07-08 08:03:49 +00:00
|
|
|
case SPDK_BDEV_IO_TYPE_ABORT:
|
|
|
|
nbdev_io_to_abort = (struct nvme_bdev_io *)bdev_io->u.abort.bio_to_abort->driver_ctx;
|
2020-11-23 06:43:41 +00:00
|
|
|
return bdev_nvme_abort(nvme_ch,
|
2020-07-08 08:03:49 +00:00
|
|
|
nbdev_io,
|
|
|
|
nbdev_io_to_abort);
|
|
|
|
|
2016-07-20 18:16:23 +00:00
|
|
|
default:
|
2017-05-20 00:12:39 +00:00
|
|
|
return -EINVAL;
|
2016-07-20 18:16:23 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-02-28 17:51:25 +00:00
|
|
|
static void
|
2017-05-04 20:18:03 +00:00
|
|
|
bdev_nvme_submit_request(struct spdk_io_channel *ch, struct spdk_bdev_io *bdev_io)
|
2016-07-20 18:16:23 +00:00
|
|
|
{
|
2017-09-15 23:46:53 +00:00
|
|
|
int rc = _bdev_nvme_submit_request(ch, bdev_io);
|
|
|
|
|
|
|
|
if (spdk_unlikely(rc != 0)) {
|
bdev: add ENOMEM handling
At very high queue depths, bdev modules may not have enough
internal resources to track all of the incoming I/O. For example,
we allocate a finite number of nvme_request objects per allocated
queue pair. Currently if these resources are exhausted, the
bdev module will return failure (with no indication why) which
gets propagated all the way back to the application.
So instead, add SPDK_BDEV_IO_STATUS_NOMEM to allow bdev modules
to indicate this type of failure. Also add handling for this
status type in the generic bdev layer, involving queuing these
I/O for later retry after other I/O on the failing channel have
completed.
This does place an expectation on the bdev module that these
internal resources are allocated per io_channel. Otherwise we
cannot guarantee forward progress solely on reception of
completions. For example, without this guarantee, a bdev
module could theoretically return ENOMEM even if there were
no I/O oustanding for that io_channel. nvme, aio, rbd,
virtio and null drivers comply with this expectation already.
malloc only complies though when not using copy offload.
This patch will fix malloc w/ copy engine to at least
return ENOMEM when no copy descriptors are available. If the
condition above occurs, I/O waiting for resources will get
failed as part of a subsequent reset which matches the
behavior it has today.
Signed-off-by: Jim Harris <james.r.harris@intel.com>
Change-Id: Iea7cd51a611af8abe882794d0b2361fdbb74e84e
Reviewed-on: https://review.gerrithub.io/378853
Tested-by: SPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: Daniel Verkamp <daniel.verkamp@intel.com>
Reviewed-by: Changpeng Liu <changpeng.liu@intel.com>
2017-09-15 20:47:17 +00:00
|
|
|
if (rc == -ENOMEM) {
|
|
|
|
spdk_bdev_io_complete(bdev_io, SPDK_BDEV_IO_STATUS_NOMEM);
|
|
|
|
} else {
|
|
|
|
spdk_bdev_io_complete(bdev_io, SPDK_BDEV_IO_STATUS_FAILED);
|
|
|
|
}
|
2016-07-20 18:16:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-24 17:25:49 +00:00
|
|
|
static bool
|
2017-04-04 21:10:00 +00:00
|
|
|
bdev_nvme_io_type_supported(void *ctx, enum spdk_bdev_io_type io_type)
|
2016-08-24 17:25:49 +00:00
|
|
|
{
|
2017-04-04 21:10:00 +00:00
|
|
|
struct nvme_bdev *nbdev = ctx;
|
2021-01-10 18:15:22 +00:00
|
|
|
struct nvme_bdev_ns *nvme_ns;
|
|
|
|
struct spdk_nvme_ns *ns;
|
|
|
|
struct spdk_nvme_ctrlr *ctrlr;
|
2016-08-24 17:25:49 +00:00
|
|
|
const struct spdk_nvme_ctrlr_data *cdata;
|
|
|
|
|
2021-01-10 18:15:22 +00:00
|
|
|
nvme_ns = nvme_bdev_to_bdev_ns(nbdev);
|
|
|
|
assert(nvme_ns != NULL);
|
|
|
|
ns = nvme_ns->ns;
|
|
|
|
ctrlr = spdk_nvme_ns_get_ctrlr(ns);
|
|
|
|
|
2016-08-24 17:25:49 +00:00
|
|
|
switch (io_type) {
|
|
|
|
case SPDK_BDEV_IO_TYPE_READ:
|
|
|
|
case SPDK_BDEV_IO_TYPE_WRITE:
|
|
|
|
case SPDK_BDEV_IO_TYPE_RESET:
|
|
|
|
case SPDK_BDEV_IO_TYPE_FLUSH:
|
2017-05-13 20:12:13 +00:00
|
|
|
case SPDK_BDEV_IO_TYPE_NVME_ADMIN:
|
2017-06-05 18:02:09 +00:00
|
|
|
case SPDK_BDEV_IO_TYPE_NVME_IO:
|
2020-07-08 08:03:49 +00:00
|
|
|
case SPDK_BDEV_IO_TYPE_ABORT:
|
2016-08-24 17:25:49 +00:00
|
|
|
return true;
|
|
|
|
|
2019-12-13 08:40:54 +00:00
|
|
|
case SPDK_BDEV_IO_TYPE_COMPARE:
|
2020-11-14 22:40:19 +00:00
|
|
|
return spdk_nvme_ns_supports_compare(ns);
|
2019-12-13 08:40:54 +00:00
|
|
|
|
2017-11-14 06:33:11 +00:00
|
|
|
case SPDK_BDEV_IO_TYPE_NVME_IO_MD:
|
2020-11-14 22:40:19 +00:00
|
|
|
return spdk_nvme_ns_get_md_size(ns) ? true : false;
|
2017-11-14 06:33:11 +00:00
|
|
|
|
2016-08-24 17:25:49 +00:00
|
|
|
case SPDK_BDEV_IO_TYPE_UNMAP:
|
2020-11-14 22:40:19 +00:00
|
|
|
cdata = spdk_nvme_ctrlr_get_data(ctrlr);
|
2016-08-24 17:25:49 +00:00
|
|
|
return cdata->oncs.dsm;
|
|
|
|
|
2017-07-28 20:01:14 +00:00
|
|
|
case SPDK_BDEV_IO_TYPE_WRITE_ZEROES:
|
2020-11-14 22:40:19 +00:00
|
|
|
cdata = spdk_nvme_ctrlr_get_data(ctrlr);
|
2017-07-28 20:01:14 +00:00
|
|
|
/*
|
|
|
|
* If an NVMe controller guarantees reading unallocated blocks returns zero,
|
|
|
|
* we can implement WRITE_ZEROES as an NVMe deallocate command.
|
|
|
|
*/
|
|
|
|
if (cdata->oncs.dsm &&
|
2020-11-14 22:40:19 +00:00
|
|
|
spdk_nvme_ns_get_dealloc_logical_block_read_value(ns) ==
|
2019-10-14 12:35:11 +00:00
|
|
|
SPDK_NVME_DEALLOC_READ_00) {
|
2017-07-28 20:01:14 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* The NVMe controller write_zeroes function is currently not used by our driver.
|
|
|
|
* If a user submits an arbitrarily large write_zeroes request to the controller, the request will fail.
|
|
|
|
* Until this is resolved, we only claim support for write_zeroes if deallocated blocks return 0's when read.
|
|
|
|
*/
|
|
|
|
return false;
|
|
|
|
|
2019-12-20 11:29:48 +00:00
|
|
|
case SPDK_BDEV_IO_TYPE_COMPARE_AND_WRITE:
|
2020-11-14 22:40:19 +00:00
|
|
|
if (spdk_nvme_ctrlr_get_flags(ctrlr) &
|
2019-12-20 11:29:48 +00:00
|
|
|
SPDK_NVME_CTRLR_COMPARE_AND_WRITE_SUPPORTED) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
|
2016-08-24 17:25:49 +00:00
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-16 19:53:32 +00:00
|
|
|
static int
|
2017-05-18 17:48:04 +00:00
|
|
|
bdev_nvme_create_cb(void *io_device, void *ctx_buf)
|
2016-09-16 19:53:32 +00:00
|
|
|
{
|
2019-10-15 11:03:36 +00:00
|
|
|
struct nvme_bdev_ctrlr *nvme_bdev_ctrlr = io_device;
|
2020-11-13 11:59:40 +00:00
|
|
|
struct nvme_io_channel *nvme_ch = ctx_buf;
|
2020-02-07 00:20:35 +00:00
|
|
|
struct spdk_io_channel *pg_ch = NULL;
|
|
|
|
int rc;
|
2017-06-15 16:59:02 +00:00
|
|
|
|
2019-12-11 11:11:05 +00:00
|
|
|
if (spdk_nvme_ctrlr_is_ocssd_supported(nvme_bdev_ctrlr->ctrlr)) {
|
2020-11-13 12:06:52 +00:00
|
|
|
rc = bdev_ocssd_create_io_channel(nvme_ch);
|
|
|
|
if (rc != 0) {
|
|
|
|
return rc;
|
2019-12-11 11:11:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-26 00:38:30 +00:00
|
|
|
pg_ch = spdk_get_io_channel(&g_nvme_bdev_ctrlrs);
|
2020-02-07 00:20:35 +00:00
|
|
|
if (!pg_ch) {
|
2020-11-13 12:06:52 +00:00
|
|
|
rc = -1;
|
|
|
|
goto err_pg_ch;
|
2020-02-07 00:20:35 +00:00
|
|
|
}
|
|
|
|
|
2020-11-13 11:59:40 +00:00
|
|
|
nvme_ch->group = spdk_io_channel_get_ctx(pg_ch);
|
2020-02-07 00:20:35 +00:00
|
|
|
|
|
|
|
#ifdef SPDK_CONFIG_VTUNE
|
2020-11-13 11:59:40 +00:00
|
|
|
nvme_ch->group->collect_spin_stat = true;
|
2020-02-07 00:20:35 +00:00
|
|
|
#else
|
2020-11-13 11:59:40 +00:00
|
|
|
nvme_ch->group->collect_spin_stat = false;
|
2020-02-07 00:20:35 +00:00
|
|
|
#endif
|
2019-11-08 21:26:09 +00:00
|
|
|
|
2020-11-13 11:59:40 +00:00
|
|
|
TAILQ_INIT(&nvme_ch->pending_resets);
|
2020-11-13 12:06:52 +00:00
|
|
|
|
2020-12-08 21:51:00 +00:00
|
|
|
nvme_ch->ctrlr = nvme_bdev_ctrlr;
|
|
|
|
|
|
|
|
rc = bdev_nvme_create_qpair(nvme_ch);
|
2020-11-13 12:06:52 +00:00
|
|
|
if (rc != 0) {
|
|
|
|
goto err_qpair;
|
|
|
|
}
|
|
|
|
|
2016-09-16 19:53:32 +00:00
|
|
|
return 0;
|
2020-02-07 00:20:35 +00:00
|
|
|
|
2020-11-13 12:06:52 +00:00
|
|
|
err_qpair:
|
|
|
|
spdk_put_io_channel(pg_ch);
|
|
|
|
err_pg_ch:
|
2020-12-08 21:51:00 +00:00
|
|
|
if (nvme_ch->ocssd_ch) {
|
2020-11-13 12:06:52 +00:00
|
|
|
bdev_ocssd_destroy_io_channel(nvme_ch);
|
2020-02-07 00:20:35 +00:00
|
|
|
}
|
2020-11-13 12:06:52 +00:00
|
|
|
|
|
|
|
return rc;
|
2016-09-16 19:53:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2017-02-28 17:51:25 +00:00
|
|
|
bdev_nvme_destroy_cb(void *io_device, void *ctx_buf)
|
2016-09-16 19:53:32 +00:00
|
|
|
{
|
2020-11-13 11:59:40 +00:00
|
|
|
struct nvme_io_channel *nvme_ch = ctx_buf;
|
2020-02-07 00:20:35 +00:00
|
|
|
|
2020-11-13 12:06:52 +00:00
|
|
|
assert(nvme_ch->group != NULL);
|
2016-09-16 19:53:32 +00:00
|
|
|
|
2020-12-08 21:51:00 +00:00
|
|
|
if (nvme_ch->ocssd_ch != NULL) {
|
2020-11-13 11:59:40 +00:00
|
|
|
bdev_ocssd_destroy_io_channel(nvme_ch);
|
2019-12-11 11:11:05 +00:00
|
|
|
}
|
|
|
|
|
2020-12-22 04:28:01 +00:00
|
|
|
spdk_nvme_ctrlr_free_io_qpair(nvme_ch->qpair);
|
2020-02-07 00:20:35 +00:00
|
|
|
|
2020-11-13 12:06:52 +00:00
|
|
|
spdk_put_io_channel(spdk_io_channel_from_ctx(nvme_ch->group));
|
2020-02-07 00:20:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
bdev_nvme_poll_group_create_cb(void *io_device, void *ctx_buf)
|
|
|
|
{
|
|
|
|
struct nvme_bdev_poll_group *group = ctx_buf;
|
|
|
|
|
2021-03-08 15:04:46 +00:00
|
|
|
group->group = spdk_nvme_poll_group_create(group, NULL);
|
2020-02-07 00:20:35 +00:00
|
|
|
if (group->group == NULL) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2020-07-08 01:13:08 +00:00
|
|
|
group->poller = SPDK_POLLER_REGISTER(bdev_nvme_poll, group, g_opts.nvme_ioq_poll_period_us);
|
2020-02-07 00:20:35 +00:00
|
|
|
|
|
|
|
if (group->poller == NULL) {
|
|
|
|
spdk_nvme_poll_group_destroy(group->group);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
bdev_nvme_poll_group_destroy_cb(void *io_device, void *ctx_buf)
|
|
|
|
{
|
|
|
|
struct nvme_bdev_poll_group *group = ctx_buf;
|
|
|
|
|
|
|
|
spdk_poller_unregister(&group->poller);
|
|
|
|
if (spdk_nvme_poll_group_destroy(group->group)) {
|
|
|
|
SPDK_ERRLOG("Unable to destroy a poll group for the NVMe bdev module.");
|
|
|
|
assert(false);
|
|
|
|
}
|
2016-09-16 19:53:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct spdk_io_channel *
|
2017-05-18 17:48:04 +00:00
|
|
|
bdev_nvme_get_io_channel(void *ctx)
|
2016-09-16 19:53:32 +00:00
|
|
|
{
|
2017-04-04 21:10:00 +00:00
|
|
|
struct nvme_bdev *nvme_bdev = ctx;
|
2016-09-16 19:53:32 +00:00
|
|
|
|
2020-09-16 01:08:54 +00:00
|
|
|
return spdk_get_io_channel(nvme_bdev->nvme_ns->ctrlr);
|
2016-09-16 19:53:32 +00:00
|
|
|
}
|
|
|
|
|
2020-10-27 16:13:54 +00:00
|
|
|
static void *
|
|
|
|
bdev_nvme_get_module_ctx(void *ctx)
|
|
|
|
{
|
|
|
|
struct nvme_bdev *nvme_bdev = ctx;
|
|
|
|
|
|
|
|
return bdev_nvme_get_ctrlr(&nvme_bdev->disk);
|
|
|
|
}
|
|
|
|
|
2016-11-18 17:22:58 +00:00
|
|
|
static int
|
2018-02-22 12:48:13 +00:00
|
|
|
bdev_nvme_dump_info_json(void *ctx, struct spdk_json_write_ctx *w)
|
2016-11-18 17:22:58 +00:00
|
|
|
{
|
2017-04-04 21:10:00 +00:00
|
|
|
struct nvme_bdev *nvme_bdev = ctx;
|
2021-01-10 18:15:22 +00:00
|
|
|
struct nvme_bdev_ns *nvme_ns;
|
|
|
|
struct spdk_nvme_ns *ns;
|
|
|
|
struct spdk_nvme_ctrlr *ctrlr;
|
2016-12-05 20:59:39 +00:00
|
|
|
const struct spdk_nvme_ctrlr_data *cdata;
|
2020-11-14 22:57:14 +00:00
|
|
|
const struct spdk_nvme_transport_id *trid;
|
2016-12-05 20:59:39 +00:00
|
|
|
union spdk_nvme_vs_register vs;
|
2016-12-12 23:57:20 +00:00
|
|
|
union spdk_nvme_csts_register csts;
|
2016-12-05 20:59:39 +00:00
|
|
|
char buf[128];
|
|
|
|
|
2021-01-10 18:15:22 +00:00
|
|
|
nvme_ns = nvme_bdev_to_bdev_ns(nvme_bdev);
|
|
|
|
assert(nvme_ns != NULL);
|
|
|
|
ns = nvme_ns->ns;
|
|
|
|
ctrlr = spdk_nvme_ns_get_ctrlr(ns);
|
|
|
|
|
2020-11-14 23:05:33 +00:00
|
|
|
cdata = spdk_nvme_ctrlr_get_data(ctrlr);
|
|
|
|
trid = spdk_nvme_ctrlr_get_transport_id(ctrlr);
|
|
|
|
vs = spdk_nvme_ctrlr_get_regs_vs(ctrlr);
|
|
|
|
csts = spdk_nvme_ctrlr_get_regs_csts(ctrlr);
|
2016-11-18 17:22:58 +00:00
|
|
|
|
2018-02-22 19:30:03 +00:00
|
|
|
spdk_json_write_named_object_begin(w, "nvme");
|
2016-11-18 17:22:58 +00:00
|
|
|
|
2020-11-14 22:57:14 +00:00
|
|
|
if (trid->trtype == SPDK_NVME_TRANSPORT_PCIE) {
|
|
|
|
spdk_json_write_named_string(w, "pci_address", trid->traddr);
|
2017-01-25 23:36:40 +00:00
|
|
|
}
|
|
|
|
|
2018-02-22 19:30:03 +00:00
|
|
|
spdk_json_write_named_object_begin(w, "trid");
|
2017-01-25 23:36:40 +00:00
|
|
|
|
2020-11-14 22:57:14 +00:00
|
|
|
nvme_bdev_dump_trid_json(trid, w);
|
2017-01-25 23:36:40 +00:00
|
|
|
|
|
|
|
spdk_json_write_object_end(w);
|
2016-12-05 20:59:39 +00:00
|
|
|
|
2019-10-24 18:09:47 +00:00
|
|
|
#ifdef SPDK_CONFIG_NVME_CUSE
|
2020-04-22 11:36:06 +00:00
|
|
|
size_t cuse_name_size = 128;
|
|
|
|
char cuse_name[cuse_name_size];
|
2019-10-24 18:09:47 +00:00
|
|
|
|
2020-11-14 23:05:33 +00:00
|
|
|
int rc = spdk_nvme_cuse_get_ns_name(ctrlr, spdk_nvme_ns_get_id(ns),
|
2020-04-22 11:36:06 +00:00
|
|
|
cuse_name, &cuse_name_size);
|
|
|
|
if (rc == 0) {
|
|
|
|
spdk_json_write_named_string(w, "cuse_device", cuse_name);
|
2019-10-24 18:09:47 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2018-02-22 19:30:03 +00:00
|
|
|
spdk_json_write_named_object_begin(w, "ctrlr_data");
|
2016-12-12 23:57:20 +00:00
|
|
|
|
2018-02-22 19:30:03 +00:00
|
|
|
spdk_json_write_named_string_fmt(w, "vendor_id", "0x%04x", cdata->vid);
|
2016-12-05 20:59:39 +00:00
|
|
|
|
|
|
|
snprintf(buf, sizeof(cdata->mn) + 1, "%s", cdata->mn);
|
|
|
|
spdk_str_trim(buf);
|
2018-02-22 19:30:03 +00:00
|
|
|
spdk_json_write_named_string(w, "model_number", buf);
|
2016-12-05 20:59:39 +00:00
|
|
|
|
|
|
|
snprintf(buf, sizeof(cdata->sn) + 1, "%s", cdata->sn);
|
|
|
|
spdk_str_trim(buf);
|
2018-02-22 19:30:03 +00:00
|
|
|
spdk_json_write_named_string(w, "serial_number", buf);
|
2016-12-05 20:59:39 +00:00
|
|
|
|
|
|
|
snprintf(buf, sizeof(cdata->fr) + 1, "%s", cdata->fr);
|
|
|
|
spdk_str_trim(buf);
|
2018-02-22 19:30:03 +00:00
|
|
|
spdk_json_write_named_string(w, "firmware_revision", buf);
|
2016-12-05 20:59:39 +00:00
|
|
|
|
2020-10-29 19:27:14 +00:00
|
|
|
if (cdata->subnqn[0] != '\0') {
|
|
|
|
spdk_json_write_named_string(w, "subnqn", cdata->subnqn);
|
|
|
|
}
|
|
|
|
|
2018-02-22 19:30:03 +00:00
|
|
|
spdk_json_write_named_object_begin(w, "oacs");
|
2017-01-03 22:47:32 +00:00
|
|
|
|
2018-02-22 19:30:03 +00:00
|
|
|
spdk_json_write_named_uint32(w, "security", cdata->oacs.security);
|
|
|
|
spdk_json_write_named_uint32(w, "format", cdata->oacs.format);
|
|
|
|
spdk_json_write_named_uint32(w, "firmware", cdata->oacs.firmware);
|
|
|
|
spdk_json_write_named_uint32(w, "ns_manage", cdata->oacs.ns_manage);
|
2017-01-03 22:47:32 +00:00
|
|
|
|
|
|
|
spdk_json_write_object_end(w);
|
|
|
|
|
2016-12-12 23:57:20 +00:00
|
|
|
spdk_json_write_object_end(w);
|
|
|
|
|
2018-02-22 19:30:03 +00:00
|
|
|
spdk_json_write_named_object_begin(w, "vs");
|
2016-12-12 23:57:20 +00:00
|
|
|
|
2016-12-06 22:25:28 +00:00
|
|
|
spdk_json_write_name(w, "nvme_version");
|
2016-12-05 20:59:39 +00:00
|
|
|
if (vs.bits.ter) {
|
2016-12-06 22:25:28 +00:00
|
|
|
spdk_json_write_string_fmt(w, "%u.%u.%u", vs.bits.mjr, vs.bits.mnr, vs.bits.ter);
|
|
|
|
} else {
|
|
|
|
spdk_json_write_string_fmt(w, "%u.%u", vs.bits.mjr, vs.bits.mnr);
|
2016-12-05 20:59:39 +00:00
|
|
|
}
|
|
|
|
|
2016-12-12 23:57:20 +00:00
|
|
|
spdk_json_write_object_end(w);
|
|
|
|
|
2018-02-22 19:30:03 +00:00
|
|
|
spdk_json_write_named_object_begin(w, "csts");
|
2016-12-12 23:57:20 +00:00
|
|
|
|
2018-02-22 19:30:03 +00:00
|
|
|
spdk_json_write_named_uint32(w, "rdy", csts.bits.rdy);
|
|
|
|
spdk_json_write_named_uint32(w, "cfs", csts.bits.cfs);
|
2016-12-12 23:57:20 +00:00
|
|
|
|
|
|
|
spdk_json_write_object_end(w);
|
|
|
|
|
2018-02-22 19:30:03 +00:00
|
|
|
spdk_json_write_named_object_begin(w, "ns_data");
|
2016-12-12 23:57:20 +00:00
|
|
|
|
2018-02-22 19:30:03 +00:00
|
|
|
spdk_json_write_named_uint32(w, "id", spdk_nvme_ns_get_id(ns));
|
2016-12-05 20:59:39 +00:00
|
|
|
|
2016-11-18 17:22:58 +00:00
|
|
|
spdk_json_write_object_end(w);
|
|
|
|
|
2019-07-19 15:26:53 +00:00
|
|
|
if (cdata->oacs.security) {
|
|
|
|
spdk_json_write_named_object_begin(w, "security");
|
|
|
|
|
2021-01-05 22:47:47 +00:00
|
|
|
spdk_json_write_named_bool(w, "opal", nvme_bdev->opal);
|
2019-07-19 15:26:53 +00:00
|
|
|
|
|
|
|
spdk_json_write_object_end(w);
|
|
|
|
}
|
|
|
|
|
2016-12-12 23:57:20 +00:00
|
|
|
spdk_json_write_object_end(w);
|
|
|
|
|
2016-11-18 17:22:58 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-04-05 15:43:55 +00:00
|
|
|
static void
|
|
|
|
bdev_nvme_write_config_json(struct spdk_bdev *bdev, struct spdk_json_write_ctx *w)
|
|
|
|
{
|
|
|
|
/* No config per bdev needed */
|
|
|
|
}
|
|
|
|
|
2017-06-15 16:59:02 +00:00
|
|
|
static uint64_t
|
|
|
|
bdev_nvme_get_spin_time(struct spdk_io_channel *ch)
|
|
|
|
{
|
|
|
|
struct nvme_io_channel *nvme_ch = spdk_io_channel_get_ctx(ch);
|
2020-02-07 00:20:35 +00:00
|
|
|
struct nvme_bdev_poll_group *group = nvme_ch->group;
|
2017-06-15 16:59:02 +00:00
|
|
|
uint64_t spin_time;
|
|
|
|
|
2020-02-07 00:20:35 +00:00
|
|
|
if (!group || !group->collect_spin_stat) {
|
2017-06-15 16:59:02 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-02-07 00:20:35 +00:00
|
|
|
if (group->end_ticks != 0) {
|
|
|
|
group->spin_ticks += (group->end_ticks - group->start_ticks);
|
|
|
|
group->end_ticks = 0;
|
2017-06-15 16:59:02 +00:00
|
|
|
}
|
|
|
|
|
2020-02-07 00:20:35 +00:00
|
|
|
spin_time = (group->spin_ticks * 1000000ULL) / spdk_get_ticks_hz();
|
|
|
|
group->start_ticks = 0;
|
|
|
|
group->spin_ticks = 0;
|
2017-06-15 16:59:02 +00:00
|
|
|
|
|
|
|
return spin_time;
|
|
|
|
}
|
|
|
|
|
2016-08-30 19:56:06 +00:00
|
|
|
static const struct spdk_bdev_fn_table nvmelib_fn_table = {
|
2017-02-28 17:51:25 +00:00
|
|
|
.destruct = bdev_nvme_destruct,
|
|
|
|
.submit_request = bdev_nvme_submit_request,
|
|
|
|
.io_type_supported = bdev_nvme_io_type_supported,
|
|
|
|
.get_io_channel = bdev_nvme_get_io_channel,
|
2018-02-22 12:48:13 +00:00
|
|
|
.dump_info_json = bdev_nvme_dump_info_json,
|
2018-04-05 15:43:55 +00:00
|
|
|
.write_config_json = bdev_nvme_write_config_json,
|
2017-06-15 16:59:02 +00:00
|
|
|
.get_spin_time = bdev_nvme_get_spin_time,
|
2020-10-27 16:13:54 +00:00
|
|
|
.get_module_ctx = bdev_nvme_get_module_ctx,
|
2016-07-20 18:16:23 +00:00
|
|
|
};
|
|
|
|
|
2020-12-27 09:20:01 +00:00
|
|
|
static int
|
|
|
|
nvme_disk_create(struct spdk_bdev *disk, const char *base_name,
|
|
|
|
struct spdk_nvme_ctrlr *ctrlr, struct spdk_nvme_ns *ns,
|
|
|
|
uint32_t prchk_flags, void *ctx)
|
2018-06-13 05:06:40 +00:00
|
|
|
{
|
2020-11-03 23:36:48 +00:00
|
|
|
const struct spdk_uuid *uuid;
|
2018-06-13 05:06:40 +00:00
|
|
|
const struct spdk_nvme_ctrlr_data *cdata;
|
2020-11-03 23:36:48 +00:00
|
|
|
const struct spdk_nvme_ns_data *nsdata;
|
|
|
|
int rc;
|
2018-06-13 05:06:40 +00:00
|
|
|
|
|
|
|
cdata = spdk_nvme_ctrlr_get_data(ctrlr);
|
|
|
|
|
2020-12-27 09:20:01 +00:00
|
|
|
disk->name = spdk_sprintf_alloc("%sn%d", base_name, spdk_nvme_ns_get_id(ns));
|
|
|
|
if (!disk->name) {
|
|
|
|
return -ENOMEM;
|
2019-10-14 12:35:11 +00:00
|
|
|
}
|
2020-12-27 09:20:01 +00:00
|
|
|
disk->product_name = "NVMe disk";
|
2018-06-13 05:06:40 +00:00
|
|
|
|
2020-12-27 09:20:01 +00:00
|
|
|
disk->write_cache = 0;
|
2018-06-13 05:06:40 +00:00
|
|
|
if (cdata->vwc.present) {
|
|
|
|
/* Enable if the Volatile Write Cache exists */
|
2020-12-27 09:20:01 +00:00
|
|
|
disk->write_cache = 1;
|
2018-06-13 05:06:40 +00:00
|
|
|
}
|
2020-12-27 09:20:01 +00:00
|
|
|
disk->blocklen = spdk_nvme_ns_get_extended_sector_size(ns);
|
|
|
|
disk->blockcnt = spdk_nvme_ns_get_num_sectors(ns);
|
|
|
|
disk->optimal_io_boundary = spdk_nvme_ns_get_optimal_io_boundary(ns);
|
2018-06-13 05:06:40 +00:00
|
|
|
|
|
|
|
uuid = spdk_nvme_ns_get_uuid(ns);
|
|
|
|
if (uuid != NULL) {
|
2020-12-27 09:20:01 +00:00
|
|
|
disk->uuid = *uuid;
|
2018-06-13 05:06:40 +00:00
|
|
|
}
|
|
|
|
|
2019-12-13 09:56:17 +00:00
|
|
|
nsdata = spdk_nvme_ns_get_data(ns);
|
|
|
|
|
2020-12-27 09:20:01 +00:00
|
|
|
disk->md_len = spdk_nvme_ns_get_md_size(ns);
|
|
|
|
if (disk->md_len != 0) {
|
|
|
|
disk->md_interleave = nsdata->flbas.extended;
|
|
|
|
disk->dif_type = (enum spdk_dif_type)spdk_nvme_ns_get_pi_type(ns);
|
|
|
|
if (disk->dif_type != SPDK_DIF_DISABLE) {
|
|
|
|
disk->dif_is_head_of_md = nsdata->dps.md_start;
|
|
|
|
disk->dif_check_flags = prchk_flags;
|
2019-02-05 06:00:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-19 07:00:45 +00:00
|
|
|
if (!(spdk_nvme_ctrlr_get_flags(ctrlr) &
|
|
|
|
SPDK_NVME_CTRLR_COMPARE_AND_WRITE_SUPPORTED)) {
|
2020-12-27 09:20:01 +00:00
|
|
|
disk->acwu = 0;
|
2019-12-13 09:56:17 +00:00
|
|
|
} else if (nsdata->nsfeat.ns_atomic_write_unit) {
|
2020-12-27 09:20:01 +00:00
|
|
|
disk->acwu = nsdata->nacwu;
|
2019-12-13 09:56:17 +00:00
|
|
|
} else {
|
2020-12-27 09:20:01 +00:00
|
|
|
disk->acwu = cdata->acwu;
|
2019-12-13 09:56:17 +00:00
|
|
|
}
|
|
|
|
|
2020-12-27 09:20:01 +00:00
|
|
|
disk->ctxt = ctx;
|
|
|
|
disk->fn_table = &nvmelib_fn_table;
|
|
|
|
disk->module = &nvme_if;
|
|
|
|
rc = spdk_bdev_register(disk);
|
2018-06-13 05:06:40 +00:00
|
|
|
if (rc) {
|
2020-11-03 23:36:48 +00:00
|
|
|
SPDK_ERRLOG("spdk_bdev_register() failed\n");
|
2020-12-27 09:20:01 +00:00
|
|
|
free(disk->name);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-12-21 02:19:46 +00:00
|
|
|
static int
|
2020-12-27 09:20:01 +00:00
|
|
|
nvme_bdev_create(struct nvme_bdev_ctrlr *nvme_bdev_ctrlr, struct nvme_bdev_ns *nvme_ns)
|
|
|
|
{
|
|
|
|
struct nvme_bdev *bdev;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
bdev = calloc(1, sizeof(*bdev));
|
|
|
|
if (!bdev) {
|
|
|
|
SPDK_ERRLOG("bdev calloc() failed\n");
|
2020-12-21 02:19:46 +00:00
|
|
|
return -ENOMEM;
|
2020-12-27 09:20:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bdev->nvme_ns = nvme_ns;
|
2021-01-05 22:47:47 +00:00
|
|
|
bdev->opal = nvme_bdev_ctrlr->opal_dev != NULL;
|
2020-12-27 09:20:01 +00:00
|
|
|
|
|
|
|
rc = nvme_disk_create(&bdev->disk, nvme_bdev_ctrlr->name, nvme_bdev_ctrlr->ctrlr,
|
|
|
|
nvme_ns->ns, nvme_bdev_ctrlr->prchk_flags, bdev);
|
|
|
|
if (rc != 0) {
|
|
|
|
SPDK_ERRLOG("Failed to create NVMe disk\n");
|
2019-10-14 12:35:11 +00:00
|
|
|
free(bdev);
|
2020-12-21 02:19:46 +00:00
|
|
|
return rc;
|
2020-11-03 23:36:48 +00:00
|
|
|
}
|
|
|
|
|
2021-01-04 07:50:15 +00:00
|
|
|
nvme_ns->ref++;
|
2021-02-17 16:07:25 +00:00
|
|
|
nvme_ns->bdev = bdev;
|
2021-01-04 07:50:15 +00:00
|
|
|
|
2020-12-21 02:19:46 +00:00
|
|
|
return 0;
|
2020-11-03 23:36:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
nvme_ctrlr_populate_standard_namespace(struct nvme_bdev_ctrlr *nvme_bdev_ctrlr,
|
|
|
|
struct nvme_bdev_ns *nvme_ns, struct nvme_async_probe_ctx *ctx)
|
|
|
|
{
|
|
|
|
struct spdk_nvme_ctrlr *ctrlr = nvme_bdev_ctrlr->ctrlr;
|
|
|
|
struct spdk_nvme_ns *ns;
|
|
|
|
int rc = 0;
|
|
|
|
|
|
|
|
ns = spdk_nvme_ctrlr_get_ns(ctrlr, nvme_ns->id);
|
|
|
|
if (!ns) {
|
|
|
|
SPDK_DEBUGLOG(bdev_nvme, "Invalid NS %d\n", nvme_ns->id);
|
|
|
|
rc = -EINVAL;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
nvme_ns->ns = ns;
|
2020-12-19 06:42:30 +00:00
|
|
|
nvme_ns->ref = 1;
|
2020-11-03 23:36:48 +00:00
|
|
|
|
2020-12-21 02:19:46 +00:00
|
|
|
rc = nvme_bdev_create(nvme_bdev_ctrlr, nvme_ns);
|
2020-10-26 23:01:21 +00:00
|
|
|
done:
|
|
|
|
nvme_ctrlr_populate_namespace_done(ctx, nvme_ns, rc);
|
2018-06-13 05:06:40 +00:00
|
|
|
}
|
|
|
|
|
2017-03-01 01:23:53 +00:00
|
|
|
static bool
|
|
|
|
hotplug_probe_cb(void *cb_ctx, const struct spdk_nvme_transport_id *trid,
|
|
|
|
struct spdk_nvme_ctrlr_opts *opts)
|
|
|
|
{
|
2019-02-13 05:08:22 +00:00
|
|
|
struct nvme_probe_skip_entry *entry;
|
|
|
|
|
|
|
|
TAILQ_FOREACH(entry, &g_skipped_nvme_ctrlrs, tailq) {
|
|
|
|
if (spdk_nvme_transport_id_compare(trid, &entry->trid) == 0) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-03 03:48:49 +00:00
|
|
|
opts->arbitration_burst = (uint8_t)g_opts.arbitration_burst;
|
|
|
|
opts->low_priority_weight = (uint8_t)g_opts.low_priority_weight;
|
|
|
|
opts->medium_priority_weight = (uint8_t)g_opts.medium_priority_weight;
|
|
|
|
opts->high_priority_weight = (uint8_t)g_opts.high_priority_weight;
|
|
|
|
|
2020-09-04 11:27:29 +00:00
|
|
|
SPDK_DEBUGLOG(bdev_nvme, "Attaching to %s\n", trid->traddr);
|
2017-03-01 01:23:53 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-03-30 19:49:52 +00:00
|
|
|
static void
|
2020-05-10 07:46:07 +00:00
|
|
|
nvme_abort_cpl(void *ctx, const struct spdk_nvme_cpl *cpl)
|
2017-03-30 19:49:52 +00:00
|
|
|
{
|
2020-10-22 12:26:25 +00:00
|
|
|
struct nvme_bdev_ctrlr *nvme_bdev_ctrlr = ctx;
|
2017-03-30 19:49:52 +00:00
|
|
|
|
|
|
|
if (spdk_nvme_cpl_is_error(cpl)) {
|
|
|
|
SPDK_WARNLOG("Abort failed. Resetting controller.\n");
|
2020-11-02 14:21:21 +00:00
|
|
|
_bdev_nvme_reset(nvme_bdev_ctrlr, NULL);
|
2017-03-30 19:49:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-10 22:43:18 +00:00
|
|
|
static void
|
2017-02-28 17:51:25 +00:00
|
|
|
timeout_cb(void *cb_arg, struct spdk_nvme_ctrlr *ctrlr,
|
|
|
|
struct spdk_nvme_qpair *qpair, uint16_t cid)
|
2016-12-10 22:43:18 +00:00
|
|
|
{
|
2020-10-22 12:26:25 +00:00
|
|
|
struct nvme_bdev_ctrlr *nvme_bdev_ctrlr = cb_arg;
|
2018-08-07 00:17:42 +00:00
|
|
|
union spdk_nvme_csts_register csts;
|
2020-10-22 12:26:25 +00:00
|
|
|
int rc;
|
|
|
|
|
|
|
|
assert(nvme_bdev_ctrlr->ctrlr == ctrlr);
|
2016-12-10 22:43:18 +00:00
|
|
|
|
2017-02-23 16:24:58 +00:00
|
|
|
SPDK_WARNLOG("Warning: Detected a timeout. ctrlr=%p qpair=%p cid=%u\n", ctrlr, qpair, cid);
|
2016-12-10 22:43:18 +00:00
|
|
|
|
2020-12-09 23:11:08 +00:00
|
|
|
/* Only try to read CSTS if it's a PCIe controller or we have a timeout on an I/O
|
|
|
|
* queue. (Note: qpair == NULL when there's an admin cmd timeout.) Otherwise we
|
|
|
|
* would submit another fabrics cmd on the admin queue to read CSTS and check for its
|
|
|
|
* completion recursively.
|
|
|
|
*/
|
|
|
|
if (nvme_bdev_ctrlr->connected_trid->trtype == SPDK_NVME_TRANSPORT_PCIE || qpair != NULL) {
|
|
|
|
csts = spdk_nvme_ctrlr_get_regs_csts(ctrlr);
|
|
|
|
if (csts.bits.cfs) {
|
|
|
|
SPDK_ERRLOG("Controller Fatal Status, reset required\n");
|
|
|
|
_bdev_nvme_reset(nvme_bdev_ctrlr, NULL);
|
|
|
|
return;
|
|
|
|
}
|
2018-08-07 00:17:42 +00:00
|
|
|
}
|
|
|
|
|
2018-07-09 21:04:33 +00:00
|
|
|
switch (g_opts.action_on_timeout) {
|
|
|
|
case SPDK_BDEV_NVME_TIMEOUT_ACTION_ABORT:
|
2017-03-30 19:49:52 +00:00
|
|
|
if (qpair) {
|
|
|
|
rc = spdk_nvme_ctrlr_cmd_abort(ctrlr, qpair, cid,
|
2020-10-22 12:26:25 +00:00
|
|
|
nvme_abort_cpl, nvme_bdev_ctrlr);
|
2017-03-30 19:49:52 +00:00
|
|
|
if (rc == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
SPDK_ERRLOG("Unable to send abort. Resetting.\n");
|
|
|
|
}
|
|
|
|
|
2017-06-02 06:32:45 +00:00
|
|
|
/* FALLTHROUGH */
|
2018-07-09 21:04:33 +00:00
|
|
|
case SPDK_BDEV_NVME_TIMEOUT_ACTION_RESET:
|
2020-11-02 14:21:21 +00:00
|
|
|
_bdev_nvme_reset(nvme_bdev_ctrlr, NULL);
|
2017-03-30 19:49:52 +00:00
|
|
|
break;
|
2018-07-09 21:04:33 +00:00
|
|
|
case SPDK_BDEV_NVME_TIMEOUT_ACTION_NONE:
|
2020-09-04 11:27:29 +00:00
|
|
|
SPDK_DEBUGLOG(bdev_nvme, "No action for nvme controller timeout.\n");
|
2018-10-23 10:41:37 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
SPDK_ERRLOG("An invalid timeout action value is found.\n");
|
2017-03-30 19:49:52 +00:00
|
|
|
break;
|
2016-12-10 22:43:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-09 13:34:21 +00:00
|
|
|
void
|
2020-12-17 08:36:24 +00:00
|
|
|
nvme_ctrlr_depopulate_namespace_done(struct nvme_bdev_ns *nvme_ns)
|
2020-03-09 13:34:21 +00:00
|
|
|
{
|
2021-01-04 07:28:52 +00:00
|
|
|
nvme_bdev_ns_detach(nvme_ns);
|
2020-03-09 13:34:21 +00:00
|
|
|
}
|
|
|
|
|
2018-06-21 01:10:30 +00:00
|
|
|
static void
|
2020-11-25 14:52:16 +00:00
|
|
|
nvme_ctrlr_depopulate_standard_namespace(struct nvme_bdev_ns *nvme_ns)
|
2018-06-21 01:10:30 +00:00
|
|
|
{
|
2021-01-06 16:21:06 +00:00
|
|
|
struct nvme_bdev *bdev;
|
2019-10-17 11:33:25 +00:00
|
|
|
|
2021-02-17 18:23:45 +00:00
|
|
|
bdev = nvme_bdev_ns_to_bdev(nvme_ns);
|
2021-01-06 16:21:06 +00:00
|
|
|
if (bdev != NULL) {
|
2019-10-17 11:33:25 +00:00
|
|
|
spdk_bdev_unregister(&bdev->disk, NULL, NULL);
|
|
|
|
}
|
|
|
|
|
2020-11-25 14:52:16 +00:00
|
|
|
nvme_ns->populated = false;
|
2020-03-09 13:34:21 +00:00
|
|
|
|
2020-12-17 08:36:24 +00:00
|
|
|
nvme_ctrlr_depopulate_namespace_done(nvme_ns);
|
2018-06-21 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2020-10-13 07:48:13 +00:00
|
|
|
static void
|
2020-11-25 14:52:16 +00:00
|
|
|
nvme_ctrlr_populate_namespace(struct nvme_bdev_ctrlr *ctrlr, struct nvme_bdev_ns *nvme_ns,
|
2020-10-13 07:48:13 +00:00
|
|
|
struct nvme_async_probe_ctx *ctx)
|
2019-11-25 20:16:24 +00:00
|
|
|
{
|
2020-11-25 14:52:16 +00:00
|
|
|
g_populate_namespace_fn[nvme_ns->type](ctrlr, nvme_ns, ctx);
|
2019-11-25 20:16:24 +00:00
|
|
|
}
|
|
|
|
|
2020-10-13 07:48:13 +00:00
|
|
|
static void
|
2020-11-25 14:52:16 +00:00
|
|
|
nvme_ctrlr_depopulate_namespace(struct nvme_bdev_ctrlr *ctrlr, struct nvme_bdev_ns *nvme_ns)
|
2019-11-25 20:16:24 +00:00
|
|
|
{
|
2020-11-25 14:52:16 +00:00
|
|
|
g_depopulate_namespace_fn[nvme_ns->type](nvme_ns);
|
2019-11-25 20:16:24 +00:00
|
|
|
}
|
|
|
|
|
2019-11-26 18:39:01 +00:00
|
|
|
void
|
|
|
|
nvme_ctrlr_populate_namespace_done(struct nvme_async_probe_ctx *ctx,
|
2020-11-25 14:52:16 +00:00
|
|
|
struct nvme_bdev_ns *nvme_ns, int rc)
|
2019-11-26 18:39:01 +00:00
|
|
|
{
|
2021-03-01 22:39:39 +00:00
|
|
|
struct nvme_bdev_ctrlr *nvme_bdev_ctrlr = nvme_ns->ctrlr;
|
|
|
|
|
|
|
|
assert(nvme_bdev_ctrlr != NULL);
|
|
|
|
|
2019-11-26 18:39:01 +00:00
|
|
|
if (rc == 0) {
|
2020-11-25 14:52:16 +00:00
|
|
|
nvme_ns->populated = true;
|
2021-03-03 17:23:21 +00:00
|
|
|
pthread_mutex_lock(&nvme_bdev_ctrlr->mutex);
|
2021-03-01 22:39:39 +00:00
|
|
|
nvme_bdev_ctrlr->ref++;
|
2021-03-03 17:23:21 +00:00
|
|
|
pthread_mutex_unlock(&nvme_bdev_ctrlr->mutex);
|
2019-11-26 18:39:01 +00:00
|
|
|
} else {
|
2020-11-25 14:52:16 +00:00
|
|
|
memset(nvme_ns, 0, sizeof(*nvme_ns));
|
2019-11-26 18:39:01 +00:00
|
|
|
}
|
2019-11-26 18:11:29 +00:00
|
|
|
|
|
|
|
if (ctx) {
|
|
|
|
ctx->populates_in_progress--;
|
|
|
|
if (ctx->populates_in_progress == 0) {
|
2021-03-01 22:39:39 +00:00
|
|
|
nvme_ctrlr_populate_namespaces_done(nvme_bdev_ctrlr, ctx);
|
2019-11-26 18:11:29 +00:00
|
|
|
}
|
|
|
|
}
|
2019-11-26 18:39:01 +00:00
|
|
|
}
|
|
|
|
|
2018-06-21 01:10:30 +00:00
|
|
|
static void
|
2019-11-26 16:55:40 +00:00
|
|
|
nvme_ctrlr_populate_namespaces(struct nvme_bdev_ctrlr *nvme_bdev_ctrlr,
|
|
|
|
struct nvme_async_probe_ctx *ctx)
|
2018-06-21 01:10:30 +00:00
|
|
|
{
|
2019-02-26 09:49:45 +00:00
|
|
|
struct spdk_nvme_ctrlr *ctrlr = nvme_bdev_ctrlr->ctrlr;
|
2020-11-25 14:52:16 +00:00
|
|
|
struct nvme_bdev_ns *nvme_ns;
|
|
|
|
struct spdk_nvme_ns *ns;
|
2020-02-13 07:34:09 +00:00
|
|
|
struct nvme_bdev *bdev;
|
2018-06-21 01:10:30 +00:00
|
|
|
uint32_t i;
|
2020-02-13 07:34:09 +00:00
|
|
|
int rc;
|
|
|
|
uint64_t num_sectors;
|
|
|
|
bool ns_is_active;
|
2019-11-26 18:11:29 +00:00
|
|
|
|
|
|
|
if (ctx) {
|
|
|
|
/* Initialize this count to 1 to handle the populate functions
|
|
|
|
* calling nvme_ctrlr_populate_namespace_done() immediately.
|
|
|
|
*/
|
|
|
|
ctx->populates_in_progress = 1;
|
|
|
|
}
|
2018-06-21 01:10:30 +00:00
|
|
|
|
2019-02-26 09:49:45 +00:00
|
|
|
for (i = 0; i < nvme_bdev_ctrlr->num_ns; i++) {
|
2018-06-21 01:10:30 +00:00
|
|
|
uint32_t nsid = i + 1;
|
|
|
|
|
2020-11-25 14:52:16 +00:00
|
|
|
nvme_ns = nvme_bdev_ctrlr->namespaces[i];
|
2020-02-13 07:34:09 +00:00
|
|
|
ns_is_active = spdk_nvme_ctrlr_is_active_ns(ctrlr, nsid);
|
|
|
|
|
2020-11-25 14:52:16 +00:00
|
|
|
if (nvme_ns->populated && ns_is_active && nvme_ns->type == NVME_BDEV_NS_STANDARD) {
|
2020-02-13 07:34:09 +00:00
|
|
|
/* NS is still there but attributes may have changed */
|
2020-11-25 14:52:16 +00:00
|
|
|
ns = spdk_nvme_ctrlr_get_ns(ctrlr, nsid);
|
|
|
|
num_sectors = spdk_nvme_ns_get_num_sectors(ns);
|
2021-02-17 18:23:45 +00:00
|
|
|
bdev = nvme_bdev_ns_to_bdev(nvme_ns);
|
2021-01-06 16:21:06 +00:00
|
|
|
assert(bdev != NULL);
|
2020-02-13 07:34:09 +00:00
|
|
|
if (bdev->disk.blockcnt != num_sectors) {
|
2020-11-17 16:29:21 +00:00
|
|
|
SPDK_NOTICELOG("NSID %u is resized: bdev name %s, old size %" PRIu64 ", new size %" PRIu64 "\n",
|
2020-02-13 07:34:09 +00:00
|
|
|
nsid,
|
|
|
|
bdev->disk.name,
|
|
|
|
bdev->disk.blockcnt,
|
|
|
|
num_sectors);
|
|
|
|
rc = spdk_bdev_notify_blockcnt_change(&bdev->disk, num_sectors);
|
|
|
|
if (rc != 0) {
|
|
|
|
SPDK_ERRLOG("Could not change num blocks for nvme bdev: name %s, errno: %d.\n",
|
|
|
|
bdev->disk.name, rc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-25 14:52:16 +00:00
|
|
|
if (!nvme_ns->populated && ns_is_active) {
|
|
|
|
nvme_ns->id = nsid;
|
|
|
|
nvme_ns->ctrlr = nvme_bdev_ctrlr;
|
2019-11-25 19:59:29 +00:00
|
|
|
if (spdk_nvme_ctrlr_is_ocssd_supported(ctrlr)) {
|
2020-11-25 14:52:16 +00:00
|
|
|
nvme_ns->type = NVME_BDEV_NS_OCSSD;
|
2019-11-25 19:59:29 +00:00
|
|
|
} else {
|
2020-11-25 14:52:16 +00:00
|
|
|
nvme_ns->type = NVME_BDEV_NS_STANDARD;
|
2019-11-25 19:59:29 +00:00
|
|
|
}
|
2019-10-14 12:35:11 +00:00
|
|
|
|
2021-02-17 16:07:25 +00:00
|
|
|
nvme_ns->bdev = NULL;
|
2019-10-17 11:33:25 +00:00
|
|
|
|
2019-11-26 18:11:29 +00:00
|
|
|
if (ctx) {
|
|
|
|
ctx->populates_in_progress++;
|
|
|
|
}
|
2020-11-25 14:52:16 +00:00
|
|
|
nvme_ctrlr_populate_namespace(nvme_bdev_ctrlr, nvme_ns, ctx);
|
2018-06-21 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2020-11-25 14:52:16 +00:00
|
|
|
if (nvme_ns->populated && !ns_is_active) {
|
|
|
|
nvme_ctrlr_depopulate_namespace(nvme_bdev_ctrlr, nvme_ns);
|
2018-06-21 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-26 18:11:29 +00:00
|
|
|
if (ctx) {
|
|
|
|
/* Decrement this count now that the loop is over to account
|
|
|
|
* for the one we started with. If the count is then 0, we
|
|
|
|
* know any populate_namespace functions completed immediately,
|
|
|
|
* so we'll kick the callback here.
|
|
|
|
*/
|
|
|
|
ctx->populates_in_progress--;
|
|
|
|
if (ctx->populates_in_progress == 0) {
|
2021-03-01 22:39:39 +00:00
|
|
|
nvme_ctrlr_populate_namespaces_done(nvme_bdev_ctrlr, ctx);
|
2019-11-26 18:11:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-21 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2020-10-13 07:48:13 +00:00
|
|
|
static void
|
|
|
|
nvme_ctrlr_depopulate_namespaces(struct nvme_bdev_ctrlr *nvme_bdev_ctrlr)
|
|
|
|
{
|
|
|
|
uint32_t i;
|
2020-11-25 14:52:16 +00:00
|
|
|
struct nvme_bdev_ns *nvme_ns;
|
2020-10-13 07:48:13 +00:00
|
|
|
|
|
|
|
for (i = 0; i < nvme_bdev_ctrlr->num_ns; i++) {
|
|
|
|
uint32_t nsid = i + 1;
|
|
|
|
|
2020-11-25 14:52:16 +00:00
|
|
|
nvme_ns = nvme_bdev_ctrlr->namespaces[nsid - 1];
|
|
|
|
if (nvme_ns->populated) {
|
|
|
|
assert(nvme_ns->id == nsid);
|
|
|
|
nvme_ctrlr_depopulate_namespace(nvme_bdev_ctrlr, nvme_ns);
|
2020-10-13 07:48:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-21 01:10:30 +00:00
|
|
|
static void
|
|
|
|
aer_cb(void *arg, const struct spdk_nvme_cpl *cpl)
|
|
|
|
{
|
2019-02-26 09:49:45 +00:00
|
|
|
struct nvme_bdev_ctrlr *nvme_bdev_ctrlr = arg;
|
2018-06-21 01:10:30 +00:00
|
|
|
union spdk_nvme_async_event_completion event;
|
|
|
|
|
|
|
|
if (spdk_nvme_cpl_is_error(cpl)) {
|
|
|
|
SPDK_WARNLOG("AER request execute failed");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
event.raw = cpl->cdw0;
|
|
|
|
if ((event.bits.async_event_type == SPDK_NVME_ASYNC_EVENT_TYPE_NOTICE) &&
|
|
|
|
(event.bits.async_event_info == SPDK_NVME_ASYNC_EVENT_NS_ATTR_CHANGED)) {
|
2019-11-26 16:55:40 +00:00
|
|
|
nvme_ctrlr_populate_namespaces(nvme_bdev_ctrlr, NULL);
|
2019-12-11 11:20:08 +00:00
|
|
|
} else if ((event.bits.async_event_type == SPDK_NVME_ASYNC_EVENT_TYPE_VENDOR) &&
|
|
|
|
(event.bits.log_page_identifier == SPDK_OCSSD_LOG_CHUNK_NOTIFICATION) &&
|
|
|
|
spdk_nvme_ctrlr_is_ocssd_supported(nvme_bdev_ctrlr->ctrlr)) {
|
|
|
|
bdev_ocssd_handle_chunk_notification(nvme_bdev_ctrlr);
|
2018-06-21 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-15 22:30:43 +00:00
|
|
|
static int
|
2020-10-01 09:11:39 +00:00
|
|
|
nvme_bdev_ctrlr_create(struct spdk_nvme_ctrlr *ctrlr,
|
|
|
|
const char *name,
|
|
|
|
const struct spdk_nvme_transport_id *trid,
|
2021-03-02 02:12:18 +00:00
|
|
|
uint32_t prchk_flags,
|
|
|
|
struct nvme_bdev_ctrlr **_nvme_bdev_ctrlr)
|
2016-07-20 18:16:23 +00:00
|
|
|
{
|
2019-02-26 09:49:45 +00:00
|
|
|
struct nvme_bdev_ctrlr *nvme_bdev_ctrlr;
|
2020-06-12 22:14:49 +00:00
|
|
|
struct nvme_bdev_ctrlr_trid *trid_entry;
|
2019-10-14 12:35:11 +00:00
|
|
|
uint32_t i;
|
2019-12-11 11:20:08 +00:00
|
|
|
int rc;
|
2017-03-30 17:59:25 +00:00
|
|
|
|
2019-02-26 09:49:45 +00:00
|
|
|
nvme_bdev_ctrlr = calloc(1, sizeof(*nvme_bdev_ctrlr));
|
|
|
|
if (nvme_bdev_ctrlr == NULL) {
|
2016-07-20 18:16:23 +00:00
|
|
|
SPDK_ERRLOG("Failed to allocate device struct\n");
|
2018-06-15 22:30:43 +00:00
|
|
|
return -ENOMEM;
|
2016-07-20 18:16:23 +00:00
|
|
|
}
|
2020-06-24 22:00:57 +00:00
|
|
|
|
2021-03-03 17:23:21 +00:00
|
|
|
rc = pthread_mutex_init(&nvme_bdev_ctrlr->mutex, NULL);
|
|
|
|
if (rc != 0) {
|
|
|
|
goto err_init_mutex;
|
|
|
|
}
|
|
|
|
|
2020-06-12 22:14:49 +00:00
|
|
|
TAILQ_INIT(&nvme_bdev_ctrlr->trids);
|
2020-06-24 22:00:57 +00:00
|
|
|
nvme_bdev_ctrlr->num_ns = spdk_nvme_ctrlr_get_num_ns(ctrlr);
|
2021-02-24 17:03:44 +00:00
|
|
|
if (nvme_bdev_ctrlr->num_ns != 0) {
|
|
|
|
nvme_bdev_ctrlr->namespaces = calloc(nvme_bdev_ctrlr->num_ns, sizeof(struct nvme_bdev_ns *));
|
|
|
|
if (!nvme_bdev_ctrlr->namespaces) {
|
|
|
|
SPDK_ERRLOG("Failed to allocate block namespaces pointer\n");
|
|
|
|
rc = -ENOMEM;
|
|
|
|
goto err_alloc_namespaces;
|
|
|
|
}
|
2020-06-12 22:14:49 +00:00
|
|
|
}
|
|
|
|
|
2020-06-12 22:14:49 +00:00
|
|
|
trid_entry = calloc(1, sizeof(*trid_entry));
|
|
|
|
if (trid_entry == NULL) {
|
|
|
|
SPDK_ERRLOG("Failed to allocate trid entry pointer\n");
|
2020-10-01 09:11:39 +00:00
|
|
|
rc = -ENOMEM;
|
|
|
|
goto err_alloc_trid;
|
2020-06-12 22:14:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
trid_entry->trid = *trid;
|
|
|
|
|
2019-10-14 12:35:11 +00:00
|
|
|
for (i = 0; i < nvme_bdev_ctrlr->num_ns; i++) {
|
|
|
|
nvme_bdev_ctrlr->namespaces[i] = calloc(1, sizeof(struct nvme_bdev_ns));
|
|
|
|
if (nvme_bdev_ctrlr->namespaces[i] == NULL) {
|
|
|
|
SPDK_ERRLOG("Failed to allocate block namespace struct\n");
|
2020-10-01 09:11:39 +00:00
|
|
|
rc = -ENOMEM;
|
|
|
|
goto err_alloc_namespace;
|
2019-10-14 12:35:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-08 08:02:36 +00:00
|
|
|
nvme_bdev_ctrlr->thread = spdk_get_thread();
|
2019-02-26 09:49:45 +00:00
|
|
|
nvme_bdev_ctrlr->adminq_timer_poller = NULL;
|
|
|
|
nvme_bdev_ctrlr->ctrlr = ctrlr;
|
2020-10-21 21:10:57 +00:00
|
|
|
nvme_bdev_ctrlr->ref = 1;
|
2020-06-12 22:14:49 +00:00
|
|
|
nvme_bdev_ctrlr->connected_trid = &trid_entry->trid;
|
2019-02-26 09:49:45 +00:00
|
|
|
nvme_bdev_ctrlr->name = strdup(name);
|
|
|
|
if (nvme_bdev_ctrlr->name == NULL) {
|
2020-10-01 09:11:39 +00:00
|
|
|
rc = -ENOMEM;
|
|
|
|
goto err_alloc_name;
|
2018-07-31 14:05:41 +00:00
|
|
|
}
|
2019-12-11 11:20:08 +00:00
|
|
|
|
|
|
|
if (spdk_nvme_ctrlr_is_ocssd_supported(nvme_bdev_ctrlr->ctrlr)) {
|
|
|
|
rc = bdev_ocssd_init_ctrlr(nvme_bdev_ctrlr);
|
|
|
|
if (spdk_unlikely(rc != 0)) {
|
|
|
|
SPDK_ERRLOG("Unable to initialize OCSSD controller\n");
|
2020-10-01 09:11:39 +00:00
|
|
|
goto err_init_ocssd;
|
2019-12-11 11:20:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-26 09:49:45 +00:00
|
|
|
nvme_bdev_ctrlr->prchk_flags = prchk_flags;
|
2016-07-20 18:16:23 +00:00
|
|
|
|
2019-10-15 11:03:36 +00:00
|
|
|
spdk_io_device_register(nvme_bdev_ctrlr, bdev_nvme_create_cb, bdev_nvme_destroy_cb,
|
2018-08-30 20:26:50 +00:00
|
|
|
sizeof(struct nvme_io_channel),
|
|
|
|
name);
|
2017-09-25 17:39:05 +00:00
|
|
|
|
2020-07-14 23:28:56 +00:00
|
|
|
nvme_bdev_ctrlr->adminq_timer_poller = SPDK_POLLER_REGISTER(bdev_nvme_poll_adminq, nvme_bdev_ctrlr,
|
2019-02-26 09:49:45 +00:00
|
|
|
g_opts.nvme_adminq_poll_period_us);
|
2017-01-13 19:58:23 +00:00
|
|
|
|
2019-02-26 09:49:45 +00:00
|
|
|
TAILQ_INSERT_TAIL(&g_nvme_bdev_ctrlrs, nvme_bdev_ctrlr, tailq);
|
2016-07-20 18:16:23 +00:00
|
|
|
|
2019-02-19 22:03:10 +00:00
|
|
|
if (g_opts.timeout_us > 0) {
|
2018-07-09 21:04:33 +00:00
|
|
|
spdk_nvme_ctrlr_register_timeout_callback(ctrlr, g_opts.timeout_us,
|
2020-10-22 12:26:25 +00:00
|
|
|
timeout_cb, nvme_bdev_ctrlr);
|
2016-12-10 22:43:18 +00:00
|
|
|
}
|
2018-06-15 22:30:43 +00:00
|
|
|
|
2019-02-26 09:49:45 +00:00
|
|
|
spdk_nvme_ctrlr_register_aer_callback(ctrlr, aer_cb, nvme_bdev_ctrlr);
|
2020-12-07 15:42:00 +00:00
|
|
|
spdk_nvme_ctrlr_set_remove_cb(ctrlr, remove_cb, nvme_bdev_ctrlr);
|
2018-06-21 01:10:30 +00:00
|
|
|
|
2019-07-19 15:26:53 +00:00
|
|
|
if (spdk_nvme_ctrlr_get_flags(nvme_bdev_ctrlr->ctrlr) &
|
|
|
|
SPDK_NVME_CTRLR_SECURITY_SEND_RECV_SUPPORTED) {
|
2020-03-03 15:09:30 +00:00
|
|
|
nvme_bdev_ctrlr->opal_dev = spdk_opal_dev_construct(nvme_bdev_ctrlr->ctrlr);
|
2019-10-31 10:11:50 +00:00
|
|
|
if (nvme_bdev_ctrlr->opal_dev == NULL) {
|
|
|
|
SPDK_ERRLOG("Failed to initialize Opal\n");
|
|
|
|
}
|
2019-07-19 15:26:53 +00:00
|
|
|
}
|
2020-06-12 22:14:49 +00:00
|
|
|
|
|
|
|
TAILQ_INSERT_HEAD(&nvme_bdev_ctrlr->trids, trid_entry, link);
|
2021-03-02 02:12:18 +00:00
|
|
|
|
|
|
|
if (_nvme_bdev_ctrlr != NULL) {
|
|
|
|
*_nvme_bdev_ctrlr = nvme_bdev_ctrlr;
|
|
|
|
}
|
2018-06-15 22:30:43 +00:00
|
|
|
return 0;
|
2020-10-01 09:11:39 +00:00
|
|
|
|
|
|
|
err_init_ocssd:
|
|
|
|
free(nvme_bdev_ctrlr->name);
|
|
|
|
err_alloc_name:
|
|
|
|
err_alloc_namespace:
|
|
|
|
for (; i > 0; i--) {
|
|
|
|
free(nvme_bdev_ctrlr->namespaces[i - 1]);
|
|
|
|
}
|
|
|
|
free(trid_entry);
|
|
|
|
err_alloc_trid:
|
|
|
|
free(nvme_bdev_ctrlr->namespaces);
|
|
|
|
err_alloc_namespaces:
|
2021-03-03 17:23:21 +00:00
|
|
|
pthread_mutex_destroy(&nvme_bdev_ctrlr->mutex);
|
|
|
|
err_init_mutex:
|
2020-10-01 09:11:39 +00:00
|
|
|
free(nvme_bdev_ctrlr);
|
|
|
|
return rc;
|
2018-06-15 22:30:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
attach_cb(void *cb_ctx, const struct spdk_nvme_transport_id *trid,
|
|
|
|
struct spdk_nvme_ctrlr *ctrlr, const struct spdk_nvme_ctrlr_opts *opts)
|
|
|
|
{
|
2019-09-17 08:06:33 +00:00
|
|
|
struct nvme_bdev_ctrlr *nvme_bdev_ctrlr;
|
2018-06-15 22:30:43 +00:00
|
|
|
struct nvme_probe_ctx *ctx = cb_ctx;
|
|
|
|
char *name = NULL;
|
2019-02-10 08:20:40 +00:00
|
|
|
uint32_t prchk_flags = 0;
|
2018-06-15 22:30:43 +00:00
|
|
|
size_t i;
|
2021-03-02 02:12:18 +00:00
|
|
|
int rc;
|
2018-06-15 22:30:43 +00:00
|
|
|
|
|
|
|
if (ctx) {
|
|
|
|
for (i = 0; i < ctx->count; i++) {
|
|
|
|
if (spdk_nvme_transport_id_compare(trid, &ctx->trids[i]) == 0) {
|
2019-02-10 08:20:40 +00:00
|
|
|
prchk_flags = ctx->prchk_flags[i];
|
2018-06-15 22:30:43 +00:00
|
|
|
name = strdup(ctx->names[i]);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
name = spdk_sprintf_alloc("HotInNvme%d", g_hot_insert_nvme_controller_index++);
|
|
|
|
}
|
|
|
|
if (!name) {
|
|
|
|
SPDK_ERRLOG("Failed to assign name to NVMe device\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-09-04 11:27:29 +00:00
|
|
|
SPDK_DEBUGLOG(bdev_nvme, "Attached to %s (%s)\n", trid->traddr, name);
|
2018-06-15 22:30:43 +00:00
|
|
|
|
2021-03-02 02:12:18 +00:00
|
|
|
rc = nvme_bdev_ctrlr_create(ctrlr, name, trid, prchk_flags, &nvme_bdev_ctrlr);
|
|
|
|
if (rc != 0) {
|
|
|
|
SPDK_ERRLOG("Failed to create new NVMe controller\n");
|
2019-09-17 08:06:33 +00:00
|
|
|
free(name);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-11-26 16:55:40 +00:00
|
|
|
nvme_ctrlr_populate_namespaces(nvme_bdev_ctrlr, NULL);
|
2019-09-17 08:06:33 +00:00
|
|
|
|
2018-06-15 22:44:08 +00:00
|
|
|
free(name);
|
2016-07-20 18:16:23 +00:00
|
|
|
}
|
|
|
|
|
2020-11-26 06:25:08 +00:00
|
|
|
static void
|
2020-11-26 06:34:00 +00:00
|
|
|
_nvme_bdev_ctrlr_destruct(void *ctx)
|
2020-11-26 06:25:08 +00:00
|
|
|
{
|
2020-11-26 06:34:00 +00:00
|
|
|
struct nvme_bdev_ctrlr *nvme_bdev_ctrlr = ctx;
|
|
|
|
|
2020-11-26 06:25:08 +00:00
|
|
|
nvme_ctrlr_depopulate_namespaces(nvme_bdev_ctrlr);
|
2021-01-04 05:09:27 +00:00
|
|
|
nvme_bdev_ctrlr_destruct(nvme_bdev_ctrlr);
|
2020-11-26 06:25:08 +00:00
|
|
|
}
|
|
|
|
|
2021-03-03 16:07:18 +00:00
|
|
|
static int
|
|
|
|
_bdev_nvme_delete(struct nvme_bdev_ctrlr *nvme_bdev_ctrlr, bool hotplug)
|
2017-03-01 01:23:53 +00:00
|
|
|
{
|
2021-03-03 16:07:18 +00:00
|
|
|
struct nvme_probe_skip_entry *entry;
|
2017-03-01 01:23:53 +00:00
|
|
|
|
2021-03-03 17:23:21 +00:00
|
|
|
pthread_mutex_lock(&nvme_bdev_ctrlr->mutex);
|
2021-03-03 16:07:18 +00:00
|
|
|
|
2020-12-07 15:42:00 +00:00
|
|
|
/* The controller's destruction was already started */
|
|
|
|
if (nvme_bdev_ctrlr->destruct) {
|
2021-03-03 17:23:21 +00:00
|
|
|
pthread_mutex_unlock(&nvme_bdev_ctrlr->mutex);
|
2021-03-03 16:07:18 +00:00
|
|
|
return 0;
|
2017-03-01 01:23:53 +00:00
|
|
|
}
|
2021-03-03 16:07:18 +00:00
|
|
|
|
|
|
|
if (!hotplug &&
|
|
|
|
nvme_bdev_ctrlr->connected_trid->trtype == SPDK_NVME_TRANSPORT_PCIE) {
|
|
|
|
entry = calloc(1, sizeof(*entry));
|
|
|
|
if (!entry) {
|
2021-03-03 17:23:21 +00:00
|
|
|
pthread_mutex_unlock(&nvme_bdev_ctrlr->mutex);
|
2021-03-03 16:07:18 +00:00
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
entry->trid = *nvme_bdev_ctrlr->connected_trid;
|
|
|
|
TAILQ_INSERT_TAIL(&g_skipped_nvme_ctrlrs, entry, tailq);
|
|
|
|
}
|
|
|
|
|
2020-12-07 15:42:00 +00:00
|
|
|
nvme_bdev_ctrlr->destruct = true;
|
2021-03-03 17:23:21 +00:00
|
|
|
pthread_mutex_unlock(&nvme_bdev_ctrlr->mutex);
|
2021-03-03 16:07:18 +00:00
|
|
|
|
2020-12-07 15:42:00 +00:00
|
|
|
_nvme_bdev_ctrlr_destruct(nvme_bdev_ctrlr);
|
2021-03-03 16:07:18 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
remove_cb(void *cb_ctx, struct spdk_nvme_ctrlr *ctrlr)
|
|
|
|
{
|
|
|
|
struct nvme_bdev_ctrlr *nvme_bdev_ctrlr = cb_ctx;
|
|
|
|
|
|
|
|
_bdev_nvme_delete(nvme_bdev_ctrlr, true);
|
2017-03-01 01:23:53 +00:00
|
|
|
}
|
|
|
|
|
2020-12-18 13:10:56 +00:00
|
|
|
static int
|
|
|
|
bdev_nvme_hotplug_probe(void *arg)
|
|
|
|
{
|
|
|
|
if (spdk_nvme_probe_poll_async(g_hotplug_probe_ctx) != -EAGAIN) {
|
|
|
|
g_hotplug_probe_ctx = NULL;
|
|
|
|
spdk_poller_unregister(&g_hotplug_probe_poller);
|
|
|
|
}
|
|
|
|
|
|
|
|
return SPDK_POLLER_BUSY;
|
|
|
|
}
|
|
|
|
|
2018-03-13 00:16:47 +00:00
|
|
|
static int
|
2017-07-13 04:08:53 +00:00
|
|
|
bdev_nvme_hotplug(void *arg)
|
2017-03-01 01:23:53 +00:00
|
|
|
{
|
2019-03-05 07:32:34 +00:00
|
|
|
struct spdk_nvme_transport_id trid_pcie;
|
|
|
|
|
2020-12-18 13:10:56 +00:00
|
|
|
if (g_hotplug_probe_ctx) {
|
|
|
|
return SPDK_POLLER_BUSY;
|
2019-03-05 07:32:34 +00:00
|
|
|
}
|
|
|
|
|
2020-12-18 13:10:56 +00:00
|
|
|
memset(&trid_pcie, 0, sizeof(trid_pcie));
|
|
|
|
spdk_nvme_trid_populate_transport(&trid_pcie, SPDK_NVME_TRANSPORT_PCIE);
|
|
|
|
|
|
|
|
g_hotplug_probe_ctx = spdk_nvme_probe_async(&trid_pcie, NULL,
|
|
|
|
hotplug_probe_cb, attach_cb, NULL);
|
|
|
|
|
|
|
|
if (g_hotplug_probe_ctx) {
|
|
|
|
assert(g_hotplug_probe_poller == NULL);
|
|
|
|
g_hotplug_probe_poller = SPDK_POLLER_REGISTER(bdev_nvme_hotplug_probe, NULL, 1000);
|
2017-03-01 01:23:53 +00:00
|
|
|
}
|
2018-03-13 00:16:47 +00:00
|
|
|
|
2020-05-04 09:51:27 +00:00
|
|
|
return SPDK_POLLER_BUSY;
|
2017-03-01 01:23:53 +00:00
|
|
|
}
|
|
|
|
|
2018-07-09 21:04:33 +00:00
|
|
|
void
|
2020-05-10 07:46:07 +00:00
|
|
|
bdev_nvme_get_opts(struct spdk_bdev_nvme_opts *opts)
|
2018-07-09 21:04:33 +00:00
|
|
|
{
|
|
|
|
*opts = g_opts;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2020-05-10 07:46:07 +00:00
|
|
|
bdev_nvme_set_opts(const struct spdk_bdev_nvme_opts *opts)
|
2018-07-09 21:04:33 +00:00
|
|
|
{
|
2018-07-12 12:26:19 +00:00
|
|
|
if (g_bdev_nvme_init_thread != NULL) {
|
2020-01-07 18:53:13 +00:00
|
|
|
if (!TAILQ_EMPTY(&g_nvme_bdev_ctrlrs)) {
|
|
|
|
return -EPERM;
|
|
|
|
}
|
2018-07-09 21:04:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
g_opts = *opts;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2019-07-10 05:13:31 +00:00
|
|
|
|
2018-07-12 12:26:19 +00:00
|
|
|
struct set_nvme_hotplug_ctx {
|
|
|
|
uint64_t period_us;
|
|
|
|
bool enabled;
|
2018-10-10 21:05:04 +00:00
|
|
|
spdk_msg_fn fn;
|
2018-07-12 12:26:19 +00:00
|
|
|
void *fn_ctx;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
set_nvme_hotplug_period_cb(void *_ctx)
|
|
|
|
{
|
|
|
|
struct set_nvme_hotplug_ctx *ctx = _ctx;
|
|
|
|
|
|
|
|
spdk_poller_unregister(&g_hotplug_poller);
|
|
|
|
if (ctx->enabled) {
|
2020-04-14 06:49:46 +00:00
|
|
|
g_hotplug_poller = SPDK_POLLER_REGISTER(bdev_nvme_hotplug, NULL, ctx->period_us);
|
2018-07-12 12:26:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
g_nvme_hotplug_poll_period_us = ctx->period_us;
|
|
|
|
g_nvme_hotplug_enabled = ctx->enabled;
|
|
|
|
if (ctx->fn) {
|
|
|
|
ctx->fn(ctx->fn_ctx);
|
|
|
|
}
|
|
|
|
|
|
|
|
free(ctx);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2020-05-10 07:46:07 +00:00
|
|
|
bdev_nvme_set_hotplug(bool enabled, uint64_t period_us, spdk_msg_fn cb, void *cb_ctx)
|
2018-07-12 12:26:19 +00:00
|
|
|
{
|
|
|
|
struct set_nvme_hotplug_ctx *ctx;
|
|
|
|
|
|
|
|
if (enabled == true && !spdk_process_is_primary()) {
|
|
|
|
return -EPERM;
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx = calloc(1, sizeof(*ctx));
|
|
|
|
if (ctx == NULL) {
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
period_us = period_us == 0 ? NVME_HOTPLUG_POLL_PERIOD_DEFAULT : period_us;
|
|
|
|
ctx->period_us = spdk_min(period_us, NVME_HOTPLUG_POLL_PERIOD_MAX);
|
|
|
|
ctx->enabled = enabled;
|
|
|
|
ctx->fn = cb;
|
|
|
|
ctx->fn_ctx = cb_ctx;
|
|
|
|
|
|
|
|
spdk_thread_send_msg(g_bdev_nvme_init_thread, set_nvme_hotplug_period_cb, ctx);
|
|
|
|
return 0;
|
|
|
|
}
|
2018-07-09 21:04:33 +00:00
|
|
|
|
2019-09-27 09:27:30 +00:00
|
|
|
static void
|
2019-11-26 17:52:55 +00:00
|
|
|
populate_namespaces_cb(struct nvme_async_probe_ctx *ctx, size_t count, int rc)
|
2019-09-27 09:27:30 +00:00
|
|
|
{
|
|
|
|
if (ctx->cb_fn) {
|
|
|
|
ctx->cb_fn(ctx->cb_ctx, count, rc);
|
|
|
|
}
|
2019-09-16 06:54:30 +00:00
|
|
|
|
2021-01-07 07:41:32 +00:00
|
|
|
ctx->namespaces_populated = true;
|
|
|
|
if (ctx->probe_done) {
|
|
|
|
/* The probe was already completed, so we need to free the context
|
|
|
|
* here. This can happen for cases like OCSSD, where we need to
|
|
|
|
* send additional commands to the SSD after attach.
|
|
|
|
*/
|
|
|
|
free(ctx);
|
|
|
|
}
|
2019-09-27 09:27:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2021-03-01 22:39:39 +00:00
|
|
|
nvme_ctrlr_populate_namespaces_done(struct nvme_bdev_ctrlr *nvme_bdev_ctrlr,
|
|
|
|
struct nvme_async_probe_ctx *ctx)
|
2019-03-05 06:13:03 +00:00
|
|
|
{
|
2020-11-25 14:52:16 +00:00
|
|
|
struct nvme_bdev_ns *nvme_ns;
|
2021-01-06 16:21:06 +00:00
|
|
|
struct nvme_bdev *nvme_bdev;
|
2019-03-05 06:13:03 +00:00
|
|
|
uint32_t i, nsid;
|
|
|
|
size_t j;
|
|
|
|
|
2020-04-22 23:53:11 +00:00
|
|
|
assert(nvme_bdev_ctrlr != NULL);
|
2019-09-17 08:06:33 +00:00
|
|
|
|
2019-03-05 06:13:03 +00:00
|
|
|
/*
|
|
|
|
* Report the new bdevs that were created in this call.
|
2019-10-18 07:12:00 +00:00
|
|
|
* There can be more than one bdev per NVMe controller.
|
2019-03-05 06:13:03 +00:00
|
|
|
*/
|
|
|
|
j = 0;
|
|
|
|
for (i = 0; i < nvme_bdev_ctrlr->num_ns; i++) {
|
|
|
|
nsid = i + 1;
|
2020-11-25 14:52:16 +00:00
|
|
|
nvme_ns = nvme_bdev_ctrlr->namespaces[nsid - 1];
|
|
|
|
if (!nvme_ns->populated) {
|
2019-03-05 06:13:03 +00:00
|
|
|
continue;
|
|
|
|
}
|
2020-11-25 14:52:16 +00:00
|
|
|
assert(nvme_ns->id == nsid);
|
2021-02-17 18:23:45 +00:00
|
|
|
nvme_bdev = nvme_bdev_ns_to_bdev(nvme_ns);
|
2021-01-06 16:21:06 +00:00
|
|
|
if (nvme_bdev == NULL) {
|
|
|
|
assert(nvme_ns->type == NVME_BDEV_NS_OCSSD);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (j < ctx->count) {
|
|
|
|
ctx->names[j] = nvme_bdev->disk.name;
|
|
|
|
j++;
|
|
|
|
} else {
|
|
|
|
SPDK_ERRLOG("Maximum number of namespaces supported per NVMe controller is %du. Unable to return all names of created bdevs\n",
|
|
|
|
ctx->count);
|
|
|
|
populate_namespaces_cb(ctx, 0, -ERANGE);
|
|
|
|
return;
|
2019-03-05 06:13:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-26 17:52:55 +00:00
|
|
|
populate_namespaces_cb(ctx, j, 0);
|
2019-03-05 06:13:03 +00:00
|
|
|
}
|
|
|
|
|
2020-11-30 22:19:55 +00:00
|
|
|
static bool
|
|
|
|
bdev_nvme_compare_ns(struct spdk_nvme_ns *ns1, struct spdk_nvme_ns *ns2)
|
|
|
|
{
|
|
|
|
const struct spdk_nvme_ns_data *nsdata1, *nsdata2;
|
|
|
|
|
|
|
|
nsdata1 = spdk_nvme_ns_get_data(ns1);
|
|
|
|
nsdata2 = spdk_nvme_ns_get_data(ns2);
|
|
|
|
|
|
|
|
return memcmp(nsdata1->nguid, nsdata2->nguid, sizeof(nsdata1->nguid));
|
|
|
|
}
|
|
|
|
|
2020-09-24 02:05:17 +00:00
|
|
|
static int
|
2020-11-27 18:31:47 +00:00
|
|
|
bdev_nvme_add_trid(struct nvme_bdev_ctrlr *nvme_bdev_ctrlr, struct spdk_nvme_ctrlr *new_ctrlr,
|
|
|
|
struct spdk_nvme_transport_id *trid)
|
2020-06-12 22:14:49 +00:00
|
|
|
{
|
2020-11-30 22:19:55 +00:00
|
|
|
uint32_t i, nsid;
|
|
|
|
struct nvme_bdev_ns *nvme_ns;
|
|
|
|
struct spdk_nvme_ns *new_ns;
|
2020-12-22 12:50:29 +00:00
|
|
|
struct nvme_bdev_ctrlr_trid *new_trid, *tmp_trid;
|
2020-12-22 12:26:39 +00:00
|
|
|
int rc = 0;
|
2020-06-12 22:14:49 +00:00
|
|
|
|
2020-09-24 02:08:14 +00:00
|
|
|
assert(nvme_bdev_ctrlr != NULL);
|
2020-06-12 22:14:49 +00:00
|
|
|
|
2020-09-24 02:10:11 +00:00
|
|
|
if (trid->trtype == SPDK_NVME_TRANSPORT_PCIE) {
|
|
|
|
SPDK_ERRLOG("PCIe failover is not supported.\n");
|
|
|
|
return -ENOTSUP;
|
|
|
|
}
|
|
|
|
|
2021-03-03 17:23:21 +00:00
|
|
|
pthread_mutex_lock(&nvme_bdev_ctrlr->mutex);
|
2020-12-22 12:26:39 +00:00
|
|
|
|
2020-06-12 22:14:49 +00:00
|
|
|
/* Currently we only support failover to the same transport type. */
|
|
|
|
if (nvme_bdev_ctrlr->connected_trid->trtype != trid->trtype) {
|
2020-12-22 12:26:39 +00:00
|
|
|
rc = -EINVAL;
|
|
|
|
goto exit;
|
2020-06-12 22:14:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Currently we only support failover to the same NQN. */
|
|
|
|
if (strncmp(trid->subnqn, nvme_bdev_ctrlr->connected_trid->subnqn, SPDK_NVMF_NQN_MAX_LEN)) {
|
2020-12-22 12:26:39 +00:00
|
|
|
rc = -EINVAL;
|
|
|
|
goto exit;
|
2020-06-12 22:14:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Skip all the other checks if we've already registered this path. */
|
|
|
|
TAILQ_FOREACH(new_trid, &nvme_bdev_ctrlr->trids, link) {
|
|
|
|
if (!spdk_nvme_transport_id_compare(&new_trid->trid, trid)) {
|
2020-12-22 12:26:39 +00:00
|
|
|
rc = -EEXIST;
|
|
|
|
goto exit;
|
2020-06-12 22:14:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (spdk_nvme_ctrlr_get_num_ns(new_ctrlr) != nvme_bdev_ctrlr->num_ns) {
|
2020-12-22 12:26:39 +00:00
|
|
|
rc = -EINVAL;
|
|
|
|
goto exit;
|
2020-06-12 22:14:49 +00:00
|
|
|
}
|
|
|
|
|
2020-11-30 22:19:55 +00:00
|
|
|
for (i = 0; i < nvme_bdev_ctrlr->num_ns; i++) {
|
|
|
|
nsid = i + 1;
|
|
|
|
|
|
|
|
nvme_ns = nvme_bdev_ctrlr->namespaces[i];
|
|
|
|
if (!nvme_ns->populated) {
|
2020-11-03 18:14:17 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2020-11-30 22:19:55 +00:00
|
|
|
new_ns = spdk_nvme_ctrlr_get_ns(new_ctrlr, nsid);
|
2020-06-12 22:14:49 +00:00
|
|
|
assert(new_ns != NULL);
|
|
|
|
|
2020-11-30 22:19:55 +00:00
|
|
|
if (bdev_nvme_compare_ns(nvme_ns->ns, new_ns) != 0) {
|
2020-12-22 12:26:39 +00:00
|
|
|
rc = -EINVAL;
|
|
|
|
goto exit;
|
2020-06-12 22:14:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
new_trid = calloc(1, sizeof(*new_trid));
|
|
|
|
if (new_trid == NULL) {
|
2020-12-22 12:26:39 +00:00
|
|
|
rc = -ENOMEM;
|
|
|
|
goto exit;
|
2020-06-12 22:14:49 +00:00
|
|
|
}
|
|
|
|
new_trid->trid = *trid;
|
2020-12-22 12:50:29 +00:00
|
|
|
new_trid->is_failed = false;
|
|
|
|
|
|
|
|
TAILQ_FOREACH(tmp_trid, &nvme_bdev_ctrlr->trids, link) {
|
|
|
|
if (tmp_trid->is_failed) {
|
|
|
|
TAILQ_INSERT_BEFORE(tmp_trid, new_trid, link);
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-12 22:14:49 +00:00
|
|
|
TAILQ_INSERT_TAIL(&nvme_bdev_ctrlr->trids, new_trid, link);
|
|
|
|
|
2020-12-22 12:26:39 +00:00
|
|
|
exit:
|
2021-03-03 17:23:21 +00:00
|
|
|
pthread_mutex_unlock(&nvme_bdev_ctrlr->mutex);
|
2020-12-22 12:26:39 +00:00
|
|
|
return rc;
|
2020-06-12 22:14:49 +00:00
|
|
|
}
|
|
|
|
|
2020-11-27 17:38:18 +00:00
|
|
|
static void
|
|
|
|
connect_attach_cb(void *cb_ctx, const struct spdk_nvme_transport_id *trid,
|
|
|
|
struct spdk_nvme_ctrlr *ctrlr, const struct spdk_nvme_ctrlr_opts *opts)
|
2020-06-25 17:06:56 +00:00
|
|
|
{
|
2020-11-27 17:38:18 +00:00
|
|
|
struct spdk_nvme_ctrlr_opts *user_opts = cb_ctx;
|
|
|
|
struct nvme_bdev_ctrlr *nvme_bdev_ctrlr;
|
|
|
|
struct nvme_async_probe_ctx *ctx;
|
|
|
|
int rc;
|
2020-06-25 17:06:56 +00:00
|
|
|
|
2020-11-27 17:38:18 +00:00
|
|
|
ctx = SPDK_CONTAINEROF(user_opts, struct nvme_async_probe_ctx, opts);
|
2021-01-07 07:41:32 +00:00
|
|
|
ctx->ctrlr_attached = true;
|
2020-11-27 17:38:18 +00:00
|
|
|
|
2020-11-27 18:31:47 +00:00
|
|
|
nvme_bdev_ctrlr = nvme_bdev_ctrlr_get_by_name(ctx->base_name);
|
|
|
|
if (nvme_bdev_ctrlr) {
|
|
|
|
/* This is the case that a secondary path is added to an existing
|
|
|
|
* nvme_bdev_ctrlr for failover. After checking if it can access the same
|
|
|
|
* namespaces as the primary path, it is disconnected until failover occurs.
|
|
|
|
*/
|
|
|
|
rc = bdev_nvme_add_trid(nvme_bdev_ctrlr, ctrlr, &ctx->trid);
|
|
|
|
|
|
|
|
spdk_nvme_detach(ctrlr);
|
2020-12-18 17:41:30 +00:00
|
|
|
goto exit;
|
2020-11-27 18:31:47 +00:00
|
|
|
}
|
|
|
|
|
2021-03-02 02:12:18 +00:00
|
|
|
rc = nvme_bdev_ctrlr_create(ctrlr, ctx->base_name, &ctx->trid, ctx->prchk_flags,
|
|
|
|
&nvme_bdev_ctrlr);
|
2020-11-27 17:38:18 +00:00
|
|
|
if (rc) {
|
|
|
|
SPDK_ERRLOG("Failed to create new device\n");
|
2020-12-18 17:41:30 +00:00
|
|
|
goto exit;
|
2020-06-25 17:06:56 +00:00
|
|
|
}
|
|
|
|
|
2020-11-27 17:38:18 +00:00
|
|
|
nvme_ctrlr_populate_namespaces(nvme_bdev_ctrlr, ctx);
|
2020-12-18 17:41:30 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
exit:
|
|
|
|
populate_namespaces_cb(ctx, 0, rc);
|
2020-11-27 17:38:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
bdev_nvme_async_poll(void *arg)
|
|
|
|
{
|
|
|
|
struct nvme_async_probe_ctx *ctx = arg;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
rc = spdk_nvme_probe_poll_async(ctx->probe_ctx);
|
2021-01-07 07:41:32 +00:00
|
|
|
if (spdk_unlikely(rc != -EAGAIN)) {
|
|
|
|
ctx->probe_done = true;
|
2020-11-27 17:38:18 +00:00
|
|
|
spdk_poller_unregister(&ctx->poller);
|
2021-01-07 07:41:32 +00:00
|
|
|
if (!ctx->ctrlr_attached) {
|
|
|
|
/* The probe is done, but no controller was attached.
|
|
|
|
* That means we had a failure, so report -EIO back to
|
|
|
|
* the caller (usually the RPC). populate_namespaces_cb()
|
|
|
|
* will take care of freeing the nvme_async_probe_ctx.
|
|
|
|
*/
|
|
|
|
populate_namespaces_cb(ctx, 0, -EIO);
|
|
|
|
} else if (ctx->namespaces_populated) {
|
|
|
|
/* The namespaces for the attached controller were all
|
|
|
|
* populated and the response was already sent to the
|
|
|
|
* caller (usually the RPC). So free the context here.
|
|
|
|
*/
|
|
|
|
free(ctx);
|
|
|
|
}
|
2020-06-25 17:06:56 +00:00
|
|
|
}
|
|
|
|
|
2020-11-27 17:38:18 +00:00
|
|
|
return SPDK_POLLER_BUSY;
|
2020-06-25 17:06:56 +00:00
|
|
|
}
|
|
|
|
|
2016-10-10 03:54:38 +00:00
|
|
|
int
|
2020-05-10 07:46:07 +00:00
|
|
|
bdev_nvme_create(struct spdk_nvme_transport_id *trid,
|
|
|
|
struct spdk_nvme_host_id *hostid,
|
|
|
|
const char *base_name,
|
|
|
|
const char **names,
|
|
|
|
uint32_t count,
|
|
|
|
const char *hostnqn,
|
|
|
|
uint32_t prchk_flags,
|
|
|
|
spdk_bdev_create_nvme_fn cb_fn,
|
2021-01-21 11:53:16 +00:00
|
|
|
void *cb_ctx,
|
|
|
|
struct spdk_nvme_ctrlr_opts *opts)
|
2016-10-10 03:54:38 +00:00
|
|
|
{
|
2019-02-13 05:08:22 +00:00
|
|
|
struct nvme_probe_skip_entry *entry, *tmp;
|
2019-03-05 07:26:58 +00:00
|
|
|
struct nvme_async_probe_ctx *ctx;
|
2016-10-25 23:19:53 +00:00
|
|
|
|
2020-09-24 01:47:54 +00:00
|
|
|
/* TODO expand this check to include both the host and target TRIDs.
|
|
|
|
* Only if both are the same should we fail.
|
|
|
|
*/
|
|
|
|
if (nvme_bdev_ctrlr_get(trid) != NULL) {
|
|
|
|
SPDK_ERRLOG("A controller with the provided trid (traddr: %s) already exists.\n", trid->traddr);
|
|
|
|
return -EEXIST;
|
|
|
|
}
|
|
|
|
|
2020-09-24 01:54:00 +00:00
|
|
|
ctx = calloc(1, sizeof(*ctx));
|
|
|
|
if (!ctx) {
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
ctx->base_name = base_name;
|
|
|
|
ctx->names = names;
|
|
|
|
ctx->count = count;
|
|
|
|
ctx->cb_fn = cb_fn;
|
|
|
|
ctx->cb_ctx = cb_ctx;
|
|
|
|
ctx->prchk_flags = prchk_flags;
|
|
|
|
ctx->trid = *trid;
|
|
|
|
|
2019-02-13 05:08:22 +00:00
|
|
|
if (trid->trtype == SPDK_NVME_TRANSPORT_PCIE) {
|
|
|
|
TAILQ_FOREACH_SAFE(entry, &g_skipped_nvme_ctrlrs, tailq, tmp) {
|
|
|
|
if (spdk_nvme_transport_id_compare(trid, &entry->trid) == 0) {
|
|
|
|
TAILQ_REMOVE(&g_skipped_nvme_ctrlrs, entry, tailq);
|
|
|
|
free(entry);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-21 11:53:16 +00:00
|
|
|
if (opts) {
|
|
|
|
memcpy(&ctx->opts, opts, sizeof(*opts));
|
|
|
|
} else {
|
|
|
|
spdk_nvme_ctrlr_get_default_ctrlr_opts(&ctx->opts, sizeof(ctx->opts));
|
|
|
|
}
|
|
|
|
|
2019-08-08 02:30:27 +00:00
|
|
|
ctx->opts.transport_retry_count = g_opts.retry_count;
|
2020-11-27 16:10:36 +00:00
|
|
|
ctx->opts.keep_alive_timeout_ms = g_opts.keep_alive_timeout_ms;
|
2018-12-18 23:09:14 +00:00
|
|
|
|
|
|
|
if (hostnqn) {
|
2019-03-05 07:26:58 +00:00
|
|
|
snprintf(ctx->opts.hostnqn, sizeof(ctx->opts.hostnqn), "%s", hostnqn);
|
2018-12-18 23:09:14 +00:00
|
|
|
}
|
|
|
|
|
2018-12-04 23:30:11 +00:00
|
|
|
if (hostid->hostaddr[0] != '\0') {
|
2019-03-05 07:26:58 +00:00
|
|
|
snprintf(ctx->opts.src_addr, sizeof(ctx->opts.src_addr), "%s", hostid->hostaddr);
|
2018-12-04 23:30:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (hostid->hostsvcid[0] != '\0') {
|
2019-03-05 07:26:58 +00:00
|
|
|
snprintf(ctx->opts.src_svcid, sizeof(ctx->opts.src_svcid), "%s", hostid->hostsvcid);
|
2018-12-04 23:30:11 +00:00
|
|
|
}
|
|
|
|
|
2019-03-05 07:26:58 +00:00
|
|
|
ctx->probe_ctx = spdk_nvme_connect_async(trid, &ctx->opts, connect_attach_cb);
|
|
|
|
if (ctx->probe_ctx == NULL) {
|
|
|
|
SPDK_ERRLOG("No controller was found with provided trid (traddr: %s)\n", trid->traddr);
|
|
|
|
free(ctx);
|
2019-07-15 11:07:12 +00:00
|
|
|
return -ENODEV;
|
2017-05-01 23:54:11 +00:00
|
|
|
}
|
2020-04-14 06:49:46 +00:00
|
|
|
ctx->poller = SPDK_POLLER_REGISTER(bdev_nvme_async_poll, ctx, 1000);
|
2017-05-01 23:54:11 +00:00
|
|
|
|
2019-03-05 07:26:58 +00:00
|
|
|
return 0;
|
2016-10-10 03:54:38 +00:00
|
|
|
}
|
2016-07-20 18:16:23 +00:00
|
|
|
|
2020-11-27 17:38:18 +00:00
|
|
|
int
|
2021-03-03 16:32:54 +00:00
|
|
|
bdev_nvme_delete(const char *name, const struct spdk_nvme_transport_id *trid)
|
2020-11-27 17:38:18 +00:00
|
|
|
{
|
|
|
|
struct nvme_bdev_ctrlr *nvme_bdev_ctrlr;
|
|
|
|
struct nvme_bdev_ctrlr_trid *ctrlr_trid, *tmp_trid;
|
|
|
|
|
|
|
|
if (name == NULL) {
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2021-03-03 16:32:54 +00:00
|
|
|
/* case 1: remove the controller itself. */
|
|
|
|
if (trid == NULL) {
|
|
|
|
return _bdev_nvme_delete(nvme_bdev_ctrlr, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* case 2: we are currently using the path to be removed. */
|
2020-11-27 17:38:18 +00:00
|
|
|
if (!spdk_nvme_transport_id_compare(trid, nvme_bdev_ctrlr->connected_trid)) {
|
|
|
|
ctrlr_trid = TAILQ_FIRST(&nvme_bdev_ctrlr->trids);
|
|
|
|
assert(nvme_bdev_ctrlr->connected_trid == &ctrlr_trid->trid);
|
2021-03-03 16:32:54 +00:00
|
|
|
/* case 2A: the current path is the only path. */
|
2020-11-27 17:38:18 +00:00
|
|
|
if (!TAILQ_NEXT(ctrlr_trid, link)) {
|
2021-03-03 16:32:54 +00:00
|
|
|
return _bdev_nvme_delete(nvme_bdev_ctrlr, false);
|
2020-11-27 17:38:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* case 1B: there is an alternative path. */
|
|
|
|
return bdev_nvme_failover(nvme_bdev_ctrlr, true);
|
|
|
|
}
|
2021-03-03 16:32:54 +00:00
|
|
|
/* case 3: We are not using the specified path. */
|
2020-11-27 17:38:18 +00:00
|
|
|
TAILQ_FOREACH_SAFE(ctrlr_trid, &nvme_bdev_ctrlr->trids, link, tmp_trid) {
|
|
|
|
if (!spdk_nvme_transport_id_compare(&ctrlr_trid->trid, trid)) {
|
|
|
|
TAILQ_REMOVE(&nvme_bdev_ctrlr->trids, ctrlr_trid, link);
|
|
|
|
free(ctrlr_trid);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-03 16:32:54 +00:00
|
|
|
/* case 3A: The address isn't even in the registered list. */
|
2020-11-27 17:38:18 +00:00
|
|
|
return -ENXIO;
|
|
|
|
}
|
|
|
|
|
2017-07-13 17:36:19 +00:00
|
|
|
static int
|
2017-02-28 17:51:25 +00:00
|
|
|
bdev_nvme_library_init(void)
|
2016-07-20 18:16:23 +00:00
|
|
|
{
|
2018-07-12 12:26:19 +00:00
|
|
|
g_bdev_nvme_init_thread = spdk_get_thread();
|
2018-07-09 21:04:33 +00:00
|
|
|
|
2020-04-26 00:38:30 +00:00
|
|
|
spdk_io_device_register(&g_nvme_bdev_ctrlrs, bdev_nvme_poll_group_create_cb,
|
|
|
|
bdev_nvme_poll_group_destroy_cb,
|
2020-02-07 00:20:35 +00:00
|
|
|
sizeof(struct nvme_bdev_poll_group), "bdev_nvme_poll_groups");
|
|
|
|
|
2020-10-14 14:51:18 +00:00
|
|
|
return 0;
|
2016-07-20 18:16:23 +00:00
|
|
|
}
|
|
|
|
|
2016-12-14 06:05:10 +00:00
|
|
|
static void
|
2017-02-28 17:51:25 +00:00
|
|
|
bdev_nvme_library_fini(void)
|
2016-07-20 18:16:23 +00:00
|
|
|
{
|
2019-02-26 09:49:45 +00:00
|
|
|
struct nvme_bdev_ctrlr *nvme_bdev_ctrlr, *tmp;
|
2019-02-13 05:08:22 +00:00
|
|
|
struct nvme_probe_skip_entry *entry, *entry_tmp;
|
2018-11-21 10:45:31 +00:00
|
|
|
|
2018-07-12 12:26:19 +00:00
|
|
|
spdk_poller_unregister(&g_hotplug_poller);
|
2019-03-05 07:32:34 +00:00
|
|
|
free(g_hotplug_probe_ctx);
|
2018-11-21 10:45:31 +00:00
|
|
|
|
2019-02-13 05:08:22 +00:00
|
|
|
TAILQ_FOREACH_SAFE(entry, &g_skipped_nvme_ctrlrs, tailq, entry_tmp) {
|
|
|
|
TAILQ_REMOVE(&g_skipped_nvme_ctrlrs, entry, tailq);
|
|
|
|
free(entry);
|
|
|
|
}
|
|
|
|
|
2018-11-21 10:45:31 +00:00
|
|
|
pthread_mutex_lock(&g_bdev_nvme_mutex);
|
2019-02-26 09:49:45 +00:00
|
|
|
TAILQ_FOREACH_SAFE(nvme_bdev_ctrlr, &g_nvme_bdev_ctrlrs, tailq, tmp) {
|
2021-03-03 17:23:21 +00:00
|
|
|
pthread_mutex_lock(&nvme_bdev_ctrlr->mutex);
|
2019-02-26 09:49:45 +00:00
|
|
|
if (nvme_bdev_ctrlr->destruct) {
|
2018-11-21 10:45:31 +00:00
|
|
|
/* This controller's destruction was already started
|
|
|
|
* before the application started shutting down
|
|
|
|
*/
|
2021-03-03 17:23:21 +00:00
|
|
|
pthread_mutex_unlock(&nvme_bdev_ctrlr->mutex);
|
2018-11-21 10:45:31 +00:00
|
|
|
continue;
|
|
|
|
}
|
2020-10-21 21:10:57 +00:00
|
|
|
nvme_bdev_ctrlr->destruct = true;
|
2021-03-03 17:23:21 +00:00
|
|
|
pthread_mutex_unlock(&nvme_bdev_ctrlr->mutex);
|
2018-11-21 10:45:31 +00:00
|
|
|
|
2020-11-26 06:34:00 +00:00
|
|
|
spdk_thread_send_msg(nvme_bdev_ctrlr->thread, _nvme_bdev_ctrlr_destruct,
|
|
|
|
nvme_bdev_ctrlr);
|
2018-11-21 10:45:31 +00:00
|
|
|
}
|
2020-03-05 10:45:00 +00:00
|
|
|
|
|
|
|
g_bdev_nvme_module_finish = true;
|
|
|
|
if (TAILQ_EMPTY(&g_nvme_bdev_ctrlrs)) {
|
|
|
|
pthread_mutex_unlock(&g_bdev_nvme_mutex);
|
2020-04-26 00:38:30 +00:00
|
|
|
spdk_io_device_unregister(&g_nvme_bdev_ctrlrs, NULL);
|
2020-03-05 10:45:00 +00:00
|
|
|
spdk_bdev_module_finish_done();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-11-21 10:45:31 +00:00
|
|
|
pthread_mutex_unlock(&g_bdev_nvme_mutex);
|
2017-01-25 01:04:14 +00:00
|
|
|
}
|
|
|
|
|
2019-02-05 01:56:15 +00:00
|
|
|
static void
|
|
|
|
bdev_nvme_verify_pi_error(struct spdk_bdev_io *bdev_io)
|
|
|
|
{
|
|
|
|
struct spdk_bdev *bdev = bdev_io->bdev;
|
|
|
|
struct spdk_dif_ctx dif_ctx;
|
|
|
|
struct spdk_dif_error err_blk = {};
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
rc = spdk_dif_ctx_init(&dif_ctx,
|
|
|
|
bdev->blocklen, bdev->md_len, bdev->md_interleave,
|
|
|
|
bdev->dif_is_head_of_md, bdev->dif_type, bdev->dif_check_flags,
|
2019-06-04 05:52:24 +00:00
|
|
|
bdev_io->u.bdev.offset_blocks, 0, 0, 0, 0);
|
2019-02-05 01:56:15 +00:00
|
|
|
if (rc != 0) {
|
|
|
|
SPDK_ERRLOG("Initialization of DIF context failed\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-04-16 08:17:08 +00:00
|
|
|
if (bdev->md_interleave) {
|
|
|
|
rc = spdk_dif_verify(bdev_io->u.bdev.iovs, bdev_io->u.bdev.iovcnt,
|
|
|
|
bdev_io->u.bdev.num_blocks, &dif_ctx, &err_blk);
|
|
|
|
} else {
|
|
|
|
struct iovec md_iov = {
|
|
|
|
.iov_base = bdev_io->u.bdev.md_buf,
|
|
|
|
.iov_len = bdev_io->u.bdev.num_blocks * bdev->md_len,
|
|
|
|
};
|
|
|
|
|
|
|
|
rc = spdk_dix_verify(bdev_io->u.bdev.iovs, bdev_io->u.bdev.iovcnt,
|
|
|
|
&md_iov, bdev_io->u.bdev.num_blocks, &dif_ctx, &err_blk);
|
|
|
|
}
|
|
|
|
|
2019-02-05 01:56:15 +00:00
|
|
|
if (rc != 0) {
|
|
|
|
SPDK_ERRLOG("DIF error detected. type=%d, offset=%" PRIu32 "\n",
|
|
|
|
err_blk.err_type, err_blk.err_offset);
|
|
|
|
} else {
|
|
|
|
SPDK_ERRLOG("Hardware reported PI error but SPDK could not find any.\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-08 05:42:18 +00:00
|
|
|
static void
|
|
|
|
bdev_nvme_no_pi_readv_done(void *ref, const struct spdk_nvme_cpl *cpl)
|
|
|
|
{
|
|
|
|
struct nvme_bdev_io *bio = ref;
|
|
|
|
struct spdk_bdev_io *bdev_io = spdk_bdev_io_from_ctx(bio);
|
|
|
|
|
|
|
|
if (spdk_nvme_cpl_is_success(cpl)) {
|
|
|
|
/* Run PI verification for read data buffer. */
|
|
|
|
bdev_nvme_verify_pi_error(bdev_io);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Return original completion status */
|
2019-10-07 16:08:55 +00:00
|
|
|
spdk_bdev_io_complete_nvme_status(bdev_io, bio->cpl.cdw0, bio->cpl.status.sct,
|
2019-02-08 05:42:18 +00:00
|
|
|
bio->cpl.status.sc);
|
|
|
|
}
|
|
|
|
|
2019-02-05 01:47:25 +00:00
|
|
|
static void
|
|
|
|
bdev_nvme_readv_done(void *ref, const struct spdk_nvme_cpl *cpl)
|
|
|
|
{
|
2019-02-08 05:42:18 +00:00
|
|
|
struct nvme_bdev_io *bio = ref;
|
|
|
|
struct spdk_bdev_io *bdev_io = spdk_bdev_io_from_ctx(bio);
|
2020-09-23 21:09:30 +00:00
|
|
|
struct nvme_bdev *nbdev = (struct nvme_bdev *)bdev_io->bdev->ctxt;
|
2020-09-23 22:10:47 +00:00
|
|
|
struct nvme_io_channel *nvme_ch;
|
2021-02-28 22:07:32 +00:00
|
|
|
struct nvme_bdev_ns *nvme_ns;
|
|
|
|
struct spdk_nvme_qpair *qpair;
|
2019-02-08 05:42:18 +00:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (spdk_unlikely(spdk_nvme_cpl_is_pi_error(cpl))) {
|
|
|
|
SPDK_ERRLOG("readv completed with PI error (sct=%d, sc=%d)\n",
|
|
|
|
cpl->status.sct, cpl->status.sc);
|
|
|
|
|
|
|
|
/* Save completion status to use after verifying PI error. */
|
|
|
|
bio->cpl = *cpl;
|
|
|
|
|
2020-09-23 22:10:47 +00:00
|
|
|
nvme_ch = spdk_io_channel_get_ctx(spdk_bdev_io_get_io_channel(bdev_io));
|
|
|
|
|
2021-02-28 22:07:32 +00:00
|
|
|
if (spdk_likely(bdev_nvme_find_io_path(nbdev, nvme_ch, &nvme_ns, &qpair))) {
|
|
|
|
/* Read without PI checking to verify PI error. */
|
|
|
|
ret = bdev_nvme_no_pi_readv(nvme_ns->ns,
|
|
|
|
qpair,
|
|
|
|
bio,
|
|
|
|
bdev_io->u.bdev.iovs,
|
|
|
|
bdev_io->u.bdev.iovcnt,
|
|
|
|
bdev_io->u.bdev.md_buf,
|
|
|
|
bdev_io->u.bdev.num_blocks,
|
|
|
|
bdev_io->u.bdev.offset_blocks);
|
|
|
|
if (ret == 0) {
|
|
|
|
return;
|
|
|
|
}
|
2019-02-08 05:42:18 +00:00
|
|
|
}
|
|
|
|
}
|
2019-02-05 01:47:25 +00:00
|
|
|
|
2019-10-07 16:08:55 +00:00
|
|
|
spdk_bdev_io_complete_nvme_status(bdev_io, cpl->cdw0, cpl->status.sct, cpl->status.sc);
|
2019-02-05 01:47:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
bdev_nvme_writev_done(void *ref, const struct spdk_nvme_cpl *cpl)
|
|
|
|
{
|
|
|
|
struct spdk_bdev_io *bdev_io = spdk_bdev_io_from_ctx((struct nvme_bdev_io *)ref);
|
|
|
|
|
2019-02-05 01:56:15 +00:00
|
|
|
if (spdk_nvme_cpl_is_pi_error(cpl)) {
|
|
|
|
SPDK_ERRLOG("writev completed with PI error (sct=%d, sc=%d)\n",
|
|
|
|
cpl->status.sct, cpl->status.sc);
|
|
|
|
/* Run PI verification for write data buffer if PI error is detected. */
|
|
|
|
bdev_nvme_verify_pi_error(bdev_io);
|
|
|
|
}
|
|
|
|
|
2019-10-07 16:08:55 +00:00
|
|
|
spdk_bdev_io_complete_nvme_status(bdev_io, cpl->cdw0, cpl->status.sct, cpl->status.sc);
|
2019-02-05 01:47:25 +00:00
|
|
|
}
|
|
|
|
|
2019-12-13 08:40:54 +00:00
|
|
|
static void
|
|
|
|
bdev_nvme_comparev_done(void *ref, const struct spdk_nvme_cpl *cpl)
|
|
|
|
{
|
|
|
|
struct spdk_bdev_io *bdev_io = spdk_bdev_io_from_ctx((struct nvme_bdev_io *)ref);
|
|
|
|
|
|
|
|
if (spdk_nvme_cpl_is_pi_error(cpl)) {
|
|
|
|
SPDK_ERRLOG("comparev completed with PI error (sct=%d, sc=%d)\n",
|
|
|
|
cpl->status.sct, cpl->status.sc);
|
|
|
|
/* Run PI verification for compare data buffer if PI error is detected. */
|
|
|
|
bdev_nvme_verify_pi_error(bdev_io);
|
|
|
|
}
|
|
|
|
|
|
|
|
spdk_bdev_io_complete_nvme_status(bdev_io, cpl->cdw0, cpl->status.sct, cpl->status.sc);
|
|
|
|
}
|
|
|
|
|
2019-12-20 11:29:48 +00:00
|
|
|
static void
|
|
|
|
bdev_nvme_comparev_and_writev_done(void *ref, const struct spdk_nvme_cpl *cpl)
|
|
|
|
{
|
|
|
|
struct nvme_bdev_io *bio = ref;
|
|
|
|
struct spdk_bdev_io *bdev_io = spdk_bdev_io_from_ctx(bio);
|
|
|
|
|
2020-01-17 13:06:24 +00:00
|
|
|
/* Compare operation completion */
|
|
|
|
if ((cpl->cdw0 & 0xFF) == SPDK_NVME_OPC_COMPARE) {
|
|
|
|
/* Save compare result for write callback */
|
|
|
|
bio->cpl = *cpl;
|
|
|
|
return;
|
2019-12-20 11:29:48 +00:00
|
|
|
}
|
|
|
|
|
2020-01-17 13:06:24 +00:00
|
|
|
/* Write operation completion */
|
|
|
|
if (spdk_nvme_cpl_is_error(&bio->cpl)) {
|
|
|
|
/* If bio->cpl is already an error, it means the compare operation failed. In that case,
|
|
|
|
* complete the IO with the compare operation's status.
|
|
|
|
*/
|
|
|
|
if (!spdk_nvme_cpl_is_error(cpl)) {
|
|
|
|
SPDK_ERRLOG("Unexpected write success after compare failure.\n");
|
|
|
|
}
|
2019-12-20 11:29:48 +00:00
|
|
|
|
2020-01-17 13:06:24 +00:00
|
|
|
spdk_bdev_io_complete_nvme_status(bdev_io, bio->cpl.cdw0, bio->cpl.status.sct, bio->cpl.status.sc);
|
|
|
|
} else {
|
|
|
|
spdk_bdev_io_complete_nvme_status(bdev_io, cpl->cdw0, cpl->status.sct, cpl->status.sc);
|
|
|
|
}
|
2019-12-20 11:29:48 +00:00
|
|
|
}
|
|
|
|
|
2016-07-20 18:16:23 +00:00
|
|
|
static void
|
2017-02-28 17:51:25 +00:00
|
|
|
bdev_nvme_queued_done(void *ref, const struct spdk_nvme_cpl *cpl)
|
2016-07-20 18:16:23 +00:00
|
|
|
{
|
2017-02-28 17:51:25 +00:00
|
|
|
struct spdk_bdev_io *bdev_io = spdk_bdev_io_from_ctx((struct nvme_bdev_io *)ref);
|
2016-07-20 18:16:23 +00:00
|
|
|
|
2019-10-07 16:08:55 +00:00
|
|
|
spdk_bdev_io_complete_nvme_status(bdev_io, cpl->cdw0, cpl->status.sct, cpl->status.sc);
|
2016-07-20 18:16:23 +00:00
|
|
|
}
|
|
|
|
|
2017-05-13 20:12:13 +00:00
|
|
|
static void
|
2017-06-15 20:51:31 +00:00
|
|
|
bdev_nvme_admin_passthru_completion(void *ctx)
|
2017-05-13 20:12:13 +00:00
|
|
|
{
|
2017-06-15 20:51:31 +00:00
|
|
|
struct nvme_bdev_io *bio = ctx;
|
|
|
|
struct spdk_bdev_io *bdev_io = spdk_bdev_io_from_ctx(bio);
|
2017-05-13 20:12:13 +00:00
|
|
|
|
|
|
|
spdk_bdev_io_complete_nvme_status(bdev_io,
|
2019-10-07 16:08:55 +00:00
|
|
|
bio->cpl.cdw0, bio->cpl.status.sct, bio->cpl.status.sc);
|
2017-05-13 20:12:13 +00:00
|
|
|
}
|
|
|
|
|
2020-07-08 08:03:49 +00:00
|
|
|
static void
|
|
|
|
bdev_nvme_abort_completion(void *ctx)
|
|
|
|
{
|
|
|
|
struct nvme_bdev_io *bio = ctx;
|
|
|
|
struct spdk_bdev_io *bdev_io = spdk_bdev_io_from_ctx(bio);
|
|
|
|
|
|
|
|
if (spdk_nvme_cpl_is_abort_success(&bio->cpl)) {
|
|
|
|
spdk_bdev_io_complete(bdev_io, SPDK_BDEV_IO_STATUS_SUCCESS);
|
|
|
|
} else {
|
|
|
|
spdk_bdev_io_complete(bdev_io, SPDK_BDEV_IO_STATUS_FAILED);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
bdev_nvme_abort_done(void *ref, const struct spdk_nvme_cpl *cpl)
|
|
|
|
{
|
|
|
|
struct nvme_bdev_io *bio = ref;
|
|
|
|
|
|
|
|
bio->cpl = *cpl;
|
|
|
|
spdk_thread_send_msg(bio->orig_thread, bdev_nvme_abort_completion, bio);
|
|
|
|
}
|
|
|
|
|
2017-05-13 20:12:13 +00:00
|
|
|
static void
|
|
|
|
bdev_nvme_admin_passthru_done(void *ref, const struct spdk_nvme_cpl *cpl)
|
|
|
|
{
|
|
|
|
struct nvme_bdev_io *bio = ref;
|
|
|
|
|
|
|
|
bio->cpl = *cpl;
|
2017-06-15 20:51:31 +00:00
|
|
|
spdk_thread_send_msg(bio->orig_thread, bdev_nvme_admin_passthru_completion, bio);
|
2017-05-13 20:12:13 +00:00
|
|
|
}
|
|
|
|
|
2016-10-04 14:39:27 +00:00
|
|
|
static void
|
2017-02-28 17:51:25 +00:00
|
|
|
bdev_nvme_queued_reset_sgl(void *ref, uint32_t sgl_offset)
|
2016-10-04 14:39:27 +00:00
|
|
|
{
|
2017-02-28 17:51:25 +00:00
|
|
|
struct nvme_bdev_io *bio = ref;
|
2016-10-04 14:39:27 +00:00
|
|
|
struct iovec *iov;
|
|
|
|
|
|
|
|
bio->iov_offset = sgl_offset;
|
|
|
|
for (bio->iovpos = 0; bio->iovpos < bio->iovcnt; bio->iovpos++) {
|
|
|
|
iov = &bio->iovs[bio->iovpos];
|
2017-12-07 23:23:48 +00:00
|
|
|
if (bio->iov_offset < iov->iov_len) {
|
2016-10-04 14:39:27 +00:00
|
|
|
break;
|
2017-12-07 23:23:48 +00:00
|
|
|
}
|
2016-10-04 14:39:27 +00:00
|
|
|
|
|
|
|
bio->iov_offset -= iov->iov_len;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2017-02-28 17:51:25 +00:00
|
|
|
bdev_nvme_queued_next_sge(void *ref, void **address, uint32_t *length)
|
2016-10-04 14:39:27 +00:00
|
|
|
{
|
2017-02-28 17:51:25 +00:00
|
|
|
struct nvme_bdev_io *bio = ref;
|
2016-10-04 14:39:27 +00:00
|
|
|
struct iovec *iov;
|
|
|
|
|
|
|
|
assert(bio->iovpos < bio->iovcnt);
|
|
|
|
|
|
|
|
iov = &bio->iovs[bio->iovpos];
|
|
|
|
|
2016-11-03 17:12:16 +00:00
|
|
|
*address = iov->iov_base;
|
2016-10-04 14:39:27 +00:00
|
|
|
*length = iov->iov_len;
|
|
|
|
|
|
|
|
if (bio->iov_offset) {
|
|
|
|
assert(bio->iov_offset <= iov->iov_len);
|
|
|
|
*address += bio->iov_offset;
|
|
|
|
*length -= bio->iov_offset;
|
2016-11-09 06:00:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bio->iov_offset += *length;
|
|
|
|
if (bio->iov_offset == iov->iov_len) {
|
|
|
|
bio->iovpos++;
|
2016-10-04 14:39:27 +00:00
|
|
|
bio->iov_offset = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-01-16 10:10:53 +00:00
|
|
|
static void
|
|
|
|
bdev_nvme_queued_reset_fused_sgl(void *ref, uint32_t sgl_offset)
|
|
|
|
{
|
|
|
|
struct nvme_bdev_io *bio = ref;
|
|
|
|
struct iovec *iov;
|
|
|
|
|
|
|
|
bio->fused_iov_offset = sgl_offset;
|
|
|
|
for (bio->fused_iovpos = 0; bio->fused_iovpos < bio->fused_iovcnt; bio->fused_iovpos++) {
|
|
|
|
iov = &bio->fused_iovs[bio->fused_iovpos];
|
|
|
|
if (bio->fused_iov_offset < iov->iov_len) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
bio->fused_iov_offset -= iov->iov_len;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
bdev_nvme_queued_next_fused_sge(void *ref, void **address, uint32_t *length)
|
|
|
|
{
|
|
|
|
struct nvme_bdev_io *bio = ref;
|
|
|
|
struct iovec *iov;
|
|
|
|
|
|
|
|
assert(bio->fused_iovpos < bio->fused_iovcnt);
|
|
|
|
|
|
|
|
iov = &bio->fused_iovs[bio->fused_iovpos];
|
|
|
|
|
|
|
|
*address = iov->iov_base;
|
|
|
|
*length = iov->iov_len;
|
|
|
|
|
|
|
|
if (bio->fused_iov_offset) {
|
|
|
|
assert(bio->fused_iov_offset <= iov->iov_len);
|
|
|
|
*address += bio->fused_iov_offset;
|
|
|
|
*length -= bio->fused_iov_offset;
|
|
|
|
}
|
|
|
|
|
|
|
|
bio->fused_iov_offset += *length;
|
|
|
|
if (bio->fused_iov_offset == iov->iov_len) {
|
|
|
|
bio->fused_iovpos++;
|
|
|
|
bio->fused_iov_offset = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-02-08 05:42:18 +00:00
|
|
|
static int
|
2020-11-23 04:48:51 +00:00
|
|
|
bdev_nvme_no_pi_readv(struct spdk_nvme_ns *ns, struct spdk_nvme_qpair *qpair,
|
2019-04-16 08:17:08 +00:00
|
|
|
struct nvme_bdev_io *bio, struct iovec *iov, int iovcnt,
|
|
|
|
void *md, uint64_t lba_count, uint64_t lba)
|
2019-02-08 05:42:18 +00:00
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
|
2020-11-17 16:29:21 +00:00
|
|
|
SPDK_DEBUGLOG(bdev_nvme, "read %" PRIu64 " blocks with offset %#" PRIx64 " without PI check\n",
|
2019-02-08 05:42:18 +00:00
|
|
|
lba_count, lba);
|
|
|
|
|
|
|
|
bio->iovs = iov;
|
|
|
|
bio->iovcnt = iovcnt;
|
|
|
|
bio->iovpos = 0;
|
|
|
|
bio->iov_offset = 0;
|
|
|
|
|
2020-11-23 04:48:51 +00:00
|
|
|
rc = spdk_nvme_ns_cmd_readv_with_md(ns, qpair, lba, lba_count,
|
2019-04-16 08:17:08 +00:00
|
|
|
bdev_nvme_no_pi_readv_done, bio, 0,
|
|
|
|
bdev_nvme_queued_reset_sgl, bdev_nvme_queued_next_sge,
|
|
|
|
md, 0, 0);
|
2019-02-08 05:42:18 +00:00
|
|
|
|
|
|
|
if (rc != 0 && rc != -ENOMEM) {
|
|
|
|
SPDK_ERRLOG("no_pi_readv failed: rc = %d\n", rc);
|
|
|
|
}
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2017-02-28 17:51:25 +00:00
|
|
|
static int
|
2020-11-23 04:48:51 +00:00
|
|
|
bdev_nvme_readv(struct spdk_nvme_ns *ns, struct spdk_nvme_qpair *qpair,
|
2019-04-16 08:17:08 +00:00
|
|
|
struct nvme_bdev_io *bio, struct iovec *iov, int iovcnt,
|
2020-09-23 20:37:27 +00:00
|
|
|
void *md, uint64_t lba_count, uint64_t lba, uint32_t flags)
|
2016-07-20 18:16:23 +00:00
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
|
2020-11-17 16:29:21 +00:00
|
|
|
SPDK_DEBUGLOG(bdev_nvme, "read %" PRIu64 " blocks with offset %#" PRIx64 "\n",
|
2019-02-05 01:47:25 +00:00
|
|
|
lba_count, lba);
|
|
|
|
|
2016-10-04 14:39:27 +00:00
|
|
|
bio->iovs = iov;
|
|
|
|
bio->iovcnt = iovcnt;
|
|
|
|
bio->iovpos = 0;
|
|
|
|
bio->iov_offset = 0;
|
|
|
|
|
2020-09-18 17:31:23 +00:00
|
|
|
if (iovcnt == 1) {
|
2020-11-23 04:48:51 +00:00
|
|
|
rc = spdk_nvme_ns_cmd_read_with_md(ns, qpair, iov[0].iov_base, md, lba,
|
2020-09-18 17:31:23 +00:00
|
|
|
lba_count,
|
|
|
|
bdev_nvme_readv_done, bio,
|
2020-09-23 20:37:27 +00:00
|
|
|
flags,
|
2020-09-18 17:31:23 +00:00
|
|
|
0, 0);
|
|
|
|
} else {
|
2020-11-23 04:48:51 +00:00
|
|
|
rc = spdk_nvme_ns_cmd_readv_with_md(ns, qpair, lba, lba_count,
|
2020-09-23 20:37:27 +00:00
|
|
|
bdev_nvme_readv_done, bio, flags,
|
2020-09-18 17:31:23 +00:00
|
|
|
bdev_nvme_queued_reset_sgl, bdev_nvme_queued_next_sge,
|
|
|
|
md, 0, 0);
|
|
|
|
}
|
2019-02-05 01:47:25 +00:00
|
|
|
|
|
|
|
if (rc != 0 && rc != -ENOMEM) {
|
|
|
|
SPDK_ERRLOG("readv failed: rc = %d\n", rc);
|
2016-07-20 18:16:23 +00:00
|
|
|
}
|
2019-02-05 01:47:25 +00:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2020-11-23 04:48:51 +00:00
|
|
|
bdev_nvme_writev(struct spdk_nvme_ns *ns, struct spdk_nvme_qpair *qpair,
|
2019-02-05 01:47:25 +00:00
|
|
|
struct nvme_bdev_io *bio,
|
2020-09-23 20:37:27 +00:00
|
|
|
struct iovec *iov, int iovcnt, void *md, uint64_t lba_count, uint64_t lba,
|
|
|
|
uint32_t flags)
|
2019-02-05 01:47:25 +00:00
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
|
2020-11-17 16:29:21 +00:00
|
|
|
SPDK_DEBUGLOG(bdev_nvme, "write %" PRIu64 " blocks with offset %#" PRIx64 "\n",
|
2019-02-05 01:47:25 +00:00
|
|
|
lba_count, lba);
|
|
|
|
|
|
|
|
bio->iovs = iov;
|
|
|
|
bio->iovcnt = iovcnt;
|
|
|
|
bio->iovpos = 0;
|
|
|
|
bio->iov_offset = 0;
|
|
|
|
|
2020-09-18 17:46:03 +00:00
|
|
|
if (iovcnt == 1) {
|
2020-11-23 04:48:51 +00:00
|
|
|
rc = spdk_nvme_ns_cmd_write_with_md(ns, qpair, iov[0].iov_base, md, lba,
|
2020-09-18 17:46:03 +00:00
|
|
|
lba_count,
|
2021-01-26 08:17:11 +00:00
|
|
|
bdev_nvme_writev_done, bio,
|
2020-09-23 20:37:27 +00:00
|
|
|
flags,
|
2020-09-18 17:46:03 +00:00
|
|
|
0, 0);
|
|
|
|
} else {
|
2020-11-23 04:48:51 +00:00
|
|
|
rc = spdk_nvme_ns_cmd_writev_with_md(ns, qpair, lba, lba_count,
|
2020-09-23 20:37:27 +00:00
|
|
|
bdev_nvme_writev_done, bio, flags,
|
2020-09-18 17:46:03 +00:00
|
|
|
bdev_nvme_queued_reset_sgl, bdev_nvme_queued_next_sge,
|
|
|
|
md, 0, 0);
|
|
|
|
}
|
2016-07-20 18:16:23 +00:00
|
|
|
|
bdev: add ENOMEM handling
At very high queue depths, bdev modules may not have enough
internal resources to track all of the incoming I/O. For example,
we allocate a finite number of nvme_request objects per allocated
queue pair. Currently if these resources are exhausted, the
bdev module will return failure (with no indication why) which
gets propagated all the way back to the application.
So instead, add SPDK_BDEV_IO_STATUS_NOMEM to allow bdev modules
to indicate this type of failure. Also add handling for this
status type in the generic bdev layer, involving queuing these
I/O for later retry after other I/O on the failing channel have
completed.
This does place an expectation on the bdev module that these
internal resources are allocated per io_channel. Otherwise we
cannot guarantee forward progress solely on reception of
completions. For example, without this guarantee, a bdev
module could theoretically return ENOMEM even if there were
no I/O oustanding for that io_channel. nvme, aio, rbd,
virtio and null drivers comply with this expectation already.
malloc only complies though when not using copy offload.
This patch will fix malloc w/ copy engine to at least
return ENOMEM when no copy descriptors are available. If the
condition above occurs, I/O waiting for resources will get
failed as part of a subsequent reset which matches the
behavior it has today.
Signed-off-by: Jim Harris <james.r.harris@intel.com>
Change-Id: Iea7cd51a611af8abe882794d0b2361fdbb74e84e
Reviewed-on: https://review.gerrithub.io/378853
Tested-by: SPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: Daniel Verkamp <daniel.verkamp@intel.com>
Reviewed-by: Changpeng Liu <changpeng.liu@intel.com>
2017-09-15 20:47:17 +00:00
|
|
|
if (rc != 0 && rc != -ENOMEM) {
|
2019-02-05 01:47:25 +00:00
|
|
|
SPDK_ERRLOG("writev failed: rc = %d\n", rc);
|
2016-07-20 18:16:23 +00:00
|
|
|
}
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2019-12-13 08:40:54 +00:00
|
|
|
static int
|
2020-11-23 04:48:51 +00:00
|
|
|
bdev_nvme_comparev(struct spdk_nvme_ns *ns, struct spdk_nvme_qpair *qpair,
|
2019-12-13 08:40:54 +00:00
|
|
|
struct nvme_bdev_io *bio,
|
2020-09-23 20:37:27 +00:00
|
|
|
struct iovec *iov, int iovcnt, void *md, uint64_t lba_count, uint64_t lba,
|
|
|
|
uint32_t flags)
|
2019-12-13 08:40:54 +00:00
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
|
2020-11-17 16:29:21 +00:00
|
|
|
SPDK_DEBUGLOG(bdev_nvme, "compare %" PRIu64 " blocks with offset %#" PRIx64 "\n",
|
2019-12-13 08:40:54 +00:00
|
|
|
lba_count, lba);
|
|
|
|
|
|
|
|
bio->iovs = iov;
|
|
|
|
bio->iovcnt = iovcnt;
|
|
|
|
bio->iovpos = 0;
|
|
|
|
bio->iov_offset = 0;
|
|
|
|
|
2020-11-23 04:48:51 +00:00
|
|
|
rc = spdk_nvme_ns_cmd_comparev_with_md(ns, qpair, lba, lba_count,
|
2020-09-23 20:37:27 +00:00
|
|
|
bdev_nvme_comparev_done, bio, flags,
|
2019-12-13 08:40:54 +00:00
|
|
|
bdev_nvme_queued_reset_sgl, bdev_nvme_queued_next_sge,
|
|
|
|
md, 0, 0);
|
|
|
|
|
|
|
|
if (rc != 0 && rc != -ENOMEM) {
|
|
|
|
SPDK_ERRLOG("comparev failed: rc = %d\n", rc);
|
|
|
|
}
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2019-12-20 11:29:48 +00:00
|
|
|
static int
|
2020-11-23 04:48:51 +00:00
|
|
|
bdev_nvme_comparev_and_writev(struct spdk_nvme_ns *ns, struct spdk_nvme_qpair *qpair,
|
2020-09-23 20:37:27 +00:00
|
|
|
struct nvme_bdev_io *bio, struct iovec *cmp_iov, int cmp_iovcnt,
|
|
|
|
struct iovec *write_iov, int write_iovcnt,
|
|
|
|
void *md, uint64_t lba_count, uint64_t lba, uint32_t flags)
|
2019-12-20 11:29:48 +00:00
|
|
|
{
|
|
|
|
struct spdk_bdev_io *bdev_io = spdk_bdev_io_from_ctx(bio);
|
|
|
|
int rc;
|
|
|
|
|
2020-11-17 16:29:21 +00:00
|
|
|
SPDK_DEBUGLOG(bdev_nvme, "compare and write %" PRIu64 " blocks with offset %#" PRIx64 "\n",
|
2019-12-20 11:29:48 +00:00
|
|
|
lba_count, lba);
|
|
|
|
|
2020-01-16 10:10:53 +00:00
|
|
|
bio->iovs = cmp_iov;
|
|
|
|
bio->iovcnt = cmp_iovcnt;
|
2019-12-20 11:29:48 +00:00
|
|
|
bio->iovpos = 0;
|
|
|
|
bio->iov_offset = 0;
|
2020-01-16 10:10:53 +00:00
|
|
|
bio->fused_iovs = write_iov;
|
|
|
|
bio->fused_iovcnt = write_iovcnt;
|
|
|
|
bio->fused_iovpos = 0;
|
|
|
|
bio->fused_iov_offset = 0;
|
2019-12-20 11:29:48 +00:00
|
|
|
|
|
|
|
if (bdev_io->num_retries == 0) {
|
|
|
|
bio->first_fused_submitted = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!bio->first_fused_submitted) {
|
|
|
|
flags |= SPDK_NVME_IO_FLAGS_FUSE_FIRST;
|
|
|
|
memset(&bio->cpl, 0, sizeof(bio->cpl));
|
|
|
|
|
2020-11-23 04:48:51 +00:00
|
|
|
rc = spdk_nvme_ns_cmd_comparev_with_md(ns, qpair, lba, lba_count,
|
2019-12-20 11:29:48 +00:00
|
|
|
bdev_nvme_comparev_and_writev_done, bio, flags,
|
|
|
|
bdev_nvme_queued_reset_sgl, bdev_nvme_queued_next_sge, md, 0, 0);
|
|
|
|
if (rc == 0) {
|
|
|
|
bio->first_fused_submitted = true;
|
|
|
|
flags &= ~SPDK_NVME_IO_FLAGS_FUSE_FIRST;
|
|
|
|
} else {
|
|
|
|
if (rc != -ENOMEM) {
|
|
|
|
SPDK_ERRLOG("compare failed: rc = %d\n", rc);
|
|
|
|
}
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
flags |= SPDK_NVME_IO_FLAGS_FUSE_SECOND;
|
|
|
|
|
2020-11-23 04:48:51 +00:00
|
|
|
rc = spdk_nvme_ns_cmd_writev_with_md(ns, qpair, lba, lba_count,
|
2019-12-20 11:29:48 +00:00
|
|
|
bdev_nvme_comparev_and_writev_done, bio, flags,
|
2020-01-16 10:10:53 +00:00
|
|
|
bdev_nvme_queued_reset_fused_sgl, bdev_nvme_queued_next_fused_sge, md, 0, 0);
|
2019-12-20 11:29:48 +00:00
|
|
|
if (rc != 0 && rc != -ENOMEM) {
|
|
|
|
SPDK_ERRLOG("write failed: rc = %d\n", rc);
|
|
|
|
rc = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2016-07-20 18:16:23 +00:00
|
|
|
static int
|
2020-11-23 04:48:51 +00:00
|
|
|
bdev_nvme_unmap(struct spdk_nvme_ns *ns, struct spdk_nvme_qpair *qpair,
|
2017-02-28 17:51:25 +00:00
|
|
|
struct nvme_bdev_io *bio,
|
2017-08-29 00:15:53 +00:00
|
|
|
uint64_t offset_blocks,
|
|
|
|
uint64_t num_blocks)
|
2016-07-20 18:16:23 +00:00
|
|
|
{
|
2017-09-19 17:59:58 +00:00
|
|
|
struct spdk_nvme_dsm_range dsm_ranges[SPDK_NVME_DATASET_MANAGEMENT_MAX_RANGES];
|
|
|
|
struct spdk_nvme_dsm_range *range;
|
|
|
|
uint64_t offset, remaining;
|
|
|
|
uint64_t num_ranges_u64;
|
|
|
|
uint16_t num_ranges;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
num_ranges_u64 = (num_blocks + SPDK_NVME_DATASET_MANAGEMENT_RANGE_MAX_BLOCKS - 1) /
|
|
|
|
SPDK_NVME_DATASET_MANAGEMENT_RANGE_MAX_BLOCKS;
|
|
|
|
if (num_ranges_u64 > SPDK_COUNTOF(dsm_ranges)) {
|
|
|
|
SPDK_ERRLOG("Unmap request for %" PRIu64 " blocks is too large\n", num_blocks);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
num_ranges = (uint16_t)num_ranges_u64;
|
|
|
|
|
|
|
|
offset = offset_blocks;
|
|
|
|
remaining = num_blocks;
|
|
|
|
range = &dsm_ranges[0];
|
|
|
|
|
|
|
|
/* Fill max-size ranges until the remaining blocks fit into one range */
|
|
|
|
while (remaining > SPDK_NVME_DATASET_MANAGEMENT_RANGE_MAX_BLOCKS) {
|
|
|
|
range->attributes.raw = 0;
|
|
|
|
range->length = SPDK_NVME_DATASET_MANAGEMENT_RANGE_MAX_BLOCKS;
|
|
|
|
range->starting_lba = offset;
|
|
|
|
|
|
|
|
offset += SPDK_NVME_DATASET_MANAGEMENT_RANGE_MAX_BLOCKS;
|
|
|
|
remaining -= SPDK_NVME_DATASET_MANAGEMENT_RANGE_MAX_BLOCKS;
|
|
|
|
range++;
|
|
|
|
}
|
2016-10-03 17:37:48 +00:00
|
|
|
|
2017-09-19 17:59:58 +00:00
|
|
|
/* Final range describes the remaining blocks */
|
|
|
|
range->attributes.raw = 0;
|
|
|
|
range->length = remaining;
|
|
|
|
range->starting_lba = offset;
|
2016-07-20 18:16:23 +00:00
|
|
|
|
2020-11-23 04:48:51 +00:00
|
|
|
rc = spdk_nvme_ns_cmd_dataset_management(ns, qpair,
|
2016-10-03 17:37:48 +00:00
|
|
|
SPDK_NVME_DSM_ATTR_DEALLOCATE,
|
2017-09-19 17:59:58 +00:00
|
|
|
dsm_ranges, num_ranges,
|
2017-02-28 17:51:25 +00:00
|
|
|
bdev_nvme_queued_done, bio);
|
2016-07-20 18:16:23 +00:00
|
|
|
|
2017-05-20 00:12:39 +00:00
|
|
|
return rc;
|
2016-07-20 18:16:23 +00:00
|
|
|
}
|
|
|
|
|
2017-05-13 20:12:13 +00:00
|
|
|
static int
|
2020-11-23 06:43:41 +00:00
|
|
|
bdev_nvme_admin_passthru(struct nvme_io_channel *nvme_ch, struct nvme_bdev_io *bio,
|
2017-05-13 20:12:13 +00:00
|
|
|
struct spdk_nvme_cmd *cmd, void *buf, size_t nbytes)
|
|
|
|
{
|
2020-11-23 06:43:41 +00:00
|
|
|
uint32_t max_xfer_size = spdk_nvme_ctrlr_get_max_xfer_size(nvme_ch->ctrlr->ctrlr);
|
2018-05-08 23:07:30 +00:00
|
|
|
|
|
|
|
if (nbytes > max_xfer_size) {
|
|
|
|
SPDK_ERRLOG("nbytes is greater than MDTS %" PRIu32 ".\n", max_xfer_size);
|
2017-05-13 20:12:13 +00:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2020-09-23 22:10:47 +00:00
|
|
|
bio->orig_thread = spdk_io_channel_get_thread(spdk_io_channel_from_ctx(nvme_ch));
|
2017-05-13 20:12:13 +00:00
|
|
|
|
2020-11-23 06:43:41 +00:00
|
|
|
return spdk_nvme_ctrlr_cmd_admin_raw(nvme_ch->ctrlr->ctrlr, cmd, buf,
|
2017-05-13 20:12:13 +00:00
|
|
|
(uint32_t)nbytes, bdev_nvme_admin_passthru_done, bio);
|
|
|
|
}
|
|
|
|
|
2017-06-05 18:02:09 +00:00
|
|
|
static int
|
2020-11-23 04:48:51 +00:00
|
|
|
bdev_nvme_io_passthru(struct spdk_nvme_ns *ns, struct spdk_nvme_qpair *qpair,
|
2017-06-05 18:02:09 +00:00
|
|
|
struct nvme_bdev_io *bio,
|
|
|
|
struct spdk_nvme_cmd *cmd, void *buf, size_t nbytes)
|
|
|
|
{
|
2020-11-23 04:48:51 +00:00
|
|
|
uint32_t max_xfer_size = spdk_nvme_ns_get_max_io_xfer_size(ns);
|
|
|
|
struct spdk_nvme_ctrlr *ctrlr = spdk_nvme_ns_get_ctrlr(ns);
|
2017-06-05 18:02:09 +00:00
|
|
|
|
2018-05-08 23:07:30 +00:00
|
|
|
if (nbytes > max_xfer_size) {
|
|
|
|
SPDK_ERRLOG("nbytes is greater than MDTS %" PRIu32 ".\n", max_xfer_size);
|
2017-06-05 18:02:09 +00:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Each NVMe bdev is a specific namespace, and all NVMe I/O commands require a nsid,
|
|
|
|
* so fill it out automatically.
|
|
|
|
*/
|
2020-11-23 04:48:51 +00:00
|
|
|
cmd->nsid = spdk_nvme_ns_get_id(ns);
|
2017-06-05 18:02:09 +00:00
|
|
|
|
2020-11-23 04:48:51 +00:00
|
|
|
return spdk_nvme_ctrlr_cmd_io_raw(ctrlr, qpair, cmd, buf,
|
2017-06-05 18:02:09 +00:00
|
|
|
(uint32_t)nbytes, bdev_nvme_queued_done, bio);
|
|
|
|
}
|
|
|
|
|
2017-11-14 06:33:11 +00:00
|
|
|
static int
|
2020-11-23 04:48:51 +00:00
|
|
|
bdev_nvme_io_passthru_md(struct spdk_nvme_ns *ns, struct spdk_nvme_qpair *qpair,
|
2017-11-14 06:33:11 +00:00
|
|
|
struct nvme_bdev_io *bio,
|
|
|
|
struct spdk_nvme_cmd *cmd, void *buf, size_t nbytes, void *md_buf, size_t md_len)
|
|
|
|
{
|
2020-11-23 04:48:51 +00:00
|
|
|
size_t nr_sectors = nbytes / spdk_nvme_ns_get_extended_sector_size(ns);
|
|
|
|
uint32_t max_xfer_size = spdk_nvme_ns_get_max_io_xfer_size(ns);
|
|
|
|
struct spdk_nvme_ctrlr *ctrlr = spdk_nvme_ns_get_ctrlr(ns);
|
2017-11-14 06:33:11 +00:00
|
|
|
|
2018-05-08 23:07:30 +00:00
|
|
|
if (nbytes > max_xfer_size) {
|
|
|
|
SPDK_ERRLOG("nbytes is greater than MDTS %" PRIu32 ".\n", max_xfer_size);
|
2017-11-14 06:33:11 +00:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2020-11-23 04:48:51 +00:00
|
|
|
if (md_len != nr_sectors * spdk_nvme_ns_get_md_size(ns)) {
|
2017-11-14 06:33:11 +00:00
|
|
|
SPDK_ERRLOG("invalid meta data buffer size\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Each NVMe bdev is a specific namespace, and all NVMe I/O commands require a nsid,
|
|
|
|
* so fill it out automatically.
|
|
|
|
*/
|
2020-11-23 04:48:51 +00:00
|
|
|
cmd->nsid = spdk_nvme_ns_get_id(ns);
|
2017-11-14 06:33:11 +00:00
|
|
|
|
2020-11-23 04:48:51 +00:00
|
|
|
return spdk_nvme_ctrlr_cmd_io_raw_with_md(ctrlr, qpair, cmd, buf,
|
2017-11-14 06:33:11 +00:00
|
|
|
(uint32_t)nbytes, md_buf, bdev_nvme_queued_done, bio);
|
|
|
|
}
|
|
|
|
|
2020-07-08 08:03:49 +00:00
|
|
|
static void
|
|
|
|
bdev_nvme_abort_admin_cmd(void *ctx)
|
|
|
|
{
|
|
|
|
struct nvme_bdev_io *bio = ctx;
|
|
|
|
struct spdk_bdev_io *bdev_io = spdk_bdev_io_from_ctx(bio);
|
2020-11-23 06:43:41 +00:00
|
|
|
struct nvme_io_channel *nvme_ch;
|
2020-07-08 08:03:49 +00:00
|
|
|
struct nvme_bdev_io *bio_to_abort;
|
|
|
|
int rc;
|
|
|
|
|
2020-11-23 06:43:41 +00:00
|
|
|
nvme_ch = spdk_io_channel_get_ctx(spdk_bdev_io_get_io_channel(bdev_io));
|
2020-07-08 08:03:49 +00:00
|
|
|
bio_to_abort = (struct nvme_bdev_io *)bdev_io->u.abort.bio_to_abort->driver_ctx;
|
|
|
|
|
2020-11-23 06:43:41 +00:00
|
|
|
rc = spdk_nvme_ctrlr_cmd_abort_ext(nvme_ch->ctrlr->ctrlr,
|
2020-07-08 08:03:49 +00:00
|
|
|
NULL,
|
|
|
|
bio_to_abort,
|
|
|
|
bdev_nvme_abort_done, bio);
|
|
|
|
if (rc == -ENOENT) {
|
|
|
|
/* If no admin command was found in admin qpair, complete the abort
|
|
|
|
* request with failure.
|
|
|
|
*/
|
|
|
|
bio->cpl.cdw0 |= 1U;
|
|
|
|
bio->cpl.status.sc = SPDK_NVME_SC_SUCCESS;
|
|
|
|
bio->cpl.status.sct = SPDK_NVME_SCT_GENERIC;
|
|
|
|
|
|
|
|
spdk_thread_send_msg(bio->orig_thread, bdev_nvme_abort_completion, bio);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2020-11-23 06:43:41 +00:00
|
|
|
bdev_nvme_abort(struct nvme_io_channel *nvme_ch, struct nvme_bdev_io *bio,
|
|
|
|
struct nvme_bdev_io *bio_to_abort)
|
2020-07-08 08:03:49 +00:00
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
|
2020-09-23 22:10:47 +00:00
|
|
|
bio->orig_thread = spdk_io_channel_get_thread(spdk_io_channel_from_ctx(nvme_ch));
|
2020-07-08 08:03:49 +00:00
|
|
|
|
2020-11-23 06:43:41 +00:00
|
|
|
rc = spdk_nvme_ctrlr_cmd_abort_ext(nvme_ch->ctrlr->ctrlr,
|
2020-07-08 08:03:49 +00:00
|
|
|
nvme_ch->qpair,
|
|
|
|
bio_to_abort,
|
|
|
|
bdev_nvme_abort_done, bio);
|
|
|
|
if (rc == -ENOENT) {
|
|
|
|
/* If no command was found in I/O qpair, the target command may be
|
|
|
|
* admin command. Only a single thread tries aborting admin command
|
|
|
|
* to clean I/O flow.
|
|
|
|
*/
|
2020-11-23 06:43:41 +00:00
|
|
|
spdk_thread_send_msg(nvme_ch->ctrlr->thread,
|
2020-07-08 08:03:49 +00:00
|
|
|
bdev_nvme_abort_admin_cmd, bio);
|
|
|
|
rc = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2019-12-10 09:27:02 +00:00
|
|
|
static void
|
2020-11-25 14:52:16 +00:00
|
|
|
nvme_ctrlr_config_json_standard_namespace(struct spdk_json_write_ctx *w,
|
|
|
|
struct nvme_bdev_ns *nvme_ns)
|
2019-12-10 09:27:02 +00:00
|
|
|
{
|
|
|
|
/* nop */
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2020-11-25 14:52:16 +00:00
|
|
|
nvme_namespace_config_json(struct spdk_json_write_ctx *w, struct nvme_bdev_ns *nvme_ns)
|
2019-12-10 09:27:02 +00:00
|
|
|
{
|
2020-11-25 14:52:16 +00:00
|
|
|
g_config_json_namespace_fn[nvme_ns->type](w, nvme_ns);
|
2019-12-10 09:27:02 +00:00
|
|
|
}
|
|
|
|
|
2020-12-07 18:46:51 +00:00
|
|
|
static void
|
|
|
|
bdev_nvme_opts_config_json(struct spdk_json_write_ctx *w)
|
2018-04-05 15:43:55 +00:00
|
|
|
{
|
2020-12-07 18:46:51 +00:00
|
|
|
const char *action;
|
2018-07-09 21:04:33 +00:00
|
|
|
|
|
|
|
if (g_opts.action_on_timeout == SPDK_BDEV_NVME_TIMEOUT_ACTION_RESET) {
|
|
|
|
action = "reset";
|
|
|
|
} else if (g_opts.action_on_timeout == SPDK_BDEV_NVME_TIMEOUT_ACTION_ABORT) {
|
|
|
|
action = "abort";
|
|
|
|
} else {
|
|
|
|
action = "none";
|
|
|
|
}
|
|
|
|
|
|
|
|
spdk_json_write_object_begin(w);
|
|
|
|
|
2019-08-22 12:44:02 +00:00
|
|
|
spdk_json_write_named_string(w, "method", "bdev_nvme_set_options");
|
2018-07-09 21:04:33 +00:00
|
|
|
|
|
|
|
spdk_json_write_named_object_begin(w, "params");
|
|
|
|
spdk_json_write_named_string(w, "action_on_timeout", action);
|
|
|
|
spdk_json_write_named_uint64(w, "timeout_us", g_opts.timeout_us);
|
2020-12-09 21:44:31 +00:00
|
|
|
spdk_json_write_named_uint32(w, "keep_alive_timeout_ms", g_opts.keep_alive_timeout_ms);
|
2018-07-09 21:04:33 +00:00
|
|
|
spdk_json_write_named_uint32(w, "retry_count", g_opts.retry_count);
|
2019-09-03 03:48:49 +00:00
|
|
|
spdk_json_write_named_uint32(w, "arbitration_burst", g_opts.arbitration_burst);
|
|
|
|
spdk_json_write_named_uint32(w, "low_priority_weight", g_opts.low_priority_weight);
|
|
|
|
spdk_json_write_named_uint32(w, "medium_priority_weight", g_opts.medium_priority_weight);
|
|
|
|
spdk_json_write_named_uint32(w, "high_priority_weight", g_opts.high_priority_weight);
|
2018-07-09 21:04:33 +00:00
|
|
|
spdk_json_write_named_uint64(w, "nvme_adminq_poll_period_us", g_opts.nvme_adminq_poll_period_us);
|
2019-03-11 22:26:53 +00:00
|
|
|
spdk_json_write_named_uint64(w, "nvme_ioq_poll_period_us", g_opts.nvme_ioq_poll_period_us);
|
2019-07-10 05:13:31 +00:00
|
|
|
spdk_json_write_named_uint32(w, "io_queue_requests", g_opts.io_queue_requests);
|
2019-11-18 17:11:39 +00:00
|
|
|
spdk_json_write_named_bool(w, "delay_cmd_submit", g_opts.delay_cmd_submit);
|
2018-07-09 21:04:33 +00:00
|
|
|
spdk_json_write_object_end(w);
|
|
|
|
|
|
|
|
spdk_json_write_object_end(w);
|
2020-12-07 18:46:51 +00:00
|
|
|
}
|
2018-04-05 15:43:55 +00:00
|
|
|
|
2020-12-07 18:46:51 +00:00
|
|
|
static void
|
|
|
|
nvme_bdev_ctrlr_config_json(struct spdk_json_write_ctx *w,
|
|
|
|
struct nvme_bdev_ctrlr *nvme_bdev_ctrlr)
|
|
|
|
{
|
|
|
|
struct spdk_nvme_transport_id *trid;
|
2018-04-05 15:43:55 +00:00
|
|
|
|
2020-12-07 18:46:51 +00:00
|
|
|
trid = nvme_bdev_ctrlr->connected_trid;
|
2018-04-05 15:43:55 +00:00
|
|
|
|
2020-12-07 18:46:51 +00:00
|
|
|
spdk_json_write_object_begin(w);
|
2018-04-05 15:43:55 +00:00
|
|
|
|
2020-12-07 18:46:51 +00:00
|
|
|
spdk_json_write_named_string(w, "method", "bdev_nvme_attach_controller");
|
2018-04-05 15:43:55 +00:00
|
|
|
|
2020-12-07 18:46:51 +00:00
|
|
|
spdk_json_write_named_object_begin(w, "params");
|
|
|
|
spdk_json_write_named_string(w, "name", nvme_bdev_ctrlr->name);
|
|
|
|
nvme_bdev_dump_trid_json(trid, w);
|
|
|
|
spdk_json_write_named_bool(w, "prchk_reftag",
|
|
|
|
(nvme_bdev_ctrlr->prchk_flags & SPDK_NVME_IO_FLAGS_PRCHK_REFTAG) != 0);
|
|
|
|
spdk_json_write_named_bool(w, "prchk_guard",
|
|
|
|
(nvme_bdev_ctrlr->prchk_flags & SPDK_NVME_IO_FLAGS_PRCHK_GUARD) != 0);
|
2018-04-05 15:43:55 +00:00
|
|
|
|
2020-12-07 18:46:51 +00:00
|
|
|
spdk_json_write_object_end(w);
|
|
|
|
|
|
|
|
spdk_json_write_object_end(w);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
bdev_nvme_hotplug_config_json(struct spdk_json_write_ctx *w)
|
|
|
|
{
|
|
|
|
spdk_json_write_object_begin(w);
|
|
|
|
spdk_json_write_named_string(w, "method", "bdev_nvme_set_hotplug");
|
|
|
|
|
|
|
|
spdk_json_write_named_object_begin(w, "params");
|
|
|
|
spdk_json_write_named_uint64(w, "period_us", g_nvme_hotplug_poll_period_us);
|
|
|
|
spdk_json_write_named_bool(w, "enable", g_nvme_hotplug_enabled);
|
|
|
|
spdk_json_write_object_end(w);
|
|
|
|
|
|
|
|
spdk_json_write_object_end(w);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
bdev_nvme_config_json(struct spdk_json_write_ctx *w)
|
|
|
|
{
|
|
|
|
struct nvme_bdev_ctrlr *nvme_bdev_ctrlr;
|
|
|
|
uint32_t nsid;
|
|
|
|
|
|
|
|
bdev_nvme_opts_config_json(w);
|
|
|
|
|
|
|
|
pthread_mutex_lock(&g_bdev_nvme_mutex);
|
|
|
|
|
|
|
|
TAILQ_FOREACH(nvme_bdev_ctrlr, &g_nvme_bdev_ctrlrs, tailq) {
|
|
|
|
nvme_bdev_ctrlr_config_json(w, nvme_bdev_ctrlr);
|
2019-12-10 09:27:02 +00:00
|
|
|
|
|
|
|
for (nsid = 0; nsid < nvme_bdev_ctrlr->num_ns; ++nsid) {
|
|
|
|
if (!nvme_bdev_ctrlr->namespaces[nsid]->populated) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
nvme_namespace_config_json(w, nvme_bdev_ctrlr->namespaces[nsid]);
|
|
|
|
}
|
2018-04-05 15:43:55 +00:00
|
|
|
}
|
|
|
|
|
2018-07-12 12:26:19 +00:00
|
|
|
/* Dump as last parameter to give all NVMe bdevs chance to be constructed
|
|
|
|
* before enabling hotplug poller.
|
|
|
|
*/
|
2020-12-07 18:46:51 +00:00
|
|
|
bdev_nvme_hotplug_config_json(w);
|
2018-07-12 12:26:19 +00:00
|
|
|
|
2018-04-05 15:43:55 +00:00
|
|
|
pthread_mutex_unlock(&g_bdev_nvme_mutex);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-07-11 23:32:32 +00:00
|
|
|
struct spdk_nvme_ctrlr *
|
2020-05-10 07:46:07 +00:00
|
|
|
bdev_nvme_get_ctrlr(struct spdk_bdev *bdev)
|
2017-07-11 23:32:32 +00:00
|
|
|
{
|
2018-03-06 18:52:46 +00:00
|
|
|
if (!bdev || bdev->module != &nvme_if) {
|
2017-07-11 23:32:32 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2020-09-16 01:08:54 +00:00
|
|
|
return SPDK_CONTAINEROF(bdev, struct nvme_bdev, disk)->nvme_ns->ctrlr->ctrlr;
|
2017-07-11 23:32:32 +00:00
|
|
|
}
|
|
|
|
|
2020-09-04 11:27:29 +00:00
|
|
|
SPDK_LOG_REGISTER_COMPONENT(bdev_nvme)
|