lib: Return instead of exit/abort in env_dpdk

Modifies spdk_env_init() and spdk_mem_map_init() such that
they return on failure instead of terminating with exit()
or abort().

Change-Id: I054c1d9b2e46516ff53d845328ab9547f54bdbc4
Signed-off-by: Lance Hartmann <lance.hartmann@oracle.com>
Reviewed-on: https://review.gerrithub.io/393987
Tested-by: SPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
Reviewed-by: Dariusz Stojaczyk <dariuszx.stojaczyk@intel.com>
This commit is contained in:
Lance Hartmann 2017-12-18 14:57:01 -05:00 committed by Jim Harris
parent 9014e913d9
commit 095f4254f1
27 changed files with 130 additions and 35 deletions

View File

@ -31,6 +31,19 @@ callback, the user must call spdk_for_each_channel_continue() to resume iteratio
The poller abstraction was removed from the bdev layer. There is now a general purpose
abstraction for pollers available in include/spdk/io_channel.h
### Lib
A set of changes were made in the SPDK's lib code altering,
instances of calls to `exit()` and `abort()` to return a failure instead
wherever reasonably possible. This has resulted in return type changes of
the API for:
- spdk_env_init() from type `void` to `int`.
- spdk_mem_map_init() from type `void` to `int`.
Applications making use of these APIs should be modified to check for
a non-zero return value instead of relying on them to fail without return.
### NVMe Driver
SPDK now supports hotplug for vfio-attached devices. But there is one thing keep in mind:

View File

@ -251,7 +251,11 @@ spdk_fio_init_env(struct thread_data *td)
opts.mem_size = eo->mem_mb;
}
spdk_env_init(&opts);
if (spdk_env_init(&opts) < 0) {
SPDK_ERRLOG("Unable to initialize SPDK env\n");
spdk_conf_free(config);
return -1;
}
spdk_unaffinitize_thread();
/* Create an SPDK thread temporarily */

View File

@ -385,7 +385,9 @@ init(void)
spdk_env_opts_init(&opts);
opts.name = "perf";
opts.core_mask = g_user_config.core_mask;
spdk_env_init(&opts);
if (spdk_env_init(&opts) < 0) {
return -1;
}
return 0;
}

View File

@ -385,7 +385,10 @@ init(void)
spdk_env_opts_init(&opts);
opts.name = "verify";
opts.core_mask = g_user_config.core_mask;
spdk_env_init(&opts);
if (spdk_env_init(&opts) < 0) {
fprintf(stderr, "Unable to initialize SPDK env\n");
return 1;
}
if (init_src_buffer() != 0) {
fprintf(stderr, "Could not init src buffer\n");

View File

@ -1094,7 +1094,9 @@ main(int argc, char **argv)
opts.name = "arb";
opts.core_mask = g_arbitration.core_mask;
opts.shm_id = g_arbitration.shm_id;
spdk_env_init(&opts);
if (spdk_env_init(&opts) < 0) {
return 1;
}
g_arbitration.tsc_rate = spdk_get_ticks_hz();

View File

@ -243,7 +243,14 @@ static int spdk_fio_setup(struct thread_data *td)
opts.name = "fio";
opts.mem_size = fio_options->mem_size;
opts.shm_id = fio_options->shm_id;
spdk_env_init(&opts);
if (spdk_env_init(&opts) < 0) {
SPDK_ERRLOG("Unable to initialize SPDK env\n");
free(fio_thread->iocq);
free(fio_thread);
fio_thread = NULL;
pthread_mutex_unlock(&mutex);
return 1;
}
spdk_env_initialized = true;
spdk_unaffinitize_thread();
}

View File

@ -317,7 +317,10 @@ int main(int argc, char **argv)
spdk_env_opts_init(&opts);
opts.name = "hello_world";
opts.shm_id = 0;
spdk_env_init(&opts);
if (spdk_env_init(&opts) < 0) {
fprintf(stderr, "Unable to initialize SPDK env\n");
return 1;
}
printf("Initializing NVMe Controllers\n");

View File

@ -460,7 +460,10 @@ int main(int argc, char **argv)
if (g_shm_id > -1) {
opts.shm_id = g_shm_id;
}
spdk_env_init(&opts);
if (spdk_env_init(&opts) < 0) {
fprintf(stderr, "Unable to initialize SPDK env\n");
return 1;
}
g_tsc_rate = spdk_get_ticks_hz();

View File

@ -1284,7 +1284,10 @@ int main(int argc, char **argv)
if (g_trid.trtype != SPDK_NVME_TRANSPORT_PCIE) {
opts.no_pci = true;
}
spdk_env_init(&opts);
if (spdk_env_init(&opts) < 0) {
fprintf(stderr, "Unable to initialize SPDK env\n");
return 1;
}
/* A specific trid is required. */
if (strlen(g_trid.traddr) != 0) {

View File

@ -895,7 +895,10 @@ int main(int argc, char **argv)
opts.name = "nvme_manage";
opts.core_mask = "0x1";
opts.shm_id = g_shm_id;
spdk_env_init(&opts);
if (spdk_env_init(&opts) < 0) {
fprintf(stderr, "Unable to initialize SPDK env\n");
return 1;
}
if (spdk_nvme_probe(NULL, NULL, probe_cb, attach_cb, NULL) != 0) {
fprintf(stderr, "spdk_nvme_probe() failed\n");

View File

@ -1531,7 +1531,11 @@ int main(int argc, char **argv)
if (g_no_pci) {
opts.no_pci = g_no_pci;
}
spdk_env_init(&opts);
if (spdk_env_init(&opts) < 0) {
fprintf(stderr, "Unable to initialize SPDK env\n");
rc = -1;
goto cleanup;
}
g_tsc_rate = spdk_get_ticks_hz();

View File

@ -359,7 +359,10 @@ int main(int argc, char **argv)
opts.name = "reserve";
opts.core_mask = "0x1";
opts.shm_id = 0;
spdk_env_init(&opts);
if (spdk_env_init(&opts) < 0) {
fprintf(stderr, "Unable to initialize SPDK env\n");
return 1;
}
if (spdk_nvme_probe(NULL, NULL, probe_cb, attach_cb, NULL) != 0) {
fprintf(stderr, "spdk_nvme_probe() failed\n");

View File

@ -74,8 +74,9 @@ void spdk_env_opts_init(struct spdk_env_opts *opts);
/**
* \brief Initialize the environment library. This must be called prior to using
* any other functions in this library.
* \return 0 on success, or a negated errno value on failure.
*/
void spdk_env_init(const struct spdk_env_opts *opts);
int spdk_env_init(const struct spdk_env_opts *opts);
/**
* Allocate a pinned, physically contiguous memory buffer with the

View File

@ -84,8 +84,8 @@ int spdk_pci_enumerate(struct spdk_pci_enum_ctx *ctx, spdk_pci_enum_cb enum_cb,
int spdk_pci_device_attach(struct spdk_pci_enum_ctx *ctx, spdk_pci_enum_cb enum_cb, void *enum_ctx,
struct spdk_pci_addr *pci_address);
void spdk_mem_map_init(void);
void spdk_vtophys_init(void);
int spdk_mem_map_init(void);
int spdk_vtophys_init(void);
/**
* Increase the refcount of active DMA-capable devices managed by SPDK.

View File

@ -140,7 +140,9 @@ spdk_free_args(char **args, int argcount)
free(args[i]);
}
free(args);
if (argcount) {
free(args);
}
}
static char **
@ -149,6 +151,8 @@ spdk_push_arg(char *args[], int *argcount, char *arg)
char **tmp;
if (arg == NULL) {
fprintf(stderr, "%s: NULL arg supplied\n", __func__);
spdk_free_args(args, *argcount);
return NULL;
}
@ -261,7 +265,7 @@ spdk_build_eal_cmdline(const struct spdk_env_opts *opts)
return argcount;
}
void spdk_env_init(const struct spdk_env_opts *opts)
int spdk_env_init(const struct spdk_env_opts *opts)
{
char **dpdk_args = NULL;
int i, rc;
@ -270,7 +274,7 @@ void spdk_env_init(const struct spdk_env_opts *opts)
rc = spdk_build_eal_cmdline(opts);
if (rc < 0) {
fprintf(stderr, "Invalid arguments to initialize DPDK\n");
exit(-1);
return -1;
}
printf("Starting %s initialization...\n", rte_version());
@ -287,7 +291,7 @@ void spdk_env_init(const struct spdk_env_opts *opts)
dpdk_args = calloc(eal_cmdline_argcount, sizeof(char *));
if (dpdk_args == NULL) {
fprintf(stderr, "Failed to allocate dpdk_args\n");
exit(-1);
return -1;
}
memcpy(dpdk_args, eal_cmdline, sizeof(char *) * eal_cmdline_argcount);
@ -301,7 +305,7 @@ void spdk_env_init(const struct spdk_env_opts *opts)
if (rc < 0) {
fprintf(stderr, "Failed to initialize DPDK\n");
exit(-1);
return -1;
}
if (opts->shm_id < 0) {
@ -314,6 +318,14 @@ void spdk_env_init(const struct spdk_env_opts *opts)
spdk_env_unlink_shared_files();
}
spdk_mem_map_init();
spdk_vtophys_init();
if (spdk_mem_map_init() < 0) {
fprintf(stderr, "Failed to allocate mem_map\n");
return -1;
}
if (spdk_vtophys_init() < 0) {
fprintf(stderr, "Failed to initialize vtophys\n");
return -1;
}
return 0;
}

View File

@ -498,7 +498,7 @@ spdk_mem_map_translate(const struct spdk_mem_map *map, uint64_t vaddr)
return map_2mb->translation_2mb;
}
void
int
spdk_mem_map_init(void)
{
struct rte_mem_config *mcfg;
@ -507,7 +507,7 @@ spdk_mem_map_init(void)
g_mem_reg_map = spdk_mem_map_alloc(0, NULL, NULL);
if (g_mem_reg_map == NULL) {
DEBUG_PRINT("memory registration map allocation failed\n");
abort();
return -1;
}
/*
@ -525,4 +525,5 @@ spdk_mem_map_init(void)
spdk_mem_register(seg->addr, seg->len);
}
return 0;
}

View File

@ -449,7 +449,7 @@ spdk_vtophys_put_ref(void)
#endif
}
void
int
spdk_vtophys_init(void)
{
#if SPDK_VFIO_ENABLED
@ -459,8 +459,9 @@ spdk_vtophys_init(void)
g_vtophys_map = spdk_mem_map_alloc(SPDK_VTOPHYS_ERROR, spdk_vtophys_notify, NULL);
if (g_vtophys_map == NULL) {
DEBUG_PRINT("vtophys map allocation failed\n");
abort();
return -1;
}
return 0;
}
uint64_t

View File

@ -364,7 +364,11 @@ spdk_app_start(struct spdk_app_opts *opts, spdk_event_fn start_fn,
env_opts.mem_size = opts->mem_size;
env_opts.no_pci = opts->no_pci;
spdk_env_init(&env_opts);
if (spdk_env_init(&env_opts) < 0) {
SPDK_ERRLOG("Unable to initialize SPDK env\n");
spdk_conf_free(g_spdk_app.config);
exit(EXIT_FAILURE);
}
SPDK_NOTICELOG("Total cores available: %d\n", spdk_env_get_core_count());

View File

@ -240,7 +240,9 @@ main(int argc, char **argv)
g_page_array = spdk_bit_array_create(PAGE_ARRAY_SIZE);
/* Initialize the memory map */
spdk_mem_map_init();
if (spdk_mem_map_init() < 0) {
return CUE_NOMEMORY;
}
if (CU_initialize_registry() != CUE_SUCCESS) {
return CU_get_error();

View File

@ -155,7 +155,10 @@ main(int argc, char **argv)
spdk_env_opts_init(&opts);
opts.name = "vtophys";
opts.core_mask = "0x1";
spdk_env_init(&opts);
if (spdk_env_init(&opts) < 0) {
printf("Err: Unable to initialize SPDK env\n");
return 1;
}
rc = vtophys_negative_test();
if (rc < 0) {

View File

@ -356,7 +356,10 @@ int main(int argc, char **argv)
spdk_env_opts_init(&opts);
opts.name = "aer";
opts.core_mask = "0x1";
spdk_env_init(&opts);
if (spdk_env_init(&opts) < 0) {
fprintf(stderr, "Unable to initialize SPDK env\n");
return 1;
}
printf("Asynchronous Event Request test\n");

View File

@ -421,7 +421,10 @@ int main(int argc, char **argv)
spdk_env_opts_init(&opts);
opts.name = "deallocate_test";
opts.shm_id = 0;
spdk_env_init(&opts);
if (spdk_env_init(&opts) < 0) {
fprintf(stderr, "Unable to initialize SPDK env\n");
return 1;
}
printf("Initializing NVMe Controllers\n");

View File

@ -619,7 +619,10 @@ int main(int argc, char **argv)
opts.name = "nvme_dp";
opts.core_mask = "0x1";
opts.shm_id = 0;
spdk_env_init(&opts);
if (spdk_env_init(&opts) < 0) {
fprintf(stderr, "Unable to initialize SPDK env\n");
return 1;
}
printf("NVMe Write/Read with End-to-End data protection test\n");

View File

@ -636,7 +636,10 @@ int main(int argc, char **argv)
opts.name = "overhead";
opts.core_mask = "0x1";
opts.shm_id = 0;
spdk_env_init(&opts);
if (spdk_env_init(&opts) < 0) {
fprintf(stderr, "Unable to initialize SPDK env\n");
return 1;
}
g_task = spdk_dma_zmalloc(sizeof(struct perf_task), 0, NULL);
if (g_task == NULL) {

View File

@ -634,7 +634,10 @@ int main(int argc, char **argv)
spdk_env_opts_init(&opts);
opts.name = "reset";
opts.core_mask = "0x1";
spdk_env_init(&opts);
if (spdk_env_init(&opts) < 0) {
fprintf(stderr, "Unable to initialize SPDK env\n");
return 1;
}
task_pool = spdk_mempool_create("task_pool", TASK_POOL_NUM,
sizeof(struct reset_task),

View File

@ -497,7 +497,10 @@ int main(int argc, char **argv)
opts.name = "nvme_sgl";
opts.core_mask = "0x1";
opts.shm_id = 0;
spdk_env_init(&opts);
if (spdk_env_init(&opts) < 0) {
fprintf(stderr, "Unable to initialize SPDK env\n");
return 1;
}
printf("NVMe Readv/Writev Request test\n");

View File

@ -73,7 +73,10 @@ main(int argc, char **argv)
}
spdk_env_opts_init(&opts);
spdk_env_init(&opts);
if (spdk_env_init(&opts)) {
printf("Err: Unable to initialize SPDK env\n");
return 1;
}
for (i = 0; i < SPDK_COUNTOF(tsc); i++) {
tsc[i] = spdk_get_ticks();