Line data Source code
1 : /* SPDX-License-Identifier: BSD-3-Clause
2 : * Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3 : */
4 :
5 : #include "spdk/stdinc.h"
6 : #include "spdk/log.h"
7 : #include "spdk/rpc.h"
8 : #include "spdk/util.h"
9 : #include "spdk/fsdev.h"
10 :
11 : static void
12 0 : rpc_fsdev_get_opts(struct spdk_jsonrpc_request *request, const struct spdk_json_val *params)
13 : {
14 : struct spdk_json_write_ctx *w;
15 0 : struct spdk_fsdev_opts opts = {};
16 : int rc;
17 :
18 0 : if (params) {
19 0 : spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
20 : "'fsdev_get_opts' requires no arguments");
21 0 : return;
22 : }
23 :
24 0 : rc = spdk_fsdev_get_opts(&opts, sizeof(opts));
25 0 : if (rc) {
26 0 : spdk_jsonrpc_send_error_response_fmt(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
27 : "spdk_fsdev_get_opts failed with %d", rc);
28 0 : return;
29 : }
30 :
31 0 : w = spdk_jsonrpc_begin_result(request);
32 0 : spdk_json_write_object_begin(w);
33 0 : spdk_json_write_named_uint32(w, "fsdev_io_pool_size", opts.fsdev_io_pool_size);
34 0 : spdk_json_write_named_uint32(w, "fsdev_io_cache_size", opts.fsdev_io_cache_size);
35 0 : spdk_json_write_object_end(w);
36 0 : spdk_jsonrpc_end_result(request, w);
37 : }
38 0 : SPDK_RPC_REGISTER("fsdev_get_opts", rpc_fsdev_get_opts, SPDK_RPC_RUNTIME)
39 :
40 : struct rpc_fsdev_set_opts {
41 : uint32_t fsdev_io_pool_size;
42 : uint32_t fsdev_io_cache_size;
43 : };
44 :
45 : static const struct spdk_json_object_decoder rpc_fsdev_set_opts_decoders[] = {
46 : {"fsdev_io_pool_size", offsetof(struct rpc_fsdev_set_opts, fsdev_io_pool_size), spdk_json_decode_uint32, false},
47 : {"fsdev_io_cache_size", offsetof(struct rpc_fsdev_set_opts, fsdev_io_cache_size), spdk_json_decode_uint32, false},
48 : };
49 :
50 : static void
51 0 : rpc_fsdev_set_opts(struct spdk_jsonrpc_request *request, const struct spdk_json_val *params)
52 : {
53 0 : struct rpc_fsdev_set_opts req = {};
54 : int rc;
55 0 : struct spdk_fsdev_opts opts = {};
56 :
57 0 : if (spdk_json_decode_object(params, rpc_fsdev_set_opts_decoders,
58 : SPDK_COUNTOF(rpc_fsdev_set_opts_decoders),
59 : &req)) {
60 0 : SPDK_ERRLOG("spdk_json_decode_object failed\n");
61 0 : spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
62 : "spdk_json_decode_object failed");
63 0 : return;
64 : }
65 :
66 0 : rc = spdk_fsdev_get_opts(&opts, sizeof(opts));
67 0 : if (rc) {
68 0 : spdk_jsonrpc_send_error_response_fmt(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
69 : "spdk_fsdev_get_opts failed with %d", rc);
70 0 : return;
71 : }
72 :
73 0 : opts.fsdev_io_pool_size = req.fsdev_io_pool_size;
74 0 : opts.fsdev_io_cache_size = req.fsdev_io_cache_size;
75 :
76 0 : rc = spdk_fsdev_set_opts(&opts);
77 0 : if (rc) {
78 0 : spdk_jsonrpc_send_error_response_fmt(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
79 : "spdk_fsdev_set_opts failed with %d", rc);
80 0 : return;
81 : }
82 :
83 0 : spdk_jsonrpc_send_bool_response(request, true);
84 : }
85 0 : SPDK_RPC_REGISTER("fsdev_set_opts", rpc_fsdev_set_opts, SPDK_RPC_RUNTIME)
|