1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
|
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2003 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#include <mdb/mdb_modapi.h>
#include <sys/buf.h>
#include <sys/var.h>
#include <vm/page.h>
#include "bio.h"
typedef struct buf_walk {
uintptr_t bw_hbufbase; /* Base address of hbuf buckets */
struct hbuf *bw_hbufs; /* Snapshot of hbuf buckets */
size_t bw_nhbufs; /* Number of hbuf buckets */
size_t bw_hbufi; /* Current hbuf index */
buf_t *bw_bufp; /* Current buffer */
} buf_walk_t;
int
buf_walk_init(mdb_walk_state_t *wsp)
{
struct hbuf *hbufs;
struct var v;
uintptr_t hbuf_addr;
size_t nbytes;
buf_walk_t *bwp;
if (wsp->walk_addr != 0) {
mdb_warn("only global buf walk supported\n");
return (WALK_ERR);
}
if (mdb_readvar(&v, "v") == -1) {
mdb_warn("failed to read var struct");
return (WALK_ERR);
}
if (mdb_readvar(&hbuf_addr, "hbuf") == -1) {
mdb_warn("failed to read hbuf pointer");
return (WALK_ERR);
}
nbytes = sizeof (struct hbuf) * v.v_hbuf;
hbufs = mdb_alloc(nbytes, UM_SLEEP);
if (mdb_vread(hbufs, nbytes, hbuf_addr) != nbytes) {
mdb_warn("failed to read hbufs");
mdb_free(hbufs, nbytes);
return (WALK_ERR);
}
bwp = mdb_alloc(sizeof (buf_walk_t), UM_SLEEP);
bwp->bw_hbufbase = hbuf_addr;
bwp->bw_hbufs = hbufs;
bwp->bw_nhbufs = v.v_hbuf;
bwp->bw_hbufi = 0;
bwp->bw_bufp = mdb_alloc(sizeof (buf_t), UM_SLEEP);
wsp->walk_addr = (uintptr_t)hbufs[0].b_forw;
wsp->walk_data = bwp;
return (WALK_NEXT);
}
int
buf_walk_step(mdb_walk_state_t *wsp)
{
buf_walk_t *bwp = wsp->walk_data;
uintptr_t addr;
/*
* If the next buf_t address we want is NULL or points back at the
* hbuf itself, advance to the next hash bucket. When we reach
* bw_nhbufs, we're done.
*/
while (wsp->walk_addr == 0 || wsp->walk_addr == (bwp->bw_hbufbase +
bwp->bw_hbufi * sizeof (struct hbuf))) {
if (++bwp->bw_hbufi == bwp->bw_nhbufs)
return (WALK_DONE);
wsp->walk_addr = (uintptr_t)
bwp->bw_hbufs[bwp->bw_hbufi].b_forw;
}
/*
* When we have a buf_t address, read the buffer and invoke our
* walk callback. We keep the next buf_t address in wsp->walk_addr.
*/
addr = wsp->walk_addr;
(void) mdb_vread(bwp->bw_bufp, sizeof (buf_t), addr);
wsp->walk_addr = (uintptr_t)bwp->bw_bufp->b_forw;
return (wsp->walk_callback(addr, bwp->bw_bufp, wsp->walk_cbdata));
}
void
buf_walk_fini(mdb_walk_state_t *wsp)
{
buf_walk_t *bwp = wsp->walk_data;
mdb_free(bwp->bw_hbufs, sizeof (struct hbuf) * bwp->bw_nhbufs);
mdb_free(bwp->bw_bufp, sizeof (buf_t));
mdb_free(bwp, sizeof (buf_walk_t));
}
/*ARGSUSED*/
int
bufpagefind(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
{
uintptr_t b_addr = addr;
uintptr_t arg;
page_t p;
buf_t b;
if (argc != 1)
return (DCMD_USAGE);
if (argv->a_type == MDB_TYPE_IMMEDIATE)
arg = (uintptr_t)argv->a_un.a_val;
else
arg = (uintptr_t)mdb_strtoull(argv->a_un.a_str);
if (mdb_vread(&b, sizeof (buf_t), b_addr) == -1)
return (DCMD_ERR);
for (addr = (uintptr_t)b.b_pages; addr != 0;
addr = (uintptr_t)p.p_next) {
if (addr == arg) {
mdb_printf("buf %p has page %p on b_pages list\n",
b_addr, addr);
break;
}
if (mdb_vread(&p, sizeof (page_t), addr) == -1)
return (DCMD_ERR);
}
return (DCMD_OK);
}
|