forked from openebs/spdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnvmf_rpc.c
More file actions
280 lines (232 loc) · 7.96 KB
/
Copy pathnvmf_rpc.c
File metadata and controls
280 lines (232 loc) · 7.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
/* SPDX-License-Identifier: BSD-3-Clause
* Copyright (C) 2016 Intel Corporation. All rights reserved.
* Copyright (c) 2018-2019 Mellanox Technologies LTD. All rights reserved.
* Copyright (c) 2021 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
*/
#include "event_nvmf.h"
#include "spdk/rpc.h"
#include "spdk/util.h"
#include "spdk/cpuset.h"
static const struct spdk_json_object_decoder nvmf_rpc_subsystem_tgt_opts_decoder[] = {
{"max_subsystems", 0, spdk_json_decode_uint32, true}
};
struct rpc_nvmf_subsystem_set_pause_timeout {
char *nqn;
uint32_t pause_timeout_sec;
};
static const struct spdk_json_object_decoder rpc_nvmf_subsystem_set_pause_timeout_decoders[] = {
{"nqn", offsetof(struct rpc_nvmf_subsystem_set_pause_timeout, nqn), spdk_json_decode_string},
{"pause_timeout_sec", offsetof(struct rpc_nvmf_subsystem_set_pause_timeout, pause_timeout_sec), spdk_json_decode_uint32}
};
static void
rpc_nvmf_subsystem_set_pause_timeout(struct spdk_jsonrpc_request *request,
const struct spdk_json_val *params)
{
struct rpc_nvmf_subsystem_set_pause_timeout req = {};
struct spdk_nvmf_subsystem *subsystem;
int rc;
if (spdk_json_decode_object(params,
rpc_nvmf_subsystem_set_pause_timeout_decoders,
SPDK_COUNTOF(rpc_nvmf_subsystem_set_pause_timeout_decoders),
&req)) {
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
"Invalid parameters");
goto cleanup;
}
subsystem = spdk_nvmf_tgt_find_subsystem(g_spdk_nvmf_tgt, req.nqn);
if (subsystem == NULL) {
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INTERNAL_ERROR, "Invalid nqn");
goto cleanup;
}
rc = spdk_nvmf_subsystem_set_pause_timeout(subsystem, req.pause_timeout_sec);
if (rc != 0) {
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INTERNAL_ERROR,
"Failed to set timeout");
goto cleanup;
}
spdk_jsonrpc_send_bool_response(request, true);
cleanup:
free(req.nqn);
}
SPDK_RPC_REGISTER("nvmf_subsystem_set_pause_timeout",
rpc_nvmf_subsystem_set_pause_timeout,
SPDK_RPC_RUNTIME)
static void
rpc_nvmf_set_max_subsystems(struct spdk_jsonrpc_request *request,
const struct spdk_json_val *params)
{
uint32_t max_subsystems = 0;
if (g_spdk_nvmf_tgt_max_subsystems != 0) {
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,
SPDK_COUNTOF(nvmf_rpc_subsystem_tgt_opts_decoder), &max_subsystems)) {
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_max_subsystems = max_subsystems;
spdk_jsonrpc_send_bool_response(request, true);
}
SPDK_RPC_REGISTER("nvmf_set_max_subsystems", rpc_nvmf_set_max_subsystems,
SPDK_RPC_STARTUP)
static const struct spdk_json_object_decoder admin_passthru_decoder[] = {
{"identify_ctrlr", offsetof(struct spdk_nvmf_admin_passthru_conf, identify_ctrlr), spdk_json_decode_bool}
};
static int
decode_admin_passthru(const struct spdk_json_val *val, void *out)
{
struct spdk_nvmf_admin_passthru_conf *req = (struct spdk_nvmf_admin_passthru_conf *)out;
if (spdk_json_decode_object(val, admin_passthru_decoder,
SPDK_COUNTOF(admin_passthru_decoder),
req)) {
SPDK_ERRLOG("spdk_json_decode_object failed\n");
return -1;
}
return 0;
}
static int
decode_discovery_filter(const struct spdk_json_val *val, void *out)
{
enum spdk_nvmf_tgt_discovery_filter *_filter = (enum spdk_nvmf_tgt_discovery_filter *)out;
enum spdk_nvmf_tgt_discovery_filter filter = SPDK_NVMF_TGT_DISCOVERY_MATCH_ANY;
char *tokens = spdk_json_strdup(val);
char *tok;
int rc = -EINVAL;
bool all_specified = false;
if (!tokens) {
return -ENOMEM;
}
tok = strtok(tokens, ",");
while (tok) {
if (strncmp(tok, "match_any", 9) == 0) {
if (filter != SPDK_NVMF_TGT_DISCOVERY_MATCH_ANY) {
goto out;
}
filter = SPDK_NVMF_TGT_DISCOVERY_MATCH_ANY;
all_specified = true;
} else {
if (all_specified) {
goto out;
}
if (strncmp(tok, "transport", 9) == 0) {
filter |= SPDK_NVMF_TGT_DISCOVERY_MATCH_TRANSPORT_TYPE;
} else if (strncmp(tok, "address", 7) == 0) {
filter |= SPDK_NVMF_TGT_DISCOVERY_MATCH_TRANSPORT_ADDRESS;
} else if (strncmp(tok, "svcid", 5) == 0) {
filter |= SPDK_NVMF_TGT_DISCOVERY_MATCH_TRANSPORT_SVCID;
} else {
SPDK_ERRLOG("Invalid value %s\n", tok);
goto out;
}
}
tok = strtok(NULL, ",");
}
rc = 0;
*_filter = filter;
out:
free(tokens);
return rc;
}
static int
nvmf_is_subset_of_env_core_mask(const struct spdk_cpuset *set)
{
uint32_t i, tmp_counter = 0;
SPDK_ENV_FOREACH_CORE(i) {
if (spdk_cpuset_get_cpu(set, i)) {
++tmp_counter;
}
}
return spdk_cpuset_count(set) - tmp_counter;
}
static int
nvmf_decode_poll_groups_mask(const struct spdk_json_val *val, void *out)
{
char *mask = spdk_json_strdup(val);
int ret = -1;
if (mask == NULL) {
return -1;
}
if (!(g_poll_groups_mask = spdk_cpuset_alloc())) {
SPDK_ERRLOG("Unable to allocate a poll groups mask object in nvmf_decode_poll_groups_mask.\n");
free(mask);
return -1;
}
ret = spdk_cpuset_parse(g_poll_groups_mask, mask);
free(mask);
if (ret == 0) {
if (nvmf_is_subset_of_env_core_mask(g_poll_groups_mask) == 0) {
return 0;
} else {
SPDK_ERRLOG("Poll groups cpumask 0x%s is out of range\n", spdk_cpuset_fmt(g_poll_groups_mask));
}
} else {
SPDK_ERRLOG("Invalid cpumask\n");
}
spdk_cpuset_free(g_poll_groups_mask);
g_poll_groups_mask = NULL;
return -1;
}
static const struct spdk_json_object_decoder nvmf_rpc_subsystem_tgt_conf_decoder[] = {
{"admin_cmd_passthru", offsetof(struct spdk_nvmf_tgt_conf, admin_passthru), decode_admin_passthru, true},
{"poll_groups_mask", 0, nvmf_decode_poll_groups_mask, true},
{"discovery_filter", offsetof(struct spdk_nvmf_tgt_conf, discovery_filter), decode_discovery_filter, true}
};
static void
rpc_nvmf_set_config(struct spdk_jsonrpc_request *request,
const struct spdk_json_val *params)
{
struct spdk_nvmf_tgt_conf conf;
memcpy(&conf, &g_spdk_nvmf_tgt_conf, sizeof(conf));
if (params != NULL) {
if (spdk_json_decode_object(params, nvmf_rpc_subsystem_tgt_conf_decoder,
SPDK_COUNTOF(nvmf_rpc_subsystem_tgt_conf_decoder), &conf)) {
SPDK_ERRLOG("spdk_json_decode_object() failed\n");
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
"Invalid parameters");
return;
}
}
memcpy(&g_spdk_nvmf_tgt_conf, &conf, sizeof(conf));
spdk_jsonrpc_send_bool_response(request, true);
}
SPDK_RPC_REGISTER("nvmf_set_config", rpc_nvmf_set_config, SPDK_RPC_STARTUP)
struct nvmf_rpc_set_crdt {
uint16_t crdt1;
uint16_t crdt2;
uint16_t crdt3;
};
static const struct spdk_json_object_decoder rpc_set_crdt_opts_decoders[] = {
{"crdt1", offsetof(struct nvmf_rpc_set_crdt, crdt1), spdk_json_decode_uint16, true},
{"crdt2", offsetof(struct nvmf_rpc_set_crdt, crdt2), spdk_json_decode_uint16, true},
{"crdt3", offsetof(struct nvmf_rpc_set_crdt, crdt3), spdk_json_decode_uint16, true},
};
static void
rpc_nvmf_set_crdt(struct spdk_jsonrpc_request *request,
const struct spdk_json_val *params)
{
struct nvmf_rpc_set_crdt rpc_set_crdt;
rpc_set_crdt.crdt1 = 0;
rpc_set_crdt.crdt2 = 0;
rpc_set_crdt.crdt3 = 0;
if (params != NULL) {
if (spdk_json_decode_object(params, rpc_set_crdt_opts_decoders,
SPDK_COUNTOF(rpc_set_crdt_opts_decoders), &rpc_set_crdt)) {
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_crdt[0] = rpc_set_crdt.crdt1;
g_spdk_nvmf_tgt_crdt[1] = rpc_set_crdt.crdt2;
g_spdk_nvmf_tgt_crdt[2] = rpc_set_crdt.crdt3;
spdk_jsonrpc_send_bool_response(request, true);
}
SPDK_RPC_REGISTER("nvmf_set_crdt", rpc_nvmf_set_crdt, SPDK_RPC_STARTUP)