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