event: Move json config loading to init

Loading subsystems and restoring state from a JSON config file is useful
outside of the SPDK application framework, so move it to lib/init.

Change-Id: I7dd3ceace2e7b1b28eef83c91ce6a4eedc85740e
Signed-off-by: Ben Walker <benjamin.walker@intel.com>
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/6645
Reviewed-by: Tom Nabarro <tom.nabarro@outlook.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Changpeng Liu <changpeng.liu@intel.com>
Reviewed-by: Aleksey Marchuk <alexeymar@mellanox.com>
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Community-CI: Mellanox Build Bot
This commit is contained in:
Ben Walker 2021-03-02 12:34:25 -07:00 committed by Tomasz Zawadzki
parent 9f62796127
commit dde419084b
11 changed files with 29 additions and 19 deletions

View File

@ -219,8 +219,8 @@ spdk_fio_bdev_init_start(void *arg)
{
bool *done = arg;
spdk_app_json_config_load(g_json_config_file, SPDK_DEFAULT_RPC_ADDR,
spdk_fio_bdev_init_done, done, true);
spdk_subsystem_init_from_json_config(g_json_config_file, SPDK_DEFAULT_RPC_ADDR,
spdk_fio_bdev_init_done, done, true);
}
static void

View File

@ -76,6 +76,20 @@ typedef void (*spdk_subsystem_init_fn)(int rc, void *ctx);
*/
void spdk_subsystem_init(spdk_subsystem_init_fn cb_fn, void *cb_arg);
/**
* Like spdk_subsystem_init, but additionally configure each subsystem using the provided JSON config
* file. This will automatically start a JSON RPC server and then stop it.
*
* \param json_config_file Path to a JSON config file.
* \param rpc_addr Path to a unix domain socket to send configuration RPCs to.
* \param cb_fn Function called when the process is complete.
* \param cb_arg User context passed to cb_fn.
* \param stop_on_error Whether to stop initialization if one of the JSON RPCs fails.
*/
void spdk_subsystem_init_from_json_config(const char *json_config_file, const char *rpc_addr,
spdk_subsystem_init_fn cb_fn, void *cb_arg,
bool stop_on_error);
typedef void (*spdk_subsystem_fini_fn)(void *ctx);
/**

View File

@ -164,12 +164,6 @@ int spdk_reactor_set_interrupt_mode(uint32_t lcore, bool new_in_interrupt,
*/
struct spdk_thread *_spdk_get_app_thread(void);
typedef void (*spdk_app_init_fn)(int rc, void *ctx);
void spdk_app_json_config_load(const char *json_config_file, const char *rpc_addr,
spdk_app_init_fn cb_fn, void *cb_arg,
bool stop_on_error);
struct spdk_governor_capabilities {
bool freq_change;
bool freq_getset;

View File

@ -40,7 +40,7 @@ SO_MINOR := 0
CFLAGS += $(ENV_CFLAGS)
LIBNAME = event
C_SRCS = app.c reactor.c json_config.c log_rpc.c \
C_SRCS = app.c reactor.c log_rpc.c \
app_rpc.c scheduler_static.c
# Do not compile schedulers and governors based on DPDK env

View File

@ -403,8 +403,9 @@ bootstrap_fn(void *arg1)
if (g_spdk_app.json_config_file) {
g_delay_subsystem_init = false;
spdk_app_json_config_load(g_spdk_app.json_config_file, g_spdk_app.rpc_addr, app_start_rpc,
NULL, !g_spdk_app.json_config_ignore_errors);
spdk_subsystem_init_from_json_config(g_spdk_app.json_config_file, g_spdk_app.rpc_addr,
app_start_rpc,
NULL, !g_spdk_app.json_config_ignore_errors);
} else {
if (!g_delay_subsystem_init) {
spdk_subsystem_init(app_start_rpc, NULL);

View File

@ -25,7 +25,6 @@
spdk_reactor_get;
spdk_for_each_reactor;
spdk_reactor_set_interrupt_mode;
spdk_app_json_config_load;
local: *;
};

View File

@ -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 rpc.c
C_SRCS = json_config.c subsystem.c subsystem_rpc.c rpc.c
LIBNAME = init
SPDK_MAP_FILE = $(abspath $(CURDIR)/spdk_init.map)

View File

@ -86,7 +86,7 @@ typedef void (*client_resp_handler)(struct load_json_config_ctx *,
struct load_json_config_ctx {
/* Thread used during configuration. */
struct spdk_thread *thread;
spdk_app_init_fn cb_fn;
spdk_subsystem_init_fn cb_fn;
void *cb_arg;
bool stop_on_error;
@ -567,9 +567,9 @@ err:
}
void
spdk_app_json_config_load(const char *json_config_file, const char *rpc_addr,
spdk_app_init_fn cb_fn, void *cb_arg,
bool stop_on_error)
spdk_subsystem_init_from_json_config(const char *json_config_file, const char *rpc_addr,
spdk_subsystem_init_fn cb_fn, void *cb_arg,
bool stop_on_error)
{
struct load_json_config_ctx *ctx = calloc(1, sizeof(*ctx));
int rc;

View File

@ -8,6 +8,7 @@
spdk_subsystem_fini;
spdk_subsystem_init_next;
spdk_subsystem_fini_next;
spdk_subsystem_init_from_json_config;
spdk_rpc_initialize;
spdk_rpc_finish;

View File

@ -84,7 +84,7 @@ DEPDIRS-trace := log util $(JSON_LIBS)
DEPDIRS-bdev := log util thread $(JSON_LIBS) notify trace
DEPDIRS-blobfs := log thread blob trace
DEPDIRS-event := log util thread $(JSON_LIBS) trace init
DEPDIRS-init := jsonrpc json log rpc thread
DEPDIRS-init := jsonrpc json log rpc thread util
DEPDIRS-ftl := log util thread trace bdev
DEPDIRS-nbd := log util thread $(JSON_LIBS) bdev

View File

@ -51,7 +51,8 @@ DEFINE_STUB_V(spdk_rpc_set_state, (uint32_t state));
DEFINE_STUB(spdk_rpc_get_state, uint32_t, (void), SPDK_RPC_RUNTIME);
DEFINE_STUB(spdk_rpc_initialize, int, (const char *listen_addr), 0);
DEFINE_STUB_V(spdk_rpc_finish, (void));
DEFINE_STUB_V(spdk_app_json_config_load, (const char *json_config_file, const char *rpc_addr,
DEFINE_STUB_V(spdk_subsystem_init_from_json_config, (const char *json_config_file,
const char *rpc_addr,
spdk_subsystem_init_fn cb_fn, void *cb_arg, bool stop_on_error));
DEFINE_STUB_V(spdk_reactors_start, (void));
DEFINE_STUB_V(spdk_reactors_stop, (void *arg1));