xref: /illumos-gate/usr/src/cmd/zdb/zdb.c (revision 87219db7f64d5002b5a8311fd76f7900fda2c4e8)
1fa9e4066Sahrens /*
2fa9e4066Sahrens  * CDDL HEADER START
3fa9e4066Sahrens  *
4fa9e4066Sahrens  * The contents of this file are subject to the terms of the
5ea8dc4b6Seschrock  * Common Development and Distribution License (the "License").
6ea8dc4b6Seschrock  * You may not use this file except in compliance with the License.
7fa9e4066Sahrens  *
8fa9e4066Sahrens  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9fa9e4066Sahrens  * or http://www.opensolaris.org/os/licensing.
10fa9e4066Sahrens  * See the License for the specific language governing permissions
11fa9e4066Sahrens  * and limitations under the License.
12fa9e4066Sahrens  *
13fa9e4066Sahrens  * When distributing Covered Code, include this CDDL HEADER in each
14fa9e4066Sahrens  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15fa9e4066Sahrens  * If applicable, add the following below this CDDL HEADER, with the
16fa9e4066Sahrens  * fields enclosed by brackets "[]" replaced with your own identifying
17fa9e4066Sahrens  * information: Portions Copyright [yyyy] [name of copyright owner]
18fa9e4066Sahrens  *
19fa9e4066Sahrens  * CDDL HEADER END
20fa9e4066Sahrens  */
21fa9e4066Sahrens /*
22ccba0801SRich Morris  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
23fa9e4066Sahrens  * Use is subject to license terms.
24fa9e4066Sahrens  */
25fa9e4066Sahrens 
26fa9e4066Sahrens #include <stdio.h>
27004388ebScasper #include <stdio_ext.h>
28fa9e4066Sahrens #include <stdlib.h>
2944cd46caSbillm #include <ctype.h>
30fa9e4066Sahrens #include <sys/zfs_context.h>
31fa9e4066Sahrens #include <sys/spa.h>
32fa9e4066Sahrens #include <sys/spa_impl.h>
33fa9e4066Sahrens #include <sys/dmu.h>
34fa9e4066Sahrens #include <sys/zap.h>
35fa9e4066Sahrens #include <sys/fs/zfs.h>
36fa9e4066Sahrens #include <sys/zfs_znode.h>
37fa9e4066Sahrens #include <sys/vdev.h>
38fa9e4066Sahrens #include <sys/vdev_impl.h>
39fa9e4066Sahrens #include <sys/metaslab_impl.h>
40fa9e4066Sahrens #include <sys/dmu_objset.h>
41fa9e4066Sahrens #include <sys/dsl_dir.h>
42fa9e4066Sahrens #include <sys/dsl_dataset.h>
43fa9e4066Sahrens #include <sys/dsl_pool.h>
44fa9e4066Sahrens #include <sys/dbuf.h>
45fa9e4066Sahrens #include <sys/zil.h>
46fa9e4066Sahrens #include <sys/zil_impl.h>
47fa9e4066Sahrens #include <sys/stat.h>
48fa9e4066Sahrens #include <sys/resource.h>
49fa9e4066Sahrens #include <sys/dmu_traverse.h>
50fa9e4066Sahrens #include <sys/zio_checksum.h>
51fa9e4066Sahrens #include <sys/zio_compress.h>
52e0d35c44Smarks #include <sys/zfs_fuid.h>
5388b7b0f2SMatthew Ahrens #include <sys/arc.h>
54de6628f0Sck #undef ZFS_MAXNAMELEN
55de6628f0Sck #undef verify
56de6628f0Sck #include <libzfs.h>
57fa9e4066Sahrens 
586de8f417SVictor Latushkin #define	ZDB_COMPRESS_NAME(idx) ((idx) < ZIO_COMPRESS_FUNCTIONS ? \
596de8f417SVictor Latushkin     zio_compress_table[(idx)].ci_name : "UNKNOWN")
606de8f417SVictor Latushkin #define	ZDB_CHECKSUM_NAME(idx) ((idx) < ZIO_CHECKSUM_FUNCTIONS ? \
616de8f417SVictor Latushkin     zio_checksum_table[(idx)].ci_name : "UNKNOWN")
626de8f417SVictor Latushkin #define	ZDB_OT_NAME(idx) ((idx) < DMU_OT_NUMTYPES ? \
636de8f417SVictor Latushkin     dmu_ot[(idx)].ot_name : "UNKNOWN")
646de8f417SVictor Latushkin #define	ZDB_OT_TYPE(idx) ((idx) < DMU_OT_NUMTYPES ? (idx) : DMU_OT_NUMTYPES)
656de8f417SVictor Latushkin 
66fa9e4066Sahrens const char cmdname[] = "zdb";
67fa9e4066Sahrens uint8_t dump_opt[256];
68fa9e4066Sahrens 
69fa9e4066Sahrens typedef void object_viewer_t(objset_t *, uint64_t, void *data, size_t size);
70fa9e4066Sahrens 
71fa9e4066Sahrens extern void dump_intent_log(zilog_t *);
72fa9e4066Sahrens uint64_t *zopt_object = NULL;
73fa9e4066Sahrens int zopt_objects = 0;
74de6628f0Sck libzfs_handle_t *g_zfs;
75d41e7643Sek boolean_t zdb_sig_user_data = B_TRUE;
76d41e7643Sek int zdb_sig_cksumalg = ZIO_CHECKSUM_SHA256;
77fa9e4066Sahrens 
78fa9e4066Sahrens /*
79fa9e4066Sahrens  * These libumem hooks provide a reasonable set of defaults for the allocator's
80fa9e4066Sahrens  * debugging facilities.
81fa9e4066Sahrens  */
82fa9e4066Sahrens const char *
83fa9e4066Sahrens _umem_debug_init()
84fa9e4066Sahrens {
85fa9e4066Sahrens 	return ("default,verbose"); /* $UMEM_DEBUG setting */
86fa9e4066Sahrens }
87fa9e4066Sahrens 
88fa9e4066Sahrens const char *
89fa9e4066Sahrens _umem_logging_init(void)
90fa9e4066Sahrens {
91fa9e4066Sahrens 	return ("fail,contents"); /* $UMEM_LOGGING setting */
92fa9e4066Sahrens }
93fa9e4066Sahrens 
94fa9e4066Sahrens static void
95fa9e4066Sahrens usage(void)
96fa9e4066Sahrens {
97fa9e4066Sahrens 	(void) fprintf(stderr,
983ad6c7f9SVictor Latushkin 	    "Usage: %s [-CumdibcsvhL] [-S user:cksumalg] "
993ad6c7f9SVictor Latushkin 	    "poolname [object...]\n"
1003ad6c7f9SVictor Latushkin 	    "       %s [-div] dataset [object...]\n"
101*87219db7SVictor Latushkin 	    "       %s -m [-L] poolname [vdev [metaslab...]]\n"
10207428bdfSVictor Latushkin 	    "       %s -R poolname vdev:offset:size[:flags]\n"
10307428bdfSVictor Latushkin 	    "       %s -l device\n"
10407428bdfSVictor Latushkin 	    "       %s -C\n\n",
105*87219db7SVictor Latushkin 	    cmdname, cmdname, cmdname, cmdname, cmdname, cmdname);
1063ad6c7f9SVictor Latushkin 
1073ad6c7f9SVictor Latushkin 	(void) fprintf(stderr, "    Dataset name must include at least one "
1083ad6c7f9SVictor Latushkin 	    "separator character '/' or '@'\n");
1093ad6c7f9SVictor Latushkin 	(void) fprintf(stderr, "    If dataset name is specified, only that "
1103ad6c7f9SVictor Latushkin 	    "dataset is dumped\n");
1113ad6c7f9SVictor Latushkin 	(void) fprintf(stderr, "    If object numbers are specified, only "
1123ad6c7f9SVictor Latushkin 	    "those objects are dumped\n\n");
1133ad6c7f9SVictor Latushkin 	(void) fprintf(stderr, "    Options to control amount of output:\n");
1143ad6c7f9SVictor Latushkin 	(void) fprintf(stderr, "        -u uberblock\n");
1153ad6c7f9SVictor Latushkin 	(void) fprintf(stderr, "        -d dataset(s)\n");
1163ad6c7f9SVictor Latushkin 	(void) fprintf(stderr, "        -i intent logs\n");
11707428bdfSVictor Latushkin 	(void) fprintf(stderr, "        -C config (or cachefile if alone)\n");
1188f18d1faSGeorge Wilson 	(void) fprintf(stderr, "        -h pool history\n");
1193ad6c7f9SVictor Latushkin 	(void) fprintf(stderr, "        -b block statistics\n");
1203ad6c7f9SVictor Latushkin 	(void) fprintf(stderr, "        -m metaslabs\n");
1213ad6c7f9SVictor Latushkin 	(void) fprintf(stderr, "        -c checksum all metadata (twice for "
1226365109dSVictor Latushkin 	    "all data) blocks\n");
1233ad6c7f9SVictor Latushkin 	(void) fprintf(stderr, "        -s report stats on zdb's I/O\n");
1243ad6c7f9SVictor Latushkin 	(void) fprintf(stderr, "        -S <user|all>:<cksum_alg|all> -- "
125d41e7643Sek 	    "dump blkptr signatures\n");
1263ad6c7f9SVictor Latushkin 	(void) fprintf(stderr, "        -v verbose (applies to all others)\n");
127fa9e4066Sahrens 	(void) fprintf(stderr, "        -l dump label contents\n");
12882a0a985SVictor Latushkin 	(void) fprintf(stderr, "        -L disable leak tracking (do not "
12982a0a985SVictor Latushkin 	    "load spacemaps)\n");
130d41e7643Sek 	(void) fprintf(stderr, "        -R read and display block from a "
1313ad6c7f9SVictor Latushkin 	    "device\n\n");
1323ad6c7f9SVictor Latushkin 	(void) fprintf(stderr, "    Below options are intended for use "
1333ad6c7f9SVictor Latushkin 	    "with other options (except -l):\n");
1343ad6c7f9SVictor Latushkin 	(void) fprintf(stderr, "        -U <cachefile_path> -- use alternate "
1353ad6c7f9SVictor Latushkin 	    "cachefile\n");
1363ad6c7f9SVictor Latushkin 	(void) fprintf(stderr, "        -e pool is exported/destroyed/"
1373ad6c7f9SVictor Latushkin 	    "has altroot/not in a cachefile\n");
1383ad6c7f9SVictor Latushkin 	(void) fprintf(stderr, "        -p <path> -- use one or more with "
1393ad6c7f9SVictor Latushkin 	    "-e to specify path to vdev dir\n");
1403ad6c7f9SVictor Latushkin 	(void) fprintf(stderr, "        -t <txg> -- highest txg to use when "
1412e551927SVictor Latushkin 	    "searching for uberblocks\n");
142fa9e4066Sahrens 	(void) fprintf(stderr, "Specify an option more than once (e.g. -bb) "
143fa9e4066Sahrens 	    "to make only that option verbose\n");
144fa9e4066Sahrens 	(void) fprintf(stderr, "Default is to dump everything non-verbosely\n");
145fa9e4066Sahrens 	exit(1);
146fa9e4066Sahrens }
147fa9e4066Sahrens 
148ccba0801SRich Morris /*
149ccba0801SRich Morris  * Called for usage errors that are discovered after a call to spa_open(),
150ccba0801SRich Morris  * dmu_bonus_hold(), or pool_match().  abort() is called for other errors.
151ccba0801SRich Morris  */
152ccba0801SRich Morris 
153fa9e4066Sahrens static void
154fa9e4066Sahrens fatal(const char *fmt, ...)
155fa9e4066Sahrens {
156fa9e4066Sahrens 	va_list ap;
157fa9e4066Sahrens 
158fa9e4066Sahrens 	va_start(ap, fmt);
159fa9e4066Sahrens 	(void) fprintf(stderr, "%s: ", cmdname);
160fa9e4066Sahrens 	(void) vfprintf(stderr, fmt, ap);
161fa9e4066Sahrens 	va_end(ap);
162fa9e4066Sahrens 	(void) fprintf(stderr, "\n");
163fa9e4066Sahrens 
164ccba0801SRich Morris 	exit(1);
165fa9e4066Sahrens }
166fa9e4066Sahrens 
167fa9e4066Sahrens /* ARGSUSED */
168fa9e4066Sahrens static void
169fa9e4066Sahrens dump_packed_nvlist(objset_t *os, uint64_t object, void *data, size_t size)
170fa9e4066Sahrens {
171fa9e4066Sahrens 	nvlist_t *nv;
172fa9e4066Sahrens 	size_t nvsize = *(uint64_t *)data;
173fa9e4066Sahrens 	char *packed = umem_alloc(nvsize, UMEM_NOFAIL);
174fa9e4066Sahrens 
1757bfdf011SNeil Perrin 	VERIFY(0 == dmu_read(os, object, 0, nvsize, packed, DMU_READ_PREFETCH));
176fa9e4066Sahrens 
177fa9e4066Sahrens 	VERIFY(nvlist_unpack(packed, nvsize, &nv, 0) == 0);
178fa9e4066Sahrens 
179fa9e4066Sahrens 	umem_free(packed, nvsize);
180fa9e4066Sahrens 
181fa9e4066Sahrens 	dump_nvlist(nv, 8);
182fa9e4066Sahrens 
183fa9e4066Sahrens 	nvlist_free(nv);
184fa9e4066Sahrens }
185fa9e4066Sahrens 
186fa9e4066Sahrens const char dump_zap_stars[] = "****************************************";
187fa9e4066Sahrens const int dump_zap_width = sizeof (dump_zap_stars) - 1;
188fa9e4066Sahrens 
189fa9e4066Sahrens static void
190fa9e4066Sahrens dump_zap_histogram(uint64_t histo[ZAP_HISTOGRAM_SIZE])
191fa9e4066Sahrens {
192fa9e4066Sahrens 	int i;
193fa9e4066Sahrens 	int minidx = ZAP_HISTOGRAM_SIZE - 1;
194fa9e4066Sahrens 	int maxidx = 0;
195fa9e4066Sahrens 	uint64_t max = 0;
196fa9e4066Sahrens 
197fa9e4066Sahrens 	for (i = 0; i < ZAP_HISTOGRAM_SIZE; i++) {
198fa9e4066Sahrens 		if (histo[i] > max)
199fa9e4066Sahrens 			max = histo[i];
200fa9e4066Sahrens 		if (histo[i] > 0 && i > maxidx)
201fa9e4066Sahrens 			maxidx = i;
202fa9e4066Sahrens 		if (histo[i] > 0 && i < minidx)
203fa9e4066Sahrens 			minidx = i;
204fa9e4066Sahrens 	}
205fa9e4066Sahrens 
206fa9e4066Sahrens 	if (max < dump_zap_width)
207fa9e4066Sahrens 		max = dump_zap_width;
208fa9e4066Sahrens 
209fa9e4066Sahrens 	for (i = minidx; i <= maxidx; i++)
210fa9e4066Sahrens 		(void) printf("\t\t\t%u: %6llu %s\n", i, (u_longlong_t)histo[i],
211fa9e4066Sahrens 		    &dump_zap_stars[(max - histo[i]) * dump_zap_width / max]);
212fa9e4066Sahrens }
213fa9e4066Sahrens 
214fa9e4066Sahrens static void
215fa9e4066Sahrens dump_zap_stats(objset_t *os, uint64_t object)
216fa9e4066Sahrens {
217fa9e4066Sahrens 	int error;
218fa9e4066Sahrens 	zap_stats_t zs;
219fa9e4066Sahrens 
220fa9e4066Sahrens 	error = zap_get_stats(os, object, &zs);
221fa9e4066Sahrens 	if (error)
222fa9e4066Sahrens 		return;
223fa9e4066Sahrens 
224fa9e4066Sahrens 	if (zs.zs_ptrtbl_len == 0) {
225fa9e4066Sahrens 		ASSERT(zs.zs_num_blocks == 1);
226fa9e4066Sahrens 		(void) printf("\tmicrozap: %llu bytes, %llu entries\n",
227fa9e4066Sahrens 		    (u_longlong_t)zs.zs_blocksize,
228fa9e4066Sahrens 		    (u_longlong_t)zs.zs_num_entries);
229fa9e4066Sahrens 		return;
230fa9e4066Sahrens 	}
231fa9e4066Sahrens 
232fa9e4066Sahrens 	(void) printf("\tFat ZAP stats:\n");
2338248818dSnd 
2348248818dSnd 	(void) printf("\t\tPointer table:\n");
2358248818dSnd 	(void) printf("\t\t\t%llu elements\n",
236fa9e4066Sahrens 	    (u_longlong_t)zs.zs_ptrtbl_len);
2378248818dSnd 	(void) printf("\t\t\tzt_blk: %llu\n",
2388248818dSnd 	    (u_longlong_t)zs.zs_ptrtbl_zt_blk);
2398248818dSnd 	(void) printf("\t\t\tzt_numblks: %llu\n",
2408248818dSnd 	    (u_longlong_t)zs.zs_ptrtbl_zt_numblks);
2418248818dSnd 	(void) printf("\t\t\tzt_shift: %llu\n",
2428248818dSnd 	    (u_longlong_t)zs.zs_ptrtbl_zt_shift);
2438248818dSnd 	(void) printf("\t\t\tzt_blks_copied: %llu\n",
2448248818dSnd 	    (u_longlong_t)zs.zs_ptrtbl_blks_copied);
2458248818dSnd 	(void) printf("\t\t\tzt_nextblk: %llu\n",
2468248818dSnd 	    (u_longlong_t)zs.zs_ptrtbl_nextblk);
2478248818dSnd 
248fa9e4066Sahrens 	(void) printf("\t\tZAP entries: %llu\n",
249fa9e4066Sahrens 	    (u_longlong_t)zs.zs_num_entries);
250fa9e4066Sahrens 	(void) printf("\t\tLeaf blocks: %llu\n",
251fa9e4066Sahrens 	    (u_longlong_t)zs.zs_num_leafs);
252fa9e4066Sahrens 	(void) printf("\t\tTotal blocks: %llu\n",
253fa9e4066Sahrens 	    (u_longlong_t)zs.zs_num_blocks);
2548248818dSnd 	(void) printf("\t\tzap_block_type: 0x%llx\n",
2558248818dSnd 	    (u_longlong_t)zs.zs_block_type);
2568248818dSnd 	(void) printf("\t\tzap_magic: 0x%llx\n",
2578248818dSnd 	    (u_longlong_t)zs.zs_magic);
2588248818dSnd 	(void) printf("\t\tzap_salt: 0x%llx\n",
2598248818dSnd 	    (u_longlong_t)zs.zs_salt);
260fa9e4066Sahrens 
261fa9e4066Sahrens 	(void) printf("\t\tLeafs with 2^n pointers:\n");
262fa9e4066Sahrens 	dump_zap_histogram(zs.zs_leafs_with_2n_pointers);
263fa9e4066Sahrens 
264fa9e4066Sahrens 	(void) printf("\t\tBlocks with n*5 entries:\n");
265fa9e4066Sahrens 	dump_zap_histogram(zs.zs_blocks_with_n5_entries);
266fa9e4066Sahrens 
267fa9e4066Sahrens 	(void) printf("\t\tBlocks n/10 full:\n");
268fa9e4066Sahrens 	dump_zap_histogram(zs.zs_blocks_n_tenths_full);
269fa9e4066Sahrens 
270fa9e4066Sahrens 	(void) printf("\t\tEntries with n chunks:\n");
271fa9e4066Sahrens 	dump_zap_histogram(zs.zs_entries_using_n_chunks);
272fa9e4066Sahrens 
273fa9e4066Sahrens 	(void) printf("\t\tBuckets with n entries:\n");
274fa9e4066Sahrens 	dump_zap_histogram(zs.zs_buckets_with_n_entries);
275fa9e4066Sahrens }
276fa9e4066Sahrens 
277fa9e4066Sahrens /*ARGSUSED*/
278fa9e4066Sahrens static void
279fa9e4066Sahrens dump_none(objset_t *os, uint64_t object, void *data, size_t size)
280fa9e4066Sahrens {
281fa9e4066Sahrens }
282fa9e4066Sahrens 
2836de8f417SVictor Latushkin /*ARGSUSED*/
2846de8f417SVictor Latushkin static void
2856de8f417SVictor Latushkin dump_unknown(objset_t *os, uint64_t object, void *data, size_t size)
2866de8f417SVictor Latushkin {
2876de8f417SVictor Latushkin 	(void) printf("\tUNKNOWN OBJECT TYPE\n");
2886de8f417SVictor Latushkin }
2896de8f417SVictor Latushkin 
290fa9e4066Sahrens /*ARGSUSED*/
291fa9e4066Sahrens void
292fa9e4066Sahrens dump_uint8(objset_t *os, uint64_t object, void *data, size_t size)
293fa9e4066Sahrens {
294fa9e4066Sahrens }
295fa9e4066Sahrens 
296fa9e4066Sahrens /*ARGSUSED*/
297fa9e4066Sahrens static void
298fa9e4066Sahrens dump_uint64(objset_t *os, uint64_t object, void *data, size_t size)
299fa9e4066Sahrens {
300fa9e4066Sahrens }
301fa9e4066Sahrens 
302fa9e4066Sahrens /*ARGSUSED*/
303fa9e4066Sahrens static void
304fa9e4066Sahrens dump_zap(objset_t *os, uint64_t object, void *data, size_t size)
305fa9e4066Sahrens {
306fa9e4066Sahrens 	zap_cursor_t zc;
307fa9e4066Sahrens 	zap_attribute_t attr;
308fa9e4066Sahrens 	void *prop;
309fa9e4066Sahrens 	int i;
310fa9e4066Sahrens 
311fa9e4066Sahrens 	dump_zap_stats(os, object);
312fa9e4066Sahrens 	(void) printf("\n");
313fa9e4066Sahrens 
314fa9e4066Sahrens 	for (zap_cursor_init(&zc, os, object);
315fa9e4066Sahrens 	    zap_cursor_retrieve(&zc, &attr) == 0;
316fa9e4066Sahrens 	    zap_cursor_advance(&zc)) {
317fa9e4066Sahrens 		(void) printf("\t\t%s = ", attr.za_name);
318fa9e4066Sahrens 		if (attr.za_num_integers == 0) {
319fa9e4066Sahrens 			(void) printf("\n");
320fa9e4066Sahrens 			continue;
321fa9e4066Sahrens 		}
322fa9e4066Sahrens 		prop = umem_zalloc(attr.za_num_integers *
323fa9e4066Sahrens 		    attr.za_integer_length, UMEM_NOFAIL);
324fa9e4066Sahrens 		(void) zap_lookup(os, object, attr.za_name,
325fa9e4066Sahrens 		    attr.za_integer_length, attr.za_num_integers, prop);
326fa9e4066Sahrens 		if (attr.za_integer_length == 1) {
327fa9e4066Sahrens 			(void) printf("%s", (char *)prop);
328fa9e4066Sahrens 		} else {
329fa9e4066Sahrens 			for (i = 0; i < attr.za_num_integers; i++) {
330fa9e4066Sahrens 				switch (attr.za_integer_length) {
331fa9e4066Sahrens 				case 2:
332fa9e4066Sahrens 					(void) printf("%u ",
333fa9e4066Sahrens 					    ((uint16_t *)prop)[i]);
334fa9e4066Sahrens 					break;
335fa9e4066Sahrens 				case 4:
336fa9e4066Sahrens 					(void) printf("%u ",
337fa9e4066Sahrens 					    ((uint32_t *)prop)[i]);
338fa9e4066Sahrens 					break;
339fa9e4066Sahrens 				case 8:
340fa9e4066Sahrens 					(void) printf("%lld ",
341fa9e4066Sahrens 					    (u_longlong_t)((int64_t *)prop)[i]);
342fa9e4066Sahrens 					break;
343fa9e4066Sahrens 				}
344fa9e4066Sahrens 			}
345fa9e4066Sahrens 		}
346fa9e4066Sahrens 		(void) printf("\n");
347fa9e4066Sahrens 		umem_free(prop, attr.za_num_integers * attr.za_integer_length);
348fa9e4066Sahrens 	}
34987e5029aSahrens 	zap_cursor_fini(&zc);
350fa9e4066Sahrens }
351fa9e4066Sahrens 
352e7437265Sahrens /*ARGSUSED*/
353e7437265Sahrens static void
354e7437265Sahrens dump_zpldir(objset_t *os, uint64_t object, void *data, size_t size)
355e7437265Sahrens {
356e7437265Sahrens 	zap_cursor_t zc;
357e7437265Sahrens 	zap_attribute_t attr;
358e7437265Sahrens 	const char *typenames[] = {
359e7437265Sahrens 		/* 0 */ "not specified",
360e7437265Sahrens 		/* 1 */ "FIFO",
361e7437265Sahrens 		/* 2 */ "Character Device",
362e7437265Sahrens 		/* 3 */ "3 (invalid)",
363e7437265Sahrens 		/* 4 */ "Directory",
364e7437265Sahrens 		/* 5 */ "5 (invalid)",
365e7437265Sahrens 		/* 6 */ "Block Device",
366e7437265Sahrens 		/* 7 */ "7 (invalid)",
367e7437265Sahrens 		/* 8 */ "Regular File",
368e7437265Sahrens 		/* 9 */ "9 (invalid)",
369e7437265Sahrens 		/* 10 */ "Symbolic Link",
370e7437265Sahrens 		/* 11 */ "11 (invalid)",
371e7437265Sahrens 		/* 12 */ "Socket",
372e7437265Sahrens 		/* 13 */ "Door",
373e7437265Sahrens 		/* 14 */ "Event Port",
374e7437265Sahrens 		/* 15 */ "15 (invalid)",
375e7437265Sahrens 	};
376e7437265Sahrens 
377e7437265Sahrens 	dump_zap_stats(os, object);
378e7437265Sahrens 	(void) printf("\n");
379e7437265Sahrens 
380e7437265Sahrens 	for (zap_cursor_init(&zc, os, object);
381e7437265Sahrens 	    zap_cursor_retrieve(&zc, &attr) == 0;
382e7437265Sahrens 	    zap_cursor_advance(&zc)) {
383e7437265Sahrens 		(void) printf("\t\t%s = %lld (type: %s)\n",
384e7437265Sahrens 		    attr.za_name, ZFS_DIRENT_OBJ(attr.za_first_integer),
385e7437265Sahrens 		    typenames[ZFS_DIRENT_TYPE(attr.za_first_integer)]);
386e7437265Sahrens 	}
387e7437265Sahrens 	zap_cursor_fini(&zc);
388e7437265Sahrens }
389e7437265Sahrens 
390fa9e4066Sahrens static void
391fa9e4066Sahrens dump_spacemap(objset_t *os, space_map_obj_t *smo, space_map_t *sm)
392fa9e4066Sahrens {
393fa9e4066Sahrens 	uint64_t alloc, offset, entry;
394ecc2d604Sbonwick 	uint8_t mapshift = sm->sm_shift;
395fa9e4066Sahrens 	uint64_t mapstart = sm->sm_start;
3968053a263Sck 	char *ddata[] = { "ALLOC", "FREE", "CONDENSE", "INVALID",
3978053a263Sck 			    "INVALID", "INVALID", "INVALID", "INVALID" };
398fa9e4066Sahrens 
399fa9e4066Sahrens 	if (smo->smo_object == 0)
400fa9e4066Sahrens 		return;
401fa9e4066Sahrens 
402fa9e4066Sahrens 	/*
403fa9e4066Sahrens 	 * Print out the freelist entries in both encoded and decoded form.
404fa9e4066Sahrens 	 */
405fa9e4066Sahrens 	alloc = 0;
406fa9e4066Sahrens 	for (offset = 0; offset < smo->smo_objsize; offset += sizeof (entry)) {
407ea8dc4b6Seschrock 		VERIFY(0 == dmu_read(os, smo->smo_object, offset,
4087bfdf011SNeil Perrin 		    sizeof (entry), &entry, DMU_READ_PREFETCH));
409fa9e4066Sahrens 		if (SM_DEBUG_DECODE(entry)) {
410*87219db7SVictor Latushkin 			(void) printf("\t    [%6llu] %s: txg %llu, pass %llu\n",
411fa9e4066Sahrens 			    (u_longlong_t)(offset / sizeof (entry)),
412fa9e4066Sahrens 			    ddata[SM_DEBUG_ACTION_DECODE(entry)],
4135ad82045Snd 			    (u_longlong_t)SM_DEBUG_TXG_DECODE(entry),
4145ad82045Snd 			    (u_longlong_t)SM_DEBUG_SYNCPASS_DECODE(entry));
415fa9e4066Sahrens 		} else {
416*87219db7SVictor Latushkin 			(void) printf("\t    [%6llu]    %c  range:"
417*87219db7SVictor Latushkin 			    " %010llx-%010llx  size: %06llx\n",
418fa9e4066Sahrens 			    (u_longlong_t)(offset / sizeof (entry)),
419fa9e4066Sahrens 			    SM_TYPE_DECODE(entry) == SM_ALLOC ? 'A' : 'F',
4205ad82045Snd 			    (u_longlong_t)((SM_OFFSET_DECODE(entry) <<
4215ad82045Snd 			    mapshift) + mapstart),
4225ad82045Snd 			    (u_longlong_t)((SM_OFFSET_DECODE(entry) <<
4235ad82045Snd 			    mapshift) + mapstart + (SM_RUN_DECODE(entry) <<
4245ad82045Snd 			    mapshift)),
4255ad82045Snd 			    (u_longlong_t)(SM_RUN_DECODE(entry) << mapshift));
426fa9e4066Sahrens 			if (SM_TYPE_DECODE(entry) == SM_ALLOC)
427fa9e4066Sahrens 				alloc += SM_RUN_DECODE(entry) << mapshift;
428fa9e4066Sahrens 			else
429fa9e4066Sahrens 				alloc -= SM_RUN_DECODE(entry) << mapshift;
430fa9e4066Sahrens 		}
431fa9e4066Sahrens 	}
432fa9e4066Sahrens 	if (alloc != smo->smo_alloc) {
433fa9e4066Sahrens 		(void) printf("space_map_object alloc (%llu) INCONSISTENT "
434fa9e4066Sahrens 		    "with space map summary (%llu)\n",
435fa9e4066Sahrens 		    (u_longlong_t)smo->smo_alloc, (u_longlong_t)alloc);
436fa9e4066Sahrens 	}
437fa9e4066Sahrens }
438fa9e4066Sahrens 
439d6e555bdSGeorge Wilson static void
440d6e555bdSGeorge Wilson dump_metaslab_stats(metaslab_t *msp)
441d6e555bdSGeorge Wilson {
442d6e555bdSGeorge Wilson 	char maxbuf[5];
443d6e555bdSGeorge Wilson 	space_map_t *sm = &msp->ms_map;
444d6e555bdSGeorge Wilson 	avl_tree_t *t = sm->sm_pp_root;
445d6e555bdSGeorge Wilson 	int free_pct = sm->sm_space * 100 / sm->sm_size;
446d6e555bdSGeorge Wilson 
447d6e555bdSGeorge Wilson 	nicenum(space_map_maxsize(sm), maxbuf);
448d6e555bdSGeorge Wilson 
449*87219db7SVictor Latushkin 	(void) printf("\t %25s %10lu   %7s  %6s   %4s %4d%%\n",
450d6e555bdSGeorge Wilson 	    "segments", avl_numnodes(t), "maxsize", maxbuf,
451d6e555bdSGeorge Wilson 	    "freepct", free_pct);
452d6e555bdSGeorge Wilson }
453d6e555bdSGeorge Wilson 
454fa9e4066Sahrens static void
455fa9e4066Sahrens dump_metaslab(metaslab_t *msp)
456fa9e4066Sahrens {
457fa9e4066Sahrens 	char freebuf[5];
458ecc2d604Sbonwick 	space_map_obj_t *smo = &msp->ms_smo;
459fa9e4066Sahrens 	vdev_t *vd = msp->ms_group->mg_vd;
460fa9e4066Sahrens 	spa_t *spa = vd->vdev_spa;
461fa9e4066Sahrens 
462fa9e4066Sahrens 	nicenum(msp->ms_map.sm_size - smo->smo_alloc, freebuf);
463fa9e4066Sahrens 
464fa9e4066Sahrens 	(void) printf(
465*87219db7SVictor Latushkin 	    "\tmetaslab %6llu   offset %12llx   spacemap %6llu   free    %5s\n",
466*87219db7SVictor Latushkin 	    (u_longlong_t)(msp->ms_map.sm_start / msp->ms_map.sm_size),
467*87219db7SVictor Latushkin 	    (u_longlong_t)msp->ms_map.sm_start, (u_longlong_t)smo->smo_object,
468*87219db7SVictor Latushkin 	    freebuf);
469fa9e4066Sahrens 
470*87219db7SVictor Latushkin 	if (dump_opt['m'] > 1 && !dump_opt['L']) {
471d6e555bdSGeorge Wilson 		mutex_enter(&msp->ms_lock);
472d6e555bdSGeorge Wilson 		VERIFY(space_map_load(&msp->ms_map, zfs_metaslab_ops,
473d6e555bdSGeorge Wilson 		    SM_FREE, &msp->ms_smo, spa->spa_meta_objset) == 0);
474d6e555bdSGeorge Wilson 		dump_metaslab_stats(msp);
475d6e555bdSGeorge Wilson 		space_map_unload(&msp->ms_map);
476d6e555bdSGeorge Wilson 		mutex_exit(&msp->ms_lock);
477d6e555bdSGeorge Wilson 	}
478d6e555bdSGeorge Wilson 
479d6e555bdSGeorge Wilson 	if (dump_opt['d'] > 5 || dump_opt['m'] > 2) {
480d6e555bdSGeorge Wilson 		ASSERT(msp->ms_map.sm_size == (1ULL << vd->vdev_ms_shift));
481d6e555bdSGeorge Wilson 
482d6e555bdSGeorge Wilson 		mutex_enter(&msp->ms_lock);
483d6e555bdSGeorge Wilson 		dump_spacemap(spa->spa_meta_objset, smo, &msp->ms_map);
484d6e555bdSGeorge Wilson 		mutex_exit(&msp->ms_lock);
485d6e555bdSGeorge Wilson 	}
486*87219db7SVictor Latushkin }
487fa9e4066Sahrens 
488*87219db7SVictor Latushkin static void
489*87219db7SVictor Latushkin print_vdev_metaslab_header(vdev_t *vd)
490*87219db7SVictor Latushkin {
491*87219db7SVictor Latushkin 	(void) printf("\tvdev %10llu\n\t%-10s%5llu   %-19s   %-15s   %-10s\n",
492*87219db7SVictor Latushkin 	    (u_longlong_t)vd->vdev_id,
493*87219db7SVictor Latushkin 	    "metaslabs", (u_longlong_t)vd->vdev_ms_count,
494*87219db7SVictor Latushkin 	    "offset", "spacemap", "free");
495*87219db7SVictor Latushkin 	(void) printf("\t%15s   %19s   %15s   %10s\n",
496*87219db7SVictor Latushkin 	    "---------------", "-------------------",
497*87219db7SVictor Latushkin 	    "---------------", "-------------");
498fa9e4066Sahrens }
499fa9e4066Sahrens 
500fa9e4066Sahrens static void
501fa9e4066Sahrens dump_metaslabs(spa_t *spa)
502fa9e4066Sahrens {
503*87219db7SVictor Latushkin 	vdev_t *vd, *rvd = spa->spa_root_vdev;
504*87219db7SVictor Latushkin 	uint64_t m, c = 0, children = rvd->vdev_children;
505fa9e4066Sahrens 
506fa9e4066Sahrens 	(void) printf("\nMetaslabs:\n");
507fa9e4066Sahrens 
508*87219db7SVictor Latushkin 	if (!dump_opt['d'] && zopt_objects > 0) {
509*87219db7SVictor Latushkin 		c = zopt_object[0];
510*87219db7SVictor Latushkin 
511*87219db7SVictor Latushkin 		if (c >= children)
512*87219db7SVictor Latushkin 			(void) fatal("bad vdev id: %llu", (u_longlong_t)c);
513fa9e4066Sahrens 
514*87219db7SVictor Latushkin 		if (zopt_objects > 1) {
515*87219db7SVictor Latushkin 			vd = rvd->vdev_child[c];
516*87219db7SVictor Latushkin 			print_vdev_metaslab_header(vd);
517*87219db7SVictor Latushkin 
518*87219db7SVictor Latushkin 			for (m = 1; m < zopt_objects; m++) {
519*87219db7SVictor Latushkin 				if (zopt_object[m] < vd->vdev_ms_count)
520*87219db7SVictor Latushkin 					dump_metaslab(
521*87219db7SVictor Latushkin 					    vd->vdev_ms[zopt_object[m]]);
522*87219db7SVictor Latushkin 				else
523*87219db7SVictor Latushkin 					(void) fprintf(stderr, "bad metaslab "
524*87219db7SVictor Latushkin 					    "number %llu\n",
525*87219db7SVictor Latushkin 					    (u_longlong_t)zopt_object[m]);
526*87219db7SVictor Latushkin 			}
527*87219db7SVictor Latushkin 			(void) printf("\n");
528*87219db7SVictor Latushkin 			return;
529*87219db7SVictor Latushkin 		}
530*87219db7SVictor Latushkin 		children = c + 1;
531*87219db7SVictor Latushkin 	}
532*87219db7SVictor Latushkin 	for (; c < children; c++) {
533*87219db7SVictor Latushkin 		vd = rvd->vdev_child[c];
534*87219db7SVictor Latushkin 		print_vdev_metaslab_header(vd);
535fa9e4066Sahrens 
536fa9e4066Sahrens 		for (m = 0; m < vd->vdev_ms_count; m++)
537fa9e4066Sahrens 			dump_metaslab(vd->vdev_ms[m]);
538fa9e4066Sahrens 		(void) printf("\n");
539fa9e4066Sahrens 	}
540fa9e4066Sahrens }
541fa9e4066Sahrens 
5428ad4d6ddSJeff Bonwick static void
5438ad4d6ddSJeff Bonwick dump_dtl_seg(space_map_t *sm, uint64_t start, uint64_t size)
5448ad4d6ddSJeff Bonwick {
5458ad4d6ddSJeff Bonwick 	char *prefix = (void *)sm;
5468ad4d6ddSJeff Bonwick 
5478ad4d6ddSJeff Bonwick 	(void) printf("%s [%llu,%llu) length %llu\n",
5488ad4d6ddSJeff Bonwick 	    prefix,
5498ad4d6ddSJeff Bonwick 	    (u_longlong_t)start,
5508ad4d6ddSJeff Bonwick 	    (u_longlong_t)(start + size),
5518ad4d6ddSJeff Bonwick 	    (u_longlong_t)(size));
5528ad4d6ddSJeff Bonwick }
5538ad4d6ddSJeff Bonwick 
554fa9e4066Sahrens static void
555fa9e4066Sahrens dump_dtl(vdev_t *vd, int indent)
556fa9e4066Sahrens {
5578ad4d6ddSJeff Bonwick 	spa_t *spa = vd->vdev_spa;
5588ad4d6ddSJeff Bonwick 	boolean_t required;
5598ad4d6ddSJeff Bonwick 	char *name[DTL_TYPES] = { "missing", "partial", "scrub", "outage" };
5608ad4d6ddSJeff Bonwick 	char prefix[256];
5618ad4d6ddSJeff Bonwick 
5628f18d1faSGeorge Wilson 	spa_vdev_state_enter(spa, SCL_NONE);
5638ad4d6ddSJeff Bonwick 	required = vdev_dtl_required(vd);
5648ad4d6ddSJeff Bonwick 	(void) spa_vdev_state_exit(spa, NULL, 0);
565fa9e4066Sahrens 
566fa9e4066Sahrens 	if (indent == 0)
567fa9e4066Sahrens 		(void) printf("\nDirty time logs:\n\n");
568fa9e4066Sahrens 
5698ad4d6ddSJeff Bonwick 	(void) printf("\t%*s%s [%s]\n", indent, "",
570e14bb325SJeff Bonwick 	    vd->vdev_path ? vd->vdev_path :
5718ad4d6ddSJeff Bonwick 	    vd->vdev_parent ? vd->vdev_ops->vdev_op_type : spa_name(spa),
5728ad4d6ddSJeff Bonwick 	    required ? "DTL-required" : "DTL-expendable");
573fa9e4066Sahrens 
5748ad4d6ddSJeff Bonwick 	for (int t = 0; t < DTL_TYPES; t++) {
5758ad4d6ddSJeff Bonwick 		space_map_t *sm = &vd->vdev_dtl[t];
5768ad4d6ddSJeff Bonwick 		if (sm->sm_space == 0)
5778ad4d6ddSJeff Bonwick 			continue;
5788ad4d6ddSJeff Bonwick 		(void) snprintf(prefix, sizeof (prefix), "\t%*s%s",
5798ad4d6ddSJeff Bonwick 		    indent + 2, "", name[t]);
5808ad4d6ddSJeff Bonwick 		mutex_enter(sm->sm_lock);
5818ad4d6ddSJeff Bonwick 		space_map_walk(sm, dump_dtl_seg, (void *)prefix);
5828ad4d6ddSJeff Bonwick 		mutex_exit(sm->sm_lock);
5838ad4d6ddSJeff Bonwick 		if (dump_opt['d'] > 5 && vd->vdev_children == 0)
5848ad4d6ddSJeff Bonwick 			dump_spacemap(spa->spa_meta_objset,
5858ad4d6ddSJeff Bonwick 			    &vd->vdev_dtl_smo, sm);
586fa9e4066Sahrens 	}
587fa9e4066Sahrens 
5888ad4d6ddSJeff Bonwick 	for (int c = 0; c < vd->vdev_children; c++)
589fa9e4066Sahrens 		dump_dtl(vd->vdev_child[c], indent + 4);
590fa9e4066Sahrens }
591fa9e4066Sahrens 
5928f18d1faSGeorge Wilson static void
5938f18d1faSGeorge Wilson dump_history(spa_t *spa)
5948f18d1faSGeorge Wilson {
5958f18d1faSGeorge Wilson 	nvlist_t **events = NULL;
5968f18d1faSGeorge Wilson 	char buf[SPA_MAXBLOCKSIZE];
597e4161df6SVictor Latushkin 	uint64_t resid, len, off = 0;
5988f18d1faSGeorge Wilson 	uint_t num = 0;
5998f18d1faSGeorge Wilson 	int error;
6008f18d1faSGeorge Wilson 	time_t tsec;
6018f18d1faSGeorge Wilson 	struct tm t;
6028f18d1faSGeorge Wilson 	char tbuf[30];
6038f18d1faSGeorge Wilson 	char internalstr[MAXPATHLEN];
6048f18d1faSGeorge Wilson 
6058f18d1faSGeorge Wilson 	do {
606e4161df6SVictor Latushkin 		len = sizeof (buf);
607e4161df6SVictor Latushkin 
6088f18d1faSGeorge Wilson 		if ((error = spa_history_get(spa, &off, &len, buf)) != 0) {
6098f18d1faSGeorge Wilson 			(void) fprintf(stderr, "Unable to read history: "
6108f18d1faSGeorge Wilson 			    "error %d\n", error);
6118f18d1faSGeorge Wilson 			return;
6128f18d1faSGeorge Wilson 		}
6138f18d1faSGeorge Wilson 
6148f18d1faSGeorge Wilson 		if (zpool_history_unpack(buf, len, &resid, &events, &num) != 0)
6158f18d1faSGeorge Wilson 			break;
6168f18d1faSGeorge Wilson 
6178f18d1faSGeorge Wilson 		off -= resid;
6188f18d1faSGeorge Wilson 	} while (len != 0);
6198f18d1faSGeorge Wilson 
6208f18d1faSGeorge Wilson 	(void) printf("\nHistory:\n");
6218f18d1faSGeorge Wilson 	for (int i = 0; i < num; i++) {
6228f18d1faSGeorge Wilson 		uint64_t time, txg, ievent;
6238f18d1faSGeorge Wilson 		char *cmd, *intstr;
6248f18d1faSGeorge Wilson 
6258f18d1faSGeorge Wilson 		if (nvlist_lookup_uint64(events[i], ZPOOL_HIST_TIME,
6268f18d1faSGeorge Wilson 		    &time) != 0)
6278f18d1faSGeorge Wilson 			continue;
6288f18d1faSGeorge Wilson 		if (nvlist_lookup_string(events[i], ZPOOL_HIST_CMD,
6298f18d1faSGeorge Wilson 		    &cmd) != 0) {
6308f18d1faSGeorge Wilson 			if (nvlist_lookup_uint64(events[i],
6318f18d1faSGeorge Wilson 			    ZPOOL_HIST_INT_EVENT, &ievent) != 0)
6328f18d1faSGeorge Wilson 				continue;
6338f18d1faSGeorge Wilson 			verify(nvlist_lookup_uint64(events[i],
6348f18d1faSGeorge Wilson 			    ZPOOL_HIST_TXG, &txg) == 0);
6358f18d1faSGeorge Wilson 			verify(nvlist_lookup_string(events[i],
6368f18d1faSGeorge Wilson 			    ZPOOL_HIST_INT_STR, &intstr) == 0);
6378f18d1faSGeorge Wilson 			if (ievent >= LOG_END)
6388f18d1faSGeorge Wilson 				continue;
6398f18d1faSGeorge Wilson 
6408f18d1faSGeorge Wilson 			(void) snprintf(internalstr,
6418f18d1faSGeorge Wilson 			    sizeof (internalstr),
6428f18d1faSGeorge Wilson 			    "[internal %s txg:%lld] %s",
6438f18d1faSGeorge Wilson 			    hist_event_table[ievent], txg,
6448f18d1faSGeorge Wilson 			    intstr);
6458f18d1faSGeorge Wilson 			cmd = internalstr;
6468f18d1faSGeorge Wilson 		}
6478f18d1faSGeorge Wilson 		tsec = time;
6488f18d1faSGeorge Wilson 		(void) localtime_r(&tsec, &t);
6498f18d1faSGeorge Wilson 		(void) strftime(tbuf, sizeof (tbuf), "%F.%T", &t);
6508f18d1faSGeorge Wilson 		(void) printf("%s %s\n", tbuf, cmd);
6518f18d1faSGeorge Wilson 	}
6528f18d1faSGeorge Wilson }
6538f18d1faSGeorge Wilson 
654fa9e4066Sahrens /*ARGSUSED*/
655fa9e4066Sahrens static void
656fa9e4066Sahrens dump_dnode(objset_t *os, uint64_t object, void *data, size_t size)
657fa9e4066Sahrens {
658fa9e4066Sahrens }
659fa9e4066Sahrens 
660fa9e4066Sahrens static uint64_t
66188b7b0f2SMatthew Ahrens blkid2offset(const dnode_phys_t *dnp, int level, uint64_t blkid)
662fa9e4066Sahrens {
663fa9e4066Sahrens 	if (level < 0)
664fa9e4066Sahrens 		return (blkid);
665fa9e4066Sahrens 
666fa9e4066Sahrens 	return ((blkid << (level * (dnp->dn_indblkshift - SPA_BLKPTRSHIFT))) *
667fa9e4066Sahrens 	    dnp->dn_datablkszsec << SPA_MINBLOCKSHIFT);
668fa9e4066Sahrens }
669fa9e4066Sahrens 
67044cd46caSbillm static void
67144cd46caSbillm sprintf_blkptr_compact(char *blkbuf, blkptr_t *bp, int alldvas)
67244cd46caSbillm {
67344cd46caSbillm 	dva_t *dva = bp->blk_dva;
67444cd46caSbillm 	int ndvas = alldvas ? BP_GET_NDVAS(bp) : 1;
67544cd46caSbillm 	int i;
67644cd46caSbillm 
67744cd46caSbillm 	blkbuf[0] = '\0';
67844cd46caSbillm 
67944cd46caSbillm 	for (i = 0; i < ndvas; i++)
68044cd46caSbillm 		(void) sprintf(blkbuf + strlen(blkbuf), "%llu:%llx:%llx ",
68144cd46caSbillm 		    (u_longlong_t)DVA_GET_VDEV(&dva[i]),
68244cd46caSbillm 		    (u_longlong_t)DVA_GET_OFFSET(&dva[i]),
68344cd46caSbillm 		    (u_longlong_t)DVA_GET_ASIZE(&dva[i]));
68444cd46caSbillm 
68544cd46caSbillm 	(void) sprintf(blkbuf + strlen(blkbuf), "%llxL/%llxP F=%llu B=%llu",
68644cd46caSbillm 	    (u_longlong_t)BP_GET_LSIZE(bp),
68744cd46caSbillm 	    (u_longlong_t)BP_GET_PSIZE(bp),
68844cd46caSbillm 	    (u_longlong_t)bp->blk_fill,
68944cd46caSbillm 	    (u_longlong_t)bp->blk_birth);
69044cd46caSbillm }
69144cd46caSbillm 
69288b7b0f2SMatthew Ahrens static void
69388b7b0f2SMatthew Ahrens print_indirect(blkptr_t *bp, const zbookmark_t *zb,
69488b7b0f2SMatthew Ahrens     const dnode_phys_t *dnp)
695fa9e4066Sahrens {
69688b7b0f2SMatthew Ahrens 	char blkbuf[BP_SPRINTF_LEN];
697fa9e4066Sahrens 	int l;
698fa9e4066Sahrens 
69988b7b0f2SMatthew Ahrens 	ASSERT3U(BP_GET_TYPE(bp), ==, dnp->dn_type);
70088b7b0f2SMatthew Ahrens 	ASSERT3U(BP_GET_LEVEL(bp), ==, zb->zb_level);
701fa9e4066Sahrens 
70288b7b0f2SMatthew Ahrens 	(void) printf("%16llx ",
703fa9e4066Sahrens 	    (u_longlong_t)blkid2offset(dnp, zb->zb_level, zb->zb_blkid));
704fa9e4066Sahrens 
705fa9e4066Sahrens 	ASSERT(zb->zb_level >= 0);
706fa9e4066Sahrens 
707fa9e4066Sahrens 	for (l = dnp->dn_nlevels - 1; l >= -1; l--) {
708fa9e4066Sahrens 		if (l == zb->zb_level) {
70988b7b0f2SMatthew Ahrens 			(void) printf("L%llx", (u_longlong_t)zb->zb_level);
710fa9e4066Sahrens 		} else {
71188b7b0f2SMatthew Ahrens 			(void) printf(" ");
712fa9e4066Sahrens 		}
713fa9e4066Sahrens 	}
714fa9e4066Sahrens 
71588b7b0f2SMatthew Ahrens 	sprintf_blkptr_compact(blkbuf, bp, dump_opt['d'] > 5 ? 1 : 0);
71688b7b0f2SMatthew Ahrens 	(void) printf("%s\n", blkbuf);
71788b7b0f2SMatthew Ahrens }
71888b7b0f2SMatthew Ahrens 
71988b7b0f2SMatthew Ahrens #define	SET_BOOKMARK(zb, objset, object, level, blkid)  \
72088b7b0f2SMatthew Ahrens {                                                       \
72188b7b0f2SMatthew Ahrens 	(zb)->zb_objset = objset;                       \
72288b7b0f2SMatthew Ahrens 	(zb)->zb_object = object;                       \
72388b7b0f2SMatthew Ahrens 	(zb)->zb_level = level;                         \
72488b7b0f2SMatthew Ahrens 	(zb)->zb_blkid = blkid;                         \
72588b7b0f2SMatthew Ahrens }
72688b7b0f2SMatthew Ahrens 
72788b7b0f2SMatthew Ahrens static int
72888b7b0f2SMatthew Ahrens visit_indirect(spa_t *spa, const dnode_phys_t *dnp,
72988b7b0f2SMatthew Ahrens     blkptr_t *bp, const zbookmark_t *zb)
73088b7b0f2SMatthew Ahrens {
731e4161df6SVictor Latushkin 	int err = 0;
73288b7b0f2SMatthew Ahrens 
73388b7b0f2SMatthew Ahrens 	if (bp->blk_birth == 0)
73488b7b0f2SMatthew Ahrens 		return (0);
73588b7b0f2SMatthew Ahrens 
73688b7b0f2SMatthew Ahrens 	print_indirect(bp, zb, dnp);
73788b7b0f2SMatthew Ahrens 
73888b7b0f2SMatthew Ahrens 	if (BP_GET_LEVEL(bp) > 0) {
73988b7b0f2SMatthew Ahrens 		uint32_t flags = ARC_WAIT;
74088b7b0f2SMatthew Ahrens 		int i;
74188b7b0f2SMatthew Ahrens 		blkptr_t *cbp;
74288b7b0f2SMatthew Ahrens 		int epb = BP_GET_LSIZE(bp) >> SPA_BLKPTRSHIFT;
74388b7b0f2SMatthew Ahrens 		arc_buf_t *buf;
74488b7b0f2SMatthew Ahrens 		uint64_t fill = 0;
74588b7b0f2SMatthew Ahrens 
74688b7b0f2SMatthew Ahrens 		err = arc_read_nolock(NULL, spa, bp, arc_getbuf_func, &buf,
74788b7b0f2SMatthew Ahrens 		    ZIO_PRIORITY_ASYNC_READ, ZIO_FLAG_CANFAIL, &flags, zb);
74888b7b0f2SMatthew Ahrens 		if (err)
74988b7b0f2SMatthew Ahrens 			return (err);
75088b7b0f2SMatthew Ahrens 
75188b7b0f2SMatthew Ahrens 		/* recursively visit blocks below this */
75288b7b0f2SMatthew Ahrens 		cbp = buf->b_data;
753