xref: /titanic_41/usr/src/cmd/mdb/common/modules/md/dumphotspare.c (revision 9e86db79b7d1bbc5f2f04e99954cbd5eae0e22bb)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * 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  * Copyright 2003 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #pragma ident	"%Z%%M%	%I%	%E% SMI"
28 
29 #include "mdinclude.h"
30 
31 static void
32 printhsp(hot_spare_pool_t hsp, uintptr_t hsp_addr)
33 {
34 	int 	i = 0;
35 	uintptr_t	hs_addr;
36 	int	recid;
37 
38 	mdb_inc_indent(2);
39 	mdb_printf("hsp_next: %p\n", hsp.hsp_next);
40 	mdb_printf("hsp_link:\n");
41 	mdb_inc_indent(2);
42 	mdb_printf("ln_next: %p\n", hsp.hsp_link.ln_next);
43 	mdb_printf("ln_setno: %u\n", hsp.hsp_link.ln_setno);
44 	mdb_printf("ln_id: %u\n", hsp.hsp_link.ln_id);
45 	mdb_inc_indent(2);
46 	mdb_printf("--- on disk structures ---\n");
47 	mdb_printf("hsp_revision:   %u\n", hsp.hsp_revision);
48 	mdb_printf("hsp_self_id:    %u \n", hsp.hsp_self_id);
49 	mdb_printf("hsp_record_id:  %d \n", hsp.hsp_record_id);
50 	mdb_printf("hsp_refcount:   %d\n", hsp.hsp_refcount);
51 	mdb_printf("hsp_nhotspares: %d # Number of slices in the pool\n",
52 	    hsp.hsp_nhotspares);
53 	mdb_inc_indent(1);
54 
55 	hs_addr = hsp_addr + ((uintptr_t)&hsp.hsp_hotspares - (uintptr_t)&hsp);
56 
57 	for (i = 0; i < hsp.hsp_nhotspares; i++) {
58 		if (mdb_vread(&recid, sizeof (int), hs_addr) !=
59 		    sizeof (int)) {
60 			mdb_warn("failed to read recid at %p\n", hs_addr);
61 			break;
62 		}
63 		mdb_printf("hsp_hotspares[%d]: %d", i, recid);
64 		mdb_printf(" # should match an hs_record_id in s_hs list\n");
65 		hs_addr += (uintptr_t)sizeof (int);
66 	}
67 	mdb_dec_indent(1);
68 	mdb_printf("--- end of on disk ---\n");
69 	mdb_dec_indent(2);
70 	mdb_dec_indent(2);
71 	mdb_dec_indent(2);
72 }
73 
74 static void
75 process_hsp(uintptr_t addr)
76 {
77 	hot_spare_pool_t	hsp;
78 
79 	if (mdb_vread(&hsp, sizeof (hot_spare_pool_t), addr) !=
80 	    sizeof (hot_spare_pool_t)) {
81 		mdb_warn("failed to read hot_spare_pool_t at %p\n", addr);
82 		return;
83 	}
84 	mdb_inc_indent(2);
85 	mdb_printf("%p\n", addr);
86 	printhsp(hsp, addr);
87 	mdb_dec_indent(2);
88 }
89 /*
90  * Dump out the hotspare pools
91  * usage: ::dumphotspare
92  */
93 int
94 dumphotspare(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
95 {
96 	if (argc != 0)	/* ensure no options */
97 		return (DCMD_USAGE);
98 
99 	snarf_sets();
100 
101 	if (!(flags & DCMD_ADDRSPEC)) {
102 		if (mdb_walk_dcmd("hotsparepool", "dumphotspare", argc,
103 		    argv) == -1) {
104 			mdb_warn("failed to walk hotsparepool");
105 			return (DCMD_ERR);
106 		}
107 		return (DCMD_OK);
108 	}
109 
110 	process_hsp(addr);
111 
112 	return (DCMD_OK);
113 }
114