Commit bcacfb78 authored by Jim Harris's avatar Jim Harris
Browse files

rpc: do not allow duplicated rpc method names



Also print error message when a duplicate is detected.

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

Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/453031


Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarShuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Reviewed-by: default avatarChangpeng Liu <changpeng.liu@intel.com>
Reviewed-by: default avatarBen Walker <benjamin.walker@intel.com>
parent c49abdd2
Loading
Loading
Loading
Loading
+18 −0
Original line number Diff line number Diff line
@@ -87,6 +87,18 @@ _get_rpc_method(const struct spdk_json_val *method)
	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
spdk_jsonrpc_handler(struct spdk_jsonrpc_request *request,
		     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;

	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));
	assert(m != NULL);