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