]> git.proxmox.com Git - ceph.git/blob - ceph/src/spdk/lib/event/rpc/subsystem_rpc.c
import 15.2.0 Octopus source
[ceph.git] / ceph / src / spdk / lib / event / rpc / subsystem_rpc.c
1 /*-
2 * BSD LICENSE
3 *
4 * Copyright (c) Intel Corporation.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
16 * distribution.
17 * * Neither the name of Intel Corporation nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 */
33
34 #include "spdk_internal/event.h"
35 #include "spdk/rpc.h"
36 #include "spdk/string.h"
37 #include "spdk/util.h"
38 #include "spdk/env.h"
39
40 static void
41 spdk_rpc_get_subsystems(struct spdk_jsonrpc_request *request,
42 const struct spdk_json_val *params)
43 {
44 struct spdk_json_write_ctx *w;
45 struct spdk_subsystem *subsystem;
46 struct spdk_subsystem_depend *deps;
47
48 if (params) {
49 spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
50 "'get_subsystems' requires no arguments");
51 return;
52 }
53
54 w = spdk_jsonrpc_begin_result(request);
55 if (w == NULL) {
56 return;
57 }
58
59 spdk_json_write_array_begin(w);
60 TAILQ_FOREACH(subsystem, &g_subsystems, tailq) {
61 spdk_json_write_object_begin(w);
62
63 spdk_json_write_named_string(w, "subsystem", subsystem->name);
64 spdk_json_write_named_array_begin(w, "depends_on");
65 TAILQ_FOREACH(deps, &g_subsystems_deps, tailq) {
66 if (strcmp(subsystem->name, deps->name) == 0) {
67 spdk_json_write_string(w, deps->depends_on);
68 }
69 }
70 spdk_json_write_array_end(w);
71
72 spdk_json_write_object_end(w);
73 }
74 spdk_json_write_array_end(w);
75 spdk_jsonrpc_end_result(request, w);
76 }
77
78 SPDK_RPC_REGISTER("get_subsystems", spdk_rpc_get_subsystems, SPDK_RPC_RUNTIME)
79
80 struct rpc_get_subsystem_config {
81 char *name;
82 };
83
84 static const struct spdk_json_object_decoder rpc_get_subsystem_config[] = {
85 {"name", offsetof(struct rpc_get_subsystem_config, name), spdk_json_decode_string},
86 };
87
88 static void
89 spdk_rpc_get_subsystem_config(struct spdk_jsonrpc_request *request,
90 const struct spdk_json_val *params)
91 {
92 struct rpc_get_subsystem_config req = {};
93 struct spdk_json_write_ctx *w;
94 struct spdk_subsystem *subsystem;
95
96 if (spdk_json_decode_object(params, rpc_get_subsystem_config,
97 SPDK_COUNTOF(rpc_get_subsystem_config), &req)) {
98 spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, "Invalid arguments");
99 return;
100 }
101
102 subsystem = spdk_subsystem_find(&g_subsystems, req.name);
103 if (!subsystem) {
104 spdk_jsonrpc_send_error_response_fmt(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
105 "Subsystem '%s' not found", req.name);
106 free(req.name);
107 return;
108 }
109
110 free(req.name);
111
112 w = spdk_jsonrpc_begin_result(request);
113 if (w) {
114 spdk_subsystem_config_json(w, subsystem);
115 spdk_jsonrpc_end_result(request, w);
116 }
117 }
118
119 SPDK_RPC_REGISTER("get_subsystem_config", spdk_rpc_get_subsystem_config, SPDK_RPC_RUNTIME)