1f38cb554SJohn Wren Kennedy#!/bin/ksh -p
2f38cb554SJohn Wren Kennedy#
3f38cb554SJohn Wren Kennedy# CDDL HEADER START
4f38cb554SJohn Wren Kennedy#
5f38cb554SJohn Wren Kennedy# The contents of this file are subject to the terms of the
6f38cb554SJohn Wren Kennedy# Common Development and Distribution License (the "License").
7f38cb554SJohn Wren Kennedy# You may not use this file except in compliance with the License.
8f38cb554SJohn Wren Kennedy#
9f38cb554SJohn Wren Kennedy# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10f38cb554SJohn Wren Kennedy# or http://www.opensolaris.org/os/licensing.
11f38cb554SJohn Wren Kennedy# See the License for the specific language governing permissions
12f38cb554SJohn Wren Kennedy# and limitations under the License.
13f38cb554SJohn Wren Kennedy#
14f38cb554SJohn Wren Kennedy# When distributing Covered Code, include this CDDL HEADER in each
15f38cb554SJohn Wren Kennedy# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16f38cb554SJohn Wren Kennedy# If applicable, add the following below this CDDL HEADER, with the
17f38cb554SJohn Wren Kennedy# fields enclosed by brackets "[]" replaced with your own identifying
18f38cb554SJohn Wren Kennedy# information: Portions Copyright [yyyy] [name of copyright owner]
19f38cb554SJohn Wren Kennedy#
20f38cb554SJohn Wren Kennedy# CDDL HEADER END
21f38cb554SJohn Wren Kennedy#
22f38cb554SJohn Wren Kennedy
23f38cb554SJohn Wren Kennedy#
24f38cb554SJohn Wren Kennedy# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
25f38cb554SJohn Wren Kennedy# Use is subject to license terms.
26f38cb554SJohn Wren Kennedy#
27f38cb554SJohn Wren Kennedy
28f38cb554SJohn Wren Kennedy#
29*b68ab351SSara Hartse# Copyright (c) 2013, 2017 by Delphix. All rights reserved.
30*b68ab351SSara Hartse# Copyright 2020 Joyent, Inc.
31f38cb554SJohn Wren Kennedy#
32f38cb554SJohn Wren Kennedy
33f38cb554SJohn Wren Kennedy. $STF_SUITE/include/libtest.shlib
34f38cb554SJohn Wren Kennedy
35f38cb554SJohn Wren Kennedy#
36f38cb554SJohn Wren Kennedy# DESCRIPTION:
37f38cb554SJohn Wren Kennedy#	Verify that the ZFS mdb dcmds and walkers are working as expected.
38f38cb554SJohn Wren Kennedy#
39f38cb554SJohn Wren Kennedy# STRATEGY:
40f38cb554SJohn Wren Kennedy#	1) Given a list of dcmds and walkers
41f38cb554SJohn Wren Kennedy#	2) Step through each element of the list
42f38cb554SJohn Wren Kennedy#	3) Verify the output by checking for "mdb:" in the output string
43f38cb554SJohn Wren Kennedy#
44f38cb554SJohn Wren Kennedy
45f38cb554SJohn Wren Kennedyfunction cleanup
46f38cb554SJohn Wren Kennedy{
47*b68ab351SSara Hartse	rm -f $tmpfile
48f38cb554SJohn Wren Kennedy}
49f38cb554SJohn Wren Kennedy
50f38cb554SJohn Wren Kennedyverify_runnable "global"
51f38cb554SJohn Wren Kennedylog_onexit cleanup
52f38cb554SJohn Wren Kennedy
53770499e1SDan Kimmeltmpfile=$(mktemp)
54770499e1SDan Kimmellog_must zpool scrub $TESTPOOL
55770499e1SDan Kimmel
56770499e1SDan Kimmeltypeset spa=$(mdb -ke "::spa" | awk "/$TESTPOOL/ {print \$1}")
57770499e1SDan Kimmeltypeset off_ub=$(mdb -ke "::offsetof spa_t spa_uberblock | =J")
58770499e1SDan Kimmeltypeset off_rbp=$(mdb -ke "::offsetof uberblock_t ub_rootbp | =J")
59770499e1SDan Kimmeltypeset bp=$(mdb -ke "$spa + $off_ub + $off_rbp =J")
60770499e1SDan Kimmel
61770499e1SDan Kimmel# dcmds and walkers skipped due to being DEBUG only or difficult to run:
62770499e1SDan Kimmel# ::zfs_params
63770499e1SDan Kimmel# ::refcount
64*b68ab351SSara Hartse# ::walk zms_freelist
65770499e1SDan Kimmel
66770499e1SDan Kimmelset -A dcmds "::abuf_find 1 2" \
67770499e1SDan Kimmel	"::arc" \
68770499e1SDan Kimmel	"::arc -b" \
69770499e1SDan Kimmel	"::arc_compression_stats" \
70770499e1SDan Kimmel	"$bp ::blkptr" \
71770499e1SDan Kimmel	"$bp ::dva" \
72770499e1SDan Kimmel	"::walk spa" \
73770499e1SDan Kimmel	"::spa" \
74770499e1SDan Kimmel	"$spa ::spa " \
75770499e1SDan Kimmel	"$spa ::spa -c" \
76770499e1SDan Kimmel	"$spa ::spa -h" \
77770499e1SDan Kimmel	"$spa ::spa -v" \
78770499e1SDan Kimmel	"$spa ::spa -Mmh" \
79770499e1SDan Kimmel	"$spa ::spa_config" \
80770499e1SDan Kimmel	"$spa ::spa_space" \
81770499e1SDan Kimmel	"$spa ::spa_space -b" \
82770499e1SDan Kimmel	"$spa ::spa_vdevs" \
83770499e1SDan Kimmel	"$spa ::print spa_t spa_root_vdev | ::vdev" \
84770499e1SDan Kimmel	"$spa ::print spa_t spa_root_vdev | ::vdev -re" \
85770499e1SDan Kimmel	"$spa ::print -a spa_t spa_dsl_pool->dp_dirty_datasets | ::walk txg_list" \
86770499e1SDan Kimmel	"$spa ::print -a spa_t spa_uberblock.ub_rootbp | ::blkptr" \
87770499e1SDan Kimmel	"$spa ::walk metaslab" \
88770499e1SDan Kimmel	"$spa ::walk metaslab | ::head -1 | ::metaslab_weight" \
89*b68ab351SSara Hartse	"*metaslab_alloc_trace_cache::walk kmem | ::metaslab_trace" \
90770499e1SDan Kimmel	"$spa ::walk zio_root | ::zio -c" \
91770499e1SDan Kimmel	"$spa ::walk zio_root | ::zio -r" \
92770499e1SDan Kimmel	"$spa ::zfs_blkstats -v" \
93f38cb554SJohn Wren Kennedy	"::dbufs" \
94f38cb554SJohn Wren Kennedy	"::dbufs -n mos -o mdn -l 0 -b 0" \
95f38cb554SJohn Wren Kennedy	"::dbufs | ::dbuf" \
96f38cb554SJohn Wren Kennedy	"::dbuf_stats" \
97*b68ab351SSara Hartse	"dbuf_caches::print dbuf_cache_t cache | ::walk multilist"
98f38cb554SJohn Wren Kennedy#
99f38cb554SJohn Wren Kennedy# The commands above were supplied by the ZFS development team. The idea is to
100f38cb554SJohn Wren Kennedy# do as much checking as possible without the need to hardcode addresses.
101f38cb554SJohn Wren Kennedy#
102f38cb554SJohn Wren Kennedy
103*b68ab351SSara Hartsefor cmd in ${cmds[@]}; do
104*b68ab351SSara Hartse	log_must eval "mdb -ke \"${cmd}\" >$tmpfile 2>&1"
105f38cb554SJohn Wren Kennedy
106f38cb554SJohn Wren Kennedy	# mdb prefixes all errors with "mdb: " so we check the output.
107*b68ab351SSara Hartse	log_mustnot grep -q "mdb:" $tmpfile
108f38cb554SJohn Wren Kennedydone
109f38cb554SJohn Wren Kennedy
110f38cb554SJohn Wren Kennedylog_pass "The ZFS mdb dcmds and walkers are working as expected."
111