Skip to content

Commit 90d2c44

Browse files
ihorobehlendorf
authored andcommitted
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 f7698f4 commit 90d2c44

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
@@ -7812,6 +7812,9 @@ ztest_dataset_open(int d)
78127812

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

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

78177820
error = ztest_dataset_create(name);
@@ -8307,41 +8310,44 @@ static void
83078310
ztest_generic_run(ztest_shared_t *zs, spa_t *spa)
83088311
{
83098312
kthread_t **run_threads;
8310-
int t;
8313+
int i, ndatasets;
83118314

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

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

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

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

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

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

@@ -8464,6 +8470,7 @@ ztest_run(ztest_shared_t *zs)
84648470

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

0 commit comments

Comments
 (0)