xref: /titanic_44/usr/src/cmd/mdb/common/modules/zfs/zfs.c (revision 3c112a2b34403220c06c3e2fcac403358cfba168)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
23  */
24 
25 /* Portions Copyright 2010 Robert Milkowski */
26 
27 #include <mdb/mdb_ctf.h>
28 #include <sys/zfs_context.h>
29 #include <sys/mdb_modapi.h>
30 #include <sys/dbuf.h>
31 #include <sys/dmu_objset.h>
32 #include <sys/dsl_dir.h>
33 #include <sys/dsl_pool.h>
34 #include <sys/metaslab_impl.h>
35 #include <sys/space_map.h>
36 #include <sys/list.h>
37 #include <sys/spa_impl.h>
38 #include <sys/vdev_impl.h>
39 #include <sys/zap_leaf.h>
40 #include <sys/zap_impl.h>
41 #include <ctype.h>
42 #include <sys/zfs_acl.h>
43 #include <sys/sa_impl.h>
44 
45 #ifdef _KERNEL
46 #define	ZFS_OBJ_NAME	"zfs"
47 #else
48 #define	ZFS_OBJ_NAME	"libzpool.so.1"
49 #endif
50 
51 #ifndef _KERNEL
52 int aok;
53 #endif
54 
55 static int
56 getmember(uintptr_t addr, const char *type, mdb_ctf_id_t *idp,
57     const char *member, int len, void *buf)
58 {
59 	mdb_ctf_id_t id;
60 	ulong_t off;
61 	char name[64];
62 
63 	if (idp == NULL) {
64 		if (mdb_ctf_lookup_by_name(type, &id) == -1) {
65 			mdb_warn("couldn't find type %s", type);
66 			return (DCMD_ERR);
67 		}
68 		idp = &id;
69 	} else {
70 		type = name;
71 		mdb_ctf_type_name(*idp, name, sizeof (name));
72 	}
73 
74 	if (mdb_ctf_offsetof(*idp, member, &off) == -1) {
75 		mdb_warn("couldn't find member %s of type %s\n", member, type);
76 		return (DCMD_ERR);
77 	}
78 	if (off % 8 != 0) {
79 		mdb_warn("member %s of type %s is unsupported bitfield",
80 		    member, type);
81 		return (DCMD_ERR);
82 	}
83 	off /= 8;
84 
85 	if (mdb_vread(buf, len, addr + off) == -1) {
86 		mdb_warn("failed to read %s from %s at %p",
87 		    member, type, addr + off);
88 		return (DCMD_ERR);
89 	}
90 	/* mdb_warn("read %s from %s at %p+%llx\n", member, type, addr, off); */
91 
92 	return (0);
93 }
94 
95 #define	GETMEMB(addr, type, member, dest) \
96 	getmember(addr, #type, NULL, #member, sizeof (dest), &(dest))
97 
98 #define	GETMEMBID(addr, ctfid, member, dest) \
99 	getmember(addr, NULL, ctfid, #member, sizeof (dest), &(dest))
100 
101 static int
102 getrefcount(uintptr_t addr, mdb_ctf_id_t *id,
103     const char *member, uint64_t *rc)
104 {
105 	static int gotid;
106 	static mdb_ctf_id_t rc_id;
107 	ulong_t off;
108 
109 	if (!gotid) {
110 		if (mdb_ctf_lookup_by_name("struct refcount", &rc_id) == -1) {
111 			mdb_warn("couldn't find struct refcount");
112 			return (DCMD_ERR);
113 		}
114 		gotid = TRUE;
115 	}
116 
117 	if (mdb_ctf_offsetof(*id, member, &off) == -1) {
118 		char name[64];
119 		mdb_ctf_type_name(*id, name, sizeof (name));
120 		mdb_warn("couldn't find member %s of type %s\n", member, name);
121 		return (DCMD_ERR);
122 	}
123 	off /= 8;
124 
125 	return (GETMEMBID(addr + off, &rc_id, rc_count, *rc));
126 }
127 
128 static boolean_t
129 strisprint(const char *cp)
130 {
131 	for (; *cp; cp++) {
132 		if (!isprint(*cp))
133 			return (B_FALSE);
134 	}
135 	return (B_TRUE);
136 }
137 
138 static int verbose;
139 
140 static int
141 freelist_walk_init(mdb_walk_state_t *wsp)
142 {
143 	if (wsp->walk_addr == NULL) {
144 		mdb_warn("must supply starting address\n");
145 		return (WALK_ERR);
146 	}
147 
148 	wsp->walk_data = 0;  /* Index into the freelist */
149 	return (WALK_NEXT);
150 }
151 
152 static int
153 freelist_walk_step(mdb_walk_state_t *wsp)
154 {
155 	uint64_t entry;
156 	uintptr_t number = (uintptr_t)wsp->walk_data;
157 	char *ddata[] = { "ALLOC", "FREE", "CONDENSE", "INVALID",
158 			    "INVALID", "INVALID", "INVALID", "INVALID" };
159 	int mapshift = SPA_MINBLOCKSHIFT;
160 
161 	if (mdb_vread(&entry, sizeof (entry), wsp->walk_addr) == -1) {
162 		mdb_warn("failed to read freelist entry %p", wsp->walk_addr);
163 		return (WALK_DONE);
164 	}
165 	wsp->walk_addr += sizeof (entry);
166 	wsp->walk_data = (void *)(number + 1);
167 
168 	if (SM_DEBUG_DECODE(entry)) {
169 		mdb_printf("DEBUG: %3u  %10s: txg=%llu  pass=%llu\n",
170 		    number,
171 		    ddata[SM_DEBUG_ACTION_DECODE(entry)],
172 		    SM_DEBUG_TXG_DECODE(entry),
173 		    SM_DEBUG_SYNCPASS_DECODE(entry));
174 	} else {
175 		mdb_printf("Entry: %3u  offsets=%08llx-%08llx  type=%c  "
176 		    "size=%06llx", number,
177 		    SM_OFFSET_DECODE(entry) << mapshift,
178 		    (SM_OFFSET_DECODE(entry) + SM_RUN_DECODE(entry)) <<
179 		    mapshift,
180 		    SM_TYPE_DECODE(entry) == SM_ALLOC ? 'A' : 'F',
181 		    SM_RUN_DECODE(entry) << mapshift);
182 		if (verbose)
183 			mdb_printf("      (raw=%012llx)\n", entry);
184 		mdb_printf("\n");
185 	}
186 	return (WALK_NEXT);
187 }
188 
189 
190 static int
191 dataset_name(uintptr_t addr, char *buf)
192 {
193 	static int gotid;
194 	static mdb_ctf_id_t dd_id;
195 	uintptr_t dd_parent;
196 	char dd_myname[MAXNAMELEN];
197 
198 	if (!gotid) {
199 		if (mdb_ctf_lookup_by_name("struct dsl_dir",
200 		    &dd_id) == -1) {
201 			mdb_warn("couldn't find struct dsl_dir");
202 			return (DCMD_ERR);
203 		}
204 		gotid = TRUE;
205 	}
206 	if (GETMEMBID(addr, &dd_id, dd_parent, dd_parent) ||
207 	    GETMEMBID(addr, &dd_id, dd_myname, dd_myname)) {
208 		return (DCMD_ERR);
209 	}
210 
211 	if (dd_parent) {
212 		if (dataset_name(dd_parent, buf))
213 			return (DCMD_ERR);
214 		strcat(buf, "/");
215 	}
216 
217 	if (dd_myname[0])
218 		strcat(buf, dd_myname);
219 	else
220 		strcat(buf, "???");
221 
222 	return (0);
223 }
224 
225 static int
226 objset_name(uintptr_t addr, char *buf)
227 {
228 	static int gotid;
229 	static mdb_ctf_id_t os_id, ds_id;
230 	uintptr_t os_dsl_dataset;
231 	char ds_snapname[MAXNAMELEN];
232 	uintptr_t ds_dir;
233 
234 	buf[0] = '\0';
235 
236 	if (!gotid) {
237 		if (mdb_ctf_lookup_by_name("struct objset",
238 		    &os_id) == -1) {
239 			mdb_warn("couldn't find struct objset");
240 			return (DCMD_ERR);
241 		}
242 		if (mdb_ctf_lookup_by_name("struct dsl_dataset",
243 		    &ds_id) == -1) {
244 			mdb_warn("couldn't find struct dsl_dataset");
245 			return (DCMD_ERR);
246 		}
247 
248 		gotid = TRUE;
249 	}
250 
251 	if (GETMEMBID(addr, &os_id, os_dsl_dataset, os_dsl_dataset))
252 		return (DCMD_ERR);
253 
254 	if (os_dsl_dataset == 0) {
255 		strcat(buf, "mos");
256 		return (0);
257 	}
258 
259 	if (GETMEMBID(os_dsl_dataset, &ds_id, ds_snapname, ds_snapname) ||
260 	    GETMEMBID(os_dsl_dataset, &ds_id, ds_dir, ds_dir)) {
261 		return (DCMD_ERR);
262 	}
263 
264 	if (ds_dir && dataset_name(ds_dir, buf))
265 		return (DCMD_ERR);
266 
267 	if (ds_snapname[0]) {
268 		strcat(buf, "@");
269 		strcat(buf, ds_snapname);
270 	}
271 	return (0);
272 }
273 
274 static void
275 enum_lookup(char *out, size_t size, mdb_ctf_id_t id, int val,
276     const char *prefix)
277 {
278 	const char *cp;
279 	size_t len = strlen(prefix);
280 
281 	if ((cp = mdb_ctf_enum_name(id, val)) != NULL) {
282 		if (strncmp(cp, prefix, len) == 0)
283 			cp += len;
284 		(void) strncpy(out, cp, size);
285 	} else {
286 		mdb_snprintf(out, size, "? (%d)", val);
287 	}
288 }
289 
290 /* ARGSUSED */
291 static int
292 zfs_params(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
293 {
294 	/*
295 	 * This table can be approximately generated by running:
296 	 * egrep "^[a-z0-9_]+ [a-z0-9_]+( =.*)?;" *.c | cut -d ' ' -f 2
297 	 */
298 	static const char *params[] = {
299 		"arc_reduce_dnlc_percent",
300 		"zfs_arc_max",
301 		"zfs_arc_min",
302 		"arc_shrink_shift",
303 		"zfs_mdcomp_disable",
304 		"zfs_prefetch_disable",
305 		"zfetch_max_streams",
306 		"zfetch_min_sec_reap",
307 		"zfetch_block_cap",
308 		"zfetch_array_rd_sz",
309 		"zfs_default_bs",
310 		"zfs_default_ibs",
311 		"metaslab_aliquot",
312 		"reference_tracking_enable",
313 		"reference_history",
314 		"spa_max_replication_override",
315 		"spa_mode_global",
316 		"zfs_flags",
317 		"zfs_txg_synctime",
318 		"zfs_txg_timeout",
319 		"zfs_write_limit_min",
320 		"zfs_write_limit_max",
321 		"zfs_write_limit_shift",
322 		"zfs_write_limit_override",
323 		"zfs_no_write_throttle",
324 		"zfs_vdev_cache_max",
325 		"zfs_vdev_cache_size",
326 		"zfs_vdev_cache_bshift",
327 		"vdev_mirror_shift",
328 		"zfs_vdev_max_pending",
329 		"zfs_vdev_min_pending",
330 		"zfs_scrub_limit",
331 		"zfs_no_scrub_io",
332 		"zfs_no_scrub_prefetch",
333 		"zfs_vdev_time_shift",
334 		"zfs_vdev_ramp_rate",
335 		"zfs_vdev_aggregation_limit",
336 		"fzap_default_block_shift",
337 		"zfs_immediate_write_sz",
338 		"zfs_read_chunk_size",
339 		"zfs_nocacheflush",
340 		"zil_replay_disable",
341 		"metaslab_gang_bang",
342 		"metaslab_df_alloc_threshold",
343 		"metaslab_df_free_pct",
344 		"zio_injection_enabled",
345 		"zvol_immediate_write_sz",
346 	};
347 
348 	for (int i = 0; i < sizeof (params) / sizeof (params[0]); i++) {
349 		int sz;
350 		uint64_t val64;
351 		uint32_t *val32p = (uint32_t *)&val64;
352 
353 		sz = mdb_readvar(&val64, params[i]);
354 		if (sz == 4) {
355 			mdb_printf("%s = 0x%x\n", params[i], *val32p);
356 		} else if (sz == 8) {
357 			mdb_printf("%s = 0x%llx\n", params[i], val64);
358 		} else {
359 			mdb_warn("variable %s not found", params[i]);
360 		}
361 	}
362 
363 	return (DCMD_OK);
364 }
365 
366 /* ARGSUSED */
367 static int
368 blkptr(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
369 {
370 	mdb_ctf_id_t type_enum, checksum_enum, compress_enum;
371 	char type[80], checksum[80], compress[80];
372 	blkptr_t blk, *bp = &blk;
373 	char buf[BP_SPRINTF_LEN];
374 
375 	if (mdb_vread(&blk, sizeof (blkptr_t), addr) == -1) {
376 		mdb_warn("failed to read blkptr_t");
377 		return (DCMD_ERR);
378 	}
379 
380 	if (mdb_ctf_lookup_by_name("enum dmu_object_type", &type_enum) == -1 ||
381 	    mdb_ctf_lookup_by_name("enum zio_checksum", &checksum_enum) == -1 ||
382 	    mdb_ctf_lookup_by_name("enum zio_compress", &compress_enum) == -1) {
383 		mdb_warn("Could not find blkptr enumerated types");
384 		return (DCMD_ERR);
385 	}
386 
387 	enum_lookup(type, sizeof (type), type_enum,
388 	    BP_GET_TYPE(bp), "DMU_OT_");
389 	enum_lookup(checksum, sizeof (checksum), checksum_enum,
390 	    BP_GET_CHECKSUM(bp), "ZIO_CHECKSUM_");
391 	enum_lookup(compress, sizeof (compress), compress_enum,
392 	    BP_GET_COMPRESS(bp), "ZIO_COMPRESS_");
393 
394 	SPRINTF_BLKPTR(mdb_snprintf, '\n', buf, bp, type, checksum, compress);
395 
396 	mdb_printf("%s\n", buf);
397 
398 	return (DCMD_OK);
399 }
400 
401 /* ARGSUSED */
402 static int
403 dbuf(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
404 {
405 	mdb_ctf_id_t id;
406 	dmu_buf_t db;
407 	uintptr_t objset;
408 	uint8_t level;
409 	uint64_t blkid;
410 	uint64_t holds;
411 	char objectname[32];
412 	char blkidname[32];
413 	char path[MAXNAMELEN];
414 
415 	if (DCMD_HDRSPEC(flags)) {
416 		mdb_printf("        addr object lvl blkid holds os\n");
417 	}
418 
419 	if (mdb_ctf_lookup_by_name("struct dmu_buf_impl", &id) == -1) {
420 		mdb_warn("couldn't find struct dmu_buf_impl_t");
421 		return (DCMD_ERR);
422 	}
423 
424 	if (GETMEMBID(addr, &id, db_objset, objset) ||
425 	    GETMEMBID(addr, &id, db, db) ||
426 	    GETMEMBID(addr, &id, db_level, level) ||
427 	    GETMEMBID(addr, &id, db_blkid, blkid)) {
428 		return (WALK_ERR);
429 	}
430 
431 	if (getrefcount(addr, &id, "db_holds", &holds)) {
432 		return (WALK_ERR);
433 	}
434 
435 	if (db.db_object == DMU_META_DNODE_OBJECT)
436 		(void) strcpy(objectname, "mdn");
437 	else
438 		(void) mdb_snprintf(objectname, sizeof (objectname), "%llx",
439 		    (u_longlong_t)db.db_object);
440 
441 	if (blkid == DMU_BONUS_BLKID)
442 		(void) strcpy(blkidname, "bonus");
443 	else
444 		(void) mdb_snprintf(blkidname, sizeof (blkidname), "%llx",
445 		    (u_longlong_t)blkid);
446 
447 	if (objset_name(objset, path)) {
448 		return (WALK_ERR);
449 	}
450 
451 	mdb_printf("%p %8s %1u %9s %2llu %s\n",
452 	    addr, objectname, level, blkidname, holds, path);
453 
454 	return (DCMD_OK);
455 }
456 
457 /* ARGSUSED */
458 static int
459 dbuf_stats(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
460 {
461 #define	HISTOSZ 32
462 	uintptr_t dbp;
463 	dmu_buf_impl_t db;
464 	dbuf_hash_table_t ht;
465 	uint64_t bucket, ndbufs;
466 	uint64_t histo[HISTOSZ];
467 	uint64_t histo2[HISTOSZ];
468 	int i, maxidx;
469 
470 	if (mdb_readvar(&ht, "dbuf_hash_table") == -1) {
471 		mdb_warn("failed to read 'dbuf_hash_table'");
472 		return (DCMD_ERR);
473 	}
474 
475 	for (i = 0; i < HISTOSZ; i++) {
476 		histo[i] = 0;
477 		histo2[i] = 0;
478 	}
479 
480 	ndbufs = 0;
481 	for (bucket = 0; bucket < ht.hash_table_mask+1; bucket++) {
482 		int len;
483 
484 		if (mdb_vread(&dbp, sizeof (void *),
485 		    (uintptr_t)(ht.hash_table+bucket)) == -1) {
486 			mdb_warn("failed to read hash bucket %u at %p",
487 			    bucket, ht.hash_table+bucket);
488 			return (DCMD_ERR);
489 		}
490 
491 		len = 0;
492 		while (dbp != 0) {
493 			if (mdb_vread(&db, sizeof (dmu_buf_impl_t),
494 			    dbp) == -1) {
495 				mdb_warn("failed to read dbuf at %p", dbp);
496 				return (DCMD_ERR);
497 			}
498 			dbp = (uintptr_t)db.db_hash_next;
499 			for (i = MIN(len, HISTOSZ - 1); i >= 0; i--)
500 				histo2[i]++;
501 			len++;
502 			ndbufs++;
503 		}
504 
505 		if (len >= HISTOSZ)
506 			len = HISTOSZ-1;
507 		histo[len]++;
508 	}
509 
510 	mdb_printf("hash table has %llu buckets, %llu dbufs "
511 	    "(avg %llu buckets/dbuf)\n",
512 	    ht.hash_table_mask+1, ndbufs,
513 	    (ht.hash_table_mask+1)/ndbufs);
514 
515 	mdb_printf("\n");
516 	maxidx = 0;
517 	for (i = 0; i < HISTOSZ; i++)
518 		if (histo[i] > 0)
519 			maxidx = i;
520 	mdb_printf("hash chain length	number of buckets\n");
521 	for (i = 0; i <= maxidx; i++)
522 		mdb_printf("%u			%llu\n", i, histo[i]);
523 
524 	mdb_printf("\n");
525 	maxidx = 0;
526 	for (i = 0; i < HISTOSZ; i++)
527 		if (histo2[i] > 0)
528 			maxidx = i;
529 	mdb_printf("hash chain depth	number of dbufs\n");
530 	for (i = 0; i <= maxidx; i++)
531 		mdb_printf("%u or more		%llu	%llu%%\n",
532 		    i, histo2[i], histo2[i]*100/ndbufs);
533 
534 
535 	return (DCMD_OK);
536 }
537 
538 #define	CHAIN_END 0xffff
539 /*
540  * ::zap_leaf [-v]
541  *
542  * Print a zap_leaf_phys_t, assumed to be 16k
543  */
544 /* ARGSUSED */
545 static int
546 zap_leaf(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
547 {
548 	char buf[16*1024];
549 	int verbose = B_FALSE;
550 	int four = B_FALSE;
551 	zap_leaf_t l;
552 	zap_leaf_phys_t *zlp = (void *)buf;
553 	int i;
554 
555 	if (mdb_getopts(argc, argv,
556 	    'v', MDB_OPT_SETBITS, TRUE, &verbose,
557 	    '4', MDB_OPT_SETBITS, TRUE, &four,
558 	    NULL) != argc)
559 		return (DCMD_USAGE);
560 
561 	l.l_phys = zlp;
562 	l.l_bs = 14; /* assume 16k blocks */
563 	if (four)
564 		l.l_bs = 12;
565 
566 	if (!(flags & DCMD_ADDRSPEC)) {
567 		return (DCMD_USAGE);
568 	}
569 
570 	if (mdb_vread(buf, sizeof (buf), addr) == -1) {
571 		mdb_warn("failed to read zap_leaf_phys_t at %p", addr);
572 		return (DCMD_ERR);
573 	}
574 
575 	if (zlp->l_hdr.lh_block_type != ZBT_LEAF ||
576 	    zlp->l_hdr.lh_magic != ZAP_LEAF_MAGIC) {
577 		mdb_warn("This does not appear to be a zap_leaf_phys_t");
578 		return (DCMD_ERR);
579 	}
580 
581 	mdb_printf("zap_leaf_phys_t at %p:\n", addr);
582 	mdb_printf("    lh_prefix_len = %u\n", zlp->l_hdr.lh_prefix_len);
583 	mdb_printf("    lh_prefix = %llx\n", zlp->l_hdr.lh_prefix);
584 	mdb_printf("    lh_nentries = %u\n", zlp->l_hdr.lh_nentries);
585 	mdb_printf("    lh_nfree = %u\n", zlp->l_hdr.lh_nfree,
586 	    zlp->l_hdr.lh_nfree * 100 / (ZAP_LEAF_NUMCHUNKS(&l)));
587 	mdb_printf("    lh_freelist = %u\n", zlp->l_hdr.lh_freelist);
588 	mdb_printf("    lh_flags = %x (%s)\n", zlp->l_hdr.lh_flags,
589 	    zlp->l_hdr.lh_flags & ZLF_ENTRIES_CDSORTED ?
590 	    "ENTRIES_CDSORTED" : "");
591 
592 	if (verbose) {
593 		mdb_printf(" hash table:\n");
594 		for (i = 0; i < ZAP_LEAF_HASH_NUMENTRIES(&l); i++) {
595 			if (zlp->l_hash[i] != CHAIN_END)
596 				mdb_printf("    %u: %u\n", i, zlp->l_hash[i]);
597 		}
598 	}
599 
600 	mdb_printf(" chunks:\n");
601 	for (i = 0; i < ZAP_LEAF_NUMCHUNKS(&l); i++) {
602 		/* LINTED: alignment */
603 		zap_leaf_chunk_t *zlc = &ZAP_LEAF_CHUNK(&l, i);
604 		switch (zlc->l_entry.le_type) {
605 		case ZAP_CHUNK_FREE:
606 			if (verbose) {
607 				mdb_printf("    %u: free; lf_next = %u\n",
608 				    i, zlc->l_free.lf_next);
609 			}
610 			break;
611 		case ZAP_CHUNK_ENTRY:
612 			mdb_printf("    %u: entry\n", i);
613 			if (verbose) {
614 				mdb_printf("        le_next = %u\n",
615 				    zlc->l_entry.le_next);
616 			}
617 			mdb_printf("        le_name_chunk = %u\n",
618 			    zlc->l_entry.le_name_chunk);
619 			mdb_printf("        le_name_numints = %u\n",
620 			    zlc->l_entry.le_name_numints);
621 			mdb_printf("        le_value_chunk = %u\n",
622 			    zlc->l_entry.le_value_chunk);
623 			mdb_printf("        le_value_intlen = %u\n",
624 			    zlc->l_entry.le_value_intlen);
625 			mdb_printf("        le_value_numints = %u\n",
626 			    zlc->l_entry.le_value_numints);
627 			mdb_printf("        le_cd = %u\n",
628 			    zlc->l_entry.le_cd);
629 			mdb_printf("        le_hash = %llx\n",
630 			    zlc->l_entry.le_hash);
631 			break;
632 		case ZAP_CHUNK_ARRAY:
633 			mdb_printf("    %u: array", i);
634 			if (strisprint((char *)zlc->l_array.la_array))
635 				mdb_printf(" \"%s\"", zlc->l_array.la_array);
636 			mdb_printf("\n");
637 			if (verbose) {
638 				int j;
639 				mdb_printf("        ");
640 				for (j = 0; j < ZAP_LEAF_ARRAY_BYTES; j++) {
641 					mdb_printf("%02x ",
642 					    zlc->l_array.la_array[j]);
643 				}
644 				mdb_printf("\n");
645 			}
646 			if (zlc->l_array.la_next != CHAIN_END) {
647 				mdb_printf("        lf_next = %u\n",
648 				    zlc->l_array.la_next);
649 			}
650 			break;
651 		default:
652 			mdb_printf("    %u: undefined type %u\n",
653 			    zlc->l_entry.le_type);
654 		}
655 	}
656 
657 	return (DCMD_OK);
658 }
659 
660 typedef struct dbufs_data {
661 	mdb_ctf_id_t id;
662 	uint64_t objset;
663 	uint64_t object;
664 	uint64_t level;
665 	uint64_t blkid;
666 	char *osname;
667 } dbufs_data_t;
668 
669 #define	DBUFS_UNSET	(0xbaddcafedeadbeefULL)
670 
671 /* ARGSUSED */
672 static int
673 dbufs_cb(uintptr_t addr, const void *unknown, void *arg)
674 {
675 	dbufs_data_t *data = arg;
676 	uintptr_t objset;
677 	dmu_buf_t db;
678 	uint8_t level;
679 	uint64_t blkid;
680 	char osname[MAXNAMELEN];
681 
682 	if (GETMEMBID(addr, &data->id, db_objset, objset) ||
683 	    GETMEMBID(addr, &data->id, db, db) ||
684 	    GETMEMBID(addr, &data->id, db_level, level) ||
685 	    GETMEMBID(addr, &data->id, db_blkid, blkid)) {
686 		return (WALK_ERR);
687 	}
688 
689 	if ((data->objset == DBUFS_UNSET || data->objset == objset) &&
690 	    (data->osname == NULL || (objset_name(objset, osname) == 0 &&
691 	    strcmp(data->osname, osname) == 0)) &&
692 	    (data->object == DBUFS_UNSET || data->object == db.db_object) &&
693 	    (data->level == DBUFS_UNSET || data->level == level) &&
694 	    (data->blkid == DBUFS_UNSET || data->blkid == blkid)) {
695 		mdb_printf("%#lr\n", addr);
696 	}
697 	return (WALK_NEXT);
698 }
699 
700 /* ARGSUSED */
701 static int
702 dbufs(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
703 {
704 	dbufs_data_t data;
705 	char *object = NULL;
706 	char *blkid = NULL;
707 
708 	data.objset = data.object = data.level = data.blkid = DBUFS_UNSET;
709 	data.osname = NULL;
710 
711 	if (mdb_getopts(argc, argv,
712 	    'O', MDB_OPT_UINT64, &data.objset,
713 	    'n', MDB_OPT_STR, &data.osname,
714 	    'o', MDB_OPT_STR, &object,
715 	    'l', MDB_OPT_UINT64, &data.level,
716 	    'b', MDB_OPT_STR, &blkid) != argc) {
717 		return (DCMD_USAGE);
718 	}
719 
720 	if (object) {
721 		if (strcmp(object, "mdn") == 0) {
722 			data.object = DMU_META_DNODE_OBJECT;
723 		} else {
724 			data.object = mdb_strtoull(object);
725 		}
726 	}
727 
728 	if (blkid) {
729 		if (strcmp(blkid, "bonus") == 0) {
730 			data.blkid = DMU_BONUS_BLKID;
731 		} else {
732 			data.blkid = mdb_strtoull(blkid);
733 		}
734 	}
735 
736 	if (mdb_ctf_lookup_by_name("struct dmu_buf_impl", &data.id) == -1) {
737 		mdb_warn("couldn't find struct dmu_buf_impl_t");
738 		return (DCMD_ERR);
739 	}
740 
741 	if (mdb_walk("dmu_buf_impl_t", dbufs_cb, &data) != 0) {
742 		mdb_warn("can't walk dbufs");
743 		return (DCMD_ERR);
744 	}
745 
746 	return (DCMD_OK);
747 }
748 
749 typedef struct abuf_find_data {
750 	dva_t dva;
751 	mdb_ctf_id_t id;
752 } abuf_find_data_t;
753 
754 /* ARGSUSED */
755 static int
756 abuf_find_cb(uintptr_t addr, const void *unknown, void *arg)
757 {
758 	abuf_find_data_t *data = arg;
759 	dva_t dva;
760 
761 	if (GETMEMBID(addr, &data->id, b_dva, dva)) {
762 		return (WALK_ERR);
763 	}
764 
765 	if (dva.dva_word[0] == data->dva.dva_word[0] &&
766 	    dva.dva_word[1] == data->dva.dva_word[1]) {
767 		mdb_printf("%#lr\n", addr);
768 	}
769 	return (WALK_NEXT);
770 }
771 
772 /* ARGSUSED */
773 static int
774 abuf_find(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
775 {
776 	abuf_find_data_t data;
777 	GElf_Sym sym;
778 	int i;
779 	const char *syms[] = {
780 		"ARC_mru",
781 		"ARC_mru_ghost",
782 		"ARC_mfu",
783 		"ARC_mfu_ghost",
784 	};
785 
786 	if (argc != 2)
787 		return (DCMD_USAGE);
788 
789 	for (i = 0; i < 2; i ++) {
790 		switch (argv[i].a_type) {
791 		case MDB_TYPE_STRING:
792 			data.dva.dva_word[i] = mdb_strtoull(argv[i].a_un.a_str);
793 			break;
794 		case MDB_TYPE_IMMEDIATE:
795 			data.dva.dva_word[i] = argv[i].a_un.a_val;
796 			break;
797 		default:
798 			return (DCMD_USAGE);
799 		}
800 	}
801 
802 	if (mdb_ctf_lookup_by_name("struct arc_buf_hdr", &data.id) == -1) {
803 		mdb_warn("couldn't find struct arc_buf_hdr");
804 		return (DCMD_ERR);
805 	}
806 
807 	for (i = 0; i < sizeof (syms) / sizeof (syms[0]); i++) {
808 		if (mdb_lookup_by_name(syms[i], &sym)) {
809 			mdb_warn("can't find symbol %s", syms[i]);
810 			return (DCMD_ERR);
811 		}
812 
813 		if (mdb_pwalk("list", abuf_find_cb, &data, sym.st_value) != 0) {
814 			mdb_warn("can't walk %s", syms[i]);
815 			return (DCMD_ERR);
816 		}
817 	}
818 
819 	return (DCMD_OK);
820 }
821 
822 /* ARGSUSED */
823 static int
824 dbgmsg_cb(uintptr_t addr, const void *unknown, void *arg)
825 {
826 	static mdb_ctf_id_t id;
827 	static boolean_t gotid;
828 	static ulong_t off;
829 
830 	int *verbosep = arg;
831 	time_t timestamp;
832 	char buf[1024];
833 
834 	if (!gotid) {
835 		if (mdb_ctf_lookup_by_name("struct zfs_dbgmsg", &id) == -1) {
836 			mdb_warn("couldn't find struct zfs_dbgmsg");
837 			return (WALK_ERR);
838 		}
839 		gotid = TRUE;
840 		if (mdb_ctf_offsetof(id, "zdm_msg", &off) == -1) {
841 			mdb_warn("couldn't find zdm_msg");
842 			return (WALK_ERR);
843 		}
844 		off /= 8;
845 	}
846 
847 
848 	if (GETMEMBID(addr, &id, zdm_timestamp, timestamp)) {
849 		return (WALK_ERR);
850 	}
851 
852 	if (mdb_readstr(buf, sizeof (buf), addr + off) == -1) {
853 		mdb_warn("failed to read zdm_msg at %p\n", addr + off);
854 		return (DCMD_ERR);
855 	}
856 
857 	if (*verbosep)
858 		mdb_printf("%Y ", timestamp);
859 
860 	mdb_printf("%s\n", buf);
861 
862 	if (*verbosep)
863 		(void) mdb_call_dcmd("whatis", addr, DCMD_ADDRSPEC, 0, NULL);
864 
865 	return (WALK_NEXT);
866 }
867 
868 /* ARGSUSED */
869 static int
870 dbgmsg(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
871 {
872 	GElf_Sym sym;
873 	int verbose = FALSE;
874 
875 	if (mdb_getopts(argc, argv,
876 	    'v', MDB_OPT_SETBITS, TRUE, &verbose,
877 	    NULL) != argc)
878 		return (DCMD_USAGE);
879 
880 	if (mdb_lookup_by_name("zfs_dbgmsgs", &sym)) {
881 		mdb_warn("can't find zfs_dbgmsgs");
882 		return (DCMD_ERR);
883 	}
884 
885 	if (mdb_pwalk("list", dbgmsg_cb, &verbose, sym.st_value) != 0) {
886 		mdb_warn("can't walk zfs_dbgmsgs");
887 		return (DCMD_ERR);
888 	}
889 
890 	return (DCMD_OK);
891 }
892 
893 /*ARGSUSED*/
894 static int
895 arc_print(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
896 {
897 	kstat_named_t *stats;
898 	GElf_Sym sym;
899 	int nstats, i;
900 	uint_t opt_a = FALSE;
901 	uint_t opt_b = FALSE;
902 	uint_t shift = 0;
903 	const char *suffix;
904 
905 	static const char *bytestats[] = {
906 		"p", "c", "c_min", "c_max", "size", NULL
907 	};
908 
909 	static const char *extras[] = {
910 		"arc_no_grow", "arc_tempreserve",
911 		"arc_meta_used", "arc_meta_limit", "arc_meta_max",
912 		NULL
913 	};
914 
915 	if (mdb_lookup_by_name("arc_stats", &sym) == -1) {
916 		mdb_warn("failed to find 'arc_stats'");
917 		return (DCMD_ERR);
918 	}
919 
920 	stats = mdb_zalloc(sym.st_size, UM_SLEEP | UM_GC);
921 
922 	if (mdb_vread(stats, sym.st_size, sym.st_value) == -1) {
923 		mdb_warn("couldn't read 'arc_stats' at %p", sym.st_value);
924 		return (DCMD_ERR);
925 	}
926 
927 	nstats = sym.st_size / sizeof (kstat_named_t);
928 
929 	/* NB: -a / opt_a are ignored for backwards compatability */
930 	if (mdb_getopts(argc, argv,
931 	    'a', MDB_OPT_SETBITS, TRUE, &opt_a,
932 	    'b', MDB_OPT_SETBITS, TRUE, &opt_b,
933 	    'k', MDB_OPT_SETBITS, 10, &shift,
934 	    'm', MDB_OPT_SETBITS, 20, &shift,
935 	    'g', MDB_OPT_SETBITS, 30, &shift,
936 	    NULL) != argc)
937 		return (DCMD_USAGE);
938 
939 	if (!opt_b && !shift)
940 		shift = 20;
941 
942 	switch (shift) {
943 	case 0:
944 		suffix = "B";
945 		break;
946 	case 10:
947 		suffix = "KB";
948 		break;
949 	case 20:
950 		suffix = "MB";
951 		break;
952 	case 30:
953 		suffix = "GB";
954 		break;
955 	default:
956 		suffix = "XX";
957 	}
958 
959 	for (i = 0; i < nstats; i++) {
960 		int j;
961 		boolean_t bytes = B_FALSE;
962 
963 		for (j = 0; bytestats[j]; j++) {
964 			if (strcmp(stats[i].name, bytestats[j]) == 0) {
965 				bytes = B_TRUE;
966 				break;
967 			}
968 		}
969 
970 		if (bytes) {
971 			mdb_printf("%-25s = %9llu %s\n", stats[i].name,
972 			    stats[i].value.ui64 >> shift, suffix);
973 		} else {
974 			mdb_printf("%-25s = %9llu\n", stats[i].name,
975 			    stats[i].value.ui64);
976 		}
977 	}
978 
979 	for (i = 0; extras[i]; i++) {
980 		uint64_t buf;
981 
982 		if (mdb_lookup_by_name(extras[i], &sym) == -1) {
983 			mdb_warn("failed to find '%s'", extras[i]);
984 			return (DCMD_ERR);
985 		}
986 
987 		if (sym.st_size != sizeof (uint64_t) &&
988 		    sym.st_size != sizeof (uint32_t)) {
989 			mdb_warn("expected scalar for variable '%s'\n",
990 			    extras[i]);
991 			return (DCMD_ERR);
992 		}
993 
994 		if (mdb_vread(&buf, sym.st_size, sym.st_value) == -1) {
995 			mdb_warn("couldn't read '%s'", extras[i]);
996 			return (DCMD_ERR);
997 		}
998 
999 		mdb_printf("%-25s = ", extras[i]);
1000 
1001 		/* NB: all the 64-bit extras happen to be byte counts */
1002 		if (sym.st_size == sizeof (uint64_t))
1003 			mdb_printf("%9llu %s\n", buf >> shift, suffix);
1004 
1005 		if (sym.st_size == sizeof (uint32_t))
1006 			mdb_printf("%9d\n", *((uint32_t *)&buf));
1007 	}
1008 	return (DCMD_OK);
1009 }
1010 
1011 /*
1012  * ::spa
1013  *
1014  * 	-c	Print configuration information as well
1015  * 	-v	Print vdev state
1016  * 	-e	Print vdev error stats
1017  *
1018  * Print a summarized spa_t.  When given no arguments, prints out a table of all
1019  * active pools on the system.
1020  */
1021 /* ARGSUSED */
1022 static int
1023 spa_print(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
1024 {
1025 	spa_t spa;
1026 	const char *statetab[] = { "ACTIVE", "EXPORTED", "DESTROYED",
1027 		"SPARE", "L2CACHE", "UNINIT", "UNAVAIL", "POTENTIAL" };
1028 	const char *state;
1029 	int config = FALSE;
1030 	int vdevs = FALSE;
1031 	int errors = FALSE;
1032 
1033 	if (mdb_getopts(argc, argv,
1034 	    'c', MDB_OPT_SETBITS, TRUE, &config,
1035 	    'v', MDB_OPT_SETBITS, TRUE, &vdevs,
1036 	    'e', MDB_OPT_SETBITS, TRUE, &errors,
1037 	    NULL) != argc)
1038 		return (DCMD_USAGE);
1039 
1040 	if (!(flags & DCMD_ADDRSPEC)) {
1041 		if (mdb_walk_dcmd("spa", "spa", argc, argv) == -1) {
1042 			mdb_warn("can't walk spa");
1043 			return (DCMD_ERR);
1044 		}
1045 
1046 		return (DCMD_OK);
1047 	}
1048 
1049 	if (flags & DCMD_PIPE_OUT) {
1050 		mdb_printf("%#lr\n", addr);
1051 		return (DCMD_OK);
1052 	}
1053 
1054 	if (DCMD_HDRSPEC(flags))
1055 		mdb_printf("%<u>%-?s %9s %-*s%</u>\n", "ADDR", "STATE",
1056 		    sizeof (uintptr_t) == 4 ? 60 : 52, "NAME");
1057 
1058 	if (mdb_vread(&spa, sizeof (spa), addr) == -1) {
1059 		mdb_warn("failed to read spa_t at %p", addr);
1060 		return (DCMD_ERR);
1061 	}
1062 
1063 	if (spa.spa_state < 0 || spa.spa_state > POOL_STATE_UNAVAIL)
1064 		state = "UNKNOWN";
1065 	else
1066 		state = statetab[spa.spa_state];
1067 
1068 	mdb_printf("%0?p %9s %s\n", addr, state, spa.spa_name);
1069 
1070 	if (config) {
1071 		mdb_printf("\n");
1072 		mdb_inc_indent(4);
1073 		if (mdb_call_dcmd("spa_config", addr, flags, 0,
1074 		    NULL) != DCMD_OK)
1075 			return (DCMD_ERR);
1076 		mdb_dec_indent(4);
1077 	}
1078 
1079 	if (vdevs || errors) {
1080 		mdb_arg_t v;
1081 
1082 		v.a_type = MDB_TYPE_STRING;
1083 		v.a_un.a_str = "-e";
1084 
1085 		mdb_printf("\n");
1086 		mdb_inc_indent(4);
1087 		if (mdb_call_dcmd("spa_vdevs", addr, flags, errors ? 1 : 0,
1088 		    &v) != DCMD_OK)
1089 			return (DCMD_ERR);
1090 		mdb_dec_indent(4);
1091 	}
1092 
1093 	return (DCMD_OK);
1094 }
1095 
1096 /*
1097  * ::spa_config
1098  *
1099  * Given a spa_t, print the configuration information stored in spa_config.
1100  * Since it's just an nvlist, format it as an indented list of name=value pairs.
1101  * We simply read the value of spa_config and pass off to ::nvlist.
1102  */
1103 /* ARGSUSED */
1104 static int
1105 spa_print_config(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
1106 {
1107 	spa_t spa;
1108 
1109 	if (argc != 0 || !(flags & DCMD_ADDRSPEC))
1110 		return (DCMD_USAGE);
1111 
1112 	if (mdb_vread(&spa, sizeof (spa), addr) == -1) {
1113 		mdb_warn("failed to read spa_t at %p", addr);
1114 		return (DCMD_ERR);
1115 	}
1116 
1117 	if (spa.spa_config == NULL) {
1118 		mdb_printf("(none)\n");
1119 		return (DCMD_OK);
1120 	}
1121 
1122 	return (mdb_call_dcmd("nvlist", (uintptr_t)spa.spa_config, flags,
1123 	    0, NULL));
1124 }
1125 
1126 /*
1127  * ::vdev
1128  *
1129  * Print out a summarized vdev_t, in the following form:
1130  *
1131  * ADDR             STATE	AUX            DESC
1132  * fffffffbcde23df0 HEALTHY	-              /dev/dsk/c0t0d0
1133  *
1134  * If '-r' is specified, recursively visit all children.
1135  *
1136  * With '-e', the statistics associated with the vdev are printed as well.
1137  */
1138 static int
1139 do_print_vdev(uintptr_t addr, int flags, int depth, int stats,
1140     int recursive)
1141 {
1142 	vdev_t vdev;
1143 	char desc[MAXNAMELEN];
1144 	int c, children;
1145 	uintptr_t *child;
1146 	const char *state, *aux;
1147 
1148 	if (mdb_vread(&vdev, sizeof (vdev), (uintptr_t)addr) == -1) {
1149 		mdb_warn("failed to read vdev_t at %p\n", (uintptr_t)addr);
1150 		return (DCMD_ERR);
1151 	}
1152 
1153 	if (flags & DCMD_PIPE_OUT) {
1154 		mdb_printf("%#lr", addr);
1155 	} else {
1156 		if (vdev.vdev_path != NULL) {
1157 			if (mdb_readstr(desc, sizeof (desc),
1158 			    (uintptr_t)vdev.vdev_path) == -1) {
1159 				mdb_warn("failed to read vdev_path at %p\n",
1160 				    vdev.vdev_path);
1161 				return (DCMD_ERR);
1162 			}
1163 		} else if (vdev.vdev_ops != NULL) {
1164 			vdev_ops_t ops;
1165 			if (mdb_vread(&ops, sizeof (ops),
1166 			    (uintptr_t)vdev.vdev_ops) == -1) {
1167 				mdb_warn("failed to read vdev_ops at %p\n",
1168 				    vdev.vdev_ops);
1169 				return (DCMD_ERR);
1170 			}
1171 			(void) strcpy(desc, ops.vdev_op_type);
1172 		} else {
1173 			(void) strcpy(desc, "<unknown>");
1174 		}
1175 
1176 		if (depth == 0 && DCMD_HDRSPEC(flags))
1177 			mdb_printf("%<u>%-?s %-9s %-12s %-*s%</u>\n",
1178 			    "ADDR", "STATE", "AUX",
1179 			    sizeof (uintptr_t) == 4 ? 43 : 35,
1180 			    "DESCRIPTION");
1181 
1182 		mdb_printf("%0?p ", addr);
1183 
1184 		switch (vdev.vdev_state) {
1185 		case VDEV_STATE_CLOSED:
1186 			state = "CLOSED";
1187 			break;
1188 		case VDEV_STATE_OFFLINE:
1189 			state = "OFFLINE";
1190 			break;
1191 		case VDEV_STATE_CANT_OPEN:
1192 			state = "CANT_OPEN";
1193 			break;
1194 		case VDEV_STATE_DEGRADED:
1195 			state = "DEGRADED";
1196 			break;
1197 		case VDEV_STATE_HEALTHY:
1198 			state = "HEALTHY";
1199 			break;
1200 		case VDEV_STATE_REMOVED:
1201 			state = "REMOVED";
1202 			break;
1203 		case VDEV_STATE_FAULTED:
1204 			state = "FAULTED";
1205 			break;
1206 		default:
1207 			state = "UNKNOWN";
1208 			break;
1209 		}
1210 
1211 		switch (vdev.vdev_stat.vs_aux) {
1212 		case VDEV_AUX_NONE:
1213 			aux = "-";
1214 			break;
1215 		case VDEV_AUX_OPEN_FAILED:
1216 			aux = "OPEN_FAILED";
1217 			break;
1218 		case VDEV_AUX_CORRUPT_DATA:
1219 			aux = "CORRUPT_DATA";
1220 			break;
1221 		case VDEV_AUX_NO_REPLICAS:
1222 			aux = "NO_REPLICAS";
1223 			break;
1224 		case VDEV_AUX_BAD_GUID_SUM:
1225 			aux = "BAD_GUID_SUM";
1226 			break;
1227 		case VDEV_AUX_TOO_SMALL:
1228 			aux = "TOO_SMALL";
1229 			break;
1230 		case VDEV_AUX_BAD_LABEL:
1231 			aux = "BAD_LABEL";
1232 			break;
1233 		case VDEV_AUX_VERSION_NEWER:
1234 			aux = "VERS_NEWER";
1235 			break;
1236 		case VDEV_AUX_VERSION_OLDER:
1237 			aux = "VERS_OLDER";
1238 			break;
1239 		case VDEV_AUX_SPARED:
1240 			aux = "SPARED";
1241 			break;
1242 		case VDEV_AUX_ERR_EXCEEDED:
1243 			aux = "ERR_EXCEEDED";
1244 			break;
1245 		case VDEV_AUX_IO_FAILURE:
1246 			aux = "IO_FAILURE";
1247 			break;
1248 		case VDEV_AUX_BAD_LOG:
1249 			aux = "BAD_LOG";
1250 			break;
1251 		case VDEV_AUX_EXTERNAL:
1252 			aux = "EXTERNAL";
1253 			break;
1254 		case VDEV_AUX_SPLIT_POOL:
1255 			aux = "SPLIT_POOL";
1256 			break;
1257 		default:
1258 			aux = "UNKNOWN";
1259 			break;
1260 		}
1261 
1262 		mdb_printf("%-9s %-12s %*s%s\n", state, aux, depth, "", desc);
1263 
1264 		if (stats) {
1265 			vdev_stat_t *vs = &vdev.vdev_stat;
1266 			int i;
1267 
1268 			mdb_inc_indent(4);
1269 			mdb_printf("\n");
1270 			mdb_printf("%<u>       %12s %12s %12s %12s "
1271 			    "%12s%</u>\n", "READ", "WRITE", "FREE", "CLAIM",
1272 			    "IOCTL");
1273 			mdb_printf("OPS     ");
1274 			for (i = 1; i < ZIO_TYPES; i++)
1275 				mdb_printf("%11#llx%s", vs->vs_ops[i],
1276 				    i == ZIO_TYPES - 1 ? "" : "  ");
1277 			mdb_printf("\n");
1278 			mdb_printf("BYTES   ");
1279 			for (i = 1; i < ZIO_TYPES; i++)
1280 				mdb_printf("%11#llx%s", vs->vs_bytes[i],
1281 				    i == ZIO_TYPES - 1 ? "" : "  ");
1282 
1283 
1284 			mdb_printf("\n");
1285 			mdb_printf("EREAD    %10#llx\n", vs->vs_read_errors);
1286 			mdb_printf("EWRITE   %10#llx\n", vs->vs_write_errors);
1287 			mdb_printf("ECKSUM   %10#llx\n",
1288 			    vs->vs_checksum_errors);
1289 			mdb_dec_indent(4);
1290 		}
1291 
1292 		if (stats)
1293 			mdb_printf("\n");
1294 	}
1295 
1296 	children = vdev.vdev_children;
1297 
1298 	if (children == 0 || !recursive)
1299 		return (DCMD_OK);
1300 
1301 	child = mdb_alloc(children * sizeof (void *), UM_SLEEP | UM_GC);
1302 	if (mdb_vread(child, children * sizeof (void *),
1303 	    (uintptr_t)vdev.vdev_child) == -1) {
1304 		mdb_warn("failed to read vdev children at %p", vdev.vdev_child);
1305 		return (DCMD_ERR);
1306 	}
1307 
1308 	for (c = 0; c < children; c++) {
1309 		if (do_print_vdev(child[c], flags, depth + 2, stats,
1310 		    recursive))
1311 			return (DCMD_ERR);
1312 	}
1313 
1314 	return (DCMD_OK);
1315 }
1316 
1317 static int
1318 vdev_print(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
1319 {
1320 	int recursive = FALSE;
1321 	int stats = FALSE;
1322 	uint64_t depth = 0;
1323 
1324 	if (mdb_getopts(argc, argv,
1325 	    'r', MDB_OPT_SETBITS, TRUE, &recursive,
1326 	    'e', MDB_OPT_SETBITS, TRUE, &stats,
1327 	    'd', MDB_OPT_UINT64, &depth,
1328 	    NULL) != argc)
1329 		return (DCMD_USAGE);
1330 
1331 	if (!(flags & DCMD_ADDRSPEC)) {
1332 		mdb_warn("no vdev_t address given\n");
1333 		return (DCMD_ERR);
1334 	}
1335 
1336 	return (do_print_vdev(addr, flags, (int)depth, stats, recursive));
1337 }
1338 
1339 typedef struct metaslab_walk_data {
1340 	uint64_t mw_numvdevs;
1341 	uintptr_t *mw_vdevs;
1342 	int mw_curvdev;
1343 	uint64_t mw_nummss;
1344 	uintptr_t *mw_mss;
1345 	int mw_curms;
1346 } metaslab_walk_data_t;
1347 
1348 static int
1349 metaslab_walk_step(mdb_walk_state_t *wsp)
1350 {
1351 	metaslab_walk_data_t *mw = wsp->walk_data;
1352 	metaslab_t ms;
1353 	uintptr_t msp;
1354 
1355 	if (mw->mw_curvdev >= mw->mw_numvdevs)
1356 		return (WALK_DONE);
1357 
1358 	if (mw->mw_mss == NULL) {
1359 		uintptr_t mssp;
1360 		uintptr_t vdevp;
1361 
1362 		ASSERT(mw->mw_curms == 0);
1363 		ASSERT(mw->mw_nummss == 0);
1364 
1365 		vdevp = mw->mw_vdevs[mw->mw_curvdev];
1366 		if (GETMEMB(vdevp, struct vdev, vdev_ms, mssp) ||
1367 		    GETMEMB(vdevp, struct vdev, vdev_ms_count, mw->mw_nummss)) {
1368 			return (WALK_ERR);
1369 		}
1370 
1371 		mw->mw_mss = mdb_alloc(mw->mw_nummss * sizeof (void*),
1372 		    UM_SLEEP | UM_GC);
1373 		if (mdb_vread(mw->mw_mss, mw->mw_nummss * sizeof (void*),
1374 		    mssp) == -1) {
1375 			mdb_warn("failed to read vdev_ms at %p", mssp);
1376 			return (WALK_ERR);
1377 		}
1378 	}
1379 
1380 	if (mw->mw_curms >= mw->mw_nummss) {
1381 		mw->mw_mss = NULL;
1382 		mw->mw_curms = 0;
1383 		mw->mw_nummss = 0;
1384 		mw->mw_curvdev++;
1385 		return (WALK_NEXT);
1386 	}
1387 
1388 	msp = mw->mw_mss[mw->mw_curms];
1389 	if (mdb_vread(&ms, sizeof (metaslab_t), msp) == -1) {
1390 		mdb_warn("failed to read metaslab_t at %p", msp);
1391 		return (WALK_ERR);
1392 	}
1393 
1394 	mw->mw_curms++;
1395 
1396 	return (wsp->walk_callback(msp, &ms, wsp->walk_cbdata));
1397 }
1398 
1399 /* ARGSUSED */
1400 static int
1401 metaslab_walk_init(mdb_walk_state_t *wsp)
1402 {
1403 	metaslab_walk_data_t *mw;
1404 	uintptr_t root_vdevp;
1405 	uintptr_t childp;
1406 
1407 	if (wsp->walk_addr == NULL) {
1408 		mdb_warn("must supply address of spa_t\n");
1409 		return (WALK_ERR);
1410 	}
1411 
1412 	mw = mdb_zalloc(sizeof (metaslab_walk_data_t), UM_SLEEP | UM_GC);
1413 
1414 	if (GETMEMB(wsp->walk_addr, struct spa, spa_root_vdev, root_vdevp) ||
1415 	    GETMEMB(root_vdevp, struct vdev, vdev_children, mw->mw_numvdevs) ||
1416 	    GETMEMB(root_vdevp, struct vdev, vdev_child, childp)) {
1417 		return (DCMD_ERR);
1418 	}
1419 
1420 	mw->mw_vdevs = mdb_alloc(mw->mw_numvdevs * sizeof (void *),
1421 	    UM_SLEEP | UM_GC);
1422 	if (mdb_vread(mw->mw_vdevs, mw->mw_numvdevs * sizeof (void *),
1423 	    childp) == -1) {
1424 		mdb_warn("failed to read root vdev children at %p", childp);
1425 		return (DCMD_ERR);
1426 	}
1427 
1428 	wsp->walk_data = mw;
1429 
1430 	return (WALK_NEXT);
1431 }
1432 
1433 typedef struct mdb_spa {
1434 	uintptr_t spa_dsl_pool;
1435 	uintptr_t spa_root_vdev;
1436 } mdb_spa_t;
1437 
1438 typedef struct mdb_dsl_dir {
1439 	uintptr_t dd_phys;
1440 	int64_t dd_space_towrite[TXG_SIZE];
1441 } mdb_dsl_dir_t;
1442 
1443 typedef struct mdb_dsl_dir_phys {
1444 	uint64_t dd_used_bytes;
1445 	uint64_t dd_compressed_bytes;
1446 	uint64_t dd_uncompressed_bytes;
1447 } mdb_dsl_dir_phys_t;
1448 
1449 typedef struct mdb_vdev {
1450 	uintptr_t vdev_parent;
1451 	uintptr_t vdev_ms;
1452 	uint64_t vdev_ms_count;
1453 	vdev_stat_t vdev_stat;
1454 } mdb_vdev_t;
1455 
1456 typedef struct mdb_metaslab {
1457 	space_map_t ms_allocmap[TXG_SIZE];
1458 	space_map_t ms_freemap[TXG_SIZE];
1459 	space_map_t ms_map;
1460 	space_map_obj_t ms_smo;
1461 	space_map_obj_t ms_smo_syncing;
1462 } mdb_metaslab_t;
1463 
1464 typedef struct space_data {
1465 	uint64_t ms_allocmap[TXG_SIZE];
1466 	uint64_t ms_freemap[TXG_SIZE];
1467 	uint64_t ms_map;
1468 	uint64_t avail;
1469 	uint64_t nowavail;
1470 } space_data_t;
1471 
1472 /* ARGSUSED */
1473 static int
1474 space_cb(uintptr_t addr, const void *unknown, void *arg)
1475 {
1476 	space_data_t *sd = arg;
1477 	mdb_metaslab_t ms;
1478 
1479 	if (GETMEMB(addr, struct metaslab, ms_allocmap, ms.ms_allocmap) ||
1480 	    GETMEMB(addr, struct metaslab, ms_freemap, ms.ms_freemap) ||
1481 	    GETMEMB(addr, struct metaslab, ms_map, ms.ms_map) ||
1482 	    GETMEMB(addr, struct metaslab, ms_smo, ms.ms_smo) ||
1483 	    GETMEMB(addr, struct metaslab, ms_smo_syncing, ms.ms_smo_syncing)) {
1484 		return (WALK_ERR);
1485 	}
1486 
1487 	sd->ms_allocmap[0] += ms.ms_allocmap[0].sm_space;
1488 	sd->ms_allocmap[1] += ms.ms_allocmap[1].sm_space;
1489 	sd->ms_allocmap[2] += ms.ms_allocmap[2].sm_space;
1490 	sd->ms_allocmap[3] += ms.ms_allocmap[3].sm_space;
1491 	sd->ms_freemap[0] += ms.ms_freemap[0].sm_space;
1492 	sd->ms_freemap[1] += ms.ms_freemap[1].sm_space;
1493 	sd->ms_freemap[2] += ms.ms_freemap[2].sm_space;
1494 	sd->ms_freemap[3] += ms.ms_freemap[3].sm_space;
1495 	sd->ms_map += ms.ms_map.sm_space;
1496 	sd->avail += ms.ms_map.sm_size - ms.ms_smo.smo_alloc;
1497 	sd->nowavail += ms.ms_map.sm_size - ms.ms_smo_syncing.smo_alloc;
1498 
1499 	return (WALK_NEXT);
1500 }
1501 
1502 /*
1503  * ::spa_space [-b]
1504  *
1505  * Given a spa_t, print out it's on-disk space usage and in-core
1506  * estimates of future usage.  If -b is given, print space in bytes.
1507  * Otherwise print in megabytes.
1508  */
1509 /* ARGSUSED */
1510 static int
1511 spa_space(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
1512 {
1513 	mdb_spa_t spa;
1514 	uintptr_t dp_root_dir;
1515 	mdb_dsl_dir_t dd;
1516 	mdb_dsl_dir_phys_t dsp;
1517 	uint64_t children;
1518 	uintptr_t childaddr;
1519 	space_data_t sd;
1520 	int shift = 20;
1521 	char *suffix = "M";
1522 	int bits = FALSE;
1523 
1524 	if (mdb_getopts(argc, argv, 'b', MDB_OPT_SETBITS, TRUE, &bits, NULL) !=
1525 	    argc)
1526 		return (DCMD_USAGE);
1527 	if (!(flags & DCMD_ADDRSPEC))
1528 		return (DCMD_USAGE);
1529 
1530 	if (bits) {
1531 		shift = 0;
1532 		suffix = "";
1533 	}
1534 
1535 	if (GETMEMB(addr, struct spa, spa_dsl_pool, spa.spa_dsl_pool) ||
1536 	    GETMEMB(addr, struct spa, spa_root_vdev, spa.spa_root_vdev) ||
1537 	    GETMEMB(spa.spa_root_vdev, struct vdev, vdev_children, children) ||
1538 	    GETMEMB(spa.spa_root_vdev, struct vdev, vdev_child, childaddr) ||
1539 	    GETMEMB(spa.spa_dsl_pool, struct dsl_pool,
1540 	    dp_root_dir, dp_root_dir) ||
1541 	    GETMEMB(dp_root_dir, struct dsl_dir, dd_phys, dd.dd_phys) ||
1542 	    GETMEMB(dp_root_dir, struct dsl_dir,
1543 	    dd_space_towrite, dd.dd_space_towrite) ||
1544 	    GETMEMB(dd.dd_phys, struct dsl_dir_phys,
1545 	    dd_used_bytes, dsp.dd_used_bytes) ||
1546 	    GETMEMB(dd.dd_phys, struct dsl_dir_phys,
1547 	    dd_compressed_bytes, dsp.dd_compressed_bytes) ||
1548 	    GETMEMB(dd.dd_phys, struct dsl_dir_phys,
1549 	    dd_uncompressed_bytes, dsp.dd_uncompressed_bytes)) {
1550 		return (DCMD_ERR);
1551 	}
1552 
1553 	mdb_printf("dd_space_towrite = %llu%s %llu%s %llu%s %llu%s\n",
1554 	    dd.dd_space_towrite[0] >> shift, suffix,
1555 	    dd.dd_space_towrite[1] >> shift, suffix,
1556 	    dd.dd_space_towrite[2] >> shift, suffix,
1557 	    dd.dd_space_towrite[3] >> shift, suffix);
1558 
1559 	mdb_printf("dd_phys.dd_used_bytes = %llu%s\n",
1560 	    dsp.dd_used_bytes >> shift, suffix);
1561 	mdb_printf("dd_phys.dd_compressed_bytes = %llu%s\n",
1562 	    dsp.dd_compressed_bytes >> shift, suffix);
1563 	mdb_printf("dd_phys.dd_uncompressed_bytes = %llu%s\n",
1564 	    dsp.dd_uncompressed_bytes >> shift, suffix);
1565 
1566 	bzero(&sd, sizeof (sd));
1567 	if (mdb_pwalk("metaslab", space_cb, &sd, addr) != 0) {
1568 		mdb_warn("can't walk metaslabs");
1569 		return (DCMD_ERR);
1570 	}
1571 
1572 	mdb_printf("ms_allocmap = %llu%s %llu%s %llu%s %llu%s\n",
1573 	    sd.ms_allocmap[0] >> shift, suffix,
1574 	    sd.ms_allocmap[1] >> shift, suffix,
1575 	    sd.ms_allocmap[2] >> shift, suffix,
1576 	    sd.ms_allocmap[3] >> shift, suffix);
1577 	mdb_printf("ms_freemap = %llu%s %llu%s %llu%s %llu%s\n",
1578 	    sd.ms_freemap[0] >> shift, suffix,
1579 	    sd.ms_freemap[1] >> shift, suffix,
1580 	    sd.ms_freemap[2] >> shift, suffix,
1581 	    sd.ms_freemap[3] >> shift, suffix);
1582 	mdb_printf("ms_map = %llu%s\n", sd.ms_map >> shift, suffix);
1583 	mdb_printf("last synced avail = %llu%s\n", sd.avail >> shift, suffix);
1584 	mdb_printf("current syncing avail = %llu%s\n",
1585 	    sd.nowavail >> shift, suffix);
1586 
1587 	return (DCMD_OK);
1588 }
1589 
1590 /*
1591  * ::spa_verify
1592  *
1593  * Given a spa_t, verify that that the pool is self-consistent.
1594  * Currently, it only checks to make sure that the vdev tree exists.
1595  */
1596 /* ARGSUSED */
1597 static int
1598 spa_verify(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
1599 {
1600 	spa_t spa;
1601 
1602 	if (argc != 0 || !(flags & DCMD_ADDRSPEC))
1603 		return (DCMD_USAGE);
1604 
1605 	if (mdb_vread(&spa, sizeof (spa), addr) == -1) {
1606 		mdb_warn("failed to read spa_t at %p", addr);
1607 		return (DCMD_ERR);
1608 	}
1609 
1610 	if (spa.spa_root_vdev == NULL) {
1611 		mdb_printf("no vdev tree present\n");
1612 		return (DCMD_OK);
1613 	}
1614 
1615 	return (DCMD_OK);
1616 }
1617 
1618 static int
1619 spa_print_aux(spa_aux_vdev_t *sav, uint_t flags, mdb_arg_t *v,
1620     const char *name)
1621 {
1622 	uintptr_t *aux;
1623 	size_t len;
1624 	int ret, i;
1625 
1626 	/*
1627 	 * Iterate over aux vdevs and print those out as well.  This is a
1628 	 * little annoying because we don't have a root vdev to pass to ::vdev.
1629 	 * Instead, we print a single line and then call it for each child
1630 	 * vdev.
1631 	 */
1632 	if (sav->sav_count != 0) {
1633 		v[1].a_type = MDB_TYPE_STRING;
1634 		v[1].a_un.a_str = "-d";
1635 		v[2].a_type = MDB_TYPE_IMMEDIATE;
1636 		v[2].a_un.a_val = 2;
1637 
1638 		len = sav->sav_count * sizeof (uintptr_t);
1639 		aux = mdb_alloc(len, UM_SLEEP);
1640 		if (mdb_vread(aux, len,
1641 		    (uintptr_t)sav->sav_vdevs) == -1) {
1642 			mdb_free(aux, len);
1643 			mdb_warn("failed to read l2cache vdevs at %p",
1644 			    sav->sav_vdevs);
1645 			return (DCMD_ERR);
1646 		}
1647 
1648 		mdb_printf("%-?s %-9s %-12s %s\n", "-", "-", "-", name);
1649 
1650 		for (i = 0; i < sav->sav_count; i++) {
1651 			ret = mdb_call_dcmd("vdev", aux[i], flags, 3, v);
1652 			if (ret != DCMD_OK) {
1653 				mdb_free(aux, len);
1654 				return (ret);
1655 			}
1656 		}
1657 
1658 		mdb_free(aux, len);
1659 	}
1660 
1661 	return (0);
1662 }
1663 
1664 /*
1665  * ::spa_vdevs
1666  *
1667  * 	-e	Include error stats
1668  *
1669  * Print out a summarized list of vdevs for the given spa_t.
1670  * This is accomplished by invoking "::vdev -re" on the root vdev, as well as
1671  * iterating over the cache devices.
1672  */
1673 /* ARGSUSED */
1674 static int
1675 spa_vdevs(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
1676 {
1677 	spa_t spa;
1678 	mdb_arg_t v[3];
1679 	int errors = FALSE;
1680 	int ret;
1681 
1682 	if (mdb_getopts(argc, argv,
1683 	    'e', MDB_OPT_SETBITS, TRUE, &errors,
1684 	    NULL) != argc)
1685 		return (DCMD_USAGE);
1686 
1687 	if (!(flags & DCMD_ADDRSPEC))
1688 		return (DCMD_USAGE);
1689 
1690 	if (mdb_vread(&spa, sizeof (spa), addr) == -1) {
1691 		mdb_warn("failed to read spa_t at %p", addr);
1692 		return (DCMD_ERR);
1693 	}
1694 
1695 	/*
1696 	 * Unitialized spa_t structures can have a NULL root vdev.
1697 	 */
1698 	if (spa.spa_root_vdev == NULL) {
1699 		mdb_printf("no associated vdevs\n");
1700 		return (DCMD_OK);
1701 	}
1702 
1703 	v[0].a_type = MDB_TYPE_STRING;
1704 	v[0].a_un.a_str = errors ? "-re" : "-r";
1705 
1706 	ret = mdb_call_dcmd("vdev", (uintptr_t)spa.spa_root_vdev,
1707 	    flags, 1, v);
1708 	if (ret != DCMD_OK)
1709 		return (ret);
1710 
1711 	if (spa_print_aux(&spa.spa_l2cache, flags, v, "cache") != 0 ||
1712 	    spa_print_aux(&spa.spa_spares, flags, v, "spares") != 0)
1713 		return (DCMD_ERR);
1714 
1715 	return (DCMD_OK);
1716 }
1717 
1718 /*
1719  * ::zio
1720  *
1721  * Print a summary of zio_t and all its children.  This is intended to display a
1722  * zio tree, and hence we only pick the most important pieces of information for
1723  * the main summary.  More detailed information can always be found by doing a
1724  * '::print zio' on the underlying zio_t.  The columns we display are:
1725  *
1726  *	ADDRESS		TYPE	STAGE		WAITER
1727  *
1728  * The 'address' column is indented by one space for each depth level as we
1729  * descend down the tree.
1730  */
1731 
1732 #define	ZIO_MAXINDENT	24
1733 #define	ZIO_MAXWIDTH	(sizeof (uintptr_t) * 2 + ZIO_MAXINDENT)
1734 #define	ZIO_WALK_SELF	0
1735 #define	ZIO_WALK_CHILD	1
1736 #define	ZIO_WALK_PARENT	2
1737 
1738 typedef struct zio_print_args {
1739 	int	zpa_current_depth;
1740 	int	zpa_min_depth;
1741 	int	zpa_max_depth;
1742 	int	zpa_type;
1743 	uint_t	zpa_flags;
1744 } zio_print_args_t;
1745 
1746 static int zio_child_cb(uintptr_t addr, const void *unknown, void *arg);
1747 
1748 static int
1749 zio_print_cb(uintptr_t addr, const void *data, void *priv)
1750 {
1751 	const zio_t *zio = data;
1752 	zio_print_args_t *zpa = priv;
1753 	mdb_ctf_id_t type_enum, stage_enum;
1754 	int indent = zpa->zpa_current_depth;
1755 	const char *type, *stage;
1756 	uintptr_t laddr;
1757 
1758 	if (indent > ZIO_MAXINDENT)
1759 		indent = ZIO_MAXINDENT;
1760 
1761 	if (mdb_ctf_lookup_by_name("enum zio_type", &type_enum) == -1 ||
1762 	    mdb_ctf_lookup_by_name("enum zio_stage", &stage_enum) == -1) {
1763 		mdb_warn("failed to lookup zio enums");
1764 		return (WALK_ERR);
1765 	}
1766 
1767 	if ((type = mdb_ctf_enum_name(type_enum, zio->io_type)) != NULL)
1768 		type += sizeof ("ZIO_TYPE_") - 1;
1769 	else
1770 		type = "?";
1771 
1772 	if ((stage = mdb_ctf_enum_name(stage_enum, zio->io_stage)) != NULL)
1773 		stage += sizeof ("ZIO_STAGE_") - 1;
1774 	else
1775 		stage = "?";
1776 
1777 	if (zpa->zpa_current_depth >= zpa->zpa_min_depth) {
1778 		if (zpa->zpa_flags & DCMD_PIPE_OUT) {
1779 			mdb_printf("%?p\n", addr);
1780 		} else {
1781 			mdb_printf("%*s%-*p %-5s %-16s ", indent, "",
1782 			    ZIO_MAXWIDTH - indent, addr, type, stage);
1783 			if (zio->io_waiter)
1784 				mdb_printf("%?p\n", zio->io_waiter);
1785 			else
1786 				mdb_printf("-\n");
1787 		}
1788 	}
1789 
1790 	if (zpa->zpa_current_depth >= zpa->zpa_max_depth)
1791 		return (WALK_NEXT);
1792 
1793 	if (zpa->zpa_type == ZIO_WALK_PARENT)
1794 		laddr = addr + OFFSETOF(zio_t, io_parent_list);
1795 	else
1796 		laddr = addr + OFFSETOF(zio_t, io_child_list);
1797 
1798 	zpa->zpa_current_depth++;
1799 	if (mdb_pwalk("list", zio_child_cb, zpa, laddr) != 0) {
1800 		mdb_warn("failed to walk zio_t children at %p\n", laddr);
1801 		return (WALK_ERR);
1802 	}
1803 	zpa->zpa_current_depth--;
1804 
1805 	return (WALK_NEXT);
1806 }
1807 
1808 /* ARGSUSED */
1809 static int
1810 zio_child_cb(uintptr_t addr, const void *unknown, void *arg)
1811 {
1812 	zio_link_t zl;
1813 	zio_t zio;
1814 	uintptr_t ziop;
1815 	zio_print_args_t *zpa = arg;
1816 
1817 	if (mdb_vread(&zl, sizeof (zl), addr) == -1) {
1818 		mdb_warn("failed to read zio_link_t at %p", addr);
1819 		return (WALK_ERR);
1820 	}
1821 
1822 	if (zpa->zpa_type == ZIO_WALK_PARENT)
1823 		ziop = (uintptr_t)zl.zl_parent;
1824 	else
1825 		ziop = (uintptr_t)zl.zl_child;
1826 
1827 	if (mdb_vread(&zio, sizeof (zio_t), ziop) == -1) {
1828 		mdb_warn("failed to read zio_t at %p", ziop);
1829 		return (WALK_ERR);
1830 	}
1831 
1832 	return (zio_print_cb(ziop, &zio, arg));
1833 }
1834 
1835 /* ARGSUSED */
1836 static int
1837 zio_print(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
1838 {
1839 	zio_t zio;
1840 	zio_print_args_t zpa = { 0 };
1841 
1842 	if (!(flags & DCMD_ADDRSPEC))
1843 		return (DCMD_USAGE);
1844 
1845 	if (mdb_getopts(argc, argv,
1846 	    'r', MDB_OPT_SETBITS, INT_MAX, &zpa.zpa_max_depth,
1847 	    'c', MDB_OPT_SETBITS, ZIO_WALK_CHILD, &zpa.zpa_type,
1848 	    'p', MDB_OPT_SETBITS, ZIO_WALK_PARENT, &zpa.zpa_type,
1849 	    NULL) != argc)
1850 		return (DCMD_USAGE);
1851 
1852 	zpa.zpa_flags = flags;
1853 	if (zpa.zpa_max_depth != 0) {
1854 		if (zpa.zpa_type == ZIO_WALK_SELF)
1855 			zpa.zpa_type = ZIO_WALK_CHILD;
1856 	} else if (zpa.zpa_type != ZIO_WALK_SELF) {
1857 		zpa.zpa_min_depth = 1;
1858 		zpa.zpa_max_depth = 1;
1859 	}
1860 
1861 	if (mdb_vread(&zio, sizeof (zio_t), addr) == -1) {
1862 		mdb_warn("failed to read zio_t at %p", addr);
1863 		return (DCMD_ERR);
1864 	}
1865 
1866 	if (!(flags & DCMD_PIPE_OUT) && DCMD_HDRSPEC(flags))
1867 		mdb_printf("%<u>%-*s %-5s %-16s %-?s%</u>\n", ZIO_MAXWIDTH,
1868 		    "ADDRESS", "TYPE", "STAGE", "WAITER");
1869 
1870 	if (zio_print_cb(addr, &zio, &zpa) != WALK_NEXT)
1871 		return (DCMD_ERR);
1872 
1873 	return (DCMD_OK);
1874 }
1875 
1876 /*
1877  * [addr]::zio_state
1878  *
1879  * Print a summary of all zio_t structures on the system, or for a particular
1880  * pool.  This is equivalent to '::walk zio_root | ::zio'.
1881  */
1882 /*ARGSUSED*/
1883 static int
1884 zio_state(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
1885 {
1886 	/*
1887 	 * MDB will remember the last address of the pipeline, so if we don't
1888 	 * zero this we'll end up trying to walk zio structures for a
1889 	 * non-existent spa_t.
1890 	 */
1891 	if (!(flags & DCMD_ADDRSPEC))
1892 		addr = 0;
1893 
1894 	return (mdb_pwalk_dcmd("zio_root", "zio", argc, argv, addr));
1895 }
1896 
1897 typedef struct txg_list_walk_data {
1898 	uintptr_t lw_head[TXG_SIZE];
1899 	int	lw_txgoff;
1900 	int	lw_maxoff;
1901 	size_t	lw_offset;
1902 	void	*lw_obj;
1903 } txg_list_walk_data_t;
1904 
1905 static int
1906 txg_list_walk_init_common(mdb_walk_state_t *wsp, int txg, int maxoff)
1907 {
1908 	txg_list_walk_data_t *lwd;
1909 	txg_list_t list;
1910 	int i;
1911 
1912 	lwd = mdb_alloc(sizeof (txg_list_walk_data_t), UM_SLEEP | UM_GC);
1913 	if (mdb_vread(&list, sizeof (txg_list_t), wsp->walk_addr) == -1) {
1914 		mdb_warn("failed to read txg_list_t at %#lx", wsp->walk_addr);
1915 		return (WALK_ERR);
1916 	}
1917 
1918 	for (i = 0; i < TXG_SIZE; i++)
1919 		lwd->lw_head[i] = (uintptr_t)list.tl_head[i];
1920 	lwd->lw_offset = list.tl_offset;
1921 	lwd->lw_obj = mdb_alloc(lwd->lw_offset + sizeof (txg_node_t),
1922 	    UM_SLEEP | UM_GC);
1923 	lwd->lw_txgoff = txg;
1924 	lwd->lw_maxoff = maxoff;
1925 
1926 	wsp->walk_addr = lwd->lw_head[lwd->lw_txgoff];
1927 	wsp->walk_data = lwd;
1928 
1929 	return (WALK_NEXT);
1930 }
1931 
1932 static int
1933 txg_list_walk_init(mdb_walk_state_t *wsp)
1934 {
1935 	return (txg_list_walk_init_common(wsp, 0, TXG_SIZE-1));
1936 }
1937 
1938 static int
1939 txg_list0_walk_init(mdb_walk_state_t *wsp)
1940 {
1941 	return (txg_list_walk_init_common(wsp, 0, 0));
1942 }
1943 
1944 static int
1945 txg_list1_walk_init(mdb_walk_state_t *wsp)
1946 {
1947 	return (txg_list_walk_init_common(wsp, 1, 1));
1948 }
1949 
1950 static int
1951 txg_list2_walk_init(mdb_walk_state_t *wsp)
1952 {
1953 	return (txg_list_walk_init_common(wsp, 2, 2));
1954 }
1955 
1956 static int
1957 txg_list3_walk_init(mdb_walk_state_t *wsp)
1958 {
1959 	return (txg_list_walk_init_common(wsp, 3, 3));
1960 }
1961 
1962 static int
1963 txg_list_walk_step(mdb_walk_state_t *wsp)
1964 {
1965 	txg_list_walk_data_t *lwd = wsp->walk_data;
1966 	uintptr_t addr;
1967 	txg_node_t *node;
1968 	int status;
1969 
1970 	while (wsp->walk_addr == NULL && lwd->lw_txgoff < lwd->lw_maxoff) {
1971 		lwd->lw_txgoff++;
1972 		wsp->walk_addr = lwd->lw_head[lwd->lw_txgoff];
1973 	}
1974 
1975 	if (wsp->walk_addr == NULL)
1976 		return (WALK_DONE);
1977 
1978 	addr = wsp->walk_addr - lwd->lw_offset;
1979 
1980 	if (mdb_vread(lwd->lw_obj,
1981 	    lwd->lw_offset + sizeof (txg_node_t), addr) == -1) {
1982 		mdb_warn("failed to read list element at %#lx", addr);
1983 		return (WALK_ERR);
1984 	}
1985 
1986 	status = wsp->walk_callback(addr, lwd->lw_obj, wsp->walk_cbdata);
1987 	node = (txg_node_t *)((uintptr_t)lwd->lw_obj + lwd->lw_offset);
1988 	wsp->walk_addr = (uintptr_t)node->tn_next[lwd->lw_txgoff];
1989 
1990 	return (status);
1991 }
1992 
1993 /*
1994  * ::walk spa
1995  *
1996  * Walk all named spa_t structures in the namespace.  This is nothing more than
1997  * a layered avl walk.
1998  */
1999 static int
2000 spa_walk_init(mdb_walk_state_t *wsp)
2001 {
2002 	GElf_Sym sym;
2003 
2004 	if (wsp->walk_addr != NULL) {
2005 		mdb_warn("spa walk only supports global walks\n");
2006 		return (WALK_ERR);
2007 	}
2008 
2009 	if (mdb_lookup_by_obj(ZFS_OBJ_NAME, "spa_namespace_avl", &sym) == -1) {
2010 		mdb_warn("failed to find symbol 'spa_namespace_avl'");
2011 		return (WALK_ERR);
2012 	}
2013 
2014 	wsp->walk_addr = (uintptr_t)sym.st_value;
2015 
2016 	if (mdb_layered_walk("avl", wsp) == -1) {
2017 		mdb_warn("failed to walk 'avl'\n");
2018 		return (WALK_ERR);
2019 	}
2020 
2021 	return (WALK_NEXT);
2022 }
2023 
2024 static int
2025 spa_walk_step(mdb_walk_state_t *wsp)
2026 {
2027 	spa_t	spa;
2028 
2029 	if (mdb_vread(&spa, sizeof (spa), wsp->walk_addr) == -1) {
2030 		mdb_warn("failed to read spa_t at %p", wsp->walk_addr);
2031 		return (WALK_ERR);
2032 	}
2033 
2034 	return (wsp->walk_callback(wsp->walk_addr, &spa, wsp->walk_cbdata));
2035 }
2036 
2037 /*
2038  * [addr]::walk zio
2039  *
2040  * Walk all active zio_t structures on the system.  This is simply a layered
2041  * walk on top of ::walk zio_cache, with the optional ability to limit the
2042  * structures to a particular pool.
2043  */
2044 static int
2045 zio_walk_init(mdb_walk_state_t *wsp)
2046 {
2047 	wsp->walk_data = (void *)wsp->walk_addr;
2048 
2049 	if (mdb_layered_walk("zio_cache", wsp) == -1) {
2050 		mdb_warn("failed to walk 'zio_cache'\n");
2051 		return (WALK_ERR);
2052 	}
2053 
2054 	return (WALK_NEXT);
2055 }
2056 
2057 static int
2058 zio_walk_step(mdb_walk_state_t *wsp)
2059 {
2060 	zio_t zio;
2061 
2062 	if (mdb_vread(&zio, sizeof (zio), wsp->walk_addr) == -1) {
2063 		mdb_warn("failed to read zio_t at %p", wsp->walk_addr);
2064 		return (WALK_ERR);
2065 	}
2066 
2067 	if (wsp->walk_data != NULL && wsp->walk_data != zio.io_spa)
2068 		return (WALK_NEXT);
2069 
2070 	return (wsp->walk_callback(wsp->walk_addr, &zio, wsp->walk_cbdata));
2071 }
2072 
2073 /*
2074  * [addr]::walk zio_root
2075  *
2076  * Walk only root zio_t structures, optionally for a particular spa_t.
2077  */
2078 static int
2079 zio_walk_root_step(mdb_walk_state_t *wsp)
2080 {
2081 	zio_t zio;
2082 
2083 	if (mdb_vread(&zio, sizeof (zio), wsp->walk_addr) == -1) {
2084 		mdb_warn("failed to read zio_t at %p", wsp->walk_addr);
2085 		return (WALK_ERR);
2086 	}
2087 
2088 	if (wsp->walk_data != NULL && wsp->walk_data != zio.io_spa)
2089 		return (WALK_NEXT);
2090 
2091 	/* If the parent list is not empty, ignore */
2092 	if (zio.io_parent_list.list_head.list_next !=
2093 	    &((zio_t *)wsp->walk_addr)->io_parent_list.list_head)
2094 		return (WALK_NEXT);
2095 
2096 	return (wsp->walk_callback(wsp->walk_addr, &zio, wsp->walk_cbdata));
2097 }
2098 
2099 #define	NICENUM_BUFLEN 6
2100 
2101 static int
2102 snprintfrac(char *buf, int len,
2103     uint64_t numerator, uint64_t denom, int frac_digits)
2104 {
2105 	int mul = 1;
2106 	int whole, frac, i;
2107 
2108 	for (i = frac_digits; i; i--)
2109 		mul *= 10;
2110 	whole = numerator / denom;
2111 	frac = mul * numerator / denom - mul * whole;
2112 	return (mdb_snprintf(buf, len, "%u.%0*u", whole, frac_digits, frac));
2113 }
2114 
2115 static void
2116 mdb_nicenum(uint64_t num, char *buf)
2117 {
2118 	uint64_t n = num;
2119 	int index = 0;
2120 	char *u;
2121 
2122 	while (n >= 1024) {
2123 		n = (n + (1024 / 2)) / 1024; /* Round up or down */
2124 		index++;
2125 	}
2126 
2127 	u = &" \0K\0M\0G\0T\0P\0E\0"[index*2];
2128 
2129 	if (index == 0) {
2130 		(void) mdb_snprintf(buf, NICENUM_BUFLEN, "%llu",
2131 		    (u_longlong_t)n);
2132 	} else if (n < 10 && (num & (num - 1)) != 0) {
2133 		(void) snprintfrac(buf, NICENUM_BUFLEN,
2134 		    num, 1ULL << 10 * index, 2);
2135 		strcat(buf, u);
2136 	} else if (n < 100 && (num & (num - 1)) != 0) {
2137 		(void) snprintfrac(buf, NICENUM_BUFLEN,
2138 		    num, 1ULL << 10 * index, 1);
2139 		strcat(buf, u);
2140 	} else {
2141 		(void) mdb_snprintf(buf, NICENUM_BUFLEN, "%llu%s",
2142 		    (u_longlong_t)n, u);
2143 	}
2144 }
2145 
2146 /*
2147  * ::zfs_blkstats
2148  *
2149  * 	-v	print verbose per-level information
2150  *
2151  */
2152 static int
2153 zfs_blkstats(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
2154 {
2155 	boolean_t verbose = B_FALSE;
2156 	zfs_all_blkstats_t stats;
2157 	dmu_object_type_t t;
2158 	zfs_blkstat_t *tzb;
2159 	uint64_t ditto;
2160 	dmu_object_type_info_t dmu_ot[DMU_OT_NUMTYPES + 10];
2161 	/* +10 in case it grew */
2162 
2163 	if (mdb_readvar(&dmu_ot, "dmu_ot") == -1) {
2164 		mdb_warn("failed to read 'dmu_ot'");
2165 		return (DCMD_ERR);
2166 	}
2167 
2168 	if (mdb_getopts(argc, argv,
2169 	    'v', MDB_OPT_SETBITS, TRUE, &verbose,
2170 	    NULL) != argc)
2171 		return (DCMD_USAGE);
2172 
2173 	if (!(flags & DCMD_ADDRSPEC))
2174 		return (DCMD_USAGE);
2175 
2176 	if (GETMEMB(addr, struct spa, spa_dsl_pool, addr) ||
2177 	    GETMEMB(addr, struct dsl_pool, dp_blkstats, addr) ||
2178 	    mdb_vread(&stats, sizeof (zfs_all_blkstats_t), addr) == -1) {
2179 		mdb_warn("failed to read data at %p;", addr);
2180 		mdb_printf("maybe no stats? run \"zpool scrub\" first.");
2181 		return (DCMD_ERR);
2182 	}
2183 
2184 	tzb = &stats.zab_type[DN_MAX_LEVELS][DMU_OT_NUMTYPES];
2185 	if (tzb->zb_gangs != 0) {
2186 		mdb_printf("Ganged blocks: %llu\n",
2187 		    (longlong_t)tzb->zb_gangs);
2188 	}
2189 
2190 	ditto = tzb->zb_ditto_2_of_2_samevdev + tzb->zb_ditto_2_of_3_samevdev +
2191 	    tzb->zb_ditto_3_of_3_samevdev;
2192 	if (ditto != 0) {
2193 		mdb_printf("Dittoed blocks on same vdev: %llu\n",
2194 		    (longlong_t)ditto);
2195 	}
2196 
2197 	mdb_printf("\nBlocks\tLSIZE\tPSIZE\tASIZE"
2198 	    "\t  avg\t comp\t%%Total\tType\n");
2199 
2200 	for (t = 0; t <= DMU_OT_NUMTYPES; t++) {
2201 		char csize[NICENUM_BUFLEN], lsize[NICENUM_BUFLEN];
2202 		char psize[NICENUM_BUFLEN], asize[NICENUM_BUFLEN];
2203 		char avg[NICENUM_BUFLEN];
2204 		char comp[NICENUM_BUFLEN], pct[NICENUM_BUFLEN];
2205 		char typename[64];
2206 		int l;
2207 
2208 
2209 		if (t == DMU_OT_DEFERRED)
2210 			strcpy(typename, "deferred free");
2211 		else if (t == DMU_OT_TOTAL)
2212 			strcpy(typename, "Total");
2213 		else if (mdb_readstr(typename, sizeof (typename),
2214 		    (uintptr_t)dmu_ot[t].ot_name) == -1) {
2215 			mdb_warn("failed to read type name");
2216 			return (DCMD_ERR);
2217 		}
2218 
2219 		if (stats.zab_type[DN_MAX_LEVELS][t].zb_asize == 0)
2220 			continue;
2221 
2222 		for (l = -1; l < DN_MAX_LEVELS; l++) {
2223 			int level = (l == -1 ? DN_MAX_LEVELS : l);
2224 			zfs_blkstat_t *zb = &stats.zab_type[level][t];
2225 
2226 			if (zb->zb_asize == 0)
2227 				continue;
2228 
2229 			/*
2230 			 * Don't print each level unless requested.
2231 			 */
2232 			if (!verbose && level != DN_MAX_LEVELS)
2233 				continue;
2234 
2235 			/*
2236 			 * If all the space is level 0, don't print the
2237 			 * level 0 separately.
2238 			 */
2239 			if (level == 0 && zb->zb_asize ==
2240 			    stats.zab_type[DN_MAX_LEVELS][t].zb_asize)
2241 				continue;
2242 
2243 			mdb_nicenum(zb->zb_count, csize);
2244 			mdb_nicenum(zb->zb_lsize, lsize);
2245 			mdb_nicenum(zb->zb_psize, psize);
2246 			mdb_nicenum(zb->zb_asize, asize);
2247 			mdb_nicenum(zb->zb_asize / zb->zb_count, avg);
2248 			(void) snprintfrac(comp, NICENUM_BUFLEN,
2249 			    zb->zb_lsize, zb->zb_psize, 2);
2250 			(void) snprintfrac(pct, NICENUM_BUFLEN,
2251 			    100 * zb->zb_asize, tzb->zb_asize, 2);
2252 
2253 			mdb_printf("%6s\t%5s\t%5s\t%5s\t%5s"
2254 			    "\t%5s\t%6s\t",
2255 			    csize, lsize, psize, asize, avg, comp, pct);
2256 
2257 			if (level == DN_MAX_LEVELS)
2258 				mdb_printf("%s\n", typename);
2259 			else
2260 				mdb_printf("  L%d %s\n",
2261 				    level, typename);
2262 		}
2263 	}
2264 
2265 	return (DCMD_OK);
2266 }
2267 
2268 /* ARGSUSED */
2269 static int
2270 reference_cb(uintptr_t addr, const void *ignored, void *arg)
2271 {
2272 	static int gotid;
2273 	static mdb_ctf_id_t ref_id;
2274 	uintptr_t ref_holder;
2275 	uintptr_t ref_removed;
2276 	uint64_t ref_number;
2277 	boolean_t holder_is_str = B_FALSE;
2278 	char holder_str[128];
2279 	boolean_t removed = (boolean_t)arg;
2280 
2281 	if (!gotid) {
2282 		if (mdb_ctf_lookup_by_name("struct reference", &ref_id) == -1) {
2283 			mdb_warn("couldn't find struct reference");
2284 			return (WALK_ERR);
2285 		}
2286 		gotid = TRUE;
2287 	}
2288 
2289 	if (GETMEMBID(addr, &ref_id, ref_holder, ref_holder) ||
2290 	    GETMEMBID(addr, &ref_id, ref_removed, ref_removed) ||
2291 	    GETMEMBID(addr, &ref_id, ref_number, ref_number))
2292 		return (WALK_ERR);
2293 
2294 	if (mdb_readstr(holder_str, sizeof (holder_str), ref_holder) != -1)
2295 		holder_is_str = strisprint(holder_str);
2296 
2297 	if (removed)
2298 		mdb_printf("removed ");
2299 	mdb_printf("reference ");
2300 	if (ref_number != 1)
2301 		mdb_printf("with count=%llu ", ref_number);
2302 	mdb_printf("with tag %p", (void*)ref_holder);
2303 	if (holder_is_str)
2304 		mdb_printf(" \"%s\"", holder_str);
2305 	mdb_printf(", held at:\n");
2306 
2307 	(void) mdb_call_dcmd("whatis", addr, DCMD_ADDRSPEC, 0, NULL);
2308 
2309 	if (removed) {
2310 		mdb_printf("removed at:\n");
2311 		(void) mdb_call_dcmd("whatis", ref_removed,
2312 		    DCMD_ADDRSPEC, 0, NULL);
2313 	}
2314 
2315 	mdb_printf("\n");
2316 
2317 	return (WALK_NEXT);
2318 }
2319 
2320 /* ARGSUSED */
2321 static int
2322 refcount(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
2323 {
2324 	uint64_t rc_count, rc_removed_count;
2325 	uintptr_t rc_list, rc_removed;
2326 	static int gotid;
2327 	static mdb_ctf_id_t rc_id;
2328 	ulong_t off;
2329 
2330 	if (!(flags & DCMD_ADDRSPEC))
2331 		return (DCMD_USAGE);
2332 
2333 	if (!gotid) {
2334 		if (mdb_ctf_lookup_by_name("struct refcount", &rc_id) == -1) {
2335 			mdb_warn("couldn't find struct refcount");
2336 			return (DCMD_ERR);
2337 		}
2338 		gotid = TRUE;
2339 	}
2340 
2341 	if (GETMEMBID(addr, &rc_id, rc_count, rc_count) ||
2342 	    GETMEMBID(addr, &rc_id, rc_removed_count, rc_removed_count))
2343 		return (DCMD_ERR);
2344 
2345 	mdb_printf("refcount_t at %p has %llu current holds, "
2346 	    "%llu recently released holds\n",
2347 	    addr, (longlong_t)rc_count, (longlong_t)rc_removed_count);
2348 
2349 	if (rc_count > 0)
2350 		mdb_printf("current holds:\n");
2351 	if (mdb_ctf_offsetof(rc_id, "rc_list", &off) == -1)
2352 		return (DCMD_ERR);
2353 	rc_list = addr + off/NBBY;
2354 	mdb_pwalk("list", reference_cb, (void*)B_FALSE, rc_list);
2355 
2356 	if (rc_removed_count > 0)
2357 		mdb_printf("released holds:\n");
2358 	if (mdb_ctf_offsetof(rc_id, "rc_removed", &off) == -1)
2359 		return (DCMD_ERR);
2360 	rc_removed = addr + off/NBBY;
2361 	mdb_pwalk("list", reference_cb, (void*)B_TRUE, rc_removed);
2362 
2363 	return (DCMD_OK);
2364 }
2365 
2366 /* ARGSUSED */
2367 static int
2368 sa_attr_table(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
2369 {
2370 	sa_attr_table_t *table;
2371 	sa_os_t sa_os;
2372 	char *name;
2373 	int i;
2374 
2375 	if (mdb_vread(&sa_os, sizeof (sa_os_t), addr) == -1) {
2376 		mdb_warn("failed to read sa_os at %p", addr);
2377 		return (DCMD_ERR);
2378 	}
2379 
2380 	table = mdb_alloc(sizeof (sa_attr_table_t) * sa_os.sa_num_attrs,
2381 	    UM_SLEEP | UM_GC);
2382 	name = mdb_alloc(MAXPATHLEN, UM_SLEEP | UM_GC);
2383 
2384 	if (mdb_vread(table, sizeof (sa_attr_table_t) * sa_os.sa_num_attrs,
2385 	    (uintptr_t)sa_os.sa_attr_table) == -1) {
2386 		mdb_warn("failed to read sa_os at %p", addr);
2387 		return (DCMD_ERR);
2388 	}
2389 
2390 	mdb_printf("%<u>%-10s %-10s %-10s %-10s %s%</u>\n",
2391 	    "ATTR ID", "REGISTERED", "LENGTH", "BSWAP", "NAME");
2392 	for (i = 0; i != sa_os.sa_num_attrs; i++) {
2393 		mdb_readstr(name, MAXPATHLEN, (uintptr_t)table[i].sa_name);
2394 		mdb_printf("%5x   %8x %8x %8x          %-s\n",
2395 		    (int)table[i].sa_attr, (int)table[i].sa_registered,
2396 		    (int)table[i].sa_length, table[i].sa_byteswap, name);
2397 	}
2398 
2399 	return (DCMD_OK);
2400 }
2401 
2402 static int
2403 sa_get_off_table(uintptr_t addr, uint32_t **off_tab, int attr_count)
2404 {
2405 	uintptr_t idx_table;
2406 
2407 	if (GETMEMB(addr, struct sa_idx_tab, sa_idx_tab, idx_table)) {
2408 		mdb_printf("can't find offset table in sa_idx_tab\n");
2409 		return (-1);
2410 	}
2411 
2412 	*off_tab = mdb_alloc(attr_count * sizeof (uint32_t),
2413 	    UM_SLEEP | UM_GC);
2414 
2415 	if (mdb_vread(*off_tab,
2416 	    attr_count * sizeof (uint32_t), idx_table) == -1) {
2417 		mdb_warn("failed to attribute offset table %p", idx_table);
2418 		return (-1);
2419 	}
2420 
2421 	return (DCMD_OK);
2422 }
2423 
2424 /*ARGSUSED*/
2425 static int
2426 sa_attr_print(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
2427 {
2428 	uint32_t *offset_tab;
2429 	int attr_count;
2430 	uint64_t attr_id;
2431 	uintptr_t attr_addr;
2432 	uintptr_t bonus_tab, spill_tab;
2433 	uintptr_t db_bonus, db_spill;
2434 	uintptr_t os, os_sa;
2435 	uintptr_t db_data;
2436 
2437 	if (argc != 1)
2438 		return (DCMD_USAGE);
2439 
2440 	if (argv[0].a_type == MDB_TYPE_STRING)
2441 		attr_id = mdb_strtoull(argv[0].a_un.a_str);
2442 	else
2443 		return (DCMD_USAGE);
2444 
2445 	if (GETMEMB(addr, struct sa_handle, sa_bonus_tab, bonus_tab) ||
2446 	    GETMEMB(addr, struct sa_handle, sa_spill_tab, spill_tab) ||
2447 	    GETMEMB(addr, struct sa_handle, sa_os, os) ||
2448 	    GETMEMB(addr, struct sa_handle, sa_bonus, db_bonus) ||
2449 	    GETMEMB(addr, struct sa_handle, sa_spill, db_spill)) {
2450 		mdb_printf("Can't find necessary information in sa_handle "
2451 		    "in sa_handle\n");
2452 		return (DCMD_ERR);
2453 	}
2454 
2455 	if (GETMEMB(os, struct objset, os_sa, os_sa)) {
2456 		mdb_printf("Can't find os_sa in objset\n");
2457 		return (DCMD_ERR);
2458 	}
2459 
2460 	if (GETMEMB(os_sa, struct sa_os, sa_num_attrs, attr_count)) {
2461 		mdb_printf("Can't find sa_num_attrs\n");
2462 		return (DCMD_ERR);
2463 	}
2464 
2465 	if (attr_id > attr_count) {
2466 		mdb_printf("attribute id number is out of range\n");
2467 		return (DCMD_ERR);
2468 	}
2469 
2470 	if (bonus_tab) {
2471 		if (sa_get_off_table(bonus_tab, &offset_tab,
2472 		    attr_count) == -1) {
2473 			return (DCMD_ERR);
2474 		}
2475 
2476 		if (GETMEMB(db_bonus, struct dmu_buf, db_data, db_data)) {
2477 			mdb_printf("can't find db_data in bonus dbuf\n");
2478 			return (DCMD_ERR);
2479 		}
2480 	}
2481 
2482 	if (bonus_tab && !TOC_ATTR_PRESENT(offset_tab[attr_id]) &&
2483 	    spill_tab == NULL) {
2484 		mdb_printf("Attribute does not exist\n");
2485 		return (DCMD_ERR);
2486 	} else if (!TOC_ATTR_PRESENT(offset_tab[attr_id]) && spill_tab) {
2487 		if (sa_get_off_table(spill_tab, &offset_tab,
2488 		    attr_count) == -1) {
2489 			return (DCMD_ERR);
2490 		}
2491 		if (GETMEMB(db_spill, struct dmu_buf, db_data, db_data)) {
2492 			mdb_printf("can't find db_data in spill dbuf\n");
2493 			return (DCMD_ERR);
2494 		}
2495 		if (!TOC_ATTR_PRESENT(offset_tab[attr_id])) {
2496 			mdb_printf("Attribute does not exist\n");
2497 			return (DCMD_ERR);
2498 		}
2499 	}
2500 	attr_addr = db_data + TOC_OFF(offset_tab[attr_id]);
2501 	mdb_printf("%p\n", attr_addr);
2502 	return (DCMD_OK);
2503 }
2504 
2505 /* ARGSUSED */
2506 static int
2507 zfs_ace_print_common(uintptr_t addr, uint_t flags,
2508     uint64_t id, uint32_t access_mask, uint16_t ace_flags,
2509     uint16_t ace_type, int verbose)
2510 {
2511 	if (DCMD_HDRSPEC(flags) && !verbose)
2512 		mdb_printf("%<u>%-?s %-8s %-8s %-8s %s%</u>\n",
2513 		    "ADDR", "FLAGS", "MASK", "TYPE", "ID");
2514 
2515 	if (!verbose) {
2516 		mdb_printf("%0?p %-8x %-8x %-8x %-llx\n", addr,
2517 		    ace_flags, access_mask, ace_type, id);
2518 		return (DCMD_OK);
2519 	}
2520 
2521 	switch (ace_flags & ACE_TYPE_FLAGS) {
2522 	case ACE_OWNER:
2523 		mdb_printf("owner@:");
2524 		break;
2525 	case (ACE_IDENTIFIER_GROUP | ACE_GROUP):
2526 		mdb_printf("group@:");
2527 		break;
2528 	case ACE_EVERYONE:
2529 		mdb_printf("everyone@:");
2530 		break;
2531 	case ACE_IDENTIFIER_GROUP:
2532 		mdb_printf("group:%llx:", (u_longlong_t)id);
2533 		break;
2534 	case 0: /* User entry */
2535 		mdb_printf("user:%llx:", (u_longlong_t)id);
2536 		break;
2537 	}
2538 
2539 	/* print out permission mask */
2540 	if (access_mask & ACE_READ_DATA)
2541 		mdb_printf("r");
2542 	else
2543 		mdb_printf("-");
2544 	if (access_mask & ACE_WRITE_DATA)
2545 		mdb_printf("w");
2546 	else
2547 		mdb_printf("-");
2548 	if (access_mask & ACE_EXECUTE)
2549 		mdb_printf("x");
2550 	else
2551 		mdb_printf("-");
2552 	if (access_mask & ACE_APPEND_DATA)
2553 		mdb_printf("p");
2554 	else
2555 		mdb_printf("-");
2556 	if (access_mask & ACE_DELETE)
2557 		mdb_printf("d");
2558 	else
2559 		mdb_printf("-");
2560 	if (access_mask & ACE_DELETE_CHILD)
2561 		mdb_printf("D");
2562 	else
2563 		mdb_printf("-");
2564 	if (access_mask & ACE_READ_ATTRIBUTES)
2565 		mdb_printf("a");
2566 	else
2567 		mdb_printf("-");
2568 	if (access_mask & ACE_WRITE_ATTRIBUTES)
2569 		mdb_printf("A");
2570 	else
2571 		mdb_printf("-");
2572 	if (access_mask & ACE_READ_NAMED_ATTRS)
2573 		mdb_printf("R");
2574 	else
2575 		mdb_printf("-");
2576 	if (access_mask & ACE_WRITE_NAMED_ATTRS)
2577 		mdb_printf("W");
2578 	else
2579 		mdb_printf("-");
2580 	if (access_mask & ACE_READ_ACL)
2581 		mdb_printf("c");
2582 	else
2583 		mdb_printf("-");
2584 	if (access_mask & ACE_WRITE_ACL)
2585 		mdb_printf("C");
2586 	else
2587 		mdb_printf("-");
2588 	if (access_mask & ACE_WRITE_OWNER)
2589 		mdb_printf("o");
2590 	else
2591 		mdb_printf("-");
2592 	if (access_mask & ACE_SYNCHRONIZE)
2593 		mdb_printf("s");
2594 	else
2595 		mdb_printf("-");
2596 
2597 	mdb_printf(":");
2598 
2599 	/* Print out inheritance flags */
2600 	if (ace_flags & ACE_FILE_INHERIT_ACE)
2601 		mdb_printf("f");
2602 	else
2603 		mdb_printf("-");
2604 	if (ace_flags & ACE_DIRECTORY_INHERIT_ACE)
2605 		mdb_printf("d");
2606 	else
2607 		mdb_printf("-");
2608 	if (ace_flags & ACE_INHERIT_ONLY_ACE)
2609 		mdb_printf("i");
2610 	else
2611 		mdb_printf("-");
2612 	if (ace_flags & ACE_NO_PROPAGATE_INHERIT_ACE)
2613 		mdb_printf("n");
2614 	else
2615 		mdb_printf("-");
2616 	if (ace_flags & ACE_SUCCESSFUL_ACCESS_ACE_FLAG)
2617 		mdb_printf("S");
2618 	else
2619 		mdb_printf("-");
2620 	if (ace_flags & ACE_FAILED_ACCESS_ACE_FLAG)
2621 		mdb_printf("F");
2622 	else
2623 		mdb_printf("-");
2624 	if (ace_flags & ACE_INHERITED_ACE)
2625 		mdb_printf("I");
2626 	else
2627 		mdb_printf("-");
2628 
2629 	switch (ace_type) {
2630 	case ACE_ACCESS_ALLOWED_ACE_TYPE:
2631 		mdb_printf(":allow\n");
2632 		break;
2633 	case ACE_ACCESS_DENIED_ACE_TYPE:
2634 		mdb_printf(":deny\n");
2635 		break;
2636 	case ACE_SYSTEM_AUDIT_ACE_TYPE:
2637 		mdb_printf(":audit\n");
2638 		break;
2639 	case ACE_SYSTEM_ALARM_ACE_TYPE:
2640 		mdb_printf(":alarm\n");
2641 		break;
2642 	default:
2643 		mdb_printf(":?\n");
2644 	}
2645 	return (DCMD_OK);
2646 }
2647 
2648 /* ARGSUSED */
2649 static int
2650 zfs_ace_print(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
2651 {
2652 	zfs_ace_t zace;
2653 	int verbose = FALSE;
2654 	uint64_t id;
2655 
2656 	if (!(flags & DCMD_ADDRSPEC))
2657 		return (DCMD_USAGE);
2658 
2659 	if (mdb_getopts(argc, argv,
2660 	    'v', MDB_OPT_SETBITS, TRUE, &verbose, TRUE, NULL) != argc)
2661 		return (DCMD_USAGE);
2662 
2663 	if (mdb_vread(&zace, sizeof (zfs_ace_t), addr) == -1) {
2664 		mdb_warn("failed to read zfs_ace_t");
2665 		return (DCMD_ERR);
2666 	}
2667 
2668 	if ((zace.z_hdr.z_flags & ACE_TYPE_FLAGS) == 0 ||
2669 	    (zace.z_hdr.z_flags & ACE_TYPE_FLAGS) == ACE_IDENTIFIER_GROUP)
2670 		id = zace.z_fuid;
2671 	else
2672 		id = -1;
2673 
2674 	return (zfs_ace_print_common(addr, flags, id, zace.z_hdr.z_access_mask,
2675 	    zace.z_hdr.z_flags, zace.z_hdr.z_type, verbose));
2676 }
2677 
2678 /* ARGSUSED */
2679 static int
2680 zfs_ace0_print(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
2681 {
2682 	ace_t ace;
2683 	uint64_t id;
2684 	int verbose = FALSE;
2685 
2686 	if (!(flags & DCMD_ADDRSPEC))
2687 		return (DCMD_USAGE);
2688 
2689 	if (mdb_getopts(argc, argv,
2690 	    'v', MDB_OPT_SETBITS, TRUE, &verbose, TRUE, NULL) != argc)
2691 		return (DCMD_USAGE);
2692 
2693 	if (mdb_vread(&ace, sizeof (ace_t), addr) == -1) {
2694 		mdb_warn("failed to read ace_t");
2695 		return (DCMD_ERR);
2696 	}
2697 
2698 	if ((ace.a_flags & ACE_TYPE_FLAGS) == 0 ||
2699 	    (ace.a_flags & ACE_TYPE_FLAGS) == ACE_IDENTIFIER_GROUP)
2700 		id = ace.a_who;
2701 	else
2702 		id = -1;
2703 
2704 	return (zfs_ace_print_common(addr, flags, id, ace.a_access_mask,
2705 	    ace.a_flags, ace.a_type, verbose));
2706 }
2707 
2708 typedef struct acl_dump_args {
2709 	int a_argc;
2710 	const mdb_arg_t *a_argv;
2711 	uint16_t a_version;
2712 	int a_flags;
2713 } acl_dump_args_t;
2714 
2715 /* ARGSUSED */
2716 static int
2717 acl_aces_cb(uintptr_t addr, const void *unknown, void *arg)
2718 {
2719 	acl_dump_args_t *acl_args = (acl_dump_args_t *)arg;
2720 
2721 	if (acl_args->a_version == 1) {
2722 		if (mdb_call_dcmd("zfs_ace", addr,
2723 		    DCMD_ADDRSPEC|acl_args->a_flags, acl_args->a_argc,
2724 		    acl_args->a_argv) != DCMD_OK) {
2725 			return (WALK_ERR);
2726 		}
2727 	} else {
2728 		if (mdb_call_dcmd("zfs_ace0", addr,
2729 		    DCMD_ADDRSPEC|acl_args->a_flags, acl_args->a_argc,
2730 		    acl_args->a_argv) != DCMD_OK) {
2731 			return (WALK_ERR);
2732 		}
2733 	}
2734 	acl_args->a_flags = DCMD_LOOP;
2735 	return (WALK_NEXT);
2736 }
2737 
2738 /* ARGSUSED */
2739 static int
2740 acl_cb(uintptr_t addr, const void *unknown, void *arg)
2741 {
2742 	acl_dump_args_t *acl_args = (acl_dump_args_t *)arg;
2743 
2744 	if (acl_args->a_version == 1) {
2745 		if (mdb_pwalk("zfs_acl_node_aces", acl_aces_cb,
2746 		    arg, addr) != 0) {
2747 			mdb_warn("can't walk ACEs");
2748 			return (DCMD_ERR);
2749 		}
2750 	} else {
2751 		if (mdb_pwalk("zfs_acl_node_aces0", acl_aces_cb,
2752 		    arg, addr) != 0) {
2753 			mdb_warn("can't walk ACEs");
2754 			return (DCMD_ERR);
2755 		}
2756 	}
2757 	return (WALK_NEXT);
2758 }
2759 
2760 /* ARGSUSED */
2761 static int
2762 zfs_acl_dump(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
2763 {
2764 	zfs_acl_t zacl;
2765 	int verbose = FALSE;
2766 	acl_dump_args_t acl_args;
2767 
2768 	if (!(flags & DCMD_ADDRSPEC))
2769 		return (DCMD_USAGE);
2770 
2771 	if (mdb_getopts(argc, argv,
2772 	    'v', MDB_OPT_SETBITS, TRUE, &verbose, TRUE, NULL) != argc)
2773 		return (DCMD_USAGE);
2774 
2775 	if (mdb_vread(&zacl, sizeof (zfs_acl_t), addr) == -1) {
2776 		mdb_warn("failed to read zfs_acl_t");
2777 		return (DCMD_ERR);
2778 	}
2779 
2780 	acl_args.a_argc = argc;
2781 	acl_args.a_argv = argv;
2782 	acl_args.a_version = zacl.z_version;
2783 	acl_args.a_flags = DCMD_LOOPFIRST;
2784 
2785 	if (mdb_pwalk("zfs_acl_node", acl_cb, &acl_args, addr) != 0) {
2786 		mdb_warn("can't walk ACL");
2787 		return (DCMD_ERR);
2788 	}
2789 
2790 	return (DCMD_OK);
2791 }
2792 
2793 /* ARGSUSED */
2794 static int
2795 zfs_acl_node_walk_init(mdb_walk_state_t *wsp)
2796 {
2797 	if (wsp->walk_addr == NULL) {
2798 		mdb_warn("must supply address of zfs_acl_node_t\n");
2799 		return (WALK_ERR);
2800 	}
2801 
2802 	wsp->walk_addr += OFFSETOF(zfs_acl_t, z_acl);
2803 
2804 	if (mdb_layered_walk("list", wsp) == -1) {
2805 		mdb_warn("failed to walk 'list'\n");
2806 		return (WALK_ERR);
2807 	}
2808 
2809 	return (WALK_NEXT);
2810 }
2811 
2812 static int
2813 zfs_acl_node_walk_step(mdb_walk_state_t *wsp)
2814 {
2815 	zfs_acl_node_t	aclnode;
2816 
2817 	if (mdb_vread(&aclnode, sizeof (zfs_acl_node_t),
2818 	    wsp->walk_addr) == -1) {
2819 		mdb_warn("failed to read zfs_acl_node at %p", wsp->walk_addr);
2820 		return (WALK_ERR);
2821 	}
2822 
2823 	return (wsp->walk_callback(wsp->walk_addr, &aclnode, wsp->walk_cbdata));
2824 }
2825 
2826 typedef struct ace_walk_data {
2827 	int		ace_count;
2828 	int		ace_version;
2829 } ace_walk_data_t;
2830 
2831 static int
2832 zfs_aces_walk_init_common(mdb_walk_state_t *wsp, int version,
2833     int ace_count, uintptr_t ace_data)
2834 {
2835 	ace_walk_data_t *ace_walk_data;
2836 
2837 	if (wsp->walk_addr == NULL) {
2838 		mdb_warn("must supply address of zfs_acl_node_t\n");
2839 		return (WALK_ERR);
2840 	}
2841 
2842 	ace_walk_data = mdb_alloc(sizeof (ace_walk_data_t), UM_SLEEP | UM_GC);
2843 
2844 	ace_walk_data->ace_count = ace_count;
2845 	ace_walk_data->ace_version = version;
2846 
2847 	wsp->walk_addr = ace_data;
2848 	wsp->walk_data = ace_walk_data;
2849 
2850 	return (WALK_NEXT);
2851 }
2852 
2853 static int
2854 zfs_acl_node_aces_walk_init_common(mdb_walk_state_t *wsp, int version)
2855 {
2856 	static int gotid;
2857 	static mdb_ctf_id_t acl_id;
2858 	int z_ace_count;
2859 	uintptr_t z_acldata;
2860 
2861 	if (!gotid) {
2862 		if (mdb_ctf_lookup_by_name("struct zfs_acl_node",
2863 		    &acl_id) == -1) {
2864 			mdb_warn("couldn't find struct zfs_acl_node");
2865 			return (DCMD_ERR);
2866 		}
2867 		gotid = TRUE;
2868 	}
2869 
2870 	if (GETMEMBID(wsp->walk_addr, &acl_id, z_ace_count, z_ace_count)) {
2871 		return (DCMD_ERR);
2872 	}
2873 	if (GETMEMBID(wsp->walk_addr, &acl_id, z_acldata, z_acldata)) {
2874 		return (DCMD_ERR);
2875 	}
2876 
2877 	return (zfs_aces_walk_init_common(wsp, version,
2878 	    z_ace_count, z_acldata));
2879 }
2880 
2881 /* ARGSUSED */
2882 static int
2883 zfs_acl_node_aces_walk_init(mdb_walk_state_t *wsp)
2884 {
2885 	return (zfs_acl_node_aces_walk_init_common(wsp, 1));
2886 }
2887 
2888 /* ARGSUSED */
2889 static int
2890 zfs_acl_node_aces0_walk_init(mdb_walk_state_t *wsp)
2891 {
2892 	return (zfs_acl_node_aces_walk_init_common(wsp, 0));
2893 }
2894 
2895 static int
2896 zfs_aces_walk_step(mdb_walk_state_t *wsp)
2897 {
2898 	ace_walk_data_t *ace_data = wsp->walk_data;
2899 	zfs_ace_t zace;
2900 	ace_t *acep;
2901 	int status;
2902 	int entry_type;
2903 	int allow_type;
2904 	uintptr_t ptr;
2905 
2906 	if (ace_data->ace_count == 0)
2907 		return (WALK_DONE);
2908 
2909 	if (mdb_vread(&zace, sizeof (zfs_ace_t), wsp->walk_addr) == -1) {
2910 		mdb_warn("failed to read zfs_ace_t at %#lx",
2911 		    wsp->walk_addr);
2912 		return (WALK_ERR);
2913 	}
2914 
2915 	switch (ace_data->ace_version) {
2916 	case 0:
2917 		acep = (ace_t *)&zace;
2918 		entry_type = acep->a_flags & ACE_TYPE_FLAGS;
2919 		allow_type = acep->a_type;
2920 		break;
2921 	case 1:
2922 		entry_type = zace.z_hdr.z_flags & ACE_TYPE_FLAGS;
2923 		allow_type = zace.z_hdr.z_type;
2924 		break;
2925 	default:
2926 		return (WALK_ERR);
2927 	}
2928 
2929 	ptr = (uintptr_t)wsp->walk_addr;
2930 	switch (entry_type) {
2931 	case ACE_OWNER:
2932 	case ACE_EVERYONE:
2933 	case (ACE_IDENTIFIER_GROUP | ACE_GROUP):
2934 		ptr += ace_data->ace_version == 0 ?
2935 		    sizeof (ace_t) : sizeof (zfs_ace_hdr_t);
2936 		break;
2937 	case ACE_IDENTIFIER_GROUP:
2938 	default:
2939 		switch (allow_type) {
2940 		case ACE_ACCESS_ALLOWED_OBJECT_ACE_TYPE:
2941 		case ACE_ACCESS_DENIED_OBJECT_ACE_TYPE:
2942 		case ACE_SYSTEM_AUDIT_OBJECT_ACE_TYPE:
2943 		case ACE_SYSTEM_ALARM_OBJECT_ACE_TYPE:
2944 			ptr += ace_data->ace_version == 0 ?
2945 			    sizeof (ace_t) : sizeof (zfs_object_ace_t);
2946 			break;
2947 		default:
2948 			ptr += ace_data->ace_version == 0 ?
2949 			    sizeof (ace_t) : sizeof (zfs_ace_t);
2950 			break;
2951 		}
2952 	}
2953 
2954 	ace_data->ace_count--;
2955 	status = wsp->walk_callback(wsp->walk_addr,
2956 	    (void *)(uintptr_t)&zace, wsp->walk_cbdata);
2957 
2958 	wsp->walk_addr = ptr;
2959 	return (status);
2960 }
2961 
2962 /*
2963  * MDB module linkage information:
2964  *
2965  * We declare a list of structures describing our dcmds, and a function
2966  * named _mdb_init to return a pointer to our module information.
2967  */
2968 
2969 static const mdb_dcmd_t dcmds[] = {
2970 	{ "arc", "[-bkmg]", "print ARC variables", arc_print },
2971 	{ "blkptr", ":", "print blkptr_t", blkptr },
2972 	{ "dbuf", ":", "print dmu_buf_impl_t", dbuf },
2973 	{ "dbuf_stats", ":", "dbuf stats", dbuf_stats },
2974 	{ "dbufs",
2975 	    "\t[-O objset_t*] [-n objset_name | \"mos\"] "
2976 	    "[-o object | \"mdn\"] \n"
2977 	    "\t[-l level] [-b blkid | \"bonus\"]",
2978 	    "find dmu_buf_impl_t's that match specified criteria", dbufs },
2979 	{ "abuf_find", "dva_word[0] dva_word[1]",
2980 	    "find arc_buf_hdr_t of a specified DVA",
2981 	    abuf_find },
2982 	{ "spa", "?[-cv]", "spa_t summary", spa_print },
2983 	{ "spa_config", ":", "print spa_t configuration", spa_print_config },
2984 	{ "spa_verify", ":", "verify spa_t consistency", spa_verify },
2985 	{ "spa_space", ":[-b]", "print spa_t on-disk space usage", spa_space },
2986 	{ "spa_vdevs", ":", "given a spa_t, print vdev summary", spa_vdevs },
2987 	{ "vdev", ":[-re]\n"
2988 	    "\t-r display recursively\n"
2989 	    "\t-e print statistics",
2990 	    "vdev_t summary", vdev_print },
2991 	{ "zio", ":[cpr]\n"
2992 	    "\t-c display children\n"
2993 	    "\t-p display parents\n"
2994 	    "\t-r display recursively",
2995 	    "zio_t summary", zio_print },
2996 	{ "zio_state", "?", "print out all zio_t structures on system or "
2997 	    "for a particular pool", zio_state },
2998 	{ "zfs_blkstats", ":[-v]",
2999 	    "given a spa_t, print block type stats from last scrub",
3000 	    zfs_blkstats },
3001 	{ "zfs_params", "", "print zfs tunable parameters", zfs_params },
3002 	{ "refcount", "", "print refcount_t holders", refcount },
3003 	{ "zap_leaf", "", "print zap_leaf_phys_t", zap_leaf },
3004 	{ "zfs_aces", ":[-v]", "print all ACEs from a zfs_acl_t",
3005 	    zfs_acl_dump },
3006 	{ "zfs_ace", ":[-v]", "print zfs_ace", zfs_ace_print },
3007 	{ "zfs_ace0", ":[-v]", "print zfs_ace0", zfs_ace0_print },
3008 	{ "sa_attr_table", ":", "print SA attribute table from sa_os_t",
3009 	    sa_attr_table},
3010 	{ "sa_attr", ": attr_id",
3011 	    "print SA attribute address when given sa_handle_t", sa_attr_print},
3012 	{ "zfs_dbgmsg", ":[-v]",
3013 	    "print zfs debug log", dbgmsg},
3014 	{ NULL }
3015 };
3016 
3017 static const mdb_walker_t walkers[] = {
3018 	{ "zms_freelist", "walk ZFS metaslab freelist",
3019 		freelist_walk_init, freelist_walk_step, NULL },
3020 	{ "txg_list", "given any txg_list_t *, walk all entries in all txgs",
3021 		txg_list_walk_init, txg_list_walk_step, NULL },
3022 	{ "txg_list0", "given any txg_list_t *, walk all entries in txg 0",
3023 		txg_list0_walk_init, txg_list_walk_step, NULL },
3024 	{ "txg_list1", "given any txg_list_t *, walk all entries in txg 1",
3025 		txg_list1_walk_init, txg_list_walk_step, NULL },
3026 	{ "txg_list2", "given any txg_list_t *, walk all entries in txg 2",
3027 		txg_list2_walk_init, txg_list_walk_step, NULL },
3028 	{ "txg_list3", "given any txg_list_t *, walk all entries in txg 3",
3029 		txg_list3_walk_init, txg_list_walk_step, NULL },
3030 	{ "zio", "walk all zio structures, optionally for a particular spa_t",
3031 		zio_walk_init, zio_walk_step, NULL },
3032 	{ "zio_root", "walk all root zio_t structures, optionally for a "
3033 	    "particular spa_t",
3034 		zio_walk_init, zio_walk_root_step, NULL },
3035 	{ "spa", "walk all spa_t entries in the namespace",
3036 		spa_walk_init, spa_walk_step, NULL },
3037 	{ "metaslab", "given a spa_t *, walk all metaslab_t structures",
3038 		metaslab_walk_init, metaslab_walk_step, NULL },
3039 	{ "zfs_acl_node", "given a zfs_acl_t, walk all zfs_acl_nodes",
3040 	    zfs_acl_node_walk_init, zfs_acl_node_walk_step, NULL },
3041 	{ "zfs_acl_node_aces", "given a zfs_acl_node_t, walk all ACEs",
3042 	    zfs_acl_node_aces_walk_init, zfs_aces_walk_step, NULL },
3043 	{ "zfs_acl_node_aces0",
3044 	    "given a zfs_acl_node_t, walk all ACEs as ace_t",
3045 	    zfs_acl_node_aces0_walk_init, zfs_aces_walk_step, NULL },
3046 	{ NULL }
3047 };
3048 
3049 static const mdb_modinfo_t modinfo = {
3050 	MDB_API_VERSION, dcmds, walkers
3051 };
3052 
3053 const mdb_modinfo_t *
3054 _mdb_init(void)
3055 {
3056 	return (&modinfo);
3057 }
3058