4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
27 * The objective of this program is to provide a DMU/ZAP/SPA stress test
28 * that runs entirely in userland, is easy to use, and easy to extend.
30 * The overall design of the ztest program is as follows:
32 * (1) For each major functional area (e.g. adding vdevs to a pool,
33 * creating and destroying datasets, reading and writing objects, etc)
34 * we have a simple routine to test that functionality. These
35 * individual routines do not have to do anything "stressful".
37 * (2) We turn these simple functionality tests into a stress test by
38 * running them all in parallel, with as many threads as desired,
39 * and spread across as many datasets, objects, and vdevs as desired.
41 * (3) While all this is happening, we inject faults into the pool to
42 * verify that self-healing data really works.
44 * (4) Every time we open a dataset, we change its checksum and compression
45 * functions. Thus even individual objects vary from block to block
46 * in which checksum they use and whether they're compressed.
48 * (5) To verify that we never lose on-disk consistency after a crash,
49 * we run the entire test in a child of the main process.
50 * At random times, the child self-immolates with a SIGKILL.
51 * This is the software equivalent of pulling the power cord.
52 * The parent then runs the test again, using the existing
53 * storage pool, as many times as desired.
55 * (6) To verify that we don't have future leaks or temporal incursions,
56 * many of the functional tests record the transaction group number
57 * as part of their data. When reading old data, they verify that
58 * the transaction group number is less than the current, open txg.
59 * If you add a new test, please do this if applicable.
61 * When run with no arguments, ztest runs for about five minutes and
62 * produces no output if successful. To get a little bit of information,
63 * specify -V. To get more information, specify -VV, and so on.
65 * To turn this into an overnight stress test, use -T to specify run time.
67 * You can ask more more vdevs [-v], datasets [-d], or threads [-t]
68 * to increase the pool capacity, fanout, and overall stress level.
70 * The -N(okill) option will suppress kills, so each child runs to completion.
71 * This can be useful when you're trying to distinguish temporal incursions
72 * from plain old race conditions.
75 #include <sys/zfs_context.h>
81 #include <sys/dmu_objset.h>
87 #include <sys/resource.h>
89 #include <sys/zio_checksum.h>
90 #include <sys/zio_compress.h>
92 #include <sys/vdev_impl.h>
93 #include <sys/vdev_file.h>
94 #include <sys/spa_impl.h>
95 #include <sys/dsl_prop.h>
96 #include <sys/dsl_dataset.h>
97 #include <sys/refcount.h>
99 #include <stdio_ext.h>
108 #include <sys/fs/zfs.h>
110 static char cmdname[] = "ztest";
111 static char *zopt_pool = cmdname;
112 static char *progname;
114 static uint64_t zopt_vdevs = 5;
115 static uint64_t zopt_vdevtime;
116 static int zopt_ashift = SPA_MINBLOCKSHIFT;
117 static int zopt_mirrors = 2;
118 static int zopt_raidz = 4;
119 static int zopt_raidz_parity = 1;
120 static size_t zopt_vdev_size = SPA_MINDEVSIZE;
121 static int zopt_datasets = 7;
122 static int zopt_threads = 23;
123 static uint64_t zopt_passtime = 60; /* 60 seconds */
124 static uint64_t zopt_killrate = 70; /* 70% kill rate */
125 static int zopt_verbose = 0;
126 static int zopt_init = 1;
127 static char *zopt_dir = "/tmp";
128 static uint64_t zopt_time = 300; /* 5 minutes */
129 static int zopt_maxfaults;
131 typedef struct ztest_block_tag {
140 typedef struct ztest_args {
141 char za_pool[MAXNAMELEN];
146 uint64_t za_instance;
149 uint64_t za_diroff_shared;
155 * Thread-local variables can go here to aid debugging.
157 ztest_block_tag_t za_rbt;
158 ztest_block_tag_t za_wbt;
159 dmu_object_info_t za_doi;
163 typedef void ztest_func_t(ztest_args_t *);
166 * Note: these aren't static because we want dladdr() to work.
168 ztest_func_t ztest_dmu_read_write;
169 ztest_func_t ztest_dmu_read_write_zcopy;
170 ztest_func_t ztest_dmu_write_parallel;
171 ztest_func_t ztest_dmu_object_alloc_free;
172 ztest_func_t ztest_zap;
173 ztest_func_t ztest_fzap;
174 ztest_func_t ztest_zap_parallel;
175 ztest_func_t ztest_traverse;
176 ztest_func_t ztest_dsl_prop_get_set;
177 ztest_func_t ztest_dmu_objset_create_destroy;
178 ztest_func_t ztest_dmu_snapshot_create_destroy;
179 ztest_func_t ztest_dsl_dataset_promote_busy;
180 ztest_func_t ztest_spa_create_destroy;
181 ztest_func_t ztest_fault_inject;
182 ztest_func_t ztest_spa_rename;
183 ztest_func_t ztest_vdev_attach_detach;
184 ztest_func_t ztest_vdev_LUN_growth;
185 ztest_func_t ztest_vdev_add_remove;
186 ztest_func_t ztest_vdev_aux_add_remove;
187 ztest_func_t ztest_scrub;
189 typedef struct ztest_info {
190 ztest_func_t *zi_func; /* test function */
191 uint64_t zi_iters; /* iterations per execution */
192 uint64_t *zi_interval; /* execute every <interval> seconds */
193 uint64_t zi_calls; /* per-pass count */
194 uint64_t zi_call_time; /* per-pass time */
195 uint64_t zi_call_total; /* cumulative total */
196 uint64_t zi_call_target; /* target cumulative total */
199 uint64_t zopt_always = 0; /* all the time */
200 uint64_t zopt_often = 1; /* every second */
201 uint64_t zopt_sometimes = 10; /* every 10 seconds */
202 uint64_t zopt_rarely = 60; /* every 60 seconds */
204 ztest_info_t ztest_info[] = {
205 { ztest_dmu_read_write, 1, &zopt_always },
206 { ztest_dmu_read_write_zcopy, 1, &zopt_always },
207 { ztest_dmu_write_parallel, 30, &zopt_always },
208 { ztest_dmu_object_alloc_free, 1, &zopt_always },
209 { ztest_zap, 30, &zopt_always },
210 { ztest_fzap, 30, &zopt_always },
211 { ztest_zap_parallel, 100, &zopt_always },
212 { ztest_dsl_prop_get_set, 1, &zopt_sometimes },
213 { ztest_dmu_objset_create_destroy, 1, &zopt_sometimes },
214 { ztest_dmu_snapshot_create_destroy, 1, &zopt_sometimes },
215 { ztest_spa_create_destroy, 1, &zopt_sometimes },
216 { ztest_fault_inject, 1, &zopt_sometimes },
217 { ztest_spa_rename, 1, &zopt_rarely },
218 { ztest_vdev_attach_detach, 1, &zopt_rarely },
219 { ztest_vdev_LUN_growth, 1, &zopt_rarely },
220 { ztest_dsl_dataset_promote_busy, 1, &zopt_rarely },
221 { ztest_vdev_add_remove, 1, &zopt_vdevtime },
222 { ztest_vdev_aux_add_remove, 1, &zopt_vdevtime },
223 { ztest_scrub, 1, &zopt_vdevtime },
226 #define ZTEST_FUNCS (sizeof (ztest_info) / sizeof (ztest_info_t))
228 #define ZTEST_SYNC_LOCKS 16
231 * Stuff we need to share writably between parent and child.
233 typedef struct ztest_shared {
234 mutex_t zs_vdev_lock;
235 rwlock_t zs_name_lock;
236 uint64_t zs_vdev_primaries;
237 uint64_t zs_vdev_aux;
238 uint64_t zs_enospc_count;
239 hrtime_t zs_start_time;
240 hrtime_t zs_stop_time;
243 ztest_info_t zs_info[ZTEST_FUNCS];
244 mutex_t zs_sync_lock[ZTEST_SYNC_LOCKS];
245 uint64_t zs_seq[ZTEST_SYNC_LOCKS];
248 static char ztest_dev_template[] = "%s/%s.%llua";
249 static char ztest_aux_template[] = "%s/%s.%s.%llu";
250 static ztest_shared_t *ztest_shared;
252 static int ztest_random_fd;
253 static int ztest_dump_core = 1;
255 static uint64_t metaslab_sz;
256 static boolean_t ztest_exiting;
258 extern uint64_t metaslab_gang_bang;
259 extern uint64_t metaslab_df_alloc_threshold;
261 #define ZTEST_DIROBJ 1
262 #define ZTEST_MICROZAP_OBJ 2
263 #define ZTEST_FATZAP_OBJ 3
265 #define ZTEST_DIROBJ_BLOCKSIZE (1 << 10)
266 #define ZTEST_DIRSIZE 256
268 static void usage(boolean_t) __NORETURN;
271 * These libumem hooks provide a reasonable set of defaults for the allocator's
272 * debugging facilities.
277 return ("default,verbose"); /* $UMEM_DEBUG setting */
281 _umem_logging_init(void)
283 return ("fail,contents"); /* $UMEM_LOGGING setting */
286 #define FATAL_MSG_SZ 1024
291 fatal(int do_perror, char *message, ...)
294 int save_errno = errno;
295 char buf[FATAL_MSG_SZ];
297 (void) fflush(stdout);
299 va_start(args, message);
300 (void) sprintf(buf, "ztest: ");
302 (void) vsprintf(buf + strlen(buf), message, args);
305 (void) snprintf(buf + strlen(buf), FATAL_MSG_SZ - strlen(buf),
306 ": %s", strerror(save_errno));
308 (void) fprintf(stderr, "%s\n", buf);
309 fatal_msg = buf; /* to ease debugging */
316 str2shift(const char *buf)
318 const char *ends = "BKMGTPEZ";
323 for (i = 0; i < strlen(ends); i++) {
324 if (toupper(buf[0]) == ends[i])
327 if (i == strlen(ends)) {
328 (void) fprintf(stderr, "ztest: invalid bytes suffix: %s\n",
332 if (buf[1] == '\0' || (toupper(buf[1]) == 'B' && buf[2] == '\0')) {
335 (void) fprintf(stderr, "ztest: invalid bytes suffix: %s\n", buf);
341 nicenumtoull(const char *buf)
346 val = strtoull(buf, &end, 0);
348 (void) fprintf(stderr, "ztest: bad numeric value: %s\n", buf);
350 } else if (end[0] == '.') {
351 double fval = strtod(buf, &end);
352 fval *= pow(2, str2shift(end));
353 if (fval > UINT64_MAX) {
354 (void) fprintf(stderr, "ztest: value too large: %s\n",
358 val = (uint64_t)fval;
360 int shift = str2shift(end);
361 if (shift >= 64 || (val << shift) >> shift != val) {
362 (void) fprintf(stderr, "ztest: value too large: %s\n",
372 usage(boolean_t requested)
374 char nice_vdev_size[10];
375 char nice_gang_bang[10];
376 FILE *fp = requested ? stdout : stderr;
378 nicenum(zopt_vdev_size, nice_vdev_size);
379 nicenum(metaslab_gang_bang, nice_gang_bang);
381 (void) fprintf(fp, "Usage: %s\n"
382 "\t[-v vdevs (default: %llu)]\n"
383 "\t[-s size_of_each_vdev (default: %s)]\n"
384 "\t[-a alignment_shift (default: %d) (use 0 for random)]\n"
385 "\t[-m mirror_copies (default: %d)]\n"
386 "\t[-r raidz_disks (default: %d)]\n"
387 "\t[-R raidz_parity (default: %d)]\n"
388 "\t[-d datasets (default: %d)]\n"
389 "\t[-t threads (default: %d)]\n"
390 "\t[-g gang_block_threshold (default: %s)]\n"
391 "\t[-i initialize pool i times (default: %d)]\n"
392 "\t[-k kill percentage (default: %llu%%)]\n"
393 "\t[-p pool_name (default: %s)]\n"
394 "\t[-f file directory for vdev files (default: %s)]\n"
395 "\t[-V(erbose)] (use multiple times for ever more blather)\n"
396 "\t[-E(xisting)] (use existing pool instead of creating new one)\n"
397 "\t[-T time] total run time (default: %llu sec)\n"
398 "\t[-P passtime] time per pass (default: %llu sec)\n"
399 "\t[-h] (print help)\n"
402 (u_longlong_t)zopt_vdevs, /* -v */
403 nice_vdev_size, /* -s */
404 zopt_ashift, /* -a */
405 zopt_mirrors, /* -m */
407 zopt_raidz_parity, /* -R */
408 zopt_datasets, /* -d */
409 zopt_threads, /* -t */
410 nice_gang_bang, /* -g */
412 (u_longlong_t)zopt_killrate, /* -k */
415 (u_longlong_t)zopt_time, /* -T */
416 (u_longlong_t)zopt_passtime); /* -P */
417 exit(requested ? 0 : 1);
421 ztest_random(uint64_t range)
428 if (read(ztest_random_fd, &r, sizeof (r)) != sizeof (r))
429 fatal(1, "short read from /dev/urandom");
436 ztest_record_enospc(char *s)
438 ztest_shared->zs_enospc_count++;
442 process_options(int argc, char **argv)
447 /* Remember program name. */
450 /* By default, test gang blocks for blocks 32K and greater */
451 metaslab_gang_bang = 32 << 10;
453 while ((opt = getopt(argc, argv,
454 "v:s:a:m:r:R:d:t:g:i:k:p:f:VET:P:h")) != EOF) {
470 value = nicenumtoull(optarg);
477 zopt_vdev_size = MAX(SPA_MINDEVSIZE, value);
483 zopt_mirrors = value;
486 zopt_raidz = MAX(1, value);
489 zopt_raidz_parity = MIN(MAX(value, 1), 2);
492 zopt_datasets = MAX(1, value);
495 zopt_threads = MAX(1, value);
498 metaslab_gang_bang = MAX(SPA_MINBLOCKSIZE << 1, value);
504 zopt_killrate = value;
507 zopt_pool = strdup(optarg);
510 zopt_dir = strdup(optarg);
522 zopt_passtime = MAX(1, value);
534 zopt_raidz_parity = MIN(zopt_raidz_parity, zopt_raidz - 1);
536 zopt_vdevtime = (zopt_vdevs > 0 ? zopt_time / zopt_vdevs : UINT64_MAX);
537 zopt_maxfaults = MAX(zopt_mirrors, 1) * (zopt_raidz_parity + 1) - 1;
541 ztest_get_ashift(void)
543 if (zopt_ashift == 0)
544 return (SPA_MINBLOCKSHIFT + ztest_random(3));
545 return (zopt_ashift);
549 make_vdev_file(char *path, char *aux, size_t size, uint64_t ashift)
551 char pathbuf[MAXPATHLEN];
556 ashift = ztest_get_ashift();
562 vdev = ztest_shared->zs_vdev_aux;
563 (void) sprintf(path, ztest_aux_template,
564 zopt_dir, zopt_pool, aux, vdev);
566 vdev = ztest_shared->zs_vdev_primaries++;
567 (void) sprintf(path, ztest_dev_template,
568 zopt_dir, zopt_pool, vdev);
573 int fd = open(path, O_RDWR | O_CREAT | O_TRUNC, 0666);
575 fatal(1, "can't open %s", path);
576 if (ftruncate(fd, size) != 0)
577 fatal(1, "can't ftruncate %s", path);
581 VERIFY(nvlist_alloc(&file, NV_UNIQUE_NAME, 0) == 0);
582 VERIFY(nvlist_add_string(file, ZPOOL_CONFIG_TYPE, VDEV_TYPE_FILE) == 0);
583 VERIFY(nvlist_add_string(file, ZPOOL_CONFIG_PATH, path) == 0);
584 VERIFY(nvlist_add_uint64(file, ZPOOL_CONFIG_ASHIFT, ashift) == 0);
590 make_vdev_raidz(char *path, char *aux, size_t size, uint64_t ashift, int r)
592 nvlist_t *raidz, **child;
596 return (make_vdev_file(path, aux, size, ashift));
597 child = umem_alloc(r * sizeof (nvlist_t *), UMEM_NOFAIL);
599 for (c = 0; c < r; c++)
600 child[c] = make_vdev_file(path, aux, size, ashift);
602 VERIFY(nvlist_alloc(&raidz, NV_UNIQUE_NAME, 0) == 0);
603 VERIFY(nvlist_add_string(raidz, ZPOOL_CONFIG_TYPE,
604 VDEV_TYPE_RAIDZ) == 0);
605 VERIFY(nvlist_add_uint64(raidz, ZPOOL_CONFIG_NPARITY,
606 zopt_raidz_parity) == 0);
607 VERIFY(nvlist_add_nvlist_array(raidz, ZPOOL_CONFIG_CHILDREN,
610 for (c = 0; c < r; c++)
611 nvlist_free(child[c]);
613 umem_free(child, r * sizeof (nvlist_t *));
619 make_vdev_mirror(char *path, char *aux, size_t size, uint64_t ashift,
622 nvlist_t *mirror, **child;
626 return (make_vdev_raidz(path, aux, size, ashift, r));
628 child = umem_alloc(m * sizeof (nvlist_t *), UMEM_NOFAIL);
630 for (c = 0; c < m; c++)
631 child[c] = make_vdev_raidz(path, aux, size, ashift, r);
633 VERIFY(nvlist_alloc(&mirror, NV_UNIQUE_NAME, 0) == 0);
634 VERIFY(nvlist_add_string(mirror, ZPOOL_CONFIG_TYPE,
635 VDEV_TYPE_MIRROR) == 0);
636 VERIFY(nvlist_add_nvlist_array(mirror, ZPOOL_CONFIG_CHILDREN,
639 for (c = 0; c < m; c++)
640 nvlist_free(child[c]);
642 umem_free(child, m * sizeof (nvlist_t *));
648 make_vdev_root(char *path, char *aux, size_t size, uint64_t ashift,
649 int log, int r, int m, int t)
651 nvlist_t *root, **child;
656 child = umem_alloc(t * sizeof (nvlist_t *), UMEM_NOFAIL);
658 for (c = 0; c < t; c++) {
659 child[c] = make_vdev_mirror(path, aux, size, ashift, r, m);
660 VERIFY(nvlist_add_uint64(child[c], ZPOOL_CONFIG_IS_LOG,
664 VERIFY(nvlist_alloc(&root, NV_UNIQUE_NAME, 0) == 0);
665 VERIFY(nvlist_add_string(root, ZPOOL_CONFIG_TYPE, VDEV_TYPE_ROOT) == 0);
666 VERIFY(nvlist_add_nvlist_array(root, aux ? aux : ZPOOL_CONFIG_CHILDREN,
669 for (c = 0; c < t; c++)
670 nvlist_free(child[c]);
672 umem_free(child, t * sizeof (nvlist_t *));
678 ztest_set_random_blocksize(objset_t *os, uint64_t object, dmu_tx_t *tx)
680 int bs = SPA_MINBLOCKSHIFT +
681 ztest_random(SPA_MAXBLOCKSHIFT - SPA_MINBLOCKSHIFT + 1);
682 int ibs = DN_MIN_INDBLKSHIFT +
683 ztest_random(DN_MAX_INDBLKSHIFT - DN_MIN_INDBLKSHIFT + 1);
686 error = dmu_object_set_blocksize(os, object, 1ULL << bs, ibs, tx);
689 dmu_objset_name(os, osname);
690 fatal(0, "dmu_object_set_blocksize('%s', %llu, %d, %d) = %d",
691 osname, object, 1 << bs, ibs, error);
696 ztest_random_checksum(void)
701 checksum = ztest_random(ZIO_CHECKSUM_FUNCTIONS);
702 } while (zio_checksum_table[checksum].ci_zbt);
704 if (checksum == ZIO_CHECKSUM_OFF)
705 checksum = ZIO_CHECKSUM_ON;
711 ztest_random_compress(void)
713 return ((uint8_t)ztest_random(ZIO_COMPRESS_FUNCTIONS));
717 ztest_replay_create(objset_t *os, lr_create_t *lr, boolean_t byteswap)
723 byteswap_uint64_array(lr, sizeof (*lr));
725 tx = dmu_tx_create(os);
726 dmu_tx_hold_bonus(tx, DMU_NEW_OBJECT);
727 error = dmu_tx_assign(tx, TXG_WAIT);
733 error = dmu_object_claim(os, lr->lr_doid, lr->lr_mode, 0,
735 ASSERT3U(error, ==, 0);
738 if (zopt_verbose >= 5) {
739 char osname[MAXNAMELEN];
740 dmu_objset_name(os, osname);
741 (void) printf("replay create of %s object %llu"
742 " in txg %llu = %d\n",
743 osname, (u_longlong_t)lr->lr_doid,
744 (u_longlong_t)dmu_tx_get_txg(tx), error);
751 ztest_replay_remove(objset_t *os, lr_remove_t *lr, boolean_t byteswap)
757 byteswap_uint64_array(lr, sizeof (*lr));
759 tx = dmu_tx_create(os);
760 dmu_tx_hold_free(tx, lr->lr_doid, 0, DMU_OBJECT_END);
761 error = dmu_tx_assign(tx, TXG_WAIT);
767 error = dmu_object_free(os, lr->lr_doid, tx);
773 zil_replay_func_t *ztest_replay_vector[TX_MAX_TYPE] = {
774 NULL, /* 0 no such transaction type */
775 ztest_replay_create, /* TX_CREATE */
777 NULL, /* TX_MKXATTR */
778 NULL, /* TX_SYMLINK */
779 ztest_replay_remove, /* TX_REMOVE */
782 NULL, /* TX_RENAME */
784 NULL, /* TX_TRUNCATE */
785 NULL, /* TX_SETATTR */
787 NULL, /* TX_CREATE_ACL */
788 NULL, /* TX_CREATE_ATTR */
789 NULL, /* TX_CREATE_ACL_ATTR */
790 NULL, /* TX_MKDIR_ACL */
791 NULL, /* TX_MKDIR_ATTR */
792 NULL, /* TX_MKDIR_ACL_ATTR */
793 NULL, /* TX_WRITE2 */
797 * Verify that we can't destroy an active pool, create an existing pool,
798 * or create a pool with a bad vdev spec.
801 ztest_spa_create_destroy(ztest_args_t *za)
808 * Attempt to create using a bad file.
810 nvroot = make_vdev_root("/dev/bogus", NULL, 0, 0, 0, 0, 0, 1);
811 error = spa_create("ztest_bad_file", nvroot, NULL, NULL, NULL);
814 fatal(0, "spa_create(bad_file) = %d", error);
817 * Attempt to create using a bad mirror.
819 nvroot = make_vdev_root("/dev/bogus", NULL, 0, 0, 0, 0, 2, 1);
820 error = spa_create("ztest_bad_mirror", nvroot, NULL, NULL, NULL);
823 fatal(0, "spa_create(bad_mirror) = %d", error);
826 * Attempt to create an existing pool. It shouldn't matter
827 * what's in the nvroot; we should fail with EEXIST.
829 (void) rw_rdlock(&ztest_shared->zs_name_lock);
830 nvroot = make_vdev_root("/dev/bogus", NULL, 0, 0, 0, 0, 0, 1);
831 error = spa_create(za->za_pool, nvroot, NULL, NULL, NULL);
834 fatal(0, "spa_create(whatever) = %d", error);
836 error = spa_open(za->za_pool, &spa, FTAG);
838 fatal(0, "spa_open() = %d", error);
840 error = spa_destroy(za->za_pool);
842 fatal(0, "spa_destroy() = %d", error);
844 spa_close(spa, FTAG);
845 (void) rw_unlock(&ztest_shared->zs_name_lock);
849 vdev_lookup_by_path(vdev_t *vd, const char *path)
853 if (vd->vdev_path != NULL && strcmp(path, vd->vdev_path) == 0)
856 for (int c = 0; c < vd->vdev_children; c++)
857 if ((mvd = vdev_lookup_by_path(vd->vdev_child[c], path)) !=
865 * Verify that vdev_add() works as expected.
868 ztest_vdev_add_remove(ztest_args_t *za)
870 spa_t *spa = za->za_spa;
871 uint64_t leaves = MAX(zopt_mirrors, 1) * zopt_raidz;
875 (void) mutex_lock(&ztest_shared->zs_vdev_lock);
877 spa_config_enter(spa, SCL_VDEV, FTAG, RW_READER);
879 ztest_shared->zs_vdev_primaries =
880 spa->spa_root_vdev->vdev_children * leaves;
882 spa_config_exit(spa, SCL_VDEV, FTAG);
885 * Make 1/4 of the devices be log devices.
887 nvroot = make_vdev_root(NULL, NULL, zopt_vdev_size, 0,
888 ztest_random(4) == 0, zopt_raidz, zopt_mirrors, 1);
890 error = spa_vdev_add(spa, nvroot);
893 (void) mutex_unlock(&ztest_shared->zs_vdev_lock);
896 ztest_record_enospc("spa_vdev_add");
898 fatal(0, "spa_vdev_add() = %d", error);
902 * Verify that adding/removing aux devices (l2arc, hot spare) works as expected.
905 ztest_vdev_aux_add_remove(ztest_args_t *za)
907 spa_t *spa = za->za_spa;
908 vdev_t *rvd = spa->spa_root_vdev;
914 if (ztest_random(2) == 0) {
915 sav = &spa->spa_spares;
916 aux = ZPOOL_CONFIG_SPARES;
918 sav = &spa->spa_l2cache;
919 aux = ZPOOL_CONFIG_L2CACHE;
922 (void) mutex_lock(&ztest_shared->zs_vdev_lock);
924 spa_config_enter(spa, SCL_VDEV, FTAG, RW_READER);
926 if (sav->sav_count != 0 && ztest_random(4) == 0) {
928 * Pick a random device to remove.
930 guid = sav->sav_vdevs[ztest_random(sav->sav_count)]->vdev_guid;
933 * Find an unused device we can add.
935 ztest_shared->zs_vdev_aux = 0;
937 char path[MAXPATHLEN];
939 (void) sprintf(path, ztest_aux_template, zopt_dir,
940 zopt_pool, aux, ztest_shared->zs_vdev_aux);
941 for (c = 0; c < sav->sav_count; c++)
942 if (strcmp(sav->sav_vdevs[c]->vdev_path,
945 if (c == sav->sav_count &&
946 vdev_lookup_by_path(rvd, path) == NULL)
948 ztest_shared->zs_vdev_aux++;
952 spa_config_exit(spa, SCL_VDEV, FTAG);
958 nvlist_t *nvroot = make_vdev_root(NULL, aux,
959 (zopt_vdev_size * 5) / 4, 0, 0, 0, 0, 1);
960 error = spa_vdev_add(spa, nvroot);
962 fatal(0, "spa_vdev_add(%p) = %d", nvroot, error);
966 * Remove an existing device. Sometimes, dirty its
967 * vdev state first to make sure we handle removal
968 * of devices that have pending state changes.
970 if (ztest_random(2) == 0)
971 (void) vdev_online(spa, guid, B_FALSE, NULL);
973 error = spa_vdev_remove(spa, guid, B_FALSE);
974 if (error != 0 && error != EBUSY)
975 fatal(0, "spa_vdev_remove(%llu) = %d", guid, error);
978 (void) mutex_unlock(&ztest_shared->zs_vdev_lock);
982 * Verify that we can attach and detach devices.
985 ztest_vdev_attach_detach(ztest_args_t *za)
987 spa_t *spa = za->za_spa;
988 spa_aux_vdev_t *sav = &spa->spa_spares;
989 vdev_t *rvd = spa->spa_root_vdev;
990 vdev_t *oldvd, *newvd, *pvd;
992 uint64_t leaves = MAX(zopt_mirrors, 1) * zopt_raidz;
994 uint64_t ashift = ztest_get_ashift();
995 uint64_t oldguid, pguid;
996 size_t oldsize, newsize;
997 char oldpath[MAXPATHLEN], newpath[MAXPATHLEN];
999 int oldvd_has_siblings = B_FALSE;
1000 int newvd_is_spare = B_FALSE;
1002 int error, expected_error;
1004 (void) mutex_lock(&ztest_shared->zs_vdev_lock);
1006 spa_config_enter(spa, SCL_VDEV, FTAG, RW_READER);
1009 * Decide whether to do an attach or a replace.
1011 replacing = ztest_random(2);
1014 * Pick a random top-level vdev.
1016 top = ztest_random(rvd->vdev_children);
1019 * Pick a random leaf within it.
1021 leaf = ztest_random(leaves);
1026 oldvd = rvd->vdev_child[top];
1027 if (zopt_mirrors >= 1) {
1028 ASSERT(oldvd->vdev_ops == &vdev_mirror_ops);
1029 ASSERT(oldvd->vdev_children >= zopt_mirrors);
1030 oldvd = oldvd->vdev_child[leaf / zopt_raidz];
1032 if (zopt_raidz > 1) {
1033 ASSERT(oldvd->vdev_ops == &vdev_raidz_ops);
1034 ASSERT(oldvd->vdev_children == zopt_raidz);
1035 oldvd = oldvd->vdev_child[leaf % zopt_raidz];
1039 * If we're already doing an attach or replace, oldvd may be a
1040 * mirror vdev -- in which case, pick a random child.
1042 while (oldvd->vdev_children != 0) {
1043 oldvd_has_siblings = B_TRUE;
1044 ASSERT(oldvd->vdev_children >= 2);
1045 oldvd = oldvd->vdev_child[ztest_random(oldvd->vdev_children)];
1048 oldguid = oldvd->vdev_guid;
1049 oldsize = vdev_get_rsize(oldvd);
1050 oldvd_is_log = oldvd->vdev_top->vdev_islog;
1051 (void) strcpy(oldpath, oldvd->vdev_path);
1052 pvd = oldvd->vdev_parent;
1053 pguid = pvd->vdev_guid;
1056 * If oldvd has siblings, then half of the time, detach it.
1058 if (oldvd_has_siblings && ztest_random(2) == 0) {
1059 spa_config_exit(spa, SCL_VDEV, FTAG);
1060 error = spa_vdev_detach(spa, oldguid, pguid, B_FALSE);
1061 if (error != 0 && error != ENODEV && error != EBUSY &&
1063 fatal(0, "detach (%s) returned %d", oldpath, error);
1064 (void) mutex_unlock(&ztest_shared->zs_vdev_lock);
1069 * For the new vdev, choose with equal probability between the two
1070 * standard paths (ending in either 'a' or 'b') or a random hot spare.
1072 if (sav->sav_count != 0 && ztest_random(3) == 0) {
1073 newvd = sav->sav_vdevs[ztest_random(sav->sav_count)];
1074 newvd_is_spare = B_TRUE;
1075 (void) strcpy(newpath, newvd->vdev_path);
1077 (void) snprintf(newpath, sizeof (newpath), ztest_dev_template,
1078 zopt_dir, zopt_pool, top * leaves + leaf);
1079 if (ztest_random(2) == 0)
1080 newpath[strlen(newpath) - 1] = 'b';
1081 newvd = vdev_lookup_by_path(rvd, newpath);
1085 newsize = vdev_get_rsize(newvd);
1088 * Make newsize a little bigger or smaller than oldsize.
1089 * If it's smaller, the attach should fail.
1090 * If it's larger, and we're doing a replace,
1091 * we should get dynamic LUN growth when we're done.
1093 newsize = 10 * oldsize / (9 + ztest_random(3));
1097 * If pvd is not a mirror or root, the attach should fail with ENOTSUP,
1098 * unless it's a replace; in that case any non-replacing parent is OK.
1100 * If newvd is already part of the pool, it should fail with EBUSY.
1102 * If newvd is too small, it should fail with EOVERFLOW.
1104 if (pvd->vdev_ops != &vdev_mirror_ops &&
1105 pvd->vdev_ops != &vdev_root_ops && (!replacing ||
1106 pvd->vdev_ops == &vdev_replacing_ops ||
1107 pvd->vdev_ops == &vdev_spare_ops))
1108 expected_error = ENOTSUP;
1109 else if (newvd_is_spare && (!replacing || oldvd_is_log))
1110 expected_error = ENOTSUP;
1111 else if (newvd == oldvd)
1112 expected_error = replacing ? 0 : EBUSY;
1113 else if (vdev_lookup_by_path(rvd, newpath) != NULL)
1114 expected_error = EBUSY;
1115 else if (newsize < oldsize)
1116 expected_error = EOVERFLOW;
1117 else if (ashift > oldvd->vdev_top->vdev_ashift)
1118 expected_error = EDOM;
1122 spa_config_exit(spa, SCL_VDEV, FTAG);
1125 * Build the nvlist describing newpath.
1127 root = make_vdev_root(newpath, NULL, newvd == NULL ? newsize : 0,
1128 ashift, 0, 0, 0, 1);
1130 error = spa_vdev_attach(spa, oldguid, root, replacing);
1135 * If our parent was the replacing vdev, but the replace completed,
1136 * then instead of failing with ENOTSUP we may either succeed,
1137 * fail with ENODEV, or fail with EOVERFLOW.
1139 if (expected_error == ENOTSUP &&
1140 (error == 0 || error == ENODEV || error == EOVERFLOW))
1141 expected_error = error;
1144 * If someone grew the LUN, the replacement may be too small.
1146 if (error == EOVERFLOW || error == EBUSY)
1147 expected_error = error;
1149 /* XXX workaround 6690467 */
1150 if (error != expected_error && expected_error != EBUSY) {
1151 fatal(0, "attach (%s %llu, %s %llu, %d) "
1152 "returned %d, expected %d",
1153 oldpath, (longlong_t)oldsize, newpath,
1154 (longlong_t)newsize, replacing, error, expected_error);
1157 (void) mutex_unlock(&ztest_shared->zs_vdev_lock);
1161 * Verify that dynamic LUN growth works as expected.
1164 ztest_vdev_LUN_growth(ztest_args_t *za)
1166 spa_t *spa = za->za_spa;
1167 char dev_name[MAXPATHLEN];
1168 uint64_t leaves = MAX(zopt_mirrors, 1) * zopt_raidz;
1173 (void) mutex_lock(&ztest_shared->zs_vdev_lock);
1176 * Pick a random leaf vdev.
1178 spa_config_enter(spa, SCL_VDEV, FTAG, RW_READER);
1179 vdev = ztest_random(spa->spa_root_vdev->vdev_children * leaves);
1180 spa_config_exit(spa, SCL_VDEV, FTAG);
1182 (void) sprintf(dev_name, ztest_dev_template, zopt_dir, zopt_pool, vdev);
1184 if ((fd = open(dev_name, O_RDWR)) != -1) {
1186 * Determine the size.
1188 fsize = lseek(fd, 0, SEEK_END);
1191 * If it's less than 2x the original size, grow by around 3%.
1193 if (fsize < 2 * zopt_vdev_size) {
1194 size_t newsize = fsize + ztest_random(fsize / 32);
1195 (void) ftruncate(fd, newsize);
1196 if (zopt_verbose >= 6) {
1197 (void) printf("%s grew from %lu to %lu bytes\n",
1198 dev_name, (ulong_t)fsize, (ulong_t)newsize);
1204 (void) mutex_unlock(&ztest_shared->zs_vdev_lock);
1209 ztest_create_cb(objset_t *os, void *arg, cred_t *cr, dmu_tx_t *tx)
1212 * Create the directory object.
1214 VERIFY(dmu_object_claim(os, ZTEST_DIROBJ,
1215 DMU_OT_UINT64_OTHER, ZTEST_DIROBJ_BLOCKSIZE,
1216 DMU_OT_UINT64_OTHER, 5 * sizeof (ztest_block_tag_t), tx) == 0);
1218 VERIFY(zap_create_claim(os, ZTEST_MICROZAP_OBJ,
1219 DMU_OT_ZAP_OTHER, DMU_OT_NONE, 0, tx) == 0);
1221 VERIFY(zap_create_claim(os, ZTEST_FATZAP_OBJ,
1222 DMU_OT_ZAP_OTHER, DMU_OT_NONE, 0, tx) == 0);
1226 ztest_destroy_cb(char *name, void *arg)
1228 ztest_args_t *za = arg;
1230 dmu_object_info_t *doi = &za->za_doi;
1234 * Verify that the dataset contains a directory object.
1236 error = dmu_objset_open(name, DMU_OST_OTHER,
1237 DS_MODE_USER | DS_MODE_READONLY, &os);
1238 ASSERT3U(error, ==, 0);
1239 error = dmu_object_info(os, ZTEST_DIROBJ, doi);
1240 if (error != ENOENT) {
1241 /* We could have crashed in the middle of destroying it */
1242 ASSERT3U(error, ==, 0);
1243 ASSERT3U(doi->doi_type, ==, DMU_OT_UINT64_OTHER);
1244 ASSERT3S(doi->doi_physical_blks, >=, 0);
1246 dmu_objset_close(os);
1249 * Destroy the dataset.
1251 error = dmu_objset_destroy(name);
1253 (void) dmu_objset_open(name, DMU_OST_OTHER,
1254 DS_MODE_USER | DS_MODE_READONLY, &os);
1255 fatal(0, "dmu_objset_destroy(os=%p) = %d\n", &os, error);
1261 * Verify that dmu_objset_{create,destroy,open,close} work as expected.
1264 ztest_log_create(zilog_t *zilog, dmu_tx_t *tx, uint64_t object, int mode)
1271 (void) sprintf(name, "ZOBJ_%llu", (u_longlong_t)object);
1272 namesize = strlen(name) + 1;
1274 itx = zil_itx_create(TX_CREATE, sizeof (*lr) + namesize +
1275 ztest_random(ZIL_MAX_BLKSZ));
1276 lr = (lr_create_t *)&itx->itx_lr;
1277 bzero(lr + 1, lr->lr_common.lrc_reclen - sizeof (*lr));
1278 lr->lr_doid = object;
1283 lr->lr_gen = dmu_tx_get_txg(tx);
1284 lr->lr_crtime[0] = time(NULL);
1285 lr->lr_crtime[1] = 0;
1287 bcopy(name, (char *)(lr + 1), namesize);
1289 return (zil_itx_assign(zilog, itx, tx));
1293 ztest_dmu_objset_create_destroy(ztest_args_t *za)
1298 int basemode, expected_error;
1303 (void) rw_rdlock(&ztest_shared->zs_name_lock);
1304 (void) snprintf(name, 100, "%s/%s_temp_%llu", za->za_pool, za->za_pool,
1305 (u_longlong_t)za->za_instance);
1307 basemode = DS_MODE_TYPE(za->za_instance);
1308 if (basemode != DS_MODE_USER && basemode != DS_MODE_OWNER)
1309 basemode = DS_MODE_USER;
1312 * If this dataset exists from a previous run, process its replay log
1313 * half of the time. If we don't replay it, then dmu_objset_destroy()
1314 * (invoked from ztest_destroy_cb() below) should just throw it away.
1316 if (ztest_random(2) == 0 &&
1317 dmu_objset_open(name, DMU_OST_OTHER, DS_MODE_OWNER, &os) == 0) {
1318 zil_replay(os, os, ztest_replay_vector);
1319 dmu_objset_close(os);
1323 * There may be an old instance of the dataset we're about to
1324 * create lying around from a previous run. If so, destroy it
1325 * and all of its snapshots.
1327 (void) dmu_objset_find(name, ztest_destroy_cb, za,
1328 DS_FIND_CHILDREN | DS_FIND_SNAPSHOTS);
1331 * Verify that the destroyed dataset is no longer in the namespace.
1333 error = dmu_objset_open(name, DMU_OST_OTHER, basemode, &os);
1334 if (error != ENOENT)
1335 fatal(1, "dmu_objset_open(%s) found destroyed dataset %p",
1339 * Verify that we can create a new dataset.
1341 error = dmu_objset_create(name, DMU_OST_OTHER, NULL, 0,
1342 ztest_create_cb, NULL);
1344 if (error == ENOSPC) {
1345 ztest_record_enospc("dmu_objset_create");
1346 (void) rw_unlock(&ztest_shared->zs_name_lock);
1349 fatal(0, "dmu_objset_create(%s) = %d", name, error);
1352 error = dmu_objset_open(name, DMU_OST_OTHER, basemode, &os);
1354 fatal(0, "dmu_objset_open(%s) = %d", name, error);
1358 * Open the intent log for it.
1360 zilog = zil_open(os, NULL);
1363 * Put a random number of objects in there.
1365 objects = ztest_random(20);
1367 while (objects-- != 0) {
1369 dmu_tx_t *tx = dmu_tx_create(os);
1370 dmu_tx_hold_write(tx, DMU_NEW_OBJECT, 0, sizeof (name));
1371 error = dmu_tx_assign(tx, TXG_WAIT);
1375 object = dmu_object_alloc(os, DMU_OT_UINT64_OTHER, 0,
1376 DMU_OT_NONE, 0, tx);
1377 ztest_set_random_blocksize(os, object, tx);
1378 seq = ztest_log_create(zilog, tx, object,
1379 DMU_OT_UINT64_OTHER);
1380 dmu_write(os, object, 0, sizeof (name), name, tx);
1383 if (ztest_random(5) == 0) {
1384 zil_commit(zilog, seq, object);
1386 if (ztest_random(100) == 0) {
1387 error = zil_suspend(zilog);
1395 * Verify that we cannot create an existing dataset.
1397 error = dmu_objset_create(name, DMU_OST_OTHER, NULL, 0, NULL, NULL);
1398 if (error != EEXIST)
1399 fatal(0, "created existing dataset, error = %d", error);
1402 * Verify that multiple dataset holds are allowed, but only when
1403 * the new access mode is compatible with the base mode.
1405 if (basemode == DS_MODE_OWNER) {
1406 error = dmu_objset_open(name, DMU_OST_OTHER, DS_MODE_USER,
1409 fatal(0, "dmu_objset_open('%s') = %d", name, error);
1411 dmu_objset_close(os2);
1413 error = dmu_objset_open(name, DMU_OST_OTHER, DS_MODE_OWNER, &os2);
1414 expected_error = (basemode == DS_MODE_OWNER) ? EBUSY : 0;
1415 if (error != expected_error)
1416 fatal(0, "dmu_objset_open('%s') = %d, expected %d",
1417 name, error, expected_error);
1419 dmu_objset_close(os2);
1422 dmu_objset_close(os);
1424 error = dmu_objset_destroy(name);
1426 fatal(0, "dmu_objset_destroy(%s) = %d", name, error);
1428 (void) rw_unlock(&ztest_shared->zs_name_lock);
1432 * Verify that dmu_snapshot_{create,destroy,open,close} work as expected.
1435 ztest_dmu_snapshot_create_destroy(ztest_args_t *za)
1438 objset_t *os = za->za_os;
1440 char osname[MAXNAMELEN];
1442 (void) rw_rdlock(&ztest_shared->zs_name_lock);
1443 dmu_objset_name(os, osname);
1444 (void) snprintf(snapname, 100, "%s@%llu", osname,
1445 (u_longlong_t)za->za_instance);
1447 error = dmu_objset_destroy(snapname);
1448 if (error != 0 && error != ENOENT)
1449 fatal(0, "dmu_objset_destroy() = %d", error);
1450 error = dmu_objset_snapshot(osname, strchr(snapname, '@')+1,
1452 if (error == ENOSPC)
1453 ztest_record_enospc("dmu_take_snapshot");
1454 else if (error != 0 && error != EEXIST)
1455 fatal(0, "dmu_take_snapshot() = %d", error);
1456 (void) rw_unlock(&ztest_shared->zs_name_lock);
1460 * Verify dsl_dataset_promote handles EBUSY
1463 ztest_dsl_dataset_promote_busy(ztest_args_t *za)
1466 objset_t *os = za->za_os;
1469 char snap1name[100];
1470 char clone1name[100];
1471 char snap2name[100];
1472 char clone2name[100];
1473 char snap3name[100];
1474 char osname[MAXNAMELEN];
1475 static uint64_t uniq = 0;
1478 curval = atomic_add_64_nv(&uniq, 5) - 5;
1480 (void) rw_rdlock(&ztest_shared->zs_name_lock);
1482 dmu_objset_name(os, osname);
1483 (void) snprintf(snap1name, 100, "%s@s1_%llu", osname, curval++);
1484 (void) snprintf(clone1name, 100, "%s/c1_%llu", osname, curval++);
1485 (void) snprintf(snap2name, 100, "%s@s2_%llu", clone1name, curval++);
1486 (void) snprintf(clone2name, 100, "%s/c2_%llu", osname, curval++);
1487 (void) snprintf(snap3name, 100, "%s@s3_%llu", clone1name, curval++);
1489 error = dmu_objset_snapshot(osname, strchr(snap1name, '@')+1,
1491 if (error && error != EEXIST) {
1492 if (error == ENOSPC) {
1493 ztest_record_enospc(FTAG);
1496 fatal(0, "dmu_take_snapshot(%s) = %d", snap1name, error);
1499 error = dmu_objset_open(snap1name, DMU_OST_OTHER,
1500 DS_MODE_USER | DS_MODE_READONLY, &clone);
1502 fatal(0, "dmu_open_snapshot(%s) = %d", snap1name, error);
1504 error = dmu_objset_create(clone1name, DMU_OST_OTHER, clone, 0,
1506 dmu_objset_close(clone);
1508 if (error == ENOSPC) {
1509 ztest_record_enospc(FTAG);
1512 fatal(0, "dmu_objset_create(%s) = %d", clone1name, error);
1515 error = dmu_objset_snapshot(clone1name, strchr(snap2name, '@')+1,
1517 if (error && error != EEXIST) {
1518 if (error == ENOSPC) {
1519 ztest_record_enospc(FTAG);
1522 fatal(0, "dmu_open_snapshot(%s) = %d", snap2name, error);
1525 error = dmu_objset_snapshot(clone1name, strchr(snap3name, '@')+1,
1527 if (error && error != EEXIST) {
1528 if (error == ENOSPC) {
1529 ztest_record_enospc(FTAG);
1532 fatal(0, "dmu_open_snapshot(%s) = %d", snap3name, error);
1535 error = dmu_objset_open(snap3name, DMU_OST_OTHER,
1536 DS_MODE_USER | DS_MODE_READONLY, &clone);
1538 fatal(0, "dmu_open_snapshot(%s) = %d", snap3name, error);
1540 error = dmu_objset_create(clone2name, DMU_OST_OTHER, clone, 0,
1542 dmu_objset_close(clone);
1544 if (error == ENOSPC) {
1545 ztest_record_enospc("dmu_objset_create");
1548 fatal(0, "dmu_objset_create(%s) = %d", clone2name, error);
1551 error = dsl_dataset_own(snap1name, 0, FTAG, &ds);
1553 fatal(0, "dsl_dataset_own(%s) = %d", snap1name, error);
1554 error = dsl_dataset_promote(clone2name);
1556 fatal(0, "dsl_dataset_promote(%s), %d, not EBUSY", clone2name,
1558 dsl_dataset_disown(ds, FTAG);
1561 error = dmu_objset_destroy(clone2name);
1562 if (error && error != ENOENT)
1563 fatal(0, "dmu_objset_destroy(%s) = %d", clone2name, error);
1565 error = dmu_objset_destroy(snap3name);
1566 if (error && error != ENOENT)
1567 fatal(0, "dmu_objset_destroy(%s) = %d", snap2name, error);
1569 error = dmu_objset_destroy(snap2name);
1570 if (error && error != ENOENT)
1571 fatal(0, "dmu_objset_destroy(%s) = %d", snap2name, error);
1573 error = dmu_objset_destroy(clone1name);
1574 if (error && error != ENOENT)
1575 fatal(0, "dmu_objset_destroy(%s) = %d", clone1name, error);
1576 error = dmu_objset_destroy(snap1name);
1577 if (error && error != ENOENT)
1578 fatal(0, "dmu_objset_destroy(%s) = %d", snap1name, error);
1580 (void) rw_unlock(&ztest_shared->zs_name_lock);
1584 * Verify that dmu_object_{alloc,free} work as expected.
1587 ztest_dmu_object_alloc_free(ztest_args_t *za)
1589 objset_t *os = za->za_os;
1592 uint64_t batchobj, object, batchsize, endoff, temp;
1593 int b, c, error, bonuslen;
1594 dmu_object_info_t *doi = &za->za_doi;
1595 char osname[MAXNAMELEN];
1597 dmu_objset_name(os, osname);
1603 * Create a batch object if necessary, and record it in the directory.
1605 VERIFY3U(0, ==, dmu_read(os, ZTEST_DIROBJ, za->za_diroff,
1606 sizeof (uint64_t), &batchobj, DMU_READ_PREFETCH));
1607 if (batchobj == 0) {
1608 tx = dmu_tx_create(os);
1609 dmu_tx_hold_write(tx, ZTEST_DIROBJ, za->za_diroff,
1611 dmu_tx_hold_bonus(tx, DMU_NEW_OBJECT);
1612 error = dmu_tx_assign(tx, TXG_WAIT);
1614 ztest_record_enospc("create a batch object");
1618 batchobj = dmu_object_alloc(os, DMU_OT_UINT64_OTHER, 0,
1619 DMU_OT_NONE, 0, tx);
1620 ztest_set_random_blocksize(os, batchobj, tx);
1621 dmu_write(os, ZTEST_DIROBJ, za->za_diroff,
1622 sizeof (uint64_t), &batchobj, tx);
1627 * Destroy the previous batch of objects.
1629 for (b = 0; b < batchsize; b++) {
1630 VERIFY3U(0, ==, dmu_read(os, batchobj, b * sizeof (uint64_t),
1631 sizeof (uint64_t), &object, DMU_READ_PREFETCH));
1635 * Read and validate contents.
1636 * We expect the nth byte of the bonus buffer to be n.
1638 VERIFY(0 == dmu_bonus_hold(os, object, FTAG, &db));
1641 dmu_object_info_from_db(db, doi);
1642 ASSERT(doi->doi_type == DMU_OT_UINT64_OTHER);
1643 ASSERT(doi->doi_bonus_type == DMU_OT_PLAIN_OTHER);
1644 ASSERT3S(doi->doi_physical_blks, >=, 0);
1646 bonuslen = doi->doi_bonus_size;
1648 for (c = 0; c < bonuslen; c++) {
1649 if (((uint8_t *)db->db_data)[c] !=
1650 (uint8_t)(c + bonuslen)) {
1652 "bad bonus: %s, obj %llu, off %d: %u != %u",
1654 ((uint8_t *)db->db_data)[c],
1655 (uint8_t)(c + bonuslen));
1659 dmu_buf_rele(db, FTAG);
1663 * We expect the word at endoff to be our object number.
1665 VERIFY(0 == dmu_read(os, object, endoff,
1666 sizeof (uint64_t), &temp, DMU_READ_PREFETCH));
1668 if (temp != object) {
1669 fatal(0, "bad data in %s, got %llu, expected %llu",
1670 osname, temp, object);
1674 * Destroy old object and clear batch entry.
1676 tx = dmu_tx_create(os);
1677 dmu_tx_hold_write(tx, batchobj,
1678 b * sizeof (uint64_t), sizeof (uint64_t));
1679 dmu_tx_hold_free(tx, object, 0, DMU_OBJECT_END);
1680 error = dmu_tx_assign(tx, TXG_WAIT);
1682 ztest_record_enospc("free object");
1686 error = dmu_object_free(os, object, tx);
1688 fatal(0, "dmu_object_free('%s', %llu) = %d",
1689 osname, object, error);
1693 dmu_object_set_checksum(os, batchobj,
1694 ztest_random_checksum(), tx);
1695 dmu_object_set_compress(os, batchobj,
1696 ztest_random_compress(), tx);
1698 dmu_write(os, batchobj, b * sizeof (uint64_t),
1699 sizeof (uint64_t), &object, tx);
1705 * Before creating the new batch of objects, generate a bunch of churn.
1707 for (b = ztest_random(100); b > 0; b--) {
1708 tx = dmu_tx_create(os);
1709 dmu_tx_hold_bonus(tx, DMU_NEW_OBJECT);
1710 error = dmu_tx_assign(tx, TXG_WAIT);
1712 ztest_record_enospc("churn objects");
1716 object = dmu_object_alloc(os, DMU_OT_UINT64_OTHER, 0,
1717 DMU_OT_NONE, 0, tx);
1718 ztest_set_random_blocksize(os, object, tx);
1719 error = dmu_object_free(os, object, tx);
1721 fatal(0, "dmu_object_free('%s', %llu) = %d",
1722 osname, object, error);
1728 * Create a new batch of objects with randomly chosen
1729 * blocksizes and record them in the batch directory.
1731 for (b = 0; b < batchsize; b++) {
1732 uint32_t va_blksize;
1733 u_longlong_t va_nblocks;
1735 tx = dmu_tx_create(os);
1736 dmu_tx_hold_write(tx, batchobj, b * sizeof (uint64_t),
1738 dmu_tx_hold_bonus(tx, DMU_NEW_OBJECT);
1739 dmu_tx_hold_write(tx, DMU_NEW_OBJECT, endoff,
1741 error = dmu_tx_assign(tx, TXG_WAIT);
1743 ztest_record_enospc("create batchobj");
1747 bonuslen = (int)ztest_random(dmu_bonus_max()) + 1;
1749 object = dmu_object_alloc(os, DMU_OT_UINT64_OTHER, 0,
1750 DMU_OT_PLAIN_OTHER, bonuslen, tx);
1752 ztest_set_random_blocksize(os, object, tx);
1754 dmu_object_set_checksum(os, object,
1755 ztest_random_checksum(), tx);
1756 dmu_object_set_compress(os, object,
1757 ztest_random_compress(), tx);
1759 dmu_write(os, batchobj, b * sizeof (uint64_t),
1760 sizeof (uint64_t), &object, tx);
1763 * Write to both the bonus buffer and the regular data.
1765 VERIFY(dmu_bonus_hold(os, object, FTAG, &db) == 0);
1767 ASSERT3U(bonuslen, <=, db->db_size);
1769 dmu_object_size_from_db(db, &va_blksize, &va_nblocks);
1770 ASSERT3S(va_nblocks, >=, 0);
1772 dmu_buf_will_dirty(db, tx);
1775 * See comments above regarding the contents of
1776 * the bonus buffer and the word at endoff.
1778 for (c = 0; c < bonuslen; c++)
1779 ((uint8_t *)db->db_data)[c] = (uint8_t)(c + bonuslen);
1781 dmu_buf_rele(db, FTAG);
1785 * Write to a large offset to increase indirection.
1787 dmu_write(os, object, endoff, sizeof (uint64_t), &object, tx);
1794 * Verify that dmu_{read,write} work as expected.
1796 typedef struct bufwad {
1802 typedef struct dmu_read_write_dir {
1803 uint64_t dd_packobj;
1806 } dmu_read_write_dir_t;
1809 ztest_dmu_read_write(ztest_args_t *za)
1811 objset_t *os = za->za_os;
1812 dmu_read_write_dir_t dd;
1814 int i, freeit, error;
1816 bufwad_t *packbuf, *bigbuf, *pack, *bigH, *bigT;
1817 uint64_t packoff, packsize, bigoff, bigsize;
1818 uint64_t regions = 997;
1819 uint64_t stride = 123456789ULL;
1820 uint64_t width = 40;
1821 int free_percent = 5;
1824 * This test uses two objects, packobj and bigobj, that are always
1825 * updated together (i.e. in the same tx) so that their contents are
1826 * in sync and can be compared. Their contents relate to each other
1827 * in a simple way: packobj is a dense array of 'bufwad' structures,
1828 * while bigobj is a sparse array of the same bufwads. Specifically,
1829 * for any index n, there are three bufwads that should be identical:
1831 * packobj, at offset n * sizeof (bufwad_t)
1832 * bigobj, at the head of the nth chunk
1833 * bigobj, at the tail of the nth chunk
1835 * The chunk size is arbitrary. It doesn't have to be a power of two,
1836 * and it doesn't have any relation to the object blocksize.
1837 * The only requirement is that it can hold at least two bufwads.
1839 * Normally, we write the bufwad to each of these locations.
1840 * However, free_percent of the time we instead write zeroes to
1841 * packobj and perform a dmu_free_range() on bigobj. By comparing
1842 * bigobj to packobj, we can verify that the DMU is correctly
1843 * tracking which parts of an object are allocated and free,
1844 * and that the contents of the allocated blocks are correct.
1848 * Read the directory info. If it's the first time, set things up.
1850 VERIFY(0 == dmu_read(os, ZTEST_DIROBJ, za->za_diroff,
1851 sizeof (dd), &dd, DMU_READ_PREFETCH));
1852 if (dd.dd_chunk == 0) {
1853 ASSERT(dd.dd_packobj == 0);
1854 ASSERT(dd.dd_bigobj == 0);
1855 tx = dmu_tx_create(os);
1856 dmu_tx_hold_write(tx, ZTEST_DIROBJ, za->za_diroff, sizeof (dd));
1857 dmu_tx_hold_bonus(tx, DMU_NEW_OBJECT);
1858 error = dmu_tx_assign(tx, TXG_WAIT);
1860 ztest_record_enospc("create r/w directory");
1865 dd.dd_packobj = dmu_object_alloc(os, DMU_OT_UINT64_OTHER, 0,
1866 DMU_OT_NONE, 0, tx);
1867 dd.dd_bigobj = dmu_object_alloc(os, DMU_OT_UINT64_OTHER, 0,
1868 DMU_OT_NONE, 0, tx);
1869 dd.dd_chunk = (1000 + ztest_random(1000)) * sizeof (uint64_t);
1871 ztest_set_random_blocksize(os, dd.dd_packobj, tx);
1872 ztest_set_random_blocksize(os, dd.dd_bigobj, tx);
1874 dmu_write(os, ZTEST_DIROBJ, za->za_diroff, sizeof (dd), &dd,
1880 * Prefetch a random chunk of the big object.
1881 * Our aim here is to get some async reads in flight
1882 * for blocks that we may free below; the DMU should
1883 * handle this race correctly.
1885 n = ztest_random(regions) * stride + ztest_random(width);
1886 s = 1 + ztest_random(2 * width - 1);
1887 dmu_prefetch(os, dd.dd_bigobj, n * dd.dd_chunk, s * dd.dd_chunk);
1890 * Pick a random index and compute the offsets into packobj and bigobj.
1892 n = ztest_random(regions) * stride + ztest_random(width);
1893 s = 1 + ztest_random(width - 1);
1895 packoff = n * sizeof (bufwad_t);
1896 packsize = s * sizeof (bufwad_t);
1898 bigoff = n * dd.dd_chunk;
1899 bigsize = s * dd.dd_chunk;
1901 packbuf = umem_alloc(packsize, UMEM_NOFAIL);
1902 bigbuf = umem_alloc(bigsize, UMEM_NOFAIL);
1905 * free_percent of the time, free a range of bigobj rather than
1908 freeit = (ztest_random(100) < free_percent);
1911 * Read the current contents of our objects.
1913 error = dmu_read(os, dd.dd_packobj, packoff, packsize, packbuf,
1915 ASSERT3U(error, ==, 0);
1916 error = dmu_read(os, dd.dd_bigobj, bigoff, bigsize, bigbuf,
1918 ASSERT3U(error, ==, 0);
1921 * Get a tx for the mods to both packobj and bigobj.
1923 tx = dmu_tx_create(os);
1925 dmu_tx_hold_write(tx, dd.dd_packobj, packoff, packsize);
1928 dmu_tx_hold_free(tx, dd.dd_bigobj, bigoff, bigsize);
1930 dmu_tx_hold_write(tx, dd.dd_bigobj, bigoff, bigsize);
1932 error = dmu_tx_assign(tx, TXG_WAIT);
1935 ztest_record_enospc("dmu r/w range");
1937 umem_free(packbuf, packsize);
1938 umem_free(bigbuf, bigsize);
1942 txg = dmu_tx_get_txg(tx);
1945 * For each index from n to n + s, verify that the existing bufwad
1946 * in packobj matches the bufwads at the head and tail of the
1947 * corresponding chunk in bigobj. Then update all three bufwads
1948 * with the new values we want to write out.
1950 for (i = 0; i < s; i++) {
1952 pack = (bufwad_t *)((char *)packbuf + i * sizeof (bufwad_t));
1954 bigH = (bufwad_t *)((char *)bigbuf + i * dd.dd_chunk);
1956 bigT = (bufwad_t *)((char *)bigH + dd.dd_chunk) - 1;
1958 ASSERT((uintptr_t)bigH - (uintptr_t)bigbuf < bigsize);
1959 ASSERT((uintptr_t)bigT - (uintptr_t)bigbuf < bigsize);
1961 if (pack->bw_txg > txg)
1962 fatal(0, "future leak: got %llx, open txg is %llx",
1965 if (pack->bw_data != 0 && pack->bw_index != n + i)
1966 fatal(0, "wrong index: got %llx, wanted %llx+%llx",
1967 pack->bw_index, n, i);
1969 if (bcmp(pack, bigH, sizeof (bufwad_t)) != 0)
1970 fatal(0, "pack/bigH mismatch in %p/%p", pack, bigH);
1972 if (bcmp(pack, bigT, sizeof (bufwad_t)) != 0)
1973 fatal(0, "pack/bigT mismatch in %p/%p", pack, bigT);
1976 bzero(pack, sizeof (bufwad_t));
1978 pack->bw_index = n + i;
1980 pack->bw_data = 1 + ztest_random(-2ULL);
1987 * We've verified all the old bufwads, and made new ones.
1988 * Now write them out.
1990 dmu_write(os, dd.dd_packobj, packoff, packsize, packbuf, tx);
1993 if (zopt_verbose >= 6) {
1994 (void) printf("freeing offset %llx size %llx"
1996 (u_longlong_t)bigoff,
1997 (u_longlong_t)bigsize,
2000 VERIFY(0 == dmu_free_range(os, dd.dd_bigobj, bigoff,
2003 if (zopt_verbose >= 6) {
2004 (void) printf("writing offset %llx size %llx"
2006 (u_longlong_t)bigoff,
2007 (u_longlong_t)bigsize,
2010 dmu_write(os, dd.dd_bigobj, bigoff, bigsize, bigbuf, tx);
2016 * Sanity check the stuff we just wrote.
2019 void *packcheck = umem_alloc(packsize, UMEM_NOFAIL);
2020 void *bigcheck = umem_alloc(bigsize, UMEM_NOFAIL);
2022 VERIFY(0 == dmu_read(os, dd.dd_packobj, packoff,
2023 packsize, packcheck, DMU_READ_PREFETCH));
2024 VERIFY(0 == dmu_read(os, dd.dd_bigobj, bigoff,
2025 bigsize, bigcheck, DMU_READ_PREFETCH));
2027 ASSERT(bcmp(packbuf, packcheck, packsize) == 0);
2028 ASSERT(bcmp(bigbuf, bigcheck, bigsize) == 0);
2030 umem_free(packcheck, packsize);
2031 umem_free(bigcheck, bigsize);
2034 umem_free(packbuf, packsize);
2035 umem_free(bigbuf, bigsize);
2039 compare_and_update_pbbufs(uint64_t s, bufwad_t *packbuf, bufwad_t *bigbuf,
2040 uint64_t bigsize, uint64_t n, dmu_read_write_dir_t dd, uint64_t txg)
2048 * For each index from n to n + s, verify that the existing bufwad
2049 * in packobj matches the bufwads at the head and tail of the
2050 * corresponding chunk in bigobj. Then update all three bufwads
2051 * with the new values we want to write out.
2053 for (i = 0; i < s; i++) {
2055 pack = (bufwad_t *)((char *)packbuf + i * sizeof (bufwad_t));
2057 bigH = (bufwad_t *)((char *)bigbuf + i * dd.dd_chunk);
2059 bigT = (bufwad_t *)((char *)bigH + dd.dd_chunk) - 1;
2061 ASSERT((uintptr_t)bigH - (uintptr_t)bigbuf < bigsize);
2062 ASSERT((uintptr_t)bigT - (uintptr_t)bigbuf < bigsize);
2064 if (pack->bw_txg > txg)
2065 fatal(0, "future leak: got %llx, open txg is %llx",
2068 if (pack->bw_data != 0 && pack->bw_index != n + i)
2069 fatal(0, "wrong index: got %llx, wanted %llx+%llx",
2070 pack->bw_index, n, i);
2072 if (bcmp(pack, bigH, sizeof (bufwad_t)) != 0)
2073 fatal(0, "pack/bigH mismatch in %p/%p", pack, bigH);
2075 if (bcmp(pack, bigT, sizeof (bufwad_t)) != 0)
2076 fatal(0, "pack/bigT mismatch in %p/%p", pack, bigT);
2078 pack->bw_index = n + i;
2080 pack->bw_data = 1 + ztest_random(-2ULL);
2088 ztest_dmu_read_write_zcopy(ztest_args_t *za)
2090 objset_t *os = za->za_os;
2091 dmu_read_write_dir_t dd;
2096 bufwad_t *packbuf, *bigbuf;
2097 uint64_t packoff, packsize, bigoff, bigsize;
2098 uint64_t regions = 997;
2099 uint64_t stride = 123456789ULL;
2101 dmu_buf_t *bonus_db;
2102 arc_buf_t **bigbuf_arcbufs;
2103 dmu_object_info_t *doi = &za->za_doi;
2106 * This test uses two objects, packobj and bigobj, that are always
2107 * updated together (i.e. in the same tx) so that their contents are
2108 * in sync and can be compared. Their contents relate to each other
2109 * in a simple way: packobj is a dense array of 'bufwad' structures,
2110 * while bigobj is a sparse array of the same bufwads. Specifically,
2111 * for any index n, there are three bufwads that should be identical:
2113 * packobj, at offset n * sizeof (bufwad_t)
2114 * bigobj, at the head of the nth chunk
2115 * bigobj, at the tail of the nth chunk
2117 * The chunk size is set equal to bigobj block size so that
2118 * dmu_assign_arcbuf() can be tested for object updates.
2122 * Read the directory info. If it's the first time, set things up.
2124 VERIFY(0 == dmu_read(os, ZTEST_DIROBJ, za->za_diroff,
2125 sizeof (dd), &dd, DMU_READ_PREFETCH));
2126 if (dd.dd_chunk == 0) {
2127 ASSERT(dd.dd_packobj == 0);
2128 ASSERT(dd.dd_bigobj == 0);
2129 tx = dmu_tx_create(os);
2130 dmu_tx_hold_write(tx, ZTEST_DIROBJ, za->za_diroff, sizeof (dd));
2131 dmu_tx_hold_bonus(tx, DMU_NEW_OBJECT);
2132 error = dmu_tx_assign(tx, TXG_WAIT);
2134 ztest_record_enospc("create r/w directory");
2139 dd.dd_packobj = dmu_object_alloc(os, DMU_OT_UINT64_OTHER, 0,
2140 DMU_OT_NONE, 0, tx);
2141 dd.dd_bigobj = dmu_object_alloc(os, DMU_OT_UINT64_OTHER, 0,
2142 DMU_OT_NONE, 0, tx);
2143 ztest_set_random_blocksize(os, dd.dd_packobj, tx);
2144 ztest_set_random_blocksize(os, dd.dd_bigobj, tx);
2146 VERIFY(dmu_object_info(os, dd.dd_bigobj, doi) == 0);
2147 ASSERT(doi->doi_data_block_size >= 2 * sizeof (bufwad_t));
2148 ASSERT(ISP2(doi->doi_data_block_size));
2149 dd.dd_chunk = doi->doi_data_block_size;
2151 dmu_write(os, ZTEST_DIROBJ, za->za_diroff, sizeof (dd), &dd,
2155 VERIFY(dmu_object_info(os, dd.dd_bigobj, doi) == 0);
2156 VERIFY(ISP2(doi->doi_data_block_size));
2157 VERIFY(dd.dd_chunk == doi->doi_data_block_size);
2158 VERIFY(dd.dd_chunk >= 2 * sizeof (bufwad_t));
2162 * Pick a random index and compute the offsets into packobj and bigobj.
2164 n = ztest_random(regions) * stride + ztest_random(width);
2165 s = 1 + ztest_random(width - 1);
2167 packoff = n * sizeof (bufwad_t);
2168 packsize = s * sizeof (bufwad_t);
2170 bigoff = n * dd.dd_chunk;
2171 bigsize = s * dd.dd_chunk;
2173 packbuf = umem_zalloc(packsize, UMEM_NOFAIL);
2174 bigbuf = umem_zalloc(bigsize, UMEM_NOFAIL);
2176 VERIFY(dmu_bonus_hold(os, dd.dd_bigobj, FTAG, &bonus_db) == 0);
2178 bigbuf_arcbufs = umem_zalloc(2 * s * sizeof (arc_buf_t *), UMEM_NOFAIL);
2181 * Iteration 0 test zcopy for DB_UNCACHED dbufs.
2182 * Iteration 1 test zcopy to already referenced dbufs.
2183 * Iteration 2 test zcopy to dirty dbuf in the same txg.
2184 * Iteration 3 test zcopy to dbuf dirty in previous txg.
2185 * Iteration 4 test zcopy when dbuf is no longer dirty.
2186 * Iteration 5 test zcopy when it can't be done.
2187 * Iteration 6 one more zcopy write.
2189 for (i = 0; i < 7; i++) {
2194 * In iteration 5 (i == 5) use arcbufs
2195 * that don't match bigobj blksz to test
2196 * dmu_assign_arcbuf() when it can't directly
2197 * assign an arcbuf to a dbuf.
2199 for (j = 0; j < s; j++) {
2202 dmu_request_arcbuf(bonus_db,
2205 bigbuf_arcbufs[2 * j] =
2206 dmu_request_arcbuf(bonus_db,
2208 bigbuf_arcbufs[2 * j + 1] =
2209 dmu_request_arcbuf(bonus_db,
2215 * Get a tx for the mods to both packobj and bigobj.
2217 tx = dmu_tx_create(os);
2219 dmu_tx_hold_write(tx, dd.dd_packobj, packoff, packsize);
2220 dmu_tx_hold_write(tx, dd.dd_bigobj, bigoff, bigsize);
2222 if (ztest_random(100) == 0) {
2225 error = dmu_tx_assign(tx, TXG_WAIT);
2230 ztest_record_enospc("dmu r/w range");
2233 umem_free(packbuf, packsize);
2234 umem_free(bigbuf, bigsize);
2235 for (j = 0; j < s; j++) {
2237 dmu_return_arcbuf(bigbuf_arcbufs[j]);
2240 bigbuf_arcbufs[2 * j]);
2242 bigbuf_arcbufs[2 * j + 1]);
2245 umem_free(bigbuf_arcbufs, 2 * s * sizeof (arc_buf_t *));
2246 dmu_buf_rele(bonus_db, FTAG);
2250 txg = dmu_tx_get_txg(tx);
2253 * 50% of the time don't read objects in the 1st iteration to
2254 * test dmu_assign_arcbuf() for the case when there're no
2255 * existing dbufs for the specified offsets.
2257 if (i != 0 || ztest_random(2) != 0) {
2258 error = dmu_read(os, dd.dd_packobj, packoff,
2259 packsize, packbuf, DMU_READ_PREFETCH);
2260 ASSERT3U(error, ==, 0);
2261 error = dmu_read(os, dd.dd_bigobj, bigoff, bigsize,
2262 bigbuf, DMU_READ_PREFETCH);
2263 ASSERT3U(error, ==, 0);
2265 compare_and_update_pbbufs(s, packbuf, bigbuf, bigsize,
2269 * We've verified all the old bufwads, and made new ones.
2270 * Now write them out.
2272 dmu_write(os, dd.dd_packobj, packoff, packsize, packbuf, tx);
2273 if (zopt_verbose >= 6) {
2274 (void) printf("writing offset %llx size %llx"
2276 (u_longlong_t)bigoff,
2277 (u_longlong_t)bigsize,
2280 for (off = bigoff, j = 0; j < s; j++, off += dd.dd_chunk) {
2283 bcopy((caddr_t)bigbuf + (off - bigoff),
2284 bigbuf_arcbufs[j]->b_data, dd.dd_chunk);
2286 bcopy((caddr_t)bigbuf + (off - bigoff),
2287 bigbuf_arcbufs[2 * j]->b_data,
2289 bcopy((caddr_t)bigbuf + (off - bigoff) +
2291 bigbuf_arcbufs[2 * j + 1]->b_data,
2296 VERIFY(dmu_buf_hold(os, dd.dd_bigobj, off,
2300 dmu_assign_arcbuf(bonus_db, off,
2301 bigbuf_arcbufs[j], tx);
2303 dmu_assign_arcbuf(bonus_db, off,
2304 bigbuf_arcbufs[2 * j], tx);
2305 dmu_assign_arcbuf(bonus_db,
2306 off + dd.dd_chunk / 2,
2307 bigbuf_arcbufs[2 * j + 1], tx);
2310 dmu_buf_rele(dbt, FTAG);
2316 * Sanity check the stuff we just wrote.
2319 void *packcheck = umem_alloc(packsize, UMEM_NOFAIL);
2320 void *bigcheck = umem_alloc(bigsize, UMEM_NOFAIL);
2322 VERIFY(0 == dmu_read(os, dd.dd_packobj, packoff,
2323 packsize, packcheck, DMU_READ_PREFETCH));
2324 VERIFY(0 == dmu_read(os, dd.dd_bigobj, bigoff,
2325 bigsize, bigcheck, DMU_READ_PREFETCH));
2327 ASSERT(bcmp(packbuf, packcheck, packsize) == 0);
2328 ASSERT(bcmp(bigbuf, bigcheck, bigsize) == 0);
2330 umem_free(packcheck, packsize);
2331 umem_free(bigcheck, bigsize);
2334 txg_wait_open(dmu_objset_pool(os), 0);
2335 } else if (i == 3) {
2336 txg_wait_synced(dmu_objset_pool(os), 0);
2340 dmu_buf_rele(bonus_db, FTAG);
2341 umem_free(packbuf, packsize);
2342 umem_free(bigbuf, bigsize);
2343 umem_free(bigbuf_arcbufs, 2 * s * sizeof (arc_buf_t *));
2347 ztest_dmu_check_future_leak(ztest_args_t *za)
2349 objset_t *os = za->za_os;
2351 ztest_block_tag_t *bt;
2352 dmu_object_info_t *doi = &za->za_doi;
2355 * Make sure that, if there is a write record in the bonus buffer
2356 * of the ZTEST_DIROBJ, that the txg for this record is <= the
2357 * last synced txg of the pool.
2359 VERIFY(dmu_bonus_hold(os, ZTEST_DIROBJ, FTAG, &db) == 0);
2361 VERIFY(dmu_object_info(os, ZTEST_DIROBJ, doi) == 0);
2362 ASSERT3U(doi->doi_bonus_size, >=, sizeof (*bt));
2363 ASSERT3U(doi->doi_bonus_size, <=, db->db_size);
2364 ASSERT3U(doi->doi_bonus_size % sizeof (*bt), ==, 0);
2365 bt = (void *)((char *)db->db_data + doi->doi_bonus_size - sizeof (*bt));
2366 if (bt->bt_objset != 0) {
2367 ASSERT3U(bt->bt_objset, ==, dmu_objset_id(os));
2368 ASSERT3U(bt->bt_object, ==, ZTEST_DIROBJ);
2369 ASSERT3U(bt->bt_offset, ==, -1ULL);
2370 ASSERT3U(bt->bt_txg, <, spa_first_txg(za->za_spa));
2372 dmu_buf_rele(db, FTAG);
2377 ztest_dmu_write_parallel(ztest_args_t *za)
2379 objset_t *os = za->za_os;
2380 ztest_block_tag_t *rbt = &za->za_rbt;
2381 ztest_block_tag_t *wbt = &za->za_wbt;
2382 const size_t btsize = sizeof (ztest_block_tag_t);
2385 int bs = ZTEST_DIROBJ_BLOCKSIZE;
2387 uint64_t off, txg, txg_how;
2389 char osname[MAXNAMELEN];
2390 char iobuf[SPA_MAXBLOCKSIZE];
2391 blkptr_t blk = { 0 };
2394 dmu_tx_t *tx = dmu_tx_create(os);
2395 dmu_buf_t *bonus_db;
2396 arc_buf_t *abuf = NULL;
2398 dmu_objset_name(os, osname);
2401 * Have multiple threads write to large offsets in ZTEST_DIROBJ
2402 * to verify that having multiple threads writing to the same object
2403 * in parallel doesn't cause any trouble.
2405 if (ztest_random(4) == 0) {
2407 * Do the bonus buffer instead of a regular block.
2408 * We need a lock to serialize resize vs. others,
2409 * so we hash on the objset ID.
2411 b = dmu_objset_id(os) % ZTEST_SYNC_LOCKS;
2413 dmu_tx_hold_bonus(tx, ZTEST_DIROBJ);
2415 b = ztest_random(ZTEST_SYNC_LOCKS);
2416 off = za->za_diroff_shared + (b << SPA_MAXBLOCKSHIFT);
2417 if (ztest_random(4) == 0) {
2419 dmu_tx_hold_free(tx, ZTEST_DIROBJ, off, bs);
2421 dmu_tx_hold_write(tx, ZTEST_DIROBJ, off, bs);
2425 if (off != -1ULL && P2PHASE(off, bs) == 0 && !do_free &&
2426 ztest_random(8) == 0) {
2427 VERIFY(dmu_bonus_hold(os, ZTEST_DIROBJ, FTAG, &bonus_db) == 0);
2428 abuf = dmu_request_arcbuf(bonus_db, bs);
2431 txg_how = ztest_random(2) == 0 ? TXG_WAIT : TXG_NOWAIT;
2432 error = dmu_tx_assign(tx, txg_how);
2434 if (error == ERESTART) {
2435 ASSERT(txg_how == TXG_NOWAIT);
2438 ztest_record_enospc("dmu write parallel");
2442 dmu_return_arcbuf(abuf);
2443 dmu_buf_rele(bonus_db, FTAG);
2447 txg = dmu_tx_get_txg(tx);
2449 lp = &ztest_shared->zs_sync_lock[b];
2450 (void) mutex_lock(lp);
2452 wbt->bt_objset = dmu_objset_id(os);
2453 wbt->bt_object = ZTEST_DIROBJ;
2454 wbt->bt_offset = off;
2456 wbt->bt_thread = za->za_instance;
2457 wbt->bt_seq = ztest_shared->zs_seq[b]++; /* protected by lp */
2460 * Occasionally, write an all-zero block to test the behavior
2461 * of blocks that compress into holes.
2463 if (off != -1ULL && ztest_random(8) == 0)
2467 dmu_object_info_t *doi = &za->za_doi;
2470 VERIFY(dmu_bonus_hold(os, ZTEST_DIROBJ, FTAG, &db) == 0);
2472 dmu_object_info_from_db(db, doi);
2473 ASSERT3U(doi->doi_bonus_size, <=, db->db_size);
2474 ASSERT3U(doi->doi_bonus_size, >=, btsize);
2475 ASSERT3U(doi->doi_bonus_size % btsize, ==, 0);
2476 dboff = (char *)db->db_data + doi->doi_bonus_size - btsize;
2477 bcopy(dboff, rbt, btsize);
2478 if (rbt->bt_objset != 0) {
2479 ASSERT3U(rbt->bt_objset, ==, wbt->bt_objset);
2480 ASSERT3U(rbt->bt_object, ==, wbt->bt_object);
2481 ASSERT3U(rbt->bt_offset, ==, wbt->bt_offset);
2482 ASSERT3U(rbt->bt_txg, <=, wbt->bt_txg);
2484 if (ztest_random(10) == 0) {
2485 int newsize = (ztest_random(db->db_size /
2486 btsize) + 1) * btsize;
2488 ASSERT3U(newsize, >=, btsize);
2489 ASSERT3U(newsize, <=, db->db_size);
2490 VERIFY3U(dmu_set_bonus(db, newsize, tx), ==, 0);
2491 dboff = (char *)db->db_data + newsize - btsize;
2493 dmu_buf_will_dirty(db, tx);
2494 bcopy(wbt, dboff, btsize);
2495 dmu_buf_rele(db, FTAG);
2497 } else if (do_free) {
2498 VERIFY(dmu_free_range(os, ZTEST_DIROBJ, off, bs, tx) == 0);
2499 } else if (abuf == NULL) {
2500 dmu_write(os, ZTEST_DIROBJ, off, btsize, wbt, tx);
2502 bcopy(wbt, abuf->b_data, btsize);
2503 dmu_assign_arcbuf(bonus_db, off, abuf, tx);
2504 dmu_buf_rele(bonus_db, FTAG);
2507 (void) mutex_unlock(lp);
2509 if (ztest_random(1000) == 0)
2510 (void) poll(NULL, 0, 1); /* open dn_notxholds window */
2514 if (ztest_random(10000) == 0)
2515 txg_wait_synced(dmu_objset_pool(os), txg);
2517 if (off == -1ULL || do_free)
2520 if (ztest_random(2) != 0)
2524 * dmu_sync() the block we just wrote.
2526 (void) mutex_lock(lp);
2528 blkoff = P2ALIGN_TYPED(off, bs, uint64_t);
2529 error = dmu_buf_hold(os, ZTEST_DIROBJ, blkoff, FTAG, &db);
2532 (void) mutex_unlock(lp);
2535 blkoff = off - blkoff;
2536 error = dmu_sync(NULL, db, &blk, txg, NULL, NULL);
2537 dmu_buf_rele(db, FTAG);
2541 (void) mutex_unlock(lp);
2545 if (blk.blk_birth == 0) { /* concurrent free */
2546 (void) mutex_unlock(lp);
2550 txg_suspend(dmu_objset_pool(os));
2552 (void) mutex_unlock(lp);
2554 ASSERT(blk.blk_fill == 1);
2555 ASSERT3U(BP_GET_TYPE(&blk), ==, DMU_OT_UINT64_OTHER);
2556 ASSERT3U(BP_GET_LEVEL(&blk), ==, 0);
2557 ASSERT3U(BP_GET_LSIZE(&blk), ==, bs);
2560 * Read the block that dmu_sync() returned to make sure its contents
2561 * match what we wrote. We do this while still txg_suspend()ed
2562 * to ensure that the block can't be reused before we read it.
2564 zb.zb_objset = dmu_objset_id(os);
2565 zb.zb_object = ZTEST_DIROBJ;
2567 zb.zb_blkid = off / bs;
2568 error = zio_wait(zio_read(NULL, za->za_spa, &blk, iobuf, bs,
2569 NULL, NULL, ZIO_PRIORITY_SYNC_READ, ZIO_FLAG_MUSTSUCCEED, &zb));
2570 ASSERT3U(error, ==, 0);
2572 txg_resume(dmu_objset_pool(os));
2574 bcopy(&iobuf[blkoff], rbt, btsize);
2576 if (rbt->bt_objset == 0) /* concurrent free */
2579 if (wbt->bt_objset == 0) /* all-zero overwrite */
2582 ASSERT3U(rbt->bt_objset, ==, wbt->bt_objset);
2583 ASSERT3U(rbt->bt_object, ==, wbt->bt_object);
2584 ASSERT3U(rbt->bt_offset, ==, wbt->bt_offset);
2587 * The semantic of dmu_sync() is that we always push the most recent
2588 * version of the data, so in the face of concurrent updates we may
2589 * see a newer version of the block. That's OK.
2591 ASSERT3U(rbt->bt_txg, >=, wbt->bt_txg);
2592 if (rbt->bt_thread == wbt->bt_thread)
2593 ASSERT3U(rbt->bt_seq, ==, wbt->bt_seq);
2595 ASSERT3U(rbt->bt_seq, >, wbt->bt_seq);
2599 * Verify that zap_{create,destroy,add,remove,update} work as expected.
2601 #define ZTEST_ZAP_MIN_INTS 1
2602 #define ZTEST_ZAP_MAX_INTS 4
2603 #define ZTEST_ZAP_MAX_PROPS 1000
2606 ztest_zap(ztest_args_t *za)
2608 objset_t *os = za->za_os;
2610 uint64_t txg, last_txg;
2611 uint64_t value[ZTEST_ZAP_MAX_INTS];
2612 uint64_t zl_ints, zl_intsize, prop;
2615 char propname[100], txgname[100];
2617 char osname[MAXNAMELEN];
2618 char *hc[2] = { "s.acl.h", ".s.open.h.hyLZlg" };
2620 dmu_objset_name(os, osname);
2623 * Create a new object if necessary, and record it in the directory.
2625 VERIFY(0 == dmu_read(os, ZTEST_DIROBJ, za->za_diroff,
2626 sizeof (uint64_t), &object, DMU_READ_PREFETCH));
2629 tx = dmu_tx_create(os);
2630 dmu_tx_hold_write(tx, ZTEST_DIROBJ, za->za_diroff,
2632 dmu_tx_hold_zap(tx, DMU_NEW_OBJECT, TRUE, NULL);
2633 error = dmu_tx_assign(tx, TXG_WAIT);
2635 ztest_record_enospc("create zap test obj");
2639 object = zap_create(os, DMU_OT_ZAP_OTHER, DMU_OT_NONE, 0, tx);
2641 fatal(0, "zap_create('%s', %llu) = %d",
2642 osname, object, error);
2644 ASSERT(object != 0);
2645 dmu_write(os, ZTEST_DIROBJ, za->za_diroff,
2646 sizeof (uint64_t), &object, tx);
2648 * Generate a known hash collision, and verify that
2649 * we can lookup and remove both entries.
2651 for (i = 0; i < 2; i++) {
2653 error = zap_add(os, object, hc[i], sizeof (uint64_t),
2655 ASSERT3U(error, ==, 0);
2657 for (i = 0; i < 2; i++) {
2658 error = zap_add(os, object, hc[i], sizeof (uint64_t),
2660 ASSERT3U(error, ==, EEXIST);
2661 error = zap_length(os, object, hc[i],
2662 &zl_intsize, &zl_ints);
2663 ASSERT3U(error, ==, 0);
2664 ASSERT3U(zl_intsize, ==, sizeof (uint64_t));
2665 ASSERT3U(zl_ints, ==, 1);
2667 for (i = 0; i < 2; i++) {
2668 error = zap_remove(os, object, hc[i], tx);
2669 ASSERT3U(error, ==, 0);
2675 ints = MAX(ZTEST_ZAP_MIN_INTS, object % ZTEST_ZAP_MAX_INTS);
2677 prop = ztest_random(ZTEST_ZAP_MAX_PROPS);
2678 (void) sprintf(propname, "prop_%llu", (u_longlong_t)prop);
2679 (void) sprintf(txgname, "txg_%llu", (u_longlong_t)prop);
2680 bzero(value, sizeof (value));
2684 * If these zap entries already exist, validate their contents.
2686 error = zap_length(os, object, txgname, &zl_intsize, &zl_ints);
2688 ASSERT3U(zl_intsize, ==, sizeof (uint64_t));
2689 ASSERT3U(zl_ints, ==, 1);
2691 VERIFY(zap_lookup(os, object, txgname, zl_intsize,
2692 zl_ints, &last_txg) == 0);
2694 VERIFY(zap_length(os, object, propname, &zl_intsize,
2697 ASSERT3U(zl_intsize, ==, sizeof (uint64_t));
2698 ASSERT3U(zl_ints, ==, ints);
2700 VERIFY(zap_lookup(os, object, propname, zl_intsize,
2701 zl_ints, value) == 0);
2703 for (i = 0; i < ints; i++) {
2704 ASSERT3U(value[i], ==, last_txg + object + i);
2707 ASSERT3U(error, ==, ENOENT);
2711 * Atomically update two entries in our zap object.
2712 * The first is named txg_%llu, and contains the txg
2713 * in which the property was last updated. The second
2714 * is named prop_%llu, and the nth element of its value
2715 * should be txg + object + n.
2717 tx = dmu_tx_create(os);
2718 dmu_tx_hold_zap(tx, object, TRUE, NULL);
2719 error = dmu_tx_assign(tx, TXG_WAIT);
2721 ztest_record_enospc("create zap entry");
2725 txg = dmu_tx_get_txg(tx);
2728 fatal(0, "zap future leak: old %llu new %llu", last_txg, txg);
2730 for (i = 0; i < ints; i++)
2731 value[i] = txg + object + i;
2733 error = zap_update(os, object, txgname, sizeof (uint64_t), 1, &txg, tx);
2735 fatal(0, "zap_update('%s', %llu, '%s') = %d",
2736 osname, object, txgname, error);
2738 error = zap_update(os, object, propname, sizeof (uint64_t),
2741 fatal(0, "zap_update('%s', %llu, '%s') = %d",
2742 osname, object, propname, error);
2747 * Remove a random pair of entries.
2749 prop = ztest_random(ZTEST_ZAP_MAX_PROPS);
2750 (void) sprintf(propname, "prop_%llu", (u_longlong_t)prop);
2751 (void) sprintf(txgname, "txg_%llu", (u_longlong_t)prop);
2753 error = zap_length(os, object, txgname, &zl_intsize, &zl_ints);
2755 if (error == ENOENT)
2758 ASSERT3U(error, ==, 0);
2760 tx = dmu_tx_create(os);
2761 dmu_tx_hold_zap(tx, object, TRUE, NULL);
2762 error = dmu_tx_assign(tx, TXG_WAIT);
2764 ztest_record_enospc("remove zap entry");
2768 error = zap_remove(os, object, txgname, tx);
2770 fatal(0, "zap_remove('%s', %llu, '%s') = %d",
2771 osname, object, txgname, error);
2773 error = zap_remove(os, object, propname, tx);
2775 fatal(0, "zap_remove('%s', %llu, '%s') = %d",
2776 osname, object, propname, error);
2781 * Once in a while, destroy the object.
2783 if (ztest_random(1000) != 0)
2786 tx = dmu_tx_create(os);
2787 dmu_tx_hold_write(tx, ZTEST_DIROBJ, za->za_diroff, sizeof (uint64_t));
2788 dmu_tx_hold_free(tx, object, 0, DMU_OBJECT_END);
2789 error = dmu_tx_assign(tx, TXG_WAIT);
2791 ztest_record_enospc("destroy zap object");
2795 error = zap_destroy(os, object, tx);
2797 fatal(0, "zap_destroy('%s', %llu) = %d",
2798 osname, object, error);
2800 dmu_write(os, ZTEST_DIROBJ, za->za_diroff, sizeof (uint64_t),
2806 * Testcase to test the upgrading of a microzap to fatzap.
2809 ztest_fzap(ztest_args_t *za)
2811 objset_t *os = za->za_os;
2816 char osname[MAXNAMELEN];
2818 char entname[MAXNAMELEN];
2820 dmu_objset_name(os, osname);
2823 * Create a new object if necessary, and record it in the directory.
2825 VERIFY(0 == dmu_read(os, ZTEST_DIROBJ, za->za_diroff,
2826 sizeof (uint64_t), &object, DMU_READ_PREFETCH));
2829 tx = dmu_tx_create(os);
2830 dmu_tx_hold_write(tx, ZTEST_DIROBJ, za->za_diroff,
2832 dmu_tx_hold_zap(tx, DMU_NEW_OBJECT, TRUE, NULL);
2833 error = dmu_tx_assign(tx, TXG_WAIT);
2835 ztest_record_enospc("create zap test obj");
2839 object = zap_create(os, DMU_OT_ZAP_OTHER, DMU_OT_NONE, 0, tx);
2841 fatal(0, "zap_create('%s', %llu) = %d",
2842 osname, object, error);
2844 ASSERT(object != 0);
2845 dmu_write(os, ZTEST_DIROBJ, za->za_diroff,
2846 sizeof (uint64_t), &object, tx);
2851 * Add entries to this ZAP amd make sure it spills over
2852 * and gets upgraded to a fatzap. Also, since we are adding
2853 * 2050 entries we should see ptrtbl growth and leaf-block
2856 for (i = 0; i < 2050; i++) {
2857 (void) snprintf(entname, sizeof (entname), "%s-%d", name, i);
2860 tx = dmu_tx_create(os);
2861 dmu_tx_hold_zap(tx, object, TRUE, entname);
2862 error = dmu_tx_assign(tx, TXG_WAIT);
2865 ztest_record_enospc("create zap entry");
2869 error = zap_add(os, object, entname, sizeof (uint64_t),
2872 ASSERT(error == 0 || error == EEXIST);
2877 * Once in a while, destroy the object.
2879 if (ztest_random(1000) != 0)
2882 tx = dmu_tx_create(os);
2883 dmu_tx_hold_write(tx, ZTEST_DIROBJ, za->za_diroff, sizeof (uint64_t));
2884 dmu_tx_hold_free(tx, object, 0, DMU_OBJECT_END);
2885 error = dmu_tx_assign(tx, TXG_WAIT);
2887 ztest_record_enospc("destroy zap object");
2891 error = zap_destroy(os, object, tx);
2893 fatal(0, "zap_destroy('%s', %llu) = %d",
2894 osname, object, error);
2896 dmu_write(os, ZTEST_DIROBJ, za->za_diroff, sizeof (uint64_t),
2902 ztest_zap_parallel(ztest_args_t *za)
2904 objset_t *os = za->za_os;
2905 uint64_t txg, object, count, wsize, wc, zl_wsize, zl_wc;
2907 int i, namelen, error;
2908 char name[20], string_value[20];
2912 * Generate a random name of the form 'xxx.....' where each
2913 * x is a random printable character and the dots are dots.
2914 * There are 94 such characters, and the name length goes from
2915 * 6 to 20, so there are 94^3 * 15 = 12,458,760 possible names.
2917 namelen = ztest_random(sizeof (name) - 5) + 5 + 1;
2919 for (i = 0; i < 3; i++)
2920 name[i] = '!' + ztest_random('~' - '!' + 1);
2921 for (; i < namelen - 1; i++)
2925 if (ztest_random(2) == 0)
2926 object = ZTEST_MICROZAP_OBJ;
2928 object = ZTEST_FATZAP_OBJ;
2930 if ((namelen & 1) || object == ZTEST_MICROZAP_OBJ) {
2931 wsize = sizeof (txg);
2937 data = string_value;
2941 VERIFY(zap_count(os, object, &count) == 0);
2942 ASSERT(count != -1ULL);
2945 * Select an operation: length, lookup, add, update, remove.
2947 i = ztest_random(5);
2950 tx = dmu_tx_create(os);
2951 dmu_tx_hold_zap(tx, object, TRUE, NULL);
2952 error = dmu_tx_assign(tx, TXG_WAIT);
2954 ztest_record_enospc("zap parallel");
2958 txg = dmu_tx_get_txg(tx);
2959 bcopy(name, string_value, namelen);
2963 bzero(string_value, namelen);
2969 error = zap_length(os, object, name, &zl_wsize, &zl_wc);
2971 ASSERT3U(wsize, ==, zl_wsize);
2972 ASSERT3U(wc, ==, zl_wc);
2974 ASSERT3U(error, ==, ENOENT);
2979 error = zap_lookup(os, object, name, wsize, wc, data);
2981 if (data == string_value &&
2982 bcmp(name, data, namelen) != 0)
2983 fatal(0, "name '%s' != val '%s' len %d",
2984 name, data, namelen);
2986 ASSERT3U(error, ==, ENOENT);
2991 error = zap_add(os, object, name, wsize, wc, data, tx);
2992 ASSERT(error == 0 || error == EEXIST);
2996 VERIFY(zap_update(os, object, name, wsize, wc, data, tx) == 0);
3000 error = zap_remove(os, object, name, tx);
3001 ASSERT(error == 0 || error == ENOENT);
3010 ztest_dsl_prop_get_set(ztest_args_t *za)
3012 objset_t *os = za->za_os;
3015 const char *prop, *valname;
3016 char setpoint[MAXPATHLEN];
3017 char osname[MAXNAMELEN];
3020 (void) rw_rdlock(&ztest_shared->zs_name_lock);
3022 dmu_objset_name(os, osname);
3024 for (i = 0; i < 2; i++) {
3027 value = ztest_random_checksum();
3028 inherit = (value == ZIO_CHECKSUM_INHERIT);
3030 prop = "compression";
3031 value = ztest_random_compress();
3032 inherit = (value == ZIO_COMPRESS_INHERIT);
3035 error = dsl_prop_set(osname, prop, sizeof (value),
3038 if (error == ENOSPC) {
3039 ztest_record_enospc("dsl_prop_set");
3043 ASSERT3U(error, ==, 0);
3045 VERIFY3U(dsl_prop_get(osname, prop, sizeof (value),
3046 1, &value, setpoint), ==, 0);
3049 valname = zio_checksum_table[value].ci_name;
3051 valname = zio_compress_table[value].ci_name;
3053 if (zopt_verbose >= 6) {
3054 (void) printf("%s %s = %s for '%s'\n",
3055 osname, prop, valname, setpoint);
3059 (void) rw_unlock(&ztest_shared->zs_name_lock);
3063 * Inject random faults into the on-disk data.
3066 ztest_fault_inject(ztest_args_t *za)
3070 uint64_t leaves = MAX(zopt_mirrors, 1) * zopt_raidz;
3071 uint64_t bad = 0x1990c0ffeedecadeULL;
3073 char path0[MAXPATHLEN];
3074 char pathrand[MAXPATHLEN];
3076 spa_t *spa = za->za_spa;
3077 int bshift = SPA_MAXBLOCKSHIFT + 2; /* don't scrog all labels */
3079 int maxfaults = zopt_maxfaults;
3083 ASSERT(leaves >= 1);
3086 * We need SCL_STATE here because we're going to look at vd0->vdev_tsd.
3088 spa_config_enter(spa, SCL_STATE, FTAG, RW_READER);
3090 if (ztest_random(2) == 0) {
3092 * Inject errors on a normal data device.
3094 top = ztest_random(spa->spa_root_vdev->vdev_children);
3095 leaf = ztest_random(leaves);
3098 * Generate paths to the first leaf in this top-level vdev,
3099 * and to the random leaf we selected. We'll induce transient
3100 * write failures and random online/offline activity on leaf 0,
3101 * and we'll write random garbage to the randomly chosen leaf.
3103 (void) snprintf(path0, sizeof (path0), ztest_dev_template,
3104 zopt_dir, zopt_pool, top * leaves + 0);
3105 (void) snprintf(pathrand, sizeof (pathrand), ztest_dev_template,
3106 zopt_dir, zopt_pool, top * leaves + leaf);
3108 vd0 = vdev_lookup_by_path(spa->spa_root_vdev, path0);
3109 if (vd0 != NULL && maxfaults != 1) {
3111 * Make vd0 explicitly claim to be unreadable,
3112 * or unwriteable, or reach behind its back
3113 * and close the underlying fd. We can do this if
3114 * maxfaults == 0 because we'll fail and reexecute,
3115 * and we can do it if maxfaults >= 2 because we'll
3116 * have enough redundancy. If maxfaults == 1, the
3117 * combination of this with injection of random data
3118 * corruption below exceeds the pool's fault tolerance.
3120 vdev_file_t *vf = vd0->vdev_tsd;
3122 if (vf != NULL && ztest_random(3) == 0) {
3123 (void) close(vf->vf_vnode->v_fd);
3124 vf->vf_vnode->v_fd = -1;
3125 } else if (ztest_random(2) == 0) {
3126 vd0->vdev_cant_read = B_TRUE;
3128 vd0->vdev_cant_write = B_TRUE;
3130 guid0 = vd0->vdev_guid;
3134 * Inject errors on an l2cache device.
3136 spa_aux_vdev_t *sav = &spa->spa_l2cache;
3138 if (sav->sav_count == 0) {
3139 spa_config_exit(spa, SCL_STATE, FTAG);
3142 vd0 = sav->sav_vdevs[ztest_random(sav->sav_count)];
3143 guid0 = vd0->vdev_guid;
3144 (void) strcpy(path0, vd0->vdev_path);
3145 (void) strcpy(pathrand, vd0->vdev_path);
3149 maxfaults = INT_MAX; /* no limit on cache devices */
3152 spa_config_exit(spa, SCL_STATE, FTAG);
3158 * If we can tolerate two or more faults, randomly online/offline vd0.
3160 if (maxfaults >= 2 && guid0 != 0) {
3161 if (ztest_random(10) < 6) {
3162 int flags = (ztest_random(2) == 0 ?
3163 ZFS_OFFLINE_TEMPORARY : 0);
3164 VERIFY(vdev_offline(spa, guid0, flags) != EBUSY);
3166 (void) vdev_online(spa, guid0, 0, NULL);
3171 * We have at least single-fault tolerance, so inject data corruption.
3173 fd = open(pathrand, O_RDWR);
3175 if (fd == -1) /* we hit a gap in the device namespace */
3178 fsize = lseek(fd, 0, SEEK_END);
3180 while (--iters != 0) {
3181 offset = ztest_random(fsize / (leaves << bshift)) *
3182 (leaves << bshift) + (leaf << bshift) +
3183 (ztest_random(1ULL << (bshift - 1)) & -8ULL);
3185 if (offset >= fsize)
3188 if (zopt_verbose >= 6)
3189 (void) printf("injecting bad word into %s,"
3190 " offset 0x%llx\n", pathrand, (u_longlong_t)offset);
3192 if (pwrite(fd, &bad, sizeof (bad), offset) != sizeof (bad))
3193 fatal(1, "can't inject bad word at 0x%llx in %s",
3204 ztest_scrub(ztest_args_t *za)
3206 spa_t *spa = za->za_spa;
3208 (void) spa_scrub(spa, POOL_SCRUB_EVERYTHING);
3209 (void) poll(NULL, 0, 1000); /* wait a second, then force a restart */
3210 (void) spa_scrub(spa, POOL_SCRUB_EVERYTHING);
3214 * Rename the pool to a different name and then rename it back.
3217 ztest_spa_rename(ztest_args_t *za)
3219 char *oldname, *newname;
3223 (void) rw_wrlock(&ztest_shared->zs_name_lock);
3225 oldname = za->za_pool;
3226 newname = umem_alloc(strlen(oldname) + 5, UMEM_NOFAIL);
3227 (void) strcpy(newname, oldname);
3228 (void) strcat(newname, "_tmp");
3233 error = spa_rename(oldname, newname);
3235 fatal(0, "spa_rename('%s', '%s') = %d", oldname,
3239 * Try to open it under the old name, which shouldn't exist
3241 error = spa_open(oldname, &spa, FTAG);
3242 if (error != ENOENT)
3243 fatal(0, "spa_open('%s') = %d", oldname, error);
3246 * Open it under the new name and make sure it's still the same spa_t.
3248 error = spa_open(newname, &spa, FTAG);
3250 fatal(0, "spa_open('%s') = %d", newname, error);
3252 ASSERT(spa == za->za_spa);
3253 spa_close(spa, FTAG);
3256 * Rename it back to the original
3258 error = spa_rename(newname, oldname);
3260 fatal(0, "spa_rename('%s', '%s') = %d", newname,
3264 * Make sure it can still be opened
3266 error = spa_open(oldname, &spa, FTAG);
3268 fatal(0, "spa_open('%s') = %d", oldname, error);
3270 ASSERT(spa == za->za_spa);
3271 spa_close(spa, FTAG);
3273 umem_free(newname, strlen(newname) + 1);
3275 (void) rw_unlock(&ztest_shared->zs_name_lock);
3280 * Completely obliterate one disk.
3283 ztest_obliterate_one_disk(uint64_t vdev)
3286 char dev_name[MAXPATHLEN], copy_name[MAXPATHLEN];
3289 if (zopt_maxfaults < 2)
3292 (void) sprintf(dev_name, ztest_dev_template, zopt_dir, zopt_pool, vdev);
3293 (void) snprintf(copy_name, MAXPATHLEN, "%s.old", dev_name);
3295 fd = open(dev_name, O_RDWR);
3298 fatal(1, "can't open %s", dev_name);
3301 * Determine the size.
3303 fsize = lseek(fd, 0, SEEK_END);
3308 * Rename the old device to dev_name.old (useful for debugging).
3310 VERIFY(rename(dev_name, copy_name) == 0);
3315 VERIFY((fd = open(dev_name, O_RDWR | O_CREAT | O_TRUNC, 0666)) >= 0);
3316 VERIFY(ftruncate(fd, fsize) == 0);
3321 ztest_replace_one_disk(spa_t *spa, uint64_t vdev)
3323 char dev_name[MAXPATHLEN];
3329 (void) sprintf(dev_name, ztest_dev_template, zopt_dir, zopt_pool, vdev);
3332 * Build the nvlist describing dev_name.
3334 root = make_vdev_root(dev_name, NULL, 0, 0, 0, 0, 0, 1);
3336 spa_config_enter(spa, SCL_VDEV, FTAG, RW_READER);
3337 if ((vd = vdev_lookup_by_path(spa->spa_root_vdev, dev_name)) == NULL)
3340 guid = vd->vdev_guid;
3341 spa_config_exit(spa, SCL_VDEV, FTAG);
3342 error = spa_vdev_attach(spa, guid, root, B_TRUE);
3348 fatal(0, "spa_vdev_attach(in-place) = %d", error);
3354 ztest_verify_blocks(char *pool)
3357 char zdb[MAXPATHLEN + MAXNAMELEN + 20];
3365 if (realpath(progname, zdb) == NULL)
3366 assert(!"realpath() failed");
3368 /* zdb lives in /usr/sbin, while ztest lives in /usr/bin */
3369 bin = strstr(zdb, "/usr/bin/");
3370 ztest = strstr(bin, "/ztest");
3372 isalen = ztest - isa;
3376 "/usr/sbin%.*s/zdb -bcc%s%s -U /tmp/zpool.cache %s",
3379 zopt_verbose >= 3 ? "s" : "",
3380 zopt_verbose >= 4 ? "v" : "",
3384 if (zopt_verbose >= 5)
3385 (void) printf("Executing %s\n", strstr(zdb, "zdb "));
3387 fp = popen(zdb, "r");
3390 while (fgets(zbuf, sizeof (zbuf), fp) != NULL)
3391 if (zopt_verbose >= 3)
3392 (void) printf("%s", zbuf);
3394 status = pclose(fp);
3399 ztest_dump_core = 0;
3400 if (WIFEXITED(status))
3401 fatal(0, "'%s' exit code %d", zdb, WEXITSTATUS(status));
3403 fatal(0, "'%s' died with signal %d", zdb, WTERMSIG(status));
3407 ztest_walk_pool_directory(char *header)
3411 if (zopt_verbose >= 6)
3412 (void) printf("%s\n", header);
3414 mutex_enter(&spa_namespace_lock);
3415 while ((spa = spa_next(spa)) != NULL)
3416 if (zopt_verbose >= 6)
3417 (void) printf("\t%s\n", spa_name(spa));
3418 mutex_exit(&spa_namespace_lock);
3422 ztest_spa_import_export(char *oldname, char *newname)
3424 nvlist_t *config, *newconfig;
3429 if (zopt_verbose >= 4) {
3430 (void) printf("import/export: old = %s, new = %s\n",
3435 * Clean up from previous runs.
3437 (void) spa_destroy(newname);
3440 * Get the pool's configuration and guid.
3442 error = spa_open(oldname, &spa, FTAG);
3444 fatal(0, "spa_open('%s') = %d", oldname, error);
3447 * Kick off a scrub to tickle scrub/export races.
3449 if (ztest_random(2) == 0)
3450 (void) spa_scrub(spa, POOL_SCRUB_EVERYTHING);
3452 pool_guid = spa_guid(spa);
3453 spa_close(spa, FTAG);
3455 ztest_walk_pool_directory("pools before export");
3460 error = spa_export(oldname, &config, B_FALSE, B_FALSE);
3462 fatal(0, "spa_export('%s') = %d", oldname, error);
3464 ztest_walk_pool_directory("pools after export");
3469 newconfig = spa_tryimport(config);
3470 ASSERT(newconfig != NULL);
3471 nvlist_free(newconfig);
3474 * Import it under the new name.
3476 error = spa_import(newname, config, NULL);
3478 fatal(0, "spa_import('%s') = %d", newname, error);
3480 ztest_walk_pool_directory("pools after import");
3483 * Try to import it again -- should fail with EEXIST.
3485 error = spa_import(newname, config, NULL);
3486 if (error != EEXIST)
3487 fatal(0, "spa_import('%s') twice", newname);
3490 * Try to import it under a different name -- should fail with EEXIST.
3492 error = spa_import(oldname, config, NULL);
3493 if (error != EEXIST)
3494 fatal(0, "spa_import('%s') under multiple names", newname);
3497 * Verify that the pool is no longer visible under the old name.
3499 error = spa_open(oldname, &spa, FTAG);
3500 if (error != ENOENT)
3501 fatal(0, "spa_open('%s') = %d", newname, error);
3504 * Verify that we can open and close the pool using the new name.
3506 error = spa_open(newname, &spa, FTAG);
3508 fatal(0, "spa_open('%s') = %d", newname, error);
3509 ASSERT(pool_guid == spa_guid(spa));
3510 spa_close(spa, FTAG);
3512 nvlist_free(config);
3516 ztest_resume(spa_t *spa)
3518 if (spa_suspended(spa)) {
3519 spa_vdev_state_enter(spa);
3520 vdev_clear(spa, NULL);
3521 (void) spa_vdev_state_exit(spa, NULL, 0);
3522 (void) zio_resume(spa);
3527 ztest_resume_thread(void *arg)
3531 while (!ztest_exiting) {
3532 (void) poll(NULL, 0, 1000);
3539 ztest_thread(void *arg)
3541 ztest_args_t *za = arg;
3542 ztest_shared_t *zs = ztest_shared;
3543 hrtime_t now, functime;
3547 while ((now = gethrtime()) < za->za_stop) {
3549 * See if it's time to force a crash.
3551 if (now > za->za_kill) {
3552 zs->zs_alloc = spa_get_alloc(za->za_spa);
3553 zs->zs_space = spa_get_space(za->za_spa);
3554 (void) kill(getpid(), SIGKILL);
3558 * Pick a random function.
3560 f = ztest_random(ZTEST_FUNCS);
3561 zi = &zs->zs_info[f];
3564 * Decide whether to call it, based on the requested frequency.
3566 if (zi->zi_call_target == 0 ||
3567 (double)zi->zi_call_total / zi->zi_call_target >
3568 (double)(now - zs->zs_start_time) / (zopt_time * NANOSEC))
3571 atomic_add_64(&zi->zi_calls, 1);
3572 atomic_add_64(&zi->zi_call_total, 1);
3574 za->za_diroff = (za->za_instance * ZTEST_FUNCS + f) *
3576 za->za_diroff_shared = (1ULL << 63);
3578 for (i = 0; i < zi->zi_iters; i++)
3581 functime = gethrtime() - now;
3583 atomic_add_64(&zi->zi_call_time, functime);
3585 if (zopt_verbose >= 4) {
3587 (void) dladdr((void *)zi->zi_func, &dli);
3588 (void) printf("%6.2f sec in %s\n",
3589 (double)functime / NANOSEC, dli.dli_sname);
3593 * If we're getting ENOSPC with some regularity, stop.
3595 if (zs->zs_enospc_count > 10)
3603 * Kick off threads to run tests on all datasets in parallel.
3606 ztest_run(char *pool)
3609 ztest_shared_t *zs = ztest_shared;
3613 thread_t resume_tid;
3615 ztest_exiting = B_FALSE;
3617 (void) _mutex_init(&zs->zs_vdev_lock, USYNC_THREAD, NULL);
3618 (void) rwlock_init(&zs->zs_name_lock, USYNC_THREAD, NULL);
3620 for (t = 0; t < ZTEST_SYNC_LOCKS; t++)
3621 (void) _mutex_init(&zs->zs_sync_lock[t], USYNC_THREAD, NULL);
3624 * Destroy one disk before we even start.
3625 * It's mirrored, so everything should work just fine.
3626 * This makes us exercise fault handling very early in spa_load().
3628 ztest_obliterate_one_disk(0);
3631 * Verify that the sum of the sizes of all blocks in the pool
3632 * equals the SPA's allocated space total.
3634 ztest_verify_blocks(pool);
3637 * Kick off a replacement of the disk we just obliterated.
3639 kernel_init(FREAD | FWRITE);
3640 VERIFY(spa_open(pool, &spa, FTAG) == 0);
3641 ztest_replace_one_disk(spa, 0);
3642 if (zopt_verbose >= 5)
3643 show_pool_stats(spa);
3644 spa_close(spa, FTAG);
3647 kernel_init(FREAD | FWRITE);
3650 * Verify that we can export the pool and reimport it under a
3653 if (ztest_random(2) == 0) {
3654 (void) snprintf(name, 100, "%s_import", pool);
3655 ztest_spa_import_export(pool, name);
3656 ztest_spa_import_export(name, pool);
3660 * Verify that we can loop over all pools.
3662 mutex_enter(&spa_namespace_lock);
3663 for (spa = spa_next(NULL); spa != NULL; spa = spa_next(spa)) {
3664 if (zopt_verbose > 3) {
3665 (void) printf("spa_next: found %s\n", spa_name(spa));
3668 mutex_exit(&spa_namespace_lock);
3673 VERIFY(spa_open(pool, &spa, FTAG) == 0);
3676 * We don't expect the pool to suspend unless maxfaults == 0,
3677 * in which case ztest_fault_inject() temporarily takes away
3678 * the only valid replica.
3680 if (zopt_maxfaults == 0)
3681 spa->spa_failmode = ZIO_FAILURE_MODE_WAIT;
3683 spa->spa_failmode = ZIO_FAILURE_MODE_PANIC;
3686 * Create a thread to periodically resume suspended I/O.
3688 VERIFY(thr_create(0, 0, ztest_resume_thread, spa, THR_BOUND,
3692 * Verify that we can safely inquire about about any object,
3693 * whether it's allocated or not. To make it interesting,
3694 * we probe a 5-wide window around each power of two.
3695 * This hits all edge cases, including zero and the max.
3697 for (t = 0; t < 64; t++) {
3698 for (d = -5; d <= 5; d++) {
3699 error = dmu_object_info(spa->spa_meta_objset,
3700 (1ULL << t) + d, NULL);
3701 ASSERT(error == 0 || error == ENOENT ||
3707 * Now kick off all the tests that run in parallel.
3709 zs->zs_enospc_count = 0;
3711 za = umem_zalloc(zopt_threads * sizeof (ztest_args_t), UMEM_NOFAIL);
3713 if (zopt_verbose >= 4)
3714 (void) printf("starting main threads...\n");
3716 za[0].za_start = gethrtime();
3717 za[0].za_stop = za[0].za_start + zopt_passtime * NANOSEC;
3718 za[0].za_stop = MIN(za[0].za_stop, zs->zs_stop_time);
3719 za[0].za_kill = za[0].za_stop;
3720 if (ztest_random(100) < zopt_killrate)
3721 za[0].za_kill -= ztest_random(zopt_passtime * NANOSEC);
3723 for (t = 0; t < zopt_threads; t++) {
3724 d = t % zopt_datasets;
3726 (void) strcpy(za[t].za_pool, pool);
3727 za[t].za_os = za[d].za_os;
3729 za[t].za_zilog = za[d].za_zilog;
3730 za[t].za_instance = t;
3731 za[t].za_random = ztest_random(-1ULL);
3732 za[t].za_start = za[0].za_start;
3733 za[t].za_stop = za[0].za_stop;
3734 za[t].za_kill = za[0].za_kill;
3736 if (t < zopt_datasets) {
3737 int test_future = FALSE;
3738 (void) rw_rdlock(&ztest_shared->zs_name_lock);
3739 (void) snprintf(name, 100, "%s/%s_%d", pool, pool, d);
3740 error = dmu_objset_create(name, DMU_OST_OTHER, NULL, 0,
3741 ztest_create_cb, NULL);
3742 if (error == EEXIST) {
3744 } else if (error == ENOSPC) {
3745 zs->zs_enospc_count++;
3746 (void) rw_unlock(&ztest_shared->zs_name_lock);
3748 } else if (error != 0) {
3749 fatal(0, "dmu_objset_create(%s) = %d",
3752 error = dmu_objset_open(name, DMU_OST_OTHER,
3753 DS_MODE_USER, &za[d].za_os);
3755 fatal(0, "dmu_objset_open('%s') = %d",
3757 (void) rw_unlock(&ztest_shared->zs_name_lock);
3759 ztest_dmu_check_future_leak(&za[t]);
3760 zil_replay(za[d].za_os, za[d].za_os,
3761 ztest_replay_vector);
3762 za[d].za_zilog = zil_open(za[d].za_os, NULL);
3765 VERIFY(thr_create(0, 0, ztest_thread, &za[t], THR_BOUND,
3766 &za[t].za_thread) == 0);
3770 VERIFY(thr_join(za[t].za_thread, NULL, NULL) == 0);
3771 if (t < zopt_datasets) {
3772 zil_close(za[t].za_zilog);
3773 dmu_objset_close(za[t].za_os);
3777 if (zopt_verbose >= 3)
3778 show_pool_stats(spa);
3780 txg_wait_synced(spa_get_dsl(spa), 0);
3782 zs->zs_alloc = spa_get_alloc(spa);
3783 zs->zs_space = spa_get_space(spa);
3786 * If we had out-of-space errors, destroy a random objset.
3788 if (zs->zs_enospc_count != 0) {
3789 (void) rw_rdlock(&ztest_shared->zs_name_lock);
3790 d = (int)ztest_random(zopt_datasets);
3791 (void) snprintf(name, 100, "%s/%s_%d", pool, pool, d);
3792 if (zopt_verbose >= 3)
3793 (void) printf("Destroying %s to free up space\n", name);
3794 (void) dmu_objset_find(name, ztest_destroy_cb, &za[d],
3795 DS_FIND_SNAPSHOTS | DS_FIND_CHILDREN);
3796 (void) rw_unlock(&ztest_shared->zs_name_lock);
3799 txg_wait_synced(spa_get_dsl(spa), 0);
3801 umem_free(za, zopt_threads * sizeof (ztest_args_t));
3803 /* Kill the resume thread */
3804 ztest_exiting = B_TRUE;
3805 VERIFY(thr_join(resume_tid, NULL, NULL) == 0);
3809 * Right before closing the pool, kick off a bunch of async I/O;
3810 * spa_close() should wait for it to complete.
3812 for (t = 1; t < 50; t++)
3813 dmu_prefetch(spa->spa_meta_objset, t, 0, 1 << 15);
3815 spa_close(spa, FTAG);
3821 print_time(hrtime_t t, char *timebuf)
3823 hrtime_t s = t / NANOSEC;
3824 hrtime_t m = s / 60;
3825 hrtime_t h = m / 60;
3826 hrtime_t d = h / 24;
3835 (void) sprintf(timebuf,
3836 "%llud%02lluh%02llum%02llus", d, h, m, s);
3838 (void) sprintf(timebuf, "%lluh%02llum%02llus", h, m, s);
3840 (void) sprintf(timebuf, "%llum%02llus", m, s);
3842 (void) sprintf(timebuf, "%llus", s);
3846 * Create a storage pool with the given name and initial vdev size.
3847 * Then create the specified number of datasets in the pool.
3850 ztest_init(char *pool)
3856 kernel_init(FREAD | FWRITE);
3859 * Create the storage pool.
3861 (void) spa_destroy(pool);
3862 ztest_shared->zs_vdev_primaries = 0;
3863 nvroot = make_vdev_root(NULL, NULL, zopt_vdev_size, 0,
3864 0, zopt_raidz, zopt_mirrors, 1);
3865 error = spa_create(pool, nvroot, NULL, NULL, NULL);
3866 nvlist_free(nvroot);
3869 fatal(0, "spa_create() = %d", error);
3870 error = spa_open(pool, &spa, FTAG);
3872 fatal(0, "spa_open() = %d", error);
3874 metaslab_sz = 1ULL << spa->spa_root_vdev->vdev_child[0]->vdev_ms_shift;
3876 if (zopt_verbose >= 3)
3877 show_pool_stats(spa);
3879 spa_close(spa, FTAG);
3885 main(int argc, char **argv)
3895 (void) setvbuf(stdout, NULL, _IOLBF, 0);
3897 /* Override location of zpool.cache */
3898 spa_config_path = "/tmp/zpool.cache";
3900 ztest_random_fd = open("/dev/urandom", O_RDONLY);
3902 process_options(argc, argv);
3905 * Blow away any existing copy of zpool.cache
3908 (void) remove("/tmp/zpool.cache");
3910 zs = ztest_shared = (void *)mmap(0,
3911 P2ROUNDUP(sizeof (ztest_shared_t), getpagesize()),
3912 PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANON, -1, 0);
3914 if (zopt_verbose >= 1) {
3915 (void) printf("%llu vdevs, %d datasets, %d threads,"
3916 " %llu seconds...\n",
3917 (u_longlong_t)zopt_vdevs, zopt_datasets, zopt_threads,
3918 (u_longlong_t)zopt_time);
3922 * Create and initialize our storage pool.
3924 for (i = 1; i <= zopt_init; i++) {
3925 bzero(zs, sizeof (ztest_shared_t));
3926 if (zopt_verbose >= 3 && zopt_init != 1)
3927 (void) printf("ztest_init(), pass %d\n", i);
3928 ztest_init(zopt_pool);
3932 * Initialize the call targets for each function.
3934 for (f = 0; f < ZTEST_FUNCS; f++) {
3935 zi = &zs->zs_info[f];
3937 *zi = ztest_info[f];
3939 if (*zi->zi_interval == 0)
3940 zi->zi_call_target = UINT64_MAX;
3942 zi->zi_call_target = zopt_time / *zi->zi_interval;
3945 zs->zs_start_time = gethrtime();
3946 zs->zs_stop_time = zs->zs_start_time + zopt_time * NANOSEC;
3949 * Run the tests in a loop. These tests include fault injection
3950 * to verify that self-healing data works, and forced crashes
3951 * to verify that we never lose on-disk consistency.
3953 while (gethrtime() < zs->zs_stop_time) {
3959 * Initialize the workload counters for each function.
3961 for (f = 0; f < ZTEST_FUNCS; f++) {
3962 zi = &zs->zs_info[f];
3964 zi->zi_call_time = 0;
3967 /* Set the allocation switch size */
3968 metaslab_df_alloc_threshold = ztest_random(metaslab_sz / 4) + 1;
3973 fatal(1, "fork failed");
3975 if (pid == 0) { /* child */
3976 struct rlimit rl = { 1024, 1024 };
3977 (void) setrlimit(RLIMIT_NOFILE, &rl);
3978 (void) enable_extended_FILE_stdio(-1, -1);
3979 ztest_run(zopt_pool);
3983 while (waitpid(pid, &status, 0) != pid)
3986 if (WIFEXITED(status)) {
3987 if (WEXITSTATUS(status) != 0) {
3988 (void) fprintf(stderr,
3989 "child exited with code %d\n",
3990 WEXITSTATUS(status));
3993 } else if (WIFSIGNALED(status)) {
3994 if (WTERMSIG(status) != SIGKILL) {
3995 (void) fprintf(stderr,
3996 "child died with signal %d\n",
4002 (void) fprintf(stderr, "something strange happened "
4009 if (zopt_verbose >= 1) {
4010 hrtime_t now = gethrtime();
4012 now = MIN(now, zs->zs_stop_time);
4013 print_time(zs->zs_stop_time - now, timebuf);
4014 nicenum(zs->zs_space, numbuf);
4016 (void) printf("Pass %3d, %8s, %3llu ENOSPC, "
4017 "%4.1f%% of %5s used, %3.0f%% done, %8s to go\n",
4019 WIFEXITED(status) ? "Complete" : "SIGKILL",
4020 (u_longlong_t)zs->zs_enospc_count,
4021 100.0 * zs->zs_alloc / zs->zs_space,
4023 100.0 * (now - zs->zs_start_time) /
4024 (zopt_time * NANOSEC), timebuf);
4027 if (zopt_verbose >= 2) {
4028 (void) printf("\nWorkload summary:\n\n");
4029 (void) printf("%7s %9s %s\n",
4030 "Calls", "Time", "Function");
4031 (void) printf("%7s %9s %s\n",
4032 "-----", "----", "--------");
4033 for (f = 0; f < ZTEST_FUNCS; f++) {
4036 zi = &zs->zs_info[f];
4037 print_time(zi->zi_call_time, timebuf);
4038 (void) dladdr((void *)zi->zi_func, &dli);
4039 (void) printf("%7llu %9s %s\n",
4040 (u_longlong_t)zi->zi_calls, timebuf,
4043 (void) printf("\n");
4047 * It's possible that we killed a child during a rename test, in
4048 * which case we'll have a 'ztest_tmp' pool lying around instead
4049 * of 'ztest'. Do a blind rename in case this happened.
4051 tmp = umem_alloc(strlen(zopt_pool) + 5, UMEM_NOFAIL);
4052 (void) strcpy(tmp, zopt_pool);
4053 (void) strcat(tmp, "_tmp");
4054 kernel_init(FREAD | FWRITE);
4055 (void) spa_rename(tmp, zopt_pool);
4057 umem_free(tmp, strlen(tmp) + 1);
4060 ztest_verify_blocks(zopt_pool);
4062 if (zopt_verbose >= 1) {
4063 (void) printf("%d killed, %d completed, %.0f%% kill rate\n",
4064 kills, iters - kills, (100.0 * kills) / MAX(1, iters));