Commit 09725201 authored by Jim Harris's avatar Jim Harris Committed by Changpeng Liu
Browse files

rpc: ensure RPCs are registered before aliases



Some older clang versions will reorder constructor functions
rather than execute them in the order they are defined.  This
causes registration failures for RPC aliases when the alias
is registered before the RPC that it refers to.  So use
constructor priorities to ensure that all RPCs are registered
before any aliases.

Fixes issue #892.

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

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


Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarBen Walker <benjamin.walker@intel.com>
Reviewed-by: default avatarShuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Reviewed-by: default avatarTomasz Zawadzki <tomasz.zawadzki@intel.com>
Reviewed-by: default avatarChangpeng Liu <changpeng.liu@intel.com>
parent 59a3afa0
Loading
Loading
Loading
Loading
+8 −2
Original line number Diff line number Diff line
@@ -103,14 +103,20 @@ int spdk_rpc_is_method_allowed(const char *method, uint32_t state_mask);
#define SPDK_RPC_STARTUP	0x1
#define SPDK_RPC_RUNTIME	0x2

/* Give SPDK_RPC_REGISTER a higher execution priority than
 * SPDK_RPC_REGISTER_ALIAS_DEPRECATED to ensure all of the RPCs are registered
 * before we try registering any aliases.  Some older versions of clang may
 * otherwise execute the constructors in a different order than
 * defined in the source file (see issue #892).
 */
#define SPDK_RPC_REGISTER(method, func, state_mask) \
static void __attribute__((constructor)) rpc_register_##func(void) \
static void __attribute__((constructor(1000))) rpc_register_##func(void) \
{ \
	spdk_rpc_register_method(method, func, state_mask); \
}

#define SPDK_RPC_REGISTER_ALIAS_DEPRECATED(method, alias) \
static void __attribute__((constructor)) rpc_register_##alias(void) \
static void __attribute__((constructor(1001))) rpc_register_##alias(void) \
{ \
	spdk_rpc_register_alias_deprecated(#method, #alias); \
}