rpc: add spdk_rpc_is_method_allowed
spdk_rpc_is_method_allowed() allows to check if method is permitted for given state. Change-Id: I0b0046482262dfc7fa521647991eb88a38e4c1d3 Signed-off-by: Pawel Wodkowski <pawelx.wodkowski@intel.com> Reviewed-on: https://review.gerrithub.io/430487 Tested-by: SPDK CI Jenkins <sys_sgci@intel.com> Chandler-Test-Pool: SPDK Automated Test System <sys_sgsw@intel.com> Reviewed-by: Jim Harris <james.r.harris@intel.com> Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com> Reviewed-by: Ben Walker <benjamin.walker@intel.com>
This commit is contained in:
parent
b4692083f1
commit
69f713ee5b
@ -81,6 +81,17 @@ typedef void (*spdk_rpc_method_handler)(struct spdk_jsonrpc_request *request,
|
|||||||
void spdk_rpc_register_method(const char *method, spdk_rpc_method_handler func,
|
void spdk_rpc_register_method(const char *method, spdk_rpc_method_handler func,
|
||||||
uint32_t state_mask);
|
uint32_t state_mask);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if \c method is allowed for \c state_mask
|
||||||
|
*
|
||||||
|
* \param method Method name
|
||||||
|
* \param state_mask state mask to check against
|
||||||
|
* \return 0 if method is allowed or negative error code:
|
||||||
|
* -EPERM method is not allowed
|
||||||
|
* -ENOENT method not found
|
||||||
|
*/
|
||||||
|
int spdk_rpc_is_method_allowed(const char *method, uint32_t state_mask);
|
||||||
|
|
||||||
#define SPDK_RPC_STARTUP 0x1
|
#define SPDK_RPC_STARTUP 0x1
|
||||||
#define SPDK_RPC_RUNTIME 0x2
|
#define SPDK_RPC_RUNTIME 0x2
|
||||||
|
|
||||||
|
@ -223,6 +223,26 @@ spdk_rpc_register_method(const char *method, spdk_rpc_method_handler func, uint3
|
|||||||
SLIST_INSERT_HEAD(&g_rpc_methods, m, slist);
|
SLIST_INSERT_HEAD(&g_rpc_methods, m, slist);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
spdk_rpc_is_method_allowed(const char *method, uint32_t state_mask)
|
||||||
|
{
|
||||||
|
struct spdk_rpc_method *m;
|
||||||
|
|
||||||
|
SLIST_FOREACH(m, &g_rpc_methods, slist) {
|
||||||
|
if (strcmp(m->name, method) != 0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((m->state_mask & state_mask) == state_mask) {
|
||||||
|
return 0;
|
||||||
|
} else {
|
||||||
|
return -EPERM;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return -ENOENT;
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
spdk_rpc_close(void)
|
spdk_rpc_close(void)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user