Skip to content

Commit ee0cb4c

Browse files
authored
ztest: Fix false positive of ENOSPC handling
Before running a pass zs_enospc_count is checked to free up some space by destroying a random dataset. But the space freed may still be not re-usable during the TXG_DEFER window breaking the next dataset creation in ztest_generic_run(). Sponsored-by: Klara, Inc. Sponsored-by: Wasabi Technology, Inc. Reviewed-by: Alexander Motin <[email protected]> Reviewed-by: Brian Behlendorf <[email protected]> Signed-off-by: Igor Ostapenko <[email protected]> Closes #17506
1 parent d411ea2 commit ee0cb4c

File tree

1 file changed

+23
-16
lines changed

1 file changed

+23
-16
lines changed

cmd/ztest.c

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7813,6 +7813,9 @@ ztest_dataset_open(int d)
78137813

78147814
ztest_dataset_name(name, ztest_opts.zo_pool, d);
78157815

7816+
if (ztest_opts.zo_verbose >= 6)
7817+
(void) printf("Opening %s\n", name);
7818+
78167819
(void) pthread_rwlock_rdlock(&ztest_name_lock);
78177820

78187821
error = ztest_dataset_create(name);
@@ -8308,41 +8311,44 @@ static void
83088311
ztest_generic_run(ztest_shared_t *zs, spa_t *spa)
83098312
{
83108313
kthread_t **run_threads;
8311-
int t;
8314+
int i, ndatasets;
83128315

83138316
run_threads = umem_zalloc(ztest_opts.zo_threads * sizeof (kthread_t *),
83148317
UMEM_NOFAIL);
83158318

83168319
/*
8317-
* Kick off all the tests that run in parallel.
8320+
* Actual number of datasets to be used.
83188321
*/
8319-
for (t = 0; t < ztest_opts.zo_threads; t++) {
8320-
if (t < ztest_opts.zo_datasets && ztest_dataset_open(t) != 0) {
8321-
umem_free(run_threads, ztest_opts.zo_threads *
8322-
sizeof (kthread_t *));
8323-
return;
8324-
}
8322+
ndatasets = MIN(ztest_opts.zo_datasets, ztest_opts.zo_threads);
8323+
8324+
/*
8325+
* Prepare the datasets first.
8326+
*/
8327+
for (i = 0; i < ndatasets; i++)
8328+
VERIFY0(ztest_dataset_open(i));
83258329

8326-
run_threads[t] = thread_create(NULL, 0, ztest_thread,
8327-
(void *)(uintptr_t)t, 0, NULL, TS_RUN | TS_JOINABLE,
8330+
/*
8331+
* Kick off all the tests that run in parallel.
8332+
*/
8333+
for (i = 0; i < ztest_opts.zo_threads; i++) {
8334+
run_threads[i] = thread_create(NULL, 0, ztest_thread,
8335+
(void *)(uintptr_t)i, 0, NULL, TS_RUN | TS_JOINABLE,
83288336
defclsyspri);
83298337
}
83308338

83318339
/*
83328340
* Wait for all of the tests to complete.
83338341
*/
8334-
for (t = 0; t < ztest_opts.zo_threads; t++)
8335-
VERIFY0(thread_join(run_threads[t]));
8342+
for (i = 0; i < ztest_opts.zo_threads; i++)
8343+
VERIFY0(thread_join(run_threads[i]));
83368344

83378345
/*
83388346
* Close all datasets. This must be done after all the threads
83398347
* are joined so we can be sure none of the datasets are in-use
83408348
* by any of the threads.
83418349
*/
8342-
for (t = 0; t < ztest_opts.zo_threads; t++) {
8343-
if (t < ztest_opts.zo_datasets)
8344-
ztest_dataset_close(t);
8345-
}
8350+
for (i = 0; i < ndatasets; i++)
8351+
ztest_dataset_close(i);
83468352

83478353
txg_wait_synced(spa_get_dsl(spa), 0);
83488354

@@ -8465,6 +8471,7 @@ ztest_run(ztest_shared_t *zs)
84658471

84668472
int d = ztest_random(ztest_opts.zo_datasets);
84678473
ztest_dataset_destroy(d);
8474+
txg_wait_synced(spa_get_dsl(spa), 0);
84688475
}
84698476
zs->zs_enospc_count = 0;
84708477

0 commit comments

Comments
 (0)