Commit b85881ec authored by Tomasz Zawadzki's avatar Tomasz Zawadzki Committed by Jim Harris
Browse files

lib/event: remove app.c dependency from subsystem initialization



This change adds return code to spdk_subsystem_init().
Making it's caller responsible for handling application
state - such as calling spdk_app_stop().

This change implies that start_subsystem_init RPC does not
stop the application on failure, only reports back the error.

Renamed g_app_start/stop variables to now more relevant
g_subsystem_start/stop.

Change-Id: I66a7da6ecfb234a569c65279cc4b210ddac53d2a
Signed-off-by: default avatarTomasz Zawadzki <tomasz.zawadzki@intel.com>
Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/464412


Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarShuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
parent 1d039eba
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -53,6 +53,11 @@ Metadata support has been added to Null bdev module.

Protection information support has been added to Null bdev module.

### event

start_subsystem_init RPC no longer stops the application on error during
initialization.

### rpc

Added optional parameter '--md-size'to 'construct_null_bdev' RPC method.
+3 −2
Original line number Diff line number Diff line
@@ -86,13 +86,14 @@ extern struct spdk_subsystem_depend_list g_subsystems_deps;
void spdk_add_subsystem(struct spdk_subsystem *subsystem);
void spdk_add_subsystem_depend(struct spdk_subsystem_depend *depend);

void spdk_subsystem_init(spdk_msg_fn cb_fn, void *cb_arg);
typedef void (*spdk_subsystem_init_fn)(int rc, void *ctx);
void spdk_subsystem_init(spdk_subsystem_init_fn cb_fn, void *cb_arg);
void spdk_subsystem_fini(spdk_msg_fn cb_fn, void *cb_arg);
void spdk_subsystem_init_next(int rc);
void spdk_subsystem_fini_next(void);
void spdk_subsystem_config(FILE *fp);
void spdk_app_json_config_load(const char *json_config_file, const char *rpc_addr,
			       spdk_msg_fn cb_fn, void *cb_arg);
			       spdk_subsystem_init_fn cb_fn, void *cb_arg);

/**
 * Save pointed \c subsystem configuration to the JSON write context \c w. In case of
+13 −2
Original line number Diff line number Diff line
@@ -344,8 +344,13 @@ spdk_app_start_application(void)
}

static void
spdk_app_start_rpc(void *arg1)
spdk_app_start_rpc(int rc, void *arg1)
{
	if (rc) {
		spdk_app_stop(rc);
		return;
	}

	spdk_rpc_initialize(g_spdk_app.rpc_addr);
	if (!g_delay_subsystem_init) {
		spdk_rpc_set_state(SPDK_RPC_RUNTIME);
@@ -1051,13 +1056,19 @@ spdk_app_usage(void)
}

static void
spdk_rpc_start_subsystem_init_cpl(void *arg1)
spdk_rpc_start_subsystem_init_cpl(int rc, void *arg1)
{
	struct spdk_jsonrpc_request *request = arg1;
	struct spdk_json_write_ctx *w;

	assert(spdk_get_thread() == g_app_thread);

	if (rc) {
		spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INTERNAL_ERROR,
						 "subsystem_initialization failed");
		return;
	}

	spdk_rpc_set_state(SPDK_RPC_RUNTIME);
	/* If we're loading JSON config file, we're still operating on a fake,
	 * temporary RPC server. We'll have to defer calling the app start callback
+5 −10
Original line number Diff line number Diff line
@@ -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_msg_fn cb_fn;
	spdk_subsystem_init_fn cb_fn;
	void *cb_arg;

	/* Current subsystem */
@@ -132,14 +132,9 @@ spdk_app_json_config_load_done(struct load_json_config_ctx *ctx, int rc)

	spdk_rpc_finish();

	if (rc) {
		SPDK_ERRLOG("Config load failed. Stopping SPDK application.\n");
		spdk_app_stop(rc);
	} else {
		ctx->cb_fn(ctx->cb_arg);
	}
	SPDK_DEBUG_APP_CFG("Config load finished with rc %d\n", rc);
	ctx->cb_fn(rc, ctx->cb_arg);

	SPDK_DEBUG_APP_CFG("Config load finished\n");
	free(ctx->json_data);
	free(ctx->values);
	free(ctx);
@@ -544,14 +539,14 @@ err:

void
spdk_app_json_config_load(const char *json_config_file, const char *rpc_addr,
			  spdk_msg_fn cb_fn, void *cb_arg)
			  spdk_subsystem_init_fn cb_fn, void *cb_arg)
{
	struct load_json_config_ctx *ctx = calloc(1, sizeof(*ctx));
	int rc;

	assert(cb_fn);
	if (!ctx) {
		spdk_app_stop(-ENOMEM);
		cb_fn(-ENOMEM, cb_arg);
		return;
	}

+14 −14
Original line number Diff line number Diff line
@@ -44,10 +44,10 @@ struct spdk_subsystem_depend_list g_subsystems_deps = TAILQ_HEAD_INITIALIZER(g_s
static struct spdk_subsystem *g_next_subsystem;
static bool g_subsystems_initialized = false;
static bool g_subsystems_init_interrupted = false;
static spdk_msg_fn g_app_start_fn = NULL;
static void *g_app_start_arg = NULL;
static spdk_msg_fn g_app_stop_fn = NULL;
static void *g_app_stop_arg = NULL;
static spdk_subsystem_init_fn g_subsystem_start_fn = NULL;
static void *g_subsystem_start_arg = NULL;
static spdk_msg_fn g_subsystem_stop_fn = NULL;
static void *g_subsystem_stop_arg = NULL;
static struct spdk_thread *g_fini_thread = NULL;

void
@@ -127,7 +127,7 @@ spdk_subsystem_init_next(int rc)

	if (rc) {
		SPDK_ERRLOG("Init subsystem %s failed\n", g_next_subsystem->name);
		spdk_app_stop(rc);
		g_subsystem_start_fn(rc, g_subsystem_start_arg);
		return;
	}

@@ -139,7 +139,7 @@ spdk_subsystem_init_next(int rc)

	if (!g_next_subsystem) {
		g_subsystems_initialized = true;
		g_app_start_fn(g_app_start_arg);
		g_subsystem_start_fn(0, g_subsystem_start_arg);
		return;
	}

@@ -151,24 +151,24 @@ spdk_subsystem_init_next(int rc)
}

void
spdk_subsystem_init(spdk_msg_fn cb_fn, void *cb_arg)
spdk_subsystem_init(spdk_subsystem_init_fn cb_fn, void *cb_arg)
{
	struct spdk_subsystem_depend *dep;

	g_app_start_fn = cb_fn;
	g_app_start_arg = cb_arg;
	g_subsystem_start_fn = cb_fn;
	g_subsystem_start_arg = cb_arg;

	/* Verify that all dependency name and depends_on subsystems are registered */
	TAILQ_FOREACH(dep, &g_subsystems_deps, tailq) {
		if (!spdk_subsystem_find(&g_subsystems, dep->name)) {
			SPDK_ERRLOG("subsystem %s is missing\n", dep->name);
			spdk_app_stop(-1);
			g_subsystem_start_fn(-1, g_subsystem_start_arg);
			return;
		}
		if (!spdk_subsystem_find(&g_subsystems, dep->depends_on)) {
			SPDK_ERRLOG("subsystem %s dependency %s is missing\n",
				    dep->name, dep->depends_on);
			spdk_app_stop(-1);
			g_subsystem_start_fn(-1, g_subsystem_start_arg);
			return;
		}
	}
@@ -206,7 +206,7 @@ _spdk_subsystem_fini_next(void *arg1)
		g_next_subsystem = TAILQ_PREV(g_next_subsystem, spdk_subsystem_list, tailq);
	}

	g_app_stop_fn(g_app_stop_arg);
	g_subsystem_stop_fn(g_subsystem_stop_arg);
	return;
}

@@ -223,8 +223,8 @@ spdk_subsystem_fini_next(void)
void
spdk_subsystem_fini(spdk_msg_fn cb_fn, void *cb_arg)
{
	g_app_stop_fn = cb_fn;
	g_app_stop_arg = cb_arg;
	g_subsystem_stop_fn = cb_fn;
	g_subsystem_stop_arg = cb_arg;

	g_fini_thread = spdk_get_thread();

Loading