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, 2019 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.
29 * Copyright (c) 2020 Datto Inc.
30 * Copyright (c) 2020, The FreeBSD Foundation [1]
32 * [1] Portions of this software were developed by Allan Jude
33 * under sponsorship from the FreeBSD Foundation.
34 * Copyright (c) 2021 Allan Jude
35 * Copyright (c) 2021 Toomas Soome <tsoome@me.com>
43 #include <sys/zfs_context.h>
45 #include <sys/spa_impl.h>
48 #include <sys/fs/zfs.h>
49 #include <sys/zfs_znode.h>
50 #include <sys/zfs_sa.h>
52 #include <sys/sa_impl.h>
54 #include <sys/vdev_impl.h>
55 #include <sys/metaslab_impl.h>
56 #include <sys/dmu_objset.h>
57 #include <sys/dsl_dir.h>
58 #include <sys/dsl_dataset.h>
59 #include <sys/dsl_pool.h>
60 #include <sys/dsl_bookmark.h>
63 #include <sys/zil_impl.h>
65 #include <sys/resource.h>
66 #include <sys/dmu_send.h>
67 #include <sys/dmu_traverse.h>
68 #include <sys/zio_checksum.h>
69 #include <sys/zio_compress.h>
70 #include <sys/zfs_fuid.h>
72 #include <sys/arc_impl.h>
74 #include <sys/zfeature.h>
76 #include <sys/blkptr.h>
77 #include <sys/dsl_crypt.h>
78 #include <sys/dsl_scan.h>
79 #include <sys/btree.h>
80 #include <zfs_comutil.h>
81 #include <sys/zstd/zstd.h>
83 #include <libnvpair.h>
88 #define ZDB_COMPRESS_NAME(idx) ((idx) < ZIO_COMPRESS_FUNCTIONS ? \
89 zio_compress_table[(idx)].ci_name : "UNKNOWN")
90 #define ZDB_CHECKSUM_NAME(idx) ((idx) < ZIO_CHECKSUM_FUNCTIONS ? \
91 zio_checksum_table[(idx)].ci_name : "UNKNOWN")
92 #define ZDB_OT_TYPE(idx) ((idx) < DMU_OT_NUMTYPES ? (idx) : \
93 (idx) == DMU_OTN_ZAP_DATA || (idx) == DMU_OTN_ZAP_METADATA ? \
95 (idx) == DMU_OTN_UINT64_DATA || (idx) == DMU_OTN_UINT64_METADATA ? \
96 DMU_OT_UINT64_OTHER : DMU_OT_NUMTYPES)
98 /* Some platforms require part of inode IDs to be remapped */
100 #define ZDB_MAP_OBJECT_ID(obj) INO_XNUTOZFS(obj, 2)
102 #define ZDB_MAP_OBJECT_ID(obj) (obj)
106 zdb_ot_name(dmu_object_type_t type
)
108 if (type
< DMU_OT_NUMTYPES
)
109 return (dmu_ot
[type
].ot_name
);
110 else if ((type
& DMU_OT_NEWTYPE
) &&
111 ((type
& DMU_OT_BYTESWAP_MASK
) < DMU_BSWAP_NUMFUNCS
))
112 return (dmu_ot_byteswap
[type
& DMU_OT_BYTESWAP_MASK
].ob_name
);
117 extern int reference_tracking_enable
;
118 extern int zfs_recover
;
119 extern unsigned long zfs_arc_meta_min
, zfs_arc_meta_limit
;
120 extern int zfs_vdev_async_read_max_active
;
121 extern boolean_t spa_load_verify_dryrun
;
122 extern boolean_t spa_mode_readable_spacemaps
;
123 extern int zfs_reconstruct_indirect_combinations_max
;
124 extern int zfs_btree_verify_intensity
;
126 static const char cmdname
[] = "zdb";
127 uint8_t dump_opt
[256];
129 typedef void object_viewer_t(objset_t
*, uint64_t, void *data
, size_t size
);
131 uint64_t *zopt_metaslab
= NULL
;
132 static unsigned zopt_metaslab_args
= 0;
134 typedef struct zopt_object_range
{
135 uint64_t zor_obj_start
;
136 uint64_t zor_obj_end
;
138 } zopt_object_range_t
;
139 zopt_object_range_t
*zopt_object_ranges
= NULL
;
140 static unsigned zopt_object_args
= 0;
142 static int flagbits
[256];
144 #define ZOR_FLAG_PLAIN_FILE 0x0001
145 #define ZOR_FLAG_DIRECTORY 0x0002
146 #define ZOR_FLAG_SPACE_MAP 0x0004
147 #define ZOR_FLAG_ZAP 0x0008
148 #define ZOR_FLAG_ALL_TYPES -1
149 #define ZOR_SUPPORTED_FLAGS (ZOR_FLAG_PLAIN_FILE | \
150 ZOR_FLAG_DIRECTORY | \
151 ZOR_FLAG_SPACE_MAP | \
154 #define ZDB_FLAG_CHECKSUM 0x0001
155 #define ZDB_FLAG_DECOMPRESS 0x0002
156 #define ZDB_FLAG_BSWAP 0x0004
157 #define ZDB_FLAG_GBH 0x0008
158 #define ZDB_FLAG_INDIRECT 0x0010
159 #define ZDB_FLAG_RAW 0x0020
160 #define ZDB_FLAG_PRINT_BLKPTR 0x0040
161 #define ZDB_FLAG_VERBOSE 0x0080
163 uint64_t max_inflight_bytes
= 256 * 1024 * 1024; /* 256MB */
164 static int leaked_objects
= 0;
165 static range_tree_t
*mos_refd_objs
;
167 static void snprintf_blkptr_compact(char *, size_t, const blkptr_t
*,
169 static void mos_obj_refd(uint64_t);
170 static void mos_obj_refd_multiple(uint64_t);
171 static int dump_bpobj_cb(void *arg
, const blkptr_t
*bp
, boolean_t free
,
174 typedef struct sublivelist_verify
{
175 /* FREE's that haven't yet matched to an ALLOC, in one sub-livelist */
178 /* ALLOC's without a matching FREE, accumulates across sub-livelists */
179 zfs_btree_t sv_leftover
;
180 } sublivelist_verify_t
;
183 livelist_compare(const void *larg
, const void *rarg
)
185 const blkptr_t
*l
= larg
;
186 const blkptr_t
*r
= rarg
;
188 /* Sort them according to dva[0] */
189 uint64_t l_dva0_vdev
, r_dva0_vdev
;
190 l_dva0_vdev
= DVA_GET_VDEV(&l
->blk_dva
[0]);
191 r_dva0_vdev
= DVA_GET_VDEV(&r
->blk_dva
[0]);
192 if (l_dva0_vdev
< r_dva0_vdev
)
194 else if (l_dva0_vdev
> r_dva0_vdev
)
197 /* if vdevs are equal, sort by offsets. */
198 uint64_t l_dva0_offset
;
199 uint64_t r_dva0_offset
;
200 l_dva0_offset
= DVA_GET_OFFSET(&l
->blk_dva
[0]);
201 r_dva0_offset
= DVA_GET_OFFSET(&r
->blk_dva
[0]);
202 if (l_dva0_offset
< r_dva0_offset
) {
204 } else if (l_dva0_offset
> r_dva0_offset
) {
209 * Since we're storing blkptrs without cancelling FREE/ALLOC pairs,
210 * it's possible the offsets are equal. In that case, sort by txg
212 if (l
->blk_birth
< r
->blk_birth
) {
214 } else if (l
->blk_birth
> r
->blk_birth
) {
220 typedef struct sublivelist_verify_block
{
224 * We need this to check if the block marked as allocated
225 * in the livelist was freed (and potentially reallocated)
226 * in the metaslab spacemaps at a later TXG.
228 uint64_t svb_allocated_txg
;
229 } sublivelist_verify_block_t
;
231 static void zdb_print_blkptr(const blkptr_t
*bp
, int flags
);
233 typedef struct sublivelist_verify_block_refcnt
{
234 /* block pointer entry in livelist being verified */
238 * Refcount gets incremented to 1 when we encounter the first
239 * FREE entry for the svfbr block pointer and a node for it
240 * is created in our ZDB verification/tracking metadata.
242 * As we encounter more FREE entries we increment this counter
243 * and similarly decrement it whenever we find the respective
244 * ALLOC entries for this block.
246 * When the refcount gets to 0 it means that all the FREE and
247 * ALLOC entries of this block have paired up and we no longer
248 * need to track it in our verification logic (e.g. the node
249 * containing this struct in our verification data structure
252 * [refer to sublivelist_verify_blkptr() for the actual code]
254 uint32_t svbr_refcnt
;
255 } sublivelist_verify_block_refcnt_t
;
258 sublivelist_block_refcnt_compare(const void *larg
, const void *rarg
)
260 const sublivelist_verify_block_refcnt_t
*l
= larg
;
261 const sublivelist_verify_block_refcnt_t
*r
= rarg
;
262 return (livelist_compare(&l
->svbr_blk
, &r
->svbr_blk
));
266 sublivelist_verify_blkptr(void *arg
, const blkptr_t
*bp
, boolean_t free
,
269 ASSERT3P(tx
, ==, NULL
);
270 struct sublivelist_verify
*sv
= arg
;
271 sublivelist_verify_block_refcnt_t current
= {
275 * Start with 1 in case this is the first free entry.
276 * This field is not used for our B-Tree comparisons
282 zfs_btree_index_t where
;
283 sublivelist_verify_block_refcnt_t
*pair
=
284 zfs_btree_find(&sv
->sv_pair
, ¤t
, &where
);
287 /* first free entry for this block pointer */
288 zfs_btree_add(&sv
->sv_pair
, ¤t
);
294 /* block that is currently marked as allocated */
295 for (int i
= 0; i
< SPA_DVAS_PER_BP
; i
++) {
296 if (DVA_IS_EMPTY(&bp
->blk_dva
[i
]))
298 sublivelist_verify_block_t svb
= {
299 .svb_dva
= bp
->blk_dva
[i
],
300 .svb_allocated_txg
= bp
->blk_birth
303 if (zfs_btree_find(&sv
->sv_leftover
, &svb
,
305 zfs_btree_add_idx(&sv
->sv_leftover
,
310 /* alloc matches a free entry */
312 if (pair
->svbr_refcnt
== 0) {
313 /* all allocs and frees have been matched */
314 zfs_btree_remove_idx(&sv
->sv_pair
, &where
);
323 sublivelist_verify_func(void *args
, dsl_deadlist_entry_t
*dle
)
326 struct sublivelist_verify
*sv
= args
;
328 zfs_btree_create(&sv
->sv_pair
, sublivelist_block_refcnt_compare
,
329 sizeof (sublivelist_verify_block_refcnt_t
));
331 err
= bpobj_iterate_nofree(&dle
->dle_bpobj
, sublivelist_verify_blkptr
,
334 sublivelist_verify_block_refcnt_t
*e
;
335 zfs_btree_index_t
*cookie
= NULL
;
336 while ((e
= zfs_btree_destroy_nodes(&sv
->sv_pair
, &cookie
)) != NULL
) {
337 char blkbuf
[BP_SPRINTF_LEN
];
338 snprintf_blkptr_compact(blkbuf
, sizeof (blkbuf
),
339 &e
->svbr_blk
, B_TRUE
);
340 (void) printf("\tERROR: %d unmatched FREE(s): %s\n",
341 e
->svbr_refcnt
, blkbuf
);
343 zfs_btree_destroy(&sv
->sv_pair
);
349 livelist_block_compare(const void *larg
, const void *rarg
)
351 const sublivelist_verify_block_t
*l
= larg
;
352 const sublivelist_verify_block_t
*r
= rarg
;
354 if (DVA_GET_VDEV(&l
->svb_dva
) < DVA_GET_VDEV(&r
->svb_dva
))
356 else if (DVA_GET_VDEV(&l
->svb_dva
) > DVA_GET_VDEV(&r
->svb_dva
))
359 if (DVA_GET_OFFSET(&l
->svb_dva
) < DVA_GET_OFFSET(&r
->svb_dva
))
361 else if (DVA_GET_OFFSET(&l
->svb_dva
) > DVA_GET_OFFSET(&r
->svb_dva
))
364 if (DVA_GET_ASIZE(&l
->svb_dva
) < DVA_GET_ASIZE(&r
->svb_dva
))
366 else if (DVA_GET_ASIZE(&l
->svb_dva
) > DVA_GET_ASIZE(&r
->svb_dva
))
373 * Check for errors in a livelist while tracking all unfreed ALLOCs in the
374 * sublivelist_verify_t: sv->sv_leftover
377 livelist_verify(dsl_deadlist_t
*dl
, void *arg
)
379 sublivelist_verify_t
*sv
= arg
;
380 dsl_deadlist_iterate(dl
, sublivelist_verify_func
, sv
);
384 * Check for errors in the livelist entry and discard the intermediary
388 sublivelist_verify_lightweight(void *args
, dsl_deadlist_entry_t
*dle
)
391 sublivelist_verify_t sv
;
392 zfs_btree_create(&sv
.sv_leftover
, livelist_block_compare
,
393 sizeof (sublivelist_verify_block_t
));
394 int err
= sublivelist_verify_func(&sv
, dle
);
395 zfs_btree_clear(&sv
.sv_leftover
);
396 zfs_btree_destroy(&sv
.sv_leftover
);
400 typedef struct metaslab_verify
{
402 * Tree containing all the leftover ALLOCs from the livelists
403 * that are part of this metaslab.
405 zfs_btree_t mv_livelist_allocs
;
408 * Metaslab information.
416 * What's currently allocated for this metaslab.
418 range_tree_t
*mv_allocated
;
421 typedef void ll_iter_t(dsl_deadlist_t
*ll
, void *arg
);
423 typedef int (*zdb_log_sm_cb_t
)(spa_t
*spa
, space_map_entry_t
*sme
, uint64_t txg
,
426 typedef struct unflushed_iter_cb_arg
{
430 zdb_log_sm_cb_t uic_cb
;
431 } unflushed_iter_cb_arg_t
;
434 iterate_through_spacemap_logs_cb(space_map_entry_t
*sme
, void *arg
)
436 unflushed_iter_cb_arg_t
*uic
= arg
;
437 return (uic
->uic_cb(uic
->uic_spa
, sme
, uic
->uic_txg
, uic
->uic_arg
));
441 iterate_through_spacemap_logs(spa_t
*spa
, zdb_log_sm_cb_t cb
, void *arg
)
443 if (!spa_feature_is_active(spa
, SPA_FEATURE_LOG_SPACEMAP
))
446 spa_config_enter(spa
, SCL_CONFIG
, FTAG
, RW_READER
);
447 for (spa_log_sm_t
*sls
= avl_first(&spa
->spa_sm_logs_by_txg
);
448 sls
; sls
= AVL_NEXT(&spa
->spa_sm_logs_by_txg
, sls
)) {
449 space_map_t
*sm
= NULL
;
450 VERIFY0(space_map_open(&sm
, spa_meta_objset(spa
),
451 sls
->sls_sm_obj
, 0, UINT64_MAX
, SPA_MINBLOCKSHIFT
));
453 unflushed_iter_cb_arg_t uic
= {
455 .uic_txg
= sls
->sls_txg
,
459 VERIFY0(space_map_iterate(sm
, space_map_length(sm
),
460 iterate_through_spacemap_logs_cb
, &uic
));
463 spa_config_exit(spa
, SCL_CONFIG
, FTAG
);
467 verify_livelist_allocs(metaslab_verify_t
*mv
, uint64_t txg
,
468 uint64_t offset
, uint64_t size
)
470 sublivelist_verify_block_t svb
;
471 DVA_SET_VDEV(&svb
.svb_dva
, mv
->mv_vdid
);
472 DVA_SET_OFFSET(&svb
.svb_dva
, offset
);
473 DVA_SET_ASIZE(&svb
.svb_dva
, size
);
474 zfs_btree_index_t where
;
475 uint64_t end_offset
= offset
+ size
;
478 * Look for an exact match for spacemap entry in the livelist entries.
479 * Then, look for other livelist entries that fall within the range
480 * of the spacemap entry as it may have been condensed
482 sublivelist_verify_block_t
*found
=
483 zfs_btree_find(&mv
->mv_livelist_allocs
, &svb
, &where
);
485 found
= zfs_btree_next(&mv
->mv_livelist_allocs
, &where
, &where
);
487 for (; found
!= NULL
&& DVA_GET_VDEV(&found
->svb_dva
) == mv
->mv_vdid
&&
488 DVA_GET_OFFSET(&found
->svb_dva
) < end_offset
;
489 found
= zfs_btree_next(&mv
->mv_livelist_allocs
, &where
, &where
)) {
490 if (found
->svb_allocated_txg
<= txg
) {
491 (void) printf("ERROR: Livelist ALLOC [%llx:%llx] "
492 "from TXG %llx FREED at TXG %llx\n",
493 (u_longlong_t
)DVA_GET_OFFSET(&found
->svb_dva
),
494 (u_longlong_t
)DVA_GET_ASIZE(&found
->svb_dva
),
495 (u_longlong_t
)found
->svb_allocated_txg
,
502 metaslab_spacemap_validation_cb(space_map_entry_t
*sme
, void *arg
)
504 metaslab_verify_t
*mv
= arg
;
505 uint64_t offset
= sme
->sme_offset
;
506 uint64_t size
= sme
->sme_run
;
507 uint64_t txg
= sme
->sme_txg
;
509 if (sme
->sme_type
== SM_ALLOC
) {
510 if (range_tree_contains(mv
->mv_allocated
,
512 (void) printf("ERROR: DOUBLE ALLOC: "
514 "%llu:%llu LOG_SM\n",
515 (u_longlong_t
)txg
, (u_longlong_t
)offset
,
516 (u_longlong_t
)size
, (u_longlong_t
)mv
->mv_vdid
,
517 (u_longlong_t
)mv
->mv_msid
);
519 range_tree_add(mv
->mv_allocated
,
523 if (!range_tree_contains(mv
->mv_allocated
,
525 (void) printf("ERROR: DOUBLE FREE: "
527 "%llu:%llu LOG_SM\n",
528 (u_longlong_t
)txg
, (u_longlong_t
)offset
,
529 (u_longlong_t
)size
, (u_longlong_t
)mv
->mv_vdid
,
530 (u_longlong_t
)mv
->mv_msid
);
532 range_tree_remove(mv
->mv_allocated
,
537 if (sme
->sme_type
!= SM_ALLOC
) {
539 * If something is freed in the spacemap, verify that
540 * it is not listed as allocated in the livelist.
542 verify_livelist_allocs(mv
, txg
, offset
, size
);
548 spacemap_check_sm_log_cb(spa_t
*spa
, space_map_entry_t
*sme
,
549 uint64_t txg
, void *arg
)
551 metaslab_verify_t
*mv
= arg
;
552 uint64_t offset
= sme
->sme_offset
;
553 uint64_t vdev_id
= sme
->sme_vdev
;
555 vdev_t
*vd
= vdev_lookup_top(spa
, vdev_id
);
557 /* skip indirect vdevs */
558 if (!vdev_is_concrete(vd
))
561 if (vdev_id
!= mv
->mv_vdid
)
564 metaslab_t
*ms
= vd
->vdev_ms
[offset
>> vd
->vdev_ms_shift
];
565 if (ms
->ms_id
!= mv
->mv_msid
)
568 if (txg
< metaslab_unflushed_txg(ms
))
572 ASSERT3U(txg
, ==, sme
->sme_txg
);
573 return (metaslab_spacemap_validation_cb(sme
, mv
));
577 spacemap_check_sm_log(spa_t
*spa
, metaslab_verify_t
*mv
)
579 iterate_through_spacemap_logs(spa
, spacemap_check_sm_log_cb
, mv
);
583 spacemap_check_ms_sm(space_map_t
*sm
, metaslab_verify_t
*mv
)
588 VERIFY0(space_map_iterate(sm
, space_map_length(sm
),
589 metaslab_spacemap_validation_cb
, mv
));
592 static void iterate_deleted_livelists(spa_t
*spa
, ll_iter_t func
, void *arg
);
595 * Transfer blocks from sv_leftover tree to the mv_livelist_allocs if
596 * they are part of that metaslab (mv_msid).
599 mv_populate_livelist_allocs(metaslab_verify_t
*mv
, sublivelist_verify_t
*sv
)
601 zfs_btree_index_t where
;
602 sublivelist_verify_block_t
*svb
;
603 ASSERT3U(zfs_btree_numnodes(&mv
->mv_livelist_allocs
), ==, 0);
604 for (svb
= zfs_btree_first(&sv
->sv_leftover
, &where
);
606 svb
= zfs_btree_next(&sv
->sv_leftover
, &where
, &where
)) {
607 if (DVA_GET_VDEV(&svb
->svb_dva
) != mv
->mv_vdid
)
610 if (DVA_GET_OFFSET(&svb
->svb_dva
) < mv
->mv_start
&&
611 (DVA_GET_OFFSET(&svb
->svb_dva
) +
612 DVA_GET_ASIZE(&svb
->svb_dva
)) > mv
->mv_start
) {
613 (void) printf("ERROR: Found block that crosses "
614 "metaslab boundary: <%llu:%llx:%llx>\n",
615 (u_longlong_t
)DVA_GET_VDEV(&svb
->svb_dva
),
616 (u_longlong_t
)DVA_GET_OFFSET(&svb
->svb_dva
),
617 (u_longlong_t
)DVA_GET_ASIZE(&svb
->svb_dva
));
621 if (DVA_GET_OFFSET(&svb
->svb_dva
) < mv
->mv_start
)
624 if (DVA_GET_OFFSET(&svb
->svb_dva
) >= mv
->mv_end
)
627 if ((DVA_GET_OFFSET(&svb
->svb_dva
) +
628 DVA_GET_ASIZE(&svb
->svb_dva
)) > mv
->mv_end
) {
629 (void) printf("ERROR: Found block that crosses "
630 "metaslab boundary: <%llu:%llx:%llx>\n",
631 (u_longlong_t
)DVA_GET_VDEV(&svb
->svb_dva
),
632 (u_longlong_t
)DVA_GET_OFFSET(&svb
->svb_dva
),
633 (u_longlong_t
)DVA_GET_ASIZE(&svb
->svb_dva
));
637 zfs_btree_add(&mv
->mv_livelist_allocs
, svb
);
640 for (svb
= zfs_btree_first(&mv
->mv_livelist_allocs
, &where
);
642 svb
= zfs_btree_next(&mv
->mv_livelist_allocs
, &where
, &where
)) {
643 zfs_btree_remove(&sv
->sv_leftover
, svb
);
649 * Iterate through all the sublivelists and:
650 * - report leftover frees (**)
651 * - record leftover ALLOCs together with their TXG [see Cross Check]
653 * (**) Note: Double ALLOCs are valid in datasets that have dedup
654 * enabled. Similarly double FREEs are allowed as well but
655 * only if they pair up with a corresponding ALLOC entry once
656 * we our done with our sublivelist iteration.
660 * - iterate over spacemap and then the metaslab's entries in the
661 * spacemap log, then report any double FREEs and ALLOCs (do not
665 * After finishing the Livelist Check phase and while being in the
666 * Spacemap Check phase, we find all the recorded leftover ALLOCs
667 * of the livelist check that are part of the metaslab that we are
668 * currently looking at in the Spacemap Check. We report any entries
669 * that are marked as ALLOCs in the livelists but have been actually
670 * freed (and potentially allocated again) after their TXG stamp in
671 * the spacemaps. Also report any ALLOCs from the livelists that
672 * belong to indirect vdevs (e.g. their vdev completed removal).
674 * Note that this will miss Log Spacemap entries that cancelled each other
675 * out before being flushed to the metaslab, so we are not guaranteed
676 * to match all erroneous ALLOCs.
679 livelist_metaslab_validate(spa_t
*spa
)
681 (void) printf("Verifying deleted livelist entries\n");
683 sublivelist_verify_t sv
;
684 zfs_btree_create(&sv
.sv_leftover
, livelist_block_compare
,
685 sizeof (sublivelist_verify_block_t
));
686 iterate_deleted_livelists(spa
, livelist_verify
, &sv
);
688 (void) printf("Verifying metaslab entries\n");
689 vdev_t
*rvd
= spa
->spa_root_vdev
;
690 for (uint64_t c
= 0; c
< rvd
->vdev_children
; c
++) {
691 vdev_t
*vd
= rvd
->vdev_child
[c
];
693 if (!vdev_is_concrete(vd
))
696 for (uint64_t mid
= 0; mid
< vd
->vdev_ms_count
; mid
++) {
697 metaslab_t
*m
= vd
->vdev_ms
[mid
];
699 (void) fprintf(stderr
,
700 "\rverifying concrete vdev %llu, "
701 "metaslab %llu of %llu ...",
702 (longlong_t
)vd
->vdev_id
,
704 (longlong_t
)vd
->vdev_ms_count
);
706 uint64_t shift
, start
;
707 range_seg_type_t type
=
708 metaslab_calculate_range_tree_type(vd
, m
,
710 metaslab_verify_t mv
;
711 mv
.mv_allocated
= range_tree_create(NULL
,
712 type
, NULL
, start
, shift
);
713 mv
.mv_vdid
= vd
->vdev_id
;
714 mv
.mv_msid
= m
->ms_id
;
715 mv
.mv_start
= m
->ms_start
;
716 mv
.mv_end
= m
->ms_start
+ m
->ms_size
;
717 zfs_btree_create(&mv
.mv_livelist_allocs
,
718 livelist_block_compare
,
719 sizeof (sublivelist_verify_block_t
));
721 mv_populate_livelist_allocs(&mv
, &sv
);
723 spacemap_check_ms_sm(m
->ms_sm
, &mv
);
724 spacemap_check_sm_log(spa
, &mv
);
726 range_tree_vacate(mv
.mv_allocated
, NULL
, NULL
);
727 range_tree_destroy(mv
.mv_allocated
);
728 zfs_btree_clear(&mv
.mv_livelist_allocs
);
729 zfs_btree_destroy(&mv
.mv_livelist_allocs
);
732 (void) fprintf(stderr
, "\n");
735 * If there are any segments in the leftover tree after we walked
736 * through all the metaslabs in the concrete vdevs then this means
737 * that we have segments in the livelists that belong to indirect
738 * vdevs and are marked as allocated.
740 if (zfs_btree_numnodes(&sv
.sv_leftover
) == 0) {
741 zfs_btree_destroy(&sv
.sv_leftover
);
744 (void) printf("ERROR: Found livelist blocks marked as allocated "
745 "for indirect vdevs:\n");
747 zfs_btree_index_t
*where
= NULL
;
748 sublivelist_verify_block_t
*svb
;
749 while ((svb
= zfs_btree_destroy_nodes(&sv
.sv_leftover
, &where
)) !=
751 int vdev_id
= DVA_GET_VDEV(&svb
->svb_dva
);
752 ASSERT3U(vdev_id
, <, rvd
->vdev_children
);
753 vdev_t
*vd
= rvd
->vdev_child
[vdev_id
];
754 ASSERT(!vdev_is_concrete(vd
));
755 (void) printf("<%d:%llx:%llx> TXG %llx\n",
756 vdev_id
, (u_longlong_t
)DVA_GET_OFFSET(&svb
->svb_dva
),
757 (u_longlong_t
)DVA_GET_ASIZE(&svb
->svb_dva
),
758 (u_longlong_t
)svb
->svb_allocated_txg
);
761 zfs_btree_destroy(&sv
.sv_leftover
);
765 * These libumem hooks provide a reasonable set of defaults for the allocator's
766 * debugging facilities.
769 _umem_debug_init(void)
771 return ("default,verbose"); /* $UMEM_DEBUG setting */
775 _umem_logging_init(void)
777 return ("fail,contents"); /* $UMEM_LOGGING setting */
783 (void) fprintf(stderr
,
784 "Usage:\t%s [-AbcdDFGhikLMPsvXy] [-e [-V] [-p <path> ...]] "
785 "[-I <inflight I/Os>]\n"
786 "\t\t[-o <var>=<value>]... [-t <txg>] [-U <cache>] [-x <dumpdir>]\n"
787 "\t\t[<poolname>[/<dataset | objset id>] [<object | range> ...]]\n"
788 "\t%s [-AdiPv] [-e [-V] [-p <path> ...]] [-U <cache>]\n"
789 "\t\t[<poolname>[/<dataset | objset id>] [<object | range> ...]\n"
790 "\t%s [-v] <bookmark>\n"
791 "\t%s -C [-A] [-U <cache>]\n"
792 "\t%s -l [-Aqu] <device>\n"
793 "\t%s -m [-AFLPX] [-e [-V] [-p <path> ...]] [-t <txg>] "
794 "[-U <cache>]\n\t\t<poolname> [<vdev> [<metaslab> ...]]\n"
795 "\t%s -O <dataset> <path>\n"
796 "\t%s -r <dataset> <path> <destination>\n"
797 "\t%s -R [-A] [-e [-V] [-p <path> ...]] [-U <cache>]\n"
798 "\t\t<poolname> <vdev>:<offset>:<size>[:<flags>]\n"
799 "\t%s -E [-A] word0:word1:...:word15\n"
800 "\t%s -S [-AP] [-e [-V] [-p <path> ...]] [-U <cache>] "
802 cmdname
, cmdname
, cmdname
, cmdname
, cmdname
, cmdname
, cmdname
,
803 cmdname
, cmdname
, cmdname
, cmdname
);
805 (void) fprintf(stderr
, " Dataset name must include at least one "
806 "separator character '/' or '@'\n");
807 (void) fprintf(stderr
, " If dataset name is specified, only that "
808 "dataset is dumped\n");
809 (void) fprintf(stderr
, " If object numbers or object number "
810 "ranges are specified, only those\n"
811 " objects or ranges are dumped.\n\n");
812 (void) fprintf(stderr
,
813 " Object ranges take the form <start>:<end>[:<flags>]\n"
814 " start Starting object number\n"
815 " end Ending object number, or -1 for no upper bound\n"
816 " flags Optional flags to select object types:\n"
817 " A All objects (this is the default)\n"
818 " d ZFS directories\n"
820 " m SPA space maps\n"
822 " - Negate effect of next flag\n\n");
823 (void) fprintf(stderr
, " Options to control amount of output:\n");
824 (void) fprintf(stderr
, " -b --block-stats "
825 "block statistics\n");
826 (void) fprintf(stderr
, " -c --checksum "
827 "checksum all metadata (twice for all data) blocks\n");
828 (void) fprintf(stderr
, " -C --config "
829 "config (or cachefile if alone)\n");
830 (void) fprintf(stderr
, " -d --datasets "
832 (void) fprintf(stderr
, " -D --dedup-stats "
833 "dedup statistics\n");
834 (void) fprintf(stderr
, " -E --embedded-block-pointer=INTEGER\n"
835 " decode and display block "
836 "from an embedded block pointer\n");
837 (void) fprintf(stderr
, " -h --history "
839 (void) fprintf(stderr
, " -i --intent-logs "
841 (void) fprintf(stderr
, " -l --label "
842 "read label contents\n");
843 (void) fprintf(stderr
, " -k --checkpointed-state "
844 "examine the checkpointed state of the pool\n");
845 (void) fprintf(stderr
, " -L --disable-leak-tracking "
846 "disable leak tracking (do not load spacemaps)\n");
847 (void) fprintf(stderr
, " -m --metaslabs "
849 (void) fprintf(stderr
, " -M --metaslab-groups "
850 "metaslab groups\n");
851 (void) fprintf(stderr
, " -O --object-lookups "
852 "perform object lookups by path\n");
853 (void) fprintf(stderr
, " -r --copy-object "
854 "copy an object by path to file\n");
855 (void) fprintf(stderr
, " -R --read-block "
856 "read and display block from a device\n");
857 (void) fprintf(stderr
, " -s --io-stats "
858 "report stats on zdb's I/O\n");
859 (void) fprintf(stderr
, " -S --simulate-dedup "
860 "simulate dedup to measure effect\n");
861 (void) fprintf(stderr
, " -v --verbose "
862 "verbose (applies to all others)\n");
863 (void) fprintf(stderr
, " -y --livelist "
864 "perform livelist and metaslab validation on any livelists being "
866 (void) fprintf(stderr
, " Below options are intended for use "
867 "with other options:\n");
868 (void) fprintf(stderr
, " -A --ignore-assertions "
869 "ignore assertions (-A), enable panic recovery (-AA) or both "
871 (void) fprintf(stderr
, " -e --exported "
872 "pool is exported/destroyed/has altroot/not in a cachefile\n");
873 (void) fprintf(stderr
, " -F --automatic-rewind "
874 "attempt automatic rewind within safe range of transaction "
876 (void) fprintf(stderr
, " -G --dump-debug-msg "
877 "dump zfs_dbgmsg buffer before exiting\n");
878 (void) fprintf(stderr
, " -I --inflight=INTEGER "
879 "specify the maximum number of checksumming I/Os "
880 "[default is 200]\n");
881 (void) fprintf(stderr
, " -o --option=\"OPTION=INTEGER\" "
882 "set global variable to an unsigned 32-bit integer\n");
883 (void) fprintf(stderr
, " -p --path==PATH "
884 "use one or more with -e to specify path to vdev dir\n");
885 (void) fprintf(stderr
, " -P --parseable "
886 "print numbers in parseable form\n");
887 (void) fprintf(stderr
, " -q --skip-label "
888 "don't print label contents\n");
889 (void) fprintf(stderr
, " -t --txg=INTEGER "
890 "highest txg to use when searching for uberblocks\n");
891 (void) fprintf(stderr
, " -u --uberblock "
893 (void) fprintf(stderr
, " -U --cachefile=PATH "
894 "use alternate cachefile\n");
895 (void) fprintf(stderr
, " -V --verbatim "
896 "do verbatim import\n");
897 (void) fprintf(stderr
, " -x --dump-blocks=PATH "
898 "dump all read blocks into specified directory\n");
899 (void) fprintf(stderr
, " -X --extreme-rewind "
900 "attempt extreme rewind (does not work with dataset)\n");
901 (void) fprintf(stderr
, " -Y --all-reconstruction "
902 "attempt all reconstruction combinations for split blocks\n");
903 (void) fprintf(stderr
, " -Z --zstd-headers "
904 "show ZSTD headers \n");
905 (void) fprintf(stderr
, "Specify an option more than once (e.g. -bb) "
906 "to make only that option verbose\n");
907 (void) fprintf(stderr
, "Default is to dump everything non-verbosely\n");
912 dump_debug_buffer(void)
916 (void) fflush(stdout
);
917 zfs_dbgmsg_print("zdb");
922 * Called for usage errors that are discovered after a call to spa_open(),
923 * dmu_bonus_hold(), or pool_match(). abort() is called for other errors.
927 fatal(const char *fmt
, ...)
932 (void) fprintf(stderr
, "%s: ", cmdname
);
933 (void) vfprintf(stderr
, fmt
, ap
);
935 (void) fprintf(stderr
, "\n");
943 dump_packed_nvlist(objset_t
*os
, uint64_t object
, void *data
, size_t size
)
947 size_t nvsize
= *(uint64_t *)data
;
948 char *packed
= umem_alloc(nvsize
, UMEM_NOFAIL
);
950 VERIFY(0 == dmu_read(os
, object
, 0, nvsize
, packed
, DMU_READ_PREFETCH
));
952 VERIFY(nvlist_unpack(packed
, nvsize
, &nv
, 0) == 0);
954 umem_free(packed
, nvsize
);
962 dump_history_offsets(objset_t
*os
, uint64_t object
, void *data
, size_t size
)
964 (void) os
, (void) object
, (void) size
;
965 spa_history_phys_t
*shp
= data
;
970 (void) printf("\t\tpool_create_len = %llu\n",
971 (u_longlong_t
)shp
->sh_pool_create_len
);
972 (void) printf("\t\tphys_max_off = %llu\n",
973 (u_longlong_t
)shp
->sh_phys_max_off
);
974 (void) printf("\t\tbof = %llu\n",
975 (u_longlong_t
)shp
->sh_bof
);
976 (void) printf("\t\teof = %llu\n",
977 (u_longlong_t
)shp
->sh_eof
);
978 (void) printf("\t\trecords_lost = %llu\n",
979 (u_longlong_t
)shp
->sh_records_lost
);
983 zdb_nicenum(uint64_t num
, char *buf
, size_t buflen
)
986 (void) snprintf(buf
, buflen
, "%llu", (longlong_t
)num
);
988 nicenum(num
, buf
, sizeof (buf
));
991 static const char histo_stars
[] = "****************************************";
992 static const uint64_t histo_width
= sizeof (histo_stars
) - 1;
995 dump_histogram(const uint64_t *histo
, int size
, int offset
)
998 int minidx
= size
- 1;
1002 for (i
= 0; i
< size
; i
++) {
1005 if (histo
[i
] > 0 && i
> maxidx
)
1007 if (histo
[i
] > 0 && i
< minidx
)
1011 if (max
< histo_width
)
1014 for (i
= minidx
; i
<= maxidx
; i
++) {
1015 (void) printf("\t\t\t%3u: %6llu %s\n",
1016 i
+ offset
, (u_longlong_t
)histo
[i
],
1017 &histo_stars
[(max
- histo
[i
]) * histo_width
/ max
]);
1022 dump_zap_stats(objset_t
*os
, uint64_t object
)
1027 error
= zap_get_stats(os
, object
, &zs
);
1031 if (zs
.zs_ptrtbl_len
== 0) {
1032 ASSERT(zs
.zs_num_blocks
== 1);
1033 (void) printf("\tmicrozap: %llu bytes, %llu entries\n",
1034 (u_longlong_t
)zs
.zs_blocksize
,
1035 (u_longlong_t
)zs
.zs_num_entries
);
1039 (void) printf("\tFat ZAP stats:\n");
1041 (void) printf("\t\tPointer table:\n");
1042 (void) printf("\t\t\t%llu elements\n",
1043 (u_longlong_t
)zs
.zs_ptrtbl_len
);
1044 (void) printf("\t\t\tzt_blk: %llu\n",
1045 (u_longlong_t
)zs
.zs_ptrtbl_zt_blk
);
1046 (void) printf("\t\t\tzt_numblks: %llu\n",
1047 (u_longlong_t
)zs
.zs_ptrtbl_zt_numblks
);
1048 (void) printf("\t\t\tzt_shift: %llu\n",
1049 (u_longlong_t
)zs
.zs_ptrtbl_zt_shift
);
1050 (void) printf("\t\t\tzt_blks_copied: %llu\n",
1051 (u_longlong_t
)zs
.zs_ptrtbl_blks_copied
);
1052 (void) printf("\t\t\tzt_nextblk: %llu\n",
1053 (u_longlong_t
)zs
.zs_ptrtbl_nextblk
);
1055 (void) printf("\t\tZAP entries: %llu\n",
1056 (u_longlong_t
)zs
.zs_num_entries
);
1057 (void) printf("\t\tLeaf blocks: %llu\n",
1058 (u_longlong_t
)zs
.zs_num_leafs
);
1059 (void) printf("\t\tTotal blocks: %llu\n",
1060 (u_longlong_t
)zs
.zs_num_blocks
);
1061 (void) printf("\t\tzap_block_type: 0x%llx\n",
1062 (u_longlong_t
)zs
.zs_block_type
);
1063 (void) printf("\t\tzap_magic: 0x%llx\n",
1064 (u_longlong_t
)zs
.zs_magic
);
1065 (void) printf("\t\tzap_salt: 0x%llx\n",
1066 (u_longlong_t
)zs
.zs_salt
);
1068 (void) printf("\t\tLeafs with 2^n pointers:\n");
1069 dump_histogram(zs
.zs_leafs_with_2n_pointers
, ZAP_HISTOGRAM_SIZE
, 0);
1071 (void) printf("\t\tBlocks with n*5 entries:\n");
1072 dump_histogram(zs
.zs_blocks_with_n5_entries
, ZAP_HISTOGRAM_SIZE
, 0);
1074 (void) printf("\t\tBlocks n/10 full:\n");
1075 dump_histogram(zs
.zs_blocks_n_tenths_full
, ZAP_HISTOGRAM_SIZE
, 0);
1077 (void) printf("\t\tEntries with n chunks:\n");
1078 dump_histogram(zs
.zs_entries_using_n_chunks
, ZAP_HISTOGRAM_SIZE
, 0);
1080 (void) printf("\t\tBuckets with n entries:\n");
1081 dump_histogram(zs
.zs_buckets_with_n_entries
, ZAP_HISTOGRAM_SIZE
, 0);
1085 dump_none(objset_t
*os
, uint64_t object
, void *data
, size_t size
)
1087 (void) os
, (void) object
, (void) data
, (void) size
;
1091 dump_unknown(objset_t
*os
, uint64_t object
, void *data
, size_t size
)
1093 (void) os
, (void) object
, (void) data
, (void) size
;
1094 (void) printf("\tUNKNOWN OBJECT TYPE\n");
1098 dump_uint8(objset_t
*os
, uint64_t object
, void *data
, size_t size
)
1100 (void) os
, (void) object
, (void) data
, (void) size
;
1104 dump_uint64(objset_t
*os
, uint64_t object
, void *data
, size_t size
)
1108 if (dump_opt
['d'] < 6)
1112 dmu_object_info_t doi
;
1114 VERIFY0(dmu_object_info(os
, object
, &doi
));
1115 size
= doi
.doi_max_offset
;
1117 * We cap the size at 1 mebibyte here to prevent
1118 * allocation failures and nigh-infinite printing if the
1119 * object is extremely large.
1121 oursize
= MIN(size
, 1 << 20);
1122 arr
= kmem_alloc(oursize
, KM_SLEEP
);
1124 int err
= dmu_read(os
, object
, 0, oursize
, arr
, 0);
1126 (void) printf("got error %u from dmu_read\n", err
);
1127 kmem_free(arr
, oursize
);
1132 * Even though the allocation is already done in this code path,
1133 * we still cap the size to prevent excessive printing.
1135 oursize
= MIN(size
, 1 << 20);
1140 (void) printf("\t\t[]\n");
1144 (void) printf("\t\t[%0llx", (u_longlong_t
)arr
[0]);
1145 for (size_t i
= 1; i
* sizeof (uint64_t) < oursize
; i
++) {
1147 (void) printf(", %0llx", (u_longlong_t
)arr
[i
]);
1149 (void) printf(",\n\t\t%0llx", (u_longlong_t
)arr
[i
]);
1151 if (oursize
!= size
)
1152 (void) printf(", ... ");
1153 (void) printf("]\n");
1156 kmem_free(arr
, oursize
);
1160 dump_zap(objset_t
*os
, uint64_t object
, void *data
, size_t size
)
1162 (void) data
, (void) size
;
1164 zap_attribute_t attr
;
1168 dump_zap_stats(os
, object
);
1169 (void) printf("\n");
1171 for (zap_cursor_init(&zc
, os
, object
);
1172 zap_cursor_retrieve(&zc
, &attr
) == 0;
1173 zap_cursor_advance(&zc
)) {
1174 (void) printf("\t\t%s = ", attr
.za_name
);
1175 if (attr
.za_num_integers
== 0) {
1176 (void) printf("\n");
1179 prop
= umem_zalloc(attr
.za_num_integers
*
1180 attr
.za_integer_length
, UMEM_NOFAIL
);
1181 (void) zap_lookup(os
, object
, attr
.za_name
,
1182 attr
.za_integer_length
, attr
.za_num_integers
, prop
);
1183 if (attr
.za_integer_length
== 1) {
1184 if (strcmp(attr
.za_name
,
1185 DSL_CRYPTO_KEY_MASTER_KEY
) == 0 ||
1186 strcmp(attr
.za_name
,
1187 DSL_CRYPTO_KEY_HMAC_KEY
) == 0 ||
1188 strcmp(attr
.za_name
, DSL_CRYPTO_KEY_IV
) == 0 ||
1189 strcmp(attr
.za_name
, DSL_CRYPTO_KEY_MAC
) == 0 ||
1190 strcmp(attr
.za_name
, DMU_POOL_CHECKSUM_SALT
) == 0) {
1193 for (i
= 0; i
< attr
.za_num_integers
; i
++) {
1194 (void) printf("%02x", u8
[i
]);
1197 (void) printf("%s", (char *)prop
);
1200 for (i
= 0; i
< attr
.za_num_integers
; i
++) {
1201 switch (attr
.za_integer_length
) {
1203 (void) printf("%u ",
1204 ((uint16_t *)prop
)[i
]);
1207 (void) printf("%u ",
1208 ((uint32_t *)prop
)[i
]);
1211 (void) printf("%lld ",
1212 (u_longlong_t
)((int64_t *)prop
)[i
]);
1217 (void) printf("\n");
1218 umem_free(prop
, attr
.za_num_integers
* attr
.za_integer_length
);
1220 zap_cursor_fini(&zc
);
1224 dump_bpobj(objset_t
*os
, uint64_t object
, void *data
, size_t size
)
1226 bpobj_phys_t
*bpop
= data
;
1228 char bytes
[32], comp
[32], uncomp
[32];
1230 /* make sure the output won't get truncated */
1231 _Static_assert(sizeof (bytes
) >= NN_NUMBUF_SZ
, "bytes truncated");
1232 _Static_assert(sizeof (comp
) >= NN_NUMBUF_SZ
, "comp truncated");
1233 _Static_assert(sizeof (uncomp
) >= NN_NUMBUF_SZ
, "uncomp truncated");
1238 zdb_nicenum(bpop
->bpo_bytes
, bytes
, sizeof (bytes
));
1239 zdb_nicenum(bpop
->bpo_comp
, comp
, sizeof (comp
));
1240 zdb_nicenum(bpop
->bpo_uncomp
, uncomp
, sizeof (uncomp
));
1242 (void) printf("\t\tnum_blkptrs = %llu\n",
1243 (u_longlong_t
)bpop
->bpo_num_blkptrs
);
1244 (void) printf("\t\tbytes = %s\n", bytes
);
1245 if (size
>= BPOBJ_SIZE_V1
) {
1246 (void) printf("\t\tcomp = %s\n", comp
);
1247 (void) printf("\t\tuncomp = %s\n", uncomp
);
1249 if (size
>= BPOBJ_SIZE_V2
) {
1250 (void) printf("\t\tsubobjs = %llu\n",
1251 (u_longlong_t
)bpop
->bpo_subobjs
);
1252 (void) printf("\t\tnum_subobjs = %llu\n",
1253 (u_longlong_t
)bpop
->bpo_num_subobjs
);
1255 if (size
>= sizeof (*bpop
)) {
1256 (void) printf("\t\tnum_freed = %llu\n",
1257 (u_longlong_t
)bpop
->bpo_num_freed
);
1260 if (dump_opt
['d'] < 5)
1263 for (i
= 0; i
< bpop
->bpo_num_blkptrs
; i
++) {
1264 char blkbuf
[BP_SPRINTF_LEN
];
1267 int err
= dmu_read(os
, object
,
1268 i
* sizeof (bp
), sizeof (bp
), &bp
, 0);
1270 (void) printf("got error %u from dmu_read\n", err
);
1273 snprintf_blkptr_compact(blkbuf
, sizeof (blkbuf
), &bp
,
1275 (void) printf("\t%s\n", blkbuf
);
1280 dump_bpobj_subobjs(objset_t
*os
, uint64_t object
, void *data
, size_t size
)
1282 (void) data
, (void) size
;
1283 dmu_object_info_t doi
;
1286 VERIFY0(dmu_object_info(os
, object
, &doi
));
1287 uint64_t *subobjs
= kmem_alloc(doi
.doi_max_offset
, KM_SLEEP
);
1289 int err
= dmu_read(os
, object
, 0, doi
.doi_max_offset
, subobjs
, 0);
1291 (void) printf("got error %u from dmu_read\n", err
);
1292 kmem_free(subobjs
, doi
.doi_max_offset
);
1296 int64_t last_nonzero
= -1;
1297 for (i
= 0; i
< doi
.doi_max_offset
/ 8; i
++) {
1298 if (subobjs
[i
] != 0)
1302 for (i
= 0; i
<= last_nonzero
; i
++) {
1303 (void) printf("\t%llu\n", (u_longlong_t
)subobjs
[i
]);
1305 kmem_free(subobjs
, doi
.doi_max_offset
);
1309 dump_ddt_zap(objset_t
*os
, uint64_t object
, void *data
, size_t size
)
1311 (void) data
, (void) size
;
1312 dump_zap_stats(os
, object
);
1313 /* contents are printed elsewhere, properly decoded */
1317 dump_sa_attrs(objset_t
*os
, uint64_t object
, void *data
, size_t size
)
1319 (void) data
, (void) size
;
1321 zap_attribute_t attr
;
1323 dump_zap_stats(os
, object
);
1324 (void) printf("\n");
1326 for (zap_cursor_init(&zc
, os
, object
);
1327 zap_cursor_retrieve(&zc
, &attr
) == 0;
1328 zap_cursor_advance(&zc
)) {
1329 (void) printf("\t\t%s = ", attr
.za_name
);
1330 if (attr
.za_num_integers
== 0) {
1331 (void) printf("\n");
1334 (void) printf(" %llx : [%d:%d:%d]\n",
1335 (u_longlong_t
)attr
.za_first_integer
,
1336 (int)ATTR_LENGTH(attr
.za_first_integer
),
1337 (int)ATTR_BSWAP(attr
.za_first_integer
),
1338 (int)ATTR_NUM(attr
.za_first_integer
));
1340 zap_cursor_fini(&zc
);
1344 dump_sa_layouts(objset_t
*os
, uint64_t object
, void *data
, size_t size
)
1346 (void) data
, (void) size
;
1348 zap_attribute_t attr
;
1349 uint16_t *layout_attrs
;
1352 dump_zap_stats(os
, object
);
1353 (void) printf("\n");
1355 for (zap_cursor_init(&zc
, os
, object
);
1356 zap_cursor_retrieve(&zc
, &attr
) == 0;
1357 zap_cursor_advance(&zc
)) {
1358 (void) printf("\t\t%s = [", attr
.za_name
);
1359 if (attr
.za_num_integers
== 0) {
1360 (void) printf("\n");
1364 VERIFY(attr
.za_integer_length
== 2);
1365 layout_attrs
= umem_zalloc(attr
.za_num_integers
*
1366 attr
.za_integer_length
, UMEM_NOFAIL
);
1368 VERIFY(zap_lookup(os
, object
, attr
.za_name
,
1369 attr
.za_integer_length
,
1370 attr
.za_num_integers
, layout_attrs
) == 0);
1372 for (i
= 0; i
!= attr
.za_num_integers
; i
++)
1373 (void) printf(" %d ", (int)layout_attrs
[i
]);
1374 (void) printf("]\n");
1375 umem_free(layout_attrs
,
1376 attr
.za_num_integers
* attr
.za_integer_length
);
1378 zap_cursor_fini(&zc
);
1382 dump_zpldir(objset_t
*os
, uint64_t object
, void *data
, size_t size
)
1384 (void) data
, (void) size
;
1386 zap_attribute_t attr
;
1387 const char *typenames
[] = {
1388 /* 0 */ "not specified",
1390 /* 2 */ "Character Device",
1391 /* 3 */ "3 (invalid)",
1392 /* 4 */ "Directory",
1393 /* 5 */ "5 (invalid)",
1394 /* 6 */ "Block Device",
1395 /* 7 */ "7 (invalid)",
1396 /* 8 */ "Regular File",
1397 /* 9 */ "9 (invalid)",
1398 /* 10 */ "Symbolic Link",
1399 /* 11 */ "11 (invalid)",
1402 /* 14 */ "Event Port",
1403 /* 15 */ "15 (invalid)",
1406 dump_zap_stats(os
, object
);
1407 (void) printf("\n");
1409 for (zap_cursor_init(&zc
, os
, object
);
1410 zap_cursor_retrieve(&zc
, &attr
) == 0;
1411 zap_cursor_advance(&zc
)) {
1412 (void) printf("\t\t%s = %lld (type: %s)\n",
1413 attr
.za_name
, ZFS_DIRENT_OBJ(attr
.za_first_integer
),
1414 typenames
[ZFS_DIRENT_TYPE(attr
.za_first_integer
)]);
1416 zap_cursor_fini(&zc
);
1420 get_dtl_refcount(vdev_t
*vd
)
1424 if (vd
->vdev_ops
->vdev_op_leaf
) {
1425 space_map_t
*sm
= vd
->vdev_dtl_sm
;
1428 sm
->sm_dbuf
->db_size
== sizeof (space_map_phys_t
))
1433 for (unsigned c
= 0; c
< vd
->vdev_children
; c
++)
1434 refcount
+= get_dtl_refcount(vd
->vdev_child
[c
]);
1439 get_metaslab_refcount(vdev_t
*vd
)
1443 if (vd
->vdev_top
== vd
) {
1444 for (uint64_t m
= 0; m
< vd
->vdev_ms_count
; m
++) {
1445 space_map_t
*sm
= vd
->vdev_ms
[m
]->ms_sm
;
1448 sm
->sm_dbuf
->db_size
== sizeof (space_map_phys_t
))
1452 for (unsigned c
= 0; c
< vd
->vdev_children
; c
++)
1453 refcount
+= get_metaslab_refcount(vd
->vdev_child
[c
]);
1459 get_obsolete_refcount(vdev_t
*vd
)
1461 uint64_t obsolete_sm_object
;
1464 VERIFY0(vdev_obsolete_sm_object(vd
, &obsolete_sm_object
));
1465 if (vd
->vdev_top
== vd
&& obsolete_sm_object
!= 0) {
1466 dmu_object_info_t doi
;
1467 VERIFY0(dmu_object_info(vd
->vdev_spa
->spa_meta_objset
,
1468 obsolete_sm_object
, &doi
));
1469 if (doi
.doi_bonus_size
== sizeof (space_map_phys_t
)) {
1473 ASSERT3P(vd
->vdev_obsolete_sm
, ==, NULL
);
1474 ASSERT3U(obsolete_sm_object
, ==, 0);
1476 for (unsigned c
= 0; c
< vd
->vdev_children
; c
++) {
1477 refcount
+= get_obsolete_refcount(vd
->vdev_child
[c
]);
1484 get_prev_obsolete_spacemap_refcount(spa_t
*spa
)
1487 spa
->spa_condensing_indirect_phys
.scip_prev_obsolete_sm_object
;
1488 if (prev_obj
!= 0) {
1489 dmu_object_info_t doi
;
1490 VERIFY0(dmu_object_info(spa
->spa_meta_objset
, prev_obj
, &doi
));
1491 if (doi
.doi_bonus_size
== sizeof (space_map_phys_t
)) {
1499 get_checkpoint_refcount(vdev_t
*vd
)
1503 if (vd
->vdev_top
== vd
&& vd
->vdev_top_zap
!= 0 &&
1504 zap_contains(spa_meta_objset(vd
->vdev_spa
),
1505 vd
->vdev_top_zap
, VDEV_TOP_ZAP_POOL_CHECKPOINT_SM
) == 0)
1508 for (uint64_t c
= 0; c
< vd
->vdev_children
; c
++)
1509 refcount
+= get_checkpoint_refcount(vd
->vdev_child
[c
]);
1515 get_log_spacemap_refcount(spa_t
*spa
)
1517 return (avl_numnodes(&spa
->spa_sm_logs_by_txg
));
1521 verify_spacemap_refcounts(spa_t
*spa
)
1523 uint64_t expected_refcount
= 0;
1524 uint64_t actual_refcount
;
1526 (void) feature_get_refcount(spa
,
1527 &spa_feature_table
[SPA_FEATURE_SPACEMAP_HISTOGRAM
],
1528 &expected_refcount
);
1529 actual_refcount
= get_dtl_refcount(spa
->spa_root_vdev
);
1530 actual_refcount
+= get_metaslab_refcount(spa
->spa_root_vdev
);
1531 actual_refcount
+= get_obsolete_refcount(spa
->spa_root_vdev
);
1532 actual_refcount
+= get_prev_obsolete_spacemap_refcount(spa
);
1533 actual_refcount
+= get_checkpoint_refcount(spa
->spa_root_vdev
);
1534 actual_refcount
+= get_log_spacemap_refcount(spa
);
1536 if (expected_refcount
!= actual_refcount
) {
1537 (void) printf("space map refcount mismatch: expected %lld != "
1539 (longlong_t
)expected_refcount
,
1540 (longlong_t
)actual_refcount
);
1547 dump_spacemap(objset_t
*os
, space_map_t
*sm
)
1549 const char *ddata
[] = { "ALLOC", "FREE", "CONDENSE", "INVALID",
1550 "INVALID", "INVALID", "INVALID", "INVALID" };
1555 (void) printf("space map object %llu:\n",
1556 (longlong_t
)sm
->sm_object
);
1557 (void) printf(" smp_length = 0x%llx\n",
1558 (longlong_t
)sm
->sm_phys
->smp_length
);
1559 (void) printf(" smp_alloc = 0x%llx\n",
1560 (longlong_t
)sm
->sm_phys
->smp_alloc
);
1562 if (dump_opt
['d'] < 6 && dump_opt
['m'] < 4)
1566 * Print out the freelist entries in both encoded and decoded form.
1568 uint8_t mapshift
= sm
->sm_shift
;
1570 uint64_t word
, entry_id
= 0;
1571 for (uint64_t offset
= 0; offset
< space_map_length(sm
);
1572 offset
+= sizeof (word
)) {
1574 VERIFY0(dmu_read(os
, space_map_object(sm
), offset
,
1575 sizeof (word
), &word
, DMU_READ_PREFETCH
));
1577 if (sm_entry_is_debug(word
)) {
1578 uint64_t de_txg
= SM_DEBUG_TXG_DECODE(word
);
1579 uint64_t de_sync_pass
= SM_DEBUG_SYNCPASS_DECODE(word
);
1582 "\t [%6llu] PADDING\n",
1583 (u_longlong_t
)entry_id
);
1586 "\t [%6llu] %s: txg %llu pass %llu\n",
1587 (u_longlong_t
)entry_id
,
1588 ddata
[SM_DEBUG_ACTION_DECODE(word
)],
1589 (u_longlong_t
)de_txg
,
1590 (u_longlong_t
)de_sync_pass
);
1598 uint64_t entry_off
, entry_run
, entry_vdev
= SM_NO_VDEVID
;
1600 if (sm_entry_is_single_word(word
)) {
1601 entry_type
= (SM_TYPE_DECODE(word
) == SM_ALLOC
) ?
1603 entry_off
= (SM_OFFSET_DECODE(word
) << mapshift
) +
1605 entry_run
= SM_RUN_DECODE(word
) << mapshift
;
1608 /* it is a two-word entry so we read another word */
1609 ASSERT(sm_entry_is_double_word(word
));
1611 uint64_t extra_word
;
1612 offset
+= sizeof (extra_word
);
1613 VERIFY0(dmu_read(os
, space_map_object(sm
), offset
,
1614 sizeof (extra_word
), &extra_word
,
1615 DMU_READ_PREFETCH
));
1617 ASSERT3U(offset
, <=, space_map_length(sm
));
1619 entry_run
= SM2_RUN_DECODE(word
) << mapshift
;
1620 entry_vdev
= SM2_VDEV_DECODE(word
);
1621 entry_type
= (SM2_TYPE_DECODE(extra_word
) == SM_ALLOC
) ?
1623 entry_off
= (SM2_OFFSET_DECODE(extra_word
) <<
1624 mapshift
) + sm
->sm_start
;
1628 (void) printf("\t [%6llu] %c range:"
1629 " %010llx-%010llx size: %06llx vdev: %06llu words: %u\n",
1630 (u_longlong_t
)entry_id
,
1631 entry_type
, (u_longlong_t
)entry_off
,
1632 (u_longlong_t
)(entry_off
+ entry_run
),
1633 (u_longlong_t
)entry_run
,
1634 (u_longlong_t
)entry_vdev
, words
);
1636 if (entry_type
== 'A')
1642 if (alloc
!= space_map_allocated(sm
)) {
1643 (void) printf("space_map_object alloc (%lld) INCONSISTENT "
1644 "with space map summary (%lld)\n",
1645 (longlong_t
)space_map_allocated(sm
), (longlong_t
)alloc
);
1650 dump_metaslab_stats(metaslab_t
*msp
)
1653 range_tree_t
*rt
= msp
->ms_allocatable
;
1654 zfs_btree_t
*t
= &msp
->ms_allocatable_by_size
;
1655 int free_pct
= range_tree_space(rt
) * 100 / msp
->ms_size
;
1657 /* max sure nicenum has enough space */
1658 _Static_assert(sizeof (maxbuf
) >= NN_NUMBUF_SZ
, "maxbuf truncated");
1660 zdb_nicenum(metaslab_largest_allocatable(msp
), maxbuf
, sizeof (maxbuf
));
1662 (void) printf("\t %25s %10lu %7s %6s %4s %4d%%\n",
1663 "segments", zfs_btree_numnodes(t
), "maxsize", maxbuf
,
1664 "freepct", free_pct
);
1665 (void) printf("\tIn-memory histogram:\n");
1666 dump_histogram(rt
->rt_histogram
, RANGE_TREE_HISTOGRAM_SIZE
, 0);
1670 dump_metaslab(metaslab_t
*msp
)
1672 vdev_t
*vd
= msp
->ms_group
->mg_vd
;
1673 spa_t
*spa
= vd
->vdev_spa
;
1674 space_map_t
*sm
= msp
->ms_sm
;
1677 zdb_nicenum(msp
->ms_size
- space_map_allocated(sm
), freebuf
,
1681 "\tmetaslab %6llu offset %12llx spacemap %6llu free %5s\n",
1682 (u_longlong_t
)msp
->ms_id
, (u_longlong_t
)msp
->ms_start
,
1683 (u_longlong_t
)space_map_object(sm
), freebuf
);
1685 if (dump_opt
['m'] > 2 && !dump_opt
['L']) {
1686 mutex_enter(&msp
->ms_lock
);
1687 VERIFY0(metaslab_load(msp
));
1688 range_tree_stat_verify(msp
->ms_allocatable
);
1689 dump_metaslab_stats(msp
);
1690 metaslab_unload(msp
);
1691 mutex_exit(&msp
->ms_lock
);
1694 if (dump_opt
['m'] > 1 && sm
!= NULL
&&
1695 spa_feature_is_active(spa
, SPA_FEATURE_SPACEMAP_HISTOGRAM
)) {
1697 * The space map histogram represents free space in chunks
1698 * of sm_shift (i.e. bucket 0 refers to 2^sm_shift).
1700 (void) printf("\tOn-disk histogram:\t\tfragmentation %llu\n",
1701 (u_longlong_t
)msp
->ms_fragmentation
);
1702 dump_histogram(sm
->sm_phys
->smp_histogram
,
1703 SPACE_MAP_HISTOGRAM_SIZE
, sm
->sm_shift
);
1706 if (vd
->vdev_ops
== &vdev_draid_ops
)
1707 ASSERT3U(msp
->ms_size
, <=, 1ULL << vd
->vdev_ms_shift
);
1709 ASSERT3U(msp
->ms_size
, ==, 1ULL << vd
->vdev_ms_shift
);
1711 dump_spacemap(spa
->spa_meta_objset
, msp
->ms_sm
);
1713 if (spa_feature_is_active(spa
, SPA_FEATURE_LOG_SPACEMAP
)) {
1714 (void) printf("\tFlush data:\n\tunflushed txg=%llu\n\n",
1715 (u_longlong_t
)metaslab_unflushed_txg(msp
));
1720 print_vdev_metaslab_header(vdev_t
*vd
)
1722 vdev_alloc_bias_t alloc_bias
= vd
->vdev_alloc_bias
;
1723 const char *bias_str
= "";
1724 if (alloc_bias
== VDEV_BIAS_LOG
|| vd
->vdev_islog
) {
1725 bias_str
= VDEV_ALLOC_BIAS_LOG
;
1726 } else if (alloc_bias
== VDEV_BIAS_SPECIAL
) {
1727 bias_str
= VDEV_ALLOC_BIAS_SPECIAL
;
1728 } else if (alloc_bias
== VDEV_BIAS_DEDUP
) {
1729 bias_str
= VDEV_ALLOC_BIAS_DEDUP
;
1732 uint64_t ms_flush_data_obj
= 0;
1733 if (vd
->vdev_top_zap
!= 0) {
1734 int error
= zap_lookup(spa_meta_objset(vd
->vdev_spa
),
1735 vd
->vdev_top_zap
, VDEV_TOP_ZAP_MS_UNFLUSHED_PHYS_TXGS
,
1736 sizeof (uint64_t), 1, &ms_flush_data_obj
);
1737 if (error
!= ENOENT
) {
1742 (void) printf("\tvdev %10llu %s",
1743 (u_longlong_t
)vd
->vdev_id
, bias_str
);
1745 if (ms_flush_data_obj
!= 0) {
1746 (void) printf(" ms_unflushed_phys object %llu",
1747 (u_longlong_t
)ms_flush_data_obj
);
1750 (void) printf("\n\t%-10s%5llu %-19s %-15s %-12s\n",
1751 "metaslabs", (u_longlong_t
)vd
->vdev_ms_count
,
1752 "offset", "spacemap", "free");
1753 (void) printf("\t%15s %19s %15s %12s\n",
1754 "---------------", "-------------------",
1755 "---------------", "------------");
1759 dump_metaslab_groups(spa_t
*spa
, boolean_t show_special
)
1761 vdev_t
*rvd
= spa
->spa_root_vdev
;
1762 metaslab_class_t
*mc
= spa_normal_class(spa
);
1763 metaslab_class_t
*smc
= spa_special_class(spa
);
1764 uint64_t fragmentation
;
1766 metaslab_class_histogram_verify(mc
);
1768 for (unsigned c
= 0; c
< rvd
->vdev_children
; c
++) {
1769 vdev_t
*tvd
= rvd
->vdev_child
[c
];
1770 metaslab_group_t
*mg
= tvd
->vdev_mg
;
1772 if (mg
== NULL
|| (mg
->mg_class
!= mc
&&
1773 (!show_special
|| mg
->mg_class
!= smc
)))
1776 metaslab_group_histogram_verify(mg
);
1777 mg
->mg_fragmentation
= metaslab_group_fragmentation(mg
);
1779 (void) printf("\tvdev %10llu\t\tmetaslabs%5llu\t\t"
1781 (u_longlong_t
)tvd
->vdev_id
,
1782 (u_longlong_t
)tvd
->vdev_ms_count
);
1783 if (mg
->mg_fragmentation
== ZFS_FRAG_INVALID
) {
1784 (void) printf("%3s\n", "-");
1786 (void) printf("%3llu%%\n",
1787 (u_longlong_t
)mg
->mg_fragmentation
);
1789 dump_histogram(mg
->mg_histogram
, RANGE_TREE_HISTOGRAM_SIZE
, 0);
1792 (void) printf("\tpool %s\tfragmentation", spa_name(spa
));
1793 fragmentation
= metaslab_class_fragmentation(mc
);
1794 if (fragmentation
== ZFS_FRAG_INVALID
)
1795 (void) printf("\t%3s\n", "-");
1797 (void) printf("\t%3llu%%\n", (u_longlong_t
)fragmentation
);
1798 dump_histogram(mc
->mc_histogram
, RANGE_TREE_HISTOGRAM_SIZE
, 0);
1802 print_vdev_indirect(vdev_t
*vd
)
1804 vdev_indirect_config_t
*vic
= &vd
->vdev_indirect_config
;
1805 vdev_indirect_mapping_t
*vim
= vd
->vdev_indirect_mapping
;
1806 vdev_indirect_births_t
*vib
= vd
->vdev_indirect_births
;
1809 ASSERT3P(vib
, ==, NULL
);
1813 ASSERT3U(vdev_indirect_mapping_object(vim
), ==,
1814 vic
->vic_mapping_object
);
1815 ASSERT3U(vdev_indirect_births_object(vib
), ==,
1816 vic
->vic_births_object
);
1818 (void) printf("indirect births obj %llu:\n",
1819 (longlong_t
)vic
->vic_births_object
);
1820 (void) printf(" vib_count = %llu\n",
1821 (longlong_t
)vdev_indirect_births_count(vib
));
1822 for (uint64_t i
= 0; i
< vdev_indirect_births_count(vib
); i
++) {
1823 vdev_indirect_birth_entry_phys_t
*cur_vibe
=
1824 &vib
->vib_entries
[i
];
1825 (void) printf("\toffset %llx -> txg %llu\n",
1826 (longlong_t
)cur_vibe
->vibe_offset
,
1827 (longlong_t
)cur_vibe
->vibe_phys_birth_txg
);
1829 (void) printf("\n");
1831 (void) printf("indirect mapping obj %llu:\n",
1832 (longlong_t
)vic
->vic_mapping_object
);
1833 (void) printf(" vim_max_offset = 0x%llx\n",
1834 (longlong_t
)vdev_indirect_mapping_max_offset(vim
));
1835 (void) printf(" vim_bytes_mapped = 0x%llx\n",
1836 (longlong_t
)vdev_indirect_mapping_bytes_mapped(vim
));
1837 (void) printf(" vim_count = %llu\n",
1838 (longlong_t
)vdev_indirect_mapping_num_entries(vim
));
1840 if (dump_opt
['d'] <= 5 && dump_opt
['m'] <= 3)
1843 uint32_t *counts
= vdev_indirect_mapping_load_obsolete_counts(vim
);
1845 for (uint64_t i
= 0; i
< vdev_indirect_mapping_num_entries(vim
); i
++) {
1846 vdev_indirect_mapping_entry_phys_t
*vimep
=
1847 &vim
->vim_entries
[i
];
1848 (void) printf("\t<%llx:%llx:%llx> -> "
1849 "<%llx:%llx:%llx> (%x obsolete)\n",
1850 (longlong_t
)vd
->vdev_id
,
1851 (longlong_t
)DVA_MAPPING_GET_SRC_OFFSET(vimep
),
1852 (longlong_t
)DVA_GET_ASIZE(&vimep
->vimep_dst
),
1853 (longlong_t
)DVA_GET_VDEV(&vimep
->vimep_dst
),
1854 (longlong_t
)DVA_GET_OFFSET(&vimep
->vimep_dst
),
1855 (longlong_t
)DVA_GET_ASIZE(&vimep
->vimep_dst
),
1858 (void) printf("\n");
1860 uint64_t obsolete_sm_object
;
1861 VERIFY0(vdev_obsolete_sm_object(vd
, &obsolete_sm_object
));
1862 if (obsolete_sm_object
!= 0) {
1863 objset_t
*mos
= vd
->vdev_spa
->spa_meta_objset
;
1864 (void) printf("obsolete space map object %llu:\n",
1865 (u_longlong_t
)obsolete_sm_object
);
1866 ASSERT(vd
->vdev_obsolete_sm
!= NULL
);
1867 ASSERT3U(space_map_object(vd
->vdev_obsolete_sm
), ==,
1868 obsolete_sm_object
);
1869 dump_spacemap(mos
, vd
->vdev_obsolete_sm
);
1870 (void) printf("\n");
1875 dump_metaslabs(spa_t
*spa
)
1877 vdev_t
*vd
, *rvd
= spa
->spa_root_vdev
;
1878 uint64_t m
, c
= 0, children
= rvd
->vdev_children
;
1880 (void) printf("\nMetaslabs:\n");
1882 if (!dump_opt
['d'] && zopt_metaslab_args
> 0) {
1883 c
= zopt_metaslab
[0];
1886 (void) fatal("bad vdev id: %llu", (u_longlong_t
)c
);
1888 if (zopt_metaslab_args
> 1) {
1889 vd
= rvd
->vdev_child
[c
];
1890 print_vdev_metaslab_header(vd
);
1892 for (m
= 1; m
< zopt_metaslab_args
; m
++) {
1893 if (zopt_metaslab
[m
] < vd
->vdev_ms_count
)
1895 vd
->vdev_ms
[zopt_metaslab
[m
]]);
1897 (void) fprintf(stderr
, "bad metaslab "
1899 (u_longlong_t
)zopt_metaslab
[m
]);
1901 (void) printf("\n");
1906 for (; c
< children
; c
++) {
1907 vd
= rvd
->vdev_child
[c
];
1908 print_vdev_metaslab_header(vd
);
1910 print_vdev_indirect(vd
);
1912 for (m
= 0; m
< vd
->vdev_ms_count
; m
++)
1913 dump_metaslab(vd
->vdev_ms
[m
]);
1914 (void) printf("\n");
1919 dump_log_spacemaps(spa_t
*spa
)
1921 if (!spa_feature_is_active(spa
, SPA_FEATURE_LOG_SPACEMAP
))
1924 (void) printf("\nLog Space Maps in Pool:\n");
1925 for (spa_log_sm_t
*sls
= avl_first(&spa
->spa_sm_logs_by_txg
);
1926 sls
; sls
= AVL_NEXT(&spa
->spa_sm_logs_by_txg
, sls
)) {
1927 space_map_t
*sm
= NULL
;
1928 VERIFY0(space_map_open(&sm
, spa_meta_objset(spa
),
1929 sls
->sls_sm_obj
, 0, UINT64_MAX
, SPA_MINBLOCKSHIFT
));
1931 (void) printf("Log Spacemap object %llu txg %llu\n",
1932 (u_longlong_t
)sls
->sls_sm_obj
, (u_longlong_t
)sls
->sls_txg
);
1933 dump_spacemap(spa
->spa_meta_objset
, sm
);
1934 space_map_close(sm
);
1936 (void) printf("\n");
1940 dump_dde(const ddt_t
*ddt
, const ddt_entry_t
*dde
, uint64_t index
)
1942 const ddt_phys_t
*ddp
= dde
->dde_phys
;
1943 const ddt_key_t
*ddk
= &dde
->dde_key
;
1944 const char *types
[4] = { "ditto", "single", "double", "triple" };
1945 char blkbuf
[BP_SPRINTF_LEN
];
1949 for (p
= 0; p
< DDT_PHYS_TYPES
; p
++, ddp
++) {
1950 if (ddp
->ddp_phys_birth
== 0)
1952 ddt_bp_create(ddt
->ddt_checksum
, ddk
, ddp
, &blk
);
1953 snprintf_blkptr(blkbuf
, sizeof (blkbuf
), &blk
);
1954 (void) printf("index %llx refcnt %llu %s %s\n",
1955 (u_longlong_t
)index
, (u_longlong_t
)ddp
->ddp_refcnt
,
1961 dump_dedup_ratio(const ddt_stat_t
*dds
)
1963 double rL
, rP
, rD
, D
, dedup
, compress
, copies
;
1965 if (dds
->dds_blocks
== 0)
1968 rL
= (double)dds
->dds_ref_lsize
;
1969 rP
= (double)dds
->dds_ref_psize
;
1970 rD
= (double)dds
->dds_ref_dsize
;
1971 D
= (double)dds
->dds_dsize
;
1977 (void) printf("dedup = %.2f, compress = %.2f, copies = %.2f, "
1978 "dedup * compress / copies = %.2f\n\n",
1979 dedup
, compress
, copies
, dedup
* compress
/ copies
);
1983 dump_ddt(ddt_t
*ddt
, enum ddt_type type
, enum ddt_class
class)
1985 char name
[DDT_NAMELEN
];
1988 dmu_object_info_t doi
;
1989 uint64_t count
, dspace
, mspace
;
1992 error
= ddt_object_info(ddt
, type
, class, &doi
);
1994 if (error
== ENOENT
)
1998 error
= ddt_object_count(ddt
, type
, class, &count
);
2003 dspace
= doi
.doi_physical_blocks_512
<< 9;
2004 mspace
= doi
.doi_fill_count
* doi
.doi_data_block_size
;
2006 ddt_object_name(ddt
, type
, class, name
);
2008 (void) printf("%s: %llu entries, size %llu on disk, %llu in core\n",
2010 (u_longlong_t
)count
,
2011 (u_longlong_t
)(dspace
/ count
),
2012 (u_longlong_t
)(mspace
/ count
));
2014 if (dump_opt
['D'] < 3)
2017 zpool_dump_ddt(NULL
, &ddt
->ddt_histogram
[type
][class]);
2019 if (dump_opt
['D'] < 4)
2022 if (dump_opt
['D'] < 5 && class == DDT_CLASS_UNIQUE
)
2025 (void) printf("%s contents:\n\n", name
);
2027 while ((error
= ddt_object_walk(ddt
, type
, class, &walk
, &dde
)) == 0)
2028 dump_dde(ddt
, &dde
, walk
);
2030 ASSERT3U(error
, ==, ENOENT
);
2032 (void) printf("\n");
2036 dump_all_ddts(spa_t
*spa
)
2038 ddt_histogram_t ddh_total
;
2039 ddt_stat_t dds_total
;
2041 bzero(&ddh_total
, sizeof (ddh_total
));
2042 bzero(&dds_total
, sizeof (dds_total
));
2044 for (enum zio_checksum c
= 0; c
< ZIO_CHECKSUM_FUNCTIONS
; c
++) {
2045 ddt_t
*ddt
= spa
->spa_ddt
[c
];
2046 for (enum ddt_type type
= 0; type
< DDT_TYPES
; type
++) {
2047 for (enum ddt_class
class = 0; class < DDT_CLASSES
;
2049 dump_ddt(ddt
, type
, class);
2054 ddt_get_dedup_stats(spa
, &dds_total
);
2056 if (dds_total
.dds_blocks
== 0) {
2057 (void) printf("All DDTs are empty\n");
2061 (void) printf("\n");
2063 if (dump_opt
['D'] > 1) {
2064 (void) printf("DDT histogram (aggregated over all DDTs):\n");
2065 ddt_get_dedup_histogram(spa
, &ddh_total
);
2066 zpool_dump_ddt(&dds_total
, &ddh_total
);
2069 dump_dedup_ratio(&dds_total
);
2073 dump_dtl_seg(void *arg
, uint64_t start
, uint64_t size
)
2077 (void) printf("%s [%llu,%llu) length %llu\n",
2079 (u_longlong_t
)start
,
2080 (u_longlong_t
)(start
+ size
),
2081 (u_longlong_t
)(size
));
2085 dump_dtl(vdev_t
*vd
, int indent
)
2087 spa_t
*spa
= vd
->vdev_spa
;
2089 const char *name
[DTL_TYPES
] = { "missing", "partial", "scrub",
2093 spa_vdev_state_enter(spa
, SCL_NONE
);
2094 required
= vdev_dtl_required(vd
);
2095 (void) spa_vdev_state_exit(spa
, NULL
, 0);
2098 (void) printf("\nDirty time logs:\n\n");
2100 (void) printf("\t%*s%s [%s]\n", indent
, "",
2101 vd
->vdev_path
? vd
->vdev_path
:
2102 vd
->vdev_parent
? vd
->vdev_ops
->vdev_op_type
: spa_name(spa
),
2103 required
? "DTL-required" : "DTL-expendable");
2105 for (int t
= 0; t
< DTL_TYPES
; t
++) {
2106 range_tree_t
*rt
= vd
->vdev_dtl
[t
];
2107 if (range_tree_space(rt
) == 0)
2109 (void) snprintf(prefix
, sizeof (prefix
), "\t%*s%s",
2110 indent
+ 2, "", name
[t
]);
2111 range_tree_walk(rt
, dump_dtl_seg
, prefix
);
2112 if (dump_opt
['d'] > 5 && vd
->vdev_children
== 0)
2113 dump_spacemap(spa
->spa_meta_objset
,
2117 for (unsigned c
= 0; c
< vd
->vdev_children
; c
++)
2118 dump_dtl(vd
->vdev_child
[c
], indent
+ 4);
2122 dump_history(spa_t
*spa
)
2124 nvlist_t
**events
= NULL
;
2126 uint64_t resid
, len
, off
= 0;
2131 if ((buf
= malloc(SPA_OLD_MAXBLOCKSIZE
)) == NULL
) {
2132 (void) fprintf(stderr
, "%s: unable to allocate I/O buffer\n",
2138 len
= SPA_OLD_MAXBLOCKSIZE
;
2140 if ((error
= spa_history_get(spa
, &off
, &len
, buf
)) != 0) {
2141 (void) fprintf(stderr
, "Unable to read history: "
2142 "error %d\n", error
);
2147 if (zpool_history_unpack(buf
, len
, &resid
, &events
, &num
) != 0)
2153 (void) printf("\nHistory:\n");
2154 for (unsigned i
= 0; i
< num
; i
++) {
2155 boolean_t printed
= B_FALSE
;
2157 if (nvlist_exists(events
[i
], ZPOOL_HIST_TIME
)) {
2161 tsec
= fnvlist_lookup_uint64(events
[i
],
2163 (void) localtime_r(&tsec
, &t
);
2164 (void) strftime(tbuf
, sizeof (tbuf
), "%F.%T", &t
);
2169 if (nvlist_exists(events
[i
], ZPOOL_HIST_CMD
)) {
2170 (void) printf("%s %s\n", tbuf
,
2171 fnvlist_lookup_string(events
[i
], ZPOOL_HIST_CMD
));
2172 } else if (nvlist_exists(events
[i
], ZPOOL_HIST_INT_EVENT
)) {
2175 ievent
= fnvlist_lookup_uint64(events
[i
],
2176 ZPOOL_HIST_INT_EVENT
);
2177 if (ievent
>= ZFS_NUM_LEGACY_HISTORY_EVENTS
)
2180 (void) printf(" %s [internal %s txg:%ju] %s\n",
2182 zfs_history_event_names
[ievent
],
2183 fnvlist_lookup_uint64(events
[i
],
2185 fnvlist_lookup_string(events
[i
],
2186 ZPOOL_HIST_INT_STR
));
2187 } else if (nvlist_exists(events
[i
], ZPOOL_HIST_INT_NAME
)) {
2188 (void) printf("%s [txg:%ju] %s", tbuf
,
2189 fnvlist_lookup_uint64(events
[i
],
2191 fnvlist_lookup_string(events
[i
],
2192 ZPOOL_HIST_INT_NAME
));
2194 if (nvlist_exists(events
[i
], ZPOOL_HIST_DSNAME
)) {
2195 (void) printf(" %s (%llu)",
2196 fnvlist_lookup_string(events
[i
],
2198 (u_longlong_t
)fnvlist_lookup_uint64(
2203 (void) printf(" %s\n", fnvlist_lookup_string(events
[i
],
2204 ZPOOL_HIST_INT_STR
));
2205 } else if (nvlist_exists(events
[i
], ZPOOL_HIST_IOCTL
)) {
2206 (void) printf("%s ioctl %s\n", tbuf
,
2207 fnvlist_lookup_string(events
[i
],
2210 if (nvlist_exists(events
[i
], ZPOOL_HIST_INPUT_NVL
)) {
2211 (void) printf(" input:\n");
2212 dump_nvlist(fnvlist_lookup_nvlist(events
[i
],
2213 ZPOOL_HIST_INPUT_NVL
), 8);
2215 if (nvlist_exists(events
[i
], ZPOOL_HIST_OUTPUT_NVL
)) {
2216 (void) printf(" output:\n");
2217 dump_nvlist(fnvlist_lookup_nvlist(events
[i
],
2218 ZPOOL_HIST_OUTPUT_NVL
), 8);
2220 if (nvlist_exists(events
[i
], ZPOOL_HIST_ERRNO
)) {
2221 (void) printf(" errno: %lld\n",
2222 (longlong_t
)fnvlist_lookup_int64(events
[i
],
2231 if (dump_opt
['h'] > 1) {
2233 (void) printf("unrecognized record:\n");
2234 dump_nvlist(events
[i
], 2);
2241 dump_dnode(objset_t
*os
, uint64_t object
, void *data
, size_t size
)
2243 (void) os
, (void) object
, (void) data
, (void) size
;
2247 blkid2offset(const dnode_phys_t
*dnp
, const blkptr_t
*bp
,
2248 const zbookmark_phys_t
*zb
)
2251 ASSERT(zb
->zb_level
< 0);
2252 if (zb
->zb_object
== 0)
2253 return (zb
->zb_blkid
);
2254 return (zb
->zb_blkid
* BP_GET_LSIZE(bp
));
2257 ASSERT(zb
->zb_level
>= 0);
2259 return ((zb
->zb_blkid
<<
2260 (zb
->zb_level
* (dnp
->dn_indblkshift
- SPA_BLKPTRSHIFT
))) *
2261 dnp
->dn_datablkszsec
<< SPA_MINBLOCKSHIFT
);
2265 snprintf_zstd_header(spa_t
*spa
, char *blkbuf
, size_t buflen
,
2271 zfs_zstdhdr_t zstd_hdr
;
2274 if (BP_GET_COMPRESS(bp
) != ZIO_COMPRESS_ZSTD
)
2280 if (BP_IS_EMBEDDED(bp
)) {
2281 buf
= malloc(SPA_MAXBLOCKSIZE
);
2283 (void) fprintf(stderr
, "out of memory\n");
2286 decode_embedded_bp_compressed(bp
, buf
);
2287 memcpy(&zstd_hdr
, buf
, sizeof (zstd_hdr
));
2289 zstd_hdr
.c_len
= BE_32(zstd_hdr
.c_len
);
2290 zstd_hdr
.raw_version_level
= BE_32(zstd_hdr
.raw_version_level
);
2291 (void) snprintf(blkbuf
+ strlen(blkbuf
),
2292 buflen
- strlen(blkbuf
),
2293 " ZSTD:size=%u:version=%u:level=%u:EMBEDDED",
2294 zstd_hdr
.c_len
, zfs_get_hdrversion(&zstd_hdr
),
2295 zfs_get_hdrlevel(&zstd_hdr
));
2299 pabd
= abd_alloc_for_io(SPA_MAXBLOCKSIZE
, B_FALSE
);
2300 zio
= zio_root(spa
, NULL
, NULL
, 0);
2302 /* Decrypt but don't decompress so we can read the compression header */
2303 zio_nowait(zio_read(zio
, spa
, bp
, pabd
, BP_GET_PSIZE(bp
), NULL
, NULL
,
2304 ZIO_PRIORITY_SYNC_READ
, ZIO_FLAG_CANFAIL
| ZIO_FLAG_RAW_COMPRESS
,
2306 error
= zio_wait(zio
);
2308 (void) fprintf(stderr
, "read failed: %d\n", error
);
2311 buf
= abd_borrow_buf_copy(pabd
, BP_GET_LSIZE(bp
));
2312 memcpy(&zstd_hdr
, buf
, sizeof (zstd_hdr
));
2313 zstd_hdr
.c_len
= BE_32(zstd_hdr
.c_len
);
2314 zstd_hdr
.raw_version_level
= BE_32(zstd_hdr
.raw_version_level
);
2316 (void) snprintf(blkbuf
+ strlen(blkbuf
),
2317 buflen
- strlen(blkbuf
),
2318 " ZSTD:size=%u:version=%u:level=%u:NORMAL",
2319 zstd_hdr
.c_len
, zfs_get_hdrversion(&zstd_hdr
),
2320 zfs_get_hdrlevel(&zstd_hdr
));
2322 abd_return_buf_copy(pabd
, buf
, BP_GET_LSIZE(bp
));
2326 snprintf_blkptr_compact(char *blkbuf
, size_t buflen
, const blkptr_t
*bp
,
2329 const dva_t
*dva
= bp
->blk_dva
;
2330 int ndvas
= dump_opt
['d'] > 5 ? BP_GET_NDVAS(bp
) : 1;
2333 if (dump_opt
['b'] >= 6) {
2334 snprintf_blkptr(blkbuf
, buflen
, bp
);
2336 (void) snprintf(blkbuf
+ strlen(blkbuf
),
2337 buflen
- strlen(blkbuf
), " %s", "FREE");
2342 if (BP_IS_EMBEDDED(bp
)) {
2343 (void) sprintf(blkbuf
,
2344 "EMBEDDED et=%u %llxL/%llxP B=%llu",
2345 (int)BPE_GET_ETYPE(bp
),
2346 (u_longlong_t
)BPE_GET_LSIZE(bp
),
2347 (u_longlong_t
)BPE_GET_PSIZE(bp
),
2348 (u_longlong_t
)bp
->blk_birth
);
2354 for (i
= 0; i
< ndvas
; i
++)
2355 (void) snprintf(blkbuf
+ strlen(blkbuf
),
2356 buflen
- strlen(blkbuf
), "%llu:%llx:%llx ",
2357 (u_longlong_t
)DVA_GET_VDEV(&dva
[i
]),
2358 (u_longlong_t
)DVA_GET_OFFSET(&dva
[i
]),
2359 (u_longlong_t
)DVA_GET_ASIZE(&dva
[i
]));
2361 if (BP_IS_HOLE(bp
)) {
2362 (void) snprintf(blkbuf
+ strlen(blkbuf
),
2363 buflen
- strlen(blkbuf
),
2365 (u_longlong_t
)BP_GET_LSIZE(bp
),
2366 (u_longlong_t
)bp
->blk_birth
);
2368 (void) snprintf(blkbuf
+ strlen(blkbuf
),
2369 buflen
- strlen(blkbuf
),
2370 "%llxL/%llxP F=%llu B=%llu/%llu",
2371 (u_longlong_t
)BP_GET_LSIZE(bp
),
2372 (u_longlong_t
)BP_GET_PSIZE(bp
),
2373 (u_longlong_t
)BP_GET_FILL(bp
),
2374 (u_longlong_t
)bp
->blk_birth
,
2375 (u_longlong_t
)BP_PHYSICAL_BIRTH(bp
));
2377 (void) snprintf(blkbuf
+ strlen(blkbuf
),
2378 buflen
- strlen(blkbuf
), " %s", "FREE");
2379 (void) snprintf(blkbuf
+ strlen(blkbuf
),
2380 buflen
- strlen(blkbuf
), " cksum=%llx:%llx:%llx:%llx",
2381 (u_longlong_t
)bp
->blk_cksum
.zc_word
[0],
2382 (u_longlong_t
)bp
->blk_cksum
.zc_word
[1],
2383 (u_longlong_t
)bp
->blk_cksum
.zc_word
[2],
2384 (u_longlong_t
)bp
->blk_cksum
.zc_word
[3]);
2389 print_indirect(spa_t
*spa
, blkptr_t
*bp
, const zbookmark_phys_t
*zb
,
2390 const dnode_phys_t
*dnp
)
2392 char blkbuf
[BP_SPRINTF_LEN
];
2395 if (!BP_IS_EMBEDDED(bp
)) {
2396 ASSERT3U(BP_GET_TYPE(bp
), ==, dnp
->dn_type
);
2397 ASSERT3U(BP_GET_LEVEL(bp
), ==, zb
->zb_level
);
2400 (void) printf("%16llx ", (u_longlong_t
)blkid2offset(dnp
, bp
, zb
));
2402 ASSERT(zb
->zb_level
>= 0);
2404 for (l
= dnp
->dn_nlevels
- 1; l
>= -1; l
--) {
2405 if (l
== zb
->zb_level
) {
2406 (void) printf("L%llx", (u_longlong_t
)zb
->zb_level
);
2412 snprintf_blkptr_compact(blkbuf
, sizeof (blkbuf
), bp
, B_FALSE
);
2413 if (dump_opt
['Z'] && BP_GET_COMPRESS(bp
) == ZIO_COMPRESS_ZSTD
)
2414 snprintf_zstd_header(spa
, blkbuf
, sizeof (blkbuf
), bp
);
2415 (void) printf("%s\n", blkbuf
);
2419 visit_indirect(spa_t
*spa
, const dnode_phys_t
*dnp
,
2420 blkptr_t
*bp
, const zbookmark_phys_t
*zb
)
2424 if (bp
->blk_birth
== 0)
2427 print_indirect(spa
, bp
, zb
, dnp
);
2429 if (BP_GET_LEVEL(bp
) > 0 && !BP_IS_HOLE(bp
)) {
2430 arc_flags_t flags
= ARC_FLAG_WAIT
;
2433 int epb
= BP_GET_LSIZE(bp
) >> SPA_BLKPTRSHIFT
;
2436 ASSERT(!BP_IS_REDACTED(bp
));
2438 err
= arc_read(NULL
, spa
, bp
, arc_getbuf_func
, &buf
,
2439 ZIO_PRIORITY_ASYNC_READ
, ZIO_FLAG_CANFAIL
, &flags
, zb
);
2442 ASSERT(buf
->b_data
);
2444 /* recursively visit blocks below this */
2446 for (i
= 0; i
< epb
; i
++, cbp
++) {
2447 zbookmark_phys_t czb
;
2449 SET_BOOKMARK(&czb
, zb
->zb_objset
, zb
->zb_object
,
2451 zb
->zb_blkid
* epb
+ i
);
2452 err
= visit_indirect(spa
, dnp
, cbp
, &czb
);
2455 fill
+= BP_GET_FILL(cbp
);
2458 ASSERT3U(fill
, ==, BP_GET_FILL(bp
));
2459 arc_buf_destroy(buf
, &buf
);
2466 dump_indirect(dnode_t
*dn
)
2468 dnode_phys_t
*dnp
= dn
->dn_phys
;
2469 zbookmark_phys_t czb
;
2471 (void) printf("Indirect blocks:\n");
2473 SET_BOOKMARK(&czb
, dmu_objset_id(dn
->dn_objset
),
2474 dn
->dn_object
, dnp
->dn_nlevels
- 1, 0);
2475 for (int j
= 0; j
< dnp
->dn_nblkptr
; j
++) {
2477 (void) visit_indirect(dmu_objset_spa(dn
->dn_objset
), dnp
,
2478 &dnp
->dn_blkptr
[j
], &czb
);
2481 (void) printf("\n");
2485 dump_dsl_dir(objset_t
*os
, uint64_t object
, void *data
, size_t size
)
2487 (void) os
, (void) object
;
2488 dsl_dir_phys_t
*dd
= data
;
2492 /* make sure nicenum has enough space */
2493 _Static_assert(sizeof (nice
) >= NN_NUMBUF_SZ
, "nice truncated");
2498 ASSERT3U(size
, >=, sizeof (dsl_dir_phys_t
));
2500 crtime
= dd
->dd_creation_time
;
2501 (void) printf("\t\tcreation_time = %s", ctime(&crtime
));
2502 (void) printf("\t\thead_dataset_obj = %llu\n",
2503 (u_longlong_t
)dd
->dd_head_dataset_obj
);
2504 (void) printf("\t\tparent_dir_obj = %llu\n",
2505 (u_longlong_t
)dd
->dd_parent_obj
);
2506 (void) printf("\t\torigin_obj = %llu\n",
2507 (u_longlong_t
)dd
->dd_origin_obj
);
2508 (void) printf("\t\tchild_dir_zapobj = %llu\n",
2509 (u_longlong_t
)dd
->dd_child_dir_zapobj
);
2510 zdb_nicenum(dd
->dd_used_bytes
, nice
, sizeof (nice
));
2511 (void) printf("\t\tused_bytes = %s\n", nice
);
2512 zdb_nicenum(dd
->dd_compressed_bytes
, nice
, sizeof (nice
));
2513 (void) printf("\t\tcompressed_bytes = %s\n", nice
);
2514 zdb_nicenum(dd
->dd_uncompressed_bytes
, nice
, sizeof (nice
));
2515 (void) printf("\t\tuncompressed_bytes = %s\n", nice
);
2516 zdb_nicenum(dd
->dd_quota
, nice
, sizeof (nice
));
2517 (void) printf("\t\tquota = %s\n", nice
);
2518 zdb_nicenum(dd
->dd_reserved
, nice
, sizeof (nice
));
2519 (void) printf("\t\treserved = %s\n", nice
);
2520 (void) printf("\t\tprops_zapobj = %llu\n",
2521 (u_longlong_t
)dd
->dd_props_zapobj
);
2522 (void) printf("\t\tdeleg_zapobj = %llu\n",
2523 (u_longlong_t
)dd
->dd_deleg_zapobj
);
2524 (void) printf("\t\tflags = %llx\n",
2525 (u_longlong_t
)dd
->dd_flags
);
2528 zdb_nicenum(dd->dd_used_breakdown[DD_USED_ ## which], nice, \
2530 (void) printf("\t\tused_breakdown[" #which "] = %s\n", nice)
2537 (void) printf("\t\tclones = %llu\n",
2538 (u_longlong_t
)dd
->dd_clones
);
2542 dump_dsl_dataset(objset_t
*os
, uint64_t object
, void *data
, size_t size
)
2544 (void) os
, (void) object
;
2545 dsl_dataset_phys_t
*ds
= data
;
2547 char used
[32], compressed
[32], uncompressed
[32], unique
[32];
2548 char blkbuf
[BP_SPRINTF_LEN
];
2550 /* make sure nicenum has enough space */
2551 _Static_assert(sizeof (used
) >= NN_NUMBUF_SZ
, "used truncated");
2552 _Static_assert(sizeof (compressed
) >= NN_NUMBUF_SZ
,
2553 "compressed truncated");
2554 _Static_assert(sizeof (uncompressed
) >= NN_NUMBUF_SZ
,
2555 "uncompressed truncated");
2556 _Static_assert(sizeof (unique
) >= NN_NUMBUF_SZ
, "unique truncated");
2561 ASSERT(size
== sizeof (*ds
));
2562 crtime
= ds
->ds_creation_time
;
2563 zdb_nicenum(ds
->ds_referenced_bytes
, used
, sizeof (used
));
2564 zdb_nicenum(ds
->ds_compressed_bytes
, compressed
, sizeof (compressed
));
2565 zdb_nicenum(ds
->ds_uncompressed_bytes
, uncompressed
,
2566 sizeof (uncompressed
));
2567 zdb_nicenum(ds
->ds_unique_bytes
, unique
, sizeof (unique
));
2568 snprintf_blkptr(blkbuf
, sizeof (blkbuf
), &ds
->ds_bp
);
2570 (void) printf("\t\tdir_obj = %llu\n",
2571 (u_longlong_t
)ds
->ds_dir_obj
);
2572 (void) printf("\t\tprev_snap_obj = %llu\n",
2573 (u_longlong_t
)ds
->ds_prev_snap_obj
);
2574 (void) printf("\t\tprev_snap_txg = %llu\n",
2575 (u_longlong_t
)ds
->ds_prev_snap_txg
);
2576 (void) printf("\t\tnext_snap_obj = %llu\n",
2577 (u_longlong_t
)ds
->ds_next_snap_obj
);
2578 (void) printf("\t\tsnapnames_zapobj = %llu\n",
2579 (u_longlong_t
)ds
->ds_snapnames_zapobj
);
2580 (void) printf("\t\tnum_children = %llu\n",
2581 (u_longlong_t
)ds
->ds_num_children
);
2582 (void) printf("\t\tuserrefs_obj = %llu\n",
2583 (u_longlong_t
)ds
->ds_userrefs_obj
);
2584 (void) printf("\t\tcreation_time = %s", ctime(&crtime
));
2585 (void) printf("\t\tcreation_txg = %llu\n",
2586 (u_longlong_t
)ds
->ds_creation_txg
);
2587 (void) printf("\t\tdeadlist_obj = %llu\n",
2588 (u_longlong_t
)ds
->ds_deadlist_obj
);
2589 (void) printf("\t\tused_bytes = %s\n", used
);
2590 (void) printf("\t\tcompressed_bytes = %s\n", compressed
);
2591 (void) printf("\t\tuncompressed_bytes = %s\n", uncompressed
);
2592 (void) printf("\t\tunique = %s\n", unique
);
2593 (void) printf("\t\tfsid_guid = %llu\n",
2594 (u_longlong_t
)ds
->ds_fsid_guid
);
2595 (void) printf("\t\tguid = %llu\n",
2596 (u_longlong_t
)ds
->ds_guid
);
2597 (void) printf("\t\tflags = %llx\n",
2598 (u_longlong_t
)ds
->ds_flags
);
2599 (void) printf("\t\tnext_clones_obj = %llu\n",
2600 (u_longlong_t
)ds
->ds_next_clones_obj
);
2601 (void) printf("\t\tprops_obj = %llu\n",
2602 (u_longlong_t
)ds
->ds_props_obj
);
2603 (void) printf("\t\tbp = %s\n", blkbuf
);
2607 dump_bptree_cb(void *arg
, const blkptr_t
*bp
, dmu_tx_t
*tx
)
2609 (void) arg
, (void) tx
;
2610 char blkbuf
[BP_SPRINTF_LEN
];
2612 if (bp
->blk_birth
!= 0) {
2613 snprintf_blkptr(blkbuf
, sizeof (blkbuf
), bp
);
2614 (void) printf("\t%s\n", blkbuf
);
2620 dump_bptree(objset_t
*os
, uint64_t obj
, const char *name
)
2626 /* make sure nicenum has enough space */
2627 _Static_assert(sizeof (bytes
) >= NN_NUMBUF_SZ
, "bytes truncated");
2629 if (dump_opt
['d'] < 3)
2632 VERIFY3U(0, ==, dmu_bonus_hold(os
, obj
, FTAG
, &db
));
2634 zdb_nicenum(bt
->bt_bytes
, bytes
, sizeof (bytes
));
2635 (void) printf("\n %s: %llu datasets, %s\n",
2636 name
, (unsigned long long)(bt
->bt_end
- bt
->bt_begin
), bytes
);
2637 dmu_buf_rele(db
, FTAG
);
2639 if (dump_opt
['d'] < 5)
2642 (void) printf("\n");
2644 (void) bptree_iterate(os
, obj
, B_FALSE
, dump_bptree_cb
, NULL
, NULL
);
2648 dump_bpobj_cb(void *arg
, const blkptr_t
*bp
, boolean_t bp_freed
, dmu_tx_t
*tx
)
2650 (void) arg
, (void) tx
;
2651 char blkbuf
[BP_SPRINTF_LEN
];
2653 ASSERT(bp
->blk_birth
!= 0);
2654 snprintf_blkptr_compact(blkbuf
, sizeof (blkbuf
), bp
, bp_freed
);
2655 (void) printf("\t%s\n", blkbuf
);
2660 dump_full_bpobj(bpobj_t
*bpo
, const char *name
, int indent
)
2667 /* make sure nicenum has enough space */
2668 _Static_assert(sizeof (bytes
) >= NN_NUMBUF_SZ
, "bytes truncated");
2669 _Static_assert(sizeof (comp
) >= NN_NUMBUF_SZ
, "comp truncated");
2670 _Static_assert(sizeof (uncomp
) >= NN_NUMBUF_SZ
, "uncomp truncated");
2672 if (dump_opt
['d'] < 3)
2675 zdb_nicenum(bpo
->bpo_phys
->bpo_bytes
, bytes
, sizeof (bytes
));
2676 if (bpo
->bpo_havesubobj
&& bpo
->bpo_phys
->bpo_subobjs
!= 0) {
2677 zdb_nicenum(bpo
->bpo_phys
->bpo_comp
, comp
, sizeof (comp
));
2678 zdb_nicenum(bpo
->bpo_phys
->bpo_uncomp
, uncomp
, sizeof (uncomp
));
2679 if (bpo
->bpo_havefreed
) {
2680 (void) printf(" %*s: object %llu, %llu local "
2681 "blkptrs, %llu freed, %llu subobjs in object %llu, "
2682 "%s (%s/%s comp)\n",
2684 (u_longlong_t
)bpo
->bpo_object
,
2685 (u_longlong_t
)bpo
->bpo_phys
->bpo_num_blkptrs
,
2686 (u_longlong_t
)bpo
->bpo_phys
->bpo_num_freed
,
2687 (u_longlong_t
)bpo
->bpo_phys
->bpo_num_subobjs
,
2688 (u_longlong_t
)bpo
->bpo_phys
->bpo_subobjs
,
2689 bytes
, comp
, uncomp
);
2691 (void) printf(" %*s: object %llu, %llu local "
2692 "blkptrs, %llu subobjs in object %llu, "
2693 "%s (%s/%s comp)\n",
2695 (u_longlong_t
)bpo
->bpo_object
,
2696 (u_longlong_t
)bpo
->bpo_phys
->bpo_num_blkptrs
,
2697 (u_longlong_t
)bpo
->bpo_phys
->bpo_num_subobjs
,
2698 (u_longlong_t
)bpo
->bpo_phys
->bpo_subobjs
,
2699 bytes
, comp
, uncomp
);
2702 for (i
= 0; i
< bpo
->bpo_phys
->bpo_num_subobjs
; i
++) {
2706 VERIFY0(dmu_read(bpo
->bpo_os
,
2707 bpo
->bpo_phys
->bpo_subobjs
,
2708 i
* sizeof (subobj
), sizeof (subobj
), &subobj
, 0));
2709 error
= bpobj_open(&subbpo
, bpo
->bpo_os
, subobj
);
2711 (void) printf("ERROR %u while trying to open "
2713 error
, (u_longlong_t
)subobj
);
2716 dump_full_bpobj(&subbpo
, "subobj", indent
+ 1);
2717 bpobj_close(&subbpo
);
2720 if (bpo
->bpo_havefreed
) {
2721 (void) printf(" %*s: object %llu, %llu blkptrs, "
2724 (u_longlong_t
)bpo
->bpo_object
,
2725 (u_longlong_t
)bpo
->bpo_phys
->bpo_num_blkptrs
,
2726 (u_longlong_t
)bpo
->bpo_phys
->bpo_num_freed
,
2729 (void) printf(" %*s: object %llu, %llu blkptrs, "
2732 (u_longlong_t
)bpo
->bpo_object
,
2733 (u_longlong_t
)bpo
->bpo_phys
->bpo_num_blkptrs
,
2738 if (dump_opt
['d'] < 5)
2743 (void) bpobj_iterate_nofree(bpo
, dump_bpobj_cb
, NULL
, NULL
);
2744 (void) printf("\n");
2749 dump_bookmark(dsl_pool_t
*dp
, char *name
, boolean_t print_redact
,
2750 boolean_t print_list
)
2753 zfs_bookmark_phys_t prop
;
2754 objset_t
*mos
= dp
->dp_spa
->spa_meta_objset
;
2755 err
= dsl_bookmark_lookup(dp
, name
, NULL
, &prop
);
2761 (void) printf("\t#%s: ", strchr(name
, '#') + 1);
2762 (void) printf("{guid: %llx creation_txg: %llu creation_time: "
2763 "%llu redaction_obj: %llu}\n", (u_longlong_t
)prop
.zbm_guid
,
2764 (u_longlong_t
)prop
.zbm_creation_txg
,
2765 (u_longlong_t
)prop
.zbm_creation_time
,
2766 (u_longlong_t
)prop
.zbm_redaction_obj
);
2768 IMPLY(print_list
, print_redact
);
2769 if (!print_redact
|| prop
.zbm_redaction_obj
== 0)
2772 redaction_list_t
*rl
;
2773 VERIFY0(dsl_redaction_list_hold_obj(dp
,
2774 prop
.zbm_redaction_obj
, FTAG
, &rl
));
2776 redaction_list_phys_t
*rlp
= rl
->rl_phys
;
2777 (void) printf("\tRedacted:\n\t\tProgress: ");
2778 if (rlp
->rlp_last_object
!= UINT64_MAX
||
2779 rlp
->rlp_last_blkid
!= UINT64_MAX
) {
2780 (void) printf("%llu %llu (incomplete)\n",
2781 (u_longlong_t
)rlp
->rlp_last_object
,
2782 (u_longlong_t
)rlp
->rlp_last_blkid
);
2784 (void) printf("complete\n");
2786 (void) printf("\t\tSnapshots: [");
2787 for (unsigned int i
= 0; i
< rlp
->rlp_num_snaps
; i
++) {
2789 (void) printf(", ");
2790 (void) printf("%0llu",
2791 (u_longlong_t
)rlp
->rlp_snaps
[i
]);
2793 (void) printf("]\n\t\tLength: %llu\n",
2794 (u_longlong_t
)rlp
->rlp_num_entries
);
2797 dsl_redaction_list_rele(rl
, FTAG
);
2801 if (rlp
->rlp_num_entries
== 0) {
2802 dsl_redaction_list_rele(rl
, FTAG
);
2803 (void) printf("\t\tRedaction List: []\n\n");
2807 redact_block_phys_t
*rbp_buf
;
2809 dmu_object_info_t doi
;
2811 VERIFY0(dmu_object_info(mos
, prop
.zbm_redaction_obj
, &doi
));
2812 size
= doi
.doi_max_offset
;
2813 rbp_buf
= kmem_alloc(size
, KM_SLEEP
);
2815 err
= dmu_read(mos
, prop
.zbm_redaction_obj
, 0, size
,
2818 dsl_redaction_list_rele(rl
, FTAG
);
2819 kmem_free(rbp_buf
, size
);
2823 (void) printf("\t\tRedaction List: [{object: %llx, offset: "
2824 "%llx, blksz: %x, count: %llx}",
2825 (u_longlong_t
)rbp_buf
[0].rbp_object
,
2826 (u_longlong_t
)rbp_buf
[0].rbp_blkid
,
2827 (uint_t
)(redact_block_get_size(&rbp_buf
[0])),
2828 (u_longlong_t
)redact_block_get_count(&rbp_buf
[0]));
2830 for (size_t i
= 1; i
< rlp
->rlp_num_entries
; i
++) {
2831 (void) printf(",\n\t\t{object: %llx, offset: %llx, "
2832 "blksz: %x, count: %llx}",
2833 (u_longlong_t
)rbp_buf
[i
].rbp_object
,
2834 (u_longlong_t
)rbp_buf
[i
].rbp_blkid
,
2835 (uint_t
)(redact_block_get_size(&rbp_buf
[i
])),
2836 (u_longlong_t
)redact_block_get_count(&rbp_buf
[i
]));
2838 dsl_redaction_list_rele(rl
, FTAG
);
2839 kmem_free(rbp_buf
, size
);
2840 (void) printf("]\n\n");
2845 dump_bookmarks(objset_t
*os
, int verbosity
)
2848 zap_attribute_t attr
;
2849 dsl_dataset_t
*ds
= dmu_objset_ds(os
);
2850 dsl_pool_t
*dp
= spa_get_dsl(os
->os_spa
);
2851 objset_t
*mos
= os
->os_spa
->spa_meta_objset
;
2854 dsl_pool_config_enter(dp
, FTAG
);
2856 for (zap_cursor_init(&zc
, mos
, ds
->ds_bookmarks_obj
);
2857 zap_cursor_retrieve(&zc
, &attr
) == 0;
2858 zap_cursor_advance(&zc
)) {
2859 char osname
[ZFS_MAX_DATASET_NAME_LEN
];
2860 char buf
[ZFS_MAX_DATASET_NAME_LEN
];
2861 dmu_objset_name(os
, osname
);
2862 VERIFY3S(0, <=, snprintf(buf
, sizeof (buf
), "%s#%s", osname
,
2864 (void) dump_bookmark(dp
, buf
, verbosity
>= 5, verbosity
>= 6);
2866 zap_cursor_fini(&zc
);
2867 dsl_pool_config_exit(dp
, FTAG
);
2871 bpobj_count_refd(bpobj_t
*bpo
)
2873 mos_obj_refd(bpo
->bpo_object
);
2875 if (bpo
->bpo_havesubobj
&& bpo
->bpo_phys
->bpo_subobjs
!= 0) {
2876 mos_obj_refd(bpo
->bpo_phys
->bpo_subobjs
);
2877 for (uint64_t i
= 0; i
< bpo
->bpo_phys
->bpo_num_subobjs
; i
++) {
2881 VERIFY0(dmu_read(bpo
->bpo_os
,
2882 bpo
->bpo_phys
->bpo_subobjs
,
2883 i
* sizeof (subobj
), sizeof (subobj
), &subobj
, 0));
2884 error
= bpobj_open(&subbpo
, bpo
->bpo_os
, subobj
);
2886 (void) printf("ERROR %u while trying to open "
2888 error
, (u_longlong_t
)subobj
);
2891 bpobj_count_refd(&subbpo
);
2892 bpobj_close(&subbpo
);
2898 dsl_deadlist_entry_count_refd(void *arg
, dsl_deadlist_entry_t
*dle
)
2901 uint64_t empty_bpobj
= spa
->spa_dsl_pool
->dp_empty_bpobj
;
2902 if (dle
->dle_bpobj
.bpo_object
!= empty_bpobj
)
2903 bpobj_count_refd(&dle
->dle_bpobj
);
2908 dsl_deadlist_entry_dump(void *arg
, dsl_deadlist_entry_t
*dle
)
2910 ASSERT(arg
== NULL
);
2911 if (dump_opt
['d'] >= 5) {
2913 (void) snprintf(buf
, sizeof (buf
),
2914 "mintxg %llu -> obj %llu",
2915 (longlong_t
)dle
->dle_mintxg
,
2916 (longlong_t
)dle
->dle_bpobj
.bpo_object
);
2918 dump_full_bpobj(&dle
->dle_bpobj
, buf
, 0);
2920 (void) printf("mintxg %llu -> obj %llu\n",
2921 (longlong_t
)dle
->dle_mintxg
,
2922 (longlong_t
)dle
->dle_bpobj
.bpo_object
);
2928 dump_blkptr_list(dsl_deadlist_t
*dl
, char *name
)
2934 spa_t
*spa
= dmu_objset_spa(dl
->dl_os
);
2935 uint64_t empty_bpobj
= spa
->spa_dsl_pool
->dp_empty_bpobj
;
2937 if (dl
->dl_oldfmt
) {
2938 if (dl
->dl_bpobj
.bpo_object
!= empty_bpobj
)
2939 bpobj_count_refd(&dl
->dl_bpobj
);
2941 mos_obj_refd(dl
->dl_object
);
2942 dsl_deadlist_iterate(dl
, dsl_deadlist_entry_count_refd
, spa
);
2945 /* make sure nicenum has enough space */
2946 _Static_assert(sizeof (bytes
) >= NN_NUMBUF_SZ
, "bytes truncated");
2947 _Static_assert(sizeof (comp
) >= NN_NUMBUF_SZ
, "comp truncated");
2948 _Static_assert(sizeof (uncomp
) >= NN_NUMBUF_SZ
, "uncomp truncated");
2949 _Static_assert(sizeof (entries
) >= NN_NUMBUF_SZ
, "entries truncated");
2951 if (dump_opt
['d'] < 3)
2954 if (dl
->dl_oldfmt
) {
2955 dump_full_bpobj(&dl
->dl_bpobj
, "old-format deadlist", 0);
2959 zdb_nicenum(dl
->dl_phys
->dl_used
, bytes
, sizeof (bytes
));
2960 zdb_nicenum(dl
->dl_phys
->dl_comp
, comp
, sizeof (comp
));
2961 zdb_nicenum(dl
->dl_phys
->dl_uncomp
, uncomp
, sizeof (uncomp
));
2962 zdb_nicenum(avl_numnodes(&dl
->dl_tree
), entries
, sizeof (entries
));
2963 (void) printf("\n %s: %s (%s/%s comp), %s entries\n",
2964 name
, bytes
, comp
, uncomp
, entries
);
2966 if (dump_opt
['d'] < 4)
2969 (void) printf("\n");
2971 dsl_deadlist_iterate(dl
, dsl_deadlist_entry_dump
, NULL
);
2975 verify_dd_livelist(objset_t
*os
)
2977 uint64_t ll_used
, used
, ll_comp
, comp
, ll_uncomp
, uncomp
;
2978 dsl_pool_t
*dp
= spa_get_dsl(os
->os_spa
);
2979 dsl_dir_t
*dd
= os
->os_dsl_dataset
->ds_dir
;
2981 ASSERT(!dmu_objset_is_snapshot(os
));
2982 if (!dsl_deadlist_is_open(&dd
->dd_livelist
))
2985 /* Iterate through the livelist to check for duplicates */
2986 dsl_deadlist_iterate(&dd
->dd_livelist
, sublivelist_verify_lightweight
,
2989 dsl_pool_config_enter(dp
, FTAG
);
2990 dsl_deadlist_space(&dd
->dd_livelist
, &ll_used
,
2991 &ll_comp
, &ll_uncomp
);
2993 dsl_dataset_t
*origin_ds
;
2994 ASSERT(dsl_pool_config_held(dp
));
2995 VERIFY0(dsl_dataset_hold_obj(dp
,
2996 dsl_dir_phys(dd
)->dd_origin_obj
, FTAG
, &origin_ds
));
2997 VERIFY0(dsl_dataset_space_written(origin_ds
, os
->os_dsl_dataset
,
2998 &used
, &comp
, &uncomp
));
2999 dsl_dataset_rele(origin_ds
, FTAG
);
3000 dsl_pool_config_exit(dp
, FTAG
);
3002 * It's possible that the dataset's uncomp space is larger than the
3003 * livelist's because livelists do not track embedded block pointers
3005 if (used
!= ll_used
|| comp
!= ll_comp
|| uncomp
< ll_uncomp
) {
3006 char nice_used
[32], nice_comp
[32], nice_uncomp
[32];
3007 (void) printf("Discrepancy in space accounting:\n");
3008 zdb_nicenum(used
, nice_used
, sizeof (nice_used
));
3009 zdb_nicenum(comp
, nice_comp
, sizeof (nice_comp
));
3010 zdb_nicenum(uncomp
, nice_uncomp
, sizeof (nice_uncomp
));
3011 (void) printf("dir: used %s, comp %s, uncomp %s\n",
3012 nice_used
, nice_comp
, nice_uncomp
);
3013 zdb_nicenum(ll_used
, nice_used
, sizeof (nice_used
));
3014 zdb_nicenum(ll_comp
, nice_comp
, sizeof (nice_comp
));
3015 zdb_nicenum(ll_uncomp
, nice_uncomp
, sizeof (nice_uncomp
));
3016 (void) printf("livelist: used %s, comp %s, uncomp %s\n",
3017 nice_used
, nice_comp
, nice_uncomp
);
3023 static avl_tree_t idx_tree
;
3024 static avl_tree_t domain_tree
;
3025 static boolean_t fuid_table_loaded
;
3026 static objset_t
*sa_os
= NULL
;
3027 static sa_attr_type_t
*sa_attr_table
= NULL
;
3030 open_objset(const char *path
, void *tag
, objset_t
**osp
)
3033 uint64_t sa_attrs
= 0;
3034 uint64_t version
= 0;
3036 VERIFY3P(sa_os
, ==, NULL
);
3038 * We can't own an objset if it's redacted. Therefore, we do this
3039 * dance: hold the objset, then acquire a long hold on its dataset, then
3040 * release the pool (which is held as part of holding the objset).
3042 err
= dmu_objset_hold(path
, tag
, osp
);
3044 (void) fprintf(stderr
, "failed to hold dataset '%s': %s\n",
3045 path
, strerror(err
));
3048 dsl_dataset_long_hold(dmu_objset_ds(*osp
), tag
);
3049 dsl_pool_rele(dmu_objset_pool(*osp
), tag
);
3051 if (dmu_objset_type(*osp
) == DMU_OST_ZFS
&& !(*osp
)->os_encrypted
) {
3052 (void) zap_lookup(*osp
, MASTER_NODE_OBJ
, ZPL_VERSION_STR
,
3054 if (version
>= ZPL_VERSION_SA
) {
3055 (void) zap_lookup(*osp
, MASTER_NODE_OBJ
, ZFS_SA_ATTRS
,
3058 err
= sa_setup(*osp
, sa_attrs
, zfs_attr_table
, ZPL_END
,
3061 (void) fprintf(stderr
, "sa_setup failed: %s\n",
3063 dsl_dataset_long_rele(dmu_objset_ds(*osp
), tag
);
3064 dsl_dataset_rele(dmu_objset_ds(*osp
), tag
);
3074 close_objset(objset_t
*os
, void *tag
)
3076 VERIFY3P(os
, ==, sa_os
);
3077 if (os
->os_sa
!= NULL
)
3079 dsl_dataset_long_rele(dmu_objset_ds(os
), tag
);
3080 dsl_dataset_rele(dmu_objset_ds(os
), tag
);
3081 sa_attr_table
= NULL
;
3086 fuid_table_destroy(void)
3088 if (fuid_table_loaded
) {
3089 zfs_fuid_table_destroy(&idx_tree
, &domain_tree
);
3090 fuid_table_loaded
= B_FALSE
;
3095 * print uid or gid information.
3096 * For normal POSIX id just the id is printed in decimal format.
3097 * For CIFS files with FUID the fuid is printed in hex followed by
3098 * the domain-rid string.
3101 print_idstr(uint64_t id
, const char *id_type
)
3103 if (FUID_INDEX(id
)) {
3106 domain
= zfs_fuid_idx_domain(&idx_tree
, FUID_INDEX(id
));
3107 (void) printf("\t%s %llx [%s-%d]\n", id_type
,
3108 (u_longlong_t
)id
, domain
, (int)FUID_RID(id
));
3110 (void) printf("\t%s %llu\n", id_type
, (u_longlong_t
)id
);
3116 dump_uidgid(objset_t
*os
, uint64_t uid
, uint64_t gid
)
3118 uint32_t uid_idx
, gid_idx
;
3120 uid_idx
= FUID_INDEX(uid
);
3121 gid_idx
= FUID_INDEX(gid
);
3123 /* Load domain table, if not already loaded */
3124 if (!fuid_table_loaded
&& (uid_idx
|| gid_idx
)) {
3127 /* first find the fuid object. It lives in the master node */
3128 VERIFY(zap_lookup(os
, MASTER_NODE_OBJ
, ZFS_FUID_TABLES
,
3129 8, 1, &fuid_obj
) == 0);
3130 zfs_fuid_avl_tree_create(&idx_tree
, &domain_tree
);
3131 (void) zfs_fuid_table_load(os
, fuid_obj
,
3132 &idx_tree
, &domain_tree
);
3133 fuid_table_loaded
= B_TRUE
;
3136 print_idstr(uid
, "uid");
3137 print_idstr(gid
, "gid");
3141 dump_znode_sa_xattr(sa_handle_t
*hdl
)
3144 nvpair_t
*elem
= NULL
;
3145 int sa_xattr_size
= 0;
3146 int sa_xattr_entries
= 0;
3148 char *sa_xattr_packed
;
3150 error
= sa_size(hdl
, sa_attr_table
[ZPL_DXATTR
], &sa_xattr_size
);
3151 if (error
|| sa_xattr_size
== 0)
3154 sa_xattr_packed
= malloc(sa_xattr_size
);
3155 if (sa_xattr_packed
== NULL
)
3158 error
= sa_lookup(hdl
, sa_attr_table
[ZPL_DXATTR
],
3159 sa_xattr_packed
, sa_xattr_size
);
3161 free(sa_xattr_packed
);
3165 error
= nvlist_unpack(sa_xattr_packed
, sa_xattr_size
, &sa_xattr
, 0);
3167 free(sa_xattr_packed
);
3171 while ((elem
= nvlist_next_nvpair(sa_xattr
, elem
)) != NULL
)
3174 (void) printf("\tSA xattrs: %d bytes, %d entries\n\n",
3175 sa_xattr_size
, sa_xattr_entries
);
3176 while ((elem
= nvlist_next_nvpair(sa_xattr
, elem
)) != NULL
) {
3180 (void) printf("\t\t%s = ", nvpair_name(elem
));
3181 nvpair_value_byte_array(elem
, &value
, &cnt
);
3182 for (idx
= 0; idx
< cnt
; ++idx
) {
3183 if (isprint(value
[idx
]))
3184 (void) putchar(value
[idx
]);
3186 (void) printf("\\%3.3o", value
[idx
]);
3188 (void) putchar('\n');
3191 nvlist_free(sa_xattr
);
3192 free(sa_xattr_packed
);
3196 dump_znode_symlink(sa_handle_t
*hdl
)
3198 int sa_symlink_size
= 0;
3199 char linktarget
[MAXPATHLEN
];
3200 linktarget
[0] = '\0';
3203 error
= sa_size(hdl
, sa_attr_table
[ZPL_SYMLINK
], &sa_symlink_size
);
3204 if (error
|| sa_symlink_size
== 0) {
3207 if (sa_lookup(hdl
, sa_attr_table
[ZPL_SYMLINK
],
3208 &linktarget
, sa_symlink_size
) == 0)
3209 (void) printf("\ttarget %s\n", linktarget
);
3213 dump_znode(objset_t
*os
, uint64_t object
, void *data
, size_t size
)
3215 (void) data
, (void) size
;
3216 char path
[MAXPATHLEN
* 2]; /* allow for xattr and failure prefix */
3218 uint64_t xattr
, rdev
, gen
;
3219 uint64_t uid
, gid
, mode
, fsize
, parent
, links
;
3221 uint64_t acctm
[2], modtm
[2], chgtm
[2], crtm
[2];
3222 time_t z_crtime
, z_atime
, z_mtime
, z_ctime
;
3223 sa_bulk_attr_t bulk
[12];
3227 VERIFY3P(os
, ==, sa_os
);
3228 if (sa_handle_get(os
, object
, NULL
, SA_HDL_PRIVATE
, &hdl
)) {
3229 (void) printf("Failed to get handle for SA znode\n");
3233 SA_ADD_BULK_ATTR(bulk
, idx
, sa_attr_table
[ZPL_UID
], NULL
, &uid
, 8);
3234 SA_ADD_BULK_ATTR(bulk
, idx
, sa_attr_table
[ZPL_GID
], NULL
, &gid
, 8);
3235 SA_ADD_BULK_ATTR(bulk
, idx
, sa_attr_table
[ZPL_LINKS
], NULL
,
3237 SA_ADD_BULK_ATTR(bulk
, idx
, sa_attr_table
[ZPL_GEN
], NULL
, &gen
, 8);
3238 SA_ADD_BULK_ATTR(bulk
, idx
, sa_attr_table
[ZPL_MODE
], NULL
,
3240 SA_ADD_BULK_ATTR(bulk
, idx
, sa_attr_table
[ZPL_PARENT
],
3242 SA_ADD_BULK_ATTR(bulk
, idx
, sa_attr_table
[ZPL_SIZE
], NULL
,
3244 SA_ADD_BULK_ATTR(bulk
, idx
, sa_attr_table
[ZPL_ATIME
], NULL
,
3246 SA_ADD_BULK_ATTR(bulk
, idx
, sa_attr_table
[ZPL_MTIME
], NULL
,
3248 SA_ADD_BULK_ATTR(bulk
, idx
, sa_attr_table
[ZPL_CRTIME
], NULL
,
3250 SA_ADD_BULK_ATTR(bulk
, idx
, sa_attr_table
[ZPL_CTIME
], NULL
,
3252 SA_ADD_BULK_ATTR(bulk
, idx
, sa_attr_table
[ZPL_FLAGS
], NULL
,
3255 if (sa_bulk_lookup(hdl
, bulk
, idx
)) {
3256 (void) sa_handle_destroy(hdl
);
3260 z_crtime
= (time_t)crtm
[0];
3261 z_atime
= (time_t)acctm
[0];
3262 z_mtime
= (time_t)modtm
[0];
3263 z_ctime
= (time_t)chgtm
[0];
3265 if (dump_opt
['d'] > 4) {
3266 error
= zfs_obj_to_path(os
, object
, path
, sizeof (path
));
3267 if (error
== ESTALE
) {
3268 (void) snprintf(path
, sizeof (path
), "on delete queue");
3269 } else if (error
!= 0) {
3271 (void) snprintf(path
, sizeof (path
),
3272 "path not found, possibly leaked");
3274 (void) printf("\tpath %s\n", path
);
3278 dump_znode_symlink(hdl
);
3279 dump_uidgid(os
, uid
, gid
);
3280 (void) printf("\tatime %s", ctime(&z_atime
));
3281 (void) printf("\tmtime %s", ctime(&z_mtime
));
3282 (void) printf("\tctime %s", ctime(&z_ctime
));
3283 (void) printf("\tcrtime %s", ctime(&z_crtime
));
3284 (void) printf("\tgen %llu\n", (u_longlong_t
)gen
);
3285 (void) printf("\tmode %llo\n", (u_longlong_t
)mode
);
3286 (void) printf("\tsize %llu\n", (u_longlong_t
)fsize
);
3287 (void) printf("\tparent %llu\n", (u_longlong_t
)parent
);
3288 (void) printf("\tlinks %llu\n", (u_longlong_t
)links
);
3289 (void) printf("\tpflags %llx\n", (u_longlong_t
)pflags
);
3290 if (dmu_objset_projectquota_enabled(os
) && (pflags
& ZFS_PROJID
)) {
3293 if (sa_lookup(hdl
, sa_attr_table
[ZPL_PROJID
], &projid
,
3294 sizeof (uint64_t)) == 0)
3295 (void) printf("\tprojid %llu\n", (u_longlong_t
)projid
);
3297 if (sa_lookup(hdl
, sa_attr_table
[ZPL_XATTR
], &xattr
,
3298 sizeof (uint64_t)) == 0)
3299 (void) printf("\txattr %llu\n", (u_longlong_t
)xattr
);
3300 if (sa_lookup(hdl
, sa_attr_table
[ZPL_RDEV
], &rdev
,
3301 sizeof (uint64_t)) == 0)
3302 (void) printf("\trdev 0x%016llx\n", (u_longlong_t
)rdev
);
3303 dump_znode_sa_xattr(hdl
);
3304 sa_handle_destroy(hdl
);
3308 dump_acl(objset_t
*os
, uint64_t object
, void *data
, size_t size
)
3310 (void) os
, (void) object
, (void) data
, (void) size
;
3314 dump_dmu_objset(objset_t
*os
, uint64_t object
, void *data
, size_t size
)
3316 (void) os
, (void) object
, (void) data
, (void) size
;
3319 static object_viewer_t
*object_viewer
[DMU_OT_NUMTYPES
+ 1] = {
3320 dump_none
, /* unallocated */
3321 dump_zap
, /* object directory */
3322 dump_uint64
, /* object array */
3323 dump_none
, /* packed nvlist */
3324 dump_packed_nvlist
, /* packed nvlist size */
3325 dump_none
, /* bpobj */
3326 dump_bpobj
, /* bpobj header */
3327 dump_none
, /* SPA space map header */
3328 dump_none
, /* SPA space map */
3329 dump_none
, /* ZIL intent log */
3330 dump_dnode
, /* DMU dnode */
3331 dump_dmu_objset
, /* DMU objset */
3332 dump_dsl_dir
, /* DSL directory */
3333 dump_zap
, /* DSL directory child map */
3334 dump_zap
, /* DSL dataset snap map */
3335 dump_zap
, /* DSL props */
3336 dump_dsl_dataset
, /* DSL dataset */
3337 dump_znode
, /* ZFS znode */
3338 dump_acl
, /* ZFS V0 ACL */
3339 dump_uint8
, /* ZFS plain file */
3340 dump_zpldir
, /* ZFS directory */
3341 dump_zap
, /* ZFS master node */
3342 dump_zap
, /* ZFS delete queue */
3343 dump_uint8
, /* zvol object */
3344 dump_zap
, /* zvol prop */
3345 dump_uint8
, /* other uint8[] */
3346 dump_uint64
, /* other uint64[] */
3347 dump_zap
, /* other ZAP */
3348 dump_zap
, /* persistent error log */
3349 dump_uint8
, /* SPA history */
3350 dump_history_offsets
, /* SPA history offsets */
3351 dump_zap
, /* Pool properties */
3352 dump_zap
, /* DSL permissions */
3353 dump_acl
, /* ZFS ACL */
3354 dump_uint8
, /* ZFS SYSACL */
3355 dump_none
, /* FUID nvlist */
3356 dump_packed_nvlist
, /* FUID nvlist size */
3357 dump_zap
, /* DSL dataset next clones */
3358 dump_zap
, /* DSL scrub queue */
3359 dump_zap
, /* ZFS user/group/project used */
3360 dump_zap
, /* ZFS user/group/project quota */
3361 dump_zap
, /* snapshot refcount tags */
3362 dump_ddt_zap
, /* DDT ZAP object */
3363 dump_zap
, /* DDT statistics */
3364 dump_znode
, /* SA object */
3365 dump_zap
, /* SA Master Node */
3366 dump_sa_attrs
, /* SA attribute registration */
3367 dump_sa_layouts
, /* SA attribute layouts */
3368 dump_zap
, /* DSL scrub translations */
3369 dump_none
, /* fake dedup BP */
3370 dump_zap
, /* deadlist */
3371 dump_none
, /* deadlist hdr */
3372 dump_zap
, /* dsl clones */
3373 dump_bpobj_subobjs
, /* bpobj subobjs */
3374 dump_unknown
, /* Unknown type, must be last */
3378 match_object_type(dmu_object_type_t obj_type
, uint64_t flags
)
3380 boolean_t match
= B_TRUE
;
3383 case DMU_OT_DIRECTORY_CONTENTS
:
3384 if (!(flags
& ZOR_FLAG_DIRECTORY
))
3387 case DMU_OT_PLAIN_FILE_CONTENTS
:
3388 if (!(flags
& ZOR_FLAG_PLAIN_FILE
))
3391 case DMU_OT_SPACE_MAP
:
3392 if (!(flags
& ZOR_FLAG_SPACE_MAP
))
3396 if (strcmp(zdb_ot_name(obj_type
), "zap") == 0) {
3397 if (!(flags
& ZOR_FLAG_ZAP
))
3403 * If all bits except some of the supported flags are
3404 * set, the user combined the all-types flag (A) with
3405 * a negated flag to exclude some types (e.g. A-f to
3406 * show all object types except plain files).
3408 if ((flags
| ZOR_SUPPORTED_FLAGS
) != ZOR_FLAG_ALL_TYPES
)
3418 dump_object(objset_t
*os
, uint64_t object
, int verbosity
,
3419 boolean_t
*print_header
, uint64_t *dnode_slots_used
, uint64_t flags
)
3421 dmu_buf_t
*db
= NULL
;
3422 dmu_object_info_t doi
;
3424 boolean_t dnode_held
= B_FALSE
;
3427 char iblk
[32], dblk
[32], lsize
[32], asize
[32], fill
[32], dnsize
[32];
3428 char bonus_size
[32];
3432 /* make sure nicenum has enough space */
3433 _Static_assert(sizeof (iblk
) >= NN_NUMBUF_SZ
, "iblk truncated");
3434 _Static_assert(sizeof (dblk
) >= NN_NUMBUF_SZ
, "dblk truncated");
3435 _Static_assert(sizeof (lsize
) >= NN_NUMBUF_SZ
, "lsize truncated");
3436 _Static_assert(sizeof (asize
) >= NN_NUMBUF_SZ
, "asize truncated");
3437 _Static_assert(sizeof (bonus_size
) >= NN_NUMBUF_SZ
,
3438 "bonus_size truncated");
3440 if (*print_header
) {
3441 (void) printf("\n%10s %3s %5s %5s %5s %6s %5s %6s %s\n",
3442 "Object", "lvl", "iblk", "dblk", "dsize", "dnsize",
3443 "lsize", "%full", "type");
3448 dn
= DMU_META_DNODE(os
);
3449 dmu_object_info_from_dnode(dn
, &doi
);
3452 * Encrypted datasets will have sensitive bonus buffers
3453 * encrypted. Therefore we cannot hold the bonus buffer and
3454 * must hold the dnode itself instead.
3456 error
= dmu_object_info(os
, object
, &doi
);
3458 fatal("dmu_object_info() failed, errno %u", error
);
3460 if (os
->os_encrypted
&&
3461 DMU_OT_IS_ENCRYPTED(doi
.doi_bonus_type
)) {
3462 error
= dnode_hold(os
, object
, FTAG
, &dn
);
3464 fatal("dnode_hold() failed, errno %u", error
);
3465 dnode_held
= B_TRUE
;
3467 error
= dmu_bonus_hold(os
, object
, FTAG
, &db
);
3469 fatal("dmu_bonus_hold(%llu) failed, errno %u",
3471 bonus
= db
->db_data
;
3472 bsize
= db
->db_size
;
3473 dn
= DB_DNODE((dmu_buf_impl_t
*)db
);
3478 * Default to showing all object types if no flags were specified.
3480 if (flags
!= 0 && flags
!= ZOR_FLAG_ALL_TYPES
&&
3481 !match_object_type(doi
.doi_type
, flags
))
3484 if (dnode_slots_used
)
3485 *dnode_slots_used
= doi
.doi_dnodesize
/ DNODE_MIN_SIZE
;
3487 zdb_nicenum(doi
.doi_metadata_block_size
, iblk
, sizeof (iblk
));
3488 zdb_nicenum(doi
.doi_data_block_size
, dblk
, sizeof (dblk
));
3489 zdb_nicenum(doi
.doi_max_offset
, lsize
, sizeof (lsize
));
3490 zdb_nicenum(doi
.doi_physical_blocks_512
<< 9, asize
, sizeof (asize
));
3491 zdb_nicenum(doi
.doi_bonus_size
, bonus_size
, sizeof (bonus_size
));
3492 zdb_nicenum(doi
.doi_dnodesize
, dnsize
, sizeof (dnsize
));
3493 (void) sprintf(fill
, "%6.2f", 100.0 * doi
.doi_fill_count
*
3494 doi
.doi_data_block_size
/ (object
== 0 ? DNODES_PER_BLOCK
: 1) /
3495 doi
.doi_max_offset
);
3499 if (doi
.doi_checksum
!= ZIO_CHECKSUM_INHERIT
|| verbosity
>= 6) {
3500 (void) snprintf(aux
+ strlen(aux
), sizeof (aux
) - strlen(aux
),
3501 " (K=%s)", ZDB_CHECKSUM_NAME(doi
.doi_checksum
));
3504 if (doi
.doi_compress
== ZIO_COMPRESS_INHERIT
&&
3505 ZIO_COMPRESS_HASLEVEL(os
->os_compress
) && verbosity
>= 6) {
3506 const char *compname
= NULL
;
3507 if (zfs_prop_index_to_string(ZFS_PROP_COMPRESSION
,
3508 ZIO_COMPRESS_RAW(os
->os_compress
, os
->os_complevel
),
3510 (void) snprintf(aux
+ strlen(aux
),
3511 sizeof (aux
) - strlen(aux
), " (Z=inherit=%s)",
3514 (void) snprintf(aux
+ strlen(aux
),
3515 sizeof (aux
) - strlen(aux
),
3516 " (Z=inherit=%s-unknown)",
3517 ZDB_COMPRESS_NAME(os
->os_compress
));
3519 } else if (doi
.doi_compress
== ZIO_COMPRESS_INHERIT
&& verbosity
>= 6) {
3520 (void) snprintf(aux
+ strlen(aux
), sizeof (aux
) - strlen(aux
),
3521 " (Z=inherit=%s)", ZDB_COMPRESS_NAME(os
->os_compress
));
3522 } else if (doi
.doi_compress
!= ZIO_COMPRESS_INHERIT
|| verbosity
>= 6) {
3523 (void) snprintf(aux
+ strlen(aux
), sizeof (aux
) - strlen(aux
),
3524 " (Z=%s)", ZDB_COMPRESS_NAME(doi
.doi_compress
));
3527 (void) printf("%10lld %3u %5s %5s %5s %6s %5s %6s %s%s\n",
3528 (u_longlong_t
)object
, doi
.doi_indirection
, iblk
, dblk
,
3529 asize
, dnsize
, lsize
, fill
, zdb_ot_name(doi
.doi_type
), aux
);
3531 if (doi
.doi_bonus_type
!= DMU_OT_NONE
&& verbosity
> 3) {
3532 (void) printf("%10s %3s %5s %5s %5s %5s %5s %6s %s\n",
3533 "", "", "", "", "", "", bonus_size
, "bonus",
3534 zdb_ot_name(doi
.doi_bonus_type
));
3537 if (verbosity
>= 4) {
3538 (void) printf("\tdnode flags: %s%s%s%s\n",
3539 (dn
->dn_phys
->dn_flags
& DNODE_FLAG_USED_BYTES
) ?
3541 (dn
->dn_phys
->dn_flags
& DNODE_FLAG_USERUSED_ACCOUNTED
) ?
3542 "USERUSED_ACCOUNTED " : "",
3543 (dn
->dn_phys
->dn_flags
& DNODE_FLAG_USEROBJUSED_ACCOUNTED
) ?
3544 "USEROBJUSED_ACCOUNTED " : "",
3545 (dn
->dn_phys
->dn_flags
& DNODE_FLAG_SPILL_BLKPTR
) ?
3546 "SPILL_BLKPTR" : "");
3547 (void) printf("\tdnode maxblkid: %llu\n",
3548 (longlong_t
)dn
->dn_phys
->dn_maxblkid
);
3551 object_viewer
[ZDB_OT_TYPE(doi
.doi_bonus_type
)](os
,
3552 object
, bonus
, bsize
);
3554 (void) printf("\t\t(bonus encrypted)\n");
3557 if (!os
->os_encrypted
|| !DMU_OT_IS_ENCRYPTED(doi
.doi_type
)) {
3558 object_viewer
[ZDB_OT_TYPE(doi
.doi_type
)](os
, object
,
3561 (void) printf("\t\t(object encrypted)\n");
3564 *print_header
= B_TRUE
;
3570 if (verbosity
>= 5) {
3572 * Report the list of segments that comprise the object.
3576 uint64_t blkfill
= 1;
3579 if (dn
->dn_type
== DMU_OT_DNODE
) {
3581 blkfill
= DNODES_PER_BLOCK
;
3586 /* make sure nicenum has enough space */
3587 _Static_assert(sizeof (segsize
) >= NN_NUMBUF_SZ
,
3588 "segsize truncated");
3589 error
= dnode_next_offset(dn
,
3590 0, &start
, minlvl
, blkfill
, 0);
3594 error
= dnode_next_offset(dn
,
3595 DNODE_FIND_HOLE
, &end
, minlvl
, blkfill
, 0);
3596 zdb_nicenum(end
- start
, segsize
, sizeof (segsize
));
3597 (void) printf("\t\tsegment [%016llx, %016llx)"
3598 " size %5s\n", (u_longlong_t
)start
,
3599 (u_longlong_t
)end
, segsize
);
3608 dmu_buf_rele(db
, FTAG
);
3610 dnode_rele(dn
, FTAG
);
3614 count_dir_mos_objects(dsl_dir_t
*dd
)
3616 mos_obj_refd(dd
->dd_object
);
3617 mos_obj_refd(dsl_dir_phys(dd
)->dd_child_dir_zapobj
);
3618 mos_obj_refd(dsl_dir_phys(dd
)->dd_deleg_zapobj
);
3619 mos_obj_refd(dsl_dir_phys(dd
)->dd_props_zapobj
);
3620 mos_obj_refd(dsl_dir_phys(dd
)->dd_clones
);
3623 * The dd_crypto_obj can be referenced by multiple dsl_dir's.
3624 * Ignore the references after the first one.
3626 mos_obj_refd_multiple(dd
->dd_crypto_obj
);
3630 count_ds_mos_objects(dsl_dataset_t
*ds
)
3632 mos_obj_refd(ds
->ds_object
);
3633 mos_obj_refd(dsl_dataset_phys(ds
)->ds_next_clones_obj
);
3634 mos_obj_refd(dsl_dataset_phys(ds
)->ds_props_obj
);
3635 mos_obj_refd(dsl_dataset_phys(ds
)->ds_userrefs_obj
);
3636 mos_obj_refd(dsl_dataset_phys(ds
)->ds_snapnames_zapobj
);
3637 mos_obj_refd(ds
->ds_bookmarks_obj
);
3639 if (!dsl_dataset_is_snapshot(ds
)) {
3640 count_dir_mos_objects(ds
->ds_dir
);
3644 static const char *objset_types
[DMU_OST_NUMTYPES
] = {
3645 "NONE", "META", "ZPL", "ZVOL", "OTHER", "ANY" };
3648 * Parse a string denoting a range of object IDs of the form
3649 * <start>[:<end>[:flags]], and store the results in zor.
3650 * Return 0 on success. On error, return 1 and update the msg
3651 * pointer to point to a descriptive error message.
3654 parse_object_range(char *range
, zopt_object_range_t
*zor
, char **msg
)
3657 char *p
, *s
, *dup
, *flagstr
, *tmp
= NULL
;
3662 if (strchr(range
, ':') == NULL
) {
3663 zor
->zor_obj_start
= strtoull(range
, &p
, 0);
3665 *msg
= "Invalid characters in object ID";
3668 zor
->zor_obj_start
= ZDB_MAP_OBJECT_ID(zor
->zor_obj_start
);
3669 zor
->zor_obj_end
= zor
->zor_obj_start
;
3673 if (strchr(range
, ':') == range
) {
3674 *msg
= "Invalid leading colon";
3679 len
= strlen(range
);
3680 if (range
[len
- 1] == ':') {
3681 *msg
= "Invalid trailing colon";
3686 dup
= strdup(range
);
3687 s
= strtok_r(dup
, ":", &tmp
);
3688 zor
->zor_obj_start
= strtoull(s
, &p
, 0);
3691 *msg
= "Invalid characters in start object ID";
3696 s
= strtok_r(NULL
, ":", &tmp
);
3697 zor
->zor_obj_end
= strtoull(s
, &p
, 0);
3700 *msg
= "Invalid characters in end object ID";
3705 if (zor
->zor_obj_start
> zor
->zor_obj_end
) {
3706 *msg
= "Start object ID may not exceed end object ID";
3711 s
= strtok_r(NULL
, ":", &tmp
);
3713 zor
->zor_flags
= ZOR_FLAG_ALL_TYPES
;
3715 } else if (strtok_r(NULL
, ":", &tmp
) != NULL
) {
3716 *msg
= "Invalid colon-delimited field after flags";
3722 for (i
= 0; flagstr
[i
]; i
++) {
3724 boolean_t negation
= (flagstr
[i
] == '-');
3728 if (flagstr
[i
] == '\0') {
3729 *msg
= "Invalid trailing negation operator";
3734 bit
= flagbits
[(uchar_t
)flagstr
[i
]];
3736 *msg
= "Invalid flag";
3745 zor
->zor_flags
= flags
;
3747 zor
->zor_obj_start
= ZDB_MAP_OBJECT_ID(zor
->zor_obj_start
);
3748 zor
->zor_obj_end
= ZDB_MAP_OBJECT_ID(zor
->zor_obj_end
);
3756 dump_objset(objset_t
*os
)
3758 dmu_objset_stats_t dds
= { 0 };
3759 uint64_t object
, object_count
;
3760 uint64_t refdbytes
, usedobjs
, scratch
;
3762 char blkbuf
[BP_SPRINTF_LEN
+ 20];
3763 char osname
[ZFS_MAX_DATASET_NAME_LEN
];
3764 const char *type
= "UNKNOWN";
3765 int verbosity
= dump_opt
['d'];
3766 boolean_t print_header
;
3769 uint64_t total_slots_used
= 0;
3770 uint64_t max_slot_used
= 0;
3771 uint64_t dnode_slots
;
3776 /* make sure nicenum has enough space */
3777 _Static_assert(sizeof (numbuf
) >= NN_NUMBUF_SZ
, "numbuf truncated");
3779 dsl_pool_config_enter(dmu_objset_pool(os
), FTAG
);
3780 dmu_objset_fast_stat(os
, &dds
);
3781 dsl_pool_config_exit(dmu_objset_pool(os
), FTAG
);
3783 print_header
= B_TRUE
;
3785 if (dds
.dds_type
< DMU_OST_NUMTYPES
)
3786 type
= objset_types
[dds
.dds_type
];
3788 if (dds
.dds_type
== DMU_OST_META
) {
3789 dds
.dds_creation_txg
= TXG_INITIAL
;
3790 usedobjs
= BP_GET_FILL(os
->os_rootbp
);
3791 refdbytes
= dsl_dir_phys(os
->os_spa
->spa_dsl_pool
->dp_mos_dir
)->
3794 dmu_objset_space(os
, &refdbytes
, &scratch
, &usedobjs
, &scratch
);
3797 ASSERT3U(usedobjs
, ==, BP_GET_FILL(os
->os_rootbp
));
3799 zdb_nicenum(refdbytes
, numbuf
, sizeof (numbuf
));
3801 if (verbosity
>= 4) {
3802 (void) snprintf(blkbuf
, sizeof (blkbuf
), ", rootbp ");
3803 (void) snprintf_blkptr(blkbuf
+ strlen(blkbuf
),
3804 sizeof (blkbuf
) - strlen(blkbuf
), os
->os_rootbp
);
3809 dmu_objset_name(os
, osname
);
3811 (void) printf("Dataset %s [%s], ID %llu, cr_txg %llu, "
3812 "%s, %llu objects%s%s\n",
3813 osname
, type
, (u_longlong_t
)dmu_objset_id(os
),
3814 (u_longlong_t
)dds
.dds_creation_txg
,
3815 numbuf
, (u_longlong_t
)usedobjs
, blkbuf
,
3816 (dds
.dds_inconsistent
) ? " (inconsistent)" : "");
3818 for (i
= 0; i
< zopt_object_args
; i
++) {
3819 obj_start
= zopt_object_ranges
[i
].zor_obj_start
;
3820 obj_end
= zopt_object_ranges
[i
].zor_obj_end
;
3821 flags
= zopt_object_ranges
[i
].zor_flags
;
3824 if (object
== 0 || obj_start
== obj_end
)
3825 dump_object(os
, object
, verbosity
, &print_header
, NULL
,
3830 while ((dmu_object_next(os
, &object
, B_FALSE
, 0) == 0) &&
3831 object
<= obj_end
) {
3832 dump_object(os
, object
, verbosity
, &print_header
, NULL
,
3837 if (zopt_object_args
> 0) {
3838 (void) printf("\n");
3842 if (dump_opt
['i'] != 0 || verbosity
>= 2)
3843 dump_intent_log(dmu_objset_zil(os
));
3845 if (dmu_objset_ds(os
) != NULL
) {
3846 dsl_dataset_t
*ds
= dmu_objset_ds(os
);
3847 dump_blkptr_list(&ds
->ds_deadlist
, "Deadlist");
3848 if (dsl_deadlist_is_open(&ds
->ds_dir
->dd_livelist
) &&
3849 !dmu_objset_is_snapshot(os
)) {
3850 dump_blkptr_list(&ds
->ds_dir
->dd_livelist
, "Livelist");
3851 if (verify_dd_livelist(os
) != 0)
3852 fatal("livelist is incorrect");
3855 if (dsl_dataset_remap_deadlist_exists(ds
)) {
3856 (void) printf("ds_remap_deadlist:\n");
3857 dump_blkptr_list(&ds
->ds_remap_deadlist
, "Deadlist");
3859 count_ds_mos_objects(ds
);
3862 if (dmu_objset_ds(os
) != NULL
)
3863 dump_bookmarks(os
, verbosity
);
3868 if (BP_IS_HOLE(os
->os_rootbp
))
3871 dump_object(os
, 0, verbosity
, &print_header
, NULL
, 0);
3873 if (DMU_USERUSED_DNODE(os
) != NULL
&&
3874 DMU_USERUSED_DNODE(os
)->dn_type
!= 0) {
3875 dump_object(os
, DMU_USERUSED_OBJECT
, verbosity
, &print_header
,
3877 dump_object(os
, DMU_GROUPUSED_OBJECT
, verbosity
, &print_header
,
3881 if (DMU_PROJECTUSED_DNODE(os
) != NULL
&&
3882 DMU_PROJECTUSED_DNODE(os
)->dn_type
!= 0)
3883 dump_object(os
, DMU_PROJECTUSED_OBJECT
, verbosity
,
3884 &print_header
, NULL
, 0);
3887 while ((error
= dmu_object_next(os
, &object
, B_FALSE
, 0)) == 0) {
3888 dump_object(os
, object
, verbosity
, &print_header
, &dnode_slots
,
3891 total_slots_used
+= dnode_slots
;
3892 max_slot_used
= object
+ dnode_slots
- 1;
3895 (void) printf("\n");
3897 (void) printf(" Dnode slots:\n");
3898 (void) printf("\tTotal used: %10llu\n",
3899 (u_longlong_t
)total_slots_used
);
3900 (void) printf("\tMax used: %10llu\n",
3901 (u_longlong_t
)max_slot_used
);
3902 (void) printf("\tPercent empty: %10lf\n",
3903 (double)(max_slot_used
- total_slots_used
)*100 /
3904 (double)max_slot_used
);
3905 (void) printf("\n");
3907 if (error
!= ESRCH
) {
3908 (void) fprintf(stderr
, "dmu_object_next() = %d\n", error
);
3912 ASSERT3U(object_count
, ==, usedobjs
);
3914 if (leaked_objects
!= 0) {
3915 (void) printf("%d potentially leaked objects detected\n",
3922 dump_uberblock(uberblock_t
*ub
, const char *header
, const char *footer
)
3924 time_t timestamp
= ub
->ub_timestamp
;
3926 (void) printf("%s", header
? header
: "");
3927 (void) printf("\tmagic = %016llx\n", (u_longlong_t
)ub
->ub_magic
);
3928 (void) printf("\tversion = %llu\n", (u_longlong_t
)ub
->ub_version
);
3929 (void) printf("\ttxg = %llu\n", (u_longlong_t
)ub
->ub_txg
);
3930 (void) printf("\tguid_sum = %llu\n", (u_longlong_t
)ub
->ub_guid_sum
);
3931 (void) printf("\ttimestamp = %llu UTC = %s",
3932 (u_longlong_t
)ub
->ub_timestamp
, asctime(localtime(×tamp
)));
3934 (void) printf("\tmmp_magic = %016llx\n",
3935 (u_longlong_t
)ub
->ub_mmp_magic
);
3936 if (MMP_VALID(ub
)) {
3937 (void) printf("\tmmp_delay = %0llu\n",
3938 (u_longlong_t
)ub
->ub_mmp_delay
);
3939 if (MMP_SEQ_VALID(ub
))
3940 (void) printf("\tmmp_seq = %u\n",
3941 (unsigned int) MMP_SEQ(ub
));
3942 if (MMP_FAIL_INT_VALID(ub
))
3943 (void) printf("\tmmp_fail = %u\n",
3944 (unsigned int) MMP_FAIL_INT(ub
));
3945 if (MMP_INTERVAL_VALID(ub
))
3946 (void) printf("\tmmp_write = %u\n",
3947 (unsigned int) MMP_INTERVAL(ub
));
3948 /* After MMP_* to make summarize_uberblock_mmp cleaner */
3949 (void) printf("\tmmp_valid = %x\n",
3950 (unsigned int) ub
->ub_mmp_config
& 0xFF);
3953 if (dump_opt
['u'] >= 4) {
3954 char blkbuf
[BP_SPRINTF_LEN
];
3955 snprintf_blkptr(blkbuf
, sizeof (blkbuf
), &ub
->ub_rootbp
);
3956 (void) printf("\trootbp = %s\n", blkbuf
);
3958 (void) printf("\tcheckpoint_txg = %llu\n",
3959 (u_longlong_t
)ub
->ub_checkpoint_txg
);
3960 (void) printf("%s", footer
? footer
: "");
3964 dump_config(spa_t
*spa
)
3971 error
= dmu_bonus_hold(spa
->spa_meta_objset
,
3972 spa
->spa_config_object
, FTAG
, &db
);
3975 nvsize
= *(uint64_t *)db
->db_data
;
3976 dmu_buf_rele(db
, FTAG
);
3978 (void) printf("\nMOS Configuration:\n");
3979 dump_packed_nvlist(spa
->spa_meta_objset
,
3980 spa
->spa_config_object
, (void *)&nvsize
, 1);
3982 (void) fprintf(stderr
, "dmu_bonus_hold(%llu) failed, errno %d",
3983 (u_longlong_t
)spa
->spa_config_object
, error
);
3988 dump_cachefile(const char *cachefile
)
3991 struct stat64 statbuf
;
3995 if ((fd
= open64(cachefile
, O_RDONLY
)) < 0) {
3996 (void) printf("cannot open '%s': %s\n", cachefile
,
4001 if (fstat64(fd
, &statbuf
) != 0) {
4002 (void) printf("failed to stat '%s': %s\n", cachefile
,
4007 if ((buf
= malloc(statbuf
.st_size
)) == NULL
) {
4008 (void) fprintf(stderr
, "failed to allocate %llu bytes\n",
4009 (u_longlong_t
)statbuf
.st_size
);
4013 if (read(fd
, buf
, statbuf
.st_size
) != statbuf
.st_size
) {
4014 (void) fprintf(stderr
, "failed to read %llu bytes\n",
4015 (u_longlong_t
)statbuf
.st_size
);
4021 if (nvlist_unpack(buf
, statbuf
.st_size
, &config
, 0) != 0) {
4022 (void) fprintf(stderr
, "failed to unpack nvlist\n");
4028 dump_nvlist(config
, 0);
4030 nvlist_free(config
);
4034 * ZFS label nvlist stats
4036 typedef struct zdb_nvl_stats
{
4039 size_t zns_leaf_largest
;
4040 size_t zns_leaf_total
;
4041 nvlist_t
*zns_string
;
4042 nvlist_t
*zns_uint64
;
4043 nvlist_t
*zns_boolean
;
4047 collect_nvlist_stats(nvlist_t
*nvl
, zdb_nvl_stats_t
*stats
)
4049 nvlist_t
*list
, **array
;
4050 nvpair_t
*nvp
= NULL
;
4054 stats
->zns_list_count
++;
4056 while ((nvp
= nvlist_next_nvpair(nvl
, nvp
)) != NULL
) {
4057 name
= nvpair_name(nvp
);
4059 switch (nvpair_type(nvp
)) {
4060 case DATA_TYPE_STRING
:
4061 fnvlist_add_string(stats
->zns_string
, name
,
4062 fnvpair_value_string(nvp
));
4064 case DATA_TYPE_UINT64
:
4065 fnvlist_add_uint64(stats
->zns_uint64
, name
,
4066 fnvpair_value_uint64(nvp
));
4068 case DATA_TYPE_BOOLEAN
:
4069 fnvlist_add_boolean(stats
->zns_boolean
, name
);
4071 case DATA_TYPE_NVLIST
:
4072 if (nvpair_value_nvlist(nvp
, &list
) == 0)
4073 collect_nvlist_stats(list
, stats
);
4075 case DATA_TYPE_NVLIST_ARRAY
:
4076 if (nvpair_value_nvlist_array(nvp
, &array
, &items
) != 0)
4079 for (i
= 0; i
< items
; i
++) {
4080 collect_nvlist_stats(array
[i
], stats
);
4082 /* collect stats on leaf vdev */
4083 if (strcmp(name
, "children") == 0) {
4086 (void) nvlist_size(array
[i
], &size
,
4088 stats
->zns_leaf_total
+= size
;
4089 if (size
> stats
->zns_leaf_largest
)
4090 stats
->zns_leaf_largest
= size
;
4091 stats
->zns_leaf_count
++;
4096 (void) printf("skip type %d!\n", (int)nvpair_type(nvp
));
4102 dump_nvlist_stats(nvlist_t
*nvl
, size_t cap
)
4104 zdb_nvl_stats_t stats
= { 0 };
4105 size_t size
, sum
= 0, total
;
4108 /* requires nvlist with non-unique names for stat collection */
4109 VERIFY0(nvlist_alloc(&stats
.zns_string
, 0, 0));
4110 VERIFY0(nvlist_alloc(&stats
.zns_uint64
, 0, 0));
4111 VERIFY0(nvlist_alloc(&stats
.zns_boolean
, 0, 0));
4112 VERIFY0(nvlist_size(stats
.zns_boolean
, &noise
, NV_ENCODE_XDR
));
4114 (void) printf("\n\nZFS Label NVList Config Stats:\n");
4116 VERIFY0(nvlist_size(nvl
, &total
, NV_ENCODE_XDR
));
4117 (void) printf(" %d bytes used, %d bytes free (using %4.1f%%)\n\n",
4118 (int)total
, (int)(cap
- total
), 100.0 * total
/ cap
);
4120 collect_nvlist_stats(nvl
, &stats
);
4122 VERIFY0(nvlist_size(stats
.zns_uint64
, &size
, NV_ENCODE_XDR
));
4125 (void) printf("%12s %4d %6d bytes (%5.2f%%)\n", "integers:",
4126 (int)fnvlist_num_pairs(stats
.zns_uint64
),
4127 (int)size
, 100.0 * size
/ total
);
4129 VERIFY0(nvlist_size(stats
.zns_string
, &size
, NV_ENCODE_XDR
));
4132 (void) printf("%12s %4d %6d bytes (%5.2f%%)\n", "strings:",
4133 (int)fnvlist_num_pairs(stats
.zns_string
),
4134 (int)size
, 100.0 * size
/ total
);
4136 VERIFY0(nvlist_size(stats
.zns_boolean
, &size
, NV_ENCODE_XDR
));
4139 (void) printf("%12s %4d %6d bytes (%5.2f%%)\n", "booleans:",
4140 (int)fnvlist_num_pairs(stats
.zns_boolean
),
4141 (int)size
, 100.0 * size
/ total
);
4143 size
= total
- sum
; /* treat remainder as nvlist overhead */
4144 (void) printf("%12s %4d %6d bytes (%5.2f%%)\n\n", "nvlists:",
4145 stats
.zns_list_count
, (int)size
, 100.0 * size
/ total
);
4147 if (stats
.zns_leaf_count
> 0) {
4148 size_t average
= stats
.zns_leaf_total
/ stats
.zns_leaf_count
;
4150 (void) printf("%12s %4d %6d bytes average\n", "leaf vdevs:",
4151 stats
.zns_leaf_count
, (int)average
);
4152 (void) printf("%24d bytes largest\n",
4153 (int)stats
.zns_leaf_largest
);
4155 if (dump_opt
['l'] >= 3 && average
> 0)
4156 (void) printf(" space for %d additional leaf vdevs\n",
4157 (int)((cap
- total
) / average
));
4159 (void) printf("\n");
4161 nvlist_free(stats
.zns_string
);
4162 nvlist_free(stats
.zns_uint64
);
4163 nvlist_free(stats
.zns_boolean
);
4166 typedef struct cksum_record
{
4168 boolean_t labels
[VDEV_LABELS
];
4173 cksum_record_compare(const void *x1
, const void *x2
)
4175 const cksum_record_t
*l
= (cksum_record_t
*)x1
;
4176 const cksum_record_t
*r
= (cksum_record_t
*)x2
;
4177 int arraysize
= ARRAY_SIZE(l
->cksum
.zc_word
);
4180 for (int i
= 0; i
< arraysize
; i
++) {
4181 difference
= TREE_CMP(l
->cksum
.zc_word
[i
], r
->cksum
.zc_word
[i
]);
4186 return (difference
);
4189 static cksum_record_t
*
4190 cksum_record_alloc(zio_cksum_t
*cksum
, int l
)
4192 cksum_record_t
*rec
;
4194 rec
= umem_zalloc(sizeof (*rec
), UMEM_NOFAIL
);
4195 rec
->cksum
= *cksum
;
4196 rec
->labels
[l
] = B_TRUE
;
4201 static cksum_record_t
*
4202 cksum_record_lookup(avl_tree_t
*tree
, zio_cksum_t
*cksum
)
4204 cksum_record_t lookup
= { .cksum
= *cksum
};
4207 return (avl_find(tree
, &lookup
, &where
));
4210 static cksum_record_t
*
4211 cksum_record_insert(avl_tree_t
*tree
, zio_cksum_t
*cksum
, int l
)
4213 cksum_record_t
*rec
;
4215 rec
= cksum_record_lookup(tree
, cksum
);
4217 rec
->labels
[l
] = B_TRUE
;
4219 rec
= cksum_record_alloc(cksum
, l
);
4227 first_label(cksum_record_t
*rec
)
4229 for (int i
= 0; i
< VDEV_LABELS
; i
++)
4237 print_label_numbers(char *prefix
, cksum_record_t
*rec
)
4239 printf("%s", prefix
);
4240 for (int i
= 0; i
< VDEV_LABELS
; i
++)
4241 if (rec
->labels
[i
] == B_TRUE
)
4246 #define MAX_UBERBLOCK_COUNT (VDEV_UBERBLOCK_RING >> UBERBLOCK_SHIFT)
4248 typedef struct zdb_label
{
4250 uint64_t label_offset
;
4251 nvlist_t
*config_nv
;
4252 cksum_record_t
*config
;
4253 cksum_record_t
*uberblocks
[MAX_UBERBLOCK_COUNT
];
4254 boolean_t header_printed
;
4255 boolean_t read_failed
;
4256 boolean_t cksum_valid
;
4260 print_label_header(zdb_label_t
*label
, int l
)
4266 if (label
->header_printed
== B_TRUE
)
4269 (void) printf("------------------------------------\n");
4270 (void) printf("LABEL %d %s\n", l
,
4271 label
->cksum_valid
? "" : "(Bad label cksum)");
4272 (void) printf("------------------------------------\n");
4274 label
->header_printed
= B_TRUE
;
4278 print_l2arc_header(void)
4280 (void) printf("------------------------------------\n");
4281 (void) printf("L2ARC device header\n");
4282 (void) printf("------------------------------------\n");
4286 print_l2arc_log_blocks(void)
4288 (void) printf("------------------------------------\n");
4289 (void) printf("L2ARC device log blocks\n");
4290 (void) printf("------------------------------------\n");
4294 dump_l2arc_log_entries(uint64_t log_entries
,
4295 l2arc_log_ent_phys_t
*le
, uint64_t i
)
4297 for (int j
= 0; j
< log_entries
; j
++) {
4298 dva_t dva
= le
[j
].le_dva
;
4299 (void) printf("lb[%4llu]\tle[%4d]\tDVA asize: %llu, "
4300 "vdev: %llu, offset: %llu\n",
4301 (u_longlong_t
)i
, j
+ 1,
4302 (u_longlong_t
)DVA_GET_ASIZE(&dva
),
4303 (u_longlong_t
)DVA_GET_VDEV(&dva
),
4304 (u_longlong_t
)DVA_GET_OFFSET(&dva
));
4305 (void) printf("|\t\t\t\tbirth: %llu\n",
4306 (u_longlong_t
)le
[j
].le_birth
);
4307 (void) printf("|\t\t\t\tlsize: %llu\n",
4308 (u_longlong_t
)L2BLK_GET_LSIZE((&le
[j
])->le_prop
));
4309 (void) printf("|\t\t\t\tpsize: %llu\n",
4310 (u_longlong_t
)L2BLK_GET_PSIZE((&le
[j
])->le_prop
));
4311 (void) printf("|\t\t\t\tcompr: %llu\n",
4312 (u_longlong_t
)L2BLK_GET_COMPRESS((&le
[j
])->le_prop
));
4313 (void) printf("|\t\t\t\tcomplevel: %llu\n",
4314 (u_longlong_t
)(&le
[j
])->le_complevel
);
4315 (void) printf("|\t\t\t\ttype: %llu\n",
4316 (u_longlong_t
)L2BLK_GET_TYPE((&le
[j
])->le_prop
));
4317 (void) printf("|\t\t\t\tprotected: %llu\n",
4318 (u_longlong_t
)L2BLK_GET_PROTECTED((&le
[j
])->le_prop
));
4319 (void) printf("|\t\t\t\tprefetch: %llu\n",
4320 (u_longlong_t
)L2BLK_GET_PREFETCH((&le
[j
])->le_prop
));
4321 (void) printf("|\t\t\t\taddress: %llu\n",
4322 (u_longlong_t
)le
[j
].le_daddr
);
4323 (void) printf("|\t\t\t\tARC state: %llu\n",
4324 (u_longlong_t
)L2BLK_GET_STATE((&le
[j
])->le_prop
));
4325 (void) printf("|\n");
4327 (void) printf("\n");
4331 dump_l2arc_log_blkptr(l2arc_log_blkptr_t lbps
)
4333 (void) printf("|\t\tdaddr: %llu\n", (u_longlong_t
)lbps
.lbp_daddr
);
4334 (void) printf("|\t\tpayload_asize: %llu\n",
4335 (u_longlong_t
)lbps
.lbp_payload_asize
);
4336 (void) printf("|\t\tpayload_start: %llu\n",
4337 (u_longlong_t
)lbps
.lbp_payload_start
);
4338 (void) printf("|\t\tlsize: %llu\n",
4339 (u_longlong_t
)L2BLK_GET_LSIZE((&lbps
)->lbp_prop
));
4340 (void) printf("|\t\tasize: %llu\n",
4341 (u_longlong_t
)L2BLK_GET_PSIZE((&lbps
)->lbp_prop
));
4342 (void) printf("|\t\tcompralgo: %llu\n",
4343 (u_longlong_t
)L2BLK_GET_COMPRESS((&lbps
)->lbp_prop
));
4344 (void) printf("|\t\tcksumalgo: %llu\n",
4345 (u_longlong_t
)L2BLK_GET_CHECKSUM((&lbps
)->lbp_prop
));
4346 (void) printf("|\n\n");
4350 dump_l2arc_log_blocks(int fd
, l2arc_dev_hdr_phys_t l2dhdr
,
4351 l2arc_dev_hdr_phys_t
*rebuild
)
4353 l2arc_log_blk_phys_t this_lb
;
4355 l2arc_log_blkptr_t lbps
[2];
4362 print_l2arc_log_blocks();
4363 bcopy((&l2dhdr
)->dh_start_lbps
, lbps
, sizeof (lbps
));
4365 dev
.l2ad_evict
= l2dhdr
.dh_evict
;
4366 dev
.l2ad_start
= l2dhdr
.dh_start
;
4367 dev
.l2ad_end
= l2dhdr
.dh_end
;
4369 if (l2dhdr
.dh_start_lbps
[0].lbp_daddr
== 0) {
4370 /* no log blocks to read */
4371 if (!dump_opt
['q']) {
4372 (void) printf("No log blocks to read\n");
4373 (void) printf("\n");
4377 dev
.l2ad_hand
= lbps
[0].lbp_daddr
+
4378 L2BLK_GET_PSIZE((&lbps
[0])->lbp_prop
);
4381 dev
.l2ad_first
= !!(l2dhdr
.dh_flags
& L2ARC_DEV_HDR_EVICT_FIRST
);
4384 if (!l2arc_log_blkptr_valid(&dev
, &lbps
[0]))
4387 /* L2BLK_GET_PSIZE returns aligned size for log blocks */
4388 asize
= L2BLK_GET_PSIZE((&lbps
[0])->lbp_prop
);
4389 if (pread64(fd
, &this_lb
, asize
, lbps
[0].lbp_daddr
) != asize
) {
4390 if (!dump_opt
['q']) {
4391 (void) printf("Error while reading next log "
4397 fletcher_4_native_varsize(&this_lb
, asize
, &cksum
);
4398 if (!ZIO_CHECKSUM_EQUAL(cksum
, lbps
[0].lbp_cksum
)) {
4400 if (!dump_opt
['q']) {
4401 (void) printf("Invalid cksum\n");
4402 dump_l2arc_log_blkptr(lbps
[0]);
4407 switch (L2BLK_GET_COMPRESS((&lbps
[0])->lbp_prop
)) {
4408 case ZIO_COMPRESS_OFF
:
4411 abd
= abd_alloc_for_io(asize
, B_TRUE
);
4412 abd_copy_from_buf_off(abd
, &this_lb
, 0, asize
);
4413 zio_decompress_data(L2BLK_GET_COMPRESS(
4414 (&lbps
[0])->lbp_prop
), abd
, &this_lb
,
4415 asize
, sizeof (this_lb
), NULL
);
4420 if (this_lb
.lb_magic
== BSWAP_64(L2ARC_LOG_BLK_MAGIC
))
4421 byteswap_uint64_array(&this_lb
, sizeof (this_lb
));
4422 if (this_lb
.lb_magic
!= L2ARC_LOG_BLK_MAGIC
) {
4424 (void) printf("Invalid log block magic\n\n");
4428 rebuild
->dh_lb_count
++;
4429 rebuild
->dh_lb_asize
+= asize
;
4430 if (dump_opt
['l'] > 1 && !dump_opt
['q']) {
4431 (void) printf("lb[%4llu]\tmagic: %llu\n",
4432 (u_longlong_t
)rebuild
->dh_lb_count
,
4433 (u_longlong_t
)this_lb
.lb_magic
);
4434 dump_l2arc_log_blkptr(lbps
[0]);
4437 if (dump_opt
['l'] > 2 && !dump_opt
['q'])
4438 dump_l2arc_log_entries(l2dhdr
.dh_log_entries
,
4440 rebuild
->dh_lb_count
);
4442 if (l2arc_range_check_overlap(lbps
[1].lbp_payload_start
,
4443 lbps
[0].lbp_payload_start
, dev
.l2ad_evict
) &&
4448 lbps
[1] = this_lb
.lb_prev_lbp
;
4451 if (!dump_opt
['q']) {
4452 (void) printf("log_blk_count:\t %llu with valid cksum\n",
4453 (u_longlong_t
)rebuild
->dh_lb_count
);
4454 (void) printf("\t\t %d with invalid cksum\n", failed
);
4455 (void) printf("log_blk_asize:\t %llu\n\n",
4456 (u_longlong_t
)rebuild
->dh_lb_asize
);
4461 dump_l2arc_header(int fd
)
4463 l2arc_dev_hdr_phys_t l2dhdr
, rebuild
;
4464 int error
= B_FALSE
;
4466 bzero(&l2dhdr
, sizeof (l2dhdr
));
4467 bzero(&rebuild
, sizeof (rebuild
));
4469 if (pread64(fd
, &l2dhdr
, sizeof (l2dhdr
),
4470 VDEV_LABEL_START_SIZE
) != sizeof (l2dhdr
)) {
4473 if (l2dhdr
.dh_magic
== BSWAP_64(L2ARC_DEV_HDR_MAGIC
))
4474 byteswap_uint64_array(&l2dhdr
, sizeof (l2dhdr
));
4476 if (l2dhdr
.dh_magic
!= L2ARC_DEV_HDR_MAGIC
)
4481 (void) printf("L2ARC device header not found\n\n");
4482 /* Do not return an error here for backward compatibility */
4484 } else if (!dump_opt
['q']) {
4485 print_l2arc_header();
4487 (void) printf(" magic: %llu\n",
4488 (u_longlong_t
)l2dhdr
.dh_magic
);
4489 (void) printf(" version: %llu\n",
4490 (u_longlong_t
)l2dhdr
.dh_version
);
4491 (void) printf(" pool_guid: %llu\n",
4492 (u_longlong_t
)l2dhdr
.dh_spa_guid
);
4493 (void) printf(" flags: %llu\n",
4494 (u_longlong_t
)l2dhdr
.dh_flags
);
4495 (void) printf(" start_lbps[0]: %llu\n",
4497 l2dhdr
.dh_start_lbps
[0].lbp_daddr
);
4498 (void) printf(" start_lbps[1]: %llu\n",
4500 l2dhdr
.dh_start_lbps
[1].lbp_daddr
);
4501 (void) printf(" log_blk_ent: %llu\n",
4502 (u_longlong_t
)l2dhdr
.dh_log_entries
);
4503 (void) printf(" start: %llu\n",
4504 (u_longlong_t
)l2dhdr
.dh_start
);
4505 (void) printf(" end: %llu\n",
4506 (u_longlong_t
)l2dhdr
.dh_end
);
4507 (void) printf(" evict: %llu\n",
4508 (u_longlong_t
)l2dhdr
.dh_evict
);
4509 (void) printf(" lb_asize_refcount: %llu\n",
4510 (u_longlong_t
)l2dhdr
.dh_lb_asize
);
4511 (void) printf(" lb_count_refcount: %llu\n",
4512 (u_longlong_t
)l2dhdr
.dh_lb_count
);
4513 (void) printf(" trim_action_time: %llu\n",
4514 (u_longlong_t
)l2dhdr
.dh_trim_action_time
);
4515 (void) printf(" trim_state: %llu\n\n",
4516 (u_longlong_t
)l2dhdr
.dh_trim_state
);
4519 dump_l2arc_log_blocks(fd
, l2dhdr
, &rebuild
);
4521 * The total aligned size of log blocks and the number of log blocks
4522 * reported in the header of the device may be less than what zdb
4523 * reports by dump_l2arc_log_blocks() which emulates l2arc_rebuild().
4524 * This happens because dump_l2arc_log_blocks() lacks the memory
4525 * pressure valve that l2arc_rebuild() has. Thus, if we are on a system
4526 * with low memory, l2arc_rebuild will exit prematurely and dh_lb_asize
4527 * and dh_lb_count will be lower to begin with than what exists on the
4528 * device. This is normal and zdb should not exit with an error. The
4529 * opposite case should never happen though, the values reported in the
4530 * header should never be higher than what dump_l2arc_log_blocks() and
4531 * l2arc_rebuild() report. If this happens there is a leak in the
4532 * accounting of log blocks.
4534 if (l2dhdr
.dh_lb_asize
> rebuild
.dh_lb_asize
||
4535 l2dhdr
.dh_lb_count
> rebuild
.dh_lb_count
)
4542 dump_config_from_label(zdb_label_t
*label
, size_t buflen
, int l
)
4547 if ((dump_opt
['l'] < 3) && (first_label(label
->config
) != l
))
4550 print_label_header(label
, l
);
4551 dump_nvlist(label
->config_nv
, 4);
4552 print_label_numbers(" labels = ", label
->config
);
4554 if (dump_opt
['l'] >= 2)
4555 dump_nvlist_stats(label
->config_nv
, buflen
);
4558 #define ZDB_MAX_UB_HEADER_SIZE 32
4561 dump_label_uberblocks(zdb_label_t
*label
, uint64_t ashift
, int label_num
)
4565 char header
[ZDB_MAX_UB_HEADER_SIZE
];
4567 vd
.vdev_ashift
= ashift
;
4570 for (int i
= 0; i
< VDEV_UBERBLOCK_COUNT(&vd
); i
++) {
4571 uint64_t uoff
= VDEV_UBERBLOCK_OFFSET(&vd
, i
);
4572 uberblock_t
*ub
= (void *)((char *)&label
->label
+ uoff
);
4573 cksum_record_t
*rec
= label
->uberblocks
[i
];
4576 if (dump_opt
['u'] >= 2) {
4577 print_label_header(label
, label_num
);
4578 (void) printf(" Uberblock[%d] invalid\n", i
);
4583 if ((dump_opt
['u'] < 3) && (first_label(rec
) != label_num
))
4586 if ((dump_opt
['u'] < 4) &&
4587 (ub
->ub_mmp_magic
== MMP_MAGIC
) && ub
->ub_mmp_delay
&&
4588 (i
>= VDEV_UBERBLOCK_COUNT(&vd
) - MMP_BLOCKS_PER_LABEL
))
4591 print_label_header(label
, label_num
);
4592 (void) snprintf(header
, ZDB_MAX_UB_HEADER_SIZE
,
4593 " Uberblock[%d]\n", i
);
4594 dump_uberblock(ub
, header
, "");
4595 print_label_numbers(" labels = ", rec
);
4599 static char curpath
[PATH_MAX
];
4602 * Iterate through the path components, recursively passing
4603 * current one's obj and remaining path until we find the obj
4607 dump_path_impl(objset_t
*os
, uint64_t obj
, char *name
, uint64_t *retobj
)
4610 boolean_t header
= B_TRUE
;
4614 dmu_object_info_t doi
;
4616 if ((s
= strchr(name
, '/')) != NULL
)
4618 err
= zap_lookup(os
, obj
, name
, 8, 1, &child_obj
);
4620 (void) strlcat(curpath
, name
, sizeof (curpath
));
4623 (void) fprintf(stderr
, "failed to lookup %s: %s\n",
4624 curpath
, strerror(err
));
4628 child_obj
= ZFS_DIRENT_OBJ(child_obj
);
4629 err
= sa_buf_hold(os
, child_obj
, FTAG
, &db
);
4631 (void) fprintf(stderr
,
4632 "failed to get SA dbuf for obj %llu: %s\n",
4633 (u_longlong_t
)child_obj
, strerror(err
));
4636 dmu_object_info_from_db(db
, &doi
);
4637 sa_buf_rele(db
, FTAG
);
4639 if (doi
.doi_bonus_type
!= DMU_OT_SA
&&
4640 doi
.doi_bonus_type
!= DMU_OT_ZNODE
) {
4641 (void) fprintf(stderr
, "invalid bonus type %d for obj %llu\n",
4642 doi
.doi_bonus_type
, (u_longlong_t
)child_obj
);
4646 if (dump_opt
['v'] > 6) {
4647 (void) printf("obj=%llu %s type=%d bonustype=%d\n",
4648 (u_longlong_t
)child_obj
, curpath
, doi
.doi_type
,
4649 doi
.doi_bonus_type
);
4652 (void) strlcat(curpath
, "/", sizeof (curpath
));
4654 switch (doi
.doi_type
) {
4655 case DMU_OT_DIRECTORY_CONTENTS
:
4656 if (s
!= NULL
&& *(s
+ 1) != '\0')
4657 return (dump_path_impl(os
, child_obj
, s
+ 1, retobj
));
4659 case DMU_OT_PLAIN_FILE_CONTENTS
:
4660 if (retobj
!= NULL
) {
4661 *retobj
= child_obj
;
4663 dump_object(os
, child_obj
, dump_opt
['v'], &header
,
4668 (void) fprintf(stderr
, "object %llu has non-file/directory "
4669 "type %d\n", (u_longlong_t
)obj
, doi
.doi_type
);
4677 * Dump the blocks for the object specified by path inside the dataset.
4680 dump_path(char *ds
, char *path
, uint64_t *retobj
)
4686 err
= open_objset(ds
, FTAG
, &os
);
4690 err
= zap_lookup(os
, MASTER_NODE_OBJ
, ZFS_ROOT_OBJ
, 8, 1, &root_obj
);
4692 (void) fprintf(stderr
, "can't lookup root znode: %s\n",
4694 close_objset(os
, FTAG
);
4698 (void) snprintf(curpath
, sizeof (curpath
), "dataset=%s path=/", ds
);
4700 err
= dump_path_impl(os
, root_obj
, path
, retobj
);
4702 close_objset(os
, FTAG
);
4707 zdb_copy_object(objset_t
*os
, uint64_t srcobj
, char *destfile
)
4710 uint64_t size
, readsize
, oursize
, offset
;
4714 (void) printf("Copying object %" PRIu64
" to file %s\n", srcobj
,
4717 VERIFY3P(os
, ==, sa_os
);
4718 if ((err
= sa_handle_get(os
, srcobj
, NULL
, SA_HDL_PRIVATE
, &hdl
))) {
4719 (void) printf("Failed to get handle for SA znode\n");
4722 if ((err
= sa_lookup(hdl
, sa_attr_table
[ZPL_SIZE
], &size
, 8))) {
4723 (void) sa_handle_destroy(hdl
);
4726 (void) sa_handle_destroy(hdl
);
4728 (void) printf("Object %" PRIu64
" is %" PRIu64
" bytes\n", srcobj
,
4734 int fd
= open(destfile
, O_WRONLY
| O_CREAT
| O_TRUNC
, 0644);
4736 * We cap the size at 1 mebibyte here to prevent
4737 * allocation failures and nigh-infinite printing if the
4738 * object is extremely large.
4740 oursize
= MIN(size
, 1 << 20);
4742 char *buf
= kmem_alloc(oursize
, KM_NOSLEEP
);
4747 while (offset
< size
) {
4748 readsize
= MIN(size
- offset
, 1 << 20);
4749 err
= dmu_read(os
, srcobj
, offset
, readsize
, buf
, 0);
4751 (void) printf("got error %u from dmu_read\n", err
);
4752 kmem_free(buf
, oursize
);
4755 if (dump_opt
['v'] > 3) {
4756 (void) printf("Read offset=%" PRIu64
" size=%" PRIu64
4757 " error=%d\n", offset
, readsize
, err
);
4760 writesize
= write(fd
, buf
, readsize
);
4761 if (writesize
< 0) {
4764 } else if (writesize
!= readsize
) {
4765 /* Incomplete write */
4766 (void) fprintf(stderr
, "Short write, only wrote %llu of"
4767 " %" PRIu64
" bytes, exiting...\n",
4768 (u_longlong_t
)writesize
, readsize
);
4778 kmem_free(buf
, oursize
);
4784 label_cksum_valid(vdev_label_t
*label
, uint64_t offset
)
4786 zio_checksum_info_t
*ci
= &zio_checksum_table
[ZIO_CHECKSUM_LABEL
];
4787 zio_cksum_t expected_cksum
;
4788 zio_cksum_t actual_cksum
;
4789 zio_cksum_t verifier
;
4793 void *data
= (char *)label
+ offsetof(vdev_label_t
, vl_vdev_phys
);
4794 eck
= (zio_eck_t
*)((char *)(data
) + VDEV_PHYS_SIZE
) - 1;
4796 offset
+= offsetof(vdev_label_t
, vl_vdev_phys
);
4797 ZIO_SET_CHECKSUM(&verifier
, offset
, 0, 0, 0);
4799 byteswap
= (eck
->zec_magic
== BSWAP_64(ZEC_MAGIC
));
4801 byteswap_uint64_array(&verifier
, sizeof (zio_cksum_t
));
4803 expected_cksum
= eck
->zec_cksum
;
4804 eck
->zec_cksum
= verifier
;
4806 abd_t
*abd
= abd_get_from_buf(data
, VDEV_PHYS_SIZE
);
4807 ci
->ci_func
[byteswap
](abd
, VDEV_PHYS_SIZE
, NULL
, &actual_cksum
);
4811 byteswap_uint64_array(&expected_cksum
, sizeof (zio_cksum_t
));
4813 if (ZIO_CHECKSUM_EQUAL(actual_cksum
, expected_cksum
))
4820 dump_label(const char *dev
)
4822 char path
[MAXPATHLEN
];
4823 zdb_label_t labels
[VDEV_LABELS
];
4824 uint64_t psize
, ashift
, l2cache
;
4825 struct stat64 statbuf
;
4826 boolean_t config_found
= B_FALSE
;
4827 boolean_t error
= B_FALSE
;
4828 boolean_t read_l2arc_header
= B_FALSE
;
4829 avl_tree_t config_tree
;
4830 avl_tree_t uberblock_tree
;
4831 void *node
, *cookie
;
4834 bzero(labels
, sizeof (labels
));
4837 * Check if we were given absolute path and use it as is.
4838 * Otherwise if the provided vdev name doesn't point to a file,
4839 * try prepending expected disk paths and partition numbers.
4841 (void) strlcpy(path
, dev
, sizeof (path
));
4842 if (dev
[0] != '/' && stat64(path
, &statbuf
) != 0) {
4845 error
= zfs_resolve_shortname(dev
, path
, MAXPATHLEN
);
4846 if (error
== 0 && zfs_dev_is_whole_disk(path
)) {
4847 if (zfs_append_partition(path
, MAXPATHLEN
) == -1)
4851 if (error
|| (stat64(path
, &statbuf
) != 0)) {
4852 (void) printf("failed to find device %s, try "
4853 "specifying absolute path instead\n", dev
);
4858 if ((fd
= open64(path
, O_RDONLY
)) < 0) {
4859 (void) printf("cannot open '%s': %s\n", path
, strerror(errno
));
4863 if (fstat64_blk(fd
, &statbuf
) != 0) {
4864 (void) printf("failed to stat '%s': %s\n", path
,
4870 if (S_ISBLK(statbuf
.st_mode
) && zfs_dev_flush(fd
) != 0)
4871 (void) printf("failed to invalidate cache '%s' : %s\n", path
,
4874 avl_create(&config_tree
, cksum_record_compare
,
4875 sizeof (cksum_record_t
), offsetof(cksum_record_t
, link
));
4876 avl_create(&uberblock_tree
, cksum_record_compare
,
4877 sizeof (cksum_record_t
), offsetof(cksum_record_t
, link
));
4879 psize
= statbuf
.st_size
;
4880 psize
= P2ALIGN(psize
, (uint64_t)sizeof (vdev_label_t
));
4881 ashift
= SPA_MINBLOCKSHIFT
;
4884 * 1. Read the label from disk
4885 * 2. Verify label cksum
4886 * 3. Unpack the configuration and insert in config tree.
4887 * 4. Traverse all uberblocks and insert in uberblock tree.
4889 for (int l
= 0; l
< VDEV_LABELS
; l
++) {
4890 zdb_label_t
*label
= &labels
[l
];
4891 char *buf
= label
->label
.vl_vdev_phys
.vp_nvlist
;
4892 size_t buflen
= sizeof (label
->label
.vl_vdev_phys
.vp_nvlist
);
4894 cksum_record_t
*rec
;
4898 label
->label_offset
= vdev_label_offset(psize
, l
, 0);
4900 if (pread64(fd
, &label
->label
, sizeof (label
->label
),
4901 label
->label_offset
) != sizeof (label
->label
)) {
4903 (void) printf("failed to read label %d\n", l
);
4904 label
->read_failed
= B_TRUE
;
4909 label
->read_failed
= B_FALSE
;
4910 label
->cksum_valid
= label_cksum_valid(&label
->label
,
4911 label
->label_offset
);
4913 if (nvlist_unpack(buf
, buflen
, &config
, 0) == 0) {
4914 nvlist_t
*vdev_tree
= NULL
;
4917 if ((nvlist_lookup_nvlist(config
,
4918 ZPOOL_CONFIG_VDEV_TREE
, &vdev_tree
) != 0) ||
4919 (nvlist_lookup_uint64(vdev_tree
,
4920 ZPOOL_CONFIG_ASHIFT
, &ashift
) != 0))
4921 ashift
= SPA_MINBLOCKSHIFT
;
4923 if (nvlist_size(config
, &size
, NV_ENCODE_XDR
) != 0)
4926 /* If the device is a cache device clear the header. */
4927 if (!read_l2arc_header
) {
4928 if (nvlist_lookup_uint64(config
,
4929 ZPOOL_CONFIG_POOL_STATE
, &l2cache
) == 0 &&
4930 l2cache
== POOL_STATE_L2CACHE
) {
4931 read_l2arc_header
= B_TRUE
;
4935 fletcher_4_native_varsize(buf
, size
, &cksum
);
4936 rec
= cksum_record_insert(&config_tree
, &cksum
, l
);
4938 label
->config
= rec
;
4939 label
->config_nv
= config
;
4940 config_found
= B_TRUE
;
4945 vd
.vdev_ashift
= ashift
;
4948 for (int i
= 0; i
< VDEV_UBERBLOCK_COUNT(&vd
); i
++) {
4949 uint64_t uoff
= VDEV_UBERBLOCK_OFFSET(&vd
, i
);
4950 uberblock_t
*ub
= (void *)((char *)label
+ uoff
);
4952 if (uberblock_verify(ub
))
4955 fletcher_4_native_varsize(ub
, sizeof (*ub
), &cksum
);
4956 rec
= cksum_record_insert(&uberblock_tree
, &cksum
, l
);
4958 label
->uberblocks
[i
] = rec
;
4963 * Dump the label and uberblocks.
4965 for (int l
= 0; l
< VDEV_LABELS
; l
++) {
4966 zdb_label_t
*label
= &labels
[l
];
4967 size_t buflen
= sizeof (label
->label
.vl_vdev_phys
.vp_nvlist
);
4969 if (label
->read_failed
== B_TRUE
)
4972 if (label
->config_nv
) {
4973 dump_config_from_label(label
, buflen
, l
);
4976 (void) printf("failed to unpack label %d\n", l
);
4980 dump_label_uberblocks(label
, ashift
, l
);
4982 nvlist_free(label
->config_nv
);
4986 * Dump the L2ARC header, if existent.
4988 if (read_l2arc_header
)
4989 error
|= dump_l2arc_header(fd
);
4992 while ((node
= avl_destroy_nodes(&config_tree
, &cookie
)) != NULL
)
4993 umem_free(node
, sizeof (cksum_record_t
));
4996 while ((node
= avl_destroy_nodes(&uberblock_tree
, &cookie
)) != NULL
)
4997 umem_free(node
, sizeof (cksum_record_t
));
4999 avl_destroy(&config_tree
);
5000 avl_destroy(&uberblock_tree
);
5004 return (config_found
== B_FALSE
? 2 :
5005 (error
== B_TRUE
? 1 : 0));
5008 static uint64_t dataset_feature_count
[SPA_FEATURES
];
5009 static uint64_t global_feature_count
[SPA_FEATURES
];
5010 static uint64_t remap_deadlist_count
= 0;
5013 dump_one_objset(const char *dsname
, void *arg
)
5020 error
= open_objset(dsname
, FTAG
, &os
);
5024 for (f
= 0; f
< SPA_FEATURES
; f
++) {
5025 if (!dsl_dataset_feature_is_active(dmu_objset_ds(os
), f
))
5027 ASSERT(spa_feature_table
[f
].fi_flags
&
5028 ZFEATURE_FLAG_PER_DATASET
);
5029 dataset_feature_count
[f
]++;
5032 if (dsl_dataset_remap_deadlist_exists(dmu_objset_ds(os
))) {
5033 remap_deadlist_count
++;
5036 for (dsl_bookmark_node_t
*dbn
=
5037 avl_first(&dmu_objset_ds(os
)->ds_bookmarks
); dbn
!= NULL
;
5038 dbn
= AVL_NEXT(&dmu_objset_ds(os
)->ds_bookmarks
, dbn
)) {
5039 mos_obj_refd(dbn
->dbn_phys
.zbm_redaction_obj
);
5040 if (dbn
->dbn_phys
.zbm_redaction_obj
!= 0)
5041 global_feature_count
[SPA_FEATURE_REDACTION_BOOKMARKS
]++;
5042 if (dbn
->dbn_phys
.zbm_flags
& ZBM_FLAG_HAS_FBN
)
5043 global_feature_count
[SPA_FEATURE_BOOKMARK_WRITTEN
]++;
5046 if (dsl_deadlist_is_open(&dmu_objset_ds(os
)->ds_dir
->dd_livelist
) &&
5047 !dmu_objset_is_snapshot(os
)) {
5048 global_feature_count
[SPA_FEATURE_LIVELIST
]++;
5052 close_objset(os
, FTAG
);
5053 fuid_table_destroy();
5060 #define PSIZE_HISTO_SIZE (SPA_OLD_MAXBLOCKSIZE / SPA_MINBLOCKSIZE + 2)
5061 typedef struct zdb_blkstats
{
5067 uint64_t zb_ditto_samevdev
;
5068 uint64_t zb_ditto_same_ms
;
5069 uint64_t zb_psize_histogram
[PSIZE_HISTO_SIZE
];
5073 * Extended object types to report deferred frees and dedup auto-ditto blocks.
5075 #define ZDB_OT_DEFERRED (DMU_OT_NUMTYPES + 0)
5076 #define ZDB_OT_DITTO (DMU_OT_NUMTYPES + 1)
5077 #define ZDB_OT_OTHER (DMU_OT_NUMTYPES + 2)
5078 #define ZDB_OT_TOTAL (DMU_OT_NUMTYPES + 3)
5080 static const char *zdb_ot_extname
[] = {
5087 #define ZB_TOTAL DN_MAX_LEVELS
5088 #define SPA_MAX_FOR_16M (SPA_MAXBLOCKSHIFT+1)
5090 typedef struct zdb_cb
{
5091 zdb_blkstats_t zcb_type
[ZB_TOTAL
+ 1][ZDB_OT_TOTAL
+ 1];
5092 uint64_t zcb_removing_size
;
5093 uint64_t zcb_checkpoint_size
;
5094 uint64_t zcb_dedup_asize
;
5095 uint64_t zcb_dedup_blocks
;
5096 uint64_t zcb_psize_count
[SPA_MAX_FOR_16M
];
5097 uint64_t zcb_lsize_count
[SPA_MAX_FOR_16M
];
5098 uint64_t zcb_asize_count
[SPA_MAX_FOR_16M
];
5099 uint64_t zcb_psize_len
[SPA_MAX_FOR_16M
];
5100 uint64_t zcb_lsize_len
[SPA_MAX_FOR_16M
];
5101 uint64_t zcb_asize_len
[SPA_MAX_FOR_16M
];
5102 uint64_t zcb_psize_total
;
5103 uint64_t zcb_lsize_total
;
5104 uint64_t zcb_asize_total
;
5105 uint64_t zcb_embedded_blocks
[NUM_BP_EMBEDDED_TYPES
];
5106 uint64_t zcb_embedded_histogram
[NUM_BP_EMBEDDED_TYPES
]
5107 [BPE_PAYLOAD_SIZE
+ 1];
5109 hrtime_t zcb_lastprint
;
5110 uint64_t zcb_totalasize
;
5111 uint64_t zcb_errors
[256];
5115 uint32_t **zcb_vd_obsolete_counts
;
5118 /* test if two DVA offsets from same vdev are within the same metaslab */
5120 same_metaslab(spa_t
*spa
, uint64_t vdev
, uint64_t off1
, uint64_t off2
)
5122 vdev_t
*vd
= vdev_lookup_top(spa
, vdev
);
5123 uint64_t ms_shift
= vd
->vdev_ms_shift
;
5125 return ((off1
>> ms_shift
) == (off2
>> ms_shift
));
5129 * Used to simplify reporting of the histogram data.
5131 typedef struct one_histo
{
5135 uint64_t cumulative
;
5139 * The number of separate histograms processed for psize, lsize and asize.
5144 * This routine will create a fixed column size output of three different
5145 * histograms showing by blocksize of 512 - 2^ SPA_MAX_FOR_16M
5146 * the count, length and cumulative length of the psize, lsize and
5149 * All three types of blocks are listed on a single line
5151 * By default the table is printed in nicenumber format (e.g. 123K) but
5152 * if the '-P' parameter is specified then the full raw number (parseable)
5156 dump_size_histograms(zdb_cb_t
*zcb
)
5159 * A temporary buffer that allows us to convert a number into
5160 * a string using zdb_nicenumber to allow either raw or human
5161 * readable numbers to be output.
5166 * Define titles which are used in the headers of the tables
5167 * printed by this routine.
5169 const char blocksize_title1
[] = "block";
5170 const char blocksize_title2
[] = "size";
5171 const char count_title
[] = "Count";
5172 const char length_title
[] = "Size";
5173 const char cumulative_title
[] = "Cum.";
5176 * Setup the histogram arrays (psize, lsize, and asize).
5178 one_histo_t parm_histo
[NUM_HISTO
];
5180 parm_histo
[0].name
= "psize";
5181 parm_histo
[0].count
= zcb
->zcb_psize_count
;
5182 parm_histo
[0].len
= zcb
->zcb_psize_len
;
5183 parm_histo
[0].cumulative
= 0;
5185 parm_histo
[1].name
= "lsize";
5186 parm_histo
[1].count
= zcb
->zcb_lsize_count
;
5187 parm_histo
[1].len
= zcb
->zcb_lsize_len
;
5188 parm_histo
[1].cumulative
= 0;
5190 parm_histo
[2].name
= "asize";
5191 parm_histo
[2].count
= zcb
->zcb_asize_count
;
5192 parm_histo
[2].len
= zcb
->zcb_asize_len
;
5193 parm_histo
[2].cumulative
= 0;
5196 (void) printf("\nBlock Size Histogram\n");
5198 * Print the first line titles
5201 (void) printf("\n%s\t", blocksize_title1
);
5203 (void) printf("\n%7s ", blocksize_title1
);
5205 for (int j
= 0; j
< NUM_HISTO
; j
++) {
5206 if (dump_opt
['P']) {
5207 if (j
< NUM_HISTO
- 1) {
5208 (void) printf("%s\t\t\t", parm_histo
[j
].name
);
5210 /* Don't print trailing spaces */
5211 (void) printf(" %s", parm_histo
[j
].name
);
5214 if (j
< NUM_HISTO
- 1) {
5215 /* Left aligned strings in the output */
5216 (void) printf("%-7s ",
5217 parm_histo
[j
].name
);
5219 /* Don't print trailing spaces */
5220 (void) printf("%s", parm_histo
[j
].name
);
5224 (void) printf("\n");
5227 * Print the second line titles
5229 if (dump_opt
['P']) {
5230 (void) printf("%s\t", blocksize_title2
);
5232 (void) printf("%7s ", blocksize_title2
);
5235 for (int i
= 0; i
< NUM_HISTO
; i
++) {
5236 if (dump_opt
['P']) {
5237 (void) printf("%s\t%s\t%s\t",
5238 count_title
, length_title
, cumulative_title
);
5240 (void) printf("%7s%7s%7s",
5241 count_title
, length_title
, cumulative_title
);
5244 (void) printf("\n");
5249 for (int i
= SPA_MINBLOCKSHIFT
; i
< SPA_MAX_FOR_16M
; i
++) {
5252 * Print the first column showing the blocksize
5254 zdb_nicenum((1ULL << i
), numbuf
, sizeof (numbuf
));
5256 if (dump_opt
['P']) {
5257 printf("%s", numbuf
);
5259 printf("%7s:", numbuf
);
5263 * Print the remaining set of 3 columns per size:
5264 * for psize, lsize and asize
5266 for (int j
= 0; j
< NUM_HISTO
; j
++) {
5267 parm_histo
[j
].cumulative
+= parm_histo
[j
].len
[i
];
5269 zdb_nicenum(parm_histo
[j
].count
[i
],
5270 numbuf
, sizeof (numbuf
));
5272 (void) printf("\t%s", numbuf
);
5274 (void) printf("%7s", numbuf
);
5276 zdb_nicenum(parm_histo
[j
].len
[i
],
5277 numbuf
, sizeof (numbuf
));
5279 (void) printf("\t%s", numbuf
);
5281 (void) printf("%7s", numbuf
);
5283 zdb_nicenum(parm_histo
[j
].cumulative
,
5284 numbuf
, sizeof (numbuf
));
5286 (void) printf("\t%s", numbuf
);
5288 (void) printf("%7s", numbuf
);
5290 (void) printf("\n");
5295 zdb_count_block(zdb_cb_t
*zcb
, zilog_t
*zilog
, const blkptr_t
*bp
,
5296 dmu_object_type_t type
)
5298 uint64_t refcnt
= 0;
5301 ASSERT(type
< ZDB_OT_TOTAL
);
5303 if (zilog
&& zil_bp_tree_add(zilog
, bp
) != 0)
5306 spa_config_enter(zcb
->zcb_spa
, SCL_CONFIG
, FTAG
, RW_READER
);
5308 for (i
= 0; i
< 4; i
++) {
5309 int l
= (i
< 2) ? BP_GET_LEVEL(bp
) : ZB_TOTAL
;
5310 int t
= (i
& 1) ? type
: ZDB_OT_TOTAL
;
5312 zdb_blkstats_t
*zb
= &zcb
->zcb_type
[l
][t
];
5314 zb
->zb_asize
+= BP_GET_ASIZE(bp
);
5315 zb
->zb_lsize
+= BP_GET_LSIZE(bp
);
5316 zb
->zb_psize
+= BP_GET_PSIZE(bp
);
5320 * The histogram is only big enough to record blocks up to
5321 * SPA_OLD_MAXBLOCKSIZE; larger blocks go into the last,
5324 unsigned idx
= BP_GET_PSIZE(bp
) >> SPA_MINBLOCKSHIFT
;
5325 idx
= MIN(idx
, SPA_OLD_MAXBLOCKSIZE
/ SPA_MINBLOCKSIZE
+ 1);
5326 zb
->zb_psize_histogram
[idx
]++;
5328 zb
->zb_gangs
+= BP_COUNT_GANG(bp
);
5330 switch (BP_GET_NDVAS(bp
)) {
5332 if (DVA_GET_VDEV(&bp
->blk_dva
[0]) ==
5333 DVA_GET_VDEV(&bp
->blk_dva
[1])) {
5334 zb
->zb_ditto_samevdev
++;
5336 if (same_metaslab(zcb
->zcb_spa
,
5337 DVA_GET_VDEV(&bp
->blk_dva
[0]),
5338 DVA_GET_OFFSET(&bp
->blk_dva
[0]),
5339 DVA_GET_OFFSET(&bp
->blk_dva
[1])))
5340 zb
->zb_ditto_same_ms
++;
5344 equal
= (DVA_GET_VDEV(&bp
->blk_dva
[0]) ==
5345 DVA_GET_VDEV(&bp
->blk_dva
[1])) +
5346 (DVA_GET_VDEV(&bp
->blk_dva
[0]) ==
5347 DVA_GET_VDEV(&bp
->blk_dva
[2])) +
5348 (DVA_GET_VDEV(&bp
->blk_dva
[1]) ==
5349 DVA_GET_VDEV(&bp
->blk_dva
[2]));
5351 zb
->zb_ditto_samevdev
++;
5353 if (DVA_GET_VDEV(&bp
->blk_dva
[0]) ==
5354 DVA_GET_VDEV(&bp
->blk_dva
[1]) &&
5355 same_metaslab(zcb
->zcb_spa
,
5356 DVA_GET_VDEV(&bp
->blk_dva
[0]),
5357 DVA_GET_OFFSET(&bp
->blk_dva
[0]),
5358 DVA_GET_OFFSET(&bp
->blk_dva
[1])))
5359 zb
->zb_ditto_same_ms
++;
5360 else if (DVA_GET_VDEV(&bp
->blk_dva
[0]) ==
5361 DVA_GET_VDEV(&bp
->blk_dva
[2]) &&
5362 same_metaslab(zcb
->zcb_spa
,
5363 DVA_GET_VDEV(&bp
->blk_dva
[0]),
5364 DVA_GET_OFFSET(&bp
->blk_dva
[0]),
5365 DVA_GET_OFFSET(&bp
->blk_dva
[2])))
5366 zb
->zb_ditto_same_ms
++;
5367 else if (DVA_GET_VDEV(&bp
->blk_dva
[1]) ==
5368 DVA_GET_VDEV(&bp
->blk_dva
[2]) &&
5369 same_metaslab(zcb
->zcb_spa
,
5370 DVA_GET_VDEV(&bp
->blk_dva
[1]),
5371 DVA_GET_OFFSET(&bp
->blk_dva
[1]),
5372 DVA_GET_OFFSET(&bp
->blk_dva
[2])))
5373 zb
->zb_ditto_same_ms
++;
5379 spa_config_exit(zcb
->zcb_spa
, SCL_CONFIG
, FTAG
);
5381 if (BP_IS_EMBEDDED(bp
)) {
5382 zcb
->zcb_embedded_blocks
[BPE_GET_ETYPE(bp
)]++;
5383 zcb
->zcb_embedded_histogram
[BPE_GET_ETYPE(bp
)]
5384 [BPE_GET_PSIZE(bp
)]++;
5388 * The binning histogram bins by powers of two up to
5389 * SPA_MAXBLOCKSIZE rather than creating bins for
5390 * every possible blocksize found in the pool.
5392 int bin
= highbit64(BP_GET_PSIZE(bp
)) - 1;
5394 zcb
->zcb_psize_count
[bin
]++;
5395 zcb
->zcb_psize_len
[bin
] += BP_GET_PSIZE(bp
);
5396 zcb
->zcb_psize_total
+= BP_GET_PSIZE(bp
);
5398 bin
= highbit64(BP_GET_LSIZE(bp
)) - 1;
5400 zcb
->zcb_lsize_count
[bin
]++;
5401 zcb
->zcb_lsize_len
[bin
] += BP_GET_LSIZE(bp
);
5402 zcb
->zcb_lsize_total
+= BP_GET_LSIZE(bp
);
5404 bin
= highbit64(BP_GET_ASIZE(bp
)) - 1;
5406 zcb
->zcb_asize_count
[bin
]++;
5407 zcb
->zcb_asize_len
[bin
] += BP_GET_ASIZE(bp
);
5408 zcb
->zcb_asize_total
+= BP_GET_ASIZE(bp
);
5413 if (BP_GET_DEDUP(bp
)) {
5417 ddt
= ddt_select(zcb
->zcb_spa
, bp
);
5419 dde
= ddt_lookup(ddt
, bp
, B_FALSE
);
5424 ddt_phys_t
*ddp
= ddt_phys_select(dde
, bp
);
5425 ddt_phys_decref(ddp
);
5426 refcnt
= ddp
->ddp_refcnt
;
5427 if (ddt_phys_total_refcnt(dde
) == 0)
5428 ddt_remove(ddt
, dde
);
5433 VERIFY3U(zio_wait(zio_claim(NULL
, zcb
->zcb_spa
,
5434 refcnt
? 0 : spa_min_claim_txg(zcb
->zcb_spa
),
5435 bp
, NULL
, NULL
, ZIO_FLAG_CANFAIL
)), ==, 0);
5439 zdb_blkptr_done(zio_t
*zio
)
5441 spa_t
*spa
= zio
->io_spa
;
5442 blkptr_t
*bp
= zio
->io_bp
;
5443 int ioerr
= zio
->io_error
;
5444 zdb_cb_t
*zcb
= zio
->io_private
;
5445 zbookmark_phys_t
*zb
= &zio
->io_bookmark
;
5447 mutex_enter(&spa
->spa_scrub_lock
);
5448 spa
->spa_load_verify_bytes
-= BP_GET_PSIZE(bp
);
5449 cv_broadcast(&spa
->spa_scrub_io_cv
);
5451 if (ioerr
&& !(zio
->io_flags
& ZIO_FLAG_SPECULATIVE
)) {
5452 char blkbuf
[BP_SPRINTF_LEN
];
5454 zcb
->zcb_haderrors
= 1;
5455 zcb
->zcb_errors
[ioerr
]++;
5457 if (dump_opt
['b'] >= 2)
5458 snprintf_blkptr(blkbuf
, sizeof (blkbuf
), bp
);
5462 (void) printf("zdb_blkptr_cb: "
5463 "Got error %d reading "
5464 "<%llu, %llu, %lld, %llx> %s -- skipping\n",
5466 (u_longlong_t
)zb
->zb_objset
,
5467 (u_longlong_t
)zb
->zb_object
,
5468 (u_longlong_t
)zb
->zb_level
,
5469 (u_longlong_t
)zb
->zb_blkid
,
5472 mutex_exit(&spa
->spa_scrub_lock
);
5474 abd_free(zio
->io_abd
);
5478 zdb_blkptr_cb(spa_t
*spa
, zilog_t
*zilog
, const blkptr_t
*bp
,
5479 const zbookmark_phys_t
*zb
, const dnode_phys_t
*dnp
, void *arg
)
5481 zdb_cb_t
*zcb
= arg
;
5482 dmu_object_type_t type
;
5483 boolean_t is_metadata
;
5485 if (zb
->zb_level
== ZB_DNODE_LEVEL
)
5488 if (dump_opt
['b'] >= 5 && bp
->blk_birth
> 0) {
5489 char blkbuf
[BP_SPRINTF_LEN
];
5490 snprintf_blkptr(blkbuf
, sizeof (blkbuf
), bp
);
5491 (void) printf("objset %llu object %llu "
5492 "level %lld offset 0x%llx %s\n",
5493 (u_longlong_t
)zb
->zb_objset
,
5494 (u_longlong_t
)zb
->zb_object
,
5495 (longlong_t
)zb
->zb_level
,
5496 (u_longlong_t
)blkid2offset(dnp
, bp
, zb
),
5500 if (BP_IS_HOLE(bp
) || BP_IS_REDACTED(bp
))
5503 type
= BP_GET_TYPE(bp
);
5505 zdb_count_block(zcb
, zilog
, bp
,
5506 (type
& DMU_OT_NEWTYPE
) ? ZDB_OT_OTHER
: type
);
5508 is_metadata
= (BP_GET_LEVEL(bp
) != 0 || DMU_OT_IS_METADATA(type
));
5510 if (!BP_IS_EMBEDDED(bp
) &&
5511 (dump_opt
['c'] > 1 || (dump_opt
['c'] && is_metadata
))) {
5512 size_t size
= BP_GET_PSIZE(bp
);
5513 abd_t
*abd
= abd_alloc(size
, B_FALSE
);
5514 int flags
= ZIO_FLAG_CANFAIL
| ZIO_FLAG_SCRUB
| ZIO_FLAG_RAW
;
5516 /* If it's an intent log block, failure is expected. */
5517 if (zb
->zb_level
== ZB_ZIL_LEVEL
)
5518 flags
|= ZIO_FLAG_SPECULATIVE
;
5520 mutex_enter(&spa
->spa_scrub_lock
);
5521 while (spa
->spa_load_verify_bytes
> max_inflight_bytes
)
5522 cv_wait(&spa
->spa_scrub_io_cv
, &spa
->spa_scrub_lock
);
5523 spa
->spa_load_verify_bytes
+= size
;
5524 mutex_exit(&spa
->spa_scrub_lock
);
5526 zio_nowait(zio_read(NULL
, spa
, bp
, abd
, size
,
5527 zdb_blkptr_done
, zcb
, ZIO_PRIORITY_ASYNC_READ
, flags
, zb
));
5530 zcb
->zcb_readfails
= 0;
5532 /* only call gethrtime() every 100 blocks */
5539 if (dump_opt
['b'] < 5 && gethrtime() > zcb
->zcb_lastprint
+ NANOSEC
) {
5540 uint64_t now
= gethrtime();
5542 uint64_t bytes
= zcb
->zcb_type
[ZB_TOTAL
][ZDB_OT_TOTAL
].zb_asize
;
5543 uint64_t kb_per_sec
=
5544 1 + bytes
/ (1 + ((now
- zcb
->zcb_start
) / 1000 / 1000));
5545 uint64_t sec_remaining
=
5546 (zcb
->zcb_totalasize
- bytes
) / 1024 / kb_per_sec
;
5548 /* make sure nicenum has enough space */
5549 _Static_assert(sizeof (buf
) >= NN_NUMBUF_SZ
, "buf truncated");
5551 zfs_nicebytes(bytes
, buf
, sizeof (buf
));
5552 (void) fprintf(stderr
,
5553 "\r%5s completed (%4"PRIu64
"MB/s) "
5554 "estimated time remaining: "
5555 "%"PRIu64
"hr %02"PRIu64
"min %02"PRIu64
"sec ",
5556 buf
, kb_per_sec
/ 1024,
5557 sec_remaining
/ 60 / 60,
5558 sec_remaining
/ 60 % 60,
5559 sec_remaining
% 60);
5561 zcb
->zcb_lastprint
= now
;
5568 zdb_leak(void *arg
, uint64_t start
, uint64_t size
)
5572 (void) printf("leaked space: vdev %llu, offset 0x%llx, size %llu\n",
5573 (u_longlong_t
)vd
->vdev_id
, (u_longlong_t
)start
, (u_longlong_t
)size
);
5576 static metaslab_ops_t zdb_metaslab_ops
= {
5581 load_unflushed_svr_segs_cb(spa_t
*spa
, space_map_entry_t
*sme
,
5582 uint64_t txg
, void *arg
)
5584 spa_vdev_removal_t
*svr
= arg
;
5586 uint64_t offset
= sme
->sme_offset
;
5587 uint64_t size
= sme
->sme_run
;
5589 /* skip vdevs we don't care about */
5590 if (sme
->sme_vdev
!= svr
->svr_vdev_id
)
5593 vdev_t
*vd
= vdev_lookup_top(spa
, sme
->sme_vdev
);
5594 metaslab_t
*ms
= vd
->vdev_ms
[offset
>> vd
->vdev_ms_shift
];
5595 ASSERT(sme
->sme_type
== SM_ALLOC
|| sme
->sme_type
== SM_FREE
);
5597 if (txg
< metaslab_unflushed_txg(ms
))
5600 if (sme
->sme_type
== SM_ALLOC
)
5601 range_tree_add(svr
->svr_allocd_segs
, offset
, size
);
5603 range_tree_remove(svr
->svr_allocd_segs
, offset
, size
);
5609 claim_segment_impl_cb(uint64_t inner_offset
, vdev_t
*vd
, uint64_t offset
,
5610 uint64_t size
, void *arg
)
5612 (void) inner_offset
, (void) arg
;
5615 * This callback was called through a remap from
5616 * a device being removed. Therefore, the vdev that
5617 * this callback is applied to is a concrete
5620 ASSERT(vdev_is_concrete(vd
));
5622 VERIFY0(metaslab_claim_impl(vd
, offset
, size
,
5623 spa_min_claim_txg(vd
->vdev_spa
)));
5627 claim_segment_cb(void *arg
, uint64_t offset
, uint64_t size
)
5631 vdev_indirect_ops
.vdev_op_remap(vd
, offset
, size
,
5632 claim_segment_impl_cb
, NULL
);
5636 * After accounting for all allocated blocks that are directly referenced,
5637 * we might have missed a reference to a block from a partially complete
5638 * (and thus unused) indirect mapping object. We perform a secondary pass
5639 * through the metaslabs we have already mapped and claim the destination
5643 zdb_claim_removing(spa_t
*spa
, zdb_cb_t
*zcb
)
5648 if (spa
->spa_vdev_removal
== NULL
)
5651 spa_config_enter(spa
, SCL_CONFIG
, FTAG
, RW_READER
);
5653 spa_vdev_removal_t
*svr
= spa
->spa_vdev_removal
;
5654 vdev_t
*vd
= vdev_lookup_top(spa
, svr
->svr_vdev_id
);
5655 vdev_indirect_mapping_t
*vim
= vd
->vdev_indirect_mapping
;
5657 ASSERT0(range_tree_space(svr
->svr_allocd_segs
));
5659 range_tree_t
*allocs
= range_tree_create(NULL
, RANGE_SEG64
, NULL
, 0, 0);
5660 for (uint64_t msi
= 0; msi
< vd
->vdev_ms_count
; msi
++) {
5661 metaslab_t
*msp
= vd
->vdev_ms
[msi
];
5663 ASSERT0(range_tree_space(allocs
));
5664 if (msp
->ms_sm
!= NULL
)
5665 VERIFY0(space_map_load(msp
->ms_sm
, allocs
, SM_ALLOC
));
5666 range_tree_vacate(allocs
, range_tree_add
, svr
->svr_allocd_segs
);
5668 range_tree_destroy(allocs
);
5670 iterate_through_spacemap_logs(spa
, load_unflushed_svr_segs_cb
, svr
);
5673 * Clear everything past what has been synced,
5674 * because we have not allocated mappings for
5677 range_tree_clear(svr
->svr_allocd_segs
,
5678 vdev_indirect_mapping_max_offset(vim
),
5679 vd
->vdev_asize
- vdev_indirect_mapping_max_offset(vim
));
5681 zcb
->zcb_removing_size
+= range_tree_space(svr
->svr_allocd_segs
);
5682 range_tree_vacate(svr
->svr_allocd_segs
, claim_segment_cb
, vd
);
5684 spa_config_exit(spa
, SCL_CONFIG
, FTAG
);
5688 increment_indirect_mapping_cb(void *arg
, const blkptr_t
*bp
, boolean_t bp_freed
,
5692 zdb_cb_t
*zcb
= arg
;
5693 spa_t
*spa
= zcb
->zcb_spa
;
5695 const dva_t
*dva
= &bp
->blk_dva
[0];
5698 ASSERT(!dump_opt
['L']);
5699 ASSERT3U(BP_GET_NDVAS(bp
), ==, 1);
5701 spa_config_enter(spa
, SCL_VDEV
, FTAG
, RW_READER
);
5702 vd
= vdev_lookup_top(zcb
->zcb_spa
, DVA_GET_VDEV(dva
));
5703 ASSERT3P(vd
, !=, NULL
);
5704 spa_config_exit(spa
, SCL_VDEV
, FTAG
);
5706 ASSERT(vd
->vdev_indirect_config
.vic_mapping_object
!= 0);
5707 ASSERT3P(zcb
->zcb_vd_obsolete_counts
[vd
->vdev_id
], !=, NULL
);
5709 vdev_indirect_mapping_increment_obsolete_count(
5710 vd
->vdev_indirect_mapping
,
5711 DVA_GET_OFFSET(dva
), DVA_GET_ASIZE(dva
),
5712 zcb
->zcb_vd_obsolete_counts
[vd
->vdev_id
]);
5718 zdb_load_obsolete_counts(vdev_t
*vd
)
5720 vdev_indirect_mapping_t
*vim
= vd
->vdev_indirect_mapping
;
5721 spa_t
*spa
= vd
->vdev_spa
;
5722 spa_condensing_indirect_phys_t
*scip
=
5723 &spa
->spa_condensing_indirect_phys
;
5724 uint64_t obsolete_sm_object
;
5727 VERIFY0(vdev_obsolete_sm_object(vd
, &obsolete_sm_object
));
5728 EQUIV(obsolete_sm_object
!= 0, vd
->vdev_obsolete_sm
!= NULL
);
5729 counts
= vdev_indirect_mapping_load_obsolete_counts(vim
);
5730 if (vd
->vdev_obsolete_sm
!= NULL
) {
5731 vdev_indirect_mapping_load_obsolete_spacemap(vim
, counts
,
5732 vd
->vdev_obsolete_sm
);
5734 if (scip
->scip_vdev
== vd
->vdev_id
&&
5735 scip
->scip_prev_obsolete_sm_object
!= 0) {
5736 space_map_t
*prev_obsolete_sm
= NULL
;
5737 VERIFY0(space_map_open(&prev_obsolete_sm
, spa
->spa_meta_objset
,
5738 scip
->scip_prev_obsolete_sm_object
, 0, vd
->vdev_asize
, 0));
5739 vdev_indirect_mapping_load_obsolete_spacemap(vim
, counts
,
5741 space_map_close(prev_obsolete_sm
);
5747 zdb_ddt_leak_init(spa_t
*spa
, zdb_cb_t
*zcb
)
5754 ASSERT(!dump_opt
['L']);
5756 bzero(&ddb
, sizeof (ddb
));
5757 while ((error
= ddt_walk(spa
, &ddb
, &dde
)) == 0) {
5759 ddt_phys_t
*ddp
= dde
.dde_phys
;
5761 if (ddb
.ddb_class
== DDT_CLASS_UNIQUE
)
5764 ASSERT(ddt_phys_total_refcnt(&dde
) > 1);
5766 for (p
= 0; p
< DDT_PHYS_TYPES
; p
++, ddp
++) {
5767 if (ddp
->ddp_phys_birth
== 0)
5769 ddt_bp_create(ddb
.ddb_checksum
,
5770 &dde
.dde_key
, ddp
, &blk
);
5771 if (p
== DDT_PHYS_DITTO
) {
5772 zdb_count_block(zcb
, NULL
, &blk
, ZDB_OT_DITTO
);
5774 zcb
->zcb_dedup_asize
+=
5775 BP_GET_ASIZE(&blk
) * (ddp
->ddp_refcnt
- 1);
5776 zcb
->zcb_dedup_blocks
++;
5779 ddt_t
*ddt
= spa
->spa_ddt
[ddb
.ddb_checksum
];
5781 VERIFY(ddt_lookup(ddt
, &blk
, B_TRUE
) != NULL
);
5785 ASSERT(error
== ENOENT
);
5788 typedef struct checkpoint_sm_exclude_entry_arg
{
5790 uint64_t cseea_checkpoint_size
;
5791 } checkpoint_sm_exclude_entry_arg_t
;
5794 checkpoint_sm_exclude_entry_cb(space_map_entry_t
*sme
, void *arg
)
5796 checkpoint_sm_exclude_entry_arg_t
*cseea
= arg
;
5797 vdev_t
*vd
= cseea
->cseea_vd
;
5798 metaslab_t
*ms
= vd
->vdev_ms
[sme
->sme_offset
>> vd
->vdev_ms_shift
];
5799 uint64_t end
= sme
->sme_offset
+ sme
->sme_run
;
5801 ASSERT(sme
->sme_type
== SM_FREE
);
5804 * Since the vdev_checkpoint_sm exists in the vdev level
5805 * and the ms_sm space maps exist in the metaslab level,
5806 * an entry in the checkpoint space map could theoretically
5807 * cross the boundaries of the metaslab that it belongs.
5809 * In reality, because of the way that we populate and
5810 * manipulate the checkpoint's space maps currently,
5811 * there shouldn't be any entries that cross metaslabs.
5812 * Hence the assertion below.
5814 * That said, there is no fundamental requirement that
5815 * the checkpoint's space map entries should not cross
5816 * metaslab boundaries. So if needed we could add code
5817 * that handles metaslab-crossing segments in the future.
5819 VERIFY3U(sme
->sme_offset
, >=, ms
->ms_start
);
5820 VERIFY3U(end
, <=, ms
->ms_start
+ ms
->ms_size
);
5823 * By removing the entry from the allocated segments we
5824 * also verify that the entry is there to begin with.
5826 mutex_enter(&ms
->ms_lock
);
5827 range_tree_remove(ms
->ms_allocatable
, sme
->sme_offset
, sme
->sme_run
);
5828 mutex_exit(&ms
->ms_lock
);
5830 cseea
->cseea_checkpoint_size
+= sme
->sme_run
;
5835 zdb_leak_init_vdev_exclude_checkpoint(vdev_t
*vd
, zdb_cb_t
*zcb
)
5837 spa_t
*spa
= vd
->vdev_spa
;
5838 space_map_t
*checkpoint_sm
= NULL
;
5839 uint64_t checkpoint_sm_obj
;
5842 * If there is no vdev_top_zap, we are in a pool whose
5843 * version predates the pool checkpoint feature.
5845 if (vd
->vdev_top_zap
== 0)
5849 * If there is no reference of the vdev_checkpoint_sm in
5850 * the vdev_top_zap, then one of the following scenarios
5853 * 1] There is no checkpoint
5854 * 2] There is a checkpoint, but no checkpointed blocks
5855 * have been freed yet
5856 * 3] The current vdev is indirect
5858 * In these cases we return immediately.
5860 if (zap_contains(spa_meta_objset(spa
), vd
->vdev_top_zap
,
5861 VDEV_TOP_ZAP_POOL_CHECKPOINT_SM
) != 0)
5864 VERIFY0(zap_lookup(spa_meta_objset(spa
), vd
->vdev_top_zap
,
5865 VDEV_TOP_ZAP_POOL_CHECKPOINT_SM
, sizeof (uint64_t), 1,
5866 &checkpoint_sm_obj
));
5868 checkpoint_sm_exclude_entry_arg_t cseea
;
5869 cseea
.cseea_vd
= vd
;
5870 cseea
.cseea_checkpoint_size
= 0;
5872 VERIFY0(space_map_open(&checkpoint_sm
, spa_meta_objset(spa
),
5873 checkpoint_sm_obj
, 0, vd
->vdev_asize
, vd
->vdev_ashift
));
5875 VERIFY0(space_map_iterate(checkpoint_sm
,
5876 space_map_length(checkpoint_sm
),
5877 checkpoint_sm_exclude_entry_cb
, &cseea
));
5878 space_map_close(checkpoint_sm
);
5880 zcb
->zcb_checkpoint_size
+= cseea
.cseea_checkpoint_size
;
5884 zdb_leak_init_exclude_checkpoint(spa_t
*spa
, zdb_cb_t
*zcb
)
5886 ASSERT(!dump_opt
['L']);
5888 vdev_t
*rvd
= spa
->spa_root_vdev
;
5889 for (uint64_t c
= 0; c
< rvd
->vdev_children
; c
++) {
5890 ASSERT3U(c
, ==, rvd
->vdev_child
[c
]->vdev_id
);
5891 zdb_leak_init_vdev_exclude_checkpoint(rvd
->vdev_child
[c
], zcb
);
5896 count_unflushed_space_cb(spa_t
*spa
, space_map_entry_t
*sme
,
5897 uint64_t txg
, void *arg
)
5899 int64_t *ualloc_space
= arg
;
5901 uint64_t offset
= sme
->sme_offset
;
5902 uint64_t vdev_id
= sme
->sme_vdev
;
5904 vdev_t
*vd
= vdev_lookup_top(spa
, vdev_id
);
5905 if (!vdev_is_concrete(vd
))
5908 metaslab_t
*ms
= vd
->vdev_ms
[offset
>> vd
->vdev_ms_shift
];
5909 ASSERT(sme
->sme_type
== SM_ALLOC
|| sme
->sme_type
== SM_FREE
);
5911 if (txg
< metaslab_unflushed_txg(ms
))
5914 if (sme
->sme_type
== SM_ALLOC
)
5915 *ualloc_space
+= sme
->sme_run
;
5917 *ualloc_space
-= sme
->sme_run
;
5923 get_unflushed_alloc_space(spa_t
*spa
)
5928 int64_t ualloc_space
= 0;
5929 iterate_through_spacemap_logs(spa
, count_unflushed_space_cb
,
5931 return (ualloc_space
);
5935 load_unflushed_cb(spa_t
*spa
, space_map_entry_t
*sme
, uint64_t txg
, void *arg
)
5937 maptype_t
*uic_maptype
= arg
;
5939 uint64_t offset
= sme
->sme_offset
;
5940 uint64_t size
= sme
->sme_run
;
5941 uint64_t vdev_id
= sme
->sme_vdev
;
5943 vdev_t
*vd
= vdev_lookup_top(spa
, vdev_id
);
5945 /* skip indirect vdevs */
5946 if (!vdev_is_concrete(vd
))
5949 metaslab_t
*ms
= vd
->vdev_ms
[offset
>> vd
->vdev_ms_shift
];
5951 ASSERT(sme
->sme_type
== SM_ALLOC
|| sme
->sme_type
== SM_FREE
);
5952 ASSERT(*uic_maptype
== SM_ALLOC
|| *uic_maptype
== SM_FREE
);
5954 if (txg
< metaslab_unflushed_txg(ms
))
5957 if (*uic_maptype
== sme
->sme_type
)
5958 range_tree_add(ms
->ms_allocatable
, offset
, size
);
5960 range_tree_remove(ms
->ms_allocatable
, offset
, size
);
5966 load_unflushed_to_ms_allocatables(spa_t
*spa
, maptype_t maptype
)
5968 iterate_through_spacemap_logs(spa
, load_unflushed_cb
, &maptype
);
5972 load_concrete_ms_allocatable_trees(spa_t
*spa
, maptype_t maptype
)
5974 vdev_t
*rvd
= spa
->spa_root_vdev
;
5975 for (uint64_t i
= 0; i
< rvd
->vdev_children
; i
++) {
5976 vdev_t
*vd
= rvd
->vdev_child
[i
];
5978 ASSERT3U(i
, ==, vd
->vdev_id
);
5980 if (vd
->vdev_ops
== &vdev_indirect_ops
)
5983 for (uint64_t m
= 0; m
< vd
->vdev_ms_count
; m
++) {
5984 metaslab_t
*msp
= vd
->vdev_ms
[m
];
5986 (void) fprintf(stderr
,
5987 "\rloading concrete vdev %llu, "
5988 "metaslab %llu of %llu ...",
5989 (longlong_t
)vd
->vdev_id
,
5990 (longlong_t
)msp
->ms_id
,
5991 (longlong_t
)vd
->vdev_ms_count
);
5993 mutex_enter(&msp
->ms_lock
);
5994 range_tree_vacate(msp
->ms_allocatable
, NULL
, NULL
);
5997 * We don't want to spend the CPU manipulating the
5998 * size-ordered tree, so clear the range_tree ops.
6000 msp
->ms_allocatable
->rt_ops
= NULL
;
6002 if (msp
->ms_sm
!= NULL
) {
6003 VERIFY0(space_map_load(msp
->ms_sm
,
6004 msp
->ms_allocatable
, maptype
));
6006 if (!msp
->ms_loaded
)
6007 msp
->ms_loaded
= B_TRUE
;
6008 mutex_exit(&msp
->ms_lock
);
6012 load_unflushed_to_ms_allocatables(spa
, maptype
);
6016 * vm_idxp is an in-out parameter which (for indirect vdevs) is the
6017 * index in vim_entries that has the first entry in this metaslab.
6018 * On return, it will be set to the first entry after this metaslab.
6021 load_indirect_ms_allocatable_tree(vdev_t
*vd
, metaslab_t
*msp
,
6024 vdev_indirect_mapping_t
*vim
= vd
->vdev_indirect_mapping
;
6026 mutex_enter(&msp
->ms_lock
);
6027 range_tree_vacate(msp
->ms_allocatable
, NULL
, NULL
);
6030 * We don't want to spend the CPU manipulating the
6031 * size-ordered tree, so clear the range_tree ops.
6033 msp
->ms_allocatable
->rt_ops
= NULL
;
6035 for (; *vim_idxp
< vdev_indirect_mapping_num_entries(vim
);
6037 vdev_indirect_mapping_entry_phys_t
*vimep
=
6038 &vim
->vim_entries
[*vim_idxp
];
6039 uint64_t ent_offset
= DVA_MAPPING_GET_SRC_OFFSET(vimep
);
6040 uint64_t ent_len
= DVA_GET_ASIZE(&vimep
->vimep_dst
);
6041 ASSERT3U(ent_offset
, >=, msp
->ms_start
);
6042 if (ent_offset
>= msp
->ms_start
+ msp
->ms_size
)
6046 * Mappings do not cross metaslab boundaries,
6047 * because we create them by walking the metaslabs.
6049 ASSERT3U(ent_offset
+ ent_len
, <=,
6050 msp
->ms_start
+ msp
->ms_size
);
6051 range_tree_add(msp
->ms_allocatable
, ent_offset
, ent_len
);
6054 if (!msp
->ms_loaded
)
6055 msp
->ms_loaded
= B_TRUE
;
6056 mutex_exit(&msp
->ms_lock
);
6060 zdb_leak_init_prepare_indirect_vdevs(spa_t
*spa
, zdb_cb_t
*zcb
)
6062 ASSERT(!dump_opt
['L']);
6064 vdev_t
*rvd
= spa
->spa_root_vdev
;
6065 for (uint64_t c
= 0; c
< rvd
->vdev_children
; c
++) {
6066 vdev_t
*vd
= rvd
->vdev_child
[c
];
6068 ASSERT3U(c
, ==, vd
->vdev_id
);
6070 if (vd
->vdev_ops
!= &vdev_indirect_ops
)
6074 * Note: we don't check for mapping leaks on
6075 * removing vdevs because their ms_allocatable's
6076 * are used to look for leaks in allocated space.
6078 zcb
->zcb_vd_obsolete_counts
[c
] = zdb_load_obsolete_counts(vd
);
6081 * Normally, indirect vdevs don't have any
6082 * metaslabs. We want to set them up for
6085 vdev_metaslab_group_create(vd
);
6086 VERIFY0(vdev_metaslab_init(vd
, 0));
6088 vdev_indirect_mapping_t
*vim __maybe_unused
=
6089 vd
->vdev_indirect_mapping
;
6090 uint64_t vim_idx
= 0;
6091 for (uint64_t m
= 0; m
< vd
->vdev_ms_count
; m
++) {
6093 (void) fprintf(stderr
,
6094 "\rloading indirect vdev %llu, "
6095 "metaslab %llu of %llu ...",
6096 (longlong_t
)vd
->vdev_id
,
6097 (longlong_t
)vd
->vdev_ms
[m
]->ms_id
,
6098 (longlong_t
)vd
->vdev_ms_count
);
6100 load_indirect_ms_allocatable_tree(vd
, vd
->vdev_ms
[m
],
6103 ASSERT3U(vim_idx
, ==, vdev_indirect_mapping_num_entries(vim
));
6108 zdb_leak_init(spa_t
*spa
, zdb_cb_t
*zcb
)
6115 dsl_pool_t
*dp
= spa
->spa_dsl_pool
;
6116 vdev_t
*rvd
= spa
->spa_root_vdev
;
6119 * We are going to be changing the meaning of the metaslab's
6120 * ms_allocatable. Ensure that the allocator doesn't try to
6123 spa
->spa_normal_class
->mc_ops
= &zdb_metaslab_ops
;
6124 spa
->spa_log_class
->mc_ops
= &zdb_metaslab_ops
;
6125 spa
->spa_embedded_log_class
->mc_ops
= &zdb_metaslab_ops
;
6127 zcb
->zcb_vd_obsolete_counts
=
6128 umem_zalloc(rvd
->vdev_children
* sizeof (uint32_t *),
6132 * For leak detection, we overload the ms_allocatable trees
6133 * to contain allocated segments instead of free segments.
6134 * As a result, we can't use the normal metaslab_load/unload
6137 zdb_leak_init_prepare_indirect_vdevs(spa
, zcb
);
6138 load_concrete_ms_allocatable_trees(spa
, SM_ALLOC
);
6141 * On load_concrete_ms_allocatable_trees() we loaded all the
6142 * allocated entries from the ms_sm to the ms_allocatable for
6143 * each metaslab. If the pool has a checkpoint or is in the
6144 * middle of discarding a checkpoint, some of these blocks
6145 * may have been freed but their ms_sm may not have been
6146 * updated because they are referenced by the checkpoint. In
6147 * order to avoid false-positives during leak-detection, we
6148 * go through the vdev's checkpoint space map and exclude all
6149 * its entries from their relevant ms_allocatable.
6151 * We also aggregate the space held by the checkpoint and add
6152 * it to zcb_checkpoint_size.
6154 * Note that at this point we are also verifying that all the
6155 * entries on the checkpoint_sm are marked as allocated in
6156 * the ms_sm of their relevant metaslab.
6157 * [see comment in checkpoint_sm_exclude_entry_cb()]
6159 zdb_leak_init_exclude_checkpoint(spa
, zcb
);
6160 ASSERT3U(zcb
->zcb_checkpoint_size
, ==, spa_get_checkpoint_space(spa
));
6162 /* for cleaner progress output */
6163 (void) fprintf(stderr
, "\n");
6165 if (bpobj_is_open(&dp
->dp_obsolete_bpobj
)) {
6166 ASSERT(spa_feature_is_enabled(spa
,
6167 SPA_FEATURE_DEVICE_REMOVAL
));
6168 (void) bpobj_iterate_nofree(&dp
->dp_obsolete_bpobj
,
6169 increment_indirect_mapping_cb
, zcb
, NULL
);
6172 spa_config_enter(spa
, SCL_CONFIG
, FTAG
, RW_READER
);
6173 zdb_ddt_leak_init(spa
, zcb
);
6174 spa_config_exit(spa
, SCL_CONFIG
, FTAG
);
6178 zdb_check_for_obsolete_leaks(vdev_t
*vd
, zdb_cb_t
*zcb
)
6180 boolean_t leaks
= B_FALSE
;
6181 vdev_indirect_mapping_t
*vim
= vd
->vdev_indirect_mapping
;
6182 uint64_t total_leaked
= 0;
6183 boolean_t are_precise
= B_FALSE
;
6185 ASSERT(vim
!= NULL
);
6187 for (uint64_t i
= 0; i
< vdev_indirect_mapping_num_entries(vim
); i
++) {
6188 vdev_indirect_mapping_entry_phys_t
*vimep
=
6189 &vim
->vim_entries
[i
];
6190 uint64_t obsolete_bytes
= 0;
6191 uint64_t offset
= DVA_MAPPING_GET_SRC_OFFSET(vimep
);
6192 metaslab_t
*msp
= vd
->vdev_ms
[offset
>> vd
->vdev_ms_shift
];
6195 * This is not very efficient but it's easy to
6196 * verify correctness.
6198 for (uint64_t inner_offset
= 0;
6199 inner_offset
< DVA_GET_ASIZE(&vimep
->vimep_dst
);
6200 inner_offset
+= 1 << vd
->vdev_ashift
) {
6201 if (range_tree_contains(msp
->ms_allocatable
,
6202 offset
+ inner_offset
, 1 << vd
->vdev_ashift
)) {
6203 obsolete_bytes
+= 1 << vd
->vdev_ashift
;
6207 int64_t bytes_leaked
= obsolete_bytes
-
6208 zcb
->zcb_vd_obsolete_counts
[vd
->vdev_id
][i
];
6209 ASSERT3U(DVA_GET_ASIZE(&vimep
->vimep_dst
), >=,
6210 zcb
->zcb_vd_obsolete_counts
[vd
->vdev_id
][i
]);
6212 VERIFY0(vdev_obsolete_counts_are_precise(vd
, &are_precise
));
6213 if (bytes_leaked
!= 0 && (are_precise
|| dump_opt
['d'] >= 5)) {
6214 (void) printf("obsolete indirect mapping count "
6215 "mismatch on %llu:%llx:%llx : %llx bytes leaked\n",
6216 (u_longlong_t
)vd
->vdev_id
,
6217 (u_longlong_t
)DVA_MAPPING_GET_SRC_OFFSET(vimep
),
6218 (u_longlong_t
)DVA_GET_ASIZE(&vimep
->vimep_dst
),
6219 (u_longlong_t
)bytes_leaked
);
6221 total_leaked
+= ABS(bytes_leaked
);
6224 VERIFY0(vdev_obsolete_counts_are_precise(vd
, &are_precise
));
6225 if (!are_precise
&& total_leaked
> 0) {
6226 int pct_leaked
= total_leaked
* 100 /
6227 vdev_indirect_mapping_bytes_mapped(vim
);
6228 (void) printf("cannot verify obsolete indirect mapping "
6229 "counts of vdev %llu because precise feature was not "
6230 "enabled when it was removed: %d%% (%llx bytes) of mapping"
6232 (u_longlong_t
)vd
->vdev_id
, pct_leaked
,
6233 (u_longlong_t
)total_leaked
);
6234 } else if (total_leaked
> 0) {
6235 (void) printf("obsolete indirect mapping count mismatch "
6236 "for vdev %llu -- %llx total bytes mismatched\n",
6237 (u_longlong_t
)vd
->vdev_id
,
6238 (u_longlong_t
)total_leaked
);
6242 vdev_indirect_mapping_free_obsolete_counts(vim
,
6243 zcb
->zcb_vd_obsolete_counts
[vd
->vdev_id
]);
6244 zcb
->zcb_vd_obsolete_counts
[vd
->vdev_id
] = NULL
;
6250 zdb_leak_fini(spa_t
*spa
, zdb_cb_t
*zcb
)
6255 boolean_t leaks
= B_FALSE
;
6256 vdev_t
*rvd
= spa
->spa_root_vdev
;
6257 for (unsigned c
= 0; c
< rvd
->vdev_children
; c
++) {
6258 vdev_t
*vd
= rvd
->vdev_child
[c
];
6260 if (zcb
->zcb_vd_obsolete_counts
[c
] != NULL
) {
6261 leaks
|= zdb_check_for_obsolete_leaks(vd
, zcb
);
6264 for (uint64_t m
= 0; m
< vd
->vdev_ms_count
; m
++) {
6265 metaslab_t
*msp
= vd
->vdev_ms
[m
];
6266 ASSERT3P(msp
->ms_group
, ==, (msp
->ms_group
->mg_class
==
6267 spa_embedded_log_class(spa
)) ?
6268 vd
->vdev_log_mg
: vd
->vdev_mg
);
6271 * ms_allocatable has been overloaded
6272 * to contain allocated segments. Now that
6273 * we finished traversing all blocks, any
6274 * block that remains in the ms_allocatable
6275 * represents an allocated block that we
6276 * did not claim during the traversal.
6277 * Claimed blocks would have been removed
6278 * from the ms_allocatable. For indirect
6279 * vdevs, space remaining in the tree
6280 * represents parts of the mapping that are
6281 * not referenced, which is not a bug.
6283 if (vd
->vdev_ops
== &vdev_indirect_ops
) {
6284 range_tree_vacate(msp
->ms_allocatable
,
6287 range_tree_vacate(msp
->ms_allocatable
,
6290 if (msp
->ms_loaded
) {
6291 msp
->ms_loaded
= B_FALSE
;
6296 umem_free(zcb
->zcb_vd_obsolete_counts
,
6297 rvd
->vdev_children
* sizeof (uint32_t *));
6298 zcb
->zcb_vd_obsolete_counts
= NULL
;
6304 count_block_cb(void *arg
, const blkptr_t
*bp
, dmu_tx_t
*tx
)
6307 zdb_cb_t
*zcb
= arg
;
6309 if (dump_opt
['b'] >= 5) {
6310 char blkbuf
[BP_SPRINTF_LEN
];
6311 snprintf_blkptr(blkbuf
, sizeof (blkbuf
), bp
);
6312 (void) printf("[%s] %s\n",
6313 "deferred free", blkbuf
);
6315 zdb_count_block(zcb
, NULL
, bp
, ZDB_OT_DEFERRED
);
6320 * Iterate over livelists which have been destroyed by the user but
6321 * are still present in the MOS, waiting to be freed
6324 iterate_deleted_livelists(spa_t
*spa
, ll_iter_t func
, void *arg
)
6326 objset_t
*mos
= spa
->spa_meta_objset
;
6328 int err
= zap_lookup(mos
, DMU_POOL_DIRECTORY_OBJECT
,
6329 DMU_POOL_DELETED_CLONES
, sizeof (uint64_t), 1, &zap_obj
);
6335 zap_attribute_t attr
;
6337 /* NULL out os prior to dsl_deadlist_open in case it's garbage */
6339 for (zap_cursor_init(&zc
, mos
, zap_obj
);
6340 zap_cursor_retrieve(&zc
, &attr
) == 0;
6341 (void) zap_cursor_advance(&zc
)) {
6342 dsl_deadlist_open(&ll
, mos
, attr
.za_first_integer
);
6344 dsl_deadlist_close(&ll
);
6346 zap_cursor_fini(&zc
);
6350 bpobj_count_block_cb(void *arg
, const blkptr_t
*bp
, boolean_t bp_freed
,
6354 return (count_block_cb(arg
, bp
, tx
));
6358 livelist_entry_count_blocks_cb(void *args
, dsl_deadlist_entry_t
*dle
)
6360 zdb_cb_t
*zbc
= args
;
6362 bplist_create(&blks
);
6363 /* determine which blocks have been alloc'd but not freed */
6364 VERIFY0(dsl_process_sub_livelist(&dle
->dle_bpobj
, &blks
, NULL
, NULL
));
6365 /* count those blocks */
6366 (void) bplist_iterate(&blks
, count_block_cb
, zbc
, NULL
);
6367 bplist_destroy(&blks
);
6372 livelist_count_blocks(dsl_deadlist_t
*ll
, void *arg
)
6374 dsl_deadlist_iterate(ll
, livelist_entry_count_blocks_cb
, arg
);
6378 * Count the blocks in the livelists that have been destroyed by the user
6379 * but haven't yet been freed.
6382 deleted_livelists_count_blocks(spa_t
*spa
, zdb_cb_t
*zbc
)
6384 iterate_deleted_livelists(spa
, livelist_count_blocks
, zbc
);
6388 dump_livelist_cb(dsl_deadlist_t
*ll
, void *arg
)
6390 ASSERT3P(arg
, ==, NULL
);
6391 global_feature_count
[SPA_FEATURE_LIVELIST
]++;
6392 dump_blkptr_list(ll
, "Deleted Livelist");
6393 dsl_deadlist_iterate(ll
, sublivelist_verify_lightweight
, NULL
);
6397 * Print out, register object references to, and increment feature counts for
6398 * livelists that have been destroyed by the user but haven't yet been freed.
6401 deleted_livelists_dump_mos(spa_t
*spa
)
6404 objset_t
*mos
= spa
->spa_meta_objset
;
6405 int err
= zap_lookup(mos
, DMU_POOL_DIRECTORY_OBJECT
,
6406 DMU_POOL_DELETED_CLONES
, sizeof (uint64_t), 1, &zap_obj
);
6409 mos_obj_refd(zap_obj
);
6410 iterate_deleted_livelists(spa
, dump_livelist_cb
, NULL
);
6414 dump_block_stats(spa_t
*spa
)
6417 zdb_blkstats_t
*zb
, *tzb
;
6418 uint64_t norm_alloc
, norm_space
, total_alloc
, total_found
;
6419 int flags
= TRAVERSE_PRE
| TRAVERSE_PREFETCH_METADATA
|
6420 TRAVERSE_NO_DECRYPT
| TRAVERSE_HARD
;
6421 boolean_t leaks
= B_FALSE
;
6423 bp_embedded_type_t i
;
6425 bzero(&zcb
, sizeof (zcb
));
6426 (void) printf("\nTraversing all blocks %s%s%s%s%s...\n\n",
6427 (dump_opt
['c'] || !dump_opt
['L']) ? "to verify " : "",
6428 (dump_opt
['c'] == 1) ? "metadata " : "",
6429 dump_opt
['c'] ? "checksums " : "",
6430 (dump_opt
['c'] && !dump_opt
['L']) ? "and verify " : "",
6431 !dump_opt
['L'] ? "nothing leaked " : "");
6434 * When leak detection is enabled we load all space maps as SM_ALLOC
6435 * maps, then traverse the pool claiming each block we discover. If
6436 * the pool is perfectly consistent, the segment trees will be empty
6437 * when we're done. Anything left over is a leak; any block we can't
6438 * claim (because it's not part of any space map) is a double
6439 * allocation, reference to a freed block, or an unclaimed log block.
6441 * When leak detection is disabled (-L option) we still traverse the
6442 * pool claiming each block we discover, but we skip opening any space
6445 bzero(&zcb
, sizeof (zdb_cb_t
));
6446 zdb_leak_init(spa
, &zcb
);
6449 * If there's a deferred-free bplist, process that first.
6451 (void) bpobj_iterate_nofree(&spa
->spa_deferred_bpobj
,
6452 bpobj_count_block_cb
, &zcb
, NULL
);
6454 if (spa_version(spa
) >= SPA_VERSION_DEADLISTS
) {
6455 (void) bpobj_iterate_nofree(&spa
->spa_dsl_pool
->dp_free_bpobj
,
6456 bpobj_count_block_cb
, &zcb
, NULL
);
6459 zdb_claim_removing(spa
, &zcb
);
6461 if (spa_feature_is_active(spa
, SPA_FEATURE_ASYNC_DESTROY
)) {
6462 VERIFY3U(0, ==, bptree_iterate(spa
->spa_meta_objset
,
6463 spa
->spa_dsl_pool
->dp_bptree_obj
, B_FALSE
, count_block_cb
,
6467 deleted_livelists_count_blocks(spa
, &zcb
);
6469 if (dump_opt
['c'] > 1)
6470 flags
|= TRAVERSE_PREFETCH_DATA
;
6472 zcb
.zcb_totalasize
= metaslab_class_get_alloc(spa_normal_class(spa
));
6473 zcb
.zcb_totalasize
+= metaslab_class_get_alloc(spa_special_class(spa
));
6474 zcb
.zcb_totalasize
+= metaslab_class_get_alloc(spa_dedup_class(spa
));
6475 zcb
.zcb_totalasize
+=
6476 metaslab_class_get_alloc(spa_embedded_log_class(spa
));
6477 zcb
.zcb_start
= zcb
.zcb_lastprint
= gethrtime();
6478 err
= traverse_pool(spa
, 0, flags
, zdb_blkptr_cb
, &zcb
);
6481 * If we've traversed the data blocks then we need to wait for those
6482 * I/Os to complete. We leverage "The Godfather" zio to wait on
6483 * all async I/Os to complete.
6485 if (dump_opt
['c']) {
6486 for (c
= 0; c
< max_ncpus
; c
++) {
6487 (void) zio_wait(spa
->spa_async_zio_root
[c
]);
6488 spa
->spa_async_zio_root
[c
] = zio_root(spa
, NULL
, NULL
,
6489 ZIO_FLAG_CANFAIL
| ZIO_FLAG_SPECULATIVE
|
6490 ZIO_FLAG_GODFATHER
);
6493 ASSERT0(spa
->spa_load_verify_bytes
);
6496 * Done after zio_wait() since zcb_haderrors is modified in
6499 zcb
.zcb_haderrors
|= err
;
6501 if (zcb
.zcb_haderrors
) {
6502 (void) printf("\nError counts:\n\n");
6503 (void) printf("\t%5s %s\n", "errno", "count");
6504 for (e
= 0; e
< 256; e
++) {
6505 if (zcb
.zcb_errors
[e
] != 0) {
6506 (void) printf("\t%5d %llu\n",
6507 e
, (u_longlong_t
)zcb
.zcb_errors
[e
]);
6513 * Report any leaked segments.
6515 leaks
|= zdb_leak_fini(spa
, &zcb
);
6517 tzb
= &zcb
.zcb_type
[ZB_TOTAL
][ZDB_OT_TOTAL
];
6519 norm_alloc
= metaslab_class_get_alloc(spa_normal_class(spa
));
6520 norm_space
= metaslab_class_get_space(spa_normal_class(spa
));
6522 total_alloc
= norm_alloc
+
6523 metaslab_class_get_alloc(spa_log_class(spa
)) +
6524 metaslab_class_get_alloc(spa_embedded_log_class(spa
)) +
6525 metaslab_class_get_alloc(spa_special_class(spa
)) +
6526 metaslab_class_get_alloc(spa_dedup_class(spa
)) +
6527 get_unflushed_alloc_space(spa
);
6528 total_found
= tzb
->zb_asize
- zcb
.zcb_dedup_asize
+
6529 zcb
.zcb_removing_size
+ zcb
.zcb_checkpoint_size
;
6531 if (total_found
== total_alloc
&& !dump_opt
['L']) {
6532 (void) printf("\n\tNo leaks (block sum matches space"
6533 " maps exactly)\n");
6534 } else if (!dump_opt
['L']) {
6535 (void) printf("block traversal size %llu != alloc %llu "
6537 (u_longlong_t
)total_found
,
6538 (u_longlong_t
)total_alloc
,
6539 (dump_opt
['L']) ? "unreachable" : "leaked",
6540 (longlong_t
)(total_alloc
- total_found
));
6544 if (tzb
->zb_count
== 0)
6547 (void) printf("\n");
6548 (void) printf("\t%-16s %14llu\n", "bp count:",
6549 (u_longlong_t
)tzb
->zb_count
);
6550 (void) printf("\t%-16s %14llu\n", "ganged count:",
6551 (longlong_t
)tzb
->zb_gangs
);
6552 (void) printf("\t%-16s %14llu avg: %6llu\n", "bp logical:",
6553 (u_longlong_t
)tzb
->zb_lsize
,
6554 (u_longlong_t
)(tzb
->zb_lsize
/ tzb
->zb_count
));
6555 (void) printf("\t%-16s %14llu avg: %6llu compression: %6.2f\n",
6556 "bp physical:", (u_longlong_t
)tzb
->zb_psize
,
6557 (u_longlong_t
)(tzb
->zb_psize
/ tzb
->zb_count
),
6558 (double)tzb
->zb_lsize
/ tzb
->zb_psize
);
6559 (void) printf("\t%-16s %14llu avg: %6llu compression: %6.2f\n",
6560 "bp allocated:", (u_longlong_t
)tzb
->zb_asize
,
6561 (u_longlong_t
)(tzb
->zb_asize
/ tzb
->zb_count
),
6562 (double)tzb
->zb_lsize
/ tzb
->zb_asize
);
6563 (void) printf("\t%-16s %14llu ref>1: %6llu deduplication: %6.2f\n",
6564 "bp deduped:", (u_longlong_t
)zcb
.zcb_dedup_asize
,
6565 (u_longlong_t
)zcb
.zcb_dedup_blocks
,
6566 (double)zcb
.zcb_dedup_asize
/ tzb
->zb_asize
+ 1.0);
6567 (void) printf("\t%-16s %14llu used: %5.2f%%\n", "Normal class:",
6568 (u_longlong_t
)norm_alloc
, 100.0 * norm_alloc
/ norm_space
);
6570 if (spa_special_class(spa
)->mc_allocator
[0].mca_rotor
!= NULL
) {
6571 uint64_t alloc
= metaslab_class_get_alloc(
6572 spa_special_class(spa
));
6573 uint64_t space
= metaslab_class_get_space(
6574 spa_special_class(spa
));
6576 (void) printf("\t%-16s %14llu used: %5.2f%%\n",
6577 "Special class", (u_longlong_t
)alloc
,
6578 100.0 * alloc
/ space
);
6581 if (spa_dedup_class(spa
)->mc_allocator
[0].mca_rotor
!= NULL
) {
6582 uint64_t alloc
= metaslab_class_get_alloc(
6583 spa_dedup_class(spa
));
6584 uint64_t space
= metaslab_class_get_space(
6585 spa_dedup_class(spa
));
6587 (void) printf("\t%-16s %14llu used: %5.2f%%\n",
6588 "Dedup class", (u_longlong_t
)alloc
,
6589 100.0 * alloc
/ space
);
6592 if (spa_embedded_log_class(spa
)->mc_allocator
[0].mca_rotor
!= NULL
) {
6593 uint64_t alloc
= metaslab_class_get_alloc(
6594 spa_embedded_log_class(spa
));
6595 uint64_t space
= metaslab_class_get_space(
6596 spa_embedded_log_class(spa
));
6598 (void) printf("\t%-16s %14llu used: %5.2f%%\n",
6599 "Embedded log class", (u_longlong_t
)alloc
,
6600 100.0 * alloc
/ space
);
6603 for (i
= 0; i
< NUM_BP_EMBEDDED_TYPES
; i
++) {
6604 if (zcb
.zcb_embedded_blocks
[i
] == 0)
6606 (void) printf("\n");
6607 (void) printf("\tadditional, non-pointer bps of type %u: "
6609 i
, (u_longlong_t
)zcb
.zcb_embedded_blocks
[i
]);
6611 if (dump_opt
['b'] >= 3) {
6612 (void) printf("\t number of (compressed) bytes: "
6614 dump_histogram(zcb
.zcb_embedded_histogram
[i
],
6615 sizeof (zcb
.zcb_embedded_histogram
[i
]) /
6616 sizeof (zcb
.zcb_embedded_histogram
[i
][0]), 0);
6620 if (tzb
->zb_ditto_samevdev
!= 0) {
6621 (void) printf("\tDittoed blocks on same vdev: %llu\n",
6622 (longlong_t
)tzb
->zb_ditto_samevdev
);
6624 if (tzb
->zb_ditto_same_ms
!= 0) {
6625 (void) printf("\tDittoed blocks in same metaslab: %llu\n",
6626 (longlong_t
)tzb
->zb_ditto_same_ms
);
6629 for (uint64_t v
= 0; v
< spa
->spa_root_vdev
->vdev_children
; v
++) {
6630 vdev_t
*vd
= spa
->spa_root_vdev
->vdev_child
[v
];
6631 vdev_indirect_mapping_t
*vim
= vd
->vdev_indirect_mapping
;
6638 zdb_nicenum(vdev_indirect_mapping_num_entries(vim
),
6639 mem
, vdev_indirect_mapping_size(vim
));
6641 (void) printf("\tindirect vdev id %llu has %llu segments "
6643 (longlong_t
)vd
->vdev_id
,
6644 (longlong_t
)vdev_indirect_mapping_num_entries(vim
), mem
);
6647 if (dump_opt
['b'] >= 2) {
6649 (void) printf("\nBlocks\tLSIZE\tPSIZE\tASIZE"
6650 "\t avg\t comp\t%%Total\tType\n");
6652 for (t
= 0; t
<= ZDB_OT_TOTAL
; t
++) {
6653 char csize
[32], lsize
[32], psize
[32], asize
[32];
6654 char avg
[32], gang
[32];
6655 const char *typename
;
6657 /* make sure nicenum has enough space */
6658 _Static_assert(sizeof (csize
) >= NN_NUMBUF_SZ
,
6660 _Static_assert(sizeof (lsize
) >= NN_NUMBUF_SZ
,
6662 _Static_assert(sizeof (psize
) >= NN_NUMBUF_SZ
,
6664 _Static_assert(sizeof (asize
) >= NN_NUMBUF_SZ
,
6666 _Static_assert(sizeof (avg
) >= NN_NUMBUF_SZ
,
6668 _Static_assert(sizeof (gang
) >= NN_NUMBUF_SZ
,
6671 if (t
< DMU_OT_NUMTYPES
)
6672 typename
= dmu_ot
[t
].ot_name
;
6674 typename
= zdb_ot_extname
[t
- DMU_OT_NUMTYPES
];
6676 if (zcb
.zcb_type
[ZB_TOTAL
][t
].zb_asize
== 0) {
6677 (void) printf("%6s\t%5s\t%5s\t%5s"
6678 "\t%5s\t%5s\t%6s\t%s\n",
6690 for (l
= ZB_TOTAL
- 1; l
>= -1; l
--) {
6691 level
= (l
== -1 ? ZB_TOTAL
: l
);
6692 zb
= &zcb
.zcb_type
[level
][t
];
6694 if (zb
->zb_asize
== 0)
6697 if (dump_opt
['b'] < 3 && level
!= ZB_TOTAL
)
6700 if (level
== 0 && zb
->zb_asize
==
6701 zcb
.zcb_type
[ZB_TOTAL
][t
].zb_asize
)
6704 zdb_nicenum(zb
->zb_count
, csize
,
6706 zdb_nicenum(zb
->zb_lsize
, lsize
,
6708 zdb_nicenum(zb
->zb_psize
, psize
,
6710 zdb_nicenum(zb
->zb_asize
, asize
,
6712 zdb_nicenum(zb
->zb_asize
/ zb
->zb_count
, avg
,
6714 zdb_nicenum(zb
->zb_gangs
, gang
, sizeof (gang
));
6716 (void) printf("%6s\t%5s\t%5s\t%5s\t%5s"
6718 csize
, lsize
, psize
, asize
, avg
,
6719 (double)zb
->zb_lsize
/ zb
->zb_psize
,
6720 100.0 * zb
->zb_asize
/ tzb
->zb_asize
);
6722 if (level
== ZB_TOTAL
)
6723 (void) printf("%s\n", typename
);
6725 (void) printf(" L%d %s\n",
6728 if (dump_opt
['b'] >= 3 && zb
->zb_gangs
> 0) {
6729 (void) printf("\t number of ganged "
6730 "blocks: %s\n", gang
);
6733 if (dump_opt
['b'] >= 4) {
6734 (void) printf("psize "
6735 "(in 512-byte sectors): "
6736 "number of blocks\n");
6737 dump_histogram(zb
->zb_psize_histogram
,
6738 PSIZE_HISTO_SIZE
, 0);
6743 /* Output a table summarizing block sizes in the pool */
6744 if (dump_opt
['b'] >= 2) {
6745 dump_size_histograms(&zcb
);
6749 (void) printf("\n");
6754 if (zcb
.zcb_haderrors
)
6760 typedef struct zdb_ddt_entry
{
6762 uint64_t zdde_ref_blocks
;
6763 uint64_t zdde_ref_lsize
;
6764 uint64_t zdde_ref_psize
;
6765 uint64_t zdde_ref_dsize
;
6766 avl_node_t zdde_node
;
6770 zdb_ddt_add_cb(spa_t
*spa
, zilog_t
*zilog
, const blkptr_t
*bp
,
6771 const zbookmark_phys_t
*zb
, const dnode_phys_t
*dnp
, void *arg
)
6773 (void) zilog
, (void) dnp
;
6774 avl_tree_t
*t
= arg
;
6776 zdb_ddt_entry_t
*zdde
, zdde_search
;
6778 if (zb
->zb_level
== ZB_DNODE_LEVEL
|| BP_IS_HOLE(bp
) ||
6782 if (dump_opt
['S'] > 1 && zb
->zb_level
== ZB_ROOT_LEVEL
) {
6783 (void) printf("traversing objset %llu, %llu objects, "
6784 "%lu blocks so far\n",
6785 (u_longlong_t
)zb
->zb_objset
,
6786 (u_longlong_t
)BP_GET_FILL(bp
),
6790 if (BP_IS_HOLE(bp
) || BP_GET_CHECKSUM(bp
) == ZIO_CHECKSUM_OFF
||
6791 BP_GET_LEVEL(bp
) > 0 || DMU_OT_IS_METADATA(BP_GET_TYPE(bp
)))
6794 ddt_key_fill(&zdde_search
.zdde_key
, bp
);
6796 zdde
= avl_find(t
, &zdde_search
, &where
);
6799 zdde
= umem_zalloc(sizeof (*zdde
), UMEM_NOFAIL
);
6800 zdde
->zdde_key
= zdde_search
.zdde_key
;
6801 avl_insert(t
, zdde
, where
);
6804 zdde
->zdde_ref_blocks
+= 1;
6805 zdde
->zdde_ref_lsize
+= BP_GET_LSIZE(bp
);
6806 zdde
->zdde_ref_psize
+= BP_GET_PSIZE(bp
);
6807 zdde
->zdde_ref_dsize
+= bp_get_dsize_sync(spa
, bp
);
6813 dump_simulated_ddt(spa_t
*spa
)
6816 void *cookie
= NULL
;
6817 zdb_ddt_entry_t
*zdde
;
6818 ddt_histogram_t ddh_total
;
6819 ddt_stat_t dds_total
;
6821 bzero(&ddh_total
, sizeof (ddh_total
));
6822 bzero(&dds_total
, sizeof (dds_total
));
6823 avl_create(&t
, ddt_entry_compare
,
6824 sizeof (zdb_ddt_entry_t
), offsetof(zdb_ddt_entry_t
, zdde_node
));
6826 spa_config_enter(spa
, SCL_CONFIG
, FTAG
, RW_READER
);
6828 (void) traverse_pool(spa
, 0, TRAVERSE_PRE
| TRAVERSE_PREFETCH_METADATA
|
6829 TRAVERSE_NO_DECRYPT
, zdb_ddt_add_cb
, &t
);
6831 spa_config_exit(spa
, SCL_CONFIG
, FTAG
);
6833 while ((zdde
= avl_destroy_nodes(&t
, &cookie
)) != NULL
) {
6835 uint64_t refcnt
= zdde
->zdde_ref_blocks
;
6836 ASSERT(refcnt
!= 0);
6838 dds
.dds_blocks
= zdde
->zdde_ref_blocks
/ refcnt
;
6839 dds
.dds_lsize
= zdde
->zdde_ref_lsize
/ refcnt
;
6840 dds
.dds_psize
= zdde
->zdde_ref_psize
/ refcnt
;
6841 dds
.dds_dsize
= zdde
->zdde_ref_dsize
/ refcnt
;
6843 dds
.dds_ref_blocks
= zdde
->zdde_ref_blocks
;
6844 dds
.dds_ref_lsize
= zdde
->zdde_ref_lsize
;
6845 dds
.dds_ref_psize
= zdde
->zdde_ref_psize
;
6846 dds
.dds_ref_dsize
= zdde
->zdde_ref_dsize
;
6848 ddt_stat_add(&ddh_total
.ddh_stat
[highbit64(refcnt
) - 1],
6851 umem_free(zdde
, sizeof (*zdde
));
6856 ddt_histogram_stat(&dds_total
, &ddh_total
);
6858 (void) printf("Simulated DDT histogram:\n");
6860 zpool_dump_ddt(&dds_total
, &ddh_total
);
6862 dump_dedup_ratio(&dds_total
);
6866 verify_device_removal_feature_counts(spa_t
*spa
)
6868 uint64_t dr_feature_refcount
= 0;
6869 uint64_t oc_feature_refcount
= 0;
6870 uint64_t indirect_vdev_count
= 0;
6871 uint64_t precise_vdev_count
= 0;
6872 uint64_t obsolete_counts_object_count
= 0;
6873 uint64_t obsolete_sm_count
= 0;
6874 uint64_t obsolete_counts_count
= 0;
6875 uint64_t scip_count
= 0;
6876 uint64_t obsolete_bpobj_count
= 0;
6879 spa_condensing_indirect_phys_t
*scip
=
6880 &spa
->spa_condensing_indirect_phys
;
6881 if (scip
->scip_next_mapping_object
!= 0) {
6882 vdev_t
*vd
= spa
->spa_root_vdev
->vdev_child
[scip
->scip_vdev
];
6883 ASSERT(scip
->scip_prev_obsolete_sm_object
!= 0);
6884 ASSERT3P(vd
->vdev_ops
, ==, &vdev_indirect_ops
);
6886 (void) printf("Condensing indirect vdev %llu: new mapping "
6887 "object %llu, prev obsolete sm %llu\n",
6888 (u_longlong_t
)scip
->scip_vdev
,
6889 (u_longlong_t
)scip
->scip_next_mapping_object
,
6890 (u_longlong_t
)scip
->scip_prev_obsolete_sm_object
);
6891 if (scip
->scip_prev_obsolete_sm_object
!= 0) {
6892 space_map_t
*prev_obsolete_sm
= NULL
;
6893 VERIFY0(space_map_open(&prev_obsolete_sm
,
6894 spa
->spa_meta_objset
,
6895 scip
->scip_prev_obsolete_sm_object
,
6896 0, vd
->vdev_asize
, 0));
6897 dump_spacemap(spa
->spa_meta_objset
, prev_obsolete_sm
);
6898 (void) printf("\n");
6899 space_map_close(prev_obsolete_sm
);
6905 for (uint64_t i
= 0; i
< spa
->spa_root_vdev
->vdev_children
; i
++) {
6906 vdev_t
*vd
= spa
->spa_root_vdev
->vdev_child
[i
];
6907 vdev_indirect_config_t
*vic
= &vd
->vdev_indirect_config
;
6909 if (vic
->vic_mapping_object
!= 0) {
6910 ASSERT(vd
->vdev_ops
== &vdev_indirect_ops
||
6912 indirect_vdev_count
++;
6914 if (vd
->vdev_indirect_mapping
->vim_havecounts
) {
6915 obsolete_counts_count
++;
6919 boolean_t are_precise
;
6920 VERIFY0(vdev_obsolete_counts_are_precise(vd
, &are_precise
));
6922 ASSERT(vic
->vic_mapping_object
!= 0);
6923 precise_vdev_count
++;
6926 uint64_t obsolete_sm_object
;
6927 VERIFY0(vdev_obsolete_sm_object(vd
, &obsolete_sm_object
));
6928 if (obsolete_sm_object
!= 0) {
6929 ASSERT(vic
->vic_mapping_object
!= 0);
6930 obsolete_sm_count
++;
6934 (void) feature_get_refcount(spa
,
6935 &spa_feature_table
[SPA_FEATURE_DEVICE_REMOVAL
],
6936 &dr_feature_refcount
);
6937 (void) feature_get_refcount(spa
,
6938 &spa_feature_table
[SPA_FEATURE_OBSOLETE_COUNTS
],
6939 &oc_feature_refcount
);
6941 if (dr_feature_refcount
!= indirect_vdev_count
) {
6943 (void) printf("Number of indirect vdevs (%llu) " \
6944 "does not match feature count (%llu)\n",
6945 (u_longlong_t
)indirect_vdev_count
,
6946 (u_longlong_t
)dr_feature_refcount
);
6948 (void) printf("Verified device_removal feature refcount " \
6949 "of %llu is correct\n",
6950 (u_longlong_t
)dr_feature_refcount
);
6953 if (zap_contains(spa_meta_objset(spa
), DMU_POOL_DIRECTORY_OBJECT
,
6954 DMU_POOL_OBSOLETE_BPOBJ
) == 0) {
6955 obsolete_bpobj_count
++;
6959 obsolete_counts_object_count
= precise_vdev_count
;
6960 obsolete_counts_object_count
+= obsolete_sm_count
;
6961 obsolete_counts_object_count
+= obsolete_counts_count
;
6962 obsolete_counts_object_count
+= scip_count
;
6963 obsolete_counts_object_count
+= obsolete_bpobj_count
;
6964 obsolete_counts_object_count
+= remap_deadlist_count
;
6966 if (oc_feature_refcount
!= obsolete_counts_object_count
) {
6968 (void) printf("Number of obsolete counts objects (%llu) " \
6969 "does not match feature count (%llu)\n",
6970 (u_longlong_t
)obsolete_counts_object_count
,
6971 (u_longlong_t
)oc_feature_refcount
);
6972 (void) printf("pv:%llu os:%llu oc:%llu sc:%llu "
6973 "ob:%llu rd:%llu\n",
6974 (u_longlong_t
)precise_vdev_count
,
6975 (u_longlong_t
)obsolete_sm_count
,
6976 (u_longlong_t
)obsolete_counts_count
,
6977 (u_longlong_t
)scip_count
,
6978 (u_longlong_t
)obsolete_bpobj_count
,
6979 (u_longlong_t
)remap_deadlist_count
);
6981 (void) printf("Verified indirect_refcount feature refcount " \
6982 "of %llu is correct\n",
6983 (u_longlong_t
)oc_feature_refcount
);
6989 zdb_set_skip_mmp(char *target
)
6994 * Disable the activity check to allow examination of
6997 mutex_enter(&spa_namespace_lock
);
6998 if ((spa
= spa_lookup(target
)) != NULL
) {
6999 spa
->spa_import_flags
|= ZFS_IMPORT_SKIP_MMP
;
7001 mutex_exit(&spa_namespace_lock
);
7004 #define BOGUS_SUFFIX "_CHECKPOINTED_UNIVERSE"
7006 * Import the checkpointed state of the pool specified by the target
7007 * parameter as readonly. The function also accepts a pool config
7008 * as an optional parameter, else it attempts to infer the config by
7009 * the name of the target pool.
7011 * Note that the checkpointed state's pool name will be the name of
7012 * the original pool with the above suffix appended to it. In addition,
7013 * if the target is not a pool name (e.g. a path to a dataset) then
7014 * the new_path parameter is populated with the updated path to
7015 * reflect the fact that we are looking into the checkpointed state.
7017 * The function returns a newly-allocated copy of the name of the
7018 * pool containing the checkpointed state. When this copy is no
7019 * longer needed it should be freed with free(3C). Same thing
7020 * applies to the new_path parameter if allocated.
7023 import_checkpointed_state(char *target
, nvlist_t
*cfg
, char **new_path
)
7026 char *poolname
, *bogus_name
= NULL
;
7027 boolean_t freecfg
= B_FALSE
;
7029 /* If the target is not a pool, the extract the pool name */
7030 char *path_start
= strchr(target
, '/');
7031 if (path_start
!= NULL
) {
7032 size_t poolname_len
= path_start
- target
;
7033 poolname
= strndup(target
, poolname_len
);
7039 zdb_set_skip_mmp(poolname
);
7040 error
= spa_get_stats(poolname
, &cfg
, NULL
, 0);
7042 fatal("Tried to read config of pool \"%s\" but "
7043 "spa_get_stats() failed with error %d\n",
7049 if (asprintf(&bogus_name
, "%s%s", poolname
, BOGUS_SUFFIX
) == -1)
7051 fnvlist_add_string(cfg
, ZPOOL_CONFIG_POOL_NAME
, bogus_name
);
7053 error
= spa_import(bogus_name
, cfg
, NULL
,
7054 ZFS_IMPORT_MISSING_LOG
| ZFS_IMPORT_CHECKPOINT
|
7055 ZFS_IMPORT_SKIP_MMP
);
7059 fatal("Tried to import pool \"%s\" but spa_import() failed "
7060 "with error %d\n", bogus_name
, error
);
7063 if (new_path
!= NULL
&& path_start
!= NULL
) {
7064 if (asprintf(new_path
, "%s%s", bogus_name
, path_start
) == -1) {
7065 if (path_start
!= NULL
)
7071 if (target
!= poolname
)
7074 return (bogus_name
);
7077 typedef struct verify_checkpoint_sm_entry_cb_arg
{
7080 /* the following fields are only used for printing progress */
7081 uint64_t vcsec_entryid
;
7082 uint64_t vcsec_num_entries
;
7083 } verify_checkpoint_sm_entry_cb_arg_t
;
7085 #define ENTRIES_PER_PROGRESS_UPDATE 10000
7088 verify_checkpoint_sm_entry_cb(space_map_entry_t
*sme
, void *arg
)
7090 verify_checkpoint_sm_entry_cb_arg_t
*vcsec
= arg
;
7091 vdev_t
*vd
= vcsec
->vcsec_vd
;
7092 metaslab_t
*ms
= vd
->vdev_ms
[sme
->sme_offset
>> vd
->vdev_ms_shift
];
7093 uint64_t end
= sme
->sme_offset
+ sme
->sme_run
;
7095 ASSERT(sme
->sme_type
== SM_FREE
);
7097 if ((vcsec
->vcsec_entryid
% ENTRIES_PER_PROGRESS_UPDATE
) == 0) {
7098 (void) fprintf(stderr
,
7099 "\rverifying vdev %llu, space map entry %llu of %llu ...",
7100 (longlong_t
)vd
->vdev_id
,
7101 (longlong_t
)vcsec
->vcsec_entryid
,
7102 (longlong_t
)vcsec
->vcsec_num_entries
);
7104 vcsec
->vcsec_entryid
++;
7107 * See comment in checkpoint_sm_exclude_entry_cb()
7109 VERIFY3U(sme
->sme_offset
, >=, ms
->ms_start
);
7110 VERIFY3U(end
, <=, ms
->ms_start
+ ms
->ms_size
);
7113 * The entries in the vdev_checkpoint_sm should be marked as
7114 * allocated in the checkpointed state of the pool, therefore
7115 * their respective ms_allocateable trees should not contain them.
7117 mutex_enter(&ms
->ms_lock
);
7118 range_tree_verify_not_present(ms
->ms_allocatable
,
7119 sme
->sme_offset
, sme
->sme_run
);
7120 mutex_exit(&ms
->ms_lock
);
7126 * Verify that all segments in the vdev_checkpoint_sm are allocated
7127 * according to the checkpoint's ms_sm (i.e. are not in the checkpoint's
7130 * Do so by comparing the checkpoint space maps (vdev_checkpoint_sm) of
7131 * each vdev in the current state of the pool to the metaslab space maps
7132 * (ms_sm) of the checkpointed state of the pool.
7134 * Note that the function changes the state of the ms_allocatable
7135 * trees of the current spa_t. The entries of these ms_allocatable
7136 * trees are cleared out and then repopulated from with the free
7137 * entries of their respective ms_sm space maps.
7140 verify_checkpoint_vdev_spacemaps(spa_t
*checkpoint
, spa_t
*current
)
7142 vdev_t
*ckpoint_rvd
= checkpoint
->spa_root_vdev
;
7143 vdev_t
*current_rvd
= current
->spa_root_vdev
;
7145 load_concrete_ms_allocatable_trees(checkpoint
, SM_FREE
);
7147 for (uint64_t c
= 0; c
< ckpoint_rvd
->vdev_children
; c
++) {
7148 vdev_t
*ckpoint_vd
= ckpoint_rvd
->vdev_child
[c
];
7149 vdev_t
*current_vd
= current_rvd
->vdev_child
[c
];
7151 space_map_t
*checkpoint_sm
= NULL
;
7152 uint64_t checkpoint_sm_obj
;
7154 if (ckpoint_vd
->vdev_ops
== &vdev_indirect_ops
) {
7156 * Since we don't allow device removal in a pool
7157 * that has a checkpoint, we expect that all removed
7158 * vdevs were removed from the pool before the
7161 ASSERT3P(current_vd
->vdev_ops
, ==, &vdev_indirect_ops
);
7166 * If the checkpoint space map doesn't exist, then nothing
7167 * here is checkpointed so there's nothing to verify.
7169 if (current_vd
->vdev_top_zap
== 0 ||
7170 zap_contains(spa_meta_objset(current
),
7171 current_vd
->vdev_top_zap
,
7172 VDEV_TOP_ZAP_POOL_CHECKPOINT_SM
) != 0)
7175 VERIFY0(zap_lookup(spa_meta_objset(current
),
7176 current_vd
->vdev_top_zap
, VDEV_TOP_ZAP_POOL_CHECKPOINT_SM
,
7177 sizeof (uint64_t), 1, &checkpoint_sm_obj
));
7179 VERIFY0(space_map_open(&checkpoint_sm
, spa_meta_objset(current
),
7180 checkpoint_sm_obj
, 0, current_vd
->vdev_asize
,
7181 current_vd
->vdev_ashift
));
7183 verify_checkpoint_sm_entry_cb_arg_t vcsec
;
7184 vcsec
.vcsec_vd
= ckpoint_vd
;
7185 vcsec
.vcsec_entryid
= 0;
7186 vcsec
.vcsec_num_entries
=
7187 space_map_length(checkpoint_sm
) / sizeof (uint64_t);
7188 VERIFY0(space_map_iterate(checkpoint_sm
,
7189 space_map_length(checkpoint_sm
),
7190 verify_checkpoint_sm_entry_cb
, &vcsec
));
7191 if (dump_opt
['m'] > 3)
7192 dump_spacemap(current
->spa_meta_objset
, checkpoint_sm
);
7193 space_map_close(checkpoint_sm
);
7197 * If we've added vdevs since we took the checkpoint, ensure
7198 * that their checkpoint space maps are empty.
7200 if (ckpoint_rvd
->vdev_children
< current_rvd
->vdev_children
) {
7201 for (uint64_t c
= ckpoint_rvd
->vdev_children
;
7202 c
< current_rvd
->vdev_children
; c
++) {
7203 vdev_t
*current_vd
= current_rvd
->vdev_child
[c
];
7204 VERIFY3P(current_vd
->vdev_checkpoint_sm
, ==, NULL
);
7208 /* for cleaner progress output */
7209 (void) fprintf(stderr
, "\n");
7213 * Verifies that all space that's allocated in the checkpoint is
7214 * still allocated in the current version, by checking that everything
7215 * in checkpoint's ms_allocatable (which is actually allocated, not
7216 * allocatable/free) is not present in current's ms_allocatable.
7218 * Note that the function changes the state of the ms_allocatable
7219 * trees of both spas when called. The entries of all ms_allocatable
7220 * trees are cleared out and then repopulated from their respective
7221 * ms_sm space maps. In the checkpointed state we load the allocated
7222 * entries, and in the current state we load the free entries.
7225 verify_checkpoint_ms_spacemaps(spa_t
*checkpoint
, spa_t
*current
)
7227 vdev_t
*ckpoint_rvd
= checkpoint
->spa_root_vdev
;
7228 vdev_t
*current_rvd
= current
->spa_root_vdev
;
7230 load_concrete_ms_allocatable_trees(checkpoint
, SM_ALLOC
);
7231 load_concrete_ms_allocatable_trees(current
, SM_FREE
);
7233 for (uint64_t i
= 0; i
< ckpoint_rvd
->vdev_children
; i
++) {
7234 vdev_t
*ckpoint_vd
= ckpoint_rvd
->vdev_child
[i
];
7235 vdev_t
*current_vd
= current_rvd
->vdev_child
[i
];
7237 if (ckpoint_vd
->vdev_ops
== &vdev_indirect_ops
) {
7239 * See comment in verify_checkpoint_vdev_spacemaps()
7241 ASSERT3P(current_vd
->vdev_ops
, ==, &vdev_indirect_ops
);
7245 for (uint64_t m
= 0; m
< ckpoint_vd
->vdev_ms_count
; m
++) {
7246 metaslab_t
*ckpoint_msp
= ckpoint_vd
->vdev_ms
[m
];
7247 metaslab_t
*current_msp
= current_vd
->vdev_ms
[m
];
7249 (void) fprintf(stderr
,
7250 "\rverifying vdev %llu of %llu, "
7251 "metaslab %llu of %llu ...",
7252 (longlong_t
)current_vd
->vdev_id
,
7253 (longlong_t
)current_rvd
->vdev_children
,
7254 (longlong_t
)current_vd
->vdev_ms
[m
]->ms_id
,
7255 (longlong_t
)current_vd
->vdev_ms_count
);
7258 * We walk through the ms_allocatable trees that
7259 * are loaded with the allocated blocks from the
7260 * ms_sm spacemaps of the checkpoint. For each
7261 * one of these ranges we ensure that none of them
7262 * exists in the ms_allocatable trees of the
7263 * current state which are loaded with the ranges
7264 * that are currently free.
7266 * This way we ensure that none of the blocks that
7267 * are part of the checkpoint were freed by mistake.
7269 range_tree_walk(ckpoint_msp
->ms_allocatable
,
7270 (range_tree_func_t
*)range_tree_verify_not_present
,
7271 current_msp
->ms_allocatable
);
7275 /* for cleaner progress output */
7276 (void) fprintf(stderr
, "\n");
7280 verify_checkpoint_blocks(spa_t
*spa
)
7282 ASSERT(!dump_opt
['L']);
7284 spa_t
*checkpoint_spa
;
7285 char *checkpoint_pool
;
7289 * We import the checkpointed state of the pool (under a different
7290 * name) so we can do verification on it against the current state
7293 checkpoint_pool
= import_checkpointed_state(spa
->spa_name
, NULL
,
7295 ASSERT(strcmp(spa
->spa_name
, checkpoint_pool
) != 0);
7297 error
= spa_open(checkpoint_pool
, &checkpoint_spa
, FTAG
);
7299 fatal("Tried to open pool \"%s\" but spa_open() failed with "
7300 "error %d\n", checkpoint_pool
, error
);
7304 * Ensure that ranges in the checkpoint space maps of each vdev
7305 * are allocated according to the checkpointed state's metaslab
7308 verify_checkpoint_vdev_spacemaps(checkpoint_spa
, spa
);
7311 * Ensure that allocated ranges in the checkpoint's metaslab
7312 * space maps remain allocated in the metaslab space maps of
7313 * the current state.
7315 verify_checkpoint_ms_spacemaps(checkpoint_spa
, spa
);
7318 * Once we are done, we get rid of the checkpointed state.
7320 spa_close(checkpoint_spa
, FTAG
);
7321 free(checkpoint_pool
);
7325 dump_leftover_checkpoint_blocks(spa_t
*spa
)
7327 vdev_t
*rvd
= spa
->spa_root_vdev
;
7329 for (uint64_t i
= 0; i
< rvd
->vdev_children
; i
++) {
7330 vdev_t
*vd
= rvd
->vdev_child
[i
];
7332 space_map_t
*checkpoint_sm
= NULL
;
7333 uint64_t checkpoint_sm_obj
;
7335 if (vd
->vdev_top_zap
== 0)
7338 if (zap_contains(spa_meta_objset(spa
), vd
->vdev_top_zap
,
7339 VDEV_TOP_ZAP_POOL_CHECKPOINT_SM
) != 0)
7342 VERIFY0(zap_lookup(spa_meta_objset(spa
), vd
->vdev_top_zap
,
7343 VDEV_TOP_ZAP_POOL_CHECKPOINT_SM
,
7344 sizeof (uint64_t), 1, &checkpoint_sm_obj
));
7346 VERIFY0(space_map_open(&checkpoint_sm
, spa_meta_objset(spa
),
7347 checkpoint_sm_obj
, 0, vd
->vdev_asize
, vd
->vdev_ashift
));
7348 dump_spacemap(spa
->spa_meta_objset
, checkpoint_sm
);
7349 space_map_close(checkpoint_sm
);
7354 verify_checkpoint(spa_t
*spa
)
7356 uberblock_t checkpoint
;
7359 if (!spa_feature_is_active(spa
, SPA_FEATURE_POOL_CHECKPOINT
))
7362 error
= zap_lookup(spa
->spa_meta_objset
, DMU_POOL_DIRECTORY_OBJECT
,
7363 DMU_POOL_ZPOOL_CHECKPOINT
, sizeof (uint64_t),
7364 sizeof (uberblock_t
) / sizeof (uint64_t), &checkpoint
);
7366 if (error
== ENOENT
&& !dump_opt
['L']) {
7368 * If the feature is active but the uberblock is missing
7369 * then we must be in the middle of discarding the
7372 (void) printf("\nPartially discarded checkpoint "
7374 if (dump_opt
['m'] > 3)
7375 dump_leftover_checkpoint_blocks(spa
);
7377 } else if (error
!= 0) {
7378 (void) printf("lookup error %d when looking for "
7379 "checkpointed uberblock in MOS\n", error
);
7382 dump_uberblock(&checkpoint
, "\nCheckpointed uberblock found:\n", "\n");
7384 if (checkpoint
.ub_checkpoint_txg
== 0) {
7385 (void) printf("\nub_checkpoint_txg not set in checkpointed "
7390 if (error
== 0 && !dump_opt
['L'])
7391 verify_checkpoint_blocks(spa
);
7397 mos_leaks_cb(void *arg
, uint64_t start
, uint64_t size
)
7400 for (uint64_t i
= start
; i
< size
; i
++) {
7401 (void) printf("MOS object %llu referenced but not allocated\n",
7407 mos_obj_refd(uint64_t obj
)
7409 if (obj
!= 0 && mos_refd_objs
!= NULL
)
7410 range_tree_add(mos_refd_objs
, obj
, 1);
7414 * Call on a MOS object that may already have been referenced.
7417 mos_obj_refd_multiple(uint64_t obj
)
7419 if (obj
!= 0 && mos_refd_objs
!= NULL
&&
7420 !range_tree_contains(mos_refd_objs
, obj
, 1))
7421 range_tree_add(mos_refd_objs
, obj
, 1);
7425 mos_leak_vdev_top_zap(vdev_t
*vd
)
7427 uint64_t ms_flush_data_obj
;
7428 int error
= zap_lookup(spa_meta_objset(vd
->vdev_spa
),
7429 vd
->vdev_top_zap
, VDEV_TOP_ZAP_MS_UNFLUSHED_PHYS_TXGS
,
7430 sizeof (ms_flush_data_obj
), 1, &ms_flush_data_obj
);
7431 if (error
== ENOENT
)
7435 mos_obj_refd(ms_flush_data_obj
);
7439 mos_leak_vdev(vdev_t
*vd
)
7441 mos_obj_refd(vd
->vdev_dtl_object
);
7442 mos_obj_refd(vd
->vdev_ms_array
);
7443 mos_obj_refd(vd
->vdev_indirect_config
.vic_births_object
);
7444 mos_obj_refd(vd
->vdev_indirect_config
.vic_mapping_object
);
7445 mos_obj_refd(vd
->vdev_leaf_zap
);
7446 if (vd
->vdev_checkpoint_sm
!= NULL
)
7447 mos_obj_refd(vd
->vdev_checkpoint_sm
->sm_object
);
7448 if (vd
->vdev_indirect_mapping
!= NULL
) {
7449 mos_obj_refd(vd
->vdev_indirect_mapping
->
7450 vim_phys
->vimp_counts_object
);
7452 if (vd
->vdev_obsolete_sm
!= NULL
)
7453 mos_obj_refd(vd
->vdev_obsolete_sm
->sm_object
);
7455 for (uint64_t m
= 0; m
< vd
->vdev_ms_count
; m
++) {
7456 metaslab_t
*ms
= vd
->vdev_ms
[m
];
7457 mos_obj_refd(space_map_object(ms
->ms_sm
));
7460 if (vd
->vdev_top_zap
!= 0) {
7461 mos_obj_refd(vd
->vdev_top_zap
);
7462 mos_leak_vdev_top_zap(vd
);
7465 for (uint64_t c
= 0; c
< vd
->vdev_children
; c
++) {
7466 mos_leak_vdev(vd
->vdev_child
[c
]);
7471 mos_leak_log_spacemaps(spa_t
*spa
)
7473 uint64_t spacemap_zap
;
7474 int error
= zap_lookup(spa_meta_objset(spa
),
7475 DMU_POOL_DIRECTORY_OBJECT
, DMU_POOL_LOG_SPACEMAP_ZAP
,
7476 sizeof (spacemap_zap
), 1, &spacemap_zap
);
7477 if (error
== ENOENT
)
7481 mos_obj_refd(spacemap_zap
);
7482 for (spa_log_sm_t
*sls
= avl_first(&spa
->spa_sm_logs_by_txg
);
7483 sls
; sls
= AVL_NEXT(&spa
->spa_sm_logs_by_txg
, sls
))
7484 mos_obj_refd(sls
->sls_sm_obj
);
7488 dump_mos_leaks(spa_t
*spa
)
7491 objset_t
*mos
= spa
->spa_meta_objset
;
7492 dsl_pool_t
*dp
= spa
->spa_dsl_pool
;
7494 /* Visit and mark all referenced objects in the MOS */
7496 mos_obj_refd(DMU_POOL_DIRECTORY_OBJECT
);
7497 mos_obj_refd(spa
->spa_pool_props_object
);
7498 mos_obj_refd(spa
->spa_config_object
);
7499 mos_obj_refd(spa
->spa_ddt_stat_object
);
7500 mos_obj_refd(spa
->spa_feat_desc_obj
);
7501 mos_obj_refd(spa
->spa_feat_enabled_txg_obj
);
7502 mos_obj_refd(spa
->spa_feat_for_read_obj
);
7503 mos_obj_refd(spa
->spa_feat_for_write_obj
);
7504 mos_obj_refd(spa
->spa_history
);
7505 mos_obj_refd(spa
->spa_errlog_last
);
7506 mos_obj_refd(spa
->spa_errlog_scrub
);
7507 mos_obj_refd(spa
->spa_all_vdev_zaps
);
7508 mos_obj_refd(spa
->spa_dsl_pool
->dp_bptree_obj
);
7509 mos_obj_refd(spa
->spa_dsl_pool
->dp_tmp_userrefs_obj
);
7510 mos_obj_refd(spa
->spa_dsl_pool
->dp_scan
->scn_phys
.scn_queue_obj
);
7511 bpobj_count_refd(&spa
->spa_deferred_bpobj
);
7512 mos_obj_refd(dp
->dp_empty_bpobj
);
7513 bpobj_count_refd(&dp
->dp_obsolete_bpobj
);
7514 bpobj_count_refd(&dp
->dp_free_bpobj
);
7515 mos_obj_refd(spa
->spa_l2cache
.sav_object
);
7516 mos_obj_refd(spa
->spa_spares
.sav_object
);
7518 if (spa
->spa_syncing_log_sm
!= NULL
)
7519 mos_obj_refd(spa
->spa_syncing_log_sm
->sm_object
);
7520 mos_leak_log_spacemaps(spa
);
7522 mos_obj_refd(spa
->spa_condensing_indirect_phys
.
7523 scip_next_mapping_object
);
7524 mos_obj_refd(spa
->spa_condensing_indirect_phys
.
7525 scip_prev_obsolete_sm_object
);
7526 if (spa
->spa_condensing_indirect_phys
.scip_next_mapping_object
!= 0) {
7527 vdev_indirect_mapping_t
*vim
=
7528 vdev_indirect_mapping_open(mos
,
7529 spa
->spa_condensing_indirect_phys
.scip_next_mapping_object
);
7530 mos_obj_refd(vim
->vim_phys
->vimp_counts_object
);
7531 vdev_indirect_mapping_close(vim
);
7533 deleted_livelists_dump_mos(spa
);
7535 if (dp
->dp_origin_snap
!= NULL
) {
7538 dsl_pool_config_enter(dp
, FTAG
);
7539 VERIFY0(dsl_dataset_hold_obj(dp
,
7540 dsl_dataset_phys(dp
->dp_origin_snap
)->ds_next_snap_obj
,
7542 count_ds_mos_objects(ds
);
7543 dump_blkptr_list(&ds
->ds_deadlist
, "Deadlist");
7544 dsl_dataset_rele(ds
, FTAG
);
7545 dsl_pool_config_exit(dp
, FTAG
);
7547 count_ds_mos_objects(dp
->dp_origin_snap
);
7548 dump_blkptr_list(&dp
->dp_origin_snap
->ds_deadlist
, "Deadlist");
7550 count_dir_mos_objects(dp
->dp_mos_dir
);
7551 if (dp
->dp_free_dir
!= NULL
)
7552 count_dir_mos_objects(dp
->dp_free_dir
);
7553 if (dp
->dp_leak_dir
!= NULL
)
7554 count_dir_mos_objects(dp
->dp_leak_dir
);
7556 mos_leak_vdev(spa
->spa_root_vdev
);
7558 for (uint64_t class = 0; class < DDT_CLASSES
; class++) {
7559 for (uint64_t type
= 0; type
< DDT_TYPES
; type
++) {
7560 for (uint64_t cksum
= 0;
7561 cksum
< ZIO_CHECKSUM_FUNCTIONS
; cksum
++) {
7562 ddt_t
*ddt
= spa
->spa_ddt
[cksum
];
7563 mos_obj_refd(ddt
->ddt_object
[type
][class]);
7569 * Visit all allocated objects and make sure they are referenced.
7571 uint64_t object
= 0;
7572 while (dmu_object_next(mos
, &object
, B_FALSE
, 0) == 0) {
7573 if (range_tree_contains(mos_refd_objs
, object
, 1)) {
7574 range_tree_remove(mos_refd_objs
, object
, 1);
7576 dmu_object_info_t doi
;
7578 dmu_object_info(mos
, object
, &doi
);
7579 if (doi
.doi_type
& DMU_OT_NEWTYPE
) {
7580 dmu_object_byteswap_t bswap
=
7581 DMU_OT_BYTESWAP(doi
.doi_type
);
7582 name
= dmu_ot_byteswap
[bswap
].ob_name
;
7584 name
= dmu_ot
[doi
.doi_type
].ot_name
;
7587 (void) printf("MOS object %llu (%s) leaked\n",
7588 (u_longlong_t
)object
, name
);
7592 (void) range_tree_walk(mos_refd_objs
, mos_leaks_cb
, NULL
);
7593 if (!range_tree_is_empty(mos_refd_objs
))
7595 range_tree_vacate(mos_refd_objs
, NULL
, NULL
);
7596 range_tree_destroy(mos_refd_objs
);
7600 typedef struct log_sm_obsolete_stats_arg
{
7601 uint64_t lsos_current_txg
;
7603 uint64_t lsos_total_entries
;
7604 uint64_t lsos_valid_entries
;
7606 uint64_t lsos_sm_entries
;
7607 uint64_t lsos_valid_sm_entries
;
7608 } log_sm_obsolete_stats_arg_t
;
7611 log_spacemap_obsolete_stats_cb(spa_t
*spa
, space_map_entry_t
*sme
,
7612 uint64_t txg
, void *arg
)
7614 log_sm_obsolete_stats_arg_t
*lsos
= arg
;
7616 uint64_t offset
= sme
->sme_offset
;
7617 uint64_t vdev_id
= sme
->sme_vdev
;
7619 if (lsos
->lsos_current_txg
== 0) {
7620 /* this is the first log */
7621 lsos
->lsos_current_txg
= txg
;
7622 } else if (lsos
->lsos_current_txg
< txg
) {
7623 /* we just changed log - print stats and reset */
7624 (void) printf("%-8llu valid entries out of %-8llu - txg %llu\n",
7625 (u_longlong_t
)lsos
->lsos_valid_sm_entries
,
7626 (u_longlong_t
)lsos
->lsos_sm_entries
,
7627 (u_longlong_t
)lsos
->lsos_current_txg
);
7628 lsos
->lsos_valid_sm_entries
= 0;
7629 lsos
->lsos_sm_entries
= 0;
7630 lsos
->lsos_current_txg
= txg
;
7632 ASSERT3U(lsos
->lsos_current_txg
, ==, txg
);
7634 lsos
->lsos_sm_entries
++;
7635 lsos
->lsos_total_entries
++;
7637 vdev_t
*vd
= vdev_lookup_top(spa
, vdev_id
);
7638 if (!vdev_is_concrete(vd
))
7641 metaslab_t
*ms
= vd
->vdev_ms
[offset
>> vd
->vdev_ms_shift
];
7642 ASSERT(sme
->sme_type
== SM_ALLOC
|| sme
->sme_type
== SM_FREE
);
7644 if (txg
< metaslab_unflushed_txg(ms
))
7646 lsos
->lsos_valid_sm_entries
++;
7647 lsos
->lsos_valid_entries
++;
7652 dump_log_spacemap_obsolete_stats(spa_t
*spa
)
7654 if (!spa_feature_is_active(spa
, SPA_FEATURE_LOG_SPACEMAP
))
7657 log_sm_obsolete_stats_arg_t lsos
;
7658 bzero(&lsos
, sizeof (lsos
));
7660 (void) printf("Log Space Map Obsolete Entry Statistics:\n");
7662 iterate_through_spacemap_logs(spa
,
7663 log_spacemap_obsolete_stats_cb
, &lsos
);
7665 /* print stats for latest log */
7666 (void) printf("%-8llu valid entries out of %-8llu - txg %llu\n",
7667 (u_longlong_t
)lsos
.lsos_valid_sm_entries
,
7668 (u_longlong_t
)lsos
.lsos_sm_entries
,
7669 (u_longlong_t
)lsos
.lsos_current_txg
);
7671 (void) printf("%-8llu valid entries out of %-8llu - total\n\n",
7672 (u_longlong_t
)lsos
.lsos_valid_entries
,
7673 (u_longlong_t
)lsos
.lsos_total_entries
);
7677 dump_zpool(spa_t
*spa
)
7679 dsl_pool_t
*dp
= spa_get_dsl(spa
);
7682 if (dump_opt
['y']) {
7683 livelist_metaslab_validate(spa
);
7686 if (dump_opt
['S']) {
7687 dump_simulated_ddt(spa
);
7691 if (!dump_opt
['e'] && dump_opt
['C'] > 1) {
7692 (void) printf("\nCached configuration:\n");
7693 dump_nvlist(spa
->spa_config
, 8);
7700 dump_uberblock(&spa
->spa_uberblock
, "\nUberblock:\n", "\n");
7705 if (dump_opt
['d'] > 2 || dump_opt
['m'])
7706 dump_metaslabs(spa
);
7708 dump_metaslab_groups(spa
, dump_opt
['M'] > 1);
7709 if (dump_opt
['d'] > 2 || dump_opt
['m']) {
7710 dump_log_spacemaps(spa
);
7711 dump_log_spacemap_obsolete_stats(spa
);
7714 if (dump_opt
['d'] || dump_opt
['i']) {
7716 mos_refd_objs
= range_tree_create(NULL
, RANGE_SEG64
, NULL
, 0,
7718 dump_objset(dp
->dp_meta_objset
);
7720 if (dump_opt
['d'] >= 3) {
7721 dsl_pool_t
*dp
= spa
->spa_dsl_pool
;
7722 dump_full_bpobj(&spa
->spa_deferred_bpobj
,
7723 "Deferred frees", 0);
7724 if (spa_version(spa
) >= SPA_VERSION_DEADLISTS
) {
7725 dump_full_bpobj(&dp
->dp_free_bpobj
,
7726 "Pool snapshot frees", 0);
7728 if (bpobj_is_open(&dp
->dp_obsolete_bpobj
)) {
7729 ASSERT(spa_feature_is_enabled(spa
,
7730 SPA_FEATURE_DEVICE_REMOVAL
));
7731 dump_full_bpobj(&dp
->dp_obsolete_bpobj
,
7732 "Pool obsolete blocks", 0);
7735 if (spa_feature_is_active(spa
,
7736 SPA_FEATURE_ASYNC_DESTROY
)) {
7737 dump_bptree(spa
->spa_meta_objset
,
7739 "Pool dataset frees");
7741 dump_dtl(spa
->spa_root_vdev
, 0);
7744 for (spa_feature_t f
= 0; f
< SPA_FEATURES
; f
++)
7745 global_feature_count
[f
] = UINT64_MAX
;
7746 global_feature_count
[SPA_FEATURE_REDACTION_BOOKMARKS
] = 0;
7747 global_feature_count
[SPA_FEATURE_BOOKMARK_WRITTEN
] = 0;
7748 global_feature_count
[SPA_FEATURE_LIVELIST
] = 0;
7750 (void) dmu_objset_find(spa_name(spa
), dump_one_objset
,
7751 NULL
, DS_FIND_SNAPSHOTS
| DS_FIND_CHILDREN
);
7753 if (rc
== 0 && !dump_opt
['L'])
7754 rc
= dump_mos_leaks(spa
);
7756 for (f
= 0; f
< SPA_FEATURES
; f
++) {
7760 if (!(spa_feature_table
[f
].fi_flags
&
7761 ZFEATURE_FLAG_PER_DATASET
)) {
7762 if (global_feature_count
[f
] == UINT64_MAX
)
7764 if (!spa_feature_is_enabled(spa
, f
)) {
7765 ASSERT0(global_feature_count
[f
]);
7768 arr
= global_feature_count
;
7770 if (!spa_feature_is_enabled(spa
, f
)) {
7771 ASSERT0(dataset_feature_count
[f
]);
7774 arr
= dataset_feature_count
;
7776 if (feature_get_refcount(spa
, &spa_feature_table
[f
],
7777 &refcount
) == ENOTSUP
)
7779 if (arr
[f
] != refcount
) {
7780 (void) printf("%s feature refcount mismatch: "
7781 "%lld consumers != %lld refcount\n",
7782 spa_feature_table
[f
].fi_uname
,
7783 (longlong_t
)arr
[f
], (longlong_t
)refcount
);
7786 (void) printf("Verified %s feature refcount "
7787 "of %llu is correct\n",
7788 spa_feature_table
[f
].fi_uname
,
7789 (longlong_t
)refcount
);
7794 rc
= verify_device_removal_feature_counts(spa
);
7797 if (rc
== 0 && (dump_opt
['b'] || dump_opt
['c']))
7798 rc
= dump_block_stats(spa
);
7801 rc
= verify_spacemap_refcounts(spa
);
7804 show_pool_stats(spa
);
7810 rc
= verify_checkpoint(spa
);
7813 dump_debug_buffer();
7818 #define ZDB_FLAG_CHECKSUM 0x0001
7819 #define ZDB_FLAG_DECOMPRESS 0x0002
7820 #define ZDB_FLAG_BSWAP 0x0004
7821 #define ZDB_FLAG_GBH 0x0008
7822 #define ZDB_FLAG_INDIRECT 0x0010
7823 #define ZDB_FLAG_RAW 0x0020
7824 #define ZDB_FLAG_PRINT_BLKPTR 0x0040
7825 #define ZDB_FLAG_VERBOSE 0x0080
7827 static int flagbits
[256];
7828 static char flagbitstr
[16];
7831 zdb_print_blkptr(const blkptr_t
*bp
, int flags
)
7833 char blkbuf
[BP_SPRINTF_LEN
];
7835 if (flags
& ZDB_FLAG_BSWAP
)
7836 byteswap_uint64_array((void *)bp
, sizeof (blkptr_t
));
7838 snprintf_blkptr(blkbuf
, sizeof (blkbuf
), bp
);
7839 (void) printf("%s\n", blkbuf
);
7843 zdb_dump_indirect(blkptr_t
*bp
, int nbps
, int flags
)
7847 for (i
= 0; i
< nbps
; i
++)
7848 zdb_print_blkptr(&bp
[i
], flags
);
7852 zdb_dump_gbh(void *buf
, int flags
)
7854 zdb_dump_indirect((blkptr_t
*)buf
, SPA_GBH_NBLKPTRS
, flags
);
7858 zdb_dump_block_raw(void *buf
, uint64_t size
, int flags
)
7860 if (flags
& ZDB_FLAG_BSWAP
)
7861 byteswap_uint64_array(buf
, size
);
7862 VERIFY(write(fileno(stdout
), buf
, size
) == size
);
7866 zdb_dump_block(char *label
, void *buf
, uint64_t size
, int flags
)
7868 uint64_t *d
= (uint64_t *)buf
;
7869 unsigned nwords
= size
/ sizeof (uint64_t);
7870 int do_bswap
= !!(flags
& ZDB_FLAG_BSWAP
);
7877 hdr
= " 7 6 5 4 3 2 1 0 f e d c b a 9 8";
7879 hdr
= " 0 1 2 3 4 5 6 7 8 9 a b c d e f";
7881 (void) printf("\n%s\n%6s %s 0123456789abcdef\n", label
, "", hdr
);
7883 #ifdef _LITTLE_ENDIAN
7884 /* correct the endianness */
7885 do_bswap
= !do_bswap
;
7887 for (i
= 0; i
< nwords
; i
+= 2) {
7888 (void) printf("%06llx: %016llx %016llx ",
7889 (u_longlong_t
)(i
* sizeof (uint64_t)),
7890 (u_longlong_t
)(do_bswap
? BSWAP_64(d
[i
]) : d
[i
]),
7891 (u_longlong_t
)(do_bswap
? BSWAP_64(d
[i
+ 1]) : d
[i
+ 1]));
7894 for (j
= 0; j
< 2 * sizeof (uint64_t); j
++)
7895 (void) printf("%c", isprint(c
[j
]) ? c
[j
] : '.');
7896 (void) printf("\n");
7901 * There are two acceptable formats:
7902 * leaf_name - For example: c1t0d0 or /tmp/ztest.0a
7903 * child[.child]* - For example: 0.1.1
7905 * The second form can be used to specify arbitrary vdevs anywhere
7906 * in the hierarchy. For example, in a pool with a mirror of
7907 * RAID-Zs, you can specify either RAID-Z vdev with 0.0 or 0.1 .
7910 zdb_vdev_lookup(vdev_t
*vdev
, const char *path
)
7918 /* First, assume the x.x.x.x format */
7919 i
= strtoul(path
, &s
, 10);
7920 if (s
== path
|| (s
&& *s
!= '.' && *s
!= '\0'))
7922 if (i
>= vdev
->vdev_children
)
7925 vdev
= vdev
->vdev_child
[i
];
7926 if (s
&& *s
== '\0')
7928 return (zdb_vdev_lookup(vdev
, s
+1));
7931 for (i
= 0; i
< vdev
->vdev_children
; i
++) {
7932 vdev_t
*vc
= vdev
->vdev_child
[i
];
7934 if (vc
->vdev_path
== NULL
) {
7935 vc
= zdb_vdev_lookup(vc
, path
);
7942 p
= strrchr(vc
->vdev_path
, '/');
7943 p
= p
? p
+ 1 : vc
->vdev_path
;
7944 q
= &vc
->vdev_path
[strlen(vc
->vdev_path
) - 2];
7946 if (strcmp(vc
->vdev_path
, path
) == 0)
7948 if (strcmp(p
, path
) == 0)
7950 if (strcmp(q
, "s0") == 0 && strncmp(p
, path
, q
- p
) == 0)
7958 name_from_objset_id(spa_t
*spa
, uint64_t objset_id
, char *outstr
)
7962 dsl_pool_config_enter(spa
->spa_dsl_pool
, FTAG
);
7963 int error
= dsl_dataset_hold_obj(spa
->spa_dsl_pool
, objset_id
,
7966 (void) fprintf(stderr
, "failed to hold objset %llu: %s\n",
7967 (u_longlong_t
)objset_id
, strerror(error
));
7968 dsl_pool_config_exit(spa
->spa_dsl_pool
, FTAG
);
7971 dsl_dataset_name(ds
, outstr
);
7972 dsl_dataset_rele(ds
, NULL
);
7973 dsl_pool_config_exit(spa
->spa_dsl_pool
, FTAG
);
7978 zdb_parse_block_sizes(char *sizes
, uint64_t *lsize
, uint64_t *psize
)
7980 char *s0
, *s1
, *tmp
= NULL
;
7985 s0
= strtok_r(sizes
, "/", &tmp
);
7988 s1
= strtok_r(NULL
, "/", &tmp
);
7989 *lsize
= strtoull(s0
, NULL
, 16);
7990 *psize
= s1
? strtoull(s1
, NULL
, 16) : *lsize
;
7991 return (*lsize
>= *psize
&& *psize
> 0);
7994 #define ZIO_COMPRESS_MASK(alg) (1ULL << (ZIO_COMPRESS_##alg))
7997 zdb_decompress_block(abd_t
*pabd
, void *buf
, void *lbuf
, uint64_t lsize
,
7998 uint64_t psize
, int flags
)
8001 boolean_t exceeded
= B_FALSE
;
8003 * We don't know how the data was compressed, so just try
8004 * every decompress function at every inflated blocksize.
8006 void *lbuf2
= umem_alloc(SPA_MAXBLOCKSIZE
, UMEM_NOFAIL
);
8007 int cfuncs
[ZIO_COMPRESS_FUNCTIONS
] = { 0 };
8008 int *cfuncp
= cfuncs
;
8009 uint64_t maxlsize
= SPA_MAXBLOCKSIZE
;
8010 uint64_t mask
= ZIO_COMPRESS_MASK(ON
) | ZIO_COMPRESS_MASK(OFF
) |
8011 ZIO_COMPRESS_MASK(INHERIT
) | ZIO_COMPRESS_MASK(EMPTY
) |
8012 (getenv("ZDB_NO_ZLE") ? ZIO_COMPRESS_MASK(ZLE
) : 0);
8013 *cfuncp
++ = ZIO_COMPRESS_LZ4
;
8014 *cfuncp
++ = ZIO_COMPRESS_LZJB
;
8015 mask
|= ZIO_COMPRESS_MASK(LZ4
) | ZIO_COMPRESS_MASK(LZJB
);
8016 for (int c
= 0; c
< ZIO_COMPRESS_FUNCTIONS
; c
++)
8017 if (((1ULL << c
) & mask
) == 0)
8021 * On the one hand, with SPA_MAXBLOCKSIZE at 16MB, this
8022 * could take a while and we should let the user know
8023 * we are not stuck. On the other hand, printing progress
8024 * info gets old after a while. User can specify 'v' flag
8025 * to see the progression.
8028 lsize
+= SPA_MINBLOCKSIZE
;
8031 for (; lsize
<= maxlsize
; lsize
+= SPA_MINBLOCKSIZE
) {
8032 for (cfuncp
= cfuncs
; *cfuncp
; cfuncp
++) {
8033 if (flags
& ZDB_FLAG_VERBOSE
) {
8034 (void) fprintf(stderr
,
8035 "Trying %05llx -> %05llx (%s)\n",
8036 (u_longlong_t
)psize
,
8037 (u_longlong_t
)lsize
,
8038 zio_compress_table
[*cfuncp
].\
8043 * We randomize lbuf2, and decompress to both
8044 * lbuf and lbuf2. This way, we will know if
8045 * decompression fill exactly to lsize.
8047 VERIFY0(random_get_pseudo_bytes(lbuf2
, lsize
));
8049 if (zio_decompress_data(*cfuncp
, pabd
,
8050 lbuf
, psize
, lsize
, NULL
) == 0 &&
8051 zio_decompress_data(*cfuncp
, pabd
,
8052 lbuf2
, psize
, lsize
, NULL
) == 0 &&
8053 bcmp(lbuf
, lbuf2
, lsize
) == 0)
8059 umem_free(lbuf2
, SPA_MAXBLOCKSIZE
);
8061 if (lsize
> maxlsize
) {
8064 if (*cfuncp
== ZIO_COMPRESS_ZLE
) {
8065 printf("\nZLE decompression was selected. If you "
8066 "suspect the results are wrong,\ntry avoiding ZLE "
8067 "by setting and exporting ZDB_NO_ZLE=\"true\"\n");
8074 * Read a block from a pool and print it out. The syntax of the
8075 * block descriptor is:
8077 * pool:vdev_specifier:offset:[lsize/]psize[:flags]
8079 * pool - The name of the pool you wish to read from
8080 * vdev_specifier - Which vdev (see comment for zdb_vdev_lookup)
8081 * offset - offset, in hex, in bytes
8082 * size - Amount of data to read, in hex, in bytes
8083 * flags - A string of characters specifying options
8084 * b: Decode a blkptr at given offset within block
8085 * c: Calculate and display checksums
8086 * d: Decompress data before dumping
8087 * e: Byteswap data before dumping
8088 * g: Display data as a gang block header
8089 * i: Display as an indirect block
8090 * r: Dump raw data to stdout
8095 zdb_read_block(char *thing
, spa_t
*spa
)
8097 blkptr_t blk
, *bp
= &blk
;
8098 dva_t
*dva
= bp
->blk_dva
;
8100 uint64_t offset
= 0, psize
= 0, lsize
= 0, blkptr_offset
= 0;
8105 char *s
, *p
, *dup
, *vdev
, *flagstr
, *sizes
, *tmp
= NULL
;
8107 boolean_t borrowed
= B_FALSE
, found
= B_FALSE
;
8109 dup
= strdup(thing
);
8110 s
= strtok_r(dup
, ":", &tmp
);
8112 s
= strtok_r(NULL
, ":", &tmp
);
8113 offset
= strtoull(s
? s
: "", NULL
, 16);
8114 sizes
= strtok_r(NULL
, ":", &tmp
);
8115 s
= strtok_r(NULL
, ":", &tmp
);
8116 flagstr
= strdup(s
? s
: "");
8120 if (!zdb_parse_block_sizes(sizes
, &lsize
, &psize
))
8121 s
= "invalid size(s)";
8122 if (!IS_P2ALIGNED(psize
, DEV_BSIZE
) || !IS_P2ALIGNED(lsize
, DEV_BSIZE
))
8123 s
= "size must be a multiple of sector size";
8124 if (!IS_P2ALIGNED(offset
, DEV_BSIZE
))
8125 s
= "offset must be a multiple of sector size";
8127 (void) printf("Invalid block specifier: %s - %s\n", thing
, s
);
8131 for (s
= strtok_r(flagstr
, ":", &tmp
);
8133 s
= strtok_r(NULL
, ":", &tmp
)) {
8134 for (i
= 0; i
< strlen(flagstr
); i
++) {
8135 int bit
= flagbits
[(uchar_t
)flagstr
[i
]];
8138 (void) printf("***Ignoring flag: %c\n",
8139 (uchar_t
)flagstr
[i
]);
8145 p
= &flagstr
[i
+ 1];
8146 if (*p
!= ':' && *p
!= '\0') {
8147 int j
= 0, nextbit
= flagbits
[(uchar_t
)*p
];
8148 char *end
, offstr
[8] = { 0 };
8149 if ((bit
== ZDB_FLAG_PRINT_BLKPTR
) &&
8151 /* look ahead to isolate the offset */
8152 while (nextbit
== 0 &&
8153 strchr(flagbitstr
, *p
) == NULL
) {
8156 if (i
+ j
> strlen(flagstr
))
8159 nextbit
= flagbits
[(uchar_t
)*p
];
8161 blkptr_offset
= strtoull(offstr
, &end
,
8164 } else if (nextbit
== 0) {
8165 (void) printf("***Ignoring flag arg:"
8166 " '%c'\n", (uchar_t
)*p
);
8171 if (blkptr_offset
% sizeof (blkptr_t
)) {
8172 printf("Block pointer offset 0x%llx "
8173 "must be divisible by 0x%x\n",
8174 (longlong_t
)blkptr_offset
, (int)sizeof (blkptr_t
));
8177 if (found
== B_FALSE
&& strlen(flagstr
) > 0) {
8178 printf("Invalid flag arg: '%s'\n", flagstr
);
8182 vd
= zdb_vdev_lookup(spa
->spa_root_vdev
, vdev
);
8184 (void) printf("***Invalid vdev: %s\n", vdev
);
8189 (void) fprintf(stderr
, "Found vdev: %s\n",
8192 (void) fprintf(stderr
, "Found vdev type: %s\n",
8193 vd
->vdev_ops
->vdev_op_type
);
8196 pabd
= abd_alloc_for_io(SPA_MAXBLOCKSIZE
, B_FALSE
);
8197 lbuf
= umem_alloc(SPA_MAXBLOCKSIZE
, UMEM_NOFAIL
);
8201 DVA_SET_VDEV(&dva
[0], vd
->vdev_id
);
8202 DVA_SET_OFFSET(&dva
[0], offset
);
8203 DVA_SET_GANG(&dva
[0], !!(flags
& ZDB_FLAG_GBH
));
8204 DVA_SET_ASIZE(&dva
[0], vdev_psize_to_asize(vd
, psize
));
8206 BP_SET_BIRTH(bp
, TXG_INITIAL
, TXG_INITIAL
);
8208 BP_SET_LSIZE(bp
, lsize
);
8209 BP_SET_PSIZE(bp
, psize
);
8210 BP_SET_COMPRESS(bp
, ZIO_COMPRESS_OFF
);
8211 BP_SET_CHECKSUM(bp
, ZIO_CHECKSUM_OFF
);
8212 BP_SET_TYPE(bp
, DMU_OT_NONE
);
8213 BP_SET_LEVEL(bp
, 0);
8214 BP_SET_DEDUP(bp
, 0);
8215 BP_SET_BYTEORDER(bp
, ZFS_HOST_BYTEORDER
);
8217 spa_config_enter(spa
, SCL_STATE
, FTAG
, RW_READER
);
8218 zio
= zio_root(spa
, NULL
, NULL
, 0);
8220 if (vd
== vd
->vdev_top
) {
8222 * Treat this as a normal block read.
8224 zio_nowait(zio_read(zio
, spa
, bp
, pabd
, psize
, NULL
, NULL
,
8225 ZIO_PRIORITY_SYNC_READ
,
8226 ZIO_FLAG_CANFAIL
| ZIO_FLAG_RAW
, NULL
));
8229 * Treat this as a vdev child I/O.
8231 zio_nowait(zio_vdev_child_io(zio
, bp
, vd
, offset
, pabd
,
8232 psize
, ZIO_TYPE_READ
, ZIO_PRIORITY_SYNC_READ
,
8233 ZIO_FLAG_DONT_CACHE
| ZIO_FLAG_DONT_PROPAGATE
|
8234 ZIO_FLAG_DONT_RETRY
| ZIO_FLAG_CANFAIL
| ZIO_FLAG_RAW
|
8235 ZIO_FLAG_OPTIONAL
, NULL
, NULL
));
8238 error
= zio_wait(zio
);
8239 spa_config_exit(spa
, SCL_STATE
, FTAG
);
8242 (void) printf("Read of %s failed, error: %d\n", thing
, error
);
8246 uint64_t orig_lsize
= lsize
;
8248 if (flags
& ZDB_FLAG_DECOMPRESS
) {
8249 boolean_t failed
= zdb_decompress_block(pabd
, buf
, lbuf
,
8250 lsize
, psize
, flags
);
8252 (void) printf("Decompress of %s failed\n", thing
);
8256 buf
= abd_borrow_buf_copy(pabd
, lsize
);
8260 * Try to detect invalid block pointer. If invalid, try
8263 if ((flags
& ZDB_FLAG_PRINT_BLKPTR
|| flags
& ZDB_FLAG_INDIRECT
) &&
8264 !(flags
& ZDB_FLAG_DECOMPRESS
)) {
8265 const blkptr_t
*b
= (const blkptr_t
*)(void *)
8266 ((uintptr_t)buf
+ (uintptr_t)blkptr_offset
);
8267 if (zfs_blkptr_verify(spa
, b
, B_FALSE
, BLK_VERIFY_ONLY
) ==
8269 abd_return_buf_copy(pabd
, buf
, lsize
);
8272 boolean_t failed
= zdb_decompress_block(pabd
, buf
,
8273 lbuf
, lsize
, psize
, flags
);
8274 b
= (const blkptr_t
*)(void *)
8275 ((uintptr_t)buf
+ (uintptr_t)blkptr_offset
);
8276 if (failed
|| zfs_blkptr_verify(spa
, b
, B_FALSE
,
8277 BLK_VERIFY_LOG
) == B_FALSE
) {
8278 printf("invalid block pointer at this DVA\n");
8284 if (flags
& ZDB_FLAG_PRINT_BLKPTR
)
8285 zdb_print_blkptr((blkptr_t
*)(void *)
8286 ((uintptr_t)buf
+ (uintptr_t)blkptr_offset
), flags
);
8287 else if (flags
& ZDB_FLAG_RAW
)
8288 zdb_dump_block_raw(buf
, lsize
, flags
);
8289 else if (flags
& ZDB_FLAG_INDIRECT
)
8290 zdb_dump_indirect((blkptr_t
*)buf
,
8291 orig_lsize
/ sizeof (blkptr_t
), flags
);
8292 else if (flags
& ZDB_FLAG_GBH
)
8293 zdb_dump_gbh(buf
, flags
);
8295 zdb_dump_block(thing
, buf
, lsize
, flags
);
8298 * If :c was specified, iterate through the checksum table to
8299 * calculate and display each checksum for our specified
8302 if ((flags
& ZDB_FLAG_CHECKSUM
) && !(flags
& ZDB_FLAG_RAW
) &&
8303 !(flags
& ZDB_FLAG_GBH
)) {
8305 (void) printf("\n");
8306 for (enum zio_checksum ck
= ZIO_CHECKSUM_LABEL
;
8307 ck
< ZIO_CHECKSUM_FUNCTIONS
; ck
++) {
8309 if ((zio_checksum_table
[ck
].ci_flags
&
8310 ZCHECKSUM_FLAG_EMBEDDED
) ||
8311 ck
== ZIO_CHECKSUM_NOPARITY
) {
8314 BP_SET_CHECKSUM(bp
, ck
);
8315 spa_config_enter(spa
, SCL_STATE
, FTAG
, RW_READER
);
8316 czio
= zio_root(spa
, NULL
, NULL
, ZIO_FLAG_CANFAIL
);
8319 if (vd
== vd
->vdev_top
) {
8320 zio_nowait(zio_read(czio
, spa
, bp
, pabd
, psize
,
8322 ZIO_PRIORITY_SYNC_READ
,
8323 ZIO_FLAG_CANFAIL
| ZIO_FLAG_RAW
|
8324 ZIO_FLAG_DONT_RETRY
, NULL
));
8326 zio_nowait(zio_vdev_child_io(czio
, bp
, vd
,
8327 offset
, pabd
, psize
, ZIO_TYPE_READ
,
8328 ZIO_PRIORITY_SYNC_READ
,
8329 ZIO_FLAG_DONT_CACHE
|
8330 ZIO_FLAG_DONT_PROPAGATE
|
8331 ZIO_FLAG_DONT_RETRY
|
8332 ZIO_FLAG_CANFAIL
| ZIO_FLAG_RAW
|
8333 ZIO_FLAG_SPECULATIVE
|
8334 ZIO_FLAG_OPTIONAL
, NULL
, NULL
));
8336 error
= zio_wait(czio
);
8337 if (error
== 0 || error
== ECKSUM
) {
8338 zio_t
*ck_zio
= zio_root(spa
, NULL
, NULL
, 0);
8340 DVA_GET_OFFSET(&bp
->blk_dva
[0]);
8342 zio_checksum_compute(ck_zio
, ck
, pabd
, lsize
);
8343 printf("%12s\tcksum=%llx:%llx:%llx:%llx\n",
8344 zio_checksum_table
[ck
].ci_name
,
8345 (u_longlong_t
)bp
->blk_cksum
.zc_word
[0],
8346 (u_longlong_t
)bp
->blk_cksum
.zc_word
[1],
8347 (u_longlong_t
)bp
->blk_cksum
.zc_word
[2],
8348 (u_longlong_t
)bp
->blk_cksum
.zc_word
[3]);
8351 printf("error %d reading block\n", error
);
8353 spa_config_exit(spa
, SCL_STATE
, FTAG
);
8358 abd_return_buf_copy(pabd
, buf
, lsize
);
8362 umem_free(lbuf
, SPA_MAXBLOCKSIZE
);
8369 zdb_embedded_block(char *thing
)
8372 unsigned long long *words
= (void *)&bp
;
8376 bzero(&bp
, sizeof (bp
));
8377 err
= sscanf(thing
, "%llx:%llx:%llx:%llx:%llx:%llx:%llx:%llx:"
8378 "%llx:%llx:%llx:%llx:%llx:%llx:%llx:%llx",
8379 words
+ 0, words
+ 1, words
+ 2, words
+ 3,
8380 words
+ 4, words
+ 5, words
+ 6, words
+ 7,
8381 words
+ 8, words
+ 9, words
+ 10, words
+ 11,
8382 words
+ 12, words
+ 13, words
+ 14, words
+ 15);
8384 (void) fprintf(stderr
, "invalid input format\n");
8387 ASSERT3U(BPE_GET_LSIZE(&bp
), <=, SPA_MAXBLOCKSIZE
);
8388 buf
= malloc(SPA_MAXBLOCKSIZE
);
8390 (void) fprintf(stderr
, "out of memory\n");
8393 err
= decode_embedded_bp(&bp
, buf
, BPE_GET_LSIZE(&bp
));
8395 (void) fprintf(stderr
, "decode failed: %u\n", err
);
8398 zdb_dump_block_raw(buf
, BPE_GET_LSIZE(&bp
), 0);
8402 /* check for valid hex or decimal numeric string */
8404 zdb_numeric(char *str
)
8408 if (strlen(str
) == 0)
8410 if (strncmp(str
, "0x", 2) == 0 || strncmp(str
, "0X", 2) == 0)
8412 for (; i
< strlen(str
); i
++) {
8413 if (!isxdigit(str
[i
]))
8420 main(int argc
, char **argv
)
8423 struct rlimit rl
= { 1024, 1024 };
8425 objset_t
*os
= NULL
;
8429 char **searchdirs
= NULL
;
8431 char *target
, *target_pool
, dsname
[ZFS_MAX_DATASET_NAME_LEN
];
8432 nvlist_t
*policy
= NULL
;
8433 uint64_t max_txg
= UINT64_MAX
;
8434 int64_t objset_id
= -1;
8436 int flags
= ZFS_IMPORT_MISSING_LOG
;
8437 int rewind
= ZPOOL_NEVER_REWIND
;
8438 char *spa_config_path_env
, *objset_str
;
8439 boolean_t target_is_spa
= B_TRUE
, dataset_lookup
= B_FALSE
;
8440 nvlist_t
*cfg
= NULL
;
8442 (void) setrlimit(RLIMIT_NOFILE
, &rl
);
8443 (void) enable_extended_FILE_stdio(-1, -1);
8445 dprintf_setup(&argc
, argv
);
8448 * If there is an environment variable SPA_CONFIG_PATH it overrides
8449 * default spa_config_path setting. If -U flag is specified it will
8450 * override this environment variable settings once again.
8452 spa_config_path_env
= getenv("SPA_CONFIG_PATH");
8453 if (spa_config_path_env
!= NULL
)
8454 spa_config_path
= spa_config_path_env
;
8457 * For performance reasons, we set this tunable down. We do so before
8458 * the arg parsing section so that the user can override this value if
8461 zfs_btree_verify_intensity
= 3;
8463 struct option long_options
[] = {
8464 {"ignore-assertions", no_argument
, NULL
, 'A'},
8465 {"block-stats", no_argument
, NULL
, 'b'},
8466 {"checksum", no_argument
, NULL
, 'c'},
8467 {"config", no_argument
, NULL
, 'C'},
8468 {"datasets", no_argument
, NULL
, 'd'},
8469 {"dedup-stats", no_argument
, NULL
, 'D'},
8470 {"exported", no_argument
, NULL
, 'e'},
8471 {"embedded-block-pointer", no_argument
, NULL
, 'E'},
8472 {"automatic-rewind", no_argument
, NULL
, 'F'},
8473 {"dump-debug-msg", no_argument
, NULL
, 'G'},
8474 {"history", no_argument
, NULL
, 'h'},
8475 {"intent-logs", no_argument
, NULL
, 'i'},
8476 {"inflight", required_argument
, NULL
, 'I'},
8477 {"checkpointed-state", no_argument
, NULL
, 'k'},
8478 {"label", no_argument
, NULL
, 'l'},
8479 {"disable-leak-tracking", no_argument
, NULL
, 'L'},
8480 {"metaslabs", no_argument
, NULL
, 'm'},
8481 {"metaslab-groups", no_argument
, NULL
, 'M'},
8482 {"numeric", no_argument
, NULL
, 'N'},
8483 {"option", required_argument
, NULL
, 'o'},
8484 {"object-lookups", no_argument
, NULL
, 'O'},
8485 {"path", required_argument
, NULL
, 'p'},
8486 {"parseable", no_argument
, NULL
, 'P'},
8487 {"skip-label", no_argument
, NULL
, 'q'},
8488 {"copy-object", no_argument
, NULL
, 'r'},
8489 {"read-block", no_argument
, NULL
, 'R'},
8490 {"io-stats", no_argument
, NULL
, 's'},
8491 {"simulate-dedup", no_argument
, NULL
, 'S'},
8492 {"txg", required_argument
, NULL
, 't'},
8493 {"uberblock", no_argument
, NULL
, 'u'},
8494 {"cachefile", required_argument
, NULL
, 'U'},
8495 {"verbose", no_argument
, NULL
, 'v'},
8496 {"verbatim", no_argument
, NULL
, 'V'},
8497 {"dump-blocks", required_argument
, NULL
, 'x'},
8498 {"extreme-rewind", no_argument
, NULL
, 'X'},
8499 {"all-reconstruction", no_argument
, NULL
, 'Y'},
8500 {"livelist", no_argument
, NULL
, 'y'},
8501 {"zstd-headers", no_argument
, NULL
, 'Z'},
8505 while ((c
= getopt_long(argc
, argv
,
8506 "AbcCdDeEFGhiI:klLmMNo:Op:PqrRsSt:uU:vVx:XYyZ",
8507 long_options
, NULL
)) != -1) {
8544 zfs_reconstruct_indirect_combinations_max
= INT_MAX
;
8545 zfs_deadman_enabled
= 0;
8547 /* NB: Sort single match options below. */
8549 max_inflight_bytes
= strtoull(optarg
, NULL
, 0);
8550 if (max_inflight_bytes
== 0) {
8551 (void) fprintf(stderr
, "maximum number "
8552 "of inflight bytes must be greater "
8558 error
= set_global_var(optarg
);
8563 if (searchdirs
== NULL
) {
8564 searchdirs
= umem_alloc(sizeof (char *),
8567 char **tmp
= umem_alloc((nsearch
+ 1) *
8568 sizeof (char *), UMEM_NOFAIL
);
8569 bcopy(searchdirs
, tmp
, nsearch
*
8571 umem_free(searchdirs
,
8572 nsearch
* sizeof (char *));
8575 searchdirs
[nsearch
++] = optarg
;
8578 max_txg
= strtoull(optarg
, NULL
, 0);
8579 if (max_txg
< TXG_INITIAL
) {
8580 (void) fprintf(stderr
, "incorrect txg "
8581 "specified: %s\n", optarg
);
8586 spa_config_path
= optarg
;
8587 if (spa_config_path
[0] != '/') {
8588 (void) fprintf(stderr
,
8589 "cachefile must be an absolute path "
8590 "(i.e. start with a slash)\n");
8598 flags
= ZFS_IMPORT_VERBATIM
;
8601 vn_dumpdir
= optarg
;
8609 if (!dump_opt
['e'] && searchdirs
!= NULL
) {
8610 (void) fprintf(stderr
, "-p option requires use of -e\n");
8615 * ZDB does not typically re-read blocks; therefore limit the ARC
8616 * to 256 MB, which can be used entirely for metadata.
8618 zfs_arc_min
= zfs_arc_meta_min
= 2ULL << SPA_MAXBLOCKSHIFT
;
8619 zfs_arc_max
= zfs_arc_meta_limit
= 256 * 1024 * 1024;
8623 * "zdb -c" uses checksum-verifying scrub i/os which are async reads.
8624 * "zdb -b" uses traversal prefetch which uses async reads.
8625 * For good performance, let several of them be active at once.
8627 zfs_vdev_async_read_max_active
= 10;
8630 * Disable reference tracking for better performance.
8632 reference_tracking_enable
= B_FALSE
;
8635 * Do not fail spa_load when spa_load_verify fails. This is needed
8636 * to load non-idle pools.
8638 spa_load_verify_dryrun
= B_TRUE
;
8641 * ZDB should have ability to read spacemaps.
8643 spa_mode_readable_spacemaps
= B_TRUE
;
8645 kernel_init(SPA_MODE_READ
);
8648 verbose
= MAX(verbose
, 1);
8650 for (c
= 0; c
< 256; c
++) {
8651 if (dump_all
&& strchr("AeEFklLNOPrRSXy", c
) == NULL
)
8654 dump_opt
[c
] += verbose
;
8657 libspl_set_assert_ok((dump_opt
['A'] == 1) || (dump_opt
['A'] > 2));
8658 zfs_recover
= (dump_opt
['A'] > 1);
8662 if (argc
< 2 && dump_opt
['R'])
8665 if (dump_opt
['E']) {
8668 zdb_embedded_block(argv
[0]);
8673 if (!dump_opt
['e'] && dump_opt
['C']) {
8674 dump_cachefile(spa_config_path
);
8681 return (dump_label(argv
[0]));
8683 if (dump_opt
['O']) {
8686 dump_opt
['v'] = verbose
+ 3;
8687 return (dump_path(argv
[0], argv
[1], NULL
));
8689 if (dump_opt
['r']) {
8690 target_is_spa
= B_FALSE
;
8693 dump_opt
['v'] = verbose
;
8694 error
= dump_path(argv
[0], argv
[1], &object
);
8697 if (dump_opt
['X'] || dump_opt
['F'])
8698 rewind
= ZPOOL_DO_REWIND
|
8699 (dump_opt
['X'] ? ZPOOL_EXTREME_REWIND
: 0);
8702 if (dump_opt
['N'] && dump_opt
['d'] == 0)
8703 dump_opt
['d'] = dump_opt
['N'];
8705 if (nvlist_alloc(&policy
, NV_UNIQUE_NAME_TYPE
, 0) != 0 ||
8706 nvlist_add_uint64(policy
, ZPOOL_LOAD_REQUEST_TXG
, max_txg
) != 0 ||
8707 nvlist_add_uint32(policy
, ZPOOL_LOAD_REWIND_POLICY
, rewind
) != 0)
8708 fatal("internal error: %s", strerror(ENOMEM
));
8713 if (strpbrk(target
, "/@") != NULL
) {
8716 target_pool
= strdup(target
);
8717 *strpbrk(target_pool
, "/@") = '\0';
8719 target_is_spa
= B_FALSE
;
8720 targetlen
= strlen(target
);
8721 if (targetlen
&& target
[targetlen
- 1] == '/')
8722 target
[targetlen
- 1] = '\0';
8725 * See if an objset ID was supplied (-d <pool>/<objset ID>).
8726 * To disambiguate tank/100, consider the 100 as objsetID
8727 * if -N was given, otherwise 100 is an objsetID iff
8728 * tank/100 as a named dataset fails on lookup.
8730 objset_str
= strchr(target
, '/');
8731 if (objset_str
&& strlen(objset_str
) > 1 &&
8732 zdb_numeric(objset_str
+ 1)) {
8736 objset_id
= strtoull(objset_str
, &endptr
, 0);
8737 /* dataset 0 is the same as opening the pool */
8738 if (errno
== 0 && endptr
!= objset_str
&&
8741 dataset_lookup
= B_TRUE
;
8743 /* normal dataset name not an objset ID */
8744 if (endptr
== objset_str
) {
8747 } else if (objset_str
&& !zdb_numeric(objset_str
+ 1) &&
8749 printf("Supply a numeric objset ID with -N\n");
8753 target_pool
= target
;
8756 if (dump_opt
['e']) {
8757 importargs_t args
= { 0 };
8759 args
.paths
= nsearch
;
8760 args
.path
= searchdirs
;
8761 args
.can_be_active
= B_TRUE
;
8763 error
= zpool_find_config(NULL
, target_pool
, &cfg
, &args
,
8764 &libzpool_config_ops
);
8768 if (nvlist_add_nvlist(cfg
,
8769 ZPOOL_LOAD_POLICY
, policy
) != 0) {
8770 fatal("can't open '%s': %s",
8771 target
, strerror(ENOMEM
));
8774 if (dump_opt
['C'] > 1) {
8775 (void) printf("\nConfiguration for import:\n");
8776 dump_nvlist(cfg
, 8);
8780 * Disable the activity check to allow examination of
8783 error
= spa_import(target_pool
, cfg
, NULL
,
8784 flags
| ZFS_IMPORT_SKIP_MMP
);
8788 if (searchdirs
!= NULL
) {
8789 umem_free(searchdirs
, nsearch
* sizeof (char *));
8794 * import_checkpointed_state makes the assumption that the
8795 * target pool that we pass it is already part of the spa
8796 * namespace. Because of that we need to make sure to call
8797 * it always after the -e option has been processed, which
8798 * imports the pool to the namespace if it's not in the
8801 char *checkpoint_pool
= NULL
;
8802 char *checkpoint_target
= NULL
;
8803 if (dump_opt
['k']) {
8804 checkpoint_pool
= import_checkpointed_state(target
, cfg
,
8805 &checkpoint_target
);
8807 if (checkpoint_target
!= NULL
)
8808 target
= checkpoint_target
;
8816 if (target_pool
!= target
)
8820 if (dump_opt
['k'] && (target_is_spa
|| dump_opt
['R'])) {
8821 ASSERT(checkpoint_pool
!= NULL
);
8822 ASSERT(checkpoint_target
== NULL
);
8824 error
= spa_open(checkpoint_pool
, &spa
, FTAG
);
8826 fatal("Tried to open pool \"%s\" but "
8827 "spa_open() failed with error %d\n",
8828 checkpoint_pool
, error
);
8831 } else if (target_is_spa
|| dump_opt
['R'] || objset_id
== 0) {
8832 zdb_set_skip_mmp(target
);
8833 error
= spa_open_rewind(target
, &spa
, FTAG
, policy
,
8837 * If we're missing the log device then
8838 * try opening the pool after clearing the
8841 mutex_enter(&spa_namespace_lock
);
8842 if ((spa
= spa_lookup(target
)) != NULL
&&
8843 spa
->spa_log_state
== SPA_LOG_MISSING
) {
8844 spa
->spa_log_state
= SPA_LOG_CLEAR
;
8847 mutex_exit(&spa_namespace_lock
);
8850 error
= spa_open_rewind(target
, &spa
,
8851 FTAG
, policy
, NULL
);
8854 } else if (strpbrk(target
, "#") != NULL
) {
8856 error
= dsl_pool_hold(target
, FTAG
, &dp
);
8858 fatal("can't dump '%s': %s", target
,
8861 error
= dump_bookmark(dp
, target
, B_TRUE
, verbose
> 1);
8862 dsl_pool_rele(dp
, FTAG
);
8864 fatal("can't dump '%s': %s", target
,
8869 target_pool
= strdup(target
);
8870 if (strpbrk(target
, "/@") != NULL
)
8871 *strpbrk(target_pool
, "/@") = '\0';
8873 zdb_set_skip_mmp(target
);
8875 * If -N was supplied, the user has indicated that
8876 * zdb -d <pool>/<objsetID> is in effect. Otherwise
8877 * we first assume that the dataset string is the
8878 * dataset name. If dmu_objset_hold fails with the
8879 * dataset string, and we have an objset_id, retry the
8880 * lookup with the objsetID.
8882 boolean_t retry
= B_TRUE
;
8884 if (dataset_lookup
== B_TRUE
) {
8886 * Use the supplied id to get the name
8889 error
= spa_open(target_pool
, &spa
, FTAG
);
8891 error
= name_from_objset_id(spa
,
8893 spa_close(spa
, FTAG
);
8899 if (objset_id
> 0 && retry
) {
8900 int err
= dmu_objset_hold(target
, FTAG
,
8903 dataset_lookup
= B_TRUE
;
8907 dmu_objset_rele(os
, FTAG
);
8910 error
= open_objset(target
, FTAG
, &os
);
8913 spa
= dmu_objset_spa(os
);
8917 nvlist_free(policy
);
8920 fatal("can't open '%s': %s", target
, strerror(error
));
8923 * Set the pool failure mode to panic in order to prevent the pool
8924 * from suspending. A suspended I/O will have no way to resume and
8925 * can prevent the zdb(8) command from terminating as expected.
8928 spa
->spa_failmode
= ZIO_FAILURE_MODE_PANIC
;
8932 if (dump_opt
['r']) {
8933 error
= zdb_copy_object(os
, object
, argv
[1]);
8934 } else if (!dump_opt
['R']) {
8935 flagbits
['d'] = ZOR_FLAG_DIRECTORY
;
8936 flagbits
['f'] = ZOR_FLAG_PLAIN_FILE
;
8937 flagbits
['m'] = ZOR_FLAG_SPACE_MAP
;
8938 flagbits
['z'] = ZOR_FLAG_ZAP
;
8939 flagbits
['A'] = ZOR_FLAG_ALL_TYPES
;
8941 if (argc
> 0 && dump_opt
['d']) {
8942 zopt_object_args
= argc
;
8943 zopt_object_ranges
= calloc(zopt_object_args
,
8944 sizeof (zopt_object_range_t
));
8945 for (unsigned i
= 0; i
< zopt_object_args
; i
++) {
8949 err
= parse_object_range(argv
[i
],
8950 &zopt_object_ranges
[i
], &msg
);
8952 fatal("Bad object or range: '%s': %s\n",
8953 argv
[i
], msg
? msg
: "");
8955 } else if (argc
> 0 && dump_opt
['m']) {
8956 zopt_metaslab_args
= argc
;
8957 zopt_metaslab
= calloc(zopt_metaslab_args
,
8959 for (unsigned i
= 0; i
< zopt_metaslab_args
; i
++) {
8961 zopt_metaslab
[i
] = strtoull(argv
[i
], NULL
, 0);
8962 if (zopt_metaslab
[i
] == 0 && errno
!= 0)
8963 fatal("bad number %s: %s", argv
[i
],
8969 } else if (zopt_object_args
> 0 && !dump_opt
['m']) {
8970 dump_objset(spa
->spa_meta_objset
);
8975 flagbits
['b'] = ZDB_FLAG_PRINT_BLKPTR
;
8976 flagbits
['c'] = ZDB_FLAG_CHECKSUM
;
8977 flagbits
['d'] = ZDB_FLAG_DECOMPRESS
;
8978 flagbits
['e'] = ZDB_FLAG_BSWAP
;
8979 flagbits
['g'] = ZDB_FLAG_GBH
;
8980 flagbits
['i'] = ZDB_FLAG_INDIRECT
;
8981 flagbits
['r'] = ZDB_FLAG_RAW
;
8982 flagbits
['v'] = ZDB_FLAG_VERBOSE
;
8984 for (int i
= 0; i
< argc
; i
++)
8985 zdb_read_block(argv
[i
], spa
);
8988 if (dump_opt
['k']) {
8989 free(checkpoint_pool
);
8991 free(checkpoint_target
);
8995 close_objset(os
, FTAG
);
8997 spa_close(spa
, FTAG
);
9000 fuid_table_destroy();
9002 dump_debug_buffer();