rpc: do not allow duplicated rpc method names

Also print error message when a duplicate is detected.

Signed-off-by: Jim Harris <james.r.harris@intel.com>
Change-Id: Ibcc667700a5b410e3a300507e76b99d04b09cfc1

Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/453031
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:
Jim Harris 2019-05-03 13:34:51 -07:00
parent c49abdd287
commit bcacfb7808

View File

@ -87,6 +87,18 @@ _get_rpc_method(const struct spdk_json_val *method)
return NULL; return NULL;
} }
static struct spdk_rpc_method *
_get_rpc_method_raw(const char *method)
{
struct spdk_json_val method_val;
method_val.type = SPDK_JSON_VAL_STRING;
method_val.len = strlen(method);
method_val.start = (char *)method;
return _get_rpc_method(&method_val);
}
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,
@ -224,6 +236,12 @@ spdk_rpc_register_method(const char *method, spdk_rpc_method_handler func, uint3
{ {
struct spdk_rpc_method *m; struct spdk_rpc_method *m;
m = _get_rpc_method_raw(method);
if (m != NULL) {
SPDK_ERRLOG("duplicate RPC %s registered - ignoring...\n", method);
return;
}
m = calloc(1, sizeof(struct spdk_rpc_method)); m = calloc(1, sizeof(struct spdk_rpc_method));
assert(m != NULL); assert(m != NULL);