rpc: Add API to get method state mask
The new API will be used in the next patch to prevent calling metods for the seconds time when subsystem is initialized with config file Signed-off-by: Aleksey Marchuk <alexeymar@nvidia.com> Change-Id: I60ac8196e46ccb3b22b3af0607e1ba35a11a66a6 Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/14406 Reviewed-by: Shuhei Matsumoto <smatsumoto@nvidia.com> Reviewed-by: Jim Harris <james.r.harris@intel.com> Community-CI: Mellanox Build Bot Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
This commit is contained in:
parent
67bb33160a
commit
515419ac66
@ -55,6 +55,8 @@ Added warning message for `bdev_rbd_create`, if it is used without -c.
|
||||
Renamed `enable_vmd` RPC to `vmd_enable` to make it consistent with our naming scheme of
|
||||
`<subsystem>_<action>`. For now, the old name is still available, but is marked as deprecated.
|
||||
|
||||
New function `spdk_rpc_get_method_state_mask` was added to RPC library.
|
||||
|
||||
### raid
|
||||
|
||||
Renamed the `raid5` module to `raid5f` to reflect that it is not a traditional
|
||||
|
@ -1,6 +1,7 @@
|
||||
/* SPDX-License-Identifier: BSD-3-Clause
|
||||
* Copyright (c) Intel Corporation.
|
||||
* All rights reserved.
|
||||
* Copyright (c) 2022 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
||||
*/
|
||||
|
||||
#ifndef SPDK_RPC_CONFIG_H_
|
||||
@ -84,6 +85,16 @@ void spdk_rpc_register_alias_deprecated(const char *method, const char *alias);
|
||||
*/
|
||||
int spdk_rpc_is_method_allowed(const char *method, uint32_t state_mask);
|
||||
|
||||
/**
|
||||
* Return state mask of the method
|
||||
*
|
||||
* \param method Method name
|
||||
* \param[out] state_mask State mask of the method
|
||||
* \retval 0 if method is found and \b state_mask is filled
|
||||
* \retval -ENOENT if method is not found
|
||||
*/
|
||||
int spdk_rpc_get_method_state_mask(const char *method, uint32_t *state_mask);
|
||||
|
||||
#define SPDK_RPC_STARTUP 0x1
|
||||
#define SPDK_RPC_RUNTIME 0x2
|
||||
|
||||
|
@ -1,13 +1,14 @@
|
||||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
# Copyright (c) Intel Corporation.
|
||||
# All rights reserved.
|
||||
# Copyright (c) 2022 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
||||
#
|
||||
|
||||
SPDK_ROOT_DIR := $(abspath $(CURDIR)/../..)
|
||||
include $(SPDK_ROOT_DIR)/mk/spdk.common.mk
|
||||
|
||||
SO_VER := 4
|
||||
SO_MINOR := 0
|
||||
SO_MINOR := 1
|
||||
|
||||
C_SRCS = rpc.c
|
||||
LIBNAME = rpc
|
||||
|
@ -1,6 +1,7 @@
|
||||
/* SPDX-License-Identifier: BSD-3-Clause
|
||||
* Copyright (c) Intel Corporation. All rights reserved.
|
||||
* Copyright (c) 2019 Mellanox Technologies LTD. All rights reserved.
|
||||
* Copyright (c) 2022 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
||||
*/
|
||||
|
||||
#include <sys/file.h>
|
||||
@ -273,6 +274,21 @@ spdk_rpc_is_method_allowed(const char *method, uint32_t state_mask)
|
||||
return -ENOENT;
|
||||
}
|
||||
|
||||
int
|
||||
spdk_rpc_get_method_state_mask(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) {
|
||||
*state_mask = m->state_mask;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return -ENOENT;
|
||||
}
|
||||
|
||||
void
|
||||
spdk_rpc_close(void)
|
||||
{
|
||||
|
@ -9,6 +9,7 @@
|
||||
spdk_rpc_register_method;
|
||||
spdk_rpc_register_alias_deprecated;
|
||||
spdk_rpc_is_method_allowed;
|
||||
spdk_rpc_get_method_state_mask;
|
||||
spdk_rpc_set_state;
|
||||
spdk_rpc_get_state;
|
||||
|
||||
|
@ -146,7 +146,7 @@ static void
|
||||
test_spdk_rpc_is_method_allowed(void)
|
||||
{
|
||||
const char method[] = "test";
|
||||
uint32_t state_mask = SPDK_RPC_STARTUP;
|
||||
uint32_t state_mask = SPDK_RPC_STARTUP, m_state_mask;
|
||||
struct spdk_rpc_method m = {};
|
||||
int rc = 0;
|
||||
|
||||
@ -156,6 +156,9 @@ test_spdk_rpc_is_method_allowed(void)
|
||||
SLIST_INSERT_HEAD(&g_rpc_methods, &m, slist);
|
||||
rc = spdk_rpc_is_method_allowed(method, state_mask);
|
||||
CU_ASSERT(rc == -EPERM);
|
||||
rc = spdk_rpc_get_method_state_mask(method, &m_state_mask);
|
||||
CU_ASSERT(rc == 0);
|
||||
CU_ASSERT(m_state_mask == m.state_mask);
|
||||
|
||||
/* Case 2: Expect return 0 */
|
||||
state_mask = SPDK_RPC_RUNTIME;
|
||||
@ -166,6 +169,8 @@ test_spdk_rpc_is_method_allowed(void)
|
||||
SLIST_REMOVE_HEAD(&g_rpc_methods, slist);
|
||||
rc = spdk_rpc_is_method_allowed(method, state_mask);
|
||||
CU_ASSERT(rc == -ENOENT);
|
||||
rc = spdk_rpc_get_method_state_mask(method, &m_state_mask);
|
||||
CU_ASSERT(rc == -ENOENT);
|
||||
}
|
||||
|
||||
static void
|
||||
|
Loading…
Reference in New Issue
Block a user