Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright (C) 2017 Intel Corporation. All rights reserved.
3 : : * All rights reserved.
4 : : */
5 : :
6 : : #include "spdk/stdinc.h"
7 : :
8 : : #include "spdk/log.h"
9 : : #include "spdk/rpc.h"
10 : : #include "spdk/util.h"
11 : : #include "spdk/string.h"
12 : : #include "spdk/env.h"
13 : : #include "spdk/scsi.h"
14 : : #include "spdk/vhost.h"
15 : : #include "vhost_internal.h"
16 : : #include "spdk/bdev.h"
17 : :
18 : : struct rpc_vhost_scsi_ctrlr {
19 : : char *ctrlr;
20 : : char *cpumask;
21 : : bool delay;
22 : : };
23 : :
24 : : static void
25 : 8 : free_rpc_vhost_scsi_ctrlr(struct rpc_vhost_scsi_ctrlr *req)
26 : : {
27 : 8 : free(req->ctrlr);
28 : 8 : free(req->cpumask);
29 : 8 : }
30 : :
31 : : static const struct spdk_json_object_decoder rpc_vhost_create_scsi_ctrlr[] = {
32 : : {"ctrlr", offsetof(struct rpc_vhost_scsi_ctrlr, ctrlr), spdk_json_decode_string },
33 : : {"cpumask", offsetof(struct rpc_vhost_scsi_ctrlr, cpumask), spdk_json_decode_string, true},
34 : : {"delay", offsetof(struct rpc_vhost_scsi_ctrlr, delay), spdk_json_decode_bool, true},
35 : : };
36 : :
37 : : static void
38 : 8 : rpc_vhost_create_scsi_controller(struct spdk_jsonrpc_request *request,
39 : : const struct spdk_json_val *params)
40 : : {
41 : 8 : struct rpc_vhost_scsi_ctrlr req = {0};
42 : : int rc;
43 : :
44 [ - + ]: 8 : if (spdk_json_decode_object(params, rpc_vhost_create_scsi_ctrlr,
45 : : SPDK_COUNTOF(rpc_vhost_create_scsi_ctrlr),
46 : : &req)) {
47 [ # # # # ]: 0 : SPDK_DEBUGLOG(vhost_rpc, "spdk_json_decode_object failed\n");
48 : 0 : rc = -EINVAL;
49 : 0 : goto invalid;
50 : : }
51 : :
52 [ - + + + ]: 8 : if (req.delay) {
53 : 1 : rc = spdk_vhost_scsi_dev_construct_no_start(req.ctrlr, req.cpumask);
54 : : } else {
55 : 7 : rc = spdk_vhost_scsi_dev_construct(req.ctrlr, req.cpumask);
56 : : }
57 [ - + ]: 8 : if (rc < 0) {
58 : 0 : goto invalid;
59 : : }
60 : :
61 : 8 : free_rpc_vhost_scsi_ctrlr(&req);
62 : :
63 : 8 : spdk_jsonrpc_send_bool_response(request, true);
64 : 8 : return;
65 : :
66 : 0 : invalid:
67 : 0 : free_rpc_vhost_scsi_ctrlr(&req);
68 : 0 : spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
69 : : spdk_strerror(-rc));
70 : : }
71 : 638 : SPDK_RPC_REGISTER("vhost_create_scsi_controller", rpc_vhost_create_scsi_controller,
72 : : SPDK_RPC_RUNTIME)
73 : :
74 : : struct rpc_start_vhost_scsi_ctrlr {
75 : : char *ctrlr;
76 : : };
77 : :
78 : : static void
79 : 1 : free_rpc_start_vhost_scsi_ctrlr(struct rpc_start_vhost_scsi_ctrlr *req)
80 : : {
81 : 1 : free(req->ctrlr);
82 : 1 : }
83 : :
84 : : static const struct spdk_json_object_decoder rpc_start_vhost_scsi_ctrlr_decoder[] = {
85 : : {"ctrlr", offsetof(struct rpc_start_vhost_scsi_ctrlr, ctrlr), spdk_json_decode_string },
86 : : };
87 : :
88 : : static void
89 : 1 : rpc_vhost_start_scsi_controller(struct spdk_jsonrpc_request *request,
90 : : const struct spdk_json_val *params)
91 : : {
92 : 1 : struct rpc_start_vhost_scsi_ctrlr req = {0};
93 : : int rc;
94 : :
95 [ - + ]: 1 : if (spdk_json_decode_object(params, rpc_start_vhost_scsi_ctrlr_decoder,
96 : : SPDK_COUNTOF(rpc_start_vhost_scsi_ctrlr_decoder),
97 : : &req)) {
98 [ # # # # ]: 0 : SPDK_DEBUGLOG(vhost_rpc, "spdk_json_decode_object failed\n");
99 : 0 : rc = -EINVAL;
100 : 0 : goto invalid;
101 : : }
102 : :
103 : 1 : rc = vhost_scsi_controller_start(req.ctrlr);
104 [ - + ]: 1 : if (rc < 0) {
105 : 0 : goto invalid;
106 : : }
107 : :
108 : 1 : free_rpc_start_vhost_scsi_ctrlr(&req);
109 : :
110 : 1 : spdk_jsonrpc_send_bool_response(request, true);
111 : 1 : return;
112 : :
113 : 0 : invalid:
114 : 0 : free_rpc_start_vhost_scsi_ctrlr(&req);
115 : 0 : spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
116 : : spdk_strerror(-rc));
117 : : }
118 : 638 : SPDK_RPC_REGISTER("vhost_start_scsi_controller", rpc_vhost_start_scsi_controller,
119 : : SPDK_RPC_RUNTIME)
120 : :
121 : : struct rpc_vhost_scsi_ctrlr_add_target {
122 : : char *ctrlr;
123 : : int32_t scsi_target_num;
124 : : char *bdev_name;
125 : : };
126 : :
127 : : static void
128 : 13 : free_rpc_vhost_scsi_ctrlr_add_target(struct rpc_vhost_scsi_ctrlr_add_target *req)
129 : : {
130 : 13 : free(req->ctrlr);
131 : 13 : free(req->bdev_name);
132 : 13 : }
133 : :
134 : : static const struct spdk_json_object_decoder rpc_vhost_scsi_ctrlr_add_target[] = {
135 : : {"ctrlr", offsetof(struct rpc_vhost_scsi_ctrlr_add_target, ctrlr), spdk_json_decode_string },
136 : : {"scsi_target_num", offsetof(struct rpc_vhost_scsi_ctrlr_add_target, scsi_target_num), spdk_json_decode_int32},
137 : : {"bdev_name", offsetof(struct rpc_vhost_scsi_ctrlr_add_target, bdev_name), spdk_json_decode_string },
138 : : };
139 : :
140 : : static void
141 : 13 : rpc_vhost_scsi_controller_add_target(struct spdk_jsonrpc_request *request,
142 : : const struct spdk_json_val *params)
143 : : {
144 : 13 : struct rpc_vhost_scsi_ctrlr_add_target req = {0};
145 : : struct spdk_json_write_ctx *w;
146 : : struct spdk_vhost_dev *vdev;
147 : : int rc;
148 : :
149 [ - + ]: 13 : if (spdk_json_decode_object(params, rpc_vhost_scsi_ctrlr_add_target,
150 : : SPDK_COUNTOF(rpc_vhost_scsi_ctrlr_add_target),
151 : : &req)) {
152 [ # # # # ]: 0 : SPDK_DEBUGLOG(vhost_rpc, "spdk_json_decode_object failed\n");
153 : 0 : rc = -EINVAL;
154 : 0 : goto invalid;
155 : : }
156 : :
157 : 13 : spdk_vhost_lock();
158 : 13 : vdev = spdk_vhost_dev_find(req.ctrlr);
159 [ - + ]: 13 : if (vdev == NULL) {
160 : 0 : spdk_vhost_unlock();
161 : 0 : rc = -ENODEV;
162 : 0 : goto invalid;
163 : : }
164 : :
165 : 13 : rc = spdk_vhost_scsi_dev_add_tgt(vdev, req.scsi_target_num, req.bdev_name);
166 : 13 : spdk_vhost_unlock();
167 [ - + ]: 13 : if (rc < 0) {
168 : 0 : goto invalid;
169 : : }
170 : :
171 : 13 : free_rpc_vhost_scsi_ctrlr_add_target(&req);
172 : :
173 : 13 : w = spdk_jsonrpc_begin_result(request);
174 : 13 : spdk_json_write_int32(w, rc);
175 : 13 : spdk_jsonrpc_end_result(request, w);
176 : 13 : return;
177 : :
178 : 0 : invalid:
179 : 0 : free_rpc_vhost_scsi_ctrlr_add_target(&req);
180 : 0 : spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
181 : : spdk_strerror(-rc));
182 : : }
183 : 638 : SPDK_RPC_REGISTER("vhost_scsi_controller_add_target", rpc_vhost_scsi_controller_add_target,
184 : : SPDK_RPC_RUNTIME)
185 : :
186 : : struct rpc_remove_vhost_scsi_ctrlr_target {
187 : : char *ctrlr;
188 : : uint32_t scsi_target_num;
189 : : };
190 : :
191 : : static void
192 : 3 : free_rpc_remove_vhost_scsi_ctrlr_target(struct rpc_remove_vhost_scsi_ctrlr_target *req)
193 : : {
194 : 3 : free(req->ctrlr);
195 : 3 : }
196 : :
197 : : static const struct spdk_json_object_decoder rpc_vhost_remove_target[] = {
198 : : {"ctrlr", offsetof(struct rpc_remove_vhost_scsi_ctrlr_target, ctrlr), spdk_json_decode_string },
199 : : {"scsi_target_num", offsetof(struct rpc_remove_vhost_scsi_ctrlr_target, scsi_target_num), spdk_json_decode_uint32},
200 : : };
201 : :
202 : : static int
203 : 3 : rpc_vhost_scsi_controller_remove_target_finish_cb(struct spdk_vhost_dev *vdev, void *arg)
204 : : {
205 : 3 : struct spdk_jsonrpc_request *request = arg;
206 : :
207 : 3 : spdk_jsonrpc_send_bool_response(request, true);
208 : 3 : return 0;
209 : : }
210 : :
211 : : static void
212 : 3 : rpc_vhost_scsi_controller_remove_target(struct spdk_jsonrpc_request *request,
213 : : const struct spdk_json_val *params)
214 : : {
215 : 3 : struct rpc_remove_vhost_scsi_ctrlr_target req = {0};
216 : : struct spdk_vhost_dev *vdev;
217 : : int rc;
218 : :
219 [ - + ]: 3 : if (spdk_json_decode_object(params, rpc_vhost_remove_target,
220 : : SPDK_COUNTOF(rpc_vhost_remove_target),
221 : : &req)) {
222 [ # # # # ]: 0 : SPDK_DEBUGLOG(vhost_rpc, "spdk_json_decode_object failed\n");
223 : 0 : rc = -EINVAL;
224 : 0 : goto invalid;
225 : : }
226 : :
227 : 3 : spdk_vhost_lock();
228 : 3 : vdev = spdk_vhost_dev_find(req.ctrlr);
229 [ - + ]: 3 : if (vdev == NULL) {
230 : 0 : spdk_vhost_unlock();
231 : 0 : rc = -ENODEV;
232 : 0 : goto invalid;
233 : : }
234 : :
235 : 3 : rc = spdk_vhost_scsi_dev_remove_tgt(vdev, req.scsi_target_num,
236 : : rpc_vhost_scsi_controller_remove_target_finish_cb,
237 : : request);
238 : 3 : spdk_vhost_unlock();
239 [ - + ]: 3 : if (rc < 0) {
240 : 0 : goto invalid;
241 : : }
242 : :
243 : 3 : free_rpc_remove_vhost_scsi_ctrlr_target(&req);
244 : 3 : return;
245 : :
246 : 0 : invalid:
247 : 0 : free_rpc_remove_vhost_scsi_ctrlr_target(&req);
248 : 0 : spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
249 : : spdk_strerror(-rc));
250 : : }
251 : :
252 : 638 : SPDK_RPC_REGISTER("vhost_scsi_controller_remove_target",
253 : : rpc_vhost_scsi_controller_remove_target, SPDK_RPC_RUNTIME)
254 : :
255 : : struct rpc_vhost_blk_ctrlr {
256 : : char *ctrlr;
257 : : char *dev_name;
258 : : char *cpumask;
259 : : char *transport;
260 : : };
261 : :
262 : : static const struct spdk_json_object_decoder rpc_construct_vhost_blk_ctrlr[] = {
263 : : {"ctrlr", offsetof(struct rpc_vhost_blk_ctrlr, ctrlr), spdk_json_decode_string },
264 : : {"dev_name", offsetof(struct rpc_vhost_blk_ctrlr, dev_name), spdk_json_decode_string },
265 : : {"cpumask", offsetof(struct rpc_vhost_blk_ctrlr, cpumask), spdk_json_decode_string, true},
266 : : {"transport", offsetof(struct rpc_vhost_blk_ctrlr, transport), spdk_json_decode_string, true},
267 : : };
268 : :
269 : : static void
270 : 13 : free_rpc_vhost_blk_ctrlr(struct rpc_vhost_blk_ctrlr *req)
271 : : {
272 : 13 : free(req->ctrlr);
273 : 13 : free(req->dev_name);
274 : 13 : free(req->cpumask);
275 : 13 : free(req->transport);
276 : 13 : }
277 : :
278 : : static void
279 : 13 : rpc_vhost_create_blk_controller(struct spdk_jsonrpc_request *request,
280 : : const struct spdk_json_val *params)
281 : : {
282 : 13 : struct rpc_vhost_blk_ctrlr req = {0};
283 : : int rc;
284 : :
285 [ - + ]: 13 : if (spdk_json_decode_object_relaxed(params, rpc_construct_vhost_blk_ctrlr,
286 : : SPDK_COUNTOF(rpc_construct_vhost_blk_ctrlr),
287 : : &req)) {
288 [ # # # # ]: 0 : SPDK_DEBUGLOG(vhost_rpc, "spdk_json_decode_object failed\n");
289 : 0 : rc = -EINVAL;
290 : 0 : goto invalid;
291 : : }
292 : :
293 : 13 : rc = spdk_vhost_blk_construct(req.ctrlr, req.cpumask, req.dev_name, req.transport, params);
294 [ - + ]: 13 : if (rc < 0) {
295 : 0 : goto invalid;
296 : : }
297 : :
298 : 13 : free_rpc_vhost_blk_ctrlr(&req);
299 : :
300 : 13 : spdk_jsonrpc_send_bool_response(request, true);
301 : 13 : return;
302 : :
303 : 0 : invalid:
304 : 0 : free_rpc_vhost_blk_ctrlr(&req);
305 : 0 : spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
306 : : spdk_strerror(-rc));
307 : :
308 : : }
309 : 638 : SPDK_RPC_REGISTER("vhost_create_blk_controller", rpc_vhost_create_blk_controller,
310 : : SPDK_RPC_RUNTIME)
311 : :
312 : : struct rpc_delete_vhost_ctrlr {
313 : : char *ctrlr;
314 : : };
315 : :
316 : : static const struct spdk_json_object_decoder rpc_delete_vhost_ctrlr_decoder[] = {
317 : : {"ctrlr", offsetof(struct rpc_delete_vhost_ctrlr, ctrlr), spdk_json_decode_string },
318 : : };
319 : :
320 : : static void
321 : 10 : free_rpc_delete_vhost_ctrlr(struct rpc_delete_vhost_ctrlr *req)
322 : : {
323 : 10 : free(req->ctrlr);
324 : 10 : }
325 : :
326 : : struct vhost_delete_ctrlr_context {
327 : : struct spdk_jsonrpc_request *request;
328 : : const struct spdk_json_val *params;
329 : : };
330 : :
331 : : static void _rpc_vhost_delete_controller(void *arg);
332 : :
333 : : static void
334 : 10 : rpc_vhost_delete_controller(struct spdk_jsonrpc_request *request,
335 : : const struct spdk_json_val *params)
336 : : {
337 : 10 : struct rpc_delete_vhost_ctrlr req = {0};
338 : : struct spdk_vhost_dev *vdev;
339 : : int rc;
340 : :
341 [ - + ]: 10 : if (spdk_json_decode_object(params, rpc_delete_vhost_ctrlr_decoder,
342 : : SPDK_COUNTOF(rpc_delete_vhost_ctrlr_decoder), &req)) {
343 [ # # # # ]: 0 : SPDK_DEBUGLOG(vhost_rpc, "spdk_json_decode_object failed\n");
344 : 0 : rc = -EINVAL;
345 : 0 : goto invalid;
346 : : }
347 : :
348 : 10 : spdk_vhost_lock();
349 : 10 : vdev = spdk_vhost_dev_find(req.ctrlr);
350 [ - + ]: 10 : if (vdev == NULL) {
351 : 0 : spdk_vhost_unlock();
352 : 0 : rc = -ENODEV;
353 : 0 : goto invalid;
354 : : }
355 : 10 : spdk_vhost_unlock();
356 : :
357 : 10 : rc = spdk_vhost_dev_remove(vdev);
358 [ - + ]: 10 : if (rc < 0) {
359 [ # # ]: 0 : if (rc == -EBUSY) {
360 : : struct vhost_delete_ctrlr_context *ctx;
361 : :
362 : 0 : ctx = calloc(1, sizeof(*ctx));
363 [ # # ]: 0 : if (ctx == NULL) {
364 : 0 : SPDK_ERRLOG("Failed to allocate memory for vhost_delete_ctrlr context\n");
365 : 0 : rc = -ENOMEM;
366 : 0 : goto invalid;
367 : : }
368 : 0 : ctx->request = request;
369 : 0 : ctx->params = params;
370 : 0 : spdk_thread_send_msg(spdk_get_thread(), _rpc_vhost_delete_controller, ctx);
371 : 0 : free_rpc_delete_vhost_ctrlr(&req);
372 : 4 : return;
373 : : }
374 : 0 : goto invalid;
375 : : }
376 : :
377 : 10 : free_rpc_delete_vhost_ctrlr(&req);
378 : :
379 : 10 : spdk_jsonrpc_send_bool_response(request, true);
380 : 10 : return;
381 : :
382 : 0 : invalid:
383 : 0 : free_rpc_delete_vhost_ctrlr(&req);
384 : 0 : spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
385 : : spdk_strerror(-rc));
386 : :
387 : : }
388 : 638 : SPDK_RPC_REGISTER("vhost_delete_controller", rpc_vhost_delete_controller, SPDK_RPC_RUNTIME)
389 : :
390 : 0 : static void _rpc_vhost_delete_controller(void *arg)
391 : : {
392 : 0 : struct vhost_delete_ctrlr_context *ctx = arg;
393 : :
394 : 0 : rpc_vhost_delete_controller(ctx->request, ctx->params);
395 : 0 : free(ctx);
396 : 0 : }
397 : :
398 : : struct rpc_get_vhost_ctrlrs {
399 : : char *name;
400 : : };
401 : :
402 : : static void
403 : 91 : _rpc_get_vhost_controller(struct spdk_json_write_ctx *w, struct spdk_vhost_dev *vdev)
404 : : {
405 : 30 : uint32_t delay_base_us, iops_threshold;
406 : :
407 : 91 : spdk_vhost_get_coalescing(vdev, &delay_base_us, &iops_threshold);
408 : :
409 : 91 : spdk_json_write_object_begin(w);
410 : :
411 : 91 : spdk_json_write_named_string(w, "ctrlr", spdk_vhost_dev_get_name(vdev));
412 : 91 : spdk_json_write_named_string_fmt(w, "cpumask", "0x%s",
413 : : spdk_cpuset_fmt(spdk_thread_get_cpumask(vdev->thread)));
414 : 91 : spdk_json_write_named_uint32(w, "delay_base_us", delay_base_us);
415 : 91 : spdk_json_write_named_uint32(w, "iops_threshold", iops_threshold);
416 : 91 : spdk_json_write_named_string(w, "socket", vdev->path);
417 : 91 : spdk_json_write_named_array_begin(w, "sessions");
418 : 91 : vhost_session_info_json(vdev, w);
419 : 91 : spdk_json_write_array_end(w);
420 : :
421 : 91 : spdk_json_write_named_object_begin(w, "backend_specific");
422 : 91 : vhost_dump_info_json(vdev, w);
423 : 91 : spdk_json_write_object_end(w);
424 : :
425 : 91 : spdk_json_write_object_end(w);
426 : 91 : }
427 : :
428 : : static const struct spdk_json_object_decoder rpc_get_vhost_ctrlrs_decoders[] = {
429 : : {"name", offsetof(struct rpc_get_vhost_ctrlrs, name), spdk_json_decode_string, true},
430 : : };
431 : :
432 : : static void
433 : 208 : free_rpc_get_vhost_ctrlrs(struct rpc_get_vhost_ctrlrs *req)
434 : : {
435 : 208 : free(req->name);
436 : 208 : }
437 : :
438 : : static void
439 : 208 : rpc_vhost_get_controllers(struct spdk_jsonrpc_request *request,
440 : : const struct spdk_json_val *params)
441 : : {
442 : 208 : struct rpc_get_vhost_ctrlrs req = {0};
443 : : struct spdk_json_write_ctx *w;
444 : : struct spdk_vhost_dev *vdev;
445 : : int rc;
446 : :
447 [ + + - + ]: 208 : if (params && spdk_json_decode_object(params, rpc_get_vhost_ctrlrs_decoders,
448 : : SPDK_COUNTOF(rpc_get_vhost_ctrlrs_decoders), &req)) {
449 : 0 : SPDK_ERRLOG("spdk_json_decode_object failed\n");
450 : 0 : rc = -EINVAL;
451 : 0 : goto invalid;
452 : : }
453 : :
454 : 208 : spdk_vhost_lock();
455 [ + + ]: 208 : if (req.name != NULL) {
456 : 10 : vdev = spdk_vhost_dev_find(req.name);
457 [ + + ]: 10 : if (vdev == NULL) {
458 : 2 : spdk_vhost_unlock();
459 : 2 : rc = -ENODEV;
460 : 2 : goto invalid;
461 : : }
462 : :
463 : 8 : free_rpc_get_vhost_ctrlrs(&req);
464 : :
465 : 8 : w = spdk_jsonrpc_begin_result(request);
466 : 8 : spdk_json_write_array_begin(w);
467 : :
468 : 8 : _rpc_get_vhost_controller(w, vdev);
469 : 8 : spdk_vhost_unlock();
470 : :
471 : 8 : spdk_json_write_array_end(w);
472 : 8 : spdk_jsonrpc_end_result(request, w);
473 : 124 : return;
474 : : }
475 : :
476 : 198 : free_rpc_get_vhost_ctrlrs(&req);
477 : :
478 : 198 : w = spdk_jsonrpc_begin_result(request);
479 : 198 : spdk_json_write_array_begin(w);
480 : :
481 : 198 : vdev = spdk_vhost_dev_next(NULL);
482 [ + + ]: 281 : while (vdev != NULL) {
483 : 83 : _rpc_get_vhost_controller(w, vdev);
484 : 83 : vdev = spdk_vhost_dev_next(vdev);
485 : : }
486 : 198 : spdk_vhost_unlock();
487 : :
488 : 198 : spdk_json_write_array_end(w);
489 : 198 : spdk_jsonrpc_end_result(request, w);
490 : 198 : return;
491 : :
492 : 2 : invalid:
493 : 2 : free_rpc_get_vhost_ctrlrs(&req);
494 : 2 : spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INTERNAL_ERROR,
495 : : spdk_strerror(-rc));
496 : : }
497 : 638 : SPDK_RPC_REGISTER("vhost_get_controllers", rpc_vhost_get_controllers, SPDK_RPC_RUNTIME)
498 : :
499 : :
500 : : struct rpc_vhost_ctrlr_coalescing {
501 : : char *ctrlr;
502 : : uint32_t delay_base_us;
503 : : uint32_t iops_threshold;
504 : : };
505 : :
506 : : static const struct spdk_json_object_decoder rpc_set_vhost_ctrlr_coalescing[] = {
507 : : {"ctrlr", offsetof(struct rpc_vhost_ctrlr_coalescing, ctrlr), spdk_json_decode_string },
508 : : {"delay_base_us", offsetof(struct rpc_vhost_ctrlr_coalescing, delay_base_us), spdk_json_decode_uint32},
509 : : {"iops_threshold", offsetof(struct rpc_vhost_ctrlr_coalescing, iops_threshold), spdk_json_decode_uint32},
510 : : };
511 : :
512 : : static void
513 : 2 : free_rpc_set_vhost_controllers_event_coalescing(struct rpc_vhost_ctrlr_coalescing *req)
514 : : {
515 : 2 : free(req->ctrlr);
516 : 2 : }
517 : :
518 : : static void
519 : 2 : rpc_vhost_controller_set_coalescing(struct spdk_jsonrpc_request *request,
520 : : const struct spdk_json_val *params)
521 : : {
522 : 2 : struct rpc_vhost_ctrlr_coalescing req = {0};
523 : : struct spdk_vhost_dev *vdev;
524 : : int rc;
525 : :
526 [ - + ]: 2 : if (spdk_json_decode_object(params, rpc_set_vhost_ctrlr_coalescing,
527 : : SPDK_COUNTOF(rpc_set_vhost_ctrlr_coalescing), &req)) {
528 [ # # # # ]: 0 : SPDK_DEBUGLOG(vhost_rpc, "spdk_json_decode_object failed\n");
529 : 0 : rc = -EINVAL;
530 : 0 : goto invalid;
531 : : }
532 : :
533 : 2 : spdk_vhost_lock();
534 : 2 : vdev = spdk_vhost_dev_find(req.ctrlr);
535 [ - + ]: 2 : if (vdev == NULL) {
536 : 0 : spdk_vhost_unlock();
537 : 0 : rc = -ENODEV;
538 : 0 : goto invalid;
539 : : }
540 : :
541 : 2 : rc = spdk_vhost_set_coalescing(vdev, req.delay_base_us, req.iops_threshold);
542 : 2 : spdk_vhost_unlock();
543 [ - + ]: 2 : if (rc) {
544 : 0 : goto invalid;
545 : : }
546 : :
547 : 2 : free_rpc_set_vhost_controllers_event_coalescing(&req);
548 : :
549 : 2 : spdk_jsonrpc_send_bool_response(request, true);
550 : 2 : return;
551 : :
552 : 0 : invalid:
553 : 0 : free_rpc_set_vhost_controllers_event_coalescing(&req);
554 : 0 : spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
555 : : spdk_strerror(-rc));
556 : : }
557 : 638 : SPDK_RPC_REGISTER("vhost_controller_set_coalescing", rpc_vhost_controller_set_coalescing,
558 : : SPDK_RPC_RUNTIME)
559 : :
560 : : struct rpc_get_transport {
561 : : char *name;
562 : : };
563 : :
564 : : static const struct spdk_json_object_decoder rpc_get_transport_decoders[] = {
565 : : {"name", offsetof(struct rpc_get_transport, name), spdk_json_decode_string, true},
566 : : };
567 : :
568 : : static void
569 : 0 : rpc_virtio_blk_get_transports(struct spdk_jsonrpc_request *request,
570 : : const struct spdk_json_val *params)
571 : : {
572 : 0 : struct rpc_get_transport req = { 0 };
573 : : struct spdk_json_write_ctx *w;
574 : 0 : struct spdk_virtio_blk_transport *transport = NULL;
575 : :
576 [ # # ]: 0 : if (params) {
577 [ # # ]: 0 : if (spdk_json_decode_object(params, rpc_get_transport_decoders,
578 : : SPDK_COUNTOF(rpc_get_transport_decoders),
579 : : &req)) {
580 : 0 : SPDK_ERRLOG("spdk_json_decode_object failed\n");
581 : 0 : spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, "Invalid parameters");
582 : 0 : return;
583 : : }
584 : : }
585 : :
586 [ # # ]: 0 : if (req.name) {
587 : 0 : transport = virtio_blk_tgt_get_transport(req.name);
588 [ # # ]: 0 : if (transport == NULL) {
589 : 0 : SPDK_ERRLOG("transport '%s' does not exist\n", req.name);
590 : 0 : spdk_jsonrpc_send_error_response(request, -ENODEV, spdk_strerror(ENODEV));
591 : 0 : free(req.name);
592 : 0 : return;
593 : : }
594 : : }
595 : :
596 : 0 : w = spdk_jsonrpc_begin_result(request);
597 : 0 : spdk_json_write_array_begin(w);
598 : :
599 [ # # ]: 0 : if (transport) {
600 : 0 : virtio_blk_transport_dump_opts(transport, w);
601 : : } else {
602 [ # # ]: 0 : for (transport = virtio_blk_transport_get_first(); transport != NULL;
603 : 0 : transport = virtio_blk_transport_get_next(transport)) {
604 : 0 : virtio_blk_transport_dump_opts(transport, w);
605 : : }
606 : : }
607 : :
608 : 0 : spdk_json_write_array_end(w);
609 : 0 : spdk_jsonrpc_end_result(request, w);
610 : 0 : free(req.name);
611 : : }
612 : 638 : SPDK_RPC_REGISTER("virtio_blk_get_transports", rpc_virtio_blk_get_transports, SPDK_RPC_RUNTIME)
613 : :
614 : : struct rpc_virtio_blk_create_transport {
615 : : char *name;
616 : : };
617 : :
618 : : static const struct spdk_json_object_decoder rpc_create_virtio_blk_transport[] = {
619 : : {"name", offsetof(struct rpc_virtio_blk_create_transport, name), spdk_json_decode_string},
620 : : };
621 : :
622 : : static void
623 : 0 : free_rpc_virtio_blk_create_transport(struct rpc_virtio_blk_create_transport *req)
624 : : {
625 : 0 : free(req->name);
626 : 0 : }
627 : :
628 : : static void
629 : 0 : rpc_virtio_blk_create_transport(struct spdk_jsonrpc_request *request,
630 : : const struct spdk_json_val *params)
631 : : {
632 : 0 : struct rpc_virtio_blk_create_transport req = {0};
633 : : int rc;
634 : :
635 [ # # ]: 0 : if (spdk_json_decode_object_relaxed(params, rpc_create_virtio_blk_transport,
636 : : SPDK_COUNTOF(rpc_create_virtio_blk_transport), &req)) {
637 [ # # # # ]: 0 : SPDK_DEBUGLOG(vhost_rpc, "spdk_json_decode_object failed\n");
638 : 0 : rc = -EINVAL;
639 : 0 : goto invalid;
640 : : }
641 : :
642 : 0 : spdk_vhost_lock();
643 : 0 : rc = virtio_blk_transport_create(req.name, params);
644 : 0 : spdk_vhost_unlock();
645 [ # # ]: 0 : if (rc != 0) {
646 : 0 : goto invalid;
647 : : }
648 : :
649 : 0 : free_rpc_virtio_blk_create_transport(&req);
650 : 0 : spdk_jsonrpc_send_bool_response(request, true);
651 : 0 : return;
652 : :
653 : 0 : invalid:
654 : 0 : free_rpc_virtio_blk_create_transport(&req);
655 : 0 : spdk_jsonrpc_send_error_response(request, rc, spdk_strerror(-rc));
656 : : }
657 : 638 : SPDK_RPC_REGISTER("virtio_blk_create_transport", rpc_virtio_blk_create_transport,
658 : : SPDK_RPC_RUNTIME)
659 : :
660 : 638 : SPDK_LOG_REGISTER_COMPONENT(vhost_rpc)
|