From 9f62796127c23a932d95aae57806ed126919ab8d Mon Sep 17 00:00:00 2001 From: Ben Walker Date: Tue, 2 Mar 2021 12:22:03 -0700 Subject: [PATCH] event: Move RPC server initialization to init I'm not sure whether this should go into lib/init or to lib/rpc directly, but I've chosen lib/init for now. This is to support applications that want to run the SPDK JSON RPC server, but aren't using the SPDK application framework. Signed-off-by: Ben Walker Change-Id: I79ca39aa0ca6e1a3a6905b0bf73e6cc99b086e55 Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/6644 Reviewed-by: Tom Nabarro Reviewed-by: Changpeng Liu Reviewed-by: Jim Harris Reviewed-by: Aleksey Marchuk Reviewed-by: Paul Luse Reviewed-by: Shuhei Matsumoto Tested-by: SPDK CI Jenkins Community-CI: Mellanox Build Bot --- include/spdk/event.h | 3 +-- include/spdk/init.h | 17 +++++++++++++++++ include/spdk_internal/event.h | 3 --- lib/event/Makefile | 2 +- lib/event/spdk_event.map | 2 -- lib/init/Makefile | 2 +- lib/{event => init}/rpc.c | 3 +-- lib/init/spdk_init.map | 3 +++ 8 files changed, 24 insertions(+), 11 deletions(-) rename lib/{event => init}/rpc.c (98%) diff --git a/include/spdk/event.h b/include/spdk/event.h index d65c29172..74c946728 100644 --- a/include/spdk/event.h +++ b/include/spdk/event.h @@ -44,6 +44,7 @@ #include "spdk/stdinc.h" #include "spdk/cpuset.h" +#include "spdk/init.h" #include "spdk/queue.h" #include "spdk/log.h" #include "spdk/thread.h" @@ -82,8 +83,6 @@ typedef void (*spdk_app_shutdown_cb)(void); */ typedef void (*spdk_sighandler_t)(int signal); -#define SPDK_DEFAULT_RPC_ADDR "/var/tmp/spdk.sock" - /** * \brief Event framework initialization options */ diff --git a/include/spdk/init.h b/include/spdk/init.h index 46e199966..339c8900c 100644 --- a/include/spdk/init.h +++ b/include/spdk/init.h @@ -45,6 +45,23 @@ extern "C" { #endif +#define SPDK_DEFAULT_RPC_ADDR "/var/tmp/spdk.sock" + +/** + * Create the SPDK JSON-RPC server and listen at the provided address. The RPC server is optional and is + * independent of subsystem initialization. The RPC server can be started and stopped at any time. + * + * \param listen_addr Path to a unix domain socket to listen on + * + * \return Negated errno on failure. 0 on success. + */ +int spdk_rpc_initialize(const char *listen_addr); + +/** + * Shut down the SPDK JSON-RPC target + */ +void spdk_rpc_finish(void); + typedef void (*spdk_subsystem_init_fn)(int rc, void *ctx); /** diff --git a/include/spdk_internal/event.h b/include/spdk_internal/event.h index 2e65798b0..0a923b03a 100644 --- a/include/spdk_internal/event.h +++ b/include/spdk_internal/event.h @@ -170,9 +170,6 @@ void spdk_app_json_config_load(const char *json_config_file, const char *rpc_add spdk_app_init_fn cb_fn, void *cb_arg, bool stop_on_error); -int spdk_rpc_initialize(const char *listen_addr); -void spdk_rpc_finish(void); - struct spdk_governor_capabilities { bool freq_change; bool freq_getset; diff --git a/lib/event/Makefile b/lib/event/Makefile index 5cd155870..6077e3d6e 100644 --- a/lib/event/Makefile +++ b/lib/event/Makefile @@ -40,7 +40,7 @@ SO_MINOR := 0 CFLAGS += $(ENV_CFLAGS) LIBNAME = event -C_SRCS = app.c reactor.c rpc.c json_config.c log_rpc.c \ +C_SRCS = app.c reactor.c json_config.c log_rpc.c \ app_rpc.c scheduler_static.c # Do not compile schedulers and governors based on DPDK env diff --git a/lib/event/spdk_event.map b/lib/event/spdk_event.map index 146dc29c4..206670d5c 100644 --- a/lib/event/spdk_event.map +++ b/lib/event/spdk_event.map @@ -26,8 +26,6 @@ spdk_for_each_reactor; spdk_reactor_set_interrupt_mode; spdk_app_json_config_load; - spdk_rpc_initialize; - spdk_rpc_finish; local: *; }; diff --git a/lib/init/Makefile b/lib/init/Makefile index 8cd598c06..8f00ca240 100644 --- a/lib/init/Makefile +++ b/lib/init/Makefile @@ -37,7 +37,7 @@ include $(SPDK_ROOT_DIR)/mk/spdk.common.mk SO_VER := 1 SO_MINOR := 0 -C_SRCS = subsystem.c subsystem_rpc.c +C_SRCS = subsystem.c subsystem_rpc.c rpc.c LIBNAME = init SPDK_MAP_FILE = $(abspath $(CURDIR)/spdk_init.map) diff --git a/lib/event/rpc.c b/lib/init/rpc.c similarity index 98% rename from lib/event/rpc.c rename to lib/init/rpc.c index 62c8d5bb2..2adaf8bde 100644 --- a/lib/event/rpc.c +++ b/lib/init/rpc.c @@ -34,12 +34,11 @@ #include "spdk/stdinc.h" #include "spdk/env.h" +#include "spdk/init.h" #include "spdk/thread.h" #include "spdk/log.h" #include "spdk/rpc.h" -#include "spdk_internal/event.h" - #define RPC_SELECT_INTERVAL 4000 /* 4ms */ static struct spdk_poller *g_rpc_poller = NULL; diff --git a/lib/init/spdk_init.map b/lib/init/spdk_init.map index 72088d6dd..5a6d694f7 100644 --- a/lib/init/spdk_init.map +++ b/lib/init/spdk_init.map @@ -9,5 +9,8 @@ spdk_subsystem_init_next; spdk_subsystem_fini_next; + spdk_rpc_initialize; + spdk_rpc_finish; + local: *; };