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/rpc.h" 35 #include "spdk/string.h" 36 #include "spdk/util.h" 37 #include "spdk/env.h" 38 39 #include "spdk_internal/init.h" 40 41 #include "subsystem.h" 42 43 static void 44 rpc_framework_get_subsystems(struct spdk_jsonrpc_request *request, 45 const struct spdk_json_val *params) 46 { 47 struct spdk_json_write_ctx *w; 48 struct spdk_subsystem *subsystem; 49 struct spdk_subsystem_depend *deps; 50 51 if (params) { 52 spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, 53 "'framework_get_subsystems' requires no arguments"); 54 return; 55 } 56 57 w = spdk_jsonrpc_begin_result(request); 58 spdk_json_write_array_begin(w); 59 subsystem = subsystem_get_first(); 60 while (subsystem != NULL) { 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 deps = subsystem_get_first_depend(); 66 while (deps != NULL) { 67 if (strcmp(subsystem->name, deps->name) == 0) { 68 spdk_json_write_string(w, deps->depends_on); 69 } 70 deps = subsystem_get_next_depend(deps); 71 } 72 spdk_json_write_array_end(w); 73 spdk_json_write_object_end(w); 74 subsystem = subsystem_get_next(subsystem); 75 } 76 spdk_json_write_array_end(w); 77 spdk_jsonrpc_end_result(request, w); 78 } 79 80 SPDK_RPC_REGISTER("framework_get_subsystems", rpc_framework_get_subsystems, SPDK_RPC_RUNTIME) 81 SPDK_RPC_REGISTER_ALIAS_DEPRECATED(framework_get_subsystems, get_subsystems) 82 83 struct rpc_framework_get_config_ctx { 84 char *name; 85 }; 86 87 static const struct spdk_json_object_decoder rpc_framework_get_config_ctx[] = { 88 {"name", offsetof(struct rpc_framework_get_config_ctx, name), spdk_json_decode_string}, 89 }; 90 91 static void 92 rpc_framework_get_config(struct spdk_jsonrpc_request *request, 93 const struct spdk_json_val *params) 94 { 95 struct rpc_framework_get_config_ctx req = {}; 96 struct spdk_json_write_ctx *w; 97 struct spdk_subsystem *subsystem; 98 99 if (spdk_json_decode_object(params, rpc_framework_get_config_ctx, 100 SPDK_COUNTOF(rpc_framework_get_config_ctx), &req)) { 101 spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, "Invalid arguments"); 102 return; 103 } 104 105 subsystem = subsystem_find(req.name); 106 if (!subsystem) { 107 spdk_jsonrpc_send_error_response_fmt(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, 108 "Subsystem '%s' not found", req.name); 109 free(req.name); 110 return; 111 } 112 113 free(req.name); 114 115 w = spdk_jsonrpc_begin_result(request); 116 subsystem_config_json(w, subsystem); 117 spdk_jsonrpc_end_result(request, w); 118 } 119 120 SPDK_RPC_REGISTER("framework_get_config", rpc_framework_get_config, SPDK_RPC_RUNTIME) 121 SPDK_RPC_REGISTER_ALIAS_DEPRECATED(framework_get_config, get_subsystem_config) 122