diff --git a/CHANGELOG.md b/CHANGELOG.md index 9898abee5a..54763166c0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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: diff --git a/examples/bdev/fio_plugin/fio_plugin.c b/examples/bdev/fio_plugin/fio_plugin.c index 4540b0cb77..d639431c8a 100644 --- a/examples/bdev/fio_plugin/fio_plugin.c +++ b/examples/bdev/fio_plugin/fio_plugin.c @@ -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 */ diff --git a/examples/ioat/perf/perf.c b/examples/ioat/perf/perf.c index 4f5a0ae3bc..4540cedb9d 100644 --- a/examples/ioat/perf/perf.c +++ b/examples/ioat/perf/perf.c @@ -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; } diff --git a/examples/ioat/verify/verify.c b/examples/ioat/verify/verify.c index b3a656b1fd..4089bc800d 100644 --- a/examples/ioat/verify/verify.c +++ b/examples/ioat/verify/verify.c @@ -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"); diff --git a/examples/nvme/arbitration/arbitration.c b/examples/nvme/arbitration/arbitration.c index ea1fd7e4e4..8065b1bac2 100644 --- a/examples/nvme/arbitration/arbitration.c +++ b/examples/nvme/arbitration/arbitration.c @@ -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(); diff --git a/examples/nvme/fio_plugin/fio_plugin.c b/examples/nvme/fio_plugin/fio_plugin.c index 12caed6d70..d7e90592eb 100644 --- a/examples/nvme/fio_plugin/fio_plugin.c +++ b/examples/nvme/fio_plugin/fio_plugin.c @@ -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(); } diff --git a/examples/nvme/hello_world/hello_world.c b/examples/nvme/hello_world/hello_world.c index 6230a90954..23e1a21004 100644 --- a/examples/nvme/hello_world/hello_world.c +++ b/examples/nvme/hello_world/hello_world.c @@ -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"); diff --git a/examples/nvme/hotplug/hotplug.c b/examples/nvme/hotplug/hotplug.c index 5d76a9128d..66d93a71a3 100644 --- a/examples/nvme/hotplug/hotplug.c +++ b/examples/nvme/hotplug/hotplug.c @@ -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(); diff --git a/examples/nvme/identify/identify.c b/examples/nvme/identify/identify.c index eb354e7110..8379359090 100644 --- a/examples/nvme/identify/identify.c +++ b/examples/nvme/identify/identify.c @@ -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) { diff --git a/examples/nvme/nvme_manage/nvme_manage.c b/examples/nvme/nvme_manage/nvme_manage.c index de757a1025..8a023d7aa5 100644 --- a/examples/nvme/nvme_manage/nvme_manage.c +++ b/examples/nvme/nvme_manage/nvme_manage.c @@ -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"); diff --git a/examples/nvme/perf/perf.c b/examples/nvme/perf/perf.c index 71de1db5ea..9747886777 100644 --- a/examples/nvme/perf/perf.c +++ b/examples/nvme/perf/perf.c @@ -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(); diff --git a/examples/nvme/reserve/reserve.c b/examples/nvme/reserve/reserve.c index 23ab61294a..c0748060aa 100644 --- a/examples/nvme/reserve/reserve.c +++ b/examples/nvme/reserve/reserve.c @@ -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"); diff --git a/include/spdk/env.h b/include/spdk/env.h index 86c133b61b..7cece1b1e4 100644 --- a/include/spdk/env.h +++ b/include/spdk/env.h @@ -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 diff --git a/lib/env_dpdk/env_internal.h b/lib/env_dpdk/env_internal.h index c5824632e4..72bebcc36c 100644 --- a/lib/env_dpdk/env_internal.h +++ b/lib/env_dpdk/env_internal.h @@ -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. diff --git a/lib/env_dpdk/init.c b/lib/env_dpdk/init.c index f8b8cf2eef..4f51a96693 100644 --- a/lib/env_dpdk/init.c +++ b/lib/env_dpdk/init.c @@ -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; } diff --git a/lib/env_dpdk/memory.c b/lib/env_dpdk/memory.c index 79a02d1af9..83351abed6 100644 --- a/lib/env_dpdk/memory.c +++ b/lib/env_dpdk/memory.c @@ -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; } diff --git a/lib/env_dpdk/vtophys.c b/lib/env_dpdk/vtophys.c index 270af67769..bf5fd014a3 100644 --- a/lib/env_dpdk/vtophys.c +++ b/lib/env_dpdk/vtophys.c @@ -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 diff --git a/lib/event/app.c b/lib/event/app.c index 56bd3db748..bb2a27ecb5 100644 --- a/lib/event/app.c +++ b/lib/event/app.c @@ -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()); diff --git a/test/lib/env/memory/memory_ut.c b/test/lib/env/memory/memory_ut.c index a96c327f7f..f855944ce9 100644 --- a/test/lib/env/memory/memory_ut.c +++ b/test/lib/env/memory/memory_ut.c @@ -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(); diff --git a/test/lib/env/vtophys/vtophys.c b/test/lib/env/vtophys/vtophys.c index b63250842b..27da3423bc 100644 --- a/test/lib/env/vtophys/vtophys.c +++ b/test/lib/env/vtophys/vtophys.c @@ -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) { diff --git a/test/lib/nvme/aer/aer.c b/test/lib/nvme/aer/aer.c index 8f6f9eb767..4fd2b1cb85 100644 --- a/test/lib/nvme/aer/aer.c +++ b/test/lib/nvme/aer/aer.c @@ -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"); diff --git a/test/lib/nvme/deallocated_value/deallocated_value.c b/test/lib/nvme/deallocated_value/deallocated_value.c index 88a0889ef8..e1d1c9f6f1 100644 --- a/test/lib/nvme/deallocated_value/deallocated_value.c +++ b/test/lib/nvme/deallocated_value/deallocated_value.c @@ -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"); diff --git a/test/lib/nvme/e2edp/nvme_dp.c b/test/lib/nvme/e2edp/nvme_dp.c index da885c2698..3df0b34d6d 100644 --- a/test/lib/nvme/e2edp/nvme_dp.c +++ b/test/lib/nvme/e2edp/nvme_dp.c @@ -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"); diff --git a/test/lib/nvme/overhead/overhead.c b/test/lib/nvme/overhead/overhead.c index 36c3c4ef1b..670faaa219 100644 --- a/test/lib/nvme/overhead/overhead.c +++ b/test/lib/nvme/overhead/overhead.c @@ -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) { diff --git a/test/lib/nvme/reset/reset.c b/test/lib/nvme/reset/reset.c index a30b5302aa..75f2aecd70 100644 --- a/test/lib/nvme/reset/reset.c +++ b/test/lib/nvme/reset/reset.c @@ -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), diff --git a/test/lib/nvme/sgl/sgl.c b/test/lib/nvme/sgl/sgl.c index 6741d636a1..506b48f485 100644 --- a/test/lib/nvme/sgl/sgl.c +++ b/test/lib/nvme/sgl/sgl.c @@ -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"); diff --git a/test/lib/util/histogram_perf/histogram_perf.c b/test/lib/util/histogram_perf/histogram_perf.c index eeff617465..5d9de52745 100644 --- a/test/lib/util/histogram_perf/histogram_perf.c +++ b/test/lib/util/histogram_perf/histogram_perf.c @@ -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();