1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate  * CDDL HEADER START
3*0Sstevel@tonic-gate  *
4*0Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*0Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*0Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*0Sstevel@tonic-gate  * with the License.
8*0Sstevel@tonic-gate  *
9*0Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*0Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*0Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*0Sstevel@tonic-gate  * and limitations under the License.
13*0Sstevel@tonic-gate  *
14*0Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*0Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*0Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*0Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*0Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*0Sstevel@tonic-gate  *
20*0Sstevel@tonic-gate  * CDDL HEADER END
21*0Sstevel@tonic-gate  */
22*0Sstevel@tonic-gate /*
23*0Sstevel@tonic-gate  * Copyright 2003 Sun Microsystems, Inc.  All rights reserved.
24*0Sstevel@tonic-gate  * Use is subject to license terms.
25*0Sstevel@tonic-gate  */
26*0Sstevel@tonic-gate 
27*0Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
28*0Sstevel@tonic-gate 
29*0Sstevel@tonic-gate #include "mdinclude.h"
30*0Sstevel@tonic-gate 
31*0Sstevel@tonic-gate typedef struct	submirror_cb {
32*0Sstevel@tonic-gate 	minor_t		un_self_id;
33*0Sstevel@tonic-gate 	int		un_nsm;
34*0Sstevel@tonic-gate 	ushort_t	mm_un_nsm;
35*0Sstevel@tonic-gate }submirror_cb_t;
36*0Sstevel@tonic-gate 
37*0Sstevel@tonic-gate void
38*0Sstevel@tonic-gate print_setname(int setno)
39*0Sstevel@tonic-gate {
40*0Sstevel@tonic-gate 	char		setname[1024];
41*0Sstevel@tonic-gate 
42*0Sstevel@tonic-gate 	if (setno != 0) {
43*0Sstevel@tonic-gate 		if (mdb_readstr(setname, 1024,
44*0Sstevel@tonic-gate 		    (uintptr_t)set_dbs[setno].s_setname) == -1) {
45*0Sstevel@tonic-gate 			mdb_warn("failed to read setname at 0x%p\n",
46*0Sstevel@tonic-gate 			    set_dbs[setno].s_setname);
47*0Sstevel@tonic-gate 		}
48*0Sstevel@tonic-gate 		mdb_printf("%s/", setname);
49*0Sstevel@tonic-gate 	}
50*0Sstevel@tonic-gate }
51*0Sstevel@tonic-gate 
52*0Sstevel@tonic-gate void
53*0Sstevel@tonic-gate print_stripe(void *un_addr, void *mdcptr, uint_t verbose)
54*0Sstevel@tonic-gate {
55*0Sstevel@tonic-gate 	ms_unit_t	ms;
56*0Sstevel@tonic-gate 	int		setno;
57*0Sstevel@tonic-gate 	minor_t		un_self_id;
58*0Sstevel@tonic-gate 	md_parent_t	un_parent;
59*0Sstevel@tonic-gate 	diskaddr_t	un_total_blocks;
60*0Sstevel@tonic-gate 
61*0Sstevel@tonic-gate 	/* read in the device */
62*0Sstevel@tonic-gate 	un_self_id = ((mdc_unit_t *)mdcptr)->un_self_id;
63*0Sstevel@tonic-gate 	un_parent = ((mdc_unit_t *)mdcptr)->un_parent;
64*0Sstevel@tonic-gate 	un_total_blocks = ((mdc_unit_t *)mdcptr)->un_total_blocks;
65*0Sstevel@tonic-gate 	if (mdb_vread(&ms, sizeof (ms_unit_t),
66*0Sstevel@tonic-gate 	    (uintptr_t)un_addr) == -1) {
67*0Sstevel@tonic-gate 		mdb_warn("failed to read ms_unit_t at %p\n", un_addr);
68*0Sstevel@tonic-gate 		return;
69*0Sstevel@tonic-gate 	}
70*0Sstevel@tonic-gate 
71*0Sstevel@tonic-gate 	setno = MD_MIN2SET(un_self_id);
72*0Sstevel@tonic-gate 	print_setname(setno);
73*0Sstevel@tonic-gate 
74*0Sstevel@tonic-gate 	mdb_printf("d%u: ", MD_MIN2UNIT(un_self_id));
75*0Sstevel@tonic-gate 	if (un_parent == ((unit_t)-1)) {
76*0Sstevel@tonic-gate 		mdb_printf("Concat/Stripe");
77*0Sstevel@tonic-gate 	} else {
78*0Sstevel@tonic-gate 		mdb_printf("Subdevice of d%u", MD_MIN2UNIT(un_parent));
79*0Sstevel@tonic-gate 	}
80*0Sstevel@tonic-gate 	if (verbose) {
81*0Sstevel@tonic-gate 		mdb_printf("\t< %p::print ms_unit_t >\n", un_addr);
82*0Sstevel@tonic-gate 	} else {
83*0Sstevel@tonic-gate 		mdb_printf("\t< %p>\n", un_addr);
84*0Sstevel@tonic-gate 	}
85*0Sstevel@tonic-gate 	mdb_inc_indent(2);
86*0Sstevel@tonic-gate 	mdb_printf("Size: %llu blocks\n", un_total_blocks);
87*0Sstevel@tonic-gate 	mdb_printf("Rows: %u\n", ms.un_nrows);
88*0Sstevel@tonic-gate 	mdb_dec_indent(2);
89*0Sstevel@tonic-gate }
90*0Sstevel@tonic-gate 
91*0Sstevel@tonic-gate /* ARGSUSED */
92*0Sstevel@tonic-gate int
93*0Sstevel@tonic-gate print_submirror(uintptr_t addr, void *arg, submirror_cb_t *data)
94*0Sstevel@tonic-gate {
95*0Sstevel@tonic-gate 	uintptr_t	un_addr;
96*0Sstevel@tonic-gate 	mdc_unit_t	mdc_sm;
97*0Sstevel@tonic-gate 
98*0Sstevel@tonic-gate 	if (mdb_vread(&un_addr, sizeof (void *), addr) == -1) {
99*0Sstevel@tonic-gate 		mdb_warn("failed to read submirror at %p\n", addr);
100*0Sstevel@tonic-gate 		return (WALK_ERR);
101*0Sstevel@tonic-gate 	}
102*0Sstevel@tonic-gate 	if (un_addr != NULL) {
103*0Sstevel@tonic-gate 		if (mdb_vread(&mdc_sm, sizeof (mdc_unit_t), un_addr) == -1) {
104*0Sstevel@tonic-gate 			mdb_warn("failed to read mdc_unit_t at %p", un_addr);
105*0Sstevel@tonic-gate 			return (WALK_ERR);
106*0Sstevel@tonic-gate 		}
107*0Sstevel@tonic-gate 		if (mdc_sm.un_parent == data->un_self_id) {
108*0Sstevel@tonic-gate 		/* this is one of the sub mirrors */
109*0Sstevel@tonic-gate 			mdb_printf("Submirror %u: d%u ",
110*0Sstevel@tonic-gate 			    data->un_nsm, MD_MIN2UNIT(mdc_sm.un_self_id));
111*0Sstevel@tonic-gate 			mdb_printf("Size: %llu\n", mdc_sm.un_total_blocks);
112*0Sstevel@tonic-gate 			data->un_nsm++;
113*0Sstevel@tonic-gate 			if (data->un_nsm == data->mm_un_nsm)
114*0Sstevel@tonic-gate 				return (WALK_DONE);
115*0Sstevel@tonic-gate 		}
116*0Sstevel@tonic-gate 	}
117*0Sstevel@tonic-gate 	return (WALK_NEXT);
118*0Sstevel@tonic-gate }
119*0Sstevel@tonic-gate 
120*0Sstevel@tonic-gate void
121*0Sstevel@tonic-gate print_mirror(void *un_addr, void *mdcptr, uint_t verbose)
122*0Sstevel@tonic-gate {
123*0Sstevel@tonic-gate 	mm_unit_t	mm;
124*0Sstevel@tonic-gate 	void		**ptr;
125*0Sstevel@tonic-gate 	int		setno = 0;
126*0Sstevel@tonic-gate 	minor_t		un_self_id;
127*0Sstevel@tonic-gate 	diskaddr_t	un_total_blocks;
128*0Sstevel@tonic-gate 	ushort_t	mm_un_nsm;
129*0Sstevel@tonic-gate 	submirror_cb_t	data;
130*0Sstevel@tonic-gate 
131*0Sstevel@tonic-gate 	/* read in the device */
132*0Sstevel@tonic-gate 	if (mdb_vread(&mm, sizeof (mm_unit_t),
133*0Sstevel@tonic-gate 	    (uintptr_t)un_addr) == -1) {
134*0Sstevel@tonic-gate 		mdb_warn("failed to read mm_unit_t at %p\n", un_addr);
135*0Sstevel@tonic-gate 		return;
136*0Sstevel@tonic-gate 	}
137*0Sstevel@tonic-gate 	un_self_id = ((mdc_unit_t *)mdcptr)->un_self_id;
138*0Sstevel@tonic-gate 	un_total_blocks = ((mdc_unit_t *)mdcptr)->un_total_blocks;
139*0Sstevel@tonic-gate 	mm_un_nsm = mm.un_nsm;
140*0Sstevel@tonic-gate 	setno = MD_MIN2SET(un_self_id);
141*0Sstevel@tonic-gate 	print_setname(setno);
142*0Sstevel@tonic-gate 
143*0Sstevel@tonic-gate 	mdb_printf("d%u: Mirror", MD_MIN2UNIT(un_self_id));
144*0Sstevel@tonic-gate 	if (verbose) {
145*0Sstevel@tonic-gate 		mdb_printf("\t< %p::print mm_unit_t >\n", un_addr);
146*0Sstevel@tonic-gate 	} else {
147*0Sstevel@tonic-gate 		mdb_printf("\t< %p >\n", un_addr);
148*0Sstevel@tonic-gate 	}
149*0Sstevel@tonic-gate 	mdb_inc_indent(2);
150*0Sstevel@tonic-gate 	mdb_printf("Size: %llu blocks\n", un_total_blocks);
151*0Sstevel@tonic-gate 	/*
152*0Sstevel@tonic-gate 	 * find the sub mirrors, search through each metadevice looking
153*0Sstevel@tonic-gate 	 * at the un_parent.
154*0Sstevel@tonic-gate 	 */
155*0Sstevel@tonic-gate 	ptr = mdset[setno].s_un;
156*0Sstevel@tonic-gate 
157*0Sstevel@tonic-gate 	data.un_self_id = un_self_id;
158*0Sstevel@tonic-gate 	data.un_nsm = 0;
159*0Sstevel@tonic-gate 	data.mm_un_nsm = mm_un_nsm;
160*0Sstevel@tonic-gate 
161*0Sstevel@tonic-gate 	if (mdb_pwalk("md_units", (mdb_walk_cb_t)print_submirror, &data,
162*0Sstevel@tonic-gate 	    (uintptr_t)ptr) == -1) {
163*0Sstevel@tonic-gate 		mdb_warn("unable to walk units\n");
164*0Sstevel@tonic-gate 		return;
165*0Sstevel@tonic-gate 	}
166*0Sstevel@tonic-gate 
167*0Sstevel@tonic-gate 	mdb_dec_indent(2);
168*0Sstevel@tonic-gate }
169*0Sstevel@tonic-gate 
170*0Sstevel@tonic-gate void
171*0Sstevel@tonic-gate print_raid(void *un_addr, void *mdcptr, uint_t verbose)
172*0Sstevel@tonic-gate {
173*0Sstevel@tonic-gate 	mr_unit_t	mr;
174*0Sstevel@tonic-gate 	minor_t		un_self_id;
175*0Sstevel@tonic-gate 	diskaddr_t	un_total_blocks;
176*0Sstevel@tonic-gate 	mdc_unit_t	mdc_sc;
177*0Sstevel@tonic-gate 	void		**ptr;
178*0Sstevel@tonic-gate 	void		*addr;
179*0Sstevel@tonic-gate 	int		setno = 0;
180*0Sstevel@tonic-gate 	int		i;
181*0Sstevel@tonic-gate 	minor_t		sc_un_self_id;
182*0Sstevel@tonic-gate 	md_parent_t	sc_parent;
183*0Sstevel@tonic-gate 	diskaddr_t	sc_total_blocks;
184*0Sstevel@tonic-gate 
185*0Sstevel@tonic-gate 	/* read in the device */
186*0Sstevel@tonic-gate 	if (mdb_vread(&mr, sizeof (mr_unit_t), (uintptr_t)un_addr) == -1) {
187*0Sstevel@tonic-gate 		mdb_warn("failed to read mr_unit_t at %p\n", un_addr);
188*0Sstevel@tonic-gate 		return;
189*0Sstevel@tonic-gate 	}
190*0Sstevel@tonic-gate 	un_self_id = ((mdc_unit_t *)mdcptr)->un_self_id;
191*0Sstevel@tonic-gate 	un_total_blocks = ((mdc_unit_t *)mdcptr)->un_total_blocks;
192*0Sstevel@tonic-gate 	setno = MD_MIN2SET(un_self_id);
193*0Sstevel@tonic-gate 	print_setname(setno);
194*0Sstevel@tonic-gate 
195*0Sstevel@tonic-gate 	mdb_printf("d%u: Raid", MD_MIN2UNIT(un_self_id));
196*0Sstevel@tonic-gate 	if (verbose) {
197*0Sstevel@tonic-gate 		mdb_printf("\t< %p ::print mr_unit_t>\n", un_addr);
198*0Sstevel@tonic-gate 	} else {
199*0Sstevel@tonic-gate 		mdb_printf("\t< %p >\n", un_addr);
200*0Sstevel@tonic-gate 	}
201*0Sstevel@tonic-gate 	mdb_inc_indent(2);
202*0Sstevel@tonic-gate 	mdb_printf("Size: %llu\n", un_total_blocks);
203*0Sstevel@tonic-gate 
204*0Sstevel@tonic-gate 	/*
205*0Sstevel@tonic-gate 	 * find the sub components if any, search through each metadevice
206*0Sstevel@tonic-gate 	 * looking at the un_parent.
207*0Sstevel@tonic-gate 	 */
208*0Sstevel@tonic-gate 	ptr = mdset[setno].s_un;
209*0Sstevel@tonic-gate 	for (i = 0; i < md_nunits; i++, ptr++) {
210*0Sstevel@tonic-gate 		if (mdb_vread(&addr, sizeof (void *), (uintptr_t)ptr) == -1) {
211*0Sstevel@tonic-gate 			mdb_warn("failed to read addr at %p\n", ptr);
212*0Sstevel@tonic-gate 			continue;
213*0Sstevel@tonic-gate 		}
214*0Sstevel@tonic-gate 		if (addr != NULL) {
215*0Sstevel@tonic-gate 			if (mdb_vread(&mdc_sc, sizeof (mdc_unit_t),
216*0Sstevel@tonic-gate 			    (uintptr_t)addr) == -1) {
217*0Sstevel@tonic-gate 				mdb_warn("failed to read mdc_unit_t at %p",
218*0Sstevel@tonic-gate 				    un_addr);
219*0Sstevel@tonic-gate 				continue;
220*0Sstevel@tonic-gate 			}
221*0Sstevel@tonic-gate 			sc_parent = mdc_sc.un_parent;
222*0Sstevel@tonic-gate 			sc_un_self_id = mdc_sc.un_self_id;
223*0Sstevel@tonic-gate 			sc_total_blocks = mdc_sc.un_total_blocks;
224*0Sstevel@tonic-gate 			if (sc_parent == un_self_id) {
225*0Sstevel@tonic-gate 				/* this is one of the sub components */
226*0Sstevel@tonic-gate 				mdb_printf("Subdevice %u ",
227*0Sstevel@tonic-gate 				    MD_MIN2UNIT(sc_un_self_id));
228*0Sstevel@tonic-gate 				mdb_printf("Size: %llu\n", sc_total_blocks);
229*0Sstevel@tonic-gate 			}
230*0Sstevel@tonic-gate 		}
231*0Sstevel@tonic-gate 	}
232*0Sstevel@tonic-gate 	mdb_dec_indent(2);
233*0Sstevel@tonic-gate }
234*0Sstevel@tonic-gate 
235*0Sstevel@tonic-gate void
236*0Sstevel@tonic-gate print_sp(void *un_addr, void *mdcptr, uint_t verbose)
237*0Sstevel@tonic-gate {
238*0Sstevel@tonic-gate 	mp_unit_t	mp;
239*0Sstevel@tonic-gate 	minor_t		un_self_id;
240*0Sstevel@tonic-gate 	diskaddr_t	un_total_blocks;
241*0Sstevel@tonic-gate 	int		setno = 0;
242*0Sstevel@tonic-gate 	uintptr_t	extaddr;
243*0Sstevel@tonic-gate 	int		i;
244*0Sstevel@tonic-gate 
245*0Sstevel@tonic-gate 	/* read in the device */
246*0Sstevel@tonic-gate 	if (mdb_vread(&mp, sizeof (mp_unit_t), (uintptr_t)un_addr) == -1) {
247*0Sstevel@tonic-gate 		mdb_warn("failed to read mp_unit_t at %p\n", un_addr);
248*0Sstevel@tonic-gate 		return;
249*0Sstevel@tonic-gate 	}
250*0Sstevel@tonic-gate 	un_self_id = ((mdc_unit_t *)mdcptr)->un_self_id;
251*0Sstevel@tonic-gate 	un_total_blocks = ((mdc_unit_t *)mdcptr)->un_total_blocks;
252*0Sstevel@tonic-gate 	setno = MD_MIN2SET(un_self_id);
253*0Sstevel@tonic-gate 	print_setname(setno);
254*0Sstevel@tonic-gate 
255*0Sstevel@tonic-gate 	mdb_printf("d%u: Soft Partition", MD_MIN2UNIT(un_self_id));
256*0Sstevel@tonic-gate 	if (verbose) {
257*0Sstevel@tonic-gate 		mdb_printf("\t< %p ::print mp_unit_t >\n", un_addr);
258*0Sstevel@tonic-gate 	} else {
259*0Sstevel@tonic-gate 		mdb_printf("\t< %p >\n", un_addr);
260*0Sstevel@tonic-gate 	}
261*0Sstevel@tonic-gate 	mdb_inc_indent(2);
262*0Sstevel@tonic-gate 	mdb_printf("Size: %llu\n", un_total_blocks);
263*0Sstevel@tonic-gate 	mdb_inc_indent(2);
264*0Sstevel@tonic-gate 	mdb_printf("Extent\tStart Block\tBlock count\n");
265*0Sstevel@tonic-gate 	extaddr = (uintptr_t)un_addr + sizeof (mp_unit_t) - sizeof (mp_ext_t);
266*0Sstevel@tonic-gate 	for (i = 0; i < mp.un_numexts; i++) {
267*0Sstevel@tonic-gate 		mp_ext_t	mpext;
268*0Sstevel@tonic-gate 
269*0Sstevel@tonic-gate 		if (mdb_vread(&mpext, sizeof (mp_ext_t), extaddr) == -1) {
270*0Sstevel@tonic-gate 			mdb_warn("failed to read mp_ext_t at %p\n", extaddr);
271*0Sstevel@tonic-gate 			return;
272*0Sstevel@tonic-gate 		}
273*0Sstevel@tonic-gate 		mdb_printf("   %d \t      %llu\t        %llu\n",
274*0Sstevel@tonic-gate 		    i, mpext.un_poff, mpext.un_len);
275*0Sstevel@tonic-gate 		extaddr += sizeof (mp_ext_t);
276*0Sstevel@tonic-gate 	}
277*0Sstevel@tonic-gate 	mdb_dec_indent(2);
278*0Sstevel@tonic-gate 	mdb_dec_indent(2);
279*0Sstevel@tonic-gate 
280*0Sstevel@tonic-gate }
281*0Sstevel@tonic-gate 
282*0Sstevel@tonic-gate void
283*0Sstevel@tonic-gate print_trans(void *un_addr, void *mdcptr, uint_t verbose)
284*0Sstevel@tonic-gate {
285*0Sstevel@tonic-gate 	mt_unit_t	mt;
286*0Sstevel@tonic-gate 	minor_t		un_self_id;
287*0Sstevel@tonic-gate 	int		setno = 0;
288*0Sstevel@tonic-gate 
289*0Sstevel@tonic-gate 	/* read in the device */
290*0Sstevel@tonic-gate 	if (mdb_vread(&mt, sizeof (mt_unit_t), (uintptr_t)un_addr) == -1) {
291*0Sstevel@tonic-gate 		mdb_warn("failed to read mt_unit_t at %p\n", un_addr);
292*0Sstevel@tonic-gate 		return;
293*0Sstevel@tonic-gate 	}
294*0Sstevel@tonic-gate 	un_self_id = ((mdc_unit32_od_t *)mdcptr)->un_self_id;
295*0Sstevel@tonic-gate 	setno = MD_MIN2SET(un_self_id);
296*0Sstevel@tonic-gate 	print_setname(setno);
297*0Sstevel@tonic-gate 
298*0Sstevel@tonic-gate 	mdb_printf("d%u: Trans", MD_MIN2UNIT(un_self_id));
299*0Sstevel@tonic-gate 	if (verbose) {
300*0Sstevel@tonic-gate 		mdb_printf("\t< %p ::print mt_unit_t>\n", un_addr);
301*0Sstevel@tonic-gate 	} else {
302*0Sstevel@tonic-gate 		mdb_printf("\t< %p >\n", un_addr);
303*0Sstevel@tonic-gate 	}
304*0Sstevel@tonic-gate 
305*0Sstevel@tonic-gate }
306*0Sstevel@tonic-gate 
307*0Sstevel@tonic-gate void
308*0Sstevel@tonic-gate print_device(void *un_addr, void *mdcptr, uint_t verbose)
309*0Sstevel@tonic-gate {
310*0Sstevel@tonic-gate 	u_longlong_t	un_type;
311*0Sstevel@tonic-gate 
312*0Sstevel@tonic-gate 	un_type = ((mdc_unit_t *)mdcptr)->un_type;
313*0Sstevel@tonic-gate 
314*0Sstevel@tonic-gate 	switch (un_type) {
315*0Sstevel@tonic-gate 	case MD_DEVICE:		/* stripe/concat */
316*0Sstevel@tonic-gate 		print_stripe(un_addr, mdcptr, verbose);
317*0Sstevel@tonic-gate 		break;
318*0Sstevel@tonic-gate 	case MD_METAMIRROR:
319*0Sstevel@tonic-gate 		print_mirror(un_addr, mdcptr, verbose);
320*0Sstevel@tonic-gate 		break;
321*0Sstevel@tonic-gate 	case MD_METATRANS:
322*0Sstevel@tonic-gate 		print_trans(un_addr, mdcptr, verbose);
323*0Sstevel@tonic-gate 		break;
324*0Sstevel@tonic-gate 	case MD_METARAID:
325*0Sstevel@tonic-gate 		print_raid(un_addr, mdcptr, verbose);
326*0Sstevel@tonic-gate 		break;
327*0Sstevel@tonic-gate 	case MD_METASP:
328*0Sstevel@tonic-gate 		print_sp(un_addr, mdcptr, verbose);
329*0Sstevel@tonic-gate 		break;
330*0Sstevel@tonic-gate 	case MD_UNDEFINED:
331*0Sstevel@tonic-gate 		mdb_warn("undefined metadevice at %p\n", un_addr);
332*0Sstevel@tonic-gate 		break;
333*0Sstevel@tonic-gate 	default:
334*0Sstevel@tonic-gate 		mdb_warn("invalid metadevice at %p\n", un_addr);
335*0Sstevel@tonic-gate 		break;
336*0Sstevel@tonic-gate 	}
337*0Sstevel@tonic-gate }
338*0Sstevel@tonic-gate 
339*0Sstevel@tonic-gate /* ARGSUSED */
340*0Sstevel@tonic-gate /*
341*0Sstevel@tonic-gate  * usage:  ::metastat [-v]
342*0Sstevel@tonic-gate  */
343*0Sstevel@tonic-gate int
344*0Sstevel@tonic-gate metastat(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
345*0Sstevel@tonic-gate {
346*0Sstevel@tonic-gate 	mdc_unit_t	mdc;
347*0Sstevel@tonic-gate 	uintptr_t	un_addr;
348*0Sstevel@tonic-gate 	uint_t		verbose = FALSE;
349*0Sstevel@tonic-gate 
350*0Sstevel@tonic-gate 	snarf_sets();
351*0Sstevel@tonic-gate 
352*0Sstevel@tonic-gate 	if (mdb_getopts(argc, argv, 'v', MDB_OPT_SETBITS, TRUE, &verbose, NULL)
353*0Sstevel@tonic-gate 	    != argc) {
354*0Sstevel@tonic-gate 		return (DCMD_USAGE);
355*0Sstevel@tonic-gate 	}
356*0Sstevel@tonic-gate 
357*0Sstevel@tonic-gate 	if (!(flags & DCMD_ADDRSPEC)) {
358*0Sstevel@tonic-gate 		if (mdb_walk_dcmd("md_units", "metastat", argc,
359*0Sstevel@tonic-gate 		    argv) == -1) {
360*0Sstevel@tonic-gate 			mdb_warn("failed to walk units");
361*0Sstevel@tonic-gate 			return (DCMD_ERR);
362*0Sstevel@tonic-gate 		}
363*0Sstevel@tonic-gate 		return (DCMD_OK);
364*0Sstevel@tonic-gate 	}
365*0Sstevel@tonic-gate 	if (!(flags & DCMD_LOOP)) {
366*0Sstevel@tonic-gate 		/* user passed set addr */
367*0Sstevel@tonic-gate 		if (mdb_pwalk_dcmd("md_units", "metastat", argc,
368*0Sstevel@tonic-gate 		    argv, addr) == -1) {
369*0Sstevel@tonic-gate 			mdb_warn("failed to walk units");
370*0Sstevel@tonic-gate 			return (DCMD_ERR);
371*0Sstevel@tonic-gate 		}
372*0Sstevel@tonic-gate 		return (DCMD_OK);
373*0Sstevel@tonic-gate 	}
374*0Sstevel@tonic-gate 
375*0Sstevel@tonic-gate 	if (mdb_vread(&un_addr, sizeof (void *), addr) == -1) {
376*0Sstevel@tonic-gate 		mdb_warn("failed to read un_addr at %p", addr);
377*0Sstevel@tonic-gate 		return (DCMD_ERR);
378*0Sstevel@tonic-gate 	}
379*0Sstevel@tonic-gate 
380*0Sstevel@tonic-gate 	if (un_addr != NULL) {
381*0Sstevel@tonic-gate 		if (mdb_vread(&mdc, sizeof (mdc_unit_t), un_addr) == -1) {
382*0Sstevel@tonic-gate 			mdb_warn("failed to read mdc_unit_t at %p", un_addr);
383*0Sstevel@tonic-gate 			return (DCMD_ERR);
384*0Sstevel@tonic-gate 		}
385*0Sstevel@tonic-gate 		print_device((void *)un_addr, (void *)&mdc, verbose);
386*0Sstevel@tonic-gate 		mdb_dec_indent(2);
387*0Sstevel@tonic-gate 	}
388*0Sstevel@tonic-gate 	return (DCMD_OK);
389*0Sstevel@tonic-gate }
390