rpc: add helper method to find matching method_name
Signed-off-by: Jim Harris <james.r.harris@intel.com> Change-Id: I645d703985d64f171cb44ac59ee6e7e7ddf1b133 Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/453030 Tested-by: SPDK CI Jenkins <sys_sgci@intel.com> Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com> Reviewed-by: Changpeng Liu <changpeng.liu@intel.com> Reviewed-by: Ben Walker <benjamin.walker@intel.com>
This commit is contained in:
parent
656c938dcb
commit
c49abdd287
@ -73,6 +73,20 @@ spdk_rpc_get_state(void)
|
|||||||
return g_rpc_state;
|
return g_rpc_state;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static struct spdk_rpc_method *
|
||||||
|
_get_rpc_method(const struct spdk_json_val *method)
|
||||||
|
{
|
||||||
|
struct spdk_rpc_method *m;
|
||||||
|
|
||||||
|
SLIST_FOREACH(m, &g_rpc_methods, slist) {
|
||||||
|
if (spdk_json_strequal(method, m->name)) {
|
||||||
|
return m;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
spdk_jsonrpc_handler(struct spdk_jsonrpc_request *request,
|
spdk_jsonrpc_handler(struct spdk_jsonrpc_request *request,
|
||||||
const struct spdk_json_val *method,
|
const struct spdk_json_val *method,
|
||||||
@ -82,21 +96,20 @@ spdk_jsonrpc_handler(struct spdk_jsonrpc_request *request,
|
|||||||
|
|
||||||
assert(method != NULL);
|
assert(method != NULL);
|
||||||
|
|
||||||
SLIST_FOREACH(m, &g_rpc_methods, slist) {
|
m = _get_rpc_method(method);
|
||||||
if (spdk_json_strequal(method, m->name)) {
|
if (m == NULL) {
|
||||||
if ((m->state_mask & g_rpc_state) == g_rpc_state) {
|
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_METHOD_NOT_FOUND, "Method not found");
|
||||||
m->func(request, params);
|
return;
|
||||||
} else {
|
|
||||||
spdk_jsonrpc_send_error_response_fmt(request, SPDK_JSONRPC_ERROR_INVALID_STATE,
|
|
||||||
"Method is allowed in any state in the mask (%"PRIx32"),"
|
|
||||||
" but current state is (%"PRIx32")",
|
|
||||||
m->state_mask, g_rpc_state);
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_METHOD_NOT_FOUND, "Method not found");
|
if ((m->state_mask & g_rpc_state) == g_rpc_state) {
|
||||||
|
m->func(request, params);
|
||||||
|
} else {
|
||||||
|
spdk_jsonrpc_send_error_response_fmt(request, SPDK_JSONRPC_ERROR_INVALID_STATE,
|
||||||
|
"Method is allowed in any state in the mask (%"PRIx32"),"
|
||||||
|
" but current state is (%"PRIx32")",
|
||||||
|
m->state_mask, g_rpc_state);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
Loading…
Reference in New Issue
Block a user