event: Add return code to spdk_rpc_initialize

This is an internal API used in several places. The call can fail, so
make sure it can report that correctly.

Change-Id: Iac0ed2c8299c9dd3d2556070278a2224c3807b7b
Signed-off-by: Ben Walker <benjamin.walker@intel.com>
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/6640
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: <dongx.yi@intel.com>
Reviewed-by: Aleksey Marchuk <alexeymar@mellanox.com>
Reviewed-by: Tomasz Zawadzki <tomasz.zawadzki@intel.com>
Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
This commit is contained in:
Ben Walker 2021-03-02 12:45:59 -07:00 committed by Tomasz Zawadzki
parent 0731c2273d
commit f046750c32
6 changed files with 36 additions and 12 deletions

View File

@ -711,7 +711,13 @@ static void
nvmf_subsystem_init_done(int rc, void *cb_arg) nvmf_subsystem_init_done(int rc, void *cb_arg)
{ {
fprintf(stdout, "bdev subsystem init successfully\n"); fprintf(stdout, "bdev subsystem init successfully\n");
spdk_rpc_initialize(g_rpc_addr);
rc = spdk_rpc_initialize(g_rpc_addr);
if (rc) {
spdk_app_stop(rc);
return;
}
spdk_rpc_set_state(SPDK_RPC_RUNTIME); spdk_rpc_set_state(SPDK_RPC_RUNTIME);
g_target_state = NVMF_INIT_TARGET; g_target_state = NVMF_INIT_TARGET;

View File

@ -214,7 +214,7 @@ void spdk_app_json_config_load(const char *json_config_file, const char *rpc_add
*/ */
void spdk_subsystem_config_json(struct spdk_json_write_ctx *w, struct spdk_subsystem *subsystem); void spdk_subsystem_config_json(struct spdk_json_write_ctx *w, struct spdk_subsystem *subsystem);
void spdk_rpc_initialize(const char *listen_addr); int spdk_rpc_initialize(const char *listen_addr);
void spdk_rpc_finish(void); void spdk_rpc_finish(void);
struct spdk_governor_capabilities { struct spdk_governor_capabilities {

View File

@ -278,7 +278,12 @@ app_start_rpc(int rc, void *arg1)
return; return;
} }
spdk_rpc_initialize(g_spdk_app.rpc_addr); rc = spdk_rpc_initialize(g_spdk_app.rpc_addr);
if (rc) {
spdk_app_stop(rc);
return;
}
if (!g_delay_subsystem_init) { if (!g_delay_subsystem_init) {
spdk_rpc_set_state(SPDK_RPC_RUNTIME); spdk_rpc_set_state(SPDK_RPC_RUNTIME);
app_start_application(); app_start_application();
@ -393,6 +398,8 @@ app_setup_trace(struct spdk_app_opts *opts)
static void static void
bootstrap_fn(void *arg1) bootstrap_fn(void *arg1)
{ {
int rc;
if (g_spdk_app.json_config_file) { if (g_spdk_app.json_config_file) {
g_delay_subsystem_init = false; g_delay_subsystem_init = false;
spdk_app_json_config_load(g_spdk_app.json_config_file, g_spdk_app.rpc_addr, app_start_rpc, spdk_app_json_config_load(g_spdk_app.json_config_file, g_spdk_app.rpc_addr, app_start_rpc,
@ -401,7 +408,11 @@ bootstrap_fn(void *arg1)
if (!g_delay_subsystem_init) { if (!g_delay_subsystem_init) {
spdk_subsystem_init(app_start_rpc, NULL); spdk_subsystem_init(app_start_rpc, NULL);
} else { } else {
spdk_rpc_initialize(g_spdk_app.rpc_addr); rc = spdk_rpc_initialize(g_spdk_app.rpc_addr);
if (rc) {
spdk_app_stop(rc);
return;
}
} }
} }
} }

View File

@ -614,8 +614,11 @@ spdk_app_json_config_load(const char *json_config_file, const char *rpc_addr,
goto fail; goto fail;
} }
/* FIXME: spdk_rpc_initialize() function should return error code. */ rc = spdk_rpc_initialize(ctx->rpc_socket_path_temp);
spdk_rpc_initialize(ctx->rpc_socket_path_temp); if (rc) {
goto fail;
}
ctx->client_conn = spdk_jsonrpc_client_connect(ctx->rpc_socket_path_temp, AF_UNIX); ctx->client_conn = spdk_jsonrpc_client_connect(ctx->rpc_socket_path_temp, AF_UNIX);
if (ctx->client_conn == NULL) { if (ctx->client_conn == NULL) {
SPDK_ERRLOG("Failed to connect to '%s'\n", ctx->rpc_socket_path_temp); SPDK_ERRLOG("Failed to connect to '%s'\n", ctx->rpc_socket_path_temp);

View File

@ -51,31 +51,35 @@ rpc_subsystem_poll(void *arg)
return SPDK_POLLER_BUSY; return SPDK_POLLER_BUSY;
} }
void int
spdk_rpc_initialize(const char *listen_addr) spdk_rpc_initialize(const char *listen_addr)
{ {
int rc; int rc;
if (listen_addr == NULL) { if (listen_addr == NULL) {
return; /* Not treated as an error */
return 0;
} }
if (!spdk_rpc_verify_methods()) { if (!spdk_rpc_verify_methods()) {
spdk_app_stop(-EINVAL); return -EINVAL;
return;
} }
/* Listen on the requested address */ /* Listen on the requested address */
rc = spdk_rpc_listen(listen_addr); rc = spdk_rpc_listen(listen_addr);
if (rc != 0) { if (rc != 0) {
SPDK_ERRLOG("Unable to start RPC service at %s\n", listen_addr); SPDK_ERRLOG("Unable to start RPC service at %s\n", listen_addr);
return; /* TODO: Eventually, treat this as an error. But it historically has not
* been and many tests rely on this gracefully failing. */
return 0;
} }
spdk_rpc_set_state(SPDK_RPC_STARTUP); spdk_rpc_set_state(SPDK_RPC_STARTUP);
/* Register a poller to periodically check for RPCs */ /* Register a poller to periodically check for RPCs */
g_rpc_poller = SPDK_POLLER_REGISTER(rpc_subsystem_poll, NULL, RPC_SELECT_INTERVAL); g_rpc_poller = SPDK_POLLER_REGISTER(rpc_subsystem_poll, NULL, RPC_SELECT_INTERVAL);
return 0;
} }
void void

View File

@ -49,7 +49,7 @@ DEFINE_STUB_V(spdk_rpc_register_method, (const char *method, spdk_rpc_method_han
DEFINE_STUB_V(spdk_rpc_register_alias_deprecated, (const char *method, const char *alias)); DEFINE_STUB_V(spdk_rpc_register_alias_deprecated, (const char *method, const char *alias));
DEFINE_STUB_V(spdk_rpc_set_state, (uint32_t state)); 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_get_state, uint32_t, (void), SPDK_RPC_RUNTIME);
DEFINE_STUB_V(spdk_rpc_initialize, (const char *listen_addr)); DEFINE_STUB(spdk_rpc_initialize, int, (const char *listen_addr), 0);
DEFINE_STUB_V(spdk_rpc_finish, (void)); 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_app_json_config_load, (const char *json_config_file, const char *rpc_addr,
spdk_subsystem_init_fn cb_fn, void *cb_arg, bool stop_on_error)); spdk_subsystem_init_fn cb_fn, void *cb_arg, bool stop_on_error));