ztest.c (177698) | ztest.c (185029) |
---|---|
1/* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE --- 5 unchanged lines hidden (view full) --- 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 * If applicable, add the following below this CDDL HEADER, with the 16 * fields enclosed by brackets "[]" replaced with your own identifying 17 * information: Portions Copyright [yyyy] [name of copyright owner] 18 * 19 * CDDL HEADER END 20 */ 21/* | 1/* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE --- 5 unchanged lines hidden (view full) --- 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 * If applicable, add the following below this CDDL HEADER, with the 16 * fields enclosed by brackets "[]" replaced with your own identifying 17 * information: Portions Copyright [yyyy] [name of copyright owner] 18 * 19 * CDDL HEADER END 20 */ 21/* |
22 * Copyright 2007 Sun Microsystems, Inc. All rights reserved. | 22 * Copyright 2008 Sun Microsystems, Inc. All rights reserved. |
23 * Use is subject to license terms. 24 */ 25 | 23 * Use is subject to license terms. 24 */ 25 |
26#pragma ident "%Z%%M% %I% %E% SMI" 27 | |
28/* 29 * The objective of this program is to provide a DMU/ZAP/SPA stress test 30 * that runs entirely in userland, is easy to use, and easy to extend. 31 * 32 * The overall design of the ztest program is as follows: 33 * 34 * (1) For each major functional area (e.g. adding vdevs to a pool, 35 * creating and destroying datasets, reading and writing objects, etc) --- 51 unchanged lines hidden (view full) --- 87#include <sys/wait.h> 88#include <sys/mman.h> 89#include <sys/resource.h> 90#include <sys/zio.h> 91#include <sys/zio_checksum.h> 92#include <sys/zio_compress.h> 93#include <sys/zil.h> 94#include <sys/vdev_impl.h> | 26/* 27 * The objective of this program is to provide a DMU/ZAP/SPA stress test 28 * that runs entirely in userland, is easy to use, and easy to extend. 29 * 30 * The overall design of the ztest program is as follows: 31 * 32 * (1) For each major functional area (e.g. adding vdevs to a pool, 33 * creating and destroying datasets, reading and writing objects, etc) --- 51 unchanged lines hidden (view full) --- 85#include <sys/wait.h> 86#include <sys/mman.h> 87#include <sys/resource.h> 88#include <sys/zio.h> 89#include <sys/zio_checksum.h> 90#include <sys/zio_compress.h> 91#include <sys/zil.h> 92#include <sys/vdev_impl.h> |
93#include <sys/vdev_file.h> |
|
95#include <sys/spa_impl.h> 96#include <sys/dsl_prop.h> 97#include <sys/refcount.h> 98#include <stdio.h> 99#include <stdio_ext.h> 100#include <stdlib.h> 101#include <unistd.h> 102#include <signal.h> --- 20 unchanged lines hidden (view full) --- 123static uint64_t zopt_passtime = 60; /* 60 seconds */ 124static uint64_t zopt_killrate = 70; /* 70% kill rate */ 125static int zopt_verbose = 0; 126static int zopt_init = 1; 127static char *zopt_dir = "/tmp"; 128static uint64_t zopt_time = 300; /* 5 minutes */ 129static int zopt_maxfaults; 130 | 94#include <sys/spa_impl.h> 95#include <sys/dsl_prop.h> 96#include <sys/refcount.h> 97#include <stdio.h> 98#include <stdio_ext.h> 99#include <stdlib.h> 100#include <unistd.h> 101#include <signal.h> --- 20 unchanged lines hidden (view full) --- 122static uint64_t zopt_passtime = 60; /* 60 seconds */ 123static uint64_t zopt_killrate = 70; /* 70% kill rate */ 124static int zopt_verbose = 0; 125static int zopt_init = 1; 126static char *zopt_dir = "/tmp"; 127static uint64_t zopt_time = 300; /* 5 minutes */ 128static int zopt_maxfaults; 129 |
130typedef struct ztest_block_tag { 131 uint64_t bt_objset; 132 uint64_t bt_object; 133 uint64_t bt_offset; 134 uint64_t bt_txg; 135 uint64_t bt_thread; 136 uint64_t bt_seq; 137} ztest_block_tag_t; 138 |
|
131typedef struct ztest_args { | 139typedef struct ztest_args { |
132 char *za_pool; | 140 char za_pool[MAXNAMELEN]; 141 spa_t *za_spa; |
133 objset_t *za_os; 134 zilog_t *za_zilog; 135 thread_t za_thread; 136 uint64_t za_instance; 137 uint64_t za_random; 138 uint64_t za_diroff; 139 uint64_t za_diroff_shared; 140 uint64_t za_zil_seq; 141 hrtime_t za_start; 142 hrtime_t za_stop; 143 hrtime_t za_kill; 144 traverse_handle_t *za_th; | 142 objset_t *za_os; 143 zilog_t *za_zilog; 144 thread_t za_thread; 145 uint64_t za_instance; 146 uint64_t za_random; 147 uint64_t za_diroff; 148 uint64_t za_diroff_shared; 149 uint64_t za_zil_seq; 150 hrtime_t za_start; 151 hrtime_t za_stop; 152 hrtime_t za_kill; 153 traverse_handle_t *za_th; |
154 /* 155 * Thread-local variables can go here to aid debugging. 156 */ 157 ztest_block_tag_t za_rbt; 158 ztest_block_tag_t za_wbt; 159 dmu_object_info_t za_doi; 160 dmu_buf_t *za_dbuf; |
|
145} ztest_args_t; 146 147typedef void ztest_func_t(ztest_args_t *); 148 149/* 150 * Note: these aren't static because we want dladdr() to work. 151 */ 152ztest_func_t ztest_dmu_read_write; 153ztest_func_t ztest_dmu_write_parallel; 154ztest_func_t ztest_dmu_object_alloc_free; 155ztest_func_t ztest_zap; 156ztest_func_t ztest_zap_parallel; 157ztest_func_t ztest_traverse; 158ztest_func_t ztest_dsl_prop_get_set; 159ztest_func_t ztest_dmu_objset_create_destroy; 160ztest_func_t ztest_dmu_snapshot_create_destroy; 161ztest_func_t ztest_spa_create_destroy; 162ztest_func_t ztest_fault_inject; | 161} ztest_args_t; 162 163typedef void ztest_func_t(ztest_args_t *); 164 165/* 166 * Note: these aren't static because we want dladdr() to work. 167 */ 168ztest_func_t ztest_dmu_read_write; 169ztest_func_t ztest_dmu_write_parallel; 170ztest_func_t ztest_dmu_object_alloc_free; 171ztest_func_t ztest_zap; 172ztest_func_t ztest_zap_parallel; 173ztest_func_t ztest_traverse; 174ztest_func_t ztest_dsl_prop_get_set; 175ztest_func_t ztest_dmu_objset_create_destroy; 176ztest_func_t ztest_dmu_snapshot_create_destroy; 177ztest_func_t ztest_spa_create_destroy; 178ztest_func_t ztest_fault_inject; |
179ztest_func_t ztest_spa_rename; |
|
163ztest_func_t ztest_vdev_attach_detach; 164ztest_func_t ztest_vdev_LUN_growth; 165ztest_func_t ztest_vdev_add_remove; | 180ztest_func_t ztest_vdev_attach_detach; 181ztest_func_t ztest_vdev_LUN_growth; 182ztest_func_t ztest_vdev_add_remove; |
183ztest_func_t ztest_vdev_aux_add_remove; |
|
166ztest_func_t ztest_scrub; | 184ztest_func_t ztest_scrub; |
167ztest_func_t ztest_spa_rename; | |
168 169typedef struct ztest_info { 170 ztest_func_t *zi_func; /* test function */ | 185 186typedef struct ztest_info { 187 ztest_func_t *zi_func; /* test function */ |
188 uint64_t zi_iters; /* iterations per execution */ |
|
171 uint64_t *zi_interval; /* execute every <interval> seconds */ 172 uint64_t zi_calls; /* per-pass count */ 173 uint64_t zi_call_time; /* per-pass time */ 174 uint64_t zi_call_total; /* cumulative total */ 175 uint64_t zi_call_target; /* target cumulative total */ 176} ztest_info_t; 177 178uint64_t zopt_always = 0; /* all the time */ 179uint64_t zopt_often = 1; /* every second */ 180uint64_t zopt_sometimes = 10; /* every 10 seconds */ 181uint64_t zopt_rarely = 60; /* every 60 seconds */ 182 183ztest_info_t ztest_info[] = { | 189 uint64_t *zi_interval; /* execute every <interval> seconds */ 190 uint64_t zi_calls; /* per-pass count */ 191 uint64_t zi_call_time; /* per-pass time */ 192 uint64_t zi_call_total; /* cumulative total */ 193 uint64_t zi_call_target; /* target cumulative total */ 194} ztest_info_t; 195 196uint64_t zopt_always = 0; /* all the time */ 197uint64_t zopt_often = 1; /* every second */ 198uint64_t zopt_sometimes = 10; /* every 10 seconds */ 199uint64_t zopt_rarely = 60; /* every 60 seconds */ 200 201ztest_info_t ztest_info[] = { |
184 { ztest_dmu_read_write, &zopt_always }, 185 { ztest_dmu_write_parallel, &zopt_always }, 186 { ztest_dmu_object_alloc_free, &zopt_always }, 187 { ztest_zap, &zopt_always }, 188 { ztest_zap_parallel, &zopt_always }, 189 { ztest_traverse, &zopt_often }, 190 { ztest_dsl_prop_get_set, &zopt_sometimes }, 191 { ztest_dmu_objset_create_destroy, &zopt_sometimes }, 192 { ztest_dmu_snapshot_create_destroy, &zopt_rarely }, 193 { ztest_spa_create_destroy, &zopt_sometimes }, 194 { ztest_fault_inject, &zopt_sometimes }, 195 { ztest_spa_rename, &zopt_rarely }, 196 { ztest_vdev_attach_detach, &zopt_rarely }, 197 { ztest_vdev_LUN_growth, &zopt_rarely }, 198 { ztest_vdev_add_remove, &zopt_vdevtime }, 199 { ztest_scrub, &zopt_vdevtime }, | 202 { ztest_dmu_read_write, 1, &zopt_always }, 203 { ztest_dmu_write_parallel, 30, &zopt_always }, 204 { ztest_dmu_object_alloc_free, 1, &zopt_always }, 205 { ztest_zap, 30, &zopt_always }, 206 { ztest_zap_parallel, 100, &zopt_always }, 207 { ztest_traverse, 1, &zopt_often }, 208 { ztest_dsl_prop_get_set, 1, &zopt_sometimes }, 209 { ztest_dmu_objset_create_destroy, 1, &zopt_sometimes }, 210 { ztest_dmu_snapshot_create_destroy, 1, &zopt_sometimes }, 211 { ztest_spa_create_destroy, 1, &zopt_sometimes }, 212 { ztest_fault_inject, 1, &zopt_sometimes }, 213 { ztest_spa_rename, 1, &zopt_rarely }, 214 { ztest_vdev_attach_detach, 1, &zopt_rarely }, 215 { ztest_vdev_LUN_growth, 1, &zopt_rarely }, 216 { ztest_vdev_add_remove, 1, &zopt_vdevtime }, 217 { ztest_vdev_aux_add_remove, 1, &zopt_vdevtime }, 218 { ztest_scrub, 1, &zopt_vdevtime }, |
200}; 201 202#define ZTEST_FUNCS (sizeof (ztest_info) / sizeof (ztest_info_t)) 203 204#define ZTEST_SYNC_LOCKS 16 205 206/* 207 * Stuff we need to share writably between parent and child. 208 */ 209typedef struct ztest_shared { 210 mutex_t zs_vdev_lock; 211 rwlock_t zs_name_lock; 212 uint64_t zs_vdev_primaries; | 219}; 220 221#define ZTEST_FUNCS (sizeof (ztest_info) / sizeof (ztest_info_t)) 222 223#define ZTEST_SYNC_LOCKS 16 224 225/* 226 * Stuff we need to share writably between parent and child. 227 */ 228typedef struct ztest_shared { 229 mutex_t zs_vdev_lock; 230 rwlock_t zs_name_lock; 231 uint64_t zs_vdev_primaries; |
232 uint64_t zs_vdev_aux; |
|
213 uint64_t zs_enospc_count; 214 hrtime_t zs_start_time; 215 hrtime_t zs_stop_time; 216 uint64_t zs_alloc; 217 uint64_t zs_space; | 233 uint64_t zs_enospc_count; 234 hrtime_t zs_start_time; 235 hrtime_t zs_stop_time; 236 uint64_t zs_alloc; 237 uint64_t zs_space; |
218 uint64_t zs_txg; | |
219 ztest_info_t zs_info[ZTEST_FUNCS]; 220 mutex_t zs_sync_lock[ZTEST_SYNC_LOCKS]; 221 uint64_t zs_seq[ZTEST_SYNC_LOCKS]; 222} ztest_shared_t; 223 | 238 ztest_info_t zs_info[ZTEST_FUNCS]; 239 mutex_t zs_sync_lock[ZTEST_SYNC_LOCKS]; 240 uint64_t zs_seq[ZTEST_SYNC_LOCKS]; 241} ztest_shared_t; 242 |
224typedef struct ztest_block_tag { 225 uint64_t bt_objset; 226 uint64_t bt_object; 227 uint64_t bt_offset; 228 uint64_t bt_txg; 229 uint64_t bt_thread; 230 uint64_t bt_seq; 231} ztest_block_tag_t; 232 | |
233static char ztest_dev_template[] = "%s/%s.%llua"; | 243static char ztest_dev_template[] = "%s/%s.%llua"; |
244static char ztest_aux_template[] = "%s/%s.%s.%llu"; |
|
234static ztest_shared_t *ztest_shared; 235 236static int ztest_random_fd; 237static int ztest_dump_core = 1; 238 | 245static ztest_shared_t *ztest_shared; 246 247static int ztest_random_fd; 248static int ztest_dump_core = 1; 249 |
239extern uint64_t zio_gang_bang; 240extern uint16_t zio_zil_fail_shift; | 250static boolean_t ztest_exiting; |
241 | 251 |
252extern uint64_t metaslab_gang_bang; 253 |
|
242#define ZTEST_DIROBJ 1 243#define ZTEST_MICROZAP_OBJ 2 244#define ZTEST_FATZAP_OBJ 3 245 246#define ZTEST_DIROBJ_BLOCKSIZE (1 << 10) 247#define ZTEST_DIRSIZE 256 248 249static void usage(boolean_t) __NORETURN; --- 102 unchanged lines hidden (view full) --- 352static void 353usage(boolean_t requested) 354{ 355 char nice_vdev_size[10]; 356 char nice_gang_bang[10]; 357 FILE *fp = requested ? stdout : stderr; 358 359 nicenum(zopt_vdev_size, nice_vdev_size); | 254#define ZTEST_DIROBJ 1 255#define ZTEST_MICROZAP_OBJ 2 256#define ZTEST_FATZAP_OBJ 3 257 258#define ZTEST_DIROBJ_BLOCKSIZE (1 << 10) 259#define ZTEST_DIRSIZE 256 260 261static void usage(boolean_t) __NORETURN; --- 102 unchanged lines hidden (view full) --- 364static void 365usage(boolean_t requested) 366{ 367 char nice_vdev_size[10]; 368 char nice_gang_bang[10]; 369 FILE *fp = requested ? stdout : stderr; 370 371 nicenum(zopt_vdev_size, nice_vdev_size); |
360 nicenum(zio_gang_bang, nice_gang_bang); | 372 nicenum(metaslab_gang_bang, nice_gang_bang); |
361 362 (void) fprintf(fp, "Usage: %s\n" 363 "\t[-v vdevs (default: %llu)]\n" 364 "\t[-s size_of_each_vdev (default: %s)]\n" 365 "\t[-a alignment_shift (default: %d) (use 0 for random)]\n" 366 "\t[-m mirror_copies (default: %d)]\n" 367 "\t[-r raidz_disks (default: %d)]\n" 368 "\t[-R raidz_parity (default: %d)]\n" 369 "\t[-d datasets (default: %d)]\n" 370 "\t[-t threads (default: %d)]\n" 371 "\t[-g gang_block_threshold (default: %s)]\n" 372 "\t[-i initialize pool i times (default: %d)]\n" 373 "\t[-k kill percentage (default: %llu%%)]\n" 374 "\t[-p pool_name (default: %s)]\n" 375 "\t[-f file directory for vdev files (default: %s)]\n" 376 "\t[-V(erbose)] (use multiple times for ever more blather)\n" 377 "\t[-E(xisting)] (use existing pool instead of creating new one)\n" 378 "\t[-T time] total run time (default: %llu sec)\n" 379 "\t[-P passtime] time per pass (default: %llu sec)\n" | 373 374 (void) fprintf(fp, "Usage: %s\n" 375 "\t[-v vdevs (default: %llu)]\n" 376 "\t[-s size_of_each_vdev (default: %s)]\n" 377 "\t[-a alignment_shift (default: %d) (use 0 for random)]\n" 378 "\t[-m mirror_copies (default: %d)]\n" 379 "\t[-r raidz_disks (default: %d)]\n" 380 "\t[-R raidz_parity (default: %d)]\n" 381 "\t[-d datasets (default: %d)]\n" 382 "\t[-t threads (default: %d)]\n" 383 "\t[-g gang_block_threshold (default: %s)]\n" 384 "\t[-i initialize pool i times (default: %d)]\n" 385 "\t[-k kill percentage (default: %llu%%)]\n" 386 "\t[-p pool_name (default: %s)]\n" 387 "\t[-f file directory for vdev files (default: %s)]\n" 388 "\t[-V(erbose)] (use multiple times for ever more blather)\n" 389 "\t[-E(xisting)] (use existing pool instead of creating new one)\n" 390 "\t[-T time] total run time (default: %llu sec)\n" 391 "\t[-P passtime] time per pass (default: %llu sec)\n" |
380 "\t[-z zil failure rate (default: fail every 2^%llu allocs)]\n" | |
381 "\t[-h] (print help)\n" 382 "", 383 cmdname, | 392 "\t[-h] (print help)\n" 393 "", 394 cmdname, |
384 (u_longlong_t)zopt_vdevs, /* -v */ 385 nice_vdev_size, /* -s */ 386 zopt_ashift, /* -a */ 387 zopt_mirrors, /* -m */ 388 zopt_raidz, /* -r */ 389 zopt_raidz_parity, /* -R */ 390 zopt_datasets, /* -d */ 391 zopt_threads, /* -t */ 392 nice_gang_bang, /* -g */ 393 zopt_init, /* -i */ 394 (u_longlong_t)zopt_killrate, /* -k */ 395 zopt_pool, /* -p */ 396 zopt_dir, /* -f */ 397 (u_longlong_t)zopt_time, /* -T */ 398 (u_longlong_t)zopt_passtime, /* -P */ 399 (u_longlong_t)zio_zil_fail_shift); /* -z */ | 395 (u_longlong_t)zopt_vdevs, /* -v */ 396 nice_vdev_size, /* -s */ 397 zopt_ashift, /* -a */ 398 zopt_mirrors, /* -m */ 399 zopt_raidz, /* -r */ 400 zopt_raidz_parity, /* -R */ 401 zopt_datasets, /* -d */ 402 zopt_threads, /* -t */ 403 nice_gang_bang, /* -g */ 404 zopt_init, /* -i */ 405 (u_longlong_t)zopt_killrate, /* -k */ 406 zopt_pool, /* -p */ 407 zopt_dir, /* -f */ 408 (u_longlong_t)zopt_time, /* -T */ 409 (u_longlong_t)zopt_passtime); /* -P */ |
400 exit(requested ? 0 : 1); 401} 402 403static uint64_t 404ztest_random(uint64_t range) 405{ 406 uint64_t r; 407 --- 18 unchanged lines hidden (view full) --- 426{ 427 int opt; 428 uint64_t value; 429 430 /* Remember program name. */ 431 progname = argv[0]; 432 433 /* By default, test gang blocks for blocks 32K and greater */ | 410 exit(requested ? 0 : 1); 411} 412 413static uint64_t 414ztest_random(uint64_t range) 415{ 416 uint64_t r; 417 --- 18 unchanged lines hidden (view full) --- 436{ 437 int opt; 438 uint64_t value; 439 440 /* Remember program name. */ 441 progname = argv[0]; 442 443 /* By default, test gang blocks for blocks 32K and greater */ |
434 zio_gang_bang = 32 << 10; | 444 metaslab_gang_bang = 32 << 10; |
435 | 445 |
436 /* Default value, fail every 32nd allocation */ 437 zio_zil_fail_shift = 5; 438 | |
439 while ((opt = getopt(argc, argv, | 446 while ((opt = getopt(argc, argv, |
440 "v:s:a:m:r:R:d:t:g:i:k:p:f:VET:P:z:h")) != EOF) { | 447 "v:s:a:m:r:R:d:t:g:i:k:p:f:VET:P:h")) != EOF) { |
441 value = 0; 442 switch (opt) { | 448 value = 0; 449 switch (opt) { |
443 case 'v': 444 case 's': 445 case 'a': 446 case 'm': 447 case 'r': 448 case 'R': 449 case 'd': 450 case 't': 451 case 'g': 452 case 'i': 453 case 'k': 454 case 'T': 455 case 'P': 456 case 'z': | 450 case 'v': 451 case 's': 452 case 'a': 453 case 'm': 454 case 'r': 455 case 'R': 456 case 'd': 457 case 't': 458 case 'g': 459 case 'i': 460 case 'k': 461 case 'T': 462 case 'P': |
457 value = nicenumtoull(optarg); 458 } 459 switch (opt) { | 463 value = nicenumtoull(optarg); 464 } 465 switch (opt) { |
460 case 'v': | 466 case 'v': |
461 zopt_vdevs = value; 462 break; | 467 zopt_vdevs = value; 468 break; |
463 case 's': | 469 case 's': |
464 zopt_vdev_size = MAX(SPA_MINDEVSIZE, value); 465 break; | 470 zopt_vdev_size = MAX(SPA_MINDEVSIZE, value); 471 break; |
466 case 'a': | 472 case 'a': |
467 zopt_ashift = value; 468 break; | 473 zopt_ashift = value; 474 break; |
469 case 'm': | 475 case 'm': |
470 zopt_mirrors = value; 471 break; | 476 zopt_mirrors = value; 477 break; |
472 case 'r': | 478 case 'r': |
473 zopt_raidz = MAX(1, value); 474 break; | 479 zopt_raidz = MAX(1, value); 480 break; |
475 case 'R': | 481 case 'R': |
476 zopt_raidz_parity = MIN(MAX(value, 1), 2); 477 break; | 482 zopt_raidz_parity = MIN(MAX(value, 1), 2); 483 break; |
478 case 'd': | 484 case 'd': |
479 zopt_datasets = MAX(1, value); 480 break; | 485 zopt_datasets = MAX(1, value); 486 break; |
481 case 't': | 487 case 't': |
482 zopt_threads = MAX(1, value); 483 break; | 488 zopt_threads = MAX(1, value); 489 break; |
484 case 'g': 485 zio_gang_bang = MAX(SPA_MINBLOCKSIZE << 1, value); | 490 case 'g': 491 metaslab_gang_bang = MAX(SPA_MINBLOCKSIZE << 1, value); |
486 break; | 492 break; |
487 case 'i': | 493 case 'i': |
488 zopt_init = value; 489 break; | 494 zopt_init = value; 495 break; |
490 case 'k': | 496 case 'k': |
491 zopt_killrate = value; 492 break; | 497 zopt_killrate = value; 498 break; |
493 case 'p': | 499 case 'p': |
494 zopt_pool = strdup(optarg); 495 break; | 500 zopt_pool = strdup(optarg); 501 break; |
496 case 'f': | 502 case 'f': |
497 zopt_dir = strdup(optarg); 498 break; | 503 zopt_dir = strdup(optarg); 504 break; |
499 case 'V': | 505 case 'V': |
500 zopt_verbose++; 501 break; | 506 zopt_verbose++; 507 break; |
502 case 'E': | 508 case 'E': |
503 zopt_init = 0; 504 break; | 509 zopt_init = 0; 510 break; |
505 case 'T': | 511 case 'T': |
506 zopt_time = value; 507 break; | 512 zopt_time = value; 513 break; |
508 case 'P': | 514 case 'P': |
509 zopt_passtime = MAX(1, value); 510 break; | 515 zopt_passtime = MAX(1, value); 516 break; |
511 case 'z': 512 zio_zil_fail_shift = MIN(value, 16); 513 break; 514 case 'h': | 517 case 'h': |
515 usage(B_TRUE); 516 break; | 518 usage(B_TRUE); 519 break; |
517 case '?': 518 default: | 520 case '?': 521 default: |
519 usage(B_FALSE); 520 break; 521 } 522 } 523 524 zopt_raidz_parity = MIN(zopt_raidz_parity, zopt_raidz - 1); 525 526 zopt_vdevtime = (zopt_vdevs > 0 ? zopt_time / zopt_vdevs : UINT64_MAX); --- 4 unchanged lines hidden (view full) --- 531ztest_get_ashift(void) 532{ 533 if (zopt_ashift == 0) 534 return (SPA_MINBLOCKSHIFT + ztest_random(3)); 535 return (zopt_ashift); 536} 537 538static nvlist_t * | 522 usage(B_FALSE); 523 break; 524 } 525 } 526 527 zopt_raidz_parity = MIN(zopt_raidz_parity, zopt_raidz - 1); 528 529 zopt_vdevtime = (zopt_vdevs > 0 ? zopt_time / zopt_vdevs : UINT64_MAX); --- 4 unchanged lines hidden (view full) --- 534ztest_get_ashift(void) 535{ 536 if (zopt_ashift == 0) 537 return (SPA_MINBLOCKSHIFT + ztest_random(3)); 538 return (zopt_ashift); 539} 540 541static nvlist_t * |
539make_vdev_file(size_t size) | 542make_vdev_file(char *path, char *aux, size_t size, uint64_t ashift) |
540{ | 543{ |
541 char dev_name[MAXPATHLEN]; | 544 char pathbuf[MAXPATHLEN]; |
542 uint64_t vdev; | 545 uint64_t vdev; |
543 uint64_t ashift = ztest_get_ashift(); 544 int fd; | |
545 nvlist_t *file; 546 | 546 nvlist_t *file; 547 |
547 if (size == 0) { 548 (void) snprintf(dev_name, sizeof (dev_name), "%s", 549 "/dev/bogus"); 550 } else { 551 vdev = ztest_shared->zs_vdev_primaries++; 552 (void) sprintf(dev_name, ztest_dev_template, 553 zopt_dir, zopt_pool, vdev); | 548 if (ashift == 0) 549 ashift = ztest_get_ashift(); |
554 | 550 |
555 fd = open(dev_name, O_RDWR | O_CREAT | O_TRUNC, 0666); | 551 if (path == NULL) { 552 path = pathbuf; 553 554 if (aux != NULL) { 555 vdev = ztest_shared->zs_vdev_aux; 556 (void) sprintf(path, ztest_aux_template, 557 zopt_dir, zopt_pool, aux, vdev); 558 } else { 559 vdev = ztest_shared->zs_vdev_primaries++; 560 (void) sprintf(path, ztest_dev_template, 561 zopt_dir, zopt_pool, vdev); 562 } 563 } 564 565 if (size != 0) { 566 int fd = open(path, O_RDWR | O_CREAT | O_TRUNC, 0666); |
556 if (fd == -1) | 567 if (fd == -1) |
557 fatal(1, "can't open %s", dev_name); | 568 fatal(1, "can't open %s", path); |
558 if (ftruncate(fd, size) != 0) | 569 if (ftruncate(fd, size) != 0) |
559 fatal(1, "can't ftruncate %s", dev_name); | 570 fatal(1, "can't ftruncate %s", path); |
560 (void) close(fd); 561 } 562 563 VERIFY(nvlist_alloc(&file, NV_UNIQUE_NAME, 0) == 0); 564 VERIFY(nvlist_add_string(file, ZPOOL_CONFIG_TYPE, VDEV_TYPE_FILE) == 0); | 571 (void) close(fd); 572 } 573 574 VERIFY(nvlist_alloc(&file, NV_UNIQUE_NAME, 0) == 0); 575 VERIFY(nvlist_add_string(file, ZPOOL_CONFIG_TYPE, VDEV_TYPE_FILE) == 0); |
565 VERIFY(nvlist_add_string(file, ZPOOL_CONFIG_PATH, dev_name) == 0); | 576 VERIFY(nvlist_add_string(file, ZPOOL_CONFIG_PATH, path) == 0); |
566 VERIFY(nvlist_add_uint64(file, ZPOOL_CONFIG_ASHIFT, ashift) == 0); 567 568 return (file); 569} 570 571static nvlist_t * | 577 VERIFY(nvlist_add_uint64(file, ZPOOL_CONFIG_ASHIFT, ashift) == 0); 578 579 return (file); 580} 581 582static nvlist_t * |
572make_vdev_raidz(size_t size, int r) | 583make_vdev_raidz(char *path, char *aux, size_t size, uint64_t ashift, int r) |
573{ 574 nvlist_t *raidz, **child; 575 int c; 576 577 if (r < 2) | 584{ 585 nvlist_t *raidz, **child; 586 int c; 587 588 if (r < 2) |
578 return (make_vdev_file(size)); 579 | 589 return (make_vdev_file(path, aux, size, ashift)); |
580 child = umem_alloc(r * sizeof (nvlist_t *), UMEM_NOFAIL); 581 582 for (c = 0; c < r; c++) | 590 child = umem_alloc(r * sizeof (nvlist_t *), UMEM_NOFAIL); 591 592 for (c = 0; c < r; c++) |
583 child[c] = make_vdev_file(size); | 593 child[c] = make_vdev_file(path, aux, size, ashift); |
584 585 VERIFY(nvlist_alloc(&raidz, NV_UNIQUE_NAME, 0) == 0); 586 VERIFY(nvlist_add_string(raidz, ZPOOL_CONFIG_TYPE, 587 VDEV_TYPE_RAIDZ) == 0); 588 VERIFY(nvlist_add_uint64(raidz, ZPOOL_CONFIG_NPARITY, 589 zopt_raidz_parity) == 0); 590 VERIFY(nvlist_add_nvlist_array(raidz, ZPOOL_CONFIG_CHILDREN, 591 child, r) == 0); 592 593 for (c = 0; c < r; c++) 594 nvlist_free(child[c]); 595 596 umem_free(child, r * sizeof (nvlist_t *)); 597 598 return (raidz); 599} 600 601static nvlist_t * | 594 595 VERIFY(nvlist_alloc(&raidz, NV_UNIQUE_NAME, 0) == 0); 596 VERIFY(nvlist_add_string(raidz, ZPOOL_CONFIG_TYPE, 597 VDEV_TYPE_RAIDZ) == 0); 598 VERIFY(nvlist_add_uint64(raidz, ZPOOL_CONFIG_NPARITY, 599 zopt_raidz_parity) == 0); 600 VERIFY(nvlist_add_nvlist_array(raidz, ZPOOL_CONFIG_CHILDREN, 601 child, r) == 0); 602 603 for (c = 0; c < r; c++) 604 nvlist_free(child[c]); 605 606 umem_free(child, r * sizeof (nvlist_t *)); 607 608 return (raidz); 609} 610 611static nvlist_t * |
602make_vdev_mirror(size_t size, int r, int m) | 612make_vdev_mirror(char *path, char *aux, size_t size, uint64_t ashift, 613 int r, int m) |
603{ 604 nvlist_t *mirror, **child; 605 int c; 606 607 if (m < 1) | 614{ 615 nvlist_t *mirror, **child; 616 int c; 617 618 if (m < 1) |
608 return (make_vdev_raidz(size, r)); | 619 return (make_vdev_raidz(path, aux, size, ashift, r)); |
609 610 child = umem_alloc(m * sizeof (nvlist_t *), UMEM_NOFAIL); 611 612 for (c = 0; c < m; c++) | 620 621 child = umem_alloc(m * sizeof (nvlist_t *), UMEM_NOFAIL); 622 623 for (c = 0; c < m; c++) |
613 child[c] = make_vdev_raidz(size, r); | 624 child[c] = make_vdev_raidz(path, aux, size, ashift, r); |
614 615 VERIFY(nvlist_alloc(&mirror, NV_UNIQUE_NAME, 0) == 0); 616 VERIFY(nvlist_add_string(mirror, ZPOOL_CONFIG_TYPE, 617 VDEV_TYPE_MIRROR) == 0); 618 VERIFY(nvlist_add_nvlist_array(mirror, ZPOOL_CONFIG_CHILDREN, 619 child, m) == 0); 620 621 for (c = 0; c < m; c++) 622 nvlist_free(child[c]); 623 624 umem_free(child, m * sizeof (nvlist_t *)); 625 626 return (mirror); 627} 628 629static nvlist_t * | 625 626 VERIFY(nvlist_alloc(&mirror, NV_UNIQUE_NAME, 0) == 0); 627 VERIFY(nvlist_add_string(mirror, ZPOOL_CONFIG_TYPE, 628 VDEV_TYPE_MIRROR) == 0); 629 VERIFY(nvlist_add_nvlist_array(mirror, ZPOOL_CONFIG_CHILDREN, 630 child, m) == 0); 631 632 for (c = 0; c < m; c++) 633 nvlist_free(child[c]); 634 635 umem_free(child, m * sizeof (nvlist_t *)); 636 637 return (mirror); 638} 639 640static nvlist_t * |
630make_vdev_root(size_t size, int r, int m, int t) | 641make_vdev_root(char *path, char *aux, size_t size, uint64_t ashift, 642 int log, int r, int m, int t) |
631{ 632 nvlist_t *root, **child; 633 int c; 634 635 ASSERT(t > 0); 636 637 child = umem_alloc(t * sizeof (nvlist_t *), UMEM_NOFAIL); 638 | 643{ 644 nvlist_t *root, **child; 645 int c; 646 647 ASSERT(t > 0); 648 649 child = umem_alloc(t * sizeof (nvlist_t *), UMEM_NOFAIL); 650 |
639 for (c = 0; c < t; c++) 640 child[c] = make_vdev_mirror(size, r, m); | 651 for (c = 0; c < t; c++) { 652 child[c] = make_vdev_mirror(path, aux, size, ashift, r, m); 653 VERIFY(nvlist_add_uint64(child[c], ZPOOL_CONFIG_IS_LOG, 654 log) == 0); 655 } |
641 642 VERIFY(nvlist_alloc(&root, NV_UNIQUE_NAME, 0) == 0); 643 VERIFY(nvlist_add_string(root, ZPOOL_CONFIG_TYPE, VDEV_TYPE_ROOT) == 0); | 656 657 VERIFY(nvlist_alloc(&root, NV_UNIQUE_NAME, 0) == 0); 658 VERIFY(nvlist_add_string(root, ZPOOL_CONFIG_TYPE, VDEV_TYPE_ROOT) == 0); |
644 VERIFY(nvlist_add_nvlist_array(root, ZPOOL_CONFIG_CHILDREN, | 659 VERIFY(nvlist_add_nvlist_array(root, aux ? aux : ZPOOL_CONFIG_CHILDREN, |
645 child, t) == 0); 646 647 for (c = 0; c < t; c++) 648 nvlist_free(child[c]); 649 650 umem_free(child, t * sizeof (nvlist_t *)); 651 652 return (root); --- 127 unchanged lines hidden (view full) --- 780{ 781 int error; 782 spa_t *spa; 783 nvlist_t *nvroot; 784 785 /* 786 * Attempt to create using a bad file. 787 */ | 660 child, t) == 0); 661 662 for (c = 0; c < t; c++) 663 nvlist_free(child[c]); 664 665 umem_free(child, t * sizeof (nvlist_t *)); 666 667 return (root); --- 127 unchanged lines hidden (view full) --- 795{ 796 int error; 797 spa_t *spa; 798 nvlist_t *nvroot; 799 800 /* 801 * Attempt to create using a bad file. 802 */ |
788 nvroot = make_vdev_root(0, 0, 0, 1); 789 error = spa_create("ztest_bad_file", nvroot, NULL); | 803 nvroot = make_vdev_root("/dev/bogus", NULL, 0, 0, 0, 0, 0, 1); 804 error = spa_create("ztest_bad_file", nvroot, NULL, NULL, NULL); |
790 nvlist_free(nvroot); 791 if (error != ENOENT) 792 fatal(0, "spa_create(bad_file) = %d", error); 793 794 /* 795 * Attempt to create using a bad mirror. 796 */ | 805 nvlist_free(nvroot); 806 if (error != ENOENT) 807 fatal(0, "spa_create(bad_file) = %d", error); 808 809 /* 810 * Attempt to create using a bad mirror. 811 */ |
797 nvroot = make_vdev_root(0, 0, 2, 1); 798 error = spa_create("ztest_bad_mirror", nvroot, NULL); | 812 nvroot = make_vdev_root("/dev/bogus", NULL, 0, 0, 0, 0, 2, 1); 813 error = spa_create("ztest_bad_mirror", nvroot, NULL, NULL, NULL); |
799 nvlist_free(nvroot); 800 if (error != ENOENT) 801 fatal(0, "spa_create(bad_mirror) = %d", error); 802 803 /* 804 * Attempt to create an existing pool. It shouldn't matter 805 * what's in the nvroot; we should fail with EEXIST. 806 */ 807 (void) rw_rdlock(&ztest_shared->zs_name_lock); | 814 nvlist_free(nvroot); 815 if (error != ENOENT) 816 fatal(0, "spa_create(bad_mirror) = %d", error); 817 818 /* 819 * Attempt to create an existing pool. It shouldn't matter 820 * what's in the nvroot; we should fail with EEXIST. 821 */ 822 (void) rw_rdlock(&ztest_shared->zs_name_lock); |
808 nvroot = make_vdev_root(0, 0, 0, 1); 809 error = spa_create(za->za_pool, nvroot, NULL); | 823 nvroot = make_vdev_root("/dev/bogus", NULL, 0, 0, 0, 0, 0, 1); 824 error = spa_create(za->za_pool, nvroot, NULL, NULL, NULL); |
810 nvlist_free(nvroot); 811 if (error != EEXIST) 812 fatal(0, "spa_create(whatever) = %d", error); 813 814 error = spa_open(za->za_pool, &spa, FTAG); 815 if (error) 816 fatal(0, "spa_open() = %d", error); 817 818 error = spa_destroy(za->za_pool); 819 if (error != EBUSY) 820 fatal(0, "spa_destroy() = %d", error); 821 822 spa_close(spa, FTAG); 823 (void) rw_unlock(&ztest_shared->zs_name_lock); 824} 825 | 825 nvlist_free(nvroot); 826 if (error != EEXIST) 827 fatal(0, "spa_create(whatever) = %d", error); 828 829 error = spa_open(za->za_pool, &spa, FTAG); 830 if (error) 831 fatal(0, "spa_open() = %d", error); 832 833 error = spa_destroy(za->za_pool); 834 if (error != EBUSY) 835 fatal(0, "spa_destroy() = %d", error); 836 837 spa_close(spa, FTAG); 838 (void) rw_unlock(&ztest_shared->zs_name_lock); 839} 840 |
841static vdev_t * 842vdev_lookup_by_path(vdev_t *vd, const char *path) 843{ 844 vdev_t *mvd; 845 846 if (vd->vdev_path != NULL && strcmp(path, vd->vdev_path) == 0) 847 return (vd); 848 849 for (int c = 0; c < vd->vdev_children; c++) 850 if ((mvd = vdev_lookup_by_path(vd->vdev_child[c], path)) != 851 NULL) 852 return (mvd); 853 854 return (NULL); 855} 856 |
|
826/* 827 * Verify that vdev_add() works as expected. 828 */ 829void 830ztest_vdev_add_remove(ztest_args_t *za) 831{ | 857/* 858 * Verify that vdev_add() works as expected. 859 */ 860void 861ztest_vdev_add_remove(ztest_args_t *za) 862{ |
832 spa_t *spa = dmu_objset_spa(za->za_os); | 863 spa_t *spa = za->za_spa; |
833 uint64_t leaves = MAX(zopt_mirrors, 1) * zopt_raidz; 834 nvlist_t *nvroot; 835 int error; 836 | 864 uint64_t leaves = MAX(zopt_mirrors, 1) * zopt_raidz; 865 nvlist_t *nvroot; 866 int error; 867 |
837 if (zopt_verbose >= 6) 838 (void) printf("adding vdev\n"); 839 | |
840 (void) mutex_lock(&ztest_shared->zs_vdev_lock); 841 | 868 (void) mutex_lock(&ztest_shared->zs_vdev_lock); 869 |
842 spa_config_enter(spa, RW_READER, FTAG); | 870 spa_config_enter(spa, SCL_VDEV, FTAG, RW_READER); |
843 844 ztest_shared->zs_vdev_primaries = 845 spa->spa_root_vdev->vdev_children * leaves; 846 | 871 872 ztest_shared->zs_vdev_primaries = 873 spa->spa_root_vdev->vdev_children * leaves; 874 |
847 spa_config_exit(spa, FTAG); | 875 spa_config_exit(spa, SCL_VDEV, FTAG); |
848 | 876 |
849 nvroot = make_vdev_root(zopt_vdev_size, zopt_raidz, zopt_mirrors, 1); | 877 /* 878 * Make 1/4 of the devices be log devices. 879 */ 880 nvroot = make_vdev_root(NULL, NULL, zopt_vdev_size, 0, 881 ztest_random(4) == 0, zopt_raidz, zopt_mirrors, 1); 882 |
850 error = spa_vdev_add(spa, nvroot); 851 nvlist_free(nvroot); 852 853 (void) mutex_unlock(&ztest_shared->zs_vdev_lock); 854 855 if (error == ENOSPC) 856 ztest_record_enospc("spa_vdev_add"); 857 else if (error != 0) 858 fatal(0, "spa_vdev_add() = %d", error); | 883 error = spa_vdev_add(spa, nvroot); 884 nvlist_free(nvroot); 885 886 (void) mutex_unlock(&ztest_shared->zs_vdev_lock); 887 888 if (error == ENOSPC) 889 ztest_record_enospc("spa_vdev_add"); 890 else if (error != 0) 891 fatal(0, "spa_vdev_add() = %d", error); |
859 860 if (zopt_verbose >= 6) 861 (void) printf("spa_vdev_add = %d, as expected\n", error); | |
862} 863 | 892} 893 |
864static vdev_t * 865vdev_lookup_by_path(vdev_t *vd, const char *path) | 894/* 895 * Verify that adding/removing aux devices (l2arc, hot spare) works as expected. 896 */ 897void 898ztest_vdev_aux_add_remove(ztest_args_t *za) |
866{ | 899{ |
867 int c; 868 vdev_t *mvd; | 900 spa_t *spa = za->za_spa; 901 vdev_t *rvd = spa->spa_root_vdev; 902 spa_aux_vdev_t *sav; 903 char *aux; 904 uint64_t guid = 0; 905 int error; |
869 | 906 |
870 if (vd->vdev_path != NULL) { 871 if (vd->vdev_wholedisk == 1) { 872 /* 873 * For whole disks, the internal path has 's0', but the 874 * path passed in by the user doesn't. 875 */ 876 if (strlen(path) == strlen(vd->vdev_path) - 2 && 877 strncmp(path, vd->vdev_path, strlen(path)) == 0) 878 return (vd); 879 } else if (strcmp(path, vd->vdev_path) == 0) { 880 return (vd); | 907 if (ztest_random(2) == 0) { 908 sav = &spa->spa_spares; 909 aux = ZPOOL_CONFIG_SPARES; 910 } else { 911 sav = &spa->spa_l2cache; 912 aux = ZPOOL_CONFIG_L2CACHE; 913 } 914 915 (void) mutex_lock(&ztest_shared->zs_vdev_lock); 916 917 spa_config_enter(spa, SCL_VDEV, FTAG, RW_READER); 918 919 if (sav->sav_count != 0 && ztest_random(4) == 0) { 920 /* 921 * Pick a random device to remove. 922 */ 923 guid = sav->sav_vdevs[ztest_random(sav->sav_count)]->vdev_guid; 924 } else { 925 /* 926 * Find an unused device we can add. 927 */ 928 ztest_shared->zs_vdev_aux = 0; 929 for (;;) { 930 char path[MAXPATHLEN]; 931 int c; 932 (void) sprintf(path, ztest_aux_template, zopt_dir, 933 zopt_pool, aux, ztest_shared->zs_vdev_aux); 934 for (c = 0; c < sav->sav_count; c++) 935 if (strcmp(sav->sav_vdevs[c]->vdev_path, 936 path) == 0) 937 break; 938 if (c == sav->sav_count && 939 vdev_lookup_by_path(rvd, path) == NULL) 940 break; 941 ztest_shared->zs_vdev_aux++; |
881 } 882 } 883 | 942 } 943 } 944 |
884 for (c = 0; c < vd->vdev_children; c++) 885 if ((mvd = vdev_lookup_by_path(vd->vdev_child[c], path)) != 886 NULL) 887 return (mvd); | 945 spa_config_exit(spa, SCL_VDEV, FTAG); |
888 | 946 |
889 return (NULL); | 947 if (guid == 0) { 948 /* 949 * Add a new device. 950 */ 951 nvlist_t *nvroot = make_vdev_root(NULL, aux, 952 (zopt_vdev_size * 5) / 4, 0, 0, 0, 0, 1); 953 error = spa_vdev_add(spa, nvroot); 954 if (error != 0) 955 fatal(0, "spa_vdev_add(%p) = %d", nvroot, error); 956 nvlist_free(nvroot); 957 } else { 958 /* 959 * Remove an existing device. Sometimes, dirty its 960 * vdev state first to make sure we handle removal 961 * of devices that have pending state changes. 962 */ 963 if (ztest_random(2) == 0) 964 (void) vdev_online(spa, guid, B_FALSE, NULL); 965 966 error = spa_vdev_remove(spa, guid, B_FALSE); 967 if (error != 0 && error != EBUSY) 968 fatal(0, "spa_vdev_remove(%llu) = %d", guid, error); 969 } 970 971 (void) mutex_unlock(&ztest_shared->zs_vdev_lock); |
890} 891 892/* 893 * Verify that we can attach and detach devices. 894 */ 895void 896ztest_vdev_attach_detach(ztest_args_t *za) 897{ | 972} 973 974/* 975 * Verify that we can attach and detach devices. 976 */ 977void 978ztest_vdev_attach_detach(ztest_args_t *za) 979{ |
898 spa_t *spa = dmu_objset_spa(za->za_os); | 980 spa_t *spa = za->za_spa; 981 spa_aux_vdev_t *sav = &spa->spa_spares; |
899 vdev_t *rvd = spa->spa_root_vdev; 900 vdev_t *oldvd, *newvd, *pvd; | 982 vdev_t *rvd = spa->spa_root_vdev; 983 vdev_t *oldvd, *newvd, *pvd; |
901 nvlist_t *root, *file; | 984 nvlist_t *root; |
902 uint64_t leaves = MAX(zopt_mirrors, 1) * zopt_raidz; 903 uint64_t leaf, top; 904 uint64_t ashift = ztest_get_ashift(); | 985 uint64_t leaves = MAX(zopt_mirrors, 1) * zopt_raidz; 986 uint64_t leaf, top; 987 uint64_t ashift = ztest_get_ashift(); |
988 uint64_t oldguid; |
|
905 size_t oldsize, newsize; 906 char oldpath[MAXPATHLEN], newpath[MAXPATHLEN]; 907 int replacing; | 989 size_t oldsize, newsize; 990 char oldpath[MAXPATHLEN], newpath[MAXPATHLEN]; 991 int replacing; |
992 int oldvd_has_siblings = B_FALSE; 993 int newvd_is_spare = B_FALSE; 994 int oldvd_is_log; |
|
908 int error, expected_error; | 995 int error, expected_error; |
909 int fd; | |
910 911 (void) mutex_lock(&ztest_shared->zs_vdev_lock); 912 | 996 997 (void) mutex_lock(&ztest_shared->zs_vdev_lock); 998 |
913 spa_config_enter(spa, RW_READER, FTAG); | 999 spa_config_enter(spa, SCL_VDEV, FTAG, RW_READER); |
914 915 /* 916 * Decide whether to do an attach or a replace. 917 */ 918 replacing = ztest_random(2); 919 920 /* 921 * Pick a random top-level vdev. 922 */ 923 top = ztest_random(rvd->vdev_children); 924 925 /* 926 * Pick a random leaf within it. 927 */ 928 leaf = ztest_random(leaves); 929 930 /* | 1000 1001 /* 1002 * Decide whether to do an attach or a replace. 1003 */ 1004 replacing = ztest_random(2); 1005 1006 /* 1007 * Pick a random top-level vdev. 1008 */ 1009 top = ztest_random(rvd->vdev_children); 1010 1011 /* 1012 * Pick a random leaf within it. 1013 */ 1014 leaf = ztest_random(leaves); 1015 1016 /* |
931 * Generate the path to this leaf. The filename will end with 'a'. 932 * We'll alternate replacements with a filename that ends with 'b'. | 1017 * Locate this vdev. |
933 */ | 1018 */ |
934 (void) snprintf(oldpath, sizeof (oldpath), 935 ztest_dev_template, zopt_dir, zopt_pool, top * leaves + leaf); | 1019 oldvd = rvd->vdev_child[top]; 1020 if (zopt_mirrors >= 1) 1021 oldvd = oldvd->vdev_child[leaf / zopt_raidz]; 1022 if (zopt_raidz > 1) 1023 oldvd = oldvd->vdev_child[leaf % zopt_raidz]; |
936 | 1024 |
937 bcopy(oldpath, newpath, MAXPATHLEN); 938 | |
939 /* | 1025 /* |
940 * If the 'a' file isn't part of the pool, the 'b' file must be. | 1026 * If we're already doing an attach or replace, oldvd may be a 1027 * mirror vdev -- in which case, pick a random child. |
941 */ | 1028 */ |
942 if (vdev_lookup_by_path(rvd, oldpath) == NULL) 943 oldpath[strlen(oldpath) - 1] = 'b'; 944 else 945 newpath[strlen(newpath) - 1] = 'b'; | 1029 while (oldvd->vdev_children != 0) { 1030 oldvd_has_siblings = B_TRUE; 1031 ASSERT(oldvd->vdev_children == 2); 1032 oldvd = oldvd->vdev_child[ztest_random(2)]; 1033 } |
946 | 1034 |
1035 oldguid = oldvd->vdev_guid; 1036 oldsize = vdev_get_rsize(oldvd); 1037 oldvd_is_log = oldvd->vdev_top->vdev_islog; 1038 (void) strcpy(oldpath, oldvd->vdev_path); 1039 pvd = oldvd->vdev_parent; 1040 |
|
947 /* | 1041 /* |
948 * Now oldpath represents something that's already in the pool, 949 * and newpath is the thing we'll try to attach. | 1042 * If oldvd has siblings, then half of the time, detach it. |
950 */ | 1043 */ |
951 oldvd = vdev_lookup_by_path(rvd, oldpath); 952 newvd = vdev_lookup_by_path(rvd, newpath); 953 ASSERT(oldvd != NULL); 954 pvd = oldvd->vdev_parent; | 1044 if (oldvd_has_siblings && ztest_random(2) == 0) { 1045 spa_config_exit(spa, SCL_VDEV, FTAG); 1046 error = spa_vdev_detach(spa, oldguid, B_FALSE); 1047 if (error != 0 && error != ENODEV && error != EBUSY) 1048 fatal(0, "detach (%s) returned %d", 1049 oldpath, error); 1050 (void) mutex_unlock(&ztest_shared->zs_vdev_lock); 1051 return; 1052 } |
955 956 /* | 1053 1054 /* |
957 * Make newsize a little bigger or smaller than oldsize. 958 * If it's smaller, the attach should fail. 959 * If it's larger, and we're doing a replace, 960 * we should get dynamic LUN growth when we're done. | 1055 * For the new vdev, choose with equal probability between the two 1056 * standard paths (ending in either 'a' or 'b') or a random hot spare. |
961 */ | 1057 */ |
962 oldsize = vdev_get_rsize(oldvd); 963 newsize = 10 * oldsize / (9 + ztest_random(3)); | 1058 if (sav->sav_count != 0 && ztest_random(3) == 0) { 1059 newvd = sav->sav_vdevs[ztest_random(sav->sav_count)]; 1060 newvd_is_spare = B_TRUE; 1061 (void) strcpy(newpath, newvd->vdev_path); 1062 } else { 1063 (void) snprintf(newpath, sizeof (newpath), ztest_dev_template, 1064 zopt_dir, zopt_pool, top * leaves + leaf); 1065 if (ztest_random(2) == 0) 1066 newpath[strlen(newpath) - 1] = 'b'; 1067 newvd = vdev_lookup_by_path(rvd, newpath); 1068 } |
964 | 1069 |
1070 if (newvd) { 1071 newsize = vdev_get_rsize(newvd); 1072 } else { 1073 /* 1074 * Make newsize a little bigger or smaller than oldsize. 1075 * If it's smaller, the attach should fail. 1076 * If it's larger, and we're doing a replace, 1077 * we should get dynamic LUN growth when we're done. 1078 */ 1079 newsize = 10 * oldsize / (9 + ztest_random(3)); 1080 } 1081 |
|
965 /* 966 * If pvd is not a mirror or root, the attach should fail with ENOTSUP, 967 * unless it's a replace; in that case any non-replacing parent is OK. 968 * 969 * If newvd is already part of the pool, it should fail with EBUSY. 970 * 971 * If newvd is too small, it should fail with EOVERFLOW. 972 */ | 1082 /* 1083 * If pvd is not a mirror or root, the attach should fail with ENOTSUP, 1084 * unless it's a replace; in that case any non-replacing parent is OK. 1085 * 1086 * If newvd is already part of the pool, it should fail with EBUSY. 1087 * 1088 * If newvd is too small, it should fail with EOVERFLOW. 1089 */ |
973 if (newvd != NULL) 974 expected_error = EBUSY; 975 else if (pvd->vdev_ops != &vdev_mirror_ops && 976 pvd->vdev_ops != &vdev_root_ops && 977 (!replacing || pvd->vdev_ops == &vdev_replacing_ops)) | 1090 if (pvd->vdev_ops != &vdev_mirror_ops && 1091 pvd->vdev_ops != &vdev_root_ops && (!replacing || 1092 pvd->vdev_ops == &vdev_replacing_ops || 1093 pvd->vdev_ops == &vdev_spare_ops)) |
978 expected_error = ENOTSUP; | 1094 expected_error = ENOTSUP; |
1095 else if (newvd_is_spare && (!replacing || oldvd_is_log)) 1096 expected_error = ENOTSUP; 1097 else if (newvd == oldvd) 1098 expected_error = replacing ? 0 : EBUSY; 1099 else if (vdev_lookup_by_path(rvd, newpath) != NULL) 1100 expected_error = EBUSY; |
|
979 else if (newsize < oldsize) 980 expected_error = EOVERFLOW; 981 else if (ashift > oldvd->vdev_top->vdev_ashift) 982 expected_error = EDOM; 983 else 984 expected_error = 0; 985 | 1101 else if (newsize < oldsize) 1102 expected_error = EOVERFLOW; 1103 else if (ashift > oldvd->vdev_top->vdev_ashift) 1104 expected_error = EDOM; 1105 else 1106 expected_error = 0; 1107 |
986 /* 987 * If newvd isn't already part of the pool, create it. 988 */ 989 if (newvd == NULL) { 990 fd = open(newpath, O_RDWR | O_CREAT | O_TRUNC, 0666); 991 if (fd == -1) 992 fatal(1, "can't open %s", newpath); 993 if (ftruncate(fd, newsize) != 0) 994 fatal(1, "can't ftruncate %s", newpath); 995 (void) close(fd); 996 } | 1108 spa_config_exit(spa, SCL_VDEV, FTAG); |
997 | 1109 |
998 spa_config_exit(spa, FTAG); 999 | |
1000 /* 1001 * Build the nvlist describing newpath. 1002 */ | 1110 /* 1111 * Build the nvlist describing newpath. 1112 */ |
1003 VERIFY(nvlist_alloc(&file, NV_UNIQUE_NAME, 0) == 0); 1004 VERIFY(nvlist_add_string(file, ZPOOL_CONFIG_TYPE, VDEV_TYPE_FILE) == 0); 1005 VERIFY(nvlist_add_string(file, ZPOOL_CONFIG_PATH, newpath) == 0); 1006 VERIFY(nvlist_add_uint64(file, ZPOOL_CONFIG_ASHIFT, ashift) == 0); | 1113 root = make_vdev_root(newpath, NULL, newvd == NULL ? newsize : 0, 1114 ashift, 0, 0, 0, 1); |
1007 | 1115 |
1008 VERIFY(nvlist_alloc(&root, NV_UNIQUE_NAME, 0) == 0); 1009 VERIFY(nvlist_add_string(root, ZPOOL_CONFIG_TYPE, VDEV_TYPE_ROOT) == 0); 1010 VERIFY(nvlist_add_nvlist_array(root, ZPOOL_CONFIG_CHILDREN, 1011 &file, 1) == 0); | 1116 error = spa_vdev_attach(spa, oldguid, root, replacing); |
1012 | 1117 |
1013 error = spa_vdev_attach(spa, oldvd->vdev_guid, root, replacing); 1014 1015 nvlist_free(file); | |
1016 nvlist_free(root); 1017 1018 /* 1019 * If our parent was the replacing vdev, but the replace completed, 1020 * then instead of failing with ENOTSUP we may either succeed, 1021 * fail with ENODEV, or fail with EOVERFLOW. 1022 */ 1023 if (expected_error == ENOTSUP && 1024 (error == 0 || error == ENODEV || error == EOVERFLOW)) 1025 expected_error = error; 1026 1027 /* 1028 * If someone grew the LUN, the replacement may be too small. 1029 */ | 1118 nvlist_free(root); 1119 1120 /* 1121 * If our parent was the replacing vdev, but the replace completed, 1122 * then instead of failing with ENOTSUP we may either succeed, 1123 * fail with ENODEV, or fail with EOVERFLOW. 1124 */ 1125 if (expected_error == ENOTSUP && 1126 (error == 0 || error == ENODEV || error == EOVERFLOW)) 1127 expected_error = error; 1128 1129 /* 1130 * If someone grew the LUN, the replacement may be too small. 1131 */ |
1030 if (error == EOVERFLOW) | 1132 if (error == EOVERFLOW || error == EBUSY) |
1031 expected_error = error; 1032 | 1133 expected_error = error; 1134 |
1033 if (error != expected_error) { 1034 fatal(0, "attach (%s, %s, %d) returned %d, expected %d", 1035 oldpath, newpath, replacing, error, expected_error); | 1135 /* XXX workaround 6690467 */ 1136 if (error != expected_error && expected_error != EBUSY) { 1137 fatal(0, "attach (%s %llu, %s %llu, %d) " 1138 "returned %d, expected %d", 1139 oldpath, (longlong_t)oldsize, newpath, 1140 (longlong_t)newsize, replacing, error, expected_error); |
1036 } 1037 1038 (void) mutex_unlock(&ztest_shared->zs_vdev_lock); 1039} 1040 1041/* 1042 * Verify that dynamic LUN growth works as expected. 1043 */ 1044/* ARGSUSED */ 1045void 1046ztest_vdev_LUN_growth(ztest_args_t *za) 1047{ | 1141 } 1142 1143 (void) mutex_unlock(&ztest_shared->zs_vdev_lock); 1144} 1145 1146/* 1147 * Verify that dynamic LUN growth works as expected. 1148 */ 1149/* ARGSUSED */ 1150void 1151ztest_vdev_LUN_growth(ztest_args_t *za) 1152{ |
1048 spa_t *spa = dmu_objset_spa(za->za_os); | 1153 spa_t *spa = za->za_spa; |
1049 char dev_name[MAXPATHLEN]; 1050 uint64_t leaves = MAX(zopt_mirrors, 1) * zopt_raidz; 1051 uint64_t vdev; 1052 size_t fsize; 1053 int fd; 1054 1055 (void) mutex_lock(&ztest_shared->zs_vdev_lock); 1056 1057 /* 1058 * Pick a random leaf vdev. 1059 */ | 1154 char dev_name[MAXPATHLEN]; 1155 uint64_t leaves = MAX(zopt_mirrors, 1) * zopt_raidz; 1156 uint64_t vdev; 1157 size_t fsize; 1158 int fd; 1159 1160 (void) mutex_lock(&ztest_shared->zs_vdev_lock); 1161 1162 /* 1163 * Pick a random leaf vdev. 1164 */ |
1060 spa_config_enter(spa, RW_READER, FTAG); | 1165 spa_config_enter(spa, SCL_VDEV, FTAG, RW_READER); |
1061 vdev = ztest_random(spa->spa_root_vdev->vdev_children * leaves); | 1166 vdev = ztest_random(spa->spa_root_vdev->vdev_children * leaves); |
1062 spa_config_exit(spa, FTAG); | 1167 spa_config_exit(spa, SCL_VDEV, FTAG); |
1063 1064 (void) sprintf(dev_name, ztest_dev_template, zopt_dir, zopt_pool, vdev); 1065 1066 if ((fd = open(dev_name, O_RDWR)) != -1) { 1067 /* 1068 * Determine the size. 1069 */ 1070 fsize = lseek(fd, 0, SEEK_END); --- 12 unchanged lines hidden (view full) --- 1083 (void) close(fd); 1084 } 1085 1086 (void) mutex_unlock(&ztest_shared->zs_vdev_lock); 1087} 1088 1089/* ARGSUSED */ 1090static void | 1168 1169 (void) sprintf(dev_name, ztest_dev_template, zopt_dir, zopt_pool, vdev); 1170 1171 if ((fd = open(dev_name, O_RDWR)) != -1) { 1172 /* 1173 * Determine the size. 1174 */ 1175 fsize = lseek(fd, 0, SEEK_END); --- 12 unchanged lines hidden (view full) --- 1188 (void) close(fd); 1189 } 1190 1191 (void) mutex_unlock(&ztest_shared->zs_vdev_lock); 1192} 1193 1194/* ARGSUSED */ 1195static void |
1091ztest_create_cb(objset_t *os, void *arg, dmu_tx_t *tx) | 1196ztest_create_cb(objset_t *os, void *arg, cred_t *cr, dmu_tx_t *tx) |
1092{ 1093 /* 1094 * Create the directory object. 1095 */ 1096 VERIFY(dmu_object_claim(os, ZTEST_DIROBJ, 1097 DMU_OT_UINT64_OTHER, ZTEST_DIROBJ_BLOCKSIZE, | 1197{ 1198 /* 1199 * Create the directory object. 1200 */ 1201 VERIFY(dmu_object_claim(os, ZTEST_DIROBJ, 1202 DMU_OT_UINT64_OTHER, ZTEST_DIROBJ_BLOCKSIZE, |
1098 DMU_OT_UINT64_OTHER, sizeof (ztest_block_tag_t), tx) == 0); | 1203 DMU_OT_UINT64_OTHER, 5 * sizeof (ztest_block_tag_t), tx) == 0); |
1099 1100 VERIFY(zap_create_claim(os, ZTEST_MICROZAP_OBJ, 1101 DMU_OT_ZAP_OTHER, DMU_OT_NONE, 0, tx) == 0); 1102 1103 VERIFY(zap_create_claim(os, ZTEST_FATZAP_OBJ, 1104 DMU_OT_ZAP_OTHER, DMU_OT_NONE, 0, tx) == 0); 1105} 1106 | 1204 1205 VERIFY(zap_create_claim(os, ZTEST_MICROZAP_OBJ, 1206 DMU_OT_ZAP_OTHER, DMU_OT_NONE, 0, tx) == 0); 1207 1208 VERIFY(zap_create_claim(os, ZTEST_FATZAP_OBJ, 1209 DMU_OT_ZAP_OTHER, DMU_OT_NONE, 0, tx) == 0); 1210} 1211 |
1107/* ARGSUSED */ | |
1108static int 1109ztest_destroy_cb(char *name, void *arg) 1110{ | 1212static int 1213ztest_destroy_cb(char *name, void *arg) 1214{ |
1215 ztest_args_t *za = arg; |
|
1111 objset_t *os; | 1216 objset_t *os; |
1112 dmu_object_info_t doi; | 1217 dmu_object_info_t *doi = &za->za_doi; |
1113 int error; 1114 1115 /* 1116 * Verify that the dataset contains a directory object. 1117 */ 1118 error = dmu_objset_open(name, DMU_OST_OTHER, | 1218 int error; 1219 1220 /* 1221 * Verify that the dataset contains a directory object. 1222 */ 1223 error = dmu_objset_open(name, DMU_OST_OTHER, |
1119 DS_MODE_STANDARD | DS_MODE_READONLY, &os); | 1224 DS_MODE_USER | DS_MODE_READONLY, &os); |
1120 ASSERT3U(error, ==, 0); | 1225 ASSERT3U(error, ==, 0); |
1121 error = dmu_object_info(os, ZTEST_DIROBJ, &doi); | 1226 error = dmu_object_info(os, ZTEST_DIROBJ, doi); |
1122 if (error != ENOENT) { 1123 /* We could have crashed in the middle of destroying it */ 1124 ASSERT3U(error, ==, 0); | 1227 if (error != ENOENT) { 1228 /* We could have crashed in the middle of destroying it */ 1229 ASSERT3U(error, ==, 0); |
1125 ASSERT3U(doi.doi_type, ==, DMU_OT_UINT64_OTHER); 1126 ASSERT3S(doi.doi_physical_blks, >=, 0); | 1230 ASSERT3U(doi->doi_type, ==, DMU_OT_UINT64_OTHER); 1231 ASSERT3S(doi->doi_physical_blks, >=, 0); |
1127 } 1128 dmu_objset_close(os); 1129 1130 /* 1131 * Destroy the dataset. 1132 */ 1133 error = dmu_objset_destroy(name); | 1232 } 1233 dmu_objset_close(os); 1234 1235 /* 1236 * Destroy the dataset. 1237 */ 1238 error = dmu_objset_destroy(name); |
1134 ASSERT3U(error, ==, 0); | 1239 if (error) { 1240 (void) dmu_objset_open(name, DMU_OST_OTHER, 1241 DS_MODE_USER | DS_MODE_READONLY, &os); 1242 fatal(0, "dmu_objset_destroy(os=%p) = %d\n", &os, error); 1243 } |
1135 return (0); 1136} 1137 1138/* 1139 * Verify that dmu_objset_{create,destroy,open,close} work as expected. 1140 */ 1141static uint64_t 1142ztest_log_create(zilog_t *zilog, dmu_tx_t *tx, uint64_t object, int mode) --- 23 unchanged lines hidden (view full) --- 1166 1167 return (zil_itx_assign(zilog, itx, tx)); 1168} 1169 1170void 1171ztest_dmu_objset_create_destroy(ztest_args_t *za) 1172{ 1173 int error; | 1244 return (0); 1245} 1246 1247/* 1248 * Verify that dmu_objset_{create,destroy,open,close} work as expected. 1249 */ 1250static uint64_t 1251ztest_log_create(zilog_t *zilog, dmu_tx_t *tx, uint64_t object, int mode) --- 23 unchanged lines hidden (view full) --- 1275 1276 return (zil_itx_assign(zilog, itx, tx)); 1277} 1278 1279void 1280ztest_dmu_objset_create_destroy(ztest_args_t *za) 1281{ 1282 int error; |
1174 objset_t *os; | 1283 objset_t *os, *os2; |
1175 char name[100]; | 1284 char name[100]; |
1176 int mode, basemode, expected_error; | 1285 int basemode, expected_error; |
1177 zilog_t *zilog; 1178 uint64_t seq; 1179 uint64_t objects; 1180 ztest_replay_t zr; 1181 1182 (void) rw_rdlock(&ztest_shared->zs_name_lock); 1183 (void) snprintf(name, 100, "%s/%s_temp_%llu", za->za_pool, za->za_pool, 1184 (u_longlong_t)za->za_instance); 1185 | 1286 zilog_t *zilog; 1287 uint64_t seq; 1288 uint64_t objects; 1289 ztest_replay_t zr; 1290 1291 (void) rw_rdlock(&ztest_shared->zs_name_lock); 1292 (void) snprintf(name, 100, "%s/%s_temp_%llu", za->za_pool, za->za_pool, 1293 (u_longlong_t)za->za_instance); 1294 |
1186 basemode = DS_MODE_LEVEL(za->za_instance); 1187 if (basemode == DS_MODE_NONE) 1188 basemode++; | 1295 basemode = DS_MODE_TYPE(za->za_instance); 1296 if (basemode != DS_MODE_USER && basemode != DS_MODE_OWNER) 1297 basemode = DS_MODE_USER; |
1189 1190 /* 1191 * If this dataset exists from a previous run, process its replay log 1192 * half of the time. If we don't replay it, then dmu_objset_destroy() 1193 * (invoked from ztest_destroy_cb() below) should just throw it away. 1194 */ 1195 if (ztest_random(2) == 0 && | 1298 1299 /* 1300 * If this dataset exists from a previous run, process its replay log 1301 * half of the time. If we don't replay it, then dmu_objset_destroy() 1302 * (invoked from ztest_destroy_cb() below) should just throw it away. 1303 */ 1304 if (ztest_random(2) == 0 && |
1196 dmu_objset_open(name, DMU_OST_OTHER, DS_MODE_PRIMARY, &os) == 0) { | 1305 dmu_objset_open(name, DMU_OST_OTHER, DS_MODE_OWNER, &os) == 0) { |
1197 zr.zr_os = os; | 1306 zr.zr_os = os; |
1198 zil_replay(os, &zr, &zr.zr_assign, ztest_replay_vector); | 1307 zil_replay(os, &zr, &zr.zr_assign, ztest_replay_vector, NULL); |
1199 dmu_objset_close(os); 1200 } 1201 1202 /* 1203 * There may be an old instance of the dataset we're about to 1204 * create lying around from a previous run. If so, destroy it 1205 * and all of its snapshots. 1206 */ | 1308 dmu_objset_close(os); 1309 } 1310 1311 /* 1312 * There may be an old instance of the dataset we're about to 1313 * create lying around from a previous run. If so, destroy it 1314 * and all of its snapshots. 1315 */ |
1207 (void) dmu_objset_find(name, ztest_destroy_cb, NULL, | 1316 (void) dmu_objset_find(name, ztest_destroy_cb, za, |
1208 DS_FIND_CHILDREN | DS_FIND_SNAPSHOTS); 1209 1210 /* 1211 * Verify that the destroyed dataset is no longer in the namespace. 1212 */ 1213 error = dmu_objset_open(name, DMU_OST_OTHER, basemode, &os); 1214 if (error != ENOENT) 1215 fatal(1, "dmu_objset_open(%s) found destroyed dataset %p", 1216 name, os); 1217 1218 /* 1219 * Verify that we can create a new dataset. 1220 */ | 1317 DS_FIND_CHILDREN | DS_FIND_SNAPSHOTS); 1318 1319 /* 1320 * Verify that the destroyed dataset is no longer in the namespace. 1321 */ 1322 error = dmu_objset_open(name, DMU_OST_OTHER, basemode, &os); 1323 if (error != ENOENT) 1324 fatal(1, "dmu_objset_open(%s) found destroyed dataset %p", 1325 name, os); 1326 1327 /* 1328 * Verify that we can create a new dataset. 1329 */ |
1221 error = dmu_objset_create(name, DMU_OST_OTHER, NULL, ztest_create_cb, 1222 NULL); | 1330 error = dmu_objset_create(name, DMU_OST_OTHER, NULL, 0, 1331 ztest_create_cb, NULL); |
1223 if (error) { 1224 if (error == ENOSPC) { 1225 ztest_record_enospc("dmu_objset_create"); 1226 (void) rw_unlock(&ztest_shared->zs_name_lock); 1227 return; 1228 } 1229 fatal(0, "dmu_objset_create(%s) = %d", name, error); 1230 } --- 38 unchanged lines hidden (view full) --- 1269 zil_resume(zilog); 1270 } 1271 } 1272 } 1273 1274 /* 1275 * Verify that we cannot create an existing dataset. 1276 */ | 1332 if (error) { 1333 if (error == ENOSPC) { 1334 ztest_record_enospc("dmu_objset_create"); 1335 (void) rw_unlock(&ztest_shared->zs_name_lock); 1336 return; 1337 } 1338 fatal(0, "dmu_objset_create(%s) = %d", name, error); 1339 } --- 38 unchanged lines hidden (view full) --- 1378 zil_resume(zilog); 1379 } 1380 } 1381 } 1382 1383 /* 1384 * Verify that we cannot create an existing dataset. 1385 */ |
1277 error = dmu_objset_create(name, DMU_OST_OTHER, NULL, NULL, NULL); | 1386 error = dmu_objset_create(name, DMU_OST_OTHER, NULL, 0, NULL, NULL); |
1278 if (error != EEXIST) 1279 fatal(0, "created existing dataset, error = %d", error); 1280 1281 /* | 1387 if (error != EEXIST) 1388 fatal(0, "created existing dataset, error = %d", error); 1389 1390 /* |
1282 * Verify that multiple dataset opens are allowed, but only when | 1391 * Verify that multiple dataset holds are allowed, but only when |
1283 * the new access mode is compatible with the base mode. | 1392 * the new access mode is compatible with the base mode. |
1284 * We use a mixture of typed and typeless opens, and when the 1285 * open succeeds, verify that the discovered type is correct. | |
1286 */ | 1393 */ |
1287 for (mode = DS_MODE_STANDARD; mode < DS_MODE_LEVELS; mode++) { 1288 objset_t *os2; 1289 error = dmu_objset_open(name, DMU_OST_OTHER, mode, &os2); 1290 expected_error = (basemode + mode < DS_MODE_LEVELS) ? 0 : EBUSY; 1291 if (error != expected_error) 1292 fatal(0, "dmu_objset_open('%s') = %d, expected %d", 1293 name, error, expected_error); 1294 if (error == 0) | 1394 if (basemode == DS_MODE_OWNER) { 1395 error = dmu_objset_open(name, DMU_OST_OTHER, DS_MODE_USER, 1396 &os2); 1397 if (error) 1398 fatal(0, "dmu_objset_open('%s') = %d", name, error); 1399 else |
1295 dmu_objset_close(os2); 1296 } | 1400 dmu_objset_close(os2); 1401 } |
1402 error = dmu_objset_open(name, DMU_OST_OTHER, DS_MODE_OWNER, &os2); 1403 expected_error = (basemode == DS_MODE_OWNER) ? EBUSY : 0; 1404 if (error != expected_error) 1405 fatal(0, "dmu_objset_open('%s') = %d, expected %d", 1406 name, error, expected_error); 1407 if (error == 0) 1408 dmu_objset_close(os2); |
|
1297 1298 zil_close(zilog); 1299 dmu_objset_close(os); 1300 1301 error = dmu_objset_destroy(name); 1302 if (error) 1303 fatal(0, "dmu_objset_destroy(%s) = %d", name, error); 1304 --- 107 unchanged lines hidden (view full) --- 1412} 1413 1414/* 1415 * Verify that live pool traversal works. 1416 */ 1417void 1418ztest_traverse(ztest_args_t *za) 1419{ | 1409 1410 zil_close(zilog); 1411 dmu_objset_close(os); 1412 1413 error = dmu_objset_destroy(name); 1414 if (error) 1415 fatal(0, "dmu_objset_destroy(%s) = %d", name, error); 1416 --- 107 unchanged lines hidden (view full) --- 1524} 1525 1526/* 1527 * Verify that live pool traversal works. 1528 */ 1529void 1530ztest_traverse(ztest_args_t *za) 1531{ |
1420 spa_t *spa = dmu_objset_spa(za->za_os); | 1532 spa_t *spa = za->za_spa; |
1421 traverse_handle_t *th = za->za_th; 1422 int rc, advance; 1423 uint64_t cbstart, cblimit; 1424 1425 if (th == NULL) { 1426 advance = 0; 1427 1428 if (ztest_random(2) == 0) --- 55 unchanged lines hidden (view full) --- 1484void 1485ztest_dmu_object_alloc_free(ztest_args_t *za) 1486{ 1487 objset_t *os = za->za_os; 1488 dmu_buf_t *db; 1489 dmu_tx_t *tx; 1490 uint64_t batchobj, object, batchsize, endoff, temp; 1491 int b, c, error, bonuslen; | 1533 traverse_handle_t *th = za->za_th; 1534 int rc, advance; 1535 uint64_t cbstart, cblimit; 1536 1537 if (th == NULL) { 1538 advance = 0; 1539 1540 if (ztest_random(2) == 0) --- 55 unchanged lines hidden (view full) --- 1596void 1597ztest_dmu_object_alloc_free(ztest_args_t *za) 1598{ 1599 objset_t *os = za->za_os; 1600 dmu_buf_t *db; 1601 dmu_tx_t *tx; 1602 uint64_t batchobj, object, batchsize, endoff, temp; 1603 int b, c, error, bonuslen; |
1492 dmu_object_info_t doi; | 1604 dmu_object_info_t *doi = &za->za_doi; |
1493 char osname[MAXNAMELEN]; 1494 1495 dmu_objset_name(os, osname); 1496 1497 endoff = -8ULL; 1498 batchsize = 2; 1499 1500 /* 1501 * Create a batch object if necessary, and record it in the directory. 1502 */ | 1605 char osname[MAXNAMELEN]; 1606 1607 dmu_objset_name(os, osname); 1608 1609 endoff = -8ULL; 1610 batchsize = 2; 1611 1612 /* 1613 * Create a batch object if necessary, and record it in the directory. 1614 */ |
1503 VERIFY(0 == dmu_read(os, ZTEST_DIROBJ, za->za_diroff, | 1615 VERIFY3U(0, ==, dmu_read(os, ZTEST_DIROBJ, za->za_diroff, |
1504 sizeof (uint64_t), &batchobj)); 1505 if (batchobj == 0) { 1506 tx = dmu_tx_create(os); 1507 dmu_tx_hold_write(tx, ZTEST_DIROBJ, za->za_diroff, 1508 sizeof (uint64_t)); 1509 dmu_tx_hold_bonus(tx, DMU_NEW_OBJECT); 1510 error = dmu_tx_assign(tx, TXG_WAIT); 1511 if (error) { --- 8 unchanged lines hidden (view full) --- 1520 sizeof (uint64_t), &batchobj, tx); 1521 dmu_tx_commit(tx); 1522 } 1523 1524 /* 1525 * Destroy the previous batch of objects. 1526 */ 1527 for (b = 0; b < batchsize; b++) { | 1616 sizeof (uint64_t), &batchobj)); 1617 if (batchobj == 0) { 1618 tx = dmu_tx_create(os); 1619 dmu_tx_hold_write(tx, ZTEST_DIROBJ, za->za_diroff, 1620 sizeof (uint64_t)); 1621 dmu_tx_hold_bonus(tx, DMU_NEW_OBJECT); 1622 error = dmu_tx_assign(tx, TXG_WAIT); 1623 if (error) { --- 8 unchanged lines hidden (view full) --- 1632 sizeof (uint64_t), &batchobj, tx); 1633 dmu_tx_commit(tx); 1634 } 1635 1636 /* 1637 * Destroy the previous batch of objects. 1638 */ 1639 for (b = 0; b < batchsize; b++) { |
1528 VERIFY(0 == dmu_read(os, batchobj, b * sizeof (uint64_t), | 1640 VERIFY3U(0, ==, dmu_read(os, batchobj, b * sizeof (uint64_t), |
1529 sizeof (uint64_t), &object)); 1530 if (object == 0) 1531 continue; 1532 /* 1533 * Read and validate contents. 1534 * We expect the nth byte of the bonus buffer to be n. 1535 */ 1536 VERIFY(0 == dmu_bonus_hold(os, object, FTAG, &db)); | 1641 sizeof (uint64_t), &object)); 1642 if (object == 0) 1643 continue; 1644 /* 1645 * Read and validate contents. 1646 * We expect the nth byte of the bonus buffer to be n. 1647 */ 1648 VERIFY(0 == dmu_bonus_hold(os, object, FTAG, &db)); |
1649 za->za_dbuf = db; |
|
1537 | 1650 |
1538 dmu_object_info_from_db(db, &doi); 1539 ASSERT(doi.doi_type == DMU_OT_UINT64_OTHER); 1540 ASSERT(doi.doi_bonus_type == DMU_OT_PLAIN_OTHER); 1541 ASSERT3S(doi.doi_physical_blks, >=, 0); | 1651 dmu_object_info_from_db(db, doi); 1652 ASSERT(doi->doi_type == DMU_OT_UINT64_OTHER); 1653 ASSERT(doi->doi_bonus_type == DMU_OT_PLAIN_OTHER); 1654 ASSERT3S(doi->doi_physical_blks, >=, 0); |
1542 | 1655 |
1543 bonuslen = db->db_size; | 1656 bonuslen = doi->doi_bonus_size; |
1544 1545 for (c = 0; c < bonuslen; c++) { 1546 if (((uint8_t *)db->db_data)[c] != 1547 (uint8_t)(c + bonuslen)) { 1548 fatal(0, 1549 "bad bonus: %s, obj %llu, off %d: %u != %u", 1550 osname, object, c, 1551 ((uint8_t *)db->db_data)[c], 1552 (uint8_t)(c + bonuslen)); 1553 } 1554 } 1555 1556 dmu_buf_rele(db, FTAG); | 1657 1658 for (c = 0; c < bonuslen; c++) { 1659 if (((uint8_t *)db->db_data)[c] != 1660 (uint8_t)(c + bonuslen)) { 1661 fatal(0, 1662 "bad bonus: %s, obj %llu, off %d: %u != %u", 1663 osname, object, c, 1664 ((uint8_t *)db->db_data)[c], 1665 (uint8_t)(c + bonuslen)); 1666 } 1667 } 1668 1669 dmu_buf_rele(db, FTAG); |
1670 za->za_dbuf = NULL; |
|
1557 1558 /* 1559 * We expect the word at endoff to be our object number. 1560 */ 1561 VERIFY(0 == dmu_read(os, object, endoff, 1562 sizeof (uint64_t), &temp)); 1563 1564 if (temp != object) { --- 88 unchanged lines hidden (view full) --- 1653 ztest_random_compress(), tx); 1654 1655 dmu_write(os, batchobj, b * sizeof (uint64_t), 1656 sizeof (uint64_t), &object, tx); 1657 1658 /* 1659 * Write to both the bonus buffer and the regular data. 1660 */ | 1671 1672 /* 1673 * We expect the word at endoff to be our object number. 1674 */ 1675 VERIFY(0 == dmu_read(os, object, endoff, 1676 sizeof (uint64_t), &temp)); 1677 1678 if (temp != object) { --- 88 unchanged lines hidden (view full) --- 1767 ztest_random_compress(), tx); 1768 1769 dmu_write(os, batchobj, b * sizeof (uint64_t), 1770 sizeof (uint64_t), &object, tx); 1771 1772 /* 1773 * Write to both the bonus buffer and the regular data. 1774 */ |
1661 VERIFY(0 == dmu_bonus_hold(os, object, FTAG, &db)); 1662 ASSERT3U(bonuslen, ==, db->db_size); | 1775 VERIFY(dmu_bonus_hold(os, object, FTAG, &db) == 0); 1776 za->za_dbuf = db; 1777 ASSERT3U(bonuslen, <=, db->db_size); |
1663 1664 dmu_object_size_from_db(db, &va_blksize, &va_nblocks); 1665 ASSERT3S(va_nblocks, >=, 0); 1666 1667 dmu_buf_will_dirty(db, tx); 1668 1669 /* 1670 * See comments above regarding the contents of 1671 * the bonus buffer and the word at endoff. 1672 */ | 1778 1779 dmu_object_size_from_db(db, &va_blksize, &va_nblocks); 1780 ASSERT3S(va_nblocks, >=, 0); 1781 1782 dmu_buf_will_dirty(db, tx); 1783 1784 /* 1785 * See comments above regarding the contents of 1786 * the bonus buffer and the word at endoff. 1787 */ |
1673 for (c = 0; c < db->db_size; c++) | 1788 for (c = 0; c < bonuslen; c++) |
1674 ((uint8_t *)db->db_data)[c] = (uint8_t)(c + bonuslen); 1675 1676 dmu_buf_rele(db, FTAG); | 1789 ((uint8_t *)db->db_data)[c] = (uint8_t)(c + bonuslen); 1790 1791 dmu_buf_rele(db, FTAG); |
1792 za->za_dbuf = NULL; |
|
1677 1678 /* 1679 * Write to a large offset to increase indirection. 1680 */ 1681 dmu_write(os, object, endoff, sizeof (uint64_t), &object, tx); 1682 1683 dmu_tx_commit(tx); 1684 } --- 238 unchanged lines hidden (view full) --- 1923 umem_free(bigcheck, bigsize); 1924 } 1925 1926 umem_free(packbuf, packsize); 1927 umem_free(bigbuf, bigsize); 1928} 1929 1930void | 1793 1794 /* 1795 * Write to a large offset to increase indirection. 1796 */ 1797 dmu_write(os, object, endoff, sizeof (uint64_t), &object, tx); 1798 1799 dmu_tx_commit(tx); 1800 } --- 238 unchanged lines hidden (view full) --- 2039 umem_free(bigcheck, bigsize); 2040 } 2041 2042 umem_free(packbuf, packsize); 2043 umem_free(bigbuf, bigsize); 2044} 2045 2046void |
1931ztest_dmu_check_future_leak(objset_t *os, uint64_t txg) | 2047ztest_dmu_check_future_leak(ztest_args_t *za) |
1932{ | 2048{ |
2049 objset_t *os = za->za_os; |
|
1933 dmu_buf_t *db; | 2050 dmu_buf_t *db; |
1934 ztest_block_tag_t rbt; | 2051 ztest_block_tag_t *bt; 2052 dmu_object_info_t *doi = &za->za_doi; |
1935 | 2053 |
1936 if (zopt_verbose >= 3) { 1937 char osname[MAXNAMELEN]; 1938 dmu_objset_name(os, osname); 1939 (void) printf("checking %s for future leaks in txg %lld...\n", 1940 osname, (u_longlong_t)txg); 1941 } 1942 | |
1943 /* 1944 * Make sure that, if there is a write record in the bonus buffer 1945 * of the ZTEST_DIROBJ, that the txg for this record is <= the 1946 * last synced txg of the pool. 1947 */ | 2054 /* 2055 * Make sure that, if there is a write record in the bonus buffer 2056 * of the ZTEST_DIROBJ, that the txg for this record is <= the 2057 * last synced txg of the pool. 2058 */ |
1948 1949 VERIFY(0 == dmu_bonus_hold(os, ZTEST_DIROBJ, FTAG, &db)); 1950 ASSERT3U(db->db_size, ==, sizeof (rbt)); 1951 bcopy(db->db_data, &rbt, db->db_size); 1952 if (rbt.bt_objset != 0) { 1953 ASSERT3U(rbt.bt_objset, ==, dmu_objset_id(os)); 1954 ASSERT3U(rbt.bt_object, ==, ZTEST_DIROBJ); 1955 ASSERT3U(rbt.bt_offset, ==, -1ULL); 1956 if (rbt.bt_txg > txg) { 1957 fatal(0, 1958 "future leak: got %llx, last synced txg is %llx", 1959 rbt.bt_txg, txg); 1960 } | 2059 VERIFY(dmu_bonus_hold(os, ZTEST_DIROBJ, FTAG, &db) == 0); 2060 za->za_dbuf = db; 2061 VERIFY(dmu_object_info(os, ZTEST_DIROBJ, doi) == 0); 2062 ASSERT3U(doi->doi_bonus_size, >=, sizeof (*bt)); 2063 ASSERT3U(doi->doi_bonus_size, <=, db->db_size); 2064 ASSERT3U(doi->doi_bonus_size % sizeof (*bt), ==, 0); 2065 bt = (void *)((char *)db->db_data + doi->doi_bonus_size - sizeof (*bt)); 2066 if (bt->bt_objset != 0) { 2067 ASSERT3U(bt->bt_objset, ==, dmu_objset_id(os)); 2068 ASSERT3U(bt->bt_object, ==, ZTEST_DIROBJ); 2069 ASSERT3U(bt->bt_offset, ==, -1ULL); 2070 ASSERT3U(bt->bt_txg, <, spa_first_txg(za->za_spa)); |
1961 } 1962 dmu_buf_rele(db, FTAG); | 2071 } 2072 dmu_buf_rele(db, FTAG); |
2073 za->za_dbuf = NULL; |
|
1963} 1964 1965void 1966ztest_dmu_write_parallel(ztest_args_t *za) 1967{ 1968 objset_t *os = za->za_os; | 2074} 2075 2076void 2077ztest_dmu_write_parallel(ztest_args_t *za) 2078{ 2079 objset_t *os = za->za_os; |
1969 dmu_tx_t *tx; | 2080 ztest_block_tag_t *rbt = &za->za_rbt; 2081 ztest_block_tag_t *wbt = &za->za_wbt; 2082 const size_t btsize = sizeof (ztest_block_tag_t); |
1970 dmu_buf_t *db; | 2083 dmu_buf_t *db; |
1971 int i, b, error, do_free, bs; 1972 uint64_t off, txg_how, txg; | 2084 int b, error; 2085 int bs = ZTEST_DIROBJ_BLOCKSIZE; 2086 int do_free = 0; 2087 uint64_t off, txg, txg_how; |
1973 mutex_t *lp; 1974 char osname[MAXNAMELEN]; 1975 char iobuf[SPA_MAXBLOCKSIZE]; | 2088 mutex_t *lp; 2089 char osname[MAXNAMELEN]; 2090 char iobuf[SPA_MAXBLOCKSIZE]; |
1976 ztest_block_tag_t rbt, wbt; | 2091 blkptr_t blk = { 0 }; 2092 uint64_t blkoff; 2093 zbookmark_t zb; 2094 dmu_tx_t *tx = dmu_tx_create(os); |
1977 1978 dmu_objset_name(os, osname); | 2095 2096 dmu_objset_name(os, osname); |
1979 bs = ZTEST_DIROBJ_BLOCKSIZE; | |
1980 1981 /* 1982 * Have multiple threads write to large offsets in ZTEST_DIROBJ 1983 * to verify that having multiple threads writing to the same object 1984 * in parallel doesn't cause any trouble. | 2097 2098 /* 2099 * Have multiple threads write to large offsets in ZTEST_DIROBJ 2100 * to verify that having multiple threads writing to the same object 2101 * in parallel doesn't cause any trouble. |
1985 * Also do parallel writes to the bonus buffer on occasion. | |
1986 */ | 2102 */ |
1987 for (i = 0; i < 50; i++) { | 2103 if (ztest_random(4) == 0) { 2104 /* 2105 * Do the bonus buffer instead of a regular block. 2106 * We need a lock to serialize resize vs. others, 2107 * so we hash on the objset ID. 2108 */ 2109 b = dmu_objset_id(os) % ZTEST_SYNC_LOCKS; 2110 off = -1ULL; 2111 dmu_tx_hold_bonus(tx, ZTEST_DIROBJ); 2112 } else { |
1988 b = ztest_random(ZTEST_SYNC_LOCKS); | 2113 b = ztest_random(ZTEST_SYNC_LOCKS); |
1989 lp = &ztest_shared->zs_sync_lock[b]; | 2114 off = za->za_diroff_shared + (b << SPA_MAXBLOCKSHIFT); 2115 if (ztest_random(4) == 0) { 2116 do_free = 1; 2117 dmu_tx_hold_free(tx, ZTEST_DIROBJ, off, bs); 2118 } else { 2119 dmu_tx_hold_write(tx, ZTEST_DIROBJ, off, bs); 2120 } 2121 } |
1990 | 2122 |
1991 do_free = (ztest_random(4) == 0); | 2123 txg_how = ztest_random(2) == 0 ? TXG_WAIT : TXG_NOWAIT; 2124 error = dmu_tx_assign(tx, txg_how); 2125 if (error) { 2126 if (error == ERESTART) { 2127 ASSERT(txg_how == TXG_NOWAIT); 2128 dmu_tx_wait(tx); 2129 } else { 2130 ztest_record_enospc("dmu write parallel"); 2131 } 2132 dmu_tx_abort(tx); 2133 return; 2134 } 2135 txg = dmu_tx_get_txg(tx); |
1992 | 2136 |
1993 off = za->za_diroff_shared + ((uint64_t)b << SPA_MAXBLOCKSHIFT); | 2137 lp = &ztest_shared->zs_sync_lock[b]; 2138 (void) mutex_lock(lp); |
1994 | 2139 |
1995 if (ztest_random(4) == 0) { 1996 /* 1997 * Do the bonus buffer instead of a regular block. 1998 */ 1999 do_free = 0; 2000 off = -1ULL; 2001 } | 2140 wbt->bt_objset = dmu_objset_id(os); 2141 wbt->bt_object = ZTEST_DIROBJ; 2142 wbt->bt_offset = off; 2143 wbt->bt_txg = txg; 2144 wbt->bt_thread = za->za_instance; 2145 wbt->bt_seq = ztest_shared->zs_seq[b]++; /* protected by lp */ |
2002 | 2146 |
2003 tx = dmu_tx_create(os); | 2147 /* 2148 * Occasionally, write an all-zero block to test the behavior 2149 * of blocks that compress into holes. 2150 */ 2151 if (off != -1ULL && ztest_random(8) == 0) 2152 bzero(wbt, btsize); |
2004 | 2153 |
2005 if (off == -1ULL) 2006 dmu_tx_hold_bonus(tx, ZTEST_DIROBJ); 2007 else if (do_free) 2008 dmu_tx_hold_free(tx, ZTEST_DIROBJ, off, bs); 2009 else 2010 dmu_tx_hold_write(tx, ZTEST_DIROBJ, off, bs); | 2154 if (off == -1ULL) { 2155 dmu_object_info_t *doi = &za->za_doi; 2156 char *dboff; |
2011 | 2157 |
2012 txg_how = ztest_random(2) == 0 ? TXG_WAIT : TXG_NOWAIT; 2013 error = dmu_tx_assign(tx, txg_how); 2014 if (error) { 2015 if (error == ERESTART) { 2016 ASSERT(txg_how == TXG_NOWAIT); 2017 dmu_tx_wait(tx); 2018 dmu_tx_abort(tx); 2019 continue; 2020 } 2021 dmu_tx_abort(tx); 2022 ztest_record_enospc("dmu write parallel"); 2023 return; | 2158 VERIFY(dmu_bonus_hold(os, ZTEST_DIROBJ, FTAG, &db) == 0); 2159 za->za_dbuf = db; 2160 dmu_object_info_from_db(db, doi); 2161 ASSERT3U(doi->doi_bonus_size, <=, db->db_size); 2162 ASSERT3U(doi->doi_bonus_size, >=, btsize); 2163 ASSERT3U(doi->doi_bonus_size % btsize, ==, 0); 2164 dboff = (char *)db->db_data + doi->doi_bonus_size - btsize; 2165 bcopy(dboff, rbt, btsize); 2166 if (rbt->bt_objset != 0) { 2167 ASSERT3U(rbt->bt_objset, ==, wbt->bt_objset); 2168 ASSERT3U(rbt->bt_object, ==, wbt->bt_object); 2169 ASSERT3U(rbt->bt_offset, ==, wbt->bt_offset); 2170 ASSERT3U(rbt->bt_txg, <=, wbt->bt_txg); |
2024 } | 2171 } |
2025 txg = dmu_tx_get_txg(tx); | 2172 if (ztest_random(10) == 0) { 2173 int newsize = (ztest_random(db->db_size / 2174 btsize) + 1) * btsize; |
2026 | 2175 |
2027 if (do_free) { 2028 (void) mutex_lock(lp); 2029 VERIFY(0 == dmu_free_range(os, ZTEST_DIROBJ, off, 2030 bs, tx)); 2031 (void) mutex_unlock(lp); 2032 dmu_tx_commit(tx); 2033 continue; | 2176 ASSERT3U(newsize, >=, btsize); 2177 ASSERT3U(newsize, <=, db->db_size); 2178 VERIFY3U(dmu_set_bonus(db, newsize, tx), ==, 0); 2179 dboff = (char *)db->db_data + newsize - btsize; |
2034 } | 2180 } |
2181 dmu_buf_will_dirty(db, tx); 2182 bcopy(wbt, dboff, btsize); 2183 dmu_buf_rele(db, FTAG); 2184 za->za_dbuf = NULL; 2185 } else if (do_free) { 2186 VERIFY(dmu_free_range(os, ZTEST_DIROBJ, off, bs, tx) == 0); 2187 } else { 2188 dmu_write(os, ZTEST_DIROBJ, off, btsize, wbt, tx); 2189 } |
|
2035 | 2190 |
2036 wbt.bt_objset = dmu_objset_id(os); 2037 wbt.bt_object = ZTEST_DIROBJ; 2038 wbt.bt_offset = off; 2039 wbt.bt_txg = txg; 2040 wbt.bt_thread = za->za_instance; | 2191 (void) mutex_unlock(lp); |
2041 | 2192 |
2042 if (off == -1ULL) { 2043 wbt.bt_seq = 0; 2044 VERIFY(0 == dmu_bonus_hold(os, ZTEST_DIROBJ, 2045 FTAG, &db)); 2046 ASSERT3U(db->db_size, ==, sizeof (wbt)); 2047 bcopy(db->db_data, &rbt, db->db_size); 2048 if (rbt.bt_objset != 0) { 2049 ASSERT3U(rbt.bt_objset, ==, wbt.bt_objset); 2050 ASSERT3U(rbt.bt_object, ==, wbt.bt_object); 2051 ASSERT3U(rbt.bt_offset, ==, wbt.bt_offset); 2052 ASSERT3U(rbt.bt_txg, <=, wbt.bt_txg); 2053 } 2054 dmu_buf_will_dirty(db, tx); 2055 bcopy(&wbt, db->db_data, db->db_size); 2056 dmu_buf_rele(db, FTAG); 2057 dmu_tx_commit(tx); 2058 continue; 2059 } | 2193 if (ztest_random(1000) == 0) 2194 (void) poll(NULL, 0, 1); /* open dn_notxholds window */ |
2060 | 2195 |
2061 (void) mutex_lock(lp); | 2196 dmu_tx_commit(tx); |
2062 | 2197 |
2063 wbt.bt_seq = ztest_shared->zs_seq[b]++; | 2198 if (ztest_random(10000) == 0) 2199 txg_wait_synced(dmu_objset_pool(os), txg); |
2064 | 2200 |
2065 dmu_write(os, ZTEST_DIROBJ, off, sizeof (wbt), &wbt, tx); | 2201 if (off == -1ULL || do_free) 2202 return; |
2066 | 2203 |
2067 (void) mutex_unlock(lp); | 2204 if (ztest_random(2) != 0) 2205 return; |
2068 | 2206 |
2069 if (ztest_random(100) == 0) 2070 (void) poll(NULL, 0, 1); /* open dn_notxholds window */ | 2207 /* 2208 * dmu_sync() the block we just wrote. 2209 */ 2210 (void) mutex_lock(lp); |
2071 | 2211 |
2072 dmu_tx_commit(tx); | 2212 blkoff = P2ALIGN_TYPED(off, bs, uint64_t); 2213 error = dmu_buf_hold(os, ZTEST_DIROBJ, blkoff, FTAG, &db); 2214 za->za_dbuf = db; 2215 if (error) { 2216 dprintf("dmu_buf_hold(%s, %d, %llx) = %d\n", 2217 osname, ZTEST_DIROBJ, blkoff, error); 2218 (void) mutex_unlock(lp); 2219 return; 2220 } 2221 blkoff = off - blkoff; 2222 error = dmu_sync(NULL, db, &blk, txg, NULL, NULL); 2223 dmu_buf_rele(db, FTAG); 2224 za->za_dbuf = NULL; |
2073 | 2225 |
2074 if (ztest_random(1000) == 0) 2075 txg_wait_synced(dmu_objset_pool(os), txg); | 2226 (void) mutex_unlock(lp); |
2076 | 2227 |
2077 if (ztest_random(2) == 0) { 2078 blkptr_t blk = { 0 }; 2079 uint64_t blkoff; 2080 zbookmark_t zb; | 2228 if (error) { 2229 dprintf("dmu_sync(%s, %d, %llx) = %d\n", 2230 osname, ZTEST_DIROBJ, off, error); 2231 return; 2232 } |
2081 | 2233 |
2082 (void) mutex_lock(lp); 2083 blkoff = P2ALIGN_TYPED(off, bs, uint64_t); 2084 error = dmu_buf_hold(os, 2085 ZTEST_DIROBJ, blkoff, FTAG, &db); 2086 if (error) { 2087 dprintf("dmu_buf_hold(%s, %d, %llx) = %d\n", 2088 osname, ZTEST_DIROBJ, blkoff, error); 2089 (void) mutex_unlock(lp); 2090 continue; 2091 } 2092 blkoff = off - blkoff; 2093 error = dmu_sync(NULL, db, &blk, txg, NULL, NULL); 2094 dmu_buf_rele(db, FTAG); 2095 (void) mutex_unlock(lp); 2096 if (error) { 2097 dprintf("dmu_sync(%s, %d, %llx) = %d\n", 2098 osname, ZTEST_DIROBJ, off, error); 2099 continue; 2100 } | 2234 if (blk.blk_birth == 0) /* concurrent free */ 2235 return; |
2101 | 2236 |
2102 if (blk.blk_birth == 0) { /* concurrent free */ 2103 continue; 2104 } 2105 txg_suspend(dmu_objset_pool(os)); | 2237 txg_suspend(dmu_objset_pool(os)); |
2106 | 2238 |
2107 ASSERT(blk.blk_fill == 1); 2108 ASSERT3U(BP_GET_TYPE(&blk), ==, DMU_OT_UINT64_OTHER); 2109 ASSERT3U(BP_GET_LEVEL(&blk), ==, 0); 2110 ASSERT3U(BP_GET_LSIZE(&blk), ==, bs); | 2239 ASSERT(blk.blk_fill == 1); 2240 ASSERT3U(BP_GET_TYPE(&blk), ==, DMU_OT_UINT64_OTHER); 2241 ASSERT3U(BP_GET_LEVEL(&blk), ==, 0); 2242 ASSERT3U(BP_GET_LSIZE(&blk), ==, bs); |
2111 | 2243 |
2112 /* 2113 * Read the block that dmu_sync() returned to 2114 * make sure its contents match what we wrote. 2115 * We do this while still txg_suspend()ed to ensure 2116 * that the block can't be reused before we read it. 2117 */ 2118 zb.zb_objset = dmu_objset_id(os); 2119 zb.zb_object = ZTEST_DIROBJ; 2120 zb.zb_level = 0; 2121 zb.zb_blkid = off / bs; 2122 error = zio_wait(zio_read(NULL, dmu_objset_spa(os), 2123 &blk, iobuf, bs, NULL, NULL, 2124 ZIO_PRIORITY_SYNC_READ, ZIO_FLAG_MUSTSUCCEED, &zb)); 2125 ASSERT(error == 0); | 2244 /* 2245 * Read the block that dmu_sync() returned to make sure its contents 2246 * match what we wrote. We do this while still txg_suspend()ed 2247 * to ensure that the block can't be reused before we read it. 2248 */ 2249 zb.zb_objset = dmu_objset_id(os); 2250 zb.zb_object = ZTEST_DIROBJ; 2251 zb.zb_level = 0; 2252 zb.zb_blkid = off / bs; 2253 error = zio_wait(zio_read(NULL, za->za_spa, &blk, iobuf, bs, 2254 NULL, NULL, ZIO_PRIORITY_SYNC_READ, ZIO_FLAG_MUSTSUCCEED, &zb)); 2255 ASSERT3U(error, ==, 0); |
2126 | 2256 |
2127 txg_resume(dmu_objset_pool(os)); | 2257 txg_resume(dmu_objset_pool(os)); |
2128 | 2258 |
2129 bcopy(&iobuf[blkoff], &rbt, sizeof (rbt)); | 2259 bcopy(&iobuf[blkoff], rbt, btsize); |
2130 | 2260 |
2131 if (rbt.bt_objset == 0) /* concurrent free */ 2132 continue; | 2261 if (rbt->bt_objset == 0) /* concurrent free */ 2262 return; |
2133 | 2263 |
2134 ASSERT3U(rbt.bt_objset, ==, wbt.bt_objset); 2135 ASSERT3U(rbt.bt_object, ==, wbt.bt_object); 2136 ASSERT3U(rbt.bt_offset, ==, wbt.bt_offset); | 2264 if (wbt->bt_objset == 0) /* all-zero overwrite */ 2265 return; |
2137 | 2266 |
2138 /* 2139 * The semantic of dmu_sync() is that we always 2140 * push the most recent version of the data, 2141 * so in the face of concurrent updates we may 2142 * see a newer version of the block. That's OK. 2143 */ 2144 ASSERT3U(rbt.bt_txg, >=, wbt.bt_txg); 2145 if (rbt.bt_thread == wbt.bt_thread) 2146 ASSERT3U(rbt.bt_seq, ==, wbt.bt_seq); 2147 else 2148 ASSERT3U(rbt.bt_seq, >, wbt.bt_seq); 2149 } 2150 } | 2267 ASSERT3U(rbt->bt_objset, ==, wbt->bt_objset); 2268 ASSERT3U(rbt->bt_object, ==, wbt->bt_object); 2269 ASSERT3U(rbt->bt_offset, ==, wbt->bt_offset); 2270 2271 /* 2272 * The semantic of dmu_sync() is that we always push the most recent 2273 * version of the data, so in the face of concurrent updates we may 2274 * see a newer version of the block. That's OK. 2275 */ 2276 ASSERT3U(rbt->bt_txg, >=, wbt->bt_txg); 2277 if (rbt->bt_thread == wbt->bt_thread) 2278 ASSERT3U(rbt->bt_seq, ==, wbt->bt_seq); 2279 else 2280 ASSERT3U(rbt->bt_seq, >, wbt->bt_seq); |
2151} 2152 2153/* 2154 * Verify that zap_{create,destroy,add,remove,update} work as expected. 2155 */ 2156#define ZTEST_ZAP_MIN_INTS 1 2157#define ZTEST_ZAP_MAX_INTS 4 2158#define ZTEST_ZAP_MAX_PROPS 1000 2159 2160void 2161ztest_zap(ztest_args_t *za) 2162{ 2163 objset_t *os = za->za_os; 2164 uint64_t object; 2165 uint64_t txg, last_txg; 2166 uint64_t value[ZTEST_ZAP_MAX_INTS]; 2167 uint64_t zl_ints, zl_intsize, prop; 2168 int i, ints; | 2281} 2282 2283/* 2284 * Verify that zap_{create,destroy,add,remove,update} work as expected. 2285 */ 2286#define ZTEST_ZAP_MIN_INTS 1 2287#define ZTEST_ZAP_MAX_INTS 4 2288#define ZTEST_ZAP_MAX_PROPS 1000 2289 2290void 2291ztest_zap(ztest_args_t *za) 2292{ 2293 objset_t *os = za->za_os; 2294 uint64_t object; 2295 uint64_t txg, last_txg; 2296 uint64_t value[ZTEST_ZAP_MAX_INTS]; 2297 uint64_t zl_ints, zl_intsize, prop; 2298 int i, ints; |
2169 int iters = 100; | |
2170 dmu_tx_t *tx; 2171 char propname[100], txgname[100]; 2172 int error; 2173 char osname[MAXNAMELEN]; 2174 char *hc[2] = { "s.acl.h", ".s.open.h.hyLZlg" }; 2175 2176 dmu_objset_name(os, osname); 2177 --- 47 unchanged lines hidden (view full) --- 2225 ASSERT3U(error, ==, 0); 2226 } 2227 2228 dmu_tx_commit(tx); 2229 } 2230 2231 ints = MAX(ZTEST_ZAP_MIN_INTS, object % ZTEST_ZAP_MAX_INTS); 2232 | 2299 dmu_tx_t *tx; 2300 char propname[100], txgname[100]; 2301 int error; 2302 char osname[MAXNAMELEN]; 2303 char *hc[2] = { "s.acl.h", ".s.open.h.hyLZlg" }; 2304 2305 dmu_objset_name(os, osname); 2306 --- 47 unchanged lines hidden (view full) --- 2354 ASSERT3U(error, ==, 0); 2355 } 2356 2357 dmu_tx_commit(tx); 2358 } 2359 2360 ints = MAX(ZTEST_ZAP_MIN_INTS, object % ZTEST_ZAP_MAX_INTS); 2361 |
2233 while (--iters >= 0) { 2234 prop = ztest_random(ZTEST_ZAP_MAX_PROPS); 2235 (void) sprintf(propname, "prop_%llu", (u_longlong_t)prop); 2236 (void) sprintf(txgname, "txg_%llu", (u_longlong_t)prop); 2237 bzero(value, sizeof (value)); 2238 last_txg = 0; | 2362 prop = ztest_random(ZTEST_ZAP_MAX_PROPS); 2363 (void) sprintf(propname, "prop_%llu", (u_longlong_t)prop); 2364 (void) sprintf(txgname, "txg_%llu", (u_longlong_t)prop); 2365 bzero(value, sizeof (value)); 2366 last_txg = 0; |
2239 | 2367 |
2240 /* 2241 * If these zap entries already exist, validate their contents. 2242 */ 2243 error = zap_length(os, object, txgname, &zl_intsize, &zl_ints); 2244 if (error == 0) { 2245 ASSERT3U(zl_intsize, ==, sizeof (uint64_t)); 2246 ASSERT3U(zl_ints, ==, 1); | 2368 /* 2369 * If these zap entries already exist, validate their contents. 2370 */ 2371 error = zap_length(os, object, txgname, &zl_intsize, &zl_ints); 2372 if (error == 0) { 2373 ASSERT3U(zl_intsize, ==, sizeof (uint64_t)); 2374 ASSERT3U(zl_ints, ==, 1); |
2247 | 2375 |
2248 error = zap_lookup(os, object, txgname, zl_intsize, 2249 zl_ints, &last_txg); | 2376 VERIFY(zap_lookup(os, object, txgname, zl_intsize, 2377 zl_ints, &last_txg) == 0); |
2250 | 2378 |
2251 ASSERT3U(error, ==, 0); | 2379 VERIFY(zap_length(os, object, propname, &zl_intsize, 2380 &zl_ints) == 0); |
2252 | 2381 |
2253 error = zap_length(os, object, propname, &zl_intsize, 2254 &zl_ints); | 2382 ASSERT3U(zl_intsize, ==, sizeof (uint64_t)); 2383 ASSERT3U(zl_ints, ==, ints); |
2255 | 2384 |
2256 ASSERT3U(error, ==, 0); 2257 ASSERT3U(zl_intsize, ==, sizeof (uint64_t)); 2258 ASSERT3U(zl_ints, ==, ints); | 2385 VERIFY(zap_lookup(os, object, propname, zl_intsize, 2386 zl_ints, value) == 0); |
2259 | 2387 |
2260 error = zap_lookup(os, object, propname, zl_intsize, 2261 zl_ints, value); 2262 2263 ASSERT3U(error, ==, 0); 2264 2265 for (i = 0; i < ints; i++) { 2266 ASSERT3U(value[i], ==, last_txg + object + i); 2267 } 2268 } else { 2269 ASSERT3U(error, ==, ENOENT); | 2388 for (i = 0; i < ints; i++) { 2389 ASSERT3U(value[i], ==, last_txg + object + i); |
2270 } | 2390 } |
2391 } else { 2392 ASSERT3U(error, ==, ENOENT); 2393 } |
|
2271 | 2394 |
2272 /* 2273 * Atomically update two entries in our zap object. 2274 * The first is named txg_%llu, and contains the txg 2275 * in which the property was last updated. The second 2276 * is named prop_%llu, and the nth element of its value 2277 * should be txg + object + n. 2278 */ 2279 tx = dmu_tx_create(os); 2280 dmu_tx_hold_zap(tx, object, TRUE, NULL); 2281 error = dmu_tx_assign(tx, TXG_WAIT); 2282 if (error) { 2283 ztest_record_enospc("create zap entry"); 2284 dmu_tx_abort(tx); 2285 return; 2286 } 2287 txg = dmu_tx_get_txg(tx); | 2395 /* 2396 * Atomically update two entries in our zap object. 2397 * The first is named txg_%llu, and contains the txg 2398 * in which the property was last updated. The second 2399 * is named prop_%llu, and the nth element of its value 2400 * should be txg + object + n. 2401 */ 2402 tx = dmu_tx_create(os); 2403 dmu_tx_hold_zap(tx, object, TRUE, NULL); 2404 error = dmu_tx_assign(tx, TXG_WAIT); 2405 if (error) { 2406 ztest_record_enospc("create zap entry"); 2407 dmu_tx_abort(tx); 2408 return; 2409 } 2410 txg = dmu_tx_get_txg(tx); |
2288 | 2411 |
2289 if (last_txg > txg) 2290 fatal(0, "zap future leak: old %llu new %llu", 2291 last_txg, txg); | 2412 if (last_txg > txg) 2413 fatal(0, "zap future leak: old %llu new %llu", last_txg, txg); |
2292 | 2414 |
2293 for (i = 0; i < ints; i++) 2294 value[i] = txg + object + i; | 2415 for (i = 0; i < ints; i++) 2416 value[i] = txg + object + i; |
2295 | 2417 |
2296 error = zap_update(os, object, txgname, sizeof (uint64_t), 2297 1, &txg, tx); 2298 if (error) 2299 fatal(0, "zap_update('%s', %llu, '%s') = %d", 2300 osname, object, txgname, error); | 2418 error = zap_update(os, object, txgname, sizeof (uint64_t), 1, &txg, tx); 2419 if (error) 2420 fatal(0, "zap_update('%s', %llu, '%s') = %d", 2421 osname, object, txgname, error); |
2301 | 2422 |
2302 error = zap_update(os, object, propname, sizeof (uint64_t), 2303 ints, value, tx); 2304 if (error) 2305 fatal(0, "zap_update('%s', %llu, '%s') = %d", 2306 osname, object, propname, error); | 2423 error = zap_update(os, object, propname, sizeof (uint64_t), 2424 ints, value, tx); 2425 if (error) 2426 fatal(0, "zap_update('%s', %llu, '%s') = %d", 2427 osname, object, propname, error); |
2307 | 2428 |
2308 dmu_tx_commit(tx); | 2429 dmu_tx_commit(tx); |
2309 | 2430 |
2310 /* 2311 * Remove a random pair of entries. 2312 */ 2313 prop = ztest_random(ZTEST_ZAP_MAX_PROPS); 2314 (void) sprintf(propname, "prop_%llu", (u_longlong_t)prop); 2315 (void) sprintf(txgname, "txg_%llu", (u_longlong_t)prop); | 2431 /* 2432 * Remove a random pair of entries. 2433 */ 2434 prop = ztest_random(ZTEST_ZAP_MAX_PROPS); 2435 (void) sprintf(propname, "prop_%llu", (u_longlong_t)prop); 2436 (void) sprintf(txgname, "txg_%llu", (u_longlong_t)prop); |
2316 | 2437 |
2317 error = zap_length(os, object, txgname, &zl_intsize, &zl_ints); | 2438 error = zap_length(os, object, txgname, &zl_intsize, &zl_ints); |
2318 | 2439 |
2319 if (error == ENOENT) 2320 continue; | 2440 if (error == ENOENT) 2441 return; |
2321 | 2442 |
2322 ASSERT3U(error, ==, 0); | 2443 ASSERT3U(error, ==, 0); |
2323 | 2444 |
2324 tx = dmu_tx_create(os); 2325 dmu_tx_hold_zap(tx, object, TRUE, NULL); 2326 error = dmu_tx_assign(tx, TXG_WAIT); 2327 if (error) { 2328 ztest_record_enospc("remove zap entry"); 2329 dmu_tx_abort(tx); 2330 return; 2331 } 2332 error = zap_remove(os, object, txgname, tx); 2333 if (error) 2334 fatal(0, "zap_remove('%s', %llu, '%s') = %d", 2335 osname, object, txgname, error); | 2445 tx = dmu_tx_create(os); 2446 dmu_tx_hold_zap(tx, object, TRUE, NULL); 2447 error = dmu_tx_assign(tx, TXG_WAIT); 2448 if (error) { 2449 ztest_record_enospc("remove zap entry"); 2450 dmu_tx_abort(tx); 2451 return; 2452 } 2453 error = zap_remove(os, object, txgname, tx); 2454 if (error) 2455 fatal(0, "zap_remove('%s', %llu, '%s') = %d", 2456 osname, object, txgname, error); |
2336 | 2457 |
2337 error = zap_remove(os, object, propname, tx); 2338 if (error) 2339 fatal(0, "zap_remove('%s', %llu, '%s') = %d", 2340 osname, object, propname, error); | 2458 error = zap_remove(os, object, propname, tx); 2459 if (error) 2460 fatal(0, "zap_remove('%s', %llu, '%s') = %d", 2461 osname, object, propname, error); |
2341 | 2462 |
2342 dmu_tx_commit(tx); 2343 } | 2463 dmu_tx_commit(tx); |
2344 2345 /* 2346 * Once in a while, destroy the object. 2347 */ | 2464 2465 /* 2466 * Once in a while, destroy the object. 2467 */ |
2348 if (ztest_random(100) != 0) | 2468 if (ztest_random(1000) != 0) |
2349 return; 2350 2351 tx = dmu_tx_create(os); 2352 dmu_tx_hold_write(tx, ZTEST_DIROBJ, za->za_diroff, sizeof (uint64_t)); 2353 dmu_tx_hold_free(tx, object, 0, DMU_OBJECT_END); 2354 error = dmu_tx_assign(tx, TXG_WAIT); 2355 if (error) { 2356 ztest_record_enospc("destroy zap object"); --- 10 unchanged lines hidden (view full) --- 2367 dmu_tx_commit(tx); 2368} 2369 2370void 2371ztest_zap_parallel(ztest_args_t *za) 2372{ 2373 objset_t *os = za->za_os; 2374 uint64_t txg, object, count, wsize, wc, zl_wsize, zl_wc; | 2469 return; 2470 2471 tx = dmu_tx_create(os); 2472 dmu_tx_hold_write(tx, ZTEST_DIROBJ, za->za_diroff, sizeof (uint64_t)); 2473 dmu_tx_hold_free(tx, object, 0, DMU_OBJECT_END); 2474 error = dmu_tx_assign(tx, TXG_WAIT); 2475 if (error) { 2476 ztest_record_enospc("destroy zap object"); --- 10 unchanged lines hidden (view full) --- 2487 dmu_tx_commit(tx); 2488} 2489 2490void 2491ztest_zap_parallel(ztest_args_t *za) 2492{ 2493 objset_t *os = za->za_os; 2494 uint64_t txg, object, count, wsize, wc, zl_wsize, zl_wc; |
2375 int iters = 100; | |
2376 dmu_tx_t *tx; 2377 int i, namelen, error; 2378 char name[20], string_value[20]; 2379 void *data; 2380 | 2495 dmu_tx_t *tx; 2496 int i, namelen, error; 2497 char name[20], string_value[20]; 2498 void *data; 2499 |
2381 while (--iters >= 0) { 2382 /* 2383 * Generate a random name of the form 'xxx.....' where each 2384 * x is a random printable character and the dots are dots. 2385 * There are 94 such characters, and the name length goes from 2386 * 6 to 20, so there are 94^3 * 15 = 12,458,760 possible names. 2387 */ 2388 namelen = ztest_random(sizeof (name) - 5) + 5 + 1; | 2500 /* 2501 * Generate a random name of the form 'xxx.....' where each 2502 * x is a random printable character and the dots are dots. 2503 * There are 94 such characters, and the name length goes from 2504 * 6 to 20, so there are 94^3 * 15 = 12,458,760 possible names. 2505 */ 2506 namelen = ztest_random(sizeof (name) - 5) + 5 + 1; |
2389 | 2507 |
2390 for (i = 0; i < 3; i++) 2391 name[i] = '!' + ztest_random('~' - '!' + 1); 2392 for (; i < namelen - 1; i++) 2393 name[i] = '.'; 2394 name[i] = '\0'; | 2508 for (i = 0; i < 3; i++) 2509 name[i] = '!' + ztest_random('~' - '!' + 1); 2510 for (; i < namelen - 1; i++) 2511 name[i] = '.'; 2512 name[i] = '\0'; |
2395 | 2513 |
2396 if (ztest_random(2) == 0) 2397 object = ZTEST_MICROZAP_OBJ; 2398 else 2399 object = ZTEST_FATZAP_OBJ; | 2514 if (ztest_random(2) == 0) 2515 object = ZTEST_MICROZAP_OBJ; 2516 else 2517 object = ZTEST_FATZAP_OBJ; |
2400 | 2518 |
2401 if ((namelen & 1) || object == ZTEST_MICROZAP_OBJ) { 2402 wsize = sizeof (txg); 2403 wc = 1; 2404 data = &txg; 2405 } else { 2406 wsize = 1; 2407 wc = namelen; 2408 data = string_value; 2409 } | 2519 if ((namelen & 1) || object == ZTEST_MICROZAP_OBJ) { 2520 wsize = sizeof (txg); 2521 wc = 1; 2522 data = &txg; 2523 } else { 2524 wsize = 1; 2525 wc = namelen; 2526 data = string_value; 2527 } |
2410 | 2528 |
2411 count = -1ULL; 2412 VERIFY(zap_count(os, object, &count) == 0); 2413 ASSERT(count != -1ULL); | 2529 count = -1ULL; 2530 VERIFY(zap_count(os, object, &count) == 0); 2531 ASSERT(count != -1ULL); |
2414 | 2532 |
2415 /* 2416 * Select an operation: length, lookup, add, update, remove. 2417 */ 2418 i = ztest_random(5); | 2533 /* 2534 * Select an operation: length, lookup, add, update, remove. 2535 */ 2536 i = ztest_random(5); |
2419 | 2537 |
2420 if (i >= 2) { 2421 tx = dmu_tx_create(os); 2422 dmu_tx_hold_zap(tx, object, TRUE, NULL); 2423 error = dmu_tx_assign(tx, TXG_WAIT); 2424 if (error) { 2425 ztest_record_enospc("zap parallel"); 2426 dmu_tx_abort(tx); 2427 return; 2428 } 2429 txg = dmu_tx_get_txg(tx); 2430 bcopy(name, string_value, namelen); 2431 } else { 2432 tx = NULL; 2433 txg = 0; 2434 bzero(string_value, namelen); | 2538 if (i >= 2) { 2539 tx = dmu_tx_create(os); 2540 dmu_tx_hold_zap(tx, object, TRUE, NULL); 2541 error = dmu_tx_assign(tx, TXG_WAIT); 2542 if (error) { 2543 ztest_record_enospc("zap parallel"); 2544 dmu_tx_abort(tx); 2545 return; |
2435 } | 2546 } |
2547 txg = dmu_tx_get_txg(tx); 2548 bcopy(name, string_value, namelen); 2549 } else { 2550 tx = NULL; 2551 txg = 0; 2552 bzero(string_value, namelen); 2553 } |
|
2436 | 2554 |
2437 switch (i) { | 2555 switch (i) { |
2438 | 2556 |
2439 case 0: 2440 error = zap_length(os, object, name, &zl_wsize, &zl_wc); 2441 if (error == 0) { 2442 ASSERT3U(wsize, ==, zl_wsize); 2443 ASSERT3U(wc, ==, zl_wc); 2444 } else { 2445 ASSERT3U(error, ==, ENOENT); 2446 } 2447 break; | 2557 case 0: 2558 error = zap_length(os, object, name, &zl_wsize, &zl_wc); 2559 if (error == 0) { 2560 ASSERT3U(wsize, ==, zl_wsize); 2561 ASSERT3U(wc, ==, zl_wc); 2562 } else { 2563 ASSERT3U(error, ==, ENOENT); 2564 } 2565 break; |
2448 | 2566 |
2449 case 1: 2450 error = zap_lookup(os, object, name, wsize, wc, data); 2451 if (error == 0) { 2452 if (data == string_value && 2453 bcmp(name, data, namelen) != 0) 2454 fatal(0, "name '%s' != val '%s' len %d", 2455 name, data, namelen); 2456 } else { 2457 ASSERT3U(error, ==, ENOENT); 2458 } 2459 break; | 2567 case 1: 2568 error = zap_lookup(os, object, name, wsize, wc, data); 2569 if (error == 0) { 2570 if (data == string_value && 2571 bcmp(name, data, namelen) != 0) 2572 fatal(0, "name '%s' != val '%s' len %d", 2573 name, data, namelen); 2574 } else { 2575 ASSERT3U(error, ==, ENOENT); 2576 } 2577 break; |
2460 | 2578 |
2461 case 2: 2462 error = zap_add(os, object, name, wsize, wc, data, tx); 2463 ASSERT(error == 0 || error == EEXIST); 2464 break; | 2579 case 2: 2580 error = zap_add(os, object, name, wsize, wc, data, tx); 2581 ASSERT(error == 0 || error == EEXIST); 2582 break; |
2465 | 2583 |
2466 case 3: 2467 VERIFY(zap_update(os, object, name, wsize, wc, 2468 data, tx) == 0); 2469 break; | 2584 case 3: 2585 VERIFY(zap_update(os, object, name, wsize, wc, data, tx) == 0); 2586 break; |
2470 | 2587 |
2471 case 4: 2472 error = zap_remove(os, object, name, tx); 2473 ASSERT(error == 0 || error == ENOENT); 2474 break; 2475 } 2476 2477 if (tx != NULL) 2478 dmu_tx_commit(tx); | 2588 case 4: 2589 error = zap_remove(os, object, name, tx); 2590 ASSERT(error == 0 || error == ENOENT); 2591 break; |
2479 } | 2592 } |
2593 2594 if (tx != NULL) 2595 dmu_tx_commit(tx); |
|
2480} 2481 2482void 2483ztest_dsl_prop_get_set(ztest_args_t *za) 2484{ 2485 objset_t *os = za->za_os; 2486 int i, inherit; 2487 uint64_t value; --- 39 unchanged lines hidden (view full) --- 2527 (void) printf("%s %s = %s for '%s'\n", 2528 osname, prop, valname, setpoint); 2529 } 2530 } 2531 2532 (void) rw_unlock(&ztest_shared->zs_name_lock); 2533} 2534 | 2596} 2597 2598void 2599ztest_dsl_prop_get_set(ztest_args_t *za) 2600{ 2601 objset_t *os = za->za_os; 2602 int i, inherit; 2603 uint64_t value; --- 39 unchanged lines hidden (view full) --- 2643 (void) printf("%s %s = %s for '%s'\n", 2644 osname, prop, valname, setpoint); 2645 } 2646 } 2647 2648 (void) rw_unlock(&ztest_shared->zs_name_lock); 2649} 2650 |
2535static void 2536ztest_error_setup(vdev_t *vd, int mode, int mask, uint64_t arg) 2537{ 2538 int c; 2539 2540 for (c = 0; c < vd->vdev_children; c++) 2541 ztest_error_setup(vd->vdev_child[c], mode, mask, arg); 2542 2543 if (vd->vdev_path != NULL) { 2544 vd->vdev_fault_mode = mode; 2545 vd->vdev_fault_mask = mask; 2546 vd->vdev_fault_arg = arg; 2547 } 2548} 2549 | |
2550/* 2551 * Inject random faults into the on-disk data. 2552 */ 2553void 2554ztest_fault_inject(ztest_args_t *za) 2555{ 2556 int fd; 2557 uint64_t offset; 2558 uint64_t leaves = MAX(zopt_mirrors, 1) * zopt_raidz; 2559 uint64_t bad = 0x1990c0ffeedecadeULL; 2560 uint64_t top, leaf; 2561 char path0[MAXPATHLEN]; 2562 char pathrand[MAXPATHLEN]; 2563 size_t fsize; | 2651/* 2652 * Inject random faults into the on-disk data. 2653 */ 2654void 2655ztest_fault_inject(ztest_args_t *za) 2656{ 2657 int fd; 2658 uint64_t offset; 2659 uint64_t leaves = MAX(zopt_mirrors, 1) * zopt_raidz; 2660 uint64_t bad = 0x1990c0ffeedecadeULL; 2661 uint64_t top, leaf; 2662 char path0[MAXPATHLEN]; 2663 char pathrand[MAXPATHLEN]; 2664 size_t fsize; |
2564 spa_t *spa = dmu_objset_spa(za->za_os); | 2665 spa_t *spa = za->za_spa; |
2565 int bshift = SPA_MAXBLOCKSHIFT + 2; /* don't scrog all labels */ 2566 int iters = 1000; | 2666 int bshift = SPA_MAXBLOCKSHIFT + 2; /* don't scrog all labels */ 2667 int iters = 1000; |
2567 vdev_t *vd0; | 2668 int maxfaults = zopt_maxfaults; 2669 vdev_t *vd0 = NULL; |
2568 uint64_t guid0 = 0; 2569 | 2670 uint64_t guid0 = 0; 2671 |
2570 /* 2571 * We can't inject faults when we have no fault tolerance. 2572 */ 2573 if (zopt_maxfaults == 0) 2574 return; | 2672 ASSERT(leaves >= 1); |
2575 | 2673 |
2576 ASSERT(leaves >= 2); 2577 | |
2578 /* | 2674 /* |
2579 * Pick a random top-level vdev. | 2675 * We need SCL_STATE here because we're going to look at vd0->vdev_tsd. |
2580 */ | 2676 */ |
2581 spa_config_enter(spa, RW_READER, FTAG); 2582 top = ztest_random(spa->spa_root_vdev->vdev_children); 2583 spa_config_exit(spa, FTAG); | 2677 spa_config_enter(spa, SCL_STATE, FTAG, RW_READER); |
2584 | 2678 |
2585 /* 2586 * Pick a random leaf. 2587 */ 2588 leaf = ztest_random(leaves); | 2679 if (ztest_random(2) == 0) { 2680 /* 2681 * Inject errors on a normal data device. 2682 */ 2683 top = ztest_random(spa->spa_root_vdev->vdev_children); 2684 leaf = ztest_random(leaves); |
2589 | 2685 |
2590 /* 2591 * Generate paths to the first two leaves in this top-level vdev, 2592 * and to the random leaf we selected. We'll induce transient 2593 * I/O errors and random online/offline activity on leaf 0, 2594 * and we'll write random garbage to the randomly chosen leaf. 2595 */ 2596 (void) snprintf(path0, sizeof (path0), 2597 ztest_dev_template, zopt_dir, zopt_pool, top * leaves + 0); 2598 (void) snprintf(pathrand, sizeof (pathrand), 2599 ztest_dev_template, zopt_dir, zopt_pool, top * leaves + leaf); | 2686 /* 2687 * Generate paths to the first leaf in this top-level vdev, 2688 * and to the random leaf we selected. We'll induce transient 2689 * write failures and random online/offline activity on leaf 0, 2690 * and we'll write random garbage to the randomly chosen leaf. 2691 */ 2692 (void) snprintf(path0, sizeof (path0), ztest_dev_template, 2693 zopt_dir, zopt_pool, top * leaves + 0); 2694 (void) snprintf(pathrand, sizeof (pathrand), ztest_dev_template, 2695 zopt_dir, zopt_pool, top * leaves + leaf); |
2600 | 2696 |
2601 dprintf("damaging %s and %s\n", path0, pathrand); | 2697 vd0 = vdev_lookup_by_path(spa->spa_root_vdev, path0); 2698 if (vd0 != NULL && maxfaults != 1) { 2699 /* 2700 * Make vd0 explicitly claim to be unreadable, 2701 * or unwriteable, or reach behind its back 2702 * and close the underlying fd. We can do this if 2703 * maxfaults == 0 because we'll fail and reexecute, 2704 * and we can do it if maxfaults >= 2 because we'll 2705 * have enough redundancy. If maxfaults == 1, the 2706 * combination of this with injection of random data 2707 * corruption below exceeds the pool's fault tolerance. 2708 */ 2709 vdev_file_t *vf = vd0->vdev_tsd; |
2602 | 2710 |
2603 spa_config_enter(spa, RW_READER, FTAG); | 2711 if (vf != NULL && ztest_random(3) == 0) { 2712 (void) close(vf->vf_vnode->v_fd); 2713 vf->vf_vnode->v_fd = -1; 2714 } else if (ztest_random(2) == 0) { 2715 vd0->vdev_cant_read = B_TRUE; 2716 } else { 2717 vd0->vdev_cant_write = B_TRUE; 2718 } 2719 guid0 = vd0->vdev_guid; 2720 } 2721 } else { 2722 /* 2723 * Inject errors on an l2cache device. 2724 */ 2725 spa_aux_vdev_t *sav = &spa->spa_l2cache; |
2604 | 2726 |
2605 /* 2606 * If we can tolerate two or more faults, make vd0 fail randomly. 2607 */ 2608 vd0 = vdev_lookup_by_path(spa->spa_root_vdev, path0); 2609 if (vd0 != NULL && zopt_maxfaults >= 2) { | 2727 if (sav->sav_count == 0) { 2728 spa_config_exit(spa, SCL_STATE, FTAG); 2729 return; 2730 } 2731 vd0 = sav->sav_vdevs[ztest_random(sav->sav_count)]; |
2610 guid0 = vd0->vdev_guid; | 2732 guid0 = vd0->vdev_guid; |
2611 ztest_error_setup(vd0, VDEV_FAULT_COUNT, 2612 (1U << ZIO_TYPE_READ) | (1U << ZIO_TYPE_WRITE), 100); | 2733 (void) strcpy(path0, vd0->vdev_path); 2734 (void) strcpy(pathrand, vd0->vdev_path); 2735 2736 leaf = 0; 2737 leaves = 1; 2738 maxfaults = INT_MAX; /* no limit on cache devices */ |
2613 } 2614 | 2739 } 2740 |
2615 spa_config_exit(spa, FTAG); | 2741 dprintf("damaging %s and %s\n", path0, pathrand); |
2616 | 2742 |
2743 spa_config_exit(spa, SCL_STATE, FTAG); 2744 2745 if (maxfaults == 0) 2746 return; 2747 |
|
2617 /* 2618 * If we can tolerate two or more faults, randomly online/offline vd0. 2619 */ | 2748 /* 2749 * If we can tolerate two or more faults, randomly online/offline vd0. 2750 */ |
2620 if (zopt_maxfaults >= 2 && guid0 != 0) { | 2751 if (maxfaults >= 2 && guid0 != 0) { |
2621 if (ztest_random(10) < 6) 2622 (void) vdev_offline(spa, guid0, B_TRUE); 2623 else | 2752 if (ztest_random(10) < 6) 2753 (void) vdev_offline(spa, guid0, B_TRUE); 2754 else |
2624 (void) vdev_online(spa, guid0); | 2755 (void) vdev_online(spa, guid0, B_FALSE, NULL); |
2625 } 2626 2627 /* 2628 * We have at least single-fault tolerance, so inject data corruption. 2629 */ 2630 fd = open(pathrand, O_RDWR); 2631 2632 if (fd == -1) /* we hit a gap in the device namespace */ --- 22 unchanged lines hidden (view full) --- 2655} 2656 2657/* 2658 * Scrub the pool. 2659 */ 2660void 2661ztest_scrub(ztest_args_t *za) 2662{ | 2756 } 2757 2758 /* 2759 * We have at least single-fault tolerance, so inject data corruption. 2760 */ 2761 fd = open(pathrand, O_RDWR); 2762 2763 if (fd == -1) /* we hit a gap in the device namespace */ --- 22 unchanged lines hidden (view full) --- 2786} 2787 2788/* 2789 * Scrub the pool. 2790 */ 2791void 2792ztest_scrub(ztest_args_t *za) 2793{ |
2663 spa_t *spa = dmu_objset_spa(za->za_os); | 2794 spa_t *spa = za->za_spa; |
2664 | 2795 |
2665 (void) spa_scrub(spa, POOL_SCRUB_EVERYTHING, B_FALSE); | 2796 (void) spa_scrub(spa, POOL_SCRUB_EVERYTHING); |
2666 (void) poll(NULL, 0, 1000); /* wait a second, then force a restart */ | 2797 (void) poll(NULL, 0, 1000); /* wait a second, then force a restart */ |
2667 (void) spa_scrub(spa, POOL_SCRUB_EVERYTHING, B_FALSE); | 2798 (void) spa_scrub(spa, POOL_SCRUB_EVERYTHING); |
2668} 2669 2670/* 2671 * Rename the pool to a different name and then rename it back. 2672 */ 2673void 2674ztest_spa_rename(ztest_args_t *za) 2675{ --- 25 unchanged lines hidden (view full) --- 2701 2702 /* 2703 * Open it under the new name and make sure it's still the same spa_t. 2704 */ 2705 error = spa_open(newname, &spa, FTAG); 2706 if (error != 0) 2707 fatal(0, "spa_open('%s') = %d", newname, error); 2708 | 2799} 2800 2801/* 2802 * Rename the pool to a different name and then rename it back. 2803 */ 2804void 2805ztest_spa_rename(ztest_args_t *za) 2806{ --- 25 unchanged lines hidden (view full) --- 2832 2833 /* 2834 * Open it under the new name and make sure it's still the same spa_t. 2835 */ 2836 error = spa_open(newname, &spa, FTAG); 2837 if (error != 0) 2838 fatal(0, "spa_open('%s') = %d", newname, error); 2839 |
2709 ASSERT(spa == dmu_objset_spa(za->za_os)); | 2840 ASSERT(spa == za->za_spa); |
2710 spa_close(spa, FTAG); 2711 2712 /* 2713 * Rename it back to the original 2714 */ 2715 error = spa_rename(newname, oldname); 2716 if (error) 2717 fatal(0, "spa_rename('%s', '%s') = %d", newname, 2718 oldname, error); 2719 2720 /* 2721 * Make sure it can still be opened 2722 */ 2723 error = spa_open(oldname, &spa, FTAG); 2724 if (error != 0) 2725 fatal(0, "spa_open('%s') = %d", oldname, error); 2726 | 2841 spa_close(spa, FTAG); 2842 2843 /* 2844 * Rename it back to the original 2845 */ 2846 error = spa_rename(newname, oldname); 2847 if (error) 2848 fatal(0, "spa_rename('%s', '%s') = %d", newname, 2849 oldname, error); 2850 2851 /* 2852 * Make sure it can still be opened 2853 */ 2854 error = spa_open(oldname, &spa, FTAG); 2855 if (error != 0) 2856 fatal(0, "spa_open('%s') = %d", oldname, error); 2857 |
2727 ASSERT(spa == dmu_objset_spa(za->za_os)); | 2858 ASSERT(spa == za->za_spa); |
2728 spa_close(spa, FTAG); 2729 2730 umem_free(newname, strlen(newname) + 1); 2731 2732 (void) rw_unlock(&ztest_shared->zs_name_lock); 2733} 2734 2735 --- 37 unchanged lines hidden (view full) --- 2773 VERIFY(ftruncate(fd, fsize) == 0); 2774 (void) close(fd); 2775} 2776 2777static void 2778ztest_replace_one_disk(spa_t *spa, uint64_t vdev) 2779{ 2780 char dev_name[MAXPATHLEN]; | 2859 spa_close(spa, FTAG); 2860 2861 umem_free(newname, strlen(newname) + 1); 2862 2863 (void) rw_unlock(&ztest_shared->zs_name_lock); 2864} 2865 2866 --- 37 unchanged lines hidden (view full) --- 2904 VERIFY(ftruncate(fd, fsize) == 0); 2905 (void) close(fd); 2906} 2907 2908static void 2909ztest_replace_one_disk(spa_t *spa, uint64_t vdev) 2910{ 2911 char dev_name[MAXPATHLEN]; |
2781 nvlist_t *file, *root; | 2912 nvlist_t *root; |
2782 int error; 2783 uint64_t guid; | 2913 int error; 2914 uint64_t guid; |
2784 uint64_t ashift = ztest_get_ashift(); | |
2785 vdev_t *vd; 2786 2787 (void) sprintf(dev_name, ztest_dev_template, zopt_dir, zopt_pool, vdev); 2788 2789 /* 2790 * Build the nvlist describing dev_name. 2791 */ | 2915 vdev_t *vd; 2916 2917 (void) sprintf(dev_name, ztest_dev_template, zopt_dir, zopt_pool, vdev); 2918 2919 /* 2920 * Build the nvlist describing dev_name. 2921 */ |
2792 VERIFY(nvlist_alloc(&file, NV_UNIQUE_NAME, 0) == 0); 2793 VERIFY(nvlist_add_string(file, ZPOOL_CONFIG_TYPE, VDEV_TYPE_FILE) == 0); 2794 VERIFY(nvlist_add_string(file, ZPOOL_CONFIG_PATH, dev_name) == 0); 2795 VERIFY(nvlist_add_uint64(file, ZPOOL_CONFIG_ASHIFT, ashift) == 0); | 2922 root = make_vdev_root(dev_name, NULL, 0, 0, 0, 0, 0, 1); |
2796 | 2923 |
2797 VERIFY(nvlist_alloc(&root, NV_UNIQUE_NAME, 0) == 0); 2798 VERIFY(nvlist_add_string(root, ZPOOL_CONFIG_TYPE, VDEV_TYPE_ROOT) == 0); 2799 VERIFY(nvlist_add_nvlist_array(root, ZPOOL_CONFIG_CHILDREN, 2800 &file, 1) == 0); 2801 2802 spa_config_enter(spa, RW_READER, FTAG); | 2924 spa_config_enter(spa, SCL_VDEV, FTAG, RW_READER); |
2803 if ((vd = vdev_lookup_by_path(spa->spa_root_vdev, dev_name)) == NULL) 2804 guid = 0; 2805 else 2806 guid = vd->vdev_guid; | 2925 if ((vd = vdev_lookup_by_path(spa->spa_root_vdev, dev_name)) == NULL) 2926 guid = 0; 2927 else 2928 guid = vd->vdev_guid; |
2807 spa_config_exit(spa, FTAG); | 2929 spa_config_exit(spa, SCL_VDEV, FTAG); |
2808 error = spa_vdev_attach(spa, guid, root, B_TRUE); 2809 if (error != 0 && 2810 error != EBUSY && 2811 error != ENOTSUP && 2812 error != ENODEV && 2813 error != EDOM) 2814 fatal(0, "spa_vdev_attach(in-place) = %d", error); 2815 | 2930 error = spa_vdev_attach(spa, guid, root, B_TRUE); 2931 if (error != 0 && 2932 error != EBUSY && 2933 error != ENOTSUP && 2934 error != ENODEV && 2935 error != EDOM) 2936 fatal(0, "spa_vdev_attach(in-place) = %d", error); 2937 |
2816 nvlist_free(file); | |
2817 nvlist_free(root); 2818} 2819 2820static void 2821ztest_verify_blocks(char *pool) 2822{ 2823 int status; 2824 char zdb[MAXPATHLEN + MAXNAMELEN + 20]; 2825 char zbuf[1024]; 2826 char *bin; | 2938 nvlist_free(root); 2939} 2940 2941static void 2942ztest_verify_blocks(char *pool) 2943{ 2944 int status; 2945 char zdb[MAXPATHLEN + MAXNAMELEN + 20]; 2946 char zbuf[1024]; 2947 char *bin; |
2948 char *ztest; 2949 char *isa; 2950 int isalen; |
|
2827 FILE *fp; 2828 2829 if (realpath(progname, zdb) == NULL) 2830 assert(!"realpath() failed"); 2831 2832 /* zdb lives in /usr/sbin, while ztest lives in /usr/bin */ 2833 bin = strstr(zdb, "/usr/bin/"); | 2951 FILE *fp; 2952 2953 if (realpath(progname, zdb) == NULL) 2954 assert(!"realpath() failed"); 2955 2956 /* zdb lives in /usr/sbin, while ztest lives in /usr/bin */ 2957 bin = strstr(zdb, "/usr/bin/"); |
2834 if (bin == NULL) 2835 bin = zdb; | 2958 ztest = strstr(bin, "/ztest"); 2959 isa = bin + 8; 2960 isalen = ztest - isa; 2961 isa = strdup(isa); |
2836 /* LINTED */ | 2962 /* LINTED */ |
2837 (void) sprintf(bin, "/usr/sbin/zdb -bc%s%s -U -O %s %s", | 2963 (void) sprintf(bin, 2964 "/usr/sbin%.*s/zdb -bc%s%s -U /tmp/zpool.cache -O %s %s", 2965 isalen, 2966 isa, |
2838 zopt_verbose >= 3 ? "s" : "", 2839 zopt_verbose >= 4 ? "v" : "", 2840 ztest_random(2) == 0 ? "pre" : "post", pool); | 2967 zopt_verbose >= 3 ? "s" : "", 2968 zopt_verbose >= 4 ? "v" : "", 2969 ztest_random(2) == 0 ? "pre" : "post", pool); |
2970 free(isa); |
|
2841 2842 if (zopt_verbose >= 5) 2843 (void) printf("Executing %s\n", strstr(zdb, "zdb ")); 2844 2845 fp = popen(zdb, "r"); 2846 assert(fp != NULL); 2847 2848 while (fgets(zbuf, sizeof (zbuf), fp) != NULL) --- 55 unchanged lines hidden (view full) --- 2904 pool_guid = spa_guid(spa); 2905 spa_close(spa, FTAG); 2906 2907 ztest_walk_pool_directory("pools before export"); 2908 2909 /* 2910 * Export it. 2911 */ | 2971 2972 if (zopt_verbose >= 5) 2973 (void) printf("Executing %s\n", strstr(zdb, "zdb ")); 2974 2975 fp = popen(zdb, "r"); 2976 assert(fp != NULL); 2977 2978 while (fgets(zbuf, sizeof (zbuf), fp) != NULL) --- 55 unchanged lines hidden (view full) --- 3034 pool_guid = spa_guid(spa); 3035 spa_close(spa, FTAG); 3036 3037 ztest_walk_pool_directory("pools before export"); 3038 3039 /* 3040 * Export it. 3041 */ |
2912 error = spa_export(oldname, &config); | 3042 error = spa_export(oldname, &config, B_FALSE); |
2913 if (error) 2914 fatal(0, "spa_export('%s') = %d", oldname, error); 2915 2916 ztest_walk_pool_directory("pools after export"); 2917 2918 /* 2919 * Import it under the new name. 2920 */ --- 32 unchanged lines hidden (view full) --- 2953 fatal(0, "spa_open('%s') = %d", newname, error); 2954 ASSERT(pool_guid == spa_guid(spa)); 2955 spa_close(spa, FTAG); 2956 2957 nvlist_free(config); 2958} 2959 2960static void * | 3043 if (error) 3044 fatal(0, "spa_export('%s') = %d", oldname, error); 3045 3046 ztest_walk_pool_directory("pools after export"); 3047 3048 /* 3049 * Import it under the new name. 3050 */ --- 32 unchanged lines hidden (view full) --- 3083 fatal(0, "spa_open('%s') = %d", newname, error); 3084 ASSERT(pool_guid == spa_guid(spa)); 3085 spa_close(spa, FTAG); 3086 3087 nvlist_free(config); 3088} 3089 3090static void * |
3091ztest_resume(void *arg) 3092{ 3093 spa_t *spa = arg; 3094 3095 while (!ztest_exiting) { 3096 (void) poll(NULL, 0, 1000); 3097 3098 if (!spa_suspended(spa)) 3099 continue; 3100 3101 spa_vdev_state_enter(spa); 3102 vdev_clear(spa, NULL); 3103 (void) spa_vdev_state_exit(spa, NULL, 0); 3104 3105 zio_resume(spa); 3106 } 3107 return (NULL); 3108} 3109 3110static void * |
|
2961ztest_thread(void *arg) 2962{ 2963 ztest_args_t *za = arg; 2964 ztest_shared_t *zs = ztest_shared; 2965 hrtime_t now, functime; 2966 ztest_info_t *zi; | 3111ztest_thread(void *arg) 3112{ 3113 ztest_args_t *za = arg; 3114 ztest_shared_t *zs = ztest_shared; 3115 hrtime_t now, functime; 3116 ztest_info_t *zi; |
2967 int f; | 3117 int f, i; |
2968 2969 while ((now = gethrtime()) < za->za_stop) { 2970 /* 2971 * See if it's time to force a crash. 2972 */ 2973 if (now > za->za_kill) { | 3118 3119 while ((now = gethrtime()) < za->za_stop) { 3120 /* 3121 * See if it's time to force a crash. 3122 */ 3123 if (now > za->za_kill) { |
2974 dmu_tx_t *tx; 2975 uint64_t txg; 2976 2977 mutex_enter(&spa_namespace_lock); 2978 tx = dmu_tx_create(za->za_os); 2979 VERIFY(0 == dmu_tx_assign(tx, TXG_NOWAIT)); 2980 txg = dmu_tx_get_txg(tx); 2981 dmu_tx_commit(tx); 2982 zs->zs_txg = txg; 2983 if (zopt_verbose >= 3) 2984 (void) printf( 2985 "killing process after txg %lld\n", 2986 (u_longlong_t)txg); 2987 txg_wait_synced(dmu_objset_pool(za->za_os), txg); 2988 zs->zs_alloc = spa_get_alloc(dmu_objset_spa(za->za_os)); 2989 zs->zs_space = spa_get_space(dmu_objset_spa(za->za_os)); | 3124 zs->zs_alloc = spa_get_alloc(za->za_spa); 3125 zs->zs_space = spa_get_space(za->za_spa); |
2990 (void) kill(getpid(), SIGKILL); 2991 } 2992 2993 /* 2994 * Pick a random function. 2995 */ 2996 f = ztest_random(ZTEST_FUNCS); 2997 zi = &zs->zs_info[f]; --- 8 unchanged lines hidden (view full) --- 3006 3007 atomic_add_64(&zi->zi_calls, 1); 3008 atomic_add_64(&zi->zi_call_total, 1); 3009 3010 za->za_diroff = (za->za_instance * ZTEST_FUNCS + f) * 3011 ZTEST_DIRSIZE; 3012 za->za_diroff_shared = (1ULL << 63); 3013 | 3126 (void) kill(getpid(), SIGKILL); 3127 } 3128 3129 /* 3130 * Pick a random function. 3131 */ 3132 f = ztest_random(ZTEST_FUNCS); 3133 zi = &zs->zs_info[f]; --- 8 unchanged lines hidden (view full) --- 3142 3143 atomic_add_64(&zi->zi_calls, 1); 3144 atomic_add_64(&zi->zi_call_total, 1); 3145 3146 za->za_diroff = (za->za_instance * ZTEST_FUNCS + f) * 3147 ZTEST_DIRSIZE; 3148 za->za_diroff_shared = (1ULL << 63); 3149 |
3014 ztest_dmu_write_parallel(za); | 3150 for (i = 0; i < zi->zi_iters; i++) 3151 zi->zi_func(za); |
3015 | 3152 |
3016 zi->zi_func(za); 3017 | |
3018 functime = gethrtime() - now; 3019 3020 atomic_add_64(&zi->zi_call_time, functime); 3021 3022 if (zopt_verbose >= 4) { 3023 Dl_info dli; 3024 (void) dladdr((void *)zi->zi_func, &dli); 3025 (void) printf("%6.2f sec in %s\n", --- 16 unchanged lines hidden (view full) --- 3042static void 3043ztest_run(char *pool) 3044{ 3045 int t, d, error; 3046 ztest_shared_t *zs = ztest_shared; 3047 ztest_args_t *za; 3048 spa_t *spa; 3049 char name[100]; | 3153 functime = gethrtime() - now; 3154 3155 atomic_add_64(&zi->zi_call_time, functime); 3156 3157 if (zopt_verbose >= 4) { 3158 Dl_info dli; 3159 (void) dladdr((void *)zi->zi_func, &dli); 3160 (void) printf("%6.2f sec in %s\n", --- 16 unchanged lines hidden (view full) --- 3177static void 3178ztest_run(char *pool) 3179{ 3180 int t, d, error; 3181 ztest_shared_t *zs = ztest_shared; 3182 ztest_args_t *za; 3183 spa_t *spa; 3184 char name[100]; |
3185 thread_t resume_tid; |
|
3050 | 3186 |
3187 ztest_exiting = B_FALSE; 3188 |
|
3051 (void) _mutex_init(&zs->zs_vdev_lock, USYNC_THREAD, NULL); 3052 (void) rwlock_init(&zs->zs_name_lock, USYNC_THREAD, NULL); 3053 3054 for (t = 0; t < ZTEST_SYNC_LOCKS; t++) 3055 (void) _mutex_init(&zs->zs_sync_lock[t], USYNC_THREAD, NULL); 3056 3057 /* 3058 * Destroy one disk before we even start. --- 7 unchanged lines hidden (view full) --- 3066 * equals the SPA's allocated space total. 3067 */ 3068 ztest_verify_blocks(pool); 3069 3070 /* 3071 * Kick off a replacement of the disk we just obliterated. 3072 */ 3073 kernel_init(FREAD | FWRITE); | 3189 (void) _mutex_init(&zs->zs_vdev_lock, USYNC_THREAD, NULL); 3190 (void) rwlock_init(&zs->zs_name_lock, USYNC_THREAD, NULL); 3191 3192 for (t = 0; t < ZTEST_SYNC_LOCKS; t++) 3193 (void) _mutex_init(&zs->zs_sync_lock[t], USYNC_THREAD, NULL); 3194 3195 /* 3196 * Destroy one disk before we even start. --- 7 unchanged lines hidden (view full) --- 3204 * equals the SPA's allocated space total. 3205 */ 3206 ztest_verify_blocks(pool); 3207 3208 /* 3209 * Kick off a replacement of the disk we just obliterated. 3210 */ 3211 kernel_init(FREAD | FWRITE); |
3074 error = spa_open(pool, &spa, FTAG); 3075 if (error) 3076 fatal(0, "spa_open(%s) = %d", pool, error); | 3212 VERIFY(spa_open(pool, &spa, FTAG) == 0); |
3077 ztest_replace_one_disk(spa, 0); 3078 if (zopt_verbose >= 5) 3079 show_pool_stats(spa); 3080 spa_close(spa, FTAG); 3081 kernel_fini(); 3082 3083 kernel_init(FREAD | FWRITE); 3084 --- 16 unchanged lines hidden (view full) --- 3101 (void) printf("spa_next: found %s\n", spa_name(spa)); 3102 } 3103 } 3104 mutex_exit(&spa_namespace_lock); 3105 3106 /* 3107 * Open our pool. 3108 */ | 3213 ztest_replace_one_disk(spa, 0); 3214 if (zopt_verbose >= 5) 3215 show_pool_stats(spa); 3216 spa_close(spa, FTAG); 3217 kernel_fini(); 3218 3219 kernel_init(FREAD | FWRITE); 3220 --- 16 unchanged lines hidden (view full) --- 3237 (void) printf("spa_next: found %s\n", spa_name(spa)); 3238 } 3239 } 3240 mutex_exit(&spa_namespace_lock); 3241 3242 /* 3243 * Open our pool. 3244 */ |
3109 error = spa_open(pool, &spa, FTAG); 3110 if (error) 3111 fatal(0, "spa_open() = %d", error); | 3245 VERIFY(spa_open(pool, &spa, FTAG) == 0); |
3112 3113 /* | 3246 3247 /* |
3248 * Create a thread to periodically resume suspended I/O. 3249 */ 3250 VERIFY(thr_create(0, 0, ztest_resume, spa, THR_BOUND, 3251 &resume_tid) == 0); 3252 3253 /* |
|
3114 * Verify that we can safely inquire about about any object, 3115 * whether it's allocated or not. To make it interesting, 3116 * we probe a 5-wide window around each power of two. 3117 * This hits all edge cases, including zero and the max. 3118 */ 3119 for (t = 0; t < 64; t++) { 3120 for (d = -5; d <= 5; d++) { 3121 error = dmu_object_info(spa->spa_meta_objset, --- 17 unchanged lines hidden (view full) --- 3139 za[0].za_stop = za[0].za_start + zopt_passtime * NANOSEC; 3140 za[0].za_stop = MIN(za[0].za_stop, zs->zs_stop_time); 3141 za[0].za_kill = za[0].za_stop; 3142 if (ztest_random(100) < zopt_killrate) 3143 za[0].za_kill -= ztest_random(zopt_passtime * NANOSEC); 3144 3145 for (t = 0; t < zopt_threads; t++) { 3146 d = t % zopt_datasets; | 3254 * Verify that we can safely inquire about about any object, 3255 * whether it's allocated or not. To make it interesting, 3256 * we probe a 5-wide window around each power of two. 3257 * This hits all edge cases, including zero and the max. 3258 */ 3259 for (t = 0; t < 64; t++) { 3260 for (d = -5; d <= 5; d++) { 3261 error = dmu_object_info(spa->spa_meta_objset, --- 17 unchanged lines hidden (view full) --- 3279 za[0].za_stop = za[0].za_start + zopt_passtime * NANOSEC; 3280 za[0].za_stop = MIN(za[0].za_stop, zs->zs_stop_time); 3281 za[0].za_kill = za[0].za_stop; 3282 if (ztest_random(100) < zopt_killrate) 3283 za[0].za_kill -= ztest_random(zopt_passtime * NANOSEC); 3284 3285 for (t = 0; t < zopt_threads; t++) { 3286 d = t % zopt_datasets; |
3287 3288 (void) strcpy(za[t].za_pool, pool); 3289 za[t].za_os = za[d].za_os; 3290 za[t].za_spa = spa; 3291 za[t].za_zilog = za[d].za_zilog; 3292 za[t].za_instance = t; 3293 za[t].za_random = ztest_random(-1ULL); 3294 za[t].za_start = za[0].za_start; 3295 za[t].za_stop = za[0].za_stop; 3296 za[t].za_kill = za[0].za_kill; 3297 |
|
3147 if (t < zopt_datasets) { 3148 ztest_replay_t zr; 3149 int test_future = FALSE; 3150 (void) rw_rdlock(&ztest_shared->zs_name_lock); 3151 (void) snprintf(name, 100, "%s/%s_%d", pool, pool, d); | 3298 if (t < zopt_datasets) { 3299 ztest_replay_t zr; 3300 int test_future = FALSE; 3301 (void) rw_rdlock(&ztest_shared->zs_name_lock); 3302 (void) snprintf(name, 100, "%s/%s_%d", pool, pool, d); |
3152 error = dmu_objset_create(name, DMU_OST_OTHER, NULL, | 3303 error = dmu_objset_create(name, DMU_OST_OTHER, NULL, 0, |
3153 ztest_create_cb, NULL); 3154 if (error == EEXIST) { 3155 test_future = TRUE; | 3304 ztest_create_cb, NULL); 3305 if (error == EEXIST) { 3306 test_future = TRUE; |
3307 } else if (error == ENOSPC) { 3308 zs->zs_enospc_count++; 3309 (void) rw_unlock(&ztest_shared->zs_name_lock); 3310 break; |
|
3156 } else if (error != 0) { | 3311 } else if (error != 0) { |
3157 if (error == ENOSPC) { 3158 zs->zs_enospc_count++; 3159 (void) rw_unlock( 3160 &ztest_shared->zs_name_lock); 3161 break; 3162 } | |
3163 fatal(0, "dmu_objset_create(%s) = %d", 3164 name, error); 3165 } 3166 error = dmu_objset_open(name, DMU_OST_OTHER, | 3312 fatal(0, "dmu_objset_create(%s) = %d", 3313 name, error); 3314 } 3315 error = dmu_objset_open(name, DMU_OST_OTHER, |
3167 DS_MODE_STANDARD, &za[d].za_os); | 3316 DS_MODE_USER, &za[d].za_os); |
3168 if (error) 3169 fatal(0, "dmu_objset_open('%s') = %d", 3170 name, error); 3171 (void) rw_unlock(&ztest_shared->zs_name_lock); | 3317 if (error) 3318 fatal(0, "dmu_objset_open('%s') = %d", 3319 name, error); 3320 (void) rw_unlock(&ztest_shared->zs_name_lock); |
3172 if (test_future && ztest_shared->zs_txg > 0) 3173 ztest_dmu_check_future_leak(za[d].za_os, 3174 ztest_shared->zs_txg); | 3321 if (test_future) 3322 ztest_dmu_check_future_leak(&za[t]); |
3175 zr.zr_os = za[d].za_os; 3176 zil_replay(zr.zr_os, &zr, &zr.zr_assign, | 3323 zr.zr_os = za[d].za_os; 3324 zil_replay(zr.zr_os, &zr, &zr.zr_assign, |
3177 ztest_replay_vector); | 3325 ztest_replay_vector, NULL); |
3178 za[d].za_zilog = zil_open(za[d].za_os, NULL); 3179 } | 3326 za[d].za_zilog = zil_open(za[d].za_os, NULL); 3327 } |
3180 za[t].za_pool = spa_strdup(pool); 3181 za[t].za_os = za[d].za_os; 3182 za[t].za_zilog = za[d].za_zilog; 3183 za[t].za_instance = t; 3184 za[t].za_random = ztest_random(-1ULL); 3185 za[t].za_start = za[0].za_start; 3186 za[t].za_stop = za[0].za_stop; 3187 za[t].za_kill = za[0].za_kill; | |
3188 | 3328 |
3189 error = thr_create(0, 0, ztest_thread, &za[t], THR_BOUND, 3190 &za[t].za_thread); 3191 if (error) 3192 fatal(0, "can't create thread %d: error %d", 3193 t, error); | 3329 VERIFY(thr_create(0, 0, ztest_thread, &za[t], THR_BOUND, 3330 &za[t].za_thread) == 0); |
3194 } | 3331 } |
3195 ztest_shared->zs_txg = 0; | |
3196 3197 while (--t >= 0) { | 3332 3333 while (--t >= 0) { |
3198 error = thr_join(za[t].za_thread, NULL, NULL); 3199 if (error) 3200 fatal(0, "thr_join(%d) = %d", t, error); | 3334 VERIFY(thr_join(za[t].za_thread, NULL, NULL) == 0); |
3201 if (za[t].za_th) 3202 traverse_fini(za[t].za_th); 3203 if (t < zopt_datasets) { 3204 zil_close(za[t].za_zilog); 3205 dmu_objset_close(za[t].za_os); 3206 } | 3335 if (za[t].za_th) 3336 traverse_fini(za[t].za_th); 3337 if (t < zopt_datasets) { 3338 zil_close(za[t].za_zilog); 3339 dmu_objset_close(za[t].za_os); 3340 } |
3207 spa_strfree(za[t].za_pool); | |
3208 } 3209 | 3341 } 3342 |
3210 umem_free(za, zopt_threads * sizeof (ztest_args_t)); 3211 | |
3212 if (zopt_verbose >= 3) 3213 show_pool_stats(spa); 3214 3215 txg_wait_synced(spa_get_dsl(spa), 0); 3216 3217 zs->zs_alloc = spa_get_alloc(spa); 3218 zs->zs_space = spa_get_space(spa); 3219 3220 /* | 3343 if (zopt_verbose >= 3) 3344 show_pool_stats(spa); 3345 3346 txg_wait_synced(spa_get_dsl(spa), 0); 3347 3348 zs->zs_alloc = spa_get_alloc(spa); 3349 zs->zs_space = spa_get_space(spa); 3350 3351 /* |
3221 * Did we have out-of-space errors? If so, destroy a random objset. | 3352 * If we had out-of-space errors, destroy a random objset. |
3222 */ 3223 if (zs->zs_enospc_count != 0) { 3224 (void) rw_rdlock(&ztest_shared->zs_name_lock); | 3353 */ 3354 if (zs->zs_enospc_count != 0) { 3355 (void) rw_rdlock(&ztest_shared->zs_name_lock); |
3225 (void) snprintf(name, 100, "%s/%s_%d", pool, pool, 3226 (int)ztest_random(zopt_datasets)); | 3356 d = (int)ztest_random(zopt_datasets); 3357 (void) snprintf(name, 100, "%s/%s_%d", pool, pool, d); |
3227 if (zopt_verbose >= 3) 3228 (void) printf("Destroying %s to free up space\n", name); | 3358 if (zopt_verbose >= 3) 3359 (void) printf("Destroying %s to free up space\n", name); |
3229 (void) dmu_objset_find(name, ztest_destroy_cb, NULL, | 3360 (void) dmu_objset_find(name, ztest_destroy_cb, &za[d], |
3230 DS_FIND_SNAPSHOTS | DS_FIND_CHILDREN); 3231 (void) rw_unlock(&ztest_shared->zs_name_lock); 3232 } 3233 3234 txg_wait_synced(spa_get_dsl(spa), 0); 3235 | 3361 DS_FIND_SNAPSHOTS | DS_FIND_CHILDREN); 3362 (void) rw_unlock(&ztest_shared->zs_name_lock); 3363 } 3364 3365 txg_wait_synced(spa_get_dsl(spa), 0); 3366 |
3367 umem_free(za, zopt_threads * sizeof (ztest_args_t)); 3368 3369 /* Kill the resume thread */ 3370 ztest_exiting = B_TRUE; 3371 VERIFY(thr_join(resume_tid, NULL, NULL) == 0); 3372 |
|
3236 /* 3237 * Right before closing the pool, kick off a bunch of async I/O; 3238 * spa_close() should wait for it to complete. 3239 */ 3240 for (t = 1; t < 50; t++) 3241 dmu_prefetch(spa->spa_meta_objset, t, 0, 1 << 15); 3242 3243 spa_close(spa, FTAG); --- 39 unchanged lines hidden (view full) --- 3283 3284 kernel_init(FREAD | FWRITE); 3285 3286 /* 3287 * Create the storage pool. 3288 */ 3289 (void) spa_destroy(pool); 3290 ztest_shared->zs_vdev_primaries = 0; | 3373 /* 3374 * Right before closing the pool, kick off a bunch of async I/O; 3375 * spa_close() should wait for it to complete. 3376 */ 3377 for (t = 1; t < 50; t++) 3378 dmu_prefetch(spa->spa_meta_objset, t, 0, 1 << 15); 3379 3380 spa_close(spa, FTAG); --- 39 unchanged lines hidden (view full) --- 3420 3421 kernel_init(FREAD | FWRITE); 3422 3423 /* 3424 * Create the storage pool. 3425 */ 3426 (void) spa_destroy(pool); 3427 ztest_shared->zs_vdev_primaries = 0; |
3291 nvroot = make_vdev_root(zopt_vdev_size, zopt_raidz, zopt_mirrors, 1); 3292 error = spa_create(pool, nvroot, NULL); | 3428 nvroot = make_vdev_root(NULL, NULL, zopt_vdev_size, 0, 3429 0, zopt_raidz, zopt_mirrors, 1); 3430 error = spa_create(pool, nvroot, NULL, NULL, NULL); |
3293 nvlist_free(nvroot); 3294 3295 if (error) 3296 fatal(0, "spa_create() = %d", error); 3297 error = spa_open(pool, &spa, FTAG); 3298 if (error) 3299 fatal(0, "spa_open() = %d", error); 3300 --- 14 unchanged lines hidden (view full) --- 3315 ztest_shared_t *zs; 3316 ztest_info_t *zi; 3317 char timebuf[100]; 3318 char numbuf[6]; 3319 3320 (void) setvbuf(stdout, NULL, _IOLBF, 0); 3321 3322 /* Override location of zpool.cache */ | 3431 nvlist_free(nvroot); 3432 3433 if (error) 3434 fatal(0, "spa_create() = %d", error); 3435 error = spa_open(pool, &spa, FTAG); 3436 if (error) 3437 fatal(0, "spa_open() = %d", error); 3438 --- 14 unchanged lines hidden (view full) --- 3453 ztest_shared_t *zs; 3454 ztest_info_t *zi; 3455 char timebuf[100]; 3456 char numbuf[6]; 3457 3458 (void) setvbuf(stdout, NULL, _IOLBF, 0); 3459 3460 /* Override location of zpool.cache */ |
3323 spa_config_dir = "/tmp"; | 3461 spa_config_path = "/tmp/zpool.cache"; |
3324 3325 ztest_random_fd = open("/dev/urandom", O_RDONLY); 3326 3327 process_options(argc, argv); 3328 3329 argc -= optind; 3330 argv += optind; 3331 --- 164 unchanged lines hidden --- | 3462 3463 ztest_random_fd = open("/dev/urandom", O_RDONLY); 3464 3465 process_options(argc, argv); 3466 3467 argc -= optind; 3468 argv += optind; 3469 --- 164 unchanged lines hidden --- |