zdb.c revision d41e76436a9498c7a8ab1f783125ac49f517eaf9
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/*
22e0d35c4marks * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
23fa9e406ahrens * Use is subject to license terms.
24fa9e406ahrens */
25fa9e406ahrens
26fa9e406ahrens#pragma ident	"%Z%%M%	%I%	%E% SMI"
27fa9e406ahrens
28fa9e406ahrens#include <stdio.h>
29004388ecasper#include <stdio_ext.h>
30fa9e406ahrens#include <stdlib.h>
3144cd46cbillm#include <ctype.h>
32fa9e406ahrens#include <sys/zfs_context.h>
33fa9e406ahrens#include <sys/spa.h>
34fa9e406ahrens#include <sys/spa_impl.h>
35fa9e406ahrens#include <sys/dmu.h>
36fa9e406ahrens#include <sys/zap.h>
37fa9e406ahrens#include <sys/fs/zfs.h>
38fa9e406ahrens#include <sys/zfs_znode.h>
39fa9e406ahrens#include <sys/vdev.h>
40fa9e406ahrens#include <sys/vdev_impl.h>
41fa9e406ahrens#include <sys/metaslab_impl.h>
42fa9e406ahrens#include <sys/dmu_objset.h>
43fa9e406ahrens#include <sys/dsl_dir.h>
44fa9e406ahrens#include <sys/dsl_dataset.h>
45fa9e406ahrens#include <sys/dsl_pool.h>
46fa9e406ahrens#include <sys/dbuf.h>
47fa9e406ahrens#include <sys/zil.h>
48fa9e406ahrens#include <sys/zil_impl.h>
49fa9e406ahrens#include <sys/stat.h>
50fa9e406ahrens#include <sys/resource.h>
51fa9e406ahrens#include <sys/dmu_traverse.h>
52fa9e406ahrens#include <sys/zio_checksum.h>
53fa9e406ahrens#include <sys/zio_compress.h>
54e0d35c4marks#include <sys/zfs_fuid.h>
55de6628fck#undef ZFS_MAXNAMELEN
56de6628fck#undef verify
57de6628fck#include <libzfs.h>
58fa9e406ahrens
59fa9e406ahrensconst char cmdname[] = "zdb";
60fa9e406ahrensuint8_t dump_opt[256];
61fa9e406ahrens
62fa9e406ahrenstypedef void object_viewer_t(objset_t *, uint64_t, void *data, size_t size);
63fa9e406ahrens
64fa9e406ahrensextern void dump_intent_log(zilog_t *);
65fa9e406ahrensuint64_t *zopt_object = NULL;
66fa9e406ahrensint zopt_objects = 0;
67fa9e406ahrensint zdb_advance = ADVANCE_PRE;
68fa9e406ahrenszbookmark_t zdb_noread = { 0, 0, ZB_NO_LEVEL, 0 };
69de6628fcklibzfs_handle_t *g_zfs;
70d41e764ekboolean_t zdb_sig_user_data = B_TRUE;
71d41e764ekint zdb_sig_cksumalg = ZIO_CHECKSUM_SHA256;
72fa9e406ahrens
73fa9e406ahrens/*
74fa9e406ahrens * These libumem hooks provide a reasonable set of defaults for the allocator's
75fa9e406ahrens * debugging facilities.
76fa9e406ahrens */
77fa9e406ahrensconst char *
78fa9e406ahrens_umem_debug_init()
79fa9e406ahrens{
80fa9e406ahrens	return ("default,verbose"); /* $UMEM_DEBUG setting */
81fa9e406ahrens}
82fa9e406ahrens
83fa9e406ahrensconst char *
84fa9e406ahrens_umem_logging_init(void)
85fa9e406ahrens{
86fa9e406ahrens	return ("fail,contents"); /* $UMEM_LOGGING setting */
87fa9e406ahrens}
88fa9e406ahrens
89fa9e406ahrensstatic void
90fa9e406ahrensusage(void)
91fa9e406ahrens{
92fa9e406ahrens	(void) fprintf(stderr,
933a57275ck	    "Usage: %s [-udibcsvL] [-U cachefile_path] [-O order] "
94d41e764ek	    "[-B os:obj:level:blkid] [-S user:cksumalg] "
95fa9e406ahrens	    "dataset [object...]\n"
96fa9e406ahrens	    "       %s -C [pool]\n"
9744cd46cbillm	    "       %s -l dev\n"
98de6628fck	    "       %s -R vdev:offset:size:flags\n"
993a57275ck	    "       %s [-p path_to_vdev_dir]\n"
1003a57275ck	    "       %s -e pool | GUID | devid ...\n",
1013a57275ck	    cmdname, cmdname, cmdname, cmdname, cmdname, cmdname);
102fa9e406ahrens
103fa9e406ahrens	(void) fprintf(stderr, "	-u uberblock\n");
104fa9e406ahrens	(void) fprintf(stderr, "	-d datasets\n");
105fa9e406ahrens	(void) fprintf(stderr, "        -C cached pool configuration\n");
106fa9e406ahrens	(void) fprintf(stderr, "	-i intent logs\n");
107fa9e406ahrens	(void) fprintf(stderr, "	-b block statistics\n");
108fa9e406ahrens	(void) fprintf(stderr, "	-c checksum all data blocks\n");
109fa9e406ahrens	(void) fprintf(stderr, "	-s report stats on zdb's I/O\n");
110d41e764ek	(void) fprintf(stderr, "	-S <user|all>:<cksum_alg|all> -- "
111d41e764ek	    "dump blkptr signatures\n");
112fa9e406ahrens	(void) fprintf(stderr, "	-v verbose (applies to all others)\n");
113fa9e406ahrens	(void) fprintf(stderr, "        -l dump label contents\n");
114fa9e406ahrens	(void) fprintf(stderr, "	-L live pool (allows some errors)\n");
115fa9e406ahrens	(void) fprintf(stderr, "	-O [!]<pre|post|prune|data|holes> "
116fa9e406ahrens	    "visitation order\n");
1173a57275ck	(void) fprintf(stderr, "	-U cachefile_path -- use alternate "
1183a57275ck	    "cachefile\n");
119fa9e406ahrens	(void) fprintf(stderr, "	-B objset:object:level:blkid -- "
120fa9e406ahrens	    "simulate bad block\n");
121d41e764ek	(void) fprintf(stderr, "        -R read and display block from a "
12244cd46cbillm	    "device\n");
1233a57275ck	(void) fprintf(stderr, "        -e Pool is exported/destroyed/"
1243a57275ck	    "has altroot\n");
125de6628fck	(void) fprintf(stderr, "	-p <Path to vdev dir> (use with -e)\n");
126fa9e406ahrens	(void) fprintf(stderr, "Specify an option more than once (e.g. -bb) "
127fa9e406ahrens	    "to make only that option verbose\n");
128fa9e406ahrens	(void) fprintf(stderr, "Default is to dump everything non-verbosely\n");
129fa9e406ahrens	exit(1);
130fa9e406ahrens}
131fa9e406ahrens
132fa9e406ahrensstatic void
133fa9e406ahrensfatal(const char *fmt, ...)
134fa9e406ahrens{
135fa9e406ahrens	va_list ap;
136fa9e406ahrens
137fa9e406ahrens	va_start(ap, fmt);
138fa9e406ahrens	(void) fprintf(stderr, "%s: ", cmdname);
139fa9e406ahrens	(void) vfprintf(stderr, fmt, ap);
140fa9e406ahrens	va_end(ap);
141fa9e406ahrens	(void) fprintf(stderr, "\n");
142fa9e406ahrens
143fa9e406ahrens	exit(1);
144fa9e406ahrens}
145fa9e406ahrens
146fa9e406ahrensstatic void
147fa9e406ahrensdump_nvlist(nvlist_t *list, int indent)
148fa9e406ahrens{
149fa9e406ahrens	nvpair_t *elem = NULL;
150fa9e406ahrens
151fa9e406ahrens	while ((elem = nvlist_next_nvpair(list, elem)) != NULL) {
152fa9e406ahrens		switch (nvpair_type(elem)) {
153fa9e406ahrens		case DATA_TYPE_STRING:
154fa9e406ahrens			{
155fa9e406ahrens				char *value;
156fa9e406ahrens
157fa9e406ahrens				VERIFY(nvpair_value_string(elem, &value) == 0);
158fa9e406ahrens				(void) printf("%*s%s='%s'\n", indent, "",
159fa9e406ahrens				    nvpair_name(elem), value);
160fa9e406ahrens			}
161fa9e406ahrens			break;
162fa9e406ahrens
163fa9e406ahrens		case DATA_TYPE_UINT64:
164fa9e406ahrens			{
165fa9e406ahrens				uint64_t value;
166fa9e406ahrens
167fa9e406ahrens				VERIFY(nvpair_value_uint64(elem, &value) == 0);
168fa9e406ahrens				(void) printf("%*s%s=%llu\n", indent, "",
169fa9e406ahrens				    nvpair_name(elem), (u_longlong_t)value);
170fa9e406ahrens			}
171fa9e406ahrens			break;
172fa9e406ahrens
173fa9e406ahrens		case DATA_TYPE_NVLIST:
174fa9e406ahrens			{
175fa9e406ahrens				nvlist_t *value;
176fa9e406ahrens
177fa9e406ahrens				VERIFY(nvpair_value_nvlist(elem, &value) == 0);
178fa9e406ahrens				(void) printf("%*s%s\n", indent, "",
179fa9e406ahrens				    nvpair_name(elem));
180fa9e406ahrens				dump_nvlist(value, indent + 4);
181fa9e406ahrens			}
182fa9e406ahrens			break;
183fa9e406ahrens
184fa9e406ahrens		case DATA_TYPE_NVLIST_ARRAY:
185fa9e406ahrens			{
186fa9e406ahrens				nvlist_t **value;
187fa9e406ahrens				uint_t c, count;
188fa9e406ahrens
189fa9e406ahrens				VERIFY(nvpair_value_nvlist_array(elem, &value,
190fa9e406ahrens				    &count) == 0);
191fa9e406ahrens
192fa9e406ahrens				for (c = 0; c < count; c++) {
193fa9e406ahrens					(void) printf("%*s%s[%u]\n", indent, "",
194fa9e406ahrens					    nvpair_name(elem), c);
195fa9e406ahrens					dump_nvlist(value[c], indent + 8);
196fa9e406ahrens				}
197fa9e406ahrens			}
198fa9e406ahrens			break;
199fa9e406ahrens
200fa9e406ahrens		default:
201fa9e406ahrens
202fa9e406ahrens			(void) printf("bad config type %d for %s\n",
203fa9e406ahrens			    nvpair_type(elem), nvpair_name(elem));
204fa9e406ahrens		}
205fa9e406ahrens	}
206fa9e406ahrens}
207fa9e406ahrens
208fa9e406ahrens/* ARGSUSED */
209fa9e406ahrensstatic void
210fa9e406ahrensdump_packed_nvlist(objset_t *os, uint64_t object, void *data, size_t size)
211fa9e406ahrens{
212fa9e406ahrens	nvlist_t *nv;
213fa9e406ahrens	size_t nvsize = *(uint64_t *)data;
214fa9e406ahrens	char *packed = umem_alloc(nvsize, UMEM_NOFAIL);
215fa9e406ahrens
216ea8dc4beschrock	VERIFY(0 == dmu_read(os, object, 0, nvsize, packed));
217fa9e406ahrens
218fa9e406ahrens	VERIFY(nvlist_unpack(packed, nvsize, &nv, 0) == 0);
219fa9e406ahrens
220fa9e406ahrens	umem_free(packed, nvsize);
221fa9e406ahrens
222fa9e406ahrens	dump_nvlist(nv, 8);
223fa9e406ahrens
224fa9e406ahrens	nvlist_free(nv);
225fa9e406ahrens}
226fa9e406ahrens
227fa9e406ahrensconst char dump_zap_stars[] = "****************************************";
228fa9e406ahrensconst int dump_zap_width = sizeof (dump_zap_stars) - 1;
229fa9e406ahrens
230fa9e406ahrensstatic void
231fa9e406ahrensdump_zap_histogram(uint64_t histo[ZAP_HISTOGRAM_SIZE])
232fa9e406ahrens{
233fa9e406ahrens	int i;
234fa9e406ahrens	int minidx = ZAP_HISTOGRAM_SIZE - 1;
235fa9e406ahrens	int maxidx = 0;
236fa9e406ahrens	uint64_t max = 0;
237fa9e406ahrens
238fa9e406ahrens	for (i = 0; i < ZAP_HISTOGRAM_SIZE; i++) {
239fa9e406ahrens		if (histo[i] > max)
240fa9e406ahrens			max = histo[i];
241fa9e406ahrens		if (histo[i] > 0 && i > maxidx)
242fa9e406ahrens			maxidx = i;
243fa9e406ahrens		if (histo[i] > 0 && i < minidx)
244fa9e406ahrens			minidx = i;
245fa9e406ahrens	}
246fa9e406ahrens
247fa9e406ahrens	if (max < dump_zap_width)
248fa9e406ahrens		max = dump_zap_width;
249fa9e406ahrens
250fa9e406ahrens	for (i = minidx; i <= maxidx; i++)
251fa9e406ahrens		(void) printf("\t\t\t%u: %6llu %s\n", i, (u_longlong_t)histo[i],
252fa9e406ahrens		    &dump_zap_stars[(max - histo[i]) * dump_zap_width / max]);
253fa9e406ahrens}
254fa9e406ahrens
255fa9e406ahrensstatic void
256fa9e406ahrensdump_zap_stats(objset_t *os, uint64_t object)
257fa9e406ahrens{
258fa9e406ahrens	int error;
259fa9e406ahrens	zap_stats_t zs;
260fa9e406ahrens
261fa9e406ahrens	error = zap_get_stats(os, object, &zs);
262fa9e406ahrens	if (error)
263fa9e406ahrens		return;
264fa9e406ahrens
265fa9e406ahrens	if (zs.zs_ptrtbl_len == 0) {
266fa9e406ahrens		ASSERT(zs.zs_num_blocks == 1);
267fa9e406ahrens		(void) printf("\tmicrozap: %llu bytes, %llu entries\n",
268fa9e406ahrens		    (u_longlong_t)zs.zs_blocksize,
269fa9e406ahrens		    (u_longlong_t)zs.zs_num_entries);
270fa9e406ahrens		return;
271fa9e406ahrens	}
272fa9e406ahrens
273fa9e406ahrens	(void) printf("\tFat ZAP stats:\n");
2748248818nd
2758248818nd	(void) printf("\t\tPointer table:\n");
2768248818nd	(void) printf("\t\t\t%llu elements\n",
277fa9e406ahrens	    (u_longlong_t)zs.zs_ptrtbl_len);
2788248818nd	(void) printf("\t\t\tzt_blk: %llu\n",
2798248818nd	    (u_longlong_t)zs.zs_ptrtbl_zt_blk);
2808248818nd	(void) printf("\t\t\tzt_numblks: %llu\n",
2818248818nd	    (u_longlong_t)zs.zs_ptrtbl_zt_numblks);
2828248818nd	(void) printf("\t\t\tzt_shift: %llu\n",
2838248818nd	    (u_longlong_t)zs.zs_ptrtbl_zt_shift);
2848248818nd	(void) printf("\t\t\tzt_blks_copied: %llu\n",
2858248818nd	    (u_longlong_t)zs.zs_ptrtbl_blks_copied);
2868248818nd	(void) printf("\t\t\tzt_nextblk: %llu\n",
2878248818nd	    (u_longlong_t)zs.zs_ptrtbl_nextblk);
2888248818nd
289fa9e406ahrens	(void) printf("\t\tZAP entries: %llu\n",
290fa9e406ahrens	    (u_longlong_t)zs.zs_num_entries);
291fa9e406ahrens	(void) printf("\t\tLeaf blocks: %llu\n",
292fa9e406ahrens	    (u_longlong_t)zs.zs_num_leafs);
293fa9e406ahrens	(void) printf("\t\tTotal blocks: %llu\n",
294fa9e406ahrens	    (u_longlong_t)zs.zs_num_blocks);
2958248818nd	(void) printf("\t\tzap_block_type: 0x%llx\n",
2968248818nd	    (u_longlong_t)zs.zs_block_type);
2978248818nd	(void) printf("\t\tzap_magic: 0x%llx\n",
2988248818nd	    (u_longlong_t)zs.zs_magic);
2998248818nd	(void) printf("\t\tzap_salt: 0x%llx\n",
3008248818nd	    (u_longlong_t)zs.zs_salt);
301fa9e406ahrens
302fa9e406ahrens	(void) printf("\t\tLeafs with 2^n pointers:\n");
303fa9e406ahrens	dump_zap_histogram(zs.zs_leafs_with_2n_pointers);
304fa9e406ahrens
305fa9e406ahrens	(void) printf("\t\tBlocks with n*5 entries:\n");
306fa9e406ahrens	dump_zap_histogram(zs.zs_blocks_with_n5_entries);
307fa9e406ahrens
308fa9e406ahrens	(void) printf("\t\tBlocks n/10 full:\n");
309fa9e406ahrens	dump_zap_histogram(zs.zs_blocks_n_tenths_full);
310fa9e406ahrens
311fa9e406ahrens	(void) printf("\t\tEntries with n chunks:\n");
312fa9e406ahrens	dump_zap_histogram(zs.zs_entries_using_n_chunks);
313fa9e406ahrens
314fa9e406ahrens	(void) printf("\t\tBuckets with n entries:\n");
315fa9e406ahrens	dump_zap_histogram(zs.zs_buckets_with_n_entries);
316fa9e406ahrens}
317fa9e406ahrens
318fa9e406ahrens/*ARGSUSED*/
319fa9e406ahrensstatic void
320fa9e406ahrensdump_none(objset_t *os, uint64_t object, void *data, size_t size)
321fa9e406ahrens{
322fa9e406ahrens}
323fa9e406ahrens
324fa9e406ahrens/*ARGSUSED*/
325fa9e406ahrensvoid
326fa9e406ahrensdump_uint8(objset_t *os, uint64_t object, void *data, size_t size)
327fa9e406ahrens{
328fa9e406ahrens}
329fa9e406ahrens
330fa9e406ahrens/*ARGSUSED*/
331fa9e406ahrensstatic void
332fa9e406ahrensdump_uint64(objset_t *os, uint64_t object, void *data, size_t size)
333fa9e406ahrens{
334fa9e406ahrens}
335fa9e406ahrens
336fa9e406ahrens/*ARGSUSED*/
337fa9e406ahrensstatic void
338fa9e406ahrensdump_zap(objset_t *os, uint64_t object, void *data, size_t size)
339fa9e406ahrens{
340fa9e406ahrens	zap_cursor_t zc;
341fa9e406ahrens	zap_attribute_t attr;
342fa9e406ahrens	void *prop;
343fa9e406ahrens	int i;
344fa9e406ahrens
345fa9e406ahrens	dump_zap_stats(os, object);
346fa9e406ahrens	(void) printf("\n");
347fa9e406ahrens
348fa9e406ahrens	for (zap_cursor_init(&zc, os, object);
349fa9e406ahrens	    zap_cursor_retrieve(&zc, &attr) == 0;
350fa9e406ahrens	    zap_cursor_advance(&zc)) {
351fa9e406ahrens		(void) printf("\t\t%s = ", attr.za_name);
352fa9e406ahrens		if (attr.za_num_integers == 0) {
353fa9e406ahrens			(void) printf("\n");
354fa9e406ahrens			continue;
355fa9e406ahrens		}
356fa9e406ahrens		prop = umem_zalloc(attr.za_num_integers *
357fa9e406ahrens		    attr.za_integer_length, UMEM_NOFAIL);
358fa9e406ahrens		(void) zap_lookup(os, object, attr.za_name,
359fa9e406ahrens		    attr.za_integer_length, attr.za_num_integers, prop);
360fa9e406ahrens		if (attr.za_integer_length == 1) {
361fa9e406ahrens			(void) printf("%s", (char *)prop);
362fa9e406ahrens		} else {
363fa9e406ahrens			for (i = 0; i < attr.za_num_integers; i++) {
364fa9e406ahrens				switch (attr.za_integer_length) {
365fa9e406ahrens				case 2:
366fa9e406ahrens					(void) printf("%u ",
367fa9e406ahrens					    ((uint16_t *)prop)[i]);
368fa9e406ahrens					break;
369fa9e406ahrens				case 4:
370fa9e406ahrens					(void) printf("%u ",
371fa9e406ahrens					    ((uint32_t *)prop)[i]);
372fa9e406ahrens					break;
373fa9e406ahrens				case 8:
374fa9e406ahrens					(void) printf("%lld ",
375fa9e406ahrens					    (u_longlong_t)((int64_t *)prop)[i]);
376fa9e406ahrens					break;
377fa9e406ahrens				}
378fa9e406ahrens			}
379fa9e406ahrens		}
380fa9e406ahrens		(void) printf("\n");
381fa9e406ahrens		umem_free(prop, attr.za_num_integers * attr.za_integer_length);
382fa9e406ahrens	}
38387e5029ahrens	zap_cursor_fini(&zc);
384fa9e406ahrens}
385fa9e406ahrens
386e743726ahrens/*ARGSUSED*/
387e743726ahrensstatic void
388e743726ahrensdump_zpldir(objset_t *os, uint64_t object, void *data, size_t size)
389e743726ahrens{
390e743726ahrens	zap_cursor_t zc;
391e743726ahrens	zap_attribute_t attr;
392e743726ahrens	const char *typenames[] = {
393e743726ahrens		/* 0 */ "not specified",
394e743726ahrens		/* 1 */ "FIFO",
395e743726ahrens		/* 2 */ "Character Device",
396e743726ahrens		/* 3 */ "3 (invalid)",
397e743726ahrens		/* 4 */ "Directory",
398e743726ahrens		/* 5 */ "5 (invalid)",
399e743726ahrens		/* 6 */ "Block Device",
400e743726ahrens		/* 7 */ "7 (invalid)",
401e743726ahrens		/* 8 */ "Regular File",
402e743726ahrens		/* 9 */ "9 (invalid)",
403e743726ahrens		/* 10 */ "Symbolic Link",
404e743726ahrens		/* 11 */ "11 (invalid)",
405e743726ahrens		/* 12 */ "Socket",
406e743726ahrens		/* 13 */ "Door",
407e743726ahrens		/* 14 */ "Event Port",
408e743726ahrens		/* 15 */ "15 (invalid)",
409e743726ahrens	};
410e743726ahrens
411e743726ahrens	dump_zap_stats(os, object);
412e743726ahrens	(void) printf("\n");
413e743726ahrens
414e743726ahrens	for (zap_cursor_init(&zc, os, object);
415e743726ahrens	    zap_cursor_retrieve(&zc, &attr) == 0;
416e743726ahrens	    zap_cursor_advance(&zc)) {
417e743726ahrens		(void) printf("\t\t%s = %lld (type: %s)\n",
418e743726ahrens		    attr.za_name, ZFS_DIRENT_OBJ(attr.za_first_integer),
419e743726ahrens		    typenames[ZFS_DIRENT_TYPE(attr.za_first_integer)]);
420e743726ahrens	}
421e743726ahrens	zap_cursor_fini(&zc);
422e743726ahrens}
423e743726ahrens
424fa9e406ahrensstatic void
425fa9e406ahrensdump_spacemap(objset_t *os, space_map_obj_t *smo, space_map_t *sm)
426fa9e406ahrens{
427fa9e406ahrens	uint64_t alloc, offset, entry;
428ecc2d60bonwick	uint8_t mapshift = sm->sm_shift;
429fa9e406ahrens	uint64_t mapstart = sm->sm_start;
4308053a26ck	char *ddata[] = { "ALLOC", "FREE", "CONDENSE", "INVALID",
4318053a26ck			    "INVALID", "INVALID", "INVALID", "INVALID" };
432fa9e406ahrens
433fa9e406ahrens	if (smo->smo_object == 0)
434fa9e406ahrens		return;
435fa9e406ahrens
436fa9e406ahrens	/*
437fa9e406ahrens	 * Print out the freelist entries in both encoded and decoded form.
438fa9e406ahrens	 */
439fa9e406ahrens	alloc = 0;
440fa9e406ahrens	for (offset = 0; offset < smo->smo_objsize; offset += sizeof (entry)) {
441ea8dc4beschrock		VERIFY(0 == dmu_read(os, smo->smo_object, offset,
442ea8dc4beschrock		    sizeof (entry), &entry));
443fa9e406ahrens		if (SM_DEBUG_DECODE(entry)) {
444fa9e406ahrens			(void) printf("\t\t[%4llu] %s: txg %llu, pass %llu\n",
445fa9e406ahrens			    (u_longlong_t)(offset / sizeof (entry)),
446fa9e406ahrens			    ddata[SM_DEBUG_ACTION_DECODE(entry)],
4475ad8204nd			    (u_longlong_t)SM_DEBUG_TXG_DECODE(entry),
4485ad8204nd			    (u_longlong_t)SM_DEBUG_SYNCPASS_DECODE(entry));
449fa9e406ahrens		} else {
450fa9e406ahrens			(void) printf("\t\t[%4llu]    %c  range:"
451fa9e406ahrens			    " %08llx-%08llx  size: %06llx\n",
452fa9e406ahrens			    (u_longlong_t)(offset / sizeof (entry)),
453fa9e406ahrens			    SM_TYPE_DECODE(entry) == SM_ALLOC ? 'A' : 'F',
4545ad8204nd			    (u_longlong_t)((SM_OFFSET_DECODE(entry) <<
4555ad8204nd			    mapshift) + mapstart),
4565ad8204nd			    (u_longlong_t)((SM_OFFSET_DECODE(entry) <<
4575ad8204nd			    mapshift) + mapstart + (SM_RUN_DECODE(entry) <<
4585ad8204nd			    mapshift)),
4595ad8204nd			    (u_longlong_t)(SM_RUN_DECODE(entry) << mapshift));
460fa9e406ahrens			if (SM_TYPE_DECODE(entry) == SM_ALLOC)
461fa9e406ahrens				alloc += SM_RUN_DECODE(entry) << mapshift;
462fa9e406ahrens			else
463fa9e406ahrens				alloc -= SM_RUN_DECODE(entry) << mapshift;
464fa9e406ahrens		}
465fa9e406ahrens	}
466fa9e406ahrens	if (alloc != smo->smo_alloc) {
467fa9e406ahrens		(void) printf("space_map_object alloc (%llu) INCONSISTENT "
468fa9e406ahrens		    "with space map summary (%llu)\n",
469fa9e406ahrens		    (u_longlong_t)smo->smo_alloc, (u_longlong_t)alloc);
470fa9e406ahrens	}
471fa9e406ahrens}
472fa9e406ahrens
473fa9e406ahrensstatic void
474fa9e406ahrensdump_metaslab(metaslab_t *msp)
475fa9e406ahrens{
476fa9e406ahrens	char freebuf[5];
477ecc2d60bonwick	space_map_obj_t *smo = &msp->ms_smo;
478fa9e406ahrens	vdev_t *vd = msp->ms_group->mg_vd;
479fa9e406ahrens	spa_t *spa = vd->vdev_spa;
480fa9e406ahrens
481fa9e406ahrens	nicenum(msp->ms_map.sm_size - smo->smo_alloc, freebuf);
482fa9e406ahrens
483fa9e406ahrens	if (dump_opt['d'] <= 5) {
484fa9e406ahrens		(void) printf("\t%10llx   %10llu   %5s\n",
485fa9e406ahrens		    (u_longlong_t)msp->ms_map.sm_start,
486fa9e406ahrens		    (u_longlong_t)smo->smo_object,
487fa9e406ahrens		    freebuf);
488fa9e406ahrens		return;
489fa9e406ahrens	}
490fa9e406ahrens
491fa9e406ahrens	(void) printf(
492fa9e406ahrens	    "\tvdev %llu   offset %08llx   spacemap %4llu   free %5s\n",
493fa9e406ahrens	    (u_longlong_t)vd->vdev_id, (u_longlong_t)msp->ms_map.sm_start,
494fa9e406ahrens	    (u_longlong_t)smo->smo_object, freebuf);
495fa9e406ahrens
496fa9e406ahrens	ASSERT(msp->ms_map.sm_size == (1ULL << vd->vdev_ms_shift));
497fa9e406ahrens
498fa9e406ahrens	dump_spacemap(spa->spa_meta_objset, smo, &msp->ms_map);
499fa9e406ahrens}
500fa9e406ahrens
501fa9e406ahrensstatic void
502fa9e406ahrensdump_metaslabs(spa_t *spa)
503fa9e406ahrens{
504fa9e406ahrens	vdev_t *rvd = spa->spa_root_vdev;
505fa9e406ahrens	vdev_t *vd;
506fa9e406ahrens	int c, m;
507fa9e406ahrens
508fa9e406ahrens	(void) printf("\nMetaslabs:\n");
509fa9e406ahrens
510fa9e406ahrens	for (c = 0; c < rvd->vdev_children; c++) {
511fa9e406ahrens		vd = rvd->vdev_child[c];
512fa9e406ahrens
513fa9e406ahrens		(void) printf("\n    vdev %llu = %s\n\n",
514fa9e406ahrens		    (u_longlong_t)vd->vdev_id, vdev_description(vd));
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
529fa9e406ahrensdump_dtl(vdev_t *vd, int indent)
530fa9e406ahrens{
531fa9e406ahrens	avl_tree_t *t = &vd->vdev_dtl_map.sm_root;
532fa9e406ahrens	space_seg_t *ss;
533fa9e406ahrens	vdev_t *pvd;
534fa9e406ahrens	int c;
535fa9e406ahrens
536fa9e406ahrens	if (indent == 0)
537fa9e406ahrens		(void) printf("\nDirty time logs:\n\n");
538fa9e406ahrens
539fa9e406ahrens	(void) printf("\t%*s%s\n", indent, "", vdev_description(vd));
540fa9e406ahrens
541fa9e406ahrens	for (ss = avl_first(t); ss; ss = AVL_NEXT(t, ss)) {
542fa9e406ahrens		/*
543fa9e406ahrens		 * Everything in this DTL must appear in all parent DTL unions.
544fa9e406ahrens		 */
545fa9e406ahrens		for (pvd = vd; pvd; pvd = pvd->vdev_parent)
546fa9e406ahrens			ASSERT(vdev_dtl_contains(&pvd->vdev_dtl_map,
547fa9e406ahrens			    ss->ss_start, ss->ss_end - ss->ss_start));
548fa9e406ahrens		(void) printf("\t%*soutage [%llu,%llu] length %llu\n",
549fa9e406ahrens		    indent, "",
550fa9e406ahrens		    (u_longlong_t)ss->ss_start,
551fa9e406ahrens		    (u_longlong_t)ss->ss_end - 1,
5525ad8204nd		    (u_longlong_t)(ss->ss_end - ss->ss_start));
553fa9e406ahrens	}
554fa9e406ahrens
555fa9e406ahrens	(void) printf("\n");
556fa9e406ahrens
557fa9e406ahrens	if (dump_opt['d'] > 5 && vd->vdev_children == 0) {
558fa9e406ahrens		dump_spacemap(vd->vdev_spa->spa_meta_objset, &vd->vdev_dtl,
559fa9e406ahrens		    &vd->vdev_dtl_map);
560fa9e406ahrens		(void) printf("\n");
561fa9e406ahrens	}
562fa9e406ahrens
563fa9e406ahrens	for (c = 0; c < vd->vdev_children; c++)
564fa9e406ahrens		dump_dtl(vd->vdev_child[c], indent + 4);
565fa9e406ahrens}
566fa9e406ahrens
567fa9e406ahrens/*ARGSUSED*/
568fa9e406ahrensstatic void
569fa9e406ahrensdump_dnode(objset_t *os, uint64_t object, void *data, size_t size)
570fa9e406ahrens{
571fa9e406ahrens}
572fa9e406ahrens
573fa9e406ahrensstatic uint64_t
574fa9e406ahrensblkid2offset(dnode_phys_t *dnp, int level, uint64_t blkid)
575fa9e406ahrens{
576fa9e406ahrens	if (level < 0)
577fa9e406ahrens		return (blkid);
578fa9e406ahrens
579fa9e406ahrens	return ((blkid << (level * (dnp->dn_indblkshift - SPA_BLKPTRSHIFT))) *
580fa9e406ahrens	    dnp->dn_datablkszsec << SPA_MINBLOCKSHIFT);
581fa9e406ahrens}
582fa9e406ahrens
58344cd46cbillmstatic void
58444cd46cbillmsprintf_blkptr_compact(char *blkbuf, blkptr_t *bp, int alldvas)
58544cd46cbillm{
58644cd46cbillm	dva_t *dva = bp->blk_dva;
58744cd46cbillm	int ndvas = alldvas ? BP_GET_NDVAS(bp) : 1;
58844cd46cbillm	int i;
58944cd46cbillm
59044cd46cbillm	blkbuf[0] = '\0';
59144cd46cbillm
59244cd46cbillm	for (i = 0; i < ndvas; i++)
59344cd46cbillm		(void) sprintf(blkbuf + strlen(blkbuf), "%llu:%llx:%llx ",
59444cd46cbillm		    (u_longlong_t)DVA_GET_VDEV(&dva[i]),
59544cd46cbillm		    (u_longlong_t)DVA_GET_OFFSET(&dva[i]),
59644cd46cbillm		    (u_longlong_t)DVA_GET_ASIZE(&dva[i]));
59744cd46cbillm
59844cd46cbillm	(void) sprintf(blkbuf + strlen(blkbuf), "%llxL/%llxP F=%llu B=%llu",
59944cd46cbillm	    (u_longlong_t)BP_GET_LSIZE(bp),
60044cd46cbillm	    (u_longlong_t)BP_GET_PSIZE(bp),
60144cd46cbillm	    (u_longlong_t)bp->blk_fill,
60244cd46cbillm	    (u_longlong_t)bp->blk_birth);
60344cd46cbillm}
60444cd46cbillm
605fa9e406ahrens/* ARGSUSED */
606fa9e406ahrensstatic int
607fa9e406ahrenszdb_indirect_cb(traverse_blk_cache_t *bc, spa_t *spa, void *a)
608fa9e406ahrens{
609fa9e406ahrens	zbookmark_t *zb = &bc->bc_bookmark;
610fa9e406ahrens	blkptr_t *bp = &bc->bc_blkptr;
611fa9e406ahrens	void *data = bc->bc_data;
612fa9e406ahrens	dnode_phys_t *dnp = bc->bc_dnode;
61344cd46cbillm	char blkbuf[BP_SPRINTF_LEN + 80];
614fa9e406ahrens	int l;
615fa9e406ahrens
616fa9e406ahrens	if (bc->bc_errno) {
61744cd46cbillm		(void) sprintf(blkbuf,
618ea8dc4beschrock		    "Error %d reading <%llu, %llu, %lld, %llu>: ",
619fa9e406ahrens		    bc->bc_errno,
620fa9e406ahrens		    (u_longlong_t)zb->zb_objset,
621fa9e406ahrens		    (u_longlong_t)zb->zb_object,
622ea8dc4beschrock		    (u_longlong_t)zb->zb_level,
623fa9e406ahrens		    (u_longlong_t)zb->zb_blkid);
624fa9e406ahrens		goto out;
625fa9e406ahrens	}
626fa9e406ahrens
627fa9e406ahrens	if (zb->zb_level == -1) {
628fa9e406ahrens		ASSERT3U(BP_GET_TYPE(bp), ==, DMU_OT_OBJSET);
629fa9e406ahrens		ASSERT3U(BP_GET_LEVEL(bp), ==, 0);
630fa9e406ahrens	} else {
631fa9e406ahrens		ASSERT3U(BP_GET_TYPE(bp), ==, dnp->dn_type);
632fa9e406ahrens		ASSERT3U(BP_GET_LEVEL(bp), ==, zb->zb_level);
633fa9e406ahrens	}
634fa9e406ahrens
635fa9e406ahrens	if (zb->zb_level > 0) {
636fa9e406ahrens		uint64_t fill = 0;
637fa9e406ahrens		blkptr_t *bpx, *bpend;
638fa9e406ahrens
639fa9e406ahrens		for (bpx = data, bpend = bpx + BP_GET_LSIZE(bp) / sizeof (*bpx);
640fa9e406ahrens		    bpx < bpend; bpx++) {
641fa9e406ahrens			if (bpx->blk_birth != 0) {
642fa9e406ahrens				fill += bpx->blk_fill;
643fa9e406ahrens			} else {
644fa9e406ahrens				ASSERT(bpx->blk_fill == 0);
645fa9e406ahrens			}
646fa9e406ahrens		}
647fa9e406ahrens		ASSERT3U(fill, ==, bp->blk_fill);
648fa9e406ahrens	}
649fa9e406ahrens
650fa9e406ahrens	if (zb->zb_level == 0 && dnp->dn_type == DMU_OT_DNODE) {
651fa9e406ahrens		uint64_t fill = 0;
652fa9e406ahrens		dnode_phys_t *dnx, *dnend;
653fa9e406ahrens
654fa9e406ahrens		for (dnx = data, dnend = dnx + (BP_GET_LSIZE(bp)>>DNODE_SHIFT);
655fa9e406ahrens		    dnx < dnend; dnx++) {
656fa9e406ahrens			if (dnx->dn_type != DMU_OT_NONE)
657fa9e406ahrens				fill++;
658fa9e406ahrens		}
659fa9e406ahrens		ASSERT3U(fill, ==, bp->blk_fill);
660fa9e406ahrens	}
661fa9e406ahrens
66244cd46cbillm	(void) sprintf(blkbuf, "%16llx ",
663fa9e406ahrens	    (u_longlong_t)blkid2offset(dnp, zb->zb_level, zb->zb_blkid));
664fa9e406ahrens
665fa9e406ahrens	ASSERT(zb->zb_level >= 0);
666fa9e406ahrens
667fa9e406ahrens	for (l = dnp->dn_nlevels - 1; l >= -1; l--) {
668fa9e406ahrens		if (l == zb->zb_level) {
66944cd46cbillm			(void) sprintf(blkbuf + strlen(blkbuf), "L%llx",
670ea8dc4beschrock			    (u_longlong_t)zb->zb_level);
671fa9e406ahrens		} else {
67244cd46cbillm			(void) sprintf(blkbuf + strlen(blkbuf), " ");
673fa9e406ahrens		}
674fa9e406ahrens	}
675fa9e406ahrens
676fa9e406ahrensout:
677fa9e406ahrens	if (bp->blk_birth == 0) {
67844cd46cbillm		(void) sprintf(blkbuf + strlen(blkbuf), "<hole>");
67944cd46cbillm		(void) printf("%s\n", blkbuf);
680fa9e406ahrens	} else {
68144cd46cbillm		sprintf_blkptr_compact(blkbuf + strlen(blkbuf), bp,
68244cd46cbillm		    dump_opt['d'] > 5 ? 1 : 0);
68344cd46cbillm		(void) printf("%s\n", blkbuf);
684fa9e406ahrens	}
685fa9e406ahrens
686fa9e406ahrens	return (bc->bc_errno ? ERESTART : 0);
687fa9e406ahrens}
688fa9e406ahrens
689fa9e406ahrens/*ARGSUSED*/
690fa9e406ahrensstatic void
691fa9e406ahrensdump_indirect(objset_t *os, uint64_t object, void *data, size_t size)
692fa9e406ahrens{
693fa9e406ahrens	traverse_handle_t *th;
694fa9e406ahrens	uint64_t objset = dmu_objset_id(os);
695fa9e406ahrens	int advance = zdb_advance;
696fa9e406ahrens
697fa9e406ahrens	(void) printf("Indirect blocks:\n");
698fa9e406ahrens
699fa9e406ahrens	if (object == 0)
700fa9e406ahrens		advance |= ADVANCE_DATA;
701fa9e406ahrens
702fa9e406ahrens	th = traverse_init(dmu_objset_spa(os), zdb_indirect_cb, NULL, advance,
703fa9e406ahrens	    ZIO_FLAG_CANFAIL);
704fa9e406ahrens	th->th_noread = zdb_noread;
705fa9e406ahrens
706fa9e406ahrens	traverse_add_dnode(th, 0, -1ULL, objset, object);
707fa9e406ahrens
708fa9e406ahrens	while (traverse_more(th) == EAGAIN)
709fa9e406ahrens		continue;
710fa9e406ahrens
711fa9e406ahrens	(void) printf("\n");
712fa9e406ahrens
713fa9e406ahrens	traverse_fini(th);
714fa9e406ahrens}
715fa9e406ahrens
716fa9e406ahrens/*ARGSUSED*/
717fa9e406ahrensstatic void
718fa9e406ahrensdump_dsl_dir(objset_t *os, uint64_t object, void *data, size_t size)
719fa9e406ahrens{
720fa9e406ahrens	dsl_dir_phys_t *dd = data;
721fa9e406ahrens	time_t crtime;
722fa9e406ahrens	char used[6], compressed[6], uncompressed[6], quota[6], resv[6];
723fa9e406ahrens
724fa9e406ahrens	if (dd == NULL)
725fa9e406ahrens		return;
726fa9e406ahrens
727da6c28aamw	ASSERT3U(size, >=, sizeof (dsl_dir_phys_t));
728fa9e406ahrens
729fa9e406ahrens	crtime = dd->dd_creation_time;
730fa9e406ahrens	nicenum(dd->dd_used_bytes, used);
731fa9e406ahrens	nicenum(dd->dd_compressed_bytes, compressed);
732fa9e406ahrens	nicenum(dd->dd_uncompressed_bytes, uncompressed);
733fa9e406ahrens	nicenum(dd->dd_quota, quota);
734fa9e406ahrens	nicenum(dd->dd_reserved, resv);
735fa9e406ahrens
736fa9e406ahrens	(void) printf("\t\tcreation_time = %s", ctime(&crtime));
737fa9e406ahrens	(void) printf("\t\thead_dataset_obj = %llu\n",
738fa9e406ahrens	    (u_longlong_t)dd->dd_head_dataset_obj);
739fa9e406ahrens	(void) printf("\t\tparent_dir_obj = %llu\n",
740fa9e406ahrens	    (u_longlong_t)dd->dd_parent_obj);
7413cb34c6ahrens	(void) printf("\t\torigin_obj = %llu\n",
7423cb34c6ahrens	    (u_longlong_t)dd->dd_origin_obj);
743fa9e406ahrens	(void) printf("\t\tchild_dir_zapobj = %llu\n",
744fa9e406ahrens	    (u_longlong_t)dd->dd_child_dir_zapobj);
745fa9e406ahrens	(void) printf("\t\tused_bytes = %s\n", used);
746fa9e406ahrens	(void) printf("\t\tcompressed_bytes = %s\n", compressed);
747fa9e406ahrens	(void) printf("\t\tuncompressed_bytes = %s\n", uncompressed);
748fa9e406ahrens	(void) printf("\t\tquota = %s\n", quota);
749fa9e406ahrens	(void) printf("\t\treserved = %s\n", resv);
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);
754fa9e406ahrens}
755fa9e406ahrens
756fa9e406ahrens/*ARGSUSED*/
757fa9e406ahrensstatic void
758fa9e406ahrensdump_dsl_dataset(objset_t *os, uint64_t object, void *data, size_t size)
759fa9e406ahrens{
760fa9e406ahrens	dsl_dataset_phys_t *ds = data;
761fa9e406ahrens	time_t crtime;
762fbabab8maybee	char used[6], compressed[6], uncompressed[6], unique[6];
763fbabab8maybee	char blkbuf[BP_SPRINTF_LEN];
764fa9e406ahrens
765fa9e406ahrens	if (ds == NULL)
766fa9e406ahrens		return;
767fa9e406ahrens
768fa9e406ahrens	ASSERT(size == sizeof (*ds));
769fa9e406ahrens	crtime = ds->ds_creation_time;
770fa9e406ahrens	nicenum(ds->ds_used_bytes, used);
771fa9e406ahrens	nicenum(ds->ds_compressed_bytes, compressed);
772fa9e406ahrens	nicenum(ds->ds_uncompressed_bytes, uncompressed);
773fa9e406ahrens	nicenum(ds->ds_unique_bytes, unique);
774fbabab8maybee	sprintf_blkptr(blkbuf, BP_SPRINTF_LEN, &ds->ds_bp);
775fa9e406ahrens
776fa9e406ahrens	(void) printf("\t\tdataset_obj = %llu\n",
777fa9e406ahrens	    (u_longlong_t)ds->ds_dir_obj);
778fa9e406ahrens	(void) printf("\t\tprev_snap_obj = %llu\n",
779fa9e406ahrens	    (u_longlong_t)ds->ds_prev_snap_obj);
780fa9e406ahrens	(void) printf("\t\tprev_snap_txg = %llu\n",
781fa9e406ahrens	    (u_longlong_t)ds->ds_prev_snap_txg);
782fa9e406ahrens	(void) printf("\t\tnext_snap_obj = %llu\n",
783fa9e406ahrens	    (u_longlong_t)ds->ds_next_snap_obj);
784fa9e406ahrens	(void) printf("\t\tsnapnames_zapobj = %llu\n",
785fa9e406ahrens	    (u_longlong_t)ds->ds_snapnames_zapobj);
786fa9e406ahrens	(void) printf("\t\tnum_children = %llu\n",
787fa9e406ahrens	    (u_longlong_t)ds->ds_num_children);
788fa9e406ahrens	(void) printf("\t\tcreation_time = %s", ctime(&crtime));
789fa9e406ahrens	(void) printf("\t\tcreation_txg = %llu\n",
790fa9e406ahrens	    (u_longlong_t)ds->ds_creation_txg);
791fa9e406ahrens	(void) printf("\t\tdeadlist_obj = %llu\n",
792fa9e406ahrens	    (u_longlong_t)ds->ds_deadlist_obj);
793fa9e406ahrens	(void) printf("\t\tused_bytes = %s\n", used);
794fa9e406ahrens	(void) printf("\t\tcompressed_bytes = %s\n", compressed);
795fa9e406ahrens	(void) printf("\t\tuncompressed_bytes = %s\n", uncompressed);
796fa9e406ahrens	(void) printf("\t\tunique = %s\n", unique);
797fa9e406ahrens	(void) printf("\t\tfsid_guid = %llu\n",
798fa9e406ahrens	    (u_longlong_t)ds->ds_fsid_guid);
799fa9e406ahrens	(void) printf("\t\tguid = %llu\n",
800fa9e406ahrens	    (u_longlong_t)ds->ds_guid);
80199653d4eschrock	(void) printf("\t\tflags = %llx\n",
80299653d4eschrock	    (u_longlong_t)ds->ds_flags);
803fa9e406ahrens	(void) printf("\t\tbp = %s\n", blkbuf);
804fa9e406ahrens}
805fa9e406ahrens
806fa9e406ahrensstatic void
807fa9e406ahrensdump_bplist(objset_t *mos, uint64_t object, char *name)
808fa9e406ahrens{
809fa9e406ahrens	bplist_t bpl = { 0 };
810fa9e406ahrens	blkptr_t blk, *bp = &blk;
811fa9e406ahrens	uint64_t itor = 0;
81299653d4eschrock	char bytes[6];
81399653d4eschrock	char comp[6];
81499653d4eschrock	char uncomp[6];
815fa9e406ahrens
816fa9e406ahrens	if (dump_opt['d'] < 3)
817fa9e406ahrens		return;
818fa9e406ahrens
819c25056dgw	mutex_init(&bpl.bpl_lock, NULL, MUTEX_DEFAULT, NULL);
820ea8dc4beschrock	VERIFY(0 == bplist_open(&bpl, mos, object));
821fa9e406ahrens	if (bplist_empty(&bpl)) {
822fa9e406ahrens		bplist_close(&bpl);
823c25056dgw		mutex_destroy(&bpl.bpl_lock);
824fa9e406ahrens		return;
825fa9e406ahrens	}
826fa9e406ahrens
82799653d4eschrock	nicenum(bpl.bpl_phys->bpl_bytes, bytes);
82899653d4eschrock	if (bpl.bpl_dbuf->db_size == sizeof (bplist_phys_t)) {
82999653d4eschrock		nicenum(bpl.bpl_phys->bpl_comp, comp);
83099653d4eschrock		nicenum(bpl.bpl_phys->bpl_uncomp, uncomp);
83199653d4eschrock		(void) printf("\n    %s: %llu entries, %s (%s/%s comp)\n",
83299653d4eschrock		    name, (u_longlong_t)bpl.bpl_phys->bpl_entries,
83399653d4eschrock		    bytes, comp, uncomp);
83499653d4eschrock	} else {
83599653d4eschrock		(void) printf("\n    %s: %llu entries, %s\n",
83699653d4eschrock		    name, (u_longlong_t)bpl.bpl_phys->bpl_entries, bytes);
83799653d4eschrock	}
838fa9e406ahrens
839fa9e406ahrens	if (dump_opt['d'] < 5) {
840fa9e406ahrens		bplist_close(&bpl);
841c25056dgw		mutex_destroy(&bpl.bpl_lock);
842fa9e406ahrens		return;
843fa9e406ahrens	}
844fa9e406ahrens
845fa9e406ahrens	(void) printf("\n");
846fa9e406ahrens
847fa9e406ahrens	while (bplist_iterate(&bpl, &itor, bp) == 0) {
84844cd46cbillm		char blkbuf[BP_SPRINTF_LEN];
84944cd46cbillm
850fa9e406ahrens		ASSERT(bp->blk_birth != 0);
85144cd46cbillm		sprintf_blkptr_compact(blkbuf, bp, dump_opt['d'] > 5 ? 1 : 0);
85244cd46cbillm		(void) printf("\tItem %3llu: %s\n",
85344cd46cbillm		    (u_longlong_t)itor - 1, blkbuf);
854fa9e406ahrens	}
855fa9e406ahrens
856fa9e406ahrens	bplist_close(&bpl);
857c25056dgw	mutex_destroy(&bpl.bpl_lock);
858fa9e406ahrens}
859fa9e406ahrens
860e0d35c4marksstatic avl_tree_t idx_tree;
861e0d35c4marksstatic avl_tree_t domain_tree;
862e0d35c4marksstatic boolean_t fuid_table_loaded;
863e0d35c4marks
864e0d35c4marksstatic void
865e0d35c4marksfuid_table_destroy()
866e0d35c4marks{
867e0d35c4marks	if (fuid_table_loaded) {
868e0d35c4marks		zfs_fuid_table_destroy(&idx_tree, &domain_tree);
869e0d35c4marks		fuid_table_loaded = B_FALSE;
870e0d35c4marks	}
871e0d35c4marks}
872e0d35c4marks
873e0d35c4marks/*
874e0d35c4marks * print uid or gid information.
875e0d35c4marks * For normal POSIX id just the id is printed in decimal format.
876e0d35c4marks * For CIFS files with FUID the fuid is printed in hex followed by
877e0d35c4marks * the doman-rid string.
878e0d35c4marks */
879e0d35c4marksstatic void
880e0d35c4marksprint_idstr(uint64_t id, const char *id_type)
881e0d35c4marks{
882e0d35c4marks	if (FUID_INDEX(id)) {
883e0d35c4marks		char *domain;
884e0d35c4marks
885e0d35c4marks		domain = zfs_fuid_idx_domain(&idx_tree, FUID_INDEX(id));
886e0d35c4marks		(void) printf("\t%s     %llx [%s-%d]\n", id_type,
887e0d35c4marks		    (u_longlong_t)id, domain, (int)FUID_RID(id));
888e0d35c4marks	} else {
889e0d35c4marks		(void) printf("\t%s     %llu\n", id_type, (u_longlong_t)id);
890e0d35c4marks	}
891e0d35c4marks
892e0d35c4marks}
893e0d35c4marks
894e0d35c4marksstatic void
895e0d35c4marksdump_uidgid(objset_t *os, znode_phys_t *zp)
896e0d35c4marks{
897e0d35c4marks	uint32_t uid_idx, gid_idx;
898e0d35c4marks
899e0d35c4marks	uid_idx = FUID_INDEX(zp->zp_uid);
900e0d35c4marks	gid_idx = FUID_INDEX(zp->zp_gid);
901e0d35c4marks
902e0d35c4marks	/* Load domain table, if not already loaded */
903e0d35c4marks	if (!fuid_table_loaded && (uid_idx || gid_idx)) {
904e0d35c4marks		uint64_t fuid_obj;
905e0d35c4marks
906e0d35c4marks		/* first find the fuid object.  It lives in the master node */
907e0d35c4marks		VERIFY(zap_lookup(os, MASTER_NODE_OBJ, ZFS_FUID_TABLES,
908e0d35c4marks		    8, 1, &fuid_obj) == 0);
909e0d35c4marks		(void) zfs_fuid_table_load(os, fuid_obj,
910e0d35c4marks		    &idx_tree, &domain_tree);
911e0d35c4marks		fuid_table_loaded = B_TRUE;
912e0d35c4marks	}
913e0d35c4marks
914e0d35c4marks	print_idstr(zp->zp_uid, "uid");
915e0d35c4marks	print_idstr(zp->zp_gid, "gid");
916e0d35c4marks}
917e0d35c4marks
918fa9e406ahrens/*ARGSUSED*/
919fa9e406ahrensstatic void
920fa9e406ahrensdump_znode(objset_t *os, uint64_t object, void *data, size_t size)
921fa9e406ahrens{
922fa9e406ahrens	znode_phys_t *zp = data;
923fa9e406ahrens	time_t z_crtime, z_atime, z_mtime, z_ctime;
924fa9e406ahrens	char path[MAXPATHLEN * 2];	/* allow for xattr and failure prefix */
92555434c7ek	int error;
926fa9e406ahrens
927fa9e406ahrens	ASSERT(size >= sizeof (znode_phys_t));
928fa9e406ahrens
92955434c7ek	error = zfs_obj_to_path(os, object, path, sizeof (path));
93055434c7ek	if (error != 0) {
93155434c7ek		(void) snprintf(path, sizeof (path), "\?\?\?<object#%llu>",
93255434c7ek		    (u_longlong_t)object);
93355434c7ek	}
93455434c7ek
935fa9e406ahrens	if (dump_opt['d'] < 3) {
93655434c7ek		(void) printf("\t%s\n", path);
937fa9e406ahrens		return;
938fa9e406ahrens	}
939fa9e406ahrens
940fa9e406ahrens	z_crtime = (time_t)zp->zp_crtime[0];
941fa9e406ahrens	z_atime = (time_t)zp->zp_atime[0];
942fa9e406ahrens	z_mtime = (time_t)zp->zp_mtime[0];
943fa9e406ahrens	z_ctime = (time_t)zp->zp_ctime[0];
944fa9e406ahrens
94555434c7ek	(void) printf("\tpath	%s\n", path);
946e0d35c4marks	dump_uidgid(os, zp);
947fa9e406ahrens	(void) printf("\tatime	%s", ctime(&z_atime));
948fa9e406ahrens	(void) printf("\tmtime	%s", ctime(&z_mtime));
949fa9e406ahrens	(void) printf("\tctime	%s", ctime(&z_ctime));
950fa9e406ahrens	(void) printf("\tcrtime	%s", ctime(&z_crtime));
951fa9e406ahrens	(void) printf("\tgen	%llu\n", (u_longlong_t)zp->zp_gen);
952fa9e406ahrens	(void) printf("\tmode	%llo\n", (u_longlong_t)zp->zp_mode);
953fa9e406ahrens	(void) printf("\tsize	%llu\n", (u_longlong_t)zp->zp_size);
954fa9e406ahrens	(void) printf("\tparent	%llu\n", (u_longlong_t)zp->zp_parent);
955fa9e406ahrens	(void) printf("\tlinks	%llu\n", (u_longlong_t)zp->zp_links);
956fa9e406ahrens	(void) printf("\txattr	%llu\n", (u_longlong_t)zp->zp_xattr);
957fa9e406ahrens	(void) printf("\trdev	0x%016llx\n", (u_longlong_t)zp->zp_rdev);
958fa9e406ahrens}
959fa9e406ahrens
960fa9e406ahrens/*ARGSUSED*/
961fa9e406ahrensstatic void
962fa9e406ahrensdump_acl(objset_t *os, uint64_t object, void *data, size_t size)
963fa9e406ahrens{
964fa9e406ahrens}
965fa9e406ahrens
966fa9e406ahrens/*ARGSUSED*/
967fa9e406ahrensstatic void
968fa9e406ahrensdump_dmu_objset(objset_t *os, uint64_t object, void *data, size_t size)
969fa9e406ahrens{
970fa9e406ahrens}
971fa9e406ahrens
972fa9e406ahrensstatic object_viewer_t *object_viewer[DMU_OT_NUMTYPES] = {
973fa9e406ahrens	dump_none,		/* unallocated			*/
974fa9e406ahrens	dump_zap,		/* object directory		*/
975fa9e406ahrens	dump_uint64,		/* object array			*/
976fa9e406ahrens	dump_none,		/* packed nvlist		*/
977fa9e406ahrens	dump_packed_nvlist,	/* packed nvlist size		*/
978fa9e406ahrens	dump_none,		/* bplist			*/
979fa9e406ahrens	dump_none,		/* bplist header		*/
980fa9e406ahrens	dump_none,		/* SPA space map header		*/
981fa9e406ahrens	dump_none,		/* SPA space map		*/
982fa9e406ahrens	dump_none,		/* ZIL intent log		*/
983fa9e406ahrens	dump_dnode,		/* DMU dnode			*/
984fa9e406ahrens	dump_dmu_objset,	/* DMU objset			*/
985ea8dc4beschrock	dump_dsl_dir,		/* DSL directory		*/
986fa9e406ahrens	dump_zap,		/* DSL directory child map	*/
987fa9e406ahrens	dump_zap,		/* DSL dataset snap map		*/
988fa9e406ahrens	dump_zap,		/* DSL props			*/
989fa9e406ahrens	dump_dsl_dataset,	/* DSL dataset			*/
990fa9e406ahrens	dump_znode,		/* ZFS znode			*/
991da6c28aamw	dump_acl,		/* ZFS V0 ACL			*/
992fa9e406ahrens	dump_uint8,		/* ZFS plain file		*/
993e743726ahrens	dump_zpldir,		/* ZFS directory		*/
994fa9e406ahrens	dump_zap,		/* ZFS master node		*/
995fa9e406ahrens	dump_zap,		/* ZFS delete queue		*/
996fa9e406ahrens	dump_uint8,		/* zvol object			*/
997fa9e406ahrens	dump_zap,		/* zvol prop			*/
998fa9e406ahrens	dump_uint8,		/* other uint8[]		*/
999fa9e406ahrens	dump_uint64,		/* other uint64[]		*/
1000fa9e406ahrens	dump_zap,		/* other ZAP			*/
1001ea8dc4beschrock	dump_zap,		/* persistent error log		*/
100206eeb2aek	dump_uint8,		/* SPA history			*/
1003