diff --git a/include/spdk/rpc.h b/include/spdk/rpc.h index e48c86dc5..b85606e43 100644 --- a/include/spdk/rpc.h +++ b/include/spdk/rpc.h @@ -42,6 +42,18 @@ extern "C" { #endif +/** + * Verify correctness of registered RPC methods and aliases. + * + * Incorrect registrations include: + * - multiple RPC methods registered with the same name + * - RPC alias registered with a method that does not exist + * - RPC alias registered that points to another alias + * + * \return true if registrations are all correct, false otherwise + */ +bool spdk_rpc_verify_methods(void); + /** * Start listening for RPC connections. * diff --git a/lib/event/rpc.c b/lib/event/rpc.c index f84143496..5f20fe5f7 100644 --- a/lib/event/rpc.c +++ b/lib/event/rpc.c @@ -61,6 +61,11 @@ spdk_rpc_initialize(const char *listen_addr) return; } + if (!spdk_rpc_verify_methods()) { + spdk_app_stop(-EINVAL); + return; + } + /* Listen on the requested address */ rc = spdk_rpc_listen(listen_addr); if (rc != 0) { diff --git a/lib/rpc/rpc.c b/lib/rpc/rpc.c index 1fac2b5e5..192d85986 100644 --- a/lib/rpc/rpc.c +++ b/lib/rpc/rpc.c @@ -51,6 +51,7 @@ static int g_rpc_lock_fd = -1; static struct spdk_jsonrpc_server *g_jsonrpc_server = NULL; static uint32_t g_rpc_state; +static bool g_rpcs_correct = true; struct spdk_rpc_method { const char *name; @@ -249,7 +250,8 @@ spdk_rpc_register_method(const char *method, spdk_rpc_method_handler func, uint3 m = _get_rpc_method_raw(method); if (m != NULL) { - SPDK_ERRLOG("duplicate RPC %s registered - ignoring...\n", method); + SPDK_ERRLOG("duplicate RPC %s registered...\n", method); + g_rpcs_correct = false; return; } @@ -275,11 +277,13 @@ spdk_rpc_register_alias_deprecated(const char *method, const char *alias) if (base == NULL) { SPDK_ERRLOG("cannot create alias %s - method %s does not exist\n", alias, method); + g_rpcs_correct = false; return; } if (base->is_alias_of != NULL) { SPDK_ERRLOG("cannot create alias %s of alias %s\n", alias, method); + g_rpcs_correct = false; return; } @@ -297,6 +301,12 @@ spdk_rpc_register_alias_deprecated(const char *method, const char *alias) SLIST_INSERT_HEAD(&g_rpc_methods, m, slist); } +bool +spdk_rpc_verify_methods(void) +{ + return g_rpcs_correct; +} + int spdk_rpc_is_method_allowed(const char *method, uint32_t state_mask) {