2016-06-06 21:44:30 +00:00
|
|
|
/*-
|
|
|
|
* BSD LICENSE
|
|
|
|
*
|
|
|
|
* Copyright (c) Intel Corporation.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
*
|
|
|
|
* * Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* * Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in
|
|
|
|
* the documentation and/or other materials provided with the
|
|
|
|
* distribution.
|
|
|
|
* * Neither the name of Intel Corporation nor the names of its
|
|
|
|
* contributors may be used to endorse or promote products derived
|
|
|
|
* from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2017-05-02 18:18:25 +00:00
|
|
|
#include "spdk/stdinc.h"
|
2016-06-06 21:44:30 +00:00
|
|
|
|
2017-11-20 16:50:10 +00:00
|
|
|
#include "spdk/bdev.h"
|
2018-06-14 17:27:37 +00:00
|
|
|
#include "spdk/bit_array.h"
|
2016-06-06 21:44:30 +00:00
|
|
|
#include "spdk/conf.h"
|
2018-06-11 20:32:15 +00:00
|
|
|
#include "spdk/thread.h"
|
2016-09-19 17:01:52 +00:00
|
|
|
#include "spdk/nvmf.h"
|
|
|
|
#include "spdk/trace.h"
|
2018-05-07 18:26:13 +00:00
|
|
|
#include "spdk/endian.h"
|
|
|
|
#include "spdk/string.h"
|
2016-09-19 17:01:52 +00:00
|
|
|
|
2016-11-07 22:10:28 +00:00
|
|
|
#include "spdk_internal/log.h"
|
|
|
|
|
2017-08-29 20:22:37 +00:00
|
|
|
#include "nvmf_internal.h"
|
2016-07-14 22:25:23 +00:00
|
|
|
#include "transport.h"
|
2016-06-06 21:44:30 +00:00
|
|
|
|
2017-08-30 18:06:33 +00:00
|
|
|
SPDK_LOG_REGISTER_COMPONENT("nvmf", SPDK_LOG_NVMF)
|
2016-06-06 21:44:30 +00:00
|
|
|
|
2017-08-17 20:39:27 +00:00
|
|
|
#define SPDK_NVMF_DEFAULT_MAX_QUEUE_DEPTH 128
|
|
|
|
#define SPDK_NVMF_DEFAULT_MAX_QPAIRS_PER_CTRLR 64
|
|
|
|
#define SPDK_NVMF_DEFAULT_IN_CAPSULE_DATA_SIZE 4096
|
|
|
|
#define SPDK_NVMF_DEFAULT_MAX_IO_SIZE 131072
|
2018-05-08 23:05:28 +00:00
|
|
|
#define SPDK_NVMF_DEFAULT_MAX_SUBSYSTEMS 1024
|
2018-05-02 14:01:41 +00:00
|
|
|
#define SPDK_NVMF_DEFAULT_IO_UNIT_SIZE 131072
|
2017-08-17 20:39:27 +00:00
|
|
|
|
2018-06-29 20:15:15 +00:00
|
|
|
typedef void (*nvmf_qpair_disconnect_cpl)(void *ctx, int status);
|
|
|
|
|
|
|
|
/* supplied to a single call to nvmf_qpair_disconnect */
|
2018-06-29 19:09:47 +00:00
|
|
|
struct nvmf_qpair_disconnect_ctx {
|
|
|
|
struct spdk_nvmf_qpair *qpair;
|
|
|
|
struct spdk_nvmf_ctrlr *ctrlr;
|
|
|
|
nvmf_qpair_disconnect_cb cb_fn;
|
2018-07-19 22:50:34 +00:00
|
|
|
struct spdk_thread *thread;
|
2018-06-29 19:09:47 +00:00
|
|
|
void *ctx;
|
2018-07-31 03:55:40 +00:00
|
|
|
uint16_t qid;
|
2018-06-29 19:09:47 +00:00
|
|
|
};
|
|
|
|
|
2018-06-29 20:15:15 +00:00
|
|
|
/*
|
|
|
|
* There are several times when we need to iterate through the list of all qpairs and selectively delete them.
|
|
|
|
* In order to do this sequentially without overlap, we must provide a context to recover the next qpair from
|
|
|
|
* to enable calling nvmf_qpair_disconnect on the next desired qpair.
|
|
|
|
*/
|
|
|
|
struct nvmf_qpair_disconnect_many_ctx {
|
|
|
|
struct spdk_nvmf_subsystem *subsystem;
|
|
|
|
struct spdk_nvmf_poll_group *group;
|
2018-07-13 23:23:23 +00:00
|
|
|
spdk_nvmf_poll_group_mod_done cpl_fn;
|
|
|
|
void *cpl_ctx;
|
2018-06-29 20:15:15 +00:00
|
|
|
};
|
|
|
|
|
2018-08-24 17:16:23 +00:00
|
|
|
static void
|
|
|
|
spdk_nvmf_qpair_set_state(struct spdk_nvmf_qpair *qpair,
|
|
|
|
enum spdk_nvmf_qpair_state state)
|
|
|
|
{
|
|
|
|
assert(qpair != NULL);
|
|
|
|
assert(qpair->group->thread == spdk_get_thread());
|
|
|
|
|
|
|
|
qpair->state = state;
|
|
|
|
}
|
|
|
|
|
2017-08-17 20:39:27 +00:00
|
|
|
void
|
|
|
|
spdk_nvmf_tgt_opts_init(struct spdk_nvmf_tgt_opts *opts)
|
|
|
|
{
|
|
|
|
opts->max_queue_depth = SPDK_NVMF_DEFAULT_MAX_QUEUE_DEPTH;
|
|
|
|
opts->max_qpairs_per_ctrlr = SPDK_NVMF_DEFAULT_MAX_QPAIRS_PER_CTRLR;
|
|
|
|
opts->in_capsule_data_size = SPDK_NVMF_DEFAULT_IN_CAPSULE_DATA_SIZE;
|
|
|
|
opts->max_io_size = SPDK_NVMF_DEFAULT_MAX_IO_SIZE;
|
2018-05-08 23:05:28 +00:00
|
|
|
opts->max_subsystems = SPDK_NVMF_DEFAULT_MAX_SUBSYSTEMS;
|
2018-05-02 14:01:41 +00:00
|
|
|
opts->io_unit_size = SPDK_NVMF_DEFAULT_IO_UNIT_SIZE;
|
2017-08-17 20:39:27 +00:00
|
|
|
}
|
|
|
|
|
2018-03-13 00:16:47 +00:00
|
|
|
static int
|
2017-11-17 17:01:39 +00:00
|
|
|
spdk_nvmf_poll_group_poll(void *ctx)
|
|
|
|
{
|
|
|
|
struct spdk_nvmf_poll_group *group = ctx;
|
|
|
|
int rc;
|
2018-03-13 00:16:47 +00:00
|
|
|
int count = 0;
|
2017-11-17 17:01:39 +00:00
|
|
|
struct spdk_nvmf_transport_poll_group *tgroup;
|
|
|
|
|
|
|
|
TAILQ_FOREACH(tgroup, &group->tgroups, link) {
|
|
|
|
rc = spdk_nvmf_transport_poll_group_poll(tgroup);
|
|
|
|
if (rc < 0) {
|
2018-03-13 00:16:47 +00:00
|
|
|
return -1;
|
2017-11-17 17:01:39 +00:00
|
|
|
}
|
2018-03-13 00:16:47 +00:00
|
|
|
count += rc;
|
2017-11-17 17:01:39 +00:00
|
|
|
}
|
2018-03-13 00:16:47 +00:00
|
|
|
|
|
|
|
return count;
|
2017-11-17 17:01:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
spdk_nvmf_tgt_create_poll_group(void *io_device, void *ctx_buf)
|
|
|
|
{
|
|
|
|
struct spdk_nvmf_tgt *tgt = io_device;
|
|
|
|
struct spdk_nvmf_poll_group *group = ctx_buf;
|
|
|
|
struct spdk_nvmf_transport *transport;
|
2017-11-20 16:50:10 +00:00
|
|
|
uint32_t sid;
|
2017-11-17 17:01:39 +00:00
|
|
|
|
|
|
|
TAILQ_INIT(&group->tgroups);
|
2018-06-01 22:10:12 +00:00
|
|
|
TAILQ_INIT(&group->qpairs);
|
2017-11-17 17:01:39 +00:00
|
|
|
|
|
|
|
TAILQ_FOREACH(transport, &tgt->transports, link) {
|
|
|
|
spdk_nvmf_poll_group_add_transport(group, transport);
|
|
|
|
}
|
|
|
|
|
2018-05-08 23:05:28 +00:00
|
|
|
group->num_sgroups = tgt->opts.max_subsystems;
|
|
|
|
group->sgroups = calloc(tgt->opts.max_subsystems, sizeof(struct spdk_nvmf_subsystem_poll_group));
|
2017-11-20 16:50:10 +00:00
|
|
|
if (!group->sgroups) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2018-05-08 23:05:28 +00:00
|
|
|
for (sid = 0; sid < tgt->opts.max_subsystems; sid++) {
|
2017-11-20 16:50:10 +00:00
|
|
|
struct spdk_nvmf_subsystem *subsystem;
|
|
|
|
|
|
|
|
subsystem = tgt->subsystems[sid];
|
|
|
|
if (!subsystem) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2018-07-13 23:23:23 +00:00
|
|
|
spdk_nvmf_poll_group_add_subsystem(group, subsystem, NULL, NULL);
|
2017-11-20 16:50:10 +00:00
|
|
|
}
|
|
|
|
|
2017-11-17 17:01:39 +00:00
|
|
|
group->poller = spdk_poller_register(spdk_nvmf_poll_group_poll, group, 0);
|
2018-02-08 03:54:59 +00:00
|
|
|
group->thread = spdk_get_thread();
|
2017-11-17 17:01:39 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2018-07-23 22:40:02 +00:00
|
|
|
spdk_nvmf_tgt_destroy_poll_group(void *io_device, void *ctx_buf)
|
2017-11-17 17:01:39 +00:00
|
|
|
{
|
2018-07-23 22:40:02 +00:00
|
|
|
struct spdk_nvmf_poll_group *group = ctx_buf;
|
2017-11-17 17:01:39 +00:00
|
|
|
struct spdk_nvmf_transport_poll_group *tgroup, *tmp;
|
2017-11-20 16:50:10 +00:00
|
|
|
struct spdk_nvmf_subsystem_poll_group *sgroup;
|
|
|
|
uint32_t sid, nsid;
|
2017-11-17 17:01:39 +00:00
|
|
|
|
|
|
|
TAILQ_FOREACH_SAFE(tgroup, &group->tgroups, link, tmp) {
|
|
|
|
TAILQ_REMOVE(&group->tgroups, tgroup, link);
|
|
|
|
spdk_nvmf_transport_poll_group_destroy(tgroup);
|
|
|
|
}
|
2017-11-20 16:50:10 +00:00
|
|
|
|
|
|
|
for (sid = 0; sid < group->num_sgroups; sid++) {
|
|
|
|
sgroup = &group->sgroups[sid];
|
|
|
|
|
|
|
|
for (nsid = 0; nsid < sgroup->num_channels; nsid++) {
|
|
|
|
if (sgroup->channels[nsid]) {
|
|
|
|
spdk_put_io_channel(sgroup->channels[nsid]);
|
|
|
|
sgroup->channels[nsid] = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
free(sgroup->channels);
|
|
|
|
}
|
|
|
|
|
|
|
|
free(group->sgroups);
|
2017-11-17 17:01:39 +00:00
|
|
|
}
|
|
|
|
|
2018-06-29 23:19:45 +00:00
|
|
|
static void
|
|
|
|
_nvmf_tgt_disconnect_next_qpair(void *ctx)
|
|
|
|
{
|
|
|
|
struct spdk_nvmf_qpair *qpair;
|
|
|
|
struct nvmf_qpair_disconnect_many_ctx *qpair_ctx = ctx;
|
|
|
|
struct spdk_nvmf_poll_group *group = qpair_ctx->group;
|
2018-07-23 22:40:02 +00:00
|
|
|
struct spdk_io_channel *ch;
|
2018-06-29 23:19:45 +00:00
|
|
|
int rc = 0;
|
|
|
|
|
|
|
|
qpair = TAILQ_FIRST(&group->qpairs);
|
|
|
|
|
|
|
|
if (qpair) {
|
|
|
|
rc = spdk_nvmf_qpair_disconnect(qpair, _nvmf_tgt_disconnect_next_qpair, ctx);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!qpair || rc != 0) {
|
2018-07-23 22:40:02 +00:00
|
|
|
/* When the refcount from the channels reaches 0, spdk_nvmf_tgt_destroy_poll_group will be called. */
|
|
|
|
ch = spdk_io_channel_from_ctx(group);
|
|
|
|
spdk_put_io_channel(ch);
|
2018-06-29 23:19:45 +00:00
|
|
|
free(qpair_ctx);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2018-07-23 22:40:02 +00:00
|
|
|
spdk_nvmf_tgt_destroy_poll_group_qpairs(struct spdk_nvmf_poll_group *group)
|
2018-06-29 23:19:45 +00:00
|
|
|
{
|
|
|
|
struct nvmf_qpair_disconnect_many_ctx *ctx;
|
|
|
|
|
|
|
|
ctx = calloc(1, sizeof(struct nvmf_qpair_disconnect_many_ctx));
|
|
|
|
|
|
|
|
if (!ctx) {
|
|
|
|
SPDK_ERRLOG("Failed to allocate memory for destroy poll group ctx\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
spdk_poller_unregister(&group->poller);
|
|
|
|
|
|
|
|
ctx->group = group;
|
2018-07-23 22:40:02 +00:00
|
|
|
_nvmf_tgt_disconnect_next_qpair(ctx);
|
2018-06-29 23:19:45 +00:00
|
|
|
}
|
|
|
|
|
2017-08-18 22:38:33 +00:00
|
|
|
struct spdk_nvmf_tgt *
|
|
|
|
spdk_nvmf_tgt_create(struct spdk_nvmf_tgt_opts *opts)
|
2016-06-06 21:44:30 +00:00
|
|
|
{
|
2017-08-18 22:38:33 +00:00
|
|
|
struct spdk_nvmf_tgt *tgt;
|
|
|
|
|
2017-08-23 17:35:44 +00:00
|
|
|
tgt = calloc(1, sizeof(*tgt));
|
|
|
|
if (!tgt) {
|
|
|
|
return NULL;
|
|
|
|
}
|
2017-08-18 22:38:33 +00:00
|
|
|
|
2017-08-17 20:39:27 +00:00
|
|
|
if (!opts) {
|
2017-08-18 22:38:33 +00:00
|
|
|
spdk_nvmf_tgt_opts_init(&tgt->opts);
|
2017-08-17 20:39:27 +00:00
|
|
|
} else {
|
2017-08-18 22:38:33 +00:00
|
|
|
tgt->opts = *opts;
|
2017-08-17 20:39:27 +00:00
|
|
|
}
|
|
|
|
|
2017-08-18 22:38:33 +00:00
|
|
|
tgt->discovery_genctr = 0;
|
|
|
|
tgt->discovery_log_page = NULL;
|
|
|
|
tgt->discovery_log_page_size = 0;
|
|
|
|
TAILQ_INIT(&tgt->transports);
|
2016-07-25 21:22:58 +00:00
|
|
|
|
2018-05-08 23:05:28 +00:00
|
|
|
tgt->subsystems = calloc(tgt->opts.max_subsystems, sizeof(struct spdk_nvmf_subsystem *));
|
|
|
|
if (!tgt->subsystems) {
|
|
|
|
free(tgt);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2017-11-17 17:01:39 +00:00
|
|
|
spdk_io_device_register(tgt,
|
|
|
|
spdk_nvmf_tgt_create_poll_group,
|
|
|
|
spdk_nvmf_tgt_destroy_poll_group,
|
2018-08-30 20:26:50 +00:00
|
|
|
sizeof(struct spdk_nvmf_poll_group),
|
|
|
|
"nvmf_tgt");
|
2017-11-17 17:01:39 +00:00
|
|
|
|
2017-08-18 22:38:33 +00:00
|
|
|
return tgt;
|
2016-06-06 21:44:30 +00:00
|
|
|
}
|
|
|
|
|
2018-06-05 22:34:04 +00:00
|
|
|
static void
|
|
|
|
spdk_nvmf_tgt_destroy_cb(void *io_device)
|
2016-10-19 17:03:45 +00:00
|
|
|
{
|
2018-06-05 22:34:04 +00:00
|
|
|
struct spdk_nvmf_tgt *tgt = io_device;
|
2017-07-24 23:30:07 +00:00
|
|
|
struct spdk_nvmf_transport *transport, *transport_tmp;
|
2018-06-05 22:34:04 +00:00
|
|
|
spdk_nvmf_tgt_destroy_done_fn *destroy_cb_fn;
|
|
|
|
void *destroy_cb_arg;
|
2017-12-20 20:45:59 +00:00
|
|
|
uint32_t i;
|
2017-02-20 04:49:39 +00:00
|
|
|
|
2017-08-23 17:35:44 +00:00
|
|
|
if (tgt->discovery_log_page) {
|
|
|
|
free(tgt->discovery_log_page);
|
|
|
|
}
|
2017-08-29 20:03:13 +00:00
|
|
|
|
|
|
|
if (tgt->subsystems) {
|
2018-05-08 23:05:28 +00:00
|
|
|
for (i = 0; i < tgt->opts.max_subsystems; i++) {
|
2017-12-20 20:45:59 +00:00
|
|
|
if (tgt->subsystems[i]) {
|
2017-12-19 23:39:04 +00:00
|
|
|
spdk_nvmf_subsystem_destroy(tgt->subsystems[i]);
|
2017-12-20 20:45:59 +00:00
|
|
|
}
|
|
|
|
}
|
2017-08-29 20:03:13 +00:00
|
|
|
free(tgt->subsystems);
|
|
|
|
}
|
|
|
|
|
2018-02-12 08:58:31 +00:00
|
|
|
TAILQ_FOREACH_SAFE(transport, &tgt->transports, link, transport_tmp) {
|
|
|
|
TAILQ_REMOVE(&tgt->transports, transport, link);
|
|
|
|
spdk_nvmf_transport_destroy(transport);
|
|
|
|
}
|
|
|
|
|
2018-06-05 22:34:04 +00:00
|
|
|
destroy_cb_fn = tgt->destroy_cb_fn;
|
|
|
|
destroy_cb_arg = tgt->destroy_cb_arg;
|
|
|
|
|
2017-08-23 17:35:44 +00:00
|
|
|
free(tgt);
|
2018-06-05 22:34:04 +00:00
|
|
|
|
|
|
|
if (destroy_cb_fn) {
|
|
|
|
destroy_cb_fn(destroy_cb_arg, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
spdk_nvmf_tgt_destroy(struct spdk_nvmf_tgt *tgt,
|
|
|
|
spdk_nvmf_tgt_destroy_done_fn cb_fn,
|
|
|
|
void *cb_arg)
|
|
|
|
{
|
|
|
|
tgt->destroy_cb_fn = cb_fn;
|
|
|
|
tgt->destroy_cb_arg = cb_arg;
|
|
|
|
|
|
|
|
spdk_io_device_unregister(tgt, spdk_nvmf_tgt_destroy_cb);
|
2016-10-19 17:03:45 +00:00
|
|
|
}
|
|
|
|
|
2018-05-07 18:26:13 +00:00
|
|
|
static void
|
|
|
|
spdk_nvmf_write_subsystem_config_json(struct spdk_json_write_ctx *w,
|
|
|
|
struct spdk_nvmf_subsystem *subsystem)
|
|
|
|
{
|
|
|
|
struct spdk_nvmf_host *host;
|
|
|
|
struct spdk_nvmf_listener *listener;
|
|
|
|
const struct spdk_nvme_transport_id *trid;
|
|
|
|
struct spdk_nvmf_ns *ns;
|
|
|
|
struct spdk_nvmf_ns_opts ns_opts;
|
|
|
|
uint32_t max_namespaces;
|
|
|
|
char uuid_str[SPDK_UUID_STRING_LEN];
|
|
|
|
const char *trtype;
|
|
|
|
const char *adrfam;
|
|
|
|
|
|
|
|
if (spdk_nvmf_subsystem_get_type(subsystem) != SPDK_NVMF_SUBTYPE_NVME) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* { */
|
|
|
|
spdk_json_write_object_begin(w);
|
2018-09-10 18:27:39 +00:00
|
|
|
spdk_json_write_named_string(w, "method", "nvmf_subsystem_create");
|
2018-05-07 18:26:13 +00:00
|
|
|
|
|
|
|
/* "params" : { */
|
|
|
|
spdk_json_write_named_object_begin(w, "params");
|
|
|
|
spdk_json_write_named_string(w, "nqn", spdk_nvmf_subsystem_get_nqn(subsystem));
|
|
|
|
spdk_json_write_named_bool(w, "allow_any_host", spdk_nvmf_subsystem_get_allow_any_host(subsystem));
|
2018-09-10 18:27:39 +00:00
|
|
|
spdk_json_write_named_string(w, "serial_number", spdk_nvmf_subsystem_get_sn(subsystem));
|
|
|
|
|
|
|
|
max_namespaces = spdk_nvmf_subsystem_get_max_namespaces(subsystem);
|
|
|
|
if (max_namespaces != 0) {
|
|
|
|
spdk_json_write_named_uint32(w, "max_namespaces", max_namespaces);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* } "params" */
|
|
|
|
spdk_json_write_object_end(w);
|
|
|
|
|
|
|
|
/* } */
|
|
|
|
spdk_json_write_object_end(w);
|
2018-05-07 18:26:13 +00:00
|
|
|
|
|
|
|
for (listener = spdk_nvmf_subsystem_get_first_listener(subsystem); listener != NULL;
|
|
|
|
listener = spdk_nvmf_subsystem_get_next_listener(subsystem, listener)) {
|
|
|
|
trid = spdk_nvmf_listener_get_trid(listener);
|
|
|
|
|
|
|
|
trtype = spdk_nvme_transport_id_trtype_str(trid->trtype);
|
|
|
|
adrfam = spdk_nvme_transport_id_adrfam_str(trid->adrfam);
|
|
|
|
|
|
|
|
spdk_json_write_object_begin(w);
|
2018-09-10 18:27:39 +00:00
|
|
|
spdk_json_write_named_string(w, "method", "nvmf_subsystem_add_listener");
|
|
|
|
|
|
|
|
/* "params" : { */
|
|
|
|
spdk_json_write_named_object_begin(w, "params");
|
|
|
|
|
|
|
|
spdk_json_write_named_string(w, "nqn", spdk_nvmf_subsystem_get_nqn(subsystem));
|
|
|
|
|
|
|
|
/* "listen_address" : { */
|
|
|
|
spdk_json_write_named_object_begin(w, "listen_address");
|
|
|
|
|
2018-05-07 18:26:13 +00:00
|
|
|
spdk_json_write_named_string(w, "trtype", trtype);
|
|
|
|
if (adrfam) {
|
|
|
|
spdk_json_write_named_string(w, "adrfam", adrfam);
|
|
|
|
}
|
|
|
|
|
|
|
|
spdk_json_write_named_string(w, "traddr", trid->traddr);
|
|
|
|
spdk_json_write_named_string(w, "trsvcid", trid->trsvcid);
|
2018-09-10 18:27:39 +00:00
|
|
|
/* } "listen_address" */
|
|
|
|
spdk_json_write_object_end(w);
|
|
|
|
|
|
|
|
/* } "params" */
|
|
|
|
spdk_json_write_object_end(w);
|
|
|
|
|
|
|
|
/* } */
|
2018-05-07 18:26:13 +00:00
|
|
|
spdk_json_write_object_end(w);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (host = spdk_nvmf_subsystem_get_first_host(subsystem); host != NULL;
|
|
|
|
host = spdk_nvmf_subsystem_get_next_host(subsystem, host)) {
|
|
|
|
|
2018-09-10 18:27:39 +00:00
|
|
|
spdk_json_write_object_begin(w);
|
|
|
|
spdk_json_write_named_string(w, "method", "nvmf_subsystem_add_host");
|
2018-05-07 18:26:13 +00:00
|
|
|
|
2018-09-10 18:27:39 +00:00
|
|
|
/* "params" : { */
|
|
|
|
spdk_json_write_named_object_begin(w, "params");
|
|
|
|
|
|
|
|
spdk_json_write_named_string(w, "nqn", spdk_nvmf_subsystem_get_nqn(subsystem));
|
|
|
|
spdk_json_write_named_string(w, "host", spdk_nvmf_host_get_nqn(host));
|
|
|
|
|
|
|
|
/* } "params" */
|
|
|
|
spdk_json_write_object_end(w);
|
|
|
|
|
|
|
|
/* } */
|
|
|
|
spdk_json_write_object_end(w);
|
2018-05-07 18:26:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (ns = spdk_nvmf_subsystem_get_first_ns(subsystem); ns != NULL;
|
|
|
|
ns = spdk_nvmf_subsystem_get_next_ns(subsystem, ns)) {
|
|
|
|
spdk_nvmf_ns_get_opts(ns, &ns_opts, sizeof(ns_opts));
|
|
|
|
|
|
|
|
spdk_json_write_object_begin(w);
|
2018-09-10 18:27:39 +00:00
|
|
|
spdk_json_write_named_string(w, "method", "nvmf_subsystem_add_ns");
|
|
|
|
|
|
|
|
/* "params" : { */
|
|
|
|
spdk_json_write_named_object_begin(w, "params");
|
|
|
|
|
|
|
|
spdk_json_write_named_string(w, "nqn", spdk_nvmf_subsystem_get_nqn(subsystem));
|
|
|
|
|
|
|
|
/* "namespace" : { */
|
|
|
|
spdk_json_write_named_object_begin(w, "namespace");
|
|
|
|
|
2018-05-07 18:26:13 +00:00
|
|
|
spdk_json_write_named_uint32(w, "nsid", spdk_nvmf_ns_get_id(ns));
|
|
|
|
spdk_json_write_named_string(w, "bdev_name", spdk_bdev_get_name(spdk_nvmf_ns_get_bdev(ns)));
|
|
|
|
|
|
|
|
if (!spdk_mem_all_zero(ns_opts.nguid, sizeof(ns_opts.nguid))) {
|
|
|
|
SPDK_STATIC_ASSERT(sizeof(ns_opts.nguid) == sizeof(uint64_t) * 2, "size mismatch");
|
|
|
|
spdk_json_write_named_string_fmt(w, "nguid", "%016"PRIX64"%016"PRIX64, from_be64(&ns_opts.nguid[0]),
|
|
|
|
from_be64(&ns_opts.nguid[8]));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!spdk_mem_all_zero(ns_opts.eui64, sizeof(ns_opts.eui64))) {
|
|
|
|
SPDK_STATIC_ASSERT(sizeof(ns_opts.eui64) == sizeof(uint64_t), "size mismatch");
|
|
|
|
spdk_json_write_named_string_fmt(w, "eui64", "%016"PRIX64, from_be64(&ns_opts.eui64));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!spdk_mem_all_zero(&ns_opts.uuid, sizeof(ns_opts.uuid))) {
|
|
|
|
spdk_uuid_fmt_lower(uuid_str, sizeof(uuid_str), &ns_opts.uuid);
|
|
|
|
spdk_json_write_named_string(w, "uuid", uuid_str);
|
|
|
|
}
|
|
|
|
|
2018-09-10 18:27:39 +00:00
|
|
|
/* "namespace" */
|
|
|
|
spdk_json_write_object_end(w);
|
2018-05-07 18:26:13 +00:00
|
|
|
|
2018-09-10 18:27:39 +00:00
|
|
|
/* } "params" */
|
|
|
|
spdk_json_write_object_end(w);
|
2018-05-07 18:26:13 +00:00
|
|
|
|
2018-09-10 18:27:39 +00:00
|
|
|
/* } */
|
|
|
|
spdk_json_write_object_end(w);
|
|
|
|
}
|
2018-05-07 18:26:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
spdk_nvmf_tgt_write_config_json(struct spdk_json_write_ctx *w, struct spdk_nvmf_tgt *tgt)
|
|
|
|
{
|
|
|
|
struct spdk_nvmf_subsystem *subsystem;
|
2018-08-27 22:27:47 +00:00
|
|
|
struct spdk_nvmf_transport *transport;
|
2018-05-07 18:26:13 +00:00
|
|
|
|
|
|
|
spdk_json_write_object_begin(w);
|
|
|
|
spdk_json_write_named_string(w, "method", "set_nvmf_target_options");
|
|
|
|
|
|
|
|
spdk_json_write_named_object_begin(w, "params");
|
|
|
|
spdk_json_write_named_uint32(w, "max_queue_depth", tgt->opts.max_queue_depth);
|
|
|
|
spdk_json_write_named_uint32(w, "max_qpairs_per_ctrlr", tgt->opts.max_qpairs_per_ctrlr);
|
|
|
|
spdk_json_write_named_uint32(w, "in_capsule_data_size", tgt->opts.in_capsule_data_size);
|
|
|
|
spdk_json_write_named_uint32(w, "max_io_size", tgt->opts.max_io_size);
|
|
|
|
spdk_json_write_named_uint32(w, "max_subsystems", tgt->opts.max_subsystems);
|
|
|
|
spdk_json_write_named_uint32(w, "io_unit_size", tgt->opts.io_unit_size);
|
|
|
|
spdk_json_write_object_end(w);
|
|
|
|
|
|
|
|
spdk_json_write_object_end(w);
|
|
|
|
|
2018-08-27 22:27:47 +00:00
|
|
|
/* write transports */
|
|
|
|
TAILQ_FOREACH(transport, &tgt->transports, link) {
|
|
|
|
spdk_json_write_object_begin(w);
|
|
|
|
spdk_json_write_named_string(w, "method", "nvmf_create_transport");
|
|
|
|
|
|
|
|
spdk_json_write_named_object_begin(w, "params");
|
|
|
|
spdk_json_write_named_string(w, "trtype", spdk_nvme_transport_id_trtype_str(transport->ops->type));
|
|
|
|
spdk_json_write_named_uint32(w, "max_queue_depth", transport->opts.max_queue_depth);
|
|
|
|
spdk_json_write_named_uint32(w, "max_qpairs_per_ctrlr", transport->opts.max_qpairs_per_ctrlr);
|
|
|
|
spdk_json_write_named_uint32(w, "in_capsule_data_size", transport->opts.in_capsule_data_size);
|
|
|
|
spdk_json_write_named_uint32(w, "max_io_size", transport->opts.max_io_size);
|
|
|
|
spdk_json_write_named_uint32(w, "io_unit_size", transport->opts.io_unit_size);
|
|
|
|
spdk_json_write_named_uint32(w, "max_aq_depth", transport->opts.max_aq_depth);
|
|
|
|
spdk_json_write_object_end(w);
|
|
|
|
|
|
|
|
spdk_json_write_object_end(w);
|
|
|
|
}
|
|
|
|
|
2018-05-07 18:26:13 +00:00
|
|
|
subsystem = spdk_nvmf_subsystem_get_first(tgt);
|
|
|
|
while (subsystem) {
|
|
|
|
spdk_nvmf_write_subsystem_config_json(w, subsystem);
|
|
|
|
subsystem = spdk_nvmf_subsystem_get_next(subsystem);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-03 18:35:04 +00:00
|
|
|
void
|
2017-08-21 18:41:51 +00:00
|
|
|
spdk_nvmf_tgt_listen(struct spdk_nvmf_tgt *tgt,
|
2018-04-03 18:35:04 +00:00
|
|
|
struct spdk_nvme_transport_id *trid,
|
|
|
|
spdk_nvmf_tgt_listen_done_fn cb_fn,
|
|
|
|
void *cb_arg)
|
2017-08-21 18:41:51 +00:00
|
|
|
{
|
|
|
|
struct spdk_nvmf_transport *transport;
|
|
|
|
int rc;
|
2018-04-03 18:35:04 +00:00
|
|
|
bool propagate = false;
|
2017-08-21 18:41:51 +00:00
|
|
|
|
|
|
|
transport = spdk_nvmf_tgt_get_transport(tgt, trid->trtype);
|
|
|
|
if (!transport) {
|
2018-08-27 22:27:47 +00:00
|
|
|
struct spdk_nvmf_transport_opts opts;
|
|
|
|
|
|
|
|
opts.max_queue_depth = tgt->opts.max_queue_depth;
|
|
|
|
opts.max_qpairs_per_ctrlr = tgt->opts.max_qpairs_per_ctrlr;
|
|
|
|
opts.in_capsule_data_size = tgt->opts.in_capsule_data_size;
|
|
|
|
opts.max_io_size = tgt->opts.max_io_size;
|
|
|
|
opts.io_unit_size = tgt->opts.io_unit_size;
|
|
|
|
/* use max_queue depth since tgt. opts. doesn't have max_aq_depth */
|
|
|
|
opts.max_aq_depth = tgt->opts.max_queue_depth;
|
|
|
|
|
|
|
|
transport = spdk_nvmf_transport_create(trid->trtype, &opts);
|
2017-08-21 18:41:51 +00:00
|
|
|
if (!transport) {
|
|
|
|
SPDK_ERRLOG("Transport initialization failed\n");
|
2018-04-03 18:35:04 +00:00
|
|
|
cb_fn(cb_arg, -EINVAL);
|
|
|
|
return;
|
2017-08-21 18:41:51 +00:00
|
|
|
}
|
|
|
|
|
2018-04-03 18:35:04 +00:00
|
|
|
propagate = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
rc = spdk_nvmf_transport_listen(transport, trid);
|
|
|
|
if (rc < 0) {
|
|
|
|
SPDK_ERRLOG("Unable to listen on address '%s'\n", trid->traddr);
|
|
|
|
cb_fn(cb_arg, rc);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
tgt->discovery_genctr++;
|
|
|
|
|
|
|
|
if (propagate) {
|
2018-08-27 22:27:47 +00:00
|
|
|
spdk_nvmf_tgt_add_transport(tgt, transport, cb_fn, cb_arg);
|
|
|
|
} else {
|
|
|
|
cb_fn(cb_arg, 0);
|
|
|
|
}
|
|
|
|
}
|
2018-04-03 18:35:04 +00:00
|
|
|
|
2018-08-27 22:27:47 +00:00
|
|
|
struct spdk_nvmf_tgt_add_transport_ctx {
|
|
|
|
struct spdk_nvmf_tgt *tgt;
|
|
|
|
struct spdk_nvmf_transport *transport;
|
|
|
|
spdk_nvmf_tgt_add_transport_done_fn cb_fn;
|
|
|
|
void *cb_arg;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
_spdk_nvmf_tgt_add_transport_done(struct spdk_io_channel_iter *i, int status)
|
|
|
|
{
|
|
|
|
struct spdk_nvmf_tgt_add_transport_ctx *ctx = spdk_io_channel_iter_get_ctx(i);
|
2017-11-17 17:01:39 +00:00
|
|
|
|
2018-08-27 22:27:47 +00:00
|
|
|
ctx->cb_fn(ctx->cb_arg, status);
|
2017-11-17 17:01:39 +00:00
|
|
|
|
2018-08-27 22:27:47 +00:00
|
|
|
free(ctx);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_spdk_nvmf_tgt_add_transport(struct spdk_io_channel_iter *i)
|
|
|
|
{
|
|
|
|
struct spdk_nvmf_tgt_add_transport_ctx *ctx = spdk_io_channel_iter_get_ctx(i);
|
|
|
|
struct spdk_io_channel *ch = spdk_io_channel_iter_get_channel(i);
|
|
|
|
struct spdk_nvmf_poll_group *group = spdk_io_channel_get_ctx(ch);
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
rc = spdk_nvmf_poll_group_add_transport(group, ctx->transport);
|
|
|
|
spdk_for_each_channel_continue(i, rc);
|
|
|
|
}
|
|
|
|
|
|
|
|
void spdk_nvmf_tgt_add_transport(struct spdk_nvmf_tgt *tgt,
|
|
|
|
struct spdk_nvmf_transport *transport,
|
|
|
|
spdk_nvmf_tgt_add_transport_done_fn cb_fn,
|
|
|
|
void *cb_arg)
|
|
|
|
{
|
|
|
|
struct spdk_nvmf_tgt_add_transport_ctx *ctx;
|
|
|
|
|
|
|
|
if (spdk_nvmf_tgt_get_transport(tgt, transport->ops->type)) {
|
|
|
|
cb_fn(cb_arg, -EEXIST);
|
|
|
|
return; /* transport already created */
|
2017-11-17 17:01:39 +00:00
|
|
|
}
|
2018-08-27 22:27:47 +00:00
|
|
|
|
|
|
|
transport->tgt = tgt;
|
|
|
|
TAILQ_INSERT_TAIL(&tgt->transports, transport, link);
|
|
|
|
|
|
|
|
ctx = calloc(1, sizeof(*ctx));
|
|
|
|
if (!ctx) {
|
|
|
|
cb_fn(cb_arg, -ENOMEM);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx->tgt = tgt;
|
|
|
|
ctx->transport = transport;
|
|
|
|
ctx->cb_fn = cb_fn;
|
|
|
|
ctx->cb_arg = cb_arg;
|
|
|
|
|
|
|
|
spdk_for_each_channel(tgt,
|
|
|
|
_spdk_nvmf_tgt_add_transport,
|
|
|
|
ctx,
|
|
|
|
_spdk_nvmf_tgt_add_transport_done);
|
2017-08-21 18:41:51 +00:00
|
|
|
}
|
|
|
|
|
2017-08-18 23:05:13 +00:00
|
|
|
struct spdk_nvmf_subsystem *
|
|
|
|
spdk_nvmf_tgt_find_subsystem(struct spdk_nvmf_tgt *tgt, const char *subnqn)
|
|
|
|
{
|
|
|
|
struct spdk_nvmf_subsystem *subsystem;
|
2017-08-29 20:03:13 +00:00
|
|
|
uint32_t sid;
|
2017-08-18 23:05:13 +00:00
|
|
|
|
|
|
|
if (!subnqn) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2018-05-08 23:05:28 +00:00
|
|
|
for (sid = 0; sid < tgt->opts.max_subsystems; sid++) {
|
2017-08-29 20:03:13 +00:00
|
|
|
subsystem = tgt->subsystems[sid];
|
|
|
|
if (subsystem == NULL) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2017-08-18 23:05:13 +00:00
|
|
|
if (strcmp(subnqn, subsystem->subnqn) == 0) {
|
|
|
|
return subsystem;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2017-07-24 23:30:07 +00:00
|
|
|
struct spdk_nvmf_transport *
|
|
|
|
spdk_nvmf_tgt_get_transport(struct spdk_nvmf_tgt *tgt, enum spdk_nvme_transport_type type)
|
|
|
|
{
|
|
|
|
struct spdk_nvmf_transport *transport;
|
|
|
|
|
|
|
|
TAILQ_FOREACH(transport, &tgt->transports, link) {
|
|
|
|
if (transport->ops->type == type) {
|
|
|
|
return transport;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2017-08-30 16:36:33 +00:00
|
|
|
spdk_nvmf_tgt_accept(struct spdk_nvmf_tgt *tgt, new_qpair_fn cb_fn)
|
2017-07-24 23:30:07 +00:00
|
|
|
{
|
|
|
|
struct spdk_nvmf_transport *transport, *tmp;
|
|
|
|
|
2017-08-21 21:07:44 +00:00
|
|
|
TAILQ_FOREACH_SAFE(transport, &tgt->transports, link, tmp) {
|
2017-08-30 16:36:33 +00:00
|
|
|
spdk_nvmf_transport_accept(transport, cb_fn);
|
2017-07-24 23:30:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-28 23:24:33 +00:00
|
|
|
struct spdk_nvmf_poll_group *
|
|
|
|
spdk_nvmf_poll_group_create(struct spdk_nvmf_tgt *tgt)
|
|
|
|
{
|
2017-11-17 17:01:39 +00:00
|
|
|
struct spdk_io_channel *ch;
|
2017-08-28 23:24:33 +00:00
|
|
|
|
2017-11-17 17:01:39 +00:00
|
|
|
ch = spdk_get_io_channel(tgt);
|
|
|
|
if (!ch) {
|
|
|
|
SPDK_ERRLOG("Unable to get I/O channel for target\n");
|
2017-08-28 23:24:33 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2017-11-17 17:01:39 +00:00
|
|
|
return spdk_io_channel_get_ctx(ch);
|
2017-08-28 23:24:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
spdk_nvmf_poll_group_destroy(struct spdk_nvmf_poll_group *group)
|
|
|
|
{
|
2018-07-23 22:40:02 +00:00
|
|
|
/* This function will put the io_channel associated with this poll group */
|
|
|
|
spdk_nvmf_tgt_destroy_poll_group_qpairs(group);
|
2017-08-28 23:24:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
spdk_nvmf_poll_group_add(struct spdk_nvmf_poll_group *group,
|
|
|
|
struct spdk_nvmf_qpair *qpair)
|
|
|
|
{
|
|
|
|
int rc = -1;
|
|
|
|
struct spdk_nvmf_transport_poll_group *tgroup;
|
|
|
|
|
2018-05-11 00:18:40 +00:00
|
|
|
TAILQ_INIT(&qpair->outstanding);
|
2017-11-29 20:59:10 +00:00
|
|
|
qpair->group = group;
|
2018-08-24 17:16:23 +00:00
|
|
|
spdk_nvmf_qpair_set_state(qpair, SPDK_NVMF_QPAIR_ACTIVATING);
|
2017-11-29 20:59:10 +00:00
|
|
|
|
2018-06-01 22:10:12 +00:00
|
|
|
TAILQ_INSERT_TAIL(&group->qpairs, qpair, link);
|
|
|
|
|
2017-08-28 23:24:33 +00:00
|
|
|
TAILQ_FOREACH(tgroup, &group->tgroups, link) {
|
|
|
|
if (tgroup->transport == qpair->transport) {
|
|
|
|
rc = spdk_nvmf_transport_poll_group_add(tgroup, qpair);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-22 17:07:43 +00:00
|
|
|
if (rc == 0) {
|
2018-08-24 17:16:23 +00:00
|
|
|
spdk_nvmf_qpair_set_state(qpair, SPDK_NVMF_QPAIR_ACTIVE);
|
2018-05-22 17:07:43 +00:00
|
|
|
} else {
|
2018-08-24 17:16:23 +00:00
|
|
|
spdk_nvmf_qpair_set_state(qpair, SPDK_NVMF_QPAIR_INACTIVE);
|
2018-05-22 17:07:43 +00:00
|
|
|
}
|
|
|
|
|
2017-08-28 23:24:33 +00:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2018-07-31 03:55:40 +00:00
|
|
|
static
|
|
|
|
void _nvmf_ctrlr_destruct(void *ctx)
|
|
|
|
{
|
|
|
|
struct spdk_nvmf_ctrlr *ctrlr = ctx;
|
|
|
|
|
|
|
|
spdk_nvmf_ctrlr_destruct(ctrlr);
|
|
|
|
}
|
|
|
|
|
2018-06-14 17:27:37 +00:00
|
|
|
static void
|
2018-06-29 19:09:47 +00:00
|
|
|
_spdk_nvmf_ctrlr_free_from_qpair(void *ctx)
|
2018-06-14 17:27:37 +00:00
|
|
|
{
|
2018-06-29 19:09:47 +00:00
|
|
|
struct nvmf_qpair_disconnect_ctx *qpair_ctx = ctx;
|
|
|
|
struct spdk_nvmf_ctrlr *ctrlr = qpair_ctx->ctrlr;
|
2018-07-31 03:55:40 +00:00
|
|
|
uint32_t count;
|
2018-06-14 17:27:37 +00:00
|
|
|
|
2018-07-31 03:55:40 +00:00
|
|
|
spdk_bit_array_clear(ctrlr->qpair_mask, qpair_ctx->qid);
|
|
|
|
count = spdk_bit_array_count_set(ctrlr->qpair_mask);
|
|
|
|
if (count == 0) {
|
|
|
|
spdk_bit_array_free(&ctrlr->qpair_mask);
|
|
|
|
|
|
|
|
spdk_thread_send_msg(ctrlr->subsys->thread, _nvmf_ctrlr_destruct, ctrlr);
|
|
|
|
}
|
2018-06-29 19:09:47 +00:00
|
|
|
|
|
|
|
if (qpair_ctx->cb_fn) {
|
2018-07-19 22:50:34 +00:00
|
|
|
spdk_thread_send_msg(qpair_ctx->thread, qpair_ctx->cb_fn, qpair_ctx->ctx);
|
2018-06-29 19:09:47 +00:00
|
|
|
}
|
|
|
|
free(qpair_ctx);
|
2018-06-14 17:27:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2018-06-01 22:10:12 +00:00
|
|
|
_spdk_nvmf_qpair_destroy(void *ctx, int status)
|
2018-06-14 17:27:37 +00:00
|
|
|
{
|
2018-06-29 19:09:47 +00:00
|
|
|
struct nvmf_qpair_disconnect_ctx *qpair_ctx = ctx;
|
|
|
|
struct spdk_nvmf_qpair *qpair = qpair_ctx->qpair;
|
2018-06-01 22:10:12 +00:00
|
|
|
struct spdk_nvmf_ctrlr *ctrlr = qpair->ctrlr;
|
2018-08-02 22:27:32 +00:00
|
|
|
|
2018-06-14 17:27:37 +00:00
|
|
|
assert(qpair->state == SPDK_NVMF_QPAIR_DEACTIVATING);
|
2018-08-24 17:16:23 +00:00
|
|
|
spdk_nvmf_qpair_set_state(qpair, SPDK_NVMF_QPAIR_INACTIVE);
|
2018-07-31 03:55:40 +00:00
|
|
|
qpair_ctx->qid = qpair->qid;
|
2018-06-14 17:27:37 +00:00
|
|
|
|
2018-08-24 17:16:23 +00:00
|
|
|
TAILQ_REMOVE(&qpair->group->qpairs, qpair, link);
|
|
|
|
qpair->group = NULL;
|
|
|
|
|
2018-06-14 17:27:37 +00:00
|
|
|
spdk_nvmf_transport_qpair_fini(qpair);
|
|
|
|
|
2018-08-13 17:26:26 +00:00
|
|
|
if (!ctrlr || !ctrlr->thread) {
|
2018-06-29 19:09:47 +00:00
|
|
|
if (qpair_ctx->cb_fn) {
|
2018-07-19 22:50:34 +00:00
|
|
|
spdk_thread_send_msg(qpair_ctx->thread, qpair_ctx->cb_fn, qpair_ctx->ctx);
|
2018-06-29 19:09:47 +00:00
|
|
|
}
|
|
|
|
free(qpair_ctx);
|
2018-06-01 22:10:12 +00:00
|
|
|
return;
|
|
|
|
}
|
2018-06-14 17:27:37 +00:00
|
|
|
|
2018-07-31 03:55:40 +00:00
|
|
|
qpair_ctx->ctrlr = ctrlr;
|
2018-08-13 17:26:26 +00:00
|
|
|
spdk_thread_send_msg(ctrlr->thread, _spdk_nvmf_ctrlr_free_from_qpair, qpair_ctx);
|
2018-06-14 17:27:37 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-06-29 19:09:47 +00:00
|
|
|
int
|
|
|
|
spdk_nvmf_qpair_disconnect(struct spdk_nvmf_qpair *qpair, nvmf_qpair_disconnect_cb cb_fn, void *ctx)
|
2018-06-14 17:27:37 +00:00
|
|
|
{
|
2018-09-04 18:37:31 +00:00
|
|
|
struct nvmf_qpair_disconnect_ctx *qpair_ctx;
|
2018-06-29 19:09:47 +00:00
|
|
|
|
2018-07-27 19:21:00 +00:00
|
|
|
/* If we get a qpair in the uninitialized state, we can just destroy it immediately */
|
|
|
|
if (qpair->state == SPDK_NVMF_QPAIR_UNINITIALIZED) {
|
|
|
|
spdk_nvmf_transport_qpair_fini(qpair);
|
|
|
|
if (cb_fn) {
|
|
|
|
cb_fn(ctx);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-09-04 18:37:31 +00:00
|
|
|
/* The queue pair must be disconnected from the thread that owns it */
|
|
|
|
assert(qpair->group->thread == spdk_get_thread());
|
|
|
|
|
2018-09-04 18:46:31 +00:00
|
|
|
if (qpair->state == SPDK_NVMF_QPAIR_DEACTIVATING ||
|
|
|
|
qpair->state == SPDK_NVMF_QPAIR_INACTIVE) {
|
|
|
|
/* This can occur if the connection is killed by the target,
|
|
|
|
* which results in a notification that the connection
|
|
|
|
* died. Send a message to defer the processing of this
|
|
|
|
* callback. This allows the stack to unwind in the case
|
|
|
|
* where a bunch of connections are disconnected in
|
|
|
|
* a loop. */
|
|
|
|
if (cb_fn) {
|
|
|
|
spdk_thread_send_msg(qpair->group->thread, cb_fn, ctx);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2018-09-04 18:37:31 +00:00
|
|
|
|
2018-09-04 18:46:31 +00:00
|
|
|
assert(qpair->state == SPDK_NVMF_QPAIR_ACTIVE);
|
|
|
|
spdk_nvmf_qpair_set_state(qpair, SPDK_NVMF_QPAIR_DEACTIVATING);
|
|
|
|
|
|
|
|
qpair_ctx = calloc(1, sizeof(struct nvmf_qpair_disconnect_ctx));
|
2018-09-04 18:37:31 +00:00
|
|
|
if (!qpair_ctx) {
|
|
|
|
SPDK_ERRLOG("Unable to allocate context for nvmf_qpair_disconnect\n");
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
2018-06-29 19:09:47 +00:00
|
|
|
qpair_ctx->qpair = qpair;
|
|
|
|
qpair_ctx->cb_fn = cb_fn;
|
2018-07-19 22:50:34 +00:00
|
|
|
qpair_ctx->thread = qpair->group->thread;
|
2018-06-29 19:09:47 +00:00
|
|
|
qpair_ctx->ctx = ctx;
|
2018-09-04 18:46:31 +00:00
|
|
|
|
|
|
|
/* Check for outstanding I/O */
|
|
|
|
if (!TAILQ_EMPTY(&qpair->outstanding)) {
|
|
|
|
qpair->state_cb = _spdk_nvmf_qpair_destroy;
|
|
|
|
qpair->state_cb_arg = qpair_ctx;
|
|
|
|
spdk_nvmf_qpair_free_aer(qpair);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
_spdk_nvmf_qpair_destroy(qpair_ctx, 0);
|
|
|
|
|
2018-06-29 19:09:47 +00:00
|
|
|
return 0;
|
2018-06-14 17:27:37 +00:00
|
|
|
}
|
|
|
|
|
2018-08-02 22:08:12 +00:00
|
|
|
int
|
|
|
|
spdk_nvmf_qpair_get_peer_trid(struct spdk_nvmf_qpair *qpair,
|
|
|
|
struct spdk_nvme_transport_id *trid)
|
|
|
|
{
|
|
|
|
return spdk_nvmf_transport_qpair_get_peer_trid(qpair, trid);
|
|
|
|
}
|
|
|
|
|
2018-09-10 21:28:04 +00:00
|
|
|
int
|
|
|
|
spdk_nvmf_qpair_get_local_trid(struct spdk_nvmf_qpair *qpair,
|
|
|
|
struct spdk_nvme_transport_id *trid)
|
|
|
|
{
|
|
|
|
return spdk_nvmf_transport_qpair_get_local_trid(qpair, trid);
|
|
|
|
}
|
|
|
|
|
2018-09-07 20:41:41 +00:00
|
|
|
int
|
|
|
|
spdk_nvmf_qpair_get_listen_trid(struct spdk_nvmf_qpair *qpair,
|
|
|
|
struct spdk_nvme_transport_id *trid)
|
|
|
|
{
|
|
|
|
return spdk_nvmf_transport_qpair_get_listen_trid(qpair, trid);
|
|
|
|
}
|
|
|
|
|
2017-11-17 17:01:39 +00:00
|
|
|
int
|
|
|
|
spdk_nvmf_poll_group_add_transport(struct spdk_nvmf_poll_group *group,
|
|
|
|
struct spdk_nvmf_transport *transport)
|
|
|
|
{
|
|
|
|
struct spdk_nvmf_transport_poll_group *tgroup;
|
|
|
|
|
2018-01-17 01:06:52 +00:00
|
|
|
TAILQ_FOREACH(tgroup, &group->tgroups, link) {
|
|
|
|
if (tgroup->transport == transport) {
|
|
|
|
/* Transport already in the poll group */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-17 17:01:39 +00:00
|
|
|
tgroup = spdk_nvmf_transport_poll_group_create(transport);
|
|
|
|
if (!tgroup) {
|
|
|
|
SPDK_ERRLOG("Unable to create poll group for transport\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
TAILQ_INSERT_TAIL(&group->tgroups, tgroup, link);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-12-19 23:39:04 +00:00
|
|
|
static int
|
|
|
|
poll_group_update_subsystem(struct spdk_nvmf_poll_group *group,
|
|
|
|
struct spdk_nvmf_subsystem *subsystem)
|
2017-11-20 16:50:10 +00:00
|
|
|
{
|
|
|
|
struct spdk_nvmf_subsystem_poll_group *sgroup;
|
2017-12-19 23:39:04 +00:00
|
|
|
uint32_t new_num_channels, old_num_channels;
|
2017-11-20 16:50:10 +00:00
|
|
|
uint32_t i;
|
2017-12-19 23:39:04 +00:00
|
|
|
struct spdk_nvmf_ns *ns;
|
2017-11-20 16:50:10 +00:00
|
|
|
|
2018-04-05 20:51:51 +00:00
|
|
|
/* Make sure our poll group has memory for this subsystem allocated */
|
2017-11-20 16:50:10 +00:00
|
|
|
if (subsystem->id >= group->num_sgroups) {
|
2018-05-08 23:05:28 +00:00
|
|
|
return -ENOMEM;
|
2017-11-20 16:50:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sgroup = &group->sgroups[subsystem->id];
|
|
|
|
|
2018-04-05 20:51:51 +00:00
|
|
|
/* Make sure the array of channels is the correct size */
|
2017-12-19 23:39:04 +00:00
|
|
|
new_num_channels = subsystem->max_nsid;
|
|
|
|
old_num_channels = sgroup->num_channels;
|
|
|
|
|
2018-04-05 20:51:51 +00:00
|
|
|
if (old_num_channels == 0) {
|
|
|
|
if (new_num_channels > 0) {
|
|
|
|
/* First allocation */
|
|
|
|
sgroup->channels = calloc(new_num_channels, sizeof(sgroup->channels[0]));
|
|
|
|
if (!sgroup->channels) {
|
|
|
|
return -ENOMEM;
|
2018-03-21 06:16:23 +00:00
|
|
|
}
|
|
|
|
}
|
2018-04-05 20:51:51 +00:00
|
|
|
} else if (new_num_channels > old_num_channels) {
|
|
|
|
void *buf;
|
|
|
|
|
|
|
|
/* Make the array larger */
|
|
|
|
buf = realloc(sgroup->channels, new_num_channels * sizeof(sgroup->channels[0]));
|
|
|
|
if (!buf) {
|
2017-12-19 23:39:04 +00:00
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
2018-04-05 20:51:51 +00:00
|
|
|
sgroup->channels = buf;
|
|
|
|
|
|
|
|
/* Null out the new channels slots */
|
2017-12-19 23:39:04 +00:00
|
|
|
for (i = old_num_channels; i < new_num_channels; i++) {
|
2018-04-05 20:51:51 +00:00
|
|
|
sgroup->channels[i] = NULL;
|
2017-12-19 23:39:04 +00:00
|
|
|
}
|
|
|
|
} else if (new_num_channels < old_num_channels) {
|
2018-04-05 20:51:51 +00:00
|
|
|
void *buf;
|
|
|
|
|
2017-12-19 23:39:04 +00:00
|
|
|
/* Free the extra I/O channels */
|
|
|
|
for (i = new_num_channels; i < old_num_channels; i++) {
|
|
|
|
if (sgroup->channels[i]) {
|
|
|
|
spdk_put_io_channel(sgroup->channels[i]);
|
2018-03-07 05:31:06 +00:00
|
|
|
sgroup->channels[i] = NULL;
|
2017-12-19 23:39:04 +00:00
|
|
|
}
|
|
|
|
}
|
2017-11-20 16:50:10 +00:00
|
|
|
|
2018-04-05 20:51:51 +00:00
|
|
|
/* Make the array smaller */
|
|
|
|
if (new_num_channels > 0) {
|
|
|
|
buf = realloc(sgroup->channels, new_num_channels * sizeof(sgroup->channels[0]));
|
|
|
|
if (!buf) {
|
|
|
|
return -ENOMEM;
|
2017-11-20 16:50:10 +00:00
|
|
|
}
|
2018-04-05 20:51:51 +00:00
|
|
|
sgroup->channels = buf;
|
|
|
|
} else {
|
|
|
|
free(sgroup->channels);
|
|
|
|
sgroup->channels = NULL;
|
2017-11-20 16:50:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-05 20:51:51 +00:00
|
|
|
sgroup->num_channels = new_num_channels;
|
|
|
|
|
|
|
|
/* Detect bdevs that were added or removed */
|
|
|
|
for (i = 0; i < sgroup->num_channels; i++) {
|
|
|
|
ns = subsystem->ns[i];
|
|
|
|
if (ns == NULL && sgroup->channels[i] == NULL) {
|
|
|
|
/* Both NULL. Leave empty */
|
|
|
|
} else if (ns == NULL && sgroup->channels[i] != NULL) {
|
|
|
|
/* There was a channel here, but the namespace is gone. */
|
|
|
|
spdk_put_io_channel(sgroup->channels[i]);
|
|
|
|
sgroup->channels[i] = NULL;
|
|
|
|
} else if (ns != NULL && sgroup->channels[i] == NULL) {
|
|
|
|
/* A namespace appeared but there is no channel yet */
|
|
|
|
sgroup->channels[i] = spdk_bdev_get_io_channel(ns->desc);
|
2018-06-25 03:02:16 +00:00
|
|
|
if (sgroup->channels[i] == NULL) {
|
|
|
|
SPDK_ERRLOG("Could not allocate I/O channel.\n");
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
2018-04-05 20:51:51 +00:00
|
|
|
} else {
|
|
|
|
/* A namespace was present before and didn't change. */
|
|
|
|
}
|
|
|
|
}
|
2017-12-19 23:39:04 +00:00
|
|
|
|
2017-11-20 16:50:10 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-04-18 16:31:40 +00:00
|
|
|
int
|
|
|
|
spdk_nvmf_poll_group_update_subsystem(struct spdk_nvmf_poll_group *group,
|
|
|
|
struct spdk_nvmf_subsystem *subsystem)
|
|
|
|
{
|
|
|
|
return poll_group_update_subsystem(group, subsystem);
|
|
|
|
}
|
|
|
|
|
2018-07-13 23:23:23 +00:00
|
|
|
void
|
2017-12-19 23:39:04 +00:00
|
|
|
spdk_nvmf_poll_group_add_subsystem(struct spdk_nvmf_poll_group *group,
|
2018-07-13 23:23:23 +00:00
|
|
|
struct spdk_nvmf_subsystem *subsystem,
|
|
|
|
spdk_nvmf_poll_group_mod_done cb_fn, void *cb_arg)
|
2017-12-14 02:38:18 +00:00
|
|
|
{
|
2018-07-13 23:23:23 +00:00
|
|
|
int rc = 0;
|
2018-08-20 22:48:27 +00:00
|
|
|
struct spdk_nvmf_subsystem_poll_group *sgroup = &group->sgroups[subsystem->id];
|
|
|
|
|
|
|
|
TAILQ_INIT(&sgroup->queued);
|
2017-12-14 02:38:18 +00:00
|
|
|
|
2017-12-19 23:39:04 +00:00
|
|
|
rc = poll_group_update_subsystem(group, subsystem);
|
|
|
|
if (rc) {
|
2018-08-20 22:48:27 +00:00
|
|
|
sgroup->state = SPDK_NVMF_SUBSYSTEM_INACTIVE;
|
2018-07-13 23:23:23 +00:00
|
|
|
goto fini;
|
2017-12-14 02:38:18 +00:00
|
|
|
}
|
|
|
|
|
2017-12-19 23:39:04 +00:00
|
|
|
sgroup->state = SPDK_NVMF_SUBSYSTEM_ACTIVE;
|
2018-07-13 23:23:23 +00:00
|
|
|
fini:
|
|
|
|
if (cb_fn) {
|
|
|
|
cb_fn(cb_arg, rc);
|
|
|
|
}
|
2017-12-14 02:38:18 +00:00
|
|
|
}
|
|
|
|
|
2018-06-29 20:15:15 +00:00
|
|
|
static void
|
|
|
|
_nvmf_poll_group_remove_subsystem_cb(void *ctx, int status)
|
2017-11-20 16:50:10 +00:00
|
|
|
{
|
2018-07-13 23:23:23 +00:00
|
|
|
struct nvmf_qpair_disconnect_many_ctx *qpair_ctx = ctx;
|
|
|
|
struct spdk_nvmf_subsystem *subsystem;
|
|
|
|
struct spdk_nvmf_poll_group *group;
|
2017-11-20 16:50:10 +00:00
|
|
|
struct spdk_nvmf_subsystem_poll_group *sgroup;
|
2018-07-13 23:23:23 +00:00
|
|
|
spdk_nvmf_poll_group_mod_done cpl_fn = NULL;
|
|
|
|
void *cpl_ctx = NULL;
|
2017-11-20 16:50:10 +00:00
|
|
|
uint32_t nsid;
|
|
|
|
|
2018-07-13 23:23:23 +00:00
|
|
|
group = qpair_ctx->group;
|
|
|
|
subsystem = qpair_ctx->subsystem;
|
|
|
|
cpl_fn = qpair_ctx->cpl_fn;
|
|
|
|
cpl_ctx = qpair_ctx->cpl_ctx;
|
|
|
|
sgroup = &group->sgroups[subsystem->id];
|
|
|
|
|
2018-06-29 20:15:15 +00:00
|
|
|
if (status) {
|
2018-07-13 23:23:23 +00:00
|
|
|
goto fini;
|
2018-06-01 22:10:12 +00:00
|
|
|
}
|
|
|
|
|
2017-11-20 16:50:10 +00:00
|
|
|
for (nsid = 0; nsid < sgroup->num_channels; nsid++) {
|
|
|
|
if (sgroup->channels[nsid]) {
|
|
|
|
spdk_put_io_channel(sgroup->channels[nsid]);
|
|
|
|
sgroup->channels[nsid] = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sgroup->num_channels = 0;
|
|
|
|
free(sgroup->channels);
|
|
|
|
sgroup->channels = NULL;
|
2018-07-13 23:23:23 +00:00
|
|
|
fini:
|
|
|
|
free(qpair_ctx);
|
|
|
|
if (cpl_fn) {
|
|
|
|
cpl_fn(cpl_ctx, status);
|
|
|
|
}
|
2018-06-29 20:15:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_nvmf_subsystem_disconnect_next_qpair(void *ctx)
|
|
|
|
{
|
|
|
|
struct spdk_nvmf_qpair *qpair;
|
|
|
|
struct nvmf_qpair_disconnect_many_ctx *qpair_ctx = ctx;
|
|
|
|
struct spdk_nvmf_subsystem *subsystem;
|
|
|
|
struct spdk_nvmf_poll_group *group;
|
|
|
|
int rc = 0;
|
|
|
|
|
|
|
|
group = qpair_ctx->group;
|
|
|
|
subsystem = qpair_ctx->subsystem;
|
|
|
|
|
|
|
|
TAILQ_FOREACH(qpair, &group->qpairs, link) {
|
|
|
|
if (qpair->ctrlr->subsys == subsystem) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (qpair) {
|
|
|
|
rc = spdk_nvmf_qpair_disconnect(qpair, _nvmf_subsystem_disconnect_next_qpair, qpair_ctx);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!qpair || rc != 0) {
|
2018-07-13 23:23:23 +00:00
|
|
|
_nvmf_poll_group_remove_subsystem_cb(ctx, rc);
|
2018-06-29 20:15:15 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-07-13 23:23:23 +00:00
|
|
|
void
|
2018-06-29 20:15:15 +00:00
|
|
|
spdk_nvmf_poll_group_remove_subsystem(struct spdk_nvmf_poll_group *group,
|
2018-07-13 23:23:23 +00:00
|
|
|
struct spdk_nvmf_subsystem *subsystem,
|
|
|
|
spdk_nvmf_poll_group_mod_done cb_fn, void *cb_arg)
|
2018-06-29 20:15:15 +00:00
|
|
|
{
|
|
|
|
struct spdk_nvmf_qpair *qpair;
|
|
|
|
struct spdk_nvmf_subsystem_poll_group *sgroup;
|
|
|
|
struct nvmf_qpair_disconnect_many_ctx *ctx;
|
|
|
|
int rc = 0;
|
|
|
|
|
|
|
|
ctx = calloc(1, sizeof(struct nvmf_qpair_disconnect_many_ctx));
|
|
|
|
|
|
|
|
if (!ctx) {
|
2018-07-13 23:23:23 +00:00
|
|
|
SPDK_ERRLOG("Unable to allocate memory for context to remove poll subsystem\n");
|
|
|
|
goto fini;
|
2018-06-29 20:15:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ctx->group = group;
|
|
|
|
ctx->subsystem = subsystem;
|
2018-07-13 23:23:23 +00:00
|
|
|
ctx->cpl_fn = cb_fn;
|
|
|
|
ctx->cpl_ctx = cb_arg;
|
2018-06-29 20:15:15 +00:00
|
|
|
|
|
|
|
sgroup = &group->sgroups[subsystem->id];
|
|
|
|
sgroup->state = SPDK_NVMF_SUBSYSTEM_INACTIVE;
|
|
|
|
|
|
|
|
TAILQ_FOREACH(qpair, &group->qpairs, link) {
|
|
|
|
if (qpair->ctrlr->subsys == subsystem) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (qpair) {
|
|
|
|
rc = spdk_nvmf_qpair_disconnect(qpair, _nvmf_subsystem_disconnect_next_qpair, ctx);
|
|
|
|
} else {
|
2018-07-13 23:23:23 +00:00
|
|
|
/* call the callback immediately. It will handle any channel iteration */
|
|
|
|
_nvmf_poll_group_remove_subsystem_cb(ctx, 0);
|
2018-06-29 20:15:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (rc != 0) {
|
|
|
|
free(ctx);
|
2018-07-13 23:23:23 +00:00
|
|
|
goto fini;
|
2018-06-29 20:15:15 +00:00
|
|
|
}
|
2017-11-20 16:50:10 +00:00
|
|
|
|
2018-07-13 23:23:23 +00:00
|
|
|
return;
|
|
|
|
fini:
|
|
|
|
if (cb_fn) {
|
|
|
|
cb_fn(cb_arg, rc);
|
|
|
|
}
|
2017-11-20 16:50:10 +00:00
|
|
|
}
|
|
|
|
|
2018-07-13 23:23:23 +00:00
|
|
|
void
|
2017-12-19 23:39:04 +00:00
|
|
|
spdk_nvmf_poll_group_pause_subsystem(struct spdk_nvmf_poll_group *group,
|
2018-07-13 23:23:23 +00:00
|
|
|
struct spdk_nvmf_subsystem *subsystem,
|
|
|
|
spdk_nvmf_poll_group_mod_done cb_fn, void *cb_arg)
|
2017-11-20 17:45:39 +00:00
|
|
|
{
|
|
|
|
struct spdk_nvmf_subsystem_poll_group *sgroup;
|
2018-07-13 23:23:23 +00:00
|
|
|
int rc = 0;
|
2017-11-20 17:45:39 +00:00
|
|
|
|
2017-12-19 23:39:04 +00:00
|
|
|
if (subsystem->id >= group->num_sgroups) {
|
2018-07-13 23:23:23 +00:00
|
|
|
rc = -1;
|
|
|
|
goto fini;
|
2017-12-19 23:39:04 +00:00
|
|
|
}
|
2017-11-20 17:45:39 +00:00
|
|
|
|
2017-12-19 23:39:04 +00:00
|
|
|
sgroup = &group->sgroups[subsystem->id];
|
|
|
|
if (sgroup == NULL) {
|
2018-07-13 23:23:23 +00:00
|
|
|
rc = -1;
|
|
|
|
goto fini;
|
2017-12-19 23:39:04 +00:00
|
|
|
}
|
2017-11-20 17:45:39 +00:00
|
|
|
|
2017-12-19 23:39:04 +00:00
|
|
|
assert(sgroup->state == SPDK_NVMF_SUBSYSTEM_ACTIVE);
|
|
|
|
/* TODO: This currently does not quiesce I/O */
|
|
|
|
sgroup->state = SPDK_NVMF_SUBSYSTEM_PAUSED;
|
2018-07-13 23:23:23 +00:00
|
|
|
fini:
|
|
|
|
if (cb_fn) {
|
|
|
|
cb_fn(cb_arg, rc);
|
|
|
|
}
|
2017-12-19 23:39:04 +00:00
|
|
|
}
|
2017-11-20 17:45:39 +00:00
|
|
|
|
2018-07-13 23:23:23 +00:00
|
|
|
void
|
2017-12-19 23:39:04 +00:00
|
|
|
spdk_nvmf_poll_group_resume_subsystem(struct spdk_nvmf_poll_group *group,
|
2018-07-13 23:23:23 +00:00
|
|
|
struct spdk_nvmf_subsystem *subsystem,
|
|
|
|
spdk_nvmf_poll_group_mod_done cb_fn, void *cb_arg)
|
2017-12-19 23:39:04 +00:00
|
|
|
{
|
2018-04-04 16:16:39 +00:00
|
|
|
struct spdk_nvmf_request *req, *tmp;
|
|
|
|
struct spdk_nvmf_subsystem_poll_group *sgroup;
|
2018-07-13 23:23:23 +00:00
|
|
|
int rc = 0;
|
2017-11-20 17:45:39 +00:00
|
|
|
|
2017-12-19 23:39:04 +00:00
|
|
|
if (subsystem->id >= group->num_sgroups) {
|
2018-07-13 23:23:23 +00:00
|
|
|
rc = -1;
|
|
|
|
goto fini;
|
2017-11-20 17:45:39 +00:00
|
|
|
}
|
|
|
|
|
2018-04-04 16:16:39 +00:00
|
|
|
sgroup = &group->sgroups[subsystem->id];
|
|
|
|
|
|
|
|
assert(sgroup->state == SPDK_NVMF_SUBSYSTEM_PAUSED);
|
2017-12-19 23:39:04 +00:00
|
|
|
|
|
|
|
rc = poll_group_update_subsystem(group, subsystem);
|
|
|
|
if (rc) {
|
2018-07-13 23:23:23 +00:00
|
|
|
goto fini;
|
2017-11-20 17:45:39 +00:00
|
|
|
}
|
|
|
|
|
2018-04-04 16:16:39 +00:00
|
|
|
sgroup->state = SPDK_NVMF_SUBSYSTEM_ACTIVE;
|
|
|
|
|
|
|
|
/* Release all queued requests */
|
|
|
|
TAILQ_FOREACH_SAFE(req, &sgroup->queued, link, tmp) {
|
|
|
|
TAILQ_REMOVE(&sgroup->queued, req, link);
|
|
|
|
spdk_nvmf_request_exec(req);
|
|
|
|
}
|
2018-07-13 23:23:23 +00:00
|
|
|
fini:
|
|
|
|
if (cb_fn) {
|
|
|
|
cb_fn(cb_arg, rc);
|
|
|
|
}
|
2017-11-20 17:45:39 +00:00
|
|
|
}
|