rpc: Add option to get_rpc_methods RPC to output only currently usable RPCs

Change-Id: I2dca34e1acb38d953ca7ac6d2907e1ecf2f19df0
Signed-off-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Reviewed-on: https://review.gerrithub.io/408420
Reviewed-by: Daniel Verkamp <daniel.verkamp@intel.com>
Reviewed-by: Pawel Wodkowski <pawelx.wodkowski@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Tested-by: SPDK Automated Test System <sys_sgsw@intel.com>
This commit is contained in:
Shuhei Matsumoto 2018-05-04 10:39:27 +09:00 committed by Jim Harris
parent 5c55a00df3
commit bf9806d533
3 changed files with 29 additions and 7 deletions

View File

@ -40,6 +40,7 @@
#include "spdk/env.h" #include "spdk/env.h"
#include "spdk/log.h" #include "spdk/log.h"
#include "spdk/string.h" #include "spdk/string.h"
#include "spdk/util.h"
#define RPC_DEFAULT_PORT "5260" #define RPC_DEFAULT_PORT "5260"
@ -240,19 +241,31 @@ spdk_rpc_close(void)
} }
} }
struct rpc_get_rpc_methods {
bool current;
};
static const struct spdk_json_object_decoder rpc_get_rpc_methods_decoders[] = {
{"current", offsetof(struct rpc_get_rpc_methods, current), spdk_json_decode_bool, true},
};
static void static void
spdk_rpc_get_rpc_methods(struct spdk_jsonrpc_request *request, spdk_rpc_get_rpc_methods(struct spdk_jsonrpc_request *request,
const struct spdk_json_val *params) const struct spdk_json_val *params)
{ {
struct rpc_get_rpc_methods req = {};
struct spdk_json_write_ctx *w; struct spdk_json_write_ctx *w;
struct spdk_rpc_method *m; struct spdk_rpc_method *m;
if (params != NULL) { if (params != NULL) {
if (spdk_json_decode_object(params, rpc_get_rpc_methods_decoders,
SPDK_COUNTOF(rpc_get_rpc_methods_decoders), &req)) {
SPDK_ERRLOG("spdk_json_decode_object failed\n");
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
"get_rpc_methods requires no parameters"); "Invalid parameters");
return; return;
} }
}
w = spdk_jsonrpc_begin_result(request); w = spdk_jsonrpc_begin_result(request);
if (w == NULL) { if (w == NULL) {
@ -261,9 +274,12 @@ spdk_rpc_get_rpc_methods(struct spdk_jsonrpc_request *request,
spdk_json_write_array_begin(w); spdk_json_write_array_begin(w);
SLIST_FOREACH(m, &g_rpc_methods, slist) { SLIST_FOREACH(m, &g_rpc_methods, slist) {
if (req.current && ((m->state_mask & g_rpc_state) != g_rpc_state)) {
continue;
}
spdk_json_write_string(w, m->name); spdk_json_write_string(w, m->name);
} }
spdk_json_write_array_end(w); spdk_json_write_array_end(w);
spdk_jsonrpc_end_result(request, w); spdk_jsonrpc_end_result(request, w);
} }
SPDK_RPC_REGISTER("get_rpc_methods", spdk_rpc_get_rpc_methods, SPDK_RPC_RUNTIME) SPDK_RPC_REGISTER("get_rpc_methods", spdk_rpc_get_rpc_methods, SPDK_RPC_STARTUP | SPDK_RPC_RUNTIME)

View File

@ -49,9 +49,10 @@ if __name__ == "__main__":
@call_cmd @call_cmd
def get_rpc_methods(args): def get_rpc_methods(args):
print_dict(rpc.get_rpc_methods(args.client)) print_dict(rpc.get_rpc_methods(args.client, args))
p = subparsers.add_parser('get_rpc_methods', help='Get list of supported RPC methods') p = subparsers.add_parser('get_rpc_methods', help='Get list of supported RPC methods')
p.add_argument('-c', '--current', help='Get list of RPC methods only callable in the current state.', action='store_true')
p.set_defaults(func=get_rpc_methods) p.set_defaults(func=get_rpc_methods)
@call_cmd @call_cmd

View File

@ -18,8 +18,13 @@ def start_subsystem_init(client):
return client.call('start_subsystem_init') return client.call('start_subsystem_init')
def get_rpc_methods(client): def get_rpc_methods(client, args):
return client.call('get_rpc_methods') params = {}
if args.current:
params['current'] = args.current
return client.call('get_rpc_methods', params)
def save_config(client, args): def save_config(client, args):