Commit bf9806d5 authored by Shuhei Matsumoto's avatar Shuhei Matsumoto Committed by Jim Harris
Browse files

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

parent 5c55a00d
Loading
Loading
Loading
Loading
+20 −4
Original line number Diff line number Diff line
@@ -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,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
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) {
		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,
						 "get_rpc_methods requires no parameters");
							 "Invalid parameters");
			return;
		}
	}

	w = spdk_jsonrpc_begin_result(request);
	if (w == NULL) {
@@ -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)
+2 −1
Original line number Diff line number Diff line
@@ -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
+7 −2
Original line number Diff line number Diff line
@@ -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):