Print this page
3006 VERIFY[S,U,P] and ASSERT[S,U,P] frequently check if first argument is zero
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/cmd/ztest/ztest.c
+++ new/usr/src/cmd/ztest/ztest.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21 /*
22 22 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
23 23 * Copyright (c) 2012 by Delphix. All rights reserved.
24 24 * Copyright 2011 Nexenta Systems, Inc. All rights reserved.
25 25 */
26 26
27 27 /*
28 28 * The objective of this program is to provide a DMU/ZAP/SPA stress test
29 29 * that runs entirely in userland, is easy to use, and easy to extend.
30 30 *
31 31 * The overall design of the ztest program is as follows:
32 32 *
33 33 * (1) For each major functional area (e.g. adding vdevs to a pool,
34 34 * creating and destroying datasets, reading and writing objects, etc)
35 35 * we have a simple routine to test that functionality. These
36 36 * individual routines do not have to do anything "stressful".
37 37 *
38 38 * (2) We turn these simple functionality tests into a stress test by
39 39 * running them all in parallel, with as many threads as desired,
40 40 * and spread across as many datasets, objects, and vdevs as desired.
41 41 *
42 42 * (3) While all this is happening, we inject faults into the pool to
43 43 * verify that self-healing data really works.
44 44 *
45 45 * (4) Every time we open a dataset, we change its checksum and compression
46 46 * functions. Thus even individual objects vary from block to block
47 47 * in which checksum they use and whether they're compressed.
48 48 *
49 49 * (5) To verify that we never lose on-disk consistency after a crash,
50 50 * we run the entire test in a child of the main process.
51 51 * At random times, the child self-immolates with a SIGKILL.
52 52 * This is the software equivalent of pulling the power cord.
53 53 * The parent then runs the test again, using the existing
54 54 * storage pool, as many times as desired. If backwards compatability
55 55 * testing is enabled ztest will sometimes run the "older" version
56 56 * of ztest after a SIGKILL.
57 57 *
58 58 * (6) To verify that we don't have future leaks or temporal incursions,
59 59 * many of the functional tests record the transaction group number
60 60 * as part of their data. When reading old data, they verify that
61 61 * the transaction group number is less than the current, open txg.
62 62 * If you add a new test, please do this if applicable.
63 63 *
64 64 * When run with no arguments, ztest runs for about five minutes and
65 65 * produces no output if successful. To get a little bit of information,
66 66 * specify -V. To get more information, specify -VV, and so on.
67 67 *
68 68 * To turn this into an overnight stress test, use -T to specify run time.
69 69 *
70 70 * You can ask more more vdevs [-v], datasets [-d], or threads [-t]
71 71 * to increase the pool capacity, fanout, and overall stress level.
72 72 *
73 73 * Use the -k option to set the desired frequency of kills.
74 74 *
75 75 * When ztest invokes itself it passes all relevant information through a
76 76 * temporary file which is mmap-ed in the child process. This allows shared
77 77 * memory to survive the exec syscall. The ztest_shared_hdr_t struct is always
78 78 * stored at offset 0 of this file and contains information on the size and
79 79 * number of shared structures in the file. The information stored in this file
80 80 * must remain backwards compatible with older versions of ztest so that
81 81 * ztest can invoke them during backwards compatibility testing (-B).
82 82 */
83 83
84 84 #include <sys/zfs_context.h>
85 85 #include <sys/spa.h>
86 86 #include <sys/dmu.h>
87 87 #include <sys/txg.h>
88 88 #include <sys/dbuf.h>
89 89 #include <sys/zap.h>
90 90 #include <sys/dmu_objset.h>
91 91 #include <sys/poll.h>
92 92 #include <sys/stat.h>
93 93 #include <sys/time.h>
94 94 #include <sys/wait.h>
95 95 #include <sys/mman.h>
96 96 #include <sys/resource.h>
97 97 #include <sys/zio.h>
98 98 #include <sys/zil.h>
99 99 #include <sys/zil_impl.h>
100 100 #include <sys/vdev_impl.h>
101 101 #include <sys/vdev_file.h>
102 102 #include <sys/spa_impl.h>
103 103 #include <sys/metaslab_impl.h>
104 104 #include <sys/dsl_prop.h>
105 105 #include <sys/dsl_dataset.h>
106 106 #include <sys/dsl_scan.h>
107 107 #include <sys/zio_checksum.h>
108 108 #include <sys/refcount.h>
109 109 #include <sys/zfeature.h>
110 110 #include <stdio.h>
111 111 #include <stdio_ext.h>
112 112 #include <stdlib.h>
113 113 #include <unistd.h>
114 114 #include <signal.h>
115 115 #include <umem.h>
116 116 #include <dlfcn.h>
117 117 #include <ctype.h>
118 118 #include <math.h>
119 119 #include <sys/fs/zfs.h>
120 120 #include <libnvpair.h>
121 121
122 122 #define ZTEST_FD_DATA 3
123 123 #define ZTEST_FD_RAND 4
124 124
125 125 typedef struct ztest_shared_hdr {
126 126 uint64_t zh_hdr_size;
127 127 uint64_t zh_opts_size;
128 128 uint64_t zh_size;
129 129 uint64_t zh_stats_size;
130 130 uint64_t zh_stats_count;
131 131 uint64_t zh_ds_size;
132 132 uint64_t zh_ds_count;
133 133 } ztest_shared_hdr_t;
134 134
135 135 static ztest_shared_hdr_t *ztest_shared_hdr;
136 136
137 137 typedef struct ztest_shared_opts {
138 138 char zo_pool[MAXNAMELEN];
139 139 char zo_dir[MAXNAMELEN];
140 140 char zo_alt_ztest[MAXNAMELEN];
141 141 char zo_alt_libpath[MAXNAMELEN];
142 142 uint64_t zo_vdevs;
143 143 uint64_t zo_vdevtime;
144 144 size_t zo_vdev_size;
145 145 int zo_ashift;
146 146 int zo_mirrors;
147 147 int zo_raidz;
148 148 int zo_raidz_parity;
149 149 int zo_datasets;
150 150 int zo_threads;
151 151 uint64_t zo_passtime;
152 152 uint64_t zo_killrate;
153 153 int zo_verbose;
154 154 int zo_init;
155 155 uint64_t zo_time;
156 156 uint64_t zo_maxloops;
157 157 uint64_t zo_metaslab_gang_bang;
158 158 } ztest_shared_opts_t;
159 159
160 160 static const ztest_shared_opts_t ztest_opts_defaults = {
161 161 .zo_pool = { 'z', 't', 'e', 's', 't', '\0' },
162 162 .zo_dir = { '/', 't', 'm', 'p', '\0' },
163 163 .zo_alt_ztest = { '\0' },
164 164 .zo_alt_libpath = { '\0' },
165 165 .zo_vdevs = 5,
166 166 .zo_ashift = SPA_MINBLOCKSHIFT,
167 167 .zo_mirrors = 2,
168 168 .zo_raidz = 4,
169 169 .zo_raidz_parity = 1,
170 170 .zo_vdev_size = SPA_MINDEVSIZE,
171 171 .zo_datasets = 7,
172 172 .zo_threads = 23,
173 173 .zo_passtime = 60, /* 60 seconds */
174 174 .zo_killrate = 70, /* 70% kill rate */
175 175 .zo_verbose = 0,
176 176 .zo_init = 1,
177 177 .zo_time = 300, /* 5 minutes */
178 178 .zo_maxloops = 50, /* max loops during spa_freeze() */
179 179 .zo_metaslab_gang_bang = 32 << 10
180 180 };
181 181
182 182 extern uint64_t metaslab_gang_bang;
183 183 extern uint64_t metaslab_df_alloc_threshold;
184 184
185 185 static ztest_shared_opts_t *ztest_shared_opts;
186 186 static ztest_shared_opts_t ztest_opts;
187 187
188 188 typedef struct ztest_shared_ds {
189 189 uint64_t zd_seq;
190 190 } ztest_shared_ds_t;
191 191
192 192 static ztest_shared_ds_t *ztest_shared_ds;
193 193 #define ZTEST_GET_SHARED_DS(d) (&ztest_shared_ds[d])
194 194
195 195 #define BT_MAGIC 0x123456789abcdefULL
196 196 #define MAXFAULTS() \
197 197 (MAX(zs->zs_mirrors, 1) * (ztest_opts.zo_raidz_parity + 1) - 1)
198 198
199 199 enum ztest_io_type {
200 200 ZTEST_IO_WRITE_TAG,
201 201 ZTEST_IO_WRITE_PATTERN,
202 202 ZTEST_IO_WRITE_ZEROES,
203 203 ZTEST_IO_TRUNCATE,
204 204 ZTEST_IO_SETATTR,
205 205 ZTEST_IO_TYPES
206 206 };
207 207
208 208 typedef struct ztest_block_tag {
209 209 uint64_t bt_magic;
210 210 uint64_t bt_objset;
211 211 uint64_t bt_object;
212 212 uint64_t bt_offset;
213 213 uint64_t bt_gen;
214 214 uint64_t bt_txg;
215 215 uint64_t bt_crtxg;
216 216 } ztest_block_tag_t;
217 217
218 218 typedef struct bufwad {
219 219 uint64_t bw_index;
220 220 uint64_t bw_txg;
221 221 uint64_t bw_data;
222 222 } bufwad_t;
223 223
224 224 /*
225 225 * XXX -- fix zfs range locks to be generic so we can use them here.
226 226 */
227 227 typedef enum {
228 228 RL_READER,
229 229 RL_WRITER,
230 230 RL_APPEND
231 231 } rl_type_t;
232 232
233 233 typedef struct rll {
234 234 void *rll_writer;
235 235 int rll_readers;
236 236 mutex_t rll_lock;
237 237 cond_t rll_cv;
238 238 } rll_t;
239 239
240 240 typedef struct rl {
241 241 uint64_t rl_object;
242 242 uint64_t rl_offset;
243 243 uint64_t rl_size;
244 244 rll_t *rl_lock;
245 245 } rl_t;
246 246
247 247 #define ZTEST_RANGE_LOCKS 64
248 248 #define ZTEST_OBJECT_LOCKS 64
249 249
250 250 /*
251 251 * Object descriptor. Used as a template for object lookup/create/remove.
252 252 */
253 253 typedef struct ztest_od {
254 254 uint64_t od_dir;
255 255 uint64_t od_object;
256 256 dmu_object_type_t od_type;
257 257 dmu_object_type_t od_crtype;
258 258 uint64_t od_blocksize;
259 259 uint64_t od_crblocksize;
260 260 uint64_t od_gen;
261 261 uint64_t od_crgen;
262 262 char od_name[MAXNAMELEN];
263 263 } ztest_od_t;
264 264
265 265 /*
266 266 * Per-dataset state.
267 267 */
268 268 typedef struct ztest_ds {
269 269 ztest_shared_ds_t *zd_shared;
270 270 objset_t *zd_os;
271 271 rwlock_t zd_zilog_lock;
272 272 zilog_t *zd_zilog;
273 273 ztest_od_t *zd_od; /* debugging aid */
274 274 char zd_name[MAXNAMELEN];
275 275 mutex_t zd_dirobj_lock;
276 276 rll_t zd_object_lock[ZTEST_OBJECT_LOCKS];
277 277 rll_t zd_range_lock[ZTEST_RANGE_LOCKS];
278 278 } ztest_ds_t;
279 279
280 280 /*
281 281 * Per-iteration state.
282 282 */
283 283 typedef void ztest_func_t(ztest_ds_t *zd, uint64_t id);
284 284
285 285 typedef struct ztest_info {
286 286 ztest_func_t *zi_func; /* test function */
287 287 uint64_t zi_iters; /* iterations per execution */
288 288 uint64_t *zi_interval; /* execute every <interval> seconds */
289 289 } ztest_info_t;
290 290
291 291 typedef struct ztest_shared_callstate {
292 292 uint64_t zc_count; /* per-pass count */
293 293 uint64_t zc_time; /* per-pass time */
294 294 uint64_t zc_next; /* next time to call this function */
295 295 } ztest_shared_callstate_t;
296 296
297 297 static ztest_shared_callstate_t *ztest_shared_callstate;
298 298 #define ZTEST_GET_SHARED_CALLSTATE(c) (&ztest_shared_callstate[c])
299 299
300 300 /*
301 301 * Note: these aren't static because we want dladdr() to work.
302 302 */
303 303 ztest_func_t ztest_dmu_read_write;
304 304 ztest_func_t ztest_dmu_write_parallel;
305 305 ztest_func_t ztest_dmu_object_alloc_free;
306 306 ztest_func_t ztest_dmu_commit_callbacks;
307 307 ztest_func_t ztest_zap;
308 308 ztest_func_t ztest_zap_parallel;
309 309 ztest_func_t ztest_zil_commit;
310 310 ztest_func_t ztest_zil_remount;
311 311 ztest_func_t ztest_dmu_read_write_zcopy;
312 312 ztest_func_t ztest_dmu_objset_create_destroy;
313 313 ztest_func_t ztest_dmu_prealloc;
314 314 ztest_func_t ztest_fzap;
315 315 ztest_func_t ztest_dmu_snapshot_create_destroy;
316 316 ztest_func_t ztest_dsl_prop_get_set;
317 317 ztest_func_t ztest_spa_prop_get_set;
318 318 ztest_func_t ztest_spa_create_destroy;
319 319 ztest_func_t ztest_fault_inject;
320 320 ztest_func_t ztest_ddt_repair;
321 321 ztest_func_t ztest_dmu_snapshot_hold;
322 322 ztest_func_t ztest_spa_rename;
323 323 ztest_func_t ztest_scrub;
324 324 ztest_func_t ztest_dsl_dataset_promote_busy;
325 325 ztest_func_t ztest_vdev_attach_detach;
326 326 ztest_func_t ztest_vdev_LUN_growth;
327 327 ztest_func_t ztest_vdev_add_remove;
328 328 ztest_func_t ztest_vdev_aux_add_remove;
329 329 ztest_func_t ztest_split_pool;
330 330 ztest_func_t ztest_reguid;
331 331
332 332 uint64_t zopt_always = 0ULL * NANOSEC; /* all the time */
333 333 uint64_t zopt_incessant = 1ULL * NANOSEC / 10; /* every 1/10 second */
334 334 uint64_t zopt_often = 1ULL * NANOSEC; /* every second */
335 335 uint64_t zopt_sometimes = 10ULL * NANOSEC; /* every 10 seconds */
336 336 uint64_t zopt_rarely = 60ULL * NANOSEC; /* every 60 seconds */
337 337
338 338 ztest_info_t ztest_info[] = {
339 339 { ztest_dmu_read_write, 1, &zopt_always },
340 340 { ztest_dmu_write_parallel, 10, &zopt_always },
341 341 { ztest_dmu_object_alloc_free, 1, &zopt_always },
342 342 { ztest_dmu_commit_callbacks, 1, &zopt_always },
343 343 { ztest_zap, 30, &zopt_always },
344 344 { ztest_zap_parallel, 100, &zopt_always },
345 345 { ztest_split_pool, 1, &zopt_always },
346 346 { ztest_zil_commit, 1, &zopt_incessant },
347 347 { ztest_zil_remount, 1, &zopt_sometimes },
348 348 { ztest_dmu_read_write_zcopy, 1, &zopt_often },
349 349 { ztest_dmu_objset_create_destroy, 1, &zopt_often },
350 350 { ztest_dsl_prop_get_set, 1, &zopt_often },
351 351 { ztest_spa_prop_get_set, 1, &zopt_sometimes },
352 352 #if 0
353 353 { ztest_dmu_prealloc, 1, &zopt_sometimes },
354 354 #endif
355 355 { ztest_fzap, 1, &zopt_sometimes },
356 356 { ztest_dmu_snapshot_create_destroy, 1, &zopt_sometimes },
357 357 { ztest_spa_create_destroy, 1, &zopt_sometimes },
358 358 { ztest_fault_inject, 1, &zopt_sometimes },
359 359 { ztest_ddt_repair, 1, &zopt_sometimes },
360 360 { ztest_dmu_snapshot_hold, 1, &zopt_sometimes },
361 361 { ztest_reguid, 1, &zopt_sometimes },
362 362 { ztest_spa_rename, 1, &zopt_rarely },
363 363 { ztest_scrub, 1, &zopt_rarely },
364 364 { ztest_dsl_dataset_promote_busy, 1, &zopt_rarely },
365 365 { ztest_vdev_attach_detach, 1, &zopt_rarely },
366 366 { ztest_vdev_LUN_growth, 1, &zopt_rarely },
367 367 { ztest_vdev_add_remove, 1,
368 368 &ztest_opts.zo_vdevtime },
369 369 { ztest_vdev_aux_add_remove, 1,
370 370 &ztest_opts.zo_vdevtime },
371 371 };
372 372
373 373 #define ZTEST_FUNCS (sizeof (ztest_info) / sizeof (ztest_info_t))
374 374
375 375 /*
376 376 * The following struct is used to hold a list of uncalled commit callbacks.
377 377 * The callbacks are ordered by txg number.
378 378 */
379 379 typedef struct ztest_cb_list {
380 380 mutex_t zcl_callbacks_lock;
381 381 list_t zcl_callbacks;
382 382 } ztest_cb_list_t;
383 383
384 384 /*
385 385 * Stuff we need to share writably between parent and child.
386 386 */
387 387 typedef struct ztest_shared {
388 388 boolean_t zs_do_init;
389 389 hrtime_t zs_proc_start;
390 390 hrtime_t zs_proc_stop;
391 391 hrtime_t zs_thread_start;
392 392 hrtime_t zs_thread_stop;
393 393 hrtime_t zs_thread_kill;
394 394 uint64_t zs_enospc_count;
395 395 uint64_t zs_vdev_next_leaf;
396 396 uint64_t zs_vdev_aux;
397 397 uint64_t zs_alloc;
398 398 uint64_t zs_space;
399 399 uint64_t zs_splits;
400 400 uint64_t zs_mirrors;
401 401 uint64_t zs_metaslab_sz;
402 402 uint64_t zs_metaslab_df_alloc_threshold;
403 403 uint64_t zs_guid;
404 404 } ztest_shared_t;
405 405
406 406 #define ID_PARALLEL -1ULL
407 407
408 408 static char ztest_dev_template[] = "%s/%s.%llua";
409 409 static char ztest_aux_template[] = "%s/%s.%s.%llu";
410 410 ztest_shared_t *ztest_shared;
411 411
412 412 static spa_t *ztest_spa = NULL;
413 413 static ztest_ds_t *ztest_ds;
414 414
415 415 static mutex_t ztest_vdev_lock;
416 416 static rwlock_t ztest_name_lock;
417 417
418 418 static boolean_t ztest_dump_core = B_TRUE;
419 419 static boolean_t ztest_exiting;
420 420
421 421 /* Global commit callback list */
422 422 static ztest_cb_list_t zcl;
423 423
424 424 enum ztest_object {
425 425 ZTEST_META_DNODE = 0,
426 426 ZTEST_DIROBJ,
427 427 ZTEST_OBJECTS
428 428 };
429 429
430 430 static void usage(boolean_t) __NORETURN;
431 431
432 432 /*
433 433 * These libumem hooks provide a reasonable set of defaults for the allocator's
434 434 * debugging facilities.
435 435 */
436 436 const char *
437 437 _umem_debug_init()
438 438 {
439 439 return ("default,verbose"); /* $UMEM_DEBUG setting */
440 440 }
441 441
442 442 const char *
443 443 _umem_logging_init(void)
444 444 {
445 445 return ("fail,contents"); /* $UMEM_LOGGING setting */
446 446 }
447 447
448 448 #define FATAL_MSG_SZ 1024
449 449
450 450 char *fatal_msg;
451 451
452 452 static void
453 453 fatal(int do_perror, char *message, ...)
454 454 {
455 455 va_list args;
456 456 int save_errno = errno;
457 457 char buf[FATAL_MSG_SZ];
458 458
459 459 (void) fflush(stdout);
460 460
461 461 va_start(args, message);
462 462 (void) sprintf(buf, "ztest: ");
463 463 /* LINTED */
464 464 (void) vsprintf(buf + strlen(buf), message, args);
465 465 va_end(args);
466 466 if (do_perror) {
467 467 (void) snprintf(buf + strlen(buf), FATAL_MSG_SZ - strlen(buf),
468 468 ": %s", strerror(save_errno));
469 469 }
470 470 (void) fprintf(stderr, "%s\n", buf);
471 471 fatal_msg = buf; /* to ease debugging */
472 472 if (ztest_dump_core)
473 473 abort();
474 474 exit(3);
475 475 }
476 476
477 477 static int
478 478 str2shift(const char *buf)
479 479 {
480 480 const char *ends = "BKMGTPEZ";
481 481 int i;
482 482
483 483 if (buf[0] == '\0')
484 484 return (0);
485 485 for (i = 0; i < strlen(ends); i++) {
486 486 if (toupper(buf[0]) == ends[i])
487 487 break;
488 488 }
489 489 if (i == strlen(ends)) {
490 490 (void) fprintf(stderr, "ztest: invalid bytes suffix: %s\n",
491 491 buf);
492 492 usage(B_FALSE);
493 493 }
494 494 if (buf[1] == '\0' || (toupper(buf[1]) == 'B' && buf[2] == '\0')) {
495 495 return (10*i);
496 496 }
497 497 (void) fprintf(stderr, "ztest: invalid bytes suffix: %s\n", buf);
498 498 usage(B_FALSE);
499 499 /* NOTREACHED */
500 500 }
501 501
502 502 static uint64_t
503 503 nicenumtoull(const char *buf)
504 504 {
505 505 char *end;
506 506 uint64_t val;
507 507
508 508 val = strtoull(buf, &end, 0);
509 509 if (end == buf) {
510 510 (void) fprintf(stderr, "ztest: bad numeric value: %s\n", buf);
511 511 usage(B_FALSE);
512 512 } else if (end[0] == '.') {
513 513 double fval = strtod(buf, &end);
514 514 fval *= pow(2, str2shift(end));
515 515 if (fval > UINT64_MAX) {
516 516 (void) fprintf(stderr, "ztest: value too large: %s\n",
517 517 buf);
518 518 usage(B_FALSE);
519 519 }
520 520 val = (uint64_t)fval;
521 521 } else {
522 522 int shift = str2shift(end);
523 523 if (shift >= 64 || (val << shift) >> shift != val) {
524 524 (void) fprintf(stderr, "ztest: value too large: %s\n",
525 525 buf);
526 526 usage(B_FALSE);
527 527 }
528 528 val <<= shift;
529 529 }
530 530 return (val);
531 531 }
532 532
533 533 static void
534 534 usage(boolean_t requested)
535 535 {
536 536 const ztest_shared_opts_t *zo = &ztest_opts_defaults;
537 537
538 538 char nice_vdev_size[10];
539 539 char nice_gang_bang[10];
540 540 FILE *fp = requested ? stdout : stderr;
541 541
542 542 nicenum(zo->zo_vdev_size, nice_vdev_size);
543 543 nicenum(zo->zo_metaslab_gang_bang, nice_gang_bang);
544 544
545 545 (void) fprintf(fp, "Usage: %s\n"
546 546 "\t[-v vdevs (default: %llu)]\n"
547 547 "\t[-s size_of_each_vdev (default: %s)]\n"
548 548 "\t[-a alignment_shift (default: %d)] use 0 for random\n"
549 549 "\t[-m mirror_copies (default: %d)]\n"
550 550 "\t[-r raidz_disks (default: %d)]\n"
551 551 "\t[-R raidz_parity (default: %d)]\n"
552 552 "\t[-d datasets (default: %d)]\n"
553 553 "\t[-t threads (default: %d)]\n"
554 554 "\t[-g gang_block_threshold (default: %s)]\n"
555 555 "\t[-i init_count (default: %d)] initialize pool i times\n"
556 556 "\t[-k kill_percentage (default: %llu%%)]\n"
557 557 "\t[-p pool_name (default: %s)]\n"
558 558 "\t[-f dir (default: %s)] file directory for vdev files\n"
559 559 "\t[-V] verbose (use multiple times for ever more blather)\n"
560 560 "\t[-E] use existing pool instead of creating new one\n"
561 561 "\t[-T time (default: %llu sec)] total run time\n"
562 562 "\t[-F freezeloops (default: %llu)] max loops in spa_freeze()\n"
563 563 "\t[-P passtime (default: %llu sec)] time per pass\n"
564 564 "\t[-B alt_ztest (default: <none>)] alternate ztest path\n"
565 565 "\t[-h] (print help)\n"
566 566 "",
567 567 zo->zo_pool,
568 568 (u_longlong_t)zo->zo_vdevs, /* -v */
569 569 nice_vdev_size, /* -s */
570 570 zo->zo_ashift, /* -a */
571 571 zo->zo_mirrors, /* -m */
572 572 zo->zo_raidz, /* -r */
573 573 zo->zo_raidz_parity, /* -R */
574 574 zo->zo_datasets, /* -d */
575 575 zo->zo_threads, /* -t */
576 576 nice_gang_bang, /* -g */
577 577 zo->zo_init, /* -i */
578 578 (u_longlong_t)zo->zo_killrate, /* -k */
579 579 zo->zo_pool, /* -p */
580 580 zo->zo_dir, /* -f */
581 581 (u_longlong_t)zo->zo_time, /* -T */
582 582 (u_longlong_t)zo->zo_maxloops, /* -F */
583 583 (u_longlong_t)zo->zo_passtime);
584 584 exit(requested ? 0 : 1);
585 585 }
586 586
587 587 static void
588 588 process_options(int argc, char **argv)
589 589 {
590 590 char *path;
591 591 ztest_shared_opts_t *zo = &ztest_opts;
592 592
593 593 int opt;
594 594 uint64_t value;
595 595 char altdir[MAXNAMELEN] = { 0 };
596 596
597 597 bcopy(&ztest_opts_defaults, zo, sizeof (*zo));
598 598
599 599 while ((opt = getopt(argc, argv,
600 600 "v:s:a:m:r:R:d:t:g:i:k:p:f:VET:P:hF:B:")) != EOF) {
601 601 value = 0;
602 602 switch (opt) {
603 603 case 'v':
604 604 case 's':
605 605 case 'a':
606 606 case 'm':
607 607 case 'r':
608 608 case 'R':
609 609 case 'd':
610 610 case 't':
611 611 case 'g':
612 612 case 'i':
613 613 case 'k':
614 614 case 'T':
615 615 case 'P':
616 616 case 'F':
617 617 value = nicenumtoull(optarg);
618 618 }
619 619 switch (opt) {
620 620 case 'v':
621 621 zo->zo_vdevs = value;
622 622 break;
623 623 case 's':
624 624 zo->zo_vdev_size = MAX(SPA_MINDEVSIZE, value);
625 625 break;
626 626 case 'a':
627 627 zo->zo_ashift = value;
628 628 break;
629 629 case 'm':
630 630 zo->zo_mirrors = value;
631 631 break;
632 632 case 'r':
633 633 zo->zo_raidz = MAX(1, value);
634 634 break;
635 635 case 'R':
636 636 zo->zo_raidz_parity = MIN(MAX(value, 1), 3);
637 637 break;
638 638 case 'd':
639 639 zo->zo_datasets = MAX(1, value);
640 640 break;
641 641 case 't':
642 642 zo->zo_threads = MAX(1, value);
643 643 break;
644 644 case 'g':
645 645 zo->zo_metaslab_gang_bang = MAX(SPA_MINBLOCKSIZE << 1,
646 646 value);
647 647 break;
648 648 case 'i':
649 649 zo->zo_init = value;
650 650 break;
651 651 case 'k':
652 652 zo->zo_killrate = value;
653 653 break;
654 654 case 'p':
655 655 (void) strlcpy(zo->zo_pool, optarg,
656 656 sizeof (zo->zo_pool));
657 657 break;
658 658 case 'f':
659 659 path = realpath(optarg, NULL);
660 660 if (path == NULL) {
661 661 (void) fprintf(stderr, "error: %s: %s\n",
662 662 optarg, strerror(errno));
663 663 usage(B_FALSE);
664 664 } else {
665 665 (void) strlcpy(zo->zo_dir, path,
666 666 sizeof (zo->zo_dir));
667 667 }
668 668 break;
669 669 case 'V':
670 670 zo->zo_verbose++;
671 671 break;
672 672 case 'E':
673 673 zo->zo_init = 0;
674 674 break;
675 675 case 'T':
676 676 zo->zo_time = value;
677 677 break;
678 678 case 'P':
679 679 zo->zo_passtime = MAX(1, value);
680 680 break;
681 681 case 'F':
682 682 zo->zo_maxloops = MAX(1, value);
683 683 break;
684 684 case 'B':
685 685 (void) strlcpy(altdir, optarg, sizeof (altdir));
686 686 break;
687 687 case 'h':
688 688 usage(B_TRUE);
689 689 break;
690 690 case '?':
691 691 default:
692 692 usage(B_FALSE);
693 693 break;
694 694 }
695 695 }
696 696
697 697 zo->zo_raidz_parity = MIN(zo->zo_raidz_parity, zo->zo_raidz - 1);
698 698
699 699 zo->zo_vdevtime =
700 700 (zo->zo_vdevs > 0 ? zo->zo_time * NANOSEC / zo->zo_vdevs :
701 701 UINT64_MAX >> 2);
702 702
703 703 if (strlen(altdir) > 0) {
704 704 char cmd[MAXNAMELEN];
705 705 char realaltdir[MAXNAMELEN];
706 706 char *bin;
707 707 char *ztest;
708 708 char *isa;
709 709 int isalen;
710 710
711 711 (void) realpath(getexecname(), cmd);
712 712 if (0 != access(altdir, F_OK)) {
713 713 ztest_dump_core = B_FALSE;
714 714 fatal(B_TRUE, "invalid alternate ztest path: %s",
715 715 altdir);
716 716 }
717 717 VERIFY(NULL != realpath(altdir, realaltdir));
718 718
719 719 /*
720 720 * 'cmd' should be of the form "<anything>/usr/bin/<isa>/ztest".
721 721 * We want to extract <isa> to determine if we should use
722 722 * 32 or 64 bit binaries.
723 723 */
724 724 bin = strstr(cmd, "/usr/bin/");
725 725 ztest = strstr(bin, "/ztest");
726 726 isa = bin + 9;
727 727 isalen = ztest - isa;
728 728 (void) snprintf(zo->zo_alt_ztest, sizeof (zo->zo_alt_ztest),
729 729 "%s/usr/bin/%.*s/ztest", realaltdir, isalen, isa);
730 730 (void) snprintf(zo->zo_alt_libpath, sizeof (zo->zo_alt_libpath),
731 731 "%s/usr/lib/%.*s", realaltdir, isalen, isa);
732 732
733 733 if (0 != access(zo->zo_alt_ztest, X_OK)) {
734 734 ztest_dump_core = B_FALSE;
735 735 fatal(B_TRUE, "invalid alternate ztest: %s",
736 736 zo->zo_alt_ztest);
737 737 } else if (0 != access(zo->zo_alt_libpath, X_OK)) {
738 738 ztest_dump_core = B_FALSE;
739 739 fatal(B_TRUE, "invalid alternate lib directory %s",
740 740 zo->zo_alt_libpath);
741 741 }
742 742 }
743 743 }
744 744
745 745 static void
746 746 ztest_kill(ztest_shared_t *zs)
747 747 {
748 748 zs->zs_alloc = metaslab_class_get_alloc(spa_normal_class(ztest_spa));
749 749 zs->zs_space = metaslab_class_get_space(spa_normal_class(ztest_spa));
750 750 (void) kill(getpid(), SIGKILL);
751 751 }
752 752
753 753 static uint64_t
754 754 ztest_random(uint64_t range)
755 755 {
756 756 uint64_t r;
757 757
758 758 if (range == 0)
759 759 return (0);
760 760
761 761 if (read(ZTEST_FD_RAND, &r, sizeof (r)) != sizeof (r))
762 762 fatal(1, "short read from /dev/urandom");
763 763
764 764 return (r % range);
765 765 }
766 766
767 767 /* ARGSUSED */
768 768 static void
769 769 ztest_record_enospc(const char *s)
770 770 {
771 771 ztest_shared->zs_enospc_count++;
772 772 }
773 773
774 774 static uint64_t
775 775 ztest_get_ashift(void)
776 776 {
777 777 if (ztest_opts.zo_ashift == 0)
778 778 return (SPA_MINBLOCKSHIFT + ztest_random(3));
779 779 return (ztest_opts.zo_ashift);
780 780 }
781 781
782 782 static nvlist_t *
783 783 make_vdev_file(char *path, char *aux, size_t size, uint64_t ashift)
784 784 {
785 785 char pathbuf[MAXPATHLEN];
786 786 uint64_t vdev;
787 787 nvlist_t *file;
788 788
789 789 if (ashift == 0)
790 790 ashift = ztest_get_ashift();
791 791
792 792 if (path == NULL) {
793 793 path = pathbuf;
794 794
795 795 if (aux != NULL) {
796 796 vdev = ztest_shared->zs_vdev_aux;
797 797 (void) snprintf(path, sizeof (pathbuf),
798 798 ztest_aux_template, ztest_opts.zo_dir,
799 799 ztest_opts.zo_pool, aux, vdev);
800 800 } else {
801 801 vdev = ztest_shared->zs_vdev_next_leaf++;
802 802 (void) snprintf(path, sizeof (pathbuf),
803 803 ztest_dev_template, ztest_opts.zo_dir,
804 804 ztest_opts.zo_pool, vdev);
805 805 }
806 806 }
807 807
808 808 if (size != 0) {
809 809 int fd = open(path, O_RDWR | O_CREAT | O_TRUNC, 0666);
810 810 if (fd == -1)
811 811 fatal(1, "can't open %s", path);
812 812 if (ftruncate(fd, size) != 0)
813 813 fatal(1, "can't ftruncate %s", path);
814 814 (void) close(fd);
815 815 }
816 816
817 817 VERIFY(nvlist_alloc(&file, NV_UNIQUE_NAME, 0) == 0);
818 818 VERIFY(nvlist_add_string(file, ZPOOL_CONFIG_TYPE, VDEV_TYPE_FILE) == 0);
819 819 VERIFY(nvlist_add_string(file, ZPOOL_CONFIG_PATH, path) == 0);
820 820 VERIFY(nvlist_add_uint64(file, ZPOOL_CONFIG_ASHIFT, ashift) == 0);
821 821
822 822 return (file);
823 823 }
824 824
825 825 static nvlist_t *
826 826 make_vdev_raidz(char *path, char *aux, size_t size, uint64_t ashift, int r)
827 827 {
828 828 nvlist_t *raidz, **child;
829 829 int c;
830 830
831 831 if (r < 2)
832 832 return (make_vdev_file(path, aux, size, ashift));
833 833 child = umem_alloc(r * sizeof (nvlist_t *), UMEM_NOFAIL);
834 834
835 835 for (c = 0; c < r; c++)
836 836 child[c] = make_vdev_file(path, aux, size, ashift);
837 837
838 838 VERIFY(nvlist_alloc(&raidz, NV_UNIQUE_NAME, 0) == 0);
839 839 VERIFY(nvlist_add_string(raidz, ZPOOL_CONFIG_TYPE,
840 840 VDEV_TYPE_RAIDZ) == 0);
841 841 VERIFY(nvlist_add_uint64(raidz, ZPOOL_CONFIG_NPARITY,
842 842 ztest_opts.zo_raidz_parity) == 0);
843 843 VERIFY(nvlist_add_nvlist_array(raidz, ZPOOL_CONFIG_CHILDREN,
844 844 child, r) == 0);
845 845
846 846 for (c = 0; c < r; c++)
847 847 nvlist_free(child[c]);
848 848
849 849 umem_free(child, r * sizeof (nvlist_t *));
850 850
851 851 return (raidz);
852 852 }
853 853
854 854 static nvlist_t *
855 855 make_vdev_mirror(char *path, char *aux, size_t size, uint64_t ashift,
856 856 int r, int m)
857 857 {
858 858 nvlist_t *mirror, **child;
859 859 int c;
860 860
861 861 if (m < 1)
862 862 return (make_vdev_raidz(path, aux, size, ashift, r));
863 863
864 864 child = umem_alloc(m * sizeof (nvlist_t *), UMEM_NOFAIL);
865 865
866 866 for (c = 0; c < m; c++)
867 867 child[c] = make_vdev_raidz(path, aux, size, ashift, r);
868 868
869 869 VERIFY(nvlist_alloc(&mirror, NV_UNIQUE_NAME, 0) == 0);
870 870 VERIFY(nvlist_add_string(mirror, ZPOOL_CONFIG_TYPE,
871 871 VDEV_TYPE_MIRROR) == 0);
872 872 VERIFY(nvlist_add_nvlist_array(mirror, ZPOOL_CONFIG_CHILDREN,
873 873 child, m) == 0);
874 874
875 875 for (c = 0; c < m; c++)
876 876 nvlist_free(child[c]);
877 877
878 878 umem_free(child, m * sizeof (nvlist_t *));
879 879
880 880 return (mirror);
881 881 }
882 882
883 883 static nvlist_t *
884 884 make_vdev_root(char *path, char *aux, size_t size, uint64_t ashift,
885 885 int log, int r, int m, int t)
886 886 {
887 887 nvlist_t *root, **child;
888 888 int c;
889 889
890 890 ASSERT(t > 0);
891 891
892 892 child = umem_alloc(t * sizeof (nvlist_t *), UMEM_NOFAIL);
893 893
894 894 for (c = 0; c < t; c++) {
895 895 child[c] = make_vdev_mirror(path, aux, size, ashift, r, m);
896 896 VERIFY(nvlist_add_uint64(child[c], ZPOOL_CONFIG_IS_LOG,
897 897 log) == 0);
898 898 }
899 899
900 900 VERIFY(nvlist_alloc(&root, NV_UNIQUE_NAME, 0) == 0);
901 901 VERIFY(nvlist_add_string(root, ZPOOL_CONFIG_TYPE, VDEV_TYPE_ROOT) == 0);
902 902 VERIFY(nvlist_add_nvlist_array(root, aux ? aux : ZPOOL_CONFIG_CHILDREN,
903 903 child, t) == 0);
904 904
905 905 for (c = 0; c < t; c++)
906 906 nvlist_free(child[c]);
907 907
908 908 umem_free(child, t * sizeof (nvlist_t *));
909 909
910 910 return (root);
911 911 }
912 912
913 913 static int
914 914 ztest_random_blocksize(void)
915 915 {
916 916 return (1 << (SPA_MINBLOCKSHIFT +
917 917 ztest_random(SPA_MAXBLOCKSHIFT - SPA_MINBLOCKSHIFT + 1)));
918 918 }
919 919
920 920 static int
921 921 ztest_random_ibshift(void)
922 922 {
923 923 return (DN_MIN_INDBLKSHIFT +
924 924 ztest_random(DN_MAX_INDBLKSHIFT - DN_MIN_INDBLKSHIFT + 1));
925 925 }
926 926
927 927 static uint64_t
928 928 ztest_random_vdev_top(spa_t *spa, boolean_t log_ok)
929 929 {
930 930 uint64_t top;
931 931 vdev_t *rvd = spa->spa_root_vdev;
932 932 vdev_t *tvd;
933 933
934 934 ASSERT(spa_config_held(spa, SCL_ALL, RW_READER) != 0);
935 935
936 936 do {
937 937 top = ztest_random(rvd->vdev_children);
938 938 tvd = rvd->vdev_child[top];
939 939 } while (tvd->vdev_ishole || (tvd->vdev_islog && !log_ok) ||
940 940 tvd->vdev_mg == NULL || tvd->vdev_mg->mg_class == NULL);
941 941
942 942 return (top);
943 943 }
944 944
945 945 static uint64_t
946 946 ztest_random_dsl_prop(zfs_prop_t prop)
947 947 {
948 948 uint64_t value;
949 949
950 950 do {
951 951 value = zfs_prop_random_value(prop, ztest_random(-1ULL));
952 952 } while (prop == ZFS_PROP_CHECKSUM && value == ZIO_CHECKSUM_OFF);
953 953
954 954 return (value);
955 955 }
956 956
957 957 static int
958 958 ztest_dsl_prop_set_uint64(char *osname, zfs_prop_t prop, uint64_t value,
959 959 boolean_t inherit)
960 960 {
961 961 const char *propname = zfs_prop_to_name(prop);
962 962 const char *valname;
963 963 char setpoint[MAXPATHLEN];
964 964 uint64_t curval;
↓ open down ↓ |
964 lines elided |
↑ open up ↑ |
965 965 int error;
966 966
967 967 error = dsl_prop_set(osname, propname,
968 968 (inherit ? ZPROP_SRC_NONE : ZPROP_SRC_LOCAL),
969 969 sizeof (value), 1, &value);
970 970
971 971 if (error == ENOSPC) {
972 972 ztest_record_enospc(FTAG);
973 973 return (error);
974 974 }
975 - ASSERT3U(error, ==, 0);
975 + ASSERT0(error);
976 976
977 977 VERIFY3U(dsl_prop_get(osname, propname, sizeof (curval),
978 978 1, &curval, setpoint), ==, 0);
979 979
980 980 if (ztest_opts.zo_verbose >= 6) {
981 981 VERIFY(zfs_prop_index_to_string(prop, curval, &valname) == 0);
982 982 (void) printf("%s %s = %s at '%s'\n",
983 983 osname, propname, valname, setpoint);
984 984 }
985 985
986 986 return (error);
987 987 }
988 988
989 989 static int
990 990 ztest_spa_prop_set_uint64(zpool_prop_t prop, uint64_t value)
991 991 {
992 992 spa_t *spa = ztest_spa;
993 993 nvlist_t *props = NULL;
994 994 int error;
995 995
996 996 VERIFY(nvlist_alloc(&props, NV_UNIQUE_NAME, 0) == 0);
↓ open down ↓ |
11 lines elided |
↑ open up ↑ |
997 997 VERIFY(nvlist_add_uint64(props, zpool_prop_to_name(prop), value) == 0);
998 998
999 999 error = spa_prop_set(spa, props);
1000 1000
1001 1001 nvlist_free(props);
1002 1002
1003 1003 if (error == ENOSPC) {
1004 1004 ztest_record_enospc(FTAG);
1005 1005 return (error);
1006 1006 }
1007 - ASSERT3U(error, ==, 0);
1007 + ASSERT0(error);
1008 1008
1009 1009 return (error);
1010 1010 }
1011 1011
1012 1012 static void
1013 1013 ztest_rll_init(rll_t *rll)
1014 1014 {
1015 1015 rll->rll_writer = NULL;
1016 1016 rll->rll_readers = 0;
1017 1017 VERIFY(_mutex_init(&rll->rll_lock, USYNC_THREAD, NULL) == 0);
1018 1018 VERIFY(cond_init(&rll->rll_cv, USYNC_THREAD, NULL) == 0);
1019 1019 }
1020 1020
1021 1021 static void
1022 1022 ztest_rll_destroy(rll_t *rll)
1023 1023 {
1024 1024 ASSERT(rll->rll_writer == NULL);
1025 1025 ASSERT(rll->rll_readers == 0);
1026 1026 VERIFY(_mutex_destroy(&rll->rll_lock) == 0);
1027 1027 VERIFY(cond_destroy(&rll->rll_cv) == 0);
1028 1028 }
1029 1029
1030 1030 static void
1031 1031 ztest_rll_lock(rll_t *rll, rl_type_t type)
1032 1032 {
1033 1033 VERIFY(mutex_lock(&rll->rll_lock) == 0);
1034 1034
1035 1035 if (type == RL_READER) {
1036 1036 while (rll->rll_writer != NULL)
1037 1037 (void) cond_wait(&rll->rll_cv, &rll->rll_lock);
1038 1038 rll->rll_readers++;
1039 1039 } else {
1040 1040 while (rll->rll_writer != NULL || rll->rll_readers)
1041 1041 (void) cond_wait(&rll->rll_cv, &rll->rll_lock);
1042 1042 rll->rll_writer = curthread;
1043 1043 }
1044 1044
1045 1045 VERIFY(mutex_unlock(&rll->rll_lock) == 0);
1046 1046 }
1047 1047
1048 1048 static void
1049 1049 ztest_rll_unlock(rll_t *rll)
1050 1050 {
1051 1051 VERIFY(mutex_lock(&rll->rll_lock) == 0);
1052 1052
1053 1053 if (rll->rll_writer) {
1054 1054 ASSERT(rll->rll_readers == 0);
1055 1055 rll->rll_writer = NULL;
1056 1056 } else {
1057 1057 ASSERT(rll->rll_readers != 0);
1058 1058 ASSERT(rll->rll_writer == NULL);
1059 1059 rll->rll_readers--;
1060 1060 }
1061 1061
1062 1062 if (rll->rll_writer == NULL && rll->rll_readers == 0)
1063 1063 VERIFY(cond_broadcast(&rll->rll_cv) == 0);
1064 1064
1065 1065 VERIFY(mutex_unlock(&rll->rll_lock) == 0);
1066 1066 }
1067 1067
1068 1068 static void
1069 1069 ztest_object_lock(ztest_ds_t *zd, uint64_t object, rl_type_t type)
1070 1070 {
1071 1071 rll_t *rll = &zd->zd_object_lock[object & (ZTEST_OBJECT_LOCKS - 1)];
1072 1072
1073 1073 ztest_rll_lock(rll, type);
1074 1074 }
1075 1075
1076 1076 static void
1077 1077 ztest_object_unlock(ztest_ds_t *zd, uint64_t object)
1078 1078 {
1079 1079 rll_t *rll = &zd->zd_object_lock[object & (ZTEST_OBJECT_LOCKS - 1)];
1080 1080
1081 1081 ztest_rll_unlock(rll);
1082 1082 }
1083 1083
1084 1084 static rl_t *
1085 1085 ztest_range_lock(ztest_ds_t *zd, uint64_t object, uint64_t offset,
1086 1086 uint64_t size, rl_type_t type)
1087 1087 {
1088 1088 uint64_t hash = object ^ (offset % (ZTEST_RANGE_LOCKS + 1));
1089 1089 rll_t *rll = &zd->zd_range_lock[hash & (ZTEST_RANGE_LOCKS - 1)];
1090 1090 rl_t *rl;
1091 1091
1092 1092 rl = umem_alloc(sizeof (*rl), UMEM_NOFAIL);
1093 1093 rl->rl_object = object;
1094 1094 rl->rl_offset = offset;
1095 1095 rl->rl_size = size;
1096 1096 rl->rl_lock = rll;
1097 1097
1098 1098 ztest_rll_lock(rll, type);
1099 1099
1100 1100 return (rl);
1101 1101 }
1102 1102
1103 1103 static void
1104 1104 ztest_range_unlock(rl_t *rl)
1105 1105 {
1106 1106 rll_t *rll = rl->rl_lock;
1107 1107
1108 1108 ztest_rll_unlock(rll);
1109 1109
1110 1110 umem_free(rl, sizeof (*rl));
1111 1111 }
1112 1112
1113 1113 static void
1114 1114 ztest_zd_init(ztest_ds_t *zd, ztest_shared_ds_t *szd, objset_t *os)
1115 1115 {
1116 1116 zd->zd_os = os;
1117 1117 zd->zd_zilog = dmu_objset_zil(os);
1118 1118 zd->zd_shared = szd;
1119 1119 dmu_objset_name(os, zd->zd_name);
1120 1120
1121 1121 if (zd->zd_shared != NULL)
1122 1122 zd->zd_shared->zd_seq = 0;
1123 1123
1124 1124 VERIFY(rwlock_init(&zd->zd_zilog_lock, USYNC_THREAD, NULL) == 0);
1125 1125 VERIFY(_mutex_init(&zd->zd_dirobj_lock, USYNC_THREAD, NULL) == 0);
1126 1126
1127 1127 for (int l = 0; l < ZTEST_OBJECT_LOCKS; l++)
1128 1128 ztest_rll_init(&zd->zd_object_lock[l]);
1129 1129
1130 1130 for (int l = 0; l < ZTEST_RANGE_LOCKS; l++)
1131 1131 ztest_rll_init(&zd->zd_range_lock[l]);
1132 1132 }
1133 1133
1134 1134 static void
1135 1135 ztest_zd_fini(ztest_ds_t *zd)
1136 1136 {
1137 1137 VERIFY(_mutex_destroy(&zd->zd_dirobj_lock) == 0);
1138 1138
1139 1139 for (int l = 0; l < ZTEST_OBJECT_LOCKS; l++)
1140 1140 ztest_rll_destroy(&zd->zd_object_lock[l]);
1141 1141
1142 1142 for (int l = 0; l < ZTEST_RANGE_LOCKS; l++)
1143 1143 ztest_rll_destroy(&zd->zd_range_lock[l]);
1144 1144 }
1145 1145
1146 1146 #define TXG_MIGHTWAIT (ztest_random(10) == 0 ? TXG_NOWAIT : TXG_WAIT)
1147 1147
1148 1148 static uint64_t
1149 1149 ztest_tx_assign(dmu_tx_t *tx, uint64_t txg_how, const char *tag)
1150 1150 {
1151 1151 uint64_t txg;
1152 1152 int error;
1153 1153
1154 1154 /*
1155 1155 * Attempt to assign tx to some transaction group.
1156 1156 */
1157 1157 error = dmu_tx_assign(tx, txg_how);
1158 1158 if (error) {
1159 1159 if (error == ERESTART) {
1160 1160 ASSERT(txg_how == TXG_NOWAIT);
1161 1161 dmu_tx_wait(tx);
1162 1162 } else {
1163 1163 ASSERT3U(error, ==, ENOSPC);
1164 1164 ztest_record_enospc(tag);
1165 1165 }
1166 1166 dmu_tx_abort(tx);
1167 1167 return (0);
1168 1168 }
1169 1169 txg = dmu_tx_get_txg(tx);
1170 1170 ASSERT(txg != 0);
1171 1171 return (txg);
1172 1172 }
1173 1173
1174 1174 static void
1175 1175 ztest_pattern_set(void *buf, uint64_t size, uint64_t value)
1176 1176 {
1177 1177 uint64_t *ip = buf;
1178 1178 uint64_t *ip_end = (uint64_t *)((uintptr_t)buf + (uintptr_t)size);
1179 1179
1180 1180 while (ip < ip_end)
1181 1181 *ip++ = value;
1182 1182 }
1183 1183
1184 1184 static boolean_t
1185 1185 ztest_pattern_match(void *buf, uint64_t size, uint64_t value)
1186 1186 {
1187 1187 uint64_t *ip = buf;
1188 1188 uint64_t *ip_end = (uint64_t *)((uintptr_t)buf + (uintptr_t)size);
1189 1189 uint64_t diff = 0;
1190 1190
1191 1191 while (ip < ip_end)
1192 1192 diff |= (value - *ip++);
1193 1193
1194 1194 return (diff == 0);
1195 1195 }
1196 1196
1197 1197 static void
1198 1198 ztest_bt_generate(ztest_block_tag_t *bt, objset_t *os, uint64_t object,
1199 1199 uint64_t offset, uint64_t gen, uint64_t txg, uint64_t crtxg)
1200 1200 {
1201 1201 bt->bt_magic = BT_MAGIC;
1202 1202 bt->bt_objset = dmu_objset_id(os);
1203 1203 bt->bt_object = object;
1204 1204 bt->bt_offset = offset;
1205 1205 bt->bt_gen = gen;
1206 1206 bt->bt_txg = txg;
1207 1207 bt->bt_crtxg = crtxg;
1208 1208 }
1209 1209
1210 1210 static void
1211 1211 ztest_bt_verify(ztest_block_tag_t *bt, objset_t *os, uint64_t object,
1212 1212 uint64_t offset, uint64_t gen, uint64_t txg, uint64_t crtxg)
1213 1213 {
1214 1214 ASSERT(bt->bt_magic == BT_MAGIC);
1215 1215 ASSERT(bt->bt_objset == dmu_objset_id(os));
1216 1216 ASSERT(bt->bt_object == object);
1217 1217 ASSERT(bt->bt_offset == offset);
1218 1218 ASSERT(bt->bt_gen <= gen);
1219 1219 ASSERT(bt->bt_txg <= txg);
1220 1220 ASSERT(bt->bt_crtxg == crtxg);
1221 1221 }
1222 1222
1223 1223 static ztest_block_tag_t *
1224 1224 ztest_bt_bonus(dmu_buf_t *db)
1225 1225 {
1226 1226 dmu_object_info_t doi;
1227 1227 ztest_block_tag_t *bt;
1228 1228
1229 1229 dmu_object_info_from_db(db, &doi);
1230 1230 ASSERT3U(doi.doi_bonus_size, <=, db->db_size);
1231 1231 ASSERT3U(doi.doi_bonus_size, >=, sizeof (*bt));
1232 1232 bt = (void *)((char *)db->db_data + doi.doi_bonus_size - sizeof (*bt));
1233 1233
1234 1234 return (bt);
1235 1235 }
1236 1236
1237 1237 /*
1238 1238 * ZIL logging ops
1239 1239 */
1240 1240
1241 1241 #define lrz_type lr_mode
1242 1242 #define lrz_blocksize lr_uid
1243 1243 #define lrz_ibshift lr_gid
1244 1244 #define lrz_bonustype lr_rdev
1245 1245 #define lrz_bonuslen lr_crtime[1]
1246 1246
1247 1247 static void
1248 1248 ztest_log_create(ztest_ds_t *zd, dmu_tx_t *tx, lr_create_t *lr)
1249 1249 {
1250 1250 char *name = (void *)(lr + 1); /* name follows lr */
1251 1251 size_t namesize = strlen(name) + 1;
1252 1252 itx_t *itx;
1253 1253
1254 1254 if (zil_replaying(zd->zd_zilog, tx))
1255 1255 return;
1256 1256
1257 1257 itx = zil_itx_create(TX_CREATE, sizeof (*lr) + namesize);
1258 1258 bcopy(&lr->lr_common + 1, &itx->itx_lr + 1,
1259 1259 sizeof (*lr) + namesize - sizeof (lr_t));
1260 1260
1261 1261 zil_itx_assign(zd->zd_zilog, itx, tx);
1262 1262 }
1263 1263
1264 1264 static void
1265 1265 ztest_log_remove(ztest_ds_t *zd, dmu_tx_t *tx, lr_remove_t *lr, uint64_t object)
1266 1266 {
1267 1267 char *name = (void *)(lr + 1); /* name follows lr */
1268 1268 size_t namesize = strlen(name) + 1;
1269 1269 itx_t *itx;
1270 1270
1271 1271 if (zil_replaying(zd->zd_zilog, tx))
1272 1272 return;
1273 1273
1274 1274 itx = zil_itx_create(TX_REMOVE, sizeof (*lr) + namesize);
1275 1275 bcopy(&lr->lr_common + 1, &itx->itx_lr + 1,
1276 1276 sizeof (*lr) + namesize - sizeof (lr_t));
1277 1277
1278 1278 itx->itx_oid = object;
1279 1279 zil_itx_assign(zd->zd_zilog, itx, tx);
1280 1280 }
1281 1281
1282 1282 static void
1283 1283 ztest_log_write(ztest_ds_t *zd, dmu_tx_t *tx, lr_write_t *lr)
1284 1284 {
1285 1285 itx_t *itx;
1286 1286 itx_wr_state_t write_state = ztest_random(WR_NUM_STATES);
1287 1287
1288 1288 if (zil_replaying(zd->zd_zilog, tx))
1289 1289 return;
1290 1290
1291 1291 if (lr->lr_length > ZIL_MAX_LOG_DATA)
1292 1292 write_state = WR_INDIRECT;
1293 1293
1294 1294 itx = zil_itx_create(TX_WRITE,
1295 1295 sizeof (*lr) + (write_state == WR_COPIED ? lr->lr_length : 0));
1296 1296
1297 1297 if (write_state == WR_COPIED &&
1298 1298 dmu_read(zd->zd_os, lr->lr_foid, lr->lr_offset, lr->lr_length,
1299 1299 ((lr_write_t *)&itx->itx_lr) + 1, DMU_READ_NO_PREFETCH) != 0) {
1300 1300 zil_itx_destroy(itx);
1301 1301 itx = zil_itx_create(TX_WRITE, sizeof (*lr));
1302 1302 write_state = WR_NEED_COPY;
1303 1303 }
1304 1304 itx->itx_private = zd;
1305 1305 itx->itx_wr_state = write_state;
1306 1306 itx->itx_sync = (ztest_random(8) == 0);
1307 1307 itx->itx_sod += (write_state == WR_NEED_COPY ? lr->lr_length : 0);
1308 1308
1309 1309 bcopy(&lr->lr_common + 1, &itx->itx_lr + 1,
1310 1310 sizeof (*lr) - sizeof (lr_t));
1311 1311
1312 1312 zil_itx_assign(zd->zd_zilog, itx, tx);
1313 1313 }
1314 1314
1315 1315 static void
1316 1316 ztest_log_truncate(ztest_ds_t *zd, dmu_tx_t *tx, lr_truncate_t *lr)
1317 1317 {
1318 1318 itx_t *itx;
1319 1319
1320 1320 if (zil_replaying(zd->zd_zilog, tx))
1321 1321 return;
1322 1322
1323 1323 itx = zil_itx_create(TX_TRUNCATE, sizeof (*lr));
1324 1324 bcopy(&lr->lr_common + 1, &itx->itx_lr + 1,
1325 1325 sizeof (*lr) - sizeof (lr_t));
1326 1326
1327 1327 itx->itx_sync = B_FALSE;
1328 1328 zil_itx_assign(zd->zd_zilog, itx, tx);
1329 1329 }
1330 1330
1331 1331 static void
1332 1332 ztest_log_setattr(ztest_ds_t *zd, dmu_tx_t *tx, lr_setattr_t *lr)
1333 1333 {
1334 1334 itx_t *itx;
1335 1335
1336 1336 if (zil_replaying(zd->zd_zilog, tx))
1337 1337 return;
1338 1338
1339 1339 itx = zil_itx_create(TX_SETATTR, sizeof (*lr));
1340 1340 bcopy(&lr->lr_common + 1, &itx->itx_lr + 1,
1341 1341 sizeof (*lr) - sizeof (lr_t));
1342 1342
1343 1343 itx->itx_sync = B_FALSE;
1344 1344 zil_itx_assign(zd->zd_zilog, itx, tx);
1345 1345 }
1346 1346
1347 1347 /*
1348 1348 * ZIL replay ops
1349 1349 */
1350 1350 static int
1351 1351 ztest_replay_create(ztest_ds_t *zd, lr_create_t *lr, boolean_t byteswap)
1352 1352 {
1353 1353 char *name = (void *)(lr + 1); /* name follows lr */
1354 1354 objset_t *os = zd->zd_os;
1355 1355 ztest_block_tag_t *bbt;
1356 1356 dmu_buf_t *db;
1357 1357 dmu_tx_t *tx;
1358 1358 uint64_t txg;
1359 1359 int error = 0;
1360 1360
1361 1361 if (byteswap)
1362 1362 byteswap_uint64_array(lr, sizeof (*lr));
1363 1363
1364 1364 ASSERT(lr->lr_doid == ZTEST_DIROBJ);
1365 1365 ASSERT(name[0] != '\0');
1366 1366
1367 1367 tx = dmu_tx_create(os);
1368 1368
1369 1369 dmu_tx_hold_zap(tx, lr->lr_doid, B_TRUE, name);
1370 1370
1371 1371 if (lr->lrz_type == DMU_OT_ZAP_OTHER) {
1372 1372 dmu_tx_hold_zap(tx, DMU_NEW_OBJECT, B_TRUE, NULL);
1373 1373 } else {
1374 1374 dmu_tx_hold_bonus(tx, DMU_NEW_OBJECT);
1375 1375 }
1376 1376
1377 1377 txg = ztest_tx_assign(tx, TXG_WAIT, FTAG);
1378 1378 if (txg == 0)
1379 1379 return (ENOSPC);
1380 1380
1381 1381 ASSERT(dmu_objset_zil(os)->zl_replay == !!lr->lr_foid);
1382 1382
1383 1383 if (lr->lrz_type == DMU_OT_ZAP_OTHER) {
1384 1384 if (lr->lr_foid == 0) {
1385 1385 lr->lr_foid = zap_create(os,
1386 1386 lr->lrz_type, lr->lrz_bonustype,
1387 1387 lr->lrz_bonuslen, tx);
1388 1388 } else {
1389 1389 error = zap_create_claim(os, lr->lr_foid,
1390 1390 lr->lrz_type, lr->lrz_bonustype,
1391 1391 lr->lrz_bonuslen, tx);
1392 1392 }
1393 1393 } else {
1394 1394 if (lr->lr_foid == 0) {
1395 1395 lr->lr_foid = dmu_object_alloc(os,
1396 1396 lr->lrz_type, 0, lr->lrz_bonustype,
1397 1397 lr->lrz_bonuslen, tx);
1398 1398 } else {
1399 1399 error = dmu_object_claim(os, lr->lr_foid,
1400 1400 lr->lrz_type, 0, lr->lrz_bonustype,
1401 1401 lr->lrz_bonuslen, tx);
1402 1402 }
1403 1403 }
1404 1404
↓ open down ↓ |
387 lines elided |
↑ open up ↑ |
1405 1405 if (error) {
1406 1406 ASSERT3U(error, ==, EEXIST);
1407 1407 ASSERT(zd->zd_zilog->zl_replay);
1408 1408 dmu_tx_commit(tx);
1409 1409 return (error);
1410 1410 }
1411 1411
1412 1412 ASSERT(lr->lr_foid != 0);
1413 1413
1414 1414 if (lr->lrz_type != DMU_OT_ZAP_OTHER)
1415 - VERIFY3U(0, ==, dmu_object_set_blocksize(os, lr->lr_foid,
1415 + VERIFY0(dmu_object_set_blocksize(os, lr->lr_foid,
1416 1416 lr->lrz_blocksize, lr->lrz_ibshift, tx));
1417 1417
1418 - VERIFY3U(0, ==, dmu_bonus_hold(os, lr->lr_foid, FTAG, &db));
1418 + VERIFY0(dmu_bonus_hold(os, lr->lr_foid, FTAG, &db));
1419 1419 bbt = ztest_bt_bonus(db);
1420 1420 dmu_buf_will_dirty(db, tx);
1421 1421 ztest_bt_generate(bbt, os, lr->lr_foid, -1ULL, lr->lr_gen, txg, txg);
1422 1422 dmu_buf_rele(db, FTAG);
1423 1423
1424 - VERIFY3U(0, ==, zap_add(os, lr->lr_doid, name, sizeof (uint64_t), 1,
1424 + VERIFY0(zap_add(os, lr->lr_doid, name, sizeof (uint64_t), 1,
1425 1425 &lr->lr_foid, tx));
1426 1426
1427 1427 (void) ztest_log_create(zd, tx, lr);
1428 1428
1429 1429 dmu_tx_commit(tx);
1430 1430
1431 1431 return (0);
1432 1432 }
1433 1433
1434 1434 static int
1435 1435 ztest_replay_remove(ztest_ds_t *zd, lr_remove_t *lr, boolean_t byteswap)
1436 1436 {
1437 1437 char *name = (void *)(lr + 1); /* name follows lr */
1438 1438 objset_t *os = zd->zd_os;
↓ open down ↓ |
4 lines elided |
↑ open up ↑ |
1439 1439 dmu_object_info_t doi;
1440 1440 dmu_tx_t *tx;
1441 1441 uint64_t object, txg;
1442 1442
1443 1443 if (byteswap)
1444 1444 byteswap_uint64_array(lr, sizeof (*lr));
1445 1445
1446 1446 ASSERT(lr->lr_doid == ZTEST_DIROBJ);
1447 1447 ASSERT(name[0] != '\0');
1448 1448
1449 - VERIFY3U(0, ==,
1449 + VERIFY0(
1450 1450 zap_lookup(os, lr->lr_doid, name, sizeof (object), 1, &object));
1451 1451 ASSERT(object != 0);
1452 1452
1453 1453 ztest_object_lock(zd, object, RL_WRITER);
1454 1454
1455 - VERIFY3U(0, ==, dmu_object_info(os, object, &doi));
1455 + VERIFY0(dmu_object_info(os, object, &doi));
1456 1456
1457 1457 tx = dmu_tx_create(os);
1458 1458
1459 1459 dmu_tx_hold_zap(tx, lr->lr_doid, B_FALSE, name);
1460 1460 dmu_tx_hold_free(tx, object, 0, DMU_OBJECT_END);
1461 1461
1462 1462 txg = ztest_tx_assign(tx, TXG_WAIT, FTAG);
1463 1463 if (txg == 0) {
1464 1464 ztest_object_unlock(zd, object);
1465 1465 return (ENOSPC);
1466 1466 }
1467 1467
1468 1468 if (doi.doi_type == DMU_OT_ZAP_OTHER) {
1469 - VERIFY3U(0, ==, zap_destroy(os, object, tx));
1469 + VERIFY0(zap_destroy(os, object, tx));
1470 1470 } else {
1471 - VERIFY3U(0, ==, dmu_object_free(os, object, tx));
1471 + VERIFY0(dmu_object_free(os, object, tx));
1472 1472 }
1473 1473
1474 - VERIFY3U(0, ==, zap_remove(os, lr->lr_doid, name, tx));
1474 + VERIFY0(zap_remove(os, lr->lr_doid, name, tx));
1475 1475
1476 1476 (void) ztest_log_remove(zd, tx, lr, object);
1477 1477
1478 1478 dmu_tx_commit(tx);
1479 1479
1480 1480 ztest_object_unlock(zd, object);
1481 1481
1482 1482 return (0);
1483 1483 }
1484 1484
1485 1485 static int
1486 1486 ztest_replay_write(ztest_ds_t *zd, lr_write_t *lr, boolean_t byteswap)
1487 1487 {
1488 1488 objset_t *os = zd->zd_os;
1489 1489 void *data = lr + 1; /* data follows lr */
1490 1490 uint64_t offset, length;
1491 1491 ztest_block_tag_t *bt = data;
1492 1492 ztest_block_tag_t *bbt;
1493 1493 uint64_t gen, txg, lrtxg, crtxg;
1494 1494 dmu_object_info_t doi;
1495 1495 dmu_tx_t *tx;
1496 1496 dmu_buf_t *db;
1497 1497 arc_buf_t *abuf = NULL;
1498 1498 rl_t *rl;
1499 1499
1500 1500 if (byteswap)
1501 1501 byteswap_uint64_array(lr, sizeof (*lr));
1502 1502
1503 1503 offset = lr->lr_offset;
1504 1504 length = lr->lr_length;
1505 1505
1506 1506 /* If it's a dmu_sync() block, write the whole block */
1507 1507 if (lr->lr_common.lrc_reclen == sizeof (lr_write_t)) {
1508 1508 uint64_t blocksize = BP_GET_LSIZE(&lr->lr_blkptr);
1509 1509 if (length < blocksize) {
1510 1510 offset -= offset % blocksize;
1511 1511 length = blocksize;
1512 1512 }
1513 1513 }
↓ open down ↓ |
29 lines elided |
↑ open up ↑ |
1514 1514
1515 1515 if (bt->bt_magic == BSWAP_64(BT_MAGIC))
1516 1516 byteswap_uint64_array(bt, sizeof (*bt));
1517 1517
1518 1518 if (bt->bt_magic != BT_MAGIC)
1519 1519 bt = NULL;
1520 1520
1521 1521 ztest_object_lock(zd, lr->lr_foid, RL_READER);
1522 1522 rl = ztest_range_lock(zd, lr->lr_foid, offset, length, RL_WRITER);
1523 1523
1524 - VERIFY3U(0, ==, dmu_bonus_hold(os, lr->lr_foid, FTAG, &db));
1524 + VERIFY0(dmu_bonus_hold(os, lr->lr_foid, FTAG, &db));
1525 1525
1526 1526 dmu_object_info_from_db(db, &doi);
1527 1527
1528 1528 bbt = ztest_bt_bonus(db);
1529 1529 ASSERT3U(bbt->bt_magic, ==, BT_MAGIC);
1530 1530 gen = bbt->bt_gen;
1531 1531 crtxg = bbt->bt_crtxg;
1532 1532 lrtxg = lr->lr_common.lrc_txg;
1533 1533
1534 1534 tx = dmu_tx_create(os);
1535 1535
1536 1536 dmu_tx_hold_write(tx, lr->lr_foid, offset, length);
1537 1537
1538 1538 if (ztest_random(8) == 0 && length == doi.doi_data_block_size &&
1539 1539 P2PHASE(offset, length) == 0)
1540 1540 abuf = dmu_request_arcbuf(db, length);
1541 1541
1542 1542 txg = ztest_tx_assign(tx, TXG_WAIT, FTAG);
1543 1543 if (txg == 0) {
1544 1544 if (abuf != NULL)
1545 1545 dmu_return_arcbuf(abuf);
1546 1546 dmu_buf_rele(db, FTAG);
1547 1547 ztest_range_unlock(rl);
1548 1548 ztest_object_unlock(zd, lr->lr_foid);
1549 1549 return (ENOSPC);
1550 1550 }
1551 1551
1552 1552 if (bt != NULL) {
1553 1553 /*
1554 1554 * Usually, verify the old data before writing new data --
1555 1555 * but not always, because we also want to verify correct
1556 1556 * behavior when the data was not recently read into cache.
1557 1557 */
1558 1558 ASSERT(offset % doi.doi_data_block_size == 0);
1559 1559 if (ztest_random(4) != 0) {
1560 1560 int prefetch = ztest_random(2) ?
1561 1561 DMU_READ_PREFETCH : DMU_READ_NO_PREFETCH;
1562 1562 ztest_block_tag_t rbt;
1563 1563
1564 1564 VERIFY(dmu_read(os, lr->lr_foid, offset,
1565 1565 sizeof (rbt), &rbt, prefetch) == 0);
1566 1566 if (rbt.bt_magic == BT_MAGIC) {
1567 1567 ztest_bt_verify(&rbt, os, lr->lr_foid,
1568 1568 offset, gen, txg, crtxg);
1569 1569 }
1570 1570 }
1571 1571
1572 1572 /*
1573 1573 * Writes can appear to be newer than the bonus buffer because
1574 1574 * the ztest_get_data() callback does a dmu_read() of the
1575 1575 * open-context data, which may be different than the data
1576 1576 * as it was when the write was generated.
1577 1577 */
1578 1578 if (zd->zd_zilog->zl_replay) {
1579 1579 ztest_bt_verify(bt, os, lr->lr_foid, offset,
1580 1580 MAX(gen, bt->bt_gen), MAX(txg, lrtxg),
1581 1581 bt->bt_crtxg);
1582 1582 }
1583 1583
1584 1584 /*
1585 1585 * Set the bt's gen/txg to the bonus buffer's gen/txg
1586 1586 * so that all of the usual ASSERTs will work.
1587 1587 */
1588 1588 ztest_bt_generate(bt, os, lr->lr_foid, offset, gen, txg, crtxg);
1589 1589 }
1590 1590
1591 1591 if (abuf == NULL) {
1592 1592 dmu_write(os, lr->lr_foid, offset, length, data, tx);
1593 1593 } else {
1594 1594 bcopy(data, abuf->b_data, length);
1595 1595 dmu_assign_arcbuf(db, offset, abuf, tx);
1596 1596 }
1597 1597
1598 1598 (void) ztest_log_write(zd, tx, lr);
1599 1599
1600 1600 dmu_buf_rele(db, FTAG);
1601 1601
1602 1602 dmu_tx_commit(tx);
1603 1603
1604 1604 ztest_range_unlock(rl);
1605 1605 ztest_object_unlock(zd, lr->lr_foid);
1606 1606
1607 1607 return (0);
1608 1608 }
1609 1609
1610 1610 static int
1611 1611 ztest_replay_truncate(ztest_ds_t *zd, lr_truncate_t *lr, boolean_t byteswap)
1612 1612 {
1613 1613 objset_t *os = zd->zd_os;
1614 1614 dmu_tx_t *tx;
1615 1615 uint64_t txg;
1616 1616 rl_t *rl;
1617 1617
1618 1618 if (byteswap)
1619 1619 byteswap_uint64_array(lr, sizeof (*lr));
1620 1620
1621 1621 ztest_object_lock(zd, lr->lr_foid, RL_READER);
1622 1622 rl = ztest_range_lock(zd, lr->lr_foid, lr->lr_offset, lr->lr_length,
1623 1623 RL_WRITER);
1624 1624
1625 1625 tx = dmu_tx_create(os);
1626 1626
1627 1627 dmu_tx_hold_free(tx, lr->lr_foid, lr->lr_offset, lr->lr_length);
1628 1628
1629 1629 txg = ztest_tx_assign(tx, TXG_WAIT, FTAG);
1630 1630 if (txg == 0) {
1631 1631 ztest_range_unlock(rl);
1632 1632 ztest_object_unlock(zd, lr->lr_foid);
1633 1633 return (ENOSPC);
1634 1634 }
1635 1635
1636 1636 VERIFY(dmu_free_range(os, lr->lr_foid, lr->lr_offset,
1637 1637 lr->lr_length, tx) == 0);
1638 1638
1639 1639 (void) ztest_log_truncate(zd, tx, lr);
1640 1640
1641 1641 dmu_tx_commit(tx);
1642 1642
1643 1643 ztest_range_unlock(rl);
1644 1644 ztest_object_unlock(zd, lr->lr_foid);
1645 1645
1646 1646 return (0);
1647 1647 }
1648 1648
1649 1649 static int
1650 1650 ztest_replay_setattr(ztest_ds_t *zd, lr_setattr_t *lr, boolean_t byteswap)
1651 1651 {
1652 1652 objset_t *os = zd->zd_os;
↓ open down ↓ |
118 lines elided |
↑ open up ↑ |
1653 1653 dmu_tx_t *tx;
1654 1654 dmu_buf_t *db;
1655 1655 ztest_block_tag_t *bbt;
1656 1656 uint64_t txg, lrtxg, crtxg;
1657 1657
1658 1658 if (byteswap)
1659 1659 byteswap_uint64_array(lr, sizeof (*lr));
1660 1660
1661 1661 ztest_object_lock(zd, lr->lr_foid, RL_WRITER);
1662 1662
1663 - VERIFY3U(0, ==, dmu_bonus_hold(os, lr->lr_foid, FTAG, &db));
1663 + VERIFY0(dmu_bonus_hold(os, lr->lr_foid, FTAG, &db));
1664 1664
1665 1665 tx = dmu_tx_create(os);
1666 1666 dmu_tx_hold_bonus(tx, lr->lr_foid);
1667 1667
1668 1668 txg = ztest_tx_assign(tx, TXG_WAIT, FTAG);
1669 1669 if (txg == 0) {
1670 1670 dmu_buf_rele(db, FTAG);
1671 1671 ztest_object_unlock(zd, lr->lr_foid);
1672 1672 return (ENOSPC);
1673 1673 }
1674 1674
1675 1675 bbt = ztest_bt_bonus(db);
1676 1676 ASSERT3U(bbt->bt_magic, ==, BT_MAGIC);
1677 1677 crtxg = bbt->bt_crtxg;
1678 1678 lrtxg = lr->lr_common.lrc_txg;
1679 1679
1680 1680 if (zd->zd_zilog->zl_replay) {
1681 1681 ASSERT(lr->lr_size != 0);
1682 1682 ASSERT(lr->lr_mode != 0);
1683 1683 ASSERT(lrtxg != 0);
1684 1684 } else {
1685 1685 /*
1686 1686 * Randomly change the size and increment the generation.
1687 1687 */
1688 1688 lr->lr_size = (ztest_random(db->db_size / sizeof (*bbt)) + 1) *
1689 1689 sizeof (*bbt);
1690 1690 lr->lr_mode = bbt->bt_gen + 1;
1691 1691 ASSERT(lrtxg == 0);
1692 1692 }
1693 1693
↓ open down ↓ |
20 lines elided |
↑ open up ↑ |
1694 1694 /*
1695 1695 * Verify that the current bonus buffer is not newer than our txg.
1696 1696 */
1697 1697 ztest_bt_verify(bbt, os, lr->lr_foid, -1ULL, lr->lr_mode,
1698 1698 MAX(txg, lrtxg), crtxg);
1699 1699
1700 1700 dmu_buf_will_dirty(db, tx);
1701 1701
1702 1702 ASSERT3U(lr->lr_size, >=, sizeof (*bbt));
1703 1703 ASSERT3U(lr->lr_size, <=, db->db_size);
1704 - VERIFY3U(dmu_set_bonus(db, lr->lr_size, tx), ==, 0);
1704 + VERIFY0(dmu_set_bonus(db, lr->lr_size, tx));
1705 1705 bbt = ztest_bt_bonus(db);
1706 1706
1707 1707 ztest_bt_generate(bbt, os, lr->lr_foid, -1ULL, lr->lr_mode, txg, crtxg);
1708 1708
1709 1709 dmu_buf_rele(db, FTAG);
1710 1710
1711 1711 (void) ztest_log_setattr(zd, tx, lr);
1712 1712
1713 1713 dmu_tx_commit(tx);
1714 1714
1715 1715 ztest_object_unlock(zd, lr->lr_foid);
1716 1716
1717 1717 return (0);
1718 1718 }
1719 1719
1720 1720 zil_replay_func_t *ztest_replay_vector[TX_MAX_TYPE] = {
1721 1721 NULL, /* 0 no such transaction type */
1722 1722 ztest_replay_create, /* TX_CREATE */
1723 1723 NULL, /* TX_MKDIR */
1724 1724 NULL, /* TX_MKXATTR */
1725 1725 NULL, /* TX_SYMLINK */
1726 1726 ztest_replay_remove, /* TX_REMOVE */
1727 1727 NULL, /* TX_RMDIR */
1728 1728 NULL, /* TX_LINK */
1729 1729 NULL, /* TX_RENAME */
1730 1730 ztest_replay_write, /* TX_WRITE */
1731 1731 ztest_replay_truncate, /* TX_TRUNCATE */
1732 1732 ztest_replay_setattr, /* TX_SETATTR */
1733 1733 NULL, /* TX_ACL */
1734 1734 NULL, /* TX_CREATE_ACL */
1735 1735 NULL, /* TX_CREATE_ATTR */
1736 1736 NULL, /* TX_CREATE_ACL_ATTR */
1737 1737 NULL, /* TX_MKDIR_ACL */
1738 1738 NULL, /* TX_MKDIR_ATTR */
1739 1739 NULL, /* TX_MKDIR_ACL_ATTR */
1740 1740 NULL, /* TX_WRITE2 */
1741 1741 };
1742 1742
1743 1743 /*
1744 1744 * ZIL get_data callbacks
1745 1745 */
1746 1746
1747 1747 static void
1748 1748 ztest_get_done(zgd_t *zgd, int error)
1749 1749 {
1750 1750 ztest_ds_t *zd = zgd->zgd_private;
1751 1751 uint64_t object = zgd->zgd_rl->rl_object;
1752 1752
1753 1753 if (zgd->zgd_db)
1754 1754 dmu_buf_rele(zgd->zgd_db, zgd);
1755 1755
1756 1756 ztest_range_unlock(zgd->zgd_rl);
1757 1757 ztest_object_unlock(zd, object);
1758 1758
1759 1759 if (error == 0 && zgd->zgd_bp)
1760 1760 zil_add_block(zgd->zgd_zilog, zgd->zgd_bp);
1761 1761
1762 1762 umem_free(zgd, sizeof (*zgd));
1763 1763 }
1764 1764
1765 1765 static int
1766 1766 ztest_get_data(void *arg, lr_write_t *lr, char *buf, zio_t *zio)
1767 1767 {
1768 1768 ztest_ds_t *zd = arg;
1769 1769 objset_t *os = zd->zd_os;
1770 1770 uint64_t object = lr->lr_foid;
1771 1771 uint64_t offset = lr->lr_offset;
1772 1772 uint64_t size = lr->lr_length;
1773 1773 blkptr_t *bp = &lr->lr_blkptr;
1774 1774 uint64_t txg = lr->lr_common.lrc_txg;
1775 1775 uint64_t crtxg;
1776 1776 dmu_object_info_t doi;
1777 1777 dmu_buf_t *db;
1778 1778 zgd_t *zgd;
1779 1779 int error;
1780 1780
1781 1781 ztest_object_lock(zd, object, RL_READER);
1782 1782 error = dmu_bonus_hold(os, object, FTAG, &db);
1783 1783 if (error) {
1784 1784 ztest_object_unlock(zd, object);
1785 1785 return (error);
1786 1786 }
1787 1787
1788 1788 crtxg = ztest_bt_bonus(db)->bt_crtxg;
1789 1789
1790 1790 if (crtxg == 0 || crtxg > txg) {
1791 1791 dmu_buf_rele(db, FTAG);
1792 1792 ztest_object_unlock(zd, object);
1793 1793 return (ENOENT);
1794 1794 }
1795 1795
1796 1796 dmu_object_info_from_db(db, &doi);
1797 1797 dmu_buf_rele(db, FTAG);
1798 1798 db = NULL;
1799 1799
1800 1800 zgd = umem_zalloc(sizeof (*zgd), UMEM_NOFAIL);
1801 1801 zgd->zgd_zilog = zd->zd_zilog;
1802 1802 zgd->zgd_private = zd;
1803 1803
1804 1804 if (buf != NULL) { /* immediate write */
1805 1805 zgd->zgd_rl = ztest_range_lock(zd, object, offset, size,
1806 1806 RL_READER);
1807 1807
1808 1808 error = dmu_read(os, object, offset, size, buf,
1809 1809 DMU_READ_NO_PREFETCH);
1810 1810 ASSERT(error == 0);
1811 1811 } else {
1812 1812 size = doi.doi_data_block_size;
1813 1813 if (ISP2(size)) {
1814 1814 offset = P2ALIGN(offset, size);
1815 1815 } else {
1816 1816 ASSERT(offset < size);
1817 1817 offset = 0;
1818 1818 }
1819 1819
1820 1820 zgd->zgd_rl = ztest_range_lock(zd, object, offset, size,
1821 1821 RL_READER);
1822 1822
1823 1823 error = dmu_buf_hold(os, object, offset, zgd, &db,
1824 1824 DMU_READ_NO_PREFETCH);
1825 1825
1826 1826 if (error == 0) {
1827 1827 zgd->zgd_db = db;
1828 1828 zgd->zgd_bp = bp;
1829 1829
1830 1830 ASSERT(db->db_offset == offset);
1831 1831 ASSERT(db->db_size == size);
1832 1832
1833 1833 error = dmu_sync(zio, lr->lr_common.lrc_txg,
1834 1834 ztest_get_done, zgd);
1835 1835
1836 1836 if (error == 0)
1837 1837 return (0);
1838 1838 }
1839 1839 }
1840 1840
1841 1841 ztest_get_done(zgd, error);
1842 1842
1843 1843 return (error);
1844 1844 }
1845 1845
1846 1846 static void *
1847 1847 ztest_lr_alloc(size_t lrsize, char *name)
1848 1848 {
1849 1849 char *lr;
1850 1850 size_t namesize = name ? strlen(name) + 1 : 0;
1851 1851
1852 1852 lr = umem_zalloc(lrsize + namesize, UMEM_NOFAIL);
1853 1853
1854 1854 if (name)
1855 1855 bcopy(name, lr + lrsize, namesize);
1856 1856
1857 1857 return (lr);
1858 1858 }
1859 1859
1860 1860 void
1861 1861 ztest_lr_free(void *lr, size_t lrsize, char *name)
1862 1862 {
1863 1863 size_t namesize = name ? strlen(name) + 1 : 0;
1864 1864
1865 1865 umem_free(lr, lrsize + namesize);
1866 1866 }
1867 1867
1868 1868 /*
1869 1869 * Lookup a bunch of objects. Returns the number of objects not found.
1870 1870 */
1871 1871 static int
1872 1872 ztest_lookup(ztest_ds_t *zd, ztest_od_t *od, int count)
1873 1873 {
1874 1874 int missing = 0;
1875 1875 int error;
1876 1876
1877 1877 ASSERT(_mutex_held(&zd->zd_dirobj_lock));
1878 1878
1879 1879 for (int i = 0; i < count; i++, od++) {
1880 1880 od->od_object = 0;
1881 1881 error = zap_lookup(zd->zd_os, od->od_dir, od->od_name,
1882 1882 sizeof (uint64_t), 1, &od->od_object);
1883 1883 if (error) {
1884 1884 ASSERT(error == ENOENT);
1885 1885 ASSERT(od->od_object == 0);
↓ open down ↓ |
171 lines elided |
↑ open up ↑ |
1886 1886 missing++;
1887 1887 } else {
1888 1888 dmu_buf_t *db;
1889 1889 ztest_block_tag_t *bbt;
1890 1890 dmu_object_info_t doi;
1891 1891
1892 1892 ASSERT(od->od_object != 0);
1893 1893 ASSERT(missing == 0); /* there should be no gaps */
1894 1894
1895 1895 ztest_object_lock(zd, od->od_object, RL_READER);
1896 - VERIFY3U(0, ==, dmu_bonus_hold(zd->zd_os,
1896 + VERIFY0(dmu_bonus_hold(zd->zd_os,
1897 1897 od->od_object, FTAG, &db));
1898 1898 dmu_object_info_from_db(db, &doi);
1899 1899 bbt = ztest_bt_bonus(db);
1900 1900 ASSERT3U(bbt->bt_magic, ==, BT_MAGIC);
1901 1901 od->od_type = doi.doi_type;
1902 1902 od->od_blocksize = doi.doi_data_block_size;
1903 1903 od->od_gen = bbt->bt_gen;
1904 1904 dmu_buf_rele(db, FTAG);
1905 1905 ztest_object_unlock(zd, od->od_object);
1906 1906 }
1907 1907 }
1908 1908
1909 1909 return (missing);
1910 1910 }
1911 1911
1912 1912 static int
1913 1913 ztest_create(ztest_ds_t *zd, ztest_od_t *od, int count)
1914 1914 {
1915 1915 int missing = 0;
1916 1916
1917 1917 ASSERT(_mutex_held(&zd->zd_dirobj_lock));
1918 1918
1919 1919 for (int i = 0; i < count; i++, od++) {
1920 1920 if (missing) {
1921 1921 od->od_object = 0;
1922 1922 missing++;
1923 1923 continue;
1924 1924 }
1925 1925
1926 1926 lr_create_t *lr = ztest_lr_alloc(sizeof (*lr), od->od_name);
1927 1927
1928 1928 lr->lr_doid = od->od_dir;
1929 1929 lr->lr_foid = 0; /* 0 to allocate, > 0 to claim */
1930 1930 lr->lrz_type = od->od_crtype;
1931 1931 lr->lrz_blocksize = od->od_crblocksize;
1932 1932 lr->lrz_ibshift = ztest_random_ibshift();
1933 1933 lr->lrz_bonustype = DMU_OT_UINT64_OTHER;
1934 1934 lr->lrz_bonuslen = dmu_bonus_max();
1935 1935 lr->lr_gen = od->od_crgen;
1936 1936 lr->lr_crtime[0] = time(NULL);
1937 1937
1938 1938 if (ztest_replay_create(zd, lr, B_FALSE) != 0) {
1939 1939 ASSERT(missing == 0);
1940 1940 od->od_object = 0;
1941 1941 missing++;
1942 1942 } else {
1943 1943 od->od_object = lr->lr_foid;
1944 1944 od->od_type = od->od_crtype;
1945 1945 od->od_blocksize = od->od_crblocksize;
1946 1946 od->od_gen = od->od_crgen;
1947 1947 ASSERT(od->od_object != 0);
1948 1948 }
1949 1949
1950 1950 ztest_lr_free(lr, sizeof (*lr), od->od_name);
1951 1951 }
1952 1952
1953 1953 return (missing);
1954 1954 }
1955 1955
1956 1956 static int
1957 1957 ztest_remove(ztest_ds_t *zd, ztest_od_t *od, int count)
1958 1958 {
1959 1959 int missing = 0;
1960 1960 int error;
1961 1961
1962 1962 ASSERT(_mutex_held(&zd->zd_dirobj_lock));
1963 1963
1964 1964 od += count - 1;
1965 1965
1966 1966 for (int i = count - 1; i >= 0; i--, od--) {
1967 1967 if (missing) {
1968 1968 missing++;
1969 1969 continue;
1970 1970 }
1971 1971
1972 1972 if (od->od_object == 0)
1973 1973 continue;
1974 1974
1975 1975 lr_remove_t *lr = ztest_lr_alloc(sizeof (*lr), od->od_name);
1976 1976
1977 1977 lr->lr_doid = od->od_dir;
1978 1978
1979 1979 if ((error = ztest_replay_remove(zd, lr, B_FALSE)) != 0) {
1980 1980 ASSERT3U(error, ==, ENOSPC);
1981 1981 missing++;
1982 1982 } else {
1983 1983 od->od_object = 0;
1984 1984 }
1985 1985 ztest_lr_free(lr, sizeof (*lr), od->od_name);
1986 1986 }
1987 1987
1988 1988 return (missing);
1989 1989 }
1990 1990
1991 1991 static int
1992 1992 ztest_write(ztest_ds_t *zd, uint64_t object, uint64_t offset, uint64_t size,
1993 1993 void *data)
1994 1994 {
1995 1995 lr_write_t *lr;
1996 1996 int error;
1997 1997
1998 1998 lr = ztest_lr_alloc(sizeof (*lr) + size, NULL);
1999 1999
2000 2000 lr->lr_foid = object;
2001 2001 lr->lr_offset = offset;
2002 2002 lr->lr_length = size;
2003 2003 lr->lr_blkoff = 0;
2004 2004 BP_ZERO(&lr->lr_blkptr);
2005 2005
2006 2006 bcopy(data, lr + 1, size);
2007 2007
2008 2008 error = ztest_replay_write(zd, lr, B_FALSE);
2009 2009
2010 2010 ztest_lr_free(lr, sizeof (*lr) + size, NULL);
2011 2011
2012 2012 return (error);
2013 2013 }
2014 2014
2015 2015 static int
2016 2016 ztest_truncate(ztest_ds_t *zd, uint64_t object, uint64_t offset, uint64_t size)
2017 2017 {
2018 2018 lr_truncate_t *lr;
2019 2019 int error;
2020 2020
2021 2021 lr = ztest_lr_alloc(sizeof (*lr), NULL);
2022 2022
2023 2023 lr->lr_foid = object;
2024 2024 lr->lr_offset = offset;
2025 2025 lr->lr_length = size;
2026 2026
2027 2027 error = ztest_replay_truncate(zd, lr, B_FALSE);
2028 2028
2029 2029 ztest_lr_free(lr, sizeof (*lr), NULL);
2030 2030
2031 2031 return (error);
2032 2032 }
2033 2033
2034 2034 static int
2035 2035 ztest_setattr(ztest_ds_t *zd, uint64_t object)
2036 2036 {
2037 2037 lr_setattr_t *lr;
2038 2038 int error;
2039 2039
2040 2040 lr = ztest_lr_alloc(sizeof (*lr), NULL);
2041 2041
2042 2042 lr->lr_foid = object;
2043 2043 lr->lr_size = 0;
2044 2044 lr->lr_mode = 0;
2045 2045
2046 2046 error = ztest_replay_setattr(zd, lr, B_FALSE);
2047 2047
2048 2048 ztest_lr_free(lr, sizeof (*lr), NULL);
2049 2049
2050 2050 return (error);
2051 2051 }
2052 2052
2053 2053 static void
2054 2054 ztest_prealloc(ztest_ds_t *zd, uint64_t object, uint64_t offset, uint64_t size)
2055 2055 {
2056 2056 objset_t *os = zd->zd_os;
2057 2057 dmu_tx_t *tx;
2058 2058 uint64_t txg;
2059 2059 rl_t *rl;
2060 2060
2061 2061 txg_wait_synced(dmu_objset_pool(os), 0);
2062 2062
2063 2063 ztest_object_lock(zd, object, RL_READER);
2064 2064 rl = ztest_range_lock(zd, object, offset, size, RL_WRITER);
2065 2065
2066 2066 tx = dmu_tx_create(os);
2067 2067
2068 2068 dmu_tx_hold_write(tx, object, offset, size);
2069 2069
2070 2070 txg = ztest_tx_assign(tx, TXG_WAIT, FTAG);
2071 2071
2072 2072 if (txg != 0) {
2073 2073 dmu_prealloc(os, object, offset, size, tx);
2074 2074 dmu_tx_commit(tx);
2075 2075 txg_wait_synced(dmu_objset_pool(os), txg);
2076 2076 } else {
2077 2077 (void) dmu_free_long_range(os, object, offset, size);
2078 2078 }
2079 2079
2080 2080 ztest_range_unlock(rl);
2081 2081 ztest_object_unlock(zd, object);
2082 2082 }
2083 2083
2084 2084 static void
2085 2085 ztest_io(ztest_ds_t *zd, uint64_t object, uint64_t offset)
2086 2086 {
2087 2087 ztest_block_tag_t wbt;
2088 2088 dmu_object_info_t doi;
2089 2089 enum ztest_io_type io_type;
2090 2090 uint64_t blocksize;
2091 2091 void *data;
2092 2092
2093 2093 VERIFY(dmu_object_info(zd->zd_os, object, &doi) == 0);
2094 2094 blocksize = doi.doi_data_block_size;
2095 2095 data = umem_alloc(blocksize, UMEM_NOFAIL);
2096 2096
2097 2097 /*
2098 2098 * Pick an i/o type at random, biased toward writing block tags.
2099 2099 */
2100 2100 io_type = ztest_random(ZTEST_IO_TYPES);
2101 2101 if (ztest_random(2) == 0)
2102 2102 io_type = ZTEST_IO_WRITE_TAG;
2103 2103
2104 2104 (void) rw_rdlock(&zd->zd_zilog_lock);
2105 2105
2106 2106 switch (io_type) {
2107 2107
2108 2108 case ZTEST_IO_WRITE_TAG:
2109 2109 ztest_bt_generate(&wbt, zd->zd_os, object, offset, 0, 0, 0);
2110 2110 (void) ztest_write(zd, object, offset, sizeof (wbt), &wbt);
2111 2111 break;
2112 2112
2113 2113 case ZTEST_IO_WRITE_PATTERN:
2114 2114 (void) memset(data, 'a' + (object + offset) % 5, blocksize);
2115 2115 if (ztest_random(2) == 0) {
2116 2116 /*
2117 2117 * Induce fletcher2 collisions to ensure that
2118 2118 * zio_ddt_collision() detects and resolves them
2119 2119 * when using fletcher2-verify for deduplication.
2120 2120 */
2121 2121 ((uint64_t *)data)[0] ^= 1ULL << 63;
2122 2122 ((uint64_t *)data)[4] ^= 1ULL << 63;
2123 2123 }
2124 2124 (void) ztest_write(zd, object, offset, blocksize, data);
2125 2125 break;
2126 2126
2127 2127 case ZTEST_IO_WRITE_ZEROES:
2128 2128 bzero(data, blocksize);
2129 2129 (void) ztest_write(zd, object, offset, blocksize, data);
2130 2130 break;
2131 2131
2132 2132 case ZTEST_IO_TRUNCATE:
2133 2133 (void) ztest_truncate(zd, object, offset, blocksize);
2134 2134 break;
2135 2135
2136 2136 case ZTEST_IO_SETATTR:
2137 2137 (void) ztest_setattr(zd, object);
2138 2138 break;
2139 2139 }
2140 2140
2141 2141 (void) rw_unlock(&zd->zd_zilog_lock);
2142 2142
2143 2143 umem_free(data, blocksize);
2144 2144 }
2145 2145
2146 2146 /*
2147 2147 * Initialize an object description template.
2148 2148 */
2149 2149 static void
2150 2150 ztest_od_init(ztest_od_t *od, uint64_t id, char *tag, uint64_t index,
2151 2151 dmu_object_type_t type, uint64_t blocksize, uint64_t gen)
2152 2152 {
2153 2153 od->od_dir = ZTEST_DIROBJ;
2154 2154 od->od_object = 0;
2155 2155
2156 2156 od->od_crtype = type;
2157 2157 od->od_crblocksize = blocksize ? blocksize : ztest_random_blocksize();
2158 2158 od->od_crgen = gen;
2159 2159
2160 2160 od->od_type = DMU_OT_NONE;
2161 2161 od->od_blocksize = 0;
2162 2162 od->od_gen = 0;
2163 2163
2164 2164 (void) snprintf(od->od_name, sizeof (od->od_name), "%s(%lld)[%llu]",
2165 2165 tag, (int64_t)id, index);
2166 2166 }
2167 2167
2168 2168 /*
2169 2169 * Lookup or create the objects for a test using the od template.
2170 2170 * If the objects do not all exist, or if 'remove' is specified,
2171 2171 * remove any existing objects and create new ones. Otherwise,
2172 2172 * use the existing objects.
2173 2173 */
2174 2174 static int
2175 2175 ztest_object_init(ztest_ds_t *zd, ztest_od_t *od, size_t size, boolean_t remove)
2176 2176 {
2177 2177 int count = size / sizeof (*od);
2178 2178 int rv = 0;
2179 2179
2180 2180 VERIFY(mutex_lock(&zd->zd_dirobj_lock) == 0);
2181 2181 if ((ztest_lookup(zd, od, count) != 0 || remove) &&
2182 2182 (ztest_remove(zd, od, count) != 0 ||
2183 2183 ztest_create(zd, od, count) != 0))
2184 2184 rv = -1;
2185 2185 zd->zd_od = od;
2186 2186 VERIFY(mutex_unlock(&zd->zd_dirobj_lock) == 0);
2187 2187
2188 2188 return (rv);
2189 2189 }
2190 2190
2191 2191 /* ARGSUSED */
2192 2192 void
2193 2193 ztest_zil_commit(ztest_ds_t *zd, uint64_t id)
2194 2194 {
2195 2195 zilog_t *zilog = zd->zd_zilog;
2196 2196
2197 2197 (void) rw_rdlock(&zd->zd_zilog_lock);
2198 2198
2199 2199 zil_commit(zilog, ztest_random(ZTEST_OBJECTS));
2200 2200
2201 2201 /*
2202 2202 * Remember the committed values in zd, which is in parent/child
2203 2203 * shared memory. If we die, the next iteration of ztest_run()
2204 2204 * will verify that the log really does contain this record.
2205 2205 */
2206 2206 mutex_enter(&zilog->zl_lock);
2207 2207 ASSERT(zd->zd_shared != NULL);
2208 2208 ASSERT3U(zd->zd_shared->zd_seq, <=, zilog->zl_commit_lr_seq);
2209 2209 zd->zd_shared->zd_seq = zilog->zl_commit_lr_seq;
2210 2210 mutex_exit(&zilog->zl_lock);
2211 2211
2212 2212 (void) rw_unlock(&zd->zd_zilog_lock);
2213 2213 }
2214 2214
2215 2215 /*
2216 2216 * This function is designed to simulate the operations that occur during a
2217 2217 * mount/unmount operation. We hold the dataset across these operations in an
2218 2218 * attempt to expose any implicit assumptions about ZIL management.
2219 2219 */
2220 2220 /* ARGSUSED */
2221 2221 void
2222 2222 ztest_zil_remount(ztest_ds_t *zd, uint64_t id)
2223 2223 {
2224 2224 objset_t *os = zd->zd_os;
2225 2225
2226 2226 (void) rw_wrlock(&zd->zd_zilog_lock);
2227 2227
2228 2228 /* zfsvfs_teardown() */
2229 2229 zil_close(zd->zd_zilog);
2230 2230
2231 2231 /* zfsvfs_setup() */
2232 2232 VERIFY(zil_open(os, ztest_get_data) == zd->zd_zilog);
2233 2233 zil_replay(os, zd, ztest_replay_vector);
2234 2234
2235 2235 (void) rw_unlock(&zd->zd_zilog_lock);
2236 2236 }
2237 2237
2238 2238 /*
2239 2239 * Verify that we can't destroy an active pool, create an existing pool,
2240 2240 * or create a pool with a bad vdev spec.
2241 2241 */
2242 2242 /* ARGSUSED */
2243 2243 void
2244 2244 ztest_spa_create_destroy(ztest_ds_t *zd, uint64_t id)
2245 2245 {
2246 2246 ztest_shared_opts_t *zo = &ztest_opts;
2247 2247 spa_t *spa;
2248 2248 nvlist_t *nvroot;
2249 2249
2250 2250 /*
2251 2251 * Attempt to create using a bad file.
2252 2252 */
2253 2253 nvroot = make_vdev_root("/dev/bogus", NULL, 0, 0, 0, 0, 0, 1);
2254 2254 VERIFY3U(ENOENT, ==,
2255 2255 spa_create("ztest_bad_file", nvroot, NULL, NULL));
2256 2256 nvlist_free(nvroot);
2257 2257
2258 2258 /*
2259 2259 * Attempt to create using a bad mirror.
2260 2260 */
2261 2261 nvroot = make_vdev_root("/dev/bogus", NULL, 0, 0, 0, 0, 2, 1);
2262 2262 VERIFY3U(ENOENT, ==,
2263 2263 spa_create("ztest_bad_mirror", nvroot, NULL, NULL));
↓ open down ↓ |
357 lines elided |
↑ open up ↑ |
2264 2264 nvlist_free(nvroot);
2265 2265
2266 2266 /*
2267 2267 * Attempt to create an existing pool. It shouldn't matter
2268 2268 * what's in the nvroot; we should fail with EEXIST.
2269 2269 */
2270 2270 (void) rw_rdlock(&ztest_name_lock);
2271 2271 nvroot = make_vdev_root("/dev/bogus", NULL, 0, 0, 0, 0, 0, 1);
2272 2272 VERIFY3U(EEXIST, ==, spa_create(zo->zo_pool, nvroot, NULL, NULL));
2273 2273 nvlist_free(nvroot);
2274 - VERIFY3U(0, ==, spa_open(zo->zo_pool, &spa, FTAG));
2274 + VERIFY0(spa_open(zo->zo_pool, &spa, FTAG));
2275 2275 VERIFY3U(EBUSY, ==, spa_destroy(zo->zo_pool));
2276 2276 spa_close(spa, FTAG);
2277 2277
2278 2278 (void) rw_unlock(&ztest_name_lock);
2279 2279 }
2280 2280
2281 2281 static vdev_t *
2282 2282 vdev_lookup_by_path(vdev_t *vd, const char *path)
2283 2283 {
2284 2284 vdev_t *mvd;
2285 2285
2286 2286 if (vd->vdev_path != NULL && strcmp(path, vd->vdev_path) == 0)
2287 2287 return (vd);
2288 2288
2289 2289 for (int c = 0; c < vd->vdev_children; c++)
2290 2290 if ((mvd = vdev_lookup_by_path(vd->vdev_child[c], path)) !=
2291 2291 NULL)
2292 2292 return (mvd);
2293 2293
2294 2294 return (NULL);
2295 2295 }
2296 2296
2297 2297 /*
2298 2298 * Find the first available hole which can be used as a top-level.
2299 2299 */
2300 2300 int
2301 2301 find_vdev_hole(spa_t *spa)
2302 2302 {
2303 2303 vdev_t *rvd = spa->spa_root_vdev;
2304 2304 int c;
2305 2305
2306 2306 ASSERT(spa_config_held(spa, SCL_VDEV, RW_READER) == SCL_VDEV);
2307 2307
2308 2308 for (c = 0; c < rvd->vdev_children; c++) {
2309 2309 vdev_t *cvd = rvd->vdev_child[c];
2310 2310
2311 2311 if (cvd->vdev_ishole)
2312 2312 break;
2313 2313 }
2314 2314 return (c);
2315 2315 }
2316 2316
2317 2317 /*
2318 2318 * Verify that vdev_add() works as expected.
2319 2319 */
2320 2320 /* ARGSUSED */
2321 2321 void
2322 2322 ztest_vdev_add_remove(ztest_ds_t *zd, uint64_t id)
2323 2323 {
2324 2324 ztest_shared_t *zs = ztest_shared;
2325 2325 spa_t *spa = ztest_spa;
2326 2326 uint64_t leaves;
2327 2327 uint64_t guid;
2328 2328 nvlist_t *nvroot;
2329 2329 int error;
2330 2330
2331 2331 VERIFY(mutex_lock(&ztest_vdev_lock) == 0);
2332 2332 leaves =
2333 2333 MAX(zs->zs_mirrors + zs->zs_splits, 1) * ztest_opts.zo_raidz;
2334 2334
2335 2335 spa_config_enter(spa, SCL_VDEV, FTAG, RW_READER);
2336 2336
2337 2337 ztest_shared->zs_vdev_next_leaf = find_vdev_hole(spa) * leaves;
2338 2338
2339 2339 /*
2340 2340 * If we have slogs then remove them 1/4 of the time.
2341 2341 */
2342 2342 if (spa_has_slogs(spa) && ztest_random(4) == 0) {
2343 2343 /*
2344 2344 * Grab the guid from the head of the log class rotor.
2345 2345 */
2346 2346 guid = spa_log_class(spa)->mc_rotor->mg_vd->vdev_guid;
2347 2347
2348 2348 spa_config_exit(spa, SCL_VDEV, FTAG);
2349 2349
2350 2350 /*
2351 2351 * We have to grab the zs_name_lock as writer to
2352 2352 * prevent a race between removing a slog (dmu_objset_find)
2353 2353 * and destroying a dataset. Removing the slog will
2354 2354 * grab a reference on the dataset which may cause
2355 2355 * dmu_objset_destroy() to fail with EBUSY thus
2356 2356 * leaving the dataset in an inconsistent state.
2357 2357 */
2358 2358 VERIFY(rw_wrlock(&ztest_name_lock) == 0);
2359 2359 error = spa_vdev_remove(spa, guid, B_FALSE);
2360 2360 VERIFY(rw_unlock(&ztest_name_lock) == 0);
2361 2361
2362 2362 if (error && error != EEXIST)
2363 2363 fatal(0, "spa_vdev_remove() = %d", error);
2364 2364 } else {
2365 2365 spa_config_exit(spa, SCL_VDEV, FTAG);
2366 2366
2367 2367 /*
2368 2368 * Make 1/4 of the devices be log devices.
2369 2369 */
2370 2370 nvroot = make_vdev_root(NULL, NULL,
2371 2371 ztest_opts.zo_vdev_size, 0,
2372 2372 ztest_random(4) == 0, ztest_opts.zo_raidz,
2373 2373 zs->zs_mirrors, 1);
2374 2374
2375 2375 error = spa_vdev_add(spa, nvroot);
2376 2376 nvlist_free(nvroot);
2377 2377
2378 2378 if (error == ENOSPC)
2379 2379 ztest_record_enospc("spa_vdev_add");
2380 2380 else if (error != 0)
2381 2381 fatal(0, "spa_vdev_add() = %d", error);
2382 2382 }
2383 2383
2384 2384 VERIFY(mutex_unlock(&ztest_vdev_lock) == 0);
2385 2385 }
2386 2386
2387 2387 /*
2388 2388 * Verify that adding/removing aux devices (l2arc, hot spare) works as expected.
2389 2389 */
2390 2390 /* ARGSUSED */
2391 2391 void
2392 2392 ztest_vdev_aux_add_remove(ztest_ds_t *zd, uint64_t id)
2393 2393 {
2394 2394 ztest_shared_t *zs = ztest_shared;
2395 2395 spa_t *spa = ztest_spa;
2396 2396 vdev_t *rvd = spa->spa_root_vdev;
2397 2397 spa_aux_vdev_t *sav;
2398 2398 char *aux;
2399 2399 uint64_t guid = 0;
2400 2400 int error;
2401 2401
2402 2402 if (ztest_random(2) == 0) {
2403 2403 sav = &spa->spa_spares;
2404 2404 aux = ZPOOL_CONFIG_SPARES;
2405 2405 } else {
2406 2406 sav = &spa->spa_l2cache;
2407 2407 aux = ZPOOL_CONFIG_L2CACHE;
2408 2408 }
2409 2409
2410 2410 VERIFY(mutex_lock(&ztest_vdev_lock) == 0);
2411 2411
2412 2412 spa_config_enter(spa, SCL_VDEV, FTAG, RW_READER);
2413 2413
2414 2414 if (sav->sav_count != 0 && ztest_random(4) == 0) {
2415 2415 /*
2416 2416 * Pick a random device to remove.
2417 2417 */
2418 2418 guid = sav->sav_vdevs[ztest_random(sav->sav_count)]->vdev_guid;
2419 2419 } else {
2420 2420 /*
2421 2421 * Find an unused device we can add.
2422 2422 */
2423 2423 zs->zs_vdev_aux = 0;
2424 2424 for (;;) {
2425 2425 char path[MAXPATHLEN];
2426 2426 int c;
2427 2427 (void) snprintf(path, sizeof (path), ztest_aux_template,
2428 2428 ztest_opts.zo_dir, ztest_opts.zo_pool, aux,
2429 2429 zs->zs_vdev_aux);
2430 2430 for (c = 0; c < sav->sav_count; c++)
2431 2431 if (strcmp(sav->sav_vdevs[c]->vdev_path,
2432 2432 path) == 0)
2433 2433 break;
2434 2434 if (c == sav->sav_count &&
2435 2435 vdev_lookup_by_path(rvd, path) == NULL)
2436 2436 break;
2437 2437 zs->zs_vdev_aux++;
2438 2438 }
2439 2439 }
2440 2440
2441 2441 spa_config_exit(spa, SCL_VDEV, FTAG);
2442 2442
2443 2443 if (guid == 0) {
2444 2444 /*
2445 2445 * Add a new device.
2446 2446 */
2447 2447 nvlist_t *nvroot = make_vdev_root(NULL, aux,
2448 2448 (ztest_opts.zo_vdev_size * 5) / 4, 0, 0, 0, 0, 1);
2449 2449 error = spa_vdev_add(spa, nvroot);
2450 2450 if (error != 0)
2451 2451 fatal(0, "spa_vdev_add(%p) = %d", nvroot, error);
2452 2452 nvlist_free(nvroot);
2453 2453 } else {
2454 2454 /*
2455 2455 * Remove an existing device. Sometimes, dirty its
2456 2456 * vdev state first to make sure we handle removal
2457 2457 * of devices that have pending state changes.
2458 2458 */
2459 2459 if (ztest_random(2) == 0)
2460 2460 (void) vdev_online(spa, guid, 0, NULL);
2461 2461
2462 2462 error = spa_vdev_remove(spa, guid, B_FALSE);
2463 2463 if (error != 0 && error != EBUSY)
2464 2464 fatal(0, "spa_vdev_remove(%llu) = %d", guid, error);
2465 2465 }
2466 2466
2467 2467 VERIFY(mutex_unlock(&ztest_vdev_lock) == 0);
2468 2468 }
2469 2469
2470 2470 /*
2471 2471 * split a pool if it has mirror tlvdevs
2472 2472 */
2473 2473 /* ARGSUSED */
2474 2474 void
2475 2475 ztest_split_pool(ztest_ds_t *zd, uint64_t id)
2476 2476 {
2477 2477 ztest_shared_t *zs = ztest_shared;
2478 2478 spa_t *spa = ztest_spa;
2479 2479 vdev_t *rvd = spa->spa_root_vdev;
2480 2480 nvlist_t *tree, **child, *config, *split, **schild;
2481 2481 uint_t c, children, schildren = 0, lastlogid = 0;
2482 2482 int error = 0;
2483 2483
2484 2484 VERIFY(mutex_lock(&ztest_vdev_lock) == 0);
2485 2485
2486 2486 /* ensure we have a useable config; mirrors of raidz aren't supported */
2487 2487 if (zs->zs_mirrors < 3 || ztest_opts.zo_raidz > 1) {
2488 2488 VERIFY(mutex_unlock(&ztest_vdev_lock) == 0);
2489 2489 return;
2490 2490 }
2491 2491
2492 2492 /* clean up the old pool, if any */
2493 2493 (void) spa_destroy("splitp");
2494 2494
2495 2495 spa_config_enter(spa, SCL_VDEV, FTAG, RW_READER);
2496 2496
2497 2497 /* generate a config from the existing config */
2498 2498 mutex_enter(&spa->spa_props_lock);
2499 2499 VERIFY(nvlist_lookup_nvlist(spa->spa_config, ZPOOL_CONFIG_VDEV_TREE,
2500 2500 &tree) == 0);
2501 2501 mutex_exit(&spa->spa_props_lock);
2502 2502
2503 2503 VERIFY(nvlist_lookup_nvlist_array(tree, ZPOOL_CONFIG_CHILDREN, &child,
2504 2504 &children) == 0);
2505 2505
2506 2506 schild = malloc(rvd->vdev_children * sizeof (nvlist_t *));
2507 2507 for (c = 0; c < children; c++) {
2508 2508 vdev_t *tvd = rvd->vdev_child[c];
2509 2509 nvlist_t **mchild;
2510 2510 uint_t mchildren;
2511 2511
2512 2512 if (tvd->vdev_islog || tvd->vdev_ops == &vdev_hole_ops) {
2513 2513 VERIFY(nvlist_alloc(&schild[schildren], NV_UNIQUE_NAME,
2514 2514 0) == 0);
2515 2515 VERIFY(nvlist_add_string(schild[schildren],
2516 2516 ZPOOL_CONFIG_TYPE, VDEV_TYPE_HOLE) == 0);
2517 2517 VERIFY(nvlist_add_uint64(schild[schildren],
2518 2518 ZPOOL_CONFIG_IS_HOLE, 1) == 0);
2519 2519 if (lastlogid == 0)
2520 2520 lastlogid = schildren;
2521 2521 ++schildren;
2522 2522 continue;
2523 2523 }
2524 2524 lastlogid = 0;
2525 2525 VERIFY(nvlist_lookup_nvlist_array(child[c],
2526 2526 ZPOOL_CONFIG_CHILDREN, &mchild, &mchildren) == 0);
2527 2527 VERIFY(nvlist_dup(mchild[0], &schild[schildren++], 0) == 0);
2528 2528 }
2529 2529
2530 2530 /* OK, create a config that can be used to split */
2531 2531 VERIFY(nvlist_alloc(&split, NV_UNIQUE_NAME, 0) == 0);
2532 2532 VERIFY(nvlist_add_string(split, ZPOOL_CONFIG_TYPE,
2533 2533 VDEV_TYPE_ROOT) == 0);
2534 2534 VERIFY(nvlist_add_nvlist_array(split, ZPOOL_CONFIG_CHILDREN, schild,
2535 2535 lastlogid != 0 ? lastlogid : schildren) == 0);
2536 2536
2537 2537 VERIFY(nvlist_alloc(&config, NV_UNIQUE_NAME, 0) == 0);
2538 2538 VERIFY(nvlist_add_nvlist(config, ZPOOL_CONFIG_VDEV_TREE, split) == 0);
2539 2539
2540 2540 for (c = 0; c < schildren; c++)
2541 2541 nvlist_free(schild[c]);
2542 2542 free(schild);
2543 2543 nvlist_free(split);
2544 2544
2545 2545 spa_config_exit(spa, SCL_VDEV, FTAG);
2546 2546
2547 2547 (void) rw_wrlock(&ztest_name_lock);
2548 2548 error = spa_vdev_split_mirror(spa, "splitp", config, NULL, B_FALSE);
2549 2549 (void) rw_unlock(&ztest_name_lock);
2550 2550
2551 2551 nvlist_free(config);
2552 2552
2553 2553 if (error == 0) {
2554 2554 (void) printf("successful split - results:\n");
2555 2555 mutex_enter(&spa_namespace_lock);
2556 2556 show_pool_stats(spa);
2557 2557 show_pool_stats(spa_lookup("splitp"));
2558 2558 mutex_exit(&spa_namespace_lock);
2559 2559 ++zs->zs_splits;
2560 2560 --zs->zs_mirrors;
2561 2561 }
2562 2562 VERIFY(mutex_unlock(&ztest_vdev_lock) == 0);
2563 2563
2564 2564 }
2565 2565
2566 2566 /*
2567 2567 * Verify that we can attach and detach devices.
2568 2568 */
2569 2569 /* ARGSUSED */
2570 2570 void
2571 2571 ztest_vdev_attach_detach(ztest_ds_t *zd, uint64_t id)
2572 2572 {
2573 2573 ztest_shared_t *zs = ztest_shared;
2574 2574 spa_t *spa = ztest_spa;
2575 2575 spa_aux_vdev_t *sav = &spa->spa_spares;
2576 2576 vdev_t *rvd = spa->spa_root_vdev;
2577 2577 vdev_t *oldvd, *newvd, *pvd;
2578 2578 nvlist_t *root;
2579 2579 uint64_t leaves;
2580 2580 uint64_t leaf, top;
2581 2581 uint64_t ashift = ztest_get_ashift();
2582 2582 uint64_t oldguid, pguid;
2583 2583 size_t oldsize, newsize;
2584 2584 char oldpath[MAXPATHLEN], newpath[MAXPATHLEN];
2585 2585 int replacing;
2586 2586 int oldvd_has_siblings = B_FALSE;
2587 2587 int newvd_is_spare = B_FALSE;
2588 2588 int oldvd_is_log;
2589 2589 int error, expected_error;
2590 2590
2591 2591 VERIFY(mutex_lock(&ztest_vdev_lock) == 0);
2592 2592 leaves = MAX(zs->zs_mirrors, 1) * ztest_opts.zo_raidz;
2593 2593
2594 2594 spa_config_enter(spa, SCL_VDEV, FTAG, RW_READER);
2595 2595
2596 2596 /*
2597 2597 * Decide whether to do an attach or a replace.
2598 2598 */
2599 2599 replacing = ztest_random(2);
2600 2600
2601 2601 /*
2602 2602 * Pick a random top-level vdev.
2603 2603 */
2604 2604 top = ztest_random_vdev_top(spa, B_TRUE);
2605 2605
2606 2606 /*
2607 2607 * Pick a random leaf within it.
2608 2608 */
2609 2609 leaf = ztest_random(leaves);
2610 2610
2611 2611 /*
2612 2612 * Locate this vdev.
2613 2613 */
2614 2614 oldvd = rvd->vdev_child[top];
2615 2615 if (zs->zs_mirrors >= 1) {
2616 2616 ASSERT(oldvd->vdev_ops == &vdev_mirror_ops);
2617 2617 ASSERT(oldvd->vdev_children >= zs->zs_mirrors);
2618 2618 oldvd = oldvd->vdev_child[leaf / ztest_opts.zo_raidz];
2619 2619 }
2620 2620 if (ztest_opts.zo_raidz > 1) {
2621 2621 ASSERT(oldvd->vdev_ops == &vdev_raidz_ops);
2622 2622 ASSERT(oldvd->vdev_children == ztest_opts.zo_raidz);
2623 2623 oldvd = oldvd->vdev_child[leaf % ztest_opts.zo_raidz];
2624 2624 }
2625 2625
2626 2626 /*
2627 2627 * If we're already doing an attach or replace, oldvd may be a
2628 2628 * mirror vdev -- in which case, pick a random child.
2629 2629 */
2630 2630 while (oldvd->vdev_children != 0) {
2631 2631 oldvd_has_siblings = B_TRUE;
2632 2632 ASSERT(oldvd->vdev_children >= 2);
2633 2633 oldvd = oldvd->vdev_child[ztest_random(oldvd->vdev_children)];
2634 2634 }
2635 2635
2636 2636 oldguid = oldvd->vdev_guid;
2637 2637 oldsize = vdev_get_min_asize(oldvd);
2638 2638 oldvd_is_log = oldvd->vdev_top->vdev_islog;
2639 2639 (void) strcpy(oldpath, oldvd->vdev_path);
2640 2640 pvd = oldvd->vdev_parent;
2641 2641 pguid = pvd->vdev_guid;
2642 2642
2643 2643 /*
2644 2644 * If oldvd has siblings, then half of the time, detach it.
2645 2645 */
2646 2646 if (oldvd_has_siblings && ztest_random(2) == 0) {
2647 2647 spa_config_exit(spa, SCL_VDEV, FTAG);
2648 2648 error = spa_vdev_detach(spa, oldguid, pguid, B_FALSE);
2649 2649 if (error != 0 && error != ENODEV && error != EBUSY &&
2650 2650 error != ENOTSUP)
2651 2651 fatal(0, "detach (%s) returned %d", oldpath, error);
2652 2652 VERIFY(mutex_unlock(&ztest_vdev_lock) == 0);
2653 2653 return;
2654 2654 }
2655 2655
2656 2656 /*
2657 2657 * For the new vdev, choose with equal probability between the two
2658 2658 * standard paths (ending in either 'a' or 'b') or a random hot spare.
2659 2659 */
2660 2660 if (sav->sav_count != 0 && ztest_random(3) == 0) {
2661 2661 newvd = sav->sav_vdevs[ztest_random(sav->sav_count)];
2662 2662 newvd_is_spare = B_TRUE;
2663 2663 (void) strcpy(newpath, newvd->vdev_path);
2664 2664 } else {
2665 2665 (void) snprintf(newpath, sizeof (newpath), ztest_dev_template,
2666 2666 ztest_opts.zo_dir, ztest_opts.zo_pool,
2667 2667 top * leaves + leaf);
2668 2668 if (ztest_random(2) == 0)
2669 2669 newpath[strlen(newpath) - 1] = 'b';
2670 2670 newvd = vdev_lookup_by_path(rvd, newpath);
2671 2671 }
2672 2672
2673 2673 if (newvd) {
2674 2674 newsize = vdev_get_min_asize(newvd);
2675 2675 } else {
2676 2676 /*
2677 2677 * Make newsize a little bigger or smaller than oldsize.
2678 2678 * If it's smaller, the attach should fail.
2679 2679 * If it's larger, and we're doing a replace,
2680 2680 * we should get dynamic LUN growth when we're done.
2681 2681 */
2682 2682 newsize = 10 * oldsize / (9 + ztest_random(3));
2683 2683 }
2684 2684
2685 2685 /*
2686 2686 * If pvd is not a mirror or root, the attach should fail with ENOTSUP,
2687 2687 * unless it's a replace; in that case any non-replacing parent is OK.
2688 2688 *
2689 2689 * If newvd is already part of the pool, it should fail with EBUSY.
2690 2690 *
2691 2691 * If newvd is too small, it should fail with EOVERFLOW.
2692 2692 */
2693 2693 if (pvd->vdev_ops != &vdev_mirror_ops &&
2694 2694 pvd->vdev_ops != &vdev_root_ops && (!replacing ||
2695 2695 pvd->vdev_ops == &vdev_replacing_ops ||
2696 2696 pvd->vdev_ops == &vdev_spare_ops))
2697 2697 expected_error = ENOTSUP;
2698 2698 else if (newvd_is_spare && (!replacing || oldvd_is_log))
2699 2699 expected_error = ENOTSUP;
2700 2700 else if (newvd == oldvd)
2701 2701 expected_error = replacing ? 0 : EBUSY;
2702 2702 else if (vdev_lookup_by_path(rvd, newpath) != NULL)
2703 2703 expected_error = EBUSY;
2704 2704 else if (newsize < oldsize)
2705 2705 expected_error = EOVERFLOW;
2706 2706 else if (ashift > oldvd->vdev_top->vdev_ashift)
2707 2707 expected_error = EDOM;
2708 2708 else
2709 2709 expected_error = 0;
2710 2710
2711 2711 spa_config_exit(spa, SCL_VDEV, FTAG);
2712 2712
2713 2713 /*
2714 2714 * Build the nvlist describing newpath.
2715 2715 */
2716 2716 root = make_vdev_root(newpath, NULL, newvd == NULL ? newsize : 0,
2717 2717 ashift, 0, 0, 0, 1);
2718 2718
2719 2719 error = spa_vdev_attach(spa, oldguid, root, replacing);
2720 2720
2721 2721 nvlist_free(root);
2722 2722
2723 2723 /*
2724 2724 * If our parent was the replacing vdev, but the replace completed,
2725 2725 * then instead of failing with ENOTSUP we may either succeed,
2726 2726 * fail with ENODEV, or fail with EOVERFLOW.
2727 2727 */
2728 2728 if (expected_error == ENOTSUP &&
2729 2729 (error == 0 || error == ENODEV || error == EOVERFLOW))
2730 2730 expected_error = error;
2731 2731
2732 2732 /*
2733 2733 * If someone grew the LUN, the replacement may be too small.
2734 2734 */
2735 2735 if (error == EOVERFLOW || error == EBUSY)
2736 2736 expected_error = error;
2737 2737
2738 2738 /* XXX workaround 6690467 */
2739 2739 if (error != expected_error && expected_error != EBUSY) {
2740 2740 fatal(0, "attach (%s %llu, %s %llu, %d) "
2741 2741 "returned %d, expected %d",
2742 2742 oldpath, (longlong_t)oldsize, newpath,
2743 2743 (longlong_t)newsize, replacing, error, expected_error);
2744 2744 }
2745 2745
2746 2746 VERIFY(mutex_unlock(&ztest_vdev_lock) == 0);
2747 2747 }
2748 2748
2749 2749 /*
2750 2750 * Callback function which expands the physical size of the vdev.
2751 2751 */
2752 2752 vdev_t *
2753 2753 grow_vdev(vdev_t *vd, void *arg)
2754 2754 {
2755 2755 spa_t *spa = vd->vdev_spa;
2756 2756 size_t *newsize = arg;
2757 2757 size_t fsize;
2758 2758 int fd;
2759 2759
2760 2760 ASSERT(spa_config_held(spa, SCL_STATE, RW_READER) == SCL_STATE);
2761 2761 ASSERT(vd->vdev_ops->vdev_op_leaf);
2762 2762
2763 2763 if ((fd = open(vd->vdev_path, O_RDWR)) == -1)
2764 2764 return (vd);
2765 2765
2766 2766 fsize = lseek(fd, 0, SEEK_END);
2767 2767 (void) ftruncate(fd, *newsize);
2768 2768
2769 2769 if (ztest_opts.zo_verbose >= 6) {
2770 2770 (void) printf("%s grew from %lu to %lu bytes\n",
2771 2771 vd->vdev_path, (ulong_t)fsize, (ulong_t)*newsize);
2772 2772 }
2773 2773 (void) close(fd);
2774 2774 return (NULL);
2775 2775 }
2776 2776
2777 2777 /*
2778 2778 * Callback function which expands a given vdev by calling vdev_online().
2779 2779 */
2780 2780 /* ARGSUSED */
2781 2781 vdev_t *
2782 2782 online_vdev(vdev_t *vd, void *arg)
2783 2783 {
2784 2784 spa_t *spa = vd->vdev_spa;
2785 2785 vdev_t *tvd = vd->vdev_top;
2786 2786 uint64_t guid = vd->vdev_guid;
2787 2787 uint64_t generation = spa->spa_config_generation + 1;
2788 2788 vdev_state_t newstate = VDEV_STATE_UNKNOWN;
2789 2789 int error;
2790 2790
2791 2791 ASSERT(spa_config_held(spa, SCL_STATE, RW_READER) == SCL_STATE);
2792 2792 ASSERT(vd->vdev_ops->vdev_op_leaf);
2793 2793
2794 2794 /* Calling vdev_online will initialize the new metaslabs */
2795 2795 spa_config_exit(spa, SCL_STATE, spa);
2796 2796 error = vdev_online(spa, guid, ZFS_ONLINE_EXPAND, &newstate);
2797 2797 spa_config_enter(spa, SCL_STATE, spa, RW_READER);
2798 2798
2799 2799 /*
2800 2800 * If vdev_online returned an error or the underlying vdev_open
2801 2801 * failed then we abort the expand. The only way to know that
2802 2802 * vdev_open fails is by checking the returned newstate.
2803 2803 */
2804 2804 if (error || newstate != VDEV_STATE_HEALTHY) {
2805 2805 if (ztest_opts.zo_verbose >= 5) {
2806 2806 (void) printf("Unable to expand vdev, state %llu, "
2807 2807 "error %d\n", (u_longlong_t)newstate, error);
2808 2808 }
2809 2809 return (vd);
2810 2810 }
2811 2811 ASSERT3U(newstate, ==, VDEV_STATE_HEALTHY);
2812 2812
2813 2813 /*
2814 2814 * Since we dropped the lock we need to ensure that we're
2815 2815 * still talking to the original vdev. It's possible this
2816 2816 * vdev may have been detached/replaced while we were
2817 2817 * trying to online it.
2818 2818 */
2819 2819 if (generation != spa->spa_config_generation) {
2820 2820 if (ztest_opts.zo_verbose >= 5) {
2821 2821 (void) printf("vdev configuration has changed, "
2822 2822 "guid %llu, state %llu, expected gen %llu, "
2823 2823 "got gen %llu\n",
2824 2824 (u_longlong_t)guid,
2825 2825 (u_longlong_t)tvd->vdev_state,
2826 2826 (u_longlong_t)generation,
2827 2827 (u_longlong_t)spa->spa_config_generation);
2828 2828 }
2829 2829 return (vd);
2830 2830 }
2831 2831 return (NULL);
2832 2832 }
2833 2833
2834 2834 /*
2835 2835 * Traverse the vdev tree calling the supplied function.
2836 2836 * We continue to walk the tree until we either have walked all
2837 2837 * children or we receive a non-NULL return from the callback.
2838 2838 * If a NULL callback is passed, then we just return back the first
2839 2839 * leaf vdev we encounter.
2840 2840 */
2841 2841 vdev_t *
2842 2842 vdev_walk_tree(vdev_t *vd, vdev_t *(*func)(vdev_t *, void *), void *arg)
2843 2843 {
2844 2844 if (vd->vdev_ops->vdev_op_leaf) {
2845 2845 if (func == NULL)
2846 2846 return (vd);
2847 2847 else
2848 2848 return (func(vd, arg));
2849 2849 }
2850 2850
2851 2851 for (uint_t c = 0; c < vd->vdev_children; c++) {
2852 2852 vdev_t *cvd = vd->vdev_child[c];
2853 2853 if ((cvd = vdev_walk_tree(cvd, func, arg)) != NULL)
2854 2854 return (cvd);
2855 2855 }
2856 2856 return (NULL);
2857 2857 }
2858 2858
2859 2859 /*
2860 2860 * Verify that dynamic LUN growth works as expected.
2861 2861 */
2862 2862 /* ARGSUSED */
2863 2863 void
2864 2864 ztest_vdev_LUN_growth(ztest_ds_t *zd, uint64_t id)
2865 2865 {
2866 2866 spa_t *spa = ztest_spa;
2867 2867 vdev_t *vd, *tvd;
2868 2868 metaslab_class_t *mc;
2869 2869 metaslab_group_t *mg;
2870 2870 size_t psize, newsize;
2871 2871 uint64_t top;
2872 2872 uint64_t old_class_space, new_class_space, old_ms_count, new_ms_count;
2873 2873
2874 2874 VERIFY(mutex_lock(&ztest_vdev_lock) == 0);
2875 2875 spa_config_enter(spa, SCL_STATE, spa, RW_READER);
2876 2876
2877 2877 top = ztest_random_vdev_top(spa, B_TRUE);
2878 2878
2879 2879 tvd = spa->spa_root_vdev->vdev_child[top];
2880 2880 mg = tvd->vdev_mg;
2881 2881 mc = mg->mg_class;
2882 2882 old_ms_count = tvd->vdev_ms_count;
2883 2883 old_class_space = metaslab_class_get_space(mc);
2884 2884
2885 2885 /*
2886 2886 * Determine the size of the first leaf vdev associated with
2887 2887 * our top-level device.
2888 2888 */
2889 2889 vd = vdev_walk_tree(tvd, NULL, NULL);
2890 2890 ASSERT3P(vd, !=, NULL);
2891 2891 ASSERT(vd->vdev_ops->vdev_op_leaf);
2892 2892
2893 2893 psize = vd->vdev_psize;
2894 2894
2895 2895 /*
2896 2896 * We only try to expand the vdev if it's healthy, less than 4x its
2897 2897 * original size, and it has a valid psize.
2898 2898 */
2899 2899 if (tvd->vdev_state != VDEV_STATE_HEALTHY ||
2900 2900 psize == 0 || psize >= 4 * ztest_opts.zo_vdev_size) {
2901 2901 spa_config_exit(spa, SCL_STATE, spa);
2902 2902 VERIFY(mutex_unlock(&ztest_vdev_lock) == 0);
2903 2903 return;
2904 2904 }
2905 2905 ASSERT(psize > 0);
2906 2906 newsize = psize + psize / 8;
2907 2907 ASSERT3U(newsize, >, psize);
2908 2908
2909 2909 if (ztest_opts.zo_verbose >= 6) {
2910 2910 (void) printf("Expanding LUN %s from %lu to %lu\n",
2911 2911 vd->vdev_path, (ulong_t)psize, (ulong_t)newsize);
2912 2912 }
2913 2913
2914 2914 /*
2915 2915 * Growing the vdev is a two step process:
2916 2916 * 1). expand the physical size (i.e. relabel)
2917 2917 * 2). online the vdev to create the new metaslabs
2918 2918 */
2919 2919 if (vdev_walk_tree(tvd, grow_vdev, &newsize) != NULL ||
2920 2920 vdev_walk_tree(tvd, online_vdev, NULL) != NULL ||
2921 2921 tvd->vdev_state != VDEV_STATE_HEALTHY) {
2922 2922 if (ztest_opts.zo_verbose >= 5) {
2923 2923 (void) printf("Could not expand LUN because "
2924 2924 "the vdev configuration changed.\n");
2925 2925 }
2926 2926 spa_config_exit(spa, SCL_STATE, spa);
2927 2927 VERIFY(mutex_unlock(&ztest_vdev_lock) == 0);
2928 2928 return;
2929 2929 }
2930 2930
2931 2931 spa_config_exit(spa, SCL_STATE, spa);
2932 2932
2933 2933 /*
2934 2934 * Expanding the LUN will update the config asynchronously,
2935 2935 * thus we must wait for the async thread to complete any
2936 2936 * pending tasks before proceeding.
2937 2937 */
2938 2938 for (;;) {
2939 2939 boolean_t done;
2940 2940 mutex_enter(&spa->spa_async_lock);
2941 2941 done = (spa->spa_async_thread == NULL && !spa->spa_async_tasks);
2942 2942 mutex_exit(&spa->spa_async_lock);
2943 2943 if (done)
2944 2944 break;
2945 2945 txg_wait_synced(spa_get_dsl(spa), 0);
2946 2946 (void) poll(NULL, 0, 100);
2947 2947 }
2948 2948
2949 2949 spa_config_enter(spa, SCL_STATE, spa, RW_READER);
2950 2950
2951 2951 tvd = spa->spa_root_vdev->vdev_child[top];
2952 2952 new_ms_count = tvd->vdev_ms_count;
2953 2953 new_class_space = metaslab_class_get_space(mc);
2954 2954
2955 2955 if (tvd->vdev_mg != mg || mg->mg_class != mc) {
2956 2956 if (ztest_opts.zo_verbose >= 5) {
2957 2957 (void) printf("Could not verify LUN expansion due to "
2958 2958 "intervening vdev offline or remove.\n");
2959 2959 }
2960 2960 spa_config_exit(spa, SCL_STATE, spa);
2961 2961 VERIFY(mutex_unlock(&ztest_vdev_lock) == 0);
2962 2962 return;
2963 2963 }
2964 2964
2965 2965 /*
2966 2966 * Make sure we were able to grow the vdev.
2967 2967 */
2968 2968 if (new_ms_count <= old_ms_count)
2969 2969 fatal(0, "LUN expansion failed: ms_count %llu <= %llu\n",
2970 2970 old_ms_count, new_ms_count);
2971 2971
2972 2972 /*
2973 2973 * Make sure we were able to grow the pool.
2974 2974 */
2975 2975 if (new_class_space <= old_class_space)
2976 2976 fatal(0, "LUN expansion failed: class_space %llu <= %llu\n",
2977 2977 old_class_space, new_class_space);
2978 2978
2979 2979 if (ztest_opts.zo_verbose >= 5) {
2980 2980 char oldnumbuf[6], newnumbuf[6];
2981 2981
2982 2982 nicenum(old_class_space, oldnumbuf);
2983 2983 nicenum(new_class_space, newnumbuf);
2984 2984 (void) printf("%s grew from %s to %s\n",
2985 2985 spa->spa_name, oldnumbuf, newnumbuf);
2986 2986 }
2987 2987
2988 2988 spa_config_exit(spa, SCL_STATE, spa);
2989 2989 VERIFY(mutex_unlock(&ztest_vdev_lock) == 0);
2990 2990 }
2991 2991
2992 2992 /*
2993 2993 * Verify that dmu_objset_{create,destroy,open,close} work as expected.
2994 2994 */
2995 2995 /* ARGSUSED */
2996 2996 static void
2997 2997 ztest_objset_create_cb(objset_t *os, void *arg, cred_t *cr, dmu_tx_t *tx)
2998 2998 {
2999 2999 /*
3000 3000 * Create the objects common to all ztest datasets.
3001 3001 */
3002 3002 VERIFY(zap_create_claim(os, ZTEST_DIROBJ,
3003 3003 DMU_OT_ZAP_OTHER, DMU_OT_NONE, 0, tx) == 0);
3004 3004 }
3005 3005
3006 3006 static int
3007 3007 ztest_dataset_create(char *dsname)
3008 3008 {
3009 3009 uint64_t zilset = ztest_random(100);
3010 3010 int err = dmu_objset_create(dsname, DMU_OST_OTHER, 0,
3011 3011 ztest_objset_create_cb, NULL);
3012 3012
3013 3013 if (err || zilset < 80)
3014 3014 return (err);
3015 3015
3016 3016 if (ztest_opts.zo_verbose >= 6)
3017 3017 (void) printf("Setting dataset %s to sync always\n", dsname);
3018 3018 return (ztest_dsl_prop_set_uint64(dsname, ZFS_PROP_SYNC,
3019 3019 ZFS_SYNC_ALWAYS, B_FALSE));
3020 3020 }
3021 3021
3022 3022 /* ARGSUSED */
↓ open down ↓ |
738 lines elided |
↑ open up ↑ |
3023 3023 static int
3024 3024 ztest_objset_destroy_cb(const char *name, void *arg)
3025 3025 {
3026 3026 objset_t *os;
3027 3027 dmu_object_info_t doi;
3028 3028 int error;
3029 3029
3030 3030 /*
3031 3031 * Verify that the dataset contains a directory object.
3032 3032 */
3033 - VERIFY3U(0, ==, dmu_objset_hold(name, FTAG, &os));
3033 + VERIFY0(dmu_objset_hold(name, FTAG, &os));
3034 3034 error = dmu_object_info(os, ZTEST_DIROBJ, &doi);
3035 3035 if (error != ENOENT) {
3036 3036 /* We could have crashed in the middle of destroying it */
3037 - ASSERT3U(error, ==, 0);
3037 + ASSERT0(error);
3038 3038 ASSERT3U(doi.doi_type, ==, DMU_OT_ZAP_OTHER);
3039 3039 ASSERT3S(doi.doi_physical_blocks_512, >=, 0);
3040 3040 }
3041 3041 dmu_objset_rele(os, FTAG);
3042 3042
3043 3043 /*
3044 3044 * Destroy the dataset.
3045 3045 */
3046 - VERIFY3U(0, ==, dmu_objset_destroy(name, B_FALSE));
3046 + VERIFY0(dmu_objset_destroy(name, B_FALSE));
3047 3047 return (0);
3048 3048 }
3049 3049
3050 3050 static boolean_t
3051 3051 ztest_snapshot_create(char *osname, uint64_t id)
3052 3052 {
3053 3053 char snapname[MAXNAMELEN];
3054 3054 int error;
3055 3055
3056 3056 (void) snprintf(snapname, MAXNAMELEN, "%s@%llu", osname,
3057 3057 (u_longlong_t)id);
3058 3058
3059 3059 error = dmu_objset_snapshot_one(osname, strchr(snapname, '@') + 1);
3060 3060 if (error == ENOSPC) {
3061 3061 ztest_record_enospc(FTAG);
3062 3062 return (B_FALSE);
3063 3063 }
3064 3064 if (error != 0 && error != EEXIST)
3065 3065 fatal(0, "ztest_snapshot_create(%s) = %d", snapname, error);
3066 3066 return (B_TRUE);
3067 3067 }
3068 3068
3069 3069 static boolean_t
3070 3070 ztest_snapshot_destroy(char *osname, uint64_t id)
3071 3071 {
3072 3072 char snapname[MAXNAMELEN];
3073 3073 int error;
3074 3074
3075 3075 (void) snprintf(snapname, MAXNAMELEN, "%s@%llu", osname,
3076 3076 (u_longlong_t)id);
3077 3077
3078 3078 error = dmu_objset_destroy(snapname, B_FALSE);
3079 3079 if (error != 0 && error != ENOENT)
3080 3080 fatal(0, "ztest_snapshot_destroy(%s) = %d", snapname, error);
3081 3081 return (B_TRUE);
3082 3082 }
3083 3083
3084 3084 /* ARGSUSED */
3085 3085 void
3086 3086 ztest_dmu_objset_create_destroy(ztest_ds_t *zd, uint64_t id)
3087 3087 {
3088 3088 ztest_ds_t zdtmp;
3089 3089 int iters;
3090 3090 int error;
3091 3091 objset_t *os, *os2;
3092 3092 char name[MAXNAMELEN];
3093 3093 zilog_t *zilog;
3094 3094
3095 3095 (void) rw_rdlock(&ztest_name_lock);
3096 3096
3097 3097 (void) snprintf(name, MAXNAMELEN, "%s/temp_%llu",
3098 3098 ztest_opts.zo_pool, (u_longlong_t)id);
3099 3099
3100 3100 /*
3101 3101 * If this dataset exists from a previous run, process its replay log
3102 3102 * half of the time. If we don't replay it, then dmu_objset_destroy()
3103 3103 * (invoked from ztest_objset_destroy_cb()) should just throw it away.
3104 3104 */
3105 3105 if (ztest_random(2) == 0 &&
3106 3106 dmu_objset_own(name, DMU_OST_OTHER, B_FALSE, FTAG, &os) == 0) {
3107 3107 ztest_zd_init(&zdtmp, NULL, os);
3108 3108 zil_replay(os, &zdtmp, ztest_replay_vector);
3109 3109 ztest_zd_fini(&zdtmp);
3110 3110 dmu_objset_disown(os, FTAG);
3111 3111 }
3112 3112
3113 3113 /*
3114 3114 * There may be an old instance of the dataset we're about to
3115 3115 * create lying around from a previous run. If so, destroy it
3116 3116 * and all of its snapshots.
3117 3117 */
3118 3118 (void) dmu_objset_find(name, ztest_objset_destroy_cb, NULL,
3119 3119 DS_FIND_CHILDREN | DS_FIND_SNAPSHOTS);
3120 3120
3121 3121 /*
3122 3122 * Verify that the destroyed dataset is no longer in the namespace.
3123 3123 */
3124 3124 VERIFY3U(ENOENT, ==, dmu_objset_hold(name, FTAG, &os));
3125 3125
3126 3126 /*
3127 3127 * Verify that we can create a new dataset.
3128 3128 */
↓ open down ↓ |
72 lines elided |
↑ open up ↑ |
3129 3129 error = ztest_dataset_create(name);
3130 3130 if (error) {
3131 3131 if (error == ENOSPC) {
3132 3132 ztest_record_enospc(FTAG);
3133 3133 (void) rw_unlock(&ztest_name_lock);
3134 3134 return;
3135 3135 }
3136 3136 fatal(0, "dmu_objset_create(%s) = %d", name, error);
3137 3137 }
3138 3138
3139 - VERIFY3U(0, ==,
3140 - dmu_objset_own(name, DMU_OST_OTHER, B_FALSE, FTAG, &os));
3139 + VERIFY0(dmu_objset_own(name, DMU_OST_OTHER, B_FALSE, FTAG, &os));
3141 3140
3142 3141 ztest_zd_init(&zdtmp, NULL, os);
3143 3142
3144 3143 /*
3145 3144 * Open the intent log for it.
3146 3145 */
3147 3146 zilog = zil_open(os, ztest_get_data);
3148 3147
3149 3148 /*
3150 3149 * Put some objects in there, do a little I/O to them,
3151 3150 * and randomly take a couple of snapshots along the way.
3152 3151 */
3153 3152 iters = ztest_random(5);
3154 3153 for (int i = 0; i < iters; i++) {
3155 3154 ztest_dmu_object_alloc_free(&zdtmp, id);
3156 3155 if (ztest_random(iters) == 0)
3157 3156 (void) ztest_snapshot_create(name, i);
3158 3157 }
↓ open down ↓ |
8 lines elided |
↑ open up ↑ |
3159 3158
3160 3159 /*
3161 3160 * Verify that we cannot create an existing dataset.
3162 3161 */
3163 3162 VERIFY3U(EEXIST, ==,
3164 3163 dmu_objset_create(name, DMU_OST_OTHER, 0, NULL, NULL));
3165 3164
3166 3165 /*
3167 3166 * Verify that we can hold an objset that is also owned.
3168 3167 */
3169 - VERIFY3U(0, ==, dmu_objset_hold(name, FTAG, &os2));
3168 + VERIFY0(dmu_objset_hold(name, FTAG, &os2));
3170 3169 dmu_objset_rele(os2, FTAG);
3171 3170
3172 3171 /*
3173 3172 * Verify that we cannot own an objset that is already owned.
3174 3173 */
3175 3174 VERIFY3U(EBUSY, ==,
3176 3175 dmu_objset_own(name, DMU_OST_OTHER, B_FALSE, FTAG, &os2));
3177 3176
3178 3177 zil_close(zilog);
3179 3178 dmu_objset_disown(os, FTAG);
3180 3179 ztest_zd_fini(&zdtmp);
3181 3180
3182 3181 (void) rw_unlock(&ztest_name_lock);
3183 3182 }
3184 3183
3185 3184 /*
3186 3185 * Verify that dmu_snapshot_{create,destroy,open,close} work as expected.
3187 3186 */
3188 3187 void
3189 3188 ztest_dmu_snapshot_create_destroy(ztest_ds_t *zd, uint64_t id)
3190 3189 {
3191 3190 (void) rw_rdlock(&ztest_name_lock);
3192 3191 (void) ztest_snapshot_destroy(zd->zd_name, id);
3193 3192 (void) ztest_snapshot_create(zd->zd_name, id);
3194 3193 (void) rw_unlock(&ztest_name_lock);
3195 3194 }
3196 3195
3197 3196 /*
3198 3197 * Cleanup non-standard snapshots and clones.
3199 3198 */
3200 3199 void
3201 3200 ztest_dsl_dataset_cleanup(char *osname, uint64_t id)
3202 3201 {
3203 3202 char snap1name[MAXNAMELEN];
3204 3203 char clone1name[MAXNAMELEN];
3205 3204 char snap2name[MAXNAMELEN];
3206 3205 char clone2name[MAXNAMELEN];
3207 3206 char snap3name[MAXNAMELEN];
3208 3207 int error;
3209 3208
3210 3209 (void) snprintf(snap1name, MAXNAMELEN, "%s@s1_%llu", osname, id);
3211 3210 (void) snprintf(clone1name, MAXNAMELEN, "%s/c1_%llu", osname, id);
3212 3211 (void) snprintf(snap2name, MAXNAMELEN, "%s@s2_%llu", clone1name, id);
3213 3212 (void) snprintf(clone2name, MAXNAMELEN, "%s/c2_%llu", osname, id);
3214 3213 (void) snprintf(snap3name, MAXNAMELEN, "%s@s3_%llu", clone1name, id);
3215 3214
3216 3215 error = dmu_objset_destroy(clone2name, B_FALSE);
3217 3216 if (error && error != ENOENT)
3218 3217 fatal(0, "dmu_objset_destroy(%s) = %d", clone2name, error);
3219 3218 error = dmu_objset_destroy(snap3name, B_FALSE);
3220 3219 if (error && error != ENOENT)
3221 3220 fatal(0, "dmu_objset_destroy(%s) = %d", snap3name, error);
3222 3221 error = dmu_objset_destroy(snap2name, B_FALSE);
3223 3222 if (error && error != ENOENT)
3224 3223 fatal(0, "dmu_objset_destroy(%s) = %d", snap2name, error);
3225 3224 error = dmu_objset_destroy(clone1name, B_FALSE);
3226 3225 if (error && error != ENOENT)
3227 3226 fatal(0, "dmu_objset_destroy(%s) = %d", clone1name, error);
3228 3227 error = dmu_objset_destroy(snap1name, B_FALSE);
3229 3228 if (error && error != ENOENT)
3230 3229 fatal(0, "dmu_objset_destroy(%s) = %d", snap1name, error);
3231 3230 }
3232 3231
3233 3232 /*
3234 3233 * Verify dsl_dataset_promote handles EBUSY
3235 3234 */
3236 3235 void
3237 3236 ztest_dsl_dataset_promote_busy(ztest_ds_t *zd, uint64_t id)
3238 3237 {
3239 3238 objset_t *clone;
3240 3239 dsl_dataset_t *ds;
3241 3240 char snap1name[MAXNAMELEN];
3242 3241 char clone1name[MAXNAMELEN];
3243 3242 char snap2name[MAXNAMELEN];
3244 3243 char clone2name[MAXNAMELEN];
3245 3244 char snap3name[MAXNAMELEN];
3246 3245 char *osname = zd->zd_name;
3247 3246 int error;
3248 3247
3249 3248 (void) rw_rdlock(&ztest_name_lock);
3250 3249
3251 3250 ztest_dsl_dataset_cleanup(osname, id);
3252 3251
3253 3252 (void) snprintf(snap1name, MAXNAMELEN, "%s@s1_%llu", osname, id);
3254 3253 (void) snprintf(clone1name, MAXNAMELEN, "%s/c1_%llu", osname, id);
3255 3254 (void) snprintf(snap2name, MAXNAMELEN, "%s@s2_%llu", clone1name, id);
3256 3255 (void) snprintf(clone2name, MAXNAMELEN, "%s/c2_%llu", osname, id);
3257 3256 (void) snprintf(snap3name, MAXNAMELEN, "%s@s3_%llu", clone1name, id);
3258 3257
3259 3258 error = dmu_objset_snapshot_one(osname, strchr(snap1name, '@') + 1);
3260 3259 if (error && error != EEXIST) {
3261 3260 if (error == ENOSPC) {
3262 3261 ztest_record_enospc(FTAG);
3263 3262 goto out;
3264 3263 }
3265 3264 fatal(0, "dmu_take_snapshot(%s) = %d", snap1name, error);
3266 3265 }
3267 3266
3268 3267 error = dmu_objset_hold(snap1name, FTAG, &clone);
3269 3268 if (error)
3270 3269 fatal(0, "dmu_open_snapshot(%s) = %d", snap1name, error);
3271 3270
3272 3271 error = dmu_objset_clone(clone1name, dmu_objset_ds(clone), 0);
3273 3272 dmu_objset_rele(clone, FTAG);
3274 3273 if (error) {
3275 3274 if (error == ENOSPC) {
3276 3275 ztest_record_enospc(FTAG);
3277 3276 goto out;
3278 3277 }
3279 3278 fatal(0, "dmu_objset_create(%s) = %d", clone1name, error);
3280 3279 }
3281 3280
3282 3281 error = dmu_objset_snapshot_one(clone1name, strchr(snap2name, '@') + 1);
3283 3282 if (error && error != EEXIST) {
3284 3283 if (error == ENOSPC) {
3285 3284 ztest_record_enospc(FTAG);
3286 3285 goto out;
3287 3286 }
3288 3287 fatal(0, "dmu_open_snapshot(%s) = %d", snap2name, error);
3289 3288 }
3290 3289
3291 3290 error = dmu_objset_snapshot_one(clone1name, strchr(snap3name, '@') + 1);
3292 3291 if (error && error != EEXIST) {
3293 3292 if (error == ENOSPC) {
3294 3293 ztest_record_enospc(FTAG);
3295 3294 goto out;
3296 3295 }
3297 3296 fatal(0, "dmu_open_snapshot(%s) = %d", snap3name, error);
3298 3297 }
3299 3298
3300 3299 error = dmu_objset_hold(snap3name, FTAG, &clone);
3301 3300 if (error)
3302 3301 fatal(0, "dmu_open_snapshot(%s) = %d", snap3name, error);
3303 3302
3304 3303 error = dmu_objset_clone(clone2name, dmu_objset_ds(clone), 0);
3305 3304 dmu_objset_rele(clone, FTAG);
3306 3305 if (error) {
3307 3306 if (error == ENOSPC) {
3308 3307 ztest_record_enospc(FTAG);
3309 3308 goto out;
3310 3309 }
3311 3310 fatal(0, "dmu_objset_create(%s) = %d", clone2name, error);
3312 3311 }
3313 3312
3314 3313 error = dsl_dataset_own(snap2name, B_FALSE, FTAG, &ds);
3315 3314 if (error)
3316 3315 fatal(0, "dsl_dataset_own(%s) = %d", snap2name, error);
3317 3316 error = dsl_dataset_promote(clone2name, NULL);
3318 3317 if (error != EBUSY)
3319 3318 fatal(0, "dsl_dataset_promote(%s), %d, not EBUSY", clone2name,
3320 3319 error);
3321 3320 dsl_dataset_disown(ds, FTAG);
3322 3321
3323 3322 out:
3324 3323 ztest_dsl_dataset_cleanup(osname, id);
3325 3324
3326 3325 (void) rw_unlock(&ztest_name_lock);
3327 3326 }
3328 3327
3329 3328 /*
3330 3329 * Verify that dmu_object_{alloc,free} work as expected.
3331 3330 */
3332 3331 void
3333 3332 ztest_dmu_object_alloc_free(ztest_ds_t *zd, uint64_t id)
3334 3333 {
3335 3334 ztest_od_t od[4];
3336 3335 int batchsize = sizeof (od) / sizeof (od[0]);
3337 3336
3338 3337 for (int b = 0; b < batchsize; b++)
3339 3338 ztest_od_init(&od[b], id, FTAG, b, DMU_OT_UINT64_OTHER, 0, 0);
3340 3339
3341 3340 /*
3342 3341 * Destroy the previous batch of objects, create a new batch,
3343 3342 * and do some I/O on the new objects.
3344 3343 */
3345 3344 if (ztest_object_init(zd, od, sizeof (od), B_TRUE) != 0)
3346 3345 return;
3347 3346
3348 3347 while (ztest_random(4 * batchsize) != 0)
3349 3348 ztest_io(zd, od[ztest_random(batchsize)].od_object,
3350 3349 ztest_random(ZTEST_RANGE_LOCKS) << SPA_MAXBLOCKSHIFT);
3351 3350 }
3352 3351
3353 3352 /*
3354 3353 * Verify that dmu_{read,write} work as expected.
3355 3354 */
3356 3355 void
3357 3356 ztest_dmu_read_write(ztest_ds_t *zd, uint64_t id)
3358 3357 {
3359 3358 objset_t *os = zd->zd_os;
3360 3359 ztest_od_t od[2];
3361 3360 dmu_tx_t *tx;
3362 3361 int i, freeit, error;
3363 3362 uint64_t n, s, txg;
3364 3363 bufwad_t *packbuf, *bigbuf, *pack, *bigH, *bigT;
3365 3364 uint64_t packobj, packoff, packsize, bigobj, bigoff, bigsize;
3366 3365 uint64_t chunksize = (1000 + ztest_random(1000)) * sizeof (uint64_t);
3367 3366 uint64_t regions = 997;
3368 3367 uint64_t stride = 123456789ULL;
3369 3368 uint64_t width = 40;
3370 3369 int free_percent = 5;
3371 3370
3372 3371 /*
3373 3372 * This test uses two objects, packobj and bigobj, that are always
3374 3373 * updated together (i.e. in the same tx) so that their contents are
3375 3374 * in sync and can be compared. Their contents relate to each other
3376 3375 * in a simple way: packobj is a dense array of 'bufwad' structures,
3377 3376 * while bigobj is a sparse array of the same bufwads. Specifically,
3378 3377 * for any index n, there are three bufwads that should be identical:
3379 3378 *
3380 3379 * packobj, at offset n * sizeof (bufwad_t)
3381 3380 * bigobj, at the head of the nth chunk
3382 3381 * bigobj, at the tail of the nth chunk
3383 3382 *
3384 3383 * The chunk size is arbitrary. It doesn't have to be a power of two,
3385 3384 * and it doesn't have any relation to the object blocksize.
3386 3385 * The only requirement is that it can hold at least two bufwads.
3387 3386 *
3388 3387 * Normally, we write the bufwad to each of these locations.
3389 3388 * However, free_percent of the time we instead write zeroes to
3390 3389 * packobj and perform a dmu_free_range() on bigobj. By comparing
3391 3390 * bigobj to packobj, we can verify that the DMU is correctly
3392 3391 * tracking which parts of an object are allocated and free,
3393 3392 * and that the contents of the allocated blocks are correct.
3394 3393 */
3395 3394
3396 3395 /*
3397 3396 * Read the directory info. If it's the first time, set things up.
3398 3397 */
3399 3398 ztest_od_init(&od[0], id, FTAG, 0, DMU_OT_UINT64_OTHER, 0, chunksize);
3400 3399 ztest_od_init(&od[1], id, FTAG, 1, DMU_OT_UINT64_OTHER, 0, chunksize);
3401 3400
3402 3401 if (ztest_object_init(zd, od, sizeof (od), B_FALSE) != 0)
3403 3402 return;
3404 3403
3405 3404 bigobj = od[0].od_object;
3406 3405 packobj = od[1].od_object;
3407 3406 chunksize = od[0].od_gen;
3408 3407 ASSERT(chunksize == od[1].od_gen);
3409 3408
3410 3409 /*
3411 3410 * Prefetch a random chunk of the big object.
3412 3411 * Our aim here is to get some async reads in flight
3413 3412 * for blocks that we may free below; the DMU should
3414 3413 * handle this race correctly.
3415 3414 */
3416 3415 n = ztest_random(regions) * stride + ztest_random(width);
3417 3416 s = 1 + ztest_random(2 * width - 1);
3418 3417 dmu_prefetch(os, bigobj, n * chunksize, s * chunksize);
3419 3418
3420 3419 /*
3421 3420 * Pick a random index and compute the offsets into packobj and bigobj.
3422 3421 */
3423 3422 n = ztest_random(regions) * stride + ztest_random(width);
3424 3423 s = 1 + ztest_random(width - 1);
3425 3424
3426 3425 packoff = n * sizeof (bufwad_t);
3427 3426 packsize = s * sizeof (bufwad_t);
3428 3427
3429 3428 bigoff = n * chunksize;
3430 3429 bigsize = s * chunksize;
3431 3430
3432 3431 packbuf = umem_alloc(packsize, UMEM_NOFAIL);
3433 3432 bigbuf = umem_alloc(bigsize, UMEM_NOFAIL);
3434 3433
3435 3434 /*
↓ open down ↓ |
256 lines elided |
↑ open up ↑ |
3436 3435 * free_percent of the time, free a range of bigobj rather than
3437 3436 * overwriting it.
3438 3437 */
3439 3438 freeit = (ztest_random(100) < free_percent);
3440 3439
3441 3440 /*
3442 3441 * Read the current contents of our objects.
3443 3442 */
3444 3443 error = dmu_read(os, packobj, packoff, packsize, packbuf,
3445 3444 DMU_READ_PREFETCH);
3446 - ASSERT3U(error, ==, 0);
3445 + ASSERT0(error);
3447 3446 error = dmu_read(os, bigobj, bigoff, bigsize, bigbuf,
3448 3447 DMU_READ_PREFETCH);
3449 - ASSERT3U(error, ==, 0);
3448 + ASSERT0(error);
3450 3449
3451 3450 /*
3452 3451 * Get a tx for the mods to both packobj and bigobj.
3453 3452 */
3454 3453 tx = dmu_tx_create(os);
3455 3454
3456 3455 dmu_tx_hold_write(tx, packobj, packoff, packsize);
3457 3456
3458 3457 if (freeit)
3459 3458 dmu_tx_hold_free(tx, bigobj, bigoff, bigsize);
3460 3459 else
3461 3460 dmu_tx_hold_write(tx, bigobj, bigoff, bigsize);
3462 3461
3463 3462 txg = ztest_tx_assign(tx, TXG_MIGHTWAIT, FTAG);
3464 3463 if (txg == 0) {
3465 3464 umem_free(packbuf, packsize);
3466 3465 umem_free(bigbuf, bigsize);
3467 3466 return;
3468 3467 }
3469 3468
3470 3469 dmu_object_set_checksum(os, bigobj,
3471 3470 (enum zio_checksum)ztest_random_dsl_prop(ZFS_PROP_CHECKSUM), tx);
3472 3471
3473 3472 dmu_object_set_compress(os, bigobj,
3474 3473 (enum zio_compress)ztest_random_dsl_prop(ZFS_PROP_COMPRESSION), tx);
3475 3474
3476 3475 /*
3477 3476 * For each index from n to n + s, verify that the existing bufwad
3478 3477 * in packobj matches the bufwads at the head and tail of the
3479 3478 * corresponding chunk in bigobj. Then update all three bufwads
3480 3479 * with the new values we want to write out.
3481 3480 */
3482 3481 for (i = 0; i < s; i++) {
3483 3482 /* LINTED */
3484 3483 pack = (bufwad_t *)((char *)packbuf + i * sizeof (bufwad_t));
3485 3484 /* LINTED */
3486 3485 bigH = (bufwad_t *)((char *)bigbuf + i * chunksize);
3487 3486 /* LINTED */
3488 3487 bigT = (bufwad_t *)((char *)bigH + chunksize) - 1;
3489 3488
3490 3489 ASSERT((uintptr_t)bigH - (uintptr_t)bigbuf < bigsize);
3491 3490 ASSERT((uintptr_t)bigT - (uintptr_t)bigbuf < bigsize);
3492 3491
3493 3492 if (pack->bw_txg > txg)
3494 3493 fatal(0, "future leak: got %llx, open txg is %llx",
3495 3494 pack->bw_txg, txg);
3496 3495
3497 3496 if (pack->bw_data != 0 && pack->bw_index != n + i)
3498 3497 fatal(0, "wrong index: got %llx, wanted %llx+%llx",
3499 3498 pack->bw_index, n, i);
3500 3499
3501 3500 if (bcmp(pack, bigH, sizeof (bufwad_t)) != 0)
3502 3501 fatal(0, "pack/bigH mismatch in %p/%p", pack, bigH);
3503 3502
3504 3503 if (bcmp(pack, bigT, sizeof (bufwad_t)) != 0)
3505 3504 fatal(0, "pack/bigT mismatch in %p/%p", pack, bigT);
3506 3505
3507 3506 if (freeit) {
3508 3507 bzero(pack, sizeof (bufwad_t));
3509 3508 } else {
3510 3509 pack->bw_index = n + i;
3511 3510 pack->bw_txg = txg;
3512 3511 pack->bw_data = 1 + ztest_random(-2ULL);
3513 3512 }
3514 3513 *bigH = *pack;
3515 3514 *bigT = *pack;
3516 3515 }
3517 3516
3518 3517 /*
3519 3518 * We've verified all the old bufwads, and made new ones.
3520 3519 * Now write them out.
3521 3520 */
3522 3521 dmu_write(os, packobj, packoff, packsize, packbuf, tx);
3523 3522
3524 3523 if (freeit) {
3525 3524 if (ztest_opts.zo_verbose >= 7) {
3526 3525 (void) printf("freeing offset %llx size %llx"
3527 3526 " txg %llx\n",
3528 3527 (u_longlong_t)bigoff,
3529 3528 (u_longlong_t)bigsize,
3530 3529 (u_longlong_t)txg);
3531 3530 }
3532 3531 VERIFY(0 == dmu_free_range(os, bigobj, bigoff, bigsize, tx));
3533 3532 } else {
3534 3533 if (ztest_opts.zo_verbose >= 7) {
3535 3534 (void) printf("writing offset %llx size %llx"
3536 3535 " txg %llx\n",
3537 3536 (u_longlong_t)bigoff,
3538 3537 (u_longlong_t)bigsize,
3539 3538 (u_longlong_t)txg);
3540 3539 }
3541 3540 dmu_write(os, bigobj, bigoff, bigsize, bigbuf, tx);
3542 3541 }
3543 3542
3544 3543 dmu_tx_commit(tx);
3545 3544
3546 3545 /*
3547 3546 * Sanity check the stuff we just wrote.
3548 3547 */
3549 3548 {
3550 3549 void *packcheck = umem_alloc(packsize, UMEM_NOFAIL);
3551 3550 void *bigcheck = umem_alloc(bigsize, UMEM_NOFAIL);
3552 3551
3553 3552 VERIFY(0 == dmu_read(os, packobj, packoff,
3554 3553 packsize, packcheck, DMU_READ_PREFETCH));
3555 3554 VERIFY(0 == dmu_read(os, bigobj, bigoff,
3556 3555 bigsize, bigcheck, DMU_READ_PREFETCH));
3557 3556
3558 3557 ASSERT(bcmp(packbuf, packcheck, packsize) == 0);
3559 3558 ASSERT(bcmp(bigbuf, bigcheck, bigsize) == 0);
3560 3559
3561 3560 umem_free(packcheck, packsize);
3562 3561 umem_free(bigcheck, bigsize);
3563 3562 }
3564 3563
3565 3564 umem_free(packbuf, packsize);
3566 3565 umem_free(bigbuf, bigsize);
3567 3566 }
3568 3567
3569 3568 void
3570 3569 compare_and_update_pbbufs(uint64_t s, bufwad_t *packbuf, bufwad_t *bigbuf,
3571 3570 uint64_t bigsize, uint64_t n, uint64_t chunksize, uint64_t txg)
3572 3571 {
3573 3572 uint64_t i;
3574 3573 bufwad_t *pack;
3575 3574 bufwad_t *bigH;
3576 3575 bufwad_t *bigT;
3577 3576
3578 3577 /*
3579 3578 * For each index from n to n + s, verify that the existing bufwad
3580 3579 * in packobj matches the bufwads at the head and tail of the
3581 3580 * corresponding chunk in bigobj. Then update all three bufwads
3582 3581 * with the new values we want to write out.
3583 3582 */
3584 3583 for (i = 0; i < s; i++) {
3585 3584 /* LINTED */
3586 3585 pack = (bufwad_t *)((char *)packbuf + i * sizeof (bufwad_t));
3587 3586 /* LINTED */
3588 3587 bigH = (bufwad_t *)((char *)bigbuf + i * chunksize);
3589 3588 /* LINTED */
3590 3589 bigT = (bufwad_t *)((char *)bigH + chunksize) - 1;
3591 3590
3592 3591 ASSERT((uintptr_t)bigH - (uintptr_t)bigbuf < bigsize);
3593 3592 ASSERT((uintptr_t)bigT - (uintptr_t)bigbuf < bigsize);
3594 3593
3595 3594 if (pack->bw_txg > txg)
3596 3595 fatal(0, "future leak: got %llx, open txg is %llx",
3597 3596 pack->bw_txg, txg);
3598 3597
3599 3598 if (pack->bw_data != 0 && pack->bw_index != n + i)
3600 3599 fatal(0, "wrong index: got %llx, wanted %llx+%llx",
3601 3600 pack->bw_index, n, i);
3602 3601
3603 3602 if (bcmp(pack, bigH, sizeof (bufwad_t)) != 0)
3604 3603 fatal(0, "pack/bigH mismatch in %p/%p", pack, bigH);
3605 3604
3606 3605 if (bcmp(pack, bigT, sizeof (bufwad_t)) != 0)
3607 3606 fatal(0, "pack/bigT mismatch in %p/%p", pack, bigT);
3608 3607
3609 3608 pack->bw_index = n + i;
3610 3609 pack->bw_txg = txg;
3611 3610 pack->bw_data = 1 + ztest_random(-2ULL);
3612 3611
3613 3612 *bigH = *pack;
3614 3613 *bigT = *pack;
3615 3614 }
3616 3615 }
3617 3616
3618 3617 void
3619 3618 ztest_dmu_read_write_zcopy(ztest_ds_t *zd, uint64_t id)
3620 3619 {
3621 3620 objset_t *os = zd->zd_os;
3622 3621 ztest_od_t od[2];
3623 3622 dmu_tx_t *tx;
3624 3623 uint64_t i;
3625 3624 int error;
3626 3625 uint64_t n, s, txg;
3627 3626 bufwad_t *packbuf, *bigbuf;
3628 3627 uint64_t packobj, packoff, packsize, bigobj, bigoff, bigsize;
3629 3628 uint64_t blocksize = ztest_random_blocksize();
3630 3629 uint64_t chunksize = blocksize;
3631 3630 uint64_t regions = 997;
3632 3631 uint64_t stride = 123456789ULL;
3633 3632 uint64_t width = 9;
3634 3633 dmu_buf_t *bonus_db;
3635 3634 arc_buf_t **bigbuf_arcbufs;
3636 3635 dmu_object_info_t doi;
3637 3636
3638 3637 /*
3639 3638 * This test uses two objects, packobj and bigobj, that are always
3640 3639 * updated together (i.e. in the same tx) so that their contents are
3641 3640 * in sync and can be compared. Their contents relate to each other
3642 3641 * in a simple way: packobj is a dense array of 'bufwad' structures,
3643 3642 * while bigobj is a sparse array of the same bufwads. Specifically,
3644 3643 * for any index n, there are three bufwads that should be identical:
3645 3644 *
3646 3645 * packobj, at offset n * sizeof (bufwad_t)
3647 3646 * bigobj, at the head of the nth chunk
3648 3647 * bigobj, at the tail of the nth chunk
3649 3648 *
3650 3649 * The chunk size is set equal to bigobj block size so that
3651 3650 * dmu_assign_arcbuf() can be tested for object updates.
3652 3651 */
3653 3652
3654 3653 /*
3655 3654 * Read the directory info. If it's the first time, set things up.
3656 3655 */
3657 3656 ztest_od_init(&od[0], id, FTAG, 0, DMU_OT_UINT64_OTHER, blocksize, 0);
3658 3657 ztest_od_init(&od[1], id, FTAG, 1, DMU_OT_UINT64_OTHER, 0, chunksize);
3659 3658
3660 3659 if (ztest_object_init(zd, od, sizeof (od), B_FALSE) != 0)
3661 3660 return;
3662 3661
3663 3662 bigobj = od[0].od_object;
3664 3663 packobj = od[1].od_object;
3665 3664 blocksize = od[0].od_blocksize;
3666 3665 chunksize = blocksize;
3667 3666 ASSERT(chunksize == od[1].od_gen);
3668 3667
3669 3668 VERIFY(dmu_object_info(os, bigobj, &doi) == 0);
3670 3669 VERIFY(ISP2(doi.doi_data_block_size));
3671 3670 VERIFY(chunksize == doi.doi_data_block_size);
3672 3671 VERIFY(chunksize >= 2 * sizeof (bufwad_t));
3673 3672
3674 3673 /*
3675 3674 * Pick a random index and compute the offsets into packobj and bigobj.
3676 3675 */
3677 3676 n = ztest_random(regions) * stride + ztest_random(width);
3678 3677 s = 1 + ztest_random(width - 1);
↓ open down ↓ |
219 lines elided |
↑ open up ↑ |
3679 3678
3680 3679 packoff = n * sizeof (bufwad_t);
3681 3680 packsize = s * sizeof (bufwad_t);
3682 3681
3683 3682 bigoff = n * chunksize;
3684 3683 bigsize = s * chunksize;
3685 3684
3686 3685 packbuf = umem_zalloc(packsize, UMEM_NOFAIL);
3687 3686 bigbuf = umem_zalloc(bigsize, UMEM_NOFAIL);
3688 3687
3689 - VERIFY3U(0, ==, dmu_bonus_hold(os, bigobj, FTAG, &bonus_db));
3688 + VERIFY0(dmu_bonus_hold(os, bigobj, FTAG, &bonus_db));
3690 3689
3691 3690 bigbuf_arcbufs = umem_zalloc(2 * s * sizeof (arc_buf_t *), UMEM_NOFAIL);
3692 3691
3693 3692 /*
3694 3693 * Iteration 0 test zcopy for DB_UNCACHED dbufs.
3695 3694 * Iteration 1 test zcopy to already referenced dbufs.
3696 3695 * Iteration 2 test zcopy to dirty dbuf in the same txg.
3697 3696 * Iteration 3 test zcopy to dbuf dirty in previous txg.
3698 3697 * Iteration 4 test zcopy when dbuf is no longer dirty.
3699 3698 * Iteration 5 test zcopy when it can't be done.
3700 3699 * Iteration 6 one more zcopy write.
3701 3700 */
3702 3701 for (i = 0; i < 7; i++) {
3703 3702 uint64_t j;
3704 3703 uint64_t off;
3705 3704
3706 3705 /*
3707 3706 * In iteration 5 (i == 5) use arcbufs
3708 3707 * that don't match bigobj blksz to test
3709 3708 * dmu_assign_arcbuf() when it can't directly
3710 3709 * assign an arcbuf to a dbuf.
3711 3710 */
3712 3711 for (j = 0; j < s; j++) {
3713 3712 if (i != 5) {
3714 3713 bigbuf_arcbufs[j] =
3715 3714 dmu_request_arcbuf(bonus_db, chunksize);
3716 3715 } else {
3717 3716 bigbuf_arcbufs[2 * j] =
3718 3717 dmu_request_arcbuf(bonus_db, chunksize / 2);
3719 3718 bigbuf_arcbufs[2 * j + 1] =
3720 3719 dmu_request_arcbuf(bonus_db, chunksize / 2);
3721 3720 }
3722 3721 }
3723 3722
3724 3723 /*
3725 3724 * Get a tx for the mods to both packobj and bigobj.
3726 3725 */
3727 3726 tx = dmu_tx_create(os);
3728 3727
3729 3728 dmu_tx_hold_write(tx, packobj, packoff, packsize);
3730 3729 dmu_tx_hold_write(tx, bigobj, bigoff, bigsize);
3731 3730
3732 3731 txg = ztest_tx_assign(tx, TXG_MIGHTWAIT, FTAG);
3733 3732 if (txg == 0) {
3734 3733 umem_free(packbuf, packsize);
3735 3734 umem_free(bigbuf, bigsize);
3736 3735 for (j = 0; j < s; j++) {
3737 3736 if (i != 5) {
3738 3737 dmu_return_arcbuf(bigbuf_arcbufs[j]);
3739 3738 } else {
3740 3739 dmu_return_arcbuf(
3741 3740 bigbuf_arcbufs[2 * j]);
3742 3741 dmu_return_arcbuf(
3743 3742 bigbuf_arcbufs[2 * j + 1]);
3744 3743 }
3745 3744 }
3746 3745 umem_free(bigbuf_arcbufs, 2 * s * sizeof (arc_buf_t *));
3747 3746 dmu_buf_rele(bonus_db, FTAG);
3748 3747 return;
↓ open down ↓ |
49 lines elided |
↑ open up ↑ |
3749 3748 }
3750 3749
3751 3750 /*
3752 3751 * 50% of the time don't read objects in the 1st iteration to
3753 3752 * test dmu_assign_arcbuf() for the case when there're no
3754 3753 * existing dbufs for the specified offsets.
3755 3754 */
3756 3755 if (i != 0 || ztest_random(2) != 0) {
3757 3756 error = dmu_read(os, packobj, packoff,
3758 3757 packsize, packbuf, DMU_READ_PREFETCH);
3759 - ASSERT3U(error, ==, 0);
3758 + ASSERT0(error);
3760 3759 error = dmu_read(os, bigobj, bigoff, bigsize,
3761 3760 bigbuf, DMU_READ_PREFETCH);
3762 - ASSERT3U(error, ==, 0);
3761 + ASSERT0(error);
3763 3762 }
3764 3763 compare_and_update_pbbufs(s, packbuf, bigbuf, bigsize,
3765 3764 n, chunksize, txg);
3766 3765
3767 3766 /*
3768 3767 * We've verified all the old bufwads, and made new ones.
3769 3768 * Now write them out.
3770 3769 */
3771 3770 dmu_write(os, packobj, packoff, packsize, packbuf, tx);
3772 3771 if (ztest_opts.zo_verbose >= 7) {
3773 3772 (void) printf("writing offset %llx size %llx"
3774 3773 " txg %llx\n",
3775 3774 (u_longlong_t)bigoff,
3776 3775 (u_longlong_t)bigsize,
3777 3776 (u_longlong_t)txg);
3778 3777 }
3779 3778 for (off = bigoff, j = 0; j < s; j++, off += chunksize) {
3780 3779 dmu_buf_t *dbt;
3781 3780 if (i != 5) {
3782 3781 bcopy((caddr_t)bigbuf + (off - bigoff),
3783 3782 bigbuf_arcbufs[j]->b_data, chunksize);
3784 3783 } else {
3785 3784 bcopy((caddr_t)bigbuf + (off - bigoff),
3786 3785 bigbuf_arcbufs[2 * j]->b_data,
3787 3786 chunksize / 2);
3788 3787 bcopy((caddr_t)bigbuf + (off - bigoff) +
3789 3788 chunksize / 2,
3790 3789 bigbuf_arcbufs[2 * j + 1]->b_data,
3791 3790 chunksize / 2);
3792 3791 }
3793 3792
3794 3793 if (i == 1) {
3795 3794 VERIFY(dmu_buf_hold(os, bigobj, off,
3796 3795 FTAG, &dbt, DMU_READ_NO_PREFETCH) == 0);
3797 3796 }
3798 3797 if (i != 5) {
3799 3798 dmu_assign_arcbuf(bonus_db, off,
3800 3799 bigbuf_arcbufs[j], tx);
3801 3800 } else {
3802 3801 dmu_assign_arcbuf(bonus_db, off,
3803 3802 bigbuf_arcbufs[2 * j], tx);
3804 3803 dmu_assign_arcbuf(bonus_db,
3805 3804 off + chunksize / 2,
3806 3805 bigbuf_arcbufs[2 * j + 1], tx);
3807 3806 }
3808 3807 if (i == 1) {
3809 3808 dmu_buf_rele(dbt, FTAG);
3810 3809 }
3811 3810 }
3812 3811 dmu_tx_commit(tx);
3813 3812
3814 3813 /*
3815 3814 * Sanity check the stuff we just wrote.
3816 3815 */
3817 3816 {
3818 3817 void *packcheck = umem_alloc(packsize, UMEM_NOFAIL);
3819 3818 void *bigcheck = umem_alloc(bigsize, UMEM_NOFAIL);
3820 3819
3821 3820 VERIFY(0 == dmu_read(os, packobj, packoff,
3822 3821 packsize, packcheck, DMU_READ_PREFETCH));
3823 3822 VERIFY(0 == dmu_read(os, bigobj, bigoff,
3824 3823 bigsize, bigcheck, DMU_READ_PREFETCH));
3825 3824
3826 3825 ASSERT(bcmp(packbuf, packcheck, packsize) == 0);
3827 3826 ASSERT(bcmp(bigbuf, bigcheck, bigsize) == 0);
3828 3827
3829 3828 umem_free(packcheck, packsize);
3830 3829 umem_free(bigcheck, bigsize);
3831 3830 }
3832 3831 if (i == 2) {
3833 3832 txg_wait_open(dmu_objset_pool(os), 0);
3834 3833 } else if (i == 3) {
3835 3834 txg_wait_synced(dmu_objset_pool(os), 0);
3836 3835 }
3837 3836 }
3838 3837
3839 3838 dmu_buf_rele(bonus_db, FTAG);
3840 3839 umem_free(packbuf, packsize);
3841 3840 umem_free(bigbuf, bigsize);
3842 3841 umem_free(bigbuf_arcbufs, 2 * s * sizeof (arc_buf_t *));
3843 3842 }
3844 3843
3845 3844 /* ARGSUSED */
3846 3845 void
3847 3846 ztest_dmu_write_parallel(ztest_ds_t *zd, uint64_t id)
3848 3847 {
3849 3848 ztest_od_t od[1];
3850 3849 uint64_t offset = (1ULL << (ztest_random(20) + 43)) +
3851 3850 (ztest_random(ZTEST_RANGE_LOCKS) << SPA_MAXBLOCKSHIFT);
3852 3851
3853 3852 /*
3854 3853 * Have multiple threads write to large offsets in an object
3855 3854 * to verify that parallel writes to an object -- even to the
3856 3855 * same blocks within the object -- doesn't cause any trouble.
3857 3856 */
3858 3857 ztest_od_init(&od[0], ID_PARALLEL, FTAG, 0, DMU_OT_UINT64_OTHER, 0, 0);
3859 3858
3860 3859 if (ztest_object_init(zd, od, sizeof (od), B_FALSE) != 0)
3861 3860 return;
3862 3861
3863 3862 while (ztest_random(10) != 0)
3864 3863 ztest_io(zd, od[0].od_object, offset);
3865 3864 }
3866 3865
3867 3866 void
3868 3867 ztest_dmu_prealloc(ztest_ds_t *zd, uint64_t id)
3869 3868 {
3870 3869 ztest_od_t od[1];
3871 3870 uint64_t offset = (1ULL << (ztest_random(4) + SPA_MAXBLOCKSHIFT)) +
3872 3871 (ztest_random(ZTEST_RANGE_LOCKS) << SPA_MAXBLOCKSHIFT);
3873 3872 uint64_t count = ztest_random(20) + 1;
3874 3873 uint64_t blocksize = ztest_random_blocksize();
3875 3874 void *data;
3876 3875
3877 3876 ztest_od_init(&od[0], id, FTAG, 0, DMU_OT_UINT64_OTHER, blocksize, 0);
3878 3877
3879 3878 if (ztest_object_init(zd, od, sizeof (od), !ztest_random(2)) != 0)
3880 3879 return;
3881 3880
3882 3881 if (ztest_truncate(zd, od[0].od_object, offset, count * blocksize) != 0)
3883 3882 return;
3884 3883
3885 3884 ztest_prealloc(zd, od[0].od_object, offset, count * blocksize);
3886 3885
3887 3886 data = umem_zalloc(blocksize, UMEM_NOFAIL);
3888 3887
3889 3888 while (ztest_random(count) != 0) {
3890 3889 uint64_t randoff = offset + (ztest_random(count) * blocksize);
3891 3890 if (ztest_write(zd, od[0].od_object, randoff, blocksize,
3892 3891 data) != 0)
3893 3892 break;
3894 3893 while (ztest_random(4) != 0)
3895 3894 ztest_io(zd, od[0].od_object, randoff);
3896 3895 }
3897 3896
3898 3897 umem_free(data, blocksize);
3899 3898 }
3900 3899
3901 3900 /*
3902 3901 * Verify that zap_{create,destroy,add,remove,update} work as expected.
3903 3902 */
3904 3903 #define ZTEST_ZAP_MIN_INTS 1
3905 3904 #define ZTEST_ZAP_MAX_INTS 4
3906 3905 #define ZTEST_ZAP_MAX_PROPS 1000
3907 3906
3908 3907 void
3909 3908 ztest_zap(ztest_ds_t *zd, uint64_t id)
3910 3909 {
3911 3910 objset_t *os = zd->zd_os;
3912 3911 ztest_od_t od[1];
3913 3912 uint64_t object;
3914 3913 uint64_t txg, last_txg;
3915 3914 uint64_t value[ZTEST_ZAP_MAX_INTS];
3916 3915 uint64_t zl_ints, zl_intsize, prop;
3917 3916 int i, ints;
3918 3917 dmu_tx_t *tx;
3919 3918 char propname[100], txgname[100];
3920 3919 int error;
3921 3920 char *hc[2] = { "s.acl.h", ".s.open.h.hyLZlg" };
3922 3921
3923 3922 ztest_od_init(&od[0], id, FTAG, 0, DMU_OT_ZAP_OTHER, 0, 0);
3924 3923
3925 3924 if (ztest_object_init(zd, od, sizeof (od), !ztest_random(2)) != 0)
3926 3925 return;
3927 3926
3928 3927 object = od[0].od_object;
3929 3928
3930 3929 /*
↓ open down ↓ |
158 lines elided |
↑ open up ↑ |
3931 3930 * Generate a known hash collision, and verify that
3932 3931 * we can lookup and remove both entries.
3933 3932 */
3934 3933 tx = dmu_tx_create(os);
3935 3934 dmu_tx_hold_zap(tx, object, B_TRUE, NULL);
3936 3935 txg = ztest_tx_assign(tx, TXG_MIGHTWAIT, FTAG);
3937 3936 if (txg == 0)
3938 3937 return;
3939 3938 for (i = 0; i < 2; i++) {
3940 3939 value[i] = i;
3941 - VERIFY3U(0, ==, zap_add(os, object, hc[i], sizeof (uint64_t),
3940 + VERIFY0(zap_add(os, object, hc[i], sizeof (uint64_t),
3942 3941 1, &value[i], tx));
3943 3942 }
3944 3943 for (i = 0; i < 2; i++) {
3945 3944 VERIFY3U(EEXIST, ==, zap_add(os, object, hc[i],
3946 3945 sizeof (uint64_t), 1, &value[i], tx));
3947 - VERIFY3U(0, ==,
3948 - zap_length(os, object, hc[i], &zl_intsize, &zl_ints));
3946 + VERIFY0(zap_length(os, object, hc[i], &zl_intsize, &zl_ints));
3949 3947 ASSERT3U(zl_intsize, ==, sizeof (uint64_t));
3950 3948 ASSERT3U(zl_ints, ==, 1);
3951 3949 }
3952 3950 for (i = 0; i < 2; i++) {
3953 - VERIFY3U(0, ==, zap_remove(os, object, hc[i], tx));
3951 + VERIFY0(zap_remove(os, object, hc[i], tx));
3954 3952 }
3955 3953 dmu_tx_commit(tx);
3956 3954
3957 3955 /*
3958 3956 * Generate a buch of random entries.
3959 3957 */
3960 3958 ints = MAX(ZTEST_ZAP_MIN_INTS, object % ZTEST_ZAP_MAX_INTS);
3961 3959
3962 3960 prop = ztest_random(ZTEST_ZAP_MAX_PROPS);
3963 3961 (void) sprintf(propname, "prop_%llu", (u_longlong_t)prop);
3964 3962 (void) sprintf(txgname, "txg_%llu", (u_longlong_t)prop);
3965 3963 bzero(value, sizeof (value));
3966 3964 last_txg = 0;
3967 3965
3968 3966 /*
3969 3967 * If these zap entries already exist, validate their contents.
3970 3968 */
3971 3969 error = zap_length(os, object, txgname, &zl_intsize, &zl_ints);
3972 3970 if (error == 0) {
3973 3971 ASSERT3U(zl_intsize, ==, sizeof (uint64_t));
3974 3972 ASSERT3U(zl_ints, ==, 1);
3975 3973
3976 3974 VERIFY(zap_lookup(os, object, txgname, zl_intsize,
3977 3975 zl_ints, &last_txg) == 0);
3978 3976
3979 3977 VERIFY(zap_length(os, object, propname, &zl_intsize,
3980 3978 &zl_ints) == 0);
3981 3979
3982 3980 ASSERT3U(zl_intsize, ==, sizeof (uint64_t));
3983 3981 ASSERT3U(zl_ints, ==, ints);
3984 3982
3985 3983 VERIFY(zap_lookup(os, object, propname, zl_intsize,
3986 3984 zl_ints, value) == 0);
3987 3985
3988 3986 for (i = 0; i < ints; i++) {
3989 3987 ASSERT3U(value[i], ==, last_txg + object + i);
3990 3988 }
3991 3989 } else {
3992 3990 ASSERT3U(error, ==, ENOENT);
3993 3991 }
3994 3992
3995 3993 /*
3996 3994 * Atomically update two entries in our zap object.
3997 3995 * The first is named txg_%llu, and contains the txg
3998 3996 * in which the property was last updated. The second
3999 3997 * is named prop_%llu, and the nth element of its value
4000 3998 * should be txg + object + n.
4001 3999 */
4002 4000 tx = dmu_tx_create(os);
4003 4001 dmu_tx_hold_zap(tx, object, B_TRUE, NULL);
↓ open down ↓ |
40 lines elided |
↑ open up ↑ |
4004 4002 txg = ztest_tx_assign(tx, TXG_MIGHTWAIT, FTAG);
4005 4003 if (txg == 0)
4006 4004 return;
4007 4005
4008 4006 if (last_txg > txg)
4009 4007 fatal(0, "zap future leak: old %llu new %llu", last_txg, txg);
4010 4008
4011 4009 for (i = 0; i < ints; i++)
4012 4010 value[i] = txg + object + i;
4013 4011
4014 - VERIFY3U(0, ==, zap_update(os, object, txgname, sizeof (uint64_t),
4012 + VERIFY0(zap_update(os, object, txgname, sizeof (uint64_t),
4015 4013 1, &txg, tx));
4016 - VERIFY3U(0, ==, zap_update(os, object, propname, sizeof (uint64_t),
4014 + VERIFY0(zap_update(os, object, propname, sizeof (uint64_t),
4017 4015 ints, value, tx));
4018 4016
4019 4017 dmu_tx_commit(tx);
4020 4018
4021 4019 /*
4022 4020 * Remove a random pair of entries.
4023 4021 */
4024 4022 prop = ztest_random(ZTEST_ZAP_MAX_PROPS);
4025 4023 (void) sprintf(propname, "prop_%llu", (u_longlong_t)prop);
4026 4024 (void) sprintf(txgname, "txg_%llu", (u_longlong_t)prop);
4027 4025
4028 4026 error = zap_length(os, object, txgname, &zl_intsize, &zl_ints);
4029 4027
4030 4028 if (error == ENOENT)
4031 4029 return;
4032 4030
4033 - ASSERT3U(error, ==, 0);
4031 + ASSERT0(error);
4034 4032
4035 4033 tx = dmu_tx_create(os);
4036 4034 dmu_tx_hold_zap(tx, object, B_TRUE, NULL);
4037 4035 txg = ztest_tx_assign(tx, TXG_MIGHTWAIT, FTAG);
4038 4036 if (txg == 0)
4039 4037 return;
4040 - VERIFY3U(0, ==, zap_remove(os, object, txgname, tx));
4041 - VERIFY3U(0, ==, zap_remove(os, object, propname, tx));
4038 + VERIFY0(zap_remove(os, object, txgname, tx));
4039 + VERIFY0(zap_remove(os, object, propname, tx));
4042 4040 dmu_tx_commit(tx);
4043 4041 }
4044 4042
4045 4043 /*
4046 4044 * Testcase to test the upgrading of a microzap to fatzap.
4047 4045 */
4048 4046 void
4049 4047 ztest_fzap(ztest_ds_t *zd, uint64_t id)
4050 4048 {
4051 4049 objset_t *os = zd->zd_os;
4052 4050 ztest_od_t od[1];
4053 4051 uint64_t object, txg;
4054 4052
4055 4053 ztest_od_init(&od[0], id, FTAG, 0, DMU_OT_ZAP_OTHER, 0, 0);
4056 4054
4057 4055 if (ztest_object_init(zd, od, sizeof (od), !ztest_random(2)) != 0)
4058 4056 return;
4059 4057
4060 4058 object = od[0].od_object;
4061 4059
4062 4060 /*
4063 4061 * Add entries to this ZAP and make sure it spills over
4064 4062 * and gets upgraded to a fatzap. Also, since we are adding
4065 4063 * 2050 entries we should see ptrtbl growth and leaf-block split.
4066 4064 */
4067 4065 for (int i = 0; i < 2050; i++) {
4068 4066 char name[MAXNAMELEN];
4069 4067 uint64_t value = i;
4070 4068 dmu_tx_t *tx;
4071 4069 int error;
4072 4070
4073 4071 (void) snprintf(name, sizeof (name), "fzap-%llu-%llu",
4074 4072 id, value);
4075 4073
4076 4074 tx = dmu_tx_create(os);
4077 4075 dmu_tx_hold_zap(tx, object, B_TRUE, name);
4078 4076 txg = ztest_tx_assign(tx, TXG_MIGHTWAIT, FTAG);
4079 4077 if (txg == 0)
4080 4078 return;
4081 4079 error = zap_add(os, object, name, sizeof (uint64_t), 1,
4082 4080 &value, tx);
4083 4081 ASSERT(error == 0 || error == EEXIST);
4084 4082 dmu_tx_commit(tx);
4085 4083 }
4086 4084 }
4087 4085
4088 4086 /* ARGSUSED */
4089 4087 void
4090 4088 ztest_zap_parallel(ztest_ds_t *zd, uint64_t id)
4091 4089 {
4092 4090 objset_t *os = zd->zd_os;
4093 4091 ztest_od_t od[1];
4094 4092 uint64_t txg, object, count, wsize, wc, zl_wsize, zl_wc;
4095 4093 dmu_tx_t *tx;
4096 4094 int i, namelen, error;
4097 4095 int micro = ztest_random(2);
4098 4096 char name[20], string_value[20];
4099 4097 void *data;
4100 4098
4101 4099 ztest_od_init(&od[0], ID_PARALLEL, FTAG, micro, DMU_OT_ZAP_OTHER, 0, 0);
4102 4100
4103 4101 if (ztest_object_init(zd, od, sizeof (od), B_FALSE) != 0)
4104 4102 return;
4105 4103
4106 4104 object = od[0].od_object;
4107 4105
4108 4106 /*
4109 4107 * Generate a random name of the form 'xxx.....' where each
4110 4108 * x is a random printable character and the dots are dots.
4111 4109 * There are 94 such characters, and the name length goes from
4112 4110 * 6 to 20, so there are 94^3 * 15 = 12,458,760 possible names.
4113 4111 */
4114 4112 namelen = ztest_random(sizeof (name) - 5) + 5 + 1;
4115 4113
4116 4114 for (i = 0; i < 3; i++)
4117 4115 name[i] = '!' + ztest_random('~' - '!' + 1);
4118 4116 for (; i < namelen - 1; i++)
4119 4117 name[i] = '.';
4120 4118 name[i] = '\0';
4121 4119
4122 4120 if ((namelen & 1) || micro) {
4123 4121 wsize = sizeof (txg);
4124 4122 wc = 1;
4125 4123 data = &txg;
4126 4124 } else {
4127 4125 wsize = 1;
4128 4126 wc = namelen;
4129 4127 data = string_value;
4130 4128 }
4131 4129
4132 4130 count = -1ULL;
4133 4131 VERIFY(zap_count(os, object, &count) == 0);
4134 4132 ASSERT(count != -1ULL);
4135 4133
4136 4134 /*
4137 4135 * Select an operation: length, lookup, add, update, remove.
4138 4136 */
4139 4137 i = ztest_random(5);
4140 4138
4141 4139 if (i >= 2) {
4142 4140 tx = dmu_tx_create(os);
4143 4141 dmu_tx_hold_zap(tx, object, B_TRUE, NULL);
4144 4142 txg = ztest_tx_assign(tx, TXG_MIGHTWAIT, FTAG);
4145 4143 if (txg == 0)
4146 4144 return;
4147 4145 bcopy(name, string_value, namelen);
4148 4146 } else {
4149 4147 tx = NULL;
4150 4148 txg = 0;
4151 4149 bzero(string_value, namelen);
4152 4150 }
4153 4151
4154 4152 switch (i) {
4155 4153
4156 4154 case 0:
4157 4155 error = zap_length(os, object, name, &zl_wsize, &zl_wc);
4158 4156 if (error == 0) {
4159 4157 ASSERT3U(wsize, ==, zl_wsize);
4160 4158 ASSERT3U(wc, ==, zl_wc);
4161 4159 } else {
4162 4160 ASSERT3U(error, ==, ENOENT);
4163 4161 }
4164 4162 break;
4165 4163
4166 4164 case 1:
4167 4165 error = zap_lookup(os, object, name, wsize, wc, data);
4168 4166 if (error == 0) {
4169 4167 if (data == string_value &&
4170 4168 bcmp(name, data, namelen) != 0)
4171 4169 fatal(0, "name '%s' != val '%s' len %d",
4172 4170 name, data, namelen);
4173 4171 } else {
4174 4172 ASSERT3U(error, ==, ENOENT);
4175 4173 }
4176 4174 break;
4177 4175
4178 4176 case 2:
4179 4177 error = zap_add(os, object, name, wsize, wc, data, tx);
4180 4178 ASSERT(error == 0 || error == EEXIST);
4181 4179 break;
4182 4180
4183 4181 case 3:
4184 4182 VERIFY(zap_update(os, object, name, wsize, wc, data, tx) == 0);
4185 4183 break;
4186 4184
4187 4185 case 4:
4188 4186 error = zap_remove(os, object, name, tx);
4189 4187 ASSERT(error == 0 || error == ENOENT);
4190 4188 break;
4191 4189 }
4192 4190
4193 4191 if (tx != NULL)
4194 4192 dmu_tx_commit(tx);
4195 4193 }
4196 4194
4197 4195 /*
4198 4196 * Commit callback data.
4199 4197 */
4200 4198 typedef struct ztest_cb_data {
4201 4199 list_node_t zcd_node;
4202 4200 uint64_t zcd_txg;
4203 4201 int zcd_expected_err;
4204 4202 boolean_t zcd_added;
4205 4203 boolean_t zcd_called;
4206 4204 spa_t *zcd_spa;
4207 4205 } ztest_cb_data_t;
4208 4206
4209 4207 /* This is the actual commit callback function */
4210 4208 static void
4211 4209 ztest_commit_callback(void *arg, int error)
4212 4210 {
4213 4211 ztest_cb_data_t *data = arg;
4214 4212 uint64_t synced_txg;
4215 4213
4216 4214 VERIFY(data != NULL);
4217 4215 VERIFY3S(data->zcd_expected_err, ==, error);
4218 4216 VERIFY(!data->zcd_called);
↓ open down ↓ |
167 lines elided |
↑ open up ↑ |
4219 4217
4220 4218 synced_txg = spa_last_synced_txg(data->zcd_spa);
4221 4219 if (data->zcd_txg > synced_txg)
4222 4220 fatal(0, "commit callback of txg %" PRIu64 " called prematurely"
4223 4221 ", last synced txg = %" PRIu64 "\n", data->zcd_txg,
4224 4222 synced_txg);
4225 4223
4226 4224 data->zcd_called = B_TRUE;
4227 4225
4228 4226 if (error == ECANCELED) {
4229 - ASSERT3U(data->zcd_txg, ==, 0);
4227 + ASSERT0(data->zcd_txg);
4230 4228 ASSERT(!data->zcd_added);
4231 4229
4232 4230 /*
4233 4231 * The private callback data should be destroyed here, but
4234 4232 * since we are going to check the zcd_called field after
4235 4233 * dmu_tx_abort(), we will destroy it there.
4236 4234 */
4237 4235 return;
4238 4236 }
4239 4237
4240 4238 /* Was this callback added to the global callback list? */
4241 4239 if (!data->zcd_added)
4242 4240 goto out;
4243 4241
4244 4242 ASSERT3U(data->zcd_txg, !=, 0);
4245 4243
4246 4244 /* Remove our callback from the list */
4247 4245 (void) mutex_lock(&zcl.zcl_callbacks_lock);
4248 4246 list_remove(&zcl.zcl_callbacks, data);
4249 4247 (void) mutex_unlock(&zcl.zcl_callbacks_lock);
4250 4248
4251 4249 out:
4252 4250 umem_free(data, sizeof (ztest_cb_data_t));
4253 4251 }
4254 4252
4255 4253 /* Allocate and initialize callback data structure */
4256 4254 static ztest_cb_data_t *
4257 4255 ztest_create_cb_data(objset_t *os, uint64_t txg)
4258 4256 {
4259 4257 ztest_cb_data_t *cb_data;
4260 4258
4261 4259 cb_data = umem_zalloc(sizeof (ztest_cb_data_t), UMEM_NOFAIL);
4262 4260
4263 4261 cb_data->zcd_txg = txg;
4264 4262 cb_data->zcd_spa = dmu_objset_spa(os);
4265 4263
4266 4264 return (cb_data);
4267 4265 }
4268 4266
4269 4267 /*
4270 4268 * If a number of txgs equal to this threshold have been created after a commit
4271 4269 * callback has been registered but not called, then we assume there is an
4272 4270 * implementation bug.
4273 4271 */
4274 4272 #define ZTEST_COMMIT_CALLBACK_THRESH (TXG_CONCURRENT_STATES + 2)
4275 4273
4276 4274 /*
4277 4275 * Commit callback test.
4278 4276 */
4279 4277 void
4280 4278 ztest_dmu_commit_callbacks(ztest_ds_t *zd, uint64_t id)
4281 4279 {
4282 4280 objset_t *os = zd->zd_os;
4283 4281 ztest_od_t od[1];
4284 4282 dmu_tx_t *tx;
4285 4283 ztest_cb_data_t *cb_data[3], *tmp_cb;
4286 4284 uint64_t old_txg, txg;
4287 4285 int i, error;
4288 4286
4289 4287 ztest_od_init(&od[0], id, FTAG, 0, DMU_OT_UINT64_OTHER, 0, 0);
4290 4288
4291 4289 if (ztest_object_init(zd, od, sizeof (od), B_FALSE) != 0)
4292 4290 return;
4293 4291
4294 4292 tx = dmu_tx_create(os);
4295 4293
4296 4294 cb_data[0] = ztest_create_cb_data(os, 0);
4297 4295 dmu_tx_callback_register(tx, ztest_commit_callback, cb_data[0]);
4298 4296
4299 4297 dmu_tx_hold_write(tx, od[0].od_object, 0, sizeof (uint64_t));
4300 4298
4301 4299 /* Every once in a while, abort the transaction on purpose */
4302 4300 if (ztest_random(100) == 0)
4303 4301 error = -1;
4304 4302
4305 4303 if (!error)
4306 4304 error = dmu_tx_assign(tx, TXG_NOWAIT);
4307 4305
4308 4306 txg = error ? 0 : dmu_tx_get_txg(tx);
4309 4307
4310 4308 cb_data[0]->zcd_txg = txg;
4311 4309 cb_data[1] = ztest_create_cb_data(os, txg);
4312 4310 dmu_tx_callback_register(tx, ztest_commit_callback, cb_data[1]);
4313 4311
4314 4312 if (error) {
4315 4313 /*
4316 4314 * It's not a strict requirement to call the registered
4317 4315 * callbacks from inside dmu_tx_abort(), but that's what
4318 4316 * it's supposed to happen in the current implementation
4319 4317 * so we will check for that.
4320 4318 */
4321 4319 for (i = 0; i < 2; i++) {
4322 4320 cb_data[i]->zcd_expected_err = ECANCELED;
4323 4321 VERIFY(!cb_data[i]->zcd_called);
4324 4322 }
4325 4323
4326 4324 dmu_tx_abort(tx);
4327 4325
4328 4326 for (i = 0; i < 2; i++) {
4329 4327 VERIFY(cb_data[i]->zcd_called);
4330 4328 umem_free(cb_data[i], sizeof (ztest_cb_data_t));
4331 4329 }
4332 4330
4333 4331 return;
4334 4332 }
4335 4333
4336 4334 cb_data[2] = ztest_create_cb_data(os, txg);
4337 4335 dmu_tx_callback_register(tx, ztest_commit_callback, cb_data[2]);
4338 4336
4339 4337 /*
4340 4338 * Read existing data to make sure there isn't a future leak.
4341 4339 */
4342 4340 VERIFY(0 == dmu_read(os, od[0].od_object, 0, sizeof (uint64_t),
4343 4341 &old_txg, DMU_READ_PREFETCH));
4344 4342
4345 4343 if (old_txg > txg)
4346 4344 fatal(0, "future leak: got %" PRIu64 ", open txg is %" PRIu64,
4347 4345 old_txg, txg);
4348 4346
4349 4347 dmu_write(os, od[0].od_object, 0, sizeof (uint64_t), &txg, tx);
4350 4348
4351 4349 (void) mutex_lock(&zcl.zcl_callbacks_lock);
4352 4350
4353 4351 /*
4354 4352 * Since commit callbacks don't have any ordering requirement and since
4355 4353 * it is theoretically possible for a commit callback to be called
4356 4354 * after an arbitrary amount of time has elapsed since its txg has been
4357 4355 * synced, it is difficult to reliably determine whether a commit
4358 4356 * callback hasn't been called due to high load or due to a flawed
4359 4357 * implementation.
4360 4358 *
4361 4359 * In practice, we will assume that if after a certain number of txgs a
4362 4360 * commit callback hasn't been called, then most likely there's an
4363 4361 * implementation bug..
4364 4362 */
4365 4363 tmp_cb = list_head(&zcl.zcl_callbacks);
4366 4364 if (tmp_cb != NULL &&
4367 4365 tmp_cb->zcd_txg > txg - ZTEST_COMMIT_CALLBACK_THRESH) {
4368 4366 fatal(0, "Commit callback threshold exceeded, oldest txg: %"
4369 4367 PRIu64 ", open txg: %" PRIu64 "\n", tmp_cb->zcd_txg, txg);
4370 4368 }
4371 4369
4372 4370 /*
4373 4371 * Let's find the place to insert our callbacks.
4374 4372 *
4375 4373 * Even though the list is ordered by txg, it is possible for the
4376 4374 * insertion point to not be the end because our txg may already be
4377 4375 * quiescing at this point and other callbacks in the open txg
4378 4376 * (from other objsets) may have sneaked in.
4379 4377 */
4380 4378 tmp_cb = list_tail(&zcl.zcl_callbacks);
4381 4379 while (tmp_cb != NULL && tmp_cb->zcd_txg > txg)
4382 4380 tmp_cb = list_prev(&zcl.zcl_callbacks, tmp_cb);
4383 4381
4384 4382 /* Add the 3 callbacks to the list */
4385 4383 for (i = 0; i < 3; i++) {
4386 4384 if (tmp_cb == NULL)
4387 4385 list_insert_head(&zcl.zcl_callbacks, cb_data[i]);
4388 4386 else
4389 4387 list_insert_after(&zcl.zcl_callbacks, tmp_cb,
4390 4388 cb_data[i]);
4391 4389
4392 4390 cb_data[i]->zcd_added = B_TRUE;
4393 4391 VERIFY(!cb_data[i]->zcd_called);
4394 4392
4395 4393 tmp_cb = cb_data[i];
4396 4394 }
4397 4395
4398 4396 (void) mutex_unlock(&zcl.zcl_callbacks_lock);
4399 4397
4400 4398 dmu_tx_commit(tx);
4401 4399 }
4402 4400
4403 4401 /* ARGSUSED */
4404 4402 void
4405 4403 ztest_dsl_prop_get_set(ztest_ds_t *zd, uint64_t id)
4406 4404 {
4407 4405 zfs_prop_t proplist[] = {
4408 4406 ZFS_PROP_CHECKSUM,
4409 4407 ZFS_PROP_COMPRESSION,
4410 4408 ZFS_PROP_COPIES,
4411 4409 ZFS_PROP_DEDUP
4412 4410 };
4413 4411
4414 4412 (void) rw_rdlock(&ztest_name_lock);
4415 4413
4416 4414 for (int p = 0; p < sizeof (proplist) / sizeof (proplist[0]); p++)
4417 4415 (void) ztest_dsl_prop_set_uint64(zd->zd_name, proplist[p],
4418 4416 ztest_random_dsl_prop(proplist[p]), (int)ztest_random(2));
4419 4417
4420 4418 (void) rw_unlock(&ztest_name_lock);
4421 4419 }
4422 4420
4423 4421 /* ARGSUSED */
↓ open down ↓ |
184 lines elided |
↑ open up ↑ |
4424 4422 void
4425 4423 ztest_spa_prop_get_set(ztest_ds_t *zd, uint64_t id)
4426 4424 {
4427 4425 nvlist_t *props = NULL;
4428 4426
4429 4427 (void) rw_rdlock(&ztest_name_lock);
4430 4428
4431 4429 (void) ztest_spa_prop_set_uint64(ZPOOL_PROP_DEDUPDITTO,
4432 4430 ZIO_DEDUPDITTO_MIN + ztest_random(ZIO_DEDUPDITTO_MIN));
4433 4431
4434 - VERIFY3U(spa_prop_get(ztest_spa, &props), ==, 0);
4432 + VERIFY0(spa_prop_get(ztest_spa, &props));
4435 4433
4436 4434 if (ztest_opts.zo_verbose >= 6)
4437 4435 dump_nvlist(props, 4);
4438 4436
4439 4437 nvlist_free(props);
4440 4438
4441 4439 (void) rw_unlock(&ztest_name_lock);
4442 4440 }
4443 4441
4444 4442 /*
4445 4443 * Test snapshot hold/release and deferred destroy.
4446 4444 */
4447 4445 void
4448 4446 ztest_dmu_snapshot_hold(ztest_ds_t *zd, uint64_t id)
4449 4447 {
4450 4448 int error;
4451 4449 objset_t *os = zd->zd_os;
4452 4450 objset_t *origin;
4453 4451 char snapname[100];
4454 4452 char fullname[100];
4455 4453 char clonename[100];
4456 4454 char tag[100];
4457 4455 char osname[MAXNAMELEN];
4458 4456
4459 4457 (void) rw_rdlock(&ztest_name_lock);
4460 4458
4461 4459 dmu_objset_name(os, osname);
4462 4460
4463 4461 (void) snprintf(snapname, 100, "sh1_%llu", id);
4464 4462 (void) snprintf(fullname, 100, "%s@%s", osname, snapname);
4465 4463 (void) snprintf(clonename, 100, "%s/ch1_%llu", osname, id);
4466 4464 (void) snprintf(tag, 100, "%tag_%llu", id);
4467 4465
4468 4466 /*
4469 4467 * Clean up from any previous run.
4470 4468 */
4471 4469 (void) dmu_objset_destroy(clonename, B_FALSE);
4472 4470 (void) dsl_dataset_user_release(osname, snapname, tag, B_FALSE);
4473 4471 (void) dmu_objset_destroy(fullname, B_FALSE);
4474 4472
4475 4473 /*
4476 4474 * Create snapshot, clone it, mark snap for deferred destroy,
4477 4475 * destroy clone, verify snap was also destroyed.
4478 4476 */
4479 4477 error = dmu_objset_snapshot_one(osname, snapname);
4480 4478 if (error) {
4481 4479 if (error == ENOSPC) {
4482 4480 ztest_record_enospc("dmu_objset_snapshot");
4483 4481 goto out;
4484 4482 }
4485 4483 fatal(0, "dmu_objset_snapshot(%s) = %d", fullname, error);
4486 4484 }
4487 4485
4488 4486 error = dmu_objset_hold(fullname, FTAG, &origin);
4489 4487 if (error)
4490 4488 fatal(0, "dmu_objset_hold(%s) = %d", fullname, error);
4491 4489
4492 4490 error = dmu_objset_clone(clonename, dmu_objset_ds(origin), 0);
4493 4491 dmu_objset_rele(origin, FTAG);
4494 4492 if (error) {
4495 4493 if (error == ENOSPC) {
4496 4494 ztest_record_enospc("dmu_objset_clone");
4497 4495 goto out;
4498 4496 }
4499 4497 fatal(0, "dmu_objset_clone(%s) = %d", clonename, error);
4500 4498 }
4501 4499
4502 4500 error = dmu_objset_destroy(fullname, B_TRUE);
4503 4501 if (error) {
4504 4502 fatal(0, "dmu_objset_destroy(%s, B_TRUE) = %d",
4505 4503 fullname, error);
4506 4504 }
4507 4505
4508 4506 error = dmu_objset_destroy(clonename, B_FALSE);
4509 4507 if (error)
4510 4508 fatal(0, "dmu_objset_destroy(%s) = %d", clonename, error);
4511 4509
4512 4510 error = dmu_objset_hold(fullname, FTAG, &origin);
4513 4511 if (error != ENOENT)
4514 4512 fatal(0, "dmu_objset_hold(%s) = %d", fullname, error);
4515 4513
4516 4514 /*
4517 4515 * Create snapshot, add temporary hold, verify that we can't
4518 4516 * destroy a held snapshot, mark for deferred destroy,
4519 4517 * release hold, verify snapshot was destroyed.
4520 4518 */
4521 4519 error = dmu_objset_snapshot_one(osname, snapname);
4522 4520 if (error) {
4523 4521 if (error == ENOSPC) {
4524 4522 ztest_record_enospc("dmu_objset_snapshot");
4525 4523 goto out;
4526 4524 }
4527 4525 fatal(0, "dmu_objset_snapshot(%s) = %d", fullname, error);
4528 4526 }
4529 4527
4530 4528 error = dsl_dataset_user_hold(osname, snapname, tag, B_FALSE,
4531 4529 B_TRUE, -1);
4532 4530 if (error)
4533 4531 fatal(0, "dsl_dataset_user_hold(%s)", fullname, tag);
4534 4532
4535 4533 error = dmu_objset_destroy(fullname, B_FALSE);
4536 4534 if (error != EBUSY) {
4537 4535 fatal(0, "dmu_objset_destroy(%s, B_FALSE) = %d",
4538 4536 fullname, error);
4539 4537 }
4540 4538
4541 4539 error = dmu_objset_destroy(fullname, B_TRUE);
4542 4540 if (error) {
4543 4541 fatal(0, "dmu_objset_destroy(%s, B_TRUE) = %d",
4544 4542 fullname, error);
4545 4543 }
4546 4544
4547 4545 error = dsl_dataset_user_release(osname, snapname, tag, B_FALSE);
4548 4546 if (error)
4549 4547 fatal(0, "dsl_dataset_user_release(%s)", fullname, tag);
4550 4548
4551 4549 VERIFY(dmu_objset_hold(fullname, FTAG, &origin) == ENOENT);
4552 4550
4553 4551 out:
4554 4552 (void) rw_unlock(&ztest_name_lock);
4555 4553 }
4556 4554
4557 4555 /*
4558 4556 * Inject random faults into the on-disk data.
4559 4557 */
4560 4558 /* ARGSUSED */
4561 4559 void
4562 4560 ztest_fault_inject(ztest_ds_t *zd, uint64_t id)
4563 4561 {
4564 4562 ztest_shared_t *zs = ztest_shared;
4565 4563 spa_t *spa = ztest_spa;
4566 4564 int fd;
4567 4565 uint64_t offset;
4568 4566 uint64_t leaves;
4569 4567 uint64_t bad = 0x1990c0ffeedecade;
4570 4568 uint64_t top, leaf;
4571 4569 char path0[MAXPATHLEN];
4572 4570 char pathrand[MAXPATHLEN];
4573 4571 size_t fsize;
4574 4572 int bshift = SPA_MAXBLOCKSHIFT + 2; /* don't scrog all labels */
4575 4573 int iters = 1000;
4576 4574 int maxfaults;
4577 4575 int mirror_save;
4578 4576 vdev_t *vd0 = NULL;
4579 4577 uint64_t guid0 = 0;
4580 4578 boolean_t islog = B_FALSE;
4581 4579
4582 4580 VERIFY(mutex_lock(&ztest_vdev_lock) == 0);
4583 4581 maxfaults = MAXFAULTS();
4584 4582 leaves = MAX(zs->zs_mirrors, 1) * ztest_opts.zo_raidz;
4585 4583 mirror_save = zs->zs_mirrors;
4586 4584 VERIFY(mutex_unlock(&ztest_vdev_lock) == 0);
4587 4585
4588 4586 ASSERT(leaves >= 1);
4589 4587
4590 4588 /*
4591 4589 * We need SCL_STATE here because we're going to look at vd0->vdev_tsd.
4592 4590 */
4593 4591 spa_config_enter(spa, SCL_STATE, FTAG, RW_READER);
4594 4592
4595 4593 if (ztest_random(2) == 0) {
4596 4594 /*
4597 4595 * Inject errors on a normal data device or slog device.
4598 4596 */
4599 4597 top = ztest_random_vdev_top(spa, B_TRUE);
4600 4598 leaf = ztest_random(leaves) + zs->zs_splits;
4601 4599
4602 4600 /*
4603 4601 * Generate paths to the first leaf in this top-level vdev,
4604 4602 * and to the random leaf we selected. We'll induce transient
4605 4603 * write failures and random online/offline activity on leaf 0,
4606 4604 * and we'll write random garbage to the randomly chosen leaf.
4607 4605 */
4608 4606 (void) snprintf(path0, sizeof (path0), ztest_dev_template,
4609 4607 ztest_opts.zo_dir, ztest_opts.zo_pool,
4610 4608 top * leaves + zs->zs_splits);
4611 4609 (void) snprintf(pathrand, sizeof (pathrand), ztest_dev_template,
4612 4610 ztest_opts.zo_dir, ztest_opts.zo_pool,
4613 4611 top * leaves + leaf);
4614 4612
4615 4613 vd0 = vdev_lookup_by_path(spa->spa_root_vdev, path0);
4616 4614 if (vd0 != NULL && vd0->vdev_top->vdev_islog)
4617 4615 islog = B_TRUE;
4618 4616
4619 4617 if (vd0 != NULL && maxfaults != 1) {
4620 4618 /*
4621 4619 * Make vd0 explicitly claim to be unreadable,
4622 4620 * or unwriteable, or reach behind its back
4623 4621 * and close the underlying fd. We can do this if
4624 4622 * maxfaults == 0 because we'll fail and reexecute,
4625 4623 * and we can do it if maxfaults >= 2 because we'll
4626 4624 * have enough redundancy. If maxfaults == 1, the
4627 4625 * combination of this with injection of random data
4628 4626 * corruption below exceeds the pool's fault tolerance.
4629 4627 */
4630 4628 vdev_file_t *vf = vd0->vdev_tsd;
4631 4629
4632 4630 if (vf != NULL && ztest_random(3) == 0) {
4633 4631 (void) close(vf->vf_vnode->v_fd);
4634 4632 vf->vf_vnode->v_fd = -1;
4635 4633 } else if (ztest_random(2) == 0) {
4636 4634 vd0->vdev_cant_read = B_TRUE;
4637 4635 } else {
4638 4636 vd0->vdev_cant_write = B_TRUE;
4639 4637 }
4640 4638 guid0 = vd0->vdev_guid;
4641 4639 }
4642 4640 } else {
4643 4641 /*
4644 4642 * Inject errors on an l2cache device.
4645 4643 */
4646 4644 spa_aux_vdev_t *sav = &spa->spa_l2cache;
4647 4645
4648 4646 if (sav->sav_count == 0) {
4649 4647 spa_config_exit(spa, SCL_STATE, FTAG);
4650 4648 return;
4651 4649 }
4652 4650 vd0 = sav->sav_vdevs[ztest_random(sav->sav_count)];
4653 4651 guid0 = vd0->vdev_guid;
4654 4652 (void) strcpy(path0, vd0->vdev_path);
4655 4653 (void) strcpy(pathrand, vd0->vdev_path);
4656 4654
4657 4655 leaf = 0;
4658 4656 leaves = 1;
4659 4657 maxfaults = INT_MAX; /* no limit on cache devices */
4660 4658 }
4661 4659
4662 4660 spa_config_exit(spa, SCL_STATE, FTAG);
4663 4661
4664 4662 /*
4665 4663 * If we can tolerate two or more faults, or we're dealing
4666 4664 * with a slog, randomly online/offline vd0.
4667 4665 */
4668 4666 if ((maxfaults >= 2 || islog) && guid0 != 0) {
4669 4667 if (ztest_random(10) < 6) {
4670 4668 int flags = (ztest_random(2) == 0 ?
4671 4669 ZFS_OFFLINE_TEMPORARY : 0);
4672 4670
4673 4671 /*
4674 4672 * We have to grab the zs_name_lock as writer to
4675 4673 * prevent a race between offlining a slog and
4676 4674 * destroying a dataset. Offlining the slog will
4677 4675 * grab a reference on the dataset which may cause
4678 4676 * dmu_objset_destroy() to fail with EBUSY thus
4679 4677 * leaving the dataset in an inconsistent state.
4680 4678 */
4681 4679 if (islog)
4682 4680 (void) rw_wrlock(&ztest_name_lock);
4683 4681
4684 4682 VERIFY(vdev_offline(spa, guid0, flags) != EBUSY);
4685 4683
4686 4684 if (islog)
4687 4685 (void) rw_unlock(&ztest_name_lock);
4688 4686 } else {
4689 4687 (void) vdev_online(spa, guid0, 0, NULL);
4690 4688 }
4691 4689 }
4692 4690
4693 4691 if (maxfaults == 0)
4694 4692 return;
4695 4693
4696 4694 /*
4697 4695 * We have at least single-fault tolerance, so inject data corruption.
4698 4696 */
4699 4697 fd = open(pathrand, O_RDWR);
4700 4698
4701 4699 if (fd == -1) /* we hit a gap in the device namespace */
4702 4700 return;
4703 4701
4704 4702 fsize = lseek(fd, 0, SEEK_END);
4705 4703
4706 4704 while (--iters != 0) {
4707 4705 offset = ztest_random(fsize / (leaves << bshift)) *
4708 4706 (leaves << bshift) + (leaf << bshift) +
4709 4707 (ztest_random(1ULL << (bshift - 1)) & -8ULL);
4710 4708
4711 4709 if (offset >= fsize)
4712 4710 continue;
4713 4711
4714 4712 VERIFY(mutex_lock(&ztest_vdev_lock) == 0);
4715 4713 if (mirror_save != zs->zs_mirrors) {
4716 4714 VERIFY(mutex_unlock(&ztest_vdev_lock) == 0);
4717 4715 (void) close(fd);
4718 4716 return;
4719 4717 }
4720 4718
4721 4719 if (pwrite(fd, &bad, sizeof (bad), offset) != sizeof (bad))
4722 4720 fatal(1, "can't inject bad word at 0x%llx in %s",
4723 4721 offset, pathrand);
4724 4722
4725 4723 VERIFY(mutex_unlock(&ztest_vdev_lock) == 0);
4726 4724
4727 4725 if (ztest_opts.zo_verbose >= 7)
4728 4726 (void) printf("injected bad word into %s,"
4729 4727 " offset 0x%llx\n", pathrand, (u_longlong_t)offset);
4730 4728 }
4731 4729
4732 4730 (void) close(fd);
4733 4731 }
4734 4732
4735 4733 /*
4736 4734 * Verify that DDT repair works as expected.
4737 4735 */
4738 4736 void
4739 4737 ztest_ddt_repair(ztest_ds_t *zd, uint64_t id)
4740 4738 {
4741 4739 ztest_shared_t *zs = ztest_shared;
4742 4740 spa_t *spa = ztest_spa;
4743 4741 objset_t *os = zd->zd_os;
4744 4742 ztest_od_t od[1];
4745 4743 uint64_t object, blocksize, txg, pattern, psize;
4746 4744 enum zio_checksum checksum = spa_dedup_checksum(spa);
4747 4745 dmu_buf_t *db;
4748 4746 dmu_tx_t *tx;
4749 4747 void *buf;
4750 4748 blkptr_t blk;
4751 4749 int copies = 2 * ZIO_DEDUPDITTO_MIN;
4752 4750
4753 4751 blocksize = ztest_random_blocksize();
4754 4752 blocksize = MIN(blocksize, 2048); /* because we write so many */
4755 4753
4756 4754 ztest_od_init(&od[0], id, FTAG, 0, DMU_OT_UINT64_OTHER, blocksize, 0);
4757 4755
4758 4756 if (ztest_object_init(zd, od, sizeof (od), B_FALSE) != 0)
4759 4757 return;
4760 4758
4761 4759 /*
4762 4760 * Take the name lock as writer to prevent anyone else from changing
4763 4761 * the pool and dataset properies we need to maintain during this test.
4764 4762 */
4765 4763 (void) rw_wrlock(&ztest_name_lock);
4766 4764
4767 4765 if (ztest_dsl_prop_set_uint64(zd->zd_name, ZFS_PROP_DEDUP, checksum,
4768 4766 B_FALSE) != 0 ||
4769 4767 ztest_dsl_prop_set_uint64(zd->zd_name, ZFS_PROP_COPIES, 1,
4770 4768 B_FALSE) != 0) {
4771 4769 (void) rw_unlock(&ztest_name_lock);
4772 4770 return;
4773 4771 }
4774 4772
4775 4773 object = od[0].od_object;
4776 4774 blocksize = od[0].od_blocksize;
4777 4775 pattern = zs->zs_guid ^ dmu_objset_fsid_guid(os);
4778 4776
4779 4777 ASSERT(object != 0);
4780 4778
4781 4779 tx = dmu_tx_create(os);
4782 4780 dmu_tx_hold_write(tx, object, 0, copies * blocksize);
4783 4781 txg = ztest_tx_assign(tx, TXG_WAIT, FTAG);
4784 4782 if (txg == 0) {
4785 4783 (void) rw_unlock(&ztest_name_lock);
4786 4784 return;
4787 4785 }
4788 4786
4789 4787 /*
4790 4788 * Write all the copies of our block.
4791 4789 */
4792 4790 for (int i = 0; i < copies; i++) {
4793 4791 uint64_t offset = i * blocksize;
4794 4792 VERIFY(dmu_buf_hold(os, object, offset, FTAG, &db,
4795 4793 DMU_READ_NO_PREFETCH) == 0);
4796 4794 ASSERT(db->db_offset == offset);
4797 4795 ASSERT(db->db_size == blocksize);
4798 4796 ASSERT(ztest_pattern_match(db->db_data, db->db_size, pattern) ||
4799 4797 ztest_pattern_match(db->db_data, db->db_size, 0ULL));
4800 4798 dmu_buf_will_fill(db, tx);
4801 4799 ztest_pattern_set(db->db_data, db->db_size, pattern);
4802 4800 dmu_buf_rele(db, FTAG);
4803 4801 }
4804 4802
4805 4803 dmu_tx_commit(tx);
4806 4804 txg_wait_synced(spa_get_dsl(spa), txg);
4807 4805
4808 4806 /*
4809 4807 * Find out what block we got.
4810 4808 */
4811 4809 VERIFY(dmu_buf_hold(os, object, 0, FTAG, &db,
4812 4810 DMU_READ_NO_PREFETCH) == 0);
4813 4811 blk = *((dmu_buf_impl_t *)db)->db_blkptr;
4814 4812 dmu_buf_rele(db, FTAG);
4815 4813
4816 4814 /*
4817 4815 * Damage the block. Dedup-ditto will save us when we read it later.
4818 4816 */
4819 4817 psize = BP_GET_PSIZE(&blk);
4820 4818 buf = zio_buf_alloc(psize);
4821 4819 ztest_pattern_set(buf, psize, ~pattern);
4822 4820
4823 4821 (void) zio_wait(zio_rewrite(NULL, spa, 0, &blk,
4824 4822 buf, psize, NULL, NULL, ZIO_PRIORITY_SYNC_WRITE,
4825 4823 ZIO_FLAG_CANFAIL | ZIO_FLAG_INDUCE_DAMAGE, NULL));
4826 4824
4827 4825 zio_buf_free(buf, psize);
4828 4826
4829 4827 (void) rw_unlock(&ztest_name_lock);
4830 4828 }
4831 4829
4832 4830 /*
4833 4831 * Scrub the pool.
4834 4832 */
4835 4833 /* ARGSUSED */
4836 4834 void
4837 4835 ztest_scrub(ztest_ds_t *zd, uint64_t id)
4838 4836 {
4839 4837 spa_t *spa = ztest_spa;
4840 4838
4841 4839 (void) spa_scan(spa, POOL_SCAN_SCRUB);
4842 4840 (void) poll(NULL, 0, 100); /* wait a moment, then force a restart */
4843 4841 (void) spa_scan(spa, POOL_SCAN_SCRUB);
4844 4842 }
4845 4843
4846 4844 /*
4847 4845 * Change the guid for the pool.
4848 4846 */
4849 4847 /* ARGSUSED */
4850 4848 void
4851 4849 ztest_reguid(ztest_ds_t *zd, uint64_t id)
4852 4850 {
4853 4851 spa_t *spa = ztest_spa;
4854 4852 uint64_t orig, load;
4855 4853
4856 4854 orig = spa_guid(spa);
4857 4855 load = spa_load_guid(spa);
4858 4856 if (spa_change_guid(spa) != 0)
4859 4857 return;
4860 4858
4861 4859 if (ztest_opts.zo_verbose >= 3) {
4862 4860 (void) printf("Changed guid old %llu -> %llu\n",
4863 4861 (u_longlong_t)orig, (u_longlong_t)spa_guid(spa));
4864 4862 }
4865 4863
4866 4864 VERIFY3U(orig, !=, spa_guid(spa));
4867 4865 VERIFY3U(load, ==, spa_load_guid(spa));
4868 4866 }
4869 4867
4870 4868 /*
4871 4869 * Rename the pool to a different name and then rename it back.
4872 4870 */
4873 4871 /* ARGSUSED */
4874 4872 void
4875 4873 ztest_spa_rename(ztest_ds_t *zd, uint64_t id)
4876 4874 {
4877 4875 char *oldname, *newname;
4878 4876 spa_t *spa;
4879 4877
↓ open down ↓ |
435 lines elided |
↑ open up ↑ |
4880 4878 (void) rw_wrlock(&ztest_name_lock);
4881 4879
4882 4880 oldname = ztest_opts.zo_pool;
4883 4881 newname = umem_alloc(strlen(oldname) + 5, UMEM_NOFAIL);
4884 4882 (void) strcpy(newname, oldname);
4885 4883 (void) strcat(newname, "_tmp");
4886 4884
4887 4885 /*
4888 4886 * Do the rename
4889 4887 */
4890 - VERIFY3U(0, ==, spa_rename(oldname, newname));
4888 + VERIFY0(spa_rename(oldname, newname));
4891 4889
4892 4890 /*
4893 4891 * Try to open it under the old name, which shouldn't exist
4894 4892 */
4895 4893 VERIFY3U(ENOENT, ==, spa_open(oldname, &spa, FTAG));
4896 4894
4897 4895 /*
4898 4896 * Open it under the new name and make sure it's still the same spa_t.
4899 4897 */
4900 - VERIFY3U(0, ==, spa_open(newname, &spa, FTAG));
4898 + VERIFY0(spa_open(newname, &spa, FTAG));
4901 4899
4902 4900 ASSERT(spa == ztest_spa);
4903 4901 spa_close(spa, FTAG);
4904 4902
4905 4903 /*
4906 4904 * Rename it back to the original
4907 4905 */
4908 - VERIFY3U(0, ==, spa_rename(newname, oldname));
4906 + VERIFY0(spa_rename(newname, oldname));
4909 4907
4910 4908 /*
4911 4909 * Make sure it can still be opened
4912 4910 */
4913 - VERIFY3U(0, ==, spa_open(oldname, &spa, FTAG));
4911 + VERIFY0(spa_open(oldname, &spa, FTAG));
4914 4912
4915 4913 ASSERT(spa == ztest_spa);
4916 4914 spa_close(spa, FTAG);
4917 4915
4918 4916 umem_free(newname, strlen(newname) + 1);
4919 4917
4920 4918 (void) rw_unlock(&ztest_name_lock);
4921 4919 }
4922 4920
4923 4921 /*
4924 4922 * Verify pool integrity by running zdb.
4925 4923 */
4926 4924 static void
4927 4925 ztest_run_zdb(char *pool)
4928 4926 {
4929 4927 int status;
4930 4928 char zdb[MAXPATHLEN + MAXNAMELEN + 20];
4931 4929 char zbuf[1024];
4932 4930 char *bin;
4933 4931 char *ztest;
4934 4932 char *isa;
4935 4933 int isalen;
4936 4934 FILE *fp;
4937 4935
4938 4936 (void) realpath(getexecname(), zdb);
4939 4937
4940 4938 /* zdb lives in /usr/sbin, while ztest lives in /usr/bin */
4941 4939 bin = strstr(zdb, "/usr/bin/");
4942 4940 ztest = strstr(bin, "/ztest");
4943 4941 isa = bin + 8;
4944 4942 isalen = ztest - isa;
4945 4943 isa = strdup(isa);
4946 4944 /* LINTED */
4947 4945 (void) sprintf(bin,
4948 4946 "/usr/sbin%.*s/zdb -bcc%s%s -U %s %s",
4949 4947 isalen,
4950 4948 isa,
4951 4949 ztest_opts.zo_verbose >= 3 ? "s" : "",
4952 4950 ztest_opts.zo_verbose >= 4 ? "v" : "",
4953 4951 spa_config_path,
4954 4952 pool);
4955 4953 free(isa);
4956 4954
4957 4955 if (ztest_opts.zo_verbose >= 5)
4958 4956 (void) printf("Executing %s\n", strstr(zdb, "zdb "));
4959 4957
4960 4958 fp = popen(zdb, "r");
4961 4959
4962 4960 while (fgets(zbuf, sizeof (zbuf), fp) != NULL)
4963 4961 if (ztest_opts.zo_verbose >= 3)
4964 4962 (void) printf("%s", zbuf);
4965 4963
4966 4964 status = pclose(fp);
4967 4965
4968 4966 if (status == 0)
4969 4967 return;
4970 4968
4971 4969 ztest_dump_core = 0;
4972 4970 if (WIFEXITED(status))
4973 4971 fatal(0, "'%s' exit code %d", zdb, WEXITSTATUS(status));
4974 4972 else
4975 4973 fatal(0, "'%s' died with signal %d", zdb, WTERMSIG(status));
4976 4974 }
4977 4975
4978 4976 static void
4979 4977 ztest_walk_pool_directory(char *header)
4980 4978 {
4981 4979 spa_t *spa = NULL;
4982 4980
4983 4981 if (ztest_opts.zo_verbose >= 6)
4984 4982 (void) printf("%s\n", header);
4985 4983
4986 4984 mutex_enter(&spa_namespace_lock);
4987 4985 while ((spa = spa_next(spa)) != NULL)
4988 4986 if (ztest_opts.zo_verbose >= 6)
4989 4987 (void) printf("\t%s\n", spa_name(spa));
4990 4988 mutex_exit(&spa_namespace_lock);
4991 4989 }
4992 4990
4993 4991 static void
4994 4992 ztest_spa_import_export(char *oldname, char *newname)
4995 4993 {
4996 4994 nvlist_t *config, *newconfig;
4997 4995 uint64_t pool_guid;
4998 4996 spa_t *spa;
4999 4997
5000 4998 if (ztest_opts.zo_verbose >= 4) {
5001 4999 (void) printf("import/export: old = %s, new = %s\n",
5002 5000 oldname, newname);
↓ open down ↓ |
79 lines elided |
↑ open up ↑ |
5003 5001 }
5004 5002
5005 5003 /*
5006 5004 * Clean up from previous runs.
5007 5005 */
5008 5006 (void) spa_destroy(newname);
5009 5007
5010 5008 /*
5011 5009 * Get the pool's configuration and guid.
5012 5010 */
5013 - VERIFY3U(0, ==, spa_open(oldname, &spa, FTAG));
5011 + VERIFY0(spa_open(oldname, &spa, FTAG));
5014 5012
5015 5013 /*
5016 5014 * Kick off a scrub to tickle scrub/export races.
5017 5015 */
5018 5016 if (ztest_random(2) == 0)
5019 5017 (void) spa_scan(spa, POOL_SCAN_SCRUB);
5020 5018
5021 5019 pool_guid = spa_guid(spa);
5022 5020 spa_close(spa, FTAG);
5023 5021
5024 5022 ztest_walk_pool_directory("pools before export");
5025 5023
5026 5024 /*
5027 5025 * Export it.
5028 5026 */
5029 - VERIFY3U(0, ==, spa_export(oldname, &config, B_FALSE, B_FALSE));
5027 + VERIFY0(spa_export(oldname, &config, B_FALSE, B_FALSE));
5030 5028
5031 5029 ztest_walk_pool_directory("pools after export");
5032 5030
5033 5031 /*
5034 5032 * Try to import it.
5035 5033 */
5036 5034 newconfig = spa_tryimport(config);
5037 5035 ASSERT(newconfig != NULL);
5038 5036 nvlist_free(newconfig);
5039 5037
5040 5038 /*
5041 5039 * Import it under the new name.
5042 5040 */
5043 - VERIFY3U(0, ==, spa_import(newname, config, NULL, 0));
5041 + VERIFY0(spa_import(newname, config, NULL, 0));
5044 5042
5045 5043 ztest_walk_pool_directory("pools after import");
5046 5044
5047 5045 /*
5048 5046 * Try to import it again -- should fail with EEXIST.
5049 5047 */
5050 5048 VERIFY3U(EEXIST, ==, spa_import(newname, config, NULL, 0));
5051 5049
5052 5050 /*
5053 5051 * Try to import it under a different name -- should fail with EEXIST.
5054 5052 */
↓ open down ↓ |
1 lines elided |
↑ open up ↑ |
5055 5053 VERIFY3U(EEXIST, ==, spa_import(oldname, config, NULL, 0));
5056 5054
5057 5055 /*
5058 5056 * Verify that the pool is no longer visible under the old name.
5059 5057 */
5060 5058 VERIFY3U(ENOENT, ==, spa_open(oldname, &spa, FTAG));
5061 5059
5062 5060 /*
5063 5061 * Verify that we can open and close the pool using the new name.
5064 5062 */
5065 - VERIFY3U(0, ==, spa_open(newname, &spa, FTAG));
5063 + VERIFY0(spa_open(newname, &spa, FTAG));
5066 5064 ASSERT(pool_guid == spa_guid(spa));
5067 5065 spa_close(spa, FTAG);
5068 5066
5069 5067 nvlist_free(config);
5070 5068 }
5071 5069
5072 5070 static void
5073 5071 ztest_resume(spa_t *spa)
5074 5072 {
5075 5073 if (spa_suspended(spa) && ztest_opts.zo_verbose >= 6)
5076 5074 (void) printf("resuming from suspended state\n");
5077 5075 spa_vdev_state_enter(spa, SCL_NONE);
5078 5076 vdev_clear(spa, NULL);
5079 5077 (void) spa_vdev_state_exit(spa, NULL, 0);
5080 5078 (void) zio_resume(spa);
5081 5079 }
5082 5080
5083 5081 static void *
5084 5082 ztest_resume_thread(void *arg)
5085 5083 {
5086 5084 spa_t *spa = arg;
5087 5085
5088 5086 while (!ztest_exiting) {
5089 5087 if (spa_suspended(spa))
5090 5088 ztest_resume(spa);
5091 5089 (void) poll(NULL, 0, 100);
5092 5090 }
5093 5091 return (NULL);
5094 5092 }
5095 5093
5096 5094 static void *
5097 5095 ztest_deadman_thread(void *arg)
5098 5096 {
5099 5097 ztest_shared_t *zs = arg;
5100 5098 int grace = 300;
5101 5099 hrtime_t delta;
5102 5100
5103 5101 delta = (zs->zs_thread_stop - zs->zs_thread_start) / NANOSEC + grace;
5104 5102
5105 5103 (void) poll(NULL, 0, (int)(1000 * delta));
5106 5104
5107 5105 fatal(0, "failed to complete within %d seconds of deadline", grace);
5108 5106
5109 5107 return (NULL);
5110 5108 }
5111 5109
5112 5110 static void
5113 5111 ztest_execute(int test, ztest_info_t *zi, uint64_t id)
5114 5112 {
5115 5113 ztest_ds_t *zd = &ztest_ds[id % ztest_opts.zo_datasets];
5116 5114 ztest_shared_callstate_t *zc = ZTEST_GET_SHARED_CALLSTATE(test);
5117 5115 hrtime_t functime = gethrtime();
5118 5116
5119 5117 for (int i = 0; i < zi->zi_iters; i++)
5120 5118 zi->zi_func(zd, id);
5121 5119
5122 5120 functime = gethrtime() - functime;
5123 5121
5124 5122 atomic_add_64(&zc->zc_count, 1);
5125 5123 atomic_add_64(&zc->zc_time, functime);
5126 5124
5127 5125 if (ztest_opts.zo_verbose >= 4) {
5128 5126 Dl_info dli;
5129 5127 (void) dladdr((void *)zi->zi_func, &dli);
5130 5128 (void) printf("%6.2f sec in %s\n",
5131 5129 (double)functime / NANOSEC, dli.dli_sname);
5132 5130 }
5133 5131 }
5134 5132
5135 5133 static void *
5136 5134 ztest_thread(void *arg)
5137 5135 {
5138 5136 int rand;
5139 5137 uint64_t id = (uintptr_t)arg;
5140 5138 ztest_shared_t *zs = ztest_shared;
5141 5139 uint64_t call_next;
5142 5140 hrtime_t now;
5143 5141 ztest_info_t *zi;
5144 5142 ztest_shared_callstate_t *zc;
5145 5143
5146 5144 while ((now = gethrtime()) < zs->zs_thread_stop) {
5147 5145 /*
5148 5146 * See if it's time to force a crash.
5149 5147 */
5150 5148 if (now > zs->zs_thread_kill)
5151 5149 ztest_kill(zs);
5152 5150
5153 5151 /*
5154 5152 * If we're getting ENOSPC with some regularity, stop.
5155 5153 */
5156 5154 if (zs->zs_enospc_count > 10)
5157 5155 break;
5158 5156
5159 5157 /*
5160 5158 * Pick a random function to execute.
5161 5159 */
5162 5160 rand = ztest_random(ZTEST_FUNCS);
5163 5161 zi = &ztest_info[rand];
5164 5162 zc = ZTEST_GET_SHARED_CALLSTATE(rand);
5165 5163 call_next = zc->zc_next;
5166 5164
5167 5165 if (now >= call_next &&
5168 5166 atomic_cas_64(&zc->zc_next, call_next, call_next +
5169 5167 ztest_random(2 * zi->zi_interval[0] + 1)) == call_next) {
5170 5168 ztest_execute(rand, zi, id);
5171 5169 }
5172 5170 }
5173 5171
5174 5172 return (NULL);
5175 5173 }
5176 5174
5177 5175 static void
5178 5176 ztest_dataset_name(char *dsname, char *pool, int d)
5179 5177 {
5180 5178 (void) snprintf(dsname, MAXNAMELEN, "%s/ds_%d", pool, d);
5181 5179 }
5182 5180
5183 5181 static void
5184 5182 ztest_dataset_destroy(int d)
5185 5183 {
5186 5184 char name[MAXNAMELEN];
5187 5185
5188 5186 ztest_dataset_name(name, ztest_opts.zo_pool, d);
5189 5187
5190 5188 if (ztest_opts.zo_verbose >= 3)
5191 5189 (void) printf("Destroying %s to free up space\n", name);
5192 5190
5193 5191 /*
5194 5192 * Cleanup any non-standard clones and snapshots. In general,
5195 5193 * ztest thread t operates on dataset (t % zopt_datasets),
5196 5194 * so there may be more than one thing to clean up.
5197 5195 */
5198 5196 for (int t = d; t < ztest_opts.zo_threads;
5199 5197 t += ztest_opts.zo_datasets) {
5200 5198 ztest_dsl_dataset_cleanup(name, t);
5201 5199 }
5202 5200
5203 5201 (void) dmu_objset_find(name, ztest_objset_destroy_cb, NULL,
5204 5202 DS_FIND_SNAPSHOTS | DS_FIND_CHILDREN);
5205 5203 }
5206 5204
5207 5205 static void
5208 5206 ztest_dataset_dirobj_verify(ztest_ds_t *zd)
5209 5207 {
5210 5208 uint64_t usedobjs, dirobjs, scratch;
5211 5209
5212 5210 /*
↓ open down ↓ |
137 lines elided |
↑ open up ↑ |
5213 5211 * ZTEST_DIROBJ is the object directory for the entire dataset.
5214 5212 * Therefore, the number of objects in use should equal the
5215 5213 * number of ZTEST_DIROBJ entries, +1 for ZTEST_DIROBJ itself.
5216 5214 * If not, we have an object leak.
5217 5215 *
5218 5216 * Note that we can only check this in ztest_dataset_open(),
5219 5217 * when the open-context and syncing-context values agree.
5220 5218 * That's because zap_count() returns the open-context value,
5221 5219 * while dmu_objset_space() returns the rootbp fill count.
5222 5220 */
5223 - VERIFY3U(0, ==, zap_count(zd->zd_os, ZTEST_DIROBJ, &dirobjs));
5221 + VERIFY0(zap_count(zd->zd_os, ZTEST_DIROBJ, &dirobjs));
5224 5222 dmu_objset_space(zd->zd_os, &scratch, &scratch, &usedobjs, &scratch);
5225 5223 ASSERT3U(dirobjs + 1, ==, usedobjs);
5226 5224 }
5227 5225
5228 5226 static int
5229 5227 ztest_dataset_open(int d)
5230 5228 {
5231 5229 ztest_ds_t *zd = &ztest_ds[d];
5232 5230 uint64_t committed_seq = ZTEST_GET_SHARED_DS(d)->zd_seq;
5233 5231 objset_t *os;
5234 5232 zilog_t *zilog;
5235 5233 char name[MAXNAMELEN];
5236 5234 int error;
5237 5235
5238 5236 ztest_dataset_name(name, ztest_opts.zo_pool, d);
5239 5237
↓ open down ↓ |
6 lines elided |
↑ open up ↑ |
5240 5238 (void) rw_rdlock(&ztest_name_lock);
5241 5239
5242 5240 error = ztest_dataset_create(name);
5243 5241 if (error == ENOSPC) {
5244 5242 (void) rw_unlock(&ztest_name_lock);
5245 5243 ztest_record_enospc(FTAG);
5246 5244 return (error);
5247 5245 }
5248 5246 ASSERT(error == 0 || error == EEXIST);
5249 5247
5250 - VERIFY3U(dmu_objset_hold(name, zd, &os), ==, 0);
5248 + VERIFY0(dmu_objset_hold(name, zd, &os));
5251 5249 (void) rw_unlock(&ztest_name_lock);
5252 5250
5253 5251 ztest_zd_init(zd, ZTEST_GET_SHARED_DS(d), os);
5254 5252
5255 5253 zilog = zd->zd_zilog;
5256 5254
5257 5255 if (zilog->zl_header->zh_claim_lr_seq != 0 &&
5258 5256 zilog->zl_header->zh_claim_lr_seq < committed_seq)
5259 5257 fatal(0, "missing log records: claimed %llu < committed %llu",
5260 5258 zilog->zl_header->zh_claim_lr_seq, committed_seq);
5261 5259
5262 5260 ztest_dataset_dirobj_verify(zd);
5263 5261
5264 5262 zil_replay(os, zd, ztest_replay_vector);
5265 5263
5266 5264 ztest_dataset_dirobj_verify(zd);
5267 5265
5268 5266 if (ztest_opts.zo_verbose >= 6)
5269 5267 (void) printf("%s replay %llu blocks, %llu records, seq %llu\n",
5270 5268 zd->zd_name,
5271 5269 (u_longlong_t)zilog->zl_parse_blk_count,
5272 5270 (u_longlong_t)zilog->zl_parse_lr_count,
5273 5271 (u_longlong_t)zilog->zl_replaying_seq);
5274 5272
5275 5273 zilog = zil_open(os, ztest_get_data);
5276 5274
5277 5275 if (zilog->zl_replaying_seq != 0 &&
5278 5276 zilog->zl_replaying_seq < committed_seq)
5279 5277 fatal(0, "missing log records: replayed %llu < committed %llu",
5280 5278 zilog->zl_replaying_seq, committed_seq);
5281 5279
5282 5280 return (0);
5283 5281 }
5284 5282
5285 5283 static void
5286 5284 ztest_dataset_close(int d)
5287 5285 {
5288 5286 ztest_ds_t *zd = &ztest_ds[d];
5289 5287
5290 5288 zil_close(zd->zd_zilog);
5291 5289 dmu_objset_rele(zd->zd_os, zd);
5292 5290
5293 5291 ztest_zd_fini(zd);
5294 5292 }
5295 5293
5296 5294 /*
5297 5295 * Kick off threads to run tests on all datasets in parallel.
5298 5296 */
5299 5297 static void
5300 5298 ztest_run(ztest_shared_t *zs)
5301 5299 {
5302 5300 thread_t *tid;
5303 5301 spa_t *spa;
5304 5302 objset_t *os;
5305 5303 thread_t resume_tid;
5306 5304 int error;
5307 5305
5308 5306 ztest_exiting = B_FALSE;
5309 5307
5310 5308 /*
5311 5309 * Initialize parent/child shared state.
5312 5310 */
5313 5311 VERIFY(_mutex_init(&ztest_vdev_lock, USYNC_THREAD, NULL) == 0);
5314 5312 VERIFY(rwlock_init(&ztest_name_lock, USYNC_THREAD, NULL) == 0);
5315 5313
5316 5314 zs->zs_thread_start = gethrtime();
5317 5315 zs->zs_thread_stop =
5318 5316 zs->zs_thread_start + ztest_opts.zo_passtime * NANOSEC;
5319 5317 zs->zs_thread_stop = MIN(zs->zs_thread_stop, zs->zs_proc_stop);
5320 5318 zs->zs_thread_kill = zs->zs_thread_stop;
5321 5319 if (ztest_random(100) < ztest_opts.zo_killrate) {
5322 5320 zs->zs_thread_kill -=
5323 5321 ztest_random(ztest_opts.zo_passtime * NANOSEC);
5324 5322 }
5325 5323
5326 5324 (void) _mutex_init(&zcl.zcl_callbacks_lock, USYNC_THREAD, NULL);
5327 5325
5328 5326 list_create(&zcl.zcl_callbacks, sizeof (ztest_cb_data_t),
↓ open down ↓ |
68 lines elided |
↑ open up ↑ |
5329 5327 offsetof(ztest_cb_data_t, zcd_node));
5330 5328
5331 5329 /*
5332 5330 * Open our pool.
5333 5331 */
5334 5332 kernel_init(FREAD | FWRITE);
5335 5333 VERIFY(spa_open(ztest_opts.zo_pool, &spa, FTAG) == 0);
5336 5334 spa->spa_debug = B_TRUE;
5337 5335 ztest_spa = spa;
5338 5336
5339 - VERIFY3U(0, ==, dmu_objset_hold(ztest_opts.zo_pool, FTAG, &os));
5337 + VERIFY0(dmu_objset_hold(ztest_opts.zo_pool, FTAG, &os));
5340 5338 zs->zs_guid = dmu_objset_fsid_guid(os);
5341 5339 dmu_objset_rele(os, FTAG);
5342 5340
5343 5341 spa->spa_dedup_ditto = 2 * ZIO_DEDUPDITTO_MIN;
5344 5342
5345 5343 /*
5346 5344 * We don't expect the pool to suspend unless maxfaults == 0,
5347 5345 * in which case ztest_fault_inject() temporarily takes away
5348 5346 * the only valid replica.
5349 5347 */
5350 5348 if (MAXFAULTS() == 0)
5351 5349 spa->spa_failmode = ZIO_FAILURE_MODE_WAIT;
5352 5350 else
5353 5351 spa->spa_failmode = ZIO_FAILURE_MODE_PANIC;
5354 5352
5355 5353 /*
5356 5354 * Create a thread to periodically resume suspended I/O.
5357 5355 */
5358 5356 VERIFY(thr_create(0, 0, ztest_resume_thread, spa, THR_BOUND,
5359 5357 &resume_tid) == 0);
5360 5358
5361 5359 /*
5362 5360 * Create a deadman thread to abort() if we hang.
5363 5361 */
5364 5362 VERIFY(thr_create(0, 0, ztest_deadman_thread, zs, THR_BOUND,
5365 5363 NULL) == 0);
5366 5364
5367 5365 /*
5368 5366 * Verify that we can safely inquire about about any object,
5369 5367 * whether it's allocated or not. To make it interesting,
5370 5368 * we probe a 5-wide window around each power of two.
5371 5369 * This hits all edge cases, including zero and the max.
5372 5370 */
5373 5371 for (int t = 0; t < 64; t++) {
5374 5372 for (int d = -5; d <= 5; d++) {
5375 5373 error = dmu_object_info(spa->spa_meta_objset,
5376 5374 (1ULL << t) + d, NULL);
5377 5375 ASSERT(error == 0 || error == ENOENT ||
5378 5376 error == EINVAL);
5379 5377 }
5380 5378 }
5381 5379
5382 5380 /*
5383 5381 * If we got any ENOSPC errors on the previous run, destroy something.
5384 5382 */
5385 5383 if (zs->zs_enospc_count != 0) {
5386 5384 int d = ztest_random(ztest_opts.zo_datasets);
5387 5385 ztest_dataset_destroy(d);
5388 5386 }
5389 5387 zs->zs_enospc_count = 0;
5390 5388
5391 5389 tid = umem_zalloc(ztest_opts.zo_threads * sizeof (thread_t),
5392 5390 UMEM_NOFAIL);
5393 5391
5394 5392 if (ztest_opts.zo_verbose >= 4)
5395 5393 (void) printf("starting main threads...\n");
5396 5394
5397 5395 /*
5398 5396 * Kick off all the tests that run in parallel.
5399 5397 */
5400 5398 for (int t = 0; t < ztest_opts.zo_threads; t++) {
5401 5399 if (t < ztest_opts.zo_datasets &&
5402 5400 ztest_dataset_open(t) != 0)
5403 5401 return;
5404 5402 VERIFY(thr_create(0, 0, ztest_thread, (void *)(uintptr_t)t,
5405 5403 THR_BOUND, &tid[t]) == 0);
5406 5404 }
5407 5405
5408 5406 /*
5409 5407 * Wait for all of the tests to complete. We go in reverse order
5410 5408 * so we don't close datasets while threads are still using them.
5411 5409 */
5412 5410 for (int t = ztest_opts.zo_threads - 1; t >= 0; t--) {
5413 5411 VERIFY(thr_join(tid[t], NULL, NULL) == 0);
5414 5412 if (t < ztest_opts.zo_datasets)
5415 5413 ztest_dataset_close(t);
5416 5414 }
5417 5415
5418 5416 txg_wait_synced(spa_get_dsl(spa), 0);
5419 5417
5420 5418 zs->zs_alloc = metaslab_class_get_alloc(spa_normal_class(spa));
5421 5419 zs->zs_space = metaslab_class_get_space(spa_normal_class(spa));
5422 5420
5423 5421 umem_free(tid, ztest_opts.zo_threads * sizeof (thread_t));
5424 5422
5425 5423 /* Kill the resume thread */
5426 5424 ztest_exiting = B_TRUE;
5427 5425 VERIFY(thr_join(resume_tid, NULL, NULL) == 0);
5428 5426 ztest_resume(spa);
5429 5427
5430 5428 /*
5431 5429 * Right before closing the pool, kick off a bunch of async I/O;
5432 5430 * spa_close() should wait for it to complete.
5433 5431 */
5434 5432 for (uint64_t object = 1; object < 50; object++)
5435 5433 dmu_prefetch(spa->spa_meta_objset, object, 0, 1ULL << 20);
5436 5434
5437 5435 spa_close(spa, FTAG);
5438 5436
5439 5437 /*
5440 5438 * Verify that we can loop over all pools.
5441 5439 */
5442 5440 mutex_enter(&spa_namespace_lock);
5443 5441 for (spa = spa_next(NULL); spa != NULL; spa = spa_next(spa))
5444 5442 if (ztest_opts.zo_verbose > 3)
5445 5443 (void) printf("spa_next: found %s\n", spa_name(spa));
5446 5444 mutex_exit(&spa_namespace_lock);
5447 5445
5448 5446 /*
5449 5447 * Verify that we can export the pool and reimport it under a
5450 5448 * different name.
5451 5449 */
5452 5450 if (ztest_random(2) == 0) {
5453 5451 char name[MAXNAMELEN];
5454 5452 (void) snprintf(name, MAXNAMELEN, "%s_import",
5455 5453 ztest_opts.zo_pool);
5456 5454 ztest_spa_import_export(ztest_opts.zo_pool, name);
5457 5455 ztest_spa_import_export(name, ztest_opts.zo_pool);
5458 5456 }
5459 5457
5460 5458 kernel_fini();
5461 5459
5462 5460 list_destroy(&zcl.zcl_callbacks);
5463 5461
5464 5462 (void) _mutex_destroy(&zcl.zcl_callbacks_lock);
5465 5463
5466 5464 (void) rwlock_destroy(&ztest_name_lock);
5467 5465 (void) _mutex_destroy(&ztest_vdev_lock);
5468 5466 }
5469 5467
5470 5468 static void
↓ open down ↓ |
121 lines elided |
↑ open up ↑ |
5471 5469 ztest_freeze(void)
5472 5470 {
5473 5471 ztest_ds_t *zd = &ztest_ds[0];
5474 5472 spa_t *spa;
5475 5473 int numloops = 0;
5476 5474
5477 5475 if (ztest_opts.zo_verbose >= 3)
5478 5476 (void) printf("testing spa_freeze()...\n");
5479 5477
5480 5478 kernel_init(FREAD | FWRITE);
5481 - VERIFY3U(0, ==, spa_open(ztest_opts.zo_pool, &spa, FTAG));
5482 - VERIFY3U(0, ==, ztest_dataset_open(0));
5479 + VERIFY0(spa_open(ztest_opts.zo_pool, &spa, FTAG));
5480 + VERIFY0(ztest_dataset_open(0));
5483 5481
5484 5482 /*
5485 5483 * Force the first log block to be transactionally allocated.
5486 5484 * We have to do this before we freeze the pool -- otherwise
5487 5485 * the log chain won't be anchored.
5488 5486 */
5489 5487 while (BP_IS_HOLE(&zd->zd_zilog->zl_header->zh_log)) {
5490 5488 ztest_dmu_object_alloc_free(zd, 0);
5491 5489 zil_commit(zd->zd_zilog, 0);
5492 5490 }
5493 5491
5494 5492 txg_wait_synced(spa_get_dsl(spa), 0);
5495 5493
5496 5494 /*
5497 5495 * Freeze the pool. This stops spa_sync() from doing anything,
5498 5496 * so that the only way to record changes from now on is the ZIL.
5499 5497 */
5500 5498 spa_freeze(spa);
5501 5499
5502 5500 /*
5503 5501 * Run tests that generate log records but don't alter the pool config
5504 5502 * or depend on DSL sync tasks (snapshots, objset create/destroy, etc).
5505 5503 * We do a txg_wait_synced() after each iteration to force the txg
5506 5504 * to increase well beyond the last synced value in the uberblock.
5507 5505 * The ZIL should be OK with that.
5508 5506 */
5509 5507 while (ztest_random(10) != 0 &&
5510 5508 numloops++ < ztest_opts.zo_maxloops) {
5511 5509 ztest_dmu_write_parallel(zd, 0);
5512 5510 ztest_dmu_object_alloc_free(zd, 0);
5513 5511 txg_wait_synced(spa_get_dsl(spa), 0);
5514 5512 }
5515 5513
5516 5514 /*
5517 5515 * Commit all of the changes we just generated.
5518 5516 */
5519 5517 zil_commit(zd->zd_zilog, 0);
5520 5518 txg_wait_synced(spa_get_dsl(spa), 0);
5521 5519
5522 5520 /*
↓ open down ↓ |
30 lines elided |
↑ open up ↑ |
5523 5521 * Close our dataset and close the pool.
5524 5522 */
5525 5523 ztest_dataset_close(0);
5526 5524 spa_close(spa, FTAG);
5527 5525 kernel_fini();
5528 5526
5529 5527 /*
5530 5528 * Open and close the pool and dataset to induce log replay.
5531 5529 */
5532 5530 kernel_init(FREAD | FWRITE);
5533 - VERIFY3U(0, ==, spa_open(ztest_opts.zo_pool, &spa, FTAG));
5534 - VERIFY3U(0, ==, ztest_dataset_open(0));
5531 + VERIFY0(spa_open(ztest_opts.zo_pool, &spa, FTAG));
5532 + VERIFY0(ztest_dataset_open(0));
5535 5533 ztest_dataset_close(0);
5536 5534 spa_close(spa, FTAG);
5537 5535 kernel_fini();
5538 5536 }
5539 5537
5540 5538 void
5541 5539 print_time(hrtime_t t, char *timebuf)
5542 5540 {
5543 5541 hrtime_t s = t / NANOSEC;
5544 5542 hrtime_t m = s / 60;
5545 5543 hrtime_t h = m / 60;
5546 5544 hrtime_t d = h / 24;
5547 5545
5548 5546 s -= m * 60;
5549 5547 m -= h * 60;
5550 5548 h -= d * 24;
5551 5549
5552 5550 timebuf[0] = '\0';
5553 5551
5554 5552 if (d)
5555 5553 (void) sprintf(timebuf,
5556 5554 "%llud%02lluh%02llum%02llus", d, h, m, s);
5557 5555 else if (h)
5558 5556 (void) sprintf(timebuf, "%lluh%02llum%02llus", h, m, s);
5559 5557 else if (m)
5560 5558 (void) sprintf(timebuf, "%llum%02llus", m, s);
5561 5559 else
5562 5560 (void) sprintf(timebuf, "%llus", s);
5563 5561 }
5564 5562
5565 5563 static nvlist_t *
5566 5564 make_random_props()
5567 5565 {
5568 5566 nvlist_t *props;
5569 5567
5570 5568 VERIFY(nvlist_alloc(&props, NV_UNIQUE_NAME, 0) == 0);
5571 5569 if (ztest_random(2) == 0)
5572 5570 return (props);
5573 5571 VERIFY(nvlist_add_uint64(props, "autoreplace", 1) == 0);
5574 5572
5575 5573 return (props);
5576 5574 }
5577 5575
5578 5576 /*
5579 5577 * Create a storage pool with the given name and initial vdev size.
5580 5578 * Then test spa_freeze() functionality.
5581 5579 */
5582 5580 static void
5583 5581 ztest_init(ztest_shared_t *zs)
5584 5582 {
5585 5583 spa_t *spa;
5586 5584 nvlist_t *nvroot, *props;
5587 5585
5588 5586 VERIFY(_mutex_init(&ztest_vdev_lock, USYNC_THREAD, NULL) == 0);
5589 5587 VERIFY(rwlock_init(&ztest_name_lock, USYNC_THREAD, NULL) == 0);
5590 5588
5591 5589 kernel_init(FREAD | FWRITE);
5592 5590
5593 5591 /*
5594 5592 * Create the storage pool.
5595 5593 */
5596 5594 (void) spa_destroy(ztest_opts.zo_pool);
↓ open down ↓ |
52 lines elided |
↑ open up ↑ |
5597 5595 ztest_shared->zs_vdev_next_leaf = 0;
5598 5596 zs->zs_splits = 0;
5599 5597 zs->zs_mirrors = ztest_opts.zo_mirrors;
5600 5598 nvroot = make_vdev_root(NULL, NULL, ztest_opts.zo_vdev_size, 0,
5601 5599 0, ztest_opts.zo_raidz, zs->zs_mirrors, 1);
5602 5600 props = make_random_props();
5603 5601 for (int i = 0; i < SPA_FEATURES; i++) {
5604 5602 char buf[1024];
5605 5603 (void) snprintf(buf, sizeof (buf), "feature@%s",
5606 5604 spa_feature_table[i].fi_uname);
5607 - VERIFY3U(0, ==, nvlist_add_uint64(props, buf, 0));
5605 + VERIFY0(nvlist_add_uint64(props, buf, 0));
5608 5606 }
5609 - VERIFY3U(0, ==, spa_create(ztest_opts.zo_pool, nvroot, props, NULL));
5607 + VERIFY0(spa_create(ztest_opts.zo_pool, nvroot, props, NULL));
5610 5608 nvlist_free(nvroot);
5611 5609
5612 - VERIFY3U(0, ==, spa_open(ztest_opts.zo_pool, &spa, FTAG));
5610 + VERIFY0(spa_open(ztest_opts.zo_pool, &spa, FTAG));
5613 5611 zs->zs_metaslab_sz =
5614 5612 1ULL << spa->spa_root_vdev->vdev_child[0]->vdev_ms_shift;
5615 5613
5616 5614 spa_close(spa, FTAG);
5617 5615
5618 5616 kernel_fini();
5619 5617
5620 5618 ztest_run_zdb(ztest_opts.zo_pool);
5621 5619
5622 5620 ztest_freeze();
5623 5621
5624 5622 ztest_run_zdb(ztest_opts.zo_pool);
5625 5623
5626 5624 (void) rwlock_destroy(&ztest_name_lock);
5627 5625 (void) _mutex_destroy(&ztest_vdev_lock);
5628 5626 }
5629 5627
5630 5628 static void
5631 5629 setup_fds(void)
5632 5630 {
5633 5631 int fd;
5634 5632
5635 5633 char *tmp = tempnam(NULL, NULL);
5636 5634 fd = open(tmp, O_RDWR | O_CREAT, 0700);
5637 5635 ASSERT3U(fd, ==, ZTEST_FD_DATA);
5638 5636 (void) unlink(tmp);
5639 5637 free(tmp);
5640 5638
5641 5639 fd = open("/dev/urandom", O_RDONLY);
5642 5640 ASSERT3U(fd, ==, ZTEST_FD_RAND);
5643 5641 }
5644 5642
5645 5643 static int
5646 5644 shared_data_size(ztest_shared_hdr_t *hdr)
5647 5645 {
5648 5646 int size;
5649 5647
5650 5648 size = hdr->zh_hdr_size;
5651 5649 size += hdr->zh_opts_size;
5652 5650 size += hdr->zh_size;
5653 5651 size += hdr->zh_stats_size * hdr->zh_stats_count;
5654 5652 size += hdr->zh_ds_size * hdr->zh_ds_count;
5655 5653
5656 5654 return (size);
5657 5655 }
5658 5656
↓ open down ↓ |
36 lines elided |
↑ open up ↑ |
5659 5657 static void
5660 5658 setup_hdr(void)
5661 5659 {
5662 5660 int size;
5663 5661 ztest_shared_hdr_t *hdr;
5664 5662
5665 5663 hdr = (void *)mmap(0, P2ROUNDUP(sizeof (*hdr), getpagesize()),
5666 5664 PROT_READ | PROT_WRITE, MAP_SHARED, ZTEST_FD_DATA, 0);
5667 5665 ASSERT(hdr != MAP_FAILED);
5668 5666
5669 - VERIFY3U(0, ==, ftruncate(ZTEST_FD_DATA, sizeof (ztest_shared_hdr_t)));
5667 + VERIFY0(ftruncate(ZTEST_FD_DATA, sizeof (ztest_shared_hdr_t)));
5670 5668
5671 5669 hdr->zh_hdr_size = sizeof (ztest_shared_hdr_t);
5672 5670 hdr->zh_opts_size = sizeof (ztest_shared_opts_t);
5673 5671 hdr->zh_size = sizeof (ztest_shared_t);
5674 5672 hdr->zh_stats_size = sizeof (ztest_shared_callstate_t);
5675 5673 hdr->zh_stats_count = ZTEST_FUNCS;
5676 5674 hdr->zh_ds_size = sizeof (ztest_shared_ds_t);
5677 5675 hdr->zh_ds_count = ztest_opts.zo_datasets;
5678 5676
5679 5677 size = shared_data_size(hdr);
5680 - VERIFY3U(0, ==, ftruncate(ZTEST_FD_DATA, size));
5678 + VERIFY0(ftruncate(ZTEST_FD_DATA, size));
5681 5679
5682 5680 (void) munmap((caddr_t)hdr, P2ROUNDUP(sizeof (*hdr), getpagesize()));
5683 5681 }
5684 5682
5685 5683 static void
5686 5684 setup_data(void)
5687 5685 {
5688 5686 int size, offset;
5689 5687 ztest_shared_hdr_t *hdr;
5690 5688 uint8_t *buf;
5691 5689
5692 5690 hdr = (void *)mmap(0, P2ROUNDUP(sizeof (*hdr), getpagesize()),
5693 5691 PROT_READ, MAP_SHARED, ZTEST_FD_DATA, 0);
5694 5692 ASSERT(hdr != MAP_FAILED);
5695 5693
5696 5694 size = shared_data_size(hdr);
5697 5695
5698 5696 (void) munmap((caddr_t)hdr, P2ROUNDUP(sizeof (*hdr), getpagesize()));
5699 5697 hdr = ztest_shared_hdr = (void *)mmap(0, P2ROUNDUP(size, getpagesize()),
5700 5698 PROT_READ | PROT_WRITE, MAP_SHARED, ZTEST_FD_DATA, 0);
5701 5699 ASSERT(hdr != MAP_FAILED);
5702 5700 buf = (uint8_t *)hdr;
5703 5701
5704 5702 offset = hdr->zh_hdr_size;
5705 5703 ztest_shared_opts = (void *)&buf[offset];
5706 5704 offset += hdr->zh_opts_size;
5707 5705 ztest_shared = (void *)&buf[offset];
5708 5706 offset += hdr->zh_size;
5709 5707 ztest_shared_callstate = (void *)&buf[offset];
5710 5708 offset += hdr->zh_stats_size * hdr->zh_stats_count;
5711 5709 ztest_shared_ds = (void *)&buf[offset];
5712 5710 }
5713 5711
5714 5712 static boolean_t
5715 5713 exec_child(char *cmd, char *libpath, boolean_t ignorekill, int *statusp)
5716 5714 {
5717 5715 pid_t pid;
5718 5716 int status;
5719 5717 char cmdbuf[MAXPATHLEN];
5720 5718
5721 5719 pid = fork();
5722 5720
5723 5721 if (cmd == NULL) {
5724 5722 (void) strlcpy(cmdbuf, getexecname(), sizeof (cmdbuf));
5725 5723 cmd = cmdbuf;
5726 5724 }
5727 5725
5728 5726 if (pid == -1)
5729 5727 fatal(1, "fork failed");
5730 5728
5731 5729 if (pid == 0) { /* child */
5732 5730 char *emptyargv[2] = { cmd, NULL };
5733 5731
5734 5732 struct rlimit rl = { 1024, 1024 };
5735 5733 (void) setrlimit(RLIMIT_NOFILE, &rl);
5736 5734 (void) enable_extended_FILE_stdio(-1, -1);
5737 5735 if (libpath != NULL)
5738 5736 VERIFY(0 == setenv("LD_LIBRARY_PATH", libpath, 1));
5739 5737 (void) execv(cmd, emptyargv);
5740 5738 ztest_dump_core = B_FALSE;
5741 5739 fatal(B_TRUE, "exec failed: %s", cmd);
5742 5740 }
5743 5741
5744 5742 while (waitpid(pid, &status, 0) != pid)
5745 5743 continue;
5746 5744 if (statusp != NULL)
5747 5745 *statusp = status;
5748 5746
5749 5747 if (WIFEXITED(status)) {
5750 5748 if (WEXITSTATUS(status) != 0) {
5751 5749 (void) fprintf(stderr, "child exited with code %d\n",
5752 5750 WEXITSTATUS(status));
5753 5751 exit(2);
5754 5752 }
5755 5753 return (B_FALSE);
5756 5754 } else if (WIFSIGNALED(status)) {
5757 5755 if (!ignorekill || WTERMSIG(status) != SIGKILL) {
5758 5756 (void) fprintf(stderr, "child died with signal %d\n",
5759 5757 WTERMSIG(status));
5760 5758 exit(3);
5761 5759 }
5762 5760 return (B_TRUE);
5763 5761 } else {
5764 5762 (void) fprintf(stderr, "something strange happened to child\n");
5765 5763 exit(4);
5766 5764 /* NOTREACHED */
5767 5765 }
5768 5766 }
5769 5767
5770 5768 static void
5771 5769 ztest_run_init(void)
5772 5770 {
5773 5771 ztest_shared_t *zs = ztest_shared;
5774 5772
5775 5773 ASSERT(ztest_opts.zo_init != 0);
5776 5774
5777 5775 /*
5778 5776 * Blow away any existing copy of zpool.cache
5779 5777 */
5780 5778 (void) remove(spa_config_path);
5781 5779
5782 5780 /*
5783 5781 * Create and initialize our storage pool.
5784 5782 */
5785 5783 for (int i = 1; i <= ztest_opts.zo_init; i++) {
5786 5784 bzero(zs, sizeof (ztest_shared_t));
5787 5785 if (ztest_opts.zo_verbose >= 3 &&
5788 5786 ztest_opts.zo_init != 1) {
5789 5787 (void) printf("ztest_init(), pass %d\n", i);
5790 5788 }
5791 5789 ztest_init(zs);
5792 5790 }
5793 5791 }
5794 5792
5795 5793 int
5796 5794 main(int argc, char **argv)
5797 5795 {
5798 5796 int kills = 0;
5799 5797 int iters = 0;
5800 5798 int older = 0;
5801 5799 int newer = 0;
5802 5800 ztest_shared_t *zs;
5803 5801 ztest_info_t *zi;
5804 5802 ztest_shared_callstate_t *zc;
5805 5803 char timebuf[100];
5806 5804 char numbuf[6];
5807 5805 spa_t *spa;
5808 5806 char cmd[MAXNAMELEN];
5809 5807 boolean_t hasalt;
5810 5808
5811 5809 boolean_t ischild = (0 == lseek(ZTEST_FD_DATA, 0, SEEK_CUR));
5812 5810 ASSERT(ischild || errno == EBADF);
5813 5811
5814 5812 (void) setvbuf(stdout, NULL, _IOLBF, 0);
5815 5813
5816 5814 if (!ischild) {
5817 5815 process_options(argc, argv);
5818 5816
5819 5817 setup_fds();
5820 5818 setup_hdr();
5821 5819 setup_data();
5822 5820 bcopy(&ztest_opts, ztest_shared_opts,
5823 5821 sizeof (*ztest_shared_opts));
5824 5822 } else {
5825 5823 setup_data();
5826 5824 bcopy(ztest_shared_opts, &ztest_opts, sizeof (ztest_opts));
5827 5825 }
5828 5826 ASSERT3U(ztest_opts.zo_datasets, ==, ztest_shared_hdr->zh_ds_count);
5829 5827
5830 5828 /* Override location of zpool.cache */
5831 5829 (void) asprintf((char **)&spa_config_path, "%s/zpool.cache",
5832 5830 ztest_opts.zo_dir);
5833 5831
5834 5832 ztest_ds = umem_alloc(ztest_opts.zo_datasets * sizeof (ztest_ds_t),
5835 5833 UMEM_NOFAIL);
5836 5834 zs = ztest_shared;
5837 5835
5838 5836 if (ischild) {
5839 5837 metaslab_gang_bang = ztest_opts.zo_metaslab_gang_bang;
5840 5838 metaslab_df_alloc_threshold =
5841 5839 zs->zs_metaslab_df_alloc_threshold;
5842 5840
5843 5841 if (zs->zs_do_init)
5844 5842 ztest_run_init();
5845 5843 else
5846 5844 ztest_run(zs);
5847 5845 exit(0);
5848 5846 }
5849 5847
5850 5848 hasalt = (strlen(ztest_opts.zo_alt_ztest) != 0);
5851 5849
5852 5850 if (ztest_opts.zo_verbose >= 1) {
5853 5851 (void) printf("%llu vdevs, %d datasets, %d threads,"
5854 5852 " %llu seconds...\n",
5855 5853 (u_longlong_t)ztest_opts.zo_vdevs,
5856 5854 ztest_opts.zo_datasets,
5857 5855 ztest_opts.zo_threads,
5858 5856 (u_longlong_t)ztest_opts.zo_time);
5859 5857 }
5860 5858
5861 5859 (void) strlcpy(cmd, getexecname(), sizeof (cmd));
5862 5860
5863 5861 zs->zs_do_init = B_TRUE;
5864 5862 if (strlen(ztest_opts.zo_alt_ztest) != 0) {
5865 5863 if (ztest_opts.zo_verbose >= 1) {
5866 5864 (void) printf("Executing older ztest for "
5867 5865 "initialization: %s\n", ztest_opts.zo_alt_ztest);
5868 5866 }
5869 5867 VERIFY(!exec_child(ztest_opts.zo_alt_ztest,
5870 5868 ztest_opts.zo_alt_libpath, B_FALSE, NULL));
5871 5869 } else {
5872 5870 VERIFY(!exec_child(NULL, NULL, B_FALSE, NULL));
5873 5871 }
5874 5872 zs->zs_do_init = B_FALSE;
5875 5873
5876 5874 zs->zs_proc_start = gethrtime();
5877 5875 zs->zs_proc_stop = zs->zs_proc_start + ztest_opts.zo_time * NANOSEC;
5878 5876
5879 5877 for (int f = 0; f < ZTEST_FUNCS; f++) {
5880 5878 zi = &ztest_info[f];
5881 5879 zc = ZTEST_GET_SHARED_CALLSTATE(f);
5882 5880 if (zs->zs_proc_start + zi->zi_interval[0] > zs->zs_proc_stop)
5883 5881 zc->zc_next = UINT64_MAX;
5884 5882 else
5885 5883 zc->zc_next = zs->zs_proc_start +
5886 5884 ztest_random(2 * zi->zi_interval[0] + 1);
5887 5885 }
5888 5886
5889 5887 /*
5890 5888 * Run the tests in a loop. These tests include fault injection
5891 5889 * to verify that self-healing data works, and forced crashes
5892 5890 * to verify that we never lose on-disk consistency.
5893 5891 */
5894 5892 while (gethrtime() < zs->zs_proc_stop) {
5895 5893 int status;
5896 5894 boolean_t killed;
5897 5895
5898 5896 /*
5899 5897 * Initialize the workload counters for each function.
5900 5898 */
5901 5899 for (int f = 0; f < ZTEST_FUNCS; f++) {
5902 5900 zc = ZTEST_GET_SHARED_CALLSTATE(f);
5903 5901 zc->zc_count = 0;
5904 5902 zc->zc_time = 0;
5905 5903 }
5906 5904
5907 5905 /* Set the allocation switch size */
5908 5906 zs->zs_metaslab_df_alloc_threshold =
5909 5907 ztest_random(zs->zs_metaslab_sz / 4) + 1;
5910 5908
5911 5909 if (!hasalt || ztest_random(2) == 0) {
5912 5910 if (hasalt && ztest_opts.zo_verbose >= 1) {
5913 5911 (void) printf("Executing newer ztest: %s\n",
5914 5912 cmd);
5915 5913 }
5916 5914 newer++;
5917 5915 killed = exec_child(cmd, NULL, B_TRUE, &status);
5918 5916 } else {
5919 5917 if (hasalt && ztest_opts.zo_verbose >= 1) {
5920 5918 (void) printf("Executing older ztest: %s\n",
5921 5919 ztest_opts.zo_alt_ztest);
5922 5920 }
5923 5921 older++;
5924 5922 killed = exec_child(ztest_opts.zo_alt_ztest,
5925 5923 ztest_opts.zo_alt_libpath, B_TRUE, &status);
5926 5924 }
5927 5925
5928 5926 if (killed)
5929 5927 kills++;
5930 5928 iters++;
5931 5929
5932 5930 if (ztest_opts.zo_verbose >= 1) {
5933 5931 hrtime_t now = gethrtime();
5934 5932
5935 5933 now = MIN(now, zs->zs_proc_stop);
5936 5934 print_time(zs->zs_proc_stop - now, timebuf);
5937 5935 nicenum(zs->zs_space, numbuf);
5938 5936
5939 5937 (void) printf("Pass %3d, %8s, %3llu ENOSPC, "
5940 5938 "%4.1f%% of %5s used, %3.0f%% done, %8s to go\n",
5941 5939 iters,
5942 5940 WIFEXITED(status) ? "Complete" : "SIGKILL",
5943 5941 (u_longlong_t)zs->zs_enospc_count,
5944 5942 100.0 * zs->zs_alloc / zs->zs_space,
5945 5943 numbuf,
5946 5944 100.0 * (now - zs->zs_proc_start) /
5947 5945 (ztest_opts.zo_time * NANOSEC), timebuf);
5948 5946 }
5949 5947
5950 5948 if (ztest_opts.zo_verbose >= 2) {
5951 5949 (void) printf("\nWorkload summary:\n\n");
5952 5950 (void) printf("%7s %9s %s\n",
5953 5951 "Calls", "Time", "Function");
5954 5952 (void) printf("%7s %9s %s\n",
5955 5953 "-----", "----", "--------");
5956 5954 for (int f = 0; f < ZTEST_FUNCS; f++) {
5957 5955 Dl_info dli;
5958 5956
5959 5957 zi = &ztest_info[f];
5960 5958 zc = ZTEST_GET_SHARED_CALLSTATE(f);
5961 5959 print_time(zc->zc_time, timebuf);
5962 5960 (void) dladdr((void *)zi->zi_func, &dli);
5963 5961 (void) printf("%7llu %9s %s\n",
5964 5962 (u_longlong_t)zc->zc_count, timebuf,
5965 5963 dli.dli_sname);
5966 5964 }
5967 5965 (void) printf("\n");
5968 5966 }
5969 5967
5970 5968 /*
5971 5969 * It's possible that we killed a child during a rename test,
5972 5970 * in which case we'll have a 'ztest_tmp' pool lying around
5973 5971 * instead of 'ztest'. Do a blind rename in case this happened.
5974 5972 */
5975 5973 kernel_init(FREAD);
5976 5974 if (spa_open(ztest_opts.zo_pool, &spa, FTAG) == 0) {
5977 5975 spa_close(spa, FTAG);
5978 5976 } else {
5979 5977 char tmpname[MAXNAMELEN];
5980 5978 kernel_fini();
5981 5979 kernel_init(FREAD | FWRITE);
5982 5980 (void) snprintf(tmpname, sizeof (tmpname), "%s_tmp",
5983 5981 ztest_opts.zo_pool);
5984 5982 (void) spa_rename(tmpname, ztest_opts.zo_pool);
5985 5983 }
5986 5984 kernel_fini();
5987 5985
5988 5986 ztest_run_zdb(ztest_opts.zo_pool);
5989 5987 }
5990 5988
5991 5989 if (ztest_opts.zo_verbose >= 1) {
5992 5990 if (hasalt) {
5993 5991 (void) printf("%d runs of older ztest: %s\n", older,
5994 5992 ztest_opts.zo_alt_ztest);
5995 5993 (void) printf("%d runs of newer ztest: %s\n", newer,
5996 5994 cmd);
5997 5995 }
5998 5996 (void) printf("%d killed, %d completed, %.0f%% kill rate\n",
5999 5997 kills, iters - kills, (100.0 * kills) / MAX(1, iters));
6000 5998 }
6001 5999
6002 6000 return (0);
6003 6001 }
↓ open down ↓ |
313 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX