xref: /spdk/module/keyring/linux/keyring_rpc.c (revision 8afdeef3becfe9409cc9e7372bd0bc10e8b7d46d)
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright (c) 2024 Intel Corporation. All rights reserved.
3  */
4 
5 #include "keyring_linux.h"
6 #include "spdk/rpc.h"
7 #include "spdk/string.h"
8 #include "spdk/util.h"
9 
10 static const struct spdk_json_object_decoder rpc_keyring_linux_set_options_decoders[] = {
11 	{"enable", offsetof(struct keyring_linux_opts, enable), spdk_json_decode_bool, true},
12 };
13 
14 static void
15 rpc_keyring_linux_set_options(struct spdk_jsonrpc_request *request,
16 			      const struct spdk_json_val *params)
17 {
18 	struct keyring_linux_opts opts = {};
19 	int rc;
20 
21 	keyring_linux_get_opts(&opts);
22 	if (spdk_json_decode_object(params, rpc_keyring_linux_set_options_decoders,
23 				    SPDK_COUNTOF(rpc_keyring_linux_set_options_decoders), &opts)) {
24 		spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
25 						 spdk_strerror(EINVAL));
26 		return;
27 	}
28 
29 	rc = keyring_linux_set_opts(&opts);
30 	if (rc != 0) {
31 		spdk_jsonrpc_send_error_response(request, rc, spdk_strerror(-rc));
32 		return;
33 	}
34 
35 	spdk_jsonrpc_send_bool_response(request, true);
36 }
37 SPDK_RPC_REGISTER("keyring_linux_set_options", rpc_keyring_linux_set_options, SPDK_RPC_STARTUP)
38