Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright (C) 2022 Intel Corporation.
3 : : * All rights reserved.
4 : : */
5 : :
6 : : #include "spdk/stdinc.h"
7 : : #include "spdk/thread.h"
8 : : #include "spdk/rpc.h"
9 : : #include "spdk/string.h"
10 : : #include "spdk_internal/init.h"
11 : :
12 : : static const struct spdk_json_object_decoder rpc_iobuf_set_options_decoders[] = {
13 : : {"small_pool_count", offsetof(struct spdk_iobuf_opts, small_pool_count), spdk_json_decode_uint64, true},
14 : : {"large_pool_count", offsetof(struct spdk_iobuf_opts, large_pool_count), spdk_json_decode_uint64, true},
15 : : {"small_bufsize", offsetof(struct spdk_iobuf_opts, small_bufsize), spdk_json_decode_uint32, true},
16 : : {"large_bufsize", offsetof(struct spdk_iobuf_opts, large_bufsize), spdk_json_decode_uint32, true},
17 : : };
18 : :
19 : : static void
20 : 228 : rpc_iobuf_set_options(struct spdk_jsonrpc_request *request, const struct spdk_json_val *params)
21 : : {
22 : 112 : struct spdk_iobuf_opts opts;
23 : : int rc;
24 : :
25 : 228 : spdk_iobuf_get_opts(&opts, sizeof(opts));
26 : 228 : rc = spdk_json_decode_object(params, rpc_iobuf_set_options_decoders,
27 : : SPDK_COUNTOF(rpc_iobuf_set_options_decoders), &opts);
28 [ - + ]: 228 : if (rc != 0) {
29 : 0 : spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
30 : : "spdk_json_decode_object failed");
31 : 0 : return;
32 : : }
33 : :
34 : 228 : rc = spdk_iobuf_set_opts(&opts);
35 [ - + ]: 228 : if (rc != 0) {
36 : 0 : spdk_jsonrpc_send_error_response(request, rc, spdk_strerror(-rc));
37 : 0 : return;
38 : : }
39 : :
40 : 228 : spdk_jsonrpc_send_bool_response(request, true);
41 : : }
42 : 2109 : SPDK_RPC_REGISTER("iobuf_set_options", rpc_iobuf_set_options, SPDK_RPC_STARTUP)
43 : :
44 : : static void
45 : 3 : rpc_iobuf_get_stats_done(struct spdk_iobuf_module_stats *modules, uint32_t num_modules,
46 : : void *cb_arg)
47 : : {
48 : 3 : struct spdk_jsonrpc_request *request = cb_arg;
49 : : struct spdk_json_write_ctx *w;
50 : : struct spdk_iobuf_module_stats *it;
51 : : uint32_t i;
52 : :
53 : 3 : w = spdk_jsonrpc_begin_result(request);
54 : 3 : spdk_json_write_array_begin(w);
55 : :
56 [ + + ]: 12 : for (i = 0; i < num_modules; ++i) {
57 : 9 : it = &modules[i];
58 : :
59 : 9 : spdk_json_write_object_begin(w);
60 : 9 : spdk_json_write_named_string(w, "module", it->module);
61 : :
62 : 9 : spdk_json_write_named_object_begin(w, "small_pool");
63 : 9 : spdk_json_write_named_uint64(w, "cache", it->small_pool.cache);
64 : 9 : spdk_json_write_named_uint64(w, "main", it->small_pool.main);
65 : 9 : spdk_json_write_named_uint64(w, "retry", it->small_pool.retry);
66 : 9 : spdk_json_write_object_end(w);
67 : :
68 : 9 : spdk_json_write_named_object_begin(w, "large_pool");
69 : 9 : spdk_json_write_named_uint64(w, "cache", it->large_pool.cache);
70 : 9 : spdk_json_write_named_uint64(w, "main", it->large_pool.main);
71 : 9 : spdk_json_write_named_uint64(w, "retry", it->large_pool.retry);
72 : 9 : spdk_json_write_object_end(w);
73 : :
74 : 9 : spdk_json_write_object_end(w);
75 : : }
76 : :
77 : 3 : spdk_json_write_array_end(w);
78 : 3 : spdk_jsonrpc_end_result(request, w);
79 : 3 : }
80 : :
81 : : static void
82 : 3 : rpc_iobuf_get_stats(struct spdk_jsonrpc_request *request, const struct spdk_json_val *params)
83 : : {
84 : : int rc;
85 : :
86 : 3 : rc = spdk_iobuf_get_stats(rpc_iobuf_get_stats_done, request);
87 [ - + ]: 3 : if (rc != 0) {
88 : 0 : spdk_jsonrpc_send_error_response(request, rc, spdk_strerror(-rc));
89 : : }
90 : 3 : }
91 : 2109 : SPDK_RPC_REGISTER("iobuf_get_stats", rpc_iobuf_get_stats, SPDK_RPC_RUNTIME)
|