xref: /onnv-gate/usr/src/cmd/mdb/common/modules/md/dumphotspare.c (revision 0:68f95e015346)
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 static void
printhsp(hot_spare_pool_t hsp,uintptr_t hsp_addr)32*0Sstevel@tonic-gate printhsp(hot_spare_pool_t hsp, uintptr_t hsp_addr)
33*0Sstevel@tonic-gate {
34*0Sstevel@tonic-gate 	int 	i = 0;
35*0Sstevel@tonic-gate 	uintptr_t	hs_addr;
36*0Sstevel@tonic-gate 	int	recid;
37*0Sstevel@tonic-gate 
38*0Sstevel@tonic-gate 	mdb_inc_indent(2);
39*0Sstevel@tonic-gate 	mdb_printf("hsp_next: %p\n", hsp.hsp_next);
40*0Sstevel@tonic-gate 	mdb_printf("hsp_link:\n");
41*0Sstevel@tonic-gate 	mdb_inc_indent(2);
42*0Sstevel@tonic-gate 	mdb_printf("ln_next: %p\n", hsp.hsp_link.ln_next);
43*0Sstevel@tonic-gate 	mdb_printf("ln_setno: %u\n", hsp.hsp_link.ln_setno);
44*0Sstevel@tonic-gate 	mdb_printf("ln_id: %u\n", hsp.hsp_link.ln_id);
45*0Sstevel@tonic-gate 	mdb_inc_indent(2);
46*0Sstevel@tonic-gate 	mdb_printf("--- on disk structures ---\n");
47*0Sstevel@tonic-gate 	mdb_printf("hsp_revision:   %u\n", hsp.hsp_revision);
48*0Sstevel@tonic-gate 	mdb_printf("hsp_self_id:    %u \n", hsp.hsp_self_id);
49*0Sstevel@tonic-gate 	mdb_printf("hsp_record_id:  %d \n", hsp.hsp_record_id);
50*0Sstevel@tonic-gate 	mdb_printf("hsp_refcount:   %d\n", hsp.hsp_refcount);
51*0Sstevel@tonic-gate 	mdb_printf("hsp_nhotspares: %d # Number of slices in the pool\n",
52*0Sstevel@tonic-gate 	    hsp.hsp_nhotspares);
53*0Sstevel@tonic-gate 	mdb_inc_indent(1);
54*0Sstevel@tonic-gate 
55*0Sstevel@tonic-gate 	hs_addr = hsp_addr + ((uintptr_t)&hsp.hsp_hotspares - (uintptr_t)&hsp);
56*0Sstevel@tonic-gate 
57*0Sstevel@tonic-gate 	for (i = 0; i < hsp.hsp_nhotspares; i++) {
58*0Sstevel@tonic-gate 		if (mdb_vread(&recid, sizeof (int), hs_addr) !=
59*0Sstevel@tonic-gate 		    sizeof (int)) {
60*0Sstevel@tonic-gate 			mdb_warn("failed to read recid at %p\n", hs_addr);
61*0Sstevel@tonic-gate 			break;
62*0Sstevel@tonic-gate 		}
63*0Sstevel@tonic-gate 		mdb_printf("hsp_hotspares[%d]: %d", i, recid);
64*0Sstevel@tonic-gate 		mdb_printf(" # should match an hs_record_id in s_hs list\n");
65*0Sstevel@tonic-gate 		hs_addr += (uintptr_t)sizeof (int);
66*0Sstevel@tonic-gate 	}
67*0Sstevel@tonic-gate 	mdb_dec_indent(1);
68*0Sstevel@tonic-gate 	mdb_printf("--- end of on disk ---\n");
69*0Sstevel@tonic-gate 	mdb_dec_indent(2);
70*0Sstevel@tonic-gate 	mdb_dec_indent(2);
71*0Sstevel@tonic-gate 	mdb_dec_indent(2);
72*0Sstevel@tonic-gate }
73*0Sstevel@tonic-gate 
74*0Sstevel@tonic-gate static void
process_hsp(uintptr_t addr)75*0Sstevel@tonic-gate process_hsp(uintptr_t addr)
76*0Sstevel@tonic-gate {
77*0Sstevel@tonic-gate 	hot_spare_pool_t	hsp;
78*0Sstevel@tonic-gate 
79*0Sstevel@tonic-gate 	if (mdb_vread(&hsp, sizeof (hot_spare_pool_t), addr) !=
80*0Sstevel@tonic-gate 	    sizeof (hot_spare_pool_t)) {
81*0Sstevel@tonic-gate 		mdb_warn("failed to read hot_spare_pool_t at %p\n", addr);
82*0Sstevel@tonic-gate 		return;
83*0Sstevel@tonic-gate 	}
84*0Sstevel@tonic-gate 	mdb_inc_indent(2);
85*0Sstevel@tonic-gate 	mdb_printf("%p\n", addr);
86*0Sstevel@tonic-gate 	printhsp(hsp, addr);
87*0Sstevel@tonic-gate 	mdb_dec_indent(2);
88*0Sstevel@tonic-gate }
89*0Sstevel@tonic-gate /*
90*0Sstevel@tonic-gate  * Dump out the hotspare pools
91*0Sstevel@tonic-gate  * usage: ::dumphotspare
92*0Sstevel@tonic-gate  */
93*0Sstevel@tonic-gate int
dumphotspare(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)94*0Sstevel@tonic-gate dumphotspare(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
95*0Sstevel@tonic-gate {
96*0Sstevel@tonic-gate 	if (argc != 0)	/* ensure no options */
97*0Sstevel@tonic-gate 		return (DCMD_USAGE);
98*0Sstevel@tonic-gate 
99*0Sstevel@tonic-gate 	snarf_sets();
100*0Sstevel@tonic-gate 
101*0Sstevel@tonic-gate 	if (!(flags & DCMD_ADDRSPEC)) {
102*0Sstevel@tonic-gate 		if (mdb_walk_dcmd("hotsparepool", "dumphotspare", argc,
103*0Sstevel@tonic-gate 		    argv) == -1) {
104*0Sstevel@tonic-gate 			mdb_warn("failed to walk hotsparepool");
105*0Sstevel@tonic-gate 			return (DCMD_ERR);
106*0Sstevel@tonic-gate 		}
107*0Sstevel@tonic-gate 		return (DCMD_OK);
108*0Sstevel@tonic-gate 	}
109*0Sstevel@tonic-gate 
110*0Sstevel@tonic-gate 	process_hsp(addr);
111*0Sstevel@tonic-gate 
112*0Sstevel@tonic-gate 	return (DCMD_OK);
113*0Sstevel@tonic-gate }
114