Print this page
8115 parallel zfs mount
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/cmd/zdb/zdb.c
+++ new/usr/src/cmd/zdb/zdb.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
↓ open down ↓ |
16 lines elided |
↑ open up ↑ |
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21
22 22 /*
23 23 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
24 24 * Copyright (c) 2011, 2016 by Delphix. All rights reserved.
25 25 * Copyright (c) 2014 Integros [integros.com]
26 26 * Copyright 2017 Nexenta Systems, Inc.
27 + * Copyright 2017 RackTop Systems.
27 28 */
28 29
29 30 #include <stdio.h>
30 31 #include <unistd.h>
31 32 #include <stdio_ext.h>
32 33 #include <stdlib.h>
33 34 #include <ctype.h>
34 35 #include <sys/zfs_context.h>
35 36 #include <sys/spa.h>
36 37 #include <sys/spa_impl.h>
37 38 #include <sys/dmu.h>
38 39 #include <sys/zap.h>
39 40 #include <sys/fs/zfs.h>
40 41 #include <sys/zfs_znode.h>
41 42 #include <sys/zfs_sa.h>
42 43 #include <sys/sa.h>
43 44 #include <sys/sa_impl.h>
44 45 #include <sys/vdev.h>
45 46 #include <sys/vdev_impl.h>
46 47 #include <sys/metaslab_impl.h>
47 48 #include <sys/dmu_objset.h>
48 49 #include <sys/dsl_dir.h>
49 50 #include <sys/dsl_dataset.h>
50 51 #include <sys/dsl_pool.h>
51 52 #include <sys/dbuf.h>
52 53 #include <sys/zil.h>
53 54 #include <sys/zil_impl.h>
54 55 #include <sys/stat.h>
55 56 #include <sys/resource.h>
56 57 #include <sys/dmu_traverse.h>
57 58 #include <sys/zio_checksum.h>
58 59 #include <sys/zio_compress.h>
59 60 #include <sys/zfs_fuid.h>
60 61 #include <sys/arc.h>
61 62 #include <sys/ddt.h>
62 63 #include <sys/zfeature.h>
63 64 #include <sys/abd.h>
64 65 #include <sys/blkptr.h>
65 66 #include <zfs_comutil.h>
66 67 #include <libcmdutils.h>
67 68 #undef verify
68 69 #include <libzfs.h>
69 70
70 71 #include "zdb.h"
71 72
72 73 #define ZDB_COMPRESS_NAME(idx) ((idx) < ZIO_COMPRESS_FUNCTIONS ? \
73 74 zio_compress_table[(idx)].ci_name : "UNKNOWN")
74 75 #define ZDB_CHECKSUM_NAME(idx) ((idx) < ZIO_CHECKSUM_FUNCTIONS ? \
75 76 zio_checksum_table[(idx)].ci_name : "UNKNOWN")
76 77 #define ZDB_OT_NAME(idx) ((idx) < DMU_OT_NUMTYPES ? \
77 78 dmu_ot[(idx)].ot_name : DMU_OT_IS_VALID(idx) ? \
78 79 dmu_ot_byteswap[DMU_OT_BYTESWAP(idx)].ob_name : "UNKNOWN")
79 80 #define ZDB_OT_TYPE(idx) ((idx) < DMU_OT_NUMTYPES ? (idx) : \
80 81 (((idx) == DMU_OTN_ZAP_DATA || (idx) == DMU_OTN_ZAP_METADATA) ? \
81 82 DMU_OT_ZAP_OTHER : DMU_OT_NUMTYPES))
82 83
83 84 #ifndef lint
84 85 extern int reference_tracking_enable;
85 86 extern boolean_t zfs_recover;
86 87 extern uint64_t zfs_arc_max, zfs_arc_meta_limit;
↓ open down ↓ |
50 lines elided |
↑ open up ↑ |
87 88 extern int zfs_vdev_async_read_max_active;
88 89 #else
89 90 int reference_tracking_enable;
90 91 boolean_t zfs_recover;
91 92 uint64_t zfs_arc_max, zfs_arc_meta_limit;
92 93 int zfs_vdev_async_read_max_active;
93 94 #endif
94 95
95 96 static const char cmdname[] = "zdb";
96 97 uint8_t dump_opt[256];
98 +extern int aok;
97 99
98 100 typedef void object_viewer_t(objset_t *, uint64_t, void *data, size_t size);
99 101
100 102 uint64_t *zopt_object = NULL;
101 103 static unsigned zopt_objects = 0;
102 104 libzfs_handle_t *g_zfs;
103 105 uint64_t max_inflight = 1000;
104 106
105 107 static void snprintf_blkptr_compact(char *, size_t, const blkptr_t *);
106 108
107 109 /*
108 110 * These libumem hooks provide a reasonable set of defaults for the allocator's
109 111 * debugging facilities.
110 112 */
111 113 const char *
112 114 _umem_debug_init()
113 115 {
114 116 return ("default,verbose"); /* $UMEM_DEBUG setting */
115 117 }
116 118
117 119 const char *
118 120 _umem_logging_init(void)
119 121 {
120 122 return ("fail,contents"); /* $UMEM_LOGGING setting */
121 123 }
122 124
123 125 static void
124 126 usage(void)
125 127 {
126 128 (void) fprintf(stderr,
127 129 "Usage:\t%s [-AbcdDFGhiLMPsvX] [-e [-V] [-p <path> ...]] "
128 130 "[-I <inflight I/Os>]\n"
129 131 "\t\t[-o <var>=<value>]... [-t <txg>] [-U <cache>] [-x <dumpdir>]\n"
130 132 "\t\t[<poolname> [<object> ...]]\n"
131 133 "\t%s [-AdiPv] [-e [-V] [-p <path> ...]] [-U <cache>] <dataset> "
132 134 "[<object> ...]\n"
133 135 "\t%s -C [-A] [-U <cache>]\n"
134 136 "\t%s -l [-Aqu] <device>\n"
135 137 "\t%s -m [-AFLPX] [-e [-V] [-p <path> ...]] [-t <txg>] "
136 138 "[-U <cache>]\n\t\t<poolname> [<vdev> [<metaslab> ...]]\n"
137 139 "\t%s -O <dataset> <path>\n"
138 140 "\t%s -R [-A] [-e [-V] [-p <path> ...]] [-U <cache>]\n"
139 141 "\t\t<poolname> <vdev>:<offset>:<size>[:<flags>]\n"
140 142 "\t%s -E [-A] word0:word1:...:word15\n"
141 143 "\t%s -S [-AP] [-e [-V] [-p <path> ...]] [-U <cache>] "
142 144 "<poolname>\n\n",
143 145 cmdname, cmdname, cmdname, cmdname, cmdname, cmdname, cmdname,
144 146 cmdname, cmdname);
145 147
146 148 (void) fprintf(stderr, " Dataset name must include at least one "
147 149 "separator character '/' or '@'\n");
148 150 (void) fprintf(stderr, " If dataset name is specified, only that "
149 151 "dataset is dumped\n");
150 152 (void) fprintf(stderr, " If object numbers are specified, only "
151 153 "those objects are dumped\n\n");
152 154 (void) fprintf(stderr, " Options to control amount of output:\n");
153 155 (void) fprintf(stderr, " -b block statistics\n");
154 156 (void) fprintf(stderr, " -c checksum all metadata (twice for "
155 157 "all data) blocks\n");
156 158 (void) fprintf(stderr, " -C config (or cachefile if alone)\n");
157 159 (void) fprintf(stderr, " -d dataset(s)\n");
158 160 (void) fprintf(stderr, " -D dedup statistics\n");
159 161 (void) fprintf(stderr, " -E decode and display block from an "
160 162 "embedded block pointer\n");
161 163 (void) fprintf(stderr, " -h pool history\n");
162 164 (void) fprintf(stderr, " -i intent logs\n");
163 165 (void) fprintf(stderr, " -l read label contents\n");
164 166 (void) fprintf(stderr, " -L disable leak tracking (do not "
165 167 "load spacemaps)\n");
166 168 (void) fprintf(stderr, " -m metaslabs\n");
167 169 (void) fprintf(stderr, " -M metaslab groups\n");
168 170 (void) fprintf(stderr, " -O perform object lookups by path\n");
169 171 (void) fprintf(stderr, " -R read and display block from a "
170 172 "device\n");
171 173 (void) fprintf(stderr, " -s report stats on zdb's I/O\n");
172 174 (void) fprintf(stderr, " -S simulate dedup to measure effect\n");
173 175 (void) fprintf(stderr, " -v verbose (applies to all "
174 176 "others)\n\n");
175 177 (void) fprintf(stderr, " Below options are intended for use "
176 178 "with other options:\n");
177 179 (void) fprintf(stderr, " -A ignore assertions (-A), enable "
178 180 "panic recovery (-AA) or both (-AAA)\n");
179 181 (void) fprintf(stderr, " -e pool is exported/destroyed/"
180 182 "has altroot/not in a cachefile\n");
181 183 (void) fprintf(stderr, " -F attempt automatic rewind within "
182 184 "safe range of transaction groups\n");
183 185 (void) fprintf(stderr, " -G dump zfs_dbgmsg buffer before "
184 186 "exiting\n");
185 187 (void) fprintf(stderr, " -I <number of inflight I/Os> -- "
186 188 "specify the maximum number of "
187 189 "checksumming I/Os [default is 200]\n");
188 190 (void) fprintf(stderr, " -o <variable>=<value> set global "
189 191 "variable to an unsigned 32-bit integer value\n");
190 192 (void) fprintf(stderr, " -p <path> -- use one or more with "
191 193 "-e to specify path to vdev dir\n");
192 194 (void) fprintf(stderr, " -P print numbers in parseable form\n");
193 195 (void) fprintf(stderr, " -q don't print label contents\n");
194 196 (void) fprintf(stderr, " -t <txg> -- highest txg to use when "
195 197 "searching for uberblocks\n");
196 198 (void) fprintf(stderr, " -u uberblock\n");
197 199 (void) fprintf(stderr, " -U <cachefile_path> -- use alternate "
198 200 "cachefile\n");
199 201 (void) fprintf(stderr, " -V do verbatim import\n");
200 202 (void) fprintf(stderr, " -x <dumpdir> -- "
201 203 "dump all read blocks into specified directory\n");
202 204 (void) fprintf(stderr, " -X attempt extreme rewind (does not "
203 205 "work with dataset)\n\n");
204 206 (void) fprintf(stderr, "Specify an option more than once (e.g. -bb) "
205 207 "to make only that option verbose\n");
206 208 (void) fprintf(stderr, "Default is to dump everything non-verbosely\n");
207 209 exit(1);
208 210 }
209 211
210 212 static void
211 213 dump_debug_buffer()
212 214 {
213 215 if (dump_opt['G']) {
214 216 (void) printf("\n");
215 217 zfs_dbgmsg_print("zdb");
216 218 }
217 219 }
218 220
219 221 /*
220 222 * Called for usage errors that are discovered after a call to spa_open(),
221 223 * dmu_bonus_hold(), or pool_match(). abort() is called for other errors.
222 224 */
223 225
224 226 static void
225 227 fatal(const char *fmt, ...)
226 228 {
227 229 va_list ap;
228 230
229 231 va_start(ap, fmt);
230 232 (void) fprintf(stderr, "%s: ", cmdname);
231 233 (void) vfprintf(stderr, fmt, ap);
232 234 va_end(ap);
233 235 (void) fprintf(stderr, "\n");
234 236
235 237 dump_debug_buffer();
236 238
237 239 exit(1);
238 240 }
239 241
240 242 /* ARGSUSED */
241 243 static void
242 244 dump_packed_nvlist(objset_t *os, uint64_t object, void *data, size_t size)
243 245 {
244 246 nvlist_t *nv;
245 247 size_t nvsize = *(uint64_t *)data;
246 248 char *packed = umem_alloc(nvsize, UMEM_NOFAIL);
247 249
248 250 VERIFY(0 == dmu_read(os, object, 0, nvsize, packed, DMU_READ_PREFETCH));
249 251
250 252 VERIFY(nvlist_unpack(packed, nvsize, &nv, 0) == 0);
251 253
252 254 umem_free(packed, nvsize);
253 255
254 256 dump_nvlist(nv, 8);
255 257
256 258 nvlist_free(nv);
257 259 }
258 260
259 261 /* ARGSUSED */
260 262 static void
261 263 dump_history_offsets(objset_t *os, uint64_t object, void *data, size_t size)
262 264 {
263 265 spa_history_phys_t *shp = data;
264 266
265 267 if (shp == NULL)
266 268 return;
267 269
268 270 (void) printf("\t\tpool_create_len = %llu\n",
269 271 (u_longlong_t)shp->sh_pool_create_len);
270 272 (void) printf("\t\tphys_max_off = %llu\n",
271 273 (u_longlong_t)shp->sh_phys_max_off);
272 274 (void) printf("\t\tbof = %llu\n",
273 275 (u_longlong_t)shp->sh_bof);
274 276 (void) printf("\t\teof = %llu\n",
275 277 (u_longlong_t)shp->sh_eof);
276 278 (void) printf("\t\trecords_lost = %llu\n",
277 279 (u_longlong_t)shp->sh_records_lost);
278 280 }
279 281
280 282 static void
281 283 zdb_nicenum(uint64_t num, char *buf, size_t buflen)
282 284 {
283 285 if (dump_opt['P'])
284 286 (void) snprintf(buf, buflen, "%llu", (longlong_t)num);
285 287 else
286 288 nicenum(num, buf, sizeof (buf));
287 289 }
288 290
289 291 static const char histo_stars[] = "****************************************";
290 292 static const uint64_t histo_width = sizeof (histo_stars) - 1;
291 293
292 294 static void
293 295 dump_histogram(const uint64_t *histo, int size, int offset)
294 296 {
295 297 int i;
296 298 int minidx = size - 1;
297 299 int maxidx = 0;
298 300 uint64_t max = 0;
299 301
300 302 for (i = 0; i < size; i++) {
301 303 if (histo[i] > max)
302 304 max = histo[i];
303 305 if (histo[i] > 0 && i > maxidx)
304 306 maxidx = i;
305 307 if (histo[i] > 0 && i < minidx)
306 308 minidx = i;
307 309 }
308 310
309 311 if (max < histo_width)
310 312 max = histo_width;
311 313
312 314 for (i = minidx; i <= maxidx; i++) {
313 315 (void) printf("\t\t\t%3u: %6llu %s\n",
314 316 i + offset, (u_longlong_t)histo[i],
315 317 &histo_stars[(max - histo[i]) * histo_width / max]);
316 318 }
317 319 }
318 320
319 321 static void
320 322 dump_zap_stats(objset_t *os, uint64_t object)
321 323 {
322 324 int error;
323 325 zap_stats_t zs;
324 326
325 327 error = zap_get_stats(os, object, &zs);
326 328 if (error)
327 329 return;
328 330
329 331 if (zs.zs_ptrtbl_len == 0) {
330 332 ASSERT(zs.zs_num_blocks == 1);
331 333 (void) printf("\tmicrozap: %llu bytes, %llu entries\n",
332 334 (u_longlong_t)zs.zs_blocksize,
333 335 (u_longlong_t)zs.zs_num_entries);
334 336 return;
335 337 }
336 338
337 339 (void) printf("\tFat ZAP stats:\n");
338 340
339 341 (void) printf("\t\tPointer table:\n");
340 342 (void) printf("\t\t\t%llu elements\n",
341 343 (u_longlong_t)zs.zs_ptrtbl_len);
342 344 (void) printf("\t\t\tzt_blk: %llu\n",
343 345 (u_longlong_t)zs.zs_ptrtbl_zt_blk);
344 346 (void) printf("\t\t\tzt_numblks: %llu\n",
345 347 (u_longlong_t)zs.zs_ptrtbl_zt_numblks);
346 348 (void) printf("\t\t\tzt_shift: %llu\n",
347 349 (u_longlong_t)zs.zs_ptrtbl_zt_shift);
348 350 (void) printf("\t\t\tzt_blks_copied: %llu\n",
349 351 (u_longlong_t)zs.zs_ptrtbl_blks_copied);
350 352 (void) printf("\t\t\tzt_nextblk: %llu\n",
351 353 (u_longlong_t)zs.zs_ptrtbl_nextblk);
352 354
353 355 (void) printf("\t\tZAP entries: %llu\n",
354 356 (u_longlong_t)zs.zs_num_entries);
355 357 (void) printf("\t\tLeaf blocks: %llu\n",
356 358 (u_longlong_t)zs.zs_num_leafs);
357 359 (void) printf("\t\tTotal blocks: %llu\n",
358 360 (u_longlong_t)zs.zs_num_blocks);
359 361 (void) printf("\t\tzap_block_type: 0x%llx\n",
360 362 (u_longlong_t)zs.zs_block_type);
361 363 (void) printf("\t\tzap_magic: 0x%llx\n",
362 364 (u_longlong_t)zs.zs_magic);
363 365 (void) printf("\t\tzap_salt: 0x%llx\n",
364 366 (u_longlong_t)zs.zs_salt);
365 367
366 368 (void) printf("\t\tLeafs with 2^n pointers:\n");
367 369 dump_histogram(zs.zs_leafs_with_2n_pointers, ZAP_HISTOGRAM_SIZE, 0);
368 370
369 371 (void) printf("\t\tBlocks with n*5 entries:\n");
370 372 dump_histogram(zs.zs_blocks_with_n5_entries, ZAP_HISTOGRAM_SIZE, 0);
371 373
372 374 (void) printf("\t\tBlocks n/10 full:\n");
373 375 dump_histogram(zs.zs_blocks_n_tenths_full, ZAP_HISTOGRAM_SIZE, 0);
374 376
375 377 (void) printf("\t\tEntries with n chunks:\n");
376 378 dump_histogram(zs.zs_entries_using_n_chunks, ZAP_HISTOGRAM_SIZE, 0);
377 379
378 380 (void) printf("\t\tBuckets with n entries:\n");
379 381 dump_histogram(zs.zs_buckets_with_n_entries, ZAP_HISTOGRAM_SIZE, 0);
380 382 }
381 383
382 384 /*ARGSUSED*/
383 385 static void
384 386 dump_none(objset_t *os, uint64_t object, void *data, size_t size)
385 387 {
386 388 }
387 389
388 390 /*ARGSUSED*/
389 391 static void
390 392 dump_unknown(objset_t *os, uint64_t object, void *data, size_t size)
391 393 {
392 394 (void) printf("\tUNKNOWN OBJECT TYPE\n");
393 395 }
394 396
395 397 /*ARGSUSED*/
396 398 static void
397 399 dump_uint8(objset_t *os, uint64_t object, void *data, size_t size)
398 400 {
399 401 }
400 402
401 403 /*ARGSUSED*/
402 404 static void
403 405 dump_uint64(objset_t *os, uint64_t object, void *data, size_t size)
404 406 {
405 407 }
406 408
407 409 /*ARGSUSED*/
408 410 static void
409 411 dump_zap(objset_t *os, uint64_t object, void *data, size_t size)
410 412 {
411 413 zap_cursor_t zc;
412 414 zap_attribute_t attr;
413 415 void *prop;
414 416 unsigned i;
415 417
416 418 dump_zap_stats(os, object);
417 419 (void) printf("\n");
418 420
419 421 for (zap_cursor_init(&zc, os, object);
420 422 zap_cursor_retrieve(&zc, &attr) == 0;
421 423 zap_cursor_advance(&zc)) {
422 424 (void) printf("\t\t%s = ", attr.za_name);
423 425 if (attr.za_num_integers == 0) {
424 426 (void) printf("\n");
425 427 continue;
426 428 }
427 429 prop = umem_zalloc(attr.za_num_integers *
428 430 attr.za_integer_length, UMEM_NOFAIL);
429 431 (void) zap_lookup(os, object, attr.za_name,
430 432 attr.za_integer_length, attr.za_num_integers, prop);
431 433 if (attr.za_integer_length == 1) {
432 434 (void) printf("%s", (char *)prop);
433 435 } else {
434 436 for (i = 0; i < attr.za_num_integers; i++) {
435 437 switch (attr.za_integer_length) {
436 438 case 2:
437 439 (void) printf("%u ",
438 440 ((uint16_t *)prop)[i]);
439 441 break;
440 442 case 4:
441 443 (void) printf("%u ",
442 444 ((uint32_t *)prop)[i]);
443 445 break;
444 446 case 8:
445 447 (void) printf("%lld ",
446 448 (u_longlong_t)((int64_t *)prop)[i]);
447 449 break;
448 450 }
449 451 }
450 452 }
451 453 (void) printf("\n");
452 454 umem_free(prop, attr.za_num_integers * attr.za_integer_length);
453 455 }
454 456 zap_cursor_fini(&zc);
455 457 }
456 458
457 459 static void
458 460 dump_bpobj(objset_t *os, uint64_t object, void *data, size_t size)
459 461 {
460 462 bpobj_phys_t *bpop = data;
461 463 char bytes[32], comp[32], uncomp[32];
462 464
463 465 /* make sure the output won't get truncated */
464 466 CTASSERT(sizeof (bytes) >= NN_NUMBUF_SZ);
465 467 CTASSERT(sizeof (comp) >= NN_NUMBUF_SZ);
466 468 CTASSERT(sizeof (uncomp) >= NN_NUMBUF_SZ);
467 469
468 470 if (bpop == NULL)
469 471 return;
470 472
471 473 zdb_nicenum(bpop->bpo_bytes, bytes, sizeof (bytes));
472 474 zdb_nicenum(bpop->bpo_comp, comp, sizeof (comp));
473 475 zdb_nicenum(bpop->bpo_uncomp, uncomp, sizeof (uncomp));
474 476
475 477 (void) printf("\t\tnum_blkptrs = %llu\n",
476 478 (u_longlong_t)bpop->bpo_num_blkptrs);
477 479 (void) printf("\t\tbytes = %s\n", bytes);
478 480 if (size >= BPOBJ_SIZE_V1) {
479 481 (void) printf("\t\tcomp = %s\n", comp);
480 482 (void) printf("\t\tuncomp = %s\n", uncomp);
481 483 }
482 484 if (size >= sizeof (*bpop)) {
483 485 (void) printf("\t\tsubobjs = %llu\n",
484 486 (u_longlong_t)bpop->bpo_subobjs);
485 487 (void) printf("\t\tnum_subobjs = %llu\n",
486 488 (u_longlong_t)bpop->bpo_num_subobjs);
487 489 }
488 490
489 491 if (dump_opt['d'] < 5)
490 492 return;
491 493
492 494 for (uint64_t i = 0; i < bpop->bpo_num_blkptrs; i++) {
493 495 char blkbuf[BP_SPRINTF_LEN];
494 496 blkptr_t bp;
495 497
496 498 int err = dmu_read(os, object,
497 499 i * sizeof (bp), sizeof (bp), &bp, 0);
498 500 if (err != 0) {
499 501 (void) printf("got error %u from dmu_read\n", err);
500 502 break;
501 503 }
502 504 snprintf_blkptr_compact(blkbuf, sizeof (blkbuf), &bp);
503 505 (void) printf("\t%s\n", blkbuf);
504 506 }
505 507 }
506 508
507 509 /* ARGSUSED */
508 510 static void
509 511 dump_bpobj_subobjs(objset_t *os, uint64_t object, void *data, size_t size)
510 512 {
511 513 dmu_object_info_t doi;
512 514
513 515 VERIFY0(dmu_object_info(os, object, &doi));
514 516 uint64_t *subobjs = kmem_alloc(doi.doi_max_offset, KM_SLEEP);
515 517
516 518 int err = dmu_read(os, object, 0, doi.doi_max_offset, subobjs, 0);
517 519 if (err != 0) {
518 520 (void) printf("got error %u from dmu_read\n", err);
519 521 kmem_free(subobjs, doi.doi_max_offset);
520 522 return;
521 523 }
522 524
523 525 int64_t last_nonzero = -1;
524 526 for (uint64_t i = 0; i < doi.doi_max_offset / 8; i++) {
525 527 if (subobjs[i] != 0)
526 528 last_nonzero = i;
527 529 }
528 530
529 531 for (int64_t i = 0; i <= last_nonzero; i++) {
530 532 (void) printf("\t%llu\n", (longlong_t)subobjs[i]);
531 533 }
532 534 kmem_free(subobjs, doi.doi_max_offset);
533 535 }
534 536
535 537 /*ARGSUSED*/
536 538 static void
537 539 dump_ddt_zap(objset_t *os, uint64_t object, void *data, size_t size)
538 540 {
539 541 dump_zap_stats(os, object);
540 542 /* contents are printed elsewhere, properly decoded */
541 543 }
542 544
543 545 /*ARGSUSED*/
544 546 static void
545 547 dump_sa_attrs(objset_t *os, uint64_t object, void *data, size_t size)
546 548 {
547 549 zap_cursor_t zc;
548 550 zap_attribute_t attr;
549 551
550 552 dump_zap_stats(os, object);
551 553 (void) printf("\n");
552 554
553 555 for (zap_cursor_init(&zc, os, object);
554 556 zap_cursor_retrieve(&zc, &attr) == 0;
555 557 zap_cursor_advance(&zc)) {
556 558 (void) printf("\t\t%s = ", attr.za_name);
557 559 if (attr.za_num_integers == 0) {
558 560 (void) printf("\n");
559 561 continue;
560 562 }
561 563 (void) printf(" %llx : [%d:%d:%d]\n",
562 564 (u_longlong_t)attr.za_first_integer,
563 565 (int)ATTR_LENGTH(attr.za_first_integer),
564 566 (int)ATTR_BSWAP(attr.za_first_integer),
565 567 (int)ATTR_NUM(attr.za_first_integer));
566 568 }
567 569 zap_cursor_fini(&zc);
568 570 }
569 571
570 572 /*ARGSUSED*/
571 573 static void
572 574 dump_sa_layouts(objset_t *os, uint64_t object, void *data, size_t size)
573 575 {
574 576 zap_cursor_t zc;
575 577 zap_attribute_t attr;
576 578 uint16_t *layout_attrs;
577 579 unsigned i;
578 580
579 581 dump_zap_stats(os, object);
580 582 (void) printf("\n");
581 583
582 584 for (zap_cursor_init(&zc, os, object);
583 585 zap_cursor_retrieve(&zc, &attr) == 0;
584 586 zap_cursor_advance(&zc)) {
585 587 (void) printf("\t\t%s = [", attr.za_name);
586 588 if (attr.za_num_integers == 0) {
587 589 (void) printf("\n");
588 590 continue;
589 591 }
590 592
591 593 VERIFY(attr.za_integer_length == 2);
592 594 layout_attrs = umem_zalloc(attr.za_num_integers *
593 595 attr.za_integer_length, UMEM_NOFAIL);
594 596
595 597 VERIFY(zap_lookup(os, object, attr.za_name,
596 598 attr.za_integer_length,
597 599 attr.za_num_integers, layout_attrs) == 0);
598 600
599 601 for (i = 0; i != attr.za_num_integers; i++)
600 602 (void) printf(" %d ", (int)layout_attrs[i]);
601 603 (void) printf("]\n");
602 604 umem_free(layout_attrs,
603 605 attr.za_num_integers * attr.za_integer_length);
604 606 }
605 607 zap_cursor_fini(&zc);
606 608 }
607 609
608 610 /*ARGSUSED*/
609 611 static void
610 612 dump_zpldir(objset_t *os, uint64_t object, void *data, size_t size)
611 613 {
612 614 zap_cursor_t zc;
613 615 zap_attribute_t attr;
614 616 const char *typenames[] = {
615 617 /* 0 */ "not specified",
616 618 /* 1 */ "FIFO",
617 619 /* 2 */ "Character Device",
618 620 /* 3 */ "3 (invalid)",
619 621 /* 4 */ "Directory",
620 622 /* 5 */ "5 (invalid)",
621 623 /* 6 */ "Block Device",
622 624 /* 7 */ "7 (invalid)",
623 625 /* 8 */ "Regular File",
624 626 /* 9 */ "9 (invalid)",
625 627 /* 10 */ "Symbolic Link",
626 628 /* 11 */ "11 (invalid)",
627 629 /* 12 */ "Socket",
628 630 /* 13 */ "Door",
629 631 /* 14 */ "Event Port",
630 632 /* 15 */ "15 (invalid)",
631 633 };
632 634
633 635 dump_zap_stats(os, object);
634 636 (void) printf("\n");
635 637
636 638 for (zap_cursor_init(&zc, os, object);
637 639 zap_cursor_retrieve(&zc, &attr) == 0;
638 640 zap_cursor_advance(&zc)) {
639 641 (void) printf("\t\t%s = %lld (type: %s)\n",
640 642 attr.za_name, ZFS_DIRENT_OBJ(attr.za_first_integer),
641 643 typenames[ZFS_DIRENT_TYPE(attr.za_first_integer)]);
642 644 }
643 645 zap_cursor_fini(&zc);
644 646 }
645 647
646 648 static int
647 649 get_dtl_refcount(vdev_t *vd)
648 650 {
649 651 int refcount = 0;
650 652
651 653 if (vd->vdev_ops->vdev_op_leaf) {
652 654 space_map_t *sm = vd->vdev_dtl_sm;
653 655
654 656 if (sm != NULL &&
655 657 sm->sm_dbuf->db_size == sizeof (space_map_phys_t))
656 658 return (1);
657 659 return (0);
658 660 }
659 661
660 662 for (unsigned c = 0; c < vd->vdev_children; c++)
661 663 refcount += get_dtl_refcount(vd->vdev_child[c]);
662 664 return (refcount);
663 665 }
664 666
665 667 static int
666 668 get_metaslab_refcount(vdev_t *vd)
667 669 {
668 670 int refcount = 0;
669 671
670 672 if (vd->vdev_top == vd && !vd->vdev_removing) {
671 673 for (unsigned m = 0; m < vd->vdev_ms_count; m++) {
672 674 space_map_t *sm = vd->vdev_ms[m]->ms_sm;
673 675
674 676 if (sm != NULL &&
675 677 sm->sm_dbuf->db_size == sizeof (space_map_phys_t))
676 678 refcount++;
677 679 }
678 680 }
679 681 for (unsigned c = 0; c < vd->vdev_children; c++)
680 682 refcount += get_metaslab_refcount(vd->vdev_child[c]);
681 683
682 684 return (refcount);
683 685 }
684 686
685 687 static int
686 688 verify_spacemap_refcounts(spa_t *spa)
687 689 {
688 690 uint64_t expected_refcount = 0;
689 691 uint64_t actual_refcount;
690 692
691 693 (void) feature_get_refcount(spa,
692 694 &spa_feature_table[SPA_FEATURE_SPACEMAP_HISTOGRAM],
693 695 &expected_refcount);
694 696 actual_refcount = get_dtl_refcount(spa->spa_root_vdev);
695 697 actual_refcount += get_metaslab_refcount(spa->spa_root_vdev);
696 698
697 699 if (expected_refcount != actual_refcount) {
698 700 (void) printf("space map refcount mismatch: expected %lld != "
699 701 "actual %lld\n",
700 702 (longlong_t)expected_refcount,
701 703 (longlong_t)actual_refcount);
702 704 return (2);
703 705 }
704 706 return (0);
705 707 }
706 708
707 709 static void
708 710 dump_spacemap(objset_t *os, space_map_t *sm)
709 711 {
710 712 uint64_t alloc, offset, entry;
711 713 const char *ddata[] = { "ALLOC", "FREE", "CONDENSE", "INVALID",
712 714 "INVALID", "INVALID", "INVALID", "INVALID" };
713 715
714 716 if (sm == NULL)
715 717 return;
716 718
717 719 /*
718 720 * Print out the freelist entries in both encoded and decoded form.
719 721 */
720 722 alloc = 0;
721 723 for (offset = 0; offset < space_map_length(sm);
722 724 offset += sizeof (entry)) {
723 725 uint8_t mapshift = sm->sm_shift;
724 726
725 727 VERIFY0(dmu_read(os, space_map_object(sm), offset,
726 728 sizeof (entry), &entry, DMU_READ_PREFETCH));
727 729 if (SM_DEBUG_DECODE(entry)) {
728 730
729 731 (void) printf("\t [%6llu] %s: txg %llu, pass %llu\n",
730 732 (u_longlong_t)(offset / sizeof (entry)),
731 733 ddata[SM_DEBUG_ACTION_DECODE(entry)],
732 734 (u_longlong_t)SM_DEBUG_TXG_DECODE(entry),
733 735 (u_longlong_t)SM_DEBUG_SYNCPASS_DECODE(entry));
734 736 } else {
735 737 (void) printf("\t [%6llu] %c range:"
736 738 " %010llx-%010llx size: %06llx\n",
737 739 (u_longlong_t)(offset / sizeof (entry)),
738 740 SM_TYPE_DECODE(entry) == SM_ALLOC ? 'A' : 'F',
739 741 (u_longlong_t)((SM_OFFSET_DECODE(entry) <<
740 742 mapshift) + sm->sm_start),
741 743 (u_longlong_t)((SM_OFFSET_DECODE(entry) <<
742 744 mapshift) + sm->sm_start +
743 745 (SM_RUN_DECODE(entry) << mapshift)),
744 746 (u_longlong_t)(SM_RUN_DECODE(entry) << mapshift));
745 747 if (SM_TYPE_DECODE(entry) == SM_ALLOC)
746 748 alloc += SM_RUN_DECODE(entry) << mapshift;
747 749 else
748 750 alloc -= SM_RUN_DECODE(entry) << mapshift;
749 751 }
750 752 }
751 753 if (alloc != space_map_allocated(sm)) {
752 754 (void) printf("space_map_object alloc (%llu) INCONSISTENT "
753 755 "with space map summary (%llu)\n",
754 756 (u_longlong_t)space_map_allocated(sm), (u_longlong_t)alloc);
755 757 }
756 758 }
757 759
758 760 static void
759 761 dump_metaslab_stats(metaslab_t *msp)
760 762 {
761 763 char maxbuf[32];
762 764 range_tree_t *rt = msp->ms_tree;
763 765 avl_tree_t *t = &msp->ms_size_tree;
764 766 int free_pct = range_tree_space(rt) * 100 / msp->ms_size;
765 767
766 768 /* max sure nicenum has enough space */
767 769 CTASSERT(sizeof (maxbuf) >= NN_NUMBUF_SZ);
768 770
769 771 zdb_nicenum(metaslab_block_maxsize(msp), maxbuf, sizeof (maxbuf));
770 772
771 773 (void) printf("\t %25s %10lu %7s %6s %4s %4d%%\n",
772 774 "segments", avl_numnodes(t), "maxsize", maxbuf,
773 775 "freepct", free_pct);
774 776 (void) printf("\tIn-memory histogram:\n");
775 777 dump_histogram(rt->rt_histogram, RANGE_TREE_HISTOGRAM_SIZE, 0);
776 778 }
777 779
778 780 static void
779 781 dump_metaslab(metaslab_t *msp)
780 782 {
781 783 vdev_t *vd = msp->ms_group->mg_vd;
782 784 spa_t *spa = vd->vdev_spa;
783 785 space_map_t *sm = msp->ms_sm;
784 786 char freebuf[32];
785 787
786 788 zdb_nicenum(msp->ms_size - space_map_allocated(sm), freebuf,
787 789 sizeof (freebuf));
788 790
789 791 (void) printf(
790 792 "\tmetaslab %6llu offset %12llx spacemap %6llu free %5s\n",
791 793 (u_longlong_t)msp->ms_id, (u_longlong_t)msp->ms_start,
792 794 (u_longlong_t)space_map_object(sm), freebuf);
793 795
794 796 if (dump_opt['m'] > 2 && !dump_opt['L']) {
795 797 mutex_enter(&msp->ms_lock);
796 798 metaslab_load_wait(msp);
797 799 if (!msp->ms_loaded) {
798 800 VERIFY0(metaslab_load(msp));
799 801 range_tree_stat_verify(msp->ms_tree);
800 802 }
801 803 dump_metaslab_stats(msp);
802 804 metaslab_unload(msp);
803 805 mutex_exit(&msp->ms_lock);
804 806 }
805 807
806 808 if (dump_opt['m'] > 1 && sm != NULL &&
807 809 spa_feature_is_active(spa, SPA_FEATURE_SPACEMAP_HISTOGRAM)) {
808 810 /*
809 811 * The space map histogram represents free space in chunks
810 812 * of sm_shift (i.e. bucket 0 refers to 2^sm_shift).
811 813 */
812 814 (void) printf("\tOn-disk histogram:\t\tfragmentation %llu\n",
813 815 (u_longlong_t)msp->ms_fragmentation);
814 816 dump_histogram(sm->sm_phys->smp_histogram,
815 817 SPACE_MAP_HISTOGRAM_SIZE, sm->sm_shift);
816 818 }
817 819
818 820 if (dump_opt['d'] > 5 || dump_opt['m'] > 3) {
819 821 ASSERT(msp->ms_size == (1ULL << vd->vdev_ms_shift));
820 822
821 823 mutex_enter(&msp->ms_lock);
822 824 dump_spacemap(spa->spa_meta_objset, msp->ms_sm);
823 825 mutex_exit(&msp->ms_lock);
824 826 }
825 827 }
826 828
827 829 static void
828 830 print_vdev_metaslab_header(vdev_t *vd)
829 831 {
830 832 (void) printf("\tvdev %10llu\n\t%-10s%5llu %-19s %-15s %-10s\n",
831 833 (u_longlong_t)vd->vdev_id,
832 834 "metaslabs", (u_longlong_t)vd->vdev_ms_count,
833 835 "offset", "spacemap", "free");
834 836 (void) printf("\t%15s %19s %15s %10s\n",
835 837 "---------------", "-------------------",
836 838 "---------------", "-------------");
837 839 }
838 840
839 841 static void
840 842 dump_metaslab_groups(spa_t *spa)
841 843 {
842 844 vdev_t *rvd = spa->spa_root_vdev;
843 845 metaslab_class_t *mc = spa_normal_class(spa);
844 846 uint64_t fragmentation;
845 847
846 848 metaslab_class_histogram_verify(mc);
847 849
848 850 for (unsigned c = 0; c < rvd->vdev_children; c++) {
849 851 vdev_t *tvd = rvd->vdev_child[c];
850 852 metaslab_group_t *mg = tvd->vdev_mg;
851 853
852 854 if (mg->mg_class != mc)
853 855 continue;
854 856
855 857 metaslab_group_histogram_verify(mg);
856 858 mg->mg_fragmentation = metaslab_group_fragmentation(mg);
857 859
858 860 (void) printf("\tvdev %10llu\t\tmetaslabs%5llu\t\t"
859 861 "fragmentation",
860 862 (u_longlong_t)tvd->vdev_id,
861 863 (u_longlong_t)tvd->vdev_ms_count);
862 864 if (mg->mg_fragmentation == ZFS_FRAG_INVALID) {
863 865 (void) printf("%3s\n", "-");
864 866 } else {
865 867 (void) printf("%3llu%%\n",
866 868 (u_longlong_t)mg->mg_fragmentation);
867 869 }
868 870 dump_histogram(mg->mg_histogram, RANGE_TREE_HISTOGRAM_SIZE, 0);
869 871 }
870 872
871 873 (void) printf("\tpool %s\tfragmentation", spa_name(spa));
872 874 fragmentation = metaslab_class_fragmentation(mc);
873 875 if (fragmentation == ZFS_FRAG_INVALID)
874 876 (void) printf("\t%3s\n", "-");
875 877 else
876 878 (void) printf("\t%3llu%%\n", (u_longlong_t)fragmentation);
877 879 dump_histogram(mc->mc_histogram, RANGE_TREE_HISTOGRAM_SIZE, 0);
878 880 }
879 881
880 882 static void
881 883 dump_metaslabs(spa_t *spa)
882 884 {
883 885 vdev_t *vd, *rvd = spa->spa_root_vdev;
884 886 uint64_t m, c = 0, children = rvd->vdev_children;
885 887
886 888 (void) printf("\nMetaslabs:\n");
887 889
888 890 if (!dump_opt['d'] && zopt_objects > 0) {
889 891 c = zopt_object[0];
890 892
891 893 if (c >= children)
892 894 (void) fatal("bad vdev id: %llu", (u_longlong_t)c);
893 895
894 896 if (zopt_objects > 1) {
895 897 vd = rvd->vdev_child[c];
896 898 print_vdev_metaslab_header(vd);
897 899
898 900 for (m = 1; m < zopt_objects; m++) {
899 901 if (zopt_object[m] < vd->vdev_ms_count)
900 902 dump_metaslab(
901 903 vd->vdev_ms[zopt_object[m]]);
902 904 else
903 905 (void) fprintf(stderr, "bad metaslab "
904 906 "number %llu\n",
905 907 (u_longlong_t)zopt_object[m]);
906 908 }
907 909 (void) printf("\n");
908 910 return;
909 911 }
910 912 children = c + 1;
911 913 }
912 914 for (; c < children; c++) {
913 915 vd = rvd->vdev_child[c];
914 916 print_vdev_metaslab_header(vd);
915 917
916 918 for (m = 0; m < vd->vdev_ms_count; m++)
917 919 dump_metaslab(vd->vdev_ms[m]);
918 920 (void) printf("\n");
919 921 }
920 922 }
921 923
922 924 static void
923 925 dump_dde(const ddt_t *ddt, const ddt_entry_t *dde, uint64_t index)
924 926 {
925 927 const ddt_phys_t *ddp = dde->dde_phys;
926 928 const ddt_key_t *ddk = &dde->dde_key;
927 929 const char *types[4] = { "ditto", "single", "double", "triple" };
928 930 char blkbuf[BP_SPRINTF_LEN];
929 931 blkptr_t blk;
930 932
931 933 for (int p = 0; p < DDT_PHYS_TYPES; p++, ddp++) {
932 934 if (ddp->ddp_phys_birth == 0)
933 935 continue;
934 936 ddt_bp_create(ddt->ddt_checksum, ddk, ddp, &blk);
935 937 snprintf_blkptr(blkbuf, sizeof (blkbuf), &blk);
936 938 (void) printf("index %llx refcnt %llu %s %s\n",
937 939 (u_longlong_t)index, (u_longlong_t)ddp->ddp_refcnt,
938 940 types[p], blkbuf);
939 941 }
940 942 }
941 943
942 944 static void
943 945 dump_dedup_ratio(const ddt_stat_t *dds)
944 946 {
945 947 double rL, rP, rD, D, dedup, compress, copies;
946 948
947 949 if (dds->dds_blocks == 0)
948 950 return;
949 951
950 952 rL = (double)dds->dds_ref_lsize;
951 953 rP = (double)dds->dds_ref_psize;
952 954 rD = (double)dds->dds_ref_dsize;
953 955 D = (double)dds->dds_dsize;
954 956
955 957 dedup = rD / D;
956 958 compress = rL / rP;
957 959 copies = rD / rP;
958 960
959 961 (void) printf("dedup = %.2f, compress = %.2f, copies = %.2f, "
960 962 "dedup * compress / copies = %.2f\n\n",
961 963 dedup, compress, copies, dedup * compress / copies);
962 964 }
963 965
964 966 static void
965 967 dump_ddt(ddt_t *ddt, enum ddt_type type, enum ddt_class class)
966 968 {
967 969 char name[DDT_NAMELEN];
968 970 ddt_entry_t dde;
969 971 uint64_t walk = 0;
970 972 dmu_object_info_t doi;
971 973 uint64_t count, dspace, mspace;
972 974 int error;
973 975
974 976 error = ddt_object_info(ddt, type, class, &doi);
975 977
976 978 if (error == ENOENT)
977 979 return;
978 980 ASSERT(error == 0);
979 981
980 982 if ((count = ddt_object_count(ddt, type, class)) == 0)
981 983 return;
982 984
983 985 dspace = doi.doi_physical_blocks_512 << 9;
984 986 mspace = doi.doi_fill_count * doi.doi_data_block_size;
985 987
986 988 ddt_object_name(ddt, type, class, name);
987 989
988 990 (void) printf("%s: %llu entries, size %llu on disk, %llu in core\n",
989 991 name,
990 992 (u_longlong_t)count,
991 993 (u_longlong_t)(dspace / count),
992 994 (u_longlong_t)(mspace / count));
993 995
994 996 if (dump_opt['D'] < 3)
995 997 return;
996 998
997 999 zpool_dump_ddt(NULL, &ddt->ddt_histogram[type][class]);
998 1000
999 1001 if (dump_opt['D'] < 4)
1000 1002 return;
1001 1003
1002 1004 if (dump_opt['D'] < 5 && class == DDT_CLASS_UNIQUE)
1003 1005 return;
1004 1006
1005 1007 (void) printf("%s contents:\n\n", name);
1006 1008
1007 1009 while ((error = ddt_object_walk(ddt, type, class, &walk, &dde)) == 0)
1008 1010 dump_dde(ddt, &dde, walk);
1009 1011
1010 1012 ASSERT(error == ENOENT);
1011 1013
1012 1014 (void) printf("\n");
1013 1015 }
1014 1016
1015 1017 static void
1016 1018 dump_all_ddts(spa_t *spa)
1017 1019 {
1018 1020 ddt_histogram_t ddh_total;
1019 1021 ddt_stat_t dds_total;
1020 1022
1021 1023 bzero(&ddh_total, sizeof (ddh_total));
1022 1024 bzero(&dds_total, sizeof (dds_total));
1023 1025
1024 1026 for (enum zio_checksum c = 0; c < ZIO_CHECKSUM_FUNCTIONS; c++) {
1025 1027 ddt_t *ddt = spa->spa_ddt[c];
1026 1028 for (enum ddt_type type = 0; type < DDT_TYPES; type++) {
1027 1029 for (enum ddt_class class = 0; class < DDT_CLASSES;
1028 1030 class++) {
1029 1031 dump_ddt(ddt, type, class);
1030 1032 }
1031 1033 }
1032 1034 }
1033 1035
1034 1036 ddt_get_dedup_stats(spa, &dds_total);
1035 1037
1036 1038 if (dds_total.dds_blocks == 0) {
1037 1039 (void) printf("All DDTs are empty\n");
1038 1040 return;
1039 1041 }
1040 1042
1041 1043 (void) printf("\n");
1042 1044
1043 1045 if (dump_opt['D'] > 1) {
1044 1046 (void) printf("DDT histogram (aggregated over all DDTs):\n");
1045 1047 ddt_get_dedup_histogram(spa, &ddh_total);
1046 1048 zpool_dump_ddt(&dds_total, &ddh_total);
1047 1049 }
1048 1050
1049 1051 dump_dedup_ratio(&dds_total);
1050 1052 }
1051 1053
1052 1054 static void
1053 1055 dump_dtl_seg(void *arg, uint64_t start, uint64_t size)
1054 1056 {
1055 1057 char *prefix = arg;
1056 1058
1057 1059 (void) printf("%s [%llu,%llu) length %llu\n",
1058 1060 prefix,
1059 1061 (u_longlong_t)start,
1060 1062 (u_longlong_t)(start + size),
1061 1063 (u_longlong_t)(size));
1062 1064 }
1063 1065
1064 1066 static void
1065 1067 dump_dtl(vdev_t *vd, int indent)
1066 1068 {
1067 1069 spa_t *spa = vd->vdev_spa;
1068 1070 boolean_t required;
1069 1071 const char *name[DTL_TYPES] = { "missing", "partial", "scrub",
1070 1072 "outage" };
1071 1073 char prefix[256];
1072 1074
1073 1075 spa_vdev_state_enter(spa, SCL_NONE);
1074 1076 required = vdev_dtl_required(vd);
1075 1077 (void) spa_vdev_state_exit(spa, NULL, 0);
1076 1078
1077 1079 if (indent == 0)
1078 1080 (void) printf("\nDirty time logs:\n\n");
1079 1081
1080 1082 (void) printf("\t%*s%s [%s]\n", indent, "",
1081 1083 vd->vdev_path ? vd->vdev_path :
1082 1084 vd->vdev_parent ? vd->vdev_ops->vdev_op_type : spa_name(spa),
1083 1085 required ? "DTL-required" : "DTL-expendable");
1084 1086
1085 1087 for (int t = 0; t < DTL_TYPES; t++) {
1086 1088 range_tree_t *rt = vd->vdev_dtl[t];
1087 1089 if (range_tree_space(rt) == 0)
1088 1090 continue;
1089 1091 (void) snprintf(prefix, sizeof (prefix), "\t%*s%s",
1090 1092 indent + 2, "", name[t]);
1091 1093 mutex_enter(rt->rt_lock);
1092 1094 range_tree_walk(rt, dump_dtl_seg, prefix);
1093 1095 mutex_exit(rt->rt_lock);
1094 1096 if (dump_opt['d'] > 5 && vd->vdev_children == 0)
1095 1097 dump_spacemap(spa->spa_meta_objset, vd->vdev_dtl_sm);
1096 1098 }
1097 1099
1098 1100 for (unsigned c = 0; c < vd->vdev_children; c++)
1099 1101 dump_dtl(vd->vdev_child[c], indent + 4);
1100 1102 }
1101 1103
1102 1104 static void
1103 1105 dump_history(spa_t *spa)
1104 1106 {
1105 1107 nvlist_t **events = NULL;
1106 1108 uint64_t resid, len, off = 0;
1107 1109 uint_t num = 0;
1108 1110 int error;
1109 1111 time_t tsec;
1110 1112 struct tm t;
1111 1113 char tbuf[30];
1112 1114 char internalstr[MAXPATHLEN];
1113 1115
1114 1116 char *buf = umem_alloc(SPA_MAXBLOCKSIZE, UMEM_NOFAIL);
1115 1117 do {
1116 1118 len = SPA_MAXBLOCKSIZE;
1117 1119
1118 1120 if ((error = spa_history_get(spa, &off, &len, buf)) != 0) {
1119 1121 (void) fprintf(stderr, "Unable to read history: "
1120 1122 "error %d\n", error);
1121 1123 umem_free(buf, SPA_MAXBLOCKSIZE);
1122 1124 return;
1123 1125 }
1124 1126
1125 1127 if (zpool_history_unpack(buf, len, &resid, &events, &num) != 0)
1126 1128 break;
1127 1129
1128 1130 off -= resid;
1129 1131 } while (len != 0);
1130 1132 umem_free(buf, SPA_MAXBLOCKSIZE);
1131 1133
1132 1134 (void) printf("\nHistory:\n");
1133 1135 for (unsigned i = 0; i < num; i++) {
1134 1136 uint64_t time, txg, ievent;
1135 1137 char *cmd, *intstr;
1136 1138 boolean_t printed = B_FALSE;
1137 1139
1138 1140 if (nvlist_lookup_uint64(events[i], ZPOOL_HIST_TIME,
1139 1141 &time) != 0)
1140 1142 goto next;
1141 1143 if (nvlist_lookup_string(events[i], ZPOOL_HIST_CMD,
1142 1144 &cmd) != 0) {
1143 1145 if (nvlist_lookup_uint64(events[i],
1144 1146 ZPOOL_HIST_INT_EVENT, &ievent) != 0)
1145 1147 goto next;
1146 1148 verify(nvlist_lookup_uint64(events[i],
1147 1149 ZPOOL_HIST_TXG, &txg) == 0);
1148 1150 verify(nvlist_lookup_string(events[i],
1149 1151 ZPOOL_HIST_INT_STR, &intstr) == 0);
1150 1152 if (ievent >= ZFS_NUM_LEGACY_HISTORY_EVENTS)
1151 1153 goto next;
1152 1154
1153 1155 (void) snprintf(internalstr,
1154 1156 sizeof (internalstr),
1155 1157 "[internal %s txg:%ju] %s",
1156 1158 zfs_history_event_names[ievent], (uintmax_t)txg,
1157 1159 intstr);
1158 1160 cmd = internalstr;
1159 1161 }
1160 1162 tsec = time;
1161 1163 (void) localtime_r(&tsec, &t);
1162 1164 (void) strftime(tbuf, sizeof (tbuf), "%F.%T", &t);
1163 1165 (void) printf("%s %s\n", tbuf, cmd);
1164 1166 printed = B_TRUE;
1165 1167
1166 1168 next:
1167 1169 if (dump_opt['h'] > 1) {
1168 1170 if (!printed)
1169 1171 (void) printf("unrecognized record:\n");
1170 1172 dump_nvlist(events[i], 2);
1171 1173 }
1172 1174 }
1173 1175 }
1174 1176
1175 1177 /*ARGSUSED*/
1176 1178 static void
1177 1179 dump_dnode(objset_t *os, uint64_t object, void *data, size_t size)
1178 1180 {
1179 1181 }
1180 1182
1181 1183 static uint64_t
1182 1184 blkid2offset(const dnode_phys_t *dnp, const blkptr_t *bp,
1183 1185 const zbookmark_phys_t *zb)
1184 1186 {
1185 1187 if (dnp == NULL) {
1186 1188 ASSERT(zb->zb_level < 0);
1187 1189 if (zb->zb_object == 0)
1188 1190 return (zb->zb_blkid);
1189 1191 return (zb->zb_blkid * BP_GET_LSIZE(bp));
1190 1192 }
1191 1193
1192 1194 ASSERT(zb->zb_level >= 0);
1193 1195
1194 1196 return ((zb->zb_blkid <<
1195 1197 (zb->zb_level * (dnp->dn_indblkshift - SPA_BLKPTRSHIFT))) *
1196 1198 dnp->dn_datablkszsec << SPA_MINBLOCKSHIFT);
1197 1199 }
1198 1200
1199 1201 static void
1200 1202 snprintf_blkptr_compact(char *blkbuf, size_t buflen, const blkptr_t *bp)
1201 1203 {
1202 1204 const dva_t *dva = bp->blk_dva;
1203 1205 int ndvas = dump_opt['d'] > 5 ? BP_GET_NDVAS(bp) : 1;
1204 1206
1205 1207 if (dump_opt['b'] >= 6) {
1206 1208 snprintf_blkptr(blkbuf, buflen, bp);
1207 1209 return;
1208 1210 }
1209 1211
1210 1212 if (BP_IS_EMBEDDED(bp)) {
1211 1213 (void) sprintf(blkbuf,
1212 1214 "EMBEDDED et=%u %llxL/%llxP B=%llu",
1213 1215 (int)BPE_GET_ETYPE(bp),
1214 1216 (u_longlong_t)BPE_GET_LSIZE(bp),
1215 1217 (u_longlong_t)BPE_GET_PSIZE(bp),
1216 1218 (u_longlong_t)bp->blk_birth);
1217 1219 return;
1218 1220 }
1219 1221
1220 1222 blkbuf[0] = '\0';
1221 1223 for (int i = 0; i < ndvas; i++)
1222 1224 (void) snprintf(blkbuf + strlen(blkbuf),
1223 1225 buflen - strlen(blkbuf), "%llu:%llx:%llx ",
1224 1226 (u_longlong_t)DVA_GET_VDEV(&dva[i]),
1225 1227 (u_longlong_t)DVA_GET_OFFSET(&dva[i]),
1226 1228 (u_longlong_t)DVA_GET_ASIZE(&dva[i]));
1227 1229
1228 1230 if (BP_IS_HOLE(bp)) {
1229 1231 (void) snprintf(blkbuf + strlen(blkbuf),
1230 1232 buflen - strlen(blkbuf),
1231 1233 "%llxL B=%llu",
1232 1234 (u_longlong_t)BP_GET_LSIZE(bp),
1233 1235 (u_longlong_t)bp->blk_birth);
1234 1236 } else {
1235 1237 (void) snprintf(blkbuf + strlen(blkbuf),
1236 1238 buflen - strlen(blkbuf),
1237 1239 "%llxL/%llxP F=%llu B=%llu/%llu",
1238 1240 (u_longlong_t)BP_GET_LSIZE(bp),
1239 1241 (u_longlong_t)BP_GET_PSIZE(bp),
1240 1242 (u_longlong_t)BP_GET_FILL(bp),
1241 1243 (u_longlong_t)bp->blk_birth,
1242 1244 (u_longlong_t)BP_PHYSICAL_BIRTH(bp));
1243 1245 }
1244 1246 }
1245 1247
1246 1248 static void
1247 1249 print_indirect(blkptr_t *bp, const zbookmark_phys_t *zb,
1248 1250 const dnode_phys_t *dnp)
1249 1251 {
1250 1252 char blkbuf[BP_SPRINTF_LEN];
1251 1253 int l;
1252 1254
1253 1255 if (!BP_IS_EMBEDDED(bp)) {
1254 1256 ASSERT3U(BP_GET_TYPE(bp), ==, dnp->dn_type);
1255 1257 ASSERT3U(BP_GET_LEVEL(bp), ==, zb->zb_level);
1256 1258 }
1257 1259
1258 1260 (void) printf("%16llx ", (u_longlong_t)blkid2offset(dnp, bp, zb));
1259 1261
1260 1262 ASSERT(zb->zb_level >= 0);
1261 1263
1262 1264 for (l = dnp->dn_nlevels - 1; l >= -1; l--) {
1263 1265 if (l == zb->zb_level) {
1264 1266 (void) printf("L%llx", (u_longlong_t)zb->zb_level);
1265 1267 } else {
1266 1268 (void) printf(" ");
1267 1269 }
1268 1270 }
1269 1271
1270 1272 snprintf_blkptr_compact(blkbuf, sizeof (blkbuf), bp);
1271 1273 (void) printf("%s\n", blkbuf);
1272 1274 }
1273 1275
1274 1276 static int
1275 1277 visit_indirect(spa_t *spa, const dnode_phys_t *dnp,
1276 1278 blkptr_t *bp, const zbookmark_phys_t *zb)
1277 1279 {
1278 1280 int err = 0;
1279 1281
1280 1282 if (bp->blk_birth == 0)
1281 1283 return (0);
1282 1284
1283 1285 print_indirect(bp, zb, dnp);
1284 1286
1285 1287 if (BP_GET_LEVEL(bp) > 0 && !BP_IS_HOLE(bp)) {
1286 1288 arc_flags_t flags = ARC_FLAG_WAIT;
1287 1289 int i;
1288 1290 blkptr_t *cbp;
1289 1291 int epb = BP_GET_LSIZE(bp) >> SPA_BLKPTRSHIFT;
1290 1292 arc_buf_t *buf;
1291 1293 uint64_t fill = 0;
1292 1294
1293 1295 err = arc_read(NULL, spa, bp, arc_getbuf_func, &buf,
1294 1296 ZIO_PRIORITY_ASYNC_READ, ZIO_FLAG_CANFAIL, &flags, zb);
1295 1297 if (err)
1296 1298 return (err);
1297 1299 ASSERT(buf->b_data);
1298 1300
1299 1301 /* recursively visit blocks below this */
1300 1302 cbp = buf->b_data;
1301 1303 for (i = 0; i < epb; i++, cbp++) {
1302 1304 zbookmark_phys_t czb;
1303 1305
1304 1306 SET_BOOKMARK(&czb, zb->zb_objset, zb->zb_object,
1305 1307 zb->zb_level - 1,
1306 1308 zb->zb_blkid * epb + i);
1307 1309 err = visit_indirect(spa, dnp, cbp, &czb);
1308 1310 if (err)
1309 1311 break;
1310 1312 fill += BP_GET_FILL(cbp);
1311 1313 }
1312 1314 if (!err)
1313 1315 ASSERT3U(fill, ==, BP_GET_FILL(bp));
1314 1316 arc_buf_destroy(buf, &buf);
1315 1317 }
1316 1318
1317 1319 return (err);
1318 1320 }
1319 1321
1320 1322 /*ARGSUSED*/
1321 1323 static void
1322 1324 dump_indirect(dnode_t *dn)
1323 1325 {
1324 1326 dnode_phys_t *dnp = dn->dn_phys;
1325 1327 int j;
1326 1328 zbookmark_phys_t czb;
1327 1329
1328 1330 (void) printf("Indirect blocks:\n");
1329 1331
1330 1332 SET_BOOKMARK(&czb, dmu_objset_id(dn->dn_objset),
1331 1333 dn->dn_object, dnp->dn_nlevels - 1, 0);
1332 1334 for (j = 0; j < dnp->dn_nblkptr; j++) {
1333 1335 czb.zb_blkid = j;
1334 1336 (void) visit_indirect(dmu_objset_spa(dn->dn_objset), dnp,
1335 1337 &dnp->dn_blkptr[j], &czb);
1336 1338 }
1337 1339
1338 1340 (void) printf("\n");
1339 1341 }
1340 1342
1341 1343 /*ARGSUSED*/
1342 1344 static void
1343 1345 dump_dsl_dir(objset_t *os, uint64_t object, void *data, size_t size)
1344 1346 {
1345 1347 dsl_dir_phys_t *dd = data;
1346 1348 time_t crtime;
1347 1349 char nice[32];
1348 1350
1349 1351 /* make sure nicenum has enough space */
1350 1352 CTASSERT(sizeof (nice) >= NN_NUMBUF_SZ);
1351 1353
1352 1354 if (dd == NULL)
1353 1355 return;
1354 1356
1355 1357 ASSERT3U(size, >=, sizeof (dsl_dir_phys_t));
1356 1358
1357 1359 crtime = dd->dd_creation_time;
1358 1360 (void) printf("\t\tcreation_time = %s", ctime(&crtime));
1359 1361 (void) printf("\t\thead_dataset_obj = %llu\n",
1360 1362 (u_longlong_t)dd->dd_head_dataset_obj);
1361 1363 (void) printf("\t\tparent_dir_obj = %llu\n",
1362 1364 (u_longlong_t)dd->dd_parent_obj);
1363 1365 (void) printf("\t\torigin_obj = %llu\n",
1364 1366 (u_longlong_t)dd->dd_origin_obj);
1365 1367 (void) printf("\t\tchild_dir_zapobj = %llu\n",
1366 1368 (u_longlong_t)dd->dd_child_dir_zapobj);
1367 1369 zdb_nicenum(dd->dd_used_bytes, nice, sizeof (nice));
1368 1370 (void) printf("\t\tused_bytes = %s\n", nice);
1369 1371 zdb_nicenum(dd->dd_compressed_bytes, nice, sizeof (nice));
1370 1372 (void) printf("\t\tcompressed_bytes = %s\n", nice);
1371 1373 zdb_nicenum(dd->dd_uncompressed_bytes, nice, sizeof (nice));
1372 1374 (void) printf("\t\tuncompressed_bytes = %s\n", nice);
1373 1375 zdb_nicenum(dd->dd_quota, nice, sizeof (nice));
1374 1376 (void) printf("\t\tquota = %s\n", nice);
1375 1377 zdb_nicenum(dd->dd_reserved, nice, sizeof (nice));
1376 1378 (void) printf("\t\treserved = %s\n", nice);
1377 1379 (void) printf("\t\tprops_zapobj = %llu\n",
1378 1380 (u_longlong_t)dd->dd_props_zapobj);
1379 1381 (void) printf("\t\tdeleg_zapobj = %llu\n",
1380 1382 (u_longlong_t)dd->dd_deleg_zapobj);
1381 1383 (void) printf("\t\tflags = %llx\n",
1382 1384 (u_longlong_t)dd->dd_flags);
1383 1385
1384 1386 #define DO(which) \
1385 1387 zdb_nicenum(dd->dd_used_breakdown[DD_USED_ ## which], nice, \
1386 1388 sizeof (nice)); \
1387 1389 (void) printf("\t\tused_breakdown[" #which "] = %s\n", nice)
1388 1390 DO(HEAD);
1389 1391 DO(SNAP);
1390 1392 DO(CHILD);
1391 1393 DO(CHILD_RSRV);
1392 1394 DO(REFRSRV);
1393 1395 #undef DO
1394 1396 }
1395 1397
1396 1398 /*ARGSUSED*/
1397 1399 static void
1398 1400 dump_dsl_dataset(objset_t *os, uint64_t object, void *data, size_t size)
1399 1401 {
1400 1402 dsl_dataset_phys_t *ds = data;
1401 1403 time_t crtime;
1402 1404 char used[32], compressed[32], uncompressed[32], unique[32];
1403 1405 char blkbuf[BP_SPRINTF_LEN];
1404 1406
1405 1407 /* make sure nicenum has enough space */
1406 1408 CTASSERT(sizeof (used) >= NN_NUMBUF_SZ);
1407 1409 CTASSERT(sizeof (compressed) >= NN_NUMBUF_SZ);
1408 1410 CTASSERT(sizeof (uncompressed) >= NN_NUMBUF_SZ);
1409 1411 CTASSERT(sizeof (unique) >= NN_NUMBUF_SZ);
1410 1412
1411 1413 if (ds == NULL)
1412 1414 return;
1413 1415
1414 1416 ASSERT(size == sizeof (*ds));
1415 1417 crtime = ds->ds_creation_time;
1416 1418 zdb_nicenum(ds->ds_referenced_bytes, used, sizeof (used));
1417 1419 zdb_nicenum(ds->ds_compressed_bytes, compressed, sizeof (compressed));
1418 1420 zdb_nicenum(ds->ds_uncompressed_bytes, uncompressed,
1419 1421 sizeof (uncompressed));
1420 1422 zdb_nicenum(ds->ds_unique_bytes, unique, sizeof (unique));
1421 1423 snprintf_blkptr(blkbuf, sizeof (blkbuf), &ds->ds_bp);
1422 1424
1423 1425 (void) printf("\t\tdir_obj = %llu\n",
1424 1426 (u_longlong_t)ds->ds_dir_obj);
1425 1427 (void) printf("\t\tprev_snap_obj = %llu\n",
1426 1428 (u_longlong_t)ds->ds_prev_snap_obj);
1427 1429 (void) printf("\t\tprev_snap_txg = %llu\n",
1428 1430 (u_longlong_t)ds->ds_prev_snap_txg);
1429 1431 (void) printf("\t\tnext_snap_obj = %llu\n",
1430 1432 (u_longlong_t)ds->ds_next_snap_obj);
1431 1433 (void) printf("\t\tsnapnames_zapobj = %llu\n",
1432 1434 (u_longlong_t)ds->ds_snapnames_zapobj);
1433 1435 (void) printf("\t\tnum_children = %llu\n",
1434 1436 (u_longlong_t)ds->ds_num_children);
1435 1437 (void) printf("\t\tuserrefs_obj = %llu\n",
1436 1438 (u_longlong_t)ds->ds_userrefs_obj);
1437 1439 (void) printf("\t\tcreation_time = %s", ctime(&crtime));
1438 1440 (void) printf("\t\tcreation_txg = %llu\n",
1439 1441 (u_longlong_t)ds->ds_creation_txg);
1440 1442 (void) printf("\t\tdeadlist_obj = %llu\n",
1441 1443 (u_longlong_t)ds->ds_deadlist_obj);
1442 1444 (void) printf("\t\tused_bytes = %s\n", used);
1443 1445 (void) printf("\t\tcompressed_bytes = %s\n", compressed);
1444 1446 (void) printf("\t\tuncompressed_bytes = %s\n", uncompressed);
1445 1447 (void) printf("\t\tunique = %s\n", unique);
1446 1448 (void) printf("\t\tfsid_guid = %llu\n",
1447 1449 (u_longlong_t)ds->ds_fsid_guid);
1448 1450 (void) printf("\t\tguid = %llu\n",
1449 1451 (u_longlong_t)ds->ds_guid);
1450 1452 (void) printf("\t\tflags = %llx\n",
1451 1453 (u_longlong_t)ds->ds_flags);
1452 1454 (void) printf("\t\tnext_clones_obj = %llu\n",
1453 1455 (u_longlong_t)ds->ds_next_clones_obj);
1454 1456 (void) printf("\t\tprops_obj = %llu\n",
1455 1457 (u_longlong_t)ds->ds_props_obj);
1456 1458 (void) printf("\t\tbp = %s\n", blkbuf);
1457 1459 }
1458 1460
1459 1461 /* ARGSUSED */
1460 1462 static int
1461 1463 dump_bptree_cb(void *arg, const blkptr_t *bp, dmu_tx_t *tx)
1462 1464 {
1463 1465 char blkbuf[BP_SPRINTF_LEN];
1464 1466
1465 1467 if (bp->blk_birth != 0) {
1466 1468 snprintf_blkptr(blkbuf, sizeof (blkbuf), bp);
1467 1469 (void) printf("\t%s\n", blkbuf);
1468 1470 }
1469 1471 return (0);
1470 1472 }
1471 1473
1472 1474 static void
1473 1475 dump_bptree(objset_t *os, uint64_t obj, const char *name)
1474 1476 {
1475 1477 char bytes[32];
1476 1478 bptree_phys_t *bt;
1477 1479 dmu_buf_t *db;
1478 1480
1479 1481 /* make sure nicenum has enough space */
1480 1482 CTASSERT(sizeof (bytes) >= NN_NUMBUF_SZ);
1481 1483
1482 1484 if (dump_opt['d'] < 3)
1483 1485 return;
1484 1486
1485 1487 VERIFY3U(0, ==, dmu_bonus_hold(os, obj, FTAG, &db));
1486 1488 bt = db->db_data;
1487 1489 zdb_nicenum(bt->bt_bytes, bytes, sizeof (bytes));
1488 1490 (void) printf("\n %s: %llu datasets, %s\n",
1489 1491 name, (unsigned long long)(bt->bt_end - bt->bt_begin), bytes);
1490 1492 dmu_buf_rele(db, FTAG);
1491 1493
1492 1494 if (dump_opt['d'] < 5)
1493 1495 return;
1494 1496
1495 1497 (void) printf("\n");
1496 1498
1497 1499 (void) bptree_iterate(os, obj, B_FALSE, dump_bptree_cb, NULL, NULL);
1498 1500 }
1499 1501
1500 1502 /* ARGSUSED */
1501 1503 static int
1502 1504 dump_bpobj_cb(void *arg, const blkptr_t *bp, dmu_tx_t *tx)
1503 1505 {
1504 1506 char blkbuf[BP_SPRINTF_LEN];
1505 1507
1506 1508 ASSERT(bp->blk_birth != 0);
1507 1509 snprintf_blkptr_compact(blkbuf, sizeof (blkbuf), bp);
1508 1510 (void) printf("\t%s\n", blkbuf);
1509 1511 return (0);
1510 1512 }
1511 1513
1512 1514 static void
1513 1515 dump_full_bpobj(bpobj_t *bpo, const char *name, int indent)
1514 1516 {
1515 1517 char bytes[32];
1516 1518 char comp[32];
1517 1519 char uncomp[32];
1518 1520
1519 1521 /* make sure nicenum has enough space */
1520 1522 CTASSERT(sizeof (bytes) >= NN_NUMBUF_SZ);
1521 1523 CTASSERT(sizeof (comp) >= NN_NUMBUF_SZ);
1522 1524 CTASSERT(sizeof (uncomp) >= NN_NUMBUF_SZ);
1523 1525
1524 1526 if (dump_opt['d'] < 3)
1525 1527 return;
1526 1528
1527 1529 zdb_nicenum(bpo->bpo_phys->bpo_bytes, bytes, sizeof (bytes));
1528 1530 if (bpo->bpo_havesubobj && bpo->bpo_phys->bpo_subobjs != 0) {
1529 1531 zdb_nicenum(bpo->bpo_phys->bpo_comp, comp, sizeof (comp));
1530 1532 zdb_nicenum(bpo->bpo_phys->bpo_uncomp, uncomp, sizeof (uncomp));
1531 1533 (void) printf(" %*s: object %llu, %llu local blkptrs, "
1532 1534 "%llu subobjs in object %llu, %s (%s/%s comp)\n",
1533 1535 indent * 8, name,
1534 1536 (u_longlong_t)bpo->bpo_object,
1535 1537 (u_longlong_t)bpo->bpo_phys->bpo_num_blkptrs,
1536 1538 (u_longlong_t)bpo->bpo_phys->bpo_num_subobjs,
1537 1539 (u_longlong_t)bpo->bpo_phys->bpo_subobjs,
1538 1540 bytes, comp, uncomp);
1539 1541
1540 1542 for (uint64_t i = 0; i < bpo->bpo_phys->bpo_num_subobjs; i++) {
1541 1543 uint64_t subobj;
1542 1544 bpobj_t subbpo;
1543 1545 int error;
1544 1546 VERIFY0(dmu_read(bpo->bpo_os,
1545 1547 bpo->bpo_phys->bpo_subobjs,
1546 1548 i * sizeof (subobj), sizeof (subobj), &subobj, 0));
1547 1549 error = bpobj_open(&subbpo, bpo->bpo_os, subobj);
1548 1550 if (error != 0) {
1549 1551 (void) printf("ERROR %u while trying to open "
1550 1552 "subobj id %llu\n",
1551 1553 error, (u_longlong_t)subobj);
1552 1554 continue;
1553 1555 }
1554 1556 dump_full_bpobj(&subbpo, "subobj", indent + 1);
1555 1557 bpobj_close(&subbpo);
1556 1558 }
1557 1559 } else {
1558 1560 (void) printf(" %*s: object %llu, %llu blkptrs, %s\n",
1559 1561 indent * 8, name,
1560 1562 (u_longlong_t)bpo->bpo_object,
1561 1563 (u_longlong_t)bpo->bpo_phys->bpo_num_blkptrs,
1562 1564 bytes);
1563 1565 }
1564 1566
1565 1567 if (dump_opt['d'] < 5)
1566 1568 return;
1567 1569
1568 1570
1569 1571 if (indent == 0) {
1570 1572 (void) bpobj_iterate_nofree(bpo, dump_bpobj_cb, NULL, NULL);
1571 1573 (void) printf("\n");
1572 1574 }
1573 1575 }
1574 1576
1575 1577 static void
1576 1578 dump_deadlist(dsl_deadlist_t *dl)
1577 1579 {
1578 1580 dsl_deadlist_entry_t *dle;
1579 1581 uint64_t unused;
1580 1582 char bytes[32];
1581 1583 char comp[32];
1582 1584 char uncomp[32];
1583 1585
1584 1586 /* make sure nicenum has enough space */
1585 1587 CTASSERT(sizeof (bytes) >= NN_NUMBUF_SZ);
1586 1588 CTASSERT(sizeof (comp) >= NN_NUMBUF_SZ);
1587 1589 CTASSERT(sizeof (uncomp) >= NN_NUMBUF_SZ);
1588 1590
1589 1591 if (dump_opt['d'] < 3)
1590 1592 return;
1591 1593
1592 1594 if (dl->dl_oldfmt) {
1593 1595 dump_full_bpobj(&dl->dl_bpobj, "old-format deadlist", 0);
1594 1596 return;
1595 1597 }
1596 1598
1597 1599 zdb_nicenum(dl->dl_phys->dl_used, bytes, sizeof (bytes));
1598 1600 zdb_nicenum(dl->dl_phys->dl_comp, comp, sizeof (comp));
1599 1601 zdb_nicenum(dl->dl_phys->dl_uncomp, uncomp, sizeof (uncomp));
1600 1602 (void) printf("\n Deadlist: %s (%s/%s comp)\n",
1601 1603 bytes, comp, uncomp);
1602 1604
1603 1605 if (dump_opt['d'] < 4)
1604 1606 return;
1605 1607
1606 1608 (void) printf("\n");
1607 1609
1608 1610 /* force the tree to be loaded */
1609 1611 dsl_deadlist_space_range(dl, 0, UINT64_MAX, &unused, &unused, &unused);
1610 1612
1611 1613 for (dle = avl_first(&dl->dl_tree); dle;
1612 1614 dle = AVL_NEXT(&dl->dl_tree, dle)) {
1613 1615 if (dump_opt['d'] >= 5) {
1614 1616 char buf[128];
1615 1617 (void) snprintf(buf, sizeof (buf),
1616 1618 "mintxg %llu -> obj %llu",
1617 1619 (longlong_t)dle->dle_mintxg,
1618 1620 (longlong_t)dle->dle_bpobj.bpo_object);
1619 1621
1620 1622 dump_full_bpobj(&dle->dle_bpobj, buf, 0);
1621 1623 } else {
1622 1624 (void) printf("mintxg %llu -> obj %llu\n",
1623 1625 (longlong_t)dle->dle_mintxg,
1624 1626 (longlong_t)dle->dle_bpobj.bpo_object);
1625 1627
1626 1628 }
1627 1629 }
1628 1630 }
1629 1631
1630 1632 static avl_tree_t idx_tree;
1631 1633 static avl_tree_t domain_tree;
1632 1634 static boolean_t fuid_table_loaded;
1633 1635 static objset_t *sa_os = NULL;
1634 1636 static sa_attr_type_t *sa_attr_table = NULL;
1635 1637
1636 1638 static int
1637 1639 open_objset(const char *path, dmu_objset_type_t type, void *tag, objset_t **osp)
1638 1640 {
1639 1641 int err;
1640 1642 uint64_t sa_attrs = 0;
1641 1643 uint64_t version = 0;
1642 1644
1643 1645 VERIFY3P(sa_os, ==, NULL);
1644 1646 err = dmu_objset_own(path, type, B_TRUE, tag, osp);
1645 1647 if (err != 0) {
1646 1648 (void) fprintf(stderr, "failed to own dataset '%s': %s\n", path,
1647 1649 strerror(err));
1648 1650 return (err);
1649 1651 }
1650 1652
1651 1653 if (dmu_objset_type(*osp) == DMU_OST_ZFS) {
1652 1654 (void) zap_lookup(*osp, MASTER_NODE_OBJ, ZPL_VERSION_STR,
1653 1655 8, 1, &version);
1654 1656 if (version >= ZPL_VERSION_SA) {
1655 1657 (void) zap_lookup(*osp, MASTER_NODE_OBJ, ZFS_SA_ATTRS,
1656 1658 8, 1, &sa_attrs);
1657 1659 }
1658 1660 err = sa_setup(*osp, sa_attrs, zfs_attr_table, ZPL_END,
1659 1661 &sa_attr_table);
1660 1662 if (err != 0) {
1661 1663 (void) fprintf(stderr, "sa_setup failed: %s\n",
1662 1664 strerror(err));
1663 1665 dmu_objset_disown(*osp, tag);
1664 1666 *osp = NULL;
1665 1667 }
1666 1668 }
1667 1669 sa_os = *osp;
1668 1670
1669 1671 return (0);
1670 1672 }
1671 1673
1672 1674 static void
1673 1675 close_objset(objset_t *os, void *tag)
1674 1676 {
1675 1677 VERIFY3P(os, ==, sa_os);
1676 1678 if (os->os_sa != NULL)
1677 1679 sa_tear_down(os);
1678 1680 dmu_objset_disown(os, tag);
1679 1681 sa_attr_table = NULL;
1680 1682 sa_os = NULL;
1681 1683 }
1682 1684
1683 1685 static void
1684 1686 fuid_table_destroy()
1685 1687 {
1686 1688 if (fuid_table_loaded) {
1687 1689 zfs_fuid_table_destroy(&idx_tree, &domain_tree);
1688 1690 fuid_table_loaded = B_FALSE;
1689 1691 }
1690 1692 }
1691 1693
1692 1694 /*
1693 1695 * print uid or gid information.
1694 1696 * For normal POSIX id just the id is printed in decimal format.
1695 1697 * For CIFS files with FUID the fuid is printed in hex followed by
1696 1698 * the domain-rid string.
1697 1699 */
1698 1700 static void
1699 1701 print_idstr(uint64_t id, const char *id_type)
1700 1702 {
1701 1703 if (FUID_INDEX(id)) {
1702 1704 char *domain;
1703 1705
1704 1706 domain = zfs_fuid_idx_domain(&idx_tree, FUID_INDEX(id));
1705 1707 (void) printf("\t%s %llx [%s-%d]\n", id_type,
1706 1708 (u_longlong_t)id, domain, (int)FUID_RID(id));
1707 1709 } else {
1708 1710 (void) printf("\t%s %llu\n", id_type, (u_longlong_t)id);
1709 1711 }
1710 1712
1711 1713 }
1712 1714
1713 1715 static void
1714 1716 dump_uidgid(objset_t *os, uint64_t uid, uint64_t gid)
1715 1717 {
1716 1718 uint32_t uid_idx, gid_idx;
1717 1719
1718 1720 uid_idx = FUID_INDEX(uid);
1719 1721 gid_idx = FUID_INDEX(gid);
1720 1722
1721 1723 /* Load domain table, if not already loaded */
1722 1724 if (!fuid_table_loaded && (uid_idx || gid_idx)) {
1723 1725 uint64_t fuid_obj;
1724 1726
1725 1727 /* first find the fuid object. It lives in the master node */
1726 1728 VERIFY(zap_lookup(os, MASTER_NODE_OBJ, ZFS_FUID_TABLES,
1727 1729 8, 1, &fuid_obj) == 0);
1728 1730 zfs_fuid_avl_tree_create(&idx_tree, &domain_tree);
1729 1731 (void) zfs_fuid_table_load(os, fuid_obj,
1730 1732 &idx_tree, &domain_tree);
1731 1733 fuid_table_loaded = B_TRUE;
1732 1734 }
1733 1735
1734 1736 print_idstr(uid, "uid");
1735 1737 print_idstr(gid, "gid");
1736 1738 }
1737 1739
1738 1740 /*ARGSUSED*/
1739 1741 static void
1740 1742 dump_znode(objset_t *os, uint64_t object, void *data, size_t size)
1741 1743 {
1742 1744 char path[MAXPATHLEN * 2]; /* allow for xattr and failure prefix */
1743 1745 sa_handle_t *hdl;
1744 1746 uint64_t xattr, rdev, gen;
1745 1747 uint64_t uid, gid, mode, fsize, parent, links;
1746 1748 uint64_t pflags;
1747 1749 uint64_t acctm[2], modtm[2], chgtm[2], crtm[2];
1748 1750 time_t z_crtime, z_atime, z_mtime, z_ctime;
1749 1751 sa_bulk_attr_t bulk[12];
1750 1752 int idx = 0;
1751 1753 int error;
1752 1754
1753 1755 VERIFY3P(os, ==, sa_os);
1754 1756 if (sa_handle_get(os, object, NULL, SA_HDL_PRIVATE, &hdl)) {
1755 1757 (void) printf("Failed to get handle for SA znode\n");
1756 1758 return;
1757 1759 }
1758 1760
1759 1761 SA_ADD_BULK_ATTR(bulk, idx, sa_attr_table[ZPL_UID], NULL, &uid, 8);
1760 1762 SA_ADD_BULK_ATTR(bulk, idx, sa_attr_table[ZPL_GID], NULL, &gid, 8);
1761 1763 SA_ADD_BULK_ATTR(bulk, idx, sa_attr_table[ZPL_LINKS], NULL,
1762 1764 &links, 8);
1763 1765 SA_ADD_BULK_ATTR(bulk, idx, sa_attr_table[ZPL_GEN], NULL, &gen, 8);
1764 1766 SA_ADD_BULK_ATTR(bulk, idx, sa_attr_table[ZPL_MODE], NULL,
1765 1767 &mode, 8);
1766 1768 SA_ADD_BULK_ATTR(bulk, idx, sa_attr_table[ZPL_PARENT],
1767 1769 NULL, &parent, 8);
1768 1770 SA_ADD_BULK_ATTR(bulk, idx, sa_attr_table[ZPL_SIZE], NULL,
1769 1771 &fsize, 8);
1770 1772 SA_ADD_BULK_ATTR(bulk, idx, sa_attr_table[ZPL_ATIME], NULL,
1771 1773 acctm, 16);
1772 1774 SA_ADD_BULK_ATTR(bulk, idx, sa_attr_table[ZPL_MTIME], NULL,
1773 1775 modtm, 16);
1774 1776 SA_ADD_BULK_ATTR(bulk, idx, sa_attr_table[ZPL_CRTIME], NULL,
1775 1777 crtm, 16);
1776 1778 SA_ADD_BULK_ATTR(bulk, idx, sa_attr_table[ZPL_CTIME], NULL,
1777 1779 chgtm, 16);
1778 1780 SA_ADD_BULK_ATTR(bulk, idx, sa_attr_table[ZPL_FLAGS], NULL,
1779 1781 &pflags, 8);
1780 1782
1781 1783 if (sa_bulk_lookup(hdl, bulk, idx)) {
1782 1784 (void) sa_handle_destroy(hdl);
1783 1785 return;
1784 1786 }
1785 1787
1786 1788 z_crtime = (time_t)crtm[0];
1787 1789 z_atime = (time_t)acctm[0];
1788 1790 z_mtime = (time_t)modtm[0];
1789 1791 z_ctime = (time_t)chgtm[0];
1790 1792
1791 1793 if (dump_opt['d'] > 4) {
1792 1794 error = zfs_obj_to_path(os, object, path, sizeof (path));
1793 1795 if (error != 0) {
1794 1796 (void) snprintf(path, sizeof (path),
1795 1797 "\?\?\?<object#%llu>", (u_longlong_t)object);
1796 1798 }
1797 1799 (void) printf("\tpath %s\n", path);
1798 1800 }
1799 1801 dump_uidgid(os, uid, gid);
1800 1802 (void) printf("\tatime %s", ctime(&z_atime));
1801 1803 (void) printf("\tmtime %s", ctime(&z_mtime));
1802 1804 (void) printf("\tctime %s", ctime(&z_ctime));
1803 1805 (void) printf("\tcrtime %s", ctime(&z_crtime));
1804 1806 (void) printf("\tgen %llu\n", (u_longlong_t)gen);
1805 1807 (void) printf("\tmode %llo\n", (u_longlong_t)mode);
1806 1808 (void) printf("\tsize %llu\n", (u_longlong_t)fsize);
1807 1809 (void) printf("\tparent %llu\n", (u_longlong_t)parent);
1808 1810 (void) printf("\tlinks %llu\n", (u_longlong_t)links);
1809 1811 (void) printf("\tpflags %llx\n", (u_longlong_t)pflags);
1810 1812 if (sa_lookup(hdl, sa_attr_table[ZPL_XATTR], &xattr,
1811 1813 sizeof (uint64_t)) == 0)
1812 1814 (void) printf("\txattr %llu\n", (u_longlong_t)xattr);
1813 1815 if (sa_lookup(hdl, sa_attr_table[ZPL_RDEV], &rdev,
1814 1816 sizeof (uint64_t)) == 0)
1815 1817 (void) printf("\trdev 0x%016llx\n", (u_longlong_t)rdev);
1816 1818 sa_handle_destroy(hdl);
1817 1819 }
1818 1820
1819 1821 /*ARGSUSED*/
1820 1822 static void
1821 1823 dump_acl(objset_t *os, uint64_t object, void *data, size_t size)
1822 1824 {
1823 1825 }
1824 1826
1825 1827 /*ARGSUSED*/
1826 1828 static void
1827 1829 dump_dmu_objset(objset_t *os, uint64_t object, void *data, size_t size)
1828 1830 {
1829 1831 }
1830 1832
1831 1833 static object_viewer_t *object_viewer[DMU_OT_NUMTYPES + 1] = {
1832 1834 dump_none, /* unallocated */
1833 1835 dump_zap, /* object directory */
1834 1836 dump_uint64, /* object array */
1835 1837 dump_none, /* packed nvlist */
1836 1838 dump_packed_nvlist, /* packed nvlist size */
1837 1839 dump_none, /* bpobj */
1838 1840 dump_bpobj, /* bpobj header */
1839 1841 dump_none, /* SPA space map header */
1840 1842 dump_none, /* SPA space map */
1841 1843 dump_none, /* ZIL intent log */
1842 1844 dump_dnode, /* DMU dnode */
1843 1845 dump_dmu_objset, /* DMU objset */
1844 1846 dump_dsl_dir, /* DSL directory */
1845 1847 dump_zap, /* DSL directory child map */
1846 1848 dump_zap, /* DSL dataset snap map */
1847 1849 dump_zap, /* DSL props */
1848 1850 dump_dsl_dataset, /* DSL dataset */
1849 1851 dump_znode, /* ZFS znode */
1850 1852 dump_acl, /* ZFS V0 ACL */
1851 1853 dump_uint8, /* ZFS plain file */
1852 1854 dump_zpldir, /* ZFS directory */
1853 1855 dump_zap, /* ZFS master node */
1854 1856 dump_zap, /* ZFS delete queue */
1855 1857 dump_uint8, /* zvol object */
1856 1858 dump_zap, /* zvol prop */
1857 1859 dump_uint8, /* other uint8[] */
1858 1860 dump_uint64, /* other uint64[] */
1859 1861 dump_zap, /* other ZAP */
1860 1862 dump_zap, /* persistent error log */
1861 1863 dump_uint8, /* SPA history */
1862 1864 dump_history_offsets, /* SPA history offsets */
1863 1865 dump_zap, /* Pool properties */
1864 1866 dump_zap, /* DSL permissions */
1865 1867 dump_acl, /* ZFS ACL */
1866 1868 dump_uint8, /* ZFS SYSACL */
1867 1869 dump_none, /* FUID nvlist */
1868 1870 dump_packed_nvlist, /* FUID nvlist size */
1869 1871 dump_zap, /* DSL dataset next clones */
1870 1872 dump_zap, /* DSL scrub queue */
1871 1873 dump_zap, /* ZFS user/group used */
1872 1874 dump_zap, /* ZFS user/group quota */
1873 1875 dump_zap, /* snapshot refcount tags */
1874 1876 dump_ddt_zap, /* DDT ZAP object */
1875 1877 dump_zap, /* DDT statistics */
1876 1878 dump_znode, /* SA object */
1877 1879 dump_zap, /* SA Master Node */
1878 1880 dump_sa_attrs, /* SA attribute registration */
1879 1881 dump_sa_layouts, /* SA attribute layouts */
1880 1882 dump_zap, /* DSL scrub translations */
1881 1883 dump_none, /* fake dedup BP */
1882 1884 dump_zap, /* deadlist */
1883 1885 dump_none, /* deadlist hdr */
1884 1886 dump_zap, /* dsl clones */
1885 1887 dump_bpobj_subobjs, /* bpobj subobjs */
1886 1888 dump_unknown, /* Unknown type, must be last */
1887 1889 };
1888 1890
1889 1891 static void
1890 1892 dump_object(objset_t *os, uint64_t object, int verbosity, int *print_header)
1891 1893 {
1892 1894 dmu_buf_t *db = NULL;
1893 1895 dmu_object_info_t doi;
1894 1896 dnode_t *dn;
1895 1897 void *bonus = NULL;
1896 1898 size_t bsize = 0;
1897 1899 char iblk[32], dblk[32], lsize[32], asize[32], fill[32];
1898 1900 char bonus_size[32];
1899 1901 char aux[50];
1900 1902 int error;
1901 1903
1902 1904 /* make sure nicenum has enough space */
1903 1905 CTASSERT(sizeof (iblk) >= NN_NUMBUF_SZ);
1904 1906 CTASSERT(sizeof (dblk) >= NN_NUMBUF_SZ);
1905 1907 CTASSERT(sizeof (lsize) >= NN_NUMBUF_SZ);
1906 1908 CTASSERT(sizeof (asize) >= NN_NUMBUF_SZ);
1907 1909 CTASSERT(sizeof (bonus_size) >= NN_NUMBUF_SZ);
1908 1910
1909 1911 if (*print_header) {
1910 1912 (void) printf("\n%10s %3s %5s %5s %5s %5s %6s %s\n",
1911 1913 "Object", "lvl", "iblk", "dblk", "dsize", "lsize",
1912 1914 "%full", "type");
1913 1915 *print_header = 0;
1914 1916 }
1915 1917
1916 1918 if (object == 0) {
1917 1919 dn = DMU_META_DNODE(os);
1918 1920 } else {
1919 1921 error = dmu_bonus_hold(os, object, FTAG, &db);
1920 1922 if (error)
1921 1923 fatal("dmu_bonus_hold(%llu) failed, errno %u",
1922 1924 object, error);
1923 1925 bonus = db->db_data;
1924 1926 bsize = db->db_size;
1925 1927 dn = DB_DNODE((dmu_buf_impl_t *)db);
1926 1928 }
1927 1929 dmu_object_info_from_dnode(dn, &doi);
1928 1930
1929 1931 zdb_nicenum(doi.doi_metadata_block_size, iblk, sizeof (iblk));
1930 1932 zdb_nicenum(doi.doi_data_block_size, dblk, sizeof (dblk));
1931 1933 zdb_nicenum(doi.doi_max_offset, lsize, sizeof (lsize));
1932 1934 zdb_nicenum(doi.doi_physical_blocks_512 << 9, asize, sizeof (asize));
1933 1935 zdb_nicenum(doi.doi_bonus_size, bonus_size, sizeof (bonus_size));
1934 1936 (void) sprintf(fill, "%6.2f", 100.0 * doi.doi_fill_count *
1935 1937 doi.doi_data_block_size / (object == 0 ? DNODES_PER_BLOCK : 1) /
1936 1938 doi.doi_max_offset);
1937 1939
1938 1940 aux[0] = '\0';
1939 1941
1940 1942 if (doi.doi_checksum != ZIO_CHECKSUM_INHERIT || verbosity >= 6) {
1941 1943 (void) snprintf(aux + strlen(aux), sizeof (aux), " (K=%s)",
1942 1944 ZDB_CHECKSUM_NAME(doi.doi_checksum));
1943 1945 }
1944 1946
1945 1947 if (doi.doi_compress != ZIO_COMPRESS_INHERIT || verbosity >= 6) {
1946 1948 (void) snprintf(aux + strlen(aux), sizeof (aux), " (Z=%s)",
1947 1949 ZDB_COMPRESS_NAME(doi.doi_compress));
1948 1950 }
1949 1951
1950 1952 (void) printf("%10lld %3u %5s %5s %5s %5s %6s %s%s\n",
1951 1953 (u_longlong_t)object, doi.doi_indirection, iblk, dblk,
1952 1954 asize, lsize, fill, ZDB_OT_NAME(doi.doi_type), aux);
1953 1955
1954 1956 if (doi.doi_bonus_type != DMU_OT_NONE && verbosity > 3) {
1955 1957 (void) printf("%10s %3s %5s %5s %5s %5s %6s %s\n",
1956 1958 "", "", "", "", "", bonus_size, "bonus",
1957 1959 ZDB_OT_NAME(doi.doi_bonus_type));
1958 1960 }
1959 1961
1960 1962 if (verbosity >= 4) {
1961 1963 (void) printf("\tdnode flags: %s%s%s\n",
1962 1964 (dn->dn_phys->dn_flags & DNODE_FLAG_USED_BYTES) ?
1963 1965 "USED_BYTES " : "",
1964 1966 (dn->dn_phys->dn_flags & DNODE_FLAG_USERUSED_ACCOUNTED) ?
1965 1967 "USERUSED_ACCOUNTED " : "",
1966 1968 (dn->dn_phys->dn_flags & DNODE_FLAG_SPILL_BLKPTR) ?
1967 1969 "SPILL_BLKPTR" : "");
1968 1970 (void) printf("\tdnode maxblkid: %llu\n",
1969 1971 (longlong_t)dn->dn_phys->dn_maxblkid);
1970 1972
1971 1973 object_viewer[ZDB_OT_TYPE(doi.doi_bonus_type)](os, object,
1972 1974 bonus, bsize);
1973 1975 object_viewer[ZDB_OT_TYPE(doi.doi_type)](os, object, NULL, 0);
1974 1976 *print_header = 1;
1975 1977 }
1976 1978
1977 1979 if (verbosity >= 5)
1978 1980 dump_indirect(dn);
1979 1981
1980 1982 if (verbosity >= 5) {
1981 1983 /*
1982 1984 * Report the list of segments that comprise the object.
1983 1985 */
1984 1986 uint64_t start = 0;
1985 1987 uint64_t end;
1986 1988 uint64_t blkfill = 1;
1987 1989 int minlvl = 1;
1988 1990
1989 1991 if (dn->dn_type == DMU_OT_DNODE) {
1990 1992 minlvl = 0;
1991 1993 blkfill = DNODES_PER_BLOCK;
1992 1994 }
1993 1995
1994 1996 for (;;) {
1995 1997 char segsize[32];
1996 1998 /* make sure nicenum has enough space */
1997 1999 CTASSERT(sizeof (segsize) >= NN_NUMBUF_SZ);
1998 2000 error = dnode_next_offset(dn,
1999 2001 0, &start, minlvl, blkfill, 0);
2000 2002 if (error)
2001 2003 break;
2002 2004 end = start;
2003 2005 error = dnode_next_offset(dn,
2004 2006 DNODE_FIND_HOLE, &end, minlvl, blkfill, 0);
2005 2007 zdb_nicenum(end - start, segsize, sizeof (segsize));
2006 2008 (void) printf("\t\tsegment [%016llx, %016llx)"
2007 2009 " size %5s\n", (u_longlong_t)start,
2008 2010 (u_longlong_t)end, segsize);
2009 2011 if (error)
2010 2012 break;
2011 2013 start = end;
2012 2014 }
2013 2015 }
2014 2016
2015 2017 if (db != NULL)
2016 2018 dmu_buf_rele(db, FTAG);
2017 2019 }
2018 2020
2019 2021 static const char *objset_types[DMU_OST_NUMTYPES] = {
2020 2022 "NONE", "META", "ZPL", "ZVOL", "OTHER", "ANY" };
2021 2023
2022 2024 static void
2023 2025 dump_dir(objset_t *os)
2024 2026 {
2025 2027 dmu_objset_stats_t dds;
2026 2028 uint64_t object, object_count;
2027 2029 uint64_t refdbytes, usedobjs, scratch;
2028 2030 char numbuf[32];
2029 2031 char blkbuf[BP_SPRINTF_LEN + 20];
2030 2032 char osname[ZFS_MAX_DATASET_NAME_LEN];
2031 2033 const char *type = "UNKNOWN";
2032 2034 int verbosity = dump_opt['d'];
2033 2035 int print_header = 1;
2034 2036 unsigned i;
2035 2037 int error;
2036 2038
2037 2039 /* make sure nicenum has enough space */
2038 2040 CTASSERT(sizeof (numbuf) >= NN_NUMBUF_SZ);
2039 2041
2040 2042 dsl_pool_config_enter(dmu_objset_pool(os), FTAG);
2041 2043 dmu_objset_fast_stat(os, &dds);
2042 2044 dsl_pool_config_exit(dmu_objset_pool(os), FTAG);
2043 2045
2044 2046 if (dds.dds_type < DMU_OST_NUMTYPES)
2045 2047 type = objset_types[dds.dds_type];
2046 2048
2047 2049 if (dds.dds_type == DMU_OST_META) {
2048 2050 dds.dds_creation_txg = TXG_INITIAL;
2049 2051 usedobjs = BP_GET_FILL(os->os_rootbp);
2050 2052 refdbytes = dsl_dir_phys(os->os_spa->spa_dsl_pool->dp_mos_dir)->
2051 2053 dd_used_bytes;
2052 2054 } else {
2053 2055 dmu_objset_space(os, &refdbytes, &scratch, &usedobjs, &scratch);
2054 2056 }
2055 2057
2056 2058 ASSERT3U(usedobjs, ==, BP_GET_FILL(os->os_rootbp));
2057 2059
2058 2060 zdb_nicenum(refdbytes, numbuf, sizeof (numbuf));
2059 2061
2060 2062 if (verbosity >= 4) {
2061 2063 (void) snprintf(blkbuf, sizeof (blkbuf), ", rootbp ");
2062 2064 (void) snprintf_blkptr(blkbuf + strlen(blkbuf),
2063 2065 sizeof (blkbuf) - strlen(blkbuf), os->os_rootbp);
2064 2066 } else {
2065 2067 blkbuf[0] = '\0';
2066 2068 }
2067 2069
2068 2070 dmu_objset_name(os, osname);
2069 2071
2070 2072 (void) printf("Dataset %s [%s], ID %llu, cr_txg %llu, "
2071 2073 "%s, %llu objects%s\n",
2072 2074 osname, type, (u_longlong_t)dmu_objset_id(os),
2073 2075 (u_longlong_t)dds.dds_creation_txg,
2074 2076 numbuf, (u_longlong_t)usedobjs, blkbuf);
2075 2077
2076 2078 if (zopt_objects != 0) {
2077 2079 for (i = 0; i < zopt_objects; i++)
2078 2080 dump_object(os, zopt_object[i], verbosity,
2079 2081 &print_header);
2080 2082 (void) printf("\n");
2081 2083 return;
2082 2084 }
2083 2085
2084 2086 if (dump_opt['i'] != 0 || verbosity >= 2)
2085 2087 dump_intent_log(dmu_objset_zil(os));
2086 2088
2087 2089 if (dmu_objset_ds(os) != NULL)
2088 2090 dump_deadlist(&dmu_objset_ds(os)->ds_deadlist);
2089 2091
2090 2092 if (verbosity < 2)
2091 2093 return;
2092 2094
2093 2095 if (BP_IS_HOLE(os->os_rootbp))
2094 2096 return;
2095 2097
2096 2098 dump_object(os, 0, verbosity, &print_header);
2097 2099 object_count = 0;
2098 2100 if (DMU_USERUSED_DNODE(os) != NULL &&
2099 2101 DMU_USERUSED_DNODE(os)->dn_type != 0) {
2100 2102 dump_object(os, DMU_USERUSED_OBJECT, verbosity, &print_header);
2101 2103 dump_object(os, DMU_GROUPUSED_OBJECT, verbosity, &print_header);
2102 2104 }
2103 2105
2104 2106 object = 0;
2105 2107 while ((error = dmu_object_next(os, &object, B_FALSE, 0)) == 0) {
2106 2108 dump_object(os, object, verbosity, &print_header);
2107 2109 object_count++;
2108 2110 }
2109 2111
2110 2112 ASSERT3U(object_count, ==, usedobjs);
2111 2113
2112 2114 (void) printf("\n");
2113 2115
2114 2116 if (error != ESRCH) {
2115 2117 (void) fprintf(stderr, "dmu_object_next() = %d\n", error);
2116 2118 abort();
2117 2119 }
2118 2120 }
2119 2121
2120 2122 static void
2121 2123 dump_uberblock(uberblock_t *ub, const char *header, const char *footer)
2122 2124 {
2123 2125 time_t timestamp = ub->ub_timestamp;
2124 2126
2125 2127 (void) printf("%s", header ? header : "");
2126 2128 (void) printf("\tmagic = %016llx\n", (u_longlong_t)ub->ub_magic);
2127 2129 (void) printf("\tversion = %llu\n", (u_longlong_t)ub->ub_version);
2128 2130 (void) printf("\ttxg = %llu\n", (u_longlong_t)ub->ub_txg);
2129 2131 (void) printf("\tguid_sum = %llu\n", (u_longlong_t)ub->ub_guid_sum);
2130 2132 (void) printf("\ttimestamp = %llu UTC = %s",
2131 2133 (u_longlong_t)ub->ub_timestamp, asctime(localtime(×tamp)));
2132 2134 if (dump_opt['u'] >= 3) {
2133 2135 char blkbuf[BP_SPRINTF_LEN];
2134 2136 snprintf_blkptr(blkbuf, sizeof (blkbuf), &ub->ub_rootbp);
2135 2137 (void) printf("\trootbp = %s\n", blkbuf);
2136 2138 }
2137 2139 (void) printf("%s", footer ? footer : "");
2138 2140 }
2139 2141
2140 2142 static void
2141 2143 dump_config(spa_t *spa)
2142 2144 {
2143 2145 dmu_buf_t *db;
2144 2146 size_t nvsize = 0;
2145 2147 int error = 0;
2146 2148
2147 2149
2148 2150 error = dmu_bonus_hold(spa->spa_meta_objset,
2149 2151 spa->spa_config_object, FTAG, &db);
2150 2152
2151 2153 if (error == 0) {
2152 2154 nvsize = *(uint64_t *)db->db_data;
2153 2155 dmu_buf_rele(db, FTAG);
2154 2156
2155 2157 (void) printf("\nMOS Configuration:\n");
2156 2158 dump_packed_nvlist(spa->spa_meta_objset,
2157 2159 spa->spa_config_object, (void *)&nvsize, 1);
2158 2160 } else {
2159 2161 (void) fprintf(stderr, "dmu_bonus_hold(%llu) failed, errno %d",
2160 2162 (u_longlong_t)spa->spa_config_object, error);
2161 2163 }
2162 2164 }
2163 2165
2164 2166 static void
2165 2167 dump_cachefile(const char *cachefile)
2166 2168 {
2167 2169 int fd;
2168 2170 struct stat64 statbuf;
2169 2171 char *buf;
2170 2172 nvlist_t *config;
2171 2173
2172 2174 if ((fd = open64(cachefile, O_RDONLY)) < 0) {
2173 2175 (void) printf("cannot open '%s': %s\n", cachefile,
2174 2176 strerror(errno));
2175 2177 exit(1);
2176 2178 }
2177 2179
2178 2180 if (fstat64(fd, &statbuf) != 0) {
2179 2181 (void) printf("failed to stat '%s': %s\n", cachefile,
2180 2182 strerror(errno));
2181 2183 exit(1);
2182 2184 }
2183 2185
2184 2186 if ((buf = malloc(statbuf.st_size)) == NULL) {
2185 2187 (void) fprintf(stderr, "failed to allocate %llu bytes\n",
2186 2188 (u_longlong_t)statbuf.st_size);
2187 2189 exit(1);
2188 2190 }
2189 2191
2190 2192 if (read(fd, buf, statbuf.st_size) != statbuf.st_size) {
2191 2193 (void) fprintf(stderr, "failed to read %llu bytes\n",
2192 2194 (u_longlong_t)statbuf.st_size);
2193 2195 exit(1);
2194 2196 }
2195 2197
2196 2198 (void) close(fd);
2197 2199
2198 2200 if (nvlist_unpack(buf, statbuf.st_size, &config, 0) != 0) {
2199 2201 (void) fprintf(stderr, "failed to unpack nvlist\n");
2200 2202 exit(1);
2201 2203 }
2202 2204
2203 2205 free(buf);
2204 2206
2205 2207 dump_nvlist(config, 0);
2206 2208
2207 2209 nvlist_free(config);
2208 2210 }
2209 2211
2210 2212 #define ZDB_MAX_UB_HEADER_SIZE 32
2211 2213
2212 2214 static void
2213 2215 dump_label_uberblocks(vdev_label_t *lbl, uint64_t ashift)
2214 2216 {
2215 2217 vdev_t vd;
2216 2218 vdev_t *vdp = &vd;
2217 2219 char header[ZDB_MAX_UB_HEADER_SIZE];
2218 2220
2219 2221 vd.vdev_ashift = ashift;
2220 2222 vdp->vdev_top = vdp;
2221 2223
2222 2224 for (int i = 0; i < VDEV_UBERBLOCK_COUNT(vdp); i++) {
2223 2225 uint64_t uoff = VDEV_UBERBLOCK_OFFSET(vdp, i);
2224 2226 uberblock_t *ub = (void *)((char *)lbl + uoff);
2225 2227
2226 2228 if (uberblock_verify(ub))
2227 2229 continue;
2228 2230 (void) snprintf(header, ZDB_MAX_UB_HEADER_SIZE,
2229 2231 "Uberblock[%d]\n", i);
2230 2232 dump_uberblock(ub, header, "");
2231 2233 }
2232 2234 }
2233 2235
2234 2236 static char curpath[PATH_MAX];
2235 2237
2236 2238 /*
2237 2239 * Iterate through the path components, recursively passing
2238 2240 * current one's obj and remaining path until we find the obj
2239 2241 * for the last one.
2240 2242 */
2241 2243 static int
2242 2244 dump_path_impl(objset_t *os, uint64_t obj, char *name)
2243 2245 {
2244 2246 int err;
2245 2247 int header = 1;
2246 2248 uint64_t child_obj;
2247 2249 char *s;
2248 2250 dmu_buf_t *db;
2249 2251 dmu_object_info_t doi;
2250 2252
2251 2253 if ((s = strchr(name, '/')) != NULL)
2252 2254 *s = '\0';
2253 2255 err = zap_lookup(os, obj, name, 8, 1, &child_obj);
2254 2256
2255 2257 (void) strlcat(curpath, name, sizeof (curpath));
2256 2258
2257 2259 if (err != 0) {
2258 2260 (void) fprintf(stderr, "failed to lookup %s: %s\n",
2259 2261 curpath, strerror(err));
2260 2262 return (err);
2261 2263 }
2262 2264
2263 2265 child_obj = ZFS_DIRENT_OBJ(child_obj);
2264 2266 err = sa_buf_hold(os, child_obj, FTAG, &db);
2265 2267 if (err != 0) {
2266 2268 (void) fprintf(stderr,
2267 2269 "failed to get SA dbuf for obj %llu: %s\n",
2268 2270 (u_longlong_t)child_obj, strerror(err));
2269 2271 return (EINVAL);
2270 2272 }
2271 2273 dmu_object_info_from_db(db, &doi);
2272 2274 sa_buf_rele(db, FTAG);
2273 2275
2274 2276 if (doi.doi_bonus_type != DMU_OT_SA &&
2275 2277 doi.doi_bonus_type != DMU_OT_ZNODE) {
2276 2278 (void) fprintf(stderr, "invalid bonus type %d for obj %llu\n",
2277 2279 doi.doi_bonus_type, (u_longlong_t)child_obj);
2278 2280 return (EINVAL);
2279 2281 }
2280 2282
2281 2283 if (dump_opt['v'] > 6) {
2282 2284 (void) printf("obj=%llu %s type=%d bonustype=%d\n",
2283 2285 (u_longlong_t)child_obj, curpath, doi.doi_type,
2284 2286 doi.doi_bonus_type);
2285 2287 }
2286 2288
2287 2289 (void) strlcat(curpath, "/", sizeof (curpath));
2288 2290
2289 2291 switch (doi.doi_type) {
2290 2292 case DMU_OT_DIRECTORY_CONTENTS:
2291 2293 if (s != NULL && *(s + 1) != '\0')
2292 2294 return (dump_path_impl(os, child_obj, s + 1));
2293 2295 /*FALLTHROUGH*/
2294 2296 case DMU_OT_PLAIN_FILE_CONTENTS:
2295 2297 dump_object(os, child_obj, dump_opt['v'], &header);
2296 2298 return (0);
2297 2299 default:
2298 2300 (void) fprintf(stderr, "object %llu has non-file/directory "
2299 2301 "type %d\n", (u_longlong_t)obj, doi.doi_type);
2300 2302 break;
2301 2303 }
2302 2304
2303 2305 return (EINVAL);
2304 2306 }
2305 2307
2306 2308 /*
2307 2309 * Dump the blocks for the object specified by path inside the dataset.
2308 2310 */
2309 2311 static int
2310 2312 dump_path(char *ds, char *path)
2311 2313 {
2312 2314 int err;
2313 2315 objset_t *os;
2314 2316 uint64_t root_obj;
2315 2317
2316 2318 err = open_objset(ds, DMU_OST_ZFS, FTAG, &os);
2317 2319 if (err != 0)
2318 2320 return (err);
2319 2321
2320 2322 err = zap_lookup(os, MASTER_NODE_OBJ, ZFS_ROOT_OBJ, 8, 1, &root_obj);
2321 2323 if (err != 0) {
2322 2324 (void) fprintf(stderr, "can't lookup root znode: %s\n",
2323 2325 strerror(err));
2324 2326 dmu_objset_disown(os, FTAG);
2325 2327 return (EINVAL);
2326 2328 }
2327 2329
2328 2330 (void) snprintf(curpath, sizeof (curpath), "dataset=%s path=/", ds);
2329 2331
2330 2332 err = dump_path_impl(os, root_obj, path);
2331 2333
2332 2334 close_objset(os, FTAG);
2333 2335 return (err);
2334 2336 }
2335 2337
2336 2338 static int
2337 2339 dump_label(const char *dev)
2338 2340 {
2339 2341 int fd;
2340 2342 vdev_label_t label;
2341 2343 char path[MAXPATHLEN];
2342 2344 char *buf = label.vl_vdev_phys.vp_nvlist;
2343 2345 size_t buflen = sizeof (label.vl_vdev_phys.vp_nvlist);
2344 2346 struct stat64 statbuf;
2345 2347 uint64_t psize, ashift;
2346 2348 boolean_t label_found = B_FALSE;
2347 2349
2348 2350 (void) strlcpy(path, dev, sizeof (path));
2349 2351 if (dev[0] == '/') {
2350 2352 if (strncmp(dev, ZFS_DISK_ROOTD,
2351 2353 strlen(ZFS_DISK_ROOTD)) == 0) {
2352 2354 (void) snprintf(path, sizeof (path), "%s%s",
2353 2355 ZFS_RDISK_ROOTD, dev + strlen(ZFS_DISK_ROOTD));
2354 2356 }
2355 2357 } else if (stat64(path, &statbuf) != 0) {
2356 2358 char *s;
2357 2359
2358 2360 (void) snprintf(path, sizeof (path), "%s%s", ZFS_RDISK_ROOTD,
2359 2361 dev);
2360 2362 if (((s = strrchr(dev, 's')) == NULL &&
2361 2363 (s = strchr(dev, 'p')) == NULL) ||
2362 2364 !isdigit(*(s + 1)))
2363 2365 (void) strlcat(path, "s0", sizeof (path));
2364 2366 }
2365 2367
2366 2368 if ((fd = open64(path, O_RDONLY)) < 0) {
2367 2369 (void) fprintf(stderr, "cannot open '%s': %s\n", path,
2368 2370 strerror(errno));
2369 2371 exit(1);
2370 2372 }
2371 2373
2372 2374 if (fstat64(fd, &statbuf) != 0) {
2373 2375 (void) fprintf(stderr, "failed to stat '%s': %s\n", path,
2374 2376 strerror(errno));
2375 2377 (void) close(fd);
2376 2378 exit(1);
2377 2379 }
2378 2380
2379 2381 if (S_ISBLK(statbuf.st_mode)) {
2380 2382 (void) fprintf(stderr,
2381 2383 "cannot use '%s': character device required\n", path);
2382 2384 (void) close(fd);
2383 2385 exit(1);
2384 2386 }
2385 2387
2386 2388 psize = statbuf.st_size;
2387 2389 psize = P2ALIGN(psize, (uint64_t)sizeof (vdev_label_t));
2388 2390
2389 2391 for (int l = 0; l < VDEV_LABELS; l++) {
2390 2392 nvlist_t *config = NULL;
2391 2393
2392 2394 if (!dump_opt['q']) {
2393 2395 (void) printf("------------------------------------\n");
2394 2396 (void) printf("LABEL %d\n", l);
2395 2397 (void) printf("------------------------------------\n");
2396 2398 }
2397 2399
2398 2400 if (pread64(fd, &label, sizeof (label),
2399 2401 vdev_label_offset(psize, l, 0)) != sizeof (label)) {
2400 2402 if (!dump_opt['q'])
2401 2403 (void) printf("failed to read label %d\n", l);
2402 2404 continue;
2403 2405 }
2404 2406
2405 2407 if (nvlist_unpack(buf, buflen, &config, 0) != 0) {
2406 2408 if (!dump_opt['q'])
2407 2409 (void) printf("failed to unpack label %d\n", l);
2408 2410 ashift = SPA_MINBLOCKSHIFT;
2409 2411 } else {
2410 2412 nvlist_t *vdev_tree = NULL;
2411 2413
2412 2414 if (!dump_opt['q'])
2413 2415 dump_nvlist(config, 4);
2414 2416 if ((nvlist_lookup_nvlist(config,
2415 2417 ZPOOL_CONFIG_VDEV_TREE, &vdev_tree) != 0) ||
2416 2418 (nvlist_lookup_uint64(vdev_tree,
2417 2419 ZPOOL_CONFIG_ASHIFT, &ashift) != 0))
2418 2420 ashift = SPA_MINBLOCKSHIFT;
2419 2421 nvlist_free(config);
2420 2422 label_found = B_TRUE;
2421 2423 }
2422 2424 if (dump_opt['u'])
2423 2425 dump_label_uberblocks(&label, ashift);
2424 2426 }
2425 2427
2426 2428 (void) close(fd);
2427 2429
2428 2430 return (label_found ? 0 : 2);
2429 2431 }
2430 2432
2431 2433 static uint64_t dataset_feature_count[SPA_FEATURES];
2432 2434
2433 2435 /*ARGSUSED*/
2434 2436 static int
2435 2437 dump_one_dir(const char *dsname, void *arg)
2436 2438 {
2437 2439 int error;
2438 2440 objset_t *os;
2439 2441
2440 2442 error = open_objset(dsname, DMU_OST_ANY, FTAG, &os);
2441 2443 if (error != 0)
2442 2444 return (0);
2443 2445
2444 2446 for (spa_feature_t f = 0; f < SPA_FEATURES; f++) {
2445 2447 if (!dmu_objset_ds(os)->ds_feature_inuse[f])
2446 2448 continue;
2447 2449 ASSERT(spa_feature_table[f].fi_flags &
2448 2450 ZFEATURE_FLAG_PER_DATASET);
2449 2451 dataset_feature_count[f]++;
2450 2452 }
2451 2453
2452 2454 dump_dir(os);
2453 2455 close_objset(os, FTAG);
2454 2456 fuid_table_destroy();
2455 2457 return (0);
2456 2458 }
2457 2459
2458 2460 /*
2459 2461 * Block statistics.
2460 2462 */
2461 2463 #define PSIZE_HISTO_SIZE (SPA_OLD_MAXBLOCKSIZE / SPA_MINBLOCKSIZE + 2)
2462 2464 typedef struct zdb_blkstats {
2463 2465 uint64_t zb_asize;
2464 2466 uint64_t zb_lsize;
2465 2467 uint64_t zb_psize;
2466 2468 uint64_t zb_count;
2467 2469 uint64_t zb_gangs;
2468 2470 uint64_t zb_ditto_samevdev;
2469 2471 uint64_t zb_psize_histogram[PSIZE_HISTO_SIZE];
2470 2472 } zdb_blkstats_t;
2471 2473
2472 2474 /*
2473 2475 * Extended object types to report deferred frees and dedup auto-ditto blocks.
2474 2476 */
2475 2477 #define ZDB_OT_DEFERRED (DMU_OT_NUMTYPES + 0)
2476 2478 #define ZDB_OT_DITTO (DMU_OT_NUMTYPES + 1)
2477 2479 #define ZDB_OT_OTHER (DMU_OT_NUMTYPES + 2)
2478 2480 #define ZDB_OT_TOTAL (DMU_OT_NUMTYPES + 3)
2479 2481
2480 2482 static const char *zdb_ot_extname[] = {
2481 2483 "deferred free",
2482 2484 "dedup ditto",
2483 2485 "other",
2484 2486 "Total",
2485 2487 };
2486 2488
2487 2489 #define ZB_TOTAL DN_MAX_LEVELS
2488 2490
2489 2491 typedef struct zdb_cb {
2490 2492 zdb_blkstats_t zcb_type[ZB_TOTAL + 1][ZDB_OT_TOTAL + 1];
2491 2493 uint64_t zcb_dedup_asize;
2492 2494 uint64_t zcb_dedup_blocks;
2493 2495 uint64_t zcb_embedded_blocks[NUM_BP_EMBEDDED_TYPES];
2494 2496 uint64_t zcb_embedded_histogram[NUM_BP_EMBEDDED_TYPES]
2495 2497 [BPE_PAYLOAD_SIZE];
2496 2498 uint64_t zcb_start;
2497 2499 hrtime_t zcb_lastprint;
2498 2500 uint64_t zcb_totalasize;
2499 2501 uint64_t zcb_errors[256];
2500 2502 int zcb_readfails;
2501 2503 int zcb_haderrors;
2502 2504 spa_t *zcb_spa;
2503 2505 } zdb_cb_t;
2504 2506
2505 2507 static void
2506 2508 zdb_count_block(zdb_cb_t *zcb, zilog_t *zilog, const blkptr_t *bp,
2507 2509 dmu_object_type_t type)
2508 2510 {
2509 2511 uint64_t refcnt = 0;
2510 2512
2511 2513 ASSERT(type < ZDB_OT_TOTAL);
2512 2514
2513 2515 if (zilog && zil_bp_tree_add(zilog, bp) != 0)
2514 2516 return;
2515 2517
2516 2518 for (int i = 0; i < 4; i++) {
2517 2519 int l = (i < 2) ? BP_GET_LEVEL(bp) : ZB_TOTAL;
2518 2520 int t = (i & 1) ? type : ZDB_OT_TOTAL;
2519 2521 int equal;
2520 2522 zdb_blkstats_t *zb = &zcb->zcb_type[l][t];
2521 2523
2522 2524 zb->zb_asize += BP_GET_ASIZE(bp);
2523 2525 zb->zb_lsize += BP_GET_LSIZE(bp);
2524 2526 zb->zb_psize += BP_GET_PSIZE(bp);
2525 2527 zb->zb_count++;
2526 2528
2527 2529 /*
2528 2530 * The histogram is only big enough to record blocks up to
2529 2531 * SPA_OLD_MAXBLOCKSIZE; larger blocks go into the last,
2530 2532 * "other", bucket.
2531 2533 */
2532 2534 unsigned idx = BP_GET_PSIZE(bp) >> SPA_MINBLOCKSHIFT;
2533 2535 idx = MIN(idx, SPA_OLD_MAXBLOCKSIZE / SPA_MINBLOCKSIZE + 1);
2534 2536 zb->zb_psize_histogram[idx]++;
2535 2537
2536 2538 zb->zb_gangs += BP_COUNT_GANG(bp);
2537 2539
2538 2540 switch (BP_GET_NDVAS(bp)) {
2539 2541 case 2:
2540 2542 if (DVA_GET_VDEV(&bp->blk_dva[0]) ==
2541 2543 DVA_GET_VDEV(&bp->blk_dva[1]))
2542 2544 zb->zb_ditto_samevdev++;
2543 2545 break;
2544 2546 case 3:
2545 2547 equal = (DVA_GET_VDEV(&bp->blk_dva[0]) ==
2546 2548 DVA_GET_VDEV(&bp->blk_dva[1])) +
2547 2549 (DVA_GET_VDEV(&bp->blk_dva[0]) ==
2548 2550 DVA_GET_VDEV(&bp->blk_dva[2])) +
2549 2551 (DVA_GET_VDEV(&bp->blk_dva[1]) ==
2550 2552 DVA_GET_VDEV(&bp->blk_dva[2]));
2551 2553 if (equal != 0)
2552 2554 zb->zb_ditto_samevdev++;
2553 2555 break;
2554 2556 }
2555 2557
2556 2558 }
2557 2559
2558 2560 if (BP_IS_EMBEDDED(bp)) {
2559 2561 zcb->zcb_embedded_blocks[BPE_GET_ETYPE(bp)]++;
2560 2562 zcb->zcb_embedded_histogram[BPE_GET_ETYPE(bp)]
2561 2563 [BPE_GET_PSIZE(bp)]++;
2562 2564 return;
2563 2565 }
2564 2566
2565 2567 if (dump_opt['L'])
2566 2568 return;
2567 2569
2568 2570 if (BP_GET_DEDUP(bp)) {
2569 2571 ddt_t *ddt;
2570 2572 ddt_entry_t *dde;
2571 2573
2572 2574 ddt = ddt_select(zcb->zcb_spa, bp);
2573 2575 ddt_enter(ddt);
2574 2576 dde = ddt_lookup(ddt, bp, B_FALSE);
2575 2577
2576 2578 if (dde == NULL) {
2577 2579 refcnt = 0;
2578 2580 } else {
2579 2581 ddt_phys_t *ddp = ddt_phys_select(dde, bp);
2580 2582 ddt_phys_decref(ddp);
2581 2583 refcnt = ddp->ddp_refcnt;
2582 2584 if (ddt_phys_total_refcnt(dde) == 0)
2583 2585 ddt_remove(ddt, dde);
2584 2586 }
2585 2587 ddt_exit(ddt);
2586 2588 }
2587 2589
2588 2590 VERIFY3U(zio_wait(zio_claim(NULL, zcb->zcb_spa,
2589 2591 refcnt ? 0 : spa_first_txg(zcb->zcb_spa),
2590 2592 bp, NULL, NULL, ZIO_FLAG_CANFAIL)), ==, 0);
2591 2593 }
2592 2594
2593 2595 static void
2594 2596 zdb_blkptr_done(zio_t *zio)
2595 2597 {
2596 2598 spa_t *spa = zio->io_spa;
2597 2599 blkptr_t *bp = zio->io_bp;
2598 2600 int ioerr = zio->io_error;
2599 2601 zdb_cb_t *zcb = zio->io_private;
2600 2602 zbookmark_phys_t *zb = &zio->io_bookmark;
2601 2603
2602 2604 abd_free(zio->io_abd);
2603 2605
2604 2606 mutex_enter(&spa->spa_scrub_lock);
2605 2607 spa->spa_scrub_inflight--;
2606 2608 cv_broadcast(&spa->spa_scrub_io_cv);
2607 2609
2608 2610 if (ioerr && !(zio->io_flags & ZIO_FLAG_SPECULATIVE)) {
2609 2611 char blkbuf[BP_SPRINTF_LEN];
2610 2612
2611 2613 zcb->zcb_haderrors = 1;
2612 2614 zcb->zcb_errors[ioerr]++;
2613 2615
2614 2616 if (dump_opt['b'] >= 2)
2615 2617 snprintf_blkptr(blkbuf, sizeof (blkbuf), bp);
2616 2618 else
2617 2619 blkbuf[0] = '\0';
2618 2620
2619 2621 (void) printf("zdb_blkptr_cb: "
2620 2622 "Got error %d reading "
2621 2623 "<%llu, %llu, %lld, %llx> %s -- skipping\n",
2622 2624 ioerr,
2623 2625 (u_longlong_t)zb->zb_objset,
2624 2626 (u_longlong_t)zb->zb_object,
2625 2627 (u_longlong_t)zb->zb_level,
2626 2628 (u_longlong_t)zb->zb_blkid,
2627 2629 blkbuf);
2628 2630 }
2629 2631 mutex_exit(&spa->spa_scrub_lock);
2630 2632 }
2631 2633
2632 2634 static int
2633 2635 zdb_blkptr_cb(spa_t *spa, zilog_t *zilog, const blkptr_t *bp,
2634 2636 const zbookmark_phys_t *zb, const dnode_phys_t *dnp, void *arg)
2635 2637 {
2636 2638 zdb_cb_t *zcb = arg;
2637 2639 dmu_object_type_t type;
2638 2640 boolean_t is_metadata;
2639 2641
2640 2642 if (bp == NULL)
2641 2643 return (0);
2642 2644
2643 2645 if (dump_opt['b'] >= 5 && bp->blk_birth > 0) {
2644 2646 char blkbuf[BP_SPRINTF_LEN];
2645 2647 snprintf_blkptr(blkbuf, sizeof (blkbuf), bp);
2646 2648 (void) printf("objset %llu object %llu "
2647 2649 "level %lld offset 0x%llx %s\n",
2648 2650 (u_longlong_t)zb->zb_objset,
2649 2651 (u_longlong_t)zb->zb_object,
2650 2652 (longlong_t)zb->zb_level,
2651 2653 (u_longlong_t)blkid2offset(dnp, bp, zb),
2652 2654 blkbuf);
2653 2655 }
2654 2656
2655 2657 if (BP_IS_HOLE(bp))
2656 2658 return (0);
2657 2659
2658 2660 type = BP_GET_TYPE(bp);
2659 2661
2660 2662 zdb_count_block(zcb, zilog, bp,
2661 2663 (type & DMU_OT_NEWTYPE) ? ZDB_OT_OTHER : type);
2662 2664
2663 2665 is_metadata = (BP_GET_LEVEL(bp) != 0 || DMU_OT_IS_METADATA(type));
2664 2666
2665 2667 if (!BP_IS_EMBEDDED(bp) &&
2666 2668 (dump_opt['c'] > 1 || (dump_opt['c'] && is_metadata))) {
2667 2669 size_t size = BP_GET_PSIZE(bp);
2668 2670 abd_t *abd = abd_alloc(size, B_FALSE);
2669 2671 int flags = ZIO_FLAG_CANFAIL | ZIO_FLAG_SCRUB | ZIO_FLAG_RAW;
2670 2672
2671 2673 /* If it's an intent log block, failure is expected. */
2672 2674 if (zb->zb_level == ZB_ZIL_LEVEL)
2673 2675 flags |= ZIO_FLAG_SPECULATIVE;
2674 2676
2675 2677 mutex_enter(&spa->spa_scrub_lock);
2676 2678 while (spa->spa_scrub_inflight > max_inflight)
2677 2679 cv_wait(&spa->spa_scrub_io_cv, &spa->spa_scrub_lock);
2678 2680 spa->spa_scrub_inflight++;
2679 2681 mutex_exit(&spa->spa_scrub_lock);
2680 2682
2681 2683 zio_nowait(zio_read(NULL, spa, bp, abd, size,
2682 2684 zdb_blkptr_done, zcb, ZIO_PRIORITY_ASYNC_READ, flags, zb));
2683 2685 }
2684 2686
2685 2687 zcb->zcb_readfails = 0;
2686 2688
2687 2689 /* only call gethrtime() every 100 blocks */
2688 2690 static int iters;
2689 2691 if (++iters > 100)
2690 2692 iters = 0;
2691 2693 else
2692 2694 return (0);
2693 2695
2694 2696 if (dump_opt['b'] < 5 && gethrtime() > zcb->zcb_lastprint + NANOSEC) {
2695 2697 uint64_t now = gethrtime();
2696 2698 char buf[10];
2697 2699 uint64_t bytes = zcb->zcb_type[ZB_TOTAL][ZDB_OT_TOTAL].zb_asize;
2698 2700 int kb_per_sec =
2699 2701 1 + bytes / (1 + ((now - zcb->zcb_start) / 1000 / 1000));
2700 2702 int sec_remaining =
2701 2703 (zcb->zcb_totalasize - bytes) / 1024 / kb_per_sec;
2702 2704
2703 2705 /* make sure nicenum has enough space */
2704 2706 CTASSERT(sizeof (buf) >= NN_NUMBUF_SZ);
2705 2707
2706 2708 zfs_nicenum(bytes, buf, sizeof (buf));
2707 2709 (void) fprintf(stderr,
2708 2710 "\r%5s completed (%4dMB/s) "
2709 2711 "estimated time remaining: %uhr %02umin %02usec ",
2710 2712 buf, kb_per_sec / 1024,
2711 2713 sec_remaining / 60 / 60,
2712 2714 sec_remaining / 60 % 60,
2713 2715 sec_remaining % 60);
2714 2716
2715 2717 zcb->zcb_lastprint = now;
2716 2718 }
2717 2719
2718 2720 return (0);
2719 2721 }
2720 2722
2721 2723 static void
2722 2724 zdb_leak(void *arg, uint64_t start, uint64_t size)
2723 2725 {
2724 2726 vdev_t *vd = arg;
2725 2727
2726 2728 (void) printf("leaked space: vdev %llu, offset 0x%llx, size %llu\n",
2727 2729 (u_longlong_t)vd->vdev_id, (u_longlong_t)start, (u_longlong_t)size);
2728 2730 }
2729 2731
2730 2732 static metaslab_ops_t zdb_metaslab_ops = {
2731 2733 NULL /* alloc */
2732 2734 };
2733 2735
2734 2736 static void
2735 2737 zdb_ddt_leak_init(spa_t *spa, zdb_cb_t *zcb)
2736 2738 {
2737 2739 ddt_bookmark_t ddb;
2738 2740 ddt_entry_t dde;
2739 2741 int error;
2740 2742
2741 2743 bzero(&ddb, sizeof (ddb));
2742 2744 while ((error = ddt_walk(spa, &ddb, &dde)) == 0) {
2743 2745 blkptr_t blk;
2744 2746 ddt_phys_t *ddp = dde.dde_phys;
2745 2747
2746 2748 if (ddb.ddb_class == DDT_CLASS_UNIQUE)
2747 2749 return;
2748 2750
2749 2751 ASSERT(ddt_phys_total_refcnt(&dde) > 1);
2750 2752
2751 2753 for (int p = 0; p < DDT_PHYS_TYPES; p++, ddp++) {
2752 2754 if (ddp->ddp_phys_birth == 0)
2753 2755 continue;
2754 2756 ddt_bp_create(ddb.ddb_checksum,
2755 2757 &dde.dde_key, ddp, &blk);
2756 2758 if (p == DDT_PHYS_DITTO) {
2757 2759 zdb_count_block(zcb, NULL, &blk, ZDB_OT_DITTO);
2758 2760 } else {
2759 2761 zcb->zcb_dedup_asize +=
2760 2762 BP_GET_ASIZE(&blk) * (ddp->ddp_refcnt - 1);
2761 2763 zcb->zcb_dedup_blocks++;
2762 2764 }
2763 2765 }
2764 2766 if (!dump_opt['L']) {
2765 2767 ddt_t *ddt = spa->spa_ddt[ddb.ddb_checksum];
2766 2768 ddt_enter(ddt);
2767 2769 VERIFY(ddt_lookup(ddt, &blk, B_TRUE) != NULL);
2768 2770 ddt_exit(ddt);
2769 2771 }
2770 2772 }
2771 2773
2772 2774 ASSERT(error == ENOENT);
2773 2775 }
2774 2776
2775 2777 static void
2776 2778 zdb_leak_init(spa_t *spa, zdb_cb_t *zcb)
2777 2779 {
2778 2780 zcb->zcb_spa = spa;
2779 2781
2780 2782 if (!dump_opt['L']) {
2781 2783 vdev_t *rvd = spa->spa_root_vdev;
2782 2784
2783 2785 /*
2784 2786 * We are going to be changing the meaning of the metaslab's
2785 2787 * ms_tree. Ensure that the allocator doesn't try to
2786 2788 * use the tree.
2787 2789 */
2788 2790 spa->spa_normal_class->mc_ops = &zdb_metaslab_ops;
2789 2791 spa->spa_log_class->mc_ops = &zdb_metaslab_ops;
2790 2792
2791 2793 for (uint64_t c = 0; c < rvd->vdev_children; c++) {
2792 2794 vdev_t *vd = rvd->vdev_child[c];
2793 2795 metaslab_group_t *mg = vd->vdev_mg;
2794 2796 for (uint64_t m = 0; m < vd->vdev_ms_count; m++) {
2795 2797 metaslab_t *msp = vd->vdev_ms[m];
2796 2798 ASSERT3P(msp->ms_group, ==, mg);
2797 2799 mutex_enter(&msp->ms_lock);
2798 2800 metaslab_unload(msp);
2799 2801
2800 2802 /*
2801 2803 * For leak detection, we overload the metaslab
2802 2804 * ms_tree to contain allocated segments
2803 2805 * instead of free segments. As a result,
2804 2806 * we can't use the normal metaslab_load/unload
2805 2807 * interfaces.
2806 2808 */
2807 2809 if (msp->ms_sm != NULL) {
2808 2810 (void) fprintf(stderr,
2809 2811 "\rloading space map for "
2810 2812 "vdev %llu of %llu, "
2811 2813 "metaslab %llu of %llu ...",
2812 2814 (longlong_t)c,
2813 2815 (longlong_t)rvd->vdev_children,
2814 2816 (longlong_t)m,
2815 2817 (longlong_t)vd->vdev_ms_count);
2816 2818
2817 2819 /*
2818 2820 * We don't want to spend the CPU
2819 2821 * manipulating the size-ordered
2820 2822 * tree, so clear the range_tree
2821 2823 * ops.
2822 2824 */
2823 2825 msp->ms_tree->rt_ops = NULL;
2824 2826 VERIFY0(space_map_load(msp->ms_sm,
2825 2827 msp->ms_tree, SM_ALLOC));
2826 2828
2827 2829 if (!msp->ms_loaded) {
2828 2830 msp->ms_loaded = B_TRUE;
2829 2831 }
2830 2832 }
2831 2833 mutex_exit(&msp->ms_lock);
2832 2834 }
2833 2835 }
2834 2836 (void) fprintf(stderr, "\n");
2835 2837 }
2836 2838
2837 2839 spa_config_enter(spa, SCL_CONFIG, FTAG, RW_READER);
2838 2840
2839 2841 zdb_ddt_leak_init(spa, zcb);
2840 2842
2841 2843 spa_config_exit(spa, SCL_CONFIG, FTAG);
2842 2844 }
2843 2845
2844 2846 static void
2845 2847 zdb_leak_fini(spa_t *spa)
2846 2848 {
2847 2849 if (!dump_opt['L']) {
2848 2850 vdev_t *rvd = spa->spa_root_vdev;
2849 2851 for (unsigned c = 0; c < rvd->vdev_children; c++) {
2850 2852 vdev_t *vd = rvd->vdev_child[c];
2851 2853 metaslab_group_t *mg = vd->vdev_mg;
2852 2854 for (unsigned m = 0; m < vd->vdev_ms_count; m++) {
2853 2855 metaslab_t *msp = vd->vdev_ms[m];
2854 2856 ASSERT3P(mg, ==, msp->ms_group);
2855 2857 mutex_enter(&msp->ms_lock);
2856 2858
2857 2859 /*
2858 2860 * The ms_tree has been overloaded to
2859 2861 * contain allocated segments. Now that we
2860 2862 * finished traversing all blocks, any
2861 2863 * block that remains in the ms_tree
2862 2864 * represents an allocated block that we
2863 2865 * did not claim during the traversal.
2864 2866 * Claimed blocks would have been removed
2865 2867 * from the ms_tree.
2866 2868 */
2867 2869 range_tree_vacate(msp->ms_tree, zdb_leak, vd);
2868 2870
2869 2871 if (msp->ms_loaded) {
2870 2872 msp->ms_loaded = B_FALSE;
2871 2873 }
2872 2874
2873 2875 mutex_exit(&msp->ms_lock);
2874 2876 }
2875 2877 }
2876 2878 }
2877 2879 }
2878 2880
2879 2881 /* ARGSUSED */
2880 2882 static int
2881 2883 count_block_cb(void *arg, const blkptr_t *bp, dmu_tx_t *tx)
2882 2884 {
2883 2885 zdb_cb_t *zcb = arg;
2884 2886
2885 2887 if (dump_opt['b'] >= 5) {
2886 2888 char blkbuf[BP_SPRINTF_LEN];
2887 2889 snprintf_blkptr(blkbuf, sizeof (blkbuf), bp);
2888 2890 (void) printf("[%s] %s\n",
2889 2891 "deferred free", blkbuf);
2890 2892 }
2891 2893 zdb_count_block(zcb, NULL, bp, ZDB_OT_DEFERRED);
2892 2894 return (0);
2893 2895 }
2894 2896
2895 2897 static int
2896 2898 dump_block_stats(spa_t *spa)
2897 2899 {
2898 2900 zdb_cb_t zcb;
2899 2901 zdb_blkstats_t *zb, *tzb;
2900 2902 uint64_t norm_alloc, norm_space, total_alloc, total_found;
2901 2903 int flags = TRAVERSE_PRE | TRAVERSE_PREFETCH_METADATA | TRAVERSE_HARD;
2902 2904 boolean_t leaks = B_FALSE;
2903 2905
2904 2906 bzero(&zcb, sizeof (zcb));
2905 2907 (void) printf("\nTraversing all blocks %s%s%s%s%s...\n\n",
2906 2908 (dump_opt['c'] || !dump_opt['L']) ? "to verify " : "",
2907 2909 (dump_opt['c'] == 1) ? "metadata " : "",
2908 2910 dump_opt['c'] ? "checksums " : "",
2909 2911 (dump_opt['c'] && !dump_opt['L']) ? "and verify " : "",
2910 2912 !dump_opt['L'] ? "nothing leaked " : "");
2911 2913
2912 2914 /*
2913 2915 * Load all space maps as SM_ALLOC maps, then traverse the pool
2914 2916 * claiming each block we discover. If the pool is perfectly
2915 2917 * consistent, the space maps will be empty when we're done.
2916 2918 * Anything left over is a leak; any block we can't claim (because
2917 2919 * it's not part of any space map) is a double allocation,
2918 2920 * reference to a freed block, or an unclaimed log block.
2919 2921 */
2920 2922 zdb_leak_init(spa, &zcb);
2921 2923
2922 2924 /*
2923 2925 * If there's a deferred-free bplist, process that first.
2924 2926 */
2925 2927 (void) bpobj_iterate_nofree(&spa->spa_deferred_bpobj,
2926 2928 count_block_cb, &zcb, NULL);
2927 2929 if (spa_version(spa) >= SPA_VERSION_DEADLISTS) {
2928 2930 (void) bpobj_iterate_nofree(&spa->spa_dsl_pool->dp_free_bpobj,
2929 2931 count_block_cb, &zcb, NULL);
2930 2932 }
2931 2933 if (spa_feature_is_active(spa, SPA_FEATURE_ASYNC_DESTROY)) {
2932 2934 VERIFY3U(0, ==, bptree_iterate(spa->spa_meta_objset,
2933 2935 spa->spa_dsl_pool->dp_bptree_obj, B_FALSE, count_block_cb,
2934 2936 &zcb, NULL));
2935 2937 }
2936 2938
2937 2939 if (dump_opt['c'] > 1)
2938 2940 flags |= TRAVERSE_PREFETCH_DATA;
2939 2941
2940 2942 zcb.zcb_totalasize = metaslab_class_get_alloc(spa_normal_class(spa));
2941 2943 zcb.zcb_start = zcb.zcb_lastprint = gethrtime();
2942 2944 zcb.zcb_haderrors |= traverse_pool(spa, 0, flags, zdb_blkptr_cb, &zcb);
2943 2945
2944 2946 /*
2945 2947 * If we've traversed the data blocks then we need to wait for those
2946 2948 * I/Os to complete. We leverage "The Godfather" zio to wait on
2947 2949 * all async I/Os to complete.
2948 2950 */
2949 2951 if (dump_opt['c']) {
2950 2952 for (int i = 0; i < max_ncpus; i++) {
2951 2953 (void) zio_wait(spa->spa_async_zio_root[i]);
2952 2954 spa->spa_async_zio_root[i] = zio_root(spa, NULL, NULL,
2953 2955 ZIO_FLAG_CANFAIL | ZIO_FLAG_SPECULATIVE |
2954 2956 ZIO_FLAG_GODFATHER);
2955 2957 }
2956 2958 }
2957 2959
2958 2960 if (zcb.zcb_haderrors) {
2959 2961 (void) printf("\nError counts:\n\n");
2960 2962 (void) printf("\t%5s %s\n", "errno", "count");
2961 2963 for (int e = 0; e < 256; e++) {
2962 2964 if (zcb.zcb_errors[e] != 0) {
2963 2965 (void) printf("\t%5d %llu\n",
2964 2966 e, (u_longlong_t)zcb.zcb_errors[e]);
2965 2967 }
2966 2968 }
2967 2969 }
2968 2970
2969 2971 /*
2970 2972 * Report any leaked segments.
2971 2973 */
2972 2974 zdb_leak_fini(spa);
2973 2975
2974 2976 tzb = &zcb.zcb_type[ZB_TOTAL][ZDB_OT_TOTAL];
2975 2977
2976 2978 norm_alloc = metaslab_class_get_alloc(spa_normal_class(spa));
2977 2979 norm_space = metaslab_class_get_space(spa_normal_class(spa));
2978 2980
2979 2981 total_alloc = norm_alloc + metaslab_class_get_alloc(spa_log_class(spa));
2980 2982 total_found = tzb->zb_asize - zcb.zcb_dedup_asize;
2981 2983
2982 2984 if (total_found == total_alloc) {
2983 2985 if (!dump_opt['L'])
2984 2986 (void) printf("\n\tNo leaks (block sum matches space"
2985 2987 " maps exactly)\n");
2986 2988 } else {
2987 2989 (void) printf("block traversal size %llu != alloc %llu "
2988 2990 "(%s %lld)\n",
2989 2991 (u_longlong_t)total_found,
2990 2992 (u_longlong_t)total_alloc,
2991 2993 (dump_opt['L']) ? "unreachable" : "leaked",
2992 2994 (longlong_t)(total_alloc - total_found));
2993 2995 leaks = B_TRUE;
2994 2996 }
2995 2997
2996 2998 if (tzb->zb_count == 0)
2997 2999 return (2);
2998 3000
2999 3001 (void) printf("\n");
3000 3002 (void) printf("\tbp count: %10llu\n",
3001 3003 (u_longlong_t)tzb->zb_count);
3002 3004 (void) printf("\tganged count: %10llu\n",
3003 3005 (longlong_t)tzb->zb_gangs);
3004 3006 (void) printf("\tbp logical: %10llu avg: %6llu\n",
3005 3007 (u_longlong_t)tzb->zb_lsize,
3006 3008 (u_longlong_t)(tzb->zb_lsize / tzb->zb_count));
3007 3009 (void) printf("\tbp physical: %10llu avg:"
3008 3010 " %6llu compression: %6.2f\n",
3009 3011 (u_longlong_t)tzb->zb_psize,
3010 3012 (u_longlong_t)(tzb->zb_psize / tzb->zb_count),
3011 3013 (double)tzb->zb_lsize / tzb->zb_psize);
3012 3014 (void) printf("\tbp allocated: %10llu avg:"
3013 3015 " %6llu compression: %6.2f\n",
3014 3016 (u_longlong_t)tzb->zb_asize,
3015 3017 (u_longlong_t)(tzb->zb_asize / tzb->zb_count),
3016 3018 (double)tzb->zb_lsize / tzb->zb_asize);
3017 3019 (void) printf("\tbp deduped: %10llu ref>1:"
3018 3020 " %6llu deduplication: %6.2f\n",
3019 3021 (u_longlong_t)zcb.zcb_dedup_asize,
3020 3022 (u_longlong_t)zcb.zcb_dedup_blocks,
3021 3023 (double)zcb.zcb_dedup_asize / tzb->zb_asize + 1.0);
3022 3024 (void) printf("\tSPA allocated: %10llu used: %5.2f%%\n",
3023 3025 (u_longlong_t)norm_alloc, 100.0 * norm_alloc / norm_space);
3024 3026
3025 3027 for (bp_embedded_type_t i = 0; i < NUM_BP_EMBEDDED_TYPES; i++) {
3026 3028 if (zcb.zcb_embedded_blocks[i] == 0)
3027 3029 continue;
3028 3030 (void) printf("\n");
3029 3031 (void) printf("\tadditional, non-pointer bps of type %u: "
3030 3032 "%10llu\n",
3031 3033 i, (u_longlong_t)zcb.zcb_embedded_blocks[i]);
3032 3034
3033 3035 if (dump_opt['b'] >= 3) {
3034 3036 (void) printf("\t number of (compressed) bytes: "
3035 3037 "number of bps\n");
3036 3038 dump_histogram(zcb.zcb_embedded_histogram[i],
3037 3039 sizeof (zcb.zcb_embedded_histogram[i]) /
3038 3040 sizeof (zcb.zcb_embedded_histogram[i][0]), 0);
3039 3041 }
3040 3042 }
3041 3043
3042 3044 if (tzb->zb_ditto_samevdev != 0) {
3043 3045 (void) printf("\tDittoed blocks on same vdev: %llu\n",
3044 3046 (longlong_t)tzb->zb_ditto_samevdev);
3045 3047 }
3046 3048
3047 3049 if (dump_opt['b'] >= 2) {
3048 3050 int l, t, level;
3049 3051 (void) printf("\nBlocks\tLSIZE\tPSIZE\tASIZE"
3050 3052 "\t avg\t comp\t%%Total\tType\n");
3051 3053
3052 3054 for (t = 0; t <= ZDB_OT_TOTAL; t++) {
3053 3055 char csize[32], lsize[32], psize[32], asize[32];
3054 3056 char avg[32], gang[32];
3055 3057 const char *typename;
3056 3058
3057 3059 /* make sure nicenum has enough space */
3058 3060 CTASSERT(sizeof (csize) >= NN_NUMBUF_SZ);
3059 3061 CTASSERT(sizeof (lsize) >= NN_NUMBUF_SZ);
3060 3062 CTASSERT(sizeof (psize) >= NN_NUMBUF_SZ);
3061 3063 CTASSERT(sizeof (asize) >= NN_NUMBUF_SZ);
3062 3064 CTASSERT(sizeof (avg) >= NN_NUMBUF_SZ);
3063 3065 CTASSERT(sizeof (gang) >= NN_NUMBUF_SZ);
3064 3066
3065 3067 if (t < DMU_OT_NUMTYPES)
3066 3068 typename = dmu_ot[t].ot_name;
3067 3069 else
3068 3070 typename = zdb_ot_extname[t - DMU_OT_NUMTYPES];
3069 3071
3070 3072 if (zcb.zcb_type[ZB_TOTAL][t].zb_asize == 0) {
3071 3073 (void) printf("%6s\t%5s\t%5s\t%5s"
3072 3074 "\t%5s\t%5s\t%6s\t%s\n",
3073 3075 "-",
3074 3076 "-",
3075 3077 "-",
3076 3078 "-",
3077 3079 "-",
3078 3080 "-",
3079 3081 "-",
3080 3082 typename);
3081 3083 continue;
3082 3084 }
3083 3085
3084 3086 for (l = ZB_TOTAL - 1; l >= -1; l--) {
3085 3087 level = (l == -1 ? ZB_TOTAL : l);
3086 3088 zb = &zcb.zcb_type[level][t];
3087 3089
3088 3090 if (zb->zb_asize == 0)
3089 3091 continue;
3090 3092
3091 3093 if (dump_opt['b'] < 3 && level != ZB_TOTAL)
3092 3094 continue;
3093 3095
3094 3096 if (level == 0 && zb->zb_asize ==
3095 3097 zcb.zcb_type[ZB_TOTAL][t].zb_asize)
3096 3098 continue;
3097 3099
3098 3100 zdb_nicenum(zb->zb_count, csize,
3099 3101 sizeof (csize));
3100 3102 zdb_nicenum(zb->zb_lsize, lsize,
3101 3103 sizeof (lsize));
3102 3104 zdb_nicenum(zb->zb_psize, psize,
3103 3105 sizeof (psize));
3104 3106 zdb_nicenum(zb->zb_asize, asize,
3105 3107 sizeof (asize));
3106 3108 zdb_nicenum(zb->zb_asize / zb->zb_count, avg,
3107 3109 sizeof (avg));
3108 3110 zdb_nicenum(zb->zb_gangs, gang, sizeof (gang));
3109 3111
3110 3112 (void) printf("%6s\t%5s\t%5s\t%5s\t%5s"
3111 3113 "\t%5.2f\t%6.2f\t",
3112 3114 csize, lsize, psize, asize, avg,
3113 3115 (double)zb->zb_lsize / zb->zb_psize,
3114 3116 100.0 * zb->zb_asize / tzb->zb_asize);
3115 3117
3116 3118 if (level == ZB_TOTAL)
3117 3119 (void) printf("%s\n", typename);
3118 3120 else
3119 3121 (void) printf(" L%d %s\n",
3120 3122 level, typename);
3121 3123
3122 3124 if (dump_opt['b'] >= 3 && zb->zb_gangs > 0) {
3123 3125 (void) printf("\t number of ganged "
3124 3126 "blocks: %s\n", gang);
3125 3127 }
3126 3128
3127 3129 if (dump_opt['b'] >= 4) {
3128 3130 (void) printf("psize "
3129 3131 "(in 512-byte sectors): "
3130 3132 "number of blocks\n");
3131 3133 dump_histogram(zb->zb_psize_histogram,
3132 3134 PSIZE_HISTO_SIZE, 0);
3133 3135 }
3134 3136 }
3135 3137 }
3136 3138 }
3137 3139
3138 3140 (void) printf("\n");
3139 3141
3140 3142 if (leaks)
3141 3143 return (2);
3142 3144
3143 3145 if (zcb.zcb_haderrors)
3144 3146 return (3);
3145 3147
3146 3148 return (0);
3147 3149 }
3148 3150
3149 3151 typedef struct zdb_ddt_entry {
3150 3152 ddt_key_t zdde_key;
3151 3153 uint64_t zdde_ref_blocks;
3152 3154 uint64_t zdde_ref_lsize;
3153 3155 uint64_t zdde_ref_psize;
3154 3156 uint64_t zdde_ref_dsize;
3155 3157 avl_node_t zdde_node;
3156 3158 } zdb_ddt_entry_t;
3157 3159
3158 3160 /* ARGSUSED */
3159 3161 static int
3160 3162 zdb_ddt_add_cb(spa_t *spa, zilog_t *zilog, const blkptr_t *bp,
3161 3163 const zbookmark_phys_t *zb, const dnode_phys_t *dnp, void *arg)
3162 3164 {
3163 3165 avl_tree_t *t = arg;
3164 3166 avl_index_t where;
3165 3167 zdb_ddt_entry_t *zdde, zdde_search;
3166 3168
3167 3169 if (bp == NULL || BP_IS_HOLE(bp) || BP_IS_EMBEDDED(bp))
3168 3170 return (0);
3169 3171
3170 3172 if (dump_opt['S'] > 1 && zb->zb_level == ZB_ROOT_LEVEL) {
3171 3173 (void) printf("traversing objset %llu, %llu objects, "
3172 3174 "%lu blocks so far\n",
3173 3175 (u_longlong_t)zb->zb_objset,
3174 3176 (u_longlong_t)BP_GET_FILL(bp),
3175 3177 avl_numnodes(t));
3176 3178 }
3177 3179
3178 3180 if (BP_IS_HOLE(bp) || BP_GET_CHECKSUM(bp) == ZIO_CHECKSUM_OFF ||
3179 3181 BP_GET_LEVEL(bp) > 0 || DMU_OT_IS_METADATA(BP_GET_TYPE(bp)))
3180 3182 return (0);
3181 3183
3182 3184 ddt_key_fill(&zdde_search.zdde_key, bp);
3183 3185
3184 3186 zdde = avl_find(t, &zdde_search, &where);
3185 3187
3186 3188 if (zdde == NULL) {
3187 3189 zdde = umem_zalloc(sizeof (*zdde), UMEM_NOFAIL);
3188 3190 zdde->zdde_key = zdde_search.zdde_key;
3189 3191 avl_insert(t, zdde, where);
3190 3192 }
3191 3193
3192 3194 zdde->zdde_ref_blocks += 1;
3193 3195 zdde->zdde_ref_lsize += BP_GET_LSIZE(bp);
3194 3196 zdde->zdde_ref_psize += BP_GET_PSIZE(bp);
3195 3197 zdde->zdde_ref_dsize += bp_get_dsize_sync(spa, bp);
3196 3198
3197 3199 return (0);
3198 3200 }
3199 3201
3200 3202 static void
3201 3203 dump_simulated_ddt(spa_t *spa)
3202 3204 {
3203 3205 avl_tree_t t;
3204 3206 void *cookie = NULL;
3205 3207 zdb_ddt_entry_t *zdde;
3206 3208 ddt_histogram_t ddh_total;
3207 3209 ddt_stat_t dds_total;
3208 3210
3209 3211 bzero(&ddh_total, sizeof (ddh_total));
3210 3212 bzero(&dds_total, sizeof (dds_total));
3211 3213 avl_create(&t, ddt_entry_compare,
3212 3214 sizeof (zdb_ddt_entry_t), offsetof(zdb_ddt_entry_t, zdde_node));
3213 3215
3214 3216 spa_config_enter(spa, SCL_CONFIG, FTAG, RW_READER);
3215 3217
3216 3218 (void) traverse_pool(spa, 0, TRAVERSE_PRE | TRAVERSE_PREFETCH_METADATA,
3217 3219 zdb_ddt_add_cb, &t);
3218 3220
3219 3221 spa_config_exit(spa, SCL_CONFIG, FTAG);
3220 3222
3221 3223 while ((zdde = avl_destroy_nodes(&t, &cookie)) != NULL) {
3222 3224 ddt_stat_t dds;
3223 3225 uint64_t refcnt = zdde->zdde_ref_blocks;
3224 3226 ASSERT(refcnt != 0);
3225 3227
3226 3228 dds.dds_blocks = zdde->zdde_ref_blocks / refcnt;
3227 3229 dds.dds_lsize = zdde->zdde_ref_lsize / refcnt;
3228 3230 dds.dds_psize = zdde->zdde_ref_psize / refcnt;
3229 3231 dds.dds_dsize = zdde->zdde_ref_dsize / refcnt;
3230 3232
3231 3233 dds.dds_ref_blocks = zdde->zdde_ref_blocks;
3232 3234 dds.dds_ref_lsize = zdde->zdde_ref_lsize;
3233 3235 dds.dds_ref_psize = zdde->zdde_ref_psize;
3234 3236 dds.dds_ref_dsize = zdde->zdde_ref_dsize;
3235 3237
3236 3238 ddt_stat_add(&ddh_total.ddh_stat[highbit64(refcnt) - 1],
3237 3239 &dds, 0);
3238 3240
3239 3241 umem_free(zdde, sizeof (*zdde));
3240 3242 }
3241 3243
3242 3244 avl_destroy(&t);
3243 3245
3244 3246 ddt_histogram_stat(&dds_total, &ddh_total);
3245 3247
3246 3248 (void) printf("Simulated DDT histogram:\n");
3247 3249
3248 3250 zpool_dump_ddt(&dds_total, &ddh_total);
3249 3251
3250 3252 dump_dedup_ratio(&dds_total);
3251 3253 }
3252 3254
3253 3255 static void
3254 3256 dump_zpool(spa_t *spa)
3255 3257 {
3256 3258 dsl_pool_t *dp = spa_get_dsl(spa);
3257 3259 int rc = 0;
3258 3260
3259 3261 if (dump_opt['S']) {
3260 3262 dump_simulated_ddt(spa);
3261 3263 return;
3262 3264 }
3263 3265
3264 3266 if (!dump_opt['e'] && dump_opt['C'] > 1) {
3265 3267 (void) printf("\nCached configuration:\n");
3266 3268 dump_nvlist(spa->spa_config, 8);
3267 3269 }
3268 3270
3269 3271 if (dump_opt['C'])
3270 3272 dump_config(spa);
3271 3273
3272 3274 if (dump_opt['u'])
3273 3275 dump_uberblock(&spa->spa_uberblock, "\nUberblock:\n", "\n");
3274 3276
3275 3277 if (dump_opt['D'])
3276 3278 dump_all_ddts(spa);
3277 3279
3278 3280 if (dump_opt['d'] > 2 || dump_opt['m'])
3279 3281 dump_metaslabs(spa);
3280 3282 if (dump_opt['M'])
3281 3283 dump_metaslab_groups(spa);
3282 3284
3283 3285 if (dump_opt['d'] || dump_opt['i']) {
3284 3286 dump_dir(dp->dp_meta_objset);
3285 3287 if (dump_opt['d'] >= 3) {
3286 3288 dump_full_bpobj(&spa->spa_deferred_bpobj,
3287 3289 "Deferred frees", 0);
3288 3290 if (spa_version(spa) >= SPA_VERSION_DEADLISTS) {
3289 3291 dump_full_bpobj(
3290 3292 &spa->spa_dsl_pool->dp_free_bpobj,
3291 3293 "Pool snapshot frees", 0);
3292 3294 }
3293 3295
3294 3296 if (spa_feature_is_active(spa,
3295 3297 SPA_FEATURE_ASYNC_DESTROY)) {
3296 3298 dump_bptree(spa->spa_meta_objset,
3297 3299 spa->spa_dsl_pool->dp_bptree_obj,
3298 3300 "Pool dataset frees");
3299 3301 }
3300 3302 dump_dtl(spa->spa_root_vdev, 0);
3301 3303 }
3302 3304 (void) dmu_objset_find(spa_name(spa), dump_one_dir,
3303 3305 NULL, DS_FIND_SNAPSHOTS | DS_FIND_CHILDREN);
3304 3306
3305 3307 for (spa_feature_t f = 0; f < SPA_FEATURES; f++) {
3306 3308 uint64_t refcount;
3307 3309
3308 3310 if (!(spa_feature_table[f].fi_flags &
3309 3311 ZFEATURE_FLAG_PER_DATASET) ||
3310 3312 !spa_feature_is_enabled(spa, f)) {
3311 3313 ASSERT0(dataset_feature_count[f]);
3312 3314 continue;
3313 3315 }
3314 3316 (void) feature_get_refcount(spa,
3315 3317 &spa_feature_table[f], &refcount);
3316 3318 if (dataset_feature_count[f] != refcount) {
3317 3319 (void) printf("%s feature refcount mismatch: "
3318 3320 "%lld datasets != %lld refcount\n",
3319 3321 spa_feature_table[f].fi_uname,
3320 3322 (longlong_t)dataset_feature_count[f],
3321 3323 (longlong_t)refcount);
3322 3324 rc = 2;
3323 3325 } else {
3324 3326 (void) printf("Verified %s feature refcount "
3325 3327 "of %llu is correct\n",
3326 3328 spa_feature_table[f].fi_uname,
3327 3329 (longlong_t)refcount);
3328 3330 }
3329 3331 }
3330 3332 }
3331 3333 if (rc == 0 && (dump_opt['b'] || dump_opt['c']))
3332 3334 rc = dump_block_stats(spa);
3333 3335
3334 3336 if (rc == 0)
3335 3337 rc = verify_spacemap_refcounts(spa);
3336 3338
3337 3339 if (dump_opt['s'])
3338 3340 show_pool_stats(spa);
3339 3341
3340 3342 if (dump_opt['h'])
3341 3343 dump_history(spa);
3342 3344
3343 3345 if (rc != 0) {
3344 3346 dump_debug_buffer();
3345 3347 exit(rc);
3346 3348 }
3347 3349 }
3348 3350
3349 3351 #define ZDB_FLAG_CHECKSUM 0x0001
3350 3352 #define ZDB_FLAG_DECOMPRESS 0x0002
3351 3353 #define ZDB_FLAG_BSWAP 0x0004
3352 3354 #define ZDB_FLAG_GBH 0x0008
3353 3355 #define ZDB_FLAG_INDIRECT 0x0010
3354 3356 #define ZDB_FLAG_PHYS 0x0020
3355 3357 #define ZDB_FLAG_RAW 0x0040
3356 3358 #define ZDB_FLAG_PRINT_BLKPTR 0x0080
3357 3359
3358 3360 static int flagbits[256];
3359 3361
3360 3362 static void
3361 3363 zdb_print_blkptr(blkptr_t *bp, int flags)
3362 3364 {
3363 3365 char blkbuf[BP_SPRINTF_LEN];
3364 3366
3365 3367 if (flags & ZDB_FLAG_BSWAP)
3366 3368 byteswap_uint64_array((void *)bp, sizeof (blkptr_t));
3367 3369
3368 3370 snprintf_blkptr(blkbuf, sizeof (blkbuf), bp);
3369 3371 (void) printf("%s\n", blkbuf);
3370 3372 }
3371 3373
3372 3374 static void
3373 3375 zdb_dump_indirect(blkptr_t *bp, int nbps, int flags)
3374 3376 {
3375 3377 int i;
3376 3378
3377 3379 for (i = 0; i < nbps; i++)
3378 3380 zdb_print_blkptr(&bp[i], flags);
3379 3381 }
3380 3382
3381 3383 static void
3382 3384 zdb_dump_gbh(void *buf, int flags)
3383 3385 {
3384 3386 zdb_dump_indirect((blkptr_t *)buf, SPA_GBH_NBLKPTRS, flags);
3385 3387 }
3386 3388
3387 3389 static void
3388 3390 zdb_dump_block_raw(void *buf, uint64_t size, int flags)
3389 3391 {
3390 3392 if (flags & ZDB_FLAG_BSWAP)
3391 3393 byteswap_uint64_array(buf, size);
3392 3394 (void) write(1, buf, size);
3393 3395 }
3394 3396
3395 3397 static void
3396 3398 zdb_dump_block(char *label, void *buf, uint64_t size, int flags)
3397 3399 {
3398 3400 uint64_t *d = (uint64_t *)buf;
3399 3401 unsigned nwords = size / sizeof (uint64_t);
3400 3402 int do_bswap = !!(flags & ZDB_FLAG_BSWAP);
3401 3403 unsigned i, j;
3402 3404 const char *hdr;
3403 3405 char *c;
3404 3406
3405 3407
3406 3408 if (do_bswap)
3407 3409 hdr = " 7 6 5 4 3 2 1 0 f e d c b a 9 8";
3408 3410 else
3409 3411 hdr = " 0 1 2 3 4 5 6 7 8 9 a b c d e f";
3410 3412
3411 3413 (void) printf("\n%s\n%6s %s 0123456789abcdef\n", label, "", hdr);
3412 3414
3413 3415 for (i = 0; i < nwords; i += 2) {
3414 3416 (void) printf("%06llx: %016llx %016llx ",
3415 3417 (u_longlong_t)(i * sizeof (uint64_t)),
3416 3418 (u_longlong_t)(do_bswap ? BSWAP_64(d[i]) : d[i]),
3417 3419 (u_longlong_t)(do_bswap ? BSWAP_64(d[i + 1]) : d[i + 1]));
3418 3420
3419 3421 c = (char *)&d[i];
3420 3422 for (j = 0; j < 2 * sizeof (uint64_t); j++)
3421 3423 (void) printf("%c", isprint(c[j]) ? c[j] : '.');
3422 3424 (void) printf("\n");
3423 3425 }
3424 3426 }
3425 3427
3426 3428 /*
3427 3429 * There are two acceptable formats:
3428 3430 * leaf_name - For example: c1t0d0 or /tmp/ztest.0a
3429 3431 * child[.child]* - For example: 0.1.1
3430 3432 *
3431 3433 * The second form can be used to specify arbitrary vdevs anywhere
3432 3434 * in the heirarchy. For example, in a pool with a mirror of
3433 3435 * RAID-Zs, you can specify either RAID-Z vdev with 0.0 or 0.1 .
3434 3436 */
3435 3437 static vdev_t *
3436 3438 zdb_vdev_lookup(vdev_t *vdev, const char *path)
3437 3439 {
3438 3440 char *s, *p, *q;
3439 3441 unsigned i;
3440 3442
3441 3443 if (vdev == NULL)
3442 3444 return (NULL);
3443 3445
3444 3446 /* First, assume the x.x.x.x format */
3445 3447 i = strtoul(path, &s, 10);
3446 3448 if (s == path || (s && *s != '.' && *s != '\0'))
3447 3449 goto name;
3448 3450 if (i >= vdev->vdev_children)
3449 3451 return (NULL);
3450 3452
3451 3453 vdev = vdev->vdev_child[i];
3452 3454 if (*s == '\0')
3453 3455 return (vdev);
3454 3456 return (zdb_vdev_lookup(vdev, s+1));
3455 3457
3456 3458 name:
3457 3459 for (i = 0; i < vdev->vdev_children; i++) {
3458 3460 vdev_t *vc = vdev->vdev_child[i];
3459 3461
3460 3462 if (vc->vdev_path == NULL) {
3461 3463 vc = zdb_vdev_lookup(vc, path);
3462 3464 if (vc == NULL)
3463 3465 continue;
3464 3466 else
3465 3467 return (vc);
3466 3468 }
3467 3469
3468 3470 p = strrchr(vc->vdev_path, '/');
3469 3471 p = p ? p + 1 : vc->vdev_path;
3470 3472 q = &vc->vdev_path[strlen(vc->vdev_path) - 2];
3471 3473
3472 3474 if (strcmp(vc->vdev_path, path) == 0)
3473 3475 return (vc);
3474 3476 if (strcmp(p, path) == 0)
3475 3477 return (vc);
3476 3478 if (strcmp(q, "s0") == 0 && strncmp(p, path, q - p) == 0)
3477 3479 return (vc);
3478 3480 }
3479 3481
3480 3482 return (NULL);
3481 3483 }
3482 3484
3483 3485 /* ARGSUSED */
3484 3486 static int
3485 3487 random_get_pseudo_bytes_cb(void *buf, size_t len, void *unused)
3486 3488 {
3487 3489 return (random_get_pseudo_bytes(buf, len));
3488 3490 }
3489 3491
3490 3492 /*
3491 3493 * Read a block from a pool and print it out. The syntax of the
3492 3494 * block descriptor is:
3493 3495 *
3494 3496 * pool:vdev_specifier:offset:size[:flags]
3495 3497 *
3496 3498 * pool - The name of the pool you wish to read from
3497 3499 * vdev_specifier - Which vdev (see comment for zdb_vdev_lookup)
3498 3500 * offset - offset, in hex, in bytes
3499 3501 * size - Amount of data to read, in hex, in bytes
3500 3502 * flags - A string of characters specifying options
3501 3503 * b: Decode a blkptr at given offset within block
3502 3504 * *c: Calculate and display checksums
3503 3505 * d: Decompress data before dumping
3504 3506 * e: Byteswap data before dumping
3505 3507 * g: Display data as a gang block header
3506 3508 * i: Display as an indirect block
3507 3509 * p: Do I/O to physical offset
3508 3510 * r: Dump raw data to stdout
3509 3511 *
3510 3512 * * = not yet implemented
3511 3513 */
3512 3514 static void
3513 3515 zdb_read_block(char *thing, spa_t *spa)
3514 3516 {
3515 3517 blkptr_t blk, *bp = &blk;
3516 3518 dva_t *dva = bp->blk_dva;
3517 3519 int flags = 0;
3518 3520 uint64_t offset = 0, size = 0, psize = 0, lsize = 0, blkptr_offset = 0;
3519 3521 zio_t *zio;
3520 3522 vdev_t *vd;
3521 3523 abd_t *pabd;
3522 3524 void *lbuf, *buf;
3523 3525 const char *s, *vdev;
3524 3526 char *p, *dup, *flagstr;
3525 3527 int i, error;
3526 3528
3527 3529 dup = strdup(thing);
3528 3530 s = strtok(dup, ":");
3529 3531 vdev = s ? s : "";
3530 3532 s = strtok(NULL, ":");
3531 3533 offset = strtoull(s ? s : "", NULL, 16);
3532 3534 s = strtok(NULL, ":");
3533 3535 size = strtoull(s ? s : "", NULL, 16);
3534 3536 s = strtok(NULL, ":");
3535 3537 if (s)
3536 3538 flagstr = strdup(s);
3537 3539 else
3538 3540 flagstr = strdup("");
3539 3541
3540 3542 s = NULL;
3541 3543 if (size == 0)
3542 3544 s = "size must not be zero";
3543 3545 if (!IS_P2ALIGNED(size, DEV_BSIZE))
3544 3546 s = "size must be a multiple of sector size";
3545 3547 if (!IS_P2ALIGNED(offset, DEV_BSIZE))
3546 3548 s = "offset must be a multiple of sector size";
3547 3549 if (s) {
3548 3550 (void) printf("Invalid block specifier: %s - %s\n", thing, s);
3549 3551 free(dup);
3550 3552 return;
3551 3553 }
3552 3554
3553 3555 for (s = strtok(flagstr, ":"); s; s = strtok(NULL, ":")) {
3554 3556 for (i = 0; flagstr[i]; i++) {
3555 3557 int bit = flagbits[(uchar_t)flagstr[i]];
3556 3558
3557 3559 if (bit == 0) {
3558 3560 (void) printf("***Invalid flag: %c\n",
3559 3561 flagstr[i]);
3560 3562 continue;
3561 3563 }
3562 3564 flags |= bit;
3563 3565
3564 3566 /* If it's not something with an argument, keep going */
3565 3567 if ((bit & (ZDB_FLAG_CHECKSUM |
3566 3568 ZDB_FLAG_PRINT_BLKPTR)) == 0)
3567 3569 continue;
3568 3570
3569 3571 p = &flagstr[i + 1];
3570 3572 if (bit == ZDB_FLAG_PRINT_BLKPTR)
3571 3573 blkptr_offset = strtoull(p, &p, 16);
3572 3574 if (*p != ':' && *p != '\0') {
3573 3575 (void) printf("***Invalid flag arg: '%s'\n", s);
3574 3576 free(dup);
3575 3577 return;
3576 3578 }
3577 3579 }
3578 3580 }
3579 3581 free(flagstr);
3580 3582
3581 3583 vd = zdb_vdev_lookup(spa->spa_root_vdev, vdev);
3582 3584 if (vd == NULL) {
3583 3585 (void) printf("***Invalid vdev: %s\n", vdev);
3584 3586 free(dup);
3585 3587 return;
3586 3588 } else {
3587 3589 if (vd->vdev_path)
3588 3590 (void) fprintf(stderr, "Found vdev: %s\n",
3589 3591 vd->vdev_path);
3590 3592 else
3591 3593 (void) fprintf(stderr, "Found vdev type: %s\n",
3592 3594 vd->vdev_ops->vdev_op_type);
3593 3595 }
3594 3596
3595 3597 psize = size;
3596 3598 lsize = size;
3597 3599
3598 3600 pabd = abd_alloc_linear(SPA_MAXBLOCKSIZE, B_FALSE);
3599 3601 lbuf = umem_alloc(SPA_MAXBLOCKSIZE, UMEM_NOFAIL);
3600 3602
3601 3603 BP_ZERO(bp);
3602 3604
3603 3605 DVA_SET_VDEV(&dva[0], vd->vdev_id);
3604 3606 DVA_SET_OFFSET(&dva[0], offset);
3605 3607 DVA_SET_GANG(&dva[0], !!(flags & ZDB_FLAG_GBH));
3606 3608 DVA_SET_ASIZE(&dva[0], vdev_psize_to_asize(vd, psize));
3607 3609
3608 3610 BP_SET_BIRTH(bp, TXG_INITIAL, TXG_INITIAL);
3609 3611
3610 3612 BP_SET_LSIZE(bp, lsize);
3611 3613 BP_SET_PSIZE(bp, psize);
3612 3614 BP_SET_COMPRESS(bp, ZIO_COMPRESS_OFF);
3613 3615 BP_SET_CHECKSUM(bp, ZIO_CHECKSUM_OFF);
3614 3616 BP_SET_TYPE(bp, DMU_OT_NONE);
3615 3617 BP_SET_LEVEL(bp, 0);
3616 3618 BP_SET_DEDUP(bp, 0);
3617 3619 BP_SET_BYTEORDER(bp, ZFS_HOST_BYTEORDER);
3618 3620
3619 3621 spa_config_enter(spa, SCL_STATE, FTAG, RW_READER);
3620 3622 zio = zio_root(spa, NULL, NULL, 0);
3621 3623
3622 3624 if (vd == vd->vdev_top) {
3623 3625 /*
3624 3626 * Treat this as a normal block read.
3625 3627 */
3626 3628 zio_nowait(zio_read(zio, spa, bp, pabd, psize, NULL, NULL,
3627 3629 ZIO_PRIORITY_SYNC_READ,
3628 3630 ZIO_FLAG_CANFAIL | ZIO_FLAG_RAW, NULL));
3629 3631 } else {
3630 3632 /*
3631 3633 * Treat this as a vdev child I/O.
3632 3634 */
3633 3635 zio_nowait(zio_vdev_child_io(zio, bp, vd, offset, pabd,
3634 3636 psize, ZIO_TYPE_READ, ZIO_PRIORITY_SYNC_READ,
3635 3637 ZIO_FLAG_DONT_CACHE | ZIO_FLAG_DONT_QUEUE |
3636 3638 ZIO_FLAG_DONT_PROPAGATE | ZIO_FLAG_DONT_RETRY |
3637 3639 ZIO_FLAG_CANFAIL | ZIO_FLAG_RAW, NULL, NULL));
3638 3640 }
3639 3641
3640 3642 error = zio_wait(zio);
3641 3643 spa_config_exit(spa, SCL_STATE, FTAG);
3642 3644
3643 3645 if (error) {
3644 3646 (void) printf("Read of %s failed, error: %d\n", thing, error);
3645 3647 goto out;
3646 3648 }
3647 3649
3648 3650 if (flags & ZDB_FLAG_DECOMPRESS) {
3649 3651 /*
3650 3652 * We don't know how the data was compressed, so just try
3651 3653 * every decompress function at every inflated blocksize.
3652 3654 */
3653 3655 enum zio_compress c;
3654 3656 void *pbuf2 = umem_alloc(SPA_MAXBLOCKSIZE, UMEM_NOFAIL);
3655 3657 void *lbuf2 = umem_alloc(SPA_MAXBLOCKSIZE, UMEM_NOFAIL);
3656 3658
3657 3659 abd_copy_to_buf(pbuf2, pabd, psize);
3658 3660
3659 3661 VERIFY0(abd_iterate_func(pabd, psize, SPA_MAXBLOCKSIZE - psize,
3660 3662 random_get_pseudo_bytes_cb, NULL));
3661 3663
3662 3664 VERIFY0(random_get_pseudo_bytes((uint8_t *)pbuf2 + psize,
3663 3665 SPA_MAXBLOCKSIZE - psize));
3664 3666
3665 3667 for (lsize = SPA_MAXBLOCKSIZE; lsize > psize;
3666 3668 lsize -= SPA_MINBLOCKSIZE) {
3667 3669 for (c = 0; c < ZIO_COMPRESS_FUNCTIONS; c++) {
3668 3670 if (zio_decompress_data(c, pabd,
3669 3671 lbuf, psize, lsize) == 0 &&
3670 3672 zio_decompress_data_buf(c, pbuf2,
3671 3673 lbuf2, psize, lsize) == 0 &&
3672 3674 bcmp(lbuf, lbuf2, lsize) == 0)
3673 3675 break;
3674 3676 }
3675 3677 if (c != ZIO_COMPRESS_FUNCTIONS)
3676 3678 break;
3677 3679 lsize -= SPA_MINBLOCKSIZE;
3678 3680 }
3679 3681
3680 3682 umem_free(pbuf2, SPA_MAXBLOCKSIZE);
3681 3683 umem_free(lbuf2, SPA_MAXBLOCKSIZE);
3682 3684
3683 3685 if (lsize <= psize) {
3684 3686 (void) printf("Decompress of %s failed\n", thing);
3685 3687 goto out;
3686 3688 }
3687 3689 buf = lbuf;
3688 3690 size = lsize;
3689 3691 } else {
3690 3692 buf = abd_to_buf(pabd);
3691 3693 size = psize;
3692 3694 }
3693 3695
3694 3696 if (flags & ZDB_FLAG_PRINT_BLKPTR)
3695 3697 zdb_print_blkptr((blkptr_t *)(void *)
3696 3698 ((uintptr_t)buf + (uintptr_t)blkptr_offset), flags);
3697 3699 else if (flags & ZDB_FLAG_RAW)
3698 3700 zdb_dump_block_raw(buf, size, flags);
3699 3701 else if (flags & ZDB_FLAG_INDIRECT)
3700 3702 zdb_dump_indirect((blkptr_t *)buf, size / sizeof (blkptr_t),
3701 3703 flags);
3702 3704 else if (flags & ZDB_FLAG_GBH)
3703 3705 zdb_dump_gbh(buf, flags);
3704 3706 else
3705 3707 zdb_dump_block(thing, buf, size, flags);
3706 3708
3707 3709 out:
3708 3710 abd_free(pabd);
3709 3711 umem_free(lbuf, SPA_MAXBLOCKSIZE);
3710 3712 free(dup);
3711 3713 }
3712 3714
3713 3715 static void
3714 3716 zdb_embedded_block(char *thing)
3715 3717 {
3716 3718 blkptr_t bp;
3717 3719 unsigned long long *words = (void *)&bp;
3718 3720 char buf[SPA_MAXBLOCKSIZE];
3719 3721 int err;
3720 3722
3721 3723 bzero(&bp, sizeof (bp));
3722 3724 err = sscanf(thing, "%llx:%llx:%llx:%llx:%llx:%llx:%llx:%llx:"
3723 3725 "%llx:%llx:%llx:%llx:%llx:%llx:%llx:%llx",
3724 3726 words + 0, words + 1, words + 2, words + 3,
3725 3727 words + 4, words + 5, words + 6, words + 7,
3726 3728 words + 8, words + 9, words + 10, words + 11,
3727 3729 words + 12, words + 13, words + 14, words + 15);
3728 3730 if (err != 16) {
3729 3731 (void) printf("invalid input format\n");
3730 3732 exit(1);
3731 3733 }
3732 3734 ASSERT3U(BPE_GET_LSIZE(&bp), <=, SPA_MAXBLOCKSIZE);
3733 3735 err = decode_embedded_bp(&bp, buf, BPE_GET_LSIZE(&bp));
3734 3736 if (err != 0) {
3735 3737 (void) printf("decode failed: %u\n", err);
3736 3738 exit(1);
3737 3739 }
3738 3740 zdb_dump_block_raw(buf, BPE_GET_LSIZE(&bp), 0);
3739 3741 }
3740 3742
3741 3743 static boolean_t
3742 3744 pool_match(nvlist_t *cfg, char *tgt)
3743 3745 {
3744 3746 uint64_t v, guid = strtoull(tgt, NULL, 0);
3745 3747 char *s;
3746 3748
3747 3749 if (guid != 0) {
3748 3750 if (nvlist_lookup_uint64(cfg, ZPOOL_CONFIG_POOL_GUID, &v) == 0)
3749 3751 return (v == guid);
3750 3752 } else {
3751 3753 if (nvlist_lookup_string(cfg, ZPOOL_CONFIG_POOL_NAME, &s) == 0)
3752 3754 return (strcmp(s, tgt) == 0);
3753 3755 }
3754 3756 return (B_FALSE);
3755 3757 }
3756 3758
3757 3759 static char *
3758 3760 find_zpool(char **target, nvlist_t **configp, int dirc, char **dirv)
3759 3761 {
3760 3762 nvlist_t *pools;
3761 3763 nvlist_t *match = NULL;
3762 3764 char *name = NULL;
3763 3765 char *sepp = NULL;
3764 3766 char sep = '\0';
3765 3767 int count = 0;
3766 3768 importargs_t args;
3767 3769
3768 3770 bzero(&args, sizeof (args));
3769 3771 args.paths = dirc;
3770 3772 args.path = dirv;
3771 3773 args.can_be_active = B_TRUE;
3772 3774
3773 3775 if ((sepp = strpbrk(*target, "/@")) != NULL) {
3774 3776 sep = *sepp;
3775 3777 *sepp = '\0';
3776 3778 }
3777 3779
3778 3780 pools = zpool_search_import(g_zfs, &args);
3779 3781
3780 3782 if (pools != NULL) {
3781 3783 nvpair_t *elem = NULL;
3782 3784 while ((elem = nvlist_next_nvpair(pools, elem)) != NULL) {
3783 3785 verify(nvpair_value_nvlist(elem, configp) == 0);
3784 3786 if (pool_match(*configp, *target)) {
3785 3787 count++;
3786 3788 if (match != NULL) {
3787 3789 /* print previously found config */
3788 3790 if (name != NULL) {
3789 3791 (void) printf("%s\n", name);
3790 3792 dump_nvlist(match, 8);
3791 3793 name = NULL;
3792 3794 }
3793 3795 (void) printf("%s\n",
3794 3796 nvpair_name(elem));
3795 3797 dump_nvlist(*configp, 8);
3796 3798 } else {
3797 3799 match = *configp;
3798 3800 name = nvpair_name(elem);
3799 3801 }
3800 3802 }
3801 3803 }
3802 3804 }
3803 3805 if (count > 1)
3804 3806 (void) fatal("\tMatched %d pools - use pool GUID "
3805 3807 "instead of pool name or \n"
3806 3808 "\tpool name part of a dataset name to select pool", count);
3807 3809
3808 3810 if (sepp)
3809 3811 *sepp = sep;
3810 3812 /*
3811 3813 * If pool GUID was specified for pool id, replace it with pool name
3812 3814 */
3813 3815 if (name && (strstr(*target, name) != *target)) {
3814 3816 int sz = 1 + strlen(name) + ((sepp) ? strlen(sepp) : 0);
3815 3817
3816 3818 *target = umem_alloc(sz, UMEM_NOFAIL);
3817 3819 (void) snprintf(*target, sz, "%s%s", name, sepp ? sepp : "");
3818 3820 }
3819 3821
3820 3822 *configp = name ? match : NULL;
3821 3823
3822 3824 return (name);
3823 3825 }
3824 3826
3825 3827 int
3826 3828 main(int argc, char **argv)
3827 3829 {
3828 3830 int c;
3829 3831 struct rlimit rl = { 1024, 1024 };
3830 3832 spa_t *spa = NULL;
3831 3833 objset_t *os = NULL;
3832 3834 int dump_all = 1;
3833 3835 int verbose = 0;
3834 3836 int error = 0;
3835 3837 char **searchdirs = NULL;
3836 3838 int nsearch = 0;
3837 3839 char *target;
3838 3840 nvlist_t *policy = NULL;
3839 3841 uint64_t max_txg = UINT64_MAX;
3840 3842 int flags = ZFS_IMPORT_MISSING_LOG;
3841 3843 int rewind = ZPOOL_NEVER_REWIND;
3842 3844 char *spa_config_path_env;
3843 3845 boolean_t target_is_spa = B_TRUE;
3844 3846
3845 3847 (void) setrlimit(RLIMIT_NOFILE, &rl);
3846 3848 (void) enable_extended_FILE_stdio(-1, -1);
3847 3849
3848 3850 dprintf_setup(&argc, argv);
3849 3851
3850 3852 /*
3851 3853 * If there is an environment variable SPA_CONFIG_PATH it overrides
3852 3854 * default spa_config_path setting. If -U flag is specified it will
3853 3855 * override this environment variable settings once again.
3854 3856 */
3855 3857 spa_config_path_env = getenv("SPA_CONFIG_PATH");
3856 3858 if (spa_config_path_env != NULL)
3857 3859 spa_config_path = spa_config_path_env;
3858 3860
3859 3861 while ((c = getopt(argc, argv,
3860 3862 "AbcCdDeEFGhiI:lLmMo:Op:PqRsSt:uU:vVx:X")) != -1) {
3861 3863 switch (c) {
3862 3864 case 'b':
3863 3865 case 'c':
3864 3866 case 'C':
3865 3867 case 'd':
3866 3868 case 'D':
3867 3869 case 'E':
3868 3870 case 'G':
3869 3871 case 'h':
3870 3872 case 'i':
3871 3873 case 'l':
3872 3874 case 'm':
3873 3875 case 'M':
3874 3876 case 'O':
3875 3877 case 'R':
3876 3878 case 's':
3877 3879 case 'S':
3878 3880 case 'u':
3879 3881 dump_opt[c]++;
3880 3882 dump_all = 0;
3881 3883 break;
3882 3884 case 'A':
3883 3885 case 'e':
3884 3886 case 'F':
3885 3887 case 'L':
3886 3888 case 'P':
3887 3889 case 'q':
3888 3890 case 'X':
3889 3891 dump_opt[c]++;
3890 3892 break;
3891 3893 /* NB: Sort single match options below. */
3892 3894 case 'I':
3893 3895 max_inflight = strtoull(optarg, NULL, 0);
3894 3896 if (max_inflight == 0) {
3895 3897 (void) fprintf(stderr, "maximum number "
3896 3898 "of inflight I/Os must be greater "
3897 3899 "than 0\n");
3898 3900 usage();
3899 3901 }
3900 3902 break;
3901 3903 case 'o':
3902 3904 error = set_global_var(optarg);
3903 3905 if (error != 0)
3904 3906 usage();
3905 3907 break;
3906 3908 case 'p':
3907 3909 if (searchdirs == NULL) {
3908 3910 searchdirs = umem_alloc(sizeof (char *),
3909 3911 UMEM_NOFAIL);
3910 3912 } else {
3911 3913 char **tmp = umem_alloc((nsearch + 1) *
3912 3914 sizeof (char *), UMEM_NOFAIL);
3913 3915 bcopy(searchdirs, tmp, nsearch *
3914 3916 sizeof (char *));
3915 3917 umem_free(searchdirs,
3916 3918 nsearch * sizeof (char *));
3917 3919 searchdirs = tmp;
3918 3920 }
3919 3921 searchdirs[nsearch++] = optarg;
3920 3922 break;
3921 3923 case 't':
3922 3924 max_txg = strtoull(optarg, NULL, 0);
3923 3925 if (max_txg < TXG_INITIAL) {
3924 3926 (void) fprintf(stderr, "incorrect txg "
3925 3927 "specified: %s\n", optarg);
3926 3928 usage();
3927 3929 }
3928 3930 break;
3929 3931 case 'U':
3930 3932 spa_config_path = optarg;
3931 3933 if (spa_config_path[0] != '/') {
3932 3934 (void) fprintf(stderr,
3933 3935 "cachefile must be an absolute path "
3934 3936 "(i.e. start with a slash)\n");
3935 3937 usage();
3936 3938 }
3937 3939 break;
3938 3940 case 'v':
3939 3941 verbose++;
3940 3942 break;
3941 3943 case 'V':
3942 3944 flags = ZFS_IMPORT_VERBATIM;
3943 3945 break;
3944 3946 case 'x':
3945 3947 vn_dumpdir = optarg;
3946 3948 break;
3947 3949 default:
3948 3950 usage();
3949 3951 break;
3950 3952 }
3951 3953 }
3952 3954
3953 3955 if (!dump_opt['e'] && searchdirs != NULL) {
3954 3956 (void) fprintf(stderr, "-p option requires use of -e\n");
3955 3957 usage();
3956 3958 }
3957 3959
3958 3960 /*
3959 3961 * ZDB does not typically re-read blocks; therefore limit the ARC
3960 3962 * to 256 MB, which can be used entirely for metadata.
3961 3963 */
3962 3964 zfs_arc_max = zfs_arc_meta_limit = 256 * 1024 * 1024;
3963 3965
3964 3966 /*
3965 3967 * "zdb -c" uses checksum-verifying scrub i/os which are async reads.
3966 3968 * "zdb -b" uses traversal prefetch which uses async reads.
3967 3969 * For good performance, let several of them be active at once.
3968 3970 */
3969 3971 zfs_vdev_async_read_max_active = 10;
3970 3972
3971 3973 /*
3972 3974 * Disable reference tracking for better performance.
3973 3975 */
3974 3976 reference_tracking_enable = B_FALSE;
3975 3977
3976 3978 kernel_init(FREAD);
3977 3979 g_zfs = libzfs_init();
3978 3980 ASSERT(g_zfs != NULL);
3979 3981
3980 3982 if (dump_all)
3981 3983 verbose = MAX(verbose, 1);
3982 3984
3983 3985 for (c = 0; c < 256; c++) {
3984 3986 if (dump_all && strchr("AeEFlLOPRSX", c) == NULL)
3985 3987 dump_opt[c] = 1;
3986 3988 if (dump_opt[c])
3987 3989 dump_opt[c] += verbose;
3988 3990 }
3989 3991
3990 3992 aok = (dump_opt['A'] == 1) || (dump_opt['A'] > 2);
3991 3993 zfs_recover = (dump_opt['A'] > 1);
3992 3994
3993 3995 argc -= optind;
3994 3996 argv += optind;
3995 3997
3996 3998 if (argc < 2 && dump_opt['R'])
3997 3999 usage();
3998 4000
3999 4001 if (dump_opt['E']) {
4000 4002 if (argc != 1)
4001 4003 usage();
4002 4004 zdb_embedded_block(argv[0]);
4003 4005 return (0);
4004 4006 }
4005 4007
4006 4008 if (argc < 1) {
4007 4009 if (!dump_opt['e'] && dump_opt['C']) {
4008 4010 dump_cachefile(spa_config_path);
4009 4011 return (0);
4010 4012 }
4011 4013 usage();
4012 4014 }
4013 4015
4014 4016 if (dump_opt['l'])
4015 4017 return (dump_label(argv[0]));
4016 4018
4017 4019 if (dump_opt['O']) {
4018 4020 if (argc != 2)
4019 4021 usage();
4020 4022 dump_opt['v'] = verbose + 3;
4021 4023 return (dump_path(argv[0], argv[1]));
4022 4024 }
4023 4025
4024 4026 if (dump_opt['X'] || dump_opt['F'])
4025 4027 rewind = ZPOOL_DO_REWIND |
4026 4028 (dump_opt['X'] ? ZPOOL_EXTREME_REWIND : 0);
4027 4029
4028 4030 if (nvlist_alloc(&policy, NV_UNIQUE_NAME_TYPE, 0) != 0 ||
4029 4031 nvlist_add_uint64(policy, ZPOOL_REWIND_REQUEST_TXG, max_txg) != 0 ||
4030 4032 nvlist_add_uint32(policy, ZPOOL_REWIND_REQUEST, rewind) != 0)
4031 4033 fatal("internal error: %s", strerror(ENOMEM));
4032 4034
4033 4035 error = 0;
4034 4036 target = argv[0];
4035 4037
4036 4038 if (dump_opt['e']) {
4037 4039 nvlist_t *cfg = NULL;
4038 4040 char *name = find_zpool(&target, &cfg, nsearch, searchdirs);
4039 4041
4040 4042 error = ENOENT;
4041 4043 if (name) {
4042 4044 if (dump_opt['C'] > 1) {
4043 4045 (void) printf("\nConfiguration for import:\n");
4044 4046 dump_nvlist(cfg, 8);
4045 4047 }
4046 4048 if (nvlist_add_nvlist(cfg,
4047 4049 ZPOOL_REWIND_POLICY, policy) != 0) {
4048 4050 fatal("can't open '%s': %s",
4049 4051 target, strerror(ENOMEM));
4050 4052 }
4051 4053 error = spa_import(name, cfg, NULL, flags);
4052 4054 }
4053 4055 }
4054 4056
4055 4057 if (strpbrk(target, "/@") != NULL) {
4056 4058 size_t targetlen;
4057 4059
4058 4060 target_is_spa = B_FALSE;
4059 4061 /*
4060 4062 * Remove any trailing slash. Later code would get confused
4061 4063 * by it, but we want to allow it so that "pool/" can
4062 4064 * indicate that we want to dump the topmost filesystem,
4063 4065 * rather than the whole pool.
4064 4066 */
4065 4067 targetlen = strlen(target);
4066 4068 if (targetlen != 0 && target[targetlen - 1] == '/')
4067 4069 target[targetlen - 1] = '\0';
4068 4070 }
4069 4071
4070 4072 if (error == 0) {
4071 4073 if (target_is_spa || dump_opt['R']) {
4072 4074 error = spa_open_rewind(target, &spa, FTAG, policy,
4073 4075 NULL);
4074 4076 if (error) {
4075 4077 /*
4076 4078 * If we're missing the log device then
4077 4079 * try opening the pool after clearing the
4078 4080 * log state.
4079 4081 */
4080 4082 mutex_enter(&spa_namespace_lock);
4081 4083 if ((spa = spa_lookup(target)) != NULL &&
4082 4084 spa->spa_log_state == SPA_LOG_MISSING) {
4083 4085 spa->spa_log_state = SPA_LOG_CLEAR;
4084 4086 error = 0;
4085 4087 }
4086 4088 mutex_exit(&spa_namespace_lock);
4087 4089
4088 4090 if (!error) {
4089 4091 error = spa_open_rewind(target, &spa,
4090 4092 FTAG, policy, NULL);
4091 4093 }
4092 4094 }
4093 4095 } else {
4094 4096 error = open_objset(target, DMU_OST_ANY, FTAG, &os);
4095 4097 }
4096 4098 }
4097 4099 nvlist_free(policy);
4098 4100
4099 4101 if (error)
4100 4102 fatal("can't open '%s': %s", target, strerror(error));
4101 4103
4102 4104 argv++;
4103 4105 argc--;
4104 4106 if (!dump_opt['R']) {
4105 4107 if (argc > 0) {
4106 4108 zopt_objects = argc;
4107 4109 zopt_object = calloc(zopt_objects, sizeof (uint64_t));
4108 4110 for (unsigned i = 0; i < zopt_objects; i++) {
4109 4111 errno = 0;
4110 4112 zopt_object[i] = strtoull(argv[i], NULL, 0);
4111 4113 if (zopt_object[i] == 0 && errno != 0)
4112 4114 fatal("bad number %s: %s",
4113 4115 argv[i], strerror(errno));
4114 4116 }
4115 4117 }
4116 4118 if (os != NULL) {
4117 4119 dump_dir(os);
4118 4120 } else if (zopt_objects > 0 && !dump_opt['m']) {
4119 4121 dump_dir(spa->spa_meta_objset);
4120 4122 } else {
4121 4123 dump_zpool(spa);
4122 4124 }
4123 4125 } else {
4124 4126 flagbits['b'] = ZDB_FLAG_PRINT_BLKPTR;
4125 4127 flagbits['c'] = ZDB_FLAG_CHECKSUM;
4126 4128 flagbits['d'] = ZDB_FLAG_DECOMPRESS;
4127 4129 flagbits['e'] = ZDB_FLAG_BSWAP;
4128 4130 flagbits['g'] = ZDB_FLAG_GBH;
4129 4131 flagbits['i'] = ZDB_FLAG_INDIRECT;
4130 4132 flagbits['p'] = ZDB_FLAG_PHYS;
4131 4133 flagbits['r'] = ZDB_FLAG_RAW;
4132 4134
4133 4135 for (int i = 0; i < argc; i++)
4134 4136 zdb_read_block(argv[i], spa);
4135 4137 }
4136 4138
4137 4139 if (os != NULL)
4138 4140 close_objset(os, FTAG);
4139 4141 else
4140 4142 spa_close(spa, FTAG);
4141 4143
4142 4144 fuid_table_destroy();
4143 4145
4144 4146 dump_debug_buffer();
4145 4147
4146 4148 libzfs_fini(g_zfs);
4147 4149 kernel_fini();
4148 4150
4149 4151 return (0);
4150 4152 }
↓ open down ↓ |
4044 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX