rpc: add spdk_rpc_verify_methods()
This returns true if all registered methods and aliases are correct. False means that an error like one of the following occurred: - duplicate method with same name - alias specified for non-existant method - alias specified for another alias Also plumb this so that incorrect RPCs cause an SPDK application to exit. Note: there are cases where this would have been helpful during the recent RPC renaming. Fixes issue #940. Signed-off-by: Jim Harris <james.r.harris@intel.com> Change-Id: I235a433c9b8c01e82f16288a8d295e96c54e4eb1 Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/472441 Tested-by: SPDK CI Jenkins <sys_sgci@intel.com> Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com> Reviewed-by: Tomasz Zawadzki <tomasz.zawadzki@intel.com>
This commit is contained in:
parent
3ca9d4fc5e
commit
296e7fba03
@ -42,6 +42,18 @@
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#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.
|
* Start listening for RPC connections.
|
||||||
*
|
*
|
||||||
|
@ -61,6 +61,11 @@ spdk_rpc_initialize(const char *listen_addr)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!spdk_rpc_verify_methods()) {
|
||||||
|
spdk_app_stop(-EINVAL);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
/* Listen on the requested address */
|
/* Listen on the requested address */
|
||||||
rc = spdk_rpc_listen(listen_addr);
|
rc = spdk_rpc_listen(listen_addr);
|
||||||
if (rc != 0) {
|
if (rc != 0) {
|
||||||
|
@ -51,6 +51,7 @@ static int g_rpc_lock_fd = -1;
|
|||||||
|
|
||||||
static struct spdk_jsonrpc_server *g_jsonrpc_server = NULL;
|
static struct spdk_jsonrpc_server *g_jsonrpc_server = NULL;
|
||||||
static uint32_t g_rpc_state;
|
static uint32_t g_rpc_state;
|
||||||
|
static bool g_rpcs_correct = true;
|
||||||
|
|
||||||
struct spdk_rpc_method {
|
struct spdk_rpc_method {
|
||||||
const char *name;
|
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);
|
m = _get_rpc_method_raw(method);
|
||||||
if (m != NULL) {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -275,11 +277,13 @@ spdk_rpc_register_alias_deprecated(const char *method, const char *alias)
|
|||||||
if (base == NULL) {
|
if (base == NULL) {
|
||||||
SPDK_ERRLOG("cannot create alias %s - method %s does not exist\n",
|
SPDK_ERRLOG("cannot create alias %s - method %s does not exist\n",
|
||||||
alias, method);
|
alias, method);
|
||||||
|
g_rpcs_correct = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (base->is_alias_of != NULL) {
|
if (base->is_alias_of != NULL) {
|
||||||
SPDK_ERRLOG("cannot create alias %s of alias %s\n", alias, method);
|
SPDK_ERRLOG("cannot create alias %s of alias %s\n", alias, method);
|
||||||
|
g_rpcs_correct = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -297,6 +301,12 @@ spdk_rpc_register_alias_deprecated(const char *method, const char *alias)
|
|||||||
SLIST_INSERT_HEAD(&g_rpc_methods, m, slist);
|
SLIST_INSERT_HEAD(&g_rpc_methods, m, slist);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
spdk_rpc_verify_methods(void)
|
||||||
|
{
|
||||||
|
return g_rpcs_correct;
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
spdk_rpc_is_method_allowed(const char *method, uint32_t state_mask)
|
spdk_rpc_is_method_allowed(const char *method, uint32_t state_mask)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user