2016-09-13 02:52:21 +00:00
|
|
|
/*-
|
|
|
|
* BSD LICENSE
|
|
|
|
*
|
nvmf/rdma: Add shared receive queue support
This is a new feature for NVMEoF RDMA target, that is intended to save
resource allocation (by sharing them) and utilize the
locality (completions and memory) to get the best performance with
Shared Receive Queues (SRQs). We'll create a SRQ per core (poll
group), per device and associate each created QP/CQ with an
appropriate SRQ.
Our testing environment has 2 hosts.
Host 1:
CPU: Intel(R) Xeon(R) CPU E5-2609 0 @ 2.40GHz dual socket (8 cores total)
Network: ConnectX-5, ConnectX-5 VPI , 100GbE, single-port QSFP28, PCIe3.0 x16
Disk: Intel Optane SSD 900P Series
OS: Fedora 27 x86_64
Host 2:
CPU: Intel(R) Xeon(R) CPU E5-2630 v2 @ 2.60GHz dual-socket (24 cores total)
Network: ConnectX-4 VPI , 100GbE, dual-port QSFP28
Disk: Intel Optane SSD 900P Series
OS : CentOS 7.5.1804 x86_64
Hosts are connected via Spectrum switch.
Host 1 is running SPDK NVMeoF target.
Host 2 is used as initiator running fio with SPDK plugin.
Configuration:
- SPDK NVMeoF target: cpu mask 0x0F (4 cores), max queue depth 128,
max SRQ depth 1024, max QPs per controller 1024
- Single NVMf subsystem with single namespace backed by physical SSD disk
- fio with SPDK plugin: randread pattern, 1-256 jobs, block size 4k,
IO depth 16, cpu_mask 0xFFF0, IO rate 10k, rate process “poisson”
Here is a full fio command line:
fio --name=Job --stats=1 --group_reporting=1 --idle-prof=percpu \
--loops=1 --numjobs=1 --thread=1 --time_based=1 --runtime=30s \
--ramp_time=5s --bs=4k --size=4G --iodepth=16 --readwrite=randread \
--rwmixread=75 --randrepeat=1 --ioengine=spdk --direct=1 \
--gtod_reduce=0 --cpumask=0xFFF0 --rate_iops=10k \
--rate_process=poisson \
--filename='trtype=RDMA adrfam=IPv4 traddr=1.1.79.1 trsvcid=4420 ns=1'
SPDK allocates the following entities for every work request in
receive queue (shared or not): reqs (1024 bytes), recvs (96 bytes),
cmds (64 bytes), cpls (16 bytes), in_capsule_buffer. All except the
last one are fixed size. In capsule data size is configured to 4096.
Memory consumption calculation (target):
- Multiple SRQ: core_num * ib_devs_num * SRQ_depth * (1200 +
in_capsule_data_size)
- Multiple RQ: queue_num * RQ_depth * (1200 + in_capsule_data_size)
We ignore admin queues in calculations for simplicity.
Cases:
1. Multiple SRQ with 1024 entries:
- Mem = 4 * 1 * 1024 * (1200 + 4096) = 20.7 MiB
(Constant number – does not depend on initiators number)
2. RQ with 128 entries for 64 initiators:
- Mem = 64 * 128 * (1200 + 4096) = 41.4 MiB
Results:
FIO_JOBS kIOPS Bandwidth,MiB/s AvgLatency,us MaxResidentSize,kiB
RQ SRQ RQ SRQ RQ SRQ RQ SRQ
1 8.623 8.623 33.7 33.7 13.89 14.03 144376 155624
2 17.3 17.3 67.4 67.4 14.03 14.1 145776 155700
4 34.5 34.5 135 135 14.15 14.23 146540 156184
8 69.1 69.1 270 270 14.64 14.49 148116 156960
16 138 138 540 540 14.84 15.38 151216 158668
32 276 276 1079 1079 16.5 16.61 157560 161936
64 513 502 2005 1960 1673 1612 170408 168440
128 535 526 2092 2054 3329 3344 195796 181524
256 571 571 2232 2233 6854 6873 246484 207856
We can see the benefit in memory consumption.
Change-Id: I40c70f6ccbad7754918bcc6cb397e955b09d1033
Signed-off-by: Evgeniy Kochetov <evgeniik@mellanox.com>
Signed-off-by: Sasha Kotchubievsky <sashakot@mellanox.com>
Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/428458
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>
2018-10-04 14:59:08 +00:00
|
|
|
* Copyright (c) Intel Corporation. All rights reserved.
|
|
|
|
* Copyright (c) 2018 Mellanox Technologies LTD. All rights reserved.
|
2016-09-13 02:52:21 +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.
|
|
|
|
*/
|
|
|
|
|
2018-03-08 20:26:44 +00:00
|
|
|
#include "event_nvmf.h"
|
2016-08-08 22:57:49 +00:00
|
|
|
|
2016-09-19 17:01:52 +00:00
|
|
|
#include "spdk/bdev.h"
|
2016-09-13 02:52:21 +00:00
|
|
|
#include "spdk/log.h"
|
|
|
|
#include "spdk/rpc.h"
|
2016-08-10 17:41:12 +00:00
|
|
|
#include "spdk/env.h"
|
2016-09-13 02:52:21 +00:00
|
|
|
#include "spdk/nvme.h"
|
2016-09-19 17:01:52 +00:00
|
|
|
#include "spdk/nvmf.h"
|
2018-02-21 23:04:17 +00:00
|
|
|
#include "spdk/string.h"
|
2017-03-03 20:44:04 +00:00
|
|
|
#include "spdk/util.h"
|
2016-09-19 17:01:52 +00:00
|
|
|
|
2018-02-13 00:03:01 +00:00
|
|
|
static int
|
|
|
|
json_write_hex_str(struct spdk_json_write_ctx *w, const void *data, size_t size)
|
|
|
|
{
|
|
|
|
static const char hex_char[16] = "0123456789ABCDEF";
|
|
|
|
const uint8_t *buf = data;
|
|
|
|
char *str, *out;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
str = malloc(size * 2 + 1);
|
|
|
|
if (str == NULL) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
out = str;
|
|
|
|
while (size--) {
|
|
|
|
unsigned byte = *buf++;
|
|
|
|
|
|
|
|
out[0] = hex_char[(byte >> 4) & 0xF];
|
|
|
|
out[1] = hex_char[byte & 0xF];
|
|
|
|
|
|
|
|
out += 2;
|
|
|
|
}
|
|
|
|
*out = '\0';
|
|
|
|
|
|
|
|
rc = spdk_json_write_string(w, str);
|
|
|
|
free(str);
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
hex_nybble_to_num(char c)
|
|
|
|
{
|
|
|
|
if (c >= '0' && c <= '9') {
|
|
|
|
return c - '0';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (c >= 'a' && c <= 'f') {
|
|
|
|
return c - 'a' + 0xA;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (c >= 'A' && c <= 'F') {
|
|
|
|
return c - 'A' + 0xA;
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
hex_byte_to_num(const char *str)
|
|
|
|
{
|
|
|
|
int hi, lo;
|
|
|
|
|
|
|
|
hi = hex_nybble_to_num(str[0]);
|
|
|
|
if (hi < 0) {
|
|
|
|
return hi;
|
|
|
|
}
|
|
|
|
|
|
|
|
lo = hex_nybble_to_num(str[1]);
|
|
|
|
if (lo < 0) {
|
|
|
|
return lo;
|
|
|
|
}
|
|
|
|
|
|
|
|
return hi * 16 + lo;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
decode_hex_string_be(const char *str, uint8_t *out, size_t size)
|
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
/* Decode a string in "ABCDEF012345" format to its binary representation */
|
|
|
|
for (i = 0; i < size; i++) {
|
|
|
|
int num = hex_byte_to_num(str);
|
|
|
|
|
|
|
|
if (num < 0) {
|
|
|
|
/* Invalid hex byte or end of string */
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
out[i] = (uint8_t)num;
|
|
|
|
str += 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i != size || *str != '\0') {
|
|
|
|
/* Length mismatch */
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
decode_ns_nguid(const struct spdk_json_val *val, void *out)
|
|
|
|
{
|
|
|
|
char *str = NULL;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
rc = spdk_json_decode_string(val, &str);
|
|
|
|
if (rc == 0) {
|
|
|
|
/* 16-byte NGUID */
|
|
|
|
rc = decode_hex_string_be(str, out, 16);
|
|
|
|
}
|
|
|
|
|
|
|
|
free(str);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
decode_ns_eui64(const struct spdk_json_val *val, void *out)
|
|
|
|
{
|
|
|
|
char *str = NULL;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
rc = spdk_json_decode_string(val, &str);
|
|
|
|
if (rc == 0) {
|
|
|
|
/* 8-byte EUI-64 */
|
|
|
|
rc = decode_hex_string_be(str, out, 8);
|
|
|
|
}
|
|
|
|
|
|
|
|
free(str);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2018-06-07 21:58:17 +00:00
|
|
|
static int
|
|
|
|
decode_ns_uuid(const struct spdk_json_val *val, void *out)
|
|
|
|
{
|
|
|
|
char *str = NULL;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
rc = spdk_json_decode_string(val, &str);
|
|
|
|
if (rc == 0) {
|
|
|
|
rc = spdk_uuid_parse(out, str);
|
|
|
|
}
|
|
|
|
|
|
|
|
free(str);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2016-09-13 02:52:21 +00:00
|
|
|
static void
|
2017-11-20 18:36:36 +00:00
|
|
|
dump_nvmf_subsystem(struct spdk_json_write_ctx *w, struct spdk_nvmf_subsystem *subsystem)
|
2016-09-13 02:52:21 +00:00
|
|
|
{
|
|
|
|
struct spdk_nvmf_host *host;
|
2018-03-02 19:49:36 +00:00
|
|
|
struct spdk_nvmf_listener *listener;
|
2016-09-13 02:52:21 +00:00
|
|
|
|
|
|
|
spdk_json_write_object_begin(w);
|
|
|
|
|
2019-02-01 06:04:54 +00:00
|
|
|
spdk_json_write_named_string(w, "nqn", spdk_nvmf_subsystem_get_nqn(subsystem));
|
2016-09-13 02:52:21 +00:00
|
|
|
spdk_json_write_name(w, "subtype");
|
2016-10-10 17:25:01 +00:00
|
|
|
if (spdk_nvmf_subsystem_get_type(subsystem) == SPDK_NVMF_SUBTYPE_NVME) {
|
2016-09-13 02:52:21 +00:00
|
|
|
spdk_json_write_string(w, "NVMe");
|
|
|
|
} else {
|
|
|
|
spdk_json_write_string(w, "Discovery");
|
|
|
|
}
|
|
|
|
|
2019-02-01 06:04:54 +00:00
|
|
|
spdk_json_write_named_array_begin(w, "listen_addresses");
|
2016-09-13 02:52:21 +00:00
|
|
|
|
2017-08-18 21:43:15 +00:00
|
|
|
for (listener = spdk_nvmf_subsystem_get_first_listener(subsystem); listener != NULL;
|
|
|
|
listener = spdk_nvmf_subsystem_get_next_listener(subsystem, listener)) {
|
|
|
|
const struct spdk_nvme_transport_id *trid;
|
2017-10-20 22:45:29 +00:00
|
|
|
const char *trtype;
|
|
|
|
const char *adrfam;
|
2017-08-18 21:43:15 +00:00
|
|
|
|
|
|
|
trid = spdk_nvmf_listener_get_trid(listener);
|
2017-06-28 20:13:11 +00:00
|
|
|
|
2016-09-13 02:52:21 +00:00
|
|
|
spdk_json_write_object_begin(w);
|
2017-10-20 22:45:29 +00:00
|
|
|
trtype = spdk_nvme_transport_id_trtype_str(trid->trtype);
|
|
|
|
if (trtype == NULL) {
|
|
|
|
trtype = "unknown";
|
|
|
|
}
|
|
|
|
adrfam = spdk_nvme_transport_id_adrfam_str(trid->adrfam);
|
|
|
|
if (adrfam == NULL) {
|
|
|
|
adrfam = "unknown";
|
|
|
|
}
|
2017-06-28 18:07:41 +00:00
|
|
|
/* NOTE: "transport" is kept for compatibility; new code should use "trtype" */
|
2019-02-01 06:04:54 +00:00
|
|
|
spdk_json_write_named_string(w, "transport", trtype);
|
|
|
|
spdk_json_write_named_string(w, "trtype", trtype);
|
|
|
|
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);
|
2016-09-13 02:52:21 +00:00
|
|
|
spdk_json_write_object_end(w);
|
|
|
|
}
|
|
|
|
spdk_json_write_array_end(w);
|
|
|
|
|
2019-02-01 06:04:54 +00:00
|
|
|
spdk_json_write_named_bool(w, "allow_any_host",
|
|
|
|
spdk_nvmf_subsystem_get_allow_any_host(subsystem));
|
2017-08-30 20:21:12 +00:00
|
|
|
|
2019-02-01 06:04:54 +00:00
|
|
|
spdk_json_write_named_array_begin(w, "hosts");
|
2016-09-13 02:52:21 +00:00
|
|
|
|
2017-08-18 21:08:29 +00:00
|
|
|
for (host = spdk_nvmf_subsystem_get_first_host(subsystem); host != NULL;
|
|
|
|
host = spdk_nvmf_subsystem_get_next_host(subsystem, host)) {
|
2016-09-13 02:52:21 +00:00
|
|
|
spdk_json_write_object_begin(w);
|
2019-02-01 06:04:54 +00:00
|
|
|
spdk_json_write_named_string(w, "nqn", spdk_nvmf_host_get_nqn(host));
|
2016-09-13 02:52:21 +00:00
|
|
|
spdk_json_write_object_end(w);
|
|
|
|
}
|
|
|
|
spdk_json_write_array_end(w);
|
|
|
|
|
2016-10-10 17:25:01 +00:00
|
|
|
if (spdk_nvmf_subsystem_get_type(subsystem) == SPDK_NVMF_SUBTYPE_NVME) {
|
2017-08-18 01:20:49 +00:00
|
|
|
struct spdk_nvmf_ns *ns;
|
2018-02-13 00:03:01 +00:00
|
|
|
struct spdk_nvmf_ns_opts ns_opts;
|
2018-06-12 17:11:45 +00:00
|
|
|
uint32_t max_namespaces;
|
2017-06-27 18:26:19 +00:00
|
|
|
|
2019-02-01 06:04:54 +00:00
|
|
|
spdk_json_write_named_string(w, "serial_number", spdk_nvmf_subsystem_get_sn(subsystem));
|
2018-06-12 17:11:45 +00:00
|
|
|
|
2018-12-29 19:39:48 +00:00
|
|
|
spdk_json_write_named_string(w, "model_number", spdk_nvmf_subsystem_get_mn(subsystem));
|
|
|
|
|
2018-06-12 17:11:45 +00:00
|
|
|
max_namespaces = spdk_nvmf_subsystem_get_max_namespaces(subsystem);
|
|
|
|
if (max_namespaces != 0) {
|
|
|
|
spdk_json_write_named_uint32(w, "max_namespaces", max_namespaces);
|
|
|
|
}
|
|
|
|
|
2019-02-01 06:04:54 +00:00
|
|
|
spdk_json_write_named_array_begin(w, "namespaces");
|
2017-08-18 01:20:49 +00:00
|
|
|
for (ns = spdk_nvmf_subsystem_get_first_ns(subsystem); ns != NULL;
|
|
|
|
ns = spdk_nvmf_subsystem_get_next_ns(subsystem, ns)) {
|
2018-02-13 00:03:01 +00:00
|
|
|
spdk_nvmf_ns_get_opts(ns, &ns_opts, sizeof(ns_opts));
|
2017-06-27 18:26:19 +00:00
|
|
|
spdk_json_write_object_begin(w);
|
2019-02-01 06:04:54 +00:00
|
|
|
spdk_json_write_named_int32(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)));
|
2017-08-30 23:55:48 +00:00
|
|
|
/* NOTE: "name" is kept for compatibility only - new code should use bdev_name. */
|
2019-02-01 06:04:54 +00:00
|
|
|
spdk_json_write_named_string(w, "name",
|
|
|
|
spdk_bdev_get_name(spdk_nvmf_ns_get_bdev(ns)));
|
2018-02-13 00:03:01 +00:00
|
|
|
|
2018-02-21 23:04:17 +00:00
|
|
|
if (!spdk_mem_all_zero(ns_opts.nguid, sizeof(ns_opts.nguid))) {
|
2018-02-13 00:03:01 +00:00
|
|
|
spdk_json_write_name(w, "nguid");
|
|
|
|
json_write_hex_str(w, ns_opts.nguid, sizeof(ns_opts.nguid));
|
|
|
|
}
|
|
|
|
|
2018-02-21 23:04:17 +00:00
|
|
|
if (!spdk_mem_all_zero(ns_opts.eui64, sizeof(ns_opts.eui64))) {
|
2018-02-13 00:03:01 +00:00
|
|
|
spdk_json_write_name(w, "eui64");
|
|
|
|
json_write_hex_str(w, ns_opts.eui64, sizeof(ns_opts.eui64));
|
|
|
|
}
|
|
|
|
|
2018-02-22 00:09:56 +00:00
|
|
|
if (!spdk_mem_all_zero(&ns_opts.uuid, sizeof(ns_opts.uuid))) {
|
|
|
|
char uuid_str[SPDK_UUID_STRING_LEN];
|
|
|
|
|
|
|
|
spdk_uuid_fmt_lower(uuid_str, sizeof(uuid_str), &ns_opts.uuid);
|
2019-02-01 06:04:54 +00:00
|
|
|
spdk_json_write_named_string(w, "uuid", uuid_str);
|
2018-02-22 00:09:56 +00:00
|
|
|
}
|
|
|
|
|
2017-06-27 18:26:19 +00:00
|
|
|
spdk_json_write_object_end(w);
|
2016-09-13 02:52:21 +00:00
|
|
|
}
|
2017-06-27 18:26:19 +00:00
|
|
|
spdk_json_write_array_end(w);
|
2016-09-13 02:52:21 +00:00
|
|
|
}
|
|
|
|
spdk_json_write_object_end(w);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2017-06-29 20:37:39 +00:00
|
|
|
spdk_rpc_get_nvmf_subsystems(struct spdk_jsonrpc_request *request,
|
|
|
|
const struct spdk_json_val *params)
|
2016-09-13 02:52:21 +00:00
|
|
|
{
|
|
|
|
struct spdk_json_write_ctx *w;
|
2017-11-20 18:36:36 +00:00
|
|
|
struct spdk_nvmf_subsystem *subsystem;
|
2016-09-13 02:52:21 +00:00
|
|
|
|
|
|
|
if (params != NULL) {
|
2017-06-29 20:37:39 +00:00
|
|
|
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
|
2016-09-13 02:52:21 +00:00
|
|
|
"get_nvmf_subsystems requires no parameters");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-06-29 20:37:39 +00:00
|
|
|
w = spdk_jsonrpc_begin_result(request);
|
|
|
|
if (w == NULL) {
|
2016-09-13 02:52:21 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
spdk_json_write_array_begin(w);
|
2018-03-10 00:33:41 +00:00
|
|
|
subsystem = spdk_nvmf_subsystem_get_first(g_spdk_nvmf_tgt);
|
2017-11-20 18:36:36 +00:00
|
|
|
while (subsystem) {
|
|
|
|
dump_nvmf_subsystem(w, subsystem);
|
|
|
|
subsystem = spdk_nvmf_subsystem_get_next(subsystem);
|
2016-09-13 02:52:21 +00:00
|
|
|
}
|
|
|
|
spdk_json_write_array_end(w);
|
2017-06-29 20:37:39 +00:00
|
|
|
spdk_jsonrpc_end_result(request, w);
|
2016-09-13 02:52:21 +00:00
|
|
|
}
|
2018-05-02 04:28:57 +00:00
|
|
|
SPDK_RPC_REGISTER("get_nvmf_subsystems", spdk_rpc_get_nvmf_subsystems, SPDK_RPC_RUNTIME)
|
2016-09-13 02:52:21 +00:00
|
|
|
|
2018-09-10 18:03:46 +00:00
|
|
|
struct rpc_subsystem_create {
|
2016-09-13 02:52:21 +00:00
|
|
|
char *nqn;
|
|
|
|
char *serial_number;
|
2018-12-29 19:39:48 +00:00
|
|
|
char *model_number;
|
2018-09-10 18:03:46 +00:00
|
|
|
uint32_t max_namespaces;
|
|
|
|
bool allow_any_host;
|
2016-09-13 02:52:21 +00:00
|
|
|
};
|
|
|
|
|
2018-09-10 18:03:46 +00:00
|
|
|
static const struct spdk_json_object_decoder rpc_subsystem_create_decoders[] = {
|
|
|
|
{"nqn", offsetof(struct rpc_subsystem_create, nqn), spdk_json_decode_string},
|
|
|
|
{"serial_number", offsetof(struct rpc_subsystem_create, serial_number), spdk_json_decode_string, true},
|
2018-12-29 19:39:48 +00:00
|
|
|
{"model_number", offsetof(struct rpc_subsystem_create, model_number), spdk_json_decode_string, true},
|
2018-09-10 18:03:46 +00:00
|
|
|
{"max_namespaces", offsetof(struct rpc_subsystem_create, max_namespaces), spdk_json_decode_uint32, true},
|
|
|
|
{"allow_any_host", offsetof(struct rpc_subsystem_create, allow_any_host), spdk_json_decode_bool, true},
|
|
|
|
};
|
2016-09-13 02:52:21 +00:00
|
|
|
|
2017-12-19 23:39:04 +00:00
|
|
|
static void
|
|
|
|
spdk_rpc_nvmf_subsystem_started(struct spdk_nvmf_subsystem *subsystem,
|
|
|
|
void *cb_arg, int status)
|
|
|
|
{
|
|
|
|
struct spdk_jsonrpc_request *request = cb_arg;
|
|
|
|
struct spdk_json_write_ctx *w;
|
|
|
|
|
|
|
|
w = spdk_jsonrpc_begin_result(request);
|
|
|
|
if (w == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
spdk_json_write_bool(w, true);
|
|
|
|
spdk_jsonrpc_end_result(request, w);
|
|
|
|
}
|
|
|
|
|
2018-09-10 17:40:19 +00:00
|
|
|
static void
|
|
|
|
spdk_rpc_nvmf_subsystem_create(struct spdk_jsonrpc_request *request,
|
|
|
|
const struct spdk_json_val *params)
|
|
|
|
{
|
|
|
|
struct rpc_subsystem_create *req;
|
|
|
|
struct spdk_nvmf_subsystem *subsystem;
|
|
|
|
|
|
|
|
req = calloc(1, sizeof(*req));
|
|
|
|
if (!req) {
|
|
|
|
goto invalid;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (spdk_json_decode_object(params, rpc_subsystem_create_decoders,
|
|
|
|
SPDK_COUNTOF(rpc_subsystem_create_decoders),
|
|
|
|
req)) {
|
|
|
|
SPDK_ERRLOG("spdk_json_decode_object failed\n");
|
|
|
|
goto invalid;
|
|
|
|
}
|
|
|
|
|
|
|
|
subsystem = spdk_nvmf_subsystem_create(g_spdk_nvmf_tgt, req->nqn, SPDK_NVMF_SUBTYPE_NVME,
|
|
|
|
req->max_namespaces);
|
|
|
|
if (!subsystem) {
|
|
|
|
goto invalid;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (req->serial_number) {
|
|
|
|
if (spdk_nvmf_subsystem_set_sn(subsystem, req->serial_number)) {
|
|
|
|
SPDK_ERRLOG("Subsystem %s: invalid serial number '%s'\n", req->nqn, req->serial_number);
|
|
|
|
goto invalid;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-29 19:39:48 +00:00
|
|
|
if (req->model_number) {
|
|
|
|
if (spdk_nvmf_subsystem_set_mn(subsystem, req->model_number)) {
|
|
|
|
SPDK_ERRLOG("Subsystem %s: invalid model number '%s'\n", req->nqn, req->model_number);
|
|
|
|
goto invalid;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-10 17:40:19 +00:00
|
|
|
spdk_nvmf_subsystem_set_allow_any_host(subsystem, req->allow_any_host);
|
|
|
|
|
|
|
|
free(req->nqn);
|
|
|
|
free(req->serial_number);
|
2018-12-29 19:39:48 +00:00
|
|
|
free(req->model_number);
|
2018-09-10 17:40:19 +00:00
|
|
|
free(req);
|
|
|
|
|
|
|
|
spdk_nvmf_subsystem_start(subsystem,
|
|
|
|
spdk_rpc_nvmf_subsystem_started,
|
|
|
|
request);
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
invalid:
|
|
|
|
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, "Invalid parameters");
|
|
|
|
if (req) {
|
|
|
|
free(req->nqn);
|
|
|
|
free(req->serial_number);
|
2018-12-29 19:39:48 +00:00
|
|
|
free(req->model_number);
|
2018-09-10 17:40:19 +00:00
|
|
|
}
|
|
|
|
free(req);
|
|
|
|
}
|
|
|
|
SPDK_RPC_REGISTER("nvmf_subsystem_create", spdk_rpc_nvmf_subsystem_create, SPDK_RPC_RUNTIME)
|
|
|
|
|
2016-09-13 02:52:21 +00:00
|
|
|
struct rpc_delete_subsystem {
|
|
|
|
char *nqn;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
free_rpc_delete_subsystem(struct rpc_delete_subsystem *r)
|
|
|
|
{
|
|
|
|
free(r->nqn);
|
|
|
|
}
|
|
|
|
|
2017-12-19 23:39:04 +00:00
|
|
|
static void
|
|
|
|
spdk_rpc_nvmf_subsystem_stopped(struct spdk_nvmf_subsystem *subsystem,
|
|
|
|
void *cb_arg, int status)
|
|
|
|
{
|
|
|
|
struct spdk_jsonrpc_request *request = cb_arg;
|
|
|
|
struct spdk_json_write_ctx *w;
|
|
|
|
|
|
|
|
spdk_nvmf_subsystem_destroy(subsystem);
|
|
|
|
|
|
|
|
w = spdk_jsonrpc_begin_result(request);
|
|
|
|
if (w == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
spdk_json_write_bool(w, true);
|
|
|
|
spdk_jsonrpc_end_result(request, w);
|
|
|
|
}
|
|
|
|
|
2016-09-13 02:52:21 +00:00
|
|
|
static const struct spdk_json_object_decoder rpc_delete_subsystem_decoders[] = {
|
|
|
|
{"nqn", offsetof(struct rpc_delete_subsystem, nqn), spdk_json_decode_string},
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
2017-06-29 20:37:39 +00:00
|
|
|
spdk_rpc_delete_nvmf_subsystem(struct spdk_jsonrpc_request *request,
|
|
|
|
const struct spdk_json_val *params)
|
2016-09-13 02:52:21 +00:00
|
|
|
{
|
|
|
|
struct rpc_delete_subsystem req = {};
|
2017-12-19 23:39:04 +00:00
|
|
|
struct spdk_nvmf_subsystem *subsystem;
|
2016-09-13 02:52:21 +00:00
|
|
|
|
|
|
|
if (spdk_json_decode_object(params, rpc_delete_subsystem_decoders,
|
2017-03-03 20:44:04 +00:00
|
|
|
SPDK_COUNTOF(rpc_delete_subsystem_decoders),
|
2016-09-13 02:52:21 +00:00
|
|
|
&req)) {
|
2016-11-07 21:58:55 +00:00
|
|
|
SPDK_ERRLOG("spdk_json_decode_object failed\n");
|
2016-09-13 02:52:21 +00:00
|
|
|
goto invalid;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (req.nqn == NULL) {
|
2016-11-07 21:58:55 +00:00
|
|
|
SPDK_ERRLOG("missing name param\n");
|
2016-09-13 02:52:21 +00:00
|
|
|
goto invalid;
|
|
|
|
}
|
|
|
|
|
2018-03-10 00:33:41 +00:00
|
|
|
subsystem = spdk_nvmf_tgt_find_subsystem(g_spdk_nvmf_tgt, req.nqn);
|
2017-12-19 23:39:04 +00:00
|
|
|
if (!subsystem) {
|
2016-09-13 02:52:21 +00:00
|
|
|
goto invalid;
|
|
|
|
}
|
|
|
|
|
|
|
|
free_rpc_delete_subsystem(&req);
|
|
|
|
|
2017-12-19 23:39:04 +00:00
|
|
|
spdk_nvmf_subsystem_stop(subsystem,
|
|
|
|
spdk_rpc_nvmf_subsystem_stopped,
|
|
|
|
request);
|
2016-09-13 02:52:21 +00:00
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
invalid:
|
2017-06-29 20:37:39 +00:00
|
|
|
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, "Invalid parameters");
|
2016-09-13 02:52:21 +00:00
|
|
|
free_rpc_delete_subsystem(&req);
|
|
|
|
}
|
2018-05-02 04:28:57 +00:00
|
|
|
SPDK_RPC_REGISTER("delete_nvmf_subsystem", spdk_rpc_delete_nvmf_subsystem, SPDK_RPC_RUNTIME)
|
2018-01-17 22:35:58 +00:00
|
|
|
|
2018-09-10 18:03:46 +00:00
|
|
|
struct rpc_listen_address {
|
|
|
|
char *transport;
|
|
|
|
char *adrfam;
|
|
|
|
char *traddr;
|
|
|
|
char *trsvcid;
|
|
|
|
};
|
|
|
|
|
|
|
|
#define RPC_MAX_LISTEN_ADDRESSES 255
|
|
|
|
#define RPC_MAX_NAMESPACES 255
|
|
|
|
|
|
|
|
struct rpc_listen_addresses {
|
|
|
|
size_t num_listen_address;
|
|
|
|
struct rpc_listen_address addresses[RPC_MAX_LISTEN_ADDRESSES];
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct spdk_json_object_decoder rpc_listen_address_decoders[] = {
|
|
|
|
/* NOTE: "transport" is kept for compatibility; new code should use "trtype" */
|
|
|
|
{"transport", offsetof(struct rpc_listen_address, transport), spdk_json_decode_string, true},
|
|
|
|
{"trtype", offsetof(struct rpc_listen_address, transport), spdk_json_decode_string, true},
|
|
|
|
{"adrfam", offsetof(struct rpc_listen_address, adrfam), spdk_json_decode_string, true},
|
|
|
|
{"traddr", offsetof(struct rpc_listen_address, traddr), spdk_json_decode_string},
|
|
|
|
{"trsvcid", offsetof(struct rpc_listen_address, trsvcid), spdk_json_decode_string},
|
|
|
|
};
|
|
|
|
|
|
|
|
static int
|
|
|
|
decode_rpc_listen_address(const struct spdk_json_val *val, void *out)
|
|
|
|
{
|
|
|
|
struct rpc_listen_address *req = (struct rpc_listen_address *)out;
|
|
|
|
if (spdk_json_decode_object(val, rpc_listen_address_decoders,
|
|
|
|
SPDK_COUNTOF(rpc_listen_address_decoders),
|
|
|
|
req)) {
|
|
|
|
SPDK_ERRLOG("spdk_json_decode_object failed\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
free_rpc_listen_address(struct rpc_listen_address *r)
|
|
|
|
{
|
|
|
|
free(r->transport);
|
|
|
|
free(r->adrfam);
|
|
|
|
free(r->traddr);
|
|
|
|
free(r->trsvcid);
|
|
|
|
}
|
|
|
|
|
2018-03-08 17:20:10 +00:00
|
|
|
enum nvmf_rpc_listen_op {
|
|
|
|
NVMF_RPC_LISTEN_ADD,
|
|
|
|
NVMF_RPC_LISTEN_REMOVE,
|
|
|
|
};
|
|
|
|
|
2018-01-17 22:35:58 +00:00
|
|
|
struct nvmf_rpc_listener_ctx {
|
2018-02-07 22:27:53 +00:00
|
|
|
char *nqn;
|
2018-04-03 18:35:04 +00:00
|
|
|
struct spdk_nvmf_subsystem *subsystem;
|
2018-01-17 22:35:58 +00:00
|
|
|
struct rpc_listen_address address;
|
|
|
|
|
|
|
|
struct spdk_jsonrpc_request *request;
|
|
|
|
struct spdk_nvme_transport_id trid;
|
2018-03-08 17:20:10 +00:00
|
|
|
enum nvmf_rpc_listen_op op;
|
2018-01-17 22:35:58 +00:00
|
|
|
bool response_sent;
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct spdk_json_object_decoder nvmf_rpc_listener_decoder[] = {
|
2018-02-07 22:27:53 +00:00
|
|
|
{"nqn", offsetof(struct nvmf_rpc_listener_ctx, nqn), spdk_json_decode_string},
|
2018-01-17 22:35:58 +00:00
|
|
|
{"listen_address", offsetof(struct nvmf_rpc_listener_ctx, address), decode_rpc_listen_address},
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
nvmf_rpc_listener_ctx_free(struct nvmf_rpc_listener_ctx *ctx)
|
|
|
|
{
|
2018-02-07 22:27:53 +00:00
|
|
|
free(ctx->nqn);
|
2018-01-17 22:35:58 +00:00
|
|
|
free_rpc_listen_address(&ctx->address);
|
|
|
|
free(ctx);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
nvmf_rpc_listen_resumed(struct spdk_nvmf_subsystem *subsystem,
|
|
|
|
void *cb_arg, int status)
|
|
|
|
{
|
|
|
|
struct nvmf_rpc_listener_ctx *ctx = cb_arg;
|
|
|
|
struct spdk_jsonrpc_request *request;
|
|
|
|
struct spdk_json_write_ctx *w;
|
|
|
|
|
|
|
|
request = ctx->request;
|
|
|
|
if (ctx->response_sent) {
|
|
|
|
/* If an error occurred, the response has already been sent. */
|
|
|
|
nvmf_rpc_listener_ctx_free(ctx);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nvmf_rpc_listener_ctx_free(ctx);
|
|
|
|
|
|
|
|
w = spdk_jsonrpc_begin_result(request);
|
|
|
|
if (w == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
spdk_json_write_bool(w, true);
|
|
|
|
spdk_jsonrpc_end_result(request, w);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2018-04-03 18:35:04 +00:00
|
|
|
nvmf_rpc_tgt_listen(void *cb_arg, int status)
|
2018-01-17 22:35:58 +00:00
|
|
|
{
|
|
|
|
struct nvmf_rpc_listener_ctx *ctx = cb_arg;
|
|
|
|
|
2018-04-03 18:35:04 +00:00
|
|
|
if (status) {
|
|
|
|
spdk_jsonrpc_send_error_response(ctx->request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
|
|
|
|
"Invalid parameters");
|
|
|
|
ctx->response_sent = true;
|
|
|
|
} else {
|
|
|
|
if (spdk_nvmf_subsystem_add_listener(ctx->subsystem, &ctx->trid)) {
|
|
|
|
spdk_jsonrpc_send_error_response(ctx->request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
|
|
|
|
"Invalid parameters");
|
|
|
|
ctx->response_sent = true;
|
2018-03-08 17:20:10 +00:00
|
|
|
}
|
2018-04-03 18:35:04 +00:00
|
|
|
}
|
2018-01-17 22:35:58 +00:00
|
|
|
|
2018-04-03 18:35:04 +00:00
|
|
|
if (spdk_nvmf_subsystem_resume(ctx->subsystem, nvmf_rpc_listen_resumed, ctx)) {
|
|
|
|
if (!ctx->response_sent) {
|
|
|
|
spdk_jsonrpc_send_error_response(ctx->request, SPDK_JSONRPC_ERROR_INTERNAL_ERROR, "Internal error");
|
2018-03-08 17:20:10 +00:00
|
|
|
}
|
2018-04-03 18:35:04 +00:00
|
|
|
nvmf_rpc_listener_ctx_free(ctx);
|
|
|
|
/* Can't really do anything to recover here - subsystem will remain paused. */
|
|
|
|
}
|
|
|
|
}
|
2018-03-08 17:20:10 +00:00
|
|
|
|
2018-04-03 18:35:04 +00:00
|
|
|
static void
|
|
|
|
nvmf_rpc_listen_paused(struct spdk_nvmf_subsystem *subsystem,
|
|
|
|
void *cb_arg, int status)
|
|
|
|
{
|
|
|
|
struct nvmf_rpc_listener_ctx *ctx = cb_arg;
|
|
|
|
|
|
|
|
if (ctx->op == NVMF_RPC_LISTEN_ADD) {
|
|
|
|
spdk_nvmf_tgt_listen(g_spdk_nvmf_tgt, &ctx->trid, nvmf_rpc_tgt_listen, ctx);
|
|
|
|
return;
|
2018-03-08 17:20:10 +00:00
|
|
|
} else if (ctx->op == NVMF_RPC_LISTEN_REMOVE) {
|
|
|
|
if (spdk_nvmf_subsystem_remove_listener(subsystem, &ctx->trid)) {
|
|
|
|
SPDK_ERRLOG("Unable to remove listener.\n");
|
2018-04-03 18:35:04 +00:00
|
|
|
spdk_jsonrpc_send_error_response(ctx->request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
|
|
|
|
"Invalid parameters");
|
|
|
|
ctx->response_sent = true;
|
2018-03-08 17:20:10 +00:00
|
|
|
}
|
|
|
|
} else {
|
2018-04-03 18:35:04 +00:00
|
|
|
spdk_jsonrpc_send_error_response(ctx->request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
|
|
|
|
"Invalid parameters");
|
|
|
|
ctx->response_sent = true;
|
2018-01-17 22:35:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (spdk_nvmf_subsystem_resume(subsystem, nvmf_rpc_listen_resumed, ctx)) {
|
2018-04-03 18:35:04 +00:00
|
|
|
if (!ctx->response_sent) {
|
|
|
|
spdk_jsonrpc_send_error_response(ctx->request, SPDK_JSONRPC_ERROR_INTERNAL_ERROR, "Internal error");
|
|
|
|
}
|
|
|
|
nvmf_rpc_listener_ctx_free(ctx);
|
2018-01-17 22:35:58 +00:00
|
|
|
/* Can't really do anything to recover here - subsystem will remain paused. */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-10 18:03:46 +00:00
|
|
|
static int
|
|
|
|
rpc_listen_address_to_trid(const struct rpc_listen_address *address,
|
|
|
|
struct spdk_nvme_transport_id *trid)
|
|
|
|
{
|
|
|
|
size_t len;
|
|
|
|
|
|
|
|
memset(trid, 0, sizeof(*trid));
|
|
|
|
|
|
|
|
if (spdk_nvme_transport_id_parse_trtype(&trid->trtype, address->transport)) {
|
|
|
|
SPDK_ERRLOG("Invalid transport type: %s\n", address->transport);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (address->adrfam) {
|
|
|
|
if (spdk_nvme_transport_id_parse_adrfam(&trid->adrfam, address->adrfam)) {
|
|
|
|
SPDK_ERRLOG("Invalid adrfam: %s\n", address->adrfam);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
trid->adrfam = SPDK_NVMF_ADRFAM_IPV4;
|
|
|
|
}
|
|
|
|
|
|
|
|
len = strlen(address->traddr);
|
|
|
|
if (len > sizeof(trid->traddr) - 1) {
|
|
|
|
SPDK_ERRLOG("Transport address longer than %zu characters: %s\n",
|
|
|
|
sizeof(trid->traddr) - 1, address->traddr);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
memcpy(trid->traddr, address->traddr, len + 1);
|
|
|
|
|
|
|
|
len = strlen(address->trsvcid);
|
|
|
|
if (len > sizeof(trid->trsvcid) - 1) {
|
|
|
|
SPDK_ERRLOG("Transport service id longer than %zu characters: %s\n",
|
|
|
|
sizeof(trid->trsvcid) - 1, address->trsvcid);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
memcpy(trid->trsvcid, address->trsvcid, len + 1);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-01-17 22:35:58 +00:00
|
|
|
static void
|
2019-05-06 03:54:05 +00:00
|
|
|
spdk_rpc_nvmf_subsystem_add_listener(struct spdk_jsonrpc_request *request,
|
|
|
|
const struct spdk_json_val *params)
|
2018-01-17 22:35:58 +00:00
|
|
|
{
|
|
|
|
struct nvmf_rpc_listener_ctx *ctx;
|
|
|
|
struct spdk_nvmf_subsystem *subsystem;
|
|
|
|
|
|
|
|
ctx = calloc(1, sizeof(*ctx));
|
|
|
|
if (!ctx) {
|
|
|
|
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INTERNAL_ERROR, "Out of memory");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx->request = request;
|
|
|
|
|
|
|
|
if (spdk_json_decode_object(params, nvmf_rpc_listener_decoder,
|
|
|
|
SPDK_COUNTOF(nvmf_rpc_listener_decoder),
|
|
|
|
ctx)) {
|
|
|
|
SPDK_ERRLOG("spdk_json_decode_object failed\n");
|
|
|
|
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, "Invalid parameters");
|
|
|
|
nvmf_rpc_listener_ctx_free(ctx);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-03-10 00:33:41 +00:00
|
|
|
subsystem = spdk_nvmf_tgt_find_subsystem(g_spdk_nvmf_tgt, ctx->nqn);
|
2018-01-17 22:35:58 +00:00
|
|
|
if (!subsystem) {
|
2018-02-07 22:27:53 +00:00
|
|
|
SPDK_ERRLOG("Unable to find subsystem with NQN %s\n", ctx->nqn);
|
2018-01-17 22:35:58 +00:00
|
|
|
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, "Invalid parameters");
|
|
|
|
nvmf_rpc_listener_ctx_free(ctx);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-04-03 18:35:04 +00:00
|
|
|
ctx->subsystem = subsystem;
|
|
|
|
|
2018-02-06 17:04:06 +00:00
|
|
|
if (rpc_listen_address_to_trid(&ctx->address, &ctx->trid)) {
|
2018-01-17 22:35:58 +00:00
|
|
|
spdk_jsonrpc_send_error_response(ctx->request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
|
|
|
|
"Invalid parameters");
|
|
|
|
nvmf_rpc_listener_ctx_free(ctx);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-03-08 17:20:10 +00:00
|
|
|
ctx->op = NVMF_RPC_LISTEN_ADD;
|
|
|
|
|
2018-01-17 22:35:58 +00:00
|
|
|
if (spdk_nvmf_subsystem_pause(subsystem, nvmf_rpc_listen_paused, ctx)) {
|
|
|
|
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INTERNAL_ERROR, "Internal error");
|
|
|
|
nvmf_rpc_listener_ctx_free(ctx);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2019-05-06 03:54:05 +00:00
|
|
|
SPDK_RPC_REGISTER("nvmf_subsystem_add_listener", spdk_rpc_nvmf_subsystem_add_listener,
|
|
|
|
SPDK_RPC_RUNTIME);
|
2018-01-23 22:51:28 +00:00
|
|
|
|
2018-03-08 17:20:10 +00:00
|
|
|
static void
|
2019-05-06 03:54:05 +00:00
|
|
|
spdk_rpc_nvmf_subsystem_remove_listener(struct spdk_jsonrpc_request *request,
|
|
|
|
const struct spdk_json_val *params)
|
2018-03-08 17:20:10 +00:00
|
|
|
{
|
|
|
|
struct nvmf_rpc_listener_ctx *ctx;
|
|
|
|
struct spdk_nvmf_subsystem *subsystem;
|
|
|
|
|
|
|
|
ctx = calloc(1, sizeof(*ctx));
|
|
|
|
if (!ctx) {
|
|
|
|
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INTERNAL_ERROR, "Out of memory");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx->request = request;
|
|
|
|
|
|
|
|
if (spdk_json_decode_object(params, nvmf_rpc_listener_decoder,
|
|
|
|
SPDK_COUNTOF(nvmf_rpc_listener_decoder),
|
|
|
|
ctx)) {
|
|
|
|
SPDK_ERRLOG("spdk_json_decode_object failed\n");
|
|
|
|
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, "Invalid parameters");
|
|
|
|
nvmf_rpc_listener_ctx_free(ctx);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-03-10 00:33:41 +00:00
|
|
|
subsystem = spdk_nvmf_tgt_find_subsystem(g_spdk_nvmf_tgt, ctx->nqn);
|
2018-03-08 17:20:10 +00:00
|
|
|
if (!subsystem) {
|
|
|
|
SPDK_ERRLOG("Unable to find subsystem with NQN %s\n", ctx->nqn);
|
|
|
|
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, "Invalid parameters");
|
|
|
|
nvmf_rpc_listener_ctx_free(ctx);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-04-03 18:35:04 +00:00
|
|
|
ctx->subsystem = subsystem;
|
|
|
|
|
2018-03-08 17:20:10 +00:00
|
|
|
if (rpc_listen_address_to_trid(&ctx->address, &ctx->trid)) {
|
|
|
|
spdk_jsonrpc_send_error_response(ctx->request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
|
|
|
|
"Invalid parameters");
|
|
|
|
nvmf_rpc_listener_ctx_free(ctx);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx->op = NVMF_RPC_LISTEN_REMOVE;
|
|
|
|
|
|
|
|
if (spdk_nvmf_subsystem_pause(subsystem, nvmf_rpc_listen_paused, ctx)) {
|
|
|
|
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INTERNAL_ERROR, "Internal error");
|
|
|
|
nvmf_rpc_listener_ctx_free(ctx);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2019-05-06 03:54:05 +00:00
|
|
|
SPDK_RPC_REGISTER("nvmf_subsystem_remove_listener", spdk_rpc_nvmf_subsystem_remove_listener,
|
2018-05-02 04:28:57 +00:00
|
|
|
SPDK_RPC_RUNTIME);
|
2018-01-23 22:51:28 +00:00
|
|
|
|
2018-09-10 18:03:46 +00:00
|
|
|
struct spdk_nvmf_ns_params {
|
|
|
|
char *bdev_name;
|
2019-05-23 07:24:46 +00:00
|
|
|
char *ptpl_file;
|
2018-09-10 18:03:46 +00:00
|
|
|
uint32_t nsid;
|
|
|
|
char nguid[16];
|
|
|
|
char eui64[8];
|
|
|
|
struct spdk_uuid uuid;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct rpc_namespaces {
|
|
|
|
size_t num_ns;
|
|
|
|
struct spdk_nvmf_ns_params ns_params[RPC_MAX_NAMESPACES];
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static const struct spdk_json_object_decoder rpc_ns_params_decoders[] = {
|
|
|
|
{"nsid", offsetof(struct spdk_nvmf_ns_params, nsid), spdk_json_decode_uint32, true},
|
|
|
|
{"bdev_name", offsetof(struct spdk_nvmf_ns_params, bdev_name), spdk_json_decode_string},
|
2019-05-23 07:24:46 +00:00
|
|
|
{"ptpl_file", offsetof(struct spdk_nvmf_ns_params, ptpl_file), spdk_json_decode_string, true},
|
2018-09-10 18:03:46 +00:00
|
|
|
{"nguid", offsetof(struct spdk_nvmf_ns_params, nguid), decode_ns_nguid, true},
|
|
|
|
{"eui64", offsetof(struct spdk_nvmf_ns_params, eui64), decode_ns_eui64, true},
|
|
|
|
{"uuid", offsetof(struct spdk_nvmf_ns_params, uuid), decode_ns_uuid, true},
|
|
|
|
};
|
|
|
|
|
|
|
|
static int
|
|
|
|
decode_rpc_ns_params(const struct spdk_json_val *val, void *out)
|
|
|
|
{
|
|
|
|
struct spdk_nvmf_ns_params *ns_params = out;
|
|
|
|
|
|
|
|
return spdk_json_decode_object(val, rpc_ns_params_decoders,
|
|
|
|
SPDK_COUNTOF(rpc_ns_params_decoders),
|
|
|
|
ns_params);
|
|
|
|
}
|
|
|
|
|
2018-01-23 22:51:28 +00:00
|
|
|
struct nvmf_rpc_ns_ctx {
|
|
|
|
char *nqn;
|
|
|
|
struct spdk_nvmf_ns_params ns_params;
|
|
|
|
|
|
|
|
struct spdk_jsonrpc_request *request;
|
|
|
|
bool response_sent;
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct spdk_json_object_decoder nvmf_rpc_subsystem_ns_decoder[] = {
|
|
|
|
{"nqn", offsetof(struct nvmf_rpc_ns_ctx, nqn), spdk_json_decode_string},
|
|
|
|
{"namespace", offsetof(struct nvmf_rpc_ns_ctx, ns_params), decode_rpc_ns_params},
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
nvmf_rpc_ns_ctx_free(struct nvmf_rpc_ns_ctx *ctx)
|
|
|
|
{
|
|
|
|
free(ctx->nqn);
|
2018-09-10 18:03:46 +00:00
|
|
|
free(ctx->ns_params.bdev_name);
|
2019-05-23 07:24:46 +00:00
|
|
|
free(ctx->ns_params.ptpl_file);
|
2018-01-23 22:51:28 +00:00
|
|
|
free(ctx);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
nvmf_rpc_ns_resumed(struct spdk_nvmf_subsystem *subsystem,
|
|
|
|
void *cb_arg, int status)
|
|
|
|
{
|
|
|
|
struct nvmf_rpc_ns_ctx *ctx = cb_arg;
|
|
|
|
struct spdk_jsonrpc_request *request = ctx->request;
|
|
|
|
uint32_t nsid = ctx->ns_params.nsid;
|
|
|
|
bool response_sent = ctx->response_sent;
|
|
|
|
struct spdk_json_write_ctx *w;
|
|
|
|
|
|
|
|
nvmf_rpc_ns_ctx_free(ctx);
|
|
|
|
|
|
|
|
if (response_sent) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
w = spdk_jsonrpc_begin_result(request);
|
|
|
|
if (w == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
spdk_json_write_uint32(w, nsid);
|
|
|
|
spdk_jsonrpc_end_result(request, w);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
nvmf_rpc_ns_paused(struct spdk_nvmf_subsystem *subsystem,
|
|
|
|
void *cb_arg, int status)
|
|
|
|
{
|
|
|
|
struct nvmf_rpc_ns_ctx *ctx = cb_arg;
|
2017-08-22 15:54:12 +00:00
|
|
|
struct spdk_nvmf_ns_opts ns_opts;
|
2018-01-23 22:51:28 +00:00
|
|
|
struct spdk_bdev *bdev;
|
|
|
|
|
|
|
|
bdev = spdk_bdev_get_by_name(ctx->ns_params.bdev_name);
|
|
|
|
if (!bdev) {
|
|
|
|
SPDK_ERRLOG("No bdev with name %s\n", ctx->ns_params.bdev_name);
|
|
|
|
spdk_jsonrpc_send_error_response(ctx->request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
|
|
|
|
"Invalid parameters");
|
|
|
|
ctx->response_sent = true;
|
|
|
|
goto resume;
|
|
|
|
}
|
|
|
|
|
2017-08-22 15:54:12 +00:00
|
|
|
spdk_nvmf_ns_opts_get_defaults(&ns_opts, sizeof(ns_opts));
|
|
|
|
ns_opts.nsid = ctx->ns_params.nsid;
|
|
|
|
|
2018-02-13 00:03:01 +00:00
|
|
|
SPDK_STATIC_ASSERT(sizeof(ns_opts.nguid) == sizeof(ctx->ns_params.nguid), "size mismatch");
|
|
|
|
memcpy(ns_opts.nguid, ctx->ns_params.nguid, sizeof(ns_opts.nguid));
|
|
|
|
|
|
|
|
SPDK_STATIC_ASSERT(sizeof(ns_opts.eui64) == sizeof(ctx->ns_params.eui64), "size mismatch");
|
|
|
|
memcpy(ns_opts.eui64, ctx->ns_params.eui64, sizeof(ns_opts.eui64));
|
|
|
|
|
2018-06-07 21:58:17 +00:00
|
|
|
if (!spdk_mem_all_zero(&ctx->ns_params.uuid, sizeof(ctx->ns_params.uuid))) {
|
|
|
|
ns_opts.uuid = ctx->ns_params.uuid;
|
|
|
|
}
|
|
|
|
|
2019-05-23 07:24:46 +00:00
|
|
|
ctx->ns_params.nsid = spdk_nvmf_subsystem_add_ns(subsystem, bdev, &ns_opts, sizeof(ns_opts),
|
|
|
|
ctx->ns_params.ptpl_file);
|
2018-01-23 22:51:28 +00:00
|
|
|
if (ctx->ns_params.nsid == 0) {
|
|
|
|
SPDK_ERRLOG("Unable to add namespace\n");
|
|
|
|
spdk_jsonrpc_send_error_response(ctx->request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
|
|
|
|
"Invalid parameters");
|
|
|
|
ctx->response_sent = true;
|
|
|
|
goto resume;
|
|
|
|
}
|
|
|
|
|
|
|
|
resume:
|
|
|
|
if (spdk_nvmf_subsystem_resume(subsystem, nvmf_rpc_ns_resumed, ctx)) {
|
|
|
|
spdk_jsonrpc_send_error_response(ctx->request, SPDK_JSONRPC_ERROR_INTERNAL_ERROR, "Internal error");
|
|
|
|
nvmf_rpc_ns_ctx_free(ctx);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-05-06 03:54:05 +00:00
|
|
|
spdk_rpc_nvmf_subsystem_add_ns(struct spdk_jsonrpc_request *request,
|
|
|
|
const struct spdk_json_val *params)
|
2018-01-23 22:51:28 +00:00
|
|
|
{
|
|
|
|
struct nvmf_rpc_ns_ctx *ctx;
|
|
|
|
struct spdk_nvmf_subsystem *subsystem;
|
|
|
|
|
|
|
|
ctx = calloc(1, sizeof(*ctx));
|
|
|
|
if (!ctx) {
|
|
|
|
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INTERNAL_ERROR, "Out of memory");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (spdk_json_decode_object(params, nvmf_rpc_subsystem_ns_decoder,
|
|
|
|
SPDK_COUNTOF(nvmf_rpc_subsystem_ns_decoder),
|
|
|
|
ctx)) {
|
|
|
|
SPDK_ERRLOG("spdk_json_decode_object failed\n");
|
|
|
|
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, "Invalid parameters");
|
|
|
|
nvmf_rpc_ns_ctx_free(ctx);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx->request = request;
|
|
|
|
ctx->response_sent = false;
|
|
|
|
|
2018-03-10 00:33:41 +00:00
|
|
|
subsystem = spdk_nvmf_tgt_find_subsystem(g_spdk_nvmf_tgt, ctx->nqn);
|
2018-01-23 22:51:28 +00:00
|
|
|
if (!subsystem) {
|
|
|
|
SPDK_ERRLOG("Unable to find subsystem with NQN %s\n", ctx->nqn);
|
|
|
|
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, "Invalid parameters");
|
|
|
|
nvmf_rpc_ns_ctx_free(ctx);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (spdk_nvmf_subsystem_pause(subsystem, nvmf_rpc_ns_paused, ctx)) {
|
|
|
|
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INTERNAL_ERROR, "Internal error");
|
|
|
|
nvmf_rpc_ns_ctx_free(ctx);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2019-05-06 03:54:05 +00:00
|
|
|
SPDK_RPC_REGISTER("nvmf_subsystem_add_ns", spdk_rpc_nvmf_subsystem_add_ns, SPDK_RPC_RUNTIME)
|
2018-01-23 22:03:38 +00:00
|
|
|
|
2018-02-27 07:47:29 +00:00
|
|
|
struct nvmf_rpc_remove_ns_ctx {
|
|
|
|
char *nqn;
|
|
|
|
uint32_t nsid;
|
|
|
|
|
|
|
|
struct spdk_jsonrpc_request *request;
|
|
|
|
bool response_sent;
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct spdk_json_object_decoder nvmf_rpc_subsystem_remove_ns_decoder[] = {
|
|
|
|
{"nqn", offsetof(struct nvmf_rpc_remove_ns_ctx, nqn), spdk_json_decode_string},
|
|
|
|
{"nsid", offsetof(struct nvmf_rpc_remove_ns_ctx, nsid), spdk_json_decode_uint32},
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
nvmf_rpc_remove_ns_ctx_free(struct nvmf_rpc_remove_ns_ctx *ctx)
|
|
|
|
{
|
|
|
|
free(ctx->nqn);
|
|
|
|
free(ctx);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
nvmf_rpc_remove_ns_resumed(struct spdk_nvmf_subsystem *subsystem,
|
|
|
|
void *cb_arg, int status)
|
|
|
|
{
|
|
|
|
struct nvmf_rpc_remove_ns_ctx *ctx = cb_arg;
|
|
|
|
struct spdk_jsonrpc_request *request = ctx->request;
|
|
|
|
bool response_sent = ctx->response_sent;
|
|
|
|
struct spdk_json_write_ctx *w;
|
|
|
|
|
|
|
|
nvmf_rpc_remove_ns_ctx_free(ctx);
|
|
|
|
|
|
|
|
if (response_sent) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
w = spdk_jsonrpc_begin_result(request);
|
|
|
|
if (w == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
spdk_json_write_bool(w, true);
|
|
|
|
spdk_jsonrpc_end_result(request, w);
|
|
|
|
}
|
|
|
|
|
2018-04-18 16:31:40 +00:00
|
|
|
static void
|
|
|
|
nvmf_rpc_remove_ns_paused(struct spdk_nvmf_subsystem *subsystem,
|
|
|
|
void *cb_arg, int status)
|
|
|
|
{
|
|
|
|
struct nvmf_rpc_remove_ns_ctx *ctx = cb_arg;
|
|
|
|
int ret;
|
|
|
|
|
2019-06-27 11:46:42 +00:00
|
|
|
ret = spdk_nvmf_subsystem_remove_ns(subsystem, ctx->nsid);
|
2018-04-18 16:31:40 +00:00
|
|
|
if (ret < 0) {
|
|
|
|
SPDK_ERRLOG("Unable to remove namespace ID %u\n", ctx->nsid);
|
|
|
|
spdk_jsonrpc_send_error_response(ctx->request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
|
|
|
|
"Invalid parameters");
|
|
|
|
ctx->response_sent = true;
|
2019-06-27 11:46:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (spdk_nvmf_subsystem_resume(subsystem, nvmf_rpc_remove_ns_resumed, ctx)) {
|
|
|
|
if (!ctx->response_sent) {
|
|
|
|
spdk_jsonrpc_send_error_response(ctx->request, SPDK_JSONRPC_ERROR_INTERNAL_ERROR, "Internal error");
|
|
|
|
}
|
|
|
|
nvmf_rpc_remove_ns_ctx_free(ctx);
|
|
|
|
return;
|
2018-04-18 16:31:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-27 07:47:29 +00:00
|
|
|
static void
|
2019-05-06 03:54:05 +00:00
|
|
|
spdk_rpc_nvmf_subsystem_remove_ns(struct spdk_jsonrpc_request *request,
|
|
|
|
const struct spdk_json_val *params)
|
2018-02-27 07:47:29 +00:00
|
|
|
{
|
|
|
|
struct nvmf_rpc_remove_ns_ctx *ctx;
|
|
|
|
struct spdk_nvmf_subsystem *subsystem;
|
|
|
|
|
|
|
|
ctx = calloc(1, sizeof(*ctx));
|
|
|
|
if (!ctx) {
|
|
|
|
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INTERNAL_ERROR, "Out of memory");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (spdk_json_decode_object(params, nvmf_rpc_subsystem_remove_ns_decoder,
|
|
|
|
SPDK_COUNTOF(nvmf_rpc_subsystem_remove_ns_decoder),
|
|
|
|
ctx)) {
|
|
|
|
SPDK_ERRLOG("spdk_json_decode_object failed\n");
|
|
|
|
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, "Invalid parameters");
|
|
|
|
nvmf_rpc_remove_ns_ctx_free(ctx);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx->request = request;
|
|
|
|
ctx->response_sent = false;
|
|
|
|
|
2018-03-10 00:33:41 +00:00
|
|
|
subsystem = spdk_nvmf_tgt_find_subsystem(g_spdk_nvmf_tgt, ctx->nqn);
|
2018-02-27 07:47:29 +00:00
|
|
|
if (!subsystem) {
|
|
|
|
SPDK_ERRLOG("Unable to find subsystem with NQN %s\n", ctx->nqn);
|
|
|
|
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, "Invalid parameters");
|
|
|
|
nvmf_rpc_remove_ns_ctx_free(ctx);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (spdk_nvmf_subsystem_pause(subsystem, nvmf_rpc_remove_ns_paused, ctx)) {
|
|
|
|
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INTERNAL_ERROR, "Internal error");
|
|
|
|
nvmf_rpc_remove_ns_ctx_free(ctx);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2019-05-06 03:54:05 +00:00
|
|
|
SPDK_RPC_REGISTER("nvmf_subsystem_remove_ns", spdk_rpc_nvmf_subsystem_remove_ns, SPDK_RPC_RUNTIME)
|
2018-02-27 07:47:29 +00:00
|
|
|
|
2018-01-23 22:03:38 +00:00
|
|
|
enum nvmf_rpc_host_op {
|
|
|
|
NVMF_RPC_HOST_ADD,
|
|
|
|
NVMF_RPC_HOST_REMOVE,
|
|
|
|
NVMF_RPC_HOST_ALLOW_ANY,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct nvmf_rpc_host_ctx {
|
|
|
|
struct spdk_jsonrpc_request *request;
|
|
|
|
|
|
|
|
char *nqn;
|
|
|
|
char *host;
|
|
|
|
|
|
|
|
enum nvmf_rpc_host_op op;
|
|
|
|
|
|
|
|
bool allow_any_host;
|
|
|
|
|
|
|
|
bool response_sent;
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct spdk_json_object_decoder nvmf_rpc_subsystem_host_decoder[] = {
|
|
|
|
{"nqn", offsetof(struct nvmf_rpc_host_ctx, nqn), spdk_json_decode_string},
|
|
|
|
{"host", offsetof(struct nvmf_rpc_host_ctx, host), spdk_json_decode_string},
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
nvmf_rpc_host_ctx_free(struct nvmf_rpc_host_ctx *ctx)
|
|
|
|
{
|
|
|
|
free(ctx->nqn);
|
|
|
|
free(ctx->host);
|
|
|
|
free(ctx);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
nvmf_rpc_host_resumed(struct spdk_nvmf_subsystem *subsystem,
|
|
|
|
void *cb_arg, int status)
|
|
|
|
{
|
|
|
|
struct nvmf_rpc_host_ctx *ctx = cb_arg;
|
|
|
|
struct spdk_jsonrpc_request *request;
|
|
|
|
struct spdk_json_write_ctx *w;
|
|
|
|
bool response_sent = ctx->response_sent;
|
|
|
|
|
|
|
|
request = ctx->request;
|
|
|
|
nvmf_rpc_host_ctx_free(ctx);
|
|
|
|
|
|
|
|
if (response_sent) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
w = spdk_jsonrpc_begin_result(request);
|
|
|
|
if (w == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
spdk_json_write_bool(w, true);
|
|
|
|
spdk_jsonrpc_end_result(request, w);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
nvmf_rpc_host_paused(struct spdk_nvmf_subsystem *subsystem,
|
|
|
|
void *cb_arg, int status)
|
|
|
|
{
|
|
|
|
struct nvmf_rpc_host_ctx *ctx = cb_arg;
|
|
|
|
int rc = -1;
|
|
|
|
|
|
|
|
switch (ctx->op) {
|
|
|
|
case NVMF_RPC_HOST_ADD:
|
|
|
|
rc = spdk_nvmf_subsystem_add_host(subsystem, ctx->host);
|
|
|
|
break;
|
|
|
|
case NVMF_RPC_HOST_REMOVE:
|
|
|
|
rc = spdk_nvmf_subsystem_remove_host(subsystem, ctx->host);
|
|
|
|
break;
|
|
|
|
case NVMF_RPC_HOST_ALLOW_ANY:
|
|
|
|
rc = spdk_nvmf_subsystem_set_allow_any_host(subsystem, ctx->allow_any_host);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rc != 0) {
|
|
|
|
spdk_jsonrpc_send_error_response(ctx->request, SPDK_JSONRPC_ERROR_INTERNAL_ERROR, "Internal error");
|
|
|
|
ctx->response_sent = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (spdk_nvmf_subsystem_resume(subsystem, nvmf_rpc_host_resumed, ctx)) {
|
|
|
|
if (!ctx->response_sent) {
|
|
|
|
spdk_jsonrpc_send_error_response(ctx->request, SPDK_JSONRPC_ERROR_INTERNAL_ERROR, "Internal error");
|
|
|
|
}
|
|
|
|
nvmf_rpc_host_ctx_free(ctx);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-05-06 03:54:05 +00:00
|
|
|
spdk_rpc_nvmf_subsystem_add_host(struct spdk_jsonrpc_request *request,
|
|
|
|
const struct spdk_json_val *params)
|
2018-01-23 22:03:38 +00:00
|
|
|
{
|
|
|
|
struct nvmf_rpc_host_ctx *ctx;
|
|
|
|
struct spdk_nvmf_subsystem *subsystem;
|
|
|
|
|
|
|
|
ctx = calloc(1, sizeof(*ctx));
|
|
|
|
if (!ctx) {
|
|
|
|
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INTERNAL_ERROR, "Out of memory");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (spdk_json_decode_object(params, nvmf_rpc_subsystem_host_decoder,
|
|
|
|
SPDK_COUNTOF(nvmf_rpc_subsystem_host_decoder),
|
|
|
|
ctx)) {
|
|
|
|
SPDK_ERRLOG("spdk_json_decode_object failed\n");
|
|
|
|
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, "Invalid parameters");
|
|
|
|
nvmf_rpc_host_ctx_free(ctx);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx->request = request;
|
|
|
|
ctx->op = NVMF_RPC_HOST_ADD;
|
|
|
|
ctx->response_sent = false;
|
|
|
|
|
2018-03-10 00:33:41 +00:00
|
|
|
subsystem = spdk_nvmf_tgt_find_subsystem(g_spdk_nvmf_tgt, ctx->nqn);
|
2018-01-23 22:03:38 +00:00
|
|
|
if (!subsystem) {
|
|
|
|
SPDK_ERRLOG("Unable to find subsystem with NQN %s\n", ctx->nqn);
|
|
|
|
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, "Invalid parameters");
|
|
|
|
nvmf_rpc_host_ctx_free(ctx);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (spdk_nvmf_subsystem_pause(subsystem, nvmf_rpc_host_paused, ctx)) {
|
|
|
|
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INTERNAL_ERROR, "Internal error");
|
|
|
|
nvmf_rpc_host_ctx_free(ctx);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2019-05-06 03:54:05 +00:00
|
|
|
SPDK_RPC_REGISTER("nvmf_subsystem_add_host", spdk_rpc_nvmf_subsystem_add_host, SPDK_RPC_RUNTIME)
|
2018-01-23 22:03:38 +00:00
|
|
|
|
|
|
|
static void
|
2019-05-06 03:54:05 +00:00
|
|
|
spdk_rpc_nvmf_subsystem_remove_host(struct spdk_jsonrpc_request *request,
|
|
|
|
const struct spdk_json_val *params)
|
2018-01-23 22:03:38 +00:00
|
|
|
{
|
|
|
|
struct nvmf_rpc_host_ctx *ctx;
|
|
|
|
struct spdk_nvmf_subsystem *subsystem;
|
|
|
|
|
|
|
|
ctx = calloc(1, sizeof(*ctx));
|
|
|
|
if (!ctx) {
|
|
|
|
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INTERNAL_ERROR, "Out of memory");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (spdk_json_decode_object(params, nvmf_rpc_subsystem_host_decoder,
|
|
|
|
SPDK_COUNTOF(nvmf_rpc_subsystem_host_decoder),
|
|
|
|
ctx)) {
|
|
|
|
SPDK_ERRLOG("spdk_json_decode_object failed\n");
|
|
|
|
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, "Invalid parameters");
|
|
|
|
nvmf_rpc_host_ctx_free(ctx);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx->request = request;
|
|
|
|
ctx->op = NVMF_RPC_HOST_REMOVE;
|
|
|
|
ctx->response_sent = false;
|
|
|
|
|
2018-03-10 00:33:41 +00:00
|
|
|
subsystem = spdk_nvmf_tgt_find_subsystem(g_spdk_nvmf_tgt, ctx->nqn);
|
2018-01-23 22:03:38 +00:00
|
|
|
if (!subsystem) {
|
|
|
|
SPDK_ERRLOG("Unable to find subsystem with NQN %s\n", ctx->nqn);
|
|
|
|
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, "Invalid parameters");
|
|
|
|
nvmf_rpc_host_ctx_free(ctx);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (spdk_nvmf_subsystem_pause(subsystem, nvmf_rpc_host_paused, ctx)) {
|
|
|
|
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INTERNAL_ERROR, "Internal error");
|
|
|
|
nvmf_rpc_host_ctx_free(ctx);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2019-05-06 03:54:05 +00:00
|
|
|
SPDK_RPC_REGISTER("nvmf_subsystem_remove_host", spdk_rpc_nvmf_subsystem_remove_host,
|
|
|
|
SPDK_RPC_RUNTIME)
|
2018-01-23 22:03:38 +00:00
|
|
|
|
|
|
|
|
|
|
|
static const struct spdk_json_object_decoder nvmf_rpc_subsystem_any_host_decoder[] = {
|
|
|
|
{"nqn", offsetof(struct nvmf_rpc_host_ctx, nqn), spdk_json_decode_string},
|
|
|
|
{"allow_any_host", offsetof(struct nvmf_rpc_host_ctx, allow_any_host), spdk_json_decode_bool},
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
2019-05-06 03:54:05 +00:00
|
|
|
spdk_rpc_nvmf_subsystem_allow_any_host(struct spdk_jsonrpc_request *request,
|
|
|
|
const struct spdk_json_val *params)
|
2018-01-23 22:03:38 +00:00
|
|
|
{
|
|
|
|
struct nvmf_rpc_host_ctx *ctx;
|
|
|
|
struct spdk_nvmf_subsystem *subsystem;
|
|
|
|
|
|
|
|
ctx = calloc(1, sizeof(*ctx));
|
|
|
|
if (!ctx) {
|
|
|
|
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INTERNAL_ERROR, "Out of memory");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (spdk_json_decode_object(params, nvmf_rpc_subsystem_any_host_decoder,
|
|
|
|
SPDK_COUNTOF(nvmf_rpc_subsystem_any_host_decoder),
|
|
|
|
ctx)) {
|
|
|
|
SPDK_ERRLOG("spdk_json_decode_object failed\n");
|
|
|
|
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, "Invalid parameters");
|
|
|
|
nvmf_rpc_host_ctx_free(ctx);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx->request = request;
|
|
|
|
ctx->op = NVMF_RPC_HOST_ALLOW_ANY;
|
|
|
|
ctx->response_sent = false;
|
|
|
|
|
2018-03-10 00:33:41 +00:00
|
|
|
subsystem = spdk_nvmf_tgt_find_subsystem(g_spdk_nvmf_tgt, ctx->nqn);
|
2018-01-23 22:03:38 +00:00
|
|
|
if (!subsystem) {
|
|
|
|
SPDK_ERRLOG("Unable to find subsystem with NQN %s\n", ctx->nqn);
|
|
|
|
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, "Invalid parameters");
|
|
|
|
nvmf_rpc_host_ctx_free(ctx);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (spdk_nvmf_subsystem_pause(subsystem, nvmf_rpc_host_paused, ctx)) {
|
|
|
|
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INTERNAL_ERROR, "Internal error");
|
|
|
|
nvmf_rpc_host_ctx_free(ctx);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2019-05-06 03:54:05 +00:00
|
|
|
SPDK_RPC_REGISTER("nvmf_subsystem_allow_any_host", spdk_rpc_nvmf_subsystem_allow_any_host,
|
2018-05-02 04:28:57 +00:00
|
|
|
SPDK_RPC_RUNTIME)
|
2018-06-07 23:00:26 +00:00
|
|
|
|
|
|
|
static const struct spdk_json_object_decoder nvmf_rpc_subsystem_tgt_opts_decoder[] = {
|
2018-10-19 20:19:09 +00:00
|
|
|
{"max_subsystems", 0, spdk_json_decode_uint32, true}
|
2018-06-07 23:00:26 +00:00
|
|
|
};
|
|
|
|
|
2018-10-19 20:19:09 +00:00
|
|
|
static void
|
2019-05-06 03:54:05 +00:00
|
|
|
spdk_rpc_set_nvmf_target_max_subsystems(struct spdk_jsonrpc_request *request,
|
|
|
|
const struct spdk_json_val *params)
|
2018-10-19 20:19:09 +00:00
|
|
|
{
|
2018-06-07 23:00:26 +00:00
|
|
|
struct spdk_json_write_ctx *w;
|
2018-10-19 20:19:09 +00:00
|
|
|
uint32_t max_subsystems = 0;
|
2018-06-07 23:00:26 +00:00
|
|
|
|
2018-10-19 20:19:09 +00:00
|
|
|
if (g_spdk_nvmf_tgt_max_subsystems != 0) {
|
2018-06-07 23:00:26 +00:00
|
|
|
SPDK_ERRLOG("this RPC must not be called more than once.\n");
|
|
|
|
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INTERNAL_ERROR,
|
|
|
|
"Must not call more than once");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (params != NULL) {
|
|
|
|
if (spdk_json_decode_object(params, nvmf_rpc_subsystem_tgt_opts_decoder,
|
2018-10-19 20:19:09 +00:00
|
|
|
SPDK_COUNTOF(nvmf_rpc_subsystem_tgt_opts_decoder), &max_subsystems)) {
|
2018-06-07 23:00:26 +00:00
|
|
|
SPDK_ERRLOG("spdk_json_decode_object() failed\n");
|
|
|
|
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
|
|
|
|
"Invalid parameters");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-19 20:19:09 +00:00
|
|
|
g_spdk_nvmf_tgt_max_subsystems = max_subsystems;
|
2018-06-07 23:00:26 +00:00
|
|
|
|
|
|
|
w = spdk_jsonrpc_begin_result(request);
|
|
|
|
if (w == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
spdk_json_write_bool(w, true);
|
|
|
|
spdk_jsonrpc_end_result(request, w);
|
|
|
|
}
|
2019-05-06 03:54:05 +00:00
|
|
|
SPDK_RPC_REGISTER("set_nvmf_target_max_subsystems", spdk_rpc_set_nvmf_target_max_subsystems,
|
2018-10-19 20:19:09 +00:00
|
|
|
SPDK_RPC_STARTUP)
|
2018-06-07 23:00:26 +00:00
|
|
|
|
2018-08-14 05:34:29 +00:00
|
|
|
static int decode_conn_sched(const struct spdk_json_val *val, void *out)
|
|
|
|
{
|
|
|
|
enum spdk_nvmf_connect_sched *sched = out;
|
|
|
|
|
|
|
|
if (spdk_json_strequal(val, "roundrobin") == true) {
|
|
|
|
*sched = CONNECT_SCHED_ROUND_ROBIN;
|
|
|
|
} else if (spdk_json_strequal(val, "hostip") == true) {
|
|
|
|
*sched = CONNECT_SCHED_HOST_IP;
|
|
|
|
} else {
|
|
|
|
SPDK_ERRLOG("Invalid connection scheduling parameter\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-06-07 23:00:26 +00:00
|
|
|
static const struct spdk_json_object_decoder nvmf_rpc_subsystem_tgt_conf_decoder[] = {
|
|
|
|
{"acceptor_poll_rate", offsetof(struct spdk_nvmf_tgt_conf, acceptor_poll_rate), spdk_json_decode_uint32, true},
|
2018-08-14 05:34:29 +00:00
|
|
|
{"conn_sched", offsetof(struct spdk_nvmf_tgt_conf, conn_sched), decode_conn_sched, true},
|
2018-06-07 23:00:26 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
2019-05-06 03:54:05 +00:00
|
|
|
spdk_rpc_set_nvmf_target_config(struct spdk_jsonrpc_request *request,
|
2018-06-07 23:00:26 +00:00
|
|
|
const struct spdk_json_val *params)
|
|
|
|
{
|
|
|
|
struct spdk_nvmf_tgt_conf *conf;
|
|
|
|
struct spdk_json_write_ctx *w;
|
|
|
|
|
|
|
|
if (g_spdk_nvmf_tgt_conf != NULL) {
|
|
|
|
SPDK_ERRLOG("this RPC must not be called more than once.\n");
|
|
|
|
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INTERNAL_ERROR,
|
|
|
|
"Must not call more than once");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
conf = calloc(1, sizeof(*conf));
|
|
|
|
if (conf == NULL) {
|
|
|
|
SPDK_ERRLOG("calloc() failed for target config\n");
|
|
|
|
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INTERNAL_ERROR,
|
|
|
|
"Out of memory");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
conf->acceptor_poll_rate = ACCEPT_TIMEOUT_US;
|
2018-08-14 05:34:29 +00:00
|
|
|
conf->conn_sched = DEFAULT_CONN_SCHED;
|
2018-06-07 23:00:26 +00:00
|
|
|
|
|
|
|
if (params != NULL) {
|
|
|
|
if (spdk_json_decode_object(params, nvmf_rpc_subsystem_tgt_conf_decoder,
|
|
|
|
SPDK_COUNTOF(nvmf_rpc_subsystem_tgt_conf_decoder), conf)) {
|
|
|
|
free(conf);
|
|
|
|
SPDK_ERRLOG("spdk_json_decode_object() failed\n");
|
|
|
|
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
|
|
|
|
"Invalid parameters");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
g_spdk_nvmf_tgt_conf = conf;
|
|
|
|
|
|
|
|
w = spdk_jsonrpc_begin_result(request);
|
|
|
|
if (w == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
spdk_json_write_bool(w, true);
|
|
|
|
spdk_jsonrpc_end_result(request, w);
|
|
|
|
}
|
2019-05-06 03:54:05 +00:00
|
|
|
SPDK_RPC_REGISTER("set_nvmf_target_config", spdk_rpc_set_nvmf_target_config, SPDK_RPC_STARTUP)
|
2018-08-27 22:27:47 +00:00
|
|
|
|
|
|
|
struct nvmf_rpc_create_transport_ctx {
|
|
|
|
char *trtype;
|
|
|
|
struct spdk_nvmf_transport_opts opts;
|
|
|
|
struct spdk_jsonrpc_request *request;
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct spdk_json_object_decoder nvmf_rpc_create_transport_decoder[] = {
|
|
|
|
{ "trtype", offsetof(struct nvmf_rpc_create_transport_ctx, trtype), spdk_json_decode_string},
|
|
|
|
{
|
|
|
|
"max_queue_depth", offsetof(struct nvmf_rpc_create_transport_ctx, opts.max_queue_depth),
|
|
|
|
spdk_json_decode_uint16, true
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"max_qpairs_per_ctrlr", offsetof(struct nvmf_rpc_create_transport_ctx, opts.max_qpairs_per_ctrlr),
|
|
|
|
spdk_json_decode_uint16, true
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"in_capsule_data_size", offsetof(struct nvmf_rpc_create_transport_ctx, opts.in_capsule_data_size),
|
|
|
|
spdk_json_decode_uint32, true
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"max_io_size", offsetof(struct nvmf_rpc_create_transport_ctx, opts.max_io_size),
|
|
|
|
spdk_json_decode_uint32, true
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"io_unit_size", offsetof(struct nvmf_rpc_create_transport_ctx, opts.io_unit_size),
|
|
|
|
spdk_json_decode_uint32, true
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"max_aq_depth", offsetof(struct nvmf_rpc_create_transport_ctx, opts.max_aq_depth),
|
|
|
|
spdk_json_decode_uint32, true
|
|
|
|
},
|
2018-12-14 14:29:48 +00:00
|
|
|
{
|
|
|
|
"num_shared_buffers", offsetof(struct nvmf_rpc_create_transport_ctx, opts.num_shared_buffers),
|
|
|
|
spdk_json_decode_uint32, true
|
|
|
|
},
|
2019-01-07 20:53:44 +00:00
|
|
|
{
|
|
|
|
"buf_cache_size", offsetof(struct nvmf_rpc_create_transport_ctx, opts.buf_cache_size),
|
|
|
|
spdk_json_decode_uint32, true
|
|
|
|
},
|
nvmf/rdma: Add shared receive queue support
This is a new feature for NVMEoF RDMA target, that is intended to save
resource allocation (by sharing them) and utilize the
locality (completions and memory) to get the best performance with
Shared Receive Queues (SRQs). We'll create a SRQ per core (poll
group), per device and associate each created QP/CQ with an
appropriate SRQ.
Our testing environment has 2 hosts.
Host 1:
CPU: Intel(R) Xeon(R) CPU E5-2609 0 @ 2.40GHz dual socket (8 cores total)
Network: ConnectX-5, ConnectX-5 VPI , 100GbE, single-port QSFP28, PCIe3.0 x16
Disk: Intel Optane SSD 900P Series
OS: Fedora 27 x86_64
Host 2:
CPU: Intel(R) Xeon(R) CPU E5-2630 v2 @ 2.60GHz dual-socket (24 cores total)
Network: ConnectX-4 VPI , 100GbE, dual-port QSFP28
Disk: Intel Optane SSD 900P Series
OS : CentOS 7.5.1804 x86_64
Hosts are connected via Spectrum switch.
Host 1 is running SPDK NVMeoF target.
Host 2 is used as initiator running fio with SPDK plugin.
Configuration:
- SPDK NVMeoF target: cpu mask 0x0F (4 cores), max queue depth 128,
max SRQ depth 1024, max QPs per controller 1024
- Single NVMf subsystem with single namespace backed by physical SSD disk
- fio with SPDK plugin: randread pattern, 1-256 jobs, block size 4k,
IO depth 16, cpu_mask 0xFFF0, IO rate 10k, rate process “poisson”
Here is a full fio command line:
fio --name=Job --stats=1 --group_reporting=1 --idle-prof=percpu \
--loops=1 --numjobs=1 --thread=1 --time_based=1 --runtime=30s \
--ramp_time=5s --bs=4k --size=4G --iodepth=16 --readwrite=randread \
--rwmixread=75 --randrepeat=1 --ioengine=spdk --direct=1 \
--gtod_reduce=0 --cpumask=0xFFF0 --rate_iops=10k \
--rate_process=poisson \
--filename='trtype=RDMA adrfam=IPv4 traddr=1.1.79.1 trsvcid=4420 ns=1'
SPDK allocates the following entities for every work request in
receive queue (shared or not): reqs (1024 bytes), recvs (96 bytes),
cmds (64 bytes), cpls (16 bytes), in_capsule_buffer. All except the
last one are fixed size. In capsule data size is configured to 4096.
Memory consumption calculation (target):
- Multiple SRQ: core_num * ib_devs_num * SRQ_depth * (1200 +
in_capsule_data_size)
- Multiple RQ: queue_num * RQ_depth * (1200 + in_capsule_data_size)
We ignore admin queues in calculations for simplicity.
Cases:
1. Multiple SRQ with 1024 entries:
- Mem = 4 * 1 * 1024 * (1200 + 4096) = 20.7 MiB
(Constant number – does not depend on initiators number)
2. RQ with 128 entries for 64 initiators:
- Mem = 64 * 128 * (1200 + 4096) = 41.4 MiB
Results:
FIO_JOBS kIOPS Bandwidth,MiB/s AvgLatency,us MaxResidentSize,kiB
RQ SRQ RQ SRQ RQ SRQ RQ SRQ
1 8.623 8.623 33.7 33.7 13.89 14.03 144376 155624
2 17.3 17.3 67.4 67.4 14.03 14.1 145776 155700
4 34.5 34.5 135 135 14.15 14.23 146540 156184
8 69.1 69.1 270 270 14.64 14.49 148116 156960
16 138 138 540 540 14.84 15.38 151216 158668
32 276 276 1079 1079 16.5 16.61 157560 161936
64 513 502 2005 1960 1673 1612 170408 168440
128 535 526 2092 2054 3329 3344 195796 181524
256 571 571 2232 2233 6854 6873 246484 207856
We can see the benefit in memory consumption.
Change-Id: I40c70f6ccbad7754918bcc6cb397e955b09d1033
Signed-off-by: Evgeniy Kochetov <evgeniik@mellanox.com>
Signed-off-by: Sasha Kotchubievsky <sashakot@mellanox.com>
Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/428458
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>
2018-10-04 14:59:08 +00:00
|
|
|
{
|
|
|
|
"max_srq_depth", offsetof(struct nvmf_rpc_create_transport_ctx, opts.max_srq_depth),
|
|
|
|
spdk_json_decode_uint32, true
|
|
|
|
},
|
2019-04-26 21:25:20 +00:00
|
|
|
{
|
|
|
|
"no_srq", offsetof(struct nvmf_rpc_create_transport_ctx, opts.no_srq),
|
|
|
|
spdk_json_decode_bool, true
|
|
|
|
},
|
2019-06-11 15:07:28 +00:00
|
|
|
{
|
|
|
|
"c2h_success", offsetof(struct nvmf_rpc_create_transport_ctx, opts.c2h_success),
|
|
|
|
spdk_json_decode_bool, true
|
|
|
|
},
|
2019-07-02 08:04:16 +00:00
|
|
|
{
|
|
|
|
"dif_insert_or_strip", offsetof(struct nvmf_rpc_create_transport_ctx, opts.dif_insert_or_strip),
|
|
|
|
spdk_json_decode_bool, true
|
|
|
|
},
|
2018-08-27 22:27:47 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
nvmf_rpc_create_transport_ctx_free(struct nvmf_rpc_create_transport_ctx *ctx)
|
|
|
|
{
|
|
|
|
free(ctx->trtype);
|
|
|
|
free(ctx);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
nvmf_rpc_tgt_add_transport_done(void *cb_arg, int status)
|
|
|
|
{
|
|
|
|
struct nvmf_rpc_create_transport_ctx *ctx = cb_arg;
|
|
|
|
struct spdk_jsonrpc_request *request;
|
|
|
|
struct spdk_json_write_ctx *w;
|
|
|
|
|
|
|
|
request = ctx->request;
|
|
|
|
nvmf_rpc_create_transport_ctx_free(ctx);
|
|
|
|
|
|
|
|
if (status) {
|
|
|
|
SPDK_ERRLOG("Failed to add transport to tgt.(%d)\n", status);
|
|
|
|
spdk_jsonrpc_send_error_response_fmt(request, SPDK_JSONRPC_ERROR_INTERNAL_ERROR,
|
|
|
|
"Failed to add transport to tgt.(%d)\n",
|
|
|
|
status);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
w = spdk_jsonrpc_begin_result(request);
|
|
|
|
if (w == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
spdk_json_write_bool(w, true);
|
|
|
|
spdk_jsonrpc_end_result(request, w);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-05-06 03:54:05 +00:00
|
|
|
spdk_rpc_nvmf_create_transport(struct spdk_jsonrpc_request *request,
|
|
|
|
const struct spdk_json_val *params)
|
2018-08-27 22:27:47 +00:00
|
|
|
{
|
|
|
|
struct nvmf_rpc_create_transport_ctx *ctx;
|
|
|
|
enum spdk_nvme_transport_type trtype;
|
|
|
|
struct spdk_nvmf_transport *transport;
|
|
|
|
|
|
|
|
ctx = calloc(1, sizeof(*ctx));
|
|
|
|
if (!ctx) {
|
|
|
|
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INTERNAL_ERROR, "Out of memory");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Decode parameters the first time to get the transport type */
|
|
|
|
if (spdk_json_decode_object(params, nvmf_rpc_create_transport_decoder,
|
|
|
|
SPDK_COUNTOF(nvmf_rpc_create_transport_decoder),
|
|
|
|
ctx)) {
|
|
|
|
SPDK_ERRLOG("spdk_json_decode_object failed\n");
|
|
|
|
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, "Invalid parameters");
|
|
|
|
nvmf_rpc_create_transport_ctx_free(ctx);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (spdk_nvme_transport_id_parse_trtype(&trtype, ctx->trtype)) {
|
|
|
|
SPDK_ERRLOG("Invalid transport type '%s'\n", ctx->trtype);
|
|
|
|
spdk_jsonrpc_send_error_response_fmt(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
|
|
|
|
"Invalid transport type '%s'\n", ctx->trtype);
|
|
|
|
nvmf_rpc_create_transport_ctx_free(ctx);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Initialize all the transport options (based on transport type) and decode the
|
|
|
|
* parameters again to update any options passed in rpc create transport call.
|
|
|
|
*/
|
2018-11-30 00:19:19 +00:00
|
|
|
if (!spdk_nvmf_transport_opts_init(trtype, &ctx->opts)) {
|
|
|
|
/* This can happen if user specifies PCIE transport type which isn't valid for
|
|
|
|
* NVMe-oF.
|
|
|
|
*/
|
|
|
|
SPDK_ERRLOG("Invalid transport type '%s'\n", ctx->trtype);
|
|
|
|
spdk_jsonrpc_send_error_response_fmt(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
|
|
|
|
"Invalid transport type '%s'\n", ctx->trtype);
|
|
|
|
nvmf_rpc_create_transport_ctx_free(ctx);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-08-27 22:27:47 +00:00
|
|
|
if (spdk_json_decode_object(params, nvmf_rpc_create_transport_decoder,
|
|
|
|
SPDK_COUNTOF(nvmf_rpc_create_transport_decoder),
|
|
|
|
ctx)) {
|
|
|
|
SPDK_ERRLOG("spdk_json_decode_object failed\n");
|
|
|
|
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, "Invalid parameters");
|
|
|
|
nvmf_rpc_create_transport_ctx_free(ctx);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (spdk_nvmf_tgt_get_transport(g_spdk_nvmf_tgt, trtype)) {
|
|
|
|
SPDK_ERRLOG("Transport type '%s' already exists\n", ctx->trtype);
|
|
|
|
spdk_jsonrpc_send_error_response_fmt(request, SPDK_JSONRPC_ERROR_INTERNAL_ERROR,
|
|
|
|
"Transport type '%s' already exists\n", ctx->trtype);
|
|
|
|
nvmf_rpc_create_transport_ctx_free(ctx);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
transport = spdk_nvmf_transport_create(trtype, &ctx->opts);
|
|
|
|
|
|
|
|
if (!transport) {
|
|
|
|
SPDK_ERRLOG("Transport type '%s' create failed\n", ctx->trtype);
|
|
|
|
spdk_jsonrpc_send_error_response_fmt(request, SPDK_JSONRPC_ERROR_INTERNAL_ERROR,
|
|
|
|
"Transport type '%s' create failed\n", ctx->trtype);
|
|
|
|
nvmf_rpc_create_transport_ctx_free(ctx);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* add transport to target */
|
|
|
|
ctx->request = request;
|
|
|
|
spdk_nvmf_tgt_add_transport(g_spdk_nvmf_tgt, transport, nvmf_rpc_tgt_add_transport_done, ctx);
|
|
|
|
}
|
|
|
|
|
2019-05-06 03:54:05 +00:00
|
|
|
SPDK_RPC_REGISTER("nvmf_create_transport", spdk_rpc_nvmf_create_transport, SPDK_RPC_RUNTIME)
|
2018-10-23 22:07:42 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
dump_nvmf_transport(struct spdk_json_write_ctx *w, struct spdk_nvmf_transport *transport)
|
|
|
|
{
|
|
|
|
const struct spdk_nvmf_transport_opts *opts = spdk_nvmf_get_transport_opts(transport);
|
|
|
|
spdk_nvme_transport_type_t type = spdk_nvmf_get_transport_type(transport);
|
|
|
|
|
|
|
|
spdk_json_write_object_begin(w);
|
|
|
|
|
|
|
|
spdk_json_write_named_string(w, "trtype", spdk_nvme_transport_id_trtype_str(type));
|
|
|
|
spdk_json_write_named_uint32(w, "max_queue_depth", opts->max_queue_depth);
|
|
|
|
spdk_json_write_named_uint32(w, "max_qpairs_per_ctrlr", opts->max_qpairs_per_ctrlr);
|
|
|
|
spdk_json_write_named_uint32(w, "in_capsule_data_size", opts->in_capsule_data_size);
|
|
|
|
spdk_json_write_named_uint32(w, "max_io_size", opts->max_io_size);
|
|
|
|
spdk_json_write_named_uint32(w, "io_unit_size", opts->io_unit_size);
|
|
|
|
spdk_json_write_named_uint32(w, "max_aq_depth", opts->max_aq_depth);
|
2018-12-14 14:29:48 +00:00
|
|
|
spdk_json_write_named_uint32(w, "num_shared_buffers", opts->num_shared_buffers);
|
2019-01-07 21:27:26 +00:00
|
|
|
spdk_json_write_named_uint32(w, "buf_cache_size", opts->buf_cache_size);
|
2019-04-26 21:34:03 +00:00
|
|
|
if (type == SPDK_NVME_TRANSPORT_RDMA) {
|
|
|
|
spdk_json_write_named_uint32(w, "max_srq_depth", opts->max_srq_depth);
|
|
|
|
spdk_json_write_named_bool(w, "no_srq", opts->no_srq);
|
2019-06-11 15:07:28 +00:00
|
|
|
} else if (type == SPDK_NVME_TRANSPORT_TCP) {
|
|
|
|
spdk_json_write_named_bool(w, "c2h_success", opts->c2h_success);
|
2019-07-02 08:04:16 +00:00
|
|
|
spdk_json_write_named_bool(w, "dif_insert_or_strip", opts->dif_insert_or_strip);
|
2019-04-26 21:34:03 +00:00
|
|
|
}
|
2018-10-23 22:07:42 +00:00
|
|
|
|
|
|
|
spdk_json_write_object_end(w);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-05-06 03:54:05 +00:00
|
|
|
spdk_rpc_get_nvmf_transports(struct spdk_jsonrpc_request *request,
|
2018-10-23 22:07:42 +00:00
|
|
|
const struct spdk_json_val *params)
|
|
|
|
{
|
|
|
|
struct spdk_json_write_ctx *w;
|
|
|
|
struct spdk_nvmf_transport *transport;
|
|
|
|
|
|
|
|
if (params != NULL) {
|
|
|
|
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
|
|
|
|
"get_nvmf_transports requires no parameters");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
w = spdk_jsonrpc_begin_result(request);
|
|
|
|
if (w == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
spdk_json_write_array_begin(w);
|
|
|
|
transport = spdk_nvmf_transport_get_first(g_spdk_nvmf_tgt);
|
|
|
|
while (transport) {
|
|
|
|
dump_nvmf_transport(w, transport);
|
|
|
|
transport = spdk_nvmf_transport_get_next(transport);
|
|
|
|
}
|
|
|
|
spdk_json_write_array_end(w);
|
|
|
|
spdk_jsonrpc_end_result(request, w);
|
|
|
|
}
|
2019-05-06 03:54:05 +00:00
|
|
|
SPDK_RPC_REGISTER("get_nvmf_transports", spdk_rpc_get_nvmf_transports, SPDK_RPC_RUNTIME)
|