diff --git a/CHANGELOG.md b/CHANGELOG.md index 11c1ad38f..5e66e641b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 `_`. 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 diff --git a/include/spdk/rpc.h b/include/spdk/rpc.h index 6f8c834e2..1d7c300fd 100644 --- a/include/spdk/rpc.h +++ b/include/spdk/rpc.h @@ -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 diff --git a/lib/rpc/Makefile b/lib/rpc/Makefile index 723ff4494..a3c64bb89 100644 --- a/lib/rpc/Makefile +++ b/lib/rpc/Makefile @@ -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 diff --git a/lib/rpc/rpc.c b/lib/rpc/rpc.c index be3807f2f..b543a2409 100644 --- a/lib/rpc/rpc.c +++ b/lib/rpc/rpc.c @@ -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 @@ -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) { diff --git a/lib/rpc/spdk_rpc.map b/lib/rpc/spdk_rpc.map index e15ff8b53..ac16218d6 100644 --- a/lib/rpc/spdk_rpc.map +++ b/lib/rpc/spdk_rpc.map @@ -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; diff --git a/test/unit/lib/rpc/rpc.c/rpc_ut.c b/test/unit/lib/rpc/rpc.c/rpc_ut.c index 59dc6c415..37a35624a 100644 --- a/test/unit/lib/rpc/rpc.c/rpc_ut.c +++ b/test/unit/lib/rpc/rpc.c/rpc_ut.c @@ -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