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 rpc_fsdev_get_opts(struct spdk_jsonrpc_request *request, const struct spdk_json_val *params) 13 { 14 struct spdk_json_write_ctx *w; 15 struct spdk_fsdev_opts opts = {}; 16 int rc; 17 18 if (params) { 19 spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, 20 "'fsdev_get_opts' requires no arguments"); 21 return; 22 } 23 24 rc = spdk_fsdev_get_opts(&opts, sizeof(opts)); 25 if (rc) { 26 spdk_jsonrpc_send_error_response_fmt(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, 27 "spdk_fsdev_get_opts failed with %d", rc); 28 return; 29 } 30 31 w = spdk_jsonrpc_begin_result(request); 32 spdk_json_write_object_begin(w); 33 spdk_json_write_named_uint32(w, "fsdev_io_pool_size", opts.fsdev_io_pool_size); 34 spdk_json_write_named_uint32(w, "fsdev_io_cache_size", opts.fsdev_io_cache_size); 35 spdk_json_write_object_end(w); 36 spdk_jsonrpc_end_result(request, w); 37 } 38 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 rpc_fsdev_set_opts(struct spdk_jsonrpc_request *request, const struct spdk_json_val *params) 52 { 53 struct rpc_fsdev_set_opts req = {}; 54 int rc; 55 struct spdk_fsdev_opts opts = {}; 56 57 if (spdk_json_decode_object(params, rpc_fsdev_set_opts_decoders, 58 SPDK_COUNTOF(rpc_fsdev_set_opts_decoders), 59 &req)) { 60 SPDK_ERRLOG("spdk_json_decode_object failed\n"); 61 spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, 62 "spdk_json_decode_object failed"); 63 return; 64 } 65 66 rc = spdk_fsdev_get_opts(&opts, sizeof(opts)); 67 if (rc) { 68 spdk_jsonrpc_send_error_response_fmt(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, 69 "spdk_fsdev_get_opts failed with %d", rc); 70 return; 71 } 72 73 opts.fsdev_io_pool_size = req.fsdev_io_pool_size; 74 opts.fsdev_io_cache_size = req.fsdev_io_cache_size; 75 76 rc = spdk_fsdev_set_opts(&opts); 77 if (rc) { 78 spdk_jsonrpc_send_error_response_fmt(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, 79 "spdk_fsdev_set_opts failed with %d", rc); 80 return; 81 } 82 83 spdk_jsonrpc_send_bool_response(request, true); 84 } 85 SPDK_RPC_REGISTER("fsdev_set_opts", rpc_fsdev_set_opts, SPDK_RPC_RUNTIME) 86