dmake: do not set MAKEFLAGS=k
[unleashed/tickless.git] / usr / src / cmd / mdb / common / modules / zfs / zfs.c
blobe908127068a3c8591b83ec8cb95e832b749659be
1 /*
2 * CDDL HEADER START
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.
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.
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]
19 * CDDL HEADER END
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) 2011, 2016 by Delphix. All rights reserved.
27 /* Portions Copyright 2010 Robert Milkowski */
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/vdev_impl.h>
40 #include <sys/zap_leaf.h>
41 #include <sys/zap_impl.h>
42 #include <ctype.h>
43 #include <sys/zfs_acl.h>
44 #include <sys/sa_impl.h>
45 #include <sys/multilist.h>
47 #ifdef _KERNEL
48 #define ZFS_OBJ_NAME "zfs"
49 extern int64_t mdb_gethrtime(void);
50 #else
51 #define ZFS_OBJ_NAME "libzpool.so.1"
52 #endif
54 #define ZFS_STRUCT "struct " ZFS_OBJ_NAME "`"
56 #ifndef _KERNEL
57 int aok;
58 #endif
60 enum spa_flags {
61 SPA_FLAG_CONFIG = 1 << 0,
62 SPA_FLAG_VDEVS = 1 << 1,
63 SPA_FLAG_ERRORS = 1 << 2,
64 SPA_FLAG_METASLAB_GROUPS = 1 << 3,
65 SPA_FLAG_METASLABS = 1 << 4,
66 SPA_FLAG_HISTOGRAMS = 1 << 5
70 * If any of these flags are set, call spa_vdevs in spa_print
72 #define SPA_FLAG_ALL_VDEV \
73 (SPA_FLAG_VDEVS | SPA_FLAG_ERRORS | SPA_FLAG_METASLAB_GROUPS | \
74 SPA_FLAG_METASLABS)
76 static int
77 getmember(uintptr_t addr, const char *type, mdb_ctf_id_t *idp,
78 const char *member, int len, void *buf)
80 mdb_ctf_id_t id;
81 ulong_t off;
82 char name[64];
84 if (idp == NULL) {
85 if (mdb_ctf_lookup_by_name(type, &id) == -1) {
86 mdb_warn("couldn't find type %s", type);
87 return (DCMD_ERR);
89 idp = &id;
90 } else {
91 type = name;
92 mdb_ctf_type_name(*idp, name, sizeof (name));
95 if (mdb_ctf_offsetof(*idp, member, &off) == -1) {
96 mdb_warn("couldn't find member %s of type %s\n", member, type);
97 return (DCMD_ERR);
99 if (off % 8 != 0) {
100 mdb_warn("member %s of type %s is unsupported bitfield",
101 member, type);
102 return (DCMD_ERR);
104 off /= 8;
106 if (mdb_vread(buf, len, addr + off) == -1) {
107 mdb_warn("failed to read %s from %s at %p",
108 member, type, addr + off);
109 return (DCMD_ERR);
111 /* mdb_warn("read %s from %s at %p+%llx\n", member, type, addr, off); */
113 return (0);
116 #define GETMEMB(addr, structname, member, dest) \
117 getmember(addr, ZFS_STRUCT structname, NULL, #member, \
118 sizeof (dest), &(dest))
120 #define GETMEMBID(addr, ctfid, member, dest) \
121 getmember(addr, NULL, ctfid, #member, sizeof (dest), &(dest))
123 static boolean_t
124 strisprint(const char *cp)
126 for (; *cp; cp++) {
127 if (!isprint(*cp))
128 return (B_FALSE);
130 return (B_TRUE);
133 #define NICENUM_BUFLEN 6
135 static int
136 snprintfrac(char *buf, int len,
137 uint64_t numerator, uint64_t denom, int frac_digits)
139 int mul = 1;
140 int whole, frac, i;
142 for (i = frac_digits; i; i--)
143 mul *= 10;
144 whole = numerator / denom;
145 frac = mul * numerator / denom - mul * whole;
146 return (mdb_snprintf(buf, len, "%u.%0*u", whole, frac_digits, frac));
149 static void
150 mdb_nicenum(uint64_t num, char *buf)
152 uint64_t n = num;
153 int index = 0;
154 char *u;
156 while (n >= 1024) {
157 n = (n + (1024 / 2)) / 1024; /* Round up or down */
158 index++;
161 u = &" \0K\0M\0G\0T\0P\0E\0"[index*2];
163 if (index == 0) {
164 (void) mdb_snprintf(buf, NICENUM_BUFLEN, "%llu",
165 (u_longlong_t)n);
166 } else if (n < 10 && (num & (num - 1)) != 0) {
167 (void) snprintfrac(buf, NICENUM_BUFLEN,
168 num, 1ULL << 10 * index, 2);
169 strcat(buf, u);
170 } else if (n < 100 && (num & (num - 1)) != 0) {
171 (void) snprintfrac(buf, NICENUM_BUFLEN,
172 num, 1ULL << 10 * index, 1);
173 strcat(buf, u);
174 } else {
175 (void) mdb_snprintf(buf, NICENUM_BUFLEN, "%llu%s",
176 (u_longlong_t)n, u);
180 static int verbose;
182 static int
183 freelist_walk_init(mdb_walk_state_t *wsp)
185 if (wsp->walk_addr == (uintptr_t)NULL) {
186 mdb_warn("must supply starting address\n");
187 return (WALK_ERR);
190 wsp->walk_data = 0; /* Index into the freelist */
191 return (WALK_NEXT);
194 static int
195 freelist_walk_step(mdb_walk_state_t *wsp)
197 uint64_t entry;
198 uintptr_t number = (uintptr_t)wsp->walk_data;
199 char *ddata[] = { "ALLOC", "FREE", "CONDENSE", "INVALID",
200 "INVALID", "INVALID", "INVALID", "INVALID" };
201 int mapshift = SPA_MINBLOCKSHIFT;
203 if (mdb_vread(&entry, sizeof (entry), wsp->walk_addr) == -1) {
204 mdb_warn("failed to read freelist entry %p", wsp->walk_addr);
205 return (WALK_DONE);
207 wsp->walk_addr += sizeof (entry);
208 wsp->walk_data = (void *)(number + 1);
210 if (SM_DEBUG_DECODE(entry)) {
211 mdb_printf("DEBUG: %3u %10s: txg=%llu pass=%llu\n",
212 number,
213 ddata[SM_DEBUG_ACTION_DECODE(entry)],
214 SM_DEBUG_TXG_DECODE(entry),
215 SM_DEBUG_SYNCPASS_DECODE(entry));
216 } else {
217 mdb_printf("Entry: %3u offsets=%08llx-%08llx type=%c "
218 "size=%06llx", number,
219 SM_OFFSET_DECODE(entry) << mapshift,
220 (SM_OFFSET_DECODE(entry) + SM_RUN_DECODE(entry)) <<
221 mapshift,
222 SM_TYPE_DECODE(entry) == SM_ALLOC ? 'A' : 'F',
223 SM_RUN_DECODE(entry) << mapshift);
224 if (verbose)
225 mdb_printf(" (raw=%012llx)\n", entry);
226 mdb_printf("\n");
228 return (WALK_NEXT);
231 static int
232 mdb_dsl_dir_name(uintptr_t addr, char *buf)
234 static int gotid;
235 static mdb_ctf_id_t dd_id;
236 uintptr_t dd_parent;
237 char dd_myname[ZFS_MAX_DATASET_NAME_LEN];
239 if (!gotid) {
240 if (mdb_ctf_lookup_by_name(ZFS_STRUCT "dsl_dir",
241 &dd_id) == -1) {
242 mdb_warn("couldn't find struct dsl_dir");
243 return (DCMD_ERR);
245 gotid = TRUE;
247 if (GETMEMBID(addr, &dd_id, dd_parent, dd_parent) ||
248 GETMEMBID(addr, &dd_id, dd_myname, dd_myname)) {
249 return (DCMD_ERR);
252 if (dd_parent) {
253 if (mdb_dsl_dir_name(dd_parent, buf))
254 return (DCMD_ERR);
255 strcat(buf, "/");
258 if (dd_myname[0])
259 strcat(buf, dd_myname);
260 else
261 strcat(buf, "???");
263 return (0);
266 static int
267 objset_name(uintptr_t addr, char *buf)
269 static int gotid;
270 static mdb_ctf_id_t os_id, ds_id;
271 uintptr_t os_dsl_dataset;
272 char ds_snapname[ZFS_MAX_DATASET_NAME_LEN];
273 uintptr_t ds_dir;
275 buf[0] = '\0';
277 if (!gotid) {
278 if (mdb_ctf_lookup_by_name(ZFS_STRUCT "objset",
279 &os_id) == -1) {
280 mdb_warn("couldn't find struct objset");
281 return (DCMD_ERR);
283 if (mdb_ctf_lookup_by_name(ZFS_STRUCT "dsl_dataset",
284 &ds_id) == -1) {
285 mdb_warn("couldn't find struct dsl_dataset");
286 return (DCMD_ERR);
289 gotid = TRUE;
292 if (GETMEMBID(addr, &os_id, os_dsl_dataset, os_dsl_dataset))
293 return (DCMD_ERR);
295 if (os_dsl_dataset == 0) {
296 strcat(buf, "mos");
297 return (0);
300 if (GETMEMBID(os_dsl_dataset, &ds_id, ds_snapname, ds_snapname) ||
301 GETMEMBID(os_dsl_dataset, &ds_id, ds_dir, ds_dir)) {
302 return (DCMD_ERR);
305 if (ds_dir && mdb_dsl_dir_name(ds_dir, buf))
306 return (DCMD_ERR);
308 if (ds_snapname[0]) {
309 strcat(buf, "@");
310 strcat(buf, ds_snapname);
312 return (0);
315 static int
316 enum_lookup(char *type, int val, const char *prefix, size_t size, char *out)
318 const char *cp;
319 size_t len = strlen(prefix);
320 mdb_ctf_id_t enum_type;
322 if (mdb_ctf_lookup_by_name(type, &enum_type) != 0) {
323 mdb_warn("Could not find enum for %s", type);
324 return (-1);
327 if ((cp = mdb_ctf_enum_name(enum_type, val)) != NULL) {
328 if (strncmp(cp, prefix, len) == 0)
329 cp += len;
330 (void) strncpy(out, cp, size);
331 } else {
332 mdb_snprintf(out, size, "? (%d)", val);
334 return (0);
337 /* ARGSUSED */
338 static int
339 zfs_params(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
342 * This table can be approximately generated by running:
343 * egrep "^[a-z0-9_]+ [a-z0-9_]+( =.*)?;" *.c | cut -d ' ' -f 2
345 static const char *params[] = {
346 "arc_reduce_dnlc_percent",
347 "arc_lotsfree_percent",
348 "zfs_dirty_data_max",
349 "zfs_dirty_data_sync",
350 "zfs_delay_max_ns",
351 "zfs_delay_min_dirty_percent",
352 "zfs_delay_scale",
353 "zfs_vdev_max_active",
354 "zfs_vdev_sync_read_min_active",
355 "zfs_vdev_sync_read_max_active",
356 "zfs_vdev_sync_write_min_active",
357 "zfs_vdev_sync_write_max_active",
358 "zfs_vdev_async_read_min_active",
359 "zfs_vdev_async_read_max_active",
360 "zfs_vdev_async_write_min_active",
361 "zfs_vdev_async_write_max_active",
362 "zfs_vdev_scrub_min_active",
363 "zfs_vdev_scrub_max_active",
364 "zfs_vdev_async_write_active_min_dirty_percent",
365 "zfs_vdev_async_write_active_max_dirty_percent",
366 "spa_asize_inflation",
367 "zfs_arc_max",
368 "zfs_arc_min",
369 "arc_shrink_shift",
370 "zfs_mdcomp_disable",
371 "zfs_prefetch_disable",
372 "zfetch_max_streams",
373 "zfetch_min_sec_reap",
374 "zfetch_block_cap",
375 "zfetch_array_rd_sz",
376 "zfs_default_bs",
377 "zfs_default_ibs",
378 "metaslab_aliquot",
379 "reference_tracking_enable",
380 "reference_history",
381 "spa_max_replication_override",
382 "spa_mode_global",
383 "zfs_flags",
384 "zfs_txg_timeout",
385 "zfs_vdev_cache_max",
386 "zfs_vdev_cache_size",
387 "zfs_vdev_cache_bshift",
388 "vdev_mirror_shift",
389 "zfs_scrub_limit",
390 "zfs_no_scrub_io",
391 "zfs_no_scrub_prefetch",
392 "zfs_vdev_aggregation_limit",
393 "fzap_default_block_shift",
394 "zfs_immediate_write_sz",
395 "zfs_read_chunk_size",
396 "zfs_nocacheflush",
397 "zil_replay_disable",
398 "metaslab_gang_bang",
399 "metaslab_df_alloc_threshold",
400 "metaslab_df_free_pct",
401 "zio_injection_enabled",
402 "zvol_immediate_write_sz",
405 for (int i = 0; i < sizeof (params) / sizeof (params[0]); i++) {
406 int sz;
407 uint64_t val64;
408 uint32_t *val32p = (uint32_t *)&val64;
410 sz = mdb_readvar(&val64, params[i]);
411 if (sz == 4) {
412 mdb_printf("%s = 0x%x\n", params[i], *val32p);
413 } else if (sz == 8) {
414 mdb_printf("%s = 0x%llx\n", params[i], val64);
415 } else {
416 mdb_warn("variable %s not found", params[i]);
420 return (DCMD_OK);
423 /* ARGSUSED */
424 static int
425 blkptr(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
427 char type[80], checksum[80], compress[80];
428 blkptr_t blk, *bp = &blk;
429 char buf[BP_SPRINTF_LEN];
431 if (mdb_vread(&blk, sizeof (blkptr_t), addr) == -1) {
432 mdb_warn("failed to read blkptr_t");
433 return (DCMD_ERR);
436 if (enum_lookup("enum dmu_object_type", BP_GET_TYPE(bp), "DMU_OT_",
437 sizeof (type), type) == -1 ||
438 enum_lookup("enum zio_checksum", BP_GET_CHECKSUM(bp),
439 "ZIO_CHECKSUM_", sizeof (checksum), checksum) == -1 ||
440 enum_lookup("enum zio_compress", BP_GET_COMPRESS(bp),
441 "ZIO_COMPRESS_", sizeof (compress), compress) == -1) {
442 mdb_warn("Could not find blkptr enumerated types");
443 return (DCMD_ERR);
446 SNPRINTF_BLKPTR(mdb_snprintf, '\n', buf, sizeof (buf), bp, type,
447 checksum, compress);
449 mdb_printf("%s\n", buf);
451 return (DCMD_OK);
454 typedef struct mdb_dmu_buf_impl {
455 struct {
456 uint64_t db_object;
457 uintptr_t db_data;
458 } db;
459 uintptr_t db_objset;
460 uint64_t db_level;
461 uint64_t db_blkid;
462 struct {
463 uint64_t rc_count;
464 } db_holds;
465 } mdb_dmu_buf_impl_t;
467 /* ARGSUSED */
468 static int
469 dbuf(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
471 mdb_dmu_buf_impl_t db;
472 char objectname[32];
473 char blkidname[32];
474 char path[ZFS_MAX_DATASET_NAME_LEN];
475 int ptr_width = (int)(sizeof (void *)) * 2;
477 if (DCMD_HDRSPEC(flags))
478 mdb_printf("%*s %8s %3s %9s %5s %s\n",
479 ptr_width, "addr", "object", "lvl", "blkid", "holds", "os");
481 if (mdb_ctf_vread(&db, ZFS_STRUCT "dmu_buf_impl", "mdb_dmu_buf_impl_t",
482 addr, 0) == -1)
483 return (DCMD_ERR);
485 if (db.db.db_object == DMU_META_DNODE_OBJECT)
486 (void) strcpy(objectname, "mdn");
487 else
488 (void) mdb_snprintf(objectname, sizeof (objectname), "%llx",
489 (u_longlong_t)db.db.db_object);
491 if (db.db_blkid == DMU_BONUS_BLKID)
492 (void) strcpy(blkidname, "bonus");
493 else
494 (void) mdb_snprintf(blkidname, sizeof (blkidname), "%llx",
495 (u_longlong_t)db.db_blkid);
497 if (objset_name(db.db_objset, path)) {
498 return (DCMD_ERR);
501 mdb_printf("%*p %8s %3u %9s %5llu %s\n", ptr_width, addr,
502 objectname, (int)db.db_level, blkidname,
503 db.db_holds.rc_count, path);
505 return (DCMD_OK);
508 /* ARGSUSED */
509 static int
510 dbuf_stats(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
512 #define HISTOSZ 32
513 uintptr_t dbp;
514 dmu_buf_impl_t db;
515 dbuf_hash_table_t ht;
516 uint64_t bucket, ndbufs;
517 uint64_t histo[HISTOSZ];
518 uint64_t histo2[HISTOSZ];
519 int i, maxidx;
521 if (mdb_readvar(&ht, "dbuf_hash_table") == -1) {
522 mdb_warn("failed to read 'dbuf_hash_table'");
523 return (DCMD_ERR);
526 for (i = 0; i < HISTOSZ; i++) {
527 histo[i] = 0;
528 histo2[i] = 0;
531 ndbufs = 0;
532 for (bucket = 0; bucket < ht.hash_table_mask+1; bucket++) {
533 int len;
535 if (mdb_vread(&dbp, sizeof (void *),
536 (uintptr_t)(ht.hash_table+bucket)) == -1) {
537 mdb_warn("failed to read hash bucket %u at %p",
538 bucket, ht.hash_table+bucket);
539 return (DCMD_ERR);
542 len = 0;
543 while (dbp != 0) {
544 if (mdb_vread(&db, sizeof (dmu_buf_impl_t),
545 dbp) == -1) {
546 mdb_warn("failed to read dbuf at %p", dbp);
547 return (DCMD_ERR);
549 dbp = (uintptr_t)db.db_hash_next;
550 for (i = MIN(len, HISTOSZ - 1); i >= 0; i--)
551 histo2[i]++;
552 len++;
553 ndbufs++;
556 if (len >= HISTOSZ)
557 len = HISTOSZ-1;
558 histo[len]++;
561 mdb_printf("hash table has %llu buckets, %llu dbufs "
562 "(avg %llu buckets/dbuf)\n",
563 ht.hash_table_mask+1, ndbufs,
564 (ht.hash_table_mask+1)/ndbufs);
566 mdb_printf("\n");
567 maxidx = 0;
568 for (i = 0; i < HISTOSZ; i++)
569 if (histo[i] > 0)
570 maxidx = i;
571 mdb_printf("hash chain length number of buckets\n");
572 for (i = 0; i <= maxidx; i++)
573 mdb_printf("%u %llu\n", i, histo[i]);
575 mdb_printf("\n");
576 maxidx = 0;
577 for (i = 0; i < HISTOSZ; i++)
578 if (histo2[i] > 0)
579 maxidx = i;
580 mdb_printf("hash chain depth number of dbufs\n");
581 for (i = 0; i <= maxidx; i++)
582 mdb_printf("%u or more %llu %llu%%\n",
583 i, histo2[i], histo2[i]*100/ndbufs);
586 return (DCMD_OK);
589 #define CHAIN_END 0xffff
591 * ::zap_leaf [-v]
593 * Print a zap_leaf_phys_t, assumed to be 16k
595 /* ARGSUSED */
596 static int
597 zap_leaf(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
599 char buf[16*1024];
600 int verbose = B_FALSE;
601 int four = B_FALSE;
602 dmu_buf_t l_dbuf;
603 zap_leaf_t l;
604 zap_leaf_phys_t *zlp = (void *)buf;
605 int i;
607 if (mdb_getopts(argc, argv,
608 'v', MDB_OPT_SETBITS, TRUE, &verbose,
609 '4', MDB_OPT_SETBITS, TRUE, &four,
610 NULL) != argc)
611 return (DCMD_USAGE);
613 l_dbuf.db_data = zlp;
614 l.l_dbuf = &l_dbuf;
615 l.l_bs = 14; /* assume 16k blocks */
616 if (four)
617 l.l_bs = 12;
619 if (!(flags & DCMD_ADDRSPEC)) {
620 return (DCMD_USAGE);
623 if (mdb_vread(buf, sizeof (buf), addr) == -1) {
624 mdb_warn("failed to read zap_leaf_phys_t at %p", addr);
625 return (DCMD_ERR);
628 if (zlp->l_hdr.lh_block_type != ZBT_LEAF ||
629 zlp->l_hdr.lh_magic != ZAP_LEAF_MAGIC) {
630 mdb_warn("This does not appear to be a zap_leaf_phys_t");
631 return (DCMD_ERR);
634 mdb_printf("zap_leaf_phys_t at %p:\n", addr);
635 mdb_printf(" lh_prefix_len = %u\n", zlp->l_hdr.lh_prefix_len);
636 mdb_printf(" lh_prefix = %llx\n", zlp->l_hdr.lh_prefix);
637 mdb_printf(" lh_nentries = %u\n", zlp->l_hdr.lh_nentries);
638 mdb_printf(" lh_nfree = %u\n", zlp->l_hdr.lh_nfree,
639 zlp->l_hdr.lh_nfree * 100 / (ZAP_LEAF_NUMCHUNKS(&l)));
640 mdb_printf(" lh_freelist = %u\n", zlp->l_hdr.lh_freelist);
641 mdb_printf(" lh_flags = %x (%s)\n", zlp->l_hdr.lh_flags,
642 zlp->l_hdr.lh_flags & ZLF_ENTRIES_CDSORTED ?
643 "ENTRIES_CDSORTED" : "");
645 if (verbose) {
646 mdb_printf(" hash table:\n");
647 for (i = 0; i < ZAP_LEAF_HASH_NUMENTRIES(&l); i++) {
648 if (zlp->l_hash[i] != CHAIN_END)
649 mdb_printf(" %u: %u\n", i, zlp->l_hash[i]);
653 mdb_printf(" chunks:\n");
654 for (i = 0; i < ZAP_LEAF_NUMCHUNKS(&l); i++) {
655 /* LINTED: alignment */
656 zap_leaf_chunk_t *zlc = &ZAP_LEAF_CHUNK(&l, i);
657 switch (zlc->l_entry.le_type) {
658 case ZAP_CHUNK_FREE:
659 if (verbose) {
660 mdb_printf(" %u: free; lf_next = %u\n",
661 i, zlc->l_free.lf_next);
663 break;
664 case ZAP_CHUNK_ENTRY:
665 mdb_printf(" %u: entry\n", i);
666 if (verbose) {
667 mdb_printf(" le_next = %u\n",
668 zlc->l_entry.le_next);
670 mdb_printf(" le_name_chunk = %u\n",
671 zlc->l_entry.le_name_chunk);
672 mdb_printf(" le_name_numints = %u\n",
673 zlc->l_entry.le_name_numints);
674 mdb_printf(" le_value_chunk = %u\n",
675 zlc->l_entry.le_value_chunk);
676 mdb_printf(" le_value_intlen = %u\n",
677 zlc->l_entry.le_value_intlen);
678 mdb_printf(" le_value_numints = %u\n",
679 zlc->l_entry.le_value_numints);
680 mdb_printf(" le_cd = %u\n",
681 zlc->l_entry.le_cd);
682 mdb_printf(" le_hash = %llx\n",
683 zlc->l_entry.le_hash);
684 break;
685 case ZAP_CHUNK_ARRAY:
686 mdb_printf(" %u: array", i);
687 if (strisprint((char *)zlc->l_array.la_array))
688 mdb_printf(" \"%s\"", zlc->l_array.la_array);
689 mdb_printf("\n");
690 if (verbose) {
691 int j;
692 mdb_printf(" ");
693 for (j = 0; j < ZAP_LEAF_ARRAY_BYTES; j++) {
694 mdb_printf("%02x ",
695 zlc->l_array.la_array[j]);
697 mdb_printf("\n");
699 if (zlc->l_array.la_next != CHAIN_END) {
700 mdb_printf(" lf_next = %u\n",
701 zlc->l_array.la_next);
703 break;
704 default:
705 mdb_printf(" %u: undefined type %u\n",
706 zlc->l_entry.le_type);
710 return (DCMD_OK);
713 typedef struct dbufs_data {
714 mdb_ctf_id_t id;
715 uint64_t objset;
716 uint64_t object;
717 uint64_t level;
718 uint64_t blkid;
719 char *osname;
720 } dbufs_data_t;
722 #define DBUFS_UNSET (0xbaddcafedeadbeefULL)
724 /* ARGSUSED */
725 static int
726 dbufs_cb(uintptr_t addr, const void *unknown, void *arg)
728 dbufs_data_t *data = arg;
729 uintptr_t objset;
730 dmu_buf_t db;
731 uint8_t level;
732 uint64_t blkid;
733 char osname[ZFS_MAX_DATASET_NAME_LEN];
735 if (GETMEMBID(addr, &data->id, db_objset, objset) ||
736 GETMEMBID(addr, &data->id, db, db) ||
737 GETMEMBID(addr, &data->id, db_level, level) ||
738 GETMEMBID(addr, &data->id, db_blkid, blkid)) {
739 return (WALK_ERR);
742 if ((data->objset == DBUFS_UNSET || data->objset == objset) &&
743 (data->osname == NULL || (objset_name(objset, osname) == 0 &&
744 strcmp(data->osname, osname) == 0)) &&
745 (data->object == DBUFS_UNSET || data->object == db.db_object) &&
746 (data->level == DBUFS_UNSET || data->level == level) &&
747 (data->blkid == DBUFS_UNSET || data->blkid == blkid)) {
748 mdb_printf("%#lr\n", addr);
750 return (WALK_NEXT);
753 /* ARGSUSED */
754 static int
755 dbufs(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
757 dbufs_data_t data;
758 char *object = NULL;
759 char *blkid = NULL;
761 data.objset = data.object = data.level = data.blkid = DBUFS_UNSET;
762 data.osname = NULL;
764 if (mdb_getopts(argc, argv,
765 'O', MDB_OPT_UINT64, &data.objset,
766 'n', MDB_OPT_STR, &data.osname,
767 'o', MDB_OPT_STR, &object,
768 'l', MDB_OPT_UINT64, &data.level,
769 'b', MDB_OPT_STR, &blkid) != argc) {
770 return (DCMD_USAGE);
773 if (object) {
774 if (strcmp(object, "mdn") == 0) {
775 data.object = DMU_META_DNODE_OBJECT;
776 } else {
777 data.object = mdb_strtoull(object);
781 if (blkid) {
782 if (strcmp(blkid, "bonus") == 0) {
783 data.blkid = DMU_BONUS_BLKID;
784 } else {
785 data.blkid = mdb_strtoull(blkid);
789 if (mdb_ctf_lookup_by_name(ZFS_STRUCT "dmu_buf_impl", &data.id) == -1) {
790 mdb_warn("couldn't find struct dmu_buf_impl_t");
791 return (DCMD_ERR);
794 if (mdb_walk("dmu_buf_impl_t", dbufs_cb, &data) != 0) {
795 mdb_warn("can't walk dbufs");
796 return (DCMD_ERR);
799 return (DCMD_OK);
802 typedef struct abuf_find_data {
803 dva_t dva;
804 mdb_ctf_id_t id;
805 } abuf_find_data_t;
807 /* ARGSUSED */
808 static int
809 abuf_find_cb(uintptr_t addr, const void *unknown, void *arg)
811 abuf_find_data_t *data = arg;
812 dva_t dva;
814 if (GETMEMBID(addr, &data->id, b_dva, dva)) {
815 return (WALK_ERR);
818 if (dva.dva_word[0] == data->dva.dva_word[0] &&
819 dva.dva_word[1] == data->dva.dva_word[1]) {
820 mdb_printf("%#lr\n", addr);
822 return (WALK_NEXT);
825 /* ARGSUSED */
826 static int
827 abuf_find(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
829 abuf_find_data_t data;
830 GElf_Sym sym;
831 int i;
832 const char *syms[] = {
833 "ARC_mru",
834 "ARC_mru_ghost",
835 "ARC_mfu",
836 "ARC_mfu_ghost",
839 if (argc != 2)
840 return (DCMD_USAGE);
842 for (i = 0; i < 2; i ++) {
843 switch (argv[i].a_type) {
844 case MDB_TYPE_STRING:
845 data.dva.dva_word[i] = mdb_strtoull(argv[i].a_un.a_str);
846 break;
847 case MDB_TYPE_IMMEDIATE:
848 data.dva.dva_word[i] = argv[i].a_un.a_val;
849 break;
850 default:
851 return (DCMD_USAGE);
855 if (mdb_ctf_lookup_by_name(ZFS_STRUCT "arc_buf_hdr", &data.id) == -1) {
856 mdb_warn("couldn't find struct arc_buf_hdr");
857 return (DCMD_ERR);
860 for (i = 0; i < sizeof (syms) / sizeof (syms[0]); i++) {
861 if (mdb_lookup_by_obj(ZFS_OBJ_NAME, syms[i], &sym)) {
862 mdb_warn("can't find symbol %s", syms[i]);
863 return (DCMD_ERR);
866 if (mdb_pwalk("list", abuf_find_cb, &data, sym.st_value) != 0) {
867 mdb_warn("can't walk %s", syms[i]);
868 return (DCMD_ERR);
872 return (DCMD_OK);
876 typedef struct dbgmsg_arg {
877 boolean_t da_verbose;
878 boolean_t da_address;
879 } dbgmsg_arg_t;
881 /* ARGSUSED */
882 static int
883 dbgmsg_cb(uintptr_t addr, const void *unknown, void *arg)
885 static mdb_ctf_id_t id;
886 static boolean_t gotid;
887 static ulong_t off;
889 dbgmsg_arg_t *da = arg;
890 time_t timestamp;
891 char buf[1024];
893 if (!gotid) {
894 if (mdb_ctf_lookup_by_name(ZFS_STRUCT "zfs_dbgmsg", &id) ==
895 -1) {
896 mdb_warn("couldn't find struct zfs_dbgmsg");
897 return (WALK_ERR);
899 gotid = TRUE;
900 if (mdb_ctf_offsetof(id, "zdm_msg", &off) == -1) {
901 mdb_warn("couldn't find zdm_msg");
902 return (WALK_ERR);
904 off /= 8;
908 if (GETMEMBID(addr, &id, zdm_timestamp, timestamp)) {
909 return (WALK_ERR);
912 if (mdb_readstr(buf, sizeof (buf), addr + off) == -1) {
913 mdb_warn("failed to read zdm_msg at %p\n", addr + off);
914 return (DCMD_ERR);
917 if (da->da_address)
918 mdb_printf("%p ", addr);
919 if (da->da_verbose)
920 mdb_printf("%Y ", timestamp);
922 mdb_printf("%s\n", buf);
924 if (da->da_verbose)
925 (void) mdb_call_dcmd("whatis", addr, DCMD_ADDRSPEC, 0, NULL);
927 return (WALK_NEXT);
930 /* ARGSUSED */
931 static int
932 dbgmsg(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
934 GElf_Sym sym;
935 dbgmsg_arg_t da = { 0 };
937 if (mdb_getopts(argc, argv,
938 'v', MDB_OPT_SETBITS, B_TRUE, &da.da_verbose,
939 'a', MDB_OPT_SETBITS, B_TRUE, &da.da_address,
940 NULL) != argc)
941 return (DCMD_USAGE);
943 if (mdb_lookup_by_obj(ZFS_OBJ_NAME, "zfs_dbgmsgs", &sym)) {
944 mdb_warn("can't find zfs_dbgmsgs");
945 return (DCMD_ERR);
948 if (mdb_pwalk("list", dbgmsg_cb, &da, sym.st_value) != 0) {
949 mdb_warn("can't walk zfs_dbgmsgs");
950 return (DCMD_ERR);
953 return (DCMD_OK);
956 /*ARGSUSED*/
957 static int
958 arc_print(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
960 kstat_named_t *stats;
961 GElf_Sym sym;
962 int nstats, i;
963 uint_t opt_a = FALSE;
964 uint_t opt_b = FALSE;
965 uint_t shift = 0;
966 const char *suffix;
968 static const char *bytestats[] = {
969 "p", "c", "c_min", "c_max", "size", "duplicate_buffers_size",
970 "arc_meta_used", "arc_meta_limit", "arc_meta_max",
971 "arc_meta_min", "hdr_size", "data_size", "metadata_size",
972 "other_size", "anon_size", "anon_evictable_data",
973 "anon_evictable_metadata", "mru_size", "mru_evictable_data",
974 "mru_evictable_metadata", "mru_ghost_size",
975 "mru_ghost_evictable_data", "mru_ghost_evictable_metadata",
976 "mfu_size", "mfu_evictable_data", "mfu_evictable_metadata",
977 "mfu_ghost_size", "mfu_ghost_evictable_data",
978 "mfu_ghost_evictable_metadata", "evict_l2_cached",
979 "evict_l2_eligible", "evict_l2_ineligible", "l2_read_bytes",
980 "l2_write_bytes", "l2_size", "l2_asize", "l2_hdr_size",
981 "compressed_size", "uncompressed_size", "overhead_size",
982 NULL
985 static const char *extras[] = {
986 "arc_no_grow", "arc_tempreserve",
987 NULL
990 if (mdb_lookup_by_obj(ZFS_OBJ_NAME, "arc_stats", &sym) == -1) {
991 mdb_warn("failed to find 'arc_stats'");
992 return (DCMD_ERR);
995 stats = mdb_zalloc(sym.st_size, UM_SLEEP | UM_GC);
997 if (mdb_vread(stats, sym.st_size, sym.st_value) == -1) {
998 mdb_warn("couldn't read 'arc_stats' at %p", sym.st_value);
999 return (DCMD_ERR);
1002 nstats = sym.st_size / sizeof (kstat_named_t);
1004 /* NB: -a / opt_a are ignored for backwards compatability */
1005 if (mdb_getopts(argc, argv,
1006 'a', MDB_OPT_SETBITS, TRUE, &opt_a,
1007 'b', MDB_OPT_SETBITS, TRUE, &opt_b,
1008 'k', MDB_OPT_SETBITS, 10, &shift,
1009 'm', MDB_OPT_SETBITS, 20, &shift,
1010 'g', MDB_OPT_SETBITS, 30, &shift,
1011 NULL) != argc)
1012 return (DCMD_USAGE);
1014 if (!opt_b && !shift)
1015 shift = 20;
1017 switch (shift) {
1018 case 0:
1019 suffix = "B";
1020 break;
1021 case 10:
1022 suffix = "KB";
1023 break;
1024 case 20:
1025 suffix = "MB";
1026 break;
1027 case 30:
1028 suffix = "GB";
1029 break;
1030 default:
1031 suffix = "XX";
1034 for (i = 0; i < nstats; i++) {
1035 int j;
1036 boolean_t bytes = B_FALSE;
1038 for (j = 0; bytestats[j]; j++) {
1039 if (strcmp(stats[i].name, bytestats[j]) == 0) {
1040 bytes = B_TRUE;
1041 break;
1045 if (bytes) {
1046 mdb_printf("%-25s = %9llu %s\n", stats[i].name,
1047 stats[i].value.ui64 >> shift, suffix);
1048 } else {
1049 mdb_printf("%-25s = %9llu\n", stats[i].name,
1050 stats[i].value.ui64);
1054 for (i = 0; extras[i]; i++) {
1055 uint64_t buf;
1057 if (mdb_lookup_by_obj(ZFS_OBJ_NAME, extras[i], &sym) == -1) {
1058 mdb_warn("failed to find '%s'", extras[i]);
1059 return (DCMD_ERR);
1062 if (sym.st_size != sizeof (uint64_t) &&
1063 sym.st_size != sizeof (uint32_t)) {
1064 mdb_warn("expected scalar for variable '%s'\n",
1065 extras[i]);
1066 return (DCMD_ERR);
1069 if (mdb_vread(&buf, sym.st_size, sym.st_value) == -1) {
1070 mdb_warn("couldn't read '%s'", extras[i]);
1071 return (DCMD_ERR);
1074 mdb_printf("%-25s = ", extras[i]);
1076 /* NB: all the 64-bit extras happen to be byte counts */
1077 if (sym.st_size == sizeof (uint64_t))
1078 mdb_printf("%9llu %s\n", buf >> shift, suffix);
1080 if (sym.st_size == sizeof (uint32_t))
1081 mdb_printf("%9d\n", *((uint32_t *)&buf));
1083 return (DCMD_OK);
1086 typedef struct mdb_spa_print {
1087 pool_state_t spa_state;
1088 char spa_name[ZFS_MAX_DATASET_NAME_LEN];
1089 uintptr_t spa_normal_class;
1090 } mdb_spa_print_t;
1093 const char histo_stars[] = "****************************************";
1094 const int histo_width = sizeof (histo_stars) - 1;
1096 static void
1097 dump_histogram(const uint64_t *histo, int size, int offset)
1099 int i;
1100 int minidx = size - 1;
1101 int maxidx = 0;
1102 uint64_t max = 0;
1104 for (i = 0; i < size; i++) {
1105 if (histo[i] > max)
1106 max = histo[i];
1107 if (histo[i] > 0 && i > maxidx)
1108 maxidx = i;
1109 if (histo[i] > 0 && i < minidx)
1110 minidx = i;
1113 if (max < histo_width)
1114 max = histo_width;
1116 for (i = minidx; i <= maxidx; i++) {
1117 mdb_printf("%3u: %6llu %s\n",
1118 i + offset, (u_longlong_t)histo[i],
1119 &histo_stars[(max - histo[i]) * histo_width / max]);
1123 typedef struct mdb_metaslab_class {
1124 uint64_t mc_histogram[RANGE_TREE_HISTOGRAM_SIZE];
1125 } mdb_metaslab_class_t;
1128 * spa_class_histogram(uintptr_t class_addr)
1130 * Prints free space histogram for a device class
1132 * Returns DCMD_OK, or DCMD_ERR.
1134 static int
1135 spa_class_histogram(uintptr_t class_addr)
1137 mdb_metaslab_class_t mc;
1138 if (mdb_ctf_vread(&mc, "metaslab_class_t",
1139 "mdb_metaslab_class_t", class_addr, 0) == -1)
1140 return (DCMD_ERR);
1142 mdb_inc_indent(4);
1143 dump_histogram(mc.mc_histogram, RANGE_TREE_HISTOGRAM_SIZE, 0);
1144 mdb_dec_indent(4);
1145 return (DCMD_OK);
1149 * ::spa
1151 * -c Print configuration information as well
1152 * -v Print vdev state
1153 * -e Print vdev error stats
1154 * -m Print vdev metaslab info
1155 * -M print vdev metaslab group info
1156 * -h Print histogram info (must be combined with -m or -M)
1158 * Print a summarized spa_t. When given no arguments, prints out a table of all
1159 * active pools on the system.
1161 /* ARGSUSED */
1162 static int
1163 spa_print(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
1165 const char *statetab[] = { "ACTIVE", "EXPORTED", "DESTROYED",
1166 "SPARE", "L2CACHE", "UNINIT", "UNAVAIL", "POTENTIAL" };
1167 const char *state;
1168 int spa_flags = 0;
1170 if (mdb_getopts(argc, argv,
1171 'c', MDB_OPT_SETBITS, SPA_FLAG_CONFIG, &spa_flags,
1172 'v', MDB_OPT_SETBITS, SPA_FLAG_VDEVS, &spa_flags,
1173 'e', MDB_OPT_SETBITS, SPA_FLAG_ERRORS, &spa_flags,
1174 'M', MDB_OPT_SETBITS, SPA_FLAG_METASLAB_GROUPS, &spa_flags,
1175 'm', MDB_OPT_SETBITS, SPA_FLAG_METASLABS, &spa_flags,
1176 'h', MDB_OPT_SETBITS, SPA_FLAG_HISTOGRAMS, &spa_flags,
1177 NULL) != argc)
1178 return (DCMD_USAGE);
1180 if (!(flags & DCMD_ADDRSPEC)) {
1181 if (mdb_walk_dcmd("spa", "spa", argc, argv) == -1) {
1182 mdb_warn("can't walk spa");
1183 return (DCMD_ERR);
1186 return (DCMD_OK);
1189 if (flags & DCMD_PIPE_OUT) {
1190 mdb_printf("%#lr\n", addr);
1191 return (DCMD_OK);
1194 if (DCMD_HDRSPEC(flags))
1195 mdb_printf("%<u>%-?s %9s %-*s%</u>\n", "ADDR", "STATE",
1196 sizeof (uintptr_t) == 4 ? 60 : 52, "NAME");
1198 mdb_spa_print_t spa;
1199 if (mdb_ctf_vread(&spa, "spa_t", "mdb_spa_print_t", addr, 0) == -1)
1200 return (DCMD_ERR);
1202 if (spa.spa_state < 0 || spa.spa_state > POOL_STATE_UNAVAIL)
1203 state = "UNKNOWN";
1204 else
1205 state = statetab[spa.spa_state];
1207 mdb_printf("%0?p %9s %s\n", addr, state, spa.spa_name);
1208 if (spa_flags & SPA_FLAG_HISTOGRAMS)
1209 spa_class_histogram(spa.spa_normal_class);
1211 if (spa_flags & SPA_FLAG_CONFIG) {
1212 mdb_printf("\n");
1213 mdb_inc_indent(4);
1214 if (mdb_call_dcmd("spa_config", addr, flags, 0,
1215 NULL) != DCMD_OK)
1216 return (DCMD_ERR);
1217 mdb_dec_indent(4);
1220 if (spa_flags & SPA_FLAG_ALL_VDEV) {
1221 mdb_arg_t v;
1222 char opts[100] = "-";
1223 int args =
1224 (spa_flags | SPA_FLAG_VDEVS) == SPA_FLAG_VDEVS ? 0 : 1;
1226 if (spa_flags & SPA_FLAG_ERRORS)
1227 strcat(opts, "e");
1228 if (spa_flags & SPA_FLAG_METASLABS)
1229 strcat(opts, "m");
1230 if (spa_flags & SPA_FLAG_METASLAB_GROUPS)
1231 strcat(opts, "M");
1232 if (spa_flags & SPA_FLAG_HISTOGRAMS)
1233 strcat(opts, "h");
1235 v.a_type = MDB_TYPE_STRING;
1236 v.a_un.a_str = opts;
1238 mdb_printf("\n");
1239 mdb_inc_indent(4);
1240 if (mdb_call_dcmd("spa_vdevs", addr, flags, args,
1241 &v) != DCMD_OK)
1242 return (DCMD_ERR);
1243 mdb_dec_indent(4);
1246 return (DCMD_OK);
1249 typedef struct mdb_spa_config_spa {
1250 uintptr_t spa_config;
1251 } mdb_spa_config_spa_t;
1254 * ::spa_config
1256 * Given a spa_t, print the configuration information stored in spa_config.
1257 * Since it's just an nvlist, format it as an indented list of name=value pairs.
1258 * We simply read the value of spa_config and pass off to ::nvlist.
1260 /* ARGSUSED */
1261 static int
1262 spa_print_config(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
1264 mdb_spa_config_spa_t spa;
1266 if (argc != 0 || !(flags & DCMD_ADDRSPEC))
1267 return (DCMD_USAGE);
1269 if (mdb_ctf_vread(&spa, ZFS_STRUCT "spa", "mdb_spa_config_spa_t",
1270 addr, 0) == -1)
1271 return (DCMD_ERR);
1273 if (spa.spa_config == 0) {
1274 mdb_printf("(none)\n");
1275 return (DCMD_OK);
1278 return (mdb_call_dcmd("nvlist", spa.spa_config, flags,
1279 0, NULL));
1284 typedef struct mdb_range_tree {
1285 uint64_t rt_space;
1286 } mdb_range_tree_t;
1288 typedef struct mdb_metaslab_group {
1289 uint64_t mg_fragmentation;
1290 uint64_t mg_histogram[RANGE_TREE_HISTOGRAM_SIZE];
1291 uintptr_t mg_vd;
1292 } mdb_metaslab_group_t;
1294 typedef struct mdb_metaslab {
1295 uint64_t ms_id;
1296 uint64_t ms_start;
1297 uint64_t ms_size;
1298 int64_t ms_deferspace;
1299 uint64_t ms_fragmentation;
1300 uint64_t ms_weight;
1301 uintptr_t ms_alloctree[TXG_SIZE];
1302 uintptr_t ms_freeingtree;
1303 uintptr_t ms_freedtree;
1304 uintptr_t ms_tree;
1305 uintptr_t ms_sm;
1306 } mdb_metaslab_t;
1308 typedef struct mdb_space_map_phys_t {
1309 uint64_t smp_alloc;
1310 uint64_t smp_histogram[SPACE_MAP_HISTOGRAM_SIZE];
1311 } mdb_space_map_phys_t;
1313 typedef struct mdb_space_map {
1314 uint64_t sm_size;
1315 uint8_t sm_shift;
1316 uint64_t sm_alloc;
1317 uintptr_t sm_phys;
1318 } mdb_space_map_t;
1320 typedef struct mdb_vdev {
1321 uintptr_t vdev_path;
1322 uintptr_t vdev_ms;
1323 uintptr_t vdev_ops;
1324 uint64_t vdev_ms_count;
1325 uint64_t vdev_id;
1326 vdev_stat_t vdev_stat;
1327 } mdb_vdev_t;
1329 typedef struct mdb_vdev_ops {
1330 char vdev_op_type[16];
1331 } mdb_vdev_ops_t;
1333 static int
1334 metaslab_stats(uintptr_t addr, int spa_flags)
1336 mdb_vdev_t vdev;
1337 uintptr_t *vdev_ms;
1339 if (mdb_ctf_vread(&vdev, "vdev_t", "mdb_vdev_t",
1340 (uintptr_t)addr, 0) == -1) {
1341 mdb_warn("failed to read vdev at %p\n", addr);
1342 return (DCMD_ERR);
1345 mdb_inc_indent(4);
1346 mdb_printf("%<u>%-?s %6s %20s %10s %9s%</u>\n", "ADDR", "ID",
1347 "OFFSET", "FREE", "FRAGMENTATION");
1349 vdev_ms = mdb_alloc(vdev.vdev_ms_count * sizeof (void *),
1350 UM_SLEEP | UM_GC);
1351 if (mdb_vread(vdev_ms, vdev.vdev_ms_count * sizeof (void *),
1352 (uintptr_t)vdev.vdev_ms) == -1) {
1353 mdb_warn("failed to read vdev_ms at %p\n", vdev.vdev_ms);
1354 return (DCMD_ERR);
1357 for (int m = 0; m < vdev.vdev_ms_count; m++) {
1358 mdb_metaslab_t ms;
1359 mdb_space_map_t sm = { 0 };
1360 char free[NICENUM_BUFLEN];
1362 if (mdb_ctf_vread(&ms, "metaslab_t", "mdb_metaslab_t",
1363 (uintptr_t)vdev_ms[m], 0) == -1)
1364 return (DCMD_ERR);
1366 if (ms.ms_sm != (uintptr_t)NULL &&
1367 mdb_ctf_vread(&sm, "space_map_t", "mdb_space_map_t",
1368 ms.ms_sm, 0) == -1)
1369 return (DCMD_ERR);
1371 mdb_nicenum(ms.ms_size - sm.sm_alloc, free);
1373 mdb_printf("%0?p %6llu %20llx %10s ", vdev_ms[m], ms.ms_id,
1374 ms.ms_start, free);
1375 if (ms.ms_fragmentation == ZFS_FRAG_INVALID)
1376 mdb_printf("%9s\n", "-");
1377 else
1378 mdb_printf("%9llu%%\n", ms.ms_fragmentation);
1380 if ((spa_flags & SPA_FLAG_HISTOGRAMS) && ms.ms_sm != 0) {
1381 mdb_space_map_phys_t smp;
1383 if (sm.sm_phys == (uintptr_t)NULL)
1384 continue;
1386 (void) mdb_ctf_vread(&smp, "space_map_phys_t",
1387 "mdb_space_map_phys_t", sm.sm_phys, 0);
1389 dump_histogram(smp.smp_histogram,
1390 SPACE_MAP_HISTOGRAM_SIZE, sm.sm_shift);
1393 mdb_dec_indent(4);
1394 return (DCMD_OK);
1397 static int
1398 metaslab_group_stats(uintptr_t addr, int spa_flags)
1400 mdb_metaslab_group_t mg;
1401 if (mdb_ctf_vread(&mg, "metaslab_group_t", "mdb_metaslab_group_t",
1402 (uintptr_t)addr, 0) == -1) {
1403 mdb_warn("failed to read vdev_mg at %p\n", addr);
1404 return (DCMD_ERR);
1407 mdb_inc_indent(4);
1408 mdb_printf("%<u>%-?s %15s%</u>\n", "ADDR", "FRAGMENTATION");
1409 if (mg.mg_fragmentation == ZFS_FRAG_INVALID)
1410 mdb_printf("%0?p %15s\n", addr, "-");
1411 else
1412 mdb_printf("%0?p %15llu%%\n", addr, mg.mg_fragmentation);
1414 if (spa_flags & SPA_FLAG_HISTOGRAMS)
1415 dump_histogram(mg.mg_histogram, RANGE_TREE_HISTOGRAM_SIZE, 0);
1416 mdb_dec_indent(4);
1417 return (DCMD_OK);
1421 * ::vdev
1423 * Print out a summarized vdev_t, in the following form:
1425 * ADDR STATE AUX DESC
1426 * fffffffbcde23df0 HEALTHY - /dev/dsk/c0t0d0
1428 * If '-r' is specified, recursively visit all children.
1430 * With '-e', the statistics associated with the vdev are printed as well.
1432 static int
1433 do_print_vdev(uintptr_t addr, int flags, int depth, boolean_t recursive,
1434 int spa_flags)
1436 vdev_t vdev;
1437 char desc[MAXNAMELEN];
1438 int c, children;
1439 uintptr_t *child;
1440 const char *state, *aux;
1442 if (mdb_vread(&vdev, sizeof (vdev), (uintptr_t)addr) == -1) {
1443 mdb_warn("failed to read vdev_t at %p\n", (uintptr_t)addr);
1444 return (DCMD_ERR);
1447 if (flags & DCMD_PIPE_OUT) {
1448 mdb_printf("%#lr\n", addr);
1449 } else {
1450 if (vdev.vdev_path != NULL) {
1451 if (mdb_readstr(desc, sizeof (desc),
1452 (uintptr_t)vdev.vdev_path) == -1) {
1453 mdb_warn("failed to read vdev_path at %p\n",
1454 vdev.vdev_path);
1455 return (DCMD_ERR);
1457 } else if (vdev.vdev_ops != NULL) {
1458 vdev_ops_t ops;
1459 if (mdb_vread(&ops, sizeof (ops),
1460 (uintptr_t)vdev.vdev_ops) == -1) {
1461 mdb_warn("failed to read vdev_ops at %p\n",
1462 vdev.vdev_ops);
1463 return (DCMD_ERR);
1465 (void) strcpy(desc, ops.vdev_op_type);
1466 } else {
1467 (void) strcpy(desc, "<unknown>");
1470 if (depth == 0 && DCMD_HDRSPEC(flags))
1471 mdb_printf("%<u>%-?s %-9s %-12s %-*s%</u>\n",
1472 "ADDR", "STATE", "AUX",
1473 sizeof (uintptr_t) == 4 ? 43 : 35,
1474 "DESCRIPTION");
1476 mdb_printf("%0?p ", addr);
1478 switch (vdev.vdev_state) {
1479 case VDEV_STATE_CLOSED:
1480 state = "CLOSED";
1481 break;
1482 case VDEV_STATE_OFFLINE:
1483 state = "OFFLINE";
1484 break;
1485 case VDEV_STATE_CANT_OPEN:
1486 state = "CANT_OPEN";
1487 break;
1488 case VDEV_STATE_DEGRADED:
1489 state = "DEGRADED";
1490 break;
1491 case VDEV_STATE_HEALTHY:
1492 state = "HEALTHY";
1493 break;
1494 case VDEV_STATE_REMOVED:
1495 state = "REMOVED";
1496 break;
1497 case VDEV_STATE_FAULTED:
1498 state = "FAULTED";
1499 break;
1500 default:
1501 state = "UNKNOWN";
1502 break;
1505 switch (vdev.vdev_stat.vs_aux) {
1506 case VDEV_AUX_NONE:
1507 aux = "-";
1508 break;
1509 case VDEV_AUX_OPEN_FAILED:
1510 aux = "OPEN_FAILED";
1511 break;
1512 case VDEV_AUX_CORRUPT_DATA:
1513 aux = "CORRUPT_DATA";
1514 break;
1515 case VDEV_AUX_NO_REPLICAS:
1516 aux = "NO_REPLICAS";
1517 break;
1518 case VDEV_AUX_BAD_GUID_SUM:
1519 aux = "BAD_GUID_SUM";
1520 break;
1521 case VDEV_AUX_TOO_SMALL:
1522 aux = "TOO_SMALL";
1523 break;
1524 case VDEV_AUX_BAD_LABEL:
1525 aux = "BAD_LABEL";
1526 break;
1527 case VDEV_AUX_VERSION_NEWER:
1528 aux = "VERS_NEWER";
1529 break;
1530 case VDEV_AUX_VERSION_OLDER:
1531 aux = "VERS_OLDER";
1532 break;
1533 case VDEV_AUX_UNSUP_FEAT:
1534 aux = "UNSUP_FEAT";
1535 break;
1536 case VDEV_AUX_SPARED:
1537 aux = "SPARED";
1538 break;
1539 case VDEV_AUX_ERR_EXCEEDED:
1540 aux = "ERR_EXCEEDED";
1541 break;
1542 case VDEV_AUX_IO_FAILURE:
1543 aux = "IO_FAILURE";
1544 break;
1545 case VDEV_AUX_BAD_LOG:
1546 aux = "BAD_LOG";
1547 break;
1548 case VDEV_AUX_EXTERNAL:
1549 aux = "EXTERNAL";
1550 break;
1551 case VDEV_AUX_SPLIT_POOL:
1552 aux = "SPLIT_POOL";
1553 break;
1554 default:
1555 aux = "UNKNOWN";
1556 break;
1559 mdb_printf("%-9s %-12s %*s%s\n", state, aux, depth, "", desc);
1561 if (spa_flags & SPA_FLAG_ERRORS) {
1562 vdev_stat_t *vs = &vdev.vdev_stat;
1563 int i;
1565 mdb_inc_indent(4);
1566 mdb_printf("\n");
1567 mdb_printf("%<u> %12s %12s %12s %12s "
1568 "%12s%</u>\n", "READ", "WRITE", "FREE", "CLAIM",
1569 "IOCTL");
1570 mdb_printf("OPS ");
1571 for (i = 1; i < ZIO_TYPES; i++)
1572 mdb_printf("%11#llx%s", vs->vs_ops[i],
1573 i == ZIO_TYPES - 1 ? "" : " ");
1574 mdb_printf("\n");
1575 mdb_printf("BYTES ");
1576 for (i = 1; i < ZIO_TYPES; i++)
1577 mdb_printf("%11#llx%s", vs->vs_bytes[i],
1578 i == ZIO_TYPES - 1 ? "" : " ");
1581 mdb_printf("\n");
1582 mdb_printf("EREAD %10#llx\n", vs->vs_read_errors);
1583 mdb_printf("EWRITE %10#llx\n", vs->vs_write_errors);
1584 mdb_printf("ECKSUM %10#llx\n",
1585 vs->vs_checksum_errors);
1586 mdb_dec_indent(4);
1587 mdb_printf("\n");
1590 if (spa_flags & SPA_FLAG_METASLAB_GROUPS &&
1591 vdev.vdev_mg != NULL) {
1592 metaslab_group_stats((uintptr_t)vdev.vdev_mg,
1593 spa_flags);
1595 if (spa_flags & SPA_FLAG_METASLABS && vdev.vdev_ms != NULL) {
1596 metaslab_stats((uintptr_t)addr, spa_flags);
1600 children = vdev.vdev_children;
1602 if (children == 0 || !recursive)
1603 return (DCMD_OK);
1605 child = mdb_alloc(children * sizeof (void *), UM_SLEEP | UM_GC);
1606 if (mdb_vread(child, children * sizeof (void *),
1607 (uintptr_t)vdev.vdev_child) == -1) {
1608 mdb_warn("failed to read vdev children at %p", vdev.vdev_child);
1609 return (DCMD_ERR);
1612 for (c = 0; c < children; c++) {
1613 if (do_print_vdev(child[c], flags, depth + 2, recursive,
1614 spa_flags)) {
1615 return (DCMD_ERR);
1619 return (DCMD_OK);
1622 static int
1623 vdev_print(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
1625 uint64_t depth = 0;
1626 boolean_t recursive = B_FALSE;
1627 int spa_flags = 0;
1629 if (mdb_getopts(argc, argv,
1630 'e', MDB_OPT_SETBITS, SPA_FLAG_ERRORS, &spa_flags,
1631 'm', MDB_OPT_SETBITS, SPA_FLAG_METASLABS, &spa_flags,
1632 'M', MDB_OPT_SETBITS, SPA_FLAG_METASLAB_GROUPS, &spa_flags,
1633 'h', MDB_OPT_SETBITS, SPA_FLAG_HISTOGRAMS, &spa_flags,
1634 'r', MDB_OPT_SETBITS, TRUE, &recursive,
1635 'd', MDB_OPT_UINT64, &depth, NULL) != argc)
1636 return (DCMD_USAGE);
1638 if (!(flags & DCMD_ADDRSPEC)) {
1639 mdb_warn("no vdev_t address given\n");
1640 return (DCMD_ERR);
1643 return (do_print_vdev(addr, flags, (int)depth, recursive, spa_flags));
1646 typedef struct mdb_metaslab_alloc_trace {
1647 uintptr_t mat_mg;
1648 uintptr_t mat_msp;
1649 uint64_t mat_size;
1650 uint64_t mat_weight;
1651 uint64_t mat_offset;
1652 uint32_t mat_dva_id;
1653 } mdb_metaslab_alloc_trace_t;
1655 static void
1656 metaslab_print_weight(uint64_t weight)
1658 char buf[100];
1660 if (WEIGHT_IS_SPACEBASED(weight)) {
1661 mdb_nicenum(
1662 weight & ~(METASLAB_ACTIVE_MASK | METASLAB_WEIGHT_TYPE),
1663 buf);
1664 } else {
1665 char size[NICENUM_BUFLEN];
1666 mdb_nicenum(1ULL << WEIGHT_GET_INDEX(weight), size);
1667 (void) mdb_snprintf(buf, sizeof (buf), "%llu x %s",
1668 WEIGHT_GET_COUNT(weight), size);
1670 mdb_printf("%11s ", buf);
1673 /* ARGSUSED */
1674 static int
1675 metaslab_weight(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
1677 uint64_t weight = 0;
1678 char active;
1680 if (argc == 0 && (flags & DCMD_ADDRSPEC)) {
1681 if (mdb_vread(&weight, sizeof (uint64_t), addr) == -1) {
1682 mdb_warn("failed to read weight at %p\n", addr);
1683 return (DCMD_ERR);
1685 } else if (argc == 1 && !(flags & DCMD_ADDRSPEC)) {
1686 weight = (argv[0].a_type == MDB_TYPE_IMMEDIATE) ?
1687 argv[0].a_un.a_val : mdb_strtoull(argv[0].a_un.a_str);
1688 } else {
1689 return (DCMD_USAGE);
1692 if (DCMD_HDRSPEC(flags)) {
1693 mdb_printf("%<u>%-6s %9s %9s%</u>\n",
1694 "ACTIVE", "ALGORITHM", "WEIGHT");
1697 if (weight & METASLAB_WEIGHT_PRIMARY)
1698 active = 'P';
1699 else if (weight & METASLAB_WEIGHT_SECONDARY)
1700 active = 'S';
1701 else
1702 active = '-';
1703 mdb_printf("%6c %8s ", active,
1704 WEIGHT_IS_SPACEBASED(weight) ? "SPACE" : "SEGMENT");
1705 metaslab_print_weight(weight);
1706 mdb_printf("\n");
1708 return (DCMD_OK);
1711 /* ARGSUSED */
1712 static int
1713 metaslab_trace(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
1715 mdb_metaslab_alloc_trace_t mat;
1716 mdb_metaslab_group_t mg = { 0 };
1717 char result_type[100];
1719 if (mdb_ctf_vread(&mat, "metaslab_alloc_trace_t",
1720 "mdb_metaslab_alloc_trace_t", addr, 0) == -1) {
1721 return (DCMD_ERR);
1724 if (!(flags & DCMD_PIPE_OUT) && DCMD_HDRSPEC(flags)) {
1725 mdb_printf("%<u>%6s %6s %8s %11s %18s %18s%</u>\n",
1726 "MSID", "DVA", "ASIZE", "WEIGHT", "RESULT", "VDEV");
1729 if (mat.mat_msp != 0) {
1730 mdb_metaslab_t ms;
1732 if (mdb_ctf_vread(&ms, "metaslab_t", "mdb_metaslab_t",
1733 mat.mat_msp, 0) == -1) {
1734 return (DCMD_ERR);
1736 mdb_printf("%6llu ", ms.ms_id);
1737 } else {
1738 mdb_printf("%6s ", "-");
1741 mdb_printf("%6d %8llx ", mat.mat_dva_id, mat.mat_size);
1743 metaslab_print_weight(mat.mat_weight);
1745 if ((int64_t)mat.mat_offset < 0) {
1746 if (enum_lookup("enum trace_alloc_type", mat.mat_offset,
1747 "TRACE_", sizeof (result_type), result_type) == -1) {
1748 mdb_warn("Could not find enum for trace_alloc_type");
1749 return (DCMD_ERR);
1751 mdb_printf("%18s ", result_type);
1752 } else {
1753 mdb_printf("%<b>%18llx%</b> ", mat.mat_offset);
1756 if (mat.mat_mg != 0 &&
1757 mdb_ctf_vread(&mg, "metaslab_group_t", "mdb_metaslab_group_t",
1758 mat.mat_mg, 0) == -1) {
1759 return (DCMD_ERR);
1762 if (mg.mg_vd != 0) {
1763 mdb_vdev_t vdev;
1764 char desc[MAXNAMELEN];
1766 if (mdb_ctf_vread(&vdev, "vdev_t", "mdb_vdev_t",
1767 mg.mg_vd, 0) == -1) {
1768 return (DCMD_ERR);
1771 if (vdev.vdev_path != 0) {
1772 char path[MAXNAMELEN];
1774 if (mdb_readstr(path, sizeof (path),
1775 vdev.vdev_path) == -1) {
1776 mdb_warn("failed to read vdev_path at %p\n",
1777 vdev.vdev_path);
1778 return (DCMD_ERR);
1780 char *slash;
1781 if ((slash = strrchr(path, '/')) != NULL) {
1782 strcpy(desc, slash + 1);
1783 } else {
1784 strcpy(desc, path);
1786 } else if (vdev.vdev_ops != 0) {
1787 mdb_vdev_ops_t ops;
1788 if (mdb_ctf_vread(&ops, "vdev_ops_t", "mdb_vdev_ops_t",
1789 vdev.vdev_ops, 0) == -1) {
1790 mdb_warn("failed to read vdev_ops at %p\n",
1791 vdev.vdev_ops);
1792 return (DCMD_ERR);
1794 (void) mdb_snprintf(desc, sizeof (desc),
1795 "%s-%llu", ops.vdev_op_type, vdev.vdev_id);
1796 } else {
1797 (void) strcpy(desc, "<unknown>");
1799 mdb_printf("%18s\n", desc);
1802 return (DCMD_OK);
1805 typedef struct metaslab_walk_data {
1806 uint64_t mw_numvdevs;
1807 uintptr_t *mw_vdevs;
1808 int mw_curvdev;
1809 uint64_t mw_nummss;
1810 uintptr_t *mw_mss;
1811 int mw_curms;
1812 } metaslab_walk_data_t;
1814 static int
1815 metaslab_walk_step(mdb_walk_state_t *wsp)
1817 metaslab_walk_data_t *mw = wsp->walk_data;
1818 metaslab_t ms;
1819 uintptr_t msp;
1821 if (mw->mw_curvdev >= mw->mw_numvdevs)
1822 return (WALK_DONE);
1824 if (mw->mw_mss == NULL) {
1825 uintptr_t mssp;
1826 uintptr_t vdevp;
1828 ASSERT(mw->mw_curms == 0);
1829 ASSERT(mw->mw_nummss == 0);
1831 vdevp = mw->mw_vdevs[mw->mw_curvdev];
1832 if (GETMEMB(vdevp, "vdev", vdev_ms, mssp) ||
1833 GETMEMB(vdevp, "vdev", vdev_ms_count, mw->mw_nummss)) {
1834 return (WALK_ERR);
1837 mw->mw_mss = mdb_alloc(mw->mw_nummss * sizeof (void*),
1838 UM_SLEEP | UM_GC);
1839 if (mdb_vread(mw->mw_mss, mw->mw_nummss * sizeof (void*),
1840 mssp) == -1) {
1841 mdb_warn("failed to read vdev_ms at %p", mssp);
1842 return (WALK_ERR);
1846 if (mw->mw_curms >= mw->mw_nummss) {
1847 mw->mw_mss = NULL;
1848 mw->mw_curms = 0;
1849 mw->mw_nummss = 0;
1850 mw->mw_curvdev++;
1851 return (WALK_NEXT);
1854 msp = mw->mw_mss[mw->mw_curms];
1855 if (mdb_vread(&ms, sizeof (metaslab_t), msp) == -1) {
1856 mdb_warn("failed to read metaslab_t at %p", msp);
1857 return (WALK_ERR);
1860 mw->mw_curms++;
1862 return (wsp->walk_callback(msp, &ms, wsp->walk_cbdata));
1865 static int
1866 metaslab_walk_init(mdb_walk_state_t *wsp)
1868 metaslab_walk_data_t *mw;
1869 uintptr_t root_vdevp;
1870 uintptr_t childp;
1872 if (wsp->walk_addr == (uintptr_t)NULL) {
1873 mdb_warn("must supply address of spa_t\n");
1874 return (WALK_ERR);
1877 mw = mdb_zalloc(sizeof (metaslab_walk_data_t), UM_SLEEP | UM_GC);
1879 if (GETMEMB(wsp->walk_addr, "spa", spa_root_vdev, root_vdevp) ||
1880 GETMEMB(root_vdevp, "vdev", vdev_children, mw->mw_numvdevs) ||
1881 GETMEMB(root_vdevp, "vdev", vdev_child, childp)) {
1882 return (DCMD_ERR);
1885 mw->mw_vdevs = mdb_alloc(mw->mw_numvdevs * sizeof (void *),
1886 UM_SLEEP | UM_GC);
1887 if (mdb_vread(mw->mw_vdevs, mw->mw_numvdevs * sizeof (void *),
1888 childp) == -1) {
1889 mdb_warn("failed to read root vdev children at %p", childp);
1890 return (DCMD_ERR);
1893 wsp->walk_data = mw;
1895 return (WALK_NEXT);
1898 typedef struct mdb_spa {
1899 uintptr_t spa_dsl_pool;
1900 uintptr_t spa_root_vdev;
1901 } mdb_spa_t;
1903 typedef struct mdb_dsl_pool {
1904 uintptr_t dp_root_dir;
1905 } mdb_dsl_pool_t;
1907 typedef struct mdb_dsl_dir {
1908 uintptr_t dd_dbuf;
1909 int64_t dd_space_towrite[TXG_SIZE];
1910 } mdb_dsl_dir_t;
1912 typedef struct mdb_dsl_dir_phys {
1913 uint64_t dd_used_bytes;
1914 uint64_t dd_compressed_bytes;
1915 uint64_t dd_uncompressed_bytes;
1916 } mdb_dsl_dir_phys_t;
1918 typedef struct space_data {
1919 uint64_t ms_alloctree[TXG_SIZE];
1920 uint64_t ms_freeingtree;
1921 uint64_t ms_freedtree;
1922 uint64_t ms_tree;
1923 int64_t ms_deferspace;
1924 uint64_t avail;
1925 uint64_t nowavail;
1926 } space_data_t;
1928 /* ARGSUSED */
1929 static int
1930 space_cb(uintptr_t addr, const void *unknown, void *arg)
1932 space_data_t *sd = arg;
1933 mdb_metaslab_t ms;
1934 mdb_range_tree_t rt;
1935 mdb_space_map_t sm = { 0 };
1936 mdb_space_map_phys_t smp = { 0 };
1937 int i;
1939 if (mdb_ctf_vread(&ms, "metaslab_t", "mdb_metaslab_t",
1940 addr, 0) == -1)
1941 return (WALK_ERR);
1943 for (i = 0; i < TXG_SIZE; i++) {
1944 if (mdb_ctf_vread(&rt, "range_tree_t",
1945 "mdb_range_tree_t", ms.ms_alloctree[i], 0) == -1)
1946 return (WALK_ERR);
1948 sd->ms_alloctree[i] += rt.rt_space;
1952 if (mdb_ctf_vread(&rt, "range_tree_t",
1953 "mdb_range_tree_t", ms.ms_freeingtree, 0) == -1)
1954 return (WALK_ERR);
1955 sd->ms_freeingtree += rt.rt_space;
1957 if (mdb_ctf_vread(&rt, "range_tree_t",
1958 "mdb_range_tree_t", ms.ms_freedtree, 0) == -1)
1959 return (WALK_ERR);
1960 sd->ms_freedtree += rt.rt_space;
1962 if (mdb_ctf_vread(&rt, "range_tree_t",
1963 "mdb_range_tree_t", ms.ms_tree, 0) == -1)
1964 return (WALK_ERR);
1965 sd->ms_tree += rt.rt_space;
1967 if (ms.ms_sm != (uintptr_t)NULL &&
1968 mdb_ctf_vread(&sm, "space_map_t",
1969 "mdb_space_map_t", ms.ms_sm, 0) == -1)
1970 return (WALK_ERR);
1972 if (sm.sm_phys != (uintptr_t)NULL) {
1973 (void) mdb_ctf_vread(&smp, "space_map_phys_t",
1974 "mdb_space_map_phys_t", sm.sm_phys, 0);
1977 sd->ms_deferspace += ms.ms_deferspace;
1978 sd->avail += sm.sm_size - sm.sm_alloc;
1979 sd->nowavail += sm.sm_size - smp.smp_alloc;
1981 return (WALK_NEXT);
1985 * ::spa_space [-b]
1987 * Given a spa_t, print out it's on-disk space usage and in-core
1988 * estimates of future usage. If -b is given, print space in bytes.
1989 * Otherwise print in megabytes.
1991 /* ARGSUSED */
1992 static int
1993 spa_space(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
1995 mdb_spa_t spa;
1996 mdb_dsl_pool_t dp;
1997 mdb_dsl_dir_t dd;
1998 mdb_dmu_buf_impl_t db;
1999 mdb_dsl_dir_phys_t dsp;
2000 space_data_t sd;
2001 int shift = 20;
2002 char *suffix = "M";
2003 int bytes = B_FALSE;
2005 if (mdb_getopts(argc, argv, 'b', MDB_OPT_SETBITS, TRUE, &bytes, NULL) !=
2006 argc)
2007 return (DCMD_USAGE);
2008 if (!(flags & DCMD_ADDRSPEC))
2009 return (DCMD_USAGE);
2011 if (bytes) {
2012 shift = 0;
2013 suffix = "";
2016 if (mdb_ctf_vread(&spa, ZFS_STRUCT "spa", "mdb_spa_t",
2017 addr, 0) == -1 ||
2018 mdb_ctf_vread(&dp, ZFS_STRUCT "dsl_pool", "mdb_dsl_pool_t",
2019 spa.spa_dsl_pool, 0) == -1 ||
2020 mdb_ctf_vread(&dd, ZFS_STRUCT "dsl_dir", "mdb_dsl_dir_t",
2021 dp.dp_root_dir, 0) == -1 ||
2022 mdb_ctf_vread(&db, ZFS_STRUCT "dmu_buf_impl", "mdb_dmu_buf_impl_t",
2023 dd.dd_dbuf, 0) == -1 ||
2024 mdb_ctf_vread(&dsp, ZFS_STRUCT "dsl_dir_phys",
2025 "mdb_dsl_dir_phys_t", db.db.db_data, 0) == -1) {
2026 return (DCMD_ERR);
2029 mdb_printf("dd_space_towrite = %llu%s %llu%s %llu%s %llu%s\n",
2030 dd.dd_space_towrite[0] >> shift, suffix,
2031 dd.dd_space_towrite[1] >> shift, suffix,
2032 dd.dd_space_towrite[2] >> shift, suffix,
2033 dd.dd_space_towrite[3] >> shift, suffix);
2035 mdb_printf("dd_phys.dd_used_bytes = %llu%s\n",
2036 dsp.dd_used_bytes >> shift, suffix);
2037 mdb_printf("dd_phys.dd_compressed_bytes = %llu%s\n",
2038 dsp.dd_compressed_bytes >> shift, suffix);
2039 mdb_printf("dd_phys.dd_uncompressed_bytes = %llu%s\n",
2040 dsp.dd_uncompressed_bytes >> shift, suffix);
2042 bzero(&sd, sizeof (sd));
2043 if (mdb_pwalk("metaslab", space_cb, &sd, addr) != 0) {
2044 mdb_warn("can't walk metaslabs");
2045 return (DCMD_ERR);
2048 mdb_printf("ms_allocmap = %llu%s %llu%s %llu%s %llu%s\n",
2049 sd.ms_alloctree[0] >> shift, suffix,
2050 sd.ms_alloctree[1] >> shift, suffix,
2051 sd.ms_alloctree[2] >> shift, suffix,
2052 sd.ms_alloctree[3] >> shift, suffix);
2053 mdb_printf("ms_freeingtree = %llu%s\n",
2054 sd.ms_freeingtree >> shift, suffix);
2055 mdb_printf("ms_freedtree = %llu%s\n",
2056 sd.ms_freedtree >> shift, suffix);
2057 mdb_printf("ms_tree = %llu%s\n", sd.ms_tree >> shift, suffix);
2058 mdb_printf("ms_deferspace = %llu%s\n",
2059 sd.ms_deferspace >> shift, suffix);
2060 mdb_printf("last synced avail = %llu%s\n", sd.avail >> shift, suffix);
2061 mdb_printf("current syncing avail = %llu%s\n",
2062 sd.nowavail >> shift, suffix);
2064 return (DCMD_OK);
2067 typedef struct mdb_spa_aux_vdev {
2068 int sav_count;
2069 uintptr_t sav_vdevs;
2070 } mdb_spa_aux_vdev_t;
2072 typedef struct mdb_spa_vdevs {
2073 uintptr_t spa_root_vdev;
2074 mdb_spa_aux_vdev_t spa_l2cache;
2075 mdb_spa_aux_vdev_t spa_spares;
2076 } mdb_spa_vdevs_t;
2078 static int
2079 spa_print_aux(mdb_spa_aux_vdev_t *sav, uint_t flags, mdb_arg_t *v,
2080 const char *name)
2082 uintptr_t *aux;
2083 size_t len;
2084 int ret, i;
2087 * Iterate over aux vdevs and print those out as well. This is a
2088 * little annoying because we don't have a root vdev to pass to ::vdev.
2089 * Instead, we print a single line and then call it for each child
2090 * vdev.
2092 if (sav->sav_count != 0) {
2093 v[1].a_type = MDB_TYPE_STRING;
2094 v[1].a_un.a_str = "-d";
2095 v[2].a_type = MDB_TYPE_IMMEDIATE;
2096 v[2].a_un.a_val = 2;
2098 len = sav->sav_count * sizeof (uintptr_t);
2099 aux = mdb_alloc(len, UM_SLEEP);
2100 if (mdb_vread(aux, len, sav->sav_vdevs) == -1) {
2101 mdb_free(aux, len);
2102 mdb_warn("failed to read l2cache vdevs at %p",
2103 sav->sav_vdevs);
2104 return (DCMD_ERR);
2107 mdb_printf("%-?s %-9s %-12s %s\n", "-", "-", "-", name);
2109 for (i = 0; i < sav->sav_count; i++) {
2110 ret = mdb_call_dcmd("vdev", aux[i], flags, 3, v);
2111 if (ret != DCMD_OK) {
2112 mdb_free(aux, len);
2113 return (ret);
2117 mdb_free(aux, len);
2120 return (0);
2124 * ::spa_vdevs
2126 * -e Include error stats
2127 * -m Include metaslab information
2128 * -M Include metaslab group information
2129 * -h Include histogram information (requires -m or -M)
2131 * Print out a summarized list of vdevs for the given spa_t.
2132 * This is accomplished by invoking "::vdev -re" on the root vdev, as well as
2133 * iterating over the cache devices.
2135 /* ARGSUSED */
2136 static int
2137 spa_vdevs(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
2139 mdb_arg_t v[3];
2140 int ret;
2141 char opts[100] = "-r";
2142 int spa_flags = 0;
2144 if (mdb_getopts(argc, argv,
2145 'e', MDB_OPT_SETBITS, SPA_FLAG_ERRORS, &spa_flags,
2146 'm', MDB_OPT_SETBITS, SPA_FLAG_METASLABS, &spa_flags,
2147 'M', MDB_OPT_SETBITS, SPA_FLAG_METASLAB_GROUPS, &spa_flags,
2148 'h', MDB_OPT_SETBITS, SPA_FLAG_HISTOGRAMS, &spa_flags,
2149 NULL) != argc)
2150 return (DCMD_USAGE);
2152 if (!(flags & DCMD_ADDRSPEC))
2153 return (DCMD_USAGE);
2155 mdb_spa_vdevs_t spa;
2156 if (mdb_ctf_vread(&spa, "spa_t", "mdb_spa_vdevs_t", addr, 0) == -1)
2157 return (DCMD_ERR);
2160 * Unitialized spa_t structures can have a NULL root vdev.
2162 if (spa.spa_root_vdev == (uintptr_t)NULL) {
2163 mdb_printf("no associated vdevs\n");
2164 return (DCMD_OK);
2167 if (spa_flags & SPA_FLAG_ERRORS)
2168 strcat(opts, "e");
2169 if (spa_flags & SPA_FLAG_METASLABS)
2170 strcat(opts, "m");
2171 if (spa_flags & SPA_FLAG_METASLAB_GROUPS)
2172 strcat(opts, "M");
2173 if (spa_flags & SPA_FLAG_HISTOGRAMS)
2174 strcat(opts, "h");
2176 v[0].a_type = MDB_TYPE_STRING;
2177 v[0].a_un.a_str = opts;
2179 ret = mdb_call_dcmd("vdev", (uintptr_t)spa.spa_root_vdev,
2180 flags, 1, v);
2181 if (ret != DCMD_OK)
2182 return (ret);
2184 if (spa_print_aux(&spa.spa_l2cache, flags, v, "cache") != 0 ||
2185 spa_print_aux(&spa.spa_spares, flags, v, "spares") != 0)
2186 return (DCMD_ERR);
2188 return (DCMD_OK);
2192 * ::zio
2194 * Print a summary of zio_t and all its children. This is intended to display a
2195 * zio tree, and hence we only pick the most important pieces of information for
2196 * the main summary. More detailed information can always be found by doing a
2197 * '::print zio' on the underlying zio_t. The columns we display are:
2199 * ADDRESS TYPE STAGE WAITER TIME_ELAPSED
2201 * The 'address' column is indented by one space for each depth level as we
2202 * descend down the tree.
2205 #define ZIO_MAXINDENT 7
2206 #define ZIO_MAXWIDTH (sizeof (uintptr_t) * 2 + ZIO_MAXINDENT)
2207 #define ZIO_WALK_SELF 0
2208 #define ZIO_WALK_CHILD 1
2209 #define ZIO_WALK_PARENT 2
2211 typedef struct zio_print_args {
2212 int zpa_current_depth;
2213 int zpa_min_depth;
2214 int zpa_max_depth;
2215 int zpa_type;
2216 uint_t zpa_flags;
2217 } zio_print_args_t;
2219 typedef struct mdb_zio {
2220 enum zio_type io_type;
2221 enum zio_stage io_stage;
2222 uintptr_t io_waiter;
2223 uintptr_t io_spa;
2224 struct {
2225 struct {
2226 uintptr_t list_next;
2227 } list_head;
2228 } io_parent_list;
2229 int io_error;
2230 } mdb_zio_t;
2232 typedef struct mdb_zio_timestamp {
2233 hrtime_t io_timestamp;
2234 } mdb_zio_timestamp_t;
2236 static int zio_child_cb(uintptr_t addr, const void *unknown, void *arg);
2238 static int
2239 zio_print_cb(uintptr_t addr, zio_print_args_t *zpa)
2241 mdb_ctf_id_t type_enum, stage_enum;
2242 int indent = zpa->zpa_current_depth;
2243 const char *type, *stage;
2244 uintptr_t laddr;
2245 mdb_zio_t zio;
2246 mdb_zio_timestamp_t zio_timestamp = { 0 };
2248 if (mdb_ctf_vread(&zio, ZFS_STRUCT "zio", "mdb_zio_t", addr, 0) == -1)
2249 return (WALK_ERR);
2250 (void) mdb_ctf_vread(&zio_timestamp, ZFS_STRUCT "zio",
2251 "mdb_zio_timestamp_t", addr, MDB_CTF_VREAD_QUIET);
2253 if (indent > ZIO_MAXINDENT)
2254 indent = ZIO_MAXINDENT;
2256 if (mdb_ctf_lookup_by_name("enum zio_type", &type_enum) == -1 ||
2257 mdb_ctf_lookup_by_name("enum zio_stage", &stage_enum) == -1) {
2258 mdb_warn("failed to lookup zio enums");
2259 return (WALK_ERR);
2262 if ((type = mdb_ctf_enum_name(type_enum, zio.io_type)) != NULL)
2263 type += sizeof ("ZIO_TYPE_") - 1;
2264 else
2265 type = "?";
2267 if (zio.io_error == 0) {
2268 stage = mdb_ctf_enum_name(stage_enum, zio.io_stage);
2269 if (stage != NULL)
2270 stage += sizeof ("ZIO_STAGE_") - 1;
2271 else
2272 stage = "?";
2273 } else {
2274 stage = "FAILED";
2277 if (zpa->zpa_current_depth >= zpa->zpa_min_depth) {
2278 if (zpa->zpa_flags & DCMD_PIPE_OUT) {
2279 mdb_printf("%?p\n", addr);
2280 } else {
2281 mdb_printf("%*s%-*p %-5s %-16s ", indent, "",
2282 ZIO_MAXWIDTH - indent, addr, type, stage);
2283 if (zio.io_waiter != 0)
2284 mdb_printf("%-16lx ", zio.io_waiter);
2285 else
2286 mdb_printf("%-16s ", "-");
2287 #ifdef _KERNEL
2288 if (zio_timestamp.io_timestamp != 0) {
2289 mdb_printf("%llums", (mdb_gethrtime() -
2290 zio_timestamp.io_timestamp) /
2291 1000000);
2292 } else {
2293 mdb_printf("%-12s ", "-");
2295 #else
2296 mdb_printf("%-12s ", "-");
2297 #endif
2298 mdb_printf("\n");
2302 if (zpa->zpa_current_depth >= zpa->zpa_max_depth)
2303 return (WALK_NEXT);
2305 if (zpa->zpa_type == ZIO_WALK_PARENT)
2306 laddr = addr + mdb_ctf_offsetof_by_name(ZFS_STRUCT "zio",
2307 "io_parent_list");
2308 else
2309 laddr = addr + mdb_ctf_offsetof_by_name(ZFS_STRUCT "zio",
2310 "io_child_list");
2312 zpa->zpa_current_depth++;
2313 if (mdb_pwalk("list", zio_child_cb, zpa, laddr) != 0) {
2314 mdb_warn("failed to walk zio_t children at %p\n", laddr);
2315 return (WALK_ERR);
2317 zpa->zpa_current_depth--;
2319 return (WALK_NEXT);
2322 /* ARGSUSED */
2323 static int
2324 zio_child_cb(uintptr_t addr, const void *unknown, void *arg)
2326 zio_link_t zl;
2327 uintptr_t ziop;
2328 zio_print_args_t *zpa = arg;
2330 if (mdb_vread(&zl, sizeof (zl), addr) == -1) {
2331 mdb_warn("failed to read zio_link_t at %p", addr);
2332 return (WALK_ERR);
2335 if (zpa->zpa_type == ZIO_WALK_PARENT)
2336 ziop = (uintptr_t)zl.zl_parent;
2337 else
2338 ziop = (uintptr_t)zl.zl_child;
2340 return (zio_print_cb(ziop, zpa));
2343 /* ARGSUSED */
2344 static int
2345 zio_print(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
2347 zio_print_args_t zpa = { 0 };
2349 if (!(flags & DCMD_ADDRSPEC))
2350 return (DCMD_USAGE);
2352 if (mdb_getopts(argc, argv,
2353 'r', MDB_OPT_SETBITS, INT_MAX, &zpa.zpa_max_depth,
2354 'c', MDB_OPT_SETBITS, ZIO_WALK_CHILD, &zpa.zpa_type,
2355 'p', MDB_OPT_SETBITS, ZIO_WALK_PARENT, &zpa.zpa_type,
2356 NULL) != argc)
2357 return (DCMD_USAGE);
2359 zpa.zpa_flags = flags;
2360 if (zpa.zpa_max_depth != 0) {
2361 if (zpa.zpa_type == ZIO_WALK_SELF)
2362 zpa.zpa_type = ZIO_WALK_CHILD;
2363 } else if (zpa.zpa_type != ZIO_WALK_SELF) {
2364 zpa.zpa_min_depth = 1;
2365 zpa.zpa_max_depth = 1;
2368 if (!(flags & DCMD_PIPE_OUT) && DCMD_HDRSPEC(flags)) {
2369 mdb_printf("%<u>%-*s %-5s %-16s %-16s %-12s%</u>\n",
2370 ZIO_MAXWIDTH, "ADDRESS", "TYPE", "STAGE", "WAITER",
2371 "TIME_ELAPSED");
2374 if (zio_print_cb(addr, &zpa) != WALK_NEXT)
2375 return (DCMD_ERR);
2377 return (DCMD_OK);
2381 * [addr]::zio_state
2383 * Print a summary of all zio_t structures on the system, or for a particular
2384 * pool. This is equivalent to '::walk zio_root | ::zio'.
2386 /*ARGSUSED*/
2387 static int
2388 zio_state(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
2391 * MDB will remember the last address of the pipeline, so if we don't
2392 * zero this we'll end up trying to walk zio structures for a
2393 * non-existent spa_t.
2395 if (!(flags & DCMD_ADDRSPEC))
2396 addr = 0;
2398 return (mdb_pwalk_dcmd("zio_root", "zio", argc, argv, addr));
2401 typedef struct mdb_multilist {
2402 uint64_t ml_num_sublists;
2403 uintptr_t ml_sublists;
2404 } mdb_multilist_t;
2406 typedef struct multilist_walk_data {
2407 uint64_t mwd_idx;
2408 mdb_multilist_t mwd_ml;
2409 } multilist_walk_data_t;
2411 /* ARGSUSED */
2412 static int
2413 multilist_print_cb(uintptr_t addr, const void *unknown, void *arg)
2415 mdb_printf("%#lr\n", addr);
2416 return (WALK_NEXT);
2419 static int
2420 multilist_walk_step(mdb_walk_state_t *wsp)
2422 multilist_walk_data_t *mwd = wsp->walk_data;
2424 if (mwd->mwd_idx >= mwd->mwd_ml.ml_num_sublists)
2425 return (WALK_DONE);
2427 wsp->walk_addr = mwd->mwd_ml.ml_sublists +
2428 mdb_ctf_sizeof_by_name("multilist_sublist_t") * mwd->mwd_idx +
2429 mdb_ctf_offsetof_by_name("multilist_sublist_t", "mls_list");
2431 mdb_pwalk("list", multilist_print_cb, NULL, wsp->walk_addr);
2432 mwd->mwd_idx++;
2434 return (WALK_NEXT);
2437 static int
2438 multilist_walk_init(mdb_walk_state_t *wsp)
2440 multilist_walk_data_t *mwd;
2442 if (wsp->walk_addr == 0) {
2443 mdb_warn("must supply address of multilist_t\n");
2444 return (WALK_ERR);
2447 mwd = mdb_zalloc(sizeof (multilist_walk_data_t), UM_SLEEP | UM_GC);
2448 if (mdb_ctf_vread(&mwd->mwd_ml, "multilist_t", "mdb_multilist_t",
2449 wsp->walk_addr, 0) == -1) {
2450 return (WALK_ERR);
2453 if (mwd->mwd_ml.ml_num_sublists == 0 ||
2454 mwd->mwd_ml.ml_sublists == 0) {
2455 mdb_warn("invalid or uninitialized multilist at %#lx\n",
2456 wsp->walk_addr);
2457 return (WALK_ERR);
2460 wsp->walk_data = mwd;
2461 return (WALK_NEXT);
2464 typedef struct txg_list_walk_data {
2465 uintptr_t lw_head[TXG_SIZE];
2466 int lw_txgoff;
2467 int lw_maxoff;
2468 size_t lw_offset;
2469 void *lw_obj;
2470 } txg_list_walk_data_t;
2472 static int
2473 txg_list_walk_init_common(mdb_walk_state_t *wsp, int txg, int maxoff)
2475 txg_list_walk_data_t *lwd;
2476 txg_list_t list;
2477 int i;
2479 lwd = mdb_alloc(sizeof (txg_list_walk_data_t), UM_SLEEP | UM_GC);
2480 if (mdb_vread(&list, sizeof (txg_list_t), wsp->walk_addr) == -1) {
2481 mdb_warn("failed to read txg_list_t at %#lx", wsp->walk_addr);
2482 return (WALK_ERR);
2485 for (i = 0; i < TXG_SIZE; i++)
2486 lwd->lw_head[i] = (uintptr_t)list.tl_head[i];
2487 lwd->lw_offset = list.tl_offset;
2488 lwd->lw_obj = mdb_alloc(lwd->lw_offset + sizeof (txg_node_t),
2489 UM_SLEEP | UM_GC);
2490 lwd->lw_txgoff = txg;
2491 lwd->lw_maxoff = maxoff;
2493 wsp->walk_addr = lwd->lw_head[lwd->lw_txgoff];
2494 wsp->walk_data = lwd;
2496 return (WALK_NEXT);
2499 static int
2500 txg_list_walk_init(mdb_walk_state_t *wsp)
2502 return (txg_list_walk_init_common(wsp, 0, TXG_SIZE-1));
2505 static int
2506 txg_list0_walk_init(mdb_walk_state_t *wsp)
2508 return (txg_list_walk_init_common(wsp, 0, 0));
2511 static int
2512 txg_list1_walk_init(mdb_walk_state_t *wsp)
2514 return (txg_list_walk_init_common(wsp, 1, 1));
2517 static int
2518 txg_list2_walk_init(mdb_walk_state_t *wsp)
2520 return (txg_list_walk_init_common(wsp, 2, 2));
2523 static int
2524 txg_list3_walk_init(mdb_walk_state_t *wsp)
2526 return (txg_list_walk_init_common(wsp, 3, 3));
2529 static int
2530 txg_list_walk_step(mdb_walk_state_t *wsp)
2532 txg_list_walk_data_t *lwd = wsp->walk_data;
2533 uintptr_t addr;
2534 txg_node_t *node;
2535 int status;
2537 while (wsp->walk_addr == (uintptr_t)NULL &&
2538 lwd->lw_txgoff < lwd->lw_maxoff) {
2539 lwd->lw_txgoff++;
2540 wsp->walk_addr = lwd->lw_head[lwd->lw_txgoff];
2543 if (wsp->walk_addr == (uintptr_t)NULL)
2544 return (WALK_DONE);
2546 addr = wsp->walk_addr - lwd->lw_offset;
2548 if (mdb_vread(lwd->lw_obj,
2549 lwd->lw_offset + sizeof (txg_node_t), addr) == -1) {
2550 mdb_warn("failed to read list element at %#lx", addr);
2551 return (WALK_ERR);
2554 status = wsp->walk_callback(addr, lwd->lw_obj, wsp->walk_cbdata);
2555 node = (txg_node_t *)((uintptr_t)lwd->lw_obj + lwd->lw_offset);
2556 wsp->walk_addr = (uintptr_t)node->tn_next[lwd->lw_txgoff];
2558 return (status);
2562 * ::walk spa
2564 * Walk all named spa_t structures in the namespace. This is nothing more than
2565 * a layered avl walk.
2567 static int
2568 spa_walk_init(mdb_walk_state_t *wsp)
2570 GElf_Sym sym;
2572 if (wsp->walk_addr != (uintptr_t)NULL) {
2573 mdb_warn("spa walk only supports global walks\n");
2574 return (WALK_ERR);
2577 if (mdb_lookup_by_obj(ZFS_OBJ_NAME, "spa_namespace_avl", &sym) == -1) {
2578 mdb_warn("failed to find symbol 'spa_namespace_avl'");
2579 return (WALK_ERR);
2582 wsp->walk_addr = (uintptr_t)sym.st_value;
2584 if (mdb_layered_walk("avl", wsp) == -1) {
2585 mdb_warn("failed to walk 'avl'\n");
2586 return (WALK_ERR);
2589 return (WALK_NEXT);
2592 static int
2593 spa_walk_step(mdb_walk_state_t *wsp)
2595 return (wsp->walk_callback(wsp->walk_addr, NULL, wsp->walk_cbdata));
2599 * [addr]::walk zio
2601 * Walk all active zio_t structures on the system. This is simply a layered
2602 * walk on top of ::walk zio_cache, with the optional ability to limit the
2603 * structures to a particular pool.
2605 static int
2606 zio_walk_init(mdb_walk_state_t *wsp)
2608 wsp->walk_data = (void *)wsp->walk_addr;
2610 if (mdb_layered_walk("zio_cache", wsp) == -1) {
2611 mdb_warn("failed to walk 'zio_cache'\n");
2612 return (WALK_ERR);
2615 return (WALK_NEXT);
2618 static int
2619 zio_walk_step(mdb_walk_state_t *wsp)
2621 mdb_zio_t zio;
2622 uintptr_t spa = (uintptr_t)wsp->walk_data;
2624 if (mdb_ctf_vread(&zio, ZFS_STRUCT "zio", "mdb_zio_t",
2625 wsp->walk_addr, 0) == -1)
2626 return (WALK_ERR);
2628 if (spa != 0 && spa != zio.io_spa)
2629 return (WALK_NEXT);
2631 return (wsp->walk_callback(wsp->walk_addr, &zio, wsp->walk_cbdata));
2635 * [addr]::walk zio_root
2637 * Walk only root zio_t structures, optionally for a particular spa_t.
2639 static int
2640 zio_walk_root_step(mdb_walk_state_t *wsp)
2642 mdb_zio_t zio;
2643 uintptr_t spa = (uintptr_t)wsp->walk_data;
2645 if (mdb_ctf_vread(&zio, ZFS_STRUCT "zio", "mdb_zio_t",
2646 wsp->walk_addr, 0) == -1)
2647 return (WALK_ERR);
2649 if (spa != 0 && spa != zio.io_spa)
2650 return (WALK_NEXT);
2652 /* If the parent list is not empty, ignore */
2653 if (zio.io_parent_list.list_head.list_next !=
2654 wsp->walk_addr +
2655 mdb_ctf_offsetof_by_name(ZFS_STRUCT "zio", "io_parent_list") +
2656 mdb_ctf_offsetof_by_name("struct list", "list_head"))
2657 return (WALK_NEXT);
2659 return (wsp->walk_callback(wsp->walk_addr, &zio, wsp->walk_cbdata));
2663 * ::zfs_blkstats
2665 * -v print verbose per-level information
2668 static int
2669 zfs_blkstats(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
2671 boolean_t verbose = B_FALSE;
2672 zfs_all_blkstats_t stats;
2673 dmu_object_type_t t;
2674 zfs_blkstat_t *tzb;
2675 uint64_t ditto;
2676 dmu_object_type_info_t dmu_ot[DMU_OT_NUMTYPES + 10];
2677 /* +10 in case it grew */
2679 if (mdb_readvar(&dmu_ot, "dmu_ot") == -1) {
2680 mdb_warn("failed to read 'dmu_ot'");
2681 return (DCMD_ERR);
2684 if (mdb_getopts(argc, argv,
2685 'v', MDB_OPT_SETBITS, TRUE, &verbose,
2686 NULL) != argc)
2687 return (DCMD_USAGE);
2689 if (!(flags & DCMD_ADDRSPEC))
2690 return (DCMD_USAGE);
2692 if (GETMEMB(addr, "spa", spa_dsl_pool, addr) ||
2693 GETMEMB(addr, "dsl_pool", dp_blkstats, addr) ||
2694 mdb_vread(&stats, sizeof (zfs_all_blkstats_t), addr) == -1) {
2695 mdb_warn("failed to read data at %p;", addr);
2696 mdb_printf("maybe no stats? run \"zpool scrub\" first.");
2697 return (DCMD_ERR);
2700 tzb = &stats.zab_type[DN_MAX_LEVELS][DMU_OT_TOTAL];
2701 if (tzb->zb_gangs != 0) {
2702 mdb_printf("Ganged blocks: %llu\n",
2703 (longlong_t)tzb->zb_gangs);
2706 ditto = tzb->zb_ditto_2_of_2_samevdev + tzb->zb_ditto_2_of_3_samevdev +
2707 tzb->zb_ditto_3_of_3_samevdev;
2708 if (ditto != 0) {
2709 mdb_printf("Dittoed blocks on same vdev: %llu\n",
2710 (longlong_t)ditto);
2713 mdb_printf("\nBlocks\tLSIZE\tPSIZE\tASIZE"
2714 "\t avg\t comp\t%%Total\tType\n");
2716 for (t = 0; t <= DMU_OT_TOTAL; t++) {
2717 char csize[NICENUM_BUFLEN], lsize[NICENUM_BUFLEN];
2718 char psize[NICENUM_BUFLEN], asize[NICENUM_BUFLEN];
2719 char avg[NICENUM_BUFLEN];
2720 char comp[NICENUM_BUFLEN], pct[NICENUM_BUFLEN];
2721 char typename[64];
2722 int l;
2725 if (t == DMU_OT_DEFERRED)
2726 strcpy(typename, "deferred free");
2727 else if (t == DMU_OT_OTHER)
2728 strcpy(typename, "other");
2729 else if (t == DMU_OT_TOTAL)
2730 strcpy(typename, "Total");
2731 else if (mdb_readstr(typename, sizeof (typename),
2732 (uintptr_t)dmu_ot[t].ot_name) == -1) {
2733 mdb_warn("failed to read type name");
2734 return (DCMD_ERR);
2737 if (stats.zab_type[DN_MAX_LEVELS][t].zb_asize == 0)
2738 continue;
2740 for (l = -1; l < DN_MAX_LEVELS; l++) {
2741 int level = (l == -1 ? DN_MAX_LEVELS : l);
2742 zfs_blkstat_t *zb = &stats.zab_type[level][t];
2744 if (zb->zb_asize == 0)
2745 continue;
2748 * Don't print each level unless requested.
2750 if (!verbose && level != DN_MAX_LEVELS)
2751 continue;
2754 * If all the space is level 0, don't print the
2755 * level 0 separately.
2757 if (level == 0 && zb->zb_asize ==
2758 stats.zab_type[DN_MAX_LEVELS][t].zb_asize)
2759 continue;
2761 mdb_nicenum(zb->zb_count, csize);
2762 mdb_nicenum(zb->zb_lsize, lsize);
2763 mdb_nicenum(zb->zb_psize, psize);
2764 mdb_nicenum(zb->zb_asize, asize);
2765 mdb_nicenum(zb->zb_asize / zb->zb_count, avg);
2766 (void) snprintfrac(comp, NICENUM_BUFLEN,
2767 zb->zb_lsize, zb->zb_psize, 2);
2768 (void) snprintfrac(pct, NICENUM_BUFLEN,
2769 100 * zb->zb_asize, tzb->zb_asize, 2);
2771 mdb_printf("%6s\t%5s\t%5s\t%5s\t%5s"
2772 "\t%5s\t%6s\t",
2773 csize, lsize, psize, asize, avg, comp, pct);
2775 if (level == DN_MAX_LEVELS)
2776 mdb_printf("%s\n", typename);
2777 else
2778 mdb_printf(" L%d %s\n",
2779 level, typename);
2783 return (DCMD_OK);
2786 typedef struct mdb_reference {
2787 uintptr_t ref_holder;
2788 uintptr_t ref_removed;
2789 uint64_t ref_number;
2790 } mdb_reference_t;
2792 /* ARGSUSED */
2793 static int
2794 reference_cb(uintptr_t addr, const void *ignored, void *arg)
2796 mdb_reference_t ref;
2797 boolean_t holder_is_str = B_FALSE;
2798 char holder_str[128];
2799 boolean_t removed = (boolean_t)arg;
2801 if (mdb_ctf_vread(&ref, "reference_t", "mdb_reference_t", addr,
2802 0) == -1)
2803 return (DCMD_ERR);
2805 if (mdb_readstr(holder_str, sizeof (holder_str),
2806 ref.ref_holder) != -1)
2807 holder_is_str = strisprint(holder_str);
2809 if (removed)
2810 mdb_printf("removed ");
2811 mdb_printf("reference ");
2812 if (ref.ref_number != 1)
2813 mdb_printf("with count=%llu ", ref.ref_number);
2814 mdb_printf("with tag %lx", ref.ref_holder);
2815 if (holder_is_str)
2816 mdb_printf(" \"%s\"", holder_str);
2817 mdb_printf(", held at:\n");
2819 (void) mdb_call_dcmd("whatis", addr, DCMD_ADDRSPEC, 0, NULL);
2821 if (removed) {
2822 mdb_printf("removed at:\n");
2823 (void) mdb_call_dcmd("whatis", ref.ref_removed,
2824 DCMD_ADDRSPEC, 0, NULL);
2827 mdb_printf("\n");
2829 return (WALK_NEXT);
2832 typedef struct mdb_refcount {
2833 uint64_t rc_count;
2834 } mdb_refcount_t;
2836 typedef struct mdb_refcount_removed {
2837 uint64_t rc_removed_count;
2838 } mdb_refcount_removed_t;
2840 typedef struct mdb_refcount_tracked {
2841 boolean_t rc_tracked;
2842 } mdb_refcount_tracked_t;
2844 /* ARGSUSED */
2845 static int
2846 refcount(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
2848 mdb_refcount_t rc;
2849 mdb_refcount_removed_t rcr;
2850 mdb_refcount_tracked_t rct;
2851 int off;
2852 boolean_t released = B_FALSE;
2854 if (!(flags & DCMD_ADDRSPEC))
2855 return (DCMD_USAGE);
2857 if (mdb_getopts(argc, argv,
2858 'r', MDB_OPT_SETBITS, B_TRUE, &released,
2859 NULL) != argc)
2860 return (DCMD_USAGE);
2862 if (mdb_ctf_vread(&rc, "refcount_t", "mdb_refcount_t", addr,
2863 0) == -1)
2864 return (DCMD_ERR);
2866 if (mdb_ctf_vread(&rcr, "refcount_t", "mdb_refcount_removed_t", addr,
2867 MDB_CTF_VREAD_QUIET) == -1) {
2868 mdb_printf("refcount_t at %p has %llu holds (untracked)\n",
2869 addr, (longlong_t)rc.rc_count);
2870 return (DCMD_OK);
2873 if (mdb_ctf_vread(&rct, "refcount_t", "mdb_refcount_tracked_t", addr,
2874 MDB_CTF_VREAD_QUIET) == -1) {
2875 /* If this is an old target, it might be tracked. */
2876 rct.rc_tracked = B_TRUE;
2879 mdb_printf("refcount_t at %p has %llu current holds, "
2880 "%llu recently released holds\n",
2881 addr, (longlong_t)rc.rc_count, (longlong_t)rcr.rc_removed_count);
2883 if (rct.rc_tracked && rc.rc_count > 0)
2884 mdb_printf("current holds:\n");
2885 off = mdb_ctf_offsetof_by_name("refcount_t", "rc_list");
2886 if (off == -1)
2887 return (DCMD_ERR);
2888 mdb_pwalk("list", reference_cb, (void*)B_FALSE, addr + off);
2890 if (released && rcr.rc_removed_count > 0) {
2891 mdb_printf("released holds:\n");
2893 off = mdb_ctf_offsetof_by_name("refcount_t", "rc_removed");
2894 if (off == -1)
2895 return (DCMD_ERR);
2896 mdb_pwalk("list", reference_cb, (void*)B_TRUE, addr + off);
2899 return (DCMD_OK);
2902 /* ARGSUSED */
2903 static int
2904 sa_attr_table(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
2906 sa_attr_table_t *table;
2907 sa_os_t sa_os;
2908 char *name;
2909 int i;
2911 if (mdb_vread(&sa_os, sizeof (sa_os_t), addr) == -1) {
2912 mdb_warn("failed to read sa_os at %p", addr);
2913 return (DCMD_ERR);
2916 table = mdb_alloc(sizeof (sa_attr_table_t) * sa_os.sa_num_attrs,
2917 UM_SLEEP | UM_GC);
2918 name = mdb_alloc(MAXPATHLEN, UM_SLEEP | UM_GC);
2920 if (mdb_vread(table, sizeof (sa_attr_table_t) * sa_os.sa_num_attrs,
2921 (uintptr_t)sa_os.sa_attr_table) == -1) {
2922 mdb_warn("failed to read sa_os at %p", addr);
2923 return (DCMD_ERR);
2926 mdb_printf("%<u>%-10s %-10s %-10s %-10s %s%</u>\n",
2927 "ATTR ID", "REGISTERED", "LENGTH", "BSWAP", "NAME");
2928 for (i = 0; i != sa_os.sa_num_attrs; i++) {
2929 mdb_readstr(name, MAXPATHLEN, (uintptr_t)table[i].sa_name);
2930 mdb_printf("%5x %8x %8x %8x %-s\n",
2931 (int)table[i].sa_attr, (int)table[i].sa_registered,
2932 (int)table[i].sa_length, table[i].sa_byteswap, name);
2935 return (DCMD_OK);
2938 static int
2939 sa_get_off_table(uintptr_t addr, uint32_t **off_tab, int attr_count)
2941 uintptr_t idx_table;
2943 if (GETMEMB(addr, "sa_idx_tab", sa_idx_tab, idx_table)) {
2944 mdb_printf("can't find offset table in sa_idx_tab\n");
2945 return (-1);
2948 *off_tab = mdb_alloc(attr_count * sizeof (uint32_t),
2949 UM_SLEEP | UM_GC);
2951 if (mdb_vread(*off_tab,
2952 attr_count * sizeof (uint32_t), idx_table) == -1) {
2953 mdb_warn("failed to attribute offset table %p", idx_table);
2954 return (-1);
2957 return (DCMD_OK);
2960 /*ARGSUSED*/
2961 static int
2962 sa_attr_print(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
2964 uint32_t *offset_tab;
2965 int attr_count;
2966 uint64_t attr_id;
2967 uintptr_t attr_addr;
2968 uintptr_t bonus_tab, spill_tab;
2969 uintptr_t db_bonus, db_spill;
2970 uintptr_t os, os_sa;
2971 uintptr_t db_data;
2973 if (argc != 1)
2974 return (DCMD_USAGE);
2976 if (argv[0].a_type == MDB_TYPE_STRING)
2977 attr_id = mdb_strtoull(argv[0].a_un.a_str);
2978 else
2979 return (DCMD_USAGE);
2981 if (GETMEMB(addr, "sa_handle", sa_bonus_tab, bonus_tab) ||
2982 GETMEMB(addr, "sa_handle", sa_spill_tab, spill_tab) ||
2983 GETMEMB(addr, "sa_handle", sa_os, os) ||
2984 GETMEMB(addr, "sa_handle", sa_bonus, db_bonus) ||
2985 GETMEMB(addr, "sa_handle", sa_spill, db_spill)) {
2986 mdb_printf("Can't find necessary information in sa_handle "
2987 "in sa_handle\n");
2988 return (DCMD_ERR);
2991 if (GETMEMB(os, "objset", os_sa, os_sa)) {
2992 mdb_printf("Can't find os_sa in objset\n");
2993 return (DCMD_ERR);
2996 if (GETMEMB(os_sa, "sa_os", sa_num_attrs, attr_count)) {
2997 mdb_printf("Can't find sa_num_attrs\n");
2998 return (DCMD_ERR);
3001 if (attr_id > attr_count) {
3002 mdb_printf("attribute id number is out of range\n");
3003 return (DCMD_ERR);
3006 if (bonus_tab) {
3007 if (sa_get_off_table(bonus_tab, &offset_tab,
3008 attr_count) == -1) {
3009 return (DCMD_ERR);
3012 if (GETMEMB(db_bonus, "dmu_buf", db_data, db_data)) {
3013 mdb_printf("can't find db_data in bonus dbuf\n");
3014 return (DCMD_ERR);
3018 if (bonus_tab && !TOC_ATTR_PRESENT(offset_tab[attr_id]) &&
3019 spill_tab == (uintptr_t)NULL) {
3020 mdb_printf("Attribute does not exist\n");
3021 return (DCMD_ERR);
3022 } else if (!TOC_ATTR_PRESENT(offset_tab[attr_id]) && spill_tab) {
3023 if (sa_get_off_table(spill_tab, &offset_tab,
3024 attr_count) == -1) {
3025 return (DCMD_ERR);
3027 if (GETMEMB(db_spill, "dmu_buf", db_data, db_data)) {
3028 mdb_printf("can't find db_data in spill dbuf\n");
3029 return (DCMD_ERR);
3031 if (!TOC_ATTR_PRESENT(offset_tab[attr_id])) {
3032 mdb_printf("Attribute does not exist\n");
3033 return (DCMD_ERR);
3036 attr_addr = db_data + TOC_OFF(offset_tab[attr_id]);
3037 mdb_printf("%p\n", attr_addr);
3038 return (DCMD_OK);
3041 /* ARGSUSED */
3042 static int
3043 zfs_ace_print_common(uintptr_t addr, uint_t flags,
3044 uint64_t id, uint32_t access_mask, uint16_t ace_flags,
3045 uint16_t ace_type, int verbose)
3047 if (DCMD_HDRSPEC(flags) && !verbose)
3048 mdb_printf("%<u>%-?s %-8s %-8s %-8s %s%</u>\n",
3049 "ADDR", "FLAGS", "MASK", "TYPE", "ID");
3051 if (!verbose) {
3052 mdb_printf("%0?p %-8x %-8x %-8x %-llx\n", addr,
3053 ace_flags, access_mask, ace_type, id);
3054 return (DCMD_OK);
3057 switch (ace_flags & ACE_TYPE_FLAGS) {
3058 case ACE_OWNER:
3059 mdb_printf("owner@:");
3060 break;
3061 case (ACE_IDENTIFIER_GROUP | ACE_GROUP):
3062 mdb_printf("group@:");
3063 break;
3064 case ACE_EVERYONE:
3065 mdb_printf("everyone@:");
3066 break;
3067 case ACE_IDENTIFIER_GROUP:
3068 mdb_printf("group:%llx:", (u_longlong_t)id);
3069 break;
3070 case 0: /* User entry */
3071 mdb_printf("user:%llx:", (u_longlong_t)id);
3072 break;
3075 /* print out permission mask */
3076 if (access_mask & ACE_READ_DATA)
3077 mdb_printf("r");
3078 else
3079 mdb_printf("-");
3080 if (access_mask & ACE_WRITE_DATA)
3081 mdb_printf("w");
3082 else
3083 mdb_printf("-");
3084 if (access_mask & ACE_EXECUTE)
3085 mdb_printf("x");
3086 else
3087 mdb_printf("-");
3088 if (access_mask & ACE_APPEND_DATA)
3089 mdb_printf("p");
3090 else
3091 mdb_printf("-");
3092 if (access_mask & ACE_DELETE)
3093 mdb_printf("d");
3094 else
3095 mdb_printf("-");
3096 if (access_mask & ACE_DELETE_CHILD)
3097 mdb_printf("D");
3098 else
3099 mdb_printf("-");
3100 if (access_mask & ACE_READ_ATTRIBUTES)
3101 mdb_printf("a");
3102 else
3103 mdb_printf("-");
3104 if (access_mask & ACE_WRITE_ATTRIBUTES)
3105 mdb_printf("A");
3106 else
3107 mdb_printf("-");
3108 if (access_mask & ACE_READ_NAMED_ATTRS)
3109 mdb_printf("R");
3110 else
3111 mdb_printf("-");
3112 if (access_mask & ACE_WRITE_NAMED_ATTRS)
3113 mdb_printf("W");
3114 else
3115 mdb_printf("-");
3116 if (access_mask & ACE_READ_ACL)
3117 mdb_printf("c");
3118 else
3119 mdb_printf("-");
3120 if (access_mask & ACE_WRITE_ACL)
3121 mdb_printf("C");
3122 else
3123 mdb_printf("-");
3124 if (access_mask & ACE_WRITE_OWNER)
3125 mdb_printf("o");
3126 else
3127 mdb_printf("-");
3128 if (access_mask & ACE_SYNCHRONIZE)
3129 mdb_printf("s");
3130 else
3131 mdb_printf("-");
3133 mdb_printf(":");
3135 /* Print out inheritance flags */
3136 if (ace_flags & ACE_FILE_INHERIT_ACE)
3137 mdb_printf("f");
3138 else
3139 mdb_printf("-");
3140 if (ace_flags & ACE_DIRECTORY_INHERIT_ACE)
3141 mdb_printf("d");
3142 else
3143 mdb_printf("-");
3144 if (ace_flags & ACE_INHERIT_ONLY_ACE)
3145 mdb_printf("i");
3146 else
3147 mdb_printf("-");
3148 if (ace_flags & ACE_NO_PROPAGATE_INHERIT_ACE)
3149 mdb_printf("n");
3150 else
3151 mdb_printf("-");
3152 if (ace_flags & ACE_SUCCESSFUL_ACCESS_ACE_FLAG)
3153 mdb_printf("S");
3154 else
3155 mdb_printf("-");
3156 if (ace_flags & ACE_FAILED_ACCESS_ACE_FLAG)
3157 mdb_printf("F");
3158 else
3159 mdb_printf("-");
3160 if (ace_flags & ACE_INHERITED_ACE)
3161 mdb_printf("I");
3162 else
3163 mdb_printf("-");
3165 switch (ace_type) {
3166 case ACE_ACCESS_ALLOWED_ACE_TYPE:
3167 mdb_printf(":allow\n");
3168 break;
3169 case ACE_ACCESS_DENIED_ACE_TYPE:
3170 mdb_printf(":deny\n");
3171 break;
3172 case ACE_SYSTEM_AUDIT_ACE_TYPE:
3173 mdb_printf(":audit\n");
3174 break;
3175 case ACE_SYSTEM_ALARM_ACE_TYPE:
3176 mdb_printf(":alarm\n");
3177 break;
3178 default:
3179 mdb_printf(":?\n");
3181 return (DCMD_OK);
3184 /* ARGSUSED */
3185 static int
3186 zfs_ace_print(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
3188 zfs_ace_t zace;
3189 int verbose = FALSE;
3190 uint64_t id;
3192 if (!(flags & DCMD_ADDRSPEC))
3193 return (DCMD_USAGE);
3195 if (mdb_getopts(argc, argv,
3196 'v', MDB_OPT_SETBITS, TRUE, &verbose, TRUE, NULL) != argc)
3197 return (DCMD_USAGE);
3199 if (mdb_vread(&zace, sizeof (zfs_ace_t), addr) == -1) {
3200 mdb_warn("failed to read zfs_ace_t");
3201 return (DCMD_ERR);
3204 if ((zace.z_hdr.z_flags & ACE_TYPE_FLAGS) == 0 ||
3205 (zace.z_hdr.z_flags & ACE_TYPE_FLAGS) == ACE_IDENTIFIER_GROUP)
3206 id = zace.z_fuid;
3207 else
3208 id = -1;
3210 return (zfs_ace_print_common(addr, flags, id, zace.z_hdr.z_access_mask,
3211 zace.z_hdr.z_flags, zace.z_hdr.z_type, verbose));
3214 /* ARGSUSED */
3215 static int
3216 zfs_ace0_print(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
3218 ace_t ace;
3219 uint64_t id;
3220 int verbose = FALSE;
3222 if (!(flags & DCMD_ADDRSPEC))
3223 return (DCMD_USAGE);
3225 if (mdb_getopts(argc, argv,
3226 'v', MDB_OPT_SETBITS, TRUE, &verbose, TRUE, NULL) != argc)
3227 return (DCMD_USAGE);
3229 if (mdb_vread(&ace, sizeof (ace_t), addr) == -1) {
3230 mdb_warn("failed to read ace_t");
3231 return (DCMD_ERR);
3234 if ((ace.a_flags & ACE_TYPE_FLAGS) == 0 ||
3235 (ace.a_flags & ACE_TYPE_FLAGS) == ACE_IDENTIFIER_GROUP)
3236 id = ace.a_who;
3237 else
3238 id = -1;
3240 return (zfs_ace_print_common(addr, flags, id, ace.a_access_mask,
3241 ace.a_flags, ace.a_type, verbose));
3244 typedef struct acl_dump_args {
3245 int a_argc;
3246 const mdb_arg_t *a_argv;
3247 uint16_t a_version;
3248 int a_flags;
3249 } acl_dump_args_t;
3251 /* ARGSUSED */
3252 static int
3253 acl_aces_cb(uintptr_t addr, const void *unknown, void *arg)
3255 acl_dump_args_t *acl_args = (acl_dump_args_t *)arg;
3257 if (acl_args->a_version == 1) {
3258 if (mdb_call_dcmd("zfs_ace", addr,
3259 DCMD_ADDRSPEC|acl_args->a_flags, acl_args->a_argc,
3260 acl_args->a_argv) != DCMD_OK) {
3261 return (WALK_ERR);
3263 } else {
3264 if (mdb_call_dcmd("zfs_ace0", addr,
3265 DCMD_ADDRSPEC|acl_args->a_flags, acl_args->a_argc,
3266 acl_args->a_argv) != DCMD_OK) {
3267 return (WALK_ERR);
3270 acl_args->a_flags = DCMD_LOOP;
3271 return (WALK_NEXT);
3274 /* ARGSUSED */
3275 static int
3276 acl_cb(uintptr_t addr, const void *unknown, void *arg)
3278 acl_dump_args_t *acl_args = (acl_dump_args_t *)arg;
3280 if (acl_args->a_version == 1) {
3281 if (mdb_pwalk("zfs_acl_node_aces", acl_aces_cb,
3282 arg, addr) != 0) {
3283 mdb_warn("can't walk ACEs");
3284 return (DCMD_ERR);
3286 } else {
3287 if (mdb_pwalk("zfs_acl_node_aces0", acl_aces_cb,
3288 arg, addr) != 0) {
3289 mdb_warn("can't walk ACEs");
3290 return (DCMD_ERR);
3293 return (WALK_NEXT);
3296 /* ARGSUSED */
3297 static int
3298 zfs_acl_dump(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
3300 zfs_acl_t zacl;
3301 int verbose = FALSE;
3302 acl_dump_args_t acl_args;
3304 if (!(flags & DCMD_ADDRSPEC))
3305 return (DCMD_USAGE);
3307 if (mdb_getopts(argc, argv,
3308 'v', MDB_OPT_SETBITS, TRUE, &verbose, TRUE, NULL) != argc)
3309 return (DCMD_USAGE);
3311 if (mdb_vread(&zacl, sizeof (zfs_acl_t), addr) == -1) {
3312 mdb_warn("failed to read zfs_acl_t");
3313 return (DCMD_ERR);
3316 acl_args.a_argc = argc;
3317 acl_args.a_argv = argv;
3318 acl_args.a_version = zacl.z_version;
3319 acl_args.a_flags = DCMD_LOOPFIRST;
3321 if (mdb_pwalk("zfs_acl_node", acl_cb, &acl_args, addr) != 0) {
3322 mdb_warn("can't walk ACL");
3323 return (DCMD_ERR);
3326 return (DCMD_OK);
3329 /* ARGSUSED */
3330 static int
3331 zfs_acl_node_walk_init(mdb_walk_state_t *wsp)
3333 if (wsp->walk_addr == (uintptr_t)NULL) {
3334 mdb_warn("must supply address of zfs_acl_node_t\n");
3335 return (WALK_ERR);
3338 wsp->walk_addr +=
3339 mdb_ctf_offsetof_by_name(ZFS_STRUCT "zfs_acl", "z_acl");
3341 if (mdb_layered_walk("list", wsp) == -1) {
3342 mdb_warn("failed to walk 'list'\n");
3343 return (WALK_ERR);
3346 return (WALK_NEXT);
3349 static int
3350 zfs_acl_node_walk_step(mdb_walk_state_t *wsp)
3352 zfs_acl_node_t aclnode;
3354 if (mdb_vread(&aclnode, sizeof (zfs_acl_node_t),
3355 wsp->walk_addr) == -1) {
3356 mdb_warn("failed to read zfs_acl_node at %p", wsp->walk_addr);
3357 return (WALK_ERR);
3360 return (wsp->walk_callback(wsp->walk_addr, &aclnode, wsp->walk_cbdata));
3363 typedef struct ace_walk_data {
3364 int ace_count;
3365 int ace_version;
3366 } ace_walk_data_t;
3368 static int
3369 zfs_aces_walk_init_common(mdb_walk_state_t *wsp, int version,
3370 int ace_count, uintptr_t ace_data)
3372 ace_walk_data_t *ace_walk_data;
3374 if (wsp->walk_addr == (uintptr_t)NULL) {
3375 mdb_warn("must supply address of zfs_acl_node_t\n");
3376 return (WALK_ERR);
3379 ace_walk_data = mdb_alloc(sizeof (ace_walk_data_t), UM_SLEEP | UM_GC);
3381 ace_walk_data->ace_count = ace_count;
3382 ace_walk_data->ace_version = version;
3384 wsp->walk_addr = ace_data;
3385 wsp->walk_data = ace_walk_data;
3387 return (WALK_NEXT);
3390 static int
3391 zfs_acl_node_aces_walk_init_common(mdb_walk_state_t *wsp, int version)
3393 static int gotid;
3394 static mdb_ctf_id_t acl_id;
3395 int z_ace_count;
3396 uintptr_t z_acldata;
3398 if (!gotid) {
3399 if (mdb_ctf_lookup_by_name("struct zfs_acl_node",
3400 &acl_id) == -1) {
3401 mdb_warn("couldn't find struct zfs_acl_node");
3402 return (DCMD_ERR);
3404 gotid = TRUE;
3407 if (GETMEMBID(wsp->walk_addr, &acl_id, z_ace_count, z_ace_count)) {
3408 return (DCMD_ERR);
3410 if (GETMEMBID(wsp->walk_addr, &acl_id, z_acldata, z_acldata)) {
3411 return (DCMD_ERR);
3414 return (zfs_aces_walk_init_common(wsp, version,
3415 z_ace_count, z_acldata));
3418 /* ARGSUSED */
3419 static int
3420 zfs_acl_node_aces_walk_init(mdb_walk_state_t *wsp)
3422 return (zfs_acl_node_aces_walk_init_common(wsp, 1));
3425 /* ARGSUSED */
3426 static int
3427 zfs_acl_node_aces0_walk_init(mdb_walk_state_t *wsp)
3429 return (zfs_acl_node_aces_walk_init_common(wsp, 0));
3432 static int
3433 zfs_aces_walk_step(mdb_walk_state_t *wsp)
3435 ace_walk_data_t *ace_data = wsp->walk_data;
3436 zfs_ace_t zace;
3437 ace_t *acep;
3438 int status;
3439 int entry_type;
3440 int allow_type;
3441 uintptr_t ptr;
3443 if (ace_data->ace_count == 0)
3444 return (WALK_DONE);
3446 if (mdb_vread(&zace, sizeof (zfs_ace_t), wsp->walk_addr) == -1) {
3447 mdb_warn("failed to read zfs_ace_t at %#lx",
3448 wsp->walk_addr);
3449 return (WALK_ERR);
3452 switch (ace_data->ace_version) {
3453 case 0:
3454 acep = (ace_t *)&zace;
3455 entry_type = acep->a_flags & ACE_TYPE_FLAGS;
3456 allow_type = acep->a_type;
3457 break;
3458 case 1:
3459 entry_type = zace.z_hdr.z_flags & ACE_TYPE_FLAGS;
3460 allow_type = zace.z_hdr.z_type;
3461 break;
3462 default:
3463 return (WALK_ERR);
3466 ptr = (uintptr_t)wsp->walk_addr;
3467 switch (entry_type) {
3468 case ACE_OWNER:
3469 case ACE_EVERYONE:
3470 case (ACE_IDENTIFIER_GROUP | ACE_GROUP):
3471 ptr += ace_data->ace_version == 0 ?
3472 sizeof (ace_t) : sizeof (zfs_ace_hdr_t);
3473 break;
3474 case ACE_IDENTIFIER_GROUP:
3475 default:
3476 switch (allow_type) {
3477 case ACE_ACCESS_ALLOWED_OBJECT_ACE_TYPE:
3478 case ACE_ACCESS_DENIED_OBJECT_ACE_TYPE:
3479 case ACE_SYSTEM_AUDIT_OBJECT_ACE_TYPE:
3480 case ACE_SYSTEM_ALARM_OBJECT_ACE_TYPE:
3481 ptr += ace_data->ace_version == 0 ?
3482 sizeof (ace_t) : sizeof (zfs_object_ace_t);
3483 break;
3484 default:
3485 ptr += ace_data->ace_version == 0 ?
3486 sizeof (ace_t) : sizeof (zfs_ace_t);
3487 break;
3491 ace_data->ace_count--;
3492 status = wsp->walk_callback(wsp->walk_addr,
3493 (void *)(uintptr_t)&zace, wsp->walk_cbdata);
3495 wsp->walk_addr = ptr;
3496 return (status);
3499 typedef struct mdb_zfs_rrwlock {
3500 uintptr_t rr_writer;
3501 boolean_t rr_writer_wanted;
3502 } mdb_zfs_rrwlock_t;
3504 static uint_t rrw_key;
3506 /* ARGSUSED */
3507 static int
3508 rrwlock(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
3510 mdb_zfs_rrwlock_t rrw;
3512 if (rrw_key == 0) {
3513 if (mdb_ctf_readsym(&rrw_key, "uint_t", "rrw_tsd_key", 0) == -1)
3514 return (DCMD_ERR);
3517 if (mdb_ctf_vread(&rrw, "rrwlock_t", "mdb_zfs_rrwlock_t", addr,
3518 0) == -1)
3519 return (DCMD_ERR);
3521 if (rrw.rr_writer != 0) {
3522 mdb_printf("write lock held by thread %lx\n", rrw.rr_writer);
3523 return (DCMD_OK);
3526 if (rrw.rr_writer_wanted) {
3527 mdb_printf("writer wanted\n");
3530 mdb_printf("anonymous references:\n");
3531 (void) mdb_call_dcmd("refcount", addr +
3532 mdb_ctf_offsetof_by_name(ZFS_STRUCT "rrwlock", "rr_anon_rcount"),
3533 DCMD_ADDRSPEC, 0, NULL);
3535 mdb_printf("linked references:\n");
3536 (void) mdb_call_dcmd("refcount", addr +
3537 mdb_ctf_offsetof_by_name(ZFS_STRUCT "rrwlock", "rr_linked_rcount"),
3538 DCMD_ADDRSPEC, 0, NULL);
3541 * XXX This should find references from
3542 * "::walk thread | ::tsd -v <rrw_key>", but there is no support
3543 * for programmatic consumption of dcmds, so this would be
3544 * difficult, potentially requiring reimplementing ::tsd (both
3545 * user and kernel versions) in this MDB module.
3548 return (DCMD_OK);
3551 typedef struct mdb_arc_buf_hdr_t {
3552 uint16_t b_psize;
3553 uint16_t b_lsize;
3554 struct {
3555 uint32_t b_bufcnt;
3556 uintptr_t b_state;
3557 } b_l1hdr;
3558 } mdb_arc_buf_hdr_t;
3560 enum arc_cflags {
3561 ARC_CFLAG_VERBOSE = 1 << 0,
3562 ARC_CFLAG_ANON = 1 << 1,
3563 ARC_CFLAG_MRU = 1 << 2,
3564 ARC_CFLAG_MFU = 1 << 3,
3565 ARC_CFLAG_BUFS = 1 << 4,
3568 typedef struct arc_compression_stats_data {
3569 GElf_Sym anon_sym; /* ARC_anon symbol */
3570 GElf_Sym mru_sym; /* ARC_mru symbol */
3571 GElf_Sym mrug_sym; /* ARC_mru_ghost symbol */
3572 GElf_Sym mfu_sym; /* ARC_mfu symbol */
3573 GElf_Sym mfug_sym; /* ARC_mfu_ghost symbol */
3574 GElf_Sym l2c_sym; /* ARC_l2c_only symbol */
3575 uint64_t *anon_c_hist; /* histogram of compressed sizes in anon */
3576 uint64_t *anon_u_hist; /* histogram of uncompressed sizes in anon */
3577 uint64_t *anon_bufs; /* histogram of buffer counts in anon state */
3578 uint64_t *mru_c_hist; /* histogram of compressed sizes in mru */
3579 uint64_t *mru_u_hist; /* histogram of uncompressed sizes in mru */
3580 uint64_t *mru_bufs; /* histogram of buffer counts in mru */
3581 uint64_t *mfu_c_hist; /* histogram of compressed sizes in mfu */
3582 uint64_t *mfu_u_hist; /* histogram of uncompressed sizes in mfu */
3583 uint64_t *mfu_bufs; /* histogram of buffer counts in mfu */
3584 uint64_t *all_c_hist; /* histogram of compressed anon + mru + mfu */
3585 uint64_t *all_u_hist; /* histogram of uncompressed anon + mru + mfu */
3586 uint64_t *all_bufs; /* histogram of buffer counts in all states */
3587 int arc_cflags; /* arc compression flags, specified by user */
3588 int hist_nbuckets; /* number of buckets in each histogram */
3589 } arc_compression_stats_data_t;
3592 highbit64(uint64_t i)
3594 int h = 1;
3596 if (i == 0)
3597 return (0);
3598 if (i & 0xffffffff00000000ULL) {
3599 h += 32; i >>= 32;
3601 if (i & 0xffff0000) {
3602 h += 16; i >>= 16;
3604 if (i & 0xff00) {
3605 h += 8; i >>= 8;
3607 if (i & 0xf0) {
3608 h += 4; i >>= 4;
3610 if (i & 0xc) {
3611 h += 2; i >>= 2;
3613 if (i & 0x2) {
3614 h += 1;
3616 return (h);
3619 /* ARGSUSED */
3620 static int
3621 arc_compression_stats_cb(uintptr_t addr, const void *unknown, void *arg)
3623 arc_compression_stats_data_t *data = arg;
3624 mdb_arc_buf_hdr_t hdr;
3625 int cbucket, ubucket, bufcnt;
3627 if (mdb_ctf_vread(&hdr, "arc_buf_hdr_t", "mdb_arc_buf_hdr_t",
3628 addr, 0) == -1) {
3629 return (WALK_ERR);
3633 * Headers in the ghost states, or the l2c_only state don't have
3634 * arc buffers linked off of them. Thus, their compressed size
3635 * is meaningless, so we skip these from the stats.
3637 if (hdr.b_l1hdr.b_state == data->mrug_sym.st_value ||
3638 hdr.b_l1hdr.b_state == data->mfug_sym.st_value ||
3639 hdr.b_l1hdr.b_state == data->l2c_sym.st_value) {
3640 return (WALK_NEXT);
3644 * The physical size (compressed) and logical size
3645 * (uncompressed) are in units of SPA_MINBLOCKSIZE. By default,
3646 * we use the log2 of this value (rounded down to the nearest
3647 * integer) to determine the bucket to assign this header to.
3648 * Thus, the histogram is logarithmic with respect to the size
3649 * of the header. For example, the following is a mapping of the
3650 * bucket numbers and the range of header sizes they correspond to:
3652 * 0: 0 byte headers
3653 * 1: 512 byte headers
3654 * 2: [1024 - 2048) byte headers
3655 * 3: [2048 - 4096) byte headers
3656 * 4: [4096 - 8192) byte headers
3657 * 5: [8192 - 16394) byte headers
3658 * 6: [16384 - 32768) byte headers
3659 * 7: [32768 - 65536) byte headers
3660 * 8: [65536 - 131072) byte headers
3661 * 9: 131072 byte headers
3663 * If the ARC_CFLAG_VERBOSE flag was specified, we use the
3664 * physical and logical sizes directly. Thus, the histogram will
3665 * no longer be logarithmic; instead it will be linear with
3666 * respect to the size of the header. The following is a mapping
3667 * of the first many bucket numbers and the header size they
3668 * correspond to:
3670 * 0: 0 byte headers
3671 * 1: 512 byte headers
3672 * 2: 1024 byte headers
3673 * 3: 1536 byte headers
3674 * 4: 2048 byte headers
3675 * 5: 2560 byte headers
3676 * 6: 3072 byte headers
3678 * And so on. Keep in mind that a range of sizes isn't used in
3679 * the case of linear scale because the headers can only
3680 * increment or decrement in sizes of 512 bytes. So, it's not
3681 * possible for a header to be sized in between whats listed
3682 * above.
3684 * Also, the above mapping values were calculated assuming a
3685 * SPA_MINBLOCKSHIFT of 512 bytes and a SPA_MAXBLOCKSIZE of 128K.
3688 if (data->arc_cflags & ARC_CFLAG_VERBOSE) {
3689 cbucket = hdr.b_psize;
3690 ubucket = hdr.b_lsize;
3691 } else {
3692 cbucket = highbit64(hdr.b_psize);
3693 ubucket = highbit64(hdr.b_lsize);
3696 bufcnt = hdr.b_l1hdr.b_bufcnt;
3697 if (bufcnt >= data->hist_nbuckets)
3698 bufcnt = data->hist_nbuckets - 1;
3700 /* Ensure we stay within the bounds of the histogram array */
3701 ASSERT3U(cbucket, <, data->hist_nbuckets);
3702 ASSERT3U(ubucket, <, data->hist_nbuckets);
3704 if (hdr.b_l1hdr.b_state == data->anon_sym.st_value) {
3705 data->anon_c_hist[cbucket]++;
3706 data->anon_u_hist[ubucket]++;
3707 data->anon_bufs[bufcnt]++;
3708 } else if (hdr.b_l1hdr.b_state == data->mru_sym.st_value) {
3709 data->mru_c_hist[cbucket]++;
3710 data->mru_u_hist[ubucket]++;
3711 data->mru_bufs[bufcnt]++;
3712 } else if (hdr.b_l1hdr.b_state == data->mfu_sym.st_value) {
3713 data->mfu_c_hist[cbucket]++;
3714 data->mfu_u_hist[ubucket]++;
3715 data->mfu_bufs[bufcnt]++;
3718 data->all_c_hist[cbucket]++;
3719 data->all_u_hist[ubucket]++;
3720 data->all_bufs[bufcnt]++;
3722 return (WALK_NEXT);
3725 /* ARGSUSED */
3726 static int
3727 arc_compression_stats(uintptr_t addr, uint_t flags, int argc,
3728 const mdb_arg_t *argv)
3730 arc_compression_stats_data_t data = { 0 };
3731 unsigned int max_shifted = SPA_MAXBLOCKSIZE >> SPA_MINBLOCKSHIFT;
3732 unsigned int hist_size;
3733 char range[32];
3734 int rc = DCMD_OK;
3736 if (mdb_getopts(argc, argv,
3737 'v', MDB_OPT_SETBITS, ARC_CFLAG_VERBOSE, &data.arc_cflags,
3738 'a', MDB_OPT_SETBITS, ARC_CFLAG_ANON, &data.arc_cflags,
3739 'b', MDB_OPT_SETBITS, ARC_CFLAG_BUFS, &data.arc_cflags,
3740 'r', MDB_OPT_SETBITS, ARC_CFLAG_MRU, &data.arc_cflags,
3741 'f', MDB_OPT_SETBITS, ARC_CFLAG_MFU, &data.arc_cflags) != argc)
3742 return (DCMD_USAGE);
3744 if (mdb_lookup_by_obj(ZFS_OBJ_NAME, "ARC_anon", &data.anon_sym) ||
3745 mdb_lookup_by_obj(ZFS_OBJ_NAME, "ARC_mru", &data.mru_sym) ||
3746 mdb_lookup_by_obj(ZFS_OBJ_NAME, "ARC_mru_ghost", &data.mrug_sym) ||
3747 mdb_lookup_by_obj(ZFS_OBJ_NAME, "ARC_mfu", &data.mfu_sym) ||
3748 mdb_lookup_by_obj(ZFS_OBJ_NAME, "ARC_mfu_ghost", &data.mfug_sym) ||
3749 mdb_lookup_by_obj(ZFS_OBJ_NAME, "ARC_l2c_only", &data.l2c_sym)) {
3750 mdb_warn("can't find arc state symbol");
3751 return (DCMD_ERR);
3755 * Determine the maximum expected size for any header, and use
3756 * this to determine the number of buckets needed for each
3757 * histogram. If ARC_CFLAG_VERBOSE is specified, this value is
3758 * used directly; otherwise the log2 of the maximum size is
3759 * used. Thus, if using a log2 scale there's a maximum of 10
3760 * possible buckets, while the linear scale (when using
3761 * ARC_CFLAG_VERBOSE) has a maximum of 257 buckets.
3763 if (data.arc_cflags & ARC_CFLAG_VERBOSE)
3764 data.hist_nbuckets = max_shifted + 1;
3765 else
3766 data.hist_nbuckets = highbit64(max_shifted) + 1;
3768 hist_size = sizeof (uint64_t) * data.hist_nbuckets;
3770 data.anon_c_hist = mdb_zalloc(hist_size, UM_SLEEP);
3771 data.anon_u_hist = mdb_zalloc(hist_size, UM_SLEEP);
3772 data.anon_bufs = mdb_zalloc(hist_size, UM_SLEEP);
3774 data.mru_c_hist = mdb_zalloc(hist_size, UM_SLEEP);
3775 data.mru_u_hist = mdb_zalloc(hist_size, UM_SLEEP);
3776 data.mru_bufs = mdb_zalloc(hist_size, UM_SLEEP);
3778 data.mfu_c_hist = mdb_zalloc(hist_size, UM_SLEEP);
3779 data.mfu_u_hist = mdb_zalloc(hist_size, UM_SLEEP);
3780 data.mfu_bufs = mdb_zalloc(hist_size, UM_SLEEP);
3782 data.all_c_hist = mdb_zalloc(hist_size, UM_SLEEP);
3783 data.all_u_hist = mdb_zalloc(hist_size, UM_SLEEP);
3784 data.all_bufs = mdb_zalloc(hist_size, UM_SLEEP);
3786 if (mdb_walk("arc_buf_hdr_t_full", arc_compression_stats_cb,
3787 &data) != 0) {
3788 mdb_warn("can't walk arc_buf_hdr's");
3789 rc = DCMD_ERR;
3790 goto out;
3793 if (data.arc_cflags & ARC_CFLAG_VERBOSE) {
3794 rc = mdb_snprintf(range, sizeof (range),
3795 "[n*%llu, (n+1)*%llu)", SPA_MINBLOCKSIZE,
3796 SPA_MINBLOCKSIZE);
3797 } else {
3798 rc = mdb_snprintf(range, sizeof (range),
3799 "[2^(n-1)*%llu, 2^n*%llu)", SPA_MINBLOCKSIZE,
3800 SPA_MINBLOCKSIZE);
3803 if (rc < 0) {
3804 /* snprintf failed, abort the dcmd */
3805 rc = DCMD_ERR;
3806 goto out;
3807 } else {
3808 /* snprintf succeeded above, reset return code */
3809 rc = DCMD_OK;
3812 if (data.arc_cflags & ARC_CFLAG_ANON) {
3813 if (data.arc_cflags & ARC_CFLAG_BUFS) {
3814 mdb_printf("Histogram of the number of anon buffers "
3815 "that are associated with an arc hdr.\n");
3816 dump_histogram(data.anon_bufs, data.hist_nbuckets, 0);
3817 mdb_printf("\n");
3819 mdb_printf("Histogram of compressed anon buffers.\n"
3820 "Each bucket represents buffers of size: %s.\n", range);
3821 dump_histogram(data.anon_c_hist, data.hist_nbuckets, 0);
3822 mdb_printf("\n");
3824 mdb_printf("Histogram of uncompressed anon buffers.\n"
3825 "Each bucket represents buffers of size: %s.\n", range);
3826 dump_histogram(data.anon_u_hist, data.hist_nbuckets, 0);
3827 mdb_printf("\n");
3830 if (data.arc_cflags & ARC_CFLAG_MRU) {
3831 if (data.arc_cflags & ARC_CFLAG_BUFS) {
3832 mdb_printf("Histogram of the number of mru buffers "
3833 "that are associated with an arc hdr.\n");
3834 dump_histogram(data.mru_bufs, data.hist_nbuckets, 0);
3835 mdb_printf("\n");
3837 mdb_printf("Histogram of compressed mru buffers.\n"
3838 "Each bucket represents buffers of size: %s.\n", range);
3839 dump_histogram(data.mru_c_hist, data.hist_nbuckets, 0);
3840 mdb_printf("\n");
3842 mdb_printf("Histogram of uncompressed mru buffers.\n"
3843 "Each bucket represents buffers of size: %s.\n", range);
3844 dump_histogram(data.mru_u_hist, data.hist_nbuckets, 0);
3845 mdb_printf("\n");
3848 if (data.arc_cflags & ARC_CFLAG_MFU) {
3849 if (data.arc_cflags & ARC_CFLAG_BUFS) {
3850 mdb_printf("Histogram of the number of mfu buffers "
3851 "that are associated with an arc hdr.\n");
3852 dump_histogram(data.mfu_bufs, data.hist_nbuckets, 0);
3853 mdb_printf("\n");
3856 mdb_printf("Histogram of compressed mfu buffers.\n"
3857 "Each bucket represents buffers of size: %s.\n", range);
3858 dump_histogram(data.mfu_c_hist, data.hist_nbuckets, 0);
3859 mdb_printf("\n");
3861 mdb_printf("Histogram of uncompressed mfu buffers.\n"
3862 "Each bucket represents buffers of size: %s.\n", range);
3863 dump_histogram(data.mfu_u_hist, data.hist_nbuckets, 0);
3864 mdb_printf("\n");
3867 if (data.arc_cflags & ARC_CFLAG_BUFS) {
3868 mdb_printf("Histogram of all buffers that "
3869 "are associated with an arc hdr.\n");
3870 dump_histogram(data.all_bufs, data.hist_nbuckets, 0);
3871 mdb_printf("\n");
3874 mdb_printf("Histogram of all compressed buffers.\n"
3875 "Each bucket represents buffers of size: %s.\n", range);
3876 dump_histogram(data.all_c_hist, data.hist_nbuckets, 0);
3877 mdb_printf("\n");
3879 mdb_printf("Histogram of all uncompressed buffers.\n"
3880 "Each bucket represents buffers of size: %s.\n", range);
3881 dump_histogram(data.all_u_hist, data.hist_nbuckets, 0);
3883 out:
3884 mdb_free(data.anon_c_hist, hist_size);
3885 mdb_free(data.anon_u_hist, hist_size);
3886 mdb_free(data.anon_bufs, hist_size);
3888 mdb_free(data.mru_c_hist, hist_size);
3889 mdb_free(data.mru_u_hist, hist_size);
3890 mdb_free(data.mru_bufs, hist_size);
3892 mdb_free(data.mfu_c_hist, hist_size);
3893 mdb_free(data.mfu_u_hist, hist_size);
3894 mdb_free(data.mfu_bufs, hist_size);
3896 mdb_free(data.all_c_hist, hist_size);
3897 mdb_free(data.all_u_hist, hist_size);
3898 mdb_free(data.all_bufs, hist_size);
3900 return (rc);
3904 * MDB module linkage information:
3906 * We declare a list of structures describing our dcmds, and a function
3907 * named _mdb_init to return a pointer to our module information.
3910 static const mdb_dcmd_t dcmds[] = {
3911 { "arc", "[-bkmg]", "print ARC variables", arc_print },
3912 { "blkptr", ":", "print blkptr_t", blkptr },
3913 { "dbuf", ":", "print dmu_buf_impl_t", dbuf },
3914 { "dbuf_stats", ":", "dbuf stats", dbuf_stats },
3915 { "dbufs",
3916 "\t[-O objset_t*] [-n objset_name | \"mos\"] "
3917 "[-o object | \"mdn\"] \n"
3918 "\t[-l level] [-b blkid | \"bonus\"]",
3919 "find dmu_buf_impl_t's that match specified criteria", dbufs },
3920 { "abuf_find", "dva_word[0] dva_word[1]",
3921 "find arc_buf_hdr_t of a specified DVA",
3922 abuf_find },
3923 { "spa", "?[-cevmMh]\n"
3924 "\t-c display spa config\n"
3925 "\t-e display vdev statistics\n"
3926 "\t-v display vdev information\n"
3927 "\t-m display metaslab statistics\n"
3928 "\t-M display metaslab group statistics\n"
3929 "\t-h display histogram (requires -m or -M)\n",
3930 "spa_t summary", spa_print },
3931 { "spa_config", ":", "print spa_t configuration", spa_print_config },
3932 { "spa_space", ":[-b]", "print spa_t on-disk space usage", spa_space },
3933 { "spa_vdevs", ":[-emMh]\n"
3934 "\t-e display vdev statistics\n"
3935 "\t-m dispaly metaslab statistics\n"
3936 "\t-M display metaslab group statistic\n"
3937 "\t-h display histogram (requires -m or -M)\n",
3938 "given a spa_t, print vdev summary", spa_vdevs },
3939 { "vdev", ":[-remMh]\n"
3940 "\t-r display recursively\n"
3941 "\t-e display statistics\n"
3942 "\t-m display metaslab statistics (top level vdev only)\n"
3943 "\t-M display metaslab group statistics (top level vdev only)\n"
3944 "\t-h display histogram (requires -m or -M)\n",
3945 "vdev_t summary", vdev_print },
3946 { "zio", ":[-cpr]\n"
3947 "\t-c display children\n"
3948 "\t-p display parents\n"
3949 "\t-r display recursively",
3950 "zio_t summary", zio_print },
3951 { "zio_state", "?", "print out all zio_t structures on system or "
3952 "for a particular pool", zio_state },
3953 { "zfs_blkstats", ":[-v]",
3954 "given a spa_t, print block type stats from last scrub",
3955 zfs_blkstats },
3956 { "zfs_params", "", "print zfs tunable parameters", zfs_params },
3957 { "refcount", ":[-r]\n"
3958 "\t-r display recently removed references",
3959 "print refcount_t holders", refcount },
3960 { "zap_leaf", "", "print zap_leaf_phys_t", zap_leaf },
3961 { "zfs_aces", ":[-v]", "print all ACEs from a zfs_acl_t",
3962 zfs_acl_dump },
3963 { "zfs_ace", ":[-v]", "print zfs_ace", zfs_ace_print },
3964 { "zfs_ace0", ":[-v]", "print zfs_ace0", zfs_ace0_print },
3965 { "sa_attr_table", ":", "print SA attribute table from sa_os_t",
3966 sa_attr_table},
3967 { "sa_attr", ": attr_id",
3968 "print SA attribute address when given sa_handle_t", sa_attr_print},
3969 { "zfs_dbgmsg", ":[-va]",
3970 "print zfs debug log", dbgmsg},
3971 { "rrwlock", ":",
3972 "print rrwlock_t, including readers", rrwlock},
3973 { "metaslab_weight", "weight",
3974 "print metaslab weight", metaslab_weight},
3975 { "metaslab_trace", ":",
3976 "print metaslab allocation trace records", metaslab_trace},
3977 { "arc_compression_stats", ":[-vabrf]\n"
3978 "\t-v verbose, display a linearly scaled histogram\n"
3979 "\t-a display ARC_anon state statistics individually\n"
3980 "\t-r display ARC_mru state statistics individually\n"
3981 "\t-f display ARC_mfu state statistics individually\n"
3982 "\t-b display histogram of buffer counts\n",
3983 "print a histogram of compressed arc buffer sizes",
3984 arc_compression_stats},
3985 { NULL }
3988 static const mdb_walker_t walkers[] = {
3989 { "zms_freelist", "walk ZFS metaslab freelist",
3990 freelist_walk_init, freelist_walk_step, NULL },
3991 { "txg_list", "given any txg_list_t *, walk all entries in all txgs",
3992 txg_list_walk_init, txg_list_walk_step, NULL },
3993 { "txg_list0", "given any txg_list_t *, walk all entries in txg 0",
3994 txg_list0_walk_init, txg_list_walk_step, NULL },
3995 { "txg_list1", "given any txg_list_t *, walk all entries in txg 1",
3996 txg_list1_walk_init, txg_list_walk_step, NULL },
3997 { "txg_list2", "given any txg_list_t *, walk all entries in txg 2",
3998 txg_list2_walk_init, txg_list_walk_step, NULL },
3999 { "txg_list3", "given any txg_list_t *, walk all entries in txg 3",
4000 txg_list3_walk_init, txg_list_walk_step, NULL },
4001 { "zio", "walk all zio structures, optionally for a particular spa_t",
4002 zio_walk_init, zio_walk_step, NULL },
4003 { "zio_root",
4004 "walk all root zio_t structures, optionally for a particular spa_t",
4005 zio_walk_init, zio_walk_root_step, NULL },
4006 { "spa", "walk all spa_t entries in the namespace",
4007 spa_walk_init, spa_walk_step, NULL },
4008 { "metaslab", "given a spa_t *, walk all metaslab_t structures",
4009 metaslab_walk_init, metaslab_walk_step, NULL },
4010 { "multilist", "given a multilist_t *, walk all list_t structures",
4011 multilist_walk_init, multilist_walk_step, NULL },
4012 { "zfs_acl_node", "given a zfs_acl_t, walk all zfs_acl_nodes",
4013 zfs_acl_node_walk_init, zfs_acl_node_walk_step, NULL },
4014 { "zfs_acl_node_aces", "given a zfs_acl_node_t, walk all ACEs",
4015 zfs_acl_node_aces_walk_init, zfs_aces_walk_step, NULL },
4016 { "zfs_acl_node_aces0",
4017 "given a zfs_acl_node_t, walk all ACEs as ace_t",
4018 zfs_acl_node_aces0_walk_init, zfs_aces_walk_step, NULL },
4019 { NULL }
4022 static const mdb_modinfo_t modinfo = {
4023 MDB_API_VERSION, dcmds, walkers
4026 const mdb_modinfo_t *
4027 _mdb_init(void)
4029 return (&modinfo);