llvm_vfio_fuzz: handle thread create failure

In case of `pthread_create` or `spdk_thread_create` failed stop
spdk app with `-1` error code

Signed-off-by: Sebastian Brzezinka <sebastian.brzezinka@intel.com>
Change-Id: Id5d0f6716917f42e06fbda7db9285deb320e309a
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/16338
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
This commit is contained in:
Sebastian Brzezinka 2023-01-18 18:45:50 +01:00 committed by Konrad Sztyber
parent 943806efab
commit c019eb4d67

View File

@ -142,7 +142,7 @@ io_terminate(void *ctx)
static void
exit_handler(void)
{
if (g_io_thread.io_ctrlr_path) {
if (g_io_thread.io_ctrlr_path && g_io_thread.thread) {
spdk_thread_send_msg(g_io_thread.thread, io_terminate, &g_io_thread);
} else {
@ -392,6 +392,13 @@ init_io(void *ctx)
}
g_io_thread.thread = spdk_thread_create("io_thread", NULL);
if (g_io_thread.thread == NULL) {
fprintf(stderr, "cannot create io thread\n");
spdk_app_stop(-1);
pthread_kill(g_fuzz_td, SIGSEGV);
return NULL;
}
spdk_thread_send_msg(g_io_thread.thread, start_io_poller, &g_io_thread);
return NULL;
@ -400,15 +407,25 @@ init_io(void *ctx)
static void
begin_fuzz(void *ctx)
{
int rc = 0;
g_reactor_td = pthread_self();
pthread_create(&g_fuzz_td, NULL, start_fuzzer, NULL);
rc = pthread_create(&g_fuzz_td, NULL, start_fuzzer, NULL);
if (rc != 0) {
spdk_app_stop(-1);
return;
}
/* posix thread is use to avoid deadlock during spdk_nvme_connect
* vfio-user version negotiation may block when waiting for response
*/
if (g_io_thread.io_ctrlr_path) {
pthread_create(&g_io_thread.io_td, NULL, init_io, NULL);
rc = pthread_create(&g_io_thread.io_td, NULL, init_io, NULL);
if (rc != 0) {
spdk_app_stop(-1);
pthread_kill(g_fuzz_td, SIGSEGV);
}
}
}