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:
parent
5c55a00df3
commit
bf9806d533
@ -40,6 +40,7 @@
|
||||
#include "spdk/env.h"
|
||||
#include "spdk/log.h"
|
||||
#include "spdk/string.h"
|
||||
#include "spdk/util.h"
|
||||
|
||||
#define RPC_DEFAULT_PORT "5260"
|
||||
|
||||
@ -240,18 +241,30 @@ 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
|
||||
spdk_rpc_get_rpc_methods(struct spdk_jsonrpc_request *request,
|
||||
const struct spdk_json_val *params)
|
||||
{
|
||||
struct rpc_get_rpc_methods req = {};
|
||||
struct spdk_json_write_ctx *w;
|
||||
struct spdk_rpc_method *m;
|
||||
|
||||
if (params != NULL) {
|
||||
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
|
||||
"get_rpc_methods requires no parameters");
|
||||
return;
|
||||
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,
|
||||
"Invalid parameters");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
w = spdk_jsonrpc_begin_result(request);
|
||||
@ -261,9 +274,12 @@ spdk_rpc_get_rpc_methods(struct spdk_jsonrpc_request *request,
|
||||
|
||||
spdk_json_write_array_begin(w);
|
||||
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_array_end(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)
|
||||
|
@ -49,9 +49,10 @@ if __name__ == "__main__":
|
||||
|
||||
@call_cmd
|
||||
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.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)
|
||||
|
||||
@call_cmd
|
||||
|
@ -18,8 +18,13 @@ def start_subsystem_init(client):
|
||||
return client.call('start_subsystem_init')
|
||||
|
||||
|
||||
def get_rpc_methods(client):
|
||||
return client.call('get_rpc_methods')
|
||||
def get_rpc_methods(client, args):
|
||||
params = {}
|
||||
|
||||
if args.current:
|
||||
params['current'] = args.current
|
||||
|
||||
return client.call('get_rpc_methods', params)
|
||||
|
||||
|
||||
def save_config(client, args):
|
||||
|
Loading…
Reference in New Issue
Block a user