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