Commit 2b2ab244 authored by Ziye Yang's avatar Ziye Yang Committed by Jim Harris
Browse files

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: default avatarZiye Yang <optimistyzy@gmail.com>
Reviewed-on: https://review.gerrithub.io/362654


Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
Reviewed-by: default avatarDaniel Verkamp <daniel.verkamp@intel.com>
Tested-by: default avatarSPDK Automated Test System <sys_sgsw@intel.com>
parent 9104fe73
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -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);
+5 −11
Original line number Diff line number Diff line
@@ -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();

	/* 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,
	app_start_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();
+5 −1
Original line number Diff line number Diff line
@@ -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)) {
+8 −4
Original line number Diff line number Diff line
@@ -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);

}