zdb.c revision ccba08015a17f88186762dd6d9f91195adb387e8
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,
902e55192Victor Latushkin	    "Usage: %s [-udibcsvL] [-U cachefile_path] [-t txg]\n"
912e55192Victor Latushkin	    "\t   [-S user:cksumalg] "
92fa9e406ahrens	    "dataset [object...]\n"
93fa9e406ahrens	    "       %s -C [pool]\n"
9444cd46cbillm	    "       %s -l dev\n"
95e7cbe64gw	    "       %s -R pool:vdev:offset:size:flags\n"
963a57275ck	    "       %s [-p path_to_vdev_dir]\n"
973a57275ck	    "       %s -e pool | GUID | devid ...\n",
983a57275ck	    cmdname, cmdname, cmdname, cmdname, cmdname, cmdname);
99fa9e406ahrens
100fa9e406ahrens	(void) fprintf(stderr, "	-u uberblock\n");
101fa9e406ahrens	(void) fprintf(stderr, "	-d datasets\n");
102fa9e406ahrens	(void) fprintf(stderr, "        -C cached pool configuration\n");
103fa9e406ahrens	(void) fprintf(stderr, "	-i intent logs\n");
104fa9e406ahrens	(void) fprintf(stderr, "	-b block statistics\n");
105fa9e406ahrens	(void) fprintf(stderr, "	-c checksum all data blocks\n");
106fa9e406ahrens	(void) fprintf(stderr, "	-s report stats on zdb's I/O\n");
107d41e764ek	(void) fprintf(stderr, "	-S <user|all>:<cksum_alg|all> -- "
108d41e764ek	    "dump blkptr signatures\n");
109fa9e406ahrens	(void) fprintf(stderr, "	-v verbose (applies to all others)\n");
110fa9e406ahrens	(void) fprintf(stderr, "        -l dump label contents\n");
11182a0a98Victor Latushkin	(void) fprintf(stderr, "        -L disable leak tracking (do not "
11282a0a98Victor Latushkin	    "load spacemaps)\n");
1133a57275ck	(void) fprintf(stderr, "	-U cachefile_path -- use alternate "
1143a57275ck	    "cachefile\n");
115d41e764ek	(void) fprintf(stderr, "        -R read and display block from a "
11644cd46cbillm	    "device\n");
1173a57275ck	(void) fprintf(stderr, "        -e Pool is exported/destroyed/"
1183a57275ck	    "has altroot\n");
119de6628fck	(void) fprintf(stderr, "	-p <Path to vdev dir> (use with -e)\n");
1202e55192Victor Latushkin	(void) fprintf(stderr, "	-t <txg> highest txg to use when "
1212e55192Victor Latushkin	    "searching for uberblocks\n");
122fa9e406ahrens	(void) fprintf(stderr, "Specify an option more than once (e.g. -bb) "
123fa9e406ahrens	    "to make only that option verbose\n");
124fa9e406ahrens	(void) fprintf(stderr, "Default is to dump everything non-verbosely\n");
125fa9e406ahrens	exit(1);
126fa9e406ahrens}
127fa9e406ahrens
128ccba080Rich Morris/*
129ccba080Rich Morris * Called for usage errors that are discovered after a call to spa_open(),
130ccba080Rich Morris * dmu_bonus_hold(), or pool_match().  abort() is called for other errors.
131ccba080Rich Morris */
132ccba080Rich Morris
133fa9e406ahrensstatic void
134fa9e406ahrensfatal(const char *fmt, ...)
135fa9e406ahrens{
136fa9e406ahrens	va_list ap;
137fa9e406ahrens
138fa9e406ahrens	va_start(ap, fmt);
139fa9e406ahrens	(void) fprintf(stderr, "%s: ", cmdname);
140fa9e406ahrens	(void) vfprintf(stderr, fmt, ap);
141fa9e406ahrens	va_end(ap);
142fa9e406ahrens	(void) fprintf(stderr, "\n");
143fa9e406ahrens
144ccba080Rich Morris	exit(1);
145fa9e406ahrens}
146fa9e406ahrens
147fa9e406ahrensstatic void
148fa9e406ahrensdump_nvlist(nvlist_t *list, int indent)
149fa9e406ahrens{
150fa9e406ahrens	nvpair_t *elem = NULL;
151fa9e406ahrens
152fa9e406ahrens	while ((elem = nvlist_next_nvpair(list, elem)) != NULL) {
153fa9e406ahrens		switch (nvpair_type(elem)) {
154fa9e406ahrens		case DATA_TYPE_STRING:
155fa9e406ahrens			{
156fa9e406ahrens				char *value;
157fa9e406ahrens
158fa9e406ahrens				VERIFY(nvpair_value_string(elem, &value) == 0);
159fa9e406ahrens				(void) printf("%*s%s='%s'\n", indent, "",
160fa9e406ahrens				    nvpair_name(elem), value);
161fa9e406ahrens			}
162fa9e406ahrens			break;
163fa9e406ahrens
164fa9e406ahrens		case DATA_TYPE_UINT64:
165fa9e406ahrens			{
166fa9e406ahrens				uint64_t value;
167fa9e406ahrens
168fa9e406ahrens				VERIFY(nvpair_value_uint64(elem, &value) == 0);
169fa9e406ahrens				(void) printf("%*s%s=%llu\n", indent, "",
170fa9e406ahrens				    nvpair_name(elem), (u_longlong_t)value);
171fa9e406ahrens			}
172fa9e406ahrens			break;
173fa9e406ahrens
174fa9e406ahrens		case DATA_TYPE_NVLIST:
175fa9e406ahrens			{
176fa9e406ahrens				nvlist_t *value;
177fa9e406ahrens
178fa9e406ahrens				VERIFY(nvpair_value_nvlist(elem, &value) == 0);
179fa9e406ahrens				(void) printf("%*s%s\n", indent, "",
180fa9e406ahrens				    nvpair_name(elem));
181fa9e406ahrens				dump_nvlist(value, indent + 4);
182fa9e406ahrens			}
183fa9e406ahrens			break;
184fa9e406ahrens
185fa9e406ahrens		case DATA_TYPE_NVLIST_ARRAY:
186fa9e406ahrens			{
187fa9e406ahrens				nvlist_t **value;
188fa9e406ahrens				uint_t c, count;
189fa9e406ahrens
190fa9e406ahrens				VERIFY(nvpair_value_nvlist_array(elem, &value,
191fa9e406ahrens				    &count) == 0);
192fa9e406ahrens
193fa9e406ahrens				for (c = 0; c < count; c++) {
194fa9e406ahrens					(void) printf("%*s%s[%u]\n", indent, "",
195fa9e406ahrens					    nvpair_name(elem), c);
196fa9e406ahrens					dump_nvlist(value[c], indent + 8);
197fa9e406ahrens				}
198fa9e406ahrens			}
199fa9e406ahrens			break;
200fa9e406ahrens
201fa9e406ahrens		default:
202fa9e406ahrens
203fa9e406ahrens			(void) printf("bad config type %d for %s\n",
204fa9e406ahrens			    nvpair_type(elem), nvpair_name(elem));
205fa9e406ahrens		}
206fa9e406ahrens	}
207fa9e406ahrens}
208fa9e406ahrens
209fa9e406ahrens/* ARGSUSED */
210fa9e406ahrensstatic void
211fa9e406ahrensdump_packed_nvlist(objset_t *os, uint64_t object, void *data, size_t size)
212fa9e406ahrens{
213fa9e406ahrens	nvlist_t *nv;
214fa9e406ahrens	size_t nvsize = *(uint64_t *)data;
215fa9e406ahrens	char *packed = umem_alloc(nvsize, UMEM_NOFAIL);
216fa9e406ahrens
217ea8dc4beschrock	VERIFY(0 == dmu_read(os, object, 0, nvsize, packed));
218fa9e406ahrens
219fa9e406ahrens	VERIFY(nvlist_unpack(packed, nvsize, &nv, 0) == 0);
220fa9e406ahrens
221fa9e406ahrens	umem_free(packed, nvsize);
222fa9e406ahrens
223fa9e406ahrens	dump_nvlist(nv, 8);
224fa9e406ahrens
225fa9e406ahrens	nvlist_free(nv);
226fa9e406ahrens}
227fa9e406ahrens
228fa9e406ahrensconst char dump_zap_stars[] = "****************************************";
229fa9e406ahrensconst int dump_zap_width = sizeof (dump_zap_stars) - 1;
230fa9e406ahrens
231fa9e406ahrensstatic void
232fa9e406ahrensdump_zap_histogram(uint64_t histo[ZAP_HISTOGRAM_SIZE])
233fa9e406ahrens{
234fa9e406ahrens	int i;
235fa9e406ahrens	int minidx = ZAP_HISTOGRAM_SIZE - 1;
236fa9e406ahrens	int maxidx = 0;
237fa9e406ahrens	uint64_t max = 0;
238fa9e406ahrens
239fa9e406ahrens	for (i = 0; i < ZAP_HISTOGRAM_SIZE; i++) {
240fa9e406ahrens		if (histo[i] > max)
241fa9e406ahrens			max = histo[i];
242fa9e406ahrens		if (histo[i] > 0 && i > maxidx)
243fa9e406ahrens			maxidx = i;
244fa9e406ahrens		if (histo[i] > 0 && i < minidx)
245fa9e406ahrens			minidx = i;
246fa9e406ahrens	}
247fa9e406ahrens
248fa9e406ahrens	if (max < dump_zap_width)
249fa9e406ahrens		max = dump_zap_width;
250fa9e406ahrens
251fa9e406ahrens	for (i = minidx; i <= maxidx; i++)
252fa9e406ahrens		(void) printf("\t\t\t%u: %6llu %s\n", i, (u_longlong_t)histo[i],
253fa9e406ahrens		    &dump_zap_stars[(max - histo[i]) * dump_zap_width / max]);
254fa9e406ahrens}
255fa9e406ahrens
256fa9e406ahrensstatic void
257fa9e406ahrensdump_zap_stats(objset_t *os, uint64_t object)
258fa9e406ahrens{
259fa9e406ahrens	int error;
260fa9e406ahrens	zap_stats_t zs;
261fa9e406ahrens
262fa9e406ahrens	error = zap_get_stats(os, object, &zs);
263fa9e406ahrens	if (error)
264fa9e406ahrens		return;
265fa9e406ahrens
266fa9e406ahrens	if (zs.zs_ptrtbl_len == 0) {
267fa9e406ahrens		ASSERT(zs.zs_num_blocks == 1);
268fa9e406ahrens		(void) printf("\tmicrozap: %llu bytes, %llu entries\n",
269fa9e406ahrens		    (u_longlong_t)zs.zs_blocksize,
270fa9e406ahrens		    (u_longlong_t)zs.zs_num_entries);
271fa9e406ahrens		return;
272fa9e406ahrens	}
273fa9e406ahrens
274fa9e406ahrens	(void) printf("\tFat ZAP stats:\n");
2758248818nd
2768248818nd	(void) printf("\t\tPointer table:\n");
2778248818nd	(void) printf("\t\t\t%llu elements\n",
278fa9e406ahrens	    (u_longlong_t)zs.zs_ptrtbl_len);
2798248818nd	(void) printf("\t\t\tzt_blk: %llu\n",
2808248818nd	    (u_longlong_t)zs.zs_ptrtbl_zt_blk);
2818248818nd	(void) printf("\t\t\tzt_numblks: %llu\n",
2828248818nd	    (u_longlong_t)zs.zs_ptrtbl_zt_numblks);
2838248818nd	(void) printf("\t\t\tzt_shift: %llu\n",
2848248818nd	    (u_longlong_t)zs.zs_ptrtbl_zt_shift);
2858248818nd	(void) printf("\t\t\tzt_blks_copied: %llu\n",
2868248818nd	    (u_longlong_t)zs.zs_ptrtbl_blks_copied);
2878248818nd	(void) printf("\t\t\tzt_nextblk: %llu\n",
2888248818nd	    (u_longlong_t)zs.zs_ptrtbl_nextblk);
2898248818nd
290fa9e406ahrens	(void) printf("\t\tZAP entries: %llu\n",
291fa9e406ahrens	    (u_longlong_t)zs.zs_num_entries);
292fa9e406ahrens	(void) printf("\t\tLeaf blocks: %llu\n",
293fa9e406ahrens	    (u_longlong_t)zs.zs_num_leafs);
294fa9e406ahrens	(void) printf("\t\tTotal blocks: %llu\n",
295fa9e406ahrens	    (u_longlong_t)zs.zs_num_blocks);
2968248818nd	(void) printf("\t\tzap_block_type: 0x%llx\n",
2978248818nd	    (u_longlong_t)zs.zs_block_type);
2988248818nd	(void) printf("\t\tzap_magic: 0x%llx\n",
2998248818nd	    (u_longlong_t)zs.zs_magic);
3008248818nd	(void) printf("\t\tzap_salt: 0x%llx\n",
3018248818nd	    (u_longlong_t)zs.zs_salt);
302fa9e406ahrens
303fa9e406ahrens	(void) printf("\t\tLeafs with 2^n pointers:\n");
304fa9e406ahrens	dump_zap_histogram(zs.zs_leafs_with_2n_pointers);
305fa9e406ahrens
306fa9e406ahrens	(void) printf("\t\tBlocks with n*5 entries:\n");
307fa9e406ahrens	dump_zap_histogram(zs.zs_blocks_with_n5_entries);
308fa9e406ahrens
309fa9e406ahrens	(void) printf("\t\tBlocks n/10 full:\n");
310fa9e406ahrens	dump_zap_histogram(zs.zs_blocks_n_tenths_full);
311fa9e406ahrens
312fa9e406ahrens	(void) printf("\t\tEntries with n chunks:\n");
313fa9e406ahrens	dump_zap_histogram(zs.zs_entries_using_n_chunks);
314fa9e406ahrens
315fa9e406ahrens	(void) printf("\t\tBuckets with n entries:\n");
316fa9e406ahrens	dump_zap_histogram(zs.zs_buckets_with_n_entries);
317fa9e406ahrens}
318fa9e406ahrens
319fa9e406ahrens/*ARGSUSED*/
320fa9e406ahrensstatic void
321fa9e406ahrensdump_none(objset_t *os, uint64_t object, void *data, size_t size)
322fa9e406ahrens{
323fa9e406ahrens}
324fa9e406ahrens
325fa9e406ahrens/*ARGSUSED*/
326fa9e406ahrensvoid
327fa9e406ahrensdump_uint8(objset_t *os, uint64_t object, void *data, size_t size)
328fa9e406ahrens{
329fa9e406ahrens}
330fa9e406ahrens
331fa9e406ahrens/*ARGSUSED*/
332fa9e406ahrensstatic void
333fa9e406ahrensdump_uint64(objset_t *os, uint64_t object, void *data, size_t size)
334fa9e406ahrens{
335fa9e406ahrens}
336fa9e406ahrens
337fa9e406ahrens/*ARGSUSED*/
338fa9e406ahrensstatic void
339fa9e406ahrensdump_zap(objset_t *os, uint64_t object, void *data, size_t size)
340fa9e406ahrens{
341fa9e406ahrens	zap_cursor_t zc;
342fa9e406ahrens	zap_attribute_t attr;
343fa9e406ahrens	void *prop;
344fa9e406ahrens	int i;
345fa9e406ahrens
346fa9e406ahrens	dump_zap_stats(os, object);
347fa9e406ahrens	(void) printf("\n");
348fa9e406ahrens
349fa9e406ahrens	for (zap_cursor_init(&zc, os, object);
350fa9e406ahrens	    zap_cursor_retrieve(&zc, &attr) == 0;
351fa9e406ahrens	    zap_cursor_advance(&zc)) {
352fa9e406ahrens		(void) printf("\t\t%s = ", attr.za_name);
353fa9e406ahrens		if (attr.za_num_integers == 0) {
354fa9e406ahrens			(void) printf("\n");
355fa9e406ahrens			continue;
356fa9e406ahrens		}
357fa9e406ahrens		prop = umem_zalloc(attr.za_num_integers *
358fa9e406ahrens		    attr.za_integer_length, UMEM_NOFAIL);
359fa9e406ahrens		(void) zap_lookup(os, object, attr.za_name,
360fa9e406ahrens		    attr.za_integer_length, attr.za_num_integers, prop);
361fa9e406ahrens		if (attr.za_integer_length == 1) {
362fa9e406ahrens			(void) printf("%s", (char *)prop);
363fa9e406ahrens		} else {
364fa9e406ahrens			for (i = 0; i < attr.za_num_integers; i++) {
365fa9e406ahrens				switch (attr.za_integer_length) {
366fa9e406ahrens				case 2:
367fa9e406ahrens					(void) printf("%u ",
368fa9e406ahrens					    ((uint16_t *)prop)[i]);
369fa9e406ahrens					break;
370fa9e406ahrens				case 4:
371fa9e406ahrens					(void) printf("%u ",
372fa9e406ahrens					    ((uint32_t *)prop)[i]);
373fa9e406ahrens					break;
374fa9e406ahrens				case 8:
375fa9e406ahrens					(void) printf("%lld ",
376fa9e406ahrens					    (u_longlong_t)((int64_t *)prop)[i]);
377fa9e406ahrens					break;
378fa9e406ahrens				}
379fa9e406ahrens			}
380fa9e406ahrens		}
381fa9e406ahrens		(void) printf("\n");
382fa9e406ahrens		umem_free(prop, attr.za_num_integers * attr.za_integer_length);
383fa9e406ahrens	}
38487e5029ahrens	zap_cursor_fini(&zc);
385fa9e406ahrens}
386fa9e406ahrens
387e743726ahrens/*ARGSUSED*/
388e743726ahrensstatic void
389e743726ahrensdump_zpldir(objset_t *os, uint64_t object, void *data, size_t size)
390e743726ahrens{
391e743726ahrens	zap_cursor_t zc;
392e743726ahrens	zap_attribute_t attr;
393e743726ahrens	const char *typenames[] = {
394e743726ahrens		/* 0 */ "not specified",
395e743726ahrens		/* 1 */ "FIFO",
396e743726ahrens		/* 2 */ "Character Device",
397e743726ahrens		/* 3 */ "3 (invalid)",
398e743726ahrens		/* 4 */ "Directory",
399e743726ahrens		/* 5 */ "5 (invalid)",
400e743726ahrens		/* 6 */ "Block Device",
401e743726ahrens		/* 7 */ "7 (invalid)",
402e743726ahrens		/* 8 */ "Regular File",
403e743726ahrens		/* 9 */ "9 (invalid)",
404e743726ahrens		/* 10 */ "Symbolic Link",
405e743726ahrens		/* 11 */ "11 (invalid)",
406e743726ahrens		/* 12 */ "Socket",
407e743726ahrens		/* 13 */ "Door",
408e743726ahrens		/* 14 */ "Event Port",
409e743726ahrens		/* 15 */ "15 (invalid)",
410e743726ahrens	};
411e743726ahrens
412e743726ahrens	dump_zap_stats(os, object);
413e743726ahrens	(void) printf("\n");
414e743726ahrens
415e743726ahrens	for (zap_cursor_init(&zc, os, object);
416e743726ahrens	    zap_cursor_retrieve(&zc, &attr) == 0;
417e743726ahrens	    zap_cursor_advance(&zc)) {
418e743726ahrens		(void) printf("\t\t%s = %lld (type: %s)\n",
419e743726ahrens		    attr.za_name, ZFS_DIRENT_OBJ(attr.za_first_integer),
420e743726ahrens		    typenames[ZFS_DIRENT_TYPE(attr.za_first_integer)]);
421e743726ahrens	}
422e743726ahrens	zap_cursor_fini(&zc);
423e743726ahrens}
424e743726ahrens
425fa9e406ahrensstatic void
426fa9e406ahrensdump_spacemap(objset_t *os, space_map_obj_t *smo, space_map_t *sm)
427fa9e406ahrens{
428fa9e406ahrens	uint64_t alloc, offset, entry;
429ecc2d60bonwick	uint8_t mapshift = sm->sm_shift;
430fa9e406ahrens	uint64_t mapstart = sm->sm_start;
4318053a26ck	char *ddata[] = { "ALLOC", "FREE", "CONDENSE", "INVALID",
4328053a26ck			    "INVALID", "INVALID", "INVALID", "INVALID" };
433fa9e406ahrens
434fa9e406ahrens	if (smo->smo_object == 0)
435fa9e406ahrens		return;
436fa9e406ahrens
437fa9e406ahrens	/*
438fa9e406ahrens	 * Print out the freelist entries in both encoded and decoded form.
439fa9e406ahrens	 */
440fa9e406ahrens	alloc = 0;
441fa9e406ahrens	for (offset = 0; offset < smo->smo_objsize; offset += sizeof (entry)) {
442ea8dc4beschrock		VERIFY(0 == dmu_read(os, smo->smo_object, offset,
443ea8dc4beschrock		    sizeof (entry), &entry));
444fa9e406ahrens		if (SM_DEBUG_DECODE(entry)) {
445fa9e406ahrens			(void) printf("\t\t[%4llu] %s: txg %llu, pass %llu\n",
446fa9e406ahrens			    (u_longlong_t)(offset / sizeof (entry)),
447fa9e406ahrens			    ddata[SM_DEBUG_ACTION_DECODE(entry)],
4485ad8204nd			    (u_longlong_t)SM_DEBUG_TXG_DECODE(entry),
4495ad8204nd			    (u_longlong_t)SM_DEBUG_SYNCPASS_DECODE(entry));
450fa9e406ahrens		} else {
451fa9e406ahrens			(void) printf("\t\t[%4llu]    %c  range:"
452fa9e406ahrens			    " %08llx-%08llx  size: %06llx\n",
453fa9e406ahrens			    (u_longlong_t)(offset / sizeof (entry)),
454fa9e406ahrens			    SM_TYPE_DECODE(entry) == SM_ALLOC ? 'A' : 'F',
4555ad8204nd			    (u_longlong_t)((SM_OFFSET_DECODE(entry) <<
4565ad8204nd			    mapshift) + mapstart),
4575ad8204nd			    (u_longlong_t)((SM_OFFSET_DECODE(entry) <<
4585ad8204nd			    mapshift) + mapstart + (SM_RUN_DECODE(entry) <<
4595ad8204nd			    mapshift)),
4605ad8204nd			    (u_longlong_t)(SM_RUN_DECODE(entry) << mapshift));
461fa9e406ahrens			if (SM_TYPE_DECODE(entry) == SM_ALLOC)
462fa9e406ahrens				alloc += SM_RUN_DECODE(entry) << mapshift;
463fa9e406ahrens			else
464fa9e406ahrens				alloc -= SM_RUN_DECODE(entry) << mapshift;
465fa9e406ahrens		}
466fa9e406ahrens	}
467fa9e406ahrens	if (alloc != smo->smo_alloc) {
468fa9e406ahrens		(void) printf("space_map_object alloc (%llu) INCONSISTENT "
469fa9e406ahrens		    "with space map summary (%llu)\n",
470fa9e406ahrens		    (u_longlong_t)smo->smo_alloc, (u_longlong_t)alloc);
471fa9e406ahrens	}
472fa9e406ahrens}
473fa9e406ahrens
474fa9e406ahrensstatic void
475fa9e406ahrensdump_metaslab(metaslab_t *msp)
476fa9e406ahrens{
477fa9e406ahrens	char freebuf[5];
478ecc2d60bonwick	space_map_obj_t *smo = &msp->ms_smo;
479fa9e406ahrens	vdev_t *vd = msp->ms_group->mg_vd;
480fa9e406ahrens	spa_t *spa = vd->vdev_spa;
481fa9e406ahrens
482fa9e406ahrens	nicenum(msp->ms_map.sm_size - smo->smo_alloc, freebuf);
483fa9e406ahrens
484fa9e406ahrens	if (dump_opt['d'] <= 5) {
485fa9e406ahrens		(void) printf("\t%10llx   %10llu   %5s\n",
486fa9e406ahrens		    (u_longlong_t)msp->ms_map.sm_start,
487fa9e406ahrens		    (u_longlong_t)smo->smo_object,
488fa9e406ahrens		    freebuf);
489fa9e406ahrens		return;
490fa9e406ahrens	}
491fa9e406ahrens
492fa9e406ahrens	(void) printf(
493fa9e406ahrens	    "\tvdev %llu   offset %08llx   spacemap %4llu   free %5s\n",
494fa9e406ahrens	    (u_longlong_t)vd->vdev_id, (u_longlong_t)msp->ms_map.sm_start,
495fa9e406ahrens	    (u_longlong_t)smo->smo_object, freebuf);
496fa9e406ahrens
497fa9e406ahrens	ASSERT(msp->ms_map.sm_size == (1ULL << vd->vdev_ms_shift));
498fa9e406ahrens
499fa9e406ahrens	dump_spacemap(spa->spa_meta_objset, smo, &msp->ms_map);
500fa9e406ahrens}
501fa9e406ahrens
502fa9e406ahrensstatic void
503fa9e406ahrensdump_metaslabs(spa_t *spa)
504fa9e406ahrens{
505fa9e406ahrens	vdev_t *rvd = spa->spa_root_vdev;
506fa9e406ahrens	vdev_t *vd;
507fa9e406ahrens	int c, m;
508fa9e406ahrens
509fa9e406ahrens	(void) printf("\nMetaslabs:\n");
510fa9e406ahrens
511fa9e406ahrens	for (c = 0; c < rvd->vdev_children; c++) {
512fa9e406ahrens		vd = rvd->vdev_child[c];
513fa9e406ahrens
514e14bb32Jeff Bonwick		(void) printf("\n    vdev %llu\n\n", (u_longlong_t)vd->vdev_id);
515fa9e406ahrens
516fa9e406ahrens		if (dump_opt['d'] <= 5) {
517fa9e406ahrens			(void) printf("\t%10s   %10s   %5s\n",
518fa9e406ahrens			    "offset", "spacemap", "free");
519fa9e406ahrens			(void) printf("\t%10s   %10s   %5s\n",
520fa9e406ahrens			    "------", "--------", "----");
521fa9e406ahrens		}
522fa9e406ahrens		for (m = 0; m < vd->vdev_ms_count; m++)
523fa9e406ahrens			dump_metaslab(vd->vdev_ms[m]);
524fa9e406ahrens		(void) printf("\n");
525fa9e406ahrens	}
526fa9e406ahrens}
527fa9e406ahrens
528fa9e406ahrensstatic void
5298ad4d6dJeff Bonwickdump_dtl_seg(space_map_t *sm, uint64_t start, uint64_t size)
5308ad4d6dJeff Bonwick{
5318ad4d6dJeff Bonwick	char *prefix = (void *)sm;
5328ad4d6dJeff Bonwick
5338ad4d6dJeff Bonwick	(void) printf("%s [%llu,%llu) length %llu\n",
5348ad4d6dJeff Bonwick	    prefix,
5358ad4d6dJeff Bonwick	    (u_longlong_t)start,
5368ad4d6dJeff Bonwick	    (u_longlong_t)(start + size),
5378ad4d6dJeff Bonwick	    (u_longlong_t)(size));
5388ad4d6dJeff Bonwick}
5398ad4d6dJeff Bonwick
5408ad4d6dJeff Bonwickstatic void
541fa9e406ahrensdump_dtl(vdev_t *vd, int indent)
542fa9e406ahrens{
5438ad4d6dJeff Bonwick	spa_t *spa = vd->vdev_spa;
5448ad4d6dJeff Bonwick	boolean_t required;
5458ad4d6dJeff Bonwick	char *name[DTL_TYPES] = { "missing", "partial", "scrub", "outage" };
5468ad4d6dJeff Bonwick	char prefix[256];
5478ad4d6dJeff Bonwick
5488ad4d6dJeff Bonwick	spa_vdev_state_enter(spa);
5498ad4d6dJeff Bonwick	required = vdev_dtl_required(vd);
5508ad4d6dJeff Bonwick	(void) spa_vdev_state_exit(spa, NULL, 0);
551fa9e406ahrens
552fa9e406ahrens	if (indent == 0)
553fa9e406ahrens		(void) printf("\nDirty time logs:\n\n");
554fa9e406ahrens
5558ad4d6dJeff Bonwick	(void) printf("\t%*s%s [%s]\n", indent, "",
556e14bb32Jeff Bonwick	    vd->vdev_path ? vd->vdev_path :
5578ad4d6dJeff Bonwick	    vd->vdev_parent ? vd->vdev_ops->vdev_op_type : spa_name(spa),
5588ad4d6dJeff Bonwick	    required ? "DTL-required" : "DTL-expendable");
559fa9e406ahrens
5608ad4d6dJeff Bonwick	for (int t = 0; t < DTL_TYPES; t++) {
5618ad4d6dJeff Bonwick		space_map_t *sm = &vd->vdev_dtl[t];
5628ad4d6dJeff Bonwick		if (sm->sm_space == 0)
5638ad4d6dJeff Bonwick			continue;
5648ad4d6dJeff Bonwick		(void) snprintf(prefix, sizeof (prefix), "\t%*s%s",
5658ad4d6dJeff Bonwick		    indent + 2, "", name[t]);
5668ad4d6dJeff Bonwick		mutex_enter(sm->sm_lock);
5678ad4d6dJeff Bonwick		space_map_walk(sm, dump_dtl_seg, (void *)prefix);
5688ad4d6dJeff Bonwick		mutex_exit(sm->sm_lock);
5698ad4d6dJeff Bonwick		if (dump_opt['d'] > 5 && vd->vdev_children == 0)
5708ad4d6dJeff Bonwick			dump_spacemap(spa->spa_meta_objset,
5718ad4d6dJeff Bonwick			    &vd->vdev_dtl_smo, sm);
572fa9e406ahrens	}
573fa9e406ahrens
5748ad4d6dJeff Bonwick	for (int c = 0; c < vd->vdev_children; c++)
575fa9e406ahrens		dump_dtl(vd->vdev_child[c], indent + 4);
576fa9e406ahrens}
577fa9e406ahrens
578fa9e406ahrens/*ARGSUSED*/
579fa9e406ahrensstatic void
580fa9e406ahrensdump_dnode(objset_t *os, uint64_t object, void *data, size_t size)
581fa9e406ahrens{
582fa9e406ahrens}
583fa9e406ahrens
584fa9e406ahrensstatic uint64_t
58588b7b0fMatthew Ahrensblkid2offset(const dnode_phys_t *dnp, int level, uint64_t blkid)
586fa9e406ahrens{
587fa9e406ahrens	if (level < 0)
588fa9e406ahrens		return (blkid);
589fa9e406ahrens
590fa9e406ahrens	return ((blkid << (level * (dnp->dn_indblkshift - SPA_BLKPTRSHIFT))) *
591fa9e406ahrens	    dnp->dn_datablkszsec << SPA_MINBLOCKSHIFT);
592fa9e406ahrens}
593fa9e406ahrens
59444cd46cbillmstatic void
59544cd46cbillmsprintf_blkptr_compact(char *blkbuf, blkptr_t *bp, int alldvas)
59644cd46cbillm{
59744cd46cbillm	dva_t *dva = bp->blk_dva;
59844cd46cbillm	int ndvas = alldvas ? BP_GET_NDVAS(bp) : 1;
59944cd46cbillm	int i;
60044cd46cbillm
60144cd46cbillm	blkbuf[0] = '\0';
60244cd46cbillm
60344cd46cbillm	for (i = 0; i < ndvas; i++)
60444cd46cbillm		(void) sprintf(blkbuf + strlen(blkbuf), "%llu:%llx:%llx ",
60544cd46cbillm		    (u_longlong_t)DVA_GET_VDEV(&dva[i]),
60644cd46cbillm		    (u_longlong_t)DVA_GET_OFFSET(&dva[i]),
60744cd46cbillm		    (u_longlong_t)DVA_GET_ASIZE(&dva[i]));
60844cd46cbillm
60944cd46cbillm	(void) sprintf(blkbuf + strlen(blkbuf), "%llxL/%llxP F=%llu B=%llu",
61044cd46cbillm	    (u_longlong_t)BP_GET_LSIZE(bp),
61144cd46cbillm	    (u_longlong_t)BP_GET_PSIZE(bp),
61244cd46cbillm	    (u_longlong_t)bp->blk_fill,
61344cd46cbillm	    (u_longlong_t)bp->blk_birth);
61444cd46cbillm}
61544cd46cbillm
61688b7b0fMatthew Ahrensstatic void
61788b7b0fMatthew Ahrensprint_indirect(blkptr_t *bp, const zbookmark_t *zb,
61888b7b0fMatthew Ahrens    const dnode_phys_t *dnp)
619fa9e406ahrens{
62088b7b0fMatthew Ahrens	char blkbuf[BP_SPRINTF_LEN];
621fa9e406ahrens	int l;
622fa9e406ahrens
62388b7b0fMatthew Ahrens	ASSERT3U(BP_GET_TYPE(bp), ==, dnp->dn_type);
62488b7b0fMatthew Ahrens	ASSERT3U(BP_GET_LEVEL(bp), ==, zb->zb_level);
625fa9e406ahrens
62688b7b0fMatthew Ahrens	(void) printf("%16llx ",
627fa9e406ahrens	    (u_longlong_t)blkid2offset(dnp, zb->zb_level, zb->zb_blkid));
628fa9e406ahrens
629fa9e406ahrens	ASSERT(zb->zb_level >= 0);
630fa9e406ahrens
631fa9e406ahrens	for (l = dnp->dn_nlevels - 1; l >= -1; l--) {
632fa9e406ahrens		if (l == zb->zb_level) {
63388b7b0fMatthew Ahrens			(void) printf("L%llx", (u_longlong_t)zb->zb_level);
634fa9e406ahrens		} else {
63588b7b0fMatthew Ahrens			(void) printf(" ");
636fa9e406ahrens		}
637fa9e406ahrens	}
638fa9e406ahrens
63988b7b0fMatthew Ahrens	sprintf_blkptr_compact(blkbuf, bp, dump_opt['d'] > 5 ? 1 : 0);
64088b7b0fMatthew Ahrens	(void) printf("%s\n", blkbuf);
64188b7b0fMatthew Ahrens}
64288b7b0fMatthew Ahrens
64388b7b0fMatthew Ahrens#define	SET_BOOKMARK(zb, objset, object, level, blkid)  \
64488b7b0fMatthew Ahrens{                                                       \
64588b7b0fMatthew Ahrens	(zb)->zb_objset = objset;                       \
64688b7b0fMatthew Ahrens	(zb)->zb_object = object;                       \
64788b7b0fMatthew Ahrens	(zb)->zb_level = level;                         \
64888b7b0fMatthew Ahrens	(zb)->zb_blkid = blkid;                         \
64988b7b0fMatthew Ahrens}
65088b7b0fMatthew Ahrens
65188b7b0fMatthew Ahrensstatic int
65288b7b0fMatthew Ahrensvisit_indirect(spa_t *spa, const dnode_phys_t *dnp,
65388b7b0fMatthew Ahrens    blkptr_t *bp, const zbookmark_t *zb)
65488b7b0fMatthew Ahrens{
65588b7b0fMatthew Ahrens	int err;
65688b7b0fMatthew Ahrens
65788b7b0fMatthew Ahrens	if (bp->blk_birth == 0)
65888b7b0fMatthew Ahrens		return (0);
65988b7b0fMatthew Ahrens
66088b7b0fMatthew Ahrens	print_indirect(bp, zb, dnp);
66188b7b0fMatthew Ahrens
66288b7b0fMatthew Ahrens	if (BP_GET_LEVEL(bp) > 0) {
66388b7b0fMatthew Ahrens		uint32_t flags = ARC_WAIT;
66488b7b0fMatthew Ahrens		int i;
66588b7b0fMatthew Ahrens		blkptr_t *cbp;
66688b7b0fMatthew Ahrens		int epb = BP_GET_LSIZE(bp) >> SPA_BLKPTRSHIFT;
66788b7b0fMatthew Ahrens		arc_buf_t *buf;
66888b7b0fMatthew Ahrens		uint64_t fill = 0;
66988b7b0fMatthew Ahrens
67088b7b0fMatthew Ahrens		err = arc_read_nolock(NULL, spa, bp, arc_getbuf_func, &buf,
67188b7b0fMatthew Ahrens		    ZIO_PRIORITY_ASYNC_READ, ZIO_FLAG_CANFAIL, &flags, zb);
67288b7b0fMatthew Ahrens		if (err)
67388b7b0fMatthew Ahrens			return (err);
67488b7b0fMatthew Ahrens
67588b7b0fMatthew Ahrens		/* recursively visit blocks below this */
67688b7b0fMatthew Ahrens		cbp = buf->b_data;
67788b7b0fMatthew Ahrens		for (i = 0; i < epb; i++, cbp++) {
67888b7b0fMatthew Ahrens			zbookmark_t czb;
67988b7b0fMatthew Ahrens
68088b7b0fMatthew Ahrens			SET_BOOKMARK(&czb, zb->zb_objset, zb->zb_object,
68188b7b0fMatthew Ahrens			    zb->zb_level - 1,
68288b7b0fMatthew Ahrens			    zb->zb_blkid * epb + i);
68388b7b0fMatthew Ahrens			err = visit_indirect(spa, dnp, cbp, &czb);
68488b7b0fMatthew Ahrens			if (err)
68588b7b0fMatthew Ahrens				break;
68688b7b0fMatthew Ahrens			fill += cbp->blk_fill;
68788b7b0fMatthew Ahrens		}
6888ad4d6dJeff Bonwick		if (!err)
6898ad4d6dJeff Bonwick			ASSERT3U(fill, ==, bp->blk_fill);
69088b7b0fMatthew Ahrens		(void) arc_buf_remove_ref(buf, &buf);
691fa9e406ahrens	}
692fa9e406ahrens
69388b7b0fMatthew Ahrens	return (err);
694fa9e406ahrens}
695fa9e406ahrens
696fa9e406ahrens/*ARGSUSED*/
697fa9e406ahrensstatic void
69888b7b0fMatthew Ahrensdump_indirect(dnode_t *dn)
699fa9e406ahrens{
70088b7b0fMatthew Ahrens	dnode_phys_t *dnp = dn->dn_phys;
70188b7b0fMatthew Ahrens	int j;
70288b7b0fMatthew Ahrens	zbookmark_t czb;
703fa9e406ahrens
704fa9e406ahrens	(void) printf("Indirect blocks:\n");
705fa9e406ahrens
70688b7b0fMatthew Ahrens	SET_BOOKMARK(&czb, dmu_objset_id(&dn->dn_objset->os),
70788b7b0fMatthew Ahrens	    dn->dn_object, dnp->dn_nlevels - 1, 0);
70888b7b0fMatthew Ahrens	for (j = 0; j < dnp->dn_nblkptr; j++) {
70988b7b0fMatthew Ahrens		czb.zb_blkid = j;
71088b7b0fMatthew Ahrens		(void) visit_indirect(dmu_objset_spa(&dn->dn_objset->os), dnp,
71188b7b0fMatthew Ahrens		    &dnp->dn_blkptr[j], &czb);
71288b7b0fMatthew Ahrens	}
713fa9e406ahrens
714fa9e406ahrens	(void) printf("\n");
715fa9e406ahrens}
716fa9e406ahrens
717fa9e406ahrens/*ARGSUSED*/
718fa9e406ahrensstatic void
719fa9e406ahrensdump_dsl_dir(objset_t *os, uint64_t object, void *data, size_t size)
720fa9e406ahrens{
721fa9e406ahrens	dsl_dir_phys_t *dd = data;
722fa9e406ahrens	time_t crtime;
72374e7dc9Matthew Ahrens	char nice[6];
724fa9e406ahrens
725fa9e406ahrens	if (dd == NULL)
726fa9e406ahrens		return;
727fa9e406ahrens
728da6c28aamw	ASSERT3U(size, >=, sizeof (dsl_dir_phys_t));
729fa9e406ahrens
730fa9e406ahrens	crtime = dd->dd_creation_time;
731fa9e406ahrens	(void) printf("\t\tcreation_time = %s", ctime(&crtime));
732fa9e406ahrens	(void) printf("\t\thead_dataset_obj = %llu\n",
733fa9e406ahrens	    (u_longlong_t)dd->dd_head_dataset_obj);
734fa9e406ahrens	(void) printf("\t\tparent_dir_obj = %llu\n",
735fa9e406ahrens	    (u_longlong_t)dd->dd_parent_obj);
7363cb34c6ahrens	(void) printf("\t\torigin_obj = %llu\n",
7373cb34c6ahrens	    (u_longlong_t)dd->dd_origin_obj);
738fa9e406ahrens	(void) printf("\t\tchild_dir_zapobj = %llu\n",
739fa9e406ahrens	    (u_longlong_t)dd->dd_child_dir_zapobj);
74074e7dc9Matthew Ahrens	nicenum(dd->dd_used_bytes, nice);
74174e7dc9Matthew Ahrens	(void) printf("\t\tused_bytes = %s\n", nice);
74274e7dc9Matthew Ahrens	nicenum(dd->dd_compressed_bytes, nice);
74374e7dc9Matthew Ahrens	(void) printf("\t\tcompressed_bytes = %s\n", nice);
74474e7dc9Matthew Ahrens	nicenum(dd->dd_uncompressed_bytes, nice);
74574e7dc9Matthew Ahrens	(void) printf("\t\tuncompressed_bytes = %s\n", nice);
74674e7dc9Matthew Ahrens	nicenum(dd->dd_quota, nice);
74774e7dc9Matthew Ahrens	(void) printf("\t\tquota = %s\n", nice);
74874e7dc9Matthew Ahrens	nicenum(dd->dd_reserved, nice);
74974e7dc9Matthew Ahrens	(void) printf("\t\treserved = %s\n", nice);
750fa9e406ahrens	(void) printf("\t\tprops_zapobj = %llu\n",
751fa9e406ahrens	    (u_longlong_t)dd->dd_props_zapobj);
752ecd6cf8marks	(void) printf("\t\tdeleg_zapobj = %llu\n",
753ecd6cf8marks	    (u_longlong_t)dd->dd_deleg_zapobj);
75474e7dc9Matthew Ahrens	(void) printf("\t\tflags = %llx\n",
75574e7dc9Matthew Ahrens	    (u_longlong_t)dd->dd_flags);
75674e7dc9Matthew Ahrens
75774e7dc9Matthew Ahrens#define	DO(which) \
75874e7dc9Matthew Ahrens	nicenum(dd->dd_used_breakdown[DD_USED_ ## which], nice); \
75974e7dc9Matthew Ahrens	(void) printf("\t\tused_breakdown[" #which "] = %s\n", nice)
76074e7dc9Matthew Ahrens	DO(HEAD);
76174e7dc9Matthew Ahrens	DO(SNAP);
76274e7dc9Matthew Ahrens	DO(CHILD);
76374e7dc9Matthew Ahrens	DO(CHILD_RSRV);
76474e7dc9Matthew Ahrens	DO(REFRSRV);
76574e7dc9Matthew Ahrens#undef DO
766fa9e406ahrens}
767fa9e406ahrens
768fa9e406ahrens/*ARGSUSED*/
769fa9e406ahrensstatic void
770fa9e406ahrensdump_dsl_dataset(objset_t *os, uint64_t object, void *data, size_t size)
771fa9e406ahrens{
772fa9e406ahrens	dsl_dataset_phys_t *ds = data;
773fa9e406ahrens	time_t crtime;
774fbabab8maybee	char used[6], compressed[6], uncompressed[6], unique[6];
775fbabab8maybee	char blkbuf[BP_SPRINTF_LEN];
776fa9e406ahrens
777fa9e406ahrens	if (ds == NULL)
778fa9e406ahrens		return;
779fa9e406ahrens
780fa9e406ahrens	ASSERT(size == sizeof (*ds));
781fa9e406ahrens	crtime = ds->ds_creation_time;
782fa9e406ahrens	nicenum(ds->ds_used_bytes, used);
783fa9e406ahrens	nicenum(ds->ds_compressed_bytes, compressed);
784fa9e406ahrens	nicenum(ds->ds_uncompressed_bytes, uncompressed);
785fa9e406ahrens	nicenum(ds->ds_unique_bytes, unique);
786fbabab8maybee	sprintf_blkptr(blkbuf, BP_SPRINTF_LEN, &ds->ds_bp);
787fa9e406ahrens
788088f389ahrens	(void) printf("\t\tdir_obj = %llu\n",
789fa9e406ahrens	    (u_longlong_t)ds->ds_dir_obj);
790fa9e406ahrens	(void) printf("\t\tprev_snap_obj = %llu\n",
791fa9e406ahrens	    (u_longlong_t)ds->ds_prev_snap_obj);
792fa9e406ahrens	(void) printf("\t\tprev_snap_txg = %llu\n",
793fa9e406ahrens	    (u_longlong_t)ds->ds_prev_snap_txg);
794fa9e406ahrens	(void) printf("\t\tnext_snap_obj = %llu\n",
795fa9e406ahrens	    (u_longlong_t)ds->ds_next_snap_obj);
796fa9e406ahrens	(void) printf("\t\tsnapnames_zapobj = %llu\n",
797fa9e406ahrens	    (u_longlong_t)ds->ds_snapnames_zapobj);
798fa9e406ahrens	(void) printf("\t\tnum_children = %llu\n",
799fa9e406ahrens	    (u_longlong_t)ds->ds_num_children);
800fa9e406ahrens	(void) printf("\t\tcreation_time = %s", ctime(&crtime));
801fa9e406ahrens	(void) printf("\t\tcreation_txg = %llu\n",
802fa9e406ahrens	    (u_longlong_t)ds->ds_creation_txg);
803fa9e406ahrens	(void) printf("\t\tdeadlist_obj = %llu\n",
804fa9e406ahrens	    (u_longlong_t)ds->ds_deadlist_obj);
805fa9e406ahrens	(void) printf("\t\tused_bytes = %s\n", used);
806fa9e406ahrens	(void) printf("\t\tcompressed_bytes = %s\n", compressed);
807fa9e406ahrens	(void) printf("\t\tuncompressed_bytes = %s\n", uncompressed);
808fa9e406ahrens	(void) printf("\t\tunique = %s\n", unique);
809fa9e406ahrens	(void) printf("\t\tfsid_guid = %llu\n",
810fa9e406ahrens	    (u_longlong_t)ds->ds_fsid_guid);
811fa9e406ahrens	(void) printf("\t\tguid = %llu\n",
812fa9e406ahrens	    (u_longlong_t)ds->ds_guid);
81399653d4eschrock	(void) printf("\t\tflags = %llx\n",
81499653d4eschrock	    (u_longlong_t)ds->ds_flags);
815088f389ahrens	(void) printf("\t\tnext_clones_obj = %llu\n",
816088f389ahrens	    (u_longlong_t)ds->ds_next_clones_obj);
817bb0ade0ahrens	(void) printf("\t\tprops_obj = %llu\n",
818bb0ade0ahrens	    (u_longlong_t)ds->ds_props_obj);
819fa9e406ahrens	(void) printf("\t\tbp = %s\n", blkbuf);
820fa9e406ahrens}
821fa9e406ahrens
822fa9e406ahrensstatic void
823fa9e406ahrensdump_bplist(objset_t *mos, uint64_t object, char *name)
824fa9e406ahrens{
825fa9e406ahrens	bplist_t bpl = { 0 };
826fa9e406ahrens	blkptr_t blk, *bp = &blk;
827fa9e406ahrens	uint64_t itor = 0;
82899653d4eschrock	char bytes[6];
82999653d4eschrock	char comp[6];
83099653d4eschrock	char uncomp[6];
831fa9e406ahrens
832fa9e406ahrens	if (dump_opt['d'] < 3)
833fa9e406ahrens		return;
834fa9e406ahrens
835c25056dgw	mutex_init(&bpl.bpl_lock, NULL, MUTEX_DEFAULT, NULL);
836ea8dc4beschrock	VERIFY(0 == bplist_open(&bpl, mos, object));
837fa9e406ahrens	if (bplist_empty(&bpl)) {
838fa9e406ahrens		bplist_close(&bpl);
839c25056dgw		mutex_destroy(&bpl.bpl_lock);
840fa9e406ahrens		return;
841fa9e406ahrens	}
842fa9e406ahrens
84399653d4eschrock	nicenum(bpl.bpl_phys->bpl_bytes, bytes);
84499653d4eschrock	if (bpl.bpl_dbuf->db_size == sizeof (bplist_phys_t)) {
84599653d4eschrock		nicenum(bpl.bpl_phys->bpl_comp, comp);
84699653d4eschrock		nicenum(bpl.bpl_phys->bpl_uncomp, uncomp);
84799653d4eschrock		(void) printf("\n    %s: %llu entries, %s (%s/%s comp)\n",
84899653d4eschrock		    name, (u_longlong_t)bpl.bpl_phys->bpl_entries,
84999653d4eschrock		    bytes, comp, uncomp);
85099653d4eschrock	} else {
85199653d4eschrock		(void) printf("\n    %s: %llu entries, %s\n",
85299653d4eschrock		    name, (u_longlong_t)bpl.bpl_phys->bpl_entries, bytes);
85399653d4eschrock	}
854fa9e406ahrens
855fa9e406ahrens	if (dump_opt['d'] < 5) {
856fa9e406ahrens		bplist_close(&bpl);
857c25056dgw		mutex_destroy(&bpl.bpl_lock);
858fa9e406ahrens		return;
859fa9e406ahrens	}
860fa9e406ahrens
861fa9e406ahrens	(void) printf("\n");
862fa9e406ahrens
863fa9e406ahrens	while (bplist_iterate(&bpl, &itor, bp) == 0) {
86444cd46cbillm		char blkbuf[BP_SPRINTF_LEN];
86544cd46cbillm
866fa9e406ahrens		ASSERT(bp->blk_birth != 0);
86744cd46cbillm		sprintf_blkptr_compact(blkbuf, bp, dump_opt['d'] > 5 ? 1 : 0);
86844cd46cbillm		(void) printf("\tItem %3llu: %s\n",
86944cd46cbillm		    (u_longlong_t)itor - 1, blkbuf);
870fa9e406ahrens	}
871fa9e406ahrens
872fa9e406ahrens	bplist_close(&bpl);
873c25056dgw	mutex_destroy(&bpl.bpl_lock);
874fa9e406ahrens}
875fa9e406ahrens
876e0d35c4marksstatic avl_tree_t idx_tree;
877e0d35c4marksstatic avl_tree_t domain_tree;
878e0d35c4marksstatic boolean_t fuid_table_loaded;
879e0d35c4marks
880e0d35c4marksstatic void
881e0d35c4marksfuid_table_destroy()
882e0d35c4marks{
883e0d35c4marks	if (fuid_table_loaded) {
884e0d35c4marks		zfs_fuid_table_destroy(&idx_tree, &domain_tree);
885e0d35c4marks		fuid_table_loaded = B_FALSE;
886e0d35c4marks	}
887e0d35c4marks}
888e0d35c4marks
889e0d35c4marks/*
890