4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Copyright (c) 2011, 2018 by Delphix. All rights reserved.
25 * Copyright (c) 2014 Integros [integros.com]
26 * Copyright 2016 Nexenta Systems, Inc.
27 * Copyright (c) 2017, 2018 Lawrence Livermore National Security, LLC.
28 * Copyright (c) 2015, 2017, Intel Corporation.
33 #include <stdio_ext.h>
36 #include <sys/zfs_context.h>
38 #include <sys/spa_impl.h>
41 #include <sys/fs/zfs.h>
42 #include <sys/zfs_znode.h>
43 #include <sys/zfs_sa.h>
45 #include <sys/sa_impl.h>
47 #include <sys/vdev_impl.h>
48 #include <sys/metaslab_impl.h>
49 #include <sys/dmu_objset.h>
50 #include <sys/dsl_dir.h>
51 #include <sys/dsl_dataset.h>
52 #include <sys/dsl_pool.h>
55 #include <sys/zil_impl.h>
57 #include <sys/resource.h>
58 #include <sys/dmu_traverse.h>
59 #include <sys/zio_checksum.h>
60 #include <sys/zio_compress.h>
61 #include <sys/zfs_fuid.h>
64 #include <sys/zfeature.h>
66 #include <sys/blkptr.h>
67 #include <sys/dsl_crypt.h>
68 #include <sys/dsl_scan.h>
69 #include <zfs_comutil.h>
74 #define ZDB_COMPRESS_NAME(idx) ((idx) < ZIO_COMPRESS_FUNCTIONS ? \
75 zio_compress_table[(idx)].ci_name : "UNKNOWN")
76 #define ZDB_CHECKSUM_NAME(idx) ((idx) < ZIO_CHECKSUM_FUNCTIONS ? \
77 zio_checksum_table[(idx)].ci_name : "UNKNOWN")
78 #define ZDB_OT_TYPE(idx) ((idx) < DMU_OT_NUMTYPES ? (idx) : \
79 (idx) == DMU_OTN_ZAP_DATA || (idx) == DMU_OTN_ZAP_METADATA ? \
81 (idx) == DMU_OTN_UINT64_DATA || (idx) == DMU_OTN_UINT64_METADATA ? \
82 DMU_OT_UINT64_OTHER : DMU_OT_NUMTYPES)
85 zdb_ot_name(dmu_object_type_t type
)
87 if (type
< DMU_OT_NUMTYPES
)
88 return (dmu_ot
[type
].ot_name
);
89 else if ((type
& DMU_OT_NEWTYPE
) &&
90 ((type
& DMU_OT_BYTESWAP_MASK
) < DMU_BSWAP_NUMFUNCS
))
91 return (dmu_ot_byteswap
[type
& DMU_OT_BYTESWAP_MASK
].ob_name
);
96 extern int reference_tracking_enable
;
97 extern int zfs_recover
;
98 extern uint64_t zfs_arc_max
, zfs_arc_meta_limit
;
99 extern int zfs_vdev_async_read_max_active
;
100 extern boolean_t spa_load_verify_dryrun
;
102 static const char cmdname
[] = "zdb";
103 uint8_t dump_opt
[256];
105 typedef void object_viewer_t(objset_t
*, uint64_t, void *data
, size_t size
);
107 uint64_t *zopt_object
= NULL
;
108 static unsigned zopt_objects
= 0;
109 libzfs_handle_t
*g_zfs
;
110 uint64_t max_inflight
= 1000;
111 static int leaked_objects
= 0;
112 static range_tree_t
*mos_refd_objs
;
114 static void snprintf_blkptr_compact(char *, size_t, const blkptr_t
*);
115 static void mos_obj_refd(uint64_t);
116 static void mos_obj_refd_multiple(uint64_t);
119 * These libumem hooks provide a reasonable set of defaults for the allocator's
120 * debugging facilities.
123 _umem_debug_init(void)
125 return ("default,verbose"); /* $UMEM_DEBUG setting */
129 _umem_logging_init(void)
131 return ("fail,contents"); /* $UMEM_LOGGING setting */
137 (void) fprintf(stderr
,
138 "Usage:\t%s [-AbcdDFGhikLMPsvX] [-e [-V] [-p <path> ...]] "
139 "[-I <inflight I/Os>]\n"
140 "\t\t[-o <var>=<value>]... [-t <txg>] [-U <cache>] [-x <dumpdir>]\n"
141 "\t\t[<poolname> [<object> ...]]\n"
142 "\t%s [-AdiPv] [-e [-V] [-p <path> ...]] [-U <cache>] <dataset>\n"
143 "\t\t[<object> ...]\n"
144 "\t%s -C [-A] [-U <cache>]\n"
145 "\t%s -l [-Aqu] <device>\n"
146 "\t%s -m [-AFLPX] [-e [-V] [-p <path> ...]] [-t <txg>] "
147 "[-U <cache>]\n\t\t<poolname> [<vdev> [<metaslab> ...]]\n"
148 "\t%s -O <dataset> <path>\n"
149 "\t%s -R [-A] [-e [-V] [-p <path> ...]] [-U <cache>]\n"
150 "\t\t<poolname> <vdev>:<offset>:<size>[:<flags>]\n"
151 "\t%s -E [-A] word0:word1:...:word15\n"
152 "\t%s -S [-AP] [-e [-V] [-p <path> ...]] [-U <cache>] "
154 cmdname
, cmdname
, cmdname
, cmdname
, cmdname
, cmdname
, cmdname
,
157 (void) fprintf(stderr
, " Dataset name must include at least one "
158 "separator character '/' or '@'\n");
159 (void) fprintf(stderr
, " If dataset name is specified, only that "
160 "dataset is dumped\n");
161 (void) fprintf(stderr
, " If object numbers are specified, only "
162 "those objects are dumped\n\n");
163 (void) fprintf(stderr
, " Options to control amount of output:\n");
164 (void) fprintf(stderr
, " -b block statistics\n");
165 (void) fprintf(stderr
, " -c checksum all metadata (twice for "
166 "all data) blocks\n");
167 (void) fprintf(stderr
, " -C config (or cachefile if alone)\n");
168 (void) fprintf(stderr
, " -d dataset(s)\n");
169 (void) fprintf(stderr
, " -D dedup statistics\n");
170 (void) fprintf(stderr
, " -E decode and display block from an "
171 "embedded block pointer\n");
172 (void) fprintf(stderr
, " -h pool history\n");
173 (void) fprintf(stderr
, " -i intent logs\n");
174 (void) fprintf(stderr
, " -l read label contents\n");
175 (void) fprintf(stderr
, " -k examine the checkpointed state "
177 (void) fprintf(stderr
, " -L disable leak tracking (do not "
178 "load spacemaps)\n");
179 (void) fprintf(stderr
, " -m metaslabs\n");
180 (void) fprintf(stderr
, " -M metaslab groups\n");
181 (void) fprintf(stderr
, " -O perform object lookups by path\n");
182 (void) fprintf(stderr
, " -R read and display block from a "
184 (void) fprintf(stderr
, " -s report stats on zdb's I/O\n");
185 (void) fprintf(stderr
, " -S simulate dedup to measure effect\n");
186 (void) fprintf(stderr
, " -v verbose (applies to all "
188 (void) fprintf(stderr
, " Below options are intended for use "
189 "with other options:\n");
190 (void) fprintf(stderr
, " -A ignore assertions (-A), enable "
191 "panic recovery (-AA) or both (-AAA)\n");
192 (void) fprintf(stderr
, " -e pool is exported/destroyed/"
193 "has altroot/not in a cachefile\n");
194 (void) fprintf(stderr
, " -F attempt automatic rewind within "
195 "safe range of transaction groups\n");
196 (void) fprintf(stderr
, " -G dump zfs_dbgmsg buffer before "
198 (void) fprintf(stderr
, " -I <number of inflight I/Os> -- "
199 "specify the maximum number of\n "
200 "checksumming I/Os [default is 200]\n");
201 (void) fprintf(stderr
, " -o <variable>=<value> set global "
202 "variable to an unsigned 32-bit integer\n");
203 (void) fprintf(stderr
, " -p <path> -- use one or more with "
204 "-e to specify path to vdev dir\n");
205 (void) fprintf(stderr
, " -P print numbers in parseable form\n");
206 (void) fprintf(stderr
, " -q don't print label contents\n");
207 (void) fprintf(stderr
, " -t <txg> -- highest txg to use when "
208 "searching for uberblocks\n");
209 (void) fprintf(stderr
, " -u uberblock\n");
210 (void) fprintf(stderr
, " -U <cachefile_path> -- use alternate "
212 (void) fprintf(stderr
, " -V do verbatim import\n");
213 (void) fprintf(stderr
, " -x <dumpdir> -- "
214 "dump all read blocks into specified directory\n");
215 (void) fprintf(stderr
, " -X attempt extreme rewind (does not "
216 "work with dataset)\n");
217 (void) fprintf(stderr
, "Specify an option more than once (e.g. -bb) "
218 "to make only that option verbose\n");
219 (void) fprintf(stderr
, "Default is to dump everything non-verbosely\n");
224 dump_debug_buffer(void)
228 (void) fflush(stdout
);
229 zfs_dbgmsg_print("zdb");
234 * Called for usage errors that are discovered after a call to spa_open(),
235 * dmu_bonus_hold(), or pool_match(). abort() is called for other errors.
239 fatal(const char *fmt
, ...)
244 (void) fprintf(stderr
, "%s: ", cmdname
);
245 (void) vfprintf(stderr
, fmt
, ap
);
247 (void) fprintf(stderr
, "\n");
256 dump_packed_nvlist(objset_t
*os
, uint64_t object
, void *data
, size_t size
)
259 size_t nvsize
= *(uint64_t *)data
;
260 char *packed
= umem_alloc(nvsize
, UMEM_NOFAIL
);
262 VERIFY(0 == dmu_read(os
, object
, 0, nvsize
, packed
, DMU_READ_PREFETCH
));
264 VERIFY(nvlist_unpack(packed
, nvsize
, &nv
, 0) == 0);
266 umem_free(packed
, nvsize
);
275 dump_history_offsets(objset_t
*os
, uint64_t object
, void *data
, size_t size
)
277 spa_history_phys_t
*shp
= data
;
282 (void) printf("\t\tpool_create_len = %llu\n",
283 (u_longlong_t
)shp
->sh_pool_create_len
);
284 (void) printf("\t\tphys_max_off = %llu\n",
285 (u_longlong_t
)shp
->sh_phys_max_off
);
286 (void) printf("\t\tbof = %llu\n",
287 (u_longlong_t
)shp
->sh_bof
);
288 (void) printf("\t\teof = %llu\n",
289 (u_longlong_t
)shp
->sh_eof
);
290 (void) printf("\t\trecords_lost = %llu\n",
291 (u_longlong_t
)shp
->sh_records_lost
);
295 zdb_nicenum(uint64_t num
, char *buf
, size_t buflen
)
298 (void) snprintf(buf
, buflen
, "%llu", (longlong_t
)num
);
300 nicenum(num
, buf
, sizeof (buf
));
303 static const char histo_stars
[] = "****************************************";
304 static const uint64_t histo_width
= sizeof (histo_stars
) - 1;
307 dump_histogram(const uint64_t *histo
, int size
, int offset
)
310 int minidx
= size
- 1;
314 for (i
= 0; i
< size
; i
++) {
317 if (histo
[i
] > 0 && i
> maxidx
)
319 if (histo
[i
] > 0 && i
< minidx
)
323 if (max
< histo_width
)
326 for (i
= minidx
; i
<= maxidx
; i
++) {
327 (void) printf("\t\t\t%3u: %6llu %s\n",
328 i
+ offset
, (u_longlong_t
)histo
[i
],
329 &histo_stars
[(max
- histo
[i
]) * histo_width
/ max
]);
334 dump_zap_stats(objset_t
*os
, uint64_t object
)
339 error
= zap_get_stats(os
, object
, &zs
);
343 if (zs
.zs_ptrtbl_len
== 0) {
344 ASSERT(zs
.zs_num_blocks
== 1);
345 (void) printf("\tmicrozap: %llu bytes, %llu entries\n",
346 (u_longlong_t
)zs
.zs_blocksize
,
347 (u_longlong_t
)zs
.zs_num_entries
);
351 (void) printf("\tFat ZAP stats:\n");
353 (void) printf("\t\tPointer table:\n");
354 (void) printf("\t\t\t%llu elements\n",
355 (u_longlong_t
)zs
.zs_ptrtbl_len
);
356 (void) printf("\t\t\tzt_blk: %llu\n",
357 (u_longlong_t
)zs
.zs_ptrtbl_zt_blk
);
358 (void) printf("\t\t\tzt_numblks: %llu\n",
359 (u_longlong_t
)zs
.zs_ptrtbl_zt_numblks
);
360 (void) printf("\t\t\tzt_shift: %llu\n",
361 (u_longlong_t
)zs
.zs_ptrtbl_zt_shift
);
362 (void) printf("\t\t\tzt_blks_copied: %llu\n",
363 (u_longlong_t
)zs
.zs_ptrtbl_blks_copied
);
364 (void) printf("\t\t\tzt_nextblk: %llu\n",
365 (u_longlong_t
)zs
.zs_ptrtbl_nextblk
);
367 (void) printf("\t\tZAP entries: %llu\n",
368 (u_longlong_t
)zs
.zs_num_entries
);
369 (void) printf("\t\tLeaf blocks: %llu\n",
370 (u_longlong_t
)zs
.zs_num_leafs
);
371 (void) printf("\t\tTotal blocks: %llu\n",
372 (u_longlong_t
)zs
.zs_num_blocks
);
373 (void) printf("\t\tzap_block_type: 0x%llx\n",
374 (u_longlong_t
)zs
.zs_block_type
);
375 (void) printf("\t\tzap_magic: 0x%llx\n",
376 (u_longlong_t
)zs
.zs_magic
);
377 (void) printf("\t\tzap_salt: 0x%llx\n",
378 (u_longlong_t
)zs
.zs_salt
);
380 (void) printf("\t\tLeafs with 2^n pointers:\n");
381 dump_histogram(zs
.zs_leafs_with_2n_pointers
, ZAP_HISTOGRAM_SIZE
, 0);
383 (void) printf("\t\tBlocks with n*5 entries:\n");
384 dump_histogram(zs
.zs_blocks_with_n5_entries
, ZAP_HISTOGRAM_SIZE
, 0);
386 (void) printf("\t\tBlocks n/10 full:\n");
387 dump_histogram(zs
.zs_blocks_n_tenths_full
, ZAP_HISTOGRAM_SIZE
, 0);
389 (void) printf("\t\tEntries with n chunks:\n");
390 dump_histogram(zs
.zs_entries_using_n_chunks
, ZAP_HISTOGRAM_SIZE
, 0);
392 (void) printf("\t\tBuckets with n entries:\n");
393 dump_histogram(zs
.zs_buckets_with_n_entries
, ZAP_HISTOGRAM_SIZE
, 0);
398 dump_none(objset_t
*os
, uint64_t object
, void *data
, size_t size
)
404 dump_unknown(objset_t
*os
, uint64_t object
, void *data
, size_t size
)
406 (void) printf("\tUNKNOWN OBJECT TYPE\n");
411 dump_uint8(objset_t
*os
, uint64_t object
, void *data
, size_t size
)
417 dump_uint64(objset_t
*os
, uint64_t object
, void *data
, size_t size
)
423 dump_zap(objset_t
*os
, uint64_t object
, void *data
, size_t size
)
426 zap_attribute_t attr
;
430 dump_zap_stats(os
, object
);
433 for (zap_cursor_init(&zc
, os
, object
);
434 zap_cursor_retrieve(&zc
, &attr
) == 0;
435 zap_cursor_advance(&zc
)) {
436 (void) printf("\t\t%s = ", attr
.za_name
);
437 if (attr
.za_num_integers
== 0) {
441 prop
= umem_zalloc(attr
.za_num_integers
*
442 attr
.za_integer_length
, UMEM_NOFAIL
);
443 (void) zap_lookup(os
, object
, attr
.za_name
,
444 attr
.za_integer_length
, attr
.za_num_integers
, prop
);
445 if (attr
.za_integer_length
== 1) {
446 (void) printf("%s", (char *)prop
);
448 for (i
= 0; i
< attr
.za_num_integers
; i
++) {
449 switch (attr
.za_integer_length
) {
452 ((uint16_t *)prop
)[i
]);
456 ((uint32_t *)prop
)[i
]);
459 (void) printf("%lld ",
460 (u_longlong_t
)((int64_t *)prop
)[i
]);
466 umem_free(prop
, attr
.za_num_integers
* attr
.za_integer_length
);
468 zap_cursor_fini(&zc
);
472 dump_bpobj(objset_t
*os
, uint64_t object
, void *data
, size_t size
)
474 bpobj_phys_t
*bpop
= data
;
476 char bytes
[32], comp
[32], uncomp
[32];
478 /* make sure the output won't get truncated */
479 CTASSERT(sizeof (bytes
) >= NN_NUMBUF_SZ
);
480 CTASSERT(sizeof (comp
) >= NN_NUMBUF_SZ
);
481 CTASSERT(sizeof (uncomp
) >= NN_NUMBUF_SZ
);
486 zdb_nicenum(bpop
->bpo_bytes
, bytes
, sizeof (bytes
));
487 zdb_nicenum(bpop
->bpo_comp
, comp
, sizeof (comp
));
488 zdb_nicenum(bpop
->bpo_uncomp
, uncomp
, sizeof (uncomp
));
490 (void) printf("\t\tnum_blkptrs = %llu\n",
491 (u_longlong_t
)bpop
->bpo_num_blkptrs
);
492 (void) printf("\t\tbytes = %s\n", bytes
);
493 if (size
>= BPOBJ_SIZE_V1
) {
494 (void) printf("\t\tcomp = %s\n", comp
);
495 (void) printf("\t\tuncomp = %s\n", uncomp
);
497 if (size
>= sizeof (*bpop
)) {
498 (void) printf("\t\tsubobjs = %llu\n",
499 (u_longlong_t
)bpop
->bpo_subobjs
);
500 (void) printf("\t\tnum_subobjs = %llu\n",
501 (u_longlong_t
)bpop
->bpo_num_subobjs
);
504 if (dump_opt
['d'] < 5)
507 for (i
= 0; i
< bpop
->bpo_num_blkptrs
; i
++) {
508 char blkbuf
[BP_SPRINTF_LEN
];
511 int err
= dmu_read(os
, object
,
512 i
* sizeof (bp
), sizeof (bp
), &bp
, 0);
514 (void) printf("got error %u from dmu_read\n", err
);
517 snprintf_blkptr_compact(blkbuf
, sizeof (blkbuf
), &bp
);
518 (void) printf("\t%s\n", blkbuf
);
524 dump_bpobj_subobjs(objset_t
*os
, uint64_t object
, void *data
, size_t size
)
526 dmu_object_info_t doi
;
529 VERIFY0(dmu_object_info(os
, object
, &doi
));
530 uint64_t *subobjs
= kmem_alloc(doi
.doi_max_offset
, KM_SLEEP
);
532 int err
= dmu_read(os
, object
, 0, doi
.doi_max_offset
, subobjs
, 0);
534 (void) printf("got error %u from dmu_read\n", err
);
535 kmem_free(subobjs
, doi
.doi_max_offset
);
539 int64_t last_nonzero
= -1;
540 for (i
= 0; i
< doi
.doi_max_offset
/ 8; i
++) {
545 for (i
= 0; i
<= last_nonzero
; i
++) {
546 (void) printf("\t%llu\n", (u_longlong_t
)subobjs
[i
]);
548 kmem_free(subobjs
, doi
.doi_max_offset
);
553 dump_ddt_zap(objset_t
*os
, uint64_t object
, void *data
, size_t size
)
555 dump_zap_stats(os
, object
);
556 /* contents are printed elsewhere, properly decoded */
561 dump_sa_attrs(objset_t
*os
, uint64_t object
, void *data
, size_t size
)
564 zap_attribute_t attr
;
566 dump_zap_stats(os
, object
);
569 for (zap_cursor_init(&zc
, os
, object
);
570 zap_cursor_retrieve(&zc
, &attr
) == 0;
571 zap_cursor_advance(&zc
)) {
572 (void) printf("\t\t%s = ", attr
.za_name
);
573 if (attr
.za_num_integers
== 0) {
577 (void) printf(" %llx : [%d:%d:%d]\n",
578 (u_longlong_t
)attr
.za_first_integer
,
579 (int)ATTR_LENGTH(attr
.za_first_integer
),
580 (int)ATTR_BSWAP(attr
.za_first_integer
),
581 (int)ATTR_NUM(attr
.za_first_integer
));
583 zap_cursor_fini(&zc
);
588 dump_sa_layouts(objset_t
*os
, uint64_t object
, void *data
, size_t size
)
591 zap_attribute_t attr
;
592 uint16_t *layout_attrs
;
595 dump_zap_stats(os
, object
);
598 for (zap_cursor_init(&zc
, os
, object
);
599 zap_cursor_retrieve(&zc
, &attr
) == 0;
600 zap_cursor_advance(&zc
)) {
601 (void) printf("\t\t%s = [", attr
.za_name
);
602 if (attr
.za_num_integers
== 0) {
607 VERIFY(attr
.za_integer_length
== 2);
608 layout_attrs
= umem_zalloc(attr
.za_num_integers
*
609 attr
.za_integer_length
, UMEM_NOFAIL
);
611 VERIFY(zap_lookup(os
, object
, attr
.za_name
,
612 attr
.za_integer_length
,
613 attr
.za_num_integers
, layout_attrs
) == 0);
615 for (i
= 0; i
!= attr
.za_num_integers
; i
++)
616 (void) printf(" %d ", (int)layout_attrs
[i
]);
617 (void) printf("]\n");
618 umem_free(layout_attrs
,
619 attr
.za_num_integers
* attr
.za_integer_length
);
621 zap_cursor_fini(&zc
);
626 dump_zpldir(objset_t
*os
, uint64_t object
, void *data
, size_t size
)
629 zap_attribute_t attr
;
630 const char *typenames
[] = {
631 /* 0 */ "not specified",
633 /* 2 */ "Character Device",
634 /* 3 */ "3 (invalid)",
636 /* 5 */ "5 (invalid)",
637 /* 6 */ "Block Device",
638 /* 7 */ "7 (invalid)",
639 /* 8 */ "Regular File",
640 /* 9 */ "9 (invalid)",
641 /* 10 */ "Symbolic Link",
642 /* 11 */ "11 (invalid)",
645 /* 14 */ "Event Port",
646 /* 15 */ "15 (invalid)",
649 dump_zap_stats(os
, object
);
652 for (zap_cursor_init(&zc
, os
, object
);
653 zap_cursor_retrieve(&zc
, &attr
) == 0;
654 zap_cursor_advance(&zc
)) {
655 (void) printf("\t\t%s = %lld (type: %s)\n",
656 attr
.za_name
, ZFS_DIRENT_OBJ(attr
.za_first_integer
),
657 typenames
[ZFS_DIRENT_TYPE(attr
.za_first_integer
)]);
659 zap_cursor_fini(&zc
);
663 get_dtl_refcount(vdev_t
*vd
)
667 if (vd
->vdev_ops
->vdev_op_leaf
) {
668 space_map_t
*sm
= vd
->vdev_dtl_sm
;
671 sm
->sm_dbuf
->db_size
== sizeof (space_map_phys_t
))
676 for (unsigned c
= 0; c
< vd
->vdev_children
; c
++)
677 refcount
+= get_dtl_refcount(vd
->vdev_child
[c
]);
682 get_metaslab_refcount(vdev_t
*vd
)
686 if (vd
->vdev_top
== vd
) {
687 for (uint64_t m
= 0; m
< vd
->vdev_ms_count
; m
++) {
688 space_map_t
*sm
= vd
->vdev_ms
[m
]->ms_sm
;
691 sm
->sm_dbuf
->db_size
== sizeof (space_map_phys_t
))
695 for (unsigned c
= 0; c
< vd
->vdev_children
; c
++)
696 refcount
+= get_metaslab_refcount(vd
->vdev_child
[c
]);
702 get_obsolete_refcount(vdev_t
*vd
)
704 uint64_t obsolete_sm_object
;
707 VERIFY0(vdev_obsolete_sm_object(vd
, &obsolete_sm_object
));
708 if (vd
->vdev_top
== vd
&& obsolete_sm_object
!= 0) {
709 dmu_object_info_t doi
;
710 VERIFY0(dmu_object_info(vd
->vdev_spa
->spa_meta_objset
,
711 obsolete_sm_object
, &doi
));
712 if (doi
.doi_bonus_size
== sizeof (space_map_phys_t
)) {
716 ASSERT3P(vd
->vdev_obsolete_sm
, ==, NULL
);
717 ASSERT3U(obsolete_sm_object
, ==, 0);
719 for (unsigned c
= 0; c
< vd
->vdev_children
; c
++) {
720 refcount
+= get_obsolete_refcount(vd
->vdev_child
[c
]);
727 get_prev_obsolete_spacemap_refcount(spa_t
*spa
)
730 spa
->spa_condensing_indirect_phys
.scip_prev_obsolete_sm_object
;
732 dmu_object_info_t doi
;
733 VERIFY0(dmu_object_info(spa
->spa_meta_objset
, prev_obj
, &doi
));
734 if (doi
.doi_bonus_size
== sizeof (space_map_phys_t
)) {
742 get_checkpoint_refcount(vdev_t
*vd
)
746 if (vd
->vdev_top
== vd
&& vd
->vdev_top_zap
!= 0 &&
747 zap_contains(spa_meta_objset(vd
->vdev_spa
),
748 vd
->vdev_top_zap
, VDEV_TOP_ZAP_POOL_CHECKPOINT_SM
) == 0)
751 for (uint64_t c
= 0; c
< vd
->vdev_children
; c
++)
752 refcount
+= get_checkpoint_refcount(vd
->vdev_child
[c
]);
758 verify_spacemap_refcounts(spa_t
*spa
)
760 uint64_t expected_refcount
= 0;
761 uint64_t actual_refcount
;
763 (void) feature_get_refcount(spa
,
764 &spa_feature_table
[SPA_FEATURE_SPACEMAP_HISTOGRAM
],
766 actual_refcount
= get_dtl_refcount(spa
->spa_root_vdev
);
767 actual_refcount
+= get_metaslab_refcount(spa
->spa_root_vdev
);
768 actual_refcount
+= get_obsolete_refcount(spa
->spa_root_vdev
);
769 actual_refcount
+= get_prev_obsolete_spacemap_refcount(spa
);
770 actual_refcount
+= get_checkpoint_refcount(spa
->spa_root_vdev
);
772 if (expected_refcount
!= actual_refcount
) {
773 (void) printf("space map refcount mismatch: expected %lld != "
775 (longlong_t
)expected_refcount
,
776 (longlong_t
)actual_refcount
);
783 dump_spacemap(objset_t
*os
, space_map_t
*sm
)
785 const char *ddata
[] = { "ALLOC", "FREE", "CONDENSE", "INVALID",
786 "INVALID", "INVALID", "INVALID", "INVALID" };
791 (void) printf("space map object %llu:\n",
792 (longlong_t
)sm
->sm_phys
->smp_object
);
793 (void) printf(" smp_objsize = 0x%llx\n",
794 (longlong_t
)sm
->sm_phys
->smp_objsize
);
795 (void) printf(" smp_alloc = 0x%llx\n",
796 (longlong_t
)sm
->sm_phys
->smp_alloc
);
799 * Print out the freelist entries in both encoded and decoded form.
801 uint8_t mapshift
= sm
->sm_shift
;
804 for (uint64_t offset
= 0; offset
< space_map_length(sm
);
805 offset
+= sizeof (word
)) {
807 VERIFY0(dmu_read(os
, space_map_object(sm
), offset
,
808 sizeof (word
), &word
, DMU_READ_PREFETCH
));
810 if (sm_entry_is_debug(word
)) {
811 (void) printf("\t [%6llu] %s: txg %llu, pass %llu\n",
812 (u_longlong_t
)(offset
/ sizeof (word
)),
813 ddata
[SM_DEBUG_ACTION_DECODE(word
)],
814 (u_longlong_t
)SM_DEBUG_TXG_DECODE(word
),
815 (u_longlong_t
)SM_DEBUG_SYNCPASS_DECODE(word
));
821 uint64_t entry_off
, entry_run
, entry_vdev
= SM_NO_VDEVID
;
823 if (sm_entry_is_single_word(word
)) {
824 entry_type
= (SM_TYPE_DECODE(word
) == SM_ALLOC
) ?
826 entry_off
= (SM_OFFSET_DECODE(word
) << mapshift
) +
828 entry_run
= SM_RUN_DECODE(word
) << mapshift
;
831 /* it is a two-word entry so we read another word */
832 ASSERT(sm_entry_is_double_word(word
));
835 offset
+= sizeof (extra_word
);
836 VERIFY0(dmu_read(os
, space_map_object(sm
), offset
,
837 sizeof (extra_word
), &extra_word
,
840 ASSERT3U(offset
, <=, space_map_length(sm
));
842 entry_run
= SM2_RUN_DECODE(word
) << mapshift
;
843 entry_vdev
= SM2_VDEV_DECODE(word
);
844 entry_type
= (SM2_TYPE_DECODE(extra_word
) == SM_ALLOC
) ?
846 entry_off
= (SM2_OFFSET_DECODE(extra_word
) <<
847 mapshift
) + sm
->sm_start
;
851 (void) printf("\t [%6llu] %c range:"
852 " %010llx-%010llx size: %06llx vdev: %06llu words: %u\n",
853 (u_longlong_t
)(offset
/ sizeof (word
)),
854 entry_type
, (u_longlong_t
)entry_off
,
855 (u_longlong_t
)(entry_off
+ entry_run
),
856 (u_longlong_t
)entry_run
,
857 (u_longlong_t
)entry_vdev
, words
);
859 if (entry_type
== 'A')
864 if ((uint64_t)alloc
!= space_map_allocated(sm
)) {
865 (void) printf("space_map_object alloc (%lld) INCONSISTENT "
866 "with space map summary (%lld)\n",
867 (longlong_t
)space_map_allocated(sm
), (longlong_t
)alloc
);
872 dump_metaslab_stats(metaslab_t
*msp
)
875 range_tree_t
*rt
= msp
->ms_allocatable
;
876 avl_tree_t
*t
= &msp
->ms_allocatable_by_size
;
877 int free_pct
= range_tree_space(rt
) * 100 / msp
->ms_size
;
879 /* max sure nicenum has enough space */
880 CTASSERT(sizeof (maxbuf
) >= NN_NUMBUF_SZ
);
882 zdb_nicenum(metaslab_block_maxsize(msp
), maxbuf
, sizeof (maxbuf
));
884 (void) printf("\t %25s %10lu %7s %6s %4s %4d%%\n",
885 "segments", avl_numnodes(t
), "maxsize", maxbuf
,
886 "freepct", free_pct
);
887 (void) printf("\tIn-memory histogram:\n");
888 dump_histogram(rt
->rt_histogram
, RANGE_TREE_HISTOGRAM_SIZE
, 0);
892 dump_metaslab(metaslab_t
*msp
)
894 vdev_t
*vd
= msp
->ms_group
->mg_vd
;
895 spa_t
*spa
= vd
->vdev_spa
;
896 space_map_t
*sm
= msp
->ms_sm
;
899 zdb_nicenum(msp
->ms_size
- space_map_allocated(sm
), freebuf
,
903 "\tmetaslab %6llu offset %12llx spacemap %6llu free %5s\n",
904 (u_longlong_t
)msp
->ms_id
, (u_longlong_t
)msp
->ms_start
,
905 (u_longlong_t
)space_map_object(sm
), freebuf
);
907 if (dump_opt
['m'] > 2 && !dump_opt
['L']) {
908 mutex_enter(&msp
->ms_lock
);
909 metaslab_load_wait(msp
);
910 if (!msp
->ms_loaded
) {
911 VERIFY0(metaslab_load(msp
));
912 range_tree_stat_verify(msp
->ms_allocatable
);
914 dump_metaslab_stats(msp
);
915 metaslab_unload(msp
);
916 mutex_exit(&msp
->ms_lock
);
919 if (dump_opt
['m'] > 1 && sm
!= NULL
&&
920 spa_feature_is_active(spa
, SPA_FEATURE_SPACEMAP_HISTOGRAM
)) {
922 * The space map histogram represents free space in chunks
923 * of sm_shift (i.e. bucket 0 refers to 2^sm_shift).
925 (void) printf("\tOn-disk histogram:\t\tfragmentation %llu\n",
926 (u_longlong_t
)msp
->ms_fragmentation
);
927 dump_histogram(sm
->sm_phys
->smp_histogram
,
928 SPACE_MAP_HISTOGRAM_SIZE
, sm
->sm_shift
);
931 if (dump_opt
['d'] > 5 || dump_opt
['m'] > 3) {
932 ASSERT(msp
->ms_size
== (1ULL << vd
->vdev_ms_shift
));
934 dump_spacemap(spa
->spa_meta_objset
, msp
->ms_sm
);
939 print_vdev_metaslab_header(vdev_t
*vd
)
941 vdev_alloc_bias_t alloc_bias
= vd
->vdev_alloc_bias
;
942 const char *bias_str
;
944 bias_str
= (alloc_bias
== VDEV_BIAS_LOG
|| vd
->vdev_islog
) ?
945 VDEV_ALLOC_BIAS_LOG
:
946 (alloc_bias
== VDEV_BIAS_SPECIAL
) ? VDEV_ALLOC_BIAS_SPECIAL
:
947 (alloc_bias
== VDEV_BIAS_DEDUP
) ? VDEV_ALLOC_BIAS_DEDUP
:
948 vd
->vdev_islog
? "log" : "";
950 (void) printf("\tvdev %10llu %s\n"
951 "\t%-10s%5llu %-19s %-15s %-12s\n",
952 (u_longlong_t
)vd
->vdev_id
, bias_str
,
953 "metaslabs", (u_longlong_t
)vd
->vdev_ms_count
,
954 "offset", "spacemap", "free");
955 (void) printf("\t%15s %19s %15s %12s\n",
956 "---------------", "-------------------",
957 "---------------", "------------");
961 dump_metaslab_groups(spa_t
*spa
)
963 vdev_t
*rvd
= spa
->spa_root_vdev
;
964 metaslab_class_t
*mc
= spa_normal_class(spa
);
965 uint64_t fragmentation
;
967 metaslab_class_histogram_verify(mc
);
969 for (unsigned c
= 0; c
< rvd
->vdev_children
; c
++) {
970 vdev_t
*tvd
= rvd
->vdev_child
[c
];
971 metaslab_group_t
*mg
= tvd
->vdev_mg
;
973 if (mg
== NULL
|| mg
->mg_class
!= mc
)
976 metaslab_group_histogram_verify(mg
);
977 mg
->mg_fragmentation
= metaslab_group_fragmentation(mg
);
979 (void) printf("\tvdev %10llu\t\tmetaslabs%5llu\t\t"
981 (u_longlong_t
)tvd
->vdev_id
,
982 (u_longlong_t
)tvd
->vdev_ms_count
);
983 if (mg
->mg_fragmentation
== ZFS_FRAG_INVALID
) {
984 (void) printf("%3s\n", "-");
986 (void) printf("%3llu%%\n",
987 (u_longlong_t
)mg
->mg_fragmentation
);
989 dump_histogram(mg
->mg_histogram
, RANGE_TREE_HISTOGRAM_SIZE
, 0);
992 (void) printf("\tpool %s\tfragmentation", spa_name(spa
));
993 fragmentation
= metaslab_class_fragmentation(mc
);
994 if (fragmentation
== ZFS_FRAG_INVALID
)
995 (void) printf("\t%3s\n", "-");
997 (void) printf("\t%3llu%%\n", (u_longlong_t
)fragmentation
);
998 dump_histogram(mc
->mc_histogram
, RANGE_TREE_HISTOGRAM_SIZE
, 0);
1002 print_vdev_indirect(vdev_t
*vd
)
1004 vdev_indirect_config_t
*vic
= &vd
->vdev_indirect_config
;
1005 vdev_indirect_mapping_t
*vim
= vd
->vdev_indirect_mapping
;
1006 vdev_indirect_births_t
*vib
= vd
->vdev_indirect_births
;
1009 ASSERT3P(vib
, ==, NULL
);
1013 ASSERT3U(vdev_indirect_mapping_object(vim
), ==,
1014 vic
->vic_mapping_object
);
1015 ASSERT3U(vdev_indirect_births_object(vib
), ==,
1016 vic
->vic_births_object
);
1018 (void) printf("indirect births obj %llu:\n",
1019 (longlong_t
)vic
->vic_births_object
);
1020 (void) printf(" vib_count = %llu\n",
1021 (longlong_t
)vdev_indirect_births_count(vib
));
1022 for (uint64_t i
= 0; i
< vdev_indirect_births_count(vib
); i
++) {
1023 vdev_indirect_birth_entry_phys_t
*cur_vibe
=
1024 &vib
->vib_entries
[i
];
1025 (void) printf("\toffset %llx -> txg %llu\n",
1026 (longlong_t
)cur_vibe
->vibe_offset
,
1027 (longlong_t
)cur_vibe
->vibe_phys_birth_txg
);
1029 (void) printf("\n");
1031 (void) printf("indirect mapping obj %llu:\n",
1032 (longlong_t
)vic
->vic_mapping_object
);
1033 (void) printf(" vim_max_offset = 0x%llx\n",
1034 (longlong_t
)vdev_indirect_mapping_max_offset(vim
));
1035 (void) printf(" vim_bytes_mapped = 0x%llx\n",
1036 (longlong_t
)vdev_indirect_mapping_bytes_mapped(vim
));
1037 (void) printf(" vim_count = %llu\n",
1038 (longlong_t
)vdev_indirect_mapping_num_entries(vim
));
1040 if (dump_opt
['d'] <= 5 && dump_opt
['m'] <= 3)
1043 uint32_t *counts
= vdev_indirect_mapping_load_obsolete_counts(vim
);
1045 for (uint64_t i
= 0; i
< vdev_indirect_mapping_num_entries(vim
); i
++) {
1046 vdev_indirect_mapping_entry_phys_t
*vimep
=
1047 &vim
->vim_entries
[i
];
1048 (void) printf("\t<%llx:%llx:%llx> -> "
1049 "<%llx:%llx:%llx> (%x obsolete)\n",
1050 (longlong_t
)vd
->vdev_id
,
1051 (longlong_t
)DVA_MAPPING_GET_SRC_OFFSET(vimep
),
1052 (longlong_t
)DVA_GET_ASIZE(&vimep
->vimep_dst
),
1053 (longlong_t
)DVA_GET_VDEV(&vimep
->vimep_dst
),
1054 (longlong_t
)DVA_GET_OFFSET(&vimep
->vimep_dst
),
1055 (longlong_t
)DVA_GET_ASIZE(&vimep
->vimep_dst
),
1058 (void) printf("\n");
1060 uint64_t obsolete_sm_object
;
1061 VERIFY0(vdev_obsolete_sm_object(vd
, &obsolete_sm_object
));
1062 if (obsolete_sm_object
!= 0) {
1063 objset_t
*mos
= vd
->vdev_spa
->spa_meta_objset
;
1064 (void) printf("obsolete space map object %llu:\n",
1065 (u_longlong_t
)obsolete_sm_object
);
1066 ASSERT(vd
->vdev_obsolete_sm
!= NULL
);
1067 ASSERT3U(space_map_object(vd
->vdev_obsolete_sm
), ==,
1068 obsolete_sm_object
);
1069 dump_spacemap(mos
, vd
->vdev_obsolete_sm
);
1070 (void) printf("\n");
1075 dump_metaslabs(spa_t
*spa
)
1077 vdev_t
*vd
, *rvd
= spa
->spa_root_vdev
;
1078 uint64_t m
, c
= 0, children
= rvd
->vdev_children
;
1080 (void) printf("\nMetaslabs:\n");
1082 if (!dump_opt
['d'] && zopt_objects
> 0) {
1086 (void) fatal("bad vdev id: %llu", (u_longlong_t
)c
);
1088 if (zopt_objects
> 1) {
1089 vd
= rvd
->vdev_child
[c
];
1090 print_vdev_metaslab_header(vd
);
1092 for (m
= 1; m
< zopt_objects
; m
++) {
1093 if (zopt_object
[m
] < vd
->vdev_ms_count
)
1095 vd
->vdev_ms
[zopt_object
[m
]]);
1097 (void) fprintf(stderr
, "bad metaslab "
1099 (u_longlong_t
)zopt_object
[m
]);
1101 (void) printf("\n");
1106 for (; c
< children
; c
++) {
1107 vd
= rvd
->vdev_child
[c
];
1108 print_vdev_metaslab_header(vd
);
1110 print_vdev_indirect(vd
);
1112 for (m
= 0; m
< vd
->vdev_ms_count
; m
++)
1113 dump_metaslab(vd
->vdev_ms
[m
]);
1114 (void) printf("\n");
1119 dump_dde(const ddt_t
*ddt
, const ddt_entry_t
*dde
, uint64_t index
)
1121 const ddt_phys_t
*ddp
= dde
->dde_phys
;
1122 const ddt_key_t
*ddk
= &dde
->dde_key
;
1123 const char *types
[4] = { "ditto", "single", "double", "triple" };
1124 char blkbuf
[BP_SPRINTF_LEN
];
1128 for (p
= 0; p
< DDT_PHYS_TYPES
; p
++, ddp
++) {
1129 if (ddp
->ddp_phys_birth
== 0)
1131 ddt_bp_create(ddt
->ddt_checksum
, ddk
, ddp
, &blk
);
1132 snprintf_blkptr(blkbuf
, sizeof (blkbuf
), &blk
);
1133 (void) printf("index %llx refcnt %llu %s %s\n",
1134 (u_longlong_t
)index
, (u_longlong_t
)ddp
->ddp_refcnt
,
1140 dump_dedup_ratio(const ddt_stat_t
*dds
)
1142 double rL
, rP
, rD
, D
, dedup
, compress
, copies
;
1144 if (dds
->dds_blocks
== 0)
1147 rL
= (double)dds
->dds_ref_lsize
;
1148 rP
= (double)dds
->dds_ref_psize
;
1149 rD
= (double)dds
->dds_ref_dsize
;
1150 D
= (double)dds
->dds_dsize
;
1156 (void) printf("dedup = %.2f, compress = %.2f, copies = %.2f, "
1157 "dedup * compress / copies = %.2f\n\n",
1158 dedup
, compress
, copies
, dedup
* compress
/ copies
);
1162 dump_ddt(ddt_t
*ddt
, enum ddt_type type
, enum ddt_class
class)
1164 char name
[DDT_NAMELEN
];
1167 dmu_object_info_t doi
;
1168 uint64_t count
, dspace
, mspace
;
1171 error
= ddt_object_info(ddt
, type
, class, &doi
);
1173 if (error
== ENOENT
)
1177 error
= ddt_object_count(ddt
, type
, class, &count
);
1182 dspace
= doi
.doi_physical_blocks_512
<< 9;
1183 mspace
= doi
.doi_fill_count
* doi
.doi_data_block_size
;
1185 ddt_object_name(ddt
, type
, class, name
);
1187 (void) printf("%s: %llu entries, size %llu on disk, %llu in core\n",
1189 (u_longlong_t
)count
,
1190 (u_longlong_t
)(dspace
/ count
),
1191 (u_longlong_t
)(mspace
/ count
));
1193 if (dump_opt
['D'] < 3)
1196 zpool_dump_ddt(NULL
, &ddt
->ddt_histogram
[type
][class]);
1198 if (dump_opt
['D'] < 4)
1201 if (dump_opt
['D'] < 5 && class == DDT_CLASS_UNIQUE
)
1204 (void) printf("%s contents:\n\n", name
);
1206 while ((error
= ddt_object_walk(ddt
, type
, class, &walk
, &dde
)) == 0)
1207 dump_dde(ddt
, &dde
, walk
);
1209 ASSERT3U(error
, ==, ENOENT
);
1211 (void) printf("\n");
1215 dump_all_ddts(spa_t
*spa
)
1217 ddt_histogram_t ddh_total
;
1218 ddt_stat_t dds_total
;
1220 bzero(&ddh_total
, sizeof (ddh_total
));
1221 bzero(&dds_total
, sizeof (dds_total
));
1223 for (enum zio_checksum c
= 0; c
< ZIO_CHECKSUM_FUNCTIONS
; c
++) {
1224 ddt_t
*ddt
= spa
->spa_ddt
[c
];
1225 for (enum ddt_type type
= 0; type
< DDT_TYPES
; type
++) {
1226 for (enum ddt_class
class = 0; class < DDT_CLASSES
;
1228 dump_ddt(ddt
, type
, class);
1233 ddt_get_dedup_stats(spa
, &dds_total
);
1235 if (dds_total
.dds_blocks
== 0) {
1236 (void) printf("All DDTs are empty\n");
1240 (void) printf("\n");
1242 if (dump_opt
['D'] > 1) {
1243 (void) printf("DDT histogram (aggregated over all DDTs):\n");
1244 ddt_get_dedup_histogram(spa
, &ddh_total
);
1245 zpool_dump_ddt(&dds_total
, &ddh_total
);
1248 dump_dedup_ratio(&dds_total
);
1252 dump_dtl_seg(void *arg
, uint64_t start
, uint64_t size
)
1256 (void) printf("%s [%llu,%llu) length %llu\n",
1258 (u_longlong_t
)start
,
1259 (u_longlong_t
)(start
+ size
),
1260 (u_longlong_t
)(size
));
1264 dump_dtl(vdev_t
*vd
, int indent
)
1266 spa_t
*spa
= vd
->vdev_spa
;
1268 const char *name
[DTL_TYPES
] = { "missing", "partial", "scrub",
1272 spa_vdev_state_enter(spa
, SCL_NONE
);
1273 required
= vdev_dtl_required(vd
);
1274 (void) spa_vdev_state_exit(spa
, NULL
, 0);
1277 (void) printf("\nDirty time logs:\n\n");
1279 (void) printf("\t%*s%s [%s]\n", indent
, "",
1280 vd
->vdev_path
? vd
->vdev_path
:
1281 vd
->vdev_parent
? vd
->vdev_ops
->vdev_op_type
: spa_name(spa
),
1282 required
? "DTL-required" : "DTL-expendable");
1284 for (int t
= 0; t
< DTL_TYPES
; t
++) {
1285 range_tree_t
*rt
= vd
->vdev_dtl
[t
];
1286 if (range_tree_space(rt
) == 0)
1288 (void) snprintf(prefix
, sizeof (prefix
), "\t%*s%s",
1289 indent
+ 2, "", name
[t
]);
1290 range_tree_walk(rt
, dump_dtl_seg
, prefix
);
1291 if (dump_opt
['d'] > 5 && vd
->vdev_children
== 0)
1292 dump_spacemap(spa
->spa_meta_objset
,
1296 for (unsigned c
= 0; c
< vd
->vdev_children
; c
++)
1297 dump_dtl(vd
->vdev_child
[c
], indent
+ 4);
1301 dump_history(spa_t
*spa
)
1303 nvlist_t
**events
= NULL
;
1305 uint64_t resid
, len
, off
= 0;
1311 char internalstr
[MAXPATHLEN
];
1313 if ((buf
= malloc(SPA_OLD_MAXBLOCKSIZE
)) == NULL
) {
1314 (void) fprintf(stderr
, "%s: unable to allocate I/O buffer\n",
1320 len
= SPA_OLD_MAXBLOCKSIZE
;
1322 if ((error
= spa_history_get(spa
, &off
, &len
, buf
)) != 0) {
1323 (void) fprintf(stderr
, "Unable to read history: "
1324 "error %d\n", error
);
1329 if (zpool_history_unpack(buf
, len
, &resid
, &events
, &num
) != 0)
1335 (void) printf("\nHistory:\n");
1336 for (unsigned i
= 0; i
< num
; i
++) {
1337 uint64_t time
, txg
, ievent
;
1339 boolean_t printed
= B_FALSE
;
1341 if (nvlist_lookup_uint64(events
[i
], ZPOOL_HIST_TIME
,
1344 if (nvlist_lookup_string(events
[i
], ZPOOL_HIST_CMD
,
1346 if (nvlist_lookup_uint64(events
[i
],
1347 ZPOOL_HIST_INT_EVENT
, &ievent
) != 0)
1349 verify(nvlist_lookup_uint64(events
[i
],
1350 ZPOOL_HIST_TXG
, &txg
) == 0);
1351 verify(nvlist_lookup_string(events
[i
],
1352 ZPOOL_HIST_INT_STR
, &intstr
) == 0);
1353 if (ievent
>= ZFS_NUM_LEGACY_HISTORY_EVENTS
)
1356 (void) snprintf(internalstr
,
1357 sizeof (internalstr
),
1358 "[internal %s txg:%lld] %s",
1359 zfs_history_event_names
[ievent
],
1360 (longlong_t
)txg
, intstr
);
1364 (void) localtime_r(&tsec
, &t
);
1365 (void) strftime(tbuf
, sizeof (tbuf
), "%F.%T", &t
);
1366 (void) printf("%s %s\n", tbuf
, cmd
);
1370 if (dump_opt
['h'] > 1) {
1372 (void) printf("unrecognized record:\n");
1373 dump_nvlist(events
[i
], 2);
1381 dump_dnode(objset_t
*os
, uint64_t object
, void *data
, size_t size
)
1386 blkid2offset(const dnode_phys_t
*dnp
, const blkptr_t
*bp
,
1387 const zbookmark_phys_t
*zb
)
1390 ASSERT(zb
->zb_level
< 0);
1391 if (zb
->zb_object
== 0)
1392 return (zb
->zb_blkid
);
1393 return (zb
->zb_blkid
* BP_GET_LSIZE(bp
));
1396 ASSERT(zb
->zb_level
>= 0);
1398 return ((zb
->zb_blkid
<<
1399 (zb
->zb_level
* (dnp
->dn_indblkshift
- SPA_BLKPTRSHIFT
))) *
1400 dnp
->dn_datablkszsec
<< SPA_MINBLOCKSHIFT
);
1404 snprintf_blkptr_compact(char *blkbuf
, size_t buflen
, const blkptr_t
*bp
)
1406 const dva_t
*dva
= bp
->blk_dva
;
1407 int ndvas
= dump_opt
['d'] > 5 ? BP_GET_NDVAS(bp
) : 1;
1410 if (dump_opt
['b'] >= 6) {
1411 snprintf_blkptr(blkbuf
, buflen
, bp
);
1415 if (BP_IS_EMBEDDED(bp
)) {
1416 (void) sprintf(blkbuf
,
1417 "EMBEDDED et=%u %llxL/%llxP B=%llu",
1418 (int)BPE_GET_ETYPE(bp
),
1419 (u_longlong_t
)BPE_GET_LSIZE(bp
),
1420 (u_longlong_t
)BPE_GET_PSIZE(bp
),
1421 (u_longlong_t
)bp
->blk_birth
);
1427 for (i
= 0; i
< ndvas
; i
++)
1428 (void) snprintf(blkbuf
+ strlen(blkbuf
),
1429 buflen
- strlen(blkbuf
), "%llu:%llx:%llx ",
1430 (u_longlong_t
)DVA_GET_VDEV(&dva
[i
]),
1431 (u_longlong_t
)DVA_GET_OFFSET(&dva
[i
]),
1432 (u_longlong_t
)DVA_GET_ASIZE(&dva
[i
]));
1434 if (BP_IS_HOLE(bp
)) {
1435 (void) snprintf(blkbuf
+ strlen(blkbuf
),
1436 buflen
- strlen(blkbuf
),
1438 (u_longlong_t
)BP_GET_LSIZE(bp
),
1439 (u_longlong_t
)bp
->blk_birth
);
1441 (void) snprintf(blkbuf
+ strlen(blkbuf
),
1442 buflen
- strlen(blkbuf
),
1443 "%llxL/%llxP F=%llu B=%llu/%llu",
1444 (u_longlong_t
)BP_GET_LSIZE(bp
),
1445 (u_longlong_t
)BP_GET_PSIZE(bp
),
1446 (u_longlong_t
)BP_GET_FILL(bp
),
1447 (u_longlong_t
)bp
->blk_birth
,
1448 (u_longlong_t
)BP_PHYSICAL_BIRTH(bp
));
1453 print_indirect(blkptr_t
*bp
, const zbookmark_phys_t
*zb
,
1454 const dnode_phys_t
*dnp
)
1456 char blkbuf
[BP_SPRINTF_LEN
];
1459 if (!BP_IS_EMBEDDED(bp
)) {
1460 ASSERT3U(BP_GET_TYPE(bp
), ==, dnp
->dn_type
);
1461 ASSERT3U(BP_GET_LEVEL(bp
), ==, zb
->zb_level
);
1464 (void) printf("%16llx ", (u_longlong_t
)blkid2offset(dnp
, bp
, zb
));
1466 ASSERT(zb
->zb_level
>= 0);
1468 for (l
= dnp
->dn_nlevels
- 1; l
>= -1; l
--) {
1469 if (l
== zb
->zb_level
) {
1470 (void) printf("L%llx", (u_longlong_t
)zb
->zb_level
);
1476 snprintf_blkptr_compact(blkbuf
, sizeof (blkbuf
), bp
);
1477 (void) printf("%s\n", blkbuf
);
1481 visit_indirect(spa_t
*spa
, const dnode_phys_t
*dnp
,
1482 blkptr_t
*bp
, const zbookmark_phys_t
*zb
)
1486 if (bp
->blk_birth
== 0)
1489 print_indirect(bp
, zb
, dnp
);
1491 if (BP_GET_LEVEL(bp
) > 0 && !BP_IS_HOLE(bp
)) {
1492 arc_flags_t flags
= ARC_FLAG_WAIT
;
1495 int epb
= BP_GET_LSIZE(bp
) >> SPA_BLKPTRSHIFT
;
1499 err
= arc_read(NULL
, spa
, bp
, arc_getbuf_func
, &buf
,
1500 ZIO_PRIORITY_ASYNC_READ
, ZIO_FLAG_CANFAIL
, &flags
, zb
);
1503 ASSERT(buf
->b_data
);
1505 /* recursively visit blocks below this */
1507 for (i
= 0; i
< epb
; i
++, cbp
++) {
1508 zbookmark_phys_t czb
;
1510 SET_BOOKMARK(&czb
, zb
->zb_objset
, zb
->zb_object
,
1512 zb
->zb_blkid
* epb
+ i
);
1513 err
= visit_indirect(spa
, dnp
, cbp
, &czb
);
1516 fill
+= BP_GET_FILL(cbp
);
1519 ASSERT3U(fill
, ==, BP_GET_FILL(bp
));
1520 arc_buf_destroy(buf
, &buf
);
1528 dump_indirect(dnode_t
*dn
)
1530 dnode_phys_t
*dnp
= dn
->dn_phys
;
1532 zbookmark_phys_t czb
;
1534 (void) printf("Indirect blocks:\n");
1536 SET_BOOKMARK(&czb
, dmu_objset_id(dn
->dn_objset
),
1537 dn
->dn_object
, dnp
->dn_nlevels
- 1, 0);
1538 for (j
= 0; j
< dnp
->dn_nblkptr
; j
++) {
1540 (void) visit_indirect(dmu_objset_spa(dn
->dn_objset
), dnp
,
1541 &dnp
->dn_blkptr
[j
], &czb
);
1544 (void) printf("\n");
1549 dump_dsl_dir(objset_t
*os
, uint64_t object
, void *data
, size_t size
)
1551 dsl_dir_phys_t
*dd
= data
;
1555 /* make sure nicenum has enough space */
1556 CTASSERT(sizeof (nice
) >= NN_NUMBUF_SZ
);
1561 ASSERT3U(size
, >=, sizeof (dsl_dir_phys_t
));
1563 crtime
= dd
->dd_creation_time
;
1564 (void) printf("\t\tcreation_time = %s", ctime(&crtime
));
1565 (void) printf("\t\thead_dataset_obj = %llu\n",
1566 (u_longlong_t
)dd
->dd_head_dataset_obj
);
1567 (void) printf("\t\tparent_dir_obj = %llu\n",
1568 (u_longlong_t
)dd
->dd_parent_obj
);
1569 (void) printf("\t\torigin_obj = %llu\n",
1570 (u_longlong_t
)dd
->dd_origin_obj
);
1571 (void) printf("\t\tchild_dir_zapobj = %llu\n",
1572 (u_longlong_t
)dd
->dd_child_dir_zapobj
);
1573 zdb_nicenum(dd
->dd_used_bytes
, nice
, sizeof (nice
));
1574 (void) printf("\t\tused_bytes = %s\n", nice
);
1575 zdb_nicenum(dd
->dd_compressed_bytes
, nice
, sizeof (nice
));
1576 (void) printf("\t\tcompressed_bytes = %s\n", nice
);
1577 zdb_nicenum(dd
->dd_uncompressed_bytes
, nice
, sizeof (nice
));
1578 (void) printf("\t\tuncompressed_bytes = %s\n", nice
);
1579 zdb_nicenum(dd
->dd_quota
, nice
, sizeof (nice
));
1580 (void) printf("\t\tquota = %s\n", nice
);
1581 zdb_nicenum(dd
->dd_reserved
, nice
, sizeof (nice
));
1582 (void) printf("\t\treserved = %s\n", nice
);
1583 (void) printf("\t\tprops_zapobj = %llu\n",
1584 (u_longlong_t
)dd
->dd_props_zapobj
);
1585 (void) printf("\t\tdeleg_zapobj = %llu\n",
1586 (u_longlong_t
)dd
->dd_deleg_zapobj
);
1587 (void) printf("\t\tflags = %llx\n",
1588 (u_longlong_t
)dd
->dd_flags
);
1591 zdb_nicenum(dd->dd_used_breakdown[DD_USED_ ## which], nice, \
1593 (void) printf("\t\tused_breakdown[" #which "] = %s\n", nice)
1600 (void) printf("\t\tclones = %llu\n",
1601 (u_longlong_t
)dd
->dd_clones
);
1606 dump_dsl_dataset(objset_t
*os
, uint64_t object
, void *data
, size_t size
)
1608 dsl_dataset_phys_t
*ds
= data
;
1610 char used
[32], compressed
[32], uncompressed
[32], unique
[32];
1611 char blkbuf
[BP_SPRINTF_LEN
];
1613 /* make sure nicenum has enough space */
1614 CTASSERT(sizeof (used
) >= NN_NUMBUF_SZ
);
1615 CTASSERT(sizeof (compressed
) >= NN_NUMBUF_SZ
);
1616 CTASSERT(sizeof (uncompressed
) >= NN_NUMBUF_SZ
);
1617 CTASSERT(sizeof (unique
) >= NN_NUMBUF_SZ
);
1622 ASSERT(size
== sizeof (*ds
));
1623 crtime
= ds
->ds_creation_time
;
1624 zdb_nicenum(ds
->ds_referenced_bytes
, used
, sizeof (used
));
1625 zdb_nicenum(ds
->ds_compressed_bytes
, compressed
, sizeof (compressed
));
1626 zdb_nicenum(ds
->ds_uncompressed_bytes
, uncompressed
,
1627 sizeof (uncompressed
));
1628 zdb_nicenum(ds
->ds_unique_bytes
, unique
, sizeof (unique
));
1629 snprintf_blkptr(blkbuf
, sizeof (blkbuf
), &ds
->ds_bp
);
1631 (void) printf("\t\tdir_obj = %llu\n",
1632 (u_longlong_t
)ds
->ds_dir_obj
);
1633 (void) printf("\t\tprev_snap_obj = %llu\n",
1634 (u_longlong_t
)ds
->ds_prev_snap_obj
);
1635 (void) printf("\t\tprev_snap_txg = %llu\n",
1636 (u_longlong_t
)ds
->ds_prev_snap_txg
);
1637 (void) printf("\t\tnext_snap_obj = %llu\n",
1638 (u_longlong_t
)ds
->ds_next_snap_obj
);
1639 (void) printf("\t\tsnapnames_zapobj = %llu\n",
1640 (u_longlong_t
)ds
->ds_snapnames_zapobj
);
1641 (void) printf("\t\tnum_children = %llu\n",
1642 (u_longlong_t
)ds
->ds_num_children
);
1643 (void) printf("\t\tuserrefs_obj = %llu\n",
1644 (u_longlong_t
)ds
->ds_userrefs_obj
);
1645 (void) printf("\t\tcreation_time = %s", ctime(&crtime
));
1646 (void) printf("\t\tcreation_txg = %llu\n",
1647 (u_longlong_t
)ds
->ds_creation_txg
);
1648 (void) printf("\t\tdeadlist_obj = %llu\n",
1649 (u_longlong_t
)ds
->ds_deadlist_obj
);
1650 (void) printf("\t\tused_bytes = %s\n", used
);
1651 (void) printf("\t\tcompressed_bytes = %s\n", compressed
);
1652 (void) printf("\t\tuncompressed_bytes = %s\n", uncompressed
);
1653 (void) printf("\t\tunique = %s\n", unique
);
1654 (void) printf("\t\tfsid_guid = %llu\n",
1655 (u_longlong_t
)ds
->ds_fsid_guid
);
1656 (void) printf("\t\tguid = %llu\n",
1657 (u_longlong_t
)ds
->ds_guid
);
1658 (void) printf("\t\tflags = %llx\n",
1659 (u_longlong_t
)ds
->ds_flags
);
1660 (void) printf("\t\tnext_clones_obj = %llu\n",
1661 (u_longlong_t
)ds
->ds_next_clones_obj
);
1662 (void) printf("\t\tprops_obj = %llu\n",
1663 (u_longlong_t
)ds
->ds_props_obj
);
1664 (void) printf("\t\tbp = %s\n", blkbuf
);
1669 dump_bptree_cb(void *arg
, const blkptr_t
*bp
, dmu_tx_t
*tx
)
1671 char blkbuf
[BP_SPRINTF_LEN
];
1673 if (bp
->blk_birth
!= 0) {
1674 snprintf_blkptr(blkbuf
, sizeof (blkbuf
), bp
);
1675 (void) printf("\t%s\n", blkbuf
);
1681 dump_bptree(objset_t
*os
, uint64_t obj
, const char *name
)
1687 /* make sure nicenum has enough space */
1688 CTASSERT(sizeof (bytes
) >= NN_NUMBUF_SZ
);
1690 if (dump_opt
['d'] < 3)
1693 VERIFY3U(0, ==, dmu_bonus_hold(os
, obj
, FTAG
, &db
));
1695 zdb_nicenum(bt
->bt_bytes
, bytes
, sizeof (bytes
));
1696 (void) printf("\n %s: %llu datasets, %s\n",
1697 name
, (unsigned long long)(bt
->bt_end
- bt
->bt_begin
), bytes
);
1698 dmu_buf_rele(db
, FTAG
);
1700 if (dump_opt
['d'] < 5)
1703 (void) printf("\n");
1705 (void) bptree_iterate(os
, obj
, B_FALSE
, dump_bptree_cb
, NULL
, NULL
);
1710 dump_bpobj_cb(void *arg
, const blkptr_t
*bp
, dmu_tx_t
*tx
)
1712 char blkbuf
[BP_SPRINTF_LEN
];
1714 ASSERT(bp
->blk_birth
!= 0);
1715 snprintf_blkptr_compact(blkbuf
, sizeof (blkbuf
), bp
);
1716 (void) printf("\t%s\n", blkbuf
);
1721 dump_full_bpobj(bpobj_t
*bpo
, const char *name
, int indent
)
1728 /* make sure nicenum has enough space */
1729 CTASSERT(sizeof (bytes
) >= NN_NUMBUF_SZ
);
1730 CTASSERT(sizeof (comp
) >= NN_NUMBUF_SZ
);
1731 CTASSERT(sizeof (uncomp
) >= NN_NUMBUF_SZ
);
1733 if (dump_opt
['d'] < 3)
1736 zdb_nicenum(bpo
->bpo_phys
->bpo_bytes
, bytes
, sizeof (bytes
));
1737 if (bpo
->bpo_havesubobj
&& bpo
->bpo_phys
->bpo_subobjs
!= 0) {
1738 zdb_nicenum(bpo
->bpo_phys
->bpo_comp
, comp
, sizeof (comp
));
1739 zdb_nicenum(bpo
->bpo_phys
->bpo_uncomp
, uncomp
, sizeof (uncomp
));
1740 (void) printf(" %*s: object %llu, %llu local blkptrs, "
1741 "%llu subobjs in object, %llu, %s (%s/%s comp)\n",
1743 (u_longlong_t
)bpo
->bpo_object
,
1744 (u_longlong_t
)bpo
->bpo_phys
->bpo_num_blkptrs
,
1745 (u_longlong_t
)bpo
->bpo_phys
->bpo_num_subobjs
,
1746 (u_longlong_t
)bpo
->bpo_phys
->bpo_subobjs
,
1747 bytes
, comp
, uncomp
);
1749 for (i
= 0; i
< bpo
->bpo_phys
->bpo_num_subobjs
; i
++) {
1753 VERIFY0(dmu_read(bpo
->bpo_os
,
1754 bpo
->bpo_phys
->bpo_subobjs
,
1755 i
* sizeof (subobj
), sizeof (subobj
), &subobj
, 0));
1756 error
= bpobj_open(&subbpo
, bpo
->bpo_os
, subobj
);
1758 (void) printf("ERROR %u while trying to open "
1760 error
, (u_longlong_t
)subobj
);
1763 dump_full_bpobj(&subbpo
, "subobj", indent
+ 1);
1764 bpobj_close(&subbpo
);
1767 (void) printf(" %*s: object %llu, %llu blkptrs, %s\n",
1769 (u_longlong_t
)bpo
->bpo_object
,
1770 (u_longlong_t
)bpo
->bpo_phys
->bpo_num_blkptrs
,
1774 if (dump_opt
['d'] < 5)
1779 (void) bpobj_iterate_nofree(bpo
, dump_bpobj_cb
, NULL
, NULL
);
1780 (void) printf("\n");
1785 bpobj_count_refd(bpobj_t
*bpo
)
1787 mos_obj_refd(bpo
->bpo_object
);
1789 if (bpo
->bpo_havesubobj
&& bpo
->bpo_phys
->bpo_subobjs
!= 0) {
1790 mos_obj_refd(bpo
->bpo_phys
->bpo_subobjs
);
1791 for (uint64_t i
= 0; i
< bpo
->bpo_phys
->bpo_num_subobjs
; i
++) {
1795 VERIFY0(dmu_read(bpo
->bpo_os
,
1796 bpo
->bpo_phys
->bpo_subobjs
,
1797 i
* sizeof (subobj
), sizeof (subobj
), &subobj
, 0));
1798 error
= bpobj_open(&subbpo
, bpo
->bpo_os
, subobj
);
1800 (void) printf("ERROR %u while trying to open "
1802 error
, (u_longlong_t
)subobj
);
1805 bpobj_count_refd(&subbpo
);
1806 bpobj_close(&subbpo
);
1812 dump_deadlist(dsl_deadlist_t
*dl
)
1814 dsl_deadlist_entry_t
*dle
;
1819 uint64_t empty_bpobj
=
1820 dmu_objset_spa(dl
->dl_os
)->spa_dsl_pool
->dp_empty_bpobj
;
1822 /* force the tree to be loaded */
1823 dsl_deadlist_space_range(dl
, 0, UINT64_MAX
, &unused
, &unused
, &unused
);
1825 if (dl
->dl_oldfmt
) {
1826 if (dl
->dl_bpobj
.bpo_object
!= empty_bpobj
)
1827 bpobj_count_refd(&dl
->dl_bpobj
);
1829 mos_obj_refd(dl
->dl_object
);
1830 for (dle
= avl_first(&dl
->dl_tree
); dle
;
1831 dle
= AVL_NEXT(&dl
->dl_tree
, dle
)) {
1832 if (dle
->dle_bpobj
.bpo_object
!= empty_bpobj
)
1833 bpobj_count_refd(&dle
->dle_bpobj
);
1837 /* make sure nicenum has enough space */
1838 CTASSERT(sizeof (bytes
) >= NN_NUMBUF_SZ
);
1839 CTASSERT(sizeof (comp
) >= NN_NUMBUF_SZ
);
1840 CTASSERT(sizeof (uncomp
) >= NN_NUMBUF_SZ
);
1842 if (dump_opt
['d'] < 3)
1845 if (dl
->dl_oldfmt
) {
1846 dump_full_bpobj(&dl
->dl_bpobj
, "old-format deadlist", 0);
1850 zdb_nicenum(dl
->dl_phys
->dl_used
, bytes
, sizeof (bytes
));
1851 zdb_nicenum(dl
->dl_phys
->dl_comp
, comp
, sizeof (comp
));
1852 zdb_nicenum(dl
->dl_phys
->dl_uncomp
, uncomp
, sizeof (uncomp
));
1853 (void) printf("\n Deadlist: %s (%s/%s comp)\n",
1854 bytes
, comp
, uncomp
);
1856 if (dump_opt
['d'] < 4)
1859 (void) printf("\n");
1861 for (dle
= avl_first(&dl
->dl_tree
); dle
;
1862 dle
= AVL_NEXT(&dl
->dl_tree
, dle
)) {
1863 if (dump_opt
['d'] >= 5) {
1865 (void) snprintf(buf
, sizeof (buf
),
1866 "mintxg %llu -> obj %llu",
1867 (longlong_t
)dle
->dle_mintxg
,
1868 (longlong_t
)dle
->dle_bpobj
.bpo_object
);
1870 dump_full_bpobj(&dle
->dle_bpobj
, buf
, 0);
1872 (void) printf("mintxg %llu -> obj %llu\n",
1873 (longlong_t
)dle
->dle_mintxg
,
1874 (longlong_t
)dle
->dle_bpobj
.bpo_object
);
1879 static avl_tree_t idx_tree
;
1880 static avl_tree_t domain_tree
;
1881 static boolean_t fuid_table_loaded
;
1882 static objset_t
*sa_os
= NULL
;
1883 static sa_attr_type_t
*sa_attr_table
= NULL
;
1886 open_objset(const char *path
, dmu_objset_type_t type
, void *tag
, objset_t
**osp
)
1889 uint64_t sa_attrs
= 0;
1890 uint64_t version
= 0;
1892 VERIFY3P(sa_os
, ==, NULL
);
1893 err
= dmu_objset_own(path
, type
, B_TRUE
, B_FALSE
, tag
, osp
);
1895 (void) fprintf(stderr
, "failed to own dataset '%s': %s\n", path
,
1900 if (dmu_objset_type(*osp
) == DMU_OST_ZFS
&& !(*osp
)->os_encrypted
) {
1901 (void) zap_lookup(*osp
, MASTER_NODE_OBJ
, ZPL_VERSION_STR
,
1903 if (version
>= ZPL_VERSION_SA
) {
1904 (void) zap_lookup(*osp
, MASTER_NODE_OBJ
, ZFS_SA_ATTRS
,
1907 err
= sa_setup(*osp
, sa_attrs
, zfs_attr_table
, ZPL_END
,
1910 (void) fprintf(stderr
, "sa_setup failed: %s\n",
1912 dmu_objset_disown(*osp
, B_FALSE
, tag
);
1922 close_objset(objset_t
*os
, void *tag
)
1924 VERIFY3P(os
, ==, sa_os
);
1925 if (os
->os_sa
!= NULL
)
1927 dmu_objset_disown(os
, B_FALSE
, tag
);
1928 sa_attr_table
= NULL
;
1933 fuid_table_destroy(void)
1935 if (fuid_table_loaded
) {
1936 zfs_fuid_table_destroy(&idx_tree
, &domain_tree
);
1937 fuid_table_loaded
= B_FALSE
;
1942 * print uid or gid information.
1943 * For normal POSIX id just the id is printed in decimal format.
1944 * For CIFS files with FUID the fuid is printed in hex followed by
1945 * the domain-rid string.
1948 print_idstr(uint64_t id
, const char *id_type
)
1950 if (FUID_INDEX(id
)) {
1953 domain
= zfs_fuid_idx_domain(&idx_tree
, FUID_INDEX(id
));
1954 (void) printf("\t%s %llx [%s-%d]\n", id_type
,
1955 (u_longlong_t
)id
, domain
, (int)FUID_RID(id
));
1957 (void) printf("\t%s %llu\n", id_type
, (u_longlong_t
)id
);
1963 dump_uidgid(objset_t
*os
, uint64_t uid
, uint64_t gid
)
1965 uint32_t uid_idx
, gid_idx
;
1967 uid_idx
= FUID_INDEX(uid
);
1968 gid_idx
= FUID_INDEX(gid
);
1970 /* Load domain table, if not already loaded */
1971 if (!fuid_table_loaded
&& (uid_idx
|| gid_idx
)) {
1974 /* first find the fuid object. It lives in the master node */
1975 VERIFY(zap_lookup(os
, MASTER_NODE_OBJ
, ZFS_FUID_TABLES
,
1976 8, 1, &fuid_obj
) == 0);
1977 zfs_fuid_avl_tree_create(&idx_tree
, &domain_tree
);
1978 (void) zfs_fuid_table_load(os
, fuid_obj
,
1979 &idx_tree
, &domain_tree
);
1980 fuid_table_loaded
= B_TRUE
;
1983 print_idstr(uid
, "uid");
1984 print_idstr(gid
, "gid");
1988 dump_znode_sa_xattr(sa_handle_t
*hdl
)
1991 nvpair_t
*elem
= NULL
;
1992 int sa_xattr_size
= 0;
1993 int sa_xattr_entries
= 0;
1995 char *sa_xattr_packed
;
1997 error
= sa_size(hdl
, sa_attr_table
[ZPL_DXATTR
], &sa_xattr_size
);
1998 if (error
|| sa_xattr_size
== 0)
2001 sa_xattr_packed
= malloc(sa_xattr_size
);
2002 if (sa_xattr_packed
== NULL
)
2005 error
= sa_lookup(hdl
, sa_attr_table
[ZPL_DXATTR
],
2006 sa_xattr_packed
, sa_xattr_size
);
2008 free(sa_xattr_packed
);
2012 error
= nvlist_unpack(sa_xattr_packed
, sa_xattr_size
, &sa_xattr
, 0);
2014 free(sa_xattr_packed
);
2018 while ((elem
= nvlist_next_nvpair(sa_xattr
, elem
)) != NULL
)
2021 (void) printf("\tSA xattrs: %d bytes, %d entries\n\n",
2022 sa_xattr_size
, sa_xattr_entries
);
2023 while ((elem
= nvlist_next_nvpair(sa_xattr
, elem
)) != NULL
) {
2027 (void) printf("\t\t%s = ", nvpair_name(elem
));
2028 nvpair_value_byte_array(elem
, &value
, &cnt
);
2029 for (idx
= 0; idx
< cnt
; ++idx
) {
2030 if (isprint(value
[idx
]))
2031 (void) putchar(value
[idx
]);
2033 (void) printf("\\%3.3o", value
[idx
]);
2035 (void) putchar('\n');
2038 nvlist_free(sa_xattr
);
2039 free(sa_xattr_packed
);
2044 dump_znode(objset_t
*os
, uint64_t object
, void *data
, size_t size
)
2046 char path
[MAXPATHLEN
* 2]; /* allow for xattr and failure prefix */
2048 uint64_t xattr
, rdev
, gen
;
2049 uint64_t uid
, gid
, mode
, fsize
, parent
, links
;
2051 uint64_t acctm
[2], modtm
[2], chgtm
[2], crtm
[2];
2052 time_t z_crtime
, z_atime
, z_mtime
, z_ctime
;
2053 sa_bulk_attr_t bulk
[12];
2057 VERIFY3P(os
, ==, sa_os
);
2058 if (sa_handle_get(os
, object
, NULL
, SA_HDL_PRIVATE
, &hdl
)) {
2059 (void) printf("Failed to get handle for SA znode\n");
2063 SA_ADD_BULK_ATTR(bulk
, idx
, sa_attr_table
[ZPL_UID
], NULL
, &uid
, 8);
2064 SA_ADD_BULK_ATTR(bulk
, idx
, sa_attr_table
[ZPL_GID
], NULL
, &gid
, 8);
2065 SA_ADD_BULK_ATTR(bulk
, idx
, sa_attr_table
[ZPL_LINKS
], NULL
,
2067 SA_ADD_BULK_ATTR(bulk
, idx
, sa_attr_table
[ZPL_GEN
], NULL
, &gen
, 8);
2068 SA_ADD_BULK_ATTR(bulk
, idx
, sa_attr_table
[ZPL_MODE
], NULL
,
2070 SA_ADD_BULK_ATTR(bulk
, idx
, sa_attr_table
[ZPL_PARENT
],
2072 SA_ADD_BULK_ATTR(bulk
, idx
, sa_attr_table
[ZPL_SIZE
], NULL
,
2074 SA_ADD_BULK_ATTR(bulk
, idx
, sa_attr_table
[ZPL_ATIME
], NULL
,
2076 SA_ADD_BULK_ATTR(bulk
, idx
, sa_attr_table
[ZPL_MTIME
], NULL
,
2078 SA_ADD_BULK_ATTR(bulk
, idx
, sa_attr_table
[ZPL_CRTIME
], NULL
,
2080 SA_ADD_BULK_ATTR(bulk
, idx
, sa_attr_table
[ZPL_CTIME
], NULL
,
2082 SA_ADD_BULK_ATTR(bulk
, idx
, sa_attr_table
[ZPL_FLAGS
], NULL
,
2085 if (sa_bulk_lookup(hdl
, bulk
, idx
)) {
2086 (void) sa_handle_destroy(hdl
);
2090 z_crtime
= (time_t)crtm
[0];
2091 z_atime
= (time_t)acctm
[0];
2092 z_mtime
= (time_t)modtm
[0];
2093 z_ctime
= (time_t)chgtm
[0];
2095 if (dump_opt
['d'] > 4) {
2096 error
= zfs_obj_to_path(os
, object
, path
, sizeof (path
));
2097 if (error
== ESTALE
) {
2098 (void) snprintf(path
, sizeof (path
), "on delete queue");
2099 } else if (error
!= 0) {
2101 (void) snprintf(path
, sizeof (path
),
2102 "path not found, possibly leaked");
2104 (void) printf("\tpath %s\n", path
);
2106 dump_uidgid(os
, uid
, gid
);
2107 (void) printf("\tatime %s", ctime(&z_atime
));
2108 (void) printf("\tmtime %s", ctime(&z_mtime
));
2109 (void) printf("\tctime %s", ctime(&z_ctime
));
2110 (void) printf("\tcrtime %s", ctime(&z_crtime
));
2111 (void) printf("\tgen %llu\n", (u_longlong_t
)gen
);
2112 (void) printf("\tmode %llo\n", (u_longlong_t
)mode
);
2113 (void) printf("\tsize %llu\n", (u_longlong_t
)fsize
);
2114 (void) printf("\tparent %llu\n", (u_longlong_t
)parent
);
2115 (void) printf("\tlinks %llu\n", (u_longlong_t
)links
);
2116 (void) printf("\tpflags %llx\n", (u_longlong_t
)pflags
);
2117 if (dmu_objset_projectquota_enabled(os
) && (pflags
& ZFS_PROJID
)) {
2120 if (sa_lookup(hdl
, sa_attr_table
[ZPL_PROJID
], &projid
,
2121 sizeof (uint64_t)) == 0)
2122 (void) printf("\tprojid %llu\n", (u_longlong_t
)projid
);
2124 if (sa_lookup(hdl
, sa_attr_table
[ZPL_XATTR
], &xattr
,
2125 sizeof (uint64_t)) == 0)
2126 (void) printf("\txattr %llu\n", (u_longlong_t
)xattr
);
2127 if (sa_lookup(hdl
, sa_attr_table
[ZPL_RDEV
], &rdev
,
2128 sizeof (uint64_t)) == 0)
2129 (void) printf("\trdev 0x%016llx\n", (u_longlong_t
)rdev
);
2130 dump_znode_sa_xattr(hdl
);
2131 sa_handle_destroy(hdl
);
2136 dump_acl(objset_t
*os
, uint64_t object
, void *data
, size_t size
)
2142 dump_dmu_objset(objset_t
*os
, uint64_t object
, void *data
, size_t size
)
2146 static object_viewer_t
*object_viewer
[DMU_OT_NUMTYPES
+ 1] = {
2147 dump_none
, /* unallocated */
2148 dump_zap
, /* object directory */
2149 dump_uint64
, /* object array */
2150 dump_none
, /* packed nvlist */
2151 dump_packed_nvlist
, /* packed nvlist size */
2152 dump_none
, /* bpobj */
2153 dump_bpobj
, /* bpobj header */
2154 dump_none
, /* SPA space map header */
2155 dump_none
, /* SPA space map */
2156 dump_none
, /* ZIL intent log */
2157 dump_dnode
, /* DMU dnode */
2158 dump_dmu_objset
, /* DMU objset */
2159 dump_dsl_dir
, /* DSL directory */
2160 dump_zap
, /* DSL directory child map */
2161 dump_zap
, /* DSL dataset snap map */
2162 dump_zap
, /* DSL props */
2163 dump_dsl_dataset
, /* DSL dataset */
2164 dump_znode
, /* ZFS znode */
2165 dump_acl
, /* ZFS V0 ACL */
2166 dump_uint8
, /* ZFS plain file */
2167 dump_zpldir
, /* ZFS directory */
2168 dump_zap
, /* ZFS master node */
2169 dump_zap
, /* ZFS delete queue */
2170 dump_uint8
, /* zvol object */
2171 dump_zap
, /* zvol prop */
2172 dump_uint8
, /* other uint8[] */
2173 dump_uint64
, /* other uint64[] */
2174 dump_zap
, /* other ZAP */
2175 dump_zap
, /* persistent error log */
2176 dump_uint8
, /* SPA history */
2177 dump_history_offsets
, /* SPA history offsets */
2178 dump_zap
, /* Pool properties */
2179 dump_zap
, /* DSL permissions */
2180 dump_acl
, /* ZFS ACL */
2181 dump_uint8
, /* ZFS SYSACL */
2182 dump_none
, /* FUID nvlist */
2183 dump_packed_nvlist
, /* FUID nvlist size */
2184 dump_zap
, /* DSL dataset next clones */
2185 dump_zap
, /* DSL scrub queue */
2186 dump_zap
, /* ZFS user/group/project used */
2187 dump_zap
, /* ZFS user/group/project quota */
2188 dump_zap
, /* snapshot refcount tags */
2189 dump_ddt_zap
, /* DDT ZAP object */
2190 dump_zap
, /* DDT statistics */
2191 dump_znode
, /* SA object */
2192 dump_zap
, /* SA Master Node */
2193 dump_sa_attrs
, /* SA attribute registration */
2194 dump_sa_layouts
, /* SA attribute layouts */
2195 dump_zap
, /* DSL scrub translations */
2196 dump_none
, /* fake dedup BP */
2197 dump_zap
, /* deadlist */
2198 dump_none
, /* deadlist hdr */
2199 dump_zap
, /* dsl clones */
2200 dump_bpobj_subobjs
, /* bpobj subobjs */
2201 dump_unknown
, /* Unknown type, must be last */
2205 dump_object(objset_t
*os
, uint64_t object
, int verbosity
, int *print_header
,
2206 uint64_t *dnode_slots_used
)
2208 dmu_buf_t
*db
= NULL
;
2209 dmu_object_info_t doi
;
2211 boolean_t dnode_held
= B_FALSE
;
2214 char iblk
[32], dblk
[32], lsize
[32], asize
[32], fill
[32], dnsize
[32];
2215 char bonus_size
[32];
2219 /* make sure nicenum has enough space */
2220 CTASSERT(sizeof (iblk
) >= NN_NUMBUF_SZ
);
2221 CTASSERT(sizeof (dblk
) >= NN_NUMBUF_SZ
);
2222 CTASSERT(sizeof (lsize
) >= NN_NUMBUF_SZ
);
2223 CTASSERT(sizeof (asize
) >= NN_NUMBUF_SZ
);
2224 CTASSERT(sizeof (bonus_size
) >= NN_NUMBUF_SZ
);
2226 if (*print_header
) {
2227 (void) printf("\n%10s %3s %5s %5s %5s %6s %5s %6s %s\n",
2228 "Object", "lvl", "iblk", "dblk", "dsize", "dnsize",
2229 "lsize", "%full", "type");
2234 dn
= DMU_META_DNODE(os
);
2235 dmu_object_info_from_dnode(dn
, &doi
);
2238 * Encrypted datasets will have sensitive bonus buffers
2239 * encrypted. Therefore we cannot hold the bonus buffer and
2240 * must hold the dnode itself instead.
2242 error
= dmu_object_info(os
, object
, &doi
);
2244 fatal("dmu_object_info() failed, errno %u", error
);
2246 if (os
->os_encrypted
&&
2247 DMU_OT_IS_ENCRYPTED(doi
.doi_bonus_type
)) {
2248 error
= dnode_hold(os
, object
, FTAG
, &dn
);
2250 fatal("dnode_hold() failed, errno %u", error
);
2251 dnode_held
= B_TRUE
;
2253 error
= dmu_bonus_hold(os
, object
, FTAG
, &db
);
2255 fatal("dmu_bonus_hold(%llu) failed, errno %u",
2257 bonus
= db
->db_data
;
2258 bsize
= db
->db_size
;
2259 dn
= DB_DNODE((dmu_buf_impl_t
*)db
);
2263 if (dnode_slots_used
)
2264 *dnode_slots_used
= doi
.doi_dnodesize
/ DNODE_MIN_SIZE
;
2266 zdb_nicenum(doi
.doi_metadata_block_size
, iblk
, sizeof (iblk
));
2267 zdb_nicenum(doi
.doi_data_block_size
, dblk
, sizeof (dblk
));
2268 zdb_nicenum(doi
.doi_max_offset
, lsize
, sizeof (lsize
));
2269 zdb_nicenum(doi
.doi_physical_blocks_512
<< 9, asize
, sizeof (asize
));
2270 zdb_nicenum(doi
.doi_bonus_size
, bonus_size
, sizeof (bonus_size
));
2271 zdb_nicenum(doi
.doi_dnodesize
, dnsize
, sizeof (dnsize
));
2272 (void) sprintf(fill
, "%6.2f", 100.0 * doi
.doi_fill_count
*
2273 doi
.doi_data_block_size
/ (object
== 0 ? DNODES_PER_BLOCK
: 1) /
2274 doi
.doi_max_offset
);
2278 if (doi
.doi_checksum
!= ZIO_CHECKSUM_INHERIT
|| verbosity
>= 6) {
2279 (void) snprintf(aux
+ strlen(aux
), sizeof (aux
) - strlen(aux
),
2280 " (K=%s)", ZDB_CHECKSUM_NAME(doi
.doi_checksum
));
2283 if (doi
.doi_compress
!= ZIO_COMPRESS_INHERIT
|| verbosity
>= 6) {
2284 (void) snprintf(aux
+ strlen(aux
), sizeof (aux
) - strlen(aux
),
2285 " (Z=%s)", ZDB_COMPRESS_NAME(doi
.doi_compress
));
2288 (void) printf("%10lld %3u %5s %5s %5s %6s %5s %6s %s%s\n",
2289 (u_longlong_t
)object
, doi
.doi_indirection
, iblk
, dblk
,
2290 asize
, dnsize
, lsize
, fill
, zdb_ot_name(doi
.doi_type
), aux
);
2292 if (doi
.doi_bonus_type
!= DMU_OT_NONE
&& verbosity
> 3) {
2293 (void) printf("%10s %3s %5s %5s %5s %5s %5s %6s %s\n",
2294 "", "", "", "", "", "", bonus_size
, "bonus",
2295 zdb_ot_name(doi
.doi_bonus_type
));
2298 if (verbosity
>= 4) {
2299 (void) printf("\tdnode flags: %s%s%s%s\n",
2300 (dn
->dn_phys
->dn_flags
& DNODE_FLAG_USED_BYTES
) ?
2302 (dn
->dn_phys
->dn_flags
& DNODE_FLAG_USERUSED_ACCOUNTED
) ?
2303 "USERUSED_ACCOUNTED " : "",
2304 (dn
->dn_phys
->dn_flags
& DNODE_FLAG_USEROBJUSED_ACCOUNTED
) ?
2305 "USEROBJUSED_ACCOUNTED " : "",
2306 (dn
->dn_phys
->dn_flags
& DNODE_FLAG_SPILL_BLKPTR
) ?
2307 "SPILL_BLKPTR" : "");
2308 (void) printf("\tdnode maxblkid: %llu\n",
2309 (longlong_t
)dn
->dn_phys
->dn_maxblkid
);
2312 object_viewer
[ZDB_OT_TYPE(doi
.doi_bonus_type
)](os
,
2313 object
, bonus
, bsize
);
2315 (void) printf("\t\t(bonus encrypted)\n");
2318 if (!os
->os_encrypted
|| !DMU_OT_IS_ENCRYPTED(doi
.doi_type
)) {
2319 object_viewer
[ZDB_OT_TYPE(doi
.doi_type
)](os
, object
,
2322 (void) printf("\t\t(object encrypted)\n");
2331 if (verbosity
>= 5) {
2333 * Report the list of segments that comprise the object.
2337 uint64_t blkfill
= 1;
2340 if (dn
->dn_type
== DMU_OT_DNODE
) {
2342 blkfill
= DNODES_PER_BLOCK
;
2347 /* make sure nicenum has enough space */
2348 CTASSERT(sizeof (segsize
) >= NN_NUMBUF_SZ
);
2349 error
= dnode_next_offset(dn
,
2350 0, &start
, minlvl
, blkfill
, 0);
2354 error
= dnode_next_offset(dn
,
2355 DNODE_FIND_HOLE
, &end
, minlvl
, blkfill
, 0);
2356 zdb_nicenum(end
- start
, segsize
, sizeof (segsize
));
2357 (void) printf("\t\tsegment [%016llx, %016llx)"
2358 " size %5s\n", (u_longlong_t
)start
,
2359 (u_longlong_t
)end
, segsize
);
2367 dmu_buf_rele(db
, FTAG
);
2369 dnode_rele(dn
, FTAG
);
2373 count_dir_mos_objects(dsl_dir_t
*dd
)
2375 mos_obj_refd(dd
->dd_object
);
2376 mos_obj_refd(dsl_dir_phys(dd
)->dd_child_dir_zapobj
);
2377 mos_obj_refd(dsl_dir_phys(dd
)->dd_deleg_zapobj
);
2378 mos_obj_refd(dsl_dir_phys(dd
)->dd_props_zapobj
);
2379 mos_obj_refd(dsl_dir_phys(dd
)->dd_clones
);
2382 * The dd_crypto_obj can be referenced by multiple dsl_dir's.
2383 * Ignore the references after the first one.
2385 mos_obj_refd_multiple(dd
->dd_crypto_obj
);
2389 count_ds_mos_objects(dsl_dataset_t
*ds
)
2391 mos_obj_refd(ds
->ds_object
);
2392 mos_obj_refd(dsl_dataset_phys(ds
)->ds_next_clones_obj
);
2393 mos_obj_refd(dsl_dataset_phys(ds
)->ds_props_obj
);
2394 mos_obj_refd(dsl_dataset_phys(ds
)->ds_userrefs_obj
);
2395 mos_obj_refd(dsl_dataset_phys(ds
)->ds_snapnames_zapobj
);
2397 if (!dsl_dataset_is_snapshot(ds
)) {
2398 count_dir_mos_objects(ds
->ds_dir
);
2402 static const char *objset_types
[DMU_OST_NUMTYPES
] = {
2403 "NONE", "META", "ZPL", "ZVOL", "OTHER", "ANY" };
2406 dump_dir(objset_t
*os
)
2408 dmu_objset_stats_t dds
;
2409 uint64_t object
, object_count
;
2410 uint64_t refdbytes
, usedobjs
, scratch
;
2412 char blkbuf
[BP_SPRINTF_LEN
+ 20];
2413 char osname
[ZFS_MAX_DATASET_NAME_LEN
];
2414 const char *type
= "UNKNOWN";
2415 int verbosity
= dump_opt
['d'];
2416 int print_header
= 1;
2419 uint64_t total_slots_used
= 0;
2420 uint64_t max_slot_used
= 0;
2421 uint64_t dnode_slots
;
2423 /* make sure nicenum has enough space */
2424 CTASSERT(sizeof (numbuf
) >= NN_NUMBUF_SZ
);
2426 dsl_pool_config_enter(dmu_objset_pool(os
), FTAG
);
2427 dmu_objset_fast_stat(os
, &dds
);
2428 dsl_pool_config_exit(dmu_objset_pool(os
), FTAG
);
2430 if (dds
.dds_type
< DMU_OST_NUMTYPES
)
2431 type
= objset_types
[dds
.dds_type
];
2433 if (dds
.dds_type
== DMU_OST_META
) {
2434 dds
.dds_creation_txg
= TXG_INITIAL
;
2435 usedobjs
= BP_GET_FILL(os
->os_rootbp
);
2436 refdbytes
= dsl_dir_phys(os
->os_spa
->spa_dsl_pool
->dp_mos_dir
)->
2439 dmu_objset_space(os
, &refdbytes
, &scratch
, &usedobjs
, &scratch
);
2442 ASSERT3U(usedobjs
, ==, BP_GET_FILL(os
->os_rootbp
));
2444 zdb_nicenum(refdbytes
, numbuf
, sizeof (numbuf
));
2446 if (verbosity
>= 4) {
2447 (void) snprintf(blkbuf
, sizeof (blkbuf
), ", rootbp ");
2448 (void) snprintf_blkptr(blkbuf
+ strlen(blkbuf
),
2449 sizeof (blkbuf
) - strlen(blkbuf
), os
->os_rootbp
);
2454 dmu_objset_name(os
, osname
);
2456 (void) printf("Dataset %s [%s], ID %llu, cr_txg %llu, "
2457 "%s, %llu objects%s%s\n",
2458 osname
, type
, (u_longlong_t
)dmu_objset_id(os
),
2459 (u_longlong_t
)dds
.dds_creation_txg
,
2460 numbuf
, (u_longlong_t
)usedobjs
, blkbuf
,
2461 (dds
.dds_inconsistent
) ? " (inconsistent)" : "");
2463 if (zopt_objects
!= 0) {
2464 for (i
= 0; i
< zopt_objects
; i
++)
2465 dump_object(os
, zopt_object
[i
], verbosity
,
2466 &print_header
, NULL
);
2467 (void) printf("\n");
2471 if (dump_opt
['i'] != 0 || verbosity
>= 2)
2472 dump_intent_log(dmu_objset_zil(os
));
2474 if (dmu_objset_ds(os
) != NULL
) {
2475 dsl_dataset_t
*ds
= dmu_objset_ds(os
);
2476 dump_deadlist(&ds
->ds_deadlist
);
2478 if (dsl_dataset_remap_deadlist_exists(ds
)) {
2479 (void) printf("ds_remap_deadlist:\n");
2480 dump_deadlist(&ds
->ds_remap_deadlist
);
2482 count_ds_mos_objects(ds
);
2488 if (BP_IS_HOLE(os
->os_rootbp
))
2491 dump_object(os
, 0, verbosity
, &print_header
, NULL
);
2493 if (DMU_USERUSED_DNODE(os
) != NULL
&&
2494 DMU_USERUSED_DNODE(os
)->dn_type
!= 0) {
2495 dump_object(os
, DMU_USERUSED_OBJECT
, verbosity
, &print_header
,
2497 dump_object(os
, DMU_GROUPUSED_OBJECT
, verbosity
, &print_header
,
2501 if (DMU_PROJECTUSED_DNODE(os
) != NULL
&&
2502 DMU_PROJECTUSED_DNODE(os
)->dn_type
!= 0)
2503 dump_object(os
, DMU_PROJECTUSED_OBJECT
, verbosity
,
2504 &print_header
, NULL
);
2507 while ((error
= dmu_object_next(os
, &object
, B_FALSE
, 0)) == 0) {
2508 dump_object(os
, object
, verbosity
, &print_header
, &dnode_slots
);
2510 total_slots_used
+= dnode_slots
;
2511 max_slot_used
= object
+ dnode_slots
- 1;
2514 (void) printf("\n");
2516 (void) printf(" Dnode slots:\n");
2517 (void) printf("\tTotal used: %10llu\n",
2518 (u_longlong_t
)total_slots_used
);
2519 (void) printf("\tMax used: %10llu\n",
2520 (u_longlong_t
)max_slot_used
);
2521 (void) printf("\tPercent empty: %10lf\n",
2522 (double)(max_slot_used
- total_slots_used
)*100 /
2523 (double)max_slot_used
);
2525 ASSERT3U(object_count
, ==, usedobjs
);
2527 (void) printf("\n");
2529 if (error
!= ESRCH
) {
2530 (void) fprintf(stderr
, "dmu_object_next() = %d\n", error
);
2533 if (leaked_objects
!= 0) {
2534 (void) printf("%d potentially leaked objects detected\n",
2541 dump_uberblock(uberblock_t
*ub
, const char *header
, const char *footer
)
2543 time_t timestamp
= ub
->ub_timestamp
;
2545 (void) printf("%s", header
? header
: "");
2546 (void) printf("\tmagic = %016llx\n", (u_longlong_t
)ub
->ub_magic
);
2547 (void) printf("\tversion = %llu\n", (u_longlong_t
)ub
->ub_version
);
2548 (void) printf("\ttxg = %llu\n", (u_longlong_t
)ub
->ub_txg
);
2549 (void) printf("\tguid_sum = %llu\n", (u_longlong_t
)ub
->ub_guid_sum
);
2550 (void) printf("\ttimestamp = %llu UTC = %s",
2551 (u_longlong_t
)ub
->ub_timestamp
, asctime(localtime(×tamp
)));
2553 (void) printf("\tmmp_magic = %016llx\n",
2554 (u_longlong_t
)ub
->ub_mmp_magic
);
2555 if (ub
->ub_mmp_magic
== MMP_MAGIC
)
2556 (void) printf("\tmmp_delay = %0llu\n",
2557 (u_longlong_t
)ub
->ub_mmp_delay
);
2559 if (dump_opt
['u'] >= 4) {
2560 char blkbuf
[BP_SPRINTF_LEN
];
2561 snprintf_blkptr(blkbuf
, sizeof (blkbuf
), &ub
->ub_rootbp
);
2562 (void) printf("\trootbp = %s\n", blkbuf
);
2564 (void) printf("\tcheckpoint_txg = %llu\n",
2565 (u_longlong_t
)ub
->ub_checkpoint_txg
);
2566 (void) printf("%s", footer
? footer
: "");
2570 dump_config(spa_t
*spa
)
2577 error
= dmu_bonus_hold(spa
->spa_meta_objset
,
2578 spa
->spa_config_object
, FTAG
, &db
);
2581 nvsize
= *(uint64_t *)db
->db_data
;
2582 dmu_buf_rele(db
, FTAG
);
2584 (void) printf("\nMOS Configuration:\n");
2585 dump_packed_nvlist(spa
->spa_meta_objset
,
2586 spa
->spa_config_object
, (void *)&nvsize
, 1);
2588 (void) fprintf(stderr
, "dmu_bonus_hold(%llu) failed, errno %d",
2589 (u_longlong_t
)spa
->spa_config_object
, error
);
2594 dump_cachefile(const char *cachefile
)
2597 struct stat64 statbuf
;
2601 if ((fd
= open64(cachefile
, O_RDONLY
)) < 0) {
2602 (void) printf("cannot open '%s': %s\n", cachefile
,
2607 if (fstat64(fd
, &statbuf
) != 0) {
2608 (void) printf("failed to stat '%s': %s\n", cachefile
,
2613 if ((buf
= malloc(statbuf
.st_size
)) == NULL
) {
2614 (void) fprintf(stderr
, "failed to allocate %llu bytes\n",
2615 (u_longlong_t
)statbuf
.st_size
);
2619 if (read(fd
, buf
, statbuf
.st_size
) != statbuf
.st_size
) {
2620 (void) fprintf(stderr
, "failed to read %llu bytes\n",
2621 (u_longlong_t
)statbuf
.st_size
);
2627 if (nvlist_unpack(buf
, statbuf
.st_size
, &config
, 0) != 0) {
2628 (void) fprintf(stderr
, "failed to unpack nvlist\n");
2634 dump_nvlist(config
, 0);
2636 nvlist_free(config
);
2640 * ZFS label nvlist stats
2642 typedef struct zdb_nvl_stats
{
2645 size_t zns_leaf_largest
;
2646 size_t zns_leaf_total
;
2647 nvlist_t
*zns_string
;
2648 nvlist_t
*zns_uint64
;
2649 nvlist_t
*zns_boolean
;
2653 collect_nvlist_stats(nvlist_t
*nvl
, zdb_nvl_stats_t
*stats
)
2655 nvlist_t
*list
, **array
;
2656 nvpair_t
*nvp
= NULL
;
2660 stats
->zns_list_count
++;
2662 while ((nvp
= nvlist_next_nvpair(nvl
, nvp
)) != NULL
) {
2663 name
= nvpair_name(nvp
);
2665 switch (nvpair_type(nvp
)) {
2666 case DATA_TYPE_STRING
:
2667 fnvlist_add_string(stats
->zns_string
, name
,
2668 fnvpair_value_string(nvp
));
2670 case DATA_TYPE_UINT64
:
2671 fnvlist_add_uint64(stats
->zns_uint64
, name
,
2672 fnvpair_value_uint64(nvp
));
2674 case DATA_TYPE_BOOLEAN
:
2675 fnvlist_add_boolean(stats
->zns_boolean
, name
);
2677 case DATA_TYPE_NVLIST
:
2678 if (nvpair_value_nvlist(nvp
, &list
) == 0)
2679 collect_nvlist_stats(list
, stats
);
2681 case DATA_TYPE_NVLIST_ARRAY
:
2682 if (nvpair_value_nvlist_array(nvp
, &array
, &items
) != 0)
2685 for (i
= 0; i
< items
; i
++) {
2686 collect_nvlist_stats(array
[i
], stats
);
2688 /* collect stats on leaf vdev */
2689 if (strcmp(name
, "children") == 0) {
2692 (void) nvlist_size(array
[i
], &size
,
2694 stats
->zns_leaf_total
+= size
;
2695 if (size
> stats
->zns_leaf_largest
)
2696 stats
->zns_leaf_largest
= size
;
2697 stats
->zns_leaf_count
++;
2702 (void) printf("skip type %d!\n", (int)nvpair_type(nvp
));
2708 dump_nvlist_stats(nvlist_t
*nvl
, size_t cap
)
2710 zdb_nvl_stats_t stats
= { 0 };
2711 size_t size
, sum
= 0, total
;
2714 /* requires nvlist with non-unique names for stat collection */
2715 VERIFY0(nvlist_alloc(&stats
.zns_string
, 0, 0));
2716 VERIFY0(nvlist_alloc(&stats
.zns_uint64
, 0, 0));
2717 VERIFY0(nvlist_alloc(&stats
.zns_boolean
, 0, 0));
2718 VERIFY0(nvlist_size(stats
.zns_boolean
, &noise
, NV_ENCODE_XDR
));
2720 (void) printf("\n\nZFS Label NVList Config Stats:\n");
2722 VERIFY0(nvlist_size(nvl
, &total
, NV_ENCODE_XDR
));
2723 (void) printf(" %d bytes used, %d bytes free (using %4.1f%%)\n\n",
2724 (int)total
, (int)(cap
- total
), 100.0 * total
/ cap
);
2726 collect_nvlist_stats(nvl
, &stats
);
2728 VERIFY0(nvlist_size(stats
.zns_uint64
, &size
, NV_ENCODE_XDR
));
2731 (void) printf("%12s %4d %6d bytes (%5.2f%%)\n", "integers:",
2732 (int)fnvlist_num_pairs(stats
.zns_uint64
),
2733 (int)size
, 100.0 * size
/ total
);
2735 VERIFY0(nvlist_size(stats
.zns_string
, &size
, NV_ENCODE_XDR
));
2738 (void) printf("%12s %4d %6d bytes (%5.2f%%)\n", "strings:",
2739 (int)fnvlist_num_pairs(stats
.zns_string
),
2740 (int)size
, 100.0 * size
/ total
);
2742 VERIFY0(nvlist_size(stats
.zns_boolean
, &size
, NV_ENCODE_XDR
));
2745 (void) printf("%12s %4d %6d bytes (%5.2f%%)\n", "booleans:",
2746 (int)fnvlist_num_pairs(stats
.zns_boolean
),
2747 (int)size
, 100.0 * size
/ total
);
2749 size
= total
- sum
; /* treat remainder as nvlist overhead */
2750 (void) printf("%12s %4d %6d bytes (%5.2f%%)\n\n", "nvlists:",
2751 stats
.zns_list_count
, (int)size
, 100.0 * size
/ total
);
2753 if (stats
.zns_leaf_count
> 0) {
2754 size_t average
= stats
.zns_leaf_total
/ stats
.zns_leaf_count
;
2756 (void) printf("%12s %4d %6d bytes average\n", "leaf vdevs:",
2757 stats
.zns_leaf_count
, (int)average
);
2758 (void) printf("%24d bytes largest\n",
2759 (int)stats
.zns_leaf_largest
);
2761 if (dump_opt
['l'] >= 3 && average
> 0)
2762 (void) printf(" space for %d additional leaf vdevs\n",
2763 (int)((cap
- total
) / average
));
2765 (void) printf("\n");
2767 nvlist_free(stats
.zns_string
);
2768 nvlist_free(stats
.zns_uint64
);
2769 nvlist_free(stats
.zns_boolean
);
2772 typedef struct cksum_record
{
2774 boolean_t labels
[VDEV_LABELS
];
2779 cksum_record_compare(const void *x1
, const void *x2
)
2781 const cksum_record_t
*l
= (cksum_record_t
*)x1
;
2782 const cksum_record_t
*r
= (cksum_record_t
*)x2
;
2783 int arraysize
= ARRAY_SIZE(l
->cksum
.zc_word
);
2786 for (int i
= 0; i
< arraysize
; i
++) {
2787 difference
= AVL_CMP(l
->cksum
.zc_word
[i
], r
->cksum
.zc_word
[i
]);
2792 return (difference
);
2795 static cksum_record_t
*
2796 cksum_record_alloc(zio_cksum_t
*cksum
, int l
)
2798 cksum_record_t
*rec
;
2800 rec
= umem_zalloc(sizeof (*rec
), UMEM_NOFAIL
);
2801 rec
->cksum
= *cksum
;
2802 rec
->labels
[l
] = B_TRUE
;
2807 static cksum_record_t
*
2808 cksum_record_lookup(avl_tree_t
*tree
, zio_cksum_t
*cksum
)
2810 cksum_record_t lookup
= { .cksum
= *cksum
};
2813 return (avl_find(tree
, &lookup
, &where
));
2816 static cksum_record_t
*
2817 cksum_record_insert(avl_tree_t
*tree
, zio_cksum_t
*cksum
, int l
)
2819 cksum_record_t
*rec
;
2821 rec
= cksum_record_lookup(tree
, cksum
);
2823 rec
->labels
[l
] = B_TRUE
;
2825 rec
= cksum_record_alloc(cksum
, l
);
2833 first_label(cksum_record_t
*rec
)
2835 for (int i
= 0; i
< VDEV_LABELS
; i
++)
2843 print_label_numbers(char *prefix
, cksum_record_t
*rec
)
2845 printf("%s", prefix
);
2846 for (int i
= 0; i
< VDEV_LABELS
; i
++)
2847 if (rec
->labels
[i
] == B_TRUE
)
2852 #define MAX_UBERBLOCK_COUNT (VDEV_UBERBLOCK_RING >> UBERBLOCK_SHIFT)
2854 typedef struct label
{
2856 nvlist_t
*config_nv
;
2857 cksum_record_t
*config
;
2858 cksum_record_t
*uberblocks
[MAX_UBERBLOCK_COUNT
];
2859 boolean_t header_printed
;
2860 boolean_t read_failed
;
2864 print_label_header(label_t
*label
, int l
)
2870 if (label
->header_printed
== B_TRUE
)
2873 (void) printf("------------------------------------\n");
2874 (void) printf("LABEL %d\n", l
);
2875 (void) printf("------------------------------------\n");
2877 label
->header_printed
= B_TRUE
;
2881 dump_config_from_label(label_t
*label
, size_t buflen
, int l
)
2886 if ((dump_opt
['l'] < 3) && (first_label(label
->config
) != l
))
2889 print_label_header(label
, l
);
2890 dump_nvlist(label
->config_nv
, 4);
2891 print_label_numbers(" labels = ", label
->config
);
2893 if (dump_opt
['l'] >= 2)
2894 dump_nvlist_stats(label
->config_nv
, buflen
);
2897 #define ZDB_MAX_UB_HEADER_SIZE 32
2900 dump_label_uberblocks(label_t
*label
, uint64_t ashift
, int label_num
)
2904 char header
[ZDB_MAX_UB_HEADER_SIZE
];
2906 vd
.vdev_ashift
= ashift
;
2909 for (int i
= 0; i
< VDEV_UBERBLOCK_COUNT(&vd
); i
++) {
2910 uint64_t uoff
= VDEV_UBERBLOCK_OFFSET(&vd
, i
);
2911 uberblock_t
*ub
= (void *)((char *)&label
->label
+ uoff
);
2912 cksum_record_t
*rec
= label
->uberblocks
[i
];
2915 if (dump_opt
['u'] >= 2) {
2916 print_label_header(label
, label_num
);
2917 (void) printf(" Uberblock[%d] invalid\n", i
);
2922 if ((dump_opt
['u'] < 3) && (first_label(rec
) != label_num
))
2925 if ((dump_opt
['u'] < 4) &&
2926 (ub
->ub_mmp_magic
== MMP_MAGIC
) && ub
->ub_mmp_delay
&&
2927 (i
>= VDEV_UBERBLOCK_COUNT(&vd
) - MMP_BLOCKS_PER_LABEL
))
2930 print_label_header(label
, label_num
);
2931 (void) snprintf(header
, ZDB_MAX_UB_HEADER_SIZE
,
2932 " Uberblock[%d]\n", i
);
2933 dump_uberblock(ub
, header
, "");
2934 print_label_numbers(" labels = ", rec
);
2938 static char curpath
[PATH_MAX
];
2941 * Iterate through the path components, recursively passing
2942 * current one's obj and remaining path until we find the obj
2946 dump_path_impl(objset_t
*os
, uint64_t obj
, char *name
)
2953 dmu_object_info_t doi
;
2955 if ((s
= strchr(name
, '/')) != NULL
)
2957 err
= zap_lookup(os
, obj
, name
, 8, 1, &child_obj
);
2959 (void) strlcat(curpath
, name
, sizeof (curpath
));
2962 (void) fprintf(stderr
, "failed to lookup %s: %s\n",
2963 curpath
, strerror(err
));
2967 child_obj
= ZFS_DIRENT_OBJ(child_obj
);
2968 err
= sa_buf_hold(os
, child_obj
, FTAG
, &db
);
2970 (void) fprintf(stderr
,
2971 "failed to get SA dbuf for obj %llu: %s\n",
2972 (u_longlong_t
)child_obj
, strerror(err
));
2975 dmu_object_info_from_db(db
, &doi
);
2976 sa_buf_rele(db
, FTAG
);
2978 if (doi
.doi_bonus_type
!= DMU_OT_SA
&&
2979 doi
.doi_bonus_type
!= DMU_OT_ZNODE
) {
2980 (void) fprintf(stderr
, "invalid bonus type %d for obj %llu\n",
2981 doi
.doi_bonus_type
, (u_longlong_t
)child_obj
);
2985 if (dump_opt
['v'] > 6) {
2986 (void) printf("obj=%llu %s type=%d bonustype=%d\n",
2987 (u_longlong_t
)child_obj
, curpath
, doi
.doi_type
,
2988 doi
.doi_bonus_type
);
2991 (void) strlcat(curpath
, "/", sizeof (curpath
));
2993 switch (doi
.doi_type
) {
2994 case DMU_OT_DIRECTORY_CONTENTS
:
2995 if (s
!= NULL
&& *(s
+ 1) != '\0')
2996 return (dump_path_impl(os
, child_obj
, s
+ 1));
2998 case DMU_OT_PLAIN_FILE_CONTENTS
:
2999 dump_object(os
, child_obj
, dump_opt
['v'], &header
, NULL
);
3002 (void) fprintf(stderr
, "object %llu has non-file/directory "
3003 "type %d\n", (u_longlong_t
)obj
, doi
.doi_type
);
3011 * Dump the blocks for the object specified by path inside the dataset.
3014 dump_path(char *ds
, char *path
)
3020 err
= open_objset(ds
, DMU_OST_ZFS
, FTAG
, &os
);
3024 err
= zap_lookup(os
, MASTER_NODE_OBJ
, ZFS_ROOT_OBJ
, 8, 1, &root_obj
);
3026 (void) fprintf(stderr
, "can't lookup root znode: %s\n",
3028 dmu_objset_disown(os
, B_FALSE
, FTAG
);
3032 (void) snprintf(curpath
, sizeof (curpath
), "dataset=%s path=/", ds
);
3034 err
= dump_path_impl(os
, root_obj
, path
);
3036 close_objset(os
, FTAG
);
3041 dump_label(const char *dev
)
3043 char path
[MAXPATHLEN
];
3044 label_t labels
[VDEV_LABELS
];
3045 uint64_t psize
, ashift
;
3046 struct stat64 statbuf
;
3047 boolean_t config_found
= B_FALSE
;
3048 boolean_t error
= B_FALSE
;
3049 avl_tree_t config_tree
;
3050 avl_tree_t uberblock_tree
;
3051 void *node
, *cookie
;
3054 bzero(labels
, sizeof (labels
));
3057 * Check if we were given absolute path and use it as is.
3058 * Otherwise if the provided vdev name doesn't point to a file,
3059 * try prepending expected disk paths and partition numbers.
3061 (void) strlcpy(path
, dev
, sizeof (path
));
3062 if (dev
[0] != '/' && stat64(path
, &statbuf
) != 0) {
3065 error
= zfs_resolve_shortname(dev
, path
, MAXPATHLEN
);
3066 if (error
== 0 && zfs_dev_is_whole_disk(path
)) {
3067 if (zfs_append_partition(path
, MAXPATHLEN
) == -1)
3071 if (error
|| (stat64(path
, &statbuf
) != 0)) {
3072 (void) printf("failed to find device %s, try "
3073 "specifying absolute path instead\n", dev
);
3078 if ((fd
= open64(path
, O_RDONLY
)) < 0) {
3079 (void) printf("cannot open '%s': %s\n", path
, strerror(errno
));
3083 if (fstat64_blk(fd
, &statbuf
) != 0) {
3084 (void) printf("failed to stat '%s': %s\n", path
,
3090 if (S_ISBLK(statbuf
.st_mode
) && ioctl(fd
, BLKFLSBUF
) != 0)
3091 (void) printf("failed to invalidate cache '%s' : %s\n", path
,
3094 avl_create(&config_tree
, cksum_record_compare
,
3095 sizeof (cksum_record_t
), offsetof(cksum_record_t
, link
));
3096 avl_create(&uberblock_tree
, cksum_record_compare
,
3097 sizeof (cksum_record_t
), offsetof(cksum_record_t
, link
));
3099 psize
= statbuf
.st_size
;
3100 psize
= P2ALIGN(psize
, (uint64_t)sizeof (vdev_label_t
));
3101 ashift
= SPA_MINBLOCKSHIFT
;
3104 * 1. Read the label from disk
3105 * 2. Unpack the configuration and insert in config tree.
3106 * 3. Traverse all uberblocks and insert in uberblock tree.
3108 for (int l
= 0; l
< VDEV_LABELS
; l
++) {
3109 label_t
*label
= &labels
[l
];
3110 char *buf
= label
->label
.vl_vdev_phys
.vp_nvlist
;
3111 size_t buflen
= sizeof (label
->label
.vl_vdev_phys
.vp_nvlist
);
3113 cksum_record_t
*rec
;
3117 if (pread64(fd
, &label
->label
, sizeof (label
->label
),
3118 vdev_label_offset(psize
, l
, 0)) != sizeof (label
->label
)) {
3120 (void) printf("failed to read label %d\n", l
);
3121 label
->read_failed
= B_TRUE
;
3126 label
->read_failed
= B_FALSE
;
3128 if (nvlist_unpack(buf
, buflen
, &config
, 0) == 0) {
3129 nvlist_t
*vdev_tree
= NULL
;
3132 if ((nvlist_lookup_nvlist(config
,
3133 ZPOOL_CONFIG_VDEV_TREE
, &vdev_tree
) != 0) ||
3134 (nvlist_lookup_uint64(vdev_tree
,
3135 ZPOOL_CONFIG_ASHIFT
, &ashift
) != 0))
3136 ashift
= SPA_MINBLOCKSHIFT
;
3138 if (nvlist_size(config
, &size
, NV_ENCODE_XDR
) != 0)
3141 fletcher_4_native_varsize(buf
, size
, &cksum
);
3142 rec
= cksum_record_insert(&config_tree
, &cksum
, l
);
3144 label
->config
= rec
;
3145 label
->config_nv
= config
;
3146 config_found
= B_TRUE
;
3151 vd
.vdev_ashift
= ashift
;
3154 for (int i
= 0; i
< VDEV_UBERBLOCK_COUNT(&vd
); i
++) {
3155 uint64_t uoff
= VDEV_UBERBLOCK_OFFSET(&vd
, i
);
3156 uberblock_t
*ub
= (void *)((char *)label
+ uoff
);
3158 if (uberblock_verify(ub
))
3161 fletcher_4_native_varsize(ub
, sizeof (*ub
), &cksum
);
3162 rec
= cksum_record_insert(&uberblock_tree
, &cksum
, l
);
3164 label
->uberblocks
[i
] = rec
;
3169 * Dump the label and uberblocks.
3171 for (int l
= 0; l
< VDEV_LABELS
; l
++) {
3172 label_t
*label
= &labels
[l
];
3173 size_t buflen
= sizeof (label
->label
.vl_vdev_phys
.vp_nvlist
);
3175 if (label
->read_failed
== B_TRUE
)
3178 if (label
->config_nv
) {
3179 dump_config_from_label(label
, buflen
, l
);
3182 (void) printf("failed to unpack label %d\n", l
);
3186 dump_label_uberblocks(label
, ashift
, l
);
3188 nvlist_free(label
->config_nv
);
3192 while ((node
= avl_destroy_nodes(&config_tree
, &cookie
)) != NULL
)
3193 umem_free(node
, sizeof (cksum_record_t
));
3196 while ((node
= avl_destroy_nodes(&uberblock_tree
, &cookie
)) != NULL
)
3197 umem_free(node
, sizeof (cksum_record_t
));
3199 avl_destroy(&config_tree
);
3200 avl_destroy(&uberblock_tree
);
3204 return (config_found
== B_FALSE
? 2 :
3205 (error
== B_TRUE
? 1 : 0));
3208 static uint64_t dataset_feature_count
[SPA_FEATURES
];
3209 static uint64_t remap_deadlist_count
= 0;
3213 dump_one_dir(const char *dsname
, void *arg
)
3219 error
= open_objset(dsname
, DMU_OST_ANY
, FTAG
, &os
);
3223 for (f
= 0; f
< SPA_FEATURES
; f
++) {
3224 if (!dsl_dataset_feature_is_active(dmu_objset_ds(os
), f
))
3226 ASSERT(spa_feature_table
[f
].fi_flags
&
3227 ZFEATURE_FLAG_PER_DATASET
);
3228 dataset_feature_count
[f
]++;
3231 if (dsl_dataset_remap_deadlist_exists(dmu_objset_ds(os
))) {
3232 remap_deadlist_count
++;
3236 close_objset(os
, FTAG
);
3237 fuid_table_destroy();
3244 #define PSIZE_HISTO_SIZE (SPA_OLD_MAXBLOCKSIZE / SPA_MINBLOCKSIZE + 2)
3245 typedef struct zdb_blkstats
{
3251 uint64_t zb_ditto_samevdev
;
3252 uint64_t zb_ditto_same_ms
;
3253 uint64_t zb_psize_histogram
[PSIZE_HISTO_SIZE
];
3257 * Extended object types to report deferred frees and dedup auto-ditto blocks.
3259 #define ZDB_OT_DEFERRED (DMU_OT_NUMTYPES + 0)
3260 #define ZDB_OT_DITTO (DMU_OT_NUMTYPES + 1)
3261 #define ZDB_OT_OTHER (DMU_OT_NUMTYPES + 2)
3262 #define ZDB_OT_TOTAL (DMU_OT_NUMTYPES + 3)
3264 static const char *zdb_ot_extname
[] = {
3271 #define ZB_TOTAL DN_MAX_LEVELS
3273 typedef struct zdb_cb
{
3274 zdb_blkstats_t zcb_type
[ZB_TOTAL
+ 1][ZDB_OT_TOTAL
+ 1];
3275 uint64_t zcb_removing_size
;
3276 uint64_t zcb_checkpoint_size
;
3277 uint64_t zcb_dedup_asize
;
3278 uint64_t zcb_dedup_blocks
;
3279 uint64_t zcb_embedded_blocks
[NUM_BP_EMBEDDED_TYPES
];
3280 uint64_t zcb_embedded_histogram
[NUM_BP_EMBEDDED_TYPES
]
3281 [BPE_PAYLOAD_SIZE
+ 1];
3283 hrtime_t zcb_lastprint
;
3284 uint64_t zcb_totalasize
;
3285 uint64_t zcb_errors
[256];
3289 uint32_t **zcb_vd_obsolete_counts
;
3292 /* test if two DVA offsets from same vdev are within the same metaslab */
3294 same_metaslab(spa_t
*spa
, uint64_t vdev
, uint64_t off1
, uint64_t off2
)
3296 vdev_t
*vd
= vdev_lookup_top(spa
, vdev
);
3297 uint64_t ms_shift
= vd
->vdev_ms_shift
;
3299 return ((off1
>> ms_shift
) == (off2
>> ms_shift
));
3303 zdb_count_block(zdb_cb_t
*zcb
, zilog_t
*zilog
, const blkptr_t
*bp
,
3304 dmu_object_type_t type
)
3306 uint64_t refcnt
= 0;
3309 ASSERT(type
< ZDB_OT_TOTAL
);
3311 if (zilog
&& zil_bp_tree_add(zilog
, bp
) != 0)
3314 spa_config_enter(zcb
->zcb_spa
, SCL_CONFIG
, FTAG
, RW_READER
);
3316 for (i
= 0; i
< 4; i
++) {
3317 int l
= (i
< 2) ? BP_GET_LEVEL(bp
) : ZB_TOTAL
;
3318 int t
= (i
& 1) ? type
: ZDB_OT_TOTAL
;
3320 zdb_blkstats_t
*zb
= &zcb
->zcb_type
[l
][t
];
3322 zb
->zb_asize
+= BP_GET_ASIZE(bp
);
3323 zb
->zb_lsize
+= BP_GET_LSIZE(bp
);
3324 zb
->zb_psize
+= BP_GET_PSIZE(bp
);
3328 * The histogram is only big enough to record blocks up to
3329 * SPA_OLD_MAXBLOCKSIZE; larger blocks go into the last,
3332 unsigned idx
= BP_GET_PSIZE(bp
) >> SPA_MINBLOCKSHIFT
;
3333 idx
= MIN(idx
, SPA_OLD_MAXBLOCKSIZE
/ SPA_MINBLOCKSIZE
+ 1);
3334 zb
->zb_psize_histogram
[idx
]++;
3336 zb
->zb_gangs
+= BP_COUNT_GANG(bp
);
3338 switch (BP_GET_NDVAS(bp
)) {
3340 if (DVA_GET_VDEV(&bp
->blk_dva
[0]) ==
3341 DVA_GET_VDEV(&bp
->blk_dva
[1])) {
3342 zb
->zb_ditto_samevdev
++;
3344 if (same_metaslab(zcb
->zcb_spa
,
3345 DVA_GET_VDEV(&bp
->blk_dva
[0]),
3346 DVA_GET_OFFSET(&bp
->blk_dva
[0]),
3347 DVA_GET_OFFSET(&bp
->blk_dva
[1])))
3348 zb
->zb_ditto_same_ms
++;
3352 equal
= (DVA_GET_VDEV(&bp
->blk_dva
[0]) ==
3353 DVA_GET_VDEV(&bp
->blk_dva
[1])) +
3354 (DVA_GET_VDEV(&bp
->blk_dva
[0]) ==
3355 DVA_GET_VDEV(&bp
->blk_dva
[2])) +
3356 (DVA_GET_VDEV(&bp
->blk_dva
[1]) ==
3357 DVA_GET_VDEV(&bp
->blk_dva
[2]));
3359 zb
->zb_ditto_samevdev
++;
3361 if (DVA_GET_VDEV(&bp
->blk_dva
[0]) ==
3362 DVA_GET_VDEV(&bp
->blk_dva
[1]) &&
3363 same_metaslab(zcb
->zcb_spa
,
3364 DVA_GET_VDEV(&bp
->blk_dva
[0]),
3365 DVA_GET_OFFSET(&bp
->blk_dva
[0]),
3366 DVA_GET_OFFSET(&bp
->blk_dva
[1])))
3367 zb
->zb_ditto_same_ms
++;
3368 else if (DVA_GET_VDEV(&bp
->blk_dva
[0]) ==
3369 DVA_GET_VDEV(&bp
->blk_dva
[2]) &&
3370 same_metaslab(zcb
->zcb_spa
,
3371 DVA_GET_VDEV(&bp
->blk_dva
[0]),
3372 DVA_GET_OFFSET(&bp
->blk_dva
[0]),
3373 DVA_GET_OFFSET(&bp
->blk_dva
[2])))
3374 zb
->zb_ditto_same_ms
++;
3375 else if (DVA_GET_VDEV(&bp
->blk_dva
[1]) ==
3376 DVA_GET_VDEV(&bp
->blk_dva
[2]) &&
3377 same_metaslab(zcb
->zcb_spa
,
3378 DVA_GET_VDEV(&bp
->blk_dva
[1]),
3379 DVA_GET_OFFSET(&bp
->blk_dva
[1]),
3380 DVA_GET_OFFSET(&bp
->blk_dva
[2])))
3381 zb
->zb_ditto_same_ms
++;
3387 spa_config_exit(zcb
->zcb_spa
, SCL_CONFIG
, FTAG
);
3389 if (BP_IS_EMBEDDED(bp
)) {
3390 zcb
->zcb_embedded_blocks
[BPE_GET_ETYPE(bp
)]++;
3391 zcb
->zcb_embedded_histogram
[BPE_GET_ETYPE(bp
)]
3392 [BPE_GET_PSIZE(bp
)]++;
3399 if (BP_GET_DEDUP(bp
)) {
3403 ddt
= ddt_select(zcb
->zcb_spa
, bp
);
3405 dde
= ddt_lookup(ddt
, bp
, B_FALSE
);
3410 ddt_phys_t
*ddp
= ddt_phys_select(dde
, bp
);
3411 ddt_phys_decref(ddp
);
3412 refcnt
= ddp
->ddp_refcnt
;
3413 if (ddt_phys_total_refcnt(dde
) == 0)
3414 ddt_remove(ddt
, dde
);
3419 VERIFY3U(zio_wait(zio_claim(NULL
, zcb
->zcb_spa
,
3420 refcnt
? 0 : spa_min_claim_txg(zcb
->zcb_spa
),
3421 bp
, NULL
, NULL
, ZIO_FLAG_CANFAIL
)), ==, 0);
3425 zdb_blkptr_done(zio_t
*zio
)
3427 spa_t
*spa
= zio
->io_spa
;
3428 blkptr_t
*bp
= zio
->io_bp
;
3429 int ioerr
= zio
->io_error
;
3430 zdb_cb_t
*zcb
= zio
->io_private
;
3431 zbookmark_phys_t
*zb
= &zio
->io_bookmark
;
3433 abd_free(zio
->io_abd
);
3435 mutex_enter(&spa
->spa_scrub_lock
);
3436 spa
->spa_load_verify_ios
--;
3437 cv_broadcast(&spa
->spa_scrub_io_cv
);
3439 if (ioerr
&& !(zio
->io_flags
& ZIO_FLAG_SPECULATIVE
)) {
3440 char blkbuf
[BP_SPRINTF_LEN
];
3442 zcb
->zcb_haderrors
= 1;
3443 zcb
->zcb_errors
[ioerr
]++;
3445 if (dump_opt
['b'] >= 2)
3446 snprintf_blkptr(blkbuf
, sizeof (blkbuf
), bp
);
3450 (void) printf("zdb_blkptr_cb: "
3451 "Got error %d reading "
3452 "<%llu, %llu, %lld, %llx> %s -- skipping\n",
3454 (u_longlong_t
)zb
->zb_objset
,
3455 (u_longlong_t
)zb
->zb_object
,
3456 (u_longlong_t
)zb
->zb_level
,
3457 (u_longlong_t
)zb
->zb_blkid
,
3460 mutex_exit(&spa
->spa_scrub_lock
);
3464 zdb_blkptr_cb(spa_t
*spa
, zilog_t
*zilog
, const blkptr_t
*bp
,
3465 const zbookmark_phys_t
*zb
, const dnode_phys_t
*dnp
, void *arg
)
3467 zdb_cb_t
*zcb
= arg
;
3468 dmu_object_type_t type
;
3469 boolean_t is_metadata
;
3474 if (dump_opt
['b'] >= 5 && bp
->blk_birth
> 0) {
3475 char blkbuf
[BP_SPRINTF_LEN
];
3476 snprintf_blkptr(blkbuf
, sizeof (blkbuf
), bp
);
3477 (void) printf("objset %llu object %llu "
3478 "level %lld offset 0x%llx %s\n",
3479 (u_longlong_t
)zb
->zb_objset
,
3480 (u_longlong_t
)zb
->zb_object
,
3481 (longlong_t
)zb
->zb_level
,
3482 (u_longlong_t
)blkid2offset(dnp
, bp
, zb
),
3489 type
= BP_GET_TYPE(bp
);
3491 zdb_count_block(zcb
, zilog
, bp
,
3492 (type
& DMU_OT_NEWTYPE
) ? ZDB_OT_OTHER
: type
);
3494 is_metadata
= (BP_GET_LEVEL(bp
) != 0 || DMU_OT_IS_METADATA(type
));
3496 if (!BP_IS_EMBEDDED(bp
) &&
3497 (dump_opt
['c'] > 1 || (dump_opt
['c'] && is_metadata
))) {
3498 size_t size
= BP_GET_PSIZE(bp
);
3499 abd_t
*abd
= abd_alloc(size
, B_FALSE
);
3500 int flags
= ZIO_FLAG_CANFAIL
| ZIO_FLAG_SCRUB
| ZIO_FLAG_RAW
;
3502 /* If it's an intent log block, failure is expected. */
3503 if (zb
->zb_level
== ZB_ZIL_LEVEL
)
3504 flags
|= ZIO_FLAG_SPECULATIVE
;
3506 mutex_enter(&spa
->spa_scrub_lock
);
3507 while (spa
->spa_load_verify_ios
> max_inflight
)
3508 cv_wait(&spa
->spa_scrub_io_cv
, &spa
->spa_scrub_lock
);
3509 spa
->spa_load_verify_ios
++;
3510 mutex_exit(&spa
->spa_scrub_lock
);
3512 zio_nowait(zio_read(NULL
, spa
, bp
, abd
, size
,
3513 zdb_blkptr_done
, zcb
, ZIO_PRIORITY_ASYNC_READ
, flags
, zb
));
3516 zcb
->zcb_readfails
= 0;
3518 /* only call gethrtime() every 100 blocks */
3525 if (dump_opt
['b'] < 5 && gethrtime() > zcb
->zcb_lastprint
+ NANOSEC
) {
3526 uint64_t now
= gethrtime();
3528 uint64_t bytes
= zcb
->zcb_type
[ZB_TOTAL
][ZDB_OT_TOTAL
].zb_asize
;
3530 1 + bytes
/ (1 + ((now
- zcb
->zcb_start
) / 1000 / 1000));
3532 (zcb
->zcb_totalasize
- bytes
) / 1024 / kb_per_sec
;
3534 /* make sure nicenum has enough space */
3535 CTASSERT(sizeof (buf
) >= NN_NUMBUF_SZ
);
3537 zfs_nicebytes(bytes
, buf
, sizeof (buf
));
3538 (void) fprintf(stderr
,
3539 "\r%5s completed (%4dMB/s) "
3540 "estimated time remaining: %uhr %02umin %02usec ",
3541 buf
, kb_per_sec
/ 1024,
3542 sec_remaining
/ 60 / 60,
3543 sec_remaining
/ 60 % 60,
3544 sec_remaining
% 60);
3546 zcb
->zcb_lastprint
= now
;
3553 zdb_leak(void *arg
, uint64_t start
, uint64_t size
)
3557 (void) printf("leaked space: vdev %llu, offset 0x%llx, size %llu\n",
3558 (u_longlong_t
)vd
->vdev_id
, (u_longlong_t
)start
, (u_longlong_t
)size
);
3561 static metaslab_ops_t zdb_metaslab_ops
= {
3567 claim_segment_impl_cb(uint64_t inner_offset
, vdev_t
*vd
, uint64_t offset
,
3568 uint64_t size
, void *arg
)
3571 * This callback was called through a remap from
3572 * a device being removed. Therefore, the vdev that
3573 * this callback is applied to is a concrete
3576 ASSERT(vdev_is_concrete(vd
));
3578 VERIFY0(metaslab_claim_impl(vd
, offset
, size
,
3579 spa_min_claim_txg(vd
->vdev_spa
)));
3583 claim_segment_cb(void *arg
, uint64_t offset
, uint64_t size
)
3587 vdev_indirect_ops
.vdev_op_remap(vd
, offset
, size
,
3588 claim_segment_impl_cb
, NULL
);
3592 * After accounting for all allocated blocks that are directly referenced,
3593 * we might have missed a reference to a block from a partially complete
3594 * (and thus unused) indirect mapping object. We perform a secondary pass
3595 * through the metaslabs we have already mapped and claim the destination
3599 zdb_claim_removing(spa_t
*spa
, zdb_cb_t
*zcb
)
3601 if (spa
->spa_vdev_removal
== NULL
)
3604 spa_config_enter(spa
, SCL_CONFIG
, FTAG
, RW_READER
);
3606 spa_vdev_removal_t
*svr
= spa
->spa_vdev_removal
;
3607 vdev_t
*vd
= vdev_lookup_top(spa
, svr
->svr_vdev_id
);
3608 vdev_indirect_mapping_t
*vim
= vd
->vdev_indirect_mapping
;
3610 for (uint64_t msi
= 0; msi
< vd
->vdev_ms_count
; msi
++) {
3611 metaslab_t
*msp
= vd
->vdev_ms
[msi
];
3613 if (msp
->ms_start
>= vdev_indirect_mapping_max_offset(vim
))
3616 ASSERT0(range_tree_space(svr
->svr_allocd_segs
));
3618 if (msp
->ms_sm
!= NULL
) {
3619 VERIFY0(space_map_load(msp
->ms_sm
,
3620 svr
->svr_allocd_segs
, SM_ALLOC
));
3623 * Clear everything past what has been synced unless
3624 * it's past the spacemap, because we have not allocated
3625 * mappings for it yet.
3627 uint64_t vim_max_offset
=
3628 vdev_indirect_mapping_max_offset(vim
);
3629 uint64_t sm_end
= msp
->ms_sm
->sm_start
+
3630 msp
->ms_sm
->sm_size
;
3631 if (sm_end
> vim_max_offset
)
3632 range_tree_clear(svr
->svr_allocd_segs
,
3633 vim_max_offset
, sm_end
- vim_max_offset
);
3636 zcb
->zcb_removing_size
+=
3637 range_tree_space(svr
->svr_allocd_segs
);
3638 range_tree_vacate(svr
->svr_allocd_segs
, claim_segment_cb
, vd
);
3641 spa_config_exit(spa
, SCL_CONFIG
, FTAG
);
3646 increment_indirect_mapping_cb(void *arg
, const blkptr_t
*bp
, dmu_tx_t
*tx
)
3648 zdb_cb_t
*zcb
= arg
;
3649 spa_t
*spa
= zcb
->zcb_spa
;
3651 const dva_t
*dva
= &bp
->blk_dva
[0];
3653 ASSERT(!dump_opt
['L']);
3654 ASSERT3U(BP_GET_NDVAS(bp
), ==, 1);
3656 spa_config_enter(spa
, SCL_VDEV
, FTAG
, RW_READER
);
3657 vd
= vdev_lookup_top(zcb
->zcb_spa
, DVA_GET_VDEV(dva
));
3658 ASSERT3P(vd
, !=, NULL
);
3659 spa_config_exit(spa
, SCL_VDEV
, FTAG
);
3661 ASSERT(vd
->vdev_indirect_config
.vic_mapping_object
!= 0);
3662 ASSERT3P(zcb
->zcb_vd_obsolete_counts
[vd
->vdev_id
], !=, NULL
);
3664 vdev_indirect_mapping_increment_obsolete_count(
3665 vd
->vdev_indirect_mapping
,
3666 DVA_GET_OFFSET(dva
), DVA_GET_ASIZE(dva
),
3667 zcb
->zcb_vd_obsolete_counts
[vd
->vdev_id
]);
3673 zdb_load_obsolete_counts(vdev_t
*vd
)
3675 vdev_indirect_mapping_t
*vim
= vd
->vdev_indirect_mapping
;
3676 spa_t
*spa
= vd
->vdev_spa
;
3677 spa_condensing_indirect_phys_t
*scip
=
3678 &spa
->spa_condensing_indirect_phys
;
3679 uint64_t obsolete_sm_object
;
3682 VERIFY0(vdev_obsolete_sm_object(vd
, &obsolete_sm_object
));
3683 EQUIV(obsolete_sm_object
!= 0, vd
->vdev_obsolete_sm
!= NULL
);
3684 counts
= vdev_indirect_mapping_load_obsolete_counts(vim
);
3685 if (vd
->vdev_obsolete_sm
!= NULL
) {
3686 vdev_indirect_mapping_load_obsolete_spacemap(vim
, counts
,
3687 vd
->vdev_obsolete_sm
);
3689 if (scip
->scip_vdev
== vd
->vdev_id
&&
3690 scip
->scip_prev_obsolete_sm_object
!= 0) {
3691 space_map_t
*prev_obsolete_sm
= NULL
;
3692 VERIFY0(space_map_open(&prev_obsolete_sm
, spa
->spa_meta_objset
,
3693 scip
->scip_prev_obsolete_sm_object
, 0, vd
->vdev_asize
, 0));
3694 space_map_update(prev_obsolete_sm
);
3695 vdev_indirect_mapping_load_obsolete_spacemap(vim
, counts
,
3697 space_map_close(prev_obsolete_sm
);
3703 zdb_ddt_leak_init(spa_t
*spa
, zdb_cb_t
*zcb
)
3710 bzero(&ddb
, sizeof (ddb
));
3711 while ((error
= ddt_walk(spa
, &ddb
, &dde
)) == 0) {
3713 ddt_phys_t
*ddp
= dde
.dde_phys
;
3715 if (ddb
.ddb_class
== DDT_CLASS_UNIQUE
)
3718 ASSERT(ddt_phys_total_refcnt(&dde
) > 1);
3720 for (p
= 0; p
< DDT_PHYS_TYPES
; p
++, ddp
++) {
3721 if (ddp
->ddp_phys_birth
== 0)
3723 ddt_bp_create(ddb
.ddb_checksum
,
3724 &dde
.dde_key
, ddp
, &blk
);
3725 if (p
== DDT_PHYS_DITTO
) {
3726 zdb_count_block(zcb
, NULL
, &blk
, ZDB_OT_DITTO
);
3728 zcb
->zcb_dedup_asize
+=
3729 BP_GET_ASIZE(&blk
) * (ddp
->ddp_refcnt
- 1);
3730 zcb
->zcb_dedup_blocks
++;
3733 if (!dump_opt
['L']) {
3734 ddt_t
*ddt
= spa
->spa_ddt
[ddb
.ddb_checksum
];
3736 VERIFY(ddt_lookup(ddt
, &blk
, B_TRUE
) != NULL
);
3741 ASSERT(error
== ENOENT
);
3744 typedef struct checkpoint_sm_exclude_entry_arg
{
3746 uint64_t cseea_checkpoint_size
;
3747 } checkpoint_sm_exclude_entry_arg_t
;
3750 checkpoint_sm_exclude_entry_cb(space_map_entry_t
*sme
, void *arg
)
3752 checkpoint_sm_exclude_entry_arg_t
*cseea
= arg
;
3753 vdev_t
*vd
= cseea
->cseea_vd
;
3754 metaslab_t
*ms
= vd
->vdev_ms
[sme
->sme_offset
>> vd
->vdev_ms_shift
];
3755 uint64_t end
= sme
->sme_offset
+ sme
->sme_run
;
3757 ASSERT(sme
->sme_type
== SM_FREE
);
3760 * Since the vdev_checkpoint_sm exists in the vdev level
3761 * and the ms_sm space maps exist in the metaslab level,
3762 * an entry in the checkpoint space map could theoretically
3763 * cross the boundaries of the metaslab that it belongs.
3765 * In reality, because of the way that we populate and
3766 * manipulate the checkpoint's space maps currently,
3767 * there shouldn't be any entries that cross metaslabs.
3768 * Hence the assertion below.
3770 * That said, there is no fundamental requirement that
3771 * the checkpoint's space map entries should not cross
3772 * metaslab boundaries. So if needed we could add code
3773 * that handles metaslab-crossing segments in the future.
3775 VERIFY3U(sme
->sme_offset
, >=, ms
->ms_start
);
3776 VERIFY3U(end
, <=, ms
->ms_start
+ ms
->ms_size
);
3779 * By removing the entry from the allocated segments we
3780 * also verify that the entry is there to begin with.
3782 mutex_enter(&ms
->ms_lock
);
3783 range_tree_remove(ms
->ms_allocatable
, sme
->sme_offset
, sme
->sme_run
);
3784 mutex_exit(&ms
->ms_lock
);
3786 cseea
->cseea_checkpoint_size
+= sme
->sme_run
;
3791 zdb_leak_init_vdev_exclude_checkpoint(vdev_t
*vd
, zdb_cb_t
*zcb
)
3793 spa_t
*spa
= vd
->vdev_spa
;
3794 space_map_t
*checkpoint_sm
= NULL
;
3795 uint64_t checkpoint_sm_obj
;
3798 * If there is no vdev_top_zap, we are in a pool whose
3799 * version predates the pool checkpoint feature.
3801 if (vd
->vdev_top_zap
== 0)
3805 * If there is no reference of the vdev_checkpoint_sm in
3806 * the vdev_top_zap, then one of the following scenarios
3809 * 1] There is no checkpoint
3810 * 2] There is a checkpoint, but no checkpointed blocks
3811 * have been freed yet
3812 * 3] The current vdev is indirect
3814 * In these cases we return immediately.
3816 if (zap_contains(spa_meta_objset(spa
), vd
->vdev_top_zap
,
3817 VDEV_TOP_ZAP_POOL_CHECKPOINT_SM
) != 0)
3820 VERIFY0(zap_lookup(spa_meta_objset(spa
), vd
->vdev_top_zap
,
3821 VDEV_TOP_ZAP_POOL_CHECKPOINT_SM
, sizeof (uint64_t), 1,
3822 &checkpoint_sm_obj
));
3824 checkpoint_sm_exclude_entry_arg_t cseea
;
3825 cseea
.cseea_vd
= vd
;
3826 cseea
.cseea_checkpoint_size
= 0;
3828 VERIFY0(space_map_open(&checkpoint_sm
, spa_meta_objset(spa
),
3829 checkpoint_sm_obj
, 0, vd
->vdev_asize
, vd
->vdev_ashift
));
3830 space_map_update(checkpoint_sm
);
3832 VERIFY0(space_map_iterate(checkpoint_sm
,
3833 checkpoint_sm_exclude_entry_cb
, &cseea
));
3834 space_map_close(checkpoint_sm
);
3836 zcb
->zcb_checkpoint_size
+= cseea
.cseea_checkpoint_size
;
3840 zdb_leak_init_exclude_checkpoint(spa_t
*spa
, zdb_cb_t
*zcb
)
3842 vdev_t
*rvd
= spa
->spa_root_vdev
;
3843 for (uint64_t c
= 0; c
< rvd
->vdev_children
; c
++) {
3844 ASSERT3U(c
, ==, rvd
->vdev_child
[c
]->vdev_id
);
3845 zdb_leak_init_vdev_exclude_checkpoint(rvd
->vdev_child
[c
], zcb
);
3850 load_concrete_ms_allocatable_trees(spa_t
*spa
, maptype_t maptype
)
3852 vdev_t
*rvd
= spa
->spa_root_vdev
;
3853 for (uint64_t i
= 0; i
< rvd
->vdev_children
; i
++) {
3854 vdev_t
*vd
= rvd
->vdev_child
[i
];
3856 ASSERT3U(i
, ==, vd
->vdev_id
);
3858 if (vd
->vdev_ops
== &vdev_indirect_ops
)
3861 for (uint64_t m
= 0; m
< vd
->vdev_ms_count
; m
++) {
3862 metaslab_t
*msp
= vd
->vdev_ms
[m
];
3864 (void) fprintf(stderr
,
3865 "\rloading concrete vdev %llu, "
3866 "metaslab %llu of %llu ...",
3867 (longlong_t
)vd
->vdev_id
,
3868 (longlong_t
)msp
->ms_id
,
3869 (longlong_t
)vd
->vdev_ms_count
);
3871 mutex_enter(&msp
->ms_lock
);
3872 metaslab_unload(msp
);
3875 * We don't want to spend the CPU manipulating the
3876 * size-ordered tree, so clear the range_tree ops.
3878 msp
->ms_allocatable
->rt_ops
= NULL
;
3880 if (msp
->ms_sm
!= NULL
) {
3881 VERIFY0(space_map_load(msp
->ms_sm
,
3882 msp
->ms_allocatable
, maptype
));
3884 if (!msp
->ms_loaded
)
3885 msp
->ms_loaded
= B_TRUE
;
3886 mutex_exit(&msp
->ms_lock
);
3892 * vm_idxp is an in-out parameter which (for indirect vdevs) is the
3893 * index in vim_entries that has the first entry in this metaslab.
3894 * On return, it will be set to the first entry after this metaslab.
3897 load_indirect_ms_allocatable_tree(vdev_t
*vd
, metaslab_t
*msp
,
3900 vdev_indirect_mapping_t
*vim
= vd
->vdev_indirect_mapping
;
3902 mutex_enter(&msp
->ms_lock
);
3903 metaslab_unload(msp
);
3906 * We don't want to spend the CPU manipulating the
3907 * size-ordered tree, so clear the range_tree ops.
3909 msp
->ms_allocatable
->rt_ops
= NULL
;
3911 for (; *vim_idxp
< vdev_indirect_mapping_num_entries(vim
);
3913 vdev_indirect_mapping_entry_phys_t
*vimep
=
3914 &vim
->vim_entries
[*vim_idxp
];
3915 uint64_t ent_offset
= DVA_MAPPING_GET_SRC_OFFSET(vimep
);
3916 uint64_t ent_len
= DVA_GET_ASIZE(&vimep
->vimep_dst
);
3917 ASSERT3U(ent_offset
, >=, msp
->ms_start
);
3918 if (ent_offset
>= msp
->ms_start
+ msp
->ms_size
)
3922 * Mappings do not cross metaslab boundaries,
3923 * because we create them by walking the metaslabs.
3925 ASSERT3U(ent_offset
+ ent_len
, <=,
3926 msp
->ms_start
+ msp
->ms_size
);
3927 range_tree_add(msp
->ms_allocatable
, ent_offset
, ent_len
);
3930 if (!msp
->ms_loaded
)
3931 msp
->ms_loaded
= B_TRUE
;
3932 mutex_exit(&msp
->ms_lock
);
3936 zdb_leak_init_prepare_indirect_vdevs(spa_t
*spa
, zdb_cb_t
*zcb
)
3938 vdev_t
*rvd
= spa
->spa_root_vdev
;
3939 for (uint64_t c
= 0; c
< rvd
->vdev_children
; c
++) {
3940 vdev_t
*vd
= rvd
->vdev_child
[c
];
3942 ASSERT3U(c
, ==, vd
->vdev_id
);
3944 if (vd
->vdev_ops
!= &vdev_indirect_ops
)
3948 * Note: we don't check for mapping leaks on
3949 * removing vdevs because their ms_allocatable's
3950 * are used to look for leaks in allocated space.
3952 zcb
->zcb_vd_obsolete_counts
[c
] = zdb_load_obsolete_counts(vd
);
3955 * Normally, indirect vdevs don't have any
3956 * metaslabs. We want to set them up for
3959 VERIFY0(vdev_metaslab_init(vd
, 0));
3961 vdev_indirect_mapping_t
*vim
= vd
->vdev_indirect_mapping
;
3962 uint64_t vim_idx
= 0;
3963 for (uint64_t m
= 0; m
< vd
->vdev_ms_count
; m
++) {
3965 (void) fprintf(stderr
,
3966 "\rloading indirect vdev %llu, "
3967 "metaslab %llu of %llu ...",
3968 (longlong_t
)vd
->vdev_id
,
3969 (longlong_t
)vd
->vdev_ms
[m
]->ms_id
,
3970 (longlong_t
)vd
->vdev_ms_count
);
3972 load_indirect_ms_allocatable_tree(vd
, vd
->vdev_ms
[m
],
3975 ASSERT3U(vim_idx
, ==, vdev_indirect_mapping_num_entries(vim
));
3980 zdb_leak_init(spa_t
*spa
, zdb_cb_t
*zcb
)
3984 if (!dump_opt
['L']) {
3985 dsl_pool_t
*dp
= spa
->spa_dsl_pool
;
3986 vdev_t
*rvd
= spa
->spa_root_vdev
;
3989 * We are going to be changing the meaning of the metaslab's
3990 * ms_allocatable. Ensure that the allocator doesn't try to
3993 spa
->spa_normal_class
->mc_ops
= &zdb_metaslab_ops
;
3994 spa
->spa_log_class
->mc_ops
= &zdb_metaslab_ops
;
3996 zcb
->zcb_vd_obsolete_counts
=
3997 umem_zalloc(rvd
->vdev_children
* sizeof (uint32_t *),
4001 * For leak detection, we overload the ms_allocatable trees
4002 * to contain allocated segments instead of free segments.
4003 * As a result, we can't use the normal metaslab_load/unload
4006 zdb_leak_init_prepare_indirect_vdevs(spa
, zcb
);
4007 load_concrete_ms_allocatable_trees(spa
, SM_ALLOC
);
4010 * On load_concrete_ms_allocatable_trees() we loaded all the
4011 * allocated entries from the ms_sm to the ms_allocatable for
4012 * each metaslab. If the pool has a checkpoint or is in the
4013 * middle of discarding a checkpoint, some of these blocks
4014 * may have been freed but their ms_sm may not have been
4015 * updated because they are referenced by the checkpoint. In
4016 * order to avoid false-positives during leak-detection, we
4017 * go through the vdev's checkpoint space map and exclude all
4018 * its entries from their relevant ms_allocatable.
4020 * We also aggregate the space held by the checkpoint and add
4021 * it to zcb_checkpoint_size.
4023 * Note that at this point we are also verifying that all the
4024 * entries on the checkpoint_sm are marked as allocated in
4025 * the ms_sm of their relevant metaslab.
4026 * [see comment in checkpoint_sm_exclude_entry_cb()]
4028 zdb_leak_init_exclude_checkpoint(spa
, zcb
);
4030 /* for cleaner progress output */
4031 (void) fprintf(stderr
, "\n");
4033 if (bpobj_is_open(&dp
->dp_obsolete_bpobj
)) {
4034 ASSERT(spa_feature_is_enabled(spa
,
4035 SPA_FEATURE_DEVICE_REMOVAL
));
4036 (void) bpobj_iterate_nofree(&dp
->dp_obsolete_bpobj
,
4037 increment_indirect_mapping_cb
, zcb
, NULL
);
4041 * If leak tracing is disabled, we still need to consider
4042 * any checkpointed space in our space verification.
4044 zcb
->zcb_checkpoint_size
+= spa_get_checkpoint_space(spa
);
4047 spa_config_enter(spa
, SCL_CONFIG
, FTAG
, RW_READER
);
4048 zdb_ddt_leak_init(spa
, zcb
);
4049 spa_config_exit(spa
, SCL_CONFIG
, FTAG
);
4053 zdb_check_for_obsolete_leaks(vdev_t
*vd
, zdb_cb_t
*zcb
)
4055 boolean_t leaks
= B_FALSE
;
4056 vdev_indirect_mapping_t
*vim
= vd
->vdev_indirect_mapping
;
4057 uint64_t total_leaked
= 0;
4058 boolean_t are_precise
= B_FALSE
;
4060 ASSERT(vim
!= NULL
);
4062 for (uint64_t i
= 0; i
< vdev_indirect_mapping_num_entries(vim
); i
++) {
4063 vdev_indirect_mapping_entry_phys_t
*vimep
=
4064 &vim
->vim_entries
[i
];
4065 uint64_t obsolete_bytes
= 0;
4066 uint64_t offset
= DVA_MAPPING_GET_SRC_OFFSET(vimep
);
4067 metaslab_t
*msp
= vd
->vdev_ms
[offset
>> vd
->vdev_ms_shift
];
4070 * This is not very efficient but it's easy to
4071 * verify correctness.
4073 for (uint64_t inner_offset
= 0;
4074 inner_offset
< DVA_GET_ASIZE(&vimep
->vimep_dst
);
4075 inner_offset
+= 1 << vd
->vdev_ashift
) {
4076 if (range_tree_contains(msp
->ms_allocatable
,
4077 offset
+ inner_offset
, 1 << vd
->vdev_ashift
)) {
4078 obsolete_bytes
+= 1 << vd
->vdev_ashift
;
4082 int64_t bytes_leaked
= obsolete_bytes
-
4083 zcb
->zcb_vd_obsolete_counts
[vd
->vdev_id
][i
];
4084 ASSERT3U(DVA_GET_ASIZE(&vimep
->vimep_dst
), >=,
4085 zcb
->zcb_vd_obsolete_counts
[vd
->vdev_id
][i
]);
4087 VERIFY0(vdev_obsolete_counts_are_precise(vd
, &are_precise
));
4088 if (bytes_leaked
!= 0 && (are_precise
|| dump_opt
['d'] >= 5)) {
4089 (void) printf("obsolete indirect mapping count "
4090 "mismatch on %llu:%llx:%llx : %llx bytes leaked\n",
4091 (u_longlong_t
)vd
->vdev_id
,
4092 (u_longlong_t
)DVA_MAPPING_GET_SRC_OFFSET(vimep
),
4093 (u_longlong_t
)DVA_GET_ASIZE(&vimep
->vimep_dst
),
4094 (u_longlong_t
)bytes_leaked
);
4096 total_leaked
+= ABS(bytes_leaked
);
4099 VERIFY0(vdev_obsolete_counts_are_precise(vd
, &are_precise
));
4100 if (!are_precise
&& total_leaked
> 0) {
4101 int pct_leaked
= total_leaked
* 100 /
4102 vdev_indirect_mapping_bytes_mapped(vim
);
4103 (void) printf("cannot verify obsolete indirect mapping "
4104 "counts of vdev %llu because precise feature was not "
4105 "enabled when it was removed: %d%% (%llx bytes) of mapping"
4107 (u_longlong_t
)vd
->vdev_id
, pct_leaked
,
4108 (u_longlong_t
)total_leaked
);
4109 } else if (total_leaked
> 0) {
4110 (void) printf("obsolete indirect mapping count mismatch "
4111 "for vdev %llu -- %llx total bytes mismatched\n",
4112 (u_longlong_t
)vd
->vdev_id
,
4113 (u_longlong_t
)total_leaked
);
4117 vdev_indirect_mapping_free_obsolete_counts(vim
,
4118 zcb
->zcb_vd_obsolete_counts
[vd
->vdev_id
]);
4119 zcb
->zcb_vd_obsolete_counts
[vd
->vdev_id
] = NULL
;
4125 zdb_leak_fini(spa_t
*spa
, zdb_cb_t
*zcb
)
4127 boolean_t leaks
= B_FALSE
;
4128 if (!dump_opt
['L']) {
4129 vdev_t
*rvd
= spa
->spa_root_vdev
;
4130 for (unsigned c
= 0; c
< rvd
->vdev_children
; c
++) {
4131 vdev_t
*vd
= rvd
->vdev_child
[c
];
4132 ASSERTV(metaslab_group_t
*mg
= vd
->vdev_mg
);
4134 if (zcb
->zcb_vd_obsolete_counts
[c
] != NULL
) {
4135 leaks
|= zdb_check_for_obsolete_leaks(vd
, zcb
);
4138 for (uint64_t m
= 0; m
< vd
->vdev_ms_count
; m
++) {
4139 metaslab_t
*msp
= vd
->vdev_ms
[m
];
4140 ASSERT3P(mg
, ==, msp
->ms_group
);
4143 * ms_allocatable has been overloaded
4144 * to contain allocated segments. Now that
4145 * we finished traversing all blocks, any
4146 * block that remains in the ms_allocatable
4147 * represents an allocated block that we
4148 * did not claim during the traversal.
4149 * Claimed blocks would have been removed
4150 * from the ms_allocatable. For indirect
4151 * vdevs, space remaining in the tree
4152 * represents parts of the mapping that are
4153 * not referenced, which is not a bug.
4155 if (vd
->vdev_ops
== &vdev_indirect_ops
) {
4156 range_tree_vacate(msp
->ms_allocatable
,
4159 range_tree_vacate(msp
->ms_allocatable
,
4164 msp
->ms_loaded
= B_FALSE
;
4168 umem_free(zcb
->zcb_vd_obsolete_counts
,
4169 rvd
->vdev_children
* sizeof (uint32_t *));
4170 zcb
->zcb_vd_obsolete_counts
= NULL
;
4177 count_block_cb(void *arg
, const blkptr_t
*bp
, dmu_tx_t
*tx
)
4179 zdb_cb_t
*zcb
= arg
;
4181 if (dump_opt
['b'] >= 5) {
4182 char blkbuf
[BP_SPRINTF_LEN
];
4183 snprintf_blkptr(blkbuf
, sizeof (blkbuf
), bp
);
4184 (void) printf("[%s] %s\n",
4185 "deferred free", blkbuf
);
4187 zdb_count_block(zcb
, NULL
, bp
, ZDB_OT_DEFERRED
);
4192 dump_block_stats(spa_t
*spa
)
4195 zdb_blkstats_t
*zb
, *tzb
;
4196 uint64_t norm_alloc
, norm_space
, total_alloc
, total_found
;
4197 int flags
= TRAVERSE_PRE
| TRAVERSE_PREFETCH_METADATA
|
4198 TRAVERSE_NO_DECRYPT
| TRAVERSE_HARD
;
4199 boolean_t leaks
= B_FALSE
;
4201 bp_embedded_type_t i
;
4203 bzero(&zcb
, sizeof (zcb
));
4204 (void) printf("\nTraversing all blocks %s%s%s%s%s...\n\n",
4205 (dump_opt
['c'] || !dump_opt
['L']) ? "to verify " : "",
4206 (dump_opt
['c'] == 1) ? "metadata " : "",
4207 dump_opt
['c'] ? "checksums " : "",
4208 (dump_opt
['c'] && !dump_opt
['L']) ? "and verify " : "",
4209 !dump_opt
['L'] ? "nothing leaked " : "");
4212 * Load all space maps as SM_ALLOC maps, then traverse the pool
4213 * claiming each block we discover. If the pool is perfectly
4214 * consistent, the space maps will be empty when we're done.
4215 * Anything left over is a leak; any block we can't claim (because
4216 * it's not part of any space map) is a double allocation,
4217 * reference to a freed block, or an unclaimed log block.
4219 bzero(&zcb
, sizeof (zdb_cb_t
));
4220 zdb_leak_init(spa
, &zcb
);
4223 * If there's a deferred-free bplist, process that first.
4225 (void) bpobj_iterate_nofree(&spa
->spa_deferred_bpobj
,
4226 count_block_cb
, &zcb
, NULL
);
4228 if (spa_version(spa
) >= SPA_VERSION_DEADLISTS
) {
4229 (void) bpobj_iterate_nofree(&spa
->spa_dsl_pool
->dp_free_bpobj
,
4230 count_block_cb
, &zcb
, NULL
);
4233 zdb_claim_removing(spa
, &zcb
);
4235 if (spa_feature_is_active(spa
, SPA_FEATURE_ASYNC_DESTROY
)) {
4236 VERIFY3U(0, ==, bptree_iterate(spa
->spa_meta_objset
,
4237 spa
->spa_dsl_pool
->dp_bptree_obj
, B_FALSE
, count_block_cb
,
4241 if (dump_opt
['c'] > 1)
4242 flags
|= TRAVERSE_PREFETCH_DATA
;
4244 zcb
.zcb_totalasize
= metaslab_class_get_alloc(spa_normal_class(spa
));
4245 zcb
.zcb_totalasize
+= metaslab_class_get_alloc(spa_special_class(spa
));
4246 zcb
.zcb_totalasize
+= metaslab_class_get_alloc(spa_dedup_class(spa
));
4247 zcb
.zcb_start
= zcb
.zcb_lastprint
= gethrtime();
4248 err
= traverse_pool(spa
, 0, flags
, zdb_blkptr_cb
, &zcb
);
4251 * If we've traversed the data blocks then we need to wait for those
4252 * I/Os to complete. We leverage "The Godfather" zio to wait on
4253 * all async I/Os to complete.
4255 if (dump_opt
['c']) {
4256 for (c
= 0; c
< max_ncpus
; c
++) {
4257 (void) zio_wait(spa
->spa_async_zio_root
[c
]);
4258 spa
->spa_async_zio_root
[c
] = zio_root(spa
, NULL
, NULL
,
4259 ZIO_FLAG_CANFAIL
| ZIO_FLAG_SPECULATIVE
|
4260 ZIO_FLAG_GODFATHER
);
4265 * Done after zio_wait() since zcb_haderrors is modified in
4268 zcb
.zcb_haderrors
|= err
;
4270 if (zcb
.zcb_haderrors
) {
4271 (void) printf("\nError counts:\n\n");
4272 (void) printf("\t%5s %s\n", "errno", "count");
4273 for (e
= 0; e
< 256; e
++) {
4274 if (zcb
.zcb_errors
[e
] != 0) {
4275 (void) printf("\t%5d %llu\n",
4276 e
, (u_longlong_t
)zcb
.zcb_errors
[e
]);
4282 * Report any leaked segments.
4284 leaks
|= zdb_leak_fini(spa
, &zcb
);
4286 tzb
= &zcb
.zcb_type
[ZB_TOTAL
][ZDB_OT_TOTAL
];
4288 norm_alloc
= metaslab_class_get_alloc(spa_normal_class(spa
));
4289 norm_space
= metaslab_class_get_space(spa_normal_class(spa
));
4291 total_alloc
= norm_alloc
+
4292 metaslab_class_get_alloc(spa_log_class(spa
)) +
4293 metaslab_class_get_alloc(spa_special_class(spa
)) +
4294 metaslab_class_get_alloc(spa_dedup_class(spa
));
4295 total_found
= tzb
->zb_asize
- zcb
.zcb_dedup_asize
+
4296 zcb
.zcb_removing_size
+ zcb
.zcb_checkpoint_size
;
4298 if (total_found
== total_alloc
) {
4300 (void) printf("\n\tNo leaks (block sum matches space"
4301 " maps exactly)\n");
4303 (void) printf("block traversal size %llu != alloc %llu "
4305 (u_longlong_t
)total_found
,
4306 (u_longlong_t
)total_alloc
,
4307 (dump_opt
['L']) ? "unreachable" : "leaked",
4308 (longlong_t
)(total_alloc
- total_found
));
4312 if (tzb
->zb_count
== 0)
4315 (void) printf("\n");
4316 (void) printf("\t%-16s %14llu\n", "bp count:",
4317 (u_longlong_t
)tzb
->zb_count
);
4318 (void) printf("\t%-16s %14llu\n", "ganged count:",
4319 (longlong_t
)tzb
->zb_gangs
);
4320 (void) printf("\t%-16s %14llu avg: %6llu\n", "bp logical:",
4321 (u_longlong_t
)tzb
->zb_lsize
,
4322 (u_longlong_t
)(tzb
->zb_lsize
/ tzb
->zb_count
));
4323 (void) printf("\t%-16s %14llu avg: %6llu compression: %6.2f\n",
4324 "bp physical:", (u_longlong_t
)tzb
->zb_psize
,
4325 (u_longlong_t
)(tzb
->zb_psize
/ tzb
->zb_count
),
4326 (double)tzb
->zb_lsize
/ tzb
->zb_psize
);
4327 (void) printf("\t%-16s %14llu avg: %6llu compression: %6.2f\n",
4328 "bp allocated:", (u_longlong_t
)tzb
->zb_asize
,
4329 (u_longlong_t
)(tzb
->zb_asize
/ tzb
->zb_count
),
4330 (double)tzb
->zb_lsize
/ tzb
->zb_asize
);
4331 (void) printf("\t%-16s %14llu ref>1: %6llu deduplication: %6.2f\n",
4332 "bp deduped:", (u_longlong_t
)zcb
.zcb_dedup_asize
,
4333 (u_longlong_t
)zcb
.zcb_dedup_blocks
,
4334 (double)zcb
.zcb_dedup_asize
/ tzb
->zb_asize
+ 1.0);
4335 (void) printf("\t%-16s %14llu used: %5.2f%%\n", "Normal class:",
4336 (u_longlong_t
)norm_alloc
, 100.0 * norm_alloc
/ norm_space
);
4338 if (spa_special_class(spa
)->mc_rotor
!= NULL
) {
4339 uint64_t alloc
= metaslab_class_get_alloc(
4340 spa_special_class(spa
));
4341 uint64_t space
= metaslab_class_get_space(
4342 spa_special_class(spa
));
4344 (void) printf("\t%-16s %14llu used: %5.2f%%\n",
4345 "Special class", (u_longlong_t
)alloc
,
4346 100.0 * alloc
/ space
);
4349 if (spa_dedup_class(spa
)->mc_rotor
!= NULL
) {
4350 uint64_t alloc
= metaslab_class_get_alloc(
4351 spa_dedup_class(spa
));
4352 uint64_t space
= metaslab_class_get_space(
4353 spa_dedup_class(spa
));
4355 (void) printf("\t%-16s %14llu used: %5.2f%%\n",
4356 "Dedup class", (u_longlong_t
)alloc
,
4357 100.0 * alloc
/ space
);
4360 for (i
= 0; i
< NUM_BP_EMBEDDED_TYPES
; i
++) {
4361 if (zcb
.zcb_embedded_blocks
[i
] == 0)
4363 (void) printf("\n");
4364 (void) printf("\tadditional, non-pointer bps of type %u: "
4366 i
, (u_longlong_t
)zcb
.zcb_embedded_blocks
[i
]);
4368 if (dump_opt
['b'] >= 3) {
4369 (void) printf("\t number of (compressed) bytes: "
4371 dump_histogram(zcb
.zcb_embedded_histogram
[i
],
4372 sizeof (zcb
.zcb_embedded_histogram
[i
]) /
4373 sizeof (zcb
.zcb_embedded_histogram
[i
][0]), 0);
4377 if (tzb
->zb_ditto_samevdev
!= 0) {
4378 (void) printf("\tDittoed blocks on same vdev: %llu\n",
4379 (longlong_t
)tzb
->zb_ditto_samevdev
);
4381 if (tzb
->zb_ditto_same_ms
!= 0) {
4382 (void) printf("\tDittoed blocks in same metaslab: %llu\n",
4383 (longlong_t
)tzb
->zb_ditto_same_ms
);
4386 for (uint64_t v
= 0; v
< spa
->spa_root_vdev
->vdev_children
; v
++) {
4387 vdev_t
*vd
= spa
->spa_root_vdev
->vdev_child
[v
];
4388 vdev_indirect_mapping_t
*vim
= vd
->vdev_indirect_mapping
;
4395 zdb_nicenum(vdev_indirect_mapping_num_entries(vim
),
4396 mem
, vdev_indirect_mapping_size(vim
));
4398 (void) printf("\tindirect vdev id %llu has %llu segments "
4400 (longlong_t
)vd
->vdev_id
,
4401 (longlong_t
)vdev_indirect_mapping_num_entries(vim
), mem
);
4404 if (dump_opt
['b'] >= 2) {
4406 (void) printf("\nBlocks\tLSIZE\tPSIZE\tASIZE"
4407 "\t avg\t comp\t%%Total\tType\n");
4409 for (t
= 0; t
<= ZDB_OT_TOTAL
; t
++) {
4410 char csize
[32], lsize
[32], psize
[32], asize
[32];
4411 char avg
[32], gang
[32];
4412 const char *typename
;
4414 /* make sure nicenum has enough space */
4415 CTASSERT(sizeof (csize
) >= NN_NUMBUF_SZ
);
4416 CTASSERT(sizeof (lsize
) >= NN_NUMBUF_SZ
);
4417 CTASSERT(sizeof (psize
) >= NN_NUMBUF_SZ
);
4418 CTASSERT(sizeof (asize
) >= NN_NUMBUF_SZ
);
4419 CTASSERT(sizeof (avg
) >= NN_NUMBUF_SZ
);
4420 CTASSERT(sizeof (gang
) >= NN_NUMBUF_SZ
);
4422 if (t
< DMU_OT_NUMTYPES
)
4423 typename
= dmu_ot
[t
].ot_name
;
4425 typename
= zdb_ot_extname
[t
- DMU_OT_NUMTYPES
];
4427 if (zcb
.zcb_type
[ZB_TOTAL
][t
].zb_asize
== 0) {
4428 (void) printf("%6s\t%5s\t%5s\t%5s"
4429 "\t%5s\t%5s\t%6s\t%s\n",
4441 for (l
= ZB_TOTAL
- 1; l
>= -1; l
--) {
4442 level
= (l
== -1 ? ZB_TOTAL
: l
);
4443 zb
= &zcb
.zcb_type
[level
][t
];
4445 if (zb
->zb_asize
== 0)
4448 if (dump_opt
['b'] < 3 && level
!= ZB_TOTAL
)
4451 if (level
== 0 && zb
->zb_asize
==
4452 zcb
.zcb_type
[ZB_TOTAL
][t
].zb_asize
)
4455 zdb_nicenum(zb
->zb_count
, csize
,
4457 zdb_nicenum(zb
->zb_lsize
, lsize
,
4459 zdb_nicenum(zb
->zb_psize
, psize
,
4461 zdb_nicenum(zb
->zb_asize
, asize
,
4463 zdb_nicenum(zb
->zb_asize
/ zb
->zb_count
, avg
,
4465 zdb_nicenum(zb
->zb_gangs
, gang
, sizeof (gang
));
4467 (void) printf("%6s\t%5s\t%5s\t%5s\t%5s"
4469 csize
, lsize
, psize
, asize
, avg
,
4470 (double)zb
->zb_lsize
/ zb
->zb_psize
,
4471 100.0 * zb
->zb_asize
/ tzb
->zb_asize
);
4473 if (level
== ZB_TOTAL
)
4474 (void) printf("%s\n", typename
);
4476 (void) printf(" L%d %s\n",
4479 if (dump_opt
['b'] >= 3 && zb
->zb_gangs
> 0) {
4480 (void) printf("\t number of ganged "
4481 "blocks: %s\n", gang
);
4484 if (dump_opt
['b'] >= 4) {
4485 (void) printf("psize "
4486 "(in 512-byte sectors): "
4487 "number of blocks\n");
4488 dump_histogram(zb
->zb_psize_histogram
,
4489 PSIZE_HISTO_SIZE
, 0);
4495 (void) printf("\n");
4500 if (zcb
.zcb_haderrors
)
4506 typedef struct zdb_ddt_entry
{
4508 uint64_t zdde_ref_blocks
;
4509 uint64_t zdde_ref_lsize
;
4510 uint64_t zdde_ref_psize
;
4511 uint64_t zdde_ref_dsize
;
4512 avl_node_t zdde_node
;
4517 zdb_ddt_add_cb(spa_t
*spa
, zilog_t
*zilog
, const blkptr_t
*bp
,
4518 const zbookmark_phys_t
*zb
, const dnode_phys_t
*dnp
, void *arg
)
4520 avl_tree_t
*t
= arg
;
4522 zdb_ddt_entry_t
*zdde
, zdde_search
;
4524 if (bp
== NULL
|| BP_IS_HOLE(bp
) || BP_IS_EMBEDDED(bp
))
4527 if (dump_opt
['S'] > 1 && zb
->zb_level
== ZB_ROOT_LEVEL
) {
4528 (void) printf("traversing objset %llu, %llu objects, "
4529 "%lu blocks so far\n",
4530 (u_longlong_t
)zb
->zb_objset
,
4531 (u_longlong_t
)BP_GET_FILL(bp
),
4535 if (BP_IS_HOLE(bp
) || BP_GET_CHECKSUM(bp
) == ZIO_CHECKSUM_OFF
||
4536 BP_GET_LEVEL(bp
) > 0 || DMU_OT_IS_METADATA(BP_GET_TYPE(bp
)))
4539 ddt_key_fill(&zdde_search
.zdde_key
, bp
);
4541 zdde
= avl_find(t
, &zdde_search
, &where
);
4544 zdde
= umem_zalloc(sizeof (*zdde
), UMEM_NOFAIL
);
4545 zdde
->zdde_key
= zdde_search
.zdde_key
;
4546 avl_insert(t
, zdde
, where
);
4549 zdde
->zdde_ref_blocks
+= 1;
4550 zdde
->zdde_ref_lsize
+= BP_GET_LSIZE(bp
);
4551 zdde
->zdde_ref_psize
+= BP_GET_PSIZE(bp
);
4552 zdde
->zdde_ref_dsize
+= bp_get_dsize_sync(spa
, bp
);
4558 dump_simulated_ddt(spa_t
*spa
)
4561 void *cookie
= NULL
;
4562 zdb_ddt_entry_t
*zdde
;
4563 ddt_histogram_t ddh_total
;
4564 ddt_stat_t dds_total
;
4566 bzero(&ddh_total
, sizeof (ddh_total
));
4567 bzero(&dds_total
, sizeof (dds_total
));
4568 avl_create(&t
, ddt_entry_compare
,
4569 sizeof (zdb_ddt_entry_t
), offsetof(zdb_ddt_entry_t
, zdde_node
));
4571 spa_config_enter(spa
, SCL_CONFIG
, FTAG
, RW_READER
);
4573 (void) traverse_pool(spa
, 0, TRAVERSE_PRE
| TRAVERSE_PREFETCH_METADATA
|
4574 TRAVERSE_NO_DECRYPT
, zdb_ddt_add_cb
, &t
);
4576 spa_config_exit(spa
, SCL_CONFIG
, FTAG
);
4578 while ((zdde
= avl_destroy_nodes(&t
, &cookie
)) != NULL
) {
4580 uint64_t refcnt
= zdde
->zdde_ref_blocks
;
4581 ASSERT(refcnt
!= 0);
4583 dds
.dds_blocks
= zdde
->zdde_ref_blocks
/ refcnt
;
4584 dds
.dds_lsize
= zdde
->zdde_ref_lsize
/ refcnt
;
4585 dds
.dds_psize
= zdde
->zdde_ref_psize
/ refcnt
;
4586 dds
.dds_dsize
= zdde
->zdde_ref_dsize
/ refcnt
;
4588 dds
.dds_ref_blocks
= zdde
->zdde_ref_blocks
;
4589 dds
.dds_ref_lsize
= zdde
->zdde_ref_lsize
;
4590 dds
.dds_ref_psize
= zdde
->zdde_ref_psize
;
4591 dds
.dds_ref_dsize
= zdde
->zdde_ref_dsize
;
4593 ddt_stat_add(&ddh_total
.ddh_stat
[highbit64(refcnt
) - 1],
4596 umem_free(zdde
, sizeof (*zdde
));
4601 ddt_histogram_stat(&dds_total
, &ddh_total
);
4603 (void) printf("Simulated DDT histogram:\n");
4605 zpool_dump_ddt(&dds_total
, &ddh_total
);
4607 dump_dedup_ratio(&dds_total
);
4611 verify_device_removal_feature_counts(spa_t
*spa
)
4613 uint64_t dr_feature_refcount
= 0;
4614 uint64_t oc_feature_refcount
= 0;
4615 uint64_t indirect_vdev_count
= 0;
4616 uint64_t precise_vdev_count
= 0;
4617 uint64_t obsolete_counts_object_count
= 0;
4618 uint64_t obsolete_sm_count
= 0;
4619 uint64_t obsolete_counts_count
= 0;
4620 uint64_t scip_count
= 0;
4621 uint64_t obsolete_bpobj_count
= 0;
4624 spa_condensing_indirect_phys_t
*scip
=
4625 &spa
->spa_condensing_indirect_phys
;
4626 if (scip
->scip_next_mapping_object
!= 0) {
4627 vdev_t
*vd
= spa
->spa_root_vdev
->vdev_child
[scip
->scip_vdev
];
4628 ASSERT(scip
->scip_prev_obsolete_sm_object
!= 0);
4629 ASSERT3P(vd
->vdev_ops
, ==, &vdev_indirect_ops
);
4631 (void) printf("Condensing indirect vdev %llu: new mapping "
4632 "object %llu, prev obsolete sm %llu\n",
4633 (u_longlong_t
)scip
->scip_vdev
,
4634 (u_longlong_t
)scip
->scip_next_mapping_object
,
4635 (u_longlong_t
)scip
->scip_prev_obsolete_sm_object
);
4636 if (scip
->scip_prev_obsolete_sm_object
!= 0) {
4637 space_map_t
*prev_obsolete_sm
= NULL
;
4638 VERIFY0(space_map_open(&prev_obsolete_sm
,
4639 spa
->spa_meta_objset
,
4640 scip
->scip_prev_obsolete_sm_object
,
4641 0, vd
->vdev_asize
, 0));
4642 space_map_update(prev_obsolete_sm
);
4643 dump_spacemap(spa
->spa_meta_objset
, prev_obsolete_sm
);
4644 (void) printf("\n");
4645 space_map_close(prev_obsolete_sm
);
4651 for (uint64_t i
= 0; i
< spa
->spa_root_vdev
->vdev_children
; i
++) {
4652 vdev_t
*vd
= spa
->spa_root_vdev
->vdev_child
[i
];
4653 vdev_indirect_config_t
*vic
= &vd
->vdev_indirect_config
;
4655 if (vic
->vic_mapping_object
!= 0) {
4656 ASSERT(vd
->vdev_ops
== &vdev_indirect_ops
||
4658 indirect_vdev_count
++;
4660 if (vd
->vdev_indirect_mapping
->vim_havecounts
) {
4661 obsolete_counts_count
++;
4665 boolean_t are_precise
;
4666 VERIFY0(vdev_obsolete_counts_are_precise(vd
, &are_precise
));
4668 ASSERT(vic
->vic_mapping_object
!= 0);
4669 precise_vdev_count
++;
4672 uint64_t obsolete_sm_object
;
4673 VERIFY0(vdev_obsolete_sm_object(vd
, &obsolete_sm_object
));
4674 if (obsolete_sm_object
!= 0) {
4675 ASSERT(vic
->vic_mapping_object
!= 0);
4676 obsolete_sm_count
++;
4680 (void) feature_get_refcount(spa
,
4681 &spa_feature_table
[SPA_FEATURE_DEVICE_REMOVAL
],
4682 &dr_feature_refcount
);
4683 (void) feature_get_refcount(spa
,
4684 &spa_feature_table
[SPA_FEATURE_OBSOLETE_COUNTS
],
4685 &oc_feature_refcount
);
4687 if (dr_feature_refcount
!= indirect_vdev_count
) {
4689 (void) printf("Number of indirect vdevs (%llu) " \
4690 "does not match feature count (%llu)\n",
4691 (u_longlong_t
)indirect_vdev_count
,
4692 (u_longlong_t
)dr_feature_refcount
);
4694 (void) printf("Verified device_removal feature refcount " \
4695 "of %llu is correct\n",
4696 (u_longlong_t
)dr_feature_refcount
);
4699 if (zap_contains(spa_meta_objset(spa
), DMU_POOL_DIRECTORY_OBJECT
,
4700 DMU_POOL_OBSOLETE_BPOBJ
) == 0) {
4701 obsolete_bpobj_count
++;
4705 obsolete_counts_object_count
= precise_vdev_count
;
4706 obsolete_counts_object_count
+= obsolete_sm_count
;
4707 obsolete_counts_object_count
+= obsolete_counts_count
;
4708 obsolete_counts_object_count
+= scip_count
;
4709 obsolete_counts_object_count
+= obsolete_bpobj_count
;
4710 obsolete_counts_object_count
+= remap_deadlist_count
;
4712 if (oc_feature_refcount
!= obsolete_counts_object_count
) {
4714 (void) printf("Number of obsolete counts objects (%llu) " \
4715 "does not match feature count (%llu)\n",
4716 (u_longlong_t
)obsolete_counts_object_count
,
4717 (u_longlong_t
)oc_feature_refcount
);
4718 (void) printf("pv:%llu os:%llu oc:%llu sc:%llu "
4719 "ob:%llu rd:%llu\n",
4720 (u_longlong_t
)precise_vdev_count
,
4721 (u_longlong_t
)obsolete_sm_count
,
4722 (u_longlong_t
)obsolete_counts_count
,
4723 (u_longlong_t
)scip_count
,
4724 (u_longlong_t
)obsolete_bpobj_count
,
4725 (u_longlong_t
)remap_deadlist_count
);
4727 (void) printf("Verified indirect_refcount feature refcount " \
4728 "of %llu is correct\n",
4729 (u_longlong_t
)oc_feature_refcount
);
4735 zdb_set_skip_mmp(char *target
)
4740 * Disable the activity check to allow examination of
4743 mutex_enter(&spa_namespace_lock
);
4744 if ((spa
= spa_lookup(target
)) != NULL
) {
4745 spa
->spa_import_flags
|= ZFS_IMPORT_SKIP_MMP
;
4747 mutex_exit(&spa_namespace_lock
);
4750 #define BOGUS_SUFFIX "_CHECKPOINTED_UNIVERSE"
4752 * Import the checkpointed state of the pool specified by the target
4753 * parameter as readonly. The function also accepts a pool config
4754 * as an optional parameter, else it attempts to infer the config by
4755 * the name of the target pool.
4757 * Note that the checkpointed state's pool name will be the name of
4758 * the original pool with the above suffix appened to it. In addition,
4759 * if the target is not a pool name (e.g. a path to a dataset) then
4760 * the new_path parameter is populated with the updated path to
4761 * reflect the fact that we are looking into the checkpointed state.
4763 * The function returns a newly-allocated copy of the name of the
4764 * pool containing the checkpointed state. When this copy is no
4765 * longer needed it should be freed with free(3C). Same thing
4766 * applies to the new_path parameter if allocated.
4769 import_checkpointed_state(char *target
, nvlist_t
*cfg
, char **new_path
)
4772 char *poolname
, *bogus_name
= NULL
;
4774 /* If the target is not a pool, the extract the pool name */
4775 char *path_start
= strchr(target
, '/');
4776 if (path_start
!= NULL
) {
4777 size_t poolname_len
= path_start
- target
;
4778 poolname
= strndup(target
, poolname_len
);
4784 zdb_set_skip_mmp(poolname
);
4785 error
= spa_get_stats(poolname
, &cfg
, NULL
, 0);
4787 fatal("Tried to read config of pool \"%s\" but "
4788 "spa_get_stats() failed with error %d\n",
4793 if (asprintf(&bogus_name
, "%s%s", poolname
, BOGUS_SUFFIX
) == -1)
4795 fnvlist_add_string(cfg
, ZPOOL_CONFIG_POOL_NAME
, bogus_name
);
4797 error
= spa_import(bogus_name
, cfg
, NULL
,
4798 ZFS_IMPORT_MISSING_LOG
| ZFS_IMPORT_CHECKPOINT
|
4799 ZFS_IMPORT_SKIP_MMP
);
4801 fatal("Tried to import pool \"%s\" but spa_import() failed "
4802 "with error %d\n", bogus_name
, error
);
4805 if (new_path
!= NULL
&& path_start
!= NULL
) {
4806 if (asprintf(new_path
, "%s%s", bogus_name
, path_start
) == -1) {
4807 if (path_start
!= NULL
)
4813 if (target
!= poolname
)
4816 return (bogus_name
);
4819 typedef struct verify_checkpoint_sm_entry_cb_arg
{
4822 /* the following fields are only used for printing progress */
4823 uint64_t vcsec_entryid
;
4824 uint64_t vcsec_num_entries
;
4825 } verify_checkpoint_sm_entry_cb_arg_t
;
4827 #define ENTRIES_PER_PROGRESS_UPDATE 10000
4830 verify_checkpoint_sm_entry_cb(space_map_entry_t
*sme
, void *arg
)
4832 verify_checkpoint_sm_entry_cb_arg_t
*vcsec
= arg
;
4833 vdev_t
*vd
= vcsec
->vcsec_vd
;
4834 metaslab_t
*ms
= vd
->vdev_ms
[sme
->sme_offset
>> vd
->vdev_ms_shift
];
4835 uint64_t end
= sme
->sme_offset
+ sme
->sme_run
;
4837 ASSERT(sme
->sme_type
== SM_FREE
);
4839 if ((vcsec
->vcsec_entryid
% ENTRIES_PER_PROGRESS_UPDATE
) == 0) {
4840 (void) fprintf(stderr
,
4841 "\rverifying vdev %llu, space map entry %llu of %llu ...",
4842 (longlong_t
)vd
->vdev_id
,
4843 (longlong_t
)vcsec
->vcsec_entryid
,
4844 (longlong_t
)vcsec
->vcsec_num_entries
);
4846 vcsec
->vcsec_entryid
++;
4849 * See comment in checkpoint_sm_exclude_entry_cb()
4851 VERIFY3U(sme
->sme_offset
, >=, ms
->ms_start
);
4852 VERIFY3U(end
, <=, ms
->ms_start
+ ms
->ms_size
);
4855 * The entries in the vdev_checkpoint_sm should be marked as
4856 * allocated in the checkpointed state of the pool, therefore
4857 * their respective ms_allocateable trees should not contain them.
4859 mutex_enter(&ms
->ms_lock
);
4860 range_tree_verify(ms
->ms_allocatable
, sme
->sme_offset
, sme
->sme_run
);
4861 mutex_exit(&ms
->ms_lock
);
4867 * Verify that all segments in the vdev_checkpoint_sm are allocated
4868 * according to the checkpoint's ms_sm (i.e. are not in the checkpoint's
4871 * Do so by comparing the checkpoint space maps (vdev_checkpoint_sm) of
4872 * each vdev in the current state of the pool to the metaslab space maps
4873 * (ms_sm) of the checkpointed state of the pool.
4875 * Note that the function changes the state of the ms_allocatable
4876 * trees of the current spa_t. The entries of these ms_allocatable
4877 * trees are cleared out and then repopulated from with the free
4878 * entries of their respective ms_sm space maps.
4881 verify_checkpoint_vdev_spacemaps(spa_t
*checkpoint
, spa_t
*current
)
4883 vdev_t
*ckpoint_rvd
= checkpoint
->spa_root_vdev
;
4884 vdev_t
*current_rvd
= current
->spa_root_vdev
;
4886 load_concrete_ms_allocatable_trees(checkpoint
, SM_FREE
);
4888 for (uint64_t c
= 0; c
< ckpoint_rvd
->vdev_children
; c
++) {
4889 vdev_t
*ckpoint_vd
= ckpoint_rvd
->vdev_child
[c
];
4890 vdev_t
*current_vd
= current_rvd
->vdev_child
[c
];
4892 space_map_t
*checkpoint_sm
= NULL
;
4893 uint64_t checkpoint_sm_obj
;
4895 if (ckpoint_vd
->vdev_ops
== &vdev_indirect_ops
) {
4897 * Since we don't allow device removal in a pool
4898 * that has a checkpoint, we expect that all removed
4899 * vdevs were removed from the pool before the
4902 ASSERT3P(current_vd
->vdev_ops
, ==, &vdev_indirect_ops
);
4907 * If the checkpoint space map doesn't exist, then nothing
4908 * here is checkpointed so there's nothing to verify.
4910 if (current_vd
->vdev_top_zap
== 0 ||
4911 zap_contains(spa_meta_objset(current
),
4912 current_vd
->vdev_top_zap
,
4913 VDEV_TOP_ZAP_POOL_CHECKPOINT_SM
) != 0)
4916 VERIFY0(zap_lookup(spa_meta_objset(current
),
4917 current_vd
->vdev_top_zap
, VDEV_TOP_ZAP_POOL_CHECKPOINT_SM
,
4918 sizeof (uint64_t), 1, &checkpoint_sm_obj
));
4920 VERIFY0(space_map_open(&checkpoint_sm
, spa_meta_objset(current
),
4921 checkpoint_sm_obj
, 0, current_vd
->vdev_asize
,
4922 current_vd
->vdev_ashift
));
4923 space_map_update(checkpoint_sm
);
4925 verify_checkpoint_sm_entry_cb_arg_t vcsec
;
4926 vcsec
.vcsec_vd
= ckpoint_vd
;
4927 vcsec
.vcsec_entryid
= 0;
4928 vcsec
.vcsec_num_entries
=
4929 space_map_length(checkpoint_sm
) / sizeof (uint64_t);
4930 VERIFY0(space_map_iterate(checkpoint_sm
,
4931 verify_checkpoint_sm_entry_cb
, &vcsec
));
4932 if (dump_opt
['m'] > 3)
4933 dump_spacemap(current
->spa_meta_objset
, checkpoint_sm
);
4934 space_map_close(checkpoint_sm
);
4938 * If we've added vdevs since we took the checkpoint, ensure
4939 * that their checkpoint space maps are empty.
4941 if (ckpoint_rvd
->vdev_children
< current_rvd
->vdev_children
) {
4942 for (uint64_t c
= ckpoint_rvd
->vdev_children
;
4943 c
< current_rvd
->vdev_children
; c
++) {
4944 vdev_t
*current_vd
= current_rvd
->vdev_child
[c
];
4945 ASSERT3P(current_vd
->vdev_checkpoint_sm
, ==, NULL
);
4949 /* for cleaner progress output */
4950 (void) fprintf(stderr
, "\n");
4954 * Verifies that all space that's allocated in the checkpoint is
4955 * still allocated in the current version, by checking that everything
4956 * in checkpoint's ms_allocatable (which is actually allocated, not
4957 * allocatable/free) is not present in current's ms_allocatable.
4959 * Note that the function changes the state of the ms_allocatable
4960 * trees of both spas when called. The entries of all ms_allocatable
4961 * trees are cleared out and then repopulated from their respective
4962 * ms_sm space maps. In the checkpointed state we load the allocated
4963 * entries, and in the current state we load the free entries.
4966 verify_checkpoint_ms_spacemaps(spa_t
*checkpoint
, spa_t
*current
)
4968 vdev_t
*ckpoint_rvd
= checkpoint
->spa_root_vdev
;
4969 vdev_t
*current_rvd
= current
->spa_root_vdev
;
4971 load_concrete_ms_allocatable_trees(checkpoint
, SM_ALLOC
);
4972 load_concrete_ms_allocatable_trees(current
, SM_FREE
);
4974 for (uint64_t i
= 0; i
< ckpoint_rvd
->vdev_children
; i
++) {
4975 vdev_t
*ckpoint_vd
= ckpoint_rvd
->vdev_child
[i
];
4976 vdev_t
*current_vd
= current_rvd
->vdev_child
[i
];
4978 if (ckpoint_vd
->vdev_ops
== &vdev_indirect_ops
) {
4980 * See comment in verify_checkpoint_vdev_spacemaps()
4982 ASSERT3P(current_vd
->vdev_ops
, ==, &vdev_indirect_ops
);
4986 for (uint64_t m
= 0; m
< ckpoint_vd
->vdev_ms_count
; m
++) {
4987 metaslab_t
*ckpoint_msp
= ckpoint_vd
->vdev_ms
[m
];
4988 metaslab_t
*current_msp
= current_vd
->vdev_ms
[m
];
4990 (void) fprintf(stderr
,
4991 "\rverifying vdev %llu of %llu, "
4992 "metaslab %llu of %llu ...",
4993 (longlong_t
)current_vd
->vdev_id
,
4994 (longlong_t
)current_rvd
->vdev_children
,
4995 (longlong_t
)current_vd
->vdev_ms
[m
]->ms_id
,
4996 (longlong_t
)current_vd
->vdev_ms_count
);
4999 * We walk through the ms_allocatable trees that
5000 * are loaded with the allocated blocks from the
5001 * ms_sm spacemaps of the checkpoint. For each
5002 * one of these ranges we ensure that none of them
5003 * exists in the ms_allocatable trees of the
5004 * current state which are loaded with the ranges
5005 * that are currently free.
5007 * This way we ensure that none of the blocks that
5008 * are part of the checkpoint were freed by mistake.
5010 range_tree_walk(ckpoint_msp
->ms_allocatable
,
5011 (range_tree_func_t
*)range_tree_verify
,
5012 current_msp
->ms_allocatable
);
5016 /* for cleaner progress output */
5017 (void) fprintf(stderr
, "\n");
5021 verify_checkpoint_blocks(spa_t
*spa
)
5023 spa_t
*checkpoint_spa
;
5024 char *checkpoint_pool
;
5025 nvlist_t
*config
= NULL
;
5029 * We import the checkpointed state of the pool (under a different
5030 * name) so we can do verification on it against the current state
5033 checkpoint_pool
= import_checkpointed_state(spa
->spa_name
, config
,
5035 ASSERT(strcmp(spa
->spa_name
, checkpoint_pool
) != 0);
5037 error
= spa_open(checkpoint_pool
, &checkpoint_spa
, FTAG
);
5039 fatal("Tried to open pool \"%s\" but spa_open() failed with "
5040 "error %d\n", checkpoint_pool
, error
);
5044 * Ensure that ranges in the checkpoint space maps of each vdev
5045 * are allocated according to the checkpointed state's metaslab
5048 verify_checkpoint_vdev_spacemaps(checkpoint_spa
, spa
);
5051 * Ensure that allocated ranges in the checkpoint's metaslab
5052 * space maps remain allocated in the metaslab space maps of
5053 * the current state.
5055 verify_checkpoint_ms_spacemaps(checkpoint_spa
, spa
);
5058 * Once we are done, we get rid of the checkpointed state.
5060 spa_close(checkpoint_spa
, FTAG
);
5061 free(checkpoint_pool
);
5065 dump_leftover_checkpoint_blocks(spa_t
*spa
)
5067 vdev_t
*rvd
= spa
->spa_root_vdev
;
5069 for (uint64_t i
= 0; i
< rvd
->vdev_children
; i
++) {
5070 vdev_t
*vd
= rvd
->vdev_child
[i
];
5072 space_map_t
*checkpoint_sm
= NULL
;
5073 uint64_t checkpoint_sm_obj
;
5075 if (vd
->vdev_top_zap
== 0)
5078 if (zap_contains(spa_meta_objset(spa
), vd
->vdev_top_zap
,
5079 VDEV_TOP_ZAP_POOL_CHECKPOINT_SM
) != 0)
5082 VERIFY0(zap_lookup(spa_meta_objset(spa
), vd
->vdev_top_zap
,
5083 VDEV_TOP_ZAP_POOL_CHECKPOINT_SM
,
5084 sizeof (uint64_t), 1, &checkpoint_sm_obj
));
5086 VERIFY0(space_map_open(&checkpoint_sm
, spa_meta_objset(spa
),
5087 checkpoint_sm_obj
, 0, vd
->vdev_asize
, vd
->vdev_ashift
));
5088 space_map_update(checkpoint_sm
);
5089 dump_spacemap(spa
->spa_meta_objset
, checkpoint_sm
);
5090 space_map_close(checkpoint_sm
);
5095 verify_checkpoint(spa_t
*spa
)
5097 uberblock_t checkpoint
;
5100 if (!spa_feature_is_active(spa
, SPA_FEATURE_POOL_CHECKPOINT
))
5103 error
= zap_lookup(spa
->spa_meta_objset
, DMU_POOL_DIRECTORY_OBJECT
,
5104 DMU_POOL_ZPOOL_CHECKPOINT
, sizeof (uint64_t),
5105 sizeof (uberblock_t
) / sizeof (uint64_t), &checkpoint
);
5107 if (error
== ENOENT
&& !dump_opt
['L']) {
5109 * If the feature is active but the uberblock is missing
5110 * then we must be in the middle of discarding the
5113 (void) printf("\nPartially discarded checkpoint "
5115 if (dump_opt
['m'] > 3)
5116 dump_leftover_checkpoint_blocks(spa
);
5118 } else if (error
!= 0) {
5119 (void) printf("lookup error %d when looking for "
5120 "checkpointed uberblock in MOS\n", error
);
5123 dump_uberblock(&checkpoint
, "\nCheckpointed uberblock found:\n", "\n");
5125 if (checkpoint
.ub_checkpoint_txg
== 0) {
5126 (void) printf("\nub_checkpoint_txg not set in checkpointed "
5131 if (error
== 0 && !dump_opt
['L'])
5132 verify_checkpoint_blocks(spa
);
5139 mos_leaks_cb(void *arg
, uint64_t start
, uint64_t size
)
5141 for (uint64_t i
= start
; i
< size
; i
++) {
5142 (void) printf("MOS object %llu referenced but not allocated\n",
5148 mos_obj_refd(uint64_t obj
)
5150 if (obj
!= 0 && mos_refd_objs
!= NULL
)
5151 range_tree_add(mos_refd_objs
, obj
, 1);
5155 * Call on a MOS object that may already have been referenced.
5158 mos_obj_refd_multiple(uint64_t obj
)
5160 if (obj
!= 0 && mos_refd_objs
!= NULL
&&
5161 !range_tree_contains(mos_refd_objs
, obj
, 1))
5162 range_tree_add(mos_refd_objs
, obj
, 1);
5166 mos_leak_vdev(vdev_t
*vd
)
5168 mos_obj_refd(vd
->vdev_dtl_object
);
5169 mos_obj_refd(vd
->vdev_ms_array
);
5170 mos_obj_refd(vd
->vdev_top_zap
);
5171 mos_obj_refd(vd
->vdev_indirect_config
.vic_births_object
);
5172 mos_obj_refd(vd
->vdev_indirect_config
.vic_mapping_object
);
5173 mos_obj_refd(vd
->vdev_leaf_zap
);
5174 if (vd
->vdev_checkpoint_sm
!= NULL
)
5175 mos_obj_refd(vd
->vdev_checkpoint_sm
->sm_object
);
5176 if (vd
->vdev_indirect_mapping
!= NULL
) {
5177 mos_obj_refd(vd
->vdev_indirect_mapping
->
5178 vim_phys
->vimp_counts_object
);
5180 if (vd
->vdev_obsolete_sm
!= NULL
)
5181 mos_obj_refd(vd
->vdev_obsolete_sm
->sm_object
);
5183 for (uint64_t m
= 0; m
< vd
->vdev_ms_count
; m
++) {
5184 metaslab_t
*ms
= vd
->vdev_ms
[m
];
5185 mos_obj_refd(space_map_object(ms
->ms_sm
));
5188 for (uint64_t c
= 0; c
< vd
->vdev_children
; c
++) {
5189 mos_leak_vdev(vd
->vdev_child
[c
]);
5194 dump_mos_leaks(spa_t
*spa
)
5197 objset_t
*mos
= spa
->spa_meta_objset
;
5198 dsl_pool_t
*dp
= spa
->spa_dsl_pool
;
5200 /* Visit and mark all referenced objects in the MOS */
5202 mos_obj_refd(DMU_POOL_DIRECTORY_OBJECT
);
5203 mos_obj_refd(spa
->spa_pool_props_object
);
5204 mos_obj_refd(spa
->spa_config_object
);
5205 mos_obj_refd(spa
->spa_ddt_stat_object
);
5206 mos_obj_refd(spa
->spa_feat_desc_obj
);
5207 mos_obj_refd(spa
->spa_feat_enabled_txg_obj
);
5208 mos_obj_refd(spa
->spa_feat_for_read_obj
);
5209 mos_obj_refd(spa
->spa_feat_for_write_obj
);
5210 mos_obj_refd(spa
->spa_history
);
5211 mos_obj_refd(spa
->spa_errlog_last
);
5212 mos_obj_refd(spa
->spa_errlog_scrub
);
5213 mos_obj_refd(spa
->spa_all_vdev_zaps
);
5214 mos_obj_refd(spa
->spa_dsl_pool
->dp_bptree_obj
);
5215 mos_obj_refd(spa
->spa_dsl_pool
->dp_tmp_userrefs_obj
);
5216 mos_obj_refd(spa
->spa_dsl_pool
->dp_scan
->scn_phys
.scn_queue_obj
);
5217 bpobj_count_refd(&spa
->spa_deferred_bpobj
);
5218 mos_obj_refd(dp
->dp_empty_bpobj
);
5219 bpobj_count_refd(&dp
->dp_obsolete_bpobj
);
5220 bpobj_count_refd(&dp
->dp_free_bpobj
);
5221 mos_obj_refd(spa
->spa_l2cache
.sav_object
);
5222 mos_obj_refd(spa
->spa_spares
.sav_object
);
5224 mos_obj_refd(spa
->spa_condensing_indirect_phys
.
5225 scip_next_mapping_object
);
5226 mos_obj_refd(spa
->spa_condensing_indirect_phys
.
5227 scip_prev_obsolete_sm_object
);
5228 if (spa
->spa_condensing_indirect_phys
.scip_next_mapping_object
!= 0) {
5229 vdev_indirect_mapping_t
*vim
=
5230 vdev_indirect_mapping_open(mos
,
5231 spa
->spa_condensing_indirect_phys
.scip_next_mapping_object
);
5232 mos_obj_refd(vim
->vim_phys
->vimp_counts_object
);
5233 vdev_indirect_mapping_close(vim
);
5236 if (dp
->dp_origin_snap
!= NULL
) {
5239 dsl_pool_config_enter(dp
, FTAG
);
5240 VERIFY0(dsl_dataset_hold_obj(dp
,
5241 dsl_dataset_phys(dp
->dp_origin_snap
)->ds_next_snap_obj
,
5243 count_ds_mos_objects(ds
);
5244 dump_deadlist(&ds
->ds_deadlist
);
5245 dsl_dataset_rele(ds
, FTAG
);
5246 dsl_pool_config_exit(dp
, FTAG
);
5248 count_ds_mos_objects(dp
->dp_origin_snap
);
5249 dump_deadlist(&dp
->dp_origin_snap
->ds_deadlist
);
5251 count_dir_mos_objects(dp
->dp_mos_dir
);
5252 if (dp
->dp_free_dir
!= NULL
)
5253 count_dir_mos_objects(dp
->dp_free_dir
);
5254 if (dp
->dp_leak_dir
!= NULL
)
5255 count_dir_mos_objects(dp
->dp_leak_dir
);
5257 mos_leak_vdev(spa
->spa_root_vdev
);
5259 for (uint64_t class = 0; class < DDT_CLASSES
; class++) {
5260 for (uint64_t type
= 0; type
< DDT_TYPES
; type
++) {
5261 for (uint64_t cksum
= 0;
5262 cksum
< ZIO_CHECKSUM_FUNCTIONS
; cksum
++) {
5263 ddt_t
*ddt
= spa
->spa_ddt
[cksum
];
5264 mos_obj_refd(ddt
->ddt_object
[type
][class]);
5270 * Visit all allocated objects and make sure they are referenced.
5272 uint64_t object
= 0;
5273 while (dmu_object_next(mos
, &object
, B_FALSE
, 0) == 0) {
5274 if (range_tree_contains(mos_refd_objs
, object
, 1)) {
5275 range_tree_remove(mos_refd_objs
, object
, 1);
5277 dmu_object_info_t doi
;
5279 dmu_object_info(mos
, object
, &doi
);
5280 if (doi
.doi_type
& DMU_OT_NEWTYPE
) {
5281 dmu_object_byteswap_t bswap
=
5282 DMU_OT_BYTESWAP(doi
.doi_type
);
5283 name
= dmu_ot_byteswap
[bswap
].ob_name
;
5285 name
= dmu_ot
[doi
.doi_type
].ot_name
;
5288 (void) printf("MOS object %llu (%s) leaked\n",
5289 (u_longlong_t
)object
, name
);
5293 (void) range_tree_walk(mos_refd_objs
, mos_leaks_cb
, NULL
);
5294 if (!range_tree_is_empty(mos_refd_objs
))
5296 range_tree_vacate(mos_refd_objs
, NULL
, NULL
);
5297 range_tree_destroy(mos_refd_objs
);
5302 dump_zpool(spa_t
*spa
)
5304 dsl_pool_t
*dp
= spa_get_dsl(spa
);
5307 if (dump_opt
['S']) {
5308 dump_simulated_ddt(spa
);
5312 if (!dump_opt
['e'] && dump_opt
['C'] > 1) {
5313 (void) printf("\nCached configuration:\n");
5314 dump_nvlist(spa
->spa_config
, 8);
5321 dump_uberblock(&spa
->spa_uberblock
, "\nUberblock:\n", "\n");
5326 if (dump_opt
['d'] > 2 || dump_opt
['m'])
5327 dump_metaslabs(spa
);
5329 dump_metaslab_groups(spa
);
5331 if (dump_opt
['d'] || dump_opt
['i']) {
5333 mos_refd_objs
= range_tree_create(NULL
, NULL
);
5334 dump_dir(dp
->dp_meta_objset
);
5336 if (dump_opt
['d'] >= 3) {
5337 dsl_pool_t
*dp
= spa
->spa_dsl_pool
;
5338 dump_full_bpobj(&spa
->spa_deferred_bpobj
,
5339 "Deferred frees", 0);
5340 if (spa_version(spa
) >= SPA_VERSION_DEADLISTS
) {
5341 dump_full_bpobj(&dp
->dp_free_bpobj
,
5342 "Pool snapshot frees", 0);
5344 if (bpobj_is_open(&dp
->dp_obsolete_bpobj
)) {
5345 ASSERT(spa_feature_is_enabled(spa
,
5346 SPA_FEATURE_DEVICE_REMOVAL
));
5347 dump_full_bpobj(&dp
->dp_obsolete_bpobj
,
5348 "Pool obsolete blocks", 0);
5351 if (spa_feature_is_active(spa
,
5352 SPA_FEATURE_ASYNC_DESTROY
)) {
5353 dump_bptree(spa
->spa_meta_objset
,
5355 "Pool dataset frees");
5357 dump_dtl(spa
->spa_root_vdev
, 0);
5359 (void) dmu_objset_find(spa_name(spa
), dump_one_dir
,
5360 NULL
, DS_FIND_SNAPSHOTS
| DS_FIND_CHILDREN
);
5362 if (rc
== 0 && !dump_opt
['L'])
5363 rc
= dump_mos_leaks(spa
);
5365 for (f
= 0; f
< SPA_FEATURES
; f
++) {
5368 if (!(spa_feature_table
[f
].fi_flags
&
5369 ZFEATURE_FLAG_PER_DATASET
) ||
5370 !spa_feature_is_enabled(spa
, f
)) {
5371 ASSERT0(dataset_feature_count
[f
]);
5374 if (feature_get_refcount(spa
, &spa_feature_table
[f
],
5375 &refcount
) == ENOTSUP
)
5377 if (dataset_feature_count
[f
] != refcount
) {
5378 (void) printf("%s feature refcount mismatch: "
5379 "%lld datasets != %lld refcount\n",
5380 spa_feature_table
[f
].fi_uname
,
5381 (longlong_t
)dataset_feature_count
[f
],
5382 (longlong_t
)refcount
);
5385 (void) printf("Verified %s feature refcount "
5386 "of %llu is correct\n",
5387 spa_feature_table
[f
].fi_uname
,
5388 (longlong_t
)refcount
);
5393 rc
= verify_device_removal_feature_counts(spa
);
5397 if (rc
== 0 && (dump_opt
['b'] || dump_opt
['c']))
5398 rc
= dump_block_stats(spa
);
5401 rc
= verify_spacemap_refcounts(spa
);
5404 show_pool_stats(spa
);
5410 rc
= verify_checkpoint(spa
);
5413 dump_debug_buffer();
5418 #define ZDB_FLAG_CHECKSUM 0x0001
5419 #define ZDB_FLAG_DECOMPRESS 0x0002
5420 #define ZDB_FLAG_BSWAP 0x0004
5421 #define ZDB_FLAG_GBH 0x0008
5422 #define ZDB_FLAG_INDIRECT 0x0010
5423 #define ZDB_FLAG_PHYS 0x0020
5424 #define ZDB_FLAG_RAW 0x0040
5425 #define ZDB_FLAG_PRINT_BLKPTR 0x0080
5427 static int flagbits
[256];
5430 zdb_print_blkptr(blkptr_t
*bp
, int flags
)
5432 char blkbuf
[BP_SPRINTF_LEN
];
5434 if (flags
& ZDB_FLAG_BSWAP
)
5435 byteswap_uint64_array((void *)bp
, sizeof (blkptr_t
));
5437 snprintf_blkptr(blkbuf
, sizeof (blkbuf
), bp
);
5438 (void) printf("%s\n", blkbuf
);
5442 zdb_dump_indirect(blkptr_t
*bp
, int nbps
, int flags
)
5446 for (i
= 0; i
< nbps
; i
++)
5447 zdb_print_blkptr(&bp
[i
], flags
);
5451 zdb_dump_gbh(void *buf
, int flags
)
5453 zdb_dump_indirect((blkptr_t
*)buf
, SPA_GBH_NBLKPTRS
, flags
);
5457 zdb_dump_block_raw(void *buf
, uint64_t size
, int flags
)
5459 if (flags
& ZDB_FLAG_BSWAP
)
5460 byteswap_uint64_array(buf
, size
);
5461 VERIFY(write(fileno(stdout
), buf
, size
) == size
);
5465 zdb_dump_block(char *label
, void *buf
, uint64_t size
, int flags
)
5467 uint64_t *d
= (uint64_t *)buf
;
5468 unsigned nwords
= size
/ sizeof (uint64_t);
5469 int do_bswap
= !!(flags
& ZDB_FLAG_BSWAP
);
5476 hdr
= " 7 6 5 4 3 2 1 0 f e d c b a 9 8";
5478 hdr
= " 0 1 2 3 4 5 6 7 8 9 a b c d e f";
5480 (void) printf("\n%s\n%6s %s 0123456789abcdef\n", label
, "", hdr
);
5482 #ifdef _LITTLE_ENDIAN
5483 /* correct the endianness */
5484 do_bswap
= !do_bswap
;
5486 for (i
= 0; i
< nwords
; i
+= 2) {
5487 (void) printf("%06llx: %016llx %016llx ",
5488 (u_longlong_t
)(i
* sizeof (uint64_t)),
5489 (u_longlong_t
)(do_bswap
? BSWAP_64(d
[i
]) : d
[i
]),
5490 (u_longlong_t
)(do_bswap
? BSWAP_64(d
[i
+ 1]) : d
[i
+ 1]));
5493 for (j
= 0; j
< 2 * sizeof (uint64_t); j
++)
5494 (void) printf("%c", isprint(c
[j
]) ? c
[j
] : '.');
5495 (void) printf("\n");
5500 * There are two acceptable formats:
5501 * leaf_name - For example: c1t0d0 or /tmp/ztest.0a
5502 * child[.child]* - For example: 0.1.1
5504 * The second form can be used to specify arbitrary vdevs anywhere
5505 * in the hierarchy. For example, in a pool with a mirror of
5506 * RAID-Zs, you can specify either RAID-Z vdev with 0.0 or 0.1 .
5509 zdb_vdev_lookup(vdev_t
*vdev
, const char *path
)
5517 /* First, assume the x.x.x.x format */
5518 i
= strtoul(path
, &s
, 10);
5519 if (s
== path
|| (s
&& *s
!= '.' && *s
!= '\0'))
5521 if (i
>= vdev
->vdev_children
)
5524 vdev
= vdev
->vdev_child
[i
];
5525 if (s
&& *s
== '\0')
5527 return (zdb_vdev_lookup(vdev
, s
+1));
5530 for (i
= 0; i
< vdev
->vdev_children
; i
++) {
5531 vdev_t
*vc
= vdev
->vdev_child
[i
];
5533 if (vc
->vdev_path
== NULL
) {
5534 vc
= zdb_vdev_lookup(vc
, path
);
5541 p
= strrchr(vc
->vdev_path
, '/');
5542 p
= p
? p
+ 1 : vc
->vdev_path
;
5543 q
= &vc
->vdev_path
[strlen(vc
->vdev_path
) - 2];
5545 if (strcmp(vc
->vdev_path
, path
) == 0)
5547 if (strcmp(p
, path
) == 0)
5549 if (strcmp(q
, "s0") == 0 && strncmp(p
, path
, q
- p
) == 0)
5557 * Read a block from a pool and print it out. The syntax of the
5558 * block descriptor is:
5560 * pool:vdev_specifier:offset:size[:flags]
5562 * pool - The name of the pool you wish to read from
5563 * vdev_specifier - Which vdev (see comment for zdb_vdev_lookup)
5564 * offset - offset, in hex, in bytes
5565 * size - Amount of data to read, in hex, in bytes
5566 * flags - A string of characters specifying options
5567 * b: Decode a blkptr at given offset within block
5568 * *c: Calculate and display checksums
5569 * d: Decompress data before dumping
5570 * e: Byteswap data before dumping
5571 * g: Display data as a gang block header
5572 * i: Display as an indirect block
5573 * p: Do I/O to physical offset
5574 * r: Dump raw data to stdout
5576 * * = not yet implemented
5579 zdb_read_block(char *thing
, spa_t
*spa
)
5581 blkptr_t blk
, *bp
= &blk
;
5582 dva_t
*dva
= bp
->blk_dva
;
5584 uint64_t offset
= 0, size
= 0, psize
= 0, lsize
= 0, blkptr_offset
= 0;
5589 const char *s
, *vdev
;
5590 char *p
, *dup
, *flagstr
;
5592 boolean_t borrowed
= B_FALSE
;
5594 dup
= strdup(thing
);
5595 s
= strtok(dup
, ":");
5597 s
= strtok(NULL
, ":");
5598 offset
= strtoull(s
? s
: "", NULL
, 16);
5599 s
= strtok(NULL
, ":");
5600 size
= strtoull(s
? s
: "", NULL
, 16);
5601 s
= strtok(NULL
, ":");
5603 flagstr
= strdup(s
);
5605 flagstr
= strdup("");
5609 s
= "size must not be zero";
5610 if (!IS_P2ALIGNED(size
, DEV_BSIZE
))
5611 s
= "size must be a multiple of sector size";
5612 if (!IS_P2ALIGNED(offset
, DEV_BSIZE
))
5613 s
= "offset must be a multiple of sector size";
5615 (void) printf("Invalid block specifier: %s - %s\n", thing
, s
);
5621 for (s
= strtok(flagstr
, ":"); s
; s
= strtok(NULL
, ":")) {
5622 for (i
= 0; flagstr
[i
]; i
++) {
5623 int bit
= flagbits
[(uchar_t
)flagstr
[i
]];
5626 (void) printf("***Invalid flag: %c\n",
5632 /* If it's not something with an argument, keep going */
5633 if ((bit
& (ZDB_FLAG_CHECKSUM
|
5634 ZDB_FLAG_PRINT_BLKPTR
)) == 0)
5637 p
= &flagstr
[i
+ 1];
5638 if (bit
== ZDB_FLAG_PRINT_BLKPTR
) {
5639 blkptr_offset
= strtoull(p
, &p
, 16);
5640 i
= p
- &flagstr
[i
+ 1];
5642 if (*p
!= ':' && *p
!= '\0') {
5643 (void) printf("***Invalid flag arg: '%s'\n", s
);
5652 vd
= zdb_vdev_lookup(spa
->spa_root_vdev
, vdev
);
5654 (void) printf("***Invalid vdev: %s\n", vdev
);
5659 (void) fprintf(stderr
, "Found vdev: %s\n",
5662 (void) fprintf(stderr
, "Found vdev type: %s\n",
5663 vd
->vdev_ops
->vdev_op_type
);
5669 pabd
= abd_alloc_for_io(SPA_MAXBLOCKSIZE
, B_FALSE
);
5670 lbuf
= umem_alloc(SPA_MAXBLOCKSIZE
, UMEM_NOFAIL
);
5674 DVA_SET_VDEV(&dva
[0], vd
->vdev_id
);
5675 DVA_SET_OFFSET(&dva
[0], offset
);
5676 DVA_SET_GANG(&dva
[0], !!(flags
& ZDB_FLAG_GBH
));
5677 DVA_SET_ASIZE(&dva
[0], vdev_psize_to_asize(vd
, psize
));
5679 BP_SET_BIRTH(bp
, TXG_INITIAL
, TXG_INITIAL
);
5681 BP_SET_LSIZE(bp
, lsize
);
5682 BP_SET_PSIZE(bp
, psize
);
5683 BP_SET_COMPRESS(bp
, ZIO_COMPRESS_OFF
);
5684 BP_SET_CHECKSUM(bp
, ZIO_CHECKSUM_OFF
);
5685 BP_SET_TYPE(bp
, DMU_OT_NONE
);
5686 BP_SET_LEVEL(bp
, 0);
5687 BP_SET_DEDUP(bp
, 0);
5688 BP_SET_BYTEORDER(bp
, ZFS_HOST_BYTEORDER
);
5690 spa_config_enter(spa
, SCL_STATE
, FTAG
, RW_READER
);
5691 zio
= zio_root(spa
, NULL
, NULL
, 0);
5693 if (vd
== vd
->vdev_top
) {
5695 * Treat this as a normal block read.
5697 zio_nowait(zio_read(zio
, spa
, bp
, pabd
, psize
, NULL
, NULL
,
5698 ZIO_PRIORITY_SYNC_READ
,
5699 ZIO_FLAG_CANFAIL
| ZIO_FLAG_RAW
, NULL
));
5702 * Treat this as a vdev child I/O.
5704 zio_nowait(zio_vdev_child_io(zio
, bp
, vd
, offset
, pabd
,
5705 psize
, ZIO_TYPE_READ
, ZIO_PRIORITY_SYNC_READ
,
5706 ZIO_FLAG_DONT_CACHE
| ZIO_FLAG_DONT_QUEUE
|
5707 ZIO_FLAG_DONT_PROPAGATE
| ZIO_FLAG_DONT_RETRY
|
5708 ZIO_FLAG_CANFAIL
| ZIO_FLAG_RAW
| ZIO_FLAG_OPTIONAL
,
5712 error
= zio_wait(zio
);
5713 spa_config_exit(spa
, SCL_STATE
, FTAG
);
5716 (void) printf("Read of %s failed, error: %d\n", thing
, error
);
5720 if (flags
& ZDB_FLAG_DECOMPRESS
) {
5722 * We don't know how the data was compressed, so just try
5723 * every decompress function at every inflated blocksize.
5725 enum zio_compress c
;
5726 void *lbuf2
= umem_alloc(SPA_MAXBLOCKSIZE
, UMEM_NOFAIL
);
5729 * XXX - On the one hand, with SPA_MAXBLOCKSIZE at 16MB,
5730 * this could take a while and we should let the user know
5731 * we are not stuck. On the other hand, printing progress
5732 * info gets old after a while. What to do?
5734 for (lsize
= psize
+ SPA_MINBLOCKSIZE
;
5735 lsize
<= SPA_MAXBLOCKSIZE
; lsize
+= SPA_MINBLOCKSIZE
) {
5736 for (c
= 0; c
< ZIO_COMPRESS_FUNCTIONS
; c
++) {
5738 * ZLE can easily decompress non zle stream.
5739 * So have an option to disable it.
5741 if (c
== ZIO_COMPRESS_ZLE
&&
5742 getenv("ZDB_NO_ZLE"))
5745 (void) fprintf(stderr
,
5746 "Trying %05llx -> %05llx (%s)\n",
5747 (u_longlong_t
)psize
, (u_longlong_t
)lsize
,
5748 zio_compress_table
[c
].ci_name
);
5751 * We randomize lbuf2, and decompress to both
5752 * lbuf and lbuf2. This way, we will know if
5753 * decompression fill exactly to lsize.
5755 VERIFY0(random_get_pseudo_bytes(lbuf2
, lsize
));
5757 if (zio_decompress_data(c
, pabd
,
5758 lbuf
, psize
, lsize
) == 0 &&
5759 zio_decompress_data(c
, pabd
,
5760 lbuf2
, psize
, lsize
) == 0 &&
5761 bcmp(lbuf
, lbuf2
, lsize
) == 0)
5764 if (c
!= ZIO_COMPRESS_FUNCTIONS
)
5767 umem_free(lbuf2
, SPA_MAXBLOCKSIZE
);
5769 if (lsize
> SPA_MAXBLOCKSIZE
) {
5770 (void) printf("Decompress of %s failed\n", thing
);
5777 buf
= abd_borrow_buf_copy(pabd
, size
);
5781 if (flags
& ZDB_FLAG_PRINT_BLKPTR
)
5782 zdb_print_blkptr((blkptr_t
*)(void *)
5783 ((uintptr_t)buf
+ (uintptr_t)blkptr_offset
), flags
);
5784 else if (flags
& ZDB_FLAG_RAW
)
5785 zdb_dump_block_raw(buf
, size
, flags
);
5786 else if (flags
& ZDB_FLAG_INDIRECT
)
5787 zdb_dump_indirect((blkptr_t
*)buf
, size
/ sizeof (blkptr_t
),
5789 else if (flags
& ZDB_FLAG_GBH
)
5790 zdb_dump_gbh(buf
, flags
);
5792 zdb_dump_block(thing
, buf
, size
, flags
);
5795 abd_return_buf_copy(pabd
, buf
, size
);
5799 umem_free(lbuf
, SPA_MAXBLOCKSIZE
);
5804 zdb_embedded_block(char *thing
)
5807 unsigned long long *words
= (void *)&bp
;
5811 bzero(&bp
, sizeof (bp
));
5812 err
= sscanf(thing
, "%llx:%llx:%llx:%llx:%llx:%llx:%llx:%llx:"
5813 "%llx:%llx:%llx:%llx:%llx:%llx:%llx:%llx",
5814 words
+ 0, words
+ 1, words
+ 2, words
+ 3,
5815 words
+ 4, words
+ 5, words
+ 6, words
+ 7,
5816 words
+ 8, words
+ 9, words
+ 10, words
+ 11,
5817 words
+ 12, words
+ 13, words
+ 14, words
+ 15);
5819 (void) fprintf(stderr
, "invalid input format\n");
5822 ASSERT3U(BPE_GET_LSIZE(&bp
), <=, SPA_MAXBLOCKSIZE
);
5823 buf
= malloc(SPA_MAXBLOCKSIZE
);
5825 (void) fprintf(stderr
, "out of memory\n");
5828 err
= decode_embedded_bp(&bp
, buf
, BPE_GET_LSIZE(&bp
));
5830 (void) fprintf(stderr
, "decode failed: %u\n", err
);
5833 zdb_dump_block_raw(buf
, BPE_GET_LSIZE(&bp
), 0);
5838 main(int argc
, char **argv
)
5841 struct rlimit rl
= { 1024, 1024 };
5843 objset_t
*os
= NULL
;
5847 char **searchdirs
= NULL
;
5849 char *target
, *target_pool
;
5850 nvlist_t
*policy
= NULL
;
5851 uint64_t max_txg
= UINT64_MAX
;
5852 int flags
= ZFS_IMPORT_MISSING_LOG
;
5853 int rewind
= ZPOOL_NEVER_REWIND
;
5854 char *spa_config_path_env
;
5855 boolean_t target_is_spa
= B_TRUE
;
5856 nvlist_t
*cfg
= NULL
;
5858 (void) setrlimit(RLIMIT_NOFILE
, &rl
);
5859 (void) enable_extended_FILE_stdio(-1, -1);
5861 dprintf_setup(&argc
, argv
);
5864 * If there is an environment variable SPA_CONFIG_PATH it overrides
5865 * default spa_config_path setting. If -U flag is specified it will
5866 * override this environment variable settings once again.
5868 spa_config_path_env
= getenv("SPA_CONFIG_PATH");
5869 if (spa_config_path_env
!= NULL
)
5870 spa_config_path
= spa_config_path_env
;
5872 while ((c
= getopt(argc
, argv
,
5873 "AbcCdDeEFGhiI:klLmMo:Op:PqRsSt:uU:vVx:X")) != -1) {
5905 /* NB: Sort single match options below. */
5907 max_inflight
= strtoull(optarg
, NULL
, 0);
5908 if (max_inflight
== 0) {
5909 (void) fprintf(stderr
, "maximum number "
5910 "of inflight I/Os must be greater "
5916 error
= set_global_var(optarg
);
5921 if (searchdirs
== NULL
) {
5922 searchdirs
= umem_alloc(sizeof (char *),
5925 char **tmp
= umem_alloc((nsearch
+ 1) *
5926 sizeof (char *), UMEM_NOFAIL
);
5927 bcopy(searchdirs
, tmp
, nsearch
*
5929 umem_free(searchdirs
,
5930 nsearch
* sizeof (char *));
5933 searchdirs
[nsearch
++] = optarg
;
5936 max_txg
= strtoull(optarg
, NULL
, 0);
5937 if (max_txg
< TXG_INITIAL
) {
5938 (void) fprintf(stderr
, "incorrect txg "
5939 "specified: %s\n", optarg
);
5944 spa_config_path
= optarg
;
5945 if (spa_config_path
[0] != '/') {
5946 (void) fprintf(stderr
,
5947 "cachefile must be an absolute path "
5948 "(i.e. start with a slash)\n");
5956 flags
= ZFS_IMPORT_VERBATIM
;
5959 vn_dumpdir
= optarg
;
5967 if (!dump_opt
['e'] && searchdirs
!= NULL
) {
5968 (void) fprintf(stderr
, "-p option requires use of -e\n");
5974 * ZDB does not typically re-read blocks; therefore limit the ARC
5975 * to 256 MB, which can be used entirely for metadata.
5977 zfs_arc_max
= zfs_arc_meta_limit
= 256 * 1024 * 1024;
5981 * "zdb -c" uses checksum-verifying scrub i/os which are async reads.
5982 * "zdb -b" uses traversal prefetch which uses async reads.
5983 * For good performance, let several of them be active at once.
5985 zfs_vdev_async_read_max_active
= 10;
5988 * Disable reference tracking for better performance.
5990 reference_tracking_enable
= B_FALSE
;
5993 * Do not fail spa_load when spa_load_verify fails. This is needed
5994 * to load non-idle pools.
5996 spa_load_verify_dryrun
= B_TRUE
;
5999 if ((g_zfs
= libzfs_init()) == NULL
) {
6000 (void) fprintf(stderr
, "%s", libzfs_error_init(errno
));
6005 verbose
= MAX(verbose
, 1);
6007 for (c
= 0; c
< 256; c
++) {
6008 if (dump_all
&& strchr("AeEFklLOPRSX", c
) == NULL
)
6011 dump_opt
[c
] += verbose
;
6014 aok
= (dump_opt
['A'] == 1) || (dump_opt
['A'] > 2);
6015 zfs_recover
= (dump_opt
['A'] > 1);
6020 if (argc
< 2 && dump_opt
['R'])
6023 if (dump_opt
['E']) {
6026 zdb_embedded_block(argv
[0]);
6031 if (!dump_opt
['e'] && dump_opt
['C']) {
6032 dump_cachefile(spa_config_path
);
6039 return (dump_label(argv
[0]));
6041 if (dump_opt
['O']) {
6044 dump_opt
['v'] = verbose
+ 3;
6045 return (dump_path(argv
[0], argv
[1]));
6048 if (dump_opt
['X'] || dump_opt
['F'])
6049 rewind
= ZPOOL_DO_REWIND
|
6050 (dump_opt
['X'] ? ZPOOL_EXTREME_REWIND
: 0);
6052 if (nvlist_alloc(&policy
, NV_UNIQUE_NAME_TYPE
, 0) != 0 ||
6053 nvlist_add_uint64(policy
, ZPOOL_LOAD_REQUEST_TXG
, max_txg
) != 0 ||
6054 nvlist_add_uint32(policy
, ZPOOL_LOAD_REWIND_POLICY
, rewind
) != 0)
6055 fatal("internal error: %s", strerror(ENOMEM
));
6060 char *checkpoint_pool
= NULL
;
6061 char *checkpoint_target
= NULL
;
6062 if (dump_opt
['k']) {
6063 checkpoint_pool
= import_checkpointed_state(target
, cfg
,
6064 &checkpoint_target
);
6066 if (checkpoint_target
!= NULL
)
6067 target
= checkpoint_target
;
6071 if (strpbrk(target
, "/@") != NULL
) {
6074 target_pool
= strdup(target
);
6075 *strpbrk(target_pool
, "/@") = '\0';
6077 target_is_spa
= B_FALSE
;
6078 targetlen
= strlen(target
);
6079 if (targetlen
&& target
[targetlen
- 1] == '/')
6080 target
[targetlen
- 1] = '\0';
6082 target_pool
= target
;
6085 if (dump_opt
['e']) {
6086 importargs_t args
= { 0 };
6088 args
.paths
= nsearch
;
6089 args
.path
= searchdirs
;
6090 args
.can_be_active
= B_TRUE
;
6092 error
= zpool_tryimport(g_zfs
, target_pool
, &cfg
, &args
);
6096 if (nvlist_add_nvlist(cfg
,
6097 ZPOOL_LOAD_POLICY
, policy
) != 0) {
6098 fatal("can't open '%s': %s",
6099 target
, strerror(ENOMEM
));
6102 if (dump_opt
['C'] > 1) {
6103 (void) printf("\nConfiguration for import:\n");
6104 dump_nvlist(cfg
, 8);
6108 * Disable the activity check to allow examination of
6111 error
= spa_import(target_pool
, cfg
, NULL
,
6112 flags
| ZFS_IMPORT_SKIP_MMP
);
6116 if (target_pool
!= target
)
6120 if (dump_opt
['k'] && (target_is_spa
|| dump_opt
['R'])) {
6121 ASSERT(checkpoint_pool
!= NULL
);
6122 ASSERT(checkpoint_target
== NULL
);
6124 error
= spa_open(checkpoint_pool
, &spa
, FTAG
);
6126 fatal("Tried to open pool \"%s\" but "
6127 "spa_open() failed with error %d\n",
6128 checkpoint_pool
, error
);
6131 } else if (target_is_spa
|| dump_opt
['R']) {
6132 zdb_set_skip_mmp(target
);
6133 error
= spa_open_rewind(target
, &spa
, FTAG
, policy
,
6137 * If we're missing the log device then
6138 * try opening the pool after clearing the
6141 mutex_enter(&spa_namespace_lock
);
6142 if ((spa
= spa_lookup(target
)) != NULL
&&
6143 spa
->spa_log_state
== SPA_LOG_MISSING
) {
6144 spa
->spa_log_state
= SPA_LOG_CLEAR
;
6147 mutex_exit(&spa_namespace_lock
);
6150 error
= spa_open_rewind(target
, &spa
,
6151 FTAG
, policy
, NULL
);
6155 zdb_set_skip_mmp(target
);
6156 error
= open_objset(target
, DMU_OST_ANY
, FTAG
, &os
);
6158 spa
= dmu_objset_spa(os
);
6161 nvlist_free(policy
);
6164 fatal("can't open '%s': %s", target
, strerror(error
));
6167 * Set the pool failure mode to panic in order to prevent the pool
6168 * from suspending. A suspended I/O will have no way to resume and
6169 * can prevent the zdb(8) command from terminating as expected.
6172 spa
->spa_failmode
= ZIO_FAILURE_MODE_PANIC
;
6176 if (!dump_opt
['R']) {
6178 zopt_objects
= argc
;
6179 zopt_object
= calloc(zopt_objects
, sizeof (uint64_t));
6180 for (unsigned i
= 0; i
< zopt_objects
; i
++) {
6182 zopt_object
[i
] = strtoull(argv
[i
], NULL
, 0);
6183 if (zopt_object
[i
] == 0 && errno
!= 0)
6184 fatal("bad number %s: %s",
6185 argv
[i
], strerror(errno
));
6190 } else if (zopt_objects
> 0 && !dump_opt
['m']) {
6191 dump_dir(spa
->spa_meta_objset
);
6196 flagbits
['b'] = ZDB_FLAG_PRINT_BLKPTR
;
6197 flagbits
['c'] = ZDB_FLAG_CHECKSUM
;
6198 flagbits
['d'] = ZDB_FLAG_DECOMPRESS
;
6199 flagbits
['e'] = ZDB_FLAG_BSWAP
;
6200 flagbits
['g'] = ZDB_FLAG_GBH
;
6201 flagbits
['i'] = ZDB_FLAG_INDIRECT
;
6202 flagbits
['p'] = ZDB_FLAG_PHYS
;
6203 flagbits
['r'] = ZDB_FLAG_RAW
;
6205 for (int i
= 0; i
< argc
; i
++)
6206 zdb_read_block(argv
[i
], spa
);
6209 if (dump_opt
['k']) {
6210 free(checkpoint_pool
);
6212 free(checkpoint_target
);
6216 close_objset(os
, FTAG
);
6218 spa_close(spa
, FTAG
);
6220 fuid_table_destroy();
6222 dump_debug_buffer();