From 2b2ab244778f429b5226366426b93ea35c74f63e Mon Sep 17 00:00:00 2001 From: Ziye Yang Date: Fri, 26 May 2017 14:34:51 +0800 Subject: [PATCH] reactor: handle start_fn event after subsystem init is ready SPDK subysystem initialization now is async, so we need to guarantee the initialization is done, then call event composed of start_fn passed by user in spdk_app_start. Change-Id: Icc790cbb3da04c1063204938b79140c4218986e4 Signed-off-by: Ziye Yang Reviewed-on: https://review.gerrithub.io/362654 Reviewed-by: Jim Harris Reviewed-by: Daniel Verkamp Tested-by: SPDK Automated Test System --- include/spdk_internal/event.h | 2 +- lib/event/app.c | 16 +++++----------- lib/event/subsystem.c | 6 +++++- test/lib/event/subsystem/subsystem_ut.c | 12 ++++++++---- 4 files changed, 19 insertions(+), 17 deletions(-) diff --git a/include/spdk_internal/event.h b/include/spdk_internal/event.h index 0f1a76ebc6..6b9c8a459a 100644 --- a/include/spdk_internal/event.h +++ b/include/spdk_internal/event.h @@ -72,7 +72,7 @@ struct spdk_subsystem_depend { void spdk_add_subsystem(struct spdk_subsystem *subsystem); void spdk_add_subsystem_depend(struct spdk_subsystem_depend *depend); -void spdk_subsystem_init(void); +void spdk_subsystem_init(void *arg1, void *arg2); int spdk_subsystem_fini(void); void spdk_subsystem_init_next(int rc); void spdk_subsystem_config(FILE *fp); diff --git a/lib/event/app.c b/lib/event/app.c index 0d224e6fe5..10b329ee28 100644 --- a/lib/event/app.c +++ b/lib/event/app.c @@ -429,21 +429,15 @@ spdk_app_fini(void) int spdk_app_start(spdk_event_fn start_fn, void *arg1, void *arg2) { - struct spdk_event *event; + struct spdk_event *app_start_event; g_spdk_app.rc = 0; - spdk_subsystem_init(); + app_start_event = spdk_event_allocate(rte_get_master_lcore(), start_fn, + arg1, arg2); - /* Early return if there is error */ - if (g_spdk_app.rc) { - return g_spdk_app.rc; - } - - event = spdk_event_allocate(rte_get_master_lcore(), start_fn, - arg1, arg2); - /* Queues up the event, but can't run it until the reactors start */ - spdk_event_call(event); + spdk_event_call(spdk_event_allocate(rte_get_master_lcore(), spdk_subsystem_init, + app_start_event, NULL)); /* This blocks until spdk_app_stop is called */ spdk_reactors_start(); diff --git a/lib/event/subsystem.c b/lib/event/subsystem.c index a3ce77f942..b30c89da81 100644 --- a/lib/event/subsystem.c +++ b/lib/event/subsystem.c @@ -42,6 +42,7 @@ static TAILQ_HEAD(spdk_subsystem_list, spdk_subsystem) g_subsystems = static TAILQ_HEAD(subsystem_depend, spdk_subsystem_depend) g_depends = TAILQ_HEAD_INITIALIZER(g_depends); static struct spdk_subsystem *g_next_subsystem; +static struct spdk_event *g_app_start_event; void spdk_add_subsystem(struct spdk_subsystem *subsystem) @@ -126,6 +127,7 @@ spdk_subsystem_init_next(int rc) } if (!g_next_subsystem) { + spdk_event_call(g_app_start_event); return; } @@ -137,10 +139,12 @@ spdk_subsystem_init_next(int rc) } void -spdk_subsystem_init(void) +spdk_subsystem_init(void *arg1, void *arg2) { struct spdk_subsystem_depend *dep; + g_app_start_event = (struct spdk_event *)arg1; + /* Verify that all dependency name and depends_on subsystems are registered */ TAILQ_FOREACH(dep, &g_depends, tailq) { if (!spdk_subsystem_find(&g_subsystems, dep->name)) { diff --git a/test/lib/event/subsystem/subsystem_ut.c b/test/lib/event/subsystem/subsystem_ut.c index 93aedafca8..00360138a6 100644 --- a/test/lib/event/subsystem/subsystem_ut.c +++ b/test/lib/event/subsystem/subsystem_ut.c @@ -47,6 +47,10 @@ spdk_app_stop(int rc) global_rc = rc; } +void spdk_event_call(struct spdk_event *event) +{ +} + static void set_up_subsystem(struct spdk_subsystem *subsystem, const char *name) { @@ -87,7 +91,7 @@ subsystem_sort_test_depends_on_single(void) char subsystem_name[16]; global_rc = -1; - spdk_subsystem_init(); + spdk_subsystem_init(NULL, NULL); i = 4; TAILQ_FOREACH(subsystem, &g_subsystems, tailq) { @@ -131,7 +135,7 @@ subsystem_sort_test_depends_on_multiple(void) } global_rc = -1; - spdk_subsystem_init(); + spdk_subsystem_init(NULL, NULL); subsystem = TAILQ_FIRST(&g_subsystems); CU_ASSERT(strcmp(subsystem->name, "interface") == 0); @@ -190,7 +194,7 @@ subsystem_sort_test_missing_dependency(void) spdk_add_subsystem_depend(&g_ut_subsystem_deps[0]); global_rc = -1; - spdk_subsystem_init(); + spdk_subsystem_init(NULL, NULL); CU_ASSERT(global_rc != 0); /* @@ -205,7 +209,7 @@ subsystem_sort_test_missing_dependency(void) spdk_add_subsystem_depend(&g_ut_subsystem_deps[0]); global_rc = -1; - spdk_subsystem_init(); + spdk_subsystem_init(NULL, NULL); CU_ASSERT(global_rc != 0); }