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]
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>
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>
39 #include <sys/vdev_impl.h>
40 #include <sys/zap_leaf.h>
41 #include <sys/zap_impl.h>
43 #include <sys/zfs_acl.h>
44 #include <sys/sa_impl.h>
45 #include <sys/multilist.h>
48 #define ZFS_OBJ_NAME "zfs"
49 extern int64_t mdb_gethrtime(void);
51 #define ZFS_OBJ_NAME "libzpool.so.1"
54 #define ZFS_STRUCT "struct " ZFS_OBJ_NAME "`"
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 | \
77 getmember(uintptr_t addr
, const char *type
, mdb_ctf_id_t
*idp
,
78 const char *member
, int len
, void *buf
)
85 if (mdb_ctf_lookup_by_name(type
, &id
) == -1) {
86 mdb_warn("couldn't find type %s", type
);
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
);
100 mdb_warn("member %s of type %s is unsupported bitfield",
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
);
111 /* mdb_warn("read %s from %s at %p+%llx\n", member, type, addr, off); */
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))
124 strisprint(const char *cp
)
133 #define NICENUM_BUFLEN 6
136 snprintfrac(char *buf
, int len
,
137 uint64_t numerator
, uint64_t denom
, int frac_digits
)
142 for (i
= frac_digits
; i
; i
--)
144 whole
= numerator
/ denom
;
145 frac
= mul
* numerator
/ denom
- mul
* whole
;
146 return (mdb_snprintf(buf
, len
, "%u.%0*u", whole
, frac_digits
, frac
));
150 mdb_nicenum(uint64_t num
, char *buf
)
157 n
= (n
+ (1024 / 2)) / 1024; /* Round up or down */
161 u
= &" \0K\0M\0G\0T\0P\0E\0"[index
*2];
164 (void) mdb_snprintf(buf
, NICENUM_BUFLEN
, "%llu",
166 } else if (n
< 10 && (num
& (num
- 1)) != 0) {
167 (void) snprintfrac(buf
, NICENUM_BUFLEN
,
168 num
, 1ULL << 10 * index
, 2);
170 } else if (n
< 100 && (num
& (num
- 1)) != 0) {
171 (void) snprintfrac(buf
, NICENUM_BUFLEN
,
172 num
, 1ULL << 10 * index
, 1);
175 (void) mdb_snprintf(buf
, NICENUM_BUFLEN
, "%llu%s",
183 freelist_walk_init(mdb_walk_state_t
*wsp
)
185 if (wsp
->walk_addr
== NULL
) {
186 mdb_warn("must supply starting address\n");
190 wsp
->walk_data
= 0; /* Index into the freelist */
195 freelist_walk_step(mdb_walk_state_t
*wsp
)
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
);
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",
213 ddata
[SM_DEBUG_ACTION_DECODE(entry
)],
214 SM_DEBUG_TXG_DECODE(entry
),
215 SM_DEBUG_SYNCPASS_DECODE(entry
));
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
)) <<
222 SM_TYPE_DECODE(entry
) == SM_ALLOC
? 'A' : 'F',
223 SM_RUN_DECODE(entry
) << mapshift
);
225 mdb_printf(" (raw=%012llx)\n", entry
);
232 mdb_dsl_dir_name(uintptr_t addr
, char *buf
)
235 static mdb_ctf_id_t dd_id
;
237 char dd_myname
[ZFS_MAX_DATASET_NAME_LEN
];
240 if (mdb_ctf_lookup_by_name(ZFS_STRUCT
"dsl_dir",
242 mdb_warn("couldn't find struct dsl_dir");
247 if (GETMEMBID(addr
, &dd_id
, dd_parent
, dd_parent
) ||
248 GETMEMBID(addr
, &dd_id
, dd_myname
, dd_myname
)) {
253 if (mdb_dsl_dir_name(dd_parent
, buf
))
259 strcat(buf
, dd_myname
);
267 objset_name(uintptr_t addr
, char *buf
)
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
];
278 if (mdb_ctf_lookup_by_name(ZFS_STRUCT
"objset",
280 mdb_warn("couldn't find struct objset");
283 if (mdb_ctf_lookup_by_name(ZFS_STRUCT
"dsl_dataset",
285 mdb_warn("couldn't find struct dsl_dataset");
292 if (GETMEMBID(addr
, &os_id
, os_dsl_dataset
, os_dsl_dataset
))
295 if (os_dsl_dataset
== 0) {
300 if (GETMEMBID(os_dsl_dataset
, &ds_id
, ds_snapname
, ds_snapname
) ||
301 GETMEMBID(os_dsl_dataset
, &ds_id
, ds_dir
, ds_dir
)) {
305 if (ds_dir
&& mdb_dsl_dir_name(ds_dir
, buf
))
308 if (ds_snapname
[0]) {
310 strcat(buf
, ds_snapname
);
316 enum_lookup(char *type
, int val
, const char *prefix
, size_t size
, char *out
)
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
);
327 if ((cp
= mdb_ctf_enum_name(enum_type
, val
)) != NULL
) {
328 if (strncmp(cp
, prefix
, len
) == 0)
330 (void) strncpy(out
, cp
, size
);
332 mdb_snprintf(out
, size
, "? (%d)", val
);
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",
351 "zfs_delay_min_dirty_percent",
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",
370 "zfs_mdcomp_disable",
371 "zfs_prefetch_disable",
372 "zfetch_max_streams",
373 "zfetch_min_sec_reap",
375 "zfetch_array_rd_sz",
379 "reference_tracking_enable",
381 "spa_max_replication_override",
385 "zfs_vdev_cache_max",
386 "zfs_vdev_cache_size",
387 "zfs_vdev_cache_bshift",
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",
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
++) {
408 uint32_t *val32p
= (uint32_t *)&val64
;
410 sz
= mdb_readvar(&val64
, params
[i
]);
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
);
416 mdb_warn("variable %s not found", params
[i
]);
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");
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");
446 SNPRINTF_BLKPTR(mdb_snprintf
, '\n', buf
, sizeof (buf
), bp
, type
,
449 mdb_printf("%s\n", buf
);
454 typedef struct mdb_dmu_buf_impl
{
465 } mdb_dmu_buf_impl_t
;
469 dbuf(uintptr_t addr
, uint_t flags
, int argc
, const mdb_arg_t
*argv
)
471 mdb_dmu_buf_impl_t db
;
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",
485 if (db
.db
.db_object
== DMU_META_DNODE_OBJECT
)
486 (void) strcpy(objectname
, "mdn");
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");
494 (void) mdb_snprintf(blkidname
, sizeof (blkidname
), "%llx",
495 (u_longlong_t
)db
.db_blkid
);
497 if (objset_name(db
.db_objset
, path
)) {
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
);
510 dbuf_stats(uintptr_t addr
, uint_t flags
, int argc
, const mdb_arg_t
*argv
)
515 dbuf_hash_table_t ht
;
516 uint64_t bucket
, ndbufs
;
517 uint64_t histo
[HISTOSZ
];
518 uint64_t histo2
[HISTOSZ
];
521 if (mdb_readvar(&ht
, "dbuf_hash_table") == -1) {
522 mdb_warn("failed to read 'dbuf_hash_table'");
526 for (i
= 0; i
< HISTOSZ
; i
++) {
532 for (bucket
= 0; bucket
< ht
.hash_table_mask
+1; bucket
++) {
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
);
544 if (mdb_vread(&db
, sizeof (dmu_buf_impl_t
),
546 mdb_warn("failed to read dbuf at %p", dbp
);
549 dbp
= (uintptr_t)db
.db_hash_next
;
550 for (i
= MIN(len
, HISTOSZ
- 1); i
>= 0; i
--)
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
);
568 for (i
= 0; i
< HISTOSZ
; 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
]);
577 for (i
= 0; i
< HISTOSZ
; 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
);
589 #define CHAIN_END 0xffff
593 * Print a zap_leaf_phys_t, assumed to be 16k
597 zap_leaf(uintptr_t addr
, uint_t flags
, int argc
, const mdb_arg_t
*argv
)
600 int verbose
= B_FALSE
;
604 zap_leaf_phys_t
*zlp
= (void *)buf
;
607 if (mdb_getopts(argc
, argv
,
608 'v', MDB_OPT_SETBITS
, TRUE
, &verbose
,
609 '4', MDB_OPT_SETBITS
, TRUE
, &four
,
613 l_dbuf
.db_data
= zlp
;
615 l
.l_bs
= 14; /* assume 16k blocks */
619 if (!(flags
& DCMD_ADDRSPEC
)) {
623 if (mdb_vread(buf
, sizeof (buf
), addr
) == -1) {
624 mdb_warn("failed to read zap_leaf_phys_t at %p", addr
);
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");
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" : "");
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
) {
660 mdb_printf(" %u: free; lf_next = %u\n",
661 i
, zlc
->l_free
.lf_next
);
664 case ZAP_CHUNK_ENTRY
:
665 mdb_printf(" %u: entry\n", i
);
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",
682 mdb_printf(" le_hash = %llx\n",
683 zlc
->l_entry
.le_hash
);
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
);
693 for (j
= 0; j
< ZAP_LEAF_ARRAY_BYTES
; j
++) {
695 zlc
->l_array
.la_array
[j
]);
699 if (zlc
->l_array
.la_next
!= CHAIN_END
) {
700 mdb_printf(" lf_next = %u\n",
701 zlc
->l_array
.la_next
);
705 mdb_printf(" %u: undefined type %u\n",
706 zlc
->l_entry
.le_type
);
713 typedef struct dbufs_data
{
722 #define DBUFS_UNSET (0xbaddcafedeadbeefULL)
726 dbufs_cb(uintptr_t addr
, const void *unknown
, void *arg
)
728 dbufs_data_t
*data
= arg
;
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
)) {
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
);
755 dbufs(uintptr_t addr
, uint_t flags
, int argc
, const mdb_arg_t
*argv
)
761 data
.objset
= data
.object
= data
.level
= data
.blkid
= DBUFS_UNSET
;
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
) {
774 if (strcmp(object
, "mdn") == 0) {
775 data
.object
= DMU_META_DNODE_OBJECT
;
777 data
.object
= mdb_strtoull(object
);
782 if (strcmp(blkid
, "bonus") == 0) {
783 data
.blkid
= DMU_BONUS_BLKID
;
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");
794 if (mdb_walk("dmu_buf_impl_t", dbufs_cb
, &data
) != 0) {
795 mdb_warn("can't walk dbufs");
802 typedef struct abuf_find_data
{
809 abuf_find_cb(uintptr_t addr
, const void *unknown
, void *arg
)
811 abuf_find_data_t
*data
= arg
;
814 if (GETMEMBID(addr
, &data
->id
, b_dva
, dva
)) {
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
);
827 abuf_find(uintptr_t addr
, uint_t flags
, int argc
, const mdb_arg_t
*argv
)
829 abuf_find_data_t data
;
832 const char *syms
[] = {
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
);
847 case MDB_TYPE_IMMEDIATE
:
848 data
.dva
.dva_word
[i
] = argv
[i
].a_un
.a_val
;
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");
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
]);
866 if (mdb_pwalk("list", abuf_find_cb
, &data
, sym
.st_value
) != 0) {
867 mdb_warn("can't walk %s", syms
[i
]);
876 typedef struct dbgmsg_arg
{
877 boolean_t da_verbose
;
878 boolean_t da_address
;
883 dbgmsg_cb(uintptr_t addr
, const void *unknown
, void *arg
)
885 static mdb_ctf_id_t id
;
886 static boolean_t gotid
;
889 dbgmsg_arg_t
*da
= arg
;
894 if (mdb_ctf_lookup_by_name(ZFS_STRUCT
"zfs_dbgmsg", &id
) ==
896 mdb_warn("couldn't find struct zfs_dbgmsg");
900 if (mdb_ctf_offsetof(id
, "zdm_msg", &off
) == -1) {
901 mdb_warn("couldn't find zdm_msg");
908 if (GETMEMBID(addr
, &id
, zdm_timestamp
, timestamp
)) {
912 if (mdb_readstr(buf
, sizeof (buf
), addr
+ off
) == -1) {
913 mdb_warn("failed to read zdm_msg at %p\n", addr
+ off
);
918 mdb_printf("%p ", addr
);
920 mdb_printf("%Y ", timestamp
);
922 mdb_printf("%s\n", buf
);
925 (void) mdb_call_dcmd("whatis", addr
, DCMD_ADDRSPEC
, 0, NULL
);
932 dbgmsg(uintptr_t addr
, uint_t flags
, int argc
, const mdb_arg_t
*argv
)
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
,
943 if (mdb_lookup_by_obj(ZFS_OBJ_NAME
, "zfs_dbgmsgs", &sym
)) {
944 mdb_warn("can't find zfs_dbgmsgs");
948 if (mdb_pwalk("list", dbgmsg_cb
, &da
, sym
.st_value
) != 0) {
949 mdb_warn("can't walk zfs_dbgmsgs");
958 arc_print(uintptr_t addr
, uint_t flags
, int argc
, const mdb_arg_t
*argv
)
960 kstat_named_t
*stats
;
963 uint_t opt_a
= FALSE
;
964 uint_t opt_b
= FALSE
;
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",
985 static const char *extras
[] = {
986 "arc_no_grow", "arc_tempreserve",
990 if (mdb_lookup_by_obj(ZFS_OBJ_NAME
, "arc_stats", &sym
) == -1) {
991 mdb_warn("failed to find 'arc_stats'");
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
);
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
,
1012 return (DCMD_USAGE
);
1014 if (!opt_b
&& !shift
)
1034 for (i
= 0; i
< nstats
; i
++) {
1036 boolean_t bytes
= B_FALSE
;
1038 for (j
= 0; bytestats
[j
]; j
++) {
1039 if (strcmp(stats
[i
].name
, bytestats
[j
]) == 0) {
1046 mdb_printf("%-25s = %9llu %s\n", stats
[i
].name
,
1047 stats
[i
].value
.ui64
>> shift
, suffix
);
1049 mdb_printf("%-25s = %9llu\n", stats
[i
].name
,
1050 stats
[i
].value
.ui64
);
1054 for (i
= 0; extras
[i
]; i
++) {
1057 if (mdb_lookup_by_obj(ZFS_OBJ_NAME
, extras
[i
], &sym
) == -1) {
1058 mdb_warn("failed to find '%s'", extras
[i
]);
1062 if (sym
.st_size
!= sizeof (uint64_t) &&
1063 sym
.st_size
!= sizeof (uint32_t)) {
1064 mdb_warn("expected scalar for variable '%s'\n",
1069 if (mdb_vread(&buf
, sym
.st_size
, sym
.st_value
) == -1) {
1070 mdb_warn("couldn't read '%s'", extras
[i
]);
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
));
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
;
1093 const char histo_stars
[] = "****************************************";
1094 const int histo_width
= sizeof (histo_stars
) - 1;
1097 dump_histogram(const uint64_t *histo
, int size
, int offset
)
1100 int minidx
= size
- 1;
1104 for (i
= 0; i
< size
; i
++) {
1107 if (histo
[i
] > 0 && i
> maxidx
)
1109 if (histo
[i
] > 0 && i
< minidx
)
1113 if (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.
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)
1143 dump_histogram(mc
.mc_histogram
, RANGE_TREE_HISTOGRAM_SIZE
, 0);
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.
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" };
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
,
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");
1189 if (flags
& DCMD_PIPE_OUT
) {
1190 mdb_printf("%#lr\n", addr
);
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)
1202 if (spa
.spa_state
< 0 || spa
.spa_state
> POOL_STATE_UNAVAIL
)
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
) {
1214 if (mdb_call_dcmd("spa_config", addr
, flags
, 0,
1220 if (spa_flags
& SPA_FLAG_ALL_VDEV
) {
1222 char opts
[100] = "-";
1224 (spa_flags
| SPA_FLAG_VDEVS
) == SPA_FLAG_VDEVS
? 0 : 1;
1226 if (spa_flags
& SPA_FLAG_ERRORS
)
1228 if (spa_flags
& SPA_FLAG_METASLABS
)
1230 if (spa_flags
& SPA_FLAG_METASLAB_GROUPS
)
1232 if (spa_flags
& SPA_FLAG_HISTOGRAMS
)
1235 v
.a_type
= MDB_TYPE_STRING
;
1236 v
.a_un
.a_str
= opts
;
1240 if (mdb_call_dcmd("spa_vdevs", addr
, flags
, args
,
1249 typedef struct mdb_spa_config_spa
{
1250 uintptr_t spa_config
;
1251 } mdb_spa_config_spa_t
;
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.
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",
1273 if (spa
.spa_config
== 0) {
1274 mdb_printf("(none)\n");
1278 return (mdb_call_dcmd("nvlist", spa
.spa_config
, flags
,
1284 typedef struct mdb_range_tree
{
1288 typedef struct mdb_metaslab_group
{
1289 uint64_t mg_fragmentation
;
1290 uint64_t mg_histogram
[RANGE_TREE_HISTOGRAM_SIZE
];
1292 } mdb_metaslab_group_t
;
1294 typedef struct mdb_metaslab
{
1298 int64_t ms_deferspace
;
1299 uint64_t ms_fragmentation
;
1301 uintptr_t ms_alloctree
[TXG_SIZE
];
1302 uintptr_t ms_freeingtree
;
1303 uintptr_t ms_freedtree
;
1308 typedef struct mdb_space_map_phys_t
{
1310 uint64_t smp_histogram
[SPACE_MAP_HISTOGRAM_SIZE
];
1311 } mdb_space_map_phys_t
;
1313 typedef struct mdb_space_map
{
1320 typedef struct mdb_vdev
{
1321 uintptr_t vdev_path
;
1324 uint64_t vdev_ms_count
;
1326 vdev_stat_t vdev_stat
;
1329 typedef struct mdb_vdev_ops
{
1330 char vdev_op_type
[16];
1334 metaslab_stats(uintptr_t addr
, int spa_flags
)
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
);
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 *),
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
);
1357 for (int m
= 0; m
< vdev
.vdev_ms_count
; m
++) {
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)
1366 if (ms
.ms_sm
!= NULL
&&
1367 mdb_ctf_vread(&sm
, "space_map_t", "mdb_space_map_t",
1371 mdb_nicenum(ms
.ms_size
- sm
.sm_alloc
, free
);
1373 mdb_printf("%0?p %6llu %20llx %10s ", vdev_ms
[m
], ms
.ms_id
,
1375 if (ms
.ms_fragmentation
== ZFS_FRAG_INVALID
)
1376 mdb_printf("%9s\n", "-");
1378 mdb_printf("%9llu%%\n", ms
.ms_fragmentation
);
1380 if ((spa_flags
& SPA_FLAG_HISTOGRAMS
) && ms
.ms_sm
!= NULL
) {
1381 mdb_space_map_phys_t smp
;
1383 if (sm
.sm_phys
== NULL
)
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
);
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
);
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
, "-");
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);
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.
1433 do_print_vdev(uintptr_t addr
, int flags
, int depth
, boolean_t recursive
,
1437 char desc
[MAXNAMELEN
];
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
);
1447 if (flags
& DCMD_PIPE_OUT
) {
1448 mdb_printf("%#lr\n", addr
);
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",
1457 } else if (vdev
.vdev_ops
!= NULL
) {
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",
1465 (void) strcpy(desc
, ops
.vdev_op_type
);
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,
1476 mdb_printf("%0?p ", addr
);
1478 switch (vdev
.vdev_state
) {
1479 case VDEV_STATE_CLOSED
:
1482 case VDEV_STATE_OFFLINE
:
1485 case VDEV_STATE_CANT_OPEN
:
1486 state
= "CANT_OPEN";
1488 case VDEV_STATE_DEGRADED
:
1491 case VDEV_STATE_HEALTHY
:
1494 case VDEV_STATE_REMOVED
:
1497 case VDEV_STATE_FAULTED
:
1505 switch (vdev
.vdev_stat
.vs_aux
) {
1509 case VDEV_AUX_OPEN_FAILED
:
1510 aux
= "OPEN_FAILED";
1512 case VDEV_AUX_CORRUPT_DATA
:
1513 aux
= "CORRUPT_DATA";
1515 case VDEV_AUX_NO_REPLICAS
:
1516 aux
= "NO_REPLICAS";
1518 case VDEV_AUX_BAD_GUID_SUM
:
1519 aux
= "BAD_GUID_SUM";
1521 case VDEV_AUX_TOO_SMALL
:
1524 case VDEV_AUX_BAD_LABEL
:
1527 case VDEV_AUX_VERSION_NEWER
:
1530 case VDEV_AUX_VERSION_OLDER
:
1533 case VDEV_AUX_UNSUP_FEAT
:
1536 case VDEV_AUX_SPARED
:
1539 case VDEV_AUX_ERR_EXCEEDED
:
1540 aux
= "ERR_EXCEEDED";
1542 case VDEV_AUX_IO_FAILURE
:
1545 case VDEV_AUX_BAD_LOG
:
1548 case VDEV_AUX_EXTERNAL
:
1551 case VDEV_AUX_SPLIT_POOL
:
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
;
1567 mdb_printf("%<u> %12s %12s %12s %12s "
1568 "%12s%</u>\n", "READ", "WRITE", "FREE", "CLAIM",
1571 for (i
= 1; i
< ZIO_TYPES
; i
++)
1572 mdb_printf("%11#llx%s", vs
->vs_ops
[i
],
1573 i
== ZIO_TYPES
- 1 ? "" : " ");
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 ? "" : " ");
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
);
1590 if (spa_flags
& SPA_FLAG_METASLAB_GROUPS
&&
1591 vdev
.vdev_mg
!= NULL
) {
1592 metaslab_group_stats((uintptr_t)vdev
.vdev_mg
,
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
)
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
);
1612 for (c
= 0; c
< children
; c
++) {
1613 if (do_print_vdev(child
[c
], flags
, depth
+ 2, recursive
,
1623 vdev_print(uintptr_t addr
, uint_t flags
, int argc
, const mdb_arg_t
*argv
)
1626 boolean_t recursive
= B_FALSE
;
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");
1643 return (do_print_vdev(addr
, flags
, (int)depth
, recursive
, spa_flags
));
1646 typedef struct mdb_metaslab_alloc_trace
{
1650 uint64_t mat_weight
;
1651 uint64_t mat_offset
;
1652 uint32_t mat_dva_id
;
1653 } mdb_metaslab_alloc_trace_t
;
1656 metaslab_print_weight(uint64_t weight
)
1660 if (WEIGHT_IS_SPACEBASED(weight
)) {
1662 weight
& ~(METASLAB_ACTIVE_MASK
| METASLAB_WEIGHT_TYPE
),
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
);
1675 metaslab_weight(uintptr_t addr
, uint_t flags
, int argc
, const mdb_arg_t
*argv
)
1677 uint64_t weight
= 0;
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
);
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
);
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
)
1699 else if (weight
& METASLAB_WEIGHT_SECONDARY
)
1703 mdb_printf("%6c %8s ", active
,
1704 WEIGHT_IS_SPACEBASED(weight
) ? "SPACE" : "SEGMENT");
1705 metaslab_print_weight(weight
);
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) {
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
!= NULL
) {
1732 if (mdb_ctf_vread(&ms
, "metaslab_t", "mdb_metaslab_t",
1733 mat
.mat_msp
, 0) == -1) {
1736 mdb_printf("%6llu ", ms
.ms_id
);
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");
1751 mdb_printf("%18s ", result_type
);
1753 mdb_printf("%<b>%18llx%</b> ", mat
.mat_offset
);
1756 if (mat
.mat_mg
!= NULL
&&
1757 mdb_ctf_vread(&mg
, "metaslab_group_t", "mdb_metaslab_group_t",
1758 mat
.mat_mg
, 0) == -1) {
1762 if (mg
.mg_vd
!= NULL
) {
1764 char desc
[MAXNAMELEN
];
1766 if (mdb_ctf_vread(&vdev
, "vdev_t", "mdb_vdev_t",
1767 mg
.mg_vd
, 0) == -1) {
1771 if (vdev
.vdev_path
!= NULL
) {
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",
1781 if ((slash
= strrchr(path
, '/')) != NULL
) {
1782 strcpy(desc
, slash
+ 1);
1786 } else if (vdev
.vdev_ops
!= NULL
) {
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",
1794 (void) mdb_snprintf(desc
, sizeof (desc
),
1795 "%s-%llu", ops
.vdev_op_type
, vdev
.vdev_id
);
1797 (void) strcpy(desc
, "<unknown>");
1799 mdb_printf("%18s\n", desc
);
1805 typedef struct metaslab_walk_data
{
1806 uint64_t mw_numvdevs
;
1807 uintptr_t *mw_vdevs
;
1812 } metaslab_walk_data_t
;
1815 metaslab_walk_step(mdb_walk_state_t
*wsp
)
1817 metaslab_walk_data_t
*mw
= wsp
->walk_data
;
1821 if (mw
->mw_curvdev
>= mw
->mw_numvdevs
)
1824 if (mw
->mw_mss
== NULL
) {
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
)) {
1837 mw
->mw_mss
= mdb_alloc(mw
->mw_nummss
* sizeof (void*),
1839 if (mdb_vread(mw
->mw_mss
, mw
->mw_nummss
* sizeof (void*),
1841 mdb_warn("failed to read vdev_ms at %p", mssp
);
1846 if (mw
->mw_curms
>= mw
->mw_nummss
) {
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
);
1862 return (wsp
->walk_callback(msp
, &ms
, wsp
->walk_cbdata
));
1866 metaslab_walk_init(mdb_walk_state_t
*wsp
)
1868 metaslab_walk_data_t
*mw
;
1869 uintptr_t root_vdevp
;
1872 if (wsp
->walk_addr
== NULL
) {
1873 mdb_warn("must supply address of spa_t\n");
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
)) {
1885 mw
->mw_vdevs
= mdb_alloc(mw
->mw_numvdevs
* sizeof (void *),
1887 if (mdb_vread(mw
->mw_vdevs
, mw
->mw_numvdevs
* sizeof (void *),
1889 mdb_warn("failed to read root vdev children at %p", childp
);
1893 wsp
->walk_data
= mw
;
1898 typedef struct mdb_spa
{
1899 uintptr_t spa_dsl_pool
;
1900 uintptr_t spa_root_vdev
;
1903 typedef struct mdb_dsl_pool
{
1904 uintptr_t dp_root_dir
;
1907 typedef struct mdb_dsl_dir
{
1909 int64_t dd_space_towrite
[TXG_SIZE
];
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
;
1923 int64_t ms_deferspace
;
1930 space_cb(uintptr_t addr
, const void *unknown
, void *arg
)
1932 space_data_t
*sd
= arg
;
1934 mdb_range_tree_t rt
;
1935 mdb_space_map_t sm
= { 0 };
1936 mdb_space_map_phys_t smp
= { 0 };
1939 if (mdb_ctf_vread(&ms
, "metaslab_t", "mdb_metaslab_t",
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)
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)
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)
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)
1965 sd
->ms_tree
+= rt
.rt_space
;
1967 if (ms
.ms_sm
!= NULL
&&
1968 mdb_ctf_vread(&sm
, "space_map_t",
1969 "mdb_space_map_t", ms
.ms_sm
, 0) == -1)
1972 if (sm
.sm_phys
!= 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
;
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.
1993 spa_space(uintptr_t addr
, uint_t flags
, int argc
, const mdb_arg_t
*argv
)
1998 mdb_dmu_buf_impl_t db
;
1999 mdb_dsl_dir_phys_t dsp
;
2003 int bytes
= B_FALSE
;
2005 if (mdb_getopts(argc
, argv
, 'b', MDB_OPT_SETBITS
, TRUE
, &bytes
, NULL
) !=
2007 return (DCMD_USAGE
);
2008 if (!(flags
& DCMD_ADDRSPEC
))
2009 return (DCMD_USAGE
);
2016 if (mdb_ctf_vread(&spa
, ZFS_STRUCT
"spa", "mdb_spa_t",
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) {
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");
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
);
2067 typedef struct mdb_spa_aux_vdev
{
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
;
2079 spa_print_aux(mdb_spa_aux_vdev_t
*sav
, uint_t flags
, mdb_arg_t
*v
,
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
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) {
2102 mdb_warn("failed to read l2cache vdevs at %p",
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
) {
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.
2137 spa_vdevs(uintptr_t addr
, uint_t flags
, int argc
, const mdb_arg_t
*argv
)
2141 char opts
[100] = "-r";
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
,
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)
2160 * Unitialized spa_t structures can have a NULL root vdev.
2162 if (spa
.spa_root_vdev
== NULL
) {
2163 mdb_printf("no associated vdevs\n");
2167 if (spa_flags
& SPA_FLAG_ERRORS
)
2169 if (spa_flags
& SPA_FLAG_METASLABS
)
2171 if (spa_flags
& SPA_FLAG_METASLAB_GROUPS
)
2173 if (spa_flags
& SPA_FLAG_HISTOGRAMS
)
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
,
2184 if (spa_print_aux(&spa
.spa_l2cache
, flags
, v
, "cache") != 0 ||
2185 spa_print_aux(&spa
.spa_spares
, flags
, v
, "spares") != 0)
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
;
2219 typedef struct mdb_zio
{
2220 enum zio_type io_type
;
2221 enum zio_stage io_stage
;
2222 uintptr_t io_waiter
;
2226 uintptr_t list_next
;
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
);
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
;
2246 mdb_zio_timestamp_t zio_timestamp
= { 0 };
2248 if (mdb_ctf_vread(&zio
, ZFS_STRUCT
"zio", "mdb_zio_t", addr
, 0) == -1)
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");
2262 if ((type
= mdb_ctf_enum_name(type_enum
, zio
.io_type
)) != NULL
)
2263 type
+= sizeof ("ZIO_TYPE_") - 1;
2267 if (zio
.io_error
== 0) {
2268 stage
= mdb_ctf_enum_name(stage_enum
, zio
.io_stage
);
2270 stage
+= sizeof ("ZIO_STAGE_") - 1;
2277 if (zpa
->zpa_current_depth
>= zpa
->zpa_min_depth
) {
2278 if (zpa
->zpa_flags
& DCMD_PIPE_OUT
) {
2279 mdb_printf("%?p\n", addr
);
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
);
2286 mdb_printf("%-16s ", "-");
2288 if (zio_timestamp
.io_timestamp
!= 0) {
2289 mdb_printf("%llums", (mdb_gethrtime() -
2290 zio_timestamp
.io_timestamp
) /
2293 mdb_printf("%-12s ", "-");
2296 mdb_printf("%-12s ", "-");
2302 if (zpa
->zpa_current_depth
>= zpa
->zpa_max_depth
)
2305 if (zpa
->zpa_type
== ZIO_WALK_PARENT
)
2306 laddr
= addr
+ mdb_ctf_offsetof_by_name(ZFS_STRUCT
"zio",
2309 laddr
= addr
+ mdb_ctf_offsetof_by_name(ZFS_STRUCT
"zio",
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
);
2317 zpa
->zpa_current_depth
--;
2324 zio_child_cb(uintptr_t addr
, const void *unknown
, void *arg
)
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
);
2335 if (zpa
->zpa_type
== ZIO_WALK_PARENT
)
2336 ziop
= (uintptr_t)zl
.zl_parent
;
2338 ziop
= (uintptr_t)zl
.zl_child
;
2340 return (zio_print_cb(ziop
, zpa
));
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
,
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",
2374 if (zio_print_cb(addr
, &zpa
) != WALK_NEXT
)
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'.
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
))
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
;
2406 typedef struct multilist_walk_data
{
2408 mdb_multilist_t mwd_ml
;
2409 } multilist_walk_data_t
;
2413 multilist_print_cb(uintptr_t addr
, const void *unknown
, void *arg
)
2415 mdb_printf("%#lr\n", addr
);
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
)
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
, (void*)NULL
, wsp
->walk_addr
);
2438 multilist_walk_init(mdb_walk_state_t
*wsp
)
2440 multilist_walk_data_t
*mwd
;
2442 if (wsp
->walk_addr
== NULL
) {
2443 mdb_warn("must supply address of multilist_t\n");
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) {
2453 if (mwd
->mwd_ml
.ml_num_sublists
== 0 ||
2454 mwd
->mwd_ml
.ml_sublists
== NULL
) {
2455 mdb_warn("invalid or uninitialized multilist at %#lx\n",
2460 wsp
->walk_data
= mwd
;
2464 typedef struct txg_list_walk_data
{
2465 uintptr_t lw_head
[TXG_SIZE
];
2470 } txg_list_walk_data_t
;
2473 txg_list_walk_init_common(mdb_walk_state_t
*wsp
, int txg
, int maxoff
)
2475 txg_list_walk_data_t
*lwd
;
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
);
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
),
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
;
2500 txg_list_walk_init(mdb_walk_state_t
*wsp
)
2502 return (txg_list_walk_init_common(wsp
, 0, TXG_SIZE
-1));
2506 txg_list0_walk_init(mdb_walk_state_t
*wsp
)
2508 return (txg_list_walk_init_common(wsp
, 0, 0));
2512 txg_list1_walk_init(mdb_walk_state_t
*wsp
)
2514 return (txg_list_walk_init_common(wsp
, 1, 1));
2518 txg_list2_walk_init(mdb_walk_state_t
*wsp
)
2520 return (txg_list_walk_init_common(wsp
, 2, 2));
2524 txg_list3_walk_init(mdb_walk_state_t
*wsp
)
2526 return (txg_list_walk_init_common(wsp
, 3, 3));
2530 txg_list_walk_step(mdb_walk_state_t
*wsp
)
2532 txg_list_walk_data_t
*lwd
= wsp
->walk_data
;
2537 while (wsp
->walk_addr
== NULL
&& lwd
->lw_txgoff
< lwd
->lw_maxoff
) {
2539 wsp
->walk_addr
= lwd
->lw_head
[lwd
->lw_txgoff
];
2542 if (wsp
->walk_addr
== NULL
)
2545 addr
= wsp
->walk_addr
- lwd
->lw_offset
;
2547 if (mdb_vread(lwd
->lw_obj
,
2548 lwd
->lw_offset
+ sizeof (txg_node_t
), addr
) == -1) {
2549 mdb_warn("failed to read list element at %#lx", addr
);
2553 status
= wsp
->walk_callback(addr
, lwd
->lw_obj
, wsp
->walk_cbdata
);
2554 node
= (txg_node_t
*)((uintptr_t)lwd
->lw_obj
+ lwd
->lw_offset
);
2555 wsp
->walk_addr
= (uintptr_t)node
->tn_next
[lwd
->lw_txgoff
];
2563 * Walk all named spa_t structures in the namespace. This is nothing more than
2564 * a layered avl walk.
2567 spa_walk_init(mdb_walk_state_t
*wsp
)
2571 if (wsp
->walk_addr
!= NULL
) {
2572 mdb_warn("spa walk only supports global walks\n");
2576 if (mdb_lookup_by_obj(ZFS_OBJ_NAME
, "spa_namespace_avl", &sym
) == -1) {
2577 mdb_warn("failed to find symbol 'spa_namespace_avl'");
2581 wsp
->walk_addr
= (uintptr_t)sym
.st_value
;
2583 if (mdb_layered_walk("avl", wsp
) == -1) {
2584 mdb_warn("failed to walk 'avl'\n");
2592 spa_walk_step(mdb_walk_state_t
*wsp
)
2594 return (wsp
->walk_callback(wsp
->walk_addr
, NULL
, wsp
->walk_cbdata
));
2600 * Walk all active zio_t structures on the system. This is simply a layered
2601 * walk on top of ::walk zio_cache, with the optional ability to limit the
2602 * structures to a particular pool.
2605 zio_walk_init(mdb_walk_state_t
*wsp
)
2607 wsp
->walk_data
= (void *)wsp
->walk_addr
;
2609 if (mdb_layered_walk("zio_cache", wsp
) == -1) {
2610 mdb_warn("failed to walk 'zio_cache'\n");
2618 zio_walk_step(mdb_walk_state_t
*wsp
)
2621 uintptr_t spa
= (uintptr_t)wsp
->walk_data
;
2623 if (mdb_ctf_vread(&zio
, ZFS_STRUCT
"zio", "mdb_zio_t",
2624 wsp
->walk_addr
, 0) == -1)
2627 if (spa
!= 0 && spa
!= zio
.io_spa
)
2630 return (wsp
->walk_callback(wsp
->walk_addr
, &zio
, wsp
->walk_cbdata
));
2634 * [addr]::walk zio_root
2636 * Walk only root zio_t structures, optionally for a particular spa_t.
2639 zio_walk_root_step(mdb_walk_state_t
*wsp
)
2642 uintptr_t spa
= (uintptr_t)wsp
->walk_data
;
2644 if (mdb_ctf_vread(&zio
, ZFS_STRUCT
"zio", "mdb_zio_t",
2645 wsp
->walk_addr
, 0) == -1)
2648 if (spa
!= 0 && spa
!= zio
.io_spa
)
2651 /* If the parent list is not empty, ignore */
2652 if (zio
.io_parent_list
.list_head
.list_next
!=
2654 mdb_ctf_offsetof_by_name(ZFS_STRUCT
"zio", "io_parent_list") +
2655 mdb_ctf_offsetof_by_name("struct list", "list_head"))
2658 return (wsp
->walk_callback(wsp
->walk_addr
, &zio
, wsp
->walk_cbdata
));
2664 * -v print verbose per-level information
2668 zfs_blkstats(uintptr_t addr
, uint_t flags
, int argc
, const mdb_arg_t
*argv
)
2670 boolean_t verbose
= B_FALSE
;
2671 zfs_all_blkstats_t stats
;
2672 dmu_object_type_t t
;
2675 dmu_object_type_info_t dmu_ot
[DMU_OT_NUMTYPES
+ 10];
2676 /* +10 in case it grew */
2678 if (mdb_readvar(&dmu_ot
, "dmu_ot") == -1) {
2679 mdb_warn("failed to read 'dmu_ot'");
2683 if (mdb_getopts(argc
, argv
,
2684 'v', MDB_OPT_SETBITS
, TRUE
, &verbose
,
2686 return (DCMD_USAGE
);
2688 if (!(flags
& DCMD_ADDRSPEC
))
2689 return (DCMD_USAGE
);
2691 if (GETMEMB(addr
, "spa", spa_dsl_pool
, addr
) ||
2692 GETMEMB(addr
, "dsl_pool", dp_blkstats
, addr
) ||
2693 mdb_vread(&stats
, sizeof (zfs_all_blkstats_t
), addr
) == -1) {
2694 mdb_warn("failed to read data at %p;", addr
);
2695 mdb_printf("maybe no stats? run \"zpool scrub\" first.");
2699 tzb
= &stats
.zab_type
[DN_MAX_LEVELS
][DMU_OT_TOTAL
];
2700 if (tzb
->zb_gangs
!= 0) {
2701 mdb_printf("Ganged blocks: %llu\n",
2702 (longlong_t
)tzb
->zb_gangs
);
2705 ditto
= tzb
->zb_ditto_2_of_2_samevdev
+ tzb
->zb_ditto_2_of_3_samevdev
+
2706 tzb
->zb_ditto_3_of_3_samevdev
;
2708 mdb_printf("Dittoed blocks on same vdev: %llu\n",
2712 mdb_printf("\nBlocks\tLSIZE\tPSIZE\tASIZE"
2713 "\t avg\t comp\t%%Total\tType\n");
2715 for (t
= 0; t
<= DMU_OT_TOTAL
; t
++) {
2716 char csize
[NICENUM_BUFLEN
], lsize
[NICENUM_BUFLEN
];
2717 char psize
[NICENUM_BUFLEN
], asize
[NICENUM_BUFLEN
];
2718 char avg
[NICENUM_BUFLEN
];
2719 char comp
[NICENUM_BUFLEN
], pct
[NICENUM_BUFLEN
];
2724 if (t
== DMU_OT_DEFERRED
)
2725 strcpy(typename
, "deferred free");
2726 else if (t
== DMU_OT_OTHER
)
2727 strcpy(typename
, "other");
2728 else if (t
== DMU_OT_TOTAL
)
2729 strcpy(typename
, "Total");
2730 else if (mdb_readstr(typename
, sizeof (typename
),
2731 (uintptr_t)dmu_ot
[t
].ot_name
) == -1) {
2732 mdb_warn("failed to read type name");
2736 if (stats
.zab_type
[DN_MAX_LEVELS
][t
].zb_asize
== 0)
2739 for (l
= -1; l
< DN_MAX_LEVELS
; l
++) {
2740 int level
= (l
== -1 ? DN_MAX_LEVELS
: l
);
2741 zfs_blkstat_t
*zb
= &stats
.zab_type
[level
][t
];
2743 if (zb
->zb_asize
== 0)
2747 * Don't print each level unless requested.
2749 if (!verbose
&& level
!= DN_MAX_LEVELS
)
2753 * If all the space is level 0, don't print the
2754 * level 0 separately.
2756 if (level
== 0 && zb
->zb_asize
==
2757 stats
.zab_type
[DN_MAX_LEVELS
][t
].zb_asize
)
2760 mdb_nicenum(zb
->zb_count
, csize
);
2761 mdb_nicenum(zb
->zb_lsize
, lsize
);
2762 mdb_nicenum(zb
->zb_psize
, psize
);
2763 mdb_nicenum(zb
->zb_asize
, asize
);
2764 mdb_nicenum(zb
->zb_asize
/ zb
->zb_count
, avg
);
2765 (void) snprintfrac(comp
, NICENUM_BUFLEN
,
2766 zb
->zb_lsize
, zb
->zb_psize
, 2);
2767 (void) snprintfrac(pct
, NICENUM_BUFLEN
,
2768 100 * zb
->zb_asize
, tzb
->zb_asize
, 2);
2770 mdb_printf("%6s\t%5s\t%5s\t%5s\t%5s"
2772 csize
, lsize
, psize
, asize
, avg
, comp
, pct
);
2774 if (level
== DN_MAX_LEVELS
)
2775 mdb_printf("%s\n", typename
);
2777 mdb_printf(" L%d %s\n",
2785 typedef struct mdb_reference
{
2786 uintptr_t ref_holder
;
2787 uintptr_t ref_removed
;
2788 uint64_t ref_number
;
2793 reference_cb(uintptr_t addr
, const void *ignored
, void *arg
)
2795 mdb_reference_t ref
;
2796 boolean_t holder_is_str
= B_FALSE
;
2797 char holder_str
[128];
2798 boolean_t removed
= (boolean_t
)arg
;
2800 if (mdb_ctf_vread(&ref
, "reference_t", "mdb_reference_t", addr
,
2804 if (mdb_readstr(holder_str
, sizeof (holder_str
),
2805 ref
.ref_holder
) != -1)
2806 holder_is_str
= strisprint(holder_str
);
2809 mdb_printf("removed ");
2810 mdb_printf("reference ");
2811 if (ref
.ref_number
!= 1)
2812 mdb_printf("with count=%llu ", ref
.ref_number
);
2813 mdb_printf("with tag %lx", ref
.ref_holder
);
2815 mdb_printf(" \"%s\"", holder_str
);
2816 mdb_printf(", held at:\n");
2818 (void) mdb_call_dcmd("whatis", addr
, DCMD_ADDRSPEC
, 0, NULL
);
2821 mdb_printf("removed at:\n");
2822 (void) mdb_call_dcmd("whatis", ref
.ref_removed
,
2823 DCMD_ADDRSPEC
, 0, NULL
);
2831 typedef struct mdb_refcount
{
2835 typedef struct mdb_refcount_removed
{
2836 uint64_t rc_removed_count
;
2837 } mdb_refcount_removed_t
;
2839 typedef struct mdb_refcount_tracked
{
2840 boolean_t rc_tracked
;
2841 } mdb_refcount_tracked_t
;
2845 refcount(uintptr_t addr
, uint_t flags
, int argc
, const mdb_arg_t
*argv
)
2848 mdb_refcount_removed_t rcr
;
2849 mdb_refcount_tracked_t rct
;
2851 boolean_t released
= B_FALSE
;
2853 if (!(flags
& DCMD_ADDRSPEC
))
2854 return (DCMD_USAGE
);
2856 if (mdb_getopts(argc
, argv
,
2857 'r', MDB_OPT_SETBITS
, B_TRUE
, &released
,
2859 return (DCMD_USAGE
);
2861 if (mdb_ctf_vread(&rc
, "refcount_t", "mdb_refcount_t", addr
,
2865 if (mdb_ctf_vread(&rcr
, "refcount_t", "mdb_refcount_removed_t", addr
,
2866 MDB_CTF_VREAD_QUIET
) == -1) {
2867 mdb_printf("refcount_t at %p has %llu holds (untracked)\n",
2868 addr
, (longlong_t
)rc
.rc_count
);
2872 if (mdb_ctf_vread(&rct
, "refcount_t", "mdb_refcount_tracked_t", addr
,
2873 MDB_CTF_VREAD_QUIET
) == -1) {
2874 /* If this is an old target, it might be tracked. */
2875 rct
.rc_tracked
= B_TRUE
;
2878 mdb_printf("refcount_t at %p has %llu current holds, "
2879 "%llu recently released holds\n",
2880 addr
, (longlong_t
)rc
.rc_count
, (longlong_t
)rcr
.rc_removed_count
);
2882 if (rct
.rc_tracked
&& rc
.rc_count
> 0)
2883 mdb_printf("current holds:\n");
2884 off
= mdb_ctf_offsetof_by_name("refcount_t", "rc_list");
2887 mdb_pwalk("list", reference_cb
, (void*)B_FALSE
, addr
+ off
);
2889 if (released
&& rcr
.rc_removed_count
> 0) {
2890 mdb_printf("released holds:\n");
2892 off
= mdb_ctf_offsetof_by_name("refcount_t", "rc_removed");
2895 mdb_pwalk("list", reference_cb
, (void*)B_TRUE
, addr
+ off
);
2903 sa_attr_table(uintptr_t addr
, uint_t flags
, int argc
, const mdb_arg_t
*argv
)
2905 sa_attr_table_t
*table
;
2910 if (mdb_vread(&sa_os
, sizeof (sa_os_t
), addr
) == -1) {
2911 mdb_warn("failed to read sa_os at %p", addr
);
2915 table
= mdb_alloc(sizeof (sa_attr_table_t
) * sa_os
.sa_num_attrs
,
2917 name
= mdb_alloc(MAXPATHLEN
, UM_SLEEP
| UM_GC
);
2919 if (mdb_vread(table
, sizeof (sa_attr_table_t
) * sa_os
.sa_num_attrs
,
2920 (uintptr_t)sa_os
.sa_attr_table
) == -1) {
2921 mdb_warn("failed to read sa_os at %p", addr
);
2925 mdb_printf("%<u>%-10s %-10s %-10s %-10s %s%</u>\n",
2926 "ATTR ID", "REGISTERED", "LENGTH", "BSWAP", "NAME");
2927 for (i
= 0; i
!= sa_os
.sa_num_attrs
; i
++) {
2928 mdb_readstr(name
, MAXPATHLEN
, (uintptr_t)table
[i
].sa_name
);
2929 mdb_printf("%5x %8x %8x %8x %-s\n",
2930 (int)table
[i
].sa_attr
, (int)table
[i
].sa_registered
,
2931 (int)table
[i
].sa_length
, table
[i
].sa_byteswap
, name
);
2938 sa_get_off_table(uintptr_t addr
, uint32_t **off_tab
, int attr_count
)
2940 uintptr_t idx_table
;
2942 if (GETMEMB(addr
, "sa_idx_tab", sa_idx_tab
, idx_table
)) {
2943 mdb_printf("can't find offset table in sa_idx_tab\n");
2947 *off_tab
= mdb_alloc(attr_count
* sizeof (uint32_t),
2950 if (mdb_vread(*off_tab
,
2951 attr_count
* sizeof (uint32_t), idx_table
) == -1) {
2952 mdb_warn("failed to attribute offset table %p", idx_table
);
2961 sa_attr_print(uintptr_t addr
, uint_t flags
, int argc
, const mdb_arg_t
*argv
)
2963 uint32_t *offset_tab
;
2966 uintptr_t attr_addr
;
2967 uintptr_t bonus_tab
, spill_tab
;
2968 uintptr_t db_bonus
, db_spill
;
2969 uintptr_t os
, os_sa
;
2973 return (DCMD_USAGE
);
2975 if (argv
[0].a_type
== MDB_TYPE_STRING
)
2976 attr_id
= mdb_strtoull(argv
[0].a_un
.a_str
);
2978 return (DCMD_USAGE
);
2980 if (GETMEMB(addr
, "sa_handle", sa_bonus_tab
, bonus_tab
) ||
2981 GETMEMB(addr
, "sa_handle", sa_spill_tab
, spill_tab
) ||
2982 GETMEMB(addr
, "sa_handle", sa_os
, os
) ||
2983 GETMEMB(addr
, "sa_handle", sa_bonus
, db_bonus
) ||
2984 GETMEMB(addr
, "sa_handle", sa_spill
, db_spill
)) {
2985 mdb_printf("Can't find necessary information in sa_handle "
2990 if (GETMEMB(os
, "objset", os_sa
, os_sa
)) {
2991 mdb_printf("Can't find os_sa in objset\n");
2995 if (GETMEMB(os_sa
, "sa_os", sa_num_attrs
, attr_count
)) {
2996 mdb_printf("Can't find sa_num_attrs\n");
3000 if (attr_id
> attr_count
) {
3001 mdb_printf("attribute id number is out of range\n");
3006 if (sa_get_off_table(bonus_tab
, &offset_tab
,
3007 attr_count
) == -1) {
3011 if (GETMEMB(db_bonus
, "dmu_buf", db_data
, db_data
)) {
3012 mdb_printf("can't find db_data in bonus dbuf\n");
3017 if (bonus_tab
&& !TOC_ATTR_PRESENT(offset_tab
[attr_id
]) &&
3018 spill_tab
== NULL
) {
3019 mdb_printf("Attribute does not exist\n");
3021 } else if (!TOC_ATTR_PRESENT(offset_tab
[attr_id
]) && spill_tab
) {
3022 if (sa_get_off_table(spill_tab
, &offset_tab
,
3023 attr_count
) == -1) {
3026 if (GETMEMB(db_spill
, "dmu_buf", db_data
, db_data
)) {
3027 mdb_printf("can't find db_data in spill dbuf\n");
3030 if (!TOC_ATTR_PRESENT(offset_tab
[attr_id
])) {
3031 mdb_printf("Attribute does not exist\n");
3035 attr_addr
= db_data
+ TOC_OFF(offset_tab
[attr_id
]);
3036 mdb_printf("%p\n", attr_addr
);
3042 zfs_ace_print_common(uintptr_t addr
, uint_t flags
,
3043 uint64_t id
, uint32_t access_mask
, uint16_t ace_flags
,
3044 uint16_t ace_type
, int verbose
)
3046 if (DCMD_HDRSPEC(flags
) && !verbose
)
3047 mdb_printf("%<u>%-?s %-8s %-8s %-8s %s%</u>\n",
3048 "ADDR", "FLAGS", "MASK", "TYPE", "ID");
3051 mdb_printf("%0?p %-8x %-8x %-8x %-llx\n", addr
,
3052 ace_flags
, access_mask
, ace_type
, id
);
3056 switch (ace_flags
& ACE_TYPE_FLAGS
) {
3058 mdb_printf("owner@:");
3060 case (ACE_IDENTIFIER_GROUP
| ACE_GROUP
):
3061 mdb_printf("group@:");
3064 mdb_printf("everyone@:");
3066 case ACE_IDENTIFIER_GROUP
:
3067 mdb_printf("group:%llx:", (u_longlong_t
)id
);
3069 case 0: /* User entry */
3070 mdb_printf("user:%llx:", (u_longlong_t
)id
);
3074 /* print out permission mask */
3075 if (access_mask
& ACE_READ_DATA
)
3079 if (access_mask
& ACE_WRITE_DATA
)
3083 if (access_mask
& ACE_EXECUTE
)
3087 if (access_mask
& ACE_APPEND_DATA
)
3091 if (access_mask
& ACE_DELETE
)
3095 if (access_mask
& ACE_DELETE_CHILD
)
3099 if (access_mask
& ACE_READ_ATTRIBUTES
)
3103 if (access_mask
& ACE_WRITE_ATTRIBUTES
)
3107 if (access_mask
& ACE_READ_NAMED_ATTRS
)
3111 if (access_mask
& ACE_WRITE_NAMED_ATTRS
)
3115 if (access_mask
& ACE_READ_ACL
)
3119 if (access_mask
& ACE_WRITE_ACL
)
3123 if (access_mask
& ACE_WRITE_OWNER
)
3127 if (access_mask
& ACE_SYNCHRONIZE
)
3134 /* Print out inheritance flags */
3135 if (ace_flags
& ACE_FILE_INHERIT_ACE
)
3139 if (ace_flags
& ACE_DIRECTORY_INHERIT_ACE
)
3143 if (ace_flags
& ACE_INHERIT_ONLY_ACE
)
3147 if (ace_flags
& ACE_NO_PROPAGATE_INHERIT_ACE
)
3151 if (ace_flags
& ACE_SUCCESSFUL_ACCESS_ACE_FLAG
)
3155 if (ace_flags
& ACE_FAILED_ACCESS_ACE_FLAG
)
3159 if (ace_flags
& ACE_INHERITED_ACE
)
3165 case ACE_ACCESS_ALLOWED_ACE_TYPE
:
3166 mdb_printf(":allow\n");
3168 case ACE_ACCESS_DENIED_ACE_TYPE
:
3169 mdb_printf(":deny\n");
3171 case ACE_SYSTEM_AUDIT_ACE_TYPE
:
3172 mdb_printf(":audit\n");
3174 case ACE_SYSTEM_ALARM_ACE_TYPE
:
3175 mdb_printf(":alarm\n");
3185 zfs_ace_print(uintptr_t addr
, uint_t flags
, int argc
, const mdb_arg_t
*argv
)
3188 int verbose
= FALSE
;
3191 if (!(flags
& DCMD_ADDRSPEC
))
3192 return (DCMD_USAGE
);
3194 if (mdb_getopts(argc
, argv
,
3195 'v', MDB_OPT_SETBITS
, TRUE
, &verbose
, TRUE
, NULL
) != argc
)
3196 return (DCMD_USAGE
);
3198 if (mdb_vread(&zace
, sizeof (zfs_ace_t
), addr
) == -1) {
3199 mdb_warn("failed to read zfs_ace_t");
3203 if ((zace
.z_hdr
.z_flags
& ACE_TYPE_FLAGS
) == 0 ||
3204 (zace
.z_hdr
.z_flags
& ACE_TYPE_FLAGS
) == ACE_IDENTIFIER_GROUP
)
3209 return (zfs_ace_print_common(addr
, flags
, id
, zace
.z_hdr
.z_access_mask
,
3210 zace
.z_hdr
.z_flags
, zace
.z_hdr
.z_type
, verbose
));
3215 zfs_ace0_print(uintptr_t addr
, uint_t flags
, int argc
, const mdb_arg_t
*argv
)
3219 int verbose
= FALSE
;
3221 if (!(flags
& DCMD_ADDRSPEC
))
3222 return (DCMD_USAGE
);
3224 if (mdb_getopts(argc
, argv
,
3225 'v', MDB_OPT_SETBITS
, TRUE
, &verbose
, TRUE
, NULL
) != argc
)
3226 return (DCMD_USAGE
);
3228 if (mdb_vread(&ace
, sizeof (ace_t
), addr
) == -1) {
3229 mdb_warn("failed to read ace_t");
3233 if ((ace
.a_flags
& ACE_TYPE_FLAGS
) == 0 ||
3234 (ace
.a_flags
& ACE_TYPE_FLAGS
) == ACE_IDENTIFIER_GROUP
)
3239 return (zfs_ace_print_common(addr
, flags
, id
, ace
.a_access_mask
,
3240 ace
.a_flags
, ace
.a_type
, verbose
));
3243 typedef struct acl_dump_args
{
3245 const mdb_arg_t
*a_argv
;
3252 acl_aces_cb(uintptr_t addr
, const void *unknown
, void *arg
)
3254 acl_dump_args_t
*acl_args
= (acl_dump_args_t
*)arg
;
3256 if (acl_args
->a_version
== 1) {
3257 if (mdb_call_dcmd("zfs_ace", addr
,
3258 DCMD_ADDRSPEC
|acl_args
->a_flags
, acl_args
->a_argc
,
3259 acl_args
->a_argv
) != DCMD_OK
) {
3263 if (mdb_call_dcmd("zfs_ace0", addr
,
3264 DCMD_ADDRSPEC
|acl_args
->a_flags
, acl_args
->a_argc
,
3265 acl_args
->a_argv
) != DCMD_OK
) {
3269 acl_args
->a_flags
= DCMD_LOOP
;
3275 acl_cb(uintptr_t addr
, const void *unknown
, void *arg
)
3277 acl_dump_args_t
*acl_args
= (acl_dump_args_t
*)arg
;
3279 if (acl_args
->a_version
== 1) {
3280 if (mdb_pwalk("zfs_acl_node_aces", acl_aces_cb
,
3282 mdb_warn("can't walk ACEs");
3286 if (mdb_pwalk("zfs_acl_node_aces0", acl_aces_cb
,
3288 mdb_warn("can't walk ACEs");
3297 zfs_acl_dump(uintptr_t addr
, uint_t flags
, int argc
, const mdb_arg_t
*argv
)
3300 int verbose
= FALSE
;
3301 acl_dump_args_t acl_args
;
3303 if (!(flags
& DCMD_ADDRSPEC
))
3304 return (DCMD_USAGE
);
3306 if (mdb_getopts(argc
, argv
,
3307 'v', MDB_OPT_SETBITS
, TRUE
, &verbose
, TRUE
, NULL
) != argc
)
3308 return (DCMD_USAGE
);
3310 if (mdb_vread(&zacl
, sizeof (zfs_acl_t
), addr
) == -1) {
3311 mdb_warn("failed to read zfs_acl_t");
3315 acl_args
.a_argc
= argc
;
3316 acl_args
.a_argv
= argv
;
3317 acl_args
.a_version
= zacl
.z_version
;
3318 acl_args
.a_flags
= DCMD_LOOPFIRST
;
3320 if (mdb_pwalk("zfs_acl_node", acl_cb
, &acl_args
, addr
) != 0) {
3321 mdb_warn("can't walk ACL");
3330 zfs_acl_node_walk_init(mdb_walk_state_t
*wsp
)
3332 if (wsp
->walk_addr
== NULL
) {
3333 mdb_warn("must supply address of zfs_acl_node_t\n");
3338 mdb_ctf_offsetof_by_name(ZFS_STRUCT
"zfs_acl", "z_acl");
3340 if (mdb_layered_walk("list", wsp
) == -1) {
3341 mdb_warn("failed to walk 'list'\n");
3349 zfs_acl_node_walk_step(mdb_walk_state_t
*wsp
)
3351 zfs_acl_node_t aclnode
;
3353 if (mdb_vread(&aclnode
, sizeof (zfs_acl_node_t
),
3354 wsp
->walk_addr
) == -1) {
3355 mdb_warn("failed to read zfs_acl_node at %p", wsp
->walk_addr
);
3359 return (wsp
->walk_callback(wsp
->walk_addr
, &aclnode
, wsp
->walk_cbdata
));
3362 typedef struct ace_walk_data
{
3368 zfs_aces_walk_init_common(mdb_walk_state_t
*wsp
, int version
,
3369 int ace_count
, uintptr_t ace_data
)
3371 ace_walk_data_t
*ace_walk_data
;
3373 if (wsp
->walk_addr
== NULL
) {
3374 mdb_warn("must supply address of zfs_acl_node_t\n");
3378 ace_walk_data
= mdb_alloc(sizeof (ace_walk_data_t
), UM_SLEEP
| UM_GC
);
3380 ace_walk_data
->ace_count
= ace_count
;
3381 ace_walk_data
->ace_version
= version
;
3383 wsp
->walk_addr
= ace_data
;
3384 wsp
->walk_data
= ace_walk_data
;
3390 zfs_acl_node_aces_walk_init_common(mdb_walk_state_t
*wsp
, int version
)
3393 static mdb_ctf_id_t acl_id
;
3395 uintptr_t z_acldata
;
3398 if (mdb_ctf_lookup_by_name("struct zfs_acl_node",
3400 mdb_warn("couldn't find struct zfs_acl_node");
3406 if (GETMEMBID(wsp
->walk_addr
, &acl_id
, z_ace_count
, z_ace_count
)) {
3409 if (GETMEMBID(wsp
->walk_addr
, &acl_id
, z_acldata
, z_acldata
)) {
3413 return (zfs_aces_walk_init_common(wsp
, version
,
3414 z_ace_count
, z_acldata
));
3419 zfs_acl_node_aces_walk_init(mdb_walk_state_t
*wsp
)
3421 return (zfs_acl_node_aces_walk_init_common(wsp
, 1));
3426 zfs_acl_node_aces0_walk_init(mdb_walk_state_t
*wsp
)
3428 return (zfs_acl_node_aces_walk_init_common(wsp
, 0));
3432 zfs_aces_walk_step(mdb_walk_state_t
*wsp
)
3434 ace_walk_data_t
*ace_data
= wsp
->walk_data
;
3442 if (ace_data
->ace_count
== 0)
3445 if (mdb_vread(&zace
, sizeof (zfs_ace_t
), wsp
->walk_addr
) == -1) {
3446 mdb_warn("failed to read zfs_ace_t at %#lx",
3451 switch (ace_data
->ace_version
) {
3453 acep
= (ace_t
*)&zace
;
3454 entry_type
= acep
->a_flags
& ACE_TYPE_FLAGS
;
3455 allow_type
= acep
->a_type
;
3458 entry_type
= zace
.z_hdr
.z_flags
& ACE_TYPE_FLAGS
;
3459 allow_type
= zace
.z_hdr
.z_type
;
3465 ptr
= (uintptr_t)wsp
->walk_addr
;
3466 switch (entry_type
) {
3469 case (ACE_IDENTIFIER_GROUP
| ACE_GROUP
):
3470 ptr
+= ace_data
->ace_version
== 0 ?
3471 sizeof (ace_t
) : sizeof (zfs_ace_hdr_t
);
3473 case ACE_IDENTIFIER_GROUP
:
3475 switch (allow_type
) {
3476 case ACE_ACCESS_ALLOWED_OBJECT_ACE_TYPE
:
3477 case ACE_ACCESS_DENIED_OBJECT_ACE_TYPE
:
3478 case ACE_SYSTEM_AUDIT_OBJECT_ACE_TYPE
:
3479 case ACE_SYSTEM_ALARM_OBJECT_ACE_TYPE
:
3480 ptr
+= ace_data
->ace_version
== 0 ?
3481 sizeof (ace_t
) : sizeof (zfs_object_ace_t
);
3484 ptr
+= ace_data
->ace_version
== 0 ?
3485 sizeof (ace_t
) : sizeof (zfs_ace_t
);
3490 ace_data
->ace_count
--;
3491 status
= wsp
->walk_callback(wsp
->walk_addr
,
3492 (void *)(uintptr_t)&zace
, wsp
->walk_cbdata
);
3494 wsp
->walk_addr
= ptr
;
3498 typedef struct mdb_zfs_rrwlock
{
3499 uintptr_t rr_writer
;
3500 boolean_t rr_writer_wanted
;
3501 } mdb_zfs_rrwlock_t
;
3503 static uint_t rrw_key
;
3507 rrwlock(uintptr_t addr
, uint_t flags
, int argc
, const mdb_arg_t
*argv
)
3509 mdb_zfs_rrwlock_t rrw
;
3512 if (mdb_ctf_readsym(&rrw_key
, "uint_t", "rrw_tsd_key", 0) == -1)
3516 if (mdb_ctf_vread(&rrw
, "rrwlock_t", "mdb_zfs_rrwlock_t", addr
,
3520 if (rrw
.rr_writer
!= 0) {
3521 mdb_printf("write lock held by thread %lx\n", rrw
.rr_writer
);
3525 if (rrw
.rr_writer_wanted
) {
3526 mdb_printf("writer wanted\n");
3529 mdb_printf("anonymous references:\n");
3530 (void) mdb_call_dcmd("refcount", addr
+
3531 mdb_ctf_offsetof_by_name(ZFS_STRUCT
"rrwlock", "rr_anon_rcount"),
3532 DCMD_ADDRSPEC
, 0, NULL
);
3534 mdb_printf("linked references:\n");
3535 (void) mdb_call_dcmd("refcount", addr
+
3536 mdb_ctf_offsetof_by_name(ZFS_STRUCT
"rrwlock", "rr_linked_rcount"),
3537 DCMD_ADDRSPEC
, 0, NULL
);
3540 * XXX This should find references from
3541 * "::walk thread | ::tsd -v <rrw_key>", but there is no support
3542 * for programmatic consumption of dcmds, so this would be
3543 * difficult, potentially requiring reimplementing ::tsd (both
3544 * user and kernel versions) in this MDB module.
3550 typedef struct mdb_arc_buf_hdr_t
{
3557 } mdb_arc_buf_hdr_t
;
3560 ARC_CFLAG_VERBOSE
= 1 << 0,
3561 ARC_CFLAG_ANON
= 1 << 1,
3562 ARC_CFLAG_MRU
= 1 << 2,
3563 ARC_CFLAG_MFU
= 1 << 3,
3564 ARC_CFLAG_BUFS
= 1 << 4,
3567 typedef struct arc_compression_stats_data
{
3568 GElf_Sym anon_sym
; /* ARC_anon symbol */
3569 GElf_Sym mru_sym
; /* ARC_mru symbol */
3570 GElf_Sym mrug_sym
; /* ARC_mru_ghost symbol */
3571 GElf_Sym mfu_sym
; /* ARC_mfu symbol */
3572 GElf_Sym mfug_sym
; /* ARC_mfu_ghost symbol */
3573 GElf_Sym l2c_sym
; /* ARC_l2c_only symbol */
3574 uint64_t *anon_c_hist
; /* histogram of compressed sizes in anon */
3575 uint64_t *anon_u_hist
; /* histogram of uncompressed sizes in anon */
3576 uint64_t *anon_bufs
; /* histogram of buffer counts in anon state */
3577 uint64_t *mru_c_hist
; /* histogram of compressed sizes in mru */
3578 uint64_t *mru_u_hist
; /* histogram of uncompressed sizes in mru */
3579 uint64_t *mru_bufs
; /* histogram of buffer counts in mru */
3580 uint64_t *mfu_c_hist
; /* histogram of compressed sizes in mfu */
3581 uint64_t *mfu_u_hist
; /* histogram of uncompressed sizes in mfu */
3582 uint64_t *mfu_bufs
; /* histogram of buffer counts in mfu */
3583 uint64_t *all_c_hist
; /* histogram of compressed anon + mru + mfu */
3584 uint64_t *all_u_hist
; /* histogram of uncompressed anon + mru + mfu */
3585 uint64_t *all_bufs
; /* histogram of buffer counts in all states */
3586 int arc_cflags
; /* arc compression flags, specified by user */
3587 int hist_nbuckets
; /* number of buckets in each histogram */
3588 } arc_compression_stats_data_t
;
3591 highbit64(uint64_t i
)
3597 if (i
& 0xffffffff00000000ULL
) {
3600 if (i
& 0xffff0000) {
3620 arc_compression_stats_cb(uintptr_t addr
, const void *unknown
, void *arg
)
3622 arc_compression_stats_data_t
*data
= arg
;
3623 mdb_arc_buf_hdr_t hdr
;
3624 int cbucket
, ubucket
, bufcnt
;
3626 if (mdb_ctf_vread(&hdr
, "arc_buf_hdr_t", "mdb_arc_buf_hdr_t",
3632 * Headers in the ghost states, or the l2c_only state don't have
3633 * arc buffers linked off of them. Thus, their compressed size
3634 * is meaningless, so we skip these from the stats.
3636 if (hdr
.b_l1hdr
.b_state
== data
->mrug_sym
.st_value
||
3637 hdr
.b_l1hdr
.b_state
== data
->mfug_sym
.st_value
||
3638 hdr
.b_l1hdr
.b_state
== data
->l2c_sym
.st_value
) {
3643 * The physical size (compressed) and logical size
3644 * (uncompressed) are in units of SPA_MINBLOCKSIZE. By default,
3645 * we use the log2 of this value (rounded down to the nearest
3646 * integer) to determine the bucket to assign this header to.
3647 * Thus, the histogram is logarithmic with respect to the size
3648 * of the header. For example, the following is a mapping of the
3649 * bucket numbers and the range of header sizes they correspond to:
3652 * 1: 512 byte headers
3653 * 2: [1024 - 2048) byte headers
3654 * 3: [2048 - 4096) byte headers
3655 * 4: [4096 - 8192) byte headers
3656 * 5: [8192 - 16394) byte headers
3657 * 6: [16384 - 32768) byte headers
3658 * 7: [32768 - 65536) byte headers
3659 * 8: [65536 - 131072) byte headers
3660 * 9: 131072 byte headers
3662 * If the ARC_CFLAG_VERBOSE flag was specified, we use the
3663 * physical and logical sizes directly. Thus, the histogram will
3664 * no longer be logarithmic; instead it will be linear with
3665 * respect to the size of the header. The following is a mapping
3666 * of the first many bucket numbers and the header size they
3670 * 1: 512 byte headers
3671 * 2: 1024 byte headers
3672 * 3: 1536 byte headers
3673 * 4: 2048 byte headers
3674 * 5: 2560 byte headers
3675 * 6: 3072 byte headers
3677 * And so on. Keep in mind that a range of sizes isn't used in
3678 * the case of linear scale because the headers can only
3679 * increment or decrement in sizes of 512 bytes. So, it's not
3680 * possible for a header to be sized in between whats listed
3683 * Also, the above mapping values were calculated assuming a
3684 * SPA_MINBLOCKSHIFT of 512 bytes and a SPA_MAXBLOCKSIZE of 128K.
3687 if (data
->arc_cflags
& ARC_CFLAG_VERBOSE
) {
3688 cbucket
= hdr
.b_psize
;
3689 ubucket
= hdr
.b_lsize
;
3691 cbucket
= highbit64(hdr
.b_psize
);
3692 ubucket
= highbit64(hdr
.b_lsize
);
3695 bufcnt
= hdr
.b_l1hdr
.b_bufcnt
;
3696 if (bufcnt
>= data
->hist_nbuckets
)
3697 bufcnt
= data
->hist_nbuckets
- 1;
3699 /* Ensure we stay within the bounds of the histogram array */
3700 ASSERT3U(cbucket
, <, data
->hist_nbuckets
);
3701 ASSERT3U(ubucket
, <, data
->hist_nbuckets
);
3703 if (hdr
.b_l1hdr
.b_state
== data
->anon_sym
.st_value
) {
3704 data
->anon_c_hist
[cbucket
]++;
3705 data
->anon_u_hist
[ubucket
]++;
3706 data
->anon_bufs
[bufcnt
]++;
3707 } else if (hdr
.b_l1hdr
.b_state
== data
->mru_sym
.st_value
) {
3708 data
->mru_c_hist
[cbucket
]++;
3709 data
->mru_u_hist
[ubucket
]++;
3710 data
->mru_bufs
[bufcnt
]++;
3711 } else if (hdr
.b_l1hdr
.b_state
== data
->mfu_sym
.st_value
) {
3712 data
->mfu_c_hist
[cbucket
]++;
3713 data
->mfu_u_hist
[ubucket
]++;
3714 data
->mfu_bufs
[bufcnt
]++;
3717 data
->all_c_hist
[cbucket
]++;
3718 data
->all_u_hist
[ubucket
]++;
3719 data
->all_bufs
[bufcnt
]++;
3726 arc_compression_stats(uintptr_t addr
, uint_t flags
, int argc
,
3727 const mdb_arg_t
*argv
)
3729 arc_compression_stats_data_t data
= { 0 };
3730 unsigned int max_shifted
= SPA_MAXBLOCKSIZE
>> SPA_MINBLOCKSHIFT
;
3731 unsigned int hist_size
;
3735 if (mdb_getopts(argc
, argv
,
3736 'v', MDB_OPT_SETBITS
, ARC_CFLAG_VERBOSE
, &data
.arc_cflags
,
3737 'a', MDB_OPT_SETBITS
, ARC_CFLAG_ANON
, &data
.arc_cflags
,
3738 'b', MDB_OPT_SETBITS
, ARC_CFLAG_BUFS
, &data
.arc_cflags
,
3739 'r', MDB_OPT_SETBITS
, ARC_CFLAG_MRU
, &data
.arc_cflags
,
3740 'f', MDB_OPT_SETBITS
, ARC_CFLAG_MFU
, &data
.arc_cflags
) != argc
)
3741 return (DCMD_USAGE
);
3743 if (mdb_lookup_by_obj(ZFS_OBJ_NAME
, "ARC_anon", &data
.anon_sym
) ||
3744 mdb_lookup_by_obj(ZFS_OBJ_NAME
, "ARC_mru", &data
.mru_sym
) ||
3745 mdb_lookup_by_obj(ZFS_OBJ_NAME
, "ARC_mru_ghost", &data
.mrug_sym
) ||
3746 mdb_lookup_by_obj(ZFS_OBJ_NAME
, "ARC_mfu", &data
.mfu_sym
) ||
3747 mdb_lookup_by_obj(ZFS_OBJ_NAME
, "ARC_mfu_ghost", &data
.mfug_sym
) ||
3748 mdb_lookup_by_obj(ZFS_OBJ_NAME
, "ARC_l2c_only", &data
.l2c_sym
)) {
3749 mdb_warn("can't find arc state symbol");
3754 * Determine the maximum expected size for any header, and use
3755 * this to determine the number of buckets needed for each
3756 * histogram. If ARC_CFLAG_VERBOSE is specified, this value is
3757 * used directly; otherwise the log2 of the maximum size is
3758 * used. Thus, if using a log2 scale there's a maximum of 10
3759 * possible buckets, while the linear scale (when using
3760 * ARC_CFLAG_VERBOSE) has a maximum of 257 buckets.
3762 if (data
.arc_cflags
& ARC_CFLAG_VERBOSE
)
3763 data
.hist_nbuckets
= max_shifted
+ 1;
3765 data
.hist_nbuckets
= highbit64(max_shifted
) + 1;
3767 hist_size
= sizeof (uint64_t) * data
.hist_nbuckets
;
3769 data
.anon_c_hist
= mdb_zalloc(hist_size
, UM_SLEEP
);
3770 data
.anon_u_hist
= mdb_zalloc(hist_size
, UM_SLEEP
);
3771 data
.anon_bufs
= mdb_zalloc(hist_size
, UM_SLEEP
);
3773 data
.mru_c_hist
= mdb_zalloc(hist_size
, UM_SLEEP
);
3774 data
.mru_u_hist
= mdb_zalloc(hist_size
, UM_SLEEP
);
3775 data
.mru_bufs
= mdb_zalloc(hist_size
, UM_SLEEP
);
3777 data
.mfu_c_hist
= mdb_zalloc(hist_size
, UM_SLEEP
);
3778 data
.mfu_u_hist
= mdb_zalloc(hist_size
, UM_SLEEP
);
3779 data
.mfu_bufs
= mdb_zalloc(hist_size
, UM_SLEEP
);
3781 data
.all_c_hist
= mdb_zalloc(hist_size
, UM_SLEEP
);
3782 data
.all_u_hist
= mdb_zalloc(hist_size
, UM_SLEEP
);
3783 data
.all_bufs
= mdb_zalloc(hist_size
, UM_SLEEP
);
3785 if (mdb_walk("arc_buf_hdr_t_full", arc_compression_stats_cb
,
3787 mdb_warn("can't walk arc_buf_hdr's");
3792 if (data
.arc_cflags
& ARC_CFLAG_VERBOSE
) {
3793 rc
= mdb_snprintf(range
, sizeof (range
),
3794 "[n*%llu, (n+1)*%llu)", SPA_MINBLOCKSIZE
,
3797 rc
= mdb_snprintf(range
, sizeof (range
),
3798 "[2^(n-1)*%llu, 2^n*%llu)", SPA_MINBLOCKSIZE
,
3803 /* snprintf failed, abort the dcmd */
3807 /* snprintf succeeded above, reset return code */
3811 if (data
.arc_cflags
& ARC_CFLAG_ANON
) {
3812 if (data
.arc_cflags
& ARC_CFLAG_BUFS
) {
3813 mdb_printf("Histogram of the number of anon buffers "
3814 "that are associated with an arc hdr.\n");
3815 dump_histogram(data
.anon_bufs
, data
.hist_nbuckets
, 0);
3818 mdb_printf("Histogram of compressed anon buffers.\n"
3819 "Each bucket represents buffers of size: %s.\n", range
);
3820 dump_histogram(data
.anon_c_hist
, data
.hist_nbuckets
, 0);
3823 mdb_printf("Histogram of uncompressed anon buffers.\n"
3824 "Each bucket represents buffers of size: %s.\n", range
);
3825 dump_histogram(data
.anon_u_hist
, data
.hist_nbuckets
, 0);
3829 if (data
.arc_cflags
& ARC_CFLAG_MRU
) {
3830 if (data
.arc_cflags
& ARC_CFLAG_BUFS
) {
3831 mdb_printf("Histogram of the number of mru buffers "
3832 "that are associated with an arc hdr.\n");
3833 dump_histogram(data
.mru_bufs
, data
.hist_nbuckets
, 0);
3836 mdb_printf("Histogram of compressed mru buffers.\n"
3837 "Each bucket represents buffers of size: %s.\n", range
);
3838 dump_histogram(data
.mru_c_hist
, data
.hist_nbuckets
, 0);
3841 mdb_printf("Histogram of uncompressed mru buffers.\n"
3842 "Each bucket represents buffers of size: %s.\n", range
);
3843 dump_histogram(data
.mru_u_hist
, data
.hist_nbuckets
, 0);
3847 if (data
.arc_cflags
& ARC_CFLAG_MFU
) {
3848 if (data
.arc_cflags
& ARC_CFLAG_BUFS
) {
3849 mdb_printf("Histogram of the number of mfu buffers "
3850 "that are associated with an arc hdr.\n");
3851 dump_histogram(data
.mfu_bufs
, data
.hist_nbuckets
, 0);
3855 mdb_printf("Histogram of compressed mfu buffers.\n"
3856 "Each bucket represents buffers of size: %s.\n", range
);
3857 dump_histogram(data
.mfu_c_hist
, data
.hist_nbuckets
, 0);
3860 mdb_printf("Histogram of uncompressed mfu buffers.\n"
3861 "Each bucket represents buffers of size: %s.\n", range
);
3862 dump_histogram(data
.mfu_u_hist
, data
.hist_nbuckets
, 0);
3866 if (data
.arc_cflags
& ARC_CFLAG_BUFS
) {
3867 mdb_printf("Histogram of all buffers that "
3868 "are associated with an arc hdr.\n");
3869 dump_histogram(data
.all_bufs
, data
.hist_nbuckets
, 0);
3873 mdb_printf("Histogram of all compressed buffers.\n"
3874 "Each bucket represents buffers of size: %s.\n", range
);
3875 dump_histogram(data
.all_c_hist
, data
.hist_nbuckets
, 0);
3878 mdb_printf("Histogram of all uncompressed buffers.\n"
3879 "Each bucket represents buffers of size: %s.\n", range
);
3880 dump_histogram(data
.all_u_hist
, data
.hist_nbuckets
, 0);
3883 mdb_free(data
.anon_c_hist
, hist_size
);
3884 mdb_free(data
.anon_u_hist
, hist_size
);
3885 mdb_free(data
.anon_bufs
, hist_size
);
3887 mdb_free(data
.mru_c_hist
, hist_size
);
3888 mdb_free(data
.mru_u_hist
, hist_size
);
3889 mdb_free(data
.mru_bufs
, hist_size
);
3891 mdb_free(data
.mfu_c_hist
, hist_size
);
3892 mdb_free(data
.mfu_u_hist
, hist_size
);
3893 mdb_free(data
.mfu_bufs
, hist_size
);
3895 mdb_free(data
.all_c_hist
, hist_size
);
3896 mdb_free(data
.all_u_hist
, hist_size
);
3897 mdb_free(data
.all_bufs
, hist_size
);
3903 * MDB module linkage information:
3905 * We declare a list of structures describing our dcmds, and a function
3906 * named _mdb_init to return a pointer to our module information.
3909 static const mdb_dcmd_t dcmds
[] = {
3910 { "arc", "[-bkmg]", "print ARC variables", arc_print
},
3911 { "blkptr", ":", "print blkptr_t", blkptr
},
3912 { "dbuf", ":", "print dmu_buf_impl_t", dbuf
},
3913 { "dbuf_stats", ":", "dbuf stats", dbuf_stats
},
3915 "\t[-O objset_t*] [-n objset_name | \"mos\"] "
3916 "[-o object | \"mdn\"] \n"
3917 "\t[-l level] [-b blkid | \"bonus\"]",
3918 "find dmu_buf_impl_t's that match specified criteria", dbufs
},
3919 { "abuf_find", "dva_word[0] dva_word[1]",
3920 "find arc_buf_hdr_t of a specified DVA",
3922 { "spa", "?[-cevmMh]\n"
3923 "\t-c display spa config\n"
3924 "\t-e display vdev statistics\n"
3925 "\t-v display vdev information\n"
3926 "\t-m display metaslab statistics\n"
3927 "\t-M display metaslab group statistics\n"
3928 "\t-h display histogram (requires -m or -M)\n",
3929 "spa_t summary", spa_print
},
3930 { "spa_config", ":", "print spa_t configuration", spa_print_config
},
3931 { "spa_space", ":[-b]", "print spa_t on-disk space usage", spa_space
},
3932 { "spa_vdevs", ":[-emMh]\n"
3933 "\t-e display vdev statistics\n"
3934 "\t-m dispaly metaslab statistics\n"
3935 "\t-M display metaslab group statistic\n"
3936 "\t-h display histogram (requires -m or -M)\n",
3937 "given a spa_t, print vdev summary", spa_vdevs
},
3938 { "vdev", ":[-remMh]\n"
3939 "\t-r display recursively\n"
3940 "\t-e display statistics\n"
3941 "\t-m display metaslab statistics (top level vdev only)\n"
3942 "\t-M display metaslab group statistics (top level vdev only)\n"
3943 "\t-h display histogram (requires -m or -M)\n",
3944 "vdev_t summary", vdev_print
},
3945 { "zio", ":[-cpr]\n"
3946 "\t-c display children\n"
3947 "\t-p display parents\n"
3948 "\t-r display recursively",
3949 "zio_t summary", zio_print
},
3950 { "zio_state", "?", "print out all zio_t structures on system or "
3951 "for a particular pool", zio_state
},
3952 { "zfs_blkstats", ":[-v]",
3953 "given a spa_t, print block type stats from last scrub",
3955 { "zfs_params", "", "print zfs tunable parameters", zfs_params
},
3956 { "refcount", ":[-r]\n"
3957 "\t-r display recently removed references",
3958 "print refcount_t holders", refcount
},
3959 { "zap_leaf", "", "print zap_leaf_phys_t", zap_leaf
},
3960 { "zfs_aces", ":[-v]", "print all ACEs from a zfs_acl_t",
3962 { "zfs_ace", ":[-v]", "print zfs_ace", zfs_ace_print
},
3963 { "zfs_ace0", ":[-v]", "print zfs_ace0", zfs_ace0_print
},
3964 { "sa_attr_table", ":", "print SA attribute table from sa_os_t",
3966 { "sa_attr", ": attr_id",
3967 "print SA attribute address when given sa_handle_t", sa_attr_print
},
3968 { "zfs_dbgmsg", ":[-va]",
3969 "print zfs debug log", dbgmsg
},
3971 "print rrwlock_t, including readers", rrwlock
},
3972 { "metaslab_weight", "weight",
3973 "print metaslab weight", metaslab_weight
},
3974 { "metaslab_trace", ":",
3975 "print metaslab allocation trace records", metaslab_trace
},
3976 { "arc_compression_stats", ":[-vabrf]\n"
3977 "\t-v verbose, display a linearly scaled histogram\n"
3978 "\t-a display ARC_anon state statistics individually\n"
3979 "\t-r display ARC_mru state statistics individually\n"
3980 "\t-f display ARC_mfu state statistics individually\n"
3981 "\t-b display histogram of buffer counts\n",
3982 "print a histogram of compressed arc buffer sizes",
3983 arc_compression_stats
},
3987 static const mdb_walker_t walkers
[] = {
3988 { "zms_freelist", "walk ZFS metaslab freelist",
3989 freelist_walk_init
, freelist_walk_step
, NULL
},
3990 { "txg_list", "given any txg_list_t *, walk all entries in all txgs",
3991 txg_list_walk_init
, txg_list_walk_step
, NULL
},
3992 { "txg_list0", "given any txg_list_t *, walk all entries in txg 0",
3993 txg_list0_walk_init
, txg_list_walk_step
, NULL
},
3994 { "txg_list1", "given any txg_list_t *, walk all entries in txg 1",
3995 txg_list1_walk_init
, txg_list_walk_step
, NULL
},
3996 { "txg_list2", "given any txg_list_t *, walk all entries in txg 2",
3997 txg_list2_walk_init
, txg_list_walk_step
, NULL
},
3998 { "txg_list3", "given any txg_list_t *, walk all entries in txg 3",
3999 txg_list3_walk_init
, txg_list_walk_step
, NULL
},
4000 { "zio", "walk all zio structures, optionally for a particular spa_t",
4001 zio_walk_init
, zio_walk_step
, NULL
},
4003 "walk all root zio_t structures, optionally for a particular spa_t",
4004 zio_walk_init
, zio_walk_root_step
, NULL
},
4005 { "spa", "walk all spa_t entries in the namespace",
4006 spa_walk_init
, spa_walk_step
, NULL
},
4007 { "metaslab", "given a spa_t *, walk all metaslab_t structures",
4008 metaslab_walk_init
, metaslab_walk_step
, NULL
},
4009 { "multilist", "given a multilist_t *, walk all list_t structures",
4010 multilist_walk_init
, multilist_walk_step
, NULL
},
4011 { "zfs_acl_node", "given a zfs_acl_t, walk all zfs_acl_nodes",
4012 zfs_acl_node_walk_init
, zfs_acl_node_walk_step
, NULL
},
4013 { "zfs_acl_node_aces", "given a zfs_acl_node_t, walk all ACEs",
4014 zfs_acl_node_aces_walk_init
, zfs_aces_walk_step
, NULL
},
4015 { "zfs_acl_node_aces0",
4016 "given a zfs_acl_node_t, walk all ACEs as ace_t",
4017 zfs_acl_node_aces0_walk_init
, zfs_aces_walk_step
, NULL
},
4021 static const mdb_modinfo_t modinfo
= {
4022 MDB_API_VERSION
, dcmds
, walkers
4025 const mdb_modinfo_t
*