From c3ab46a14c9584993bbb713042ac38a93e1c6f45 Mon Sep 17 00:00:00 2001 From: Ben Walker Date: Thu, 28 Feb 2019 16:39:52 -0700 Subject: [PATCH] event: Funnel the start up actions through a single event The rest of the stuff is going to be converted to using threads, but there must be one event at the beginning of time for now. Change-Id: Id4689d73e006ccf7bbe001732798e0ae78c603ac Signed-off-by: Ben Walker Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/446987 Reviewed-by: Jim Harris Reviewed-by: Shuhei Matsumoto Reviewed-by: Changpeng Liu Reviewed-by: Darek Stojaczyk Tested-by: SPDK CI Jenkins --- lib/event/app.c | 38 +++++++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/lib/event/app.c b/lib/event/app.c index 2d5a55b40..0d309fa6c 100644 --- a/lib/event/app.c +++ b/lib/event/app.c @@ -66,6 +66,8 @@ struct spdk_app { static struct spdk_app g_spdk_app; static struct spdk_event *g_app_start_event = NULL; +struct spdk_event *g_rpc_start_event = NULL; +struct spdk_event *g_config_load_event = NULL; static struct spdk_event *g_shutdown_event = NULL; static int g_init_lcore; static bool g_delay_subsystem_init = false; @@ -562,14 +564,28 @@ spdk_app_setup_trace(struct spdk_app_opts *opts) return 0; } +static void +bootstrap_fn(void *arg1, void *arg2) +{ + if (g_config_load_event) { + spdk_event_call(g_config_load_event); + } else { + if (!g_delay_subsystem_init) { + spdk_subsystem_init(g_rpc_start_event); + } else { + spdk_event_call(g_rpc_start_event); + } + } +} + int spdk_app_start(struct spdk_app_opts *opts, spdk_event_fn start_fn, void *arg1) { struct spdk_conf *config = NULL; int rc; - struct spdk_event *rpc_start_event, *config_load_event; char *tty; + struct spdk_event *event; if (!opts) { SPDK_ERRLOG("opts should not be NULL\n"); @@ -655,24 +671,20 @@ spdk_app_start(struct spdk_app_opts *opts, spdk_event_fn start_fn, g_spdk_app.rc = 0; g_init_lcore = spdk_env_get_current_core(); g_delay_subsystem_init = opts->delay_subsystem_init; - g_app_start_event = spdk_event_allocate(g_init_lcore, start_fn, arg1, NULL); - rpc_start_event = spdk_event_allocate(g_init_lcore, spdk_app_start_rpc, - (void *)opts->rpc_addr, NULL); + event = spdk_event_allocate(g_init_lcore, bootstrap_fn, NULL, NULL); + g_app_start_event = spdk_event_allocate(g_init_lcore, start_fn, arg1, NULL); + g_rpc_start_event = spdk_event_allocate(g_init_lcore, spdk_app_start_rpc, + (void *)opts->rpc_addr, NULL); if (opts->json_config_file) { g_delay_subsystem_init = false; - config_load_event = spdk_event_allocate(g_init_lcore, _spdk_app_json_config_load, - opts, rpc_start_event); - spdk_event_call(config_load_event); - } else { - if (!g_delay_subsystem_init) { - spdk_subsystem_init(rpc_start_event); - } else { - spdk_event_call(rpc_start_event); - } + g_config_load_event = spdk_event_allocate(g_init_lcore, _spdk_app_json_config_load, + opts, g_rpc_start_event); } + spdk_event_call(event); + /* This blocks until spdk_app_stop is called */ spdk_reactors_start();