zdb.c revision 07428bdfb7bca7c9e74959692785555ea5e27ce2
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
586de8f41Victor Latushkin#define	ZDB_COMPRESS_NAME(idx) ((idx) < ZIO_COMPRESS_FUNCTIONS ? \
596de8f41Victor Latushkin    zio_compress_table[(idx)].ci_name : "UNKNOWN")
606de8f41Victor Latushkin#define	ZDB_CHECKSUM_NAME(idx) ((idx) < ZIO_CHECKSUM_FUNCTIONS ? \
616de8f41Victor Latushkin    zio_checksum_table[(idx)].ci_name : "UNKNOWN")
626de8f41Victor Latushkin#define	ZDB_OT_NAME(idx) ((idx) < DMU_OT_NUMTYPES ? \
636de8f41Victor Latushkin    dmu_ot[(idx)].ot_name : "UNKNOWN")
646de8f41Victor Latushkin#define	ZDB_OT_TYPE(idx) ((idx) < DMU_OT_NUMTYPES ? (idx) : DMU_OT_NUMTYPES)
656de8f41Victor Latushkin
66fa9e406ahrensconst char cmdname[] = "zdb";
67fa9e406ahrensuint8_t dump_opt[256];
68fa9e406ahrens
69fa9e406ahrenstypedef void object_viewer_t(objset_t *, uint64_t, void *data, size_t size);
70fa9e406ahrens
71fa9e406ahrensextern void dump_intent_log(zilog_t *);
72fa9e406ahrensuint64_t *zopt_object = NULL;
73fa9e406ahrensint zopt_objects = 0;
74de6628fcklibzfs_handle_t *g_zfs;
75d41e764ekboolean_t zdb_sig_user_data = B_TRUE;
76d41e764ekint zdb_sig_cksumalg = ZIO_CHECKSUM_SHA256;
77fa9e406ahrens
78fa9e406ahrens/*
79fa9e406ahrens * These libumem hooks provide a reasonable set of defaults for the allocator's
80fa9e406ahrens * debugging facilities.
81fa9e406ahrens */
82fa9e406ahrensconst char *
83fa9e406ahrens_umem_debug_init()
84fa9e406ahrens{
85fa9e406ahrens	return ("default,verbose"); /* $UMEM_DEBUG setting */
86fa9e406ahrens}
87fa9e406ahrens
88fa9e406ahrensconst char *
89fa9e406ahrens_umem_logging_init(void)
90fa9e406ahrens{
91fa9e406ahrens	return ("fail,contents"); /* $UMEM_LOGGING setting */
92fa9e406ahrens}
93fa9e406ahrens
94fa9e406ahrensstatic void
95fa9e406ahrensusage(void)
96fa9e406ahrens{
97fa9e406ahrens	(void) fprintf(stderr,
983ad6c7fVictor Latushkin	    "Usage: %s [-CumdibcsvhL] [-S user:cksumalg] "
993ad6c7fVictor Latushkin	    "poolname [object...]\n"
1003ad6c7fVictor Latushkin	    "       %s [-div] dataset [object...]\n"
10107428bdVictor Latushkin	    "       %s -R poolname vdev:offset:size[:flags]\n"
10207428bdVictor Latushkin	    "       %s -l device\n"
10307428bdVictor Latushkin	    "       %s -C\n\n",
1043ad6c7fVictor Latushkin	    cmdname, cmdname, cmdname, cmdname, cmdname);
1053ad6c7fVictor Latushkin
1063ad6c7fVictor Latushkin	(void) fprintf(stderr, "    Dataset name must include at least one "
1073ad6c7fVictor Latushkin	    "separator character '/' or '@'\n");
1083ad6c7fVictor Latushkin	(void) fprintf(stderr, "    If dataset name is specified, only that "
1093ad6c7fVictor Latushkin	    "dataset is dumped\n");
1103ad6c7fVictor Latushkin	(void) fprintf(stderr, "    If object numbers are specified, only "
1113ad6c7fVictor Latushkin	    "those objects are dumped\n\n");
1123ad6c7fVictor Latushkin	(void) fprintf(stderr, "    Options to control amount of output:\n");
1133ad6c7fVictor Latushkin	(void) fprintf(stderr, "        -u uberblock\n");
1143ad6c7fVictor Latushkin	(void) fprintf(stderr, "        -d dataset(s)\n");
1153ad6c7fVictor Latushkin	(void) fprintf(stderr, "        -i intent logs\n");
11607428bdVictor Latushkin	(void) fprintf(stderr, "        -C config (or cachefile if alone)\n");
1178f18d1fGeorge Wilson	(void) fprintf(stderr, "        -h pool history\n");
1183ad6c7fVictor Latushkin	(void) fprintf(stderr, "        -b block statistics\n");
1193ad6c7fVictor Latushkin	(void) fprintf(stderr, "        -m metaslabs\n");
1203ad6c7fVictor Latushkin	(void) fprintf(stderr, "        -c checksum all metadata (twice for "
1216365109Victor Latushkin	    "all data) blocks\n");
1223ad6c7fVictor Latushkin	(void) fprintf(stderr, "        -s report stats on zdb's I/O\n");
1233ad6c7fVictor Latushkin	(void) fprintf(stderr, "        -S <user|all>:<cksum_alg|all> -- "
124d41e764ek	    "dump blkptr signatures\n");
1253ad6c7fVictor Latushkin	(void) fprintf(stderr, "        -v verbose (applies to all others)\n");
126fa9e406ahrens	(void) fprintf(stderr, "        -l dump label contents\n");
12782a0a98Victor Latushkin	(void) fprintf(stderr, "        -L disable leak tracking (do not "
12882a0a98Victor Latushkin	    "load spacemaps)\n");
129d41e764ek	(void) fprintf(stderr, "        -R read and display block from a "
1303ad6c7fVictor Latushkin	    "device\n\n");
1313ad6c7fVictor Latushkin	(void) fprintf(stderr, "    Below options are intended for use "
1323ad6c7fVictor Latushkin	    "with other options (except -l):\n");
1333ad6c7fVictor Latushkin	(void) fprintf(stderr, "        -U <cachefile_path> -- use alternate "
1343ad6c7fVictor Latushkin	    "cachefile\n");
1353ad6c7fVictor Latushkin	(void) fprintf(stderr, "        -e pool is exported/destroyed/"
1363ad6c7fVictor Latushkin	    "has altroot/not in a cachefile\n");
1373ad6c7fVictor Latushkin	(void) fprintf(stderr, "        -p <path> -- use one or more with "
1383ad6c7fVictor Latushkin	    "-e to specify path to vdev dir\n");
1393ad6c7fVictor Latushkin	(void) fprintf(stderr, "        -t <txg> -- highest txg to use when "
1402e55192Victor Latushkin	    "searching for uberblocks\n");
141fa9e406ahrens	(void) fprintf(stderr, "Specify an option more than once (e.g. -bb) "
142fa9e406ahrens	    "to make only that option verbose\n");
143fa9e406ahrens	(void) fprintf(stderr, "Default is to dump everything non-verbosely\n");
144fa9e406ahrens	exit(1);
145fa9e406ahrens}
146fa9e406ahrens
147ccba080Rich Morris/*
148ccba080Rich Morris * Called for usage errors that are discovered after a call to spa_open(),
149ccba080Rich Morris * dmu_bonus_hold(), or pool_match().  abort() is called for other errors.
150ccba080Rich Morris */
151ccba080Rich Morris
152fa9e406ahrensstatic void
153fa9e406ahrensfatal(const char *fmt, ...)
154fa9e406ahrens{
155fa9e406ahrens	va_list ap;
156fa9e406ahrens
157fa9e406ahrens	va_start(ap, fmt);
158fa9e406ahrens	(void) fprintf(stderr, "%s: ", cmdname);
159fa9e406ahrens	(void) vfprintf(stderr, fmt, ap);
160fa9e406ahrens	va_end(ap);
161fa9e406ahrens	(void) fprintf(stderr, "\n");
162fa9e406ahrens
163ccba080Rich Morris	exit(1);
164fa9e406ahrens}
165fa9e406ahrens
166fa9e406ahrens/* ARGSUSED */
167fa9e406ahrensstatic void
168fa9e406ahrensdump_packed_nvlist(objset_t *os, uint64_t object, void *data, size_t size)
169fa9e406ahrens{
170fa9e406ahrens	nvlist_t *nv;
171fa9e406ahrens	size_t nvsize = *(uint64_t *)data;
172fa9e406ahrens	char *packed = umem_alloc(nvsize, UMEM_NOFAIL);
173fa9e406ahrens
1747bfdf01Neil Perrin	VERIFY(0 == dmu_read(os, object, 0, nvsize, packed, DMU_READ_PREFETCH));
175fa9e406ahrens
176fa9e406ahrens	VERIFY(nvlist_unpack(packed, nvsize, &nv, 0) == 0);
177fa9e406ahrens
178fa9e406ahrens	umem_free(packed, nvsize);
179fa9e406ahrens
180fa9e406ahrens	dump_nvlist(nv, 8);
181fa9e406ahrens
182fa9e406ahrens	nvlist_free(nv);
183fa9e406ahrens}
184fa9e406ahrens
185fa9e406ahrensconst char dump_zap_stars[] = "****************************************";
186fa9e406ahrensconst int dump_zap_width = sizeof (dump_zap_stars) - 1;
187fa9e406ahrens
188fa9e406ahrensstatic void
189fa9e406ahrensdump_zap_histogram(uint64_t histo[ZAP_HISTOGRAM_SIZE])
190fa9e406ahrens{
191fa9e406ahrens	int i;
192fa9e406ahrens	int minidx = ZAP_HISTOGRAM_SIZE - 1;
193fa9e406ahrens	int maxidx = 0;
194fa9e406ahrens	uint64_t max = 0;
195fa9e406ahrens
196fa9e406ahrens	for (i = 0; i < ZAP_HISTOGRAM_SIZE; i++) {
197fa9e406ahrens		if (histo[i] > max)
198fa9e406ahrens			max = histo[i];
199fa9e406ahrens		if (histo[i] > 0 && i > maxidx)
200fa9e406ahrens			maxidx = i;
201fa9e406ahrens		if (histo[i] > 0 && i < minidx)
202fa9e406ahrens			minidx = i;
203fa9e406ahrens	}
204fa9e406ahrens
205fa9e406ahrens	if (max < dump_zap_width)
206fa9e406ahrens		max = dump_zap_width;
207fa9e406ahrens
208fa9e406ahrens	for (i = minidx; i <= maxidx; i++)
209fa9e406ahrens		(void) printf("\t\t\t%u: %6llu %s\n", i, (u_longlong_t)histo[i],
210fa9e406ahrens		    &dump_zap_stars[(max - histo[i]) * dump_zap_width / max]);
211fa9e406ahrens}
212fa9e406ahrens
213fa9e406ahrensstatic void
214fa9e406ahrensdump_zap_stats(objset_t *os, uint64_t object)
215fa9e406ahrens{
216fa9e406ahrens	int error;
217fa9e406ahrens	zap_stats_t zs;
218fa9e406ahrens
219fa9e406ahrens	error = zap_get_stats(os, object, &zs);
220fa9e406ahrens	if (error)
221fa9e406ahrens		return;
222fa9e406ahrens
223fa9e406ahrens	if (zs.zs_ptrtbl_len == 0) {
224fa9e406ahrens		ASSERT(zs.zs_num_blocks == 1);
225fa9e406ahrens		(void) printf("\tmicrozap: %llu bytes, %llu entries\n",
226fa9e406ahrens		    (u_longlong_t)zs.zs_blocksize,
227fa9e406ahrens		    (u_longlong_t)zs.zs_num_entries);
228fa9e406ahrens		return;
229fa9e406ahrens	}
230fa9e406ahrens
231fa9e406ahrens	(void) printf("\tFat ZAP stats:\n");
2328248818nd
2338248818nd	(void) printf("\t\tPointer table:\n");
2348248818nd	(void) printf("\t\t\t%llu elements\n",
235fa9e406ahrens	    (u_longlong_t)zs.zs_ptrtbl_len);
2368248818nd	(void) printf("\t\t\tzt_blk: %llu\n",
2378248818nd	    (u_longlong_t)zs.zs_ptrtbl_zt_blk);
2388248818nd	(void) printf("\t\t\tzt_numblks: %llu\n",
2398248818nd	    (u_longlong_t)zs.zs_ptrtbl_zt_numblks);
2408248818nd	(void) printf("\t\t\tzt_shift: %llu\n",
2418248818nd	    (u_longlong_t)zs.zs_ptrtbl_zt_shift);
2428248818nd	(void) printf("\t\t\tzt_blks_copied: %llu\n",
2438248818nd	    (u_longlong_t)zs.zs_ptrtbl_blks_copied);
2448248818nd	(void) printf("\t\t\tzt_nextblk: %llu\n",
2458248818nd	    (u_longlong_t)zs.zs_ptrtbl_nextblk);
2468248818nd
247fa9e406ahrens	(void) printf("\t\tZAP entries: %llu\n",
248fa9e406ahrens	    (u_longlong_t)zs.zs_num_entries);
249fa9e406ahrens	(void) printf("\t\tLeaf blocks: %llu\n",
250fa9e406ahrens	    (u_longlong_t)zs.zs_num_leafs);
251fa9e406ahrens	(void) printf("\t\tTotal blocks: %llu\n",
252fa9e406ahrens	    (u_longlong_t)zs.zs_num_blocks);
2538248818nd	(void) printf("\t\tzap_block_type: 0x%llx\n",
2548248818nd	    (u_longlong_t)zs.zs_block_type);
2558248818nd	(void) printf("\t\tzap_magic: 0x%llx\n",
2568248818nd	    (u_longlong_t)zs.zs_magic);
2578248818nd	(void) printf("\t\tzap_salt: 0x%llx\n",
2588248818nd	    (u_longlong_t)zs.zs_salt);
259fa9e406ahrens
260fa9e406ahrens	(void) printf("\t\tLeafs with 2^n pointers:\n");
261fa9e406ahrens	dump_zap_histogram(zs.zs_leafs_with_2n_pointers);
262fa9e406ahrens
263fa9e406ahrens	(void) printf("\t\tBlocks with n*5 entries:\n");
264fa9e406ahrens	dump_zap_histogram(zs.zs_blocks_with_n5_entries);
265fa9e406ahrens
266fa9e406ahrens	(void) printf("\t\tBlocks n/10 full:\n");
267fa9e406ahrens	dump_zap_histogram(zs.zs_blocks_n_tenths_full);
268fa9e406ahrens
269fa9e406ahrens	(void) printf("\t\tEntries with n chunks:\n");
270fa9e406ahrens	dump_zap_histogram(zs.zs_entries_using_n_chunks);
271fa9e406ahrens
272fa9e406ahrens	(void) printf("\t\tBuckets with n entries:\n");
273fa9e406ahrens	dump_zap_histogram(zs.zs_buckets_with_n_entries);
274fa9e406ahrens}
275fa9e406ahrens
276fa9e406ahrens/*ARGSUSED*/
277fa9e406ahrensstatic void
278fa9e406ahrensdump_none(objset_t *os, uint64_t object, void *data, size_t size)
279fa9e406ahrens{
280fa9e406ahrens}
281fa9e406ahrens
282fa9e406ahrens/*ARGSUSED*/
2836de8f41Victor Latushkinstatic void
2846de8f41Victor Latushkindump_unknown(objset_t *os, uint64_t object, void *data, size_t size)
2856de8f41Victor Latushkin{
2866de8f41Victor Latushkin	(void) printf("\tUNKNOWN OBJECT TYPE\n");
2876de8f41Victor Latushkin}
2886de8f41Victor Latushkin
2896de8f41Victor Latushkin/*ARGSUSED*/
290fa9e406ahrensvoid
291fa9e406ahrensdump_uint8(objset_t *os, uint64_t object, void *data, size_t size)
292fa9e406ahrens{
293fa9e406ahrens}
294fa9e406ahrens
295fa9e406ahrens/*ARGSUSED*/
296fa9e406ahrensstatic void
297fa9e406ahrensdump_uint64(objset_t *os, uint64_t object, void *data, size_t size)
298fa9e406ahrens{
299fa9e406ahrens}
300fa9e406ahrens
301fa9e406ahrens/*ARGSUSED*/
302fa9e406ahrensstatic void
303fa9e406ahrensdump_zap(objset_t *os, uint64_t object, void *data, size_t size)
304fa9e406ahrens{
305fa9e406ahrens	zap_cursor_t zc;
306fa9e406ahrens	zap_attribute_t attr;
307fa9e406ahrens	void *prop;
308fa9e406ahrens	int i;
309fa9e406ahrens
310fa9e406ahrens	dump_zap_stats(os, object);
311fa9e406ahrens	(void) printf("\n");
312fa9e406ahrens
313fa9e406ahrens	for (zap_cursor_init(&zc, os, object);
314fa9e406ahrens	    zap_cursor_retrieve(&zc, &attr) == 0;
315fa9e406ahrens	    zap_cursor_advance(&zc)) {
316fa9e406ahrens		(void) printf("\t\t%s = ", attr.za_name);
317fa9e406ahrens		if (attr.za_num_integers == 0) {
318fa9e406ahrens			(void) printf("\n");
319fa9e406ahrens			continue;
320fa9e406ahrens		}
321fa9e406ahrens		prop = umem_zalloc(attr.za_num_integers *
322fa9e406ahrens		    attr.za_integer_length, UMEM_NOFAIL);
323fa9e406ahrens		(void) zap_lookup(os, object, attr.za_name,
324fa9e406ahrens		    attr.za_integer_length, attr.za_num_integers, prop);
325fa9e406ahrens		if (attr.za_integer_length == 1) {
326fa9e406ahrens			(void) printf("%s", (char *)prop);
327fa9e406ahrens		} else {
328fa9e406ahrens			for (i = 0; i < attr.za_num_integers; i++) {
329fa9e406ahrens				switch (attr.za_integer_length) {
330fa9e406ahrens				case 2:
331fa9e406ahrens					(void) printf("%u ",
332fa9e406ahrens					    ((uint16_t *)prop)[i]);
333fa9e406ahrens					break;
334fa9e406ahrens				case 4:
335fa9e406ahrens					(void) printf("%u ",
336fa9e406ahrens					    ((uint32_t *)prop)[i]);
337fa9e406ahrens					break;
338fa9e406ahrens				case 8:
339fa9e406ahrens					(void) printf("%lld ",
340fa9e406ahrens					    (u_longlong_t)((int64_t *)prop)[i]);
341fa9e406ahrens					break;
342fa9e406ahrens				}
343fa9e406ahrens			}
344fa9e406ahrens		}
345fa9e406ahrens		(void) printf("\n");
346fa9e406ahrens		umem_free(prop, attr.za_num_integers * attr.za_integer_length);
347fa9e406ahrens	}
34887e5029ahrens	zap_cursor_fini(&zc);
349fa9e406ahrens}
350fa9e406ahrens
351e743726ahrens/*ARGSUSED*/
352e743726ahrensstatic void
353e743726ahrensdump_zpldir(objset_t *os, uint64_t object, void *data, size_t size)
354e743726ahrens{
355e743726ahrens	zap_cursor_t zc;
356e743726ahrens	zap_attribute_t attr;
357e743726ahrens	const char *typenames[] = {
358e743726ahrens		/* 0 */ "not specified",
359e743726ahrens		/* 1 */ "FIFO",
360e743726ahrens		/* 2 */ "Character Device",
361e743726ahrens		/* 3 */ "3 (invalid)",
362e743726ahrens		/* 4 */ "Directory",
363e743726ahrens		/* 5 */ "5 (invalid)",
364e743726ahrens		/* 6 */ "Block Device",
365e743726ahrens		/* 7 */ "7 (invalid)",
366e743726ahrens		/* 8 */ "Regular File",
367e743726ahrens		/* 9 */ "9 (invalid)",
368e743726ahrens		/* 10 */ "Symbolic Link",
369e743726ahrens		/* 11 */ "11 (invalid)",
370e743726ahrens		/* 12 */ "Socket",
371e743726ahrens		/* 13 */ "Door",
372e743726ahrens		/* 14 */ "Event Port",
373e743726ahrens		/* 15 */ "15 (invalid)",
374e743726ahrens	};
375e743726ahrens
376e743726ahrens	dump_zap_stats(os, object);
377e743726ahrens	(void) printf("\n");
378e743726ahrens
379e743726ahrens	for (zap_cursor_init(&zc, os, object);
380e743726ahrens	    zap_cursor_retrieve(&zc, &attr) == 0;
381e743726ahrens	    zap_cursor_advance(&zc)) {
382e743726ahrens		(void) printf("\t\t%s = %lld (type: %s)\n",
383e743726ahrens		    attr.za_name, ZFS_DIRENT_OBJ(attr.za_first_integer),
384e743726ahrens		    typenames[ZFS_DIRENT_TYPE(attr.za_first_integer)]);
385e743726ahrens	}
386e743726ahrens	zap_cursor_fini(&zc);
387e743726ahrens}
388e743726ahrens
389fa9e406ahrensstatic void
390fa9e406ahrensdump_spacemap(objset_t *os, space_map_obj_t *smo, space_map_t *sm)
391fa9e406ahrens{
392fa9e406ahrens	uint64_t alloc, offset, entry;
393ecc2d60bonwick	uint8_t mapshift = sm->sm_shift;
394fa9e406ahrens	uint64_t mapstart = sm->sm_start;
3958053a26ck	char *ddata[] = { "ALLOC", "FREE", "CONDENSE", "INVALID",
3968053a26ck			    "INVALID", "INVALID", "INVALID", "INVALID" };
397fa9e406ahrens
398fa9e406ahrens	if (smo->smo_object == 0)
399fa9e406ahrens		return;
400fa9e406ahrens
401fa9e406ahrens	/*
402fa9e406ahrens	 * Print out the freelist entries in both encoded and decoded form.
403fa9e406ahrens	 */
404fa9e406ahrens	alloc = 0;
405fa9e406ahrens	for (offset = 0; offset < smo->smo_objsize; offset += sizeof (entry)) {
406ea8dc4beschrock		VERIFY(0 == dmu_read(os, smo->smo_object, offset,
4077bfdf01Neil Perrin		    sizeof (entry), &entry, DMU_READ_PREFETCH));
408fa9e406ahrens		if (SM_DEBUG_DECODE(entry)) {
409fa9e406ahrens			(void) printf("\t\t[%4llu] %s: txg %llu, pass %llu\n",
410fa9e406ahrens			    (u_longlong_t)(offset / sizeof (entry)),
411fa9e406ahrens			    ddata[SM_DEBUG_ACTION_DECODE(entry)],
4125ad8204nd			    (u_longlong_t)SM_DEBUG_TXG_DECODE(entry),
4135ad8204nd			    (u_longlong_t)SM_DEBUG_SYNCPASS_DECODE(entry));
414fa9e406ahrens		} else {
415fa9e406ahrens			(void) printf("\t\t[%4llu]    %c  range:"
416fa9e406ahrens			    " %08llx-%08llx  size: %06llx\n",
417fa9e406ahrens			    (u_longlong_t)(offset / sizeof (entry)),
418fa9e406ahrens			    SM_TYPE_DECODE(entry) == SM_ALLOC ? 'A' : 'F',
4195ad8204nd			    (u_longlong_t)((SM_OFFSET_DECODE(entry) <<
4205ad8204nd			    mapshift) + mapstart),
4215ad8204nd			    (u_longlong_t)((SM_OFFSET_DECODE(entry) <<
4225ad8204nd			    mapshift) + mapstart + (SM_RUN_DECODE(entry) <<
4235ad8204nd			    mapshift)),
4245ad8204nd			    (u_longlong_t)(SM_RUN_DECODE(entry) << mapshift));
425fa9e406ahrens			if (SM_TYPE_DECODE(entry) == SM_ALLOC)
426fa9e406ahrens				alloc += SM_RUN_DECODE(entry) << mapshift;
427fa9e406ahrens			else
428fa9e406ahrens				alloc -= SM_RUN_DECODE(entry) << mapshift;
429fa9e406ahrens		}
430fa9e406ahrens	}
431fa9e406ahrens	if (alloc != smo->smo_alloc) {
432fa9e406ahrens		(void) printf("space_map_object alloc (%llu) INCONSISTENT "
433fa9e406ahrens		    "with space map summary (%llu)\n",
434fa9e406ahrens		    (u_longlong_t)smo->smo_alloc, (u_longlong_t)alloc);
435fa9e406ahrens	}
436fa9e406ahrens}
437fa9e406ahrens
438fa9e406ahrensstatic void
439d6e555bGeorge Wilsondump_metaslab_stats(metaslab_t *msp)
440d6e555bGeorge Wilson{
441d6e555bGeorge Wilson	char maxbuf[5];
442d6e555bGeorge Wilson	space_map_t *sm = &msp->ms_map;
443d6e555bGeorge Wilson	avl_tree_t *t = sm->sm_pp_root;
444d6e555bGeorge Wilson	int free_pct = sm->sm_space * 100 / sm->sm_size;
445d6e555bGeorge Wilson
446d6e555bGeorge Wilson	nicenum(space_map_maxsize(sm), maxbuf);
447d6e555bGeorge Wilson
448d6e555bGeorge Wilson	(void) printf("\t %20s %10lu   %7s  %6s   %4s %4d%%\n",
449d6e555bGeorge Wilson	    "segments", avl_numnodes(t), "maxsize", maxbuf,
450d6e555bGeorge Wilson	    "freepct", free_pct);
451d6e555bGeorge Wilson}
452d6e555bGeorge Wilson
453d6e555bGeorge Wilsonstatic void
454fa9e406ahrensdump_metaslab(metaslab_t *msp)
455fa9e406ahrens{
456fa9e406ahrens	char freebuf[5];
457ecc2d60bonwick	space_map_obj_t *smo = &msp->ms_smo;
458fa9e406ahrens	vdev_t *vd = msp->ms_group->mg_vd;
459fa9e406ahrens	spa_t *spa = vd->vdev_spa;
460fa9e406ahrens
461fa9e406ahrens	nicenum(msp->ms_map.sm_size - smo->smo_alloc, freebuf);
462fa9e406ahrens
463fa9e406ahrens	(void) printf(
464d6e555bGeorge Wilson	    "\tvdev %5llu   offset %12llx   spacemap %6llu   free    %5s\n",
465fa9e406ahrens	    (u_longlong_t)vd->vdev_id, (u_longlong_t)msp->ms_map.sm_start,
466fa9e406ahrens	    (u_longlong_t)smo->smo_object, freebuf);
467fa9e406ahrens
468d6e555bGeorge Wilson	if (dump_opt['m'] > 1) {
469d6e555bGeorge Wilson		mutex_enter(&msp->ms_lock);
470d6e555bGeorge Wilson		VERIFY(space_map_load(&msp->ms_map, zfs_metaslab_ops,
471d6e555bGeorge Wilson		    SM_FREE, &msp->ms_smo, spa->spa_meta_objset) == 0);
472d6e555bGeorge Wilson		dump_metaslab_stats(msp);
473d6e555bGeorge Wilson		space_map_unload(&msp->ms_map);
474d6e555bGeorge Wilson		mutex_exit(&msp->ms_lock);
475d6e555bGeorge Wilson	}
476d6e555bGeorge Wilson
477d6e555bGeorge Wilson	if (dump_opt['d'] > 5 || dump_opt['m'] > 2) {
478d6e555bGeorge Wilson		ASSERT(msp->ms_map.sm_size == (1ULL << vd->vdev_ms_shift));
479d6e555bGeorge Wilson
480d6e555bGeorge Wilson		mutex_enter(&msp->ms_lock);
481d6e555bGeorge Wilson		dump_spacemap(spa->spa_meta_objset, smo, &msp->ms_map);
482d6e555bGeorge Wilson		mutex_exit(&msp->ms_lock);
483d6e555bGeorge Wilson	}
484fa9e406ahrens
485fa9e406ahrens}
486fa9e406ahrens
487fa9e406ahrensstatic void
488fa9e406ahrensdump_metaslabs(spa_t *spa)
489fa9e406ahrens{
490fa9e406ahrens	vdev_t *rvd = spa->spa_root_vdev;
491fa9e406ahrens	vdev_t *vd;
492fa9e406ahrens	int c, m;
493fa9e406ahrens
494fa9e406ahrens	(void) printf("\nMetaslabs:\n");
495fa9e406ahrens
496fa9e406ahrens	for (c = 0; c < rvd->vdev_children; c++) {
497fa9e406ahrens		vd = rvd->vdev_child[c];
498fa9e406ahrens
499d6e555bGeorge Wilson		(void) printf("\t%-10s   %-19s   %-15s   %-10s\n",
500d6e555bGeorge Wilson		    "vdev", "offset", "spacemap", "free");
501d6e555bGeorge Wilson		(void) printf("\t%10s   %19s   %15s   %10s\n",
502d6e555bGeorge Wilson		    "----------", "-------------------",
503d6e555bGeorge Wilson		    "---------------", "-------------");
504fa9e406ahrens
505fa9e406ahrens		for (m = 0; m < vd->vdev_ms_count; m++)
506fa9e406ahrens			dump_metaslab(vd->vdev_ms[m]);
507fa9e406ahrens		(void) printf("\n");
508fa9e406ahrens	}
509fa9e406ahrens}
510fa9e406ahrens
511fa9e406ahrensstatic void
5128ad4d6dJeff Bonwickdump_dtl_seg(space_map_t *sm, uint64_t start, uint64_t size)
5138ad4d6dJeff Bonwick{
5148ad4d6dJeff Bonwick	char *prefix = (void *)sm;
5158ad4d6dJeff Bonwick
5168ad4d6dJeff Bonwick	(void) printf("%s [%llu,%llu) length %llu\n",
5178ad4d6dJeff Bonwick	    prefix,
5188ad4d6dJeff Bonwick	    (u_longlong_t)start,
5198ad4d6dJeff Bonwick	    (u_longlong_t)(start + size),
5208ad4d6dJeff Bonwick	    (u_longlong_t)(size));
5218ad4d6dJeff Bonwick}
5228ad4d6dJeff Bonwick
5238ad4d6dJeff Bonwickstatic void
524fa9e406ahrensdump_dtl(vdev_t *vd, int indent)
525fa9e406ahrens{
5268ad4d6dJeff Bonwick	spa_t *spa = vd->vdev_spa;
5278ad4d6dJeff Bonwick	boolean_t required;
5288ad4d6dJeff Bonwick	char *name[DTL_TYPES] = { "missing", "partial", "scrub", "outage" };
5298ad4d6dJeff Bonwick	char prefix[256];
5308ad4d6dJeff Bonwick
5318f18d1fGeorge Wilson	spa_vdev_state_enter(spa, SCL_NONE);
5328ad4d6dJeff Bonwick	required = vdev_dtl_required(vd);
5338ad4d6dJeff Bonwick	(void) spa_vdev_state_exit(spa, NULL, 0);
534fa9e406ahrens
535fa9e406ahrens	if (indent == 0)
536fa9e406ahrens		(void) printf("\nDirty time logs:\n\n");
537fa9e406ahrens
5388ad4d6dJeff Bonwick	(void) printf("\t%*s%s [%s]\n", indent, "",
539e14bb32Jeff Bonwick	    vd->vdev_path ? vd->vdev_path :
5408ad4d6dJeff Bonwick	    vd->vdev_parent ? vd->vdev_ops->vdev_op_type : spa_name(spa),
5418ad4d6dJeff Bonwick	    required ? "DTL-required" : "DTL-expendable");
542fa9e406ahrens
5438ad4d6dJeff Bonwick	for (int t = 0; t < DTL_TYPES; t++) {
5448ad4d6dJeff Bonwick		space_map_t *sm = &vd->vdev_dtl[t];
5458ad4d6dJeff Bonwick		if (sm->sm_space == 0)
5468ad4d6dJeff Bonwick			continue;
5478ad4d6dJeff Bonwick		(void) snprintf(prefix, sizeof (prefix), "\t%*s%s",
5488ad4d6dJeff Bonwick		    indent + 2, "", name[t]);
5498ad4d6dJeff Bonwick		mutex_enter(sm->sm_lock);
5508ad4d6dJeff Bonwick		space_map_walk(sm, dump_dtl_seg, (void *)prefix);
5518ad4d6dJeff Bonwick		mutex_exit(sm->sm_lock);
5528ad4d6dJeff Bonwick		if (dump_opt['d'] > 5 && vd->vdev_children == 0)
5538ad4d6dJeff Bonwick			dump_spacemap(spa->spa_meta_objset,
5548ad4d6dJeff Bonwick			    &vd->vdev_dtl_smo, sm);
555fa9e406ahrens	}
556fa9e406ahrens
5578ad4d6dJeff Bonwick	for (int c = 0; c < vd->vdev_children; c++)
558fa9e406ahrens		dump_dtl(vd->vdev_child[c], indent + 4);
559fa9e406ahrens}
560fa9e406ahrens
5618f18d1fGeorge Wilsonstatic void
5628f18d1fGeorge Wilsondump_history(spa_t *spa)
5638f18d1fGeorge Wilson{
5648f18d1fGeorge Wilson	nvlist_t **events = NULL;
5658f18d1fGeorge Wilson	char buf[SPA_MAXBLOCKSIZE];
566e4161dfVictor Latushkin	uint64_t resid, len, off = 0;
5678f18d1fGeorge Wilson	uint_t num = 0;
5688f18d1fGeorge Wilson	int error;
5698f18d1fGeorge Wilson	time_t tsec;
5708f18d1fGeorge Wilson	struct tm t;
5718f18d1fGeorge Wilson	char tbuf[30];
5728f18d1fGeorge Wilson	char internalstr[MAXPATHLEN];
5738f18d1fGeorge Wilson
5748f18d1fGeorge Wilson	do {
575e4161dfVictor Latushkin		len = sizeof (buf);
576e4161dfVictor Latushkin
5778f18d1fGeorge Wilson		if ((error = spa_history_get(spa, &off, &len, buf)) != 0) {
5788f18d1fGeorge Wilson			(void) fprintf(stderr, "Unable to read history: "
5798f18d1fGeorge Wilson			    "error %d\n", error);
5808f18d1fGeorge Wilson			return;
5818f18d1fGeorge Wilson		}
5828f18d1fGeorge Wilson
5838f18d1fGeorge Wilson		if (zpool_history_unpack(buf, len, &resid, &events, &num) != 0)
5848f18d1fGeorge Wilson			break;
5858f18d1fGeorge Wilson
5868f18d1fGeorge Wilson		off -= resid;
5878f18d1fGeorge Wilson	} while (len != 0);
5888f18d1fGeorge Wilson
5898f18d1fGeorge Wilson	(void) printf("\nHistory:\n");
5908f18d1fGeorge Wilson	for (int i = 0; i < num; i++) {
5918f18d1fGeorge Wilson		uint64_t time, txg, ievent;
5928f18d1fGeorge Wilson		char *cmd, *intstr;
5938f18d1fGeorge Wilson
5948f18d1fGeorge Wilson		if (nvlist_lookup_uint64(events[i], ZPOOL_HIST_TIME,
5958f18d1fGeorge Wilson		    &time) != 0)
5968f18d1fGeorge Wilson			continue;
5978f18d1fGeorge Wilson		if (nvlist_lookup_string(events[i], ZPOOL_HIST_CMD,
5988f18d1fGeorge Wilson		    &cmd) != 0) {
5998f18d1fGeorge Wilson			if (nvlist_lookup_uint64(events[i],
6008f18d1fGeorge Wilson			    ZPOOL_HIST_INT_EVENT, &ievent) != 0)
6018f18d1fGeorge Wilson				continue;
6028f18d1fGeorge Wilson			verify(nvlist_lookup_uint64(events[i],
6038f18d1fGeorge Wilson			    ZPOOL_HIST_TXG, &txg) == 0);
6048f18d1fGeorge Wilson			verify(nvlist_lookup_string(events[i],
6058f18d1fGeorge Wilson			    ZPOOL_HIST_INT_STR, &intstr) == 0);
6068f18d1fGeorge Wilson			if (ievent >= LOG_END)
6078f18d1fGeorge Wilson				continue;
6088f18d1fGeorge Wilson
6098f18d1fGeorge Wilson			(void) snprintf(internalstr,
6108f18d1fGeorge Wilson			    sizeof (internalstr),
6118f18d1fGeorge Wilson			    "[internal %s txg:%lld] %s",
6128f18d1fGeorge Wilson			    hist_event_table[ievent], txg,
6138f18d1fGeorge Wilson			    intstr);
6148f18d1fGeorge Wilson			cmd = internalstr;
6158f18d1fGeorge Wilson		}
6168f18d1fGeorge Wilson		tsec = time;
6178f18d1fGeorge Wilson		(void) localtime_r(&tsec, &t);
6188f18d1fGeorge Wilson		(void) strftime(tbuf, sizeof (tbuf), "%F.%T", &t);
6198f18d1fGeorge Wilson		(void) printf("%s %s\n", tbuf, cmd);
6208f18d1fGeorge Wilson	}
6218f18d1fGeorge Wilson}
6228f18d1fGeorge Wilson
623fa9e406ahrens/*ARGSUSED*/
624fa9e406ahrensstatic void
625fa9e406ahrensdump_dnode(objset_t *os, uint64_t object, void *data, size_t size)
626fa9e406ahrens{
627fa9e406ahrens}
628fa9e406ahrens
629fa9e406ahrensstatic uint64_t
63088b7b0fMatthew Ahrensblkid2offset(const dnode_phys_t *dnp, int level, uint64_t blkid)
631fa9e406ahrens{
632fa9e406ahrens	if (level < 0)
633fa9e406ahrens		return (blkid);
634fa9e406ahrens
635fa9e406ahrens	return ((blkid << (level * (dnp->dn_indblkshift - SPA_BLKPTRSHIFT))) *
636fa9e406ahrens	    dnp->dn_datablkszsec << SPA_MINBLOCKSHIFT);
637fa9e406ahrens}
638fa9e406ahrens
63944cd46cbillmstatic void
64044cd46cbillmsprintf_blkptr_compact(char *blkbuf, blkptr_t *bp, int alldvas)
64144cd46cbillm{
64244cd46cbillm	dva_t *dva = bp->blk_dva;
64344cd46cbillm	int ndvas = alldvas ? BP_GET_NDVAS(bp) : 1;
64444cd46cbillm	int i;
64544cd46cbillm
64644cd46cbillm	blkbuf[0] = '\0';
64744cd46cbillm
64844cd46cbillm	for (i = 0; i < ndvas; i++)
64944cd46cbillm		(void) sprintf(blkbuf + strlen(blkbuf), "%llu:%llx:%llx ",
65044cd46cbillm		    (u_longlong_t)DVA_GET_VDEV(&dva[i]),
65144cd46cbillm		    (u_longlong_t)DVA_GET_OFFSET(&dva[i]),
65244cd46cbillm		    (u_longlong_t)DVA_GET_ASIZE(&dva[i]));
65344cd46cbillm
65444cd46cbillm	(void) sprintf(blkbuf + strlen(blkbuf), "%llxL/%llxP F=%llu B=%llu",
65544cd46cbillm	    (u_longlong_t)BP_GET_LSIZE(bp),
65644cd46cbillm	    (u_longlong_t)BP_GET_PSIZE(bp),
65744cd46cbillm	    (u_longlong_t)bp->blk_fill,
65844cd46cbillm	    (u_longlong_t)bp->blk_birth);
65944cd46cbillm}
66044cd46cbillm
66188b7b0fMatthew Ahrensstatic void
66288b7b0fMatthew Ahrensprint_indirect(blkptr_t *bp, const zbookmark_t *zb,
66388b7b0fMatthew Ahrens    const dnode_phys_t *dnp)
664fa9e406ahrens{
66588b7b0fMatthew Ahrens	char blkbuf[BP_SPRINTF_LEN];
666fa9e406ahrens	int l;
667fa9e406ahrens
66888b7b0fMatthew Ahrens	ASSERT3U(BP_GET_TYPE(bp), ==, dnp->dn_type);
66988b7b0fMatthew Ahrens	ASSERT3U(BP_GET_LEVEL(bp), ==, zb->zb_level);
670fa9e406ahrens
67188b7b0fMatthew Ahrens	(void) printf("%16llx ",
672fa9e406ahrens	    (u_longlong_t)blkid2offset(dnp, zb->zb_level, zb->zb_blkid));
673fa9e406ahrens
674fa9e406ahrens	ASSERT(zb->zb_level >= 0);
675fa9e406ahrens
676fa9e406ahrens	for (l = dnp->dn_nlevels - 1; l >= -1; l--) {
677fa9e406ahrens		if (l == zb->zb_level) {
67888b7b0fMatthew Ahrens			(void) printf("L%llx", (u_longlong_t)zb->zb_level);
679fa9e406ahrens		} else {
68088b7b0fMatthew Ahrens			(void) printf(" ");
681fa9e406ahrens		}
682fa9e406ahrens	}
683fa9e406ahrens
68488b7b0fMatthew Ahrens	sprintf_blkptr_compact(blkbuf, bp, dump_opt['d'] > 5 ? 1 : 0);
68588b7b0fMatthew Ahrens	(void) printf("%s\n", blkbuf);
68688b7b0fMatthew Ahrens}
68788b7b0fMatthew Ahrens
68888b7b0fMatthew Ahrens#define	SET_BOOKMARK(zb, objset, object, level, blkid)  \
68988b7b0fMatthew Ahrens{                                                       \
69088b7b0fMatthew Ahrens	(zb)->zb_objset = objset;                       \
69188b7b0fMatthew Ahrens	(zb)->zb_object = object;                       \
69288b7b0fMatthew Ahrens	(zb)->zb_level = level;                         \
69388b7b0fMatthew Ahrens	(zb)->zb_blkid = blkid;                         \
69488b7b0fMatthew Ahrens}
69588b7b0fMatthew Ahrens
69688b7b0fMatthew Ahrensstatic int
69788b7b0fMatthew Ahrensvisit_indirect(spa_t *spa, const dnode_phys_t *dnp,
69888b7b0fMatthew Ahrens    blkptr_t *bp, const zbookmark_t *zb)
69988b7b0fMatthew Ahrens{
700e4161dfVictor Latushkin	int err = 0;
70188b7b0fMatthew Ahrens
70288b7b0fMatthew Ahrens	if (bp->blk_birth == 0)
70388b7b0fMatthew Ahrens		return (0);
70488b7b0fMatthew Ahrens
70588b7b0fMatthew Ahrens	print_indirect(bp, zb, dnp);
70688b7b0fMatthew Ahrens
70788b7b0fMatthew Ahrens	if (BP_GET_LEVEL(bp) > 0) {
70888b7b0fMatthew Ahrens		uint32_t flags = ARC_WAIT;
70988b7b0fMatthew Ahrens		int i;
71088b7b0fMatthew Ahrens		blkptr_t *cbp;
71188b7b0fMatthew Ahrens		int epb = BP_GET_LSIZE(bp) >> SPA_BLKPTRSHIFT;
71288b7b0fMatthew Ahrens		arc_buf_t *buf;
71388b7b0fMatthew Ahrens		uint64_t fill = 0;
71488b7b0fMatthew Ahrens
71588b7b0fMatthew Ahrens		err = arc_read_nolock(NULL, spa, bp, arc_getbuf_func, &buf,
71688b7b0fMatthew Ahrens		    ZIO_PRIORITY_ASYNC_READ, ZIO_FLAG_CANFAIL, &flags, zb);
71788b7b0fMatthew Ahrens		if (err)
71888b7b0fMatthew Ahrens			return (err);
71988b7b0fMatthew Ahrens
72088b7b0fMatthew Ahrens		/* recursively visit blocks below this */
72188b7b0fMatthew Ahrens		cbp = buf->b_data;
72288b7b0fMatthew Ahrens		for (i = 0; i < epb; i++, cbp++) {
72388b7b0fMatthew Ahrens			zbookmark_t czb;
72488b7b0fMatthew Ahrens
72588b7b0fMatthew Ahrens			SET_BOOKMARK(&czb, zb->zb_objset, zb->zb_object,
72688b7b0fMatthew Ahrens			    zb->zb_level - 1,
72788b7b0fMatthew Ahrens			    zb->zb_blkid * epb + i);
72888b7b0fMatthew Ahrens			err = visit_indirect(spa, dnp, cbp, &czb);
72988b7b0fMatthew Ahrens			if (err)
73088b7b0fMatthew Ahrens				break;
73188b7b0fMatthew Ahrens			fill += cbp->blk_fill;
73288b7b0fMatthew Ahrens		}
7338ad4d6dJeff Bonwick		if (!err)
7348ad4d6dJeff Bonwick			ASSERT3U(fill, ==, bp->blk_fill);
73588b7b0fMatthew Ahrens		(void) arc_buf_remove_ref(buf, &buf);
736fa9e406ahrens	}
737fa9e406ahrens
73888b7b0fMatthew Ahrens	return (err);
739fa9e406ahrens}
740fa9e406ahrens
741fa9e406ahrens/*ARGSUSED*/
742fa9e406ahrensstatic void
74388b7b0fMatthew Ahrensdump_indirect(dnode_t *dn)
744fa9e406ahrens{
74588b7b0fMatthew Ahrens	dnode_phys_t *dnp = dn->dn_phys;
74688b7b0fMatthew Ahrens	int j;
74788b7b0fMatthew Ahrens	zbookmark_t czb;
748fa9e406ahrens
749fa9e406ahrens	(void) printf("Indirect blocks:\n");
750fa9e406ahrens
751503ad85Matthew Ahrens	SET_BOOKMARK(&czb, dmu_objset_id(dn->dn_objset),
75288b7b0fMatthew Ahrens	    dn->dn_object, dnp->dn_nlevels - 1, 0);
75388b7b0fMatthew Ahrens	for (j = 0; j < dnp->dn_nblkptr; j++) {
75488b7b0fMatthew Ahrens		czb.zb_blkid = j;
755503ad85Matthew Ahrens		(void) visit_indirect(dmu_objset_spa(dn->dn_objset), dnp,
75688b7b0fMatthew Ahrens		    &dnp->dn_blkptr[j], &czb);
75788b7b0fMatthew Ahrens	}
758fa9e406ahrens
759fa9e406ahrens	(void) printf("\n");
760fa9e406ahrens}
761fa9e406ahrens
762fa9e406ahrens/*ARGSUSED*/
763fa9e406ahrensstatic void
764fa9e406ahrensdump_dsl_dir(objset_t *os, uint64_t object, void *data, size_t size)
765fa9e406ahrens{
766fa9e406ahrens	dsl_dir_phys_t *dd = data;
767fa9e406ahrens	time_t crtime;
76874e7dc9Matthew Ahrens	char nice[6];
769fa9e406ahrens
770fa9e406ahrens	if (dd == NULL)
771fa9e406ahrens		return;
772fa9e406ahrens
773da6c28aamw	ASSERT3U(size, >=, sizeof (dsl_dir_phys_t));
774fa9e406ahrens
775fa9e406ahrens	crtime = dd->dd_creation_time;
776fa9e406ahrens	(void) printf("\t\tcreation_time = %s", ctime(&crtime));
777fa9e406ahrens	(void) printf("\t\thead_dataset_obj = %llu\n",
778fa9e406ahrens	    (u_longlong_t)dd->dd_head_dataset_obj);
779fa9e406ahrens	(void) printf("\t\tparent_dir_obj = %llu\n",
780fa9e406ahrens	    (u_longlong_t)dd->dd_parent_obj);
7813cb34c6ahrens	(void) printf("\t\torigin_obj = %llu\n",
7823cb34c6ahrens	    (u_longlong_t)dd->dd_origin_obj);
783fa9e406ahrens	(void) printf("\t\tchild_dir_zapobj = %llu\n",
784fa9e406ahrens	    (u_longlong_t)dd->dd_child_dir_zapobj);
78574e7dc9Matthew Ahrens	nicenum(dd->dd_used_bytes, nice);
78674e7dc9Matthew Ahrens	(void) printf("\t\tused_bytes = %s\n", nice);
78774e7dc9Matthew Ahrens	nicenum(dd->dd_compressed_bytes, nice);
78874e7dc9Matthew Ahrens	(void) printf("\t\tcompressed_bytes = %s\n", nice);
78974e7dc9Matthew Ahrens	nicenum(dd->dd_uncompressed_bytes, nice);
79074e7dc9Matthew Ahrens	(void) printf("\t\tuncompressed_bytes = %s\n", nice);
79174e7dc9Matthew Ahrens	nicenum(dd->dd_quota, nice);
79274e7dc9Matthew Ahrens	(void) printf("\t\tquota = %s\n", nice);
79374e7dc9Matthew Ahrens	nicenum(dd->dd_reserved, nice);
79474e7dc9Matthew Ahrens	(void) printf("\t\treserved = %s\n", nice);
795fa9e406ahrens	(void) printf("\t\tprops_zapobj = %llu\n",
796fa9e406ahrens	    (u_longlong_t)dd->dd_props_zapobj);
797ecd6cf8marks	(void) printf("\t\tdeleg_zapobj = %llu\n",
798ecd6cf8marks	    (u_longlong_t)dd->dd_deleg_zapobj);
79974e7dc9Matthew Ahrens	(void) printf("\t\tflags = %llx\n",
80074e7dc9Matthew Ahrens	    (u_longlong_t)dd->dd_flags);
80174e7dc9Matthew Ahrens
80274e7dc9Matthew Ahrens#define	DO(which) \
80374e7dc9Matthew Ahrens	nicenum(dd->dd_used_breakdown[DD_USED_ ## which], nice); \
80474e7dc9Matthew Ahrens	(void) printf("\t\tused_breakdown[" #which "] = %s\n", nice)
80574e7dc9Matthew Ahrens	DO(HEAD);
80674e7dc9Matthew Ahrens	DO(SNAP);
80774e7dc9Matthew Ahrens	DO(CHILD);
80874e7dc9Matthew Ahrens	DO(CHILD_RSRV);
80974e7dc9Matthew Ahrens	DO(REFRSRV);
81074e7dc9Matthew Ahrens#undef DO
811fa9e406ahrens}
812fa9e406ahrens
813fa9e406ahrens/*ARGSUSED*/
814fa9e406ahrensstatic void
815fa9e406ahrensdump_dsl_dataset(objset_t *os, uint64_t object, void *data, size_t size)
816fa9e406ahrens{
817fa9e406ahrens	dsl_dataset_phys_t *ds = data;
818fa9e406ahrens	time_t crtime;
819fbabab8maybee	char used[6], compressed[6], uncompressed[6], unique[6];
820fbabab8maybee	char blkbuf[BP_SPRINTF_LEN];
821fa9e406ahrens
822fa9e406ahrens	if (ds == NULL)
823fa9e406ahrens		return;
824fa9e406ahrens
825fa9e406ahrens	ASSERT(size == sizeof (*ds));
826fa9e406ahrens	crtime = ds->ds_creation_time;
827fa9e406ahrens	nicenum(ds->ds_used_bytes, used);
828fa9e406ahrens	nicenum(ds->ds_compressed_bytes, compressed);
829fa9e406ahrens	nicenum(ds->ds_uncompressed_bytes, uncompressed);
830fa9e406ahrens	nicenum(ds->ds_unique_bytes, unique);
831fbabab8maybee	sprintf_blkptr(blkbuf, BP_SPRINTF_LEN, &ds->ds_bp);
832fa9e406ahrens
833088f389ahrens	(void) printf("\t\tdir_obj = %llu\n",
834fa9e406ahrens	    (u_longlong_t)ds->ds_dir_obj);
835fa9e406ahrens	(void) printf("\t\tprev_snap_obj = %llu\n",
836fa9e406ahrens	    (u_longlong_t)ds->ds_prev_snap_obj);
837fa9e406ahrens	(void) printf("\t\tprev_snap_txg = %llu\n",
838fa9e406ahrens	    (u_longlong_t)ds->ds_prev_snap_txg);
839fa9e406ahrens	(void) printf("\t\tnext_snap_obj = %llu\n",
840fa9e406ahrens	    (u_longlong_t)ds->ds_next_snap_obj);
841fa9e406ahrens	(void) printf("\t\tsnapnames_zapobj = %llu\n",
842fa9e406ahrens	    (u_longlong_t)ds->ds_snapnames_zapobj);
843fa9e406ahrens	(void) printf("\t\tnum_children = %llu\n",
844fa9e406ahrens	    (u_longlong_t)ds->ds_num_children);
845842727cChris Kirby	(void) printf("\t\tuserrefs_obj = %llu\n",
846842727cChris Kirby	    (u_longlong_t)ds->ds_userrefs_obj);
847fa9e406ahrens	(void) printf("\t\tcreation_time = %s", ctime(&crtime));
848fa9e406ahrens	(void) printf("\t\tcreation_txg = %llu\n",
849fa9e406ahrens	    (u_longlong_t)ds->ds_creation_txg);
850fa9e406ahrens	(void) printf("\t\tdeadlist_obj = %llu\n",
851fa9e406ahrens	    (u_longlong_t)ds->ds_deadlist_obj);
852fa9e406ahrens	(void) printf("\t\tused_bytes = %s\n", used);
853fa9e406ahrens	(void) printf("\t\tcompressed_bytes = %s\n", compressed);
854fa9e406ahrens	(void) printf("\t\tuncompressed_bytes = %s\n", uncompressed);
855fa9e406ahrens	(void) printf("\t\tunique = %s\n", unique);
856fa9e406ahrens	(void) printf("\t\tfsid_guid = %llu\n",
857fa9e406ahrens	    (u_longlong_t)ds->ds_fsid_guid);
858fa9e406ahrens	(void) printf("\t\tguid = %llu\n",
859fa9e406ahrens	    (u_longlong_t)ds->ds_guid);
86099653d4eschrock	(void) printf("\t\tflags = %llx\n",
86199653d4eschrock	    (u_longlong_t)ds->ds_flags);
862088f389ahrens	(void) printf("\t\tnext_clones_obj = %llu\n",
863088f389ahrens	    (u_longlong_t)ds->ds_next_clones_obj);
864bb0ade0ahrens	(void) printf("\t\tprops_obj = %llu\n",
865bb0ade0ahrens	    (u_longlong_t)ds->ds_props_obj);
866fa9e406ahrens	(void) printf("\t\tbp = %s\n", blkbuf);
867fa9e406ahrens}
868fa9e406ahrens
869fa9e406ahrensstatic void
870fa9e406ahrensdump_bplist(objset_t *mos, uint64_t object, char *name)
871fa9e406ahrens{
872fa9e406ahrens	bplist_t bpl = { 0 };
873fa9e406ahrens	blkptr_t blk, *bp = &blk;
874fa9e406ahrens	uint64_t itor = 0;
87599653d4eschrock	char bytes[6];
87699653d4eschrock	char comp[6];
87799653d4eschrock	char uncomp[6];
878fa9e406ahrens
879fa9e406ahrens	if (dump_opt['d'] < 3)
880fa9e406ahrens		return;
881fa9e406ahrens
882c25056dgw	mutex_init(&bpl.bpl_lock, NULL, MUTEX_DEFAULT, NULL);
883ea8dc4beschrock	VERIFY(0 == bplist_open(&bpl, mos, object));
884fa9e406ahrens	if (bplist_empty(&bpl)) {
885fa9e406ahrens		bplist_close(&bpl);
886c25056dgw		mutex_destroy(&bpl.bpl_lock);
887fa9e406ahrens		return;
888fa9e406ahrens	}
889fa9e406ahrens
89099653d4eschrock	nicenum(bpl.bpl_phys->bpl_bytes, bytes);
89199653d4eschrock	if (bpl.bpl_dbuf->db_size == sizeof (bplist_phys_t)) {
89299653d4eschrock		nicenum(bpl.bpl_phys->bpl_comp, comp);
89399653d4eschrock		nicenum(bpl.bpl_phys->bpl_uncomp, uncomp);
89499653d4eschrock		(void) printf("\n    %s: %llu entries, %s (%s/%s comp)\n",
89599653d4eschrock		    name, (u_longlong_t)bpl.bpl_phys->bpl_entries,
89699653d4eschrock		    bytes, comp, uncomp);
89799653d4eschrock	} else {
89899653d4eschrock		(void) printf("\n    %s: %llu entries, %s\n",
89999653d4eschrock		    name, (u_longlong_t)bpl.bpl_phys->bpl_entries, bytes);
900