zdb.c revision 3ad6c7f96bc462dcbd2a112df698038f6764eabc
1fa9e406ahrens/*
2fa9e406ahrens * CDDL HEADER START
3fa9e406ahrens *
4fa9e406ahrens * The contents of this file are subject to the terms of the
5ea8dc4beschrock * Common Development and Distribution License (the "License").
6ea8dc4beschrock * You may not use this file except in compliance with the License.
7fa9e406ahrens *
8fa9e406ahrens * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9fa9e406ahrens * or http://www.opensolaris.org/os/licensing.
10fa9e406ahrens * See the License for the specific language governing permissions
11fa9e406ahrens * and limitations under the License.
12fa9e406ahrens *
13fa9e406ahrens * When distributing Covered Code, include this CDDL HEADER in each
14fa9e406ahrens * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15fa9e406ahrens * If applicable, add the following below this CDDL HEADER, with the
16fa9e406ahrens * fields enclosed by brackets "[]" replaced with your own identifying
17fa9e406ahrens * information: Portions Copyright [yyyy] [name of copyright owner]
18fa9e406ahrens *
19fa9e406ahrens * CDDL HEADER END
20fa9e406ahrens */
21fa9e406ahrens/*
22ccba080Rich Morris * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
23fa9e406ahrens * Use is subject to license terms.
24fa9e406ahrens */
25fa9e406ahrens
26fa9e406ahrens#include <stdio.h>
27004388ecasper#include <stdio_ext.h>
28fa9e406ahrens#include <stdlib.h>
2944cd46cbillm#include <ctype.h>
30fa9e406ahrens#include <sys/zfs_context.h>
31fa9e406ahrens#include <sys/spa.h>
32fa9e406ahrens#include <sys/spa_impl.h>
33fa9e406ahrens#include <sys/dmu.h>
34fa9e406ahrens#include <sys/zap.h>
35fa9e406ahrens#include <sys/fs/zfs.h>
36fa9e406ahrens#include <sys/zfs_znode.h>
37fa9e406ahrens#include <sys/vdev.h>
38fa9e406ahrens#include <sys/vdev_impl.h>
39fa9e406ahrens#include <sys/metaslab_impl.h>
40fa9e406ahrens#include <sys/dmu_objset.h>
41fa9e406ahrens#include <sys/dsl_dir.h>
42fa9e406ahrens#include <sys/dsl_dataset.h>
43fa9e406ahrens#include <sys/dsl_pool.h>
44fa9e406ahrens#include <sys/dbuf.h>
45fa9e406ahrens#include <sys/zil.h>
46fa9e406ahrens#include <sys/zil_impl.h>
47fa9e406ahrens#include <sys/stat.h>
48fa9e406ahrens#include <sys/resource.h>
49fa9e406ahrens#include <sys/dmu_traverse.h>
50fa9e406ahrens#include <sys/zio_checksum.h>
51fa9e406ahrens#include <sys/zio_compress.h>
52e0d35c4marks#include <sys/zfs_fuid.h>
5388b7b0fMatthew Ahrens#include <sys/arc.h>
54de6628fck#undef ZFS_MAXNAMELEN
55de6628fck#undef verify
56de6628fck#include <libzfs.h>
57fa9e406ahrens
58fa9e406ahrensconst char cmdname[] = "zdb";
59fa9e406ahrensuint8_t dump_opt[256];
60fa9e406ahrens
61fa9e406ahrenstypedef void object_viewer_t(objset_t *, uint64_t, void *data, size_t size);
62fa9e406ahrens
63fa9e406ahrensextern void dump_intent_log(zilog_t *);
64fa9e406ahrensuint64_t *zopt_object = NULL;
65fa9e406ahrensint zopt_objects = 0;
66de6628fcklibzfs_handle_t *g_zfs;
67d41e764ekboolean_t zdb_sig_user_data = B_TRUE;
68d41e764ekint zdb_sig_cksumalg = ZIO_CHECKSUM_SHA256;
69fa9e406ahrens
70fa9e406ahrens/*
71fa9e406ahrens * These libumem hooks provide a reasonable set of defaults for the allocator's
72fa9e406ahrens * debugging facilities.
73fa9e406ahrens */
74fa9e406ahrensconst char *
75fa9e406ahrens_umem_debug_init()
76fa9e406ahrens{
77fa9e406ahrens	return ("default,verbose"); /* $UMEM_DEBUG setting */
78fa9e406ahrens}
79fa9e406ahrens
80fa9e406ahrensconst char *
81fa9e406ahrens_umem_logging_init(void)
82fa9e406ahrens{
83fa9e406ahrens	return ("fail,contents"); /* $UMEM_LOGGING setting */
84fa9e406ahrens}
85fa9e406ahrens
86fa9e406ahrensstatic void
87fa9e406ahrensusage(void)
88fa9e406ahrens{
89fa9e406ahrens	(void) fprintf(stderr,
903ad6c7fVictor Latushkin	    "Usage: %s [-CumdibcsvhL] [-S user:cksumalg] "
913ad6c7fVictor Latushkin	    "poolname [object...]\n"
923ad6c7fVictor Latushkin	    "       %s [-div] dataset [object...]\n"
93fa9e406ahrens	    "       %s -C [pool]\n"
9444cd46cbillm	    "       %s -l dev\n"
953ad6c7fVictor Latushkin	    "       %s -R pool:vdev:offset:size:flags\n\n",
963ad6c7fVictor Latushkin	    cmdname, cmdname, cmdname, cmdname, cmdname);
973ad6c7fVictor Latushkin
983ad6c7fVictor Latushkin	(void) fprintf(stderr, "    Dataset name must include at least one "
993ad6c7fVictor Latushkin	    "separator character '/' or '@'\n");
1003ad6c7fVictor Latushkin	(void) fprintf(stderr, "    If dataset name is specified, only that "
1013ad6c7fVictor Latushkin	    "dataset is dumped\n");
1023ad6c7fVictor Latushkin	(void) fprintf(stderr, "    If object numbers are specified, only "
1033ad6c7fVictor Latushkin	    "those objects are dumped\n\n");
1043ad6c7fVictor Latushkin	(void) fprintf(stderr, "    Options to control amount of output:\n");
1053ad6c7fVictor Latushkin	(void) fprintf(stderr, "        -u uberblock\n");
1063ad6c7fVictor Latushkin	(void) fprintf(stderr, "        -d dataset(s)\n");
1073ad6c7fVictor Latushkin	(void) fprintf(stderr, "        -i intent logs\n");
108fa9e406ahrens	(void) fprintf(stderr, "        -C cached pool configuration\n");
1098f18d1fGeorge Wilson	(void) fprintf(stderr, "        -h pool history\n");
1103ad6c7fVictor Latushkin	(void) fprintf(stderr, "        -b block statistics\n");
1113ad6c7fVictor Latushkin	(void) fprintf(stderr, "        -m metaslabs\n");
1123ad6c7fVictor Latushkin	(void) fprintf(stderr, "        -c checksum all metadata (twice for "
1136365109Victor Latushkin	    "all data) blocks\n");
1143ad6c7fVictor Latushkin	(void) fprintf(stderr, "        -s report stats on zdb's I/O\n");
1153ad6c7fVictor Latushkin	(void) fprintf(stderr, "        -S <user|all>:<cksum_alg|all> -- "
116d41e764ek	    "dump blkptr signatures\n");
1173ad6c7fVictor Latushkin	(void) fprintf(stderr, "        -v verbose (applies to all others)\n");
118fa9e406ahrens	(void) fprintf(stderr, "        -l dump label contents\n");
11982a0a98Victor Latushkin	(void) fprintf(stderr, "        -L disable leak tracking (do not "
12082a0a98Victor Latushkin	    "load spacemaps)\n");
121d41e764ek	(void) fprintf(stderr, "        -R read and display block from a "
1223ad6c7fVictor Latushkin	    "device\n\n");
1233ad6c7fVictor Latushkin	(void) fprintf(stderr, "    Below options are intended for use "
1243ad6c7fVictor Latushkin	    "with other options (except -l):\n");
1253ad6c7fVictor Latushkin	(void) fprintf(stderr, "        -U <cachefile_path> -- use alternate "
1263ad6c7fVictor Latushkin	    "cachefile\n");
1273ad6c7fVictor Latushkin	(void) fprintf(stderr, "        -e pool is exported/destroyed/"
1283ad6c7fVictor Latushkin	    "has altroot/not in a cachefile\n");
1293ad6c7fVictor Latushkin	(void) fprintf(stderr, "        -p <path> -- use one or more with "
1303ad6c7fVictor Latushkin	    "-e to specify path to vdev dir\n");
1313ad6c7fVictor Latushkin	(void) fprintf(stderr, "        -t <txg> -- highest txg to use when "
1322e55192Victor Latushkin	    "searching for uberblocks\n");
133fa9e406ahrens	(void) fprintf(stderr, "Specify an option more than once (e.g. -bb) "
134fa9e406ahrens	    "to make only that option verbose\n");
135fa9e406ahrens	(void) fprintf(stderr, "Default is to dump everything non-verbosely\n");
136fa9e406ahrens	exit(1);
137fa9e406ahrens}
138fa9e406ahrens
139ccba080Rich Morris/*
140ccba080Rich Morris * Called for usage errors that are discovered after a call to spa_open(),
141ccba080Rich Morris * dmu_bonus_hold(), or pool_match().  abort() is called for other errors.
142ccba080Rich Morris */
143ccba080Rich Morris
144fa9e406ahrensstatic void
145fa9e406ahrensfatal(const char *fmt, ...)
146fa9e406ahrens{
147fa9e406ahrens	va_list ap;
148fa9e406ahrens
149fa9e406ahrens	va_start(ap, fmt);
150fa9e406ahrens	(void) fprintf(stderr, "%s: ", cmdname);
151fa9e406ahrens	(void) vfprintf(stderr, fmt, ap);
152fa9e406ahrens	va_end(ap);
153fa9e406ahrens	(void) fprintf(stderr, "\n");
154fa9e406ahrens
155ccba080Rich Morris	exit(1);
156fa9e406ahrens}
157fa9e406ahrens
158fa9e406ahrens/* ARGSUSED */
159fa9e406ahrensstatic void
160fa9e406ahrensdump_packed_nvlist(objset_t *os, uint64_t object, void *data, size_t size)
161fa9e406ahrens{
162fa9e406ahrens	nvlist_t *nv;
163fa9e406ahrens	size_t nvsize = *(uint64_t *)data;
164fa9e406ahrens	char *packed = umem_alloc(nvsize, UMEM_NOFAIL);
165fa9e406ahrens
1667bfdf01Neil Perrin	VERIFY(0 == dmu_read(os, object, 0, nvsize, packed, DMU_READ_PREFETCH));
167fa9e406ahrens
168fa9e406ahrens	VERIFY(nvlist_unpack(packed, nvsize, &nv, 0) == 0);
169fa9e406ahrens
170fa9e406ahrens	umem_free(packed, nvsize);
171fa9e406ahrens
172fa9e406ahrens	dump_nvlist(nv, 8);
173fa9e406ahrens
174fa9e406ahrens	nvlist_free(nv);
175fa9e406ahrens}
176fa9e406ahrens
177fa9e406ahrensconst char dump_zap_stars[] = "****************************************";
178fa9e406ahrensconst int dump_zap_width = sizeof (dump_zap_stars) - 1;
179fa9e406ahrens
180fa9e406ahrensstatic void
181fa9e406ahrensdump_zap_histogram(uint64_t histo[ZAP_HISTOGRAM_SIZE])
182fa9e406ahrens{
183fa9e406ahrens	int i;
184fa9e406ahrens	int minidx = ZAP_HISTOGRAM_SIZE - 1;
185fa9e406ahrens	int maxidx = 0;
186fa9e406ahrens	uint64_t max = 0;
187fa9e406ahrens
188fa9e406ahrens	for (i = 0; i < ZAP_HISTOGRAM_SIZE; i++) {
189fa9e406ahrens		if (histo[i] > max)
190fa9e406ahrens			max = histo[i];
191fa9e406ahrens		if (histo[i] > 0 && i > maxidx)
192fa9e406ahrens			maxidx = i;
193fa9e406ahrens		if (histo[i] > 0 && i < minidx)
194fa9e406ahrens			minidx = i;
195fa9e406ahrens	}
196fa9e406ahrens
197fa9e406ahrens	if (max < dump_zap_width)
198fa9e406ahrens		max = dump_zap_width;
199fa9e406ahrens
200fa9e406ahrens	for (i = minidx; i <= maxidx; i++)
201fa9e406ahrens		(void) printf("\t\t\t%u: %6llu %s\n", i, (u_longlong_t)histo[i],
202fa9e406ahrens		    &dump_zap_stars[(max - histo[i]) * dump_zap_width / max]);
203fa9e406ahrens}
204fa9e406ahrens
205fa9e406ahrensstatic void
206fa9e406ahrensdump_zap_stats(objset_t *os, uint64_t object)
207fa9e406ahrens{
208fa9e406ahrens	int error;
209fa9e406ahrens	zap_stats_t zs;
210fa9e406ahrens
211fa9e406ahrens	error = zap_get_stats(os, object, &zs);
212fa9e406ahrens	if (error)
213fa9e406ahrens		return;
214fa9e406ahrens
215fa9e406ahrens	if (zs.zs_ptrtbl_len == 0) {
216fa9e406ahrens		ASSERT(zs.zs_num_blocks == 1);
217fa9e406ahrens		(void) printf("\tmicrozap: %llu bytes, %llu entries\n",
218fa9e406ahrens		    (u_longlong_t)zs.zs_blocksize,
219fa9e406ahrens		    (u_longlong_t)zs.zs_num_entries);
220fa9e406ahrens		return;
221fa9e406ahrens	}
222fa9e406ahrens
223fa9e406ahrens	(void) printf("\tFat ZAP stats:\n");
2248248818nd
2258248818nd	(void) printf("\t\tPointer table:\n");
2268248818nd	(void) printf("\t\t\t%llu elements\n",
227fa9e406ahrens	    (u_longlong_t)zs.zs_ptrtbl_len);
2288248818nd	(void) printf("\t\t\tzt_blk: %llu\n",
2298248818nd	    (u_longlong_t)zs.zs_ptrtbl_zt_blk);
2308248818nd	(void) printf("\t\t\tzt_numblks: %llu\n",
2318248818nd	    (u_longlong_t)zs.zs_ptrtbl_zt_numblks);
2328248818nd	(void) printf("\t\t\tzt_shift: %llu\n",
2338248818nd	    (u_longlong_t)zs.zs_ptrtbl_zt_shift);
2348248818nd	(void) printf("\t\t\tzt_blks_copied: %llu\n",
2358248818nd	    (u_longlong_t)zs.zs_ptrtbl_blks_copied);
2368248818nd	(void) printf("\t\t\tzt_nextblk: %llu\n",
2378248818nd	    (u_longlong_t)zs.zs_ptrtbl_nextblk);
2388248818nd
239fa9e406ahrens	(void) printf("\t\tZAP entries: %llu\n",
240fa9e406ahrens	    (u_longlong_t)zs.zs_num_entries);
241fa9e406ahrens	(void) printf("\t\tLeaf blocks: %llu\n",
242fa9e406ahrens	    (u_longlong_t)zs.zs_num_leafs);
243fa9e406ahrens	(void) printf("\t\tTotal blocks: %llu\n",
244fa9e406ahrens	    (u_longlong_t)zs.zs_num_blocks);
2458248818nd	(void) printf("\t\tzap_block_type: 0x%llx\n",
2468248818nd	    (u_longlong_t)zs.zs_block_type);
2478248818nd	(void) printf("\t\tzap_magic: 0x%llx\n",
2488248818nd	    (u_longlong_t)zs.zs_magic);
2498248818nd	(void) printf("\t\tzap_salt: 0x%llx\n",
2508248818nd	    (u_longlong_t)zs.zs_salt);
251fa9e406ahrens
252fa9e406ahrens	(void) printf("\t\tLeafs with 2^n pointers:\n");
253fa9e406ahrens	dump_zap_histogram(zs.zs_leafs_with_2n_pointers);
254fa9e406ahrens
255fa9e406ahrens	(void) printf("\t\tBlocks with n*5 entries:\n");
256fa9e406ahrens	dump_zap_histogram(zs.zs_blocks_with_n5_entries);
257fa9e406ahrens
258fa9e406ahrens	(void) printf("\t\tBlocks n/10 full:\n");
259fa9e406ahrens	dump_zap_histogram(zs.zs_blocks_n_tenths_full);
260fa9e406ahrens
261fa9e406ahrens	(void) printf("\t\tEntries with n chunks:\n");
262fa9e406ahrens	dump_zap_histogram(zs.zs_entries_using_n_chunks);
263fa9e406ahrens
264fa9e406ahrens	(void) printf("\t\tBuckets with n entries:\n");
265fa9e406ahrens	dump_zap_histogram(zs.zs_buckets_with_n_entries);
266fa9e406ahrens}
267fa9e406ahrens
268fa9e406ahrens/*ARGSUSED*/
269fa9e406ahrensstatic void
270fa9e406ahrensdump_none(objset_t *os, uint64_t object, void *data, size_t size)
271fa9e406ahrens{
272fa9e406ahrens}
273fa9e406ahrens
274fa9e406ahrens/*ARGSUSED*/
275fa9e406ahrensvoid
276fa9e406ahrensdump_uint8(objset_t *os, uint64_t object, void *data, size_t size)
277fa9e406ahrens{
278fa9e406ahrens}
279fa9e406ahrens
280fa9e406ahrens/*ARGSUSED*/
281fa9e406ahrensstatic void
282fa9e406ahrensdump_uint64(objset_t *os, uint64_t object, void *data, size_t size)
283fa9e406ahrens{
284fa9e406ahrens}
285fa9e406ahrens
286fa9e406ahrens/*ARGSUSED*/
287fa9e406ahrensstatic void
288fa9e406ahrensdump_zap(objset_t *os, uint64_t object, void *data, size_t size)
289fa9e406ahrens{
290fa9e406ahrens	zap_cursor_t zc;
291fa9e406ahrens	zap_attribute_t attr;
292fa9e406ahrens	void *prop;
293fa9e406ahrens	int i;
294fa9e406ahrens
295fa9e406ahrens	dump_zap_stats(os, object);
296fa9e406ahrens	(void) printf("\n");
297fa9e406ahrens
298fa9e406ahrens	for (zap_cursor_init(&zc, os, object);
299fa9e406ahrens	    zap_cursor_retrieve(&zc, &attr) == 0;
300fa9e406ahrens	    zap_cursor_advance(&zc)) {
301fa9e406ahrens		(void) printf("\t\t%s = ", attr.za_name);
302fa9e406ahrens		if (attr.za_num_integers == 0) {
303fa9e406ahrens			(void) printf("\n");
304fa9e406ahrens			continue;
305fa9e406ahrens		}
306fa9e406ahrens		prop = umem_zalloc(attr.za_num_integers *
307fa9e406ahrens		    attr.za_integer_length, UMEM_NOFAIL);
308fa9e406ahrens		(void) zap_lookup(os, object, attr.za_name,
309fa9e406ahrens		    attr.za_integer_length, attr.za_num_integers, prop);
310fa9e406ahrens		if (attr.za_integer_length == 1) {
311fa9e406ahrens			(void) printf("%s", (char *)prop);
312fa9e406ahrens		} else {
313fa9e406ahrens			for (i = 0; i < attr.za_num_integers; i++) {
314fa9e406ahrens				switch (attr.za_integer_length) {
315fa9e406ahrens				case 2:
316fa9e406ahrens					(void) printf("%u ",
317fa9e406ahrens					    ((uint16_t *)prop)[i]);
318fa9e406ahrens					break;
319fa9e406ahrens				case 4:
320fa9e406ahrens					(void) printf("%u ",
321fa9e406ahrens					    ((uint32_t *)prop)[i]);
322fa9e406ahrens					break;
323fa9e406ahrens				case 8:
324fa9e406ahrens					(void) printf("%lld ",
325fa9e406ahrens					    (u_longlong_t)((int64_t *)prop)[i]);
326fa9e406ahrens					break;
327fa9e406ahrens				}
328fa9e406ahrens			}
329fa9e406ahrens		}
330fa9e406ahrens		(void) printf("\n");
331fa9e406ahrens		umem_free(prop, attr.za_num_integers * attr.za_integer_length);
332fa9e406ahrens	}
33387e5029ahrens	zap_cursor_fini(&zc);
334fa9e406ahrens}
335fa9e406ahrens
336e743726ahrens/*ARGSUSED*/
337e743726ahrensstatic void
338e743726ahrensdump_zpldir(objset_t *os, uint64_t object, void *data, size_t size)
339e743726ahrens{
340e743726ahrens	zap_cursor_t zc;
341e743726ahrens	zap_attribute_t attr;
342e743726ahrens	const char *typenames[] = {
343e743726ahrens		/* 0 */ "not specified",
344e743726ahrens		/* 1 */ "FIFO",
345e743726ahrens		/* 2 */ "Character Device",
346e743726ahrens		/* 3 */ "3 (invalid)",
347e743726ahrens		/* 4 */ "Directory",
348e743726ahrens		/* 5 */ "5 (invalid)",
349e743726ahrens		/* 6 */ "Block Device",
350e743726ahrens		/* 7 */ "7 (invalid)",
351e743726ahrens		/* 8 */ "Regular File",
352e743726ahrens		/* 9 */ "9 (invalid)",
353e743726ahrens		/* 10 */ "Symbolic Link",
354e743726ahrens		/* 11 */ "11 (invalid)",
355e743726ahrens		/* 12 */ "Socket",
356e743726ahrens		/* 13 */ "Door",
357e743726ahrens		/* 14 */ "Event Port",
358e743726ahrens		/* 15 */ "15 (invalid)",
359e743726ahrens	};
360e743726ahrens
361e743726ahrens	dump_zap_stats(os, object);
362e743726ahrens	(void) printf("\n");
363e743726ahrens
364e743726ahrens	for (zap_cursor_init(&zc, os, object);
365e743726ahrens	    zap_cursor_retrieve(&zc, &attr) == 0;
366e743726ahrens	    zap_cursor_advance(&zc)) {
367e743726ahrens		(void) printf("\t\t%s = %lld (type: %s)\n",
368e743726ahrens		    attr.za_name, ZFS_DIRENT_OBJ(attr.za_first_integer),
369e743726ahrens		    typenames[ZFS_DIRENT_TYPE(attr.za_first_integer)]);
370e743726ahrens	}
371e743726ahrens	zap_cursor_fini(&zc);
372e743726ahrens}
373e743726ahrens
374fa9e406ahrensstatic void
375fa9e406ahrensdump_spacemap(objset_t *os, space_map_obj_t *smo, space_map_t *sm)
376fa9e406ahrens{
377fa9e406ahrens	uint64_t alloc, offset, entry;
378ecc2d60bonwick	uint8_t mapshift = sm->sm_shift;
379fa9e406ahrens	uint64_t mapstart = sm->sm_start;
3808053a26ck	char *ddata[] = { "ALLOC", "FREE", "CONDENSE", "INVALID",
3818053a26ck			    "INVALID", "INVALID", "INVALID", "INVALID" };
382fa9e406ahrens
383fa9e406ahrens	if (smo->smo_object == 0)
384fa9e406ahrens		return;
385fa9e406ahrens
386fa9e406ahrens	/*
387fa9e406ahrens	 * Print out the freelist entries in both encoded and decoded form.
388fa9e406ahrens	 */
389fa9e406ahrens	alloc = 0;
390fa9e406ahrens	for (offset = 0; offset < smo->smo_objsize; offset += sizeof (entry)) {
391ea8dc4beschrock		VERIFY(0 == dmu_read(os, smo->smo_object, offset,
3927bfdf01Neil Perrin		    sizeof (entry), &entry, DMU_READ_PREFETCH));
393fa9e406ahrens		if (SM_DEBUG_DECODE(entry)) {
394fa9e406ahrens			(void) printf("\t\t[%4llu] %s: txg %llu, pass %llu\n",
395fa9e406ahrens			    (u_longlong_t)(offset / sizeof (entry)),
396fa9e406ahrens			    ddata[SM_DEBUG_ACTION_DECODE(entry)],
3975ad8204nd			    (u_longlong_t)SM_DEBUG_TXG_DECODE(entry),
3985ad8204nd			    (u_longlong_t)SM_DEBUG_SYNCPASS_DECODE(entry));
399fa9e406ahrens		} else {
400fa9e406ahrens			(void) printf("\t\t[%4llu]    %c  range:"
401fa9e406ahrens			    " %08llx-%08llx  size: %06llx\n",
402fa9e406ahrens			    (u_longlong_t)(offset / sizeof (entry)),
403fa9e406ahrens			    SM_TYPE_DECODE(entry) == SM_ALLOC ? 'A' : 'F',
4045ad8204nd			    (u_longlong_t)((SM_OFFSET_DECODE(entry) <<
4055ad8204nd			    mapshift) + mapstart),
4065ad8204nd			    (u_longlong_t)((SM_OFFSET_DECODE(entry) <<
4075ad8204nd			    mapshift) + mapstart + (SM_RUN_DECODE(entry) <<
4085ad8204nd			    mapshift)),
4095ad8204nd			    (u_longlong_t)(SM_RUN_DECODE(entry) << mapshift));
410fa9e406ahrens			if (SM_TYPE_DECODE(entry) == SM_ALLOC)
411fa9e406ahrens				alloc += SM_RUN_DECODE(entry) << mapshift;
412fa9e406ahrens			else
413fa9e406ahrens				alloc -= SM_RUN_DECODE(entry) << mapshift;
414fa9e406ahrens		}
415fa9e406ahrens	}
416fa9e406ahrens	if (alloc != smo->smo_alloc) {
417fa9e406ahrens		(void) printf("space_map_object alloc (%llu) INCONSISTENT "
418fa9e406ahrens		    "with space map summary (%llu)\n",
419fa9e406ahrens		    (u_longlong_t)smo->smo_alloc, (u_longlong_t)alloc);
420fa9e406ahrens	}
421fa9e406ahrens}
422fa9e406ahrens
423fa9e406ahrensstatic void
424d6e555bGeorge Wilsondump_metaslab_stats(metaslab_t *msp)
425d6e555bGeorge Wilson{
426d6e555bGeorge Wilson	char maxbuf[5];
427d6e555bGeorge Wilson	space_map_t *sm = &msp->ms_map;
428d6e555bGeorge Wilson	avl_tree_t *t = sm->sm_pp_root;
429d6e555bGeorge Wilson	int free_pct = sm->sm_space * 100 / sm->sm_size;
430d6e555bGeorge Wilson
431d6e555bGeorge Wilson	nicenum(space_map_maxsize(sm), maxbuf);
432d6e555bGeorge Wilson
433d6e555bGeorge Wilson	(void) printf("\t %20s %10lu   %7s  %6s   %4s %4d%%\n",
434d6e555bGeorge Wilson	    "segments", avl_numnodes(t), "maxsize", maxbuf,
435d6e555bGeorge Wilson	    "freepct", free_pct);
436d6e555bGeorge Wilson}
437d6e555bGeorge Wilson
438d6e555bGeorge Wilsonstatic void
439fa9e406ahrensdump_metaslab(metaslab_t *msp)
440fa9e406ahrens{
441fa9e406ahrens	char freebuf[5];
442ecc2d60bonwick	space_map_obj_t *smo = &msp->ms_smo;
443fa9e406ahrens	vdev_t *vd = msp->ms_group->mg_vd;
444fa9e406ahrens	spa_t *spa = vd->vdev_spa;
445fa9e406ahrens
446fa9e406ahrens	nicenum(msp->ms_map.sm_size - smo->smo_alloc, freebuf);
447fa9e406ahrens
448fa9e406ahrens	(void) printf(
449d6e555bGeorge Wilson	    "\tvdev %5llu   offset %12llx   spacemap %6llu   free    %5s\n",
450fa9e406ahrens	    (u_longlong_t)vd->vdev_id, (u_longlong_t)msp->ms_map.sm_start,
451fa9e406ahrens	    (u_longlong_t)smo->smo_object, freebuf);
452fa9e406ahrens
453d6e555bGeorge Wilson	if (dump_opt['m'] > 1) {
454d6e555bGeorge Wilson		mutex_enter(&msp->ms_lock);
455d6e555bGeorge Wilson		VERIFY(space_map_load(&msp->ms_map, zfs_metaslab_ops,
456d6e555bGeorge Wilson		    SM_FREE, &msp->ms_smo, spa->spa_meta_objset) == 0);
457d6e555bGeorge Wilson		dump_metaslab_stats(msp);
458d6e555bGeorge Wilson		space_map_unload(&msp->ms_map);
459d6e555bGeorge Wilson		mutex_exit(&msp->ms_lock);
460d6e555bGeorge Wilson	}
461d6e555bGeorge Wilson
462d6e555bGeorge Wilson	if (dump_opt['d'] > 5 || dump_opt['m'] > 2) {
463d6e555bGeorge Wilson		ASSERT(msp->ms_map.sm_size == (1ULL << vd->vdev_ms_shift));
464d6e555bGeorge Wilson
465d6e555bGeorge Wilson		mutex_enter(&msp->ms_lock);
466d6e555bGeorge Wilson		dump_spacemap(spa->spa_meta_objset, smo, &msp->ms_map);
467d6e555bGeorge Wilson		mutex_exit(&msp->ms_lock);
468d6e555bGeorge Wilson	}
469fa9e406ahrens
470fa9e406ahrens}
471fa9e406ahrens
472fa9e406ahrensstatic void
473fa9e406ahrensdump_metaslabs(spa_t *spa)
474fa9e406ahrens{
475fa9e406ahrens	vdev_t *rvd = spa->spa_root_vdev;
476fa9e406ahrens	vdev_t *vd;
477fa9e406ahrens	int c, m;
478fa9e406ahrens
479fa9e406ahrens	(void) printf("\nMetaslabs:\n");
480fa9e406ahrens
481fa9e406ahrens	for (c = 0; c < rvd->vdev_children; c++) {
482fa9e406ahrens		vd = rvd->vdev_child[c];
483fa9e406ahrens
484d6e555bGeorge Wilson		(void) printf("\t%-10s   %-19s   %-15s   %-10s\n",
485d6e555bGeorge Wilson		    "vdev", "offset", "spacemap", "free");
486d6e555bGeorge Wilson		(void) printf("\t%10s   %19s   %15s   %10s\n",
487d6e555bGeorge Wilson		    "----------", "-------------------",
488d6e555bGeorge Wilson		    "---------------", "-------------");
489fa9e406ahrens
490fa9e406ahrens		for (m = 0; m < vd->vdev_ms_count; m++)
491fa9e406ahrens			dump_metaslab(vd->vdev_ms[m]);
492fa9e406ahrens		(void) printf("\n");
493fa9e406ahrens	}
494fa9e406ahrens}
495fa9e406ahrens
496fa9e406ahrensstatic void
4978ad4d6dJeff Bonwickdump_dtl_seg(space_map_t *sm, uint64_t start, uint64_t size)
4988ad4d6dJeff Bonwick{
4998ad4d6dJeff Bonwick	char *prefix = (void *)sm;
5008ad4d6dJeff Bonwick
5018ad4d6dJeff Bonwick	(void) printf("%s [%llu,%llu) length %llu\n",
5028ad4d6dJeff Bonwick	    prefix,
5038ad4d6dJeff Bonwick	    (u_longlong_t)start,
5048ad4d6dJeff Bonwick	    (u_longlong_t)(start + size),
5058ad4d6dJeff Bonwick	    (u_longlong_t)(size));
5068ad4d6dJeff Bonwick}
5078ad4d6dJeff Bonwick
5088ad4d6dJeff Bonwickstatic void
509fa9e406ahrensdump_dtl(vdev_t *vd, int indent)
510fa9e406ahrens{
5118ad4d6dJeff Bonwick	spa_t *spa = vd->vdev_spa;
5128ad4d6dJeff Bonwick	boolean_t required;
5138ad4d6dJeff Bonwick	char *name[DTL_TYPES] = { "missing", "partial", "scrub", "outage" };
5148ad4d6dJeff Bonwick	char prefix[256];
5158ad4d6dJeff Bonwick
5168f18d1fGeorge Wilson	spa_vdev_state_enter(spa, SCL_NONE);
5178ad4d6dJeff Bonwick	required = vdev_dtl_required(vd);
5188ad4d6dJeff Bonwick	(void) spa_vdev_state_exit(spa, NULL, 0);
519fa9e406ahrens
520fa9e406ahrens	if (indent == 0)
521fa9e406ahrens		(void) printf("\nDirty time logs:\n\n");
522fa9e406ahrens
5238ad4d6dJeff Bonwick	(void) printf("\t%*s%s [%s]\n", indent, "",
524e14bb32Jeff Bonwick	    vd->vdev_path ? vd->vdev_path :
5258ad4d6dJeff Bonwick	    vd->vdev_parent ? vd->vdev_ops->vdev_op_type : spa_name(spa),
5268ad4d6dJeff Bonwick	    required ? "DTL-required" : "DTL-expendable");
527fa9e406ahrens
5288ad4d6dJeff Bonwick	for (int t = 0; t < DTL_TYPES; t++) {
5298ad4d6dJeff Bonwick		space_map_t *sm = &vd->vdev_dtl[t];
5308ad4d6dJeff Bonwick		if (sm->sm_space == 0)
5318ad4d6dJeff Bonwick			continue;
5328ad4d6dJeff Bonwick		(void) snprintf(prefix, sizeof (prefix), "\t%*s%s",
5338ad4d6dJeff Bonwick		    indent + 2, "", name[t]);
5348ad4d6dJeff Bonwick		mutex_enter(sm->sm_lock);
5358ad4d6dJeff Bonwick		space_map_walk(sm, dump_dtl_seg, (void *)prefix);
5368ad4d6dJeff Bonwick		mutex_exit(sm->sm_lock);
5378ad4d6dJeff Bonwick		if (dump_opt['d'] > 5 && vd->vdev_children == 0)
5388ad4d6dJeff Bonwick			dump_spacemap(spa->spa_meta_objset,
5398ad4d6dJeff Bonwick			    &vd->vdev_dtl_smo, sm);
540fa9e406ahrens	}
541fa9e406ahrens
5428ad4d6dJeff Bonwick	for (int c = 0; c < vd->vdev_children; c++)
543fa9e406ahrens		dump_dtl(vd->vdev_child[c], indent + 4);
544fa9e406ahrens}
545fa9e406ahrens
5468f18d1fGeorge Wilsonstatic void
5478f18d1fGeorge Wilsondump_history(spa_t *spa)
5488f18d1fGeorge Wilson{
5498f18d1fGeorge Wilson	nvlist_t **events = NULL;
5508f18d1fGeorge Wilson	char buf[SPA_MAXBLOCKSIZE];
551e4161dfVictor Latushkin	uint64_t resid, len, off = 0;
5528f18d1fGeorge Wilson	uint_t num = 0;
5538f18d1fGeorge Wilson	int error;
5548f18d1fGeorge Wilson	time_t tsec;
5558f18d1fGeorge Wilson	struct tm t;
5568f18d1fGeorge Wilson	char tbuf[30];
5578f18d1fGeorge Wilson	char internalstr[MAXPATHLEN];
5588f18d1fGeorge Wilson
5598f18d1fGeorge Wilson	do {
560e4161dfVictor Latushkin		len = sizeof (buf);
561e4161dfVictor Latushkin
5628f18d1fGeorge Wilson		if ((error = spa_history_get(spa, &off, &len, buf)) != 0) {
5638f18d1fGeorge Wilson			(void) fprintf(stderr, "Unable to read history: "
5648f18d1fGeorge Wilson			    "error %d\n", error);
5658f18d1fGeorge Wilson			return;
5668f18d1fGeorge Wilson		}
5678f18d1fGeorge Wilson
5688f18d1fGeorge Wilson		if (zpool_history_unpack(buf, len, &resid, &events, &num) != 0)
5698f18d1fGeorge Wilson			break;
5708f18d1fGeorge Wilson
5718f18d1fGeorge Wilson		off -= resid;
5728f18d1fGeorge Wilson	} while (len != 0);
5738f18d1fGeorge Wilson
5748f18d1fGeorge Wilson	(void) printf("\nHistory:\n");
5758f18d1fGeorge Wilson	for (int i = 0; i < num; i++) {
5768f18d1fGeorge Wilson		uint64_t time, txg, ievent;
5778f18d1fGeorge Wilson		char *cmd, *intstr;
5788f18d1fGeorge Wilson
5798f18d1fGeorge Wilson		if (nvlist_lookup_uint64(events[i], ZPOOL_HIST_TIME,
5808f18d1fGeorge Wilson		    &time) != 0)
5818f18d1fGeorge Wilson			continue;
5828f18d1fGeorge Wilson		if (nvlist_lookup_string(events[i], ZPOOL_HIST_CMD,
5838f18d1fGeorge Wilson		    &cmd) != 0) {
5848f18d1fGeorge Wilson			if (nvlist_lookup_uint64(events[i],
5858f18d1fGeorge Wilson			    ZPOOL_HIST_INT_EVENT, &ievent) != 0)
5868f18d1fGeorge Wilson				continue;
5878f18d1fGeorge Wilson			verify(nvlist_lookup_uint64(events[i],
5888f18d1fGeorge Wilson			    ZPOOL_HIST_TXG, &txg) == 0);
5898f18d1fGeorge Wilson			verify(nvlist_lookup_string(events[i],
5908f18d1fGeorge Wilson			    ZPOOL_HIST_INT_STR, &intstr) == 0);
5918f18d1fGeorge Wilson			if (ievent >= LOG_END)
5928f18d1fGeorge Wilson				continue;
5938f18d1fGeorge Wilson
5948f18d1fGeorge Wilson			(void) snprintf(internalstr,
5958f18d1fGeorge Wilson			    sizeof (internalstr),
5968f18d1fGeorge Wilson			    "[internal %s txg:%lld] %s",
5978f18d1fGeorge Wilson			    hist_event_table[ievent], txg,
5988f18d1fGeorge Wilson			    intstr);
5998f18d1fGeorge Wilson			cmd = internalstr;
6008f18d1fGeorge Wilson		}
6018f18d1fGeorge Wilson		tsec = time;
6028f18d1fGeorge Wilson		(void) localtime_r(&tsec, &t);
6038f18d1fGeorge Wilson		(void) strftime(tbuf, sizeof (tbuf), "%F.%T", &t);
6048f18d1fGeorge Wilson		(void) printf("%s %s\n", tbuf, cmd);
6058f18d1fGeorge Wilson	}
6068f18d1fGeorge Wilson}
6078f18d1fGeorge Wilson
608fa9e406ahrens/*ARGSUSED*/
609fa9e406ahrensstatic void
610fa9e406ahrensdump_dnode(objset_t *os, uint64_t object, void *data, size_t size)
611fa9e406ahrens{
612fa9e406ahrens}
613fa9e406ahrens
614fa9e406ahrensstatic uint64_t
61588b7b0fMatthew Ahrensblkid2offset(const dnode_phys_t *dnp, int level, uint64_t blkid)
616fa9e406ahrens{
617fa9e406ahrens	if (level < 0)
618fa9e406ahrens		return (blkid);
619fa9e406ahrens
620fa9e406ahrens	return ((blkid << (level * (dnp->dn_indblkshift - SPA_BLKPTRSHIFT))) *
621fa9e406ahrens	    dnp->dn_datablkszsec << SPA_MINBLOCKSHIFT);
622fa9e406ahrens}
623fa9e406ahrens
62444cd46cbillmstatic void
62544cd46cbillmsprintf_blkptr_compact(char *blkbuf, blkptr_t *bp, int alldvas)
62644cd46cbillm{
62744cd46cbillm	dva_t *dva = bp->blk_dva;
62844cd46cbillm	int ndvas = alldvas ? BP_GET_NDVAS(bp) : 1;
62944cd46cbillm	int i;
63044cd46cbillm
63144cd46cbillm	blkbuf[0] = '\0';
63244cd46cbillm
63344cd46cbillm	for (i = 0; i < ndvas; i++)
63444cd46cbillm		(void) sprintf(blkbuf + strlen(blkbuf), "%llu:%llx:%llx ",
63544cd46cbillm		    (u_longlong_t)DVA_GET_VDEV(&dva[i]),
63644cd46cbillm		    (u_longlong_t)DVA_GET_OFFSET(&dva[i]),
63744cd46cbillm		    (u_longlong_t)DVA_GET_ASIZE(&dva[i]));
63844cd46cbillm
63944cd46cbillm	(void) sprintf(blkbuf + strlen(blkbuf), "%llxL/%llxP F=%llu B=%llu",
64044cd46cbillm	    (u_longlong_t)BP_GET_LSIZE(bp),
64144cd46cbillm	    (u_longlong_t)BP_GET_PSIZE(bp),
64244cd46cbillm	    (u_longlong_t)bp->blk_fill,
64344cd46cbillm	    (u_longlong_t)bp->blk_birth);
64444cd46cbillm}
64544cd46cbillm
64688b7b0fMatthew Ahrensstatic void
64788b7b0fMatthew Ahrensprint_indirect(blkptr_t *bp, const zbookmark_t *zb,
64888b7b0fMatthew Ahrens    const dnode_phys_t *dnp)
649fa9e406ahrens{
65088b7b0fMatthew Ahrens	char blkbuf[BP_SPRINTF_LEN];
651fa9e406ahrens	int l;
652fa9e406ahrens
65388b7b0fMatthew Ahrens	ASSERT3U(BP_GET_TYPE(bp), ==, dnp->dn_type);
65488b7b0fMatthew Ahrens	ASSERT3U(BP_GET_LEVEL(bp), ==, zb->zb_level);
655fa9e406ahrens
65688b7b0fMatthew Ahrens	(void) printf("%16llx ",
657fa9e406ahrens	    (u_longlong_t)blkid2offset(dnp, zb->zb_level, zb->zb_blkid));
658fa9e406ahrens
659fa9e406ahrens	ASSERT(zb->zb_level >= 0);
660fa9e406ahrens
661fa9e406ahrens	for (l = dnp->dn_nlevels - 1; l >= -1; l--) {
662fa9e406ahrens		if (l == zb->zb_level) {
66388b7b0fMatthew Ahrens			(void) printf("L%llx", (u_longlong_t)zb->zb_level);
664fa9e406ahrens		} else {
66588b7b0fMatthew Ahrens			(void) printf(" ");
666fa9e406ahrens		}
667fa9e406ahrens	}
668fa9e406ahrens
66988b7b0fMatthew Ahrens	sprintf_blkptr_compact(blkbuf, bp, dump_opt['d'] > 5 ? 1 : 0);
67088b7b0fMatthew Ahrens	(void) printf("%s\n", blkbuf);
67188b7b0fMatthew Ahrens}
67288b7b0fMatthew Ahrens
67388b7b0fMatthew Ahrens#define	SET_BOOKMARK(zb, objset, object, level, blkid)  \
67488b7b0fMatthew Ahrens{                                                       \
67588b7b0fMatthew Ahrens	(zb)->zb_objset = objset;                       \
67688b7b0fMatthew Ahrens	(zb)->zb_object = object;                       \
67788b7b0fMatthew Ahrens	(zb)->zb_level = level;                         \
67888b7b0fMatthew Ahrens	(zb)->zb_blkid = blkid;                         \
67988b7b0fMatthew Ahrens}
68088b7b0fMatthew Ahrens
68188b7b0fMatthew Ahrensstatic int
68288b7b0fMatthew Ahrensvisit_indirect(spa_t *spa, const dnode_phys_t *dnp,
68388b7b0fMatthew Ahrens    blkptr_t *bp, const zbookmark_t *zb)
68488b7b0fMatthew Ahrens{
685e4161dfVictor Latushkin	int err = 0;
68688b7b0fMatthew Ahrens
68788b7b0fMatthew Ahrens	if (bp->blk_birth == 0)
68888b7b0fMatthew Ahrens		return (0);
68988b7b0fMatthew Ahrens
69088b7b0fMatthew Ahrens	print_indirect(bp, zb, dnp);
69188b7b0fMatthew Ahrens
69288b7b0fMatthew Ahrens	if (BP_GET_LEVEL(bp) > 0) {
69388b7b0fMatthew Ahrens		uint32_t flags = ARC_WAIT;
69488b7b0fMatthew Ahrens		int i;
69588b7b0fMatthew Ahrens		blkptr_t *cbp;
69688b7b0fMatthew Ahrens		int epb = BP_GET_LSIZE(bp) >> SPA_BLKPTRSHIFT;
69788b7b0fMatthew Ahrens		arc_buf_t *buf;
69888b7b0fMatthew Ahrens		uint64_t fill = 0;
69988b7b0fMatthew Ahrens
70088b7b0fMatthew Ahrens		err = arc_read_nolock(NULL, spa, bp, arc_getbuf_func, &buf,
70188b7b0fMatthew Ahrens		    ZIO_PRIORITY_ASYNC_READ, ZIO_FLAG_CANFAIL, &flags, zb);
70288b7b0fMatthew Ahrens		if (err)
70388b7b0fMatthew Ahrens			return (err);
70488b7b0fMatthew Ahrens
70588b7b0fMatthew Ahrens		/* recursively visit blocks below this */
70688b7b0fMatthew Ahrens		cbp = buf->b_data;
70788b7b0fMatthew Ahrens		for (i = 0; i < epb; i++, cbp++) {
70888b7b0fMatthew Ahrens			zbookmark_t czb;
70988b7b0fMatthew Ahrens
71088b7b0fMatthew Ahrens			SET_BOOKMARK(&czb, zb->zb_objset, zb->zb_object,
71188b7b0fMatthew Ahrens			    zb->zb_level - 1,
71288b7b0fMatthew Ahrens			    zb->zb_blkid * epb + i);
71388b7b0fMatthew Ahrens			err = visit_indirect(spa, dnp, cbp, &czb);
71488b7b0fMatthew Ahrens			if (err)
71588b7b0fMatthew Ahrens				break;
71688b7b0fMatthew Ahrens			fill += cbp->blk_fill;
71788b7b0fMatthew Ahrens		}
7188ad4d6dJeff Bonwick		if (!err)
7198ad4d6dJeff Bonwick			ASSERT3U(fill, ==, bp->blk_fill);
72088b7b0fMatthew Ahrens		(void) arc_buf_remove_ref(buf, &buf);
721fa9e406ahrens	}
722fa9e406ahrens
72388b7b0fMatthew Ahrens	return (err);
724fa9e406ahrens}
725fa9e406ahrens
726fa9e406ahrens/*ARGSUSED*/
727fa9e406ahrensstatic void
72888b7b0fMatthew Ahrensdump_indirect(dnode_t *dn)
729fa9e406ahrens{
73088b7b0fMatthew Ahrens	dnode_phys_t *dnp = dn->dn_phys;
73188b7b0fMatthew Ahrens	int j;
73288b7b0fMatthew Ahrens	zbookmark_t czb;
733fa9e406ahrens
734fa9e406ahrens	(void) printf("Indirect blocks:\n");
735fa9e406ahrens
736503ad85Matthew Ahrens	SET_BOOKMARK(&czb, dmu_objset_id(dn->dn_objset),
73788b7b0fMatthew Ahrens	    dn->dn_object, dnp->dn_nlevels - 1, 0);
73888b7b0fMatthew Ahrens	for (j = 0; j < dnp->dn_nblkptr; j++) {
73988b7b0fMatthew Ahrens		czb.zb_blkid = j;
740503ad85Matthew Ahrens		(void) visit_indirect(dmu_objset_spa(dn->dn_objset), dnp,
74188b7b0fMatthew Ahrens		    &dnp->dn_blkptr[j], &czb);
74288b7b0fMatthew Ahrens	}
743fa9e406ahrens
744fa9e406ahrens	(void) printf("\n");
745fa9e406ahrens}
746fa9e406ahrens
747fa9e406ahrens/*ARGSUSED*/
748fa9e406ahrensstatic void
749fa9e406ahrensdump_dsl_dir(objset_t *os, uint64_t object, void *data, size_t size)
750fa9e406ahrens{
751fa9e406ahrens	dsl_dir_phys_t *dd = data;
752fa9e406ahrens	time_t crtime;
75374e7dc9Matthew Ahrens	char nice[6];
754fa9e406ahrens
755fa9e406ahrens	if (dd == NULL)
756fa9e406ahrens		return;
757fa9e406ahrens
758da6c28aamw	ASSERT3U(size, >=, sizeof (dsl_dir_phys_t));
759fa9e406ahrens
760fa9e406ahrens	crtime = dd->dd_creation_time;
761fa9e406ahrens	(void) printf("\t\tcreation_time = %s", ctime(&crtime));
762fa9e406ahrens	(void) printf("\t\thead_dataset_obj = %llu\n",
763fa9e406ahrens	    (u_longlong_t)dd->dd_head_dataset_obj);
764fa9e406ahrens	(void) printf("\t\tparent_dir_obj = %llu\n",
765fa9e406ahrens	    (u_longlong_t)dd->dd_parent_obj);
7663cb34c6ahrens	(void) printf("\t\torigin_obj = %llu\n",
7673cb34c6ahrens	    (u_longlong_t)dd->dd_origin_obj);
768fa9e406ahrens	(void) printf("\t\tchild_dir_zapobj = %llu\n",
769fa9e406ahrens	    (u_longlong_t)dd->dd_child_dir_zapobj);
77074e7dc9Matthew Ahrens	nicenum(dd->dd_used_bytes, nice);
77174e7dc9Matthew Ahrens	(void) printf("\t\tused_bytes = %s\n", nice);
77274e7dc9Matthew Ahrens	nicenum(dd->dd_compressed_bytes, nice);
77374e7dc9Matthew Ahrens	(void) printf("\t\tcompressed_bytes = %s\n", nice);
77474e7dc9Matthew Ahrens	nicenum(dd->dd_uncompressed_bytes, nice);
77574e7dc9Matthew Ahrens	(void) printf("\t\tuncompressed_bytes = %s\n", nice);
77674e7dc9Matthew Ahrens	nicenum(dd->dd_quota, nice);
77774e7dc9Matthew Ahrens	(void) printf("\t\tquota = %s\n", nice);
77874e7dc9Matthew Ahrens	nicenum(dd->dd_reserved, nice);
77974e7dc9Matthew Ahrens	(void) printf("\t\treserved = %s\n", nice);
780fa9e406ahrens	(void) printf("\t\tprops_zapobj = %llu\n",
781fa9e406ahrens	    (u_longlong_t)dd->dd_props_zapobj);
782ecd6cf8marks	(void) printf("\t\tdeleg_zapobj = %llu\n",
783ecd6cf8marks	    (u_longlong_t)dd->dd_deleg_zapobj);
78474e7dc9Matthew Ahrens	(void) printf("\t\tflags = %llx\n",
78574e7dc9Matthew Ahrens	    (u_longlong_t)dd->dd_flags);
78674e7dc9Matthew Ahrens
78774e7dc9Matthew Ahrens#define	DO(which) \
78874e7dc9Matthew Ahrens	nicenum(dd->dd_used_breakdown[DD_USED_ ## which], nice); \
78974e7dc9Matthew Ahrens	(void) printf("\t\tused_breakdown[" #which "] = %s\n", nice)
79074e7dc9Matthew Ahrens	DO(HEAD);
79174e7dc9Matthew Ahrens	DO(SNAP);
79274e7dc9Matthew Ahrens	DO(CHILD);
79374e7dc9Matthew Ahrens	DO(CHILD_RSRV);
79474e7dc9Matthew Ahrens	DO(REFRSRV);
79574e7dc9Matthew Ahrens#undef DO
796fa9e406ahrens}
797fa9e406ahrens
798fa9e406ahrens/*ARGSUSED*/
799fa9e406ahrensstatic void
800fa9e406ahrensdump_dsl_dataset(objset_t *os, uint64_t object, void *data, size_t size)
801fa9e406ahrens{
802fa9e406ahrens	dsl_dataset_phys_t *ds = data;
803fa9e406ahrens	time_t crtime;
804fbabab8maybee	char used[6], compressed[6], uncompressed[6], unique[6];
805fbabab8maybee	char blkbuf[BP_SPRINTF_LEN];
806fa9e406ahrens
807fa9e406ahrens	if (ds == NULL)
808fa9e406ahrens		return;
809fa9e406ahrens
810fa9e406ahrens	ASSERT(size == sizeof (*ds));
811fa9e406ahrens	crtime = ds->ds_creation_time;
812fa9e406ahrens	nicenum(ds->ds_used_bytes, used);
813fa9e406ahrens	nicenum(ds->ds_compressed_bytes, compressed);
814fa9e406ahrens	nicenum(ds->ds_uncompressed_bytes, uncompressed);
815fa9e406ahrens	nicenum(ds->ds_unique_bytes, unique);
816fbabab8maybee	sprintf_blkptr(blkbuf, BP_SPRINTF_LEN, &ds->ds_bp);
817fa9e406ahrens
818088f389ahrens	(void) printf("\t\tdir_obj = %llu\n",
819fa9e406ahrens	    (u_longlong_t)ds->ds_dir_obj);
820fa9e406ahrens	(void) printf("\t\tprev_snap_obj = %llu\n",
821fa9e406ahrens	    (u_longlong_t)ds->ds_prev_snap_obj);
822fa9e406ahrens	(void) printf("\t\tprev_snap_txg = %llu\n",
823fa9e406ahrens	    (u_longlong_t)ds->ds_prev_snap_txg);
824fa9e406ahrens	(void) printf("\t\tnext_snap_obj = %llu\n",
825fa9e406ahrens	    (u_longlong_t)ds->ds_next_snap_obj);
826fa9e406ahrens	(void) printf("\t\tsnapnames_zapobj = %llu\n",
827fa9e406ahrens	    (u_longlong_t)ds->ds_snapnames_zapobj);
828fa9e406ahrens	(void) printf("\t\tnum_children = %llu\n",
829fa9e406ahrens	    (u_longlong_t)ds->ds_num_children);
830842727cChris Kirby	(void) printf("\t\tuserrefs_obj = %llu\n",
831842727cChris Kirby	    (u_longlong_t)ds->ds_userrefs_obj);
832fa9e406ahrens	(void) printf("\t\tcreation_time = %s", ctime(&crtime));
833fa9e406ahrens	(void) printf("\t\tcreation_txg = %llu\n",
834fa9e406ahrens	    (u_longlong_t)ds->ds_creation_txg);
835fa9e406ahrens	(void) printf("\t\tdeadlist_obj = %llu\n",
836fa9e406ahrens	    (u_longlong_t)ds->ds_deadlist_obj);
837fa9e406ahrens	(void) printf("\t\tused_bytes = %s\n", used);
838fa9e406ahrens	(void) printf("\t\tcompressed_bytes = %s\n", compressed);
839fa9e406ahrens	(void) printf("\t\tuncompressed_bytes = %s\n", uncompressed);
840fa9e406ahrens	(void) printf("\t\tunique = %s\n", unique);
841fa9e406ahrens	(void) printf("\t\tfsid_guid = %llu\n",
842fa9e406ahrens	    (u_longlong_t)ds->ds_fsid_guid);
843fa9e406ahrens	(void) printf("\t\tguid = %llu\n",
844fa9e406ahrens	    (u_longlong_t)ds->ds_guid);
84599653d4eschrock	(void) printf("\t\tflags = %llx\n",
84699653d4eschrock	    (u_longlong_t)ds->ds_flags);
847088f389ahrens	(void) printf("\t\tnext_clones_obj = %llu\n",
848088f389ahrens	    (u_longlong_t)ds->ds_next_clones_obj);
849bb0ade0ahrens	(void) printf("\t\tprops_obj = %llu\n",
850bb0ade0ahrens	    (u_longlong_t)ds->ds_props_obj);
851fa9e406ahrens	(void) printf("\t\tbp = %s\n", blkbuf);
852fa9e406ahrens}
853fa9e406ahrens
854fa9e406ahrensstatic void
855fa9e406ahrensdump_bplist(objset_t *mos, uint64_t object, char *name)
856fa9e406ahrens{
857fa9e406ahrens	bplist_t bpl = { 0 };
858fa9e406ahrens	blkptr_t blk, *bp = &blk;
859fa9e406ahrens	uint64_t itor = 0;
86099653d4eschrock	char bytes[6];
86199653d4eschrock	char comp[6];
86299653d4eschrock	char uncomp[6];
863fa9e406ahrens
864fa9e406ahrens	if (dump_opt['d'] < 3)
865fa9e406ahrens		return;
866fa9e406ahrens
867c25056dgw	mutex_init(&bpl.bpl_lock, NULL, MUTEX_DEFAULT, NULL);
868ea8dc4beschrock	VERIFY(0 == bplist_open(&bpl, mos, object));
869fa9e406ahrens	if (bplist_empty(&bpl)) {
870fa9e406ahrens		bplist_close(&bpl);
871c25056dgw		mutex_destroy(&bpl.bpl_lock);
872fa9e406ahrens		return;
873fa9e406ahrens	}
874fa9e406ahrens
87599653d4eschrock	nicenum(bpl.bpl_phys->bpl_bytes, bytes);
87699653d4eschrock	if (bpl.bpl_dbuf->db_size == sizeof (bplist_phys_t)) {
87799653d4eschrock		nicenum(bpl.bpl_phys->bpl_comp, comp);
87899653d4eschrock		nicenum(bpl.bpl_phys->bpl_uncomp, uncomp);
87999653d4eschrock		(void) printf("\n    %s: %llu entries, %s (%s/%s comp)\n",
88099653d4eschrock		    name, (u_longlong_t)bpl.bpl_phys->bpl_entries,
88199653d4eschrock		    bytes, comp, uncomp);
88299653d4eschrock	} else {
88399653d4eschrock		(void) printf("\n    %s: %llu entries, %s\n",
88499653d4eschrock		    name, (u_longlong_t)bpl.bpl_phys->bpl_entries, bytes);
88599653d4eschrock	}
886fa9e406ahrens
887fa9e406ahrens	if (dump_opt['d'] < 5) {
888fa9e406ahrens		bplist_close(&bpl);
889c25056dgw		mutex_destroy(&bpl.bpl_lock);
890fa9e406ahrens		return;
891fa9e406ahrens	}
892fa9e406ahrens
893fa9e406ahrens	(void) printf("\n");
894fa9e406ahrens
895fa9e406ahrens	while (bplist_iterate(&bpl, &itor, bp) == 0) {
89644cd46cbillm		char blkbuf[BP_SPRINTF_LEN];
89744cd46cbillm
898