xref: /illumos-gate/usr/src/test/zfs-tests/tests/functional/mdb/mdb_001_pos.ksh (revision c559157643fef9f9afb0414e00a3579407ba3052)
1#!/bin/ksh -p
2#
3# CDDL HEADER START
4#
5# The contents of this file are subject to the terms of the
6# Common Development and Distribution License (the "License").
7# You may not use this file except in compliance with the License.
8#
9# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10# or http://www.opensolaris.org/os/licensing.
11# See the License for the specific language governing permissions
12# and limitations under the License.
13#
14# When distributing Covered Code, include this CDDL HEADER in each
15# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16# If applicable, add the following below this CDDL HEADER, with the
17# fields enclosed by brackets "[]" replaced with your own identifying
18# information: Portions Copyright [yyyy] [name of copyright owner]
19#
20# CDDL HEADER END
21#
22
23#
24# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
25# Use is subject to license terms.
26#
27
28#
29# Copyright (c) 2013, 2016 by Delphix. All rights reserved.
30#
31
32. $STF_SUITE/include/libtest.shlib
33
34#
35# DESCRIPTION:
36#	Verify that the ZFS mdb dcmds and walkers are working as expected.
37#
38# STRATEGY:
39#	1) Given a list of dcmds and walkers
40#	2) Step through each element of the list
41#	3) Verify the output by checking for "mdb:" in the output string
42#
43
44function cleanup
45{
46	rm -f $OUTFILE
47}
48
49verify_runnable "global"
50log_onexit cleanup
51
52tmpfile=$(mktemp)
53log_must zpool scrub $TESTPOOL
54
55typeset spa=$(mdb -ke "::spa" | awk "/$TESTPOOL/ {print \$1}")
56typeset off_ub=$(mdb -ke "::offsetof spa_t spa_uberblock | =J")
57typeset off_rbp=$(mdb -ke "::offsetof uberblock_t ub_rootbp | =J")
58typeset bp=$(mdb -ke "$spa + $off_ub + $off_rbp =J")
59
60# dcmds and walkers skipped due to being DEBUG only or difficult to run:
61# ::zfs_params
62# ::refcount
63
64set -A dcmds "::abuf_find 1 2" \
65	"::arc" \
66	"::arc -b" \
67	"::arc_compression_stats" \
68	"$bp ::blkptr" \
69	"$bp ::dva" \
70	"::walk spa" \
71	"::spa" \
72	"$spa ::spa " \
73	"$spa ::spa -c" \
74	"$spa ::spa -h" \
75	"$spa ::spa -v" \
76	"$spa ::spa -Mmh" \
77	"$spa ::spa_config" \
78	"$spa ::spa_space" \
79	"$spa ::spa_space -b" \
80	"$spa ::spa_vdevs" \
81	"$spa ::print spa_t spa_root_vdev | ::vdev" \
82	"$spa ::print spa_t spa_root_vdev | ::vdev -re" \
83	"$spa ::print -a spa_t spa_dsl_pool->dp_dirty_datasets | ::walk txg_list" \
84	"$spa ::print -a spa_t spa_uberblock.ub_rootbp | ::blkptr" \
85	"$spa ::walk metaslab" \
86	"$spa ::walk metaslab | ::head -1 | ::metaslab_weight" \
87	"$spa ::walk metaslab | ::head -1 | ::metaslab_trace" \
88	"$spa ::walk zio_root | ::zio -c" \
89	"$spa ::walk zio_root | ::zio -r" \
90	"$spa ::walk zms_freelist"
91	"$spa ::zfs_blkstats -v" \
92	"::dbufs" \
93	"::dbufs -n mos -o mdn -l 0 -b 0" \
94	"::dbufs | ::dbuf" \
95	"::dbuf_stats" \
96	"dbuf_cache ::walk multilist"
97#
98# The commands above were supplied by the ZFS development team. The idea is to
99# do as much checking as possible without the need to hardcode addresses.
100#
101
102log_assert "Verify that the ZFS mdb dcmds and walkers are working as expected."
103
104typeset -i RET=0
105
106i=0
107while (( $i < ${#dcmds[*]} )); do
108	log_note "Verifying: '${dcmds[i]}'"
109        echo "${dcmds[i]}" | mdb -k > $OUTFILE 2>&1
110	RET=$?
111	if (( $RET != 0 )); then
112		log_fail "mdb '${dcmds[i]}' returned error $RET"
113	fi
114
115	#
116	# mdb prefixes all errors with "mdb: " so we check the output.
117	#
118	grep "mdb:" $OUTFILE > /dev/null 2>&1
119	RET=$?
120	if (( $RET == 0 )); then
121		echo "mdb '${dcmds[i]}' contained 'mdb:'"
122		# Using tail limits the number of lines in the log
123		tail -100 $OUTFILE
124		log_fail "mdb walker or dcmd failed"
125	fi
126
127        ((i = i + 1))
128done
129
130log_pass "The ZFS mdb dcmds and walkers are working as expected."
131