diff --git a/cmd/ztest/ztest.c b/cmd/ztest/ztest.c index 69086a34a2..5706055216 100644 --- a/cmd/ztest/ztest.c +++ b/cmd/ztest/ztest.c @@ -4904,21 +4904,12 @@ ztest_resume_thread(void *arg) return (NULL); } -static void * -ztest_deadman_thread(void *arg) +#define GRACE 300 + +static void +ztest_deadman_alarm(int sig) { - ztest_shared_t *zs = arg; - int grace = 300; - hrtime_t delta; - - delta = (zs->zs_thread_stop - zs->zs_thread_start) / NANOSEC + grace; - - (void) poll(NULL, 0, (int)(1000 * delta)); - - fatal(0, "failed to complete within %d seconds of deadline", grace); - thread_exit(); - - return (NULL); + fatal(0, "failed to complete within %d seconds of deadline", GRACE); } static void @@ -5106,7 +5097,7 @@ ztest_dataset_close(ztest_shared_t *zs, int d) static void ztest_run(ztest_shared_t *zs) { - kthread_t **tid; + kt_did_t *tid; spa_t *spa; kthread_t *resume_thread; uint64_t object; @@ -5158,10 +5149,10 @@ ztest_run(ztest_shared_t *zs) spa, TS_RUN, NULL, 0, 0)), !=, NULL); /* - * Create a deadman thread to abort() if we hang. + * Set a deadman alarm to abort() if we hang. */ - VERIFY3P(thread_create(NULL, 0, ztest_deadman_thread, zs, - TS_RUN, NULL, 0, 0), !=, NULL); + signal(SIGALRM, ztest_deadman_alarm); + alarm((zs->zs_thread_stop - zs->zs_thread_start) / NANOSEC + GRACE); /* * Verify that we can safely inquire about about any object, @@ -5187,7 +5178,7 @@ ztest_run(ztest_shared_t *zs) } zs->zs_enospc_count = 0; - tid = umem_zalloc(zopt_threads * sizeof (kthread_t *), UMEM_NOFAIL); + tid = umem_zalloc(zopt_threads * sizeof (kt_did_t), UMEM_NOFAIL); if (zopt_verbose >= 4) (void) printf("starting main threads...\n"); @@ -5196,11 +5187,14 @@ ztest_run(ztest_shared_t *zs) * Kick off all the tests that run in parallel. */ for (int t = 0; t < zopt_threads; t++) { + kthread_t *thread; + if (t < zopt_datasets && ztest_dataset_open(zs, t) != 0) return; - VERIFY3P(tid[t] = thread_create(NULL, 0, ztest_thread, + VERIFY3P(thread = thread_create(NULL, 0, ztest_thread, (void *)(uintptr_t)t, TS_RUN, NULL, 0, 0), !=, NULL); + tid[t] = thread->t_tid; } /* @@ -5208,7 +5202,7 @@ ztest_run(ztest_shared_t *zs) * so we don't close datasets while threads are still using them. */ for (int t = zopt_threads - 1; t >= 0; t--) { - thread_join(tid[t]->t_tid); + thread_join(tid[t]); if (t < zopt_datasets) ztest_dataset_close(zs, t); } @@ -5218,7 +5212,7 @@ ztest_run(ztest_shared_t *zs) zs->zs_alloc = metaslab_class_get_alloc(spa_normal_class(spa)); zs->zs_space = metaslab_class_get_space(spa_normal_class(spa)); - umem_free(tid, zopt_threads * sizeof (kthread_t *)); + umem_free(tid, zopt_threads * sizeof (kt_did_t)); /* Kill the resume thread */ ztest_exiting = B_TRUE; diff --git a/lib/libzpool/include/sys/zfs_context.h b/lib/libzpool/include/sys/zfs_context.h index afca6364db..c104f6d3a1 100644 --- a/lib/libzpool/include/sys/zfs_context.h +++ b/lib/libzpool/include/sys/zfs_context.h @@ -203,7 +203,8 @@ _NOTE(CONSTCOND) } while (0) /* * Threads */ -#define TS_RUN 0x00000002 +#define TS_MAGIC 0x72f158ab4261e538ull +#define TS_RUN 0x00000002 #ifdef _linux_ #define STACK_SIZE 8192 /* Linux x86 and amd64 */ #else @@ -227,7 +228,6 @@ typedef struct kthread { void * t_arg; } kthread_t; -/* XXX tsd_create()/tsd_destroy() missing */ #define tsd_get(key) pthread_getspecific(key) #define tsd_set(key, val) pthread_setspecific(key, val) #define curthread zk_thread_current() diff --git a/lib/libzpool/kernel.c b/lib/libzpool/kernel.c index 27a99cc26c..ebc979dc8c 100644 --- a/lib/libzpool/kernel.c +++ b/lib/libzpool/kernel.c @@ -191,13 +191,16 @@ zk_thread_exit(void) pthread_mutex_unlock(&kthread_lock); pthread_cond_broadcast(&kthread_cond); - pthread_exit(NULL); + pthread_exit((void *)TS_MAGIC); } void zk_thread_join(kt_did_t tid) { - pthread_join((pthread_t)tid, NULL); + void *ret; + + pthread_join((pthread_t)tid, &ret); + VERIFY3P(ret, ==, (void *)TS_MAGIC); } /*