]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/geom/geom_dump.c
o Lock page queue accesses by vm_page_deactivate().
[FreeBSD/FreeBSD.git] / sys / geom / geom_dump.c
1 /*-
2  * Copyright (c) 2002 Poul-Henning Kamp
3  * Copyright (c) 2002 Networks Associates Technology, Inc.
4  * All rights reserved.
5  *
6  * This software was developed for the FreeBSD Project by Poul-Henning Kamp
7  * and NAI Labs, the Security Research Division of Network Associates, Inc.
8  * under DARPA/SPAWAR contract N66001-01-C-8035 ("CBOSS"), as part of the
9  * DARPA CHATS research program.
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions
13  * are met:
14  * 1. Redistributions of source code must retain the above copyright
15  *    notice, this list of conditions and the following disclaimer.
16  * 2. Redistributions in binary form must reproduce the above copyright
17  *    notice, this list of conditions and the following disclaimer in the
18  *    documentation and/or other materials provided with the distribution.
19  * 3. The names of the authors may not be used to endorse or promote
20  *    products derived from this software without specific prior written
21  *    permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
24  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
27  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33  * SUCH DAMAGE.
34  *
35  * $FreeBSD$
36  */
37
38
39 #include <sys/param.h>
40 #include <sys/sbuf.h>
41 #ifndef _KERNEL
42 #include <stdio.h>
43 #include <unistd.h>
44 #include <stdlib.h>
45 #include <err.h>
46 #else
47 #include <sys/systm.h>
48 #include <sys/malloc.h>
49 #endif
50 #include <machine/stdarg.h>
51
52 #include <geom/geom.h>
53 #include <geom/geom_int.h>
54
55
56 static void
57 g_confdot_consumer(struct sbuf *sb, struct g_consumer *cp)
58 {
59
60         sbuf_printf(sb, "z%p [label=\"r%dw%de%d\\nbio #%d\"];\n",
61             cp, cp->acr, cp->acw, cp->ace, cp->biocount);
62         if (cp->provider)
63                 sbuf_printf(sb, "z%p -> z%p;\n", cp, cp->provider);
64 }
65
66 static void
67 g_confdot_provider(struct sbuf *sb, struct g_provider *pp)
68 {
69
70         sbuf_printf(sb, "z%p [shape=hexagon,label=\"%s\\nr%dw%de%d\\nerr#%d\"];\n",
71             pp, pp->name, pp->acr, pp->acw, pp->ace, pp->error);
72 }
73
74 static void
75 g_confdot_geom(struct sbuf *sb, struct g_geom *gp)
76 {
77         struct g_consumer *cp;
78         struct g_provider *pp;
79
80         sbuf_printf(sb, "z%p [shape=box,label=\"%s\\n%s\\nr#%d\"];\n",
81             gp, gp->class->name, gp->name, gp->rank);
82         LIST_FOREACH(cp, &gp->consumer, consumer) {
83                 g_confdot_consumer(sb, cp);
84                 sbuf_printf(sb, "z%p -> z%p;\n", gp, cp);
85         }
86
87         LIST_FOREACH(pp, &gp->provider, provider) {
88                 g_confdot_provider(sb, pp);
89                 sbuf_printf(sb, "z%p -> z%p;\n", pp, gp);
90         }
91 }
92
93 static void
94 g_confdot_class(struct sbuf *sb, struct g_class *mp)
95 {
96         struct g_geom *gp;
97
98         LIST_FOREACH(gp, &mp->geom, geom)
99                 g_confdot_geom(sb, gp);
100 }
101
102 struct sbuf *
103 g_confdot(void)
104 {
105         struct g_class *mp;
106         struct sbuf *sb;
107
108         sb = sbuf_new(NULL, NULL, 0, SBUF_AUTOEXTEND);
109         sbuf_clear(sb);
110         sbuf_printf(sb, "digraph geom {\n");
111         LIST_FOREACH(mp, &g_classes, class)
112                 g_confdot_class(sb, mp);
113         sbuf_printf(sb, "};\n");
114         sbuf_finish(sb);
115         return (sb);
116 }
117
118
119 static void
120 g_conf_consumer(struct sbuf *sb, struct g_consumer *cp)
121 {
122
123         sbuf_printf(sb, "\t<consumer id=\"%p\">\n", cp);
124         sbuf_printf(sb, "\t  <geom ref=\"%p\"/>\n", cp->geom);
125         if (cp->provider != NULL)
126                 sbuf_printf(sb, "\t  <provider ref=\"%p\"/>\n", cp->provider);
127         sbuf_printf(sb, "\t  <mode>r%dw%de%d</mode>\n",
128             cp->acr, cp->acw, cp->ace);
129         if (cp->geom->dumpconf) {
130                 sbuf_printf(sb, "\t  <config>\n");
131                 cp->geom->dumpconf(sb, "\t    ", cp->geom, cp, NULL);
132                 sbuf_printf(sb, "\t  </config>\n");
133         }
134         sbuf_printf(sb, "\t</consumer>\n");
135 }
136
137 static void
138 g_conf_provider(struct sbuf *sb, struct g_provider *pp)
139 {
140
141         sbuf_printf(sb, "\t<provider id=\"%p\">\n", pp);
142         sbuf_printf(sb, "\t  <geom ref=\"%p\"/>\n", pp->geom);
143         sbuf_printf(sb, "\t  <mode>r%dw%de%d</mode>\n",
144             pp->acr, pp->acw, pp->ace);
145         sbuf_printf(sb, "\t  <name>%s</name>\n", pp->name);
146         if (pp->geom->dumpconf) {
147                 sbuf_printf(sb, "\t  <config>\n");
148                 pp->geom->dumpconf(sb, "\t    ", pp->geom, NULL, pp);
149                 sbuf_printf(sb, "\t  </config>\n");
150         }
151         sbuf_printf(sb, "\t</provider>\n");
152 }
153
154
155 static void
156 g_conf_geom(struct sbuf *sb, struct g_geom *gp, struct g_provider *pp, struct g_consumer *cp)
157 {
158         struct g_consumer *cp2;
159         struct g_provider *pp2;
160         struct g_magicspace *gsp;
161         u_int u;
162
163         sbuf_printf(sb, "    <geom id=\"%p\">\n", gp);
164         sbuf_printf(sb, "      <class ref=\"%p\"/>\n", gp->class);
165         sbuf_printf(sb, "      <name>%s</name>\n", gp->name);
166         sbuf_printf(sb, "      <rank>%d</rank>\n", gp->rank);
167         if (gp->magicspaces) {
168                 for (u = 0; u < gp->magicspaces->nmagic; u++) {
169                         gsp = &gp->magicspaces->magicspace[u];
170                         if (gsp->len == 0 || gsp->name == NULL)
171                                 continue;
172                         sbuf_printf(sb, "      <magicspace>\n");
173                         sbuf_printf(sb, "        <name>%.8s</name>\n",
174                             gsp->name);
175                         sbuf_printf(sb, "        <offset>%lld</offset>\n",
176                             (long long)gsp->offset);
177                         sbuf_printf(sb, "        <length>%u</length>\n",
178                             gsp->len);
179                         sbuf_printf(sb, "        <flags>%u</flags>\n",
180                             gsp->flags);
181                         sbuf_printf(sb, "      </magicspace>\n");
182                 }
183         }
184         if (gp->dumpconf) {
185                 sbuf_printf(sb, "      <config>\n");
186                 gp->dumpconf(sb, "\t", gp, NULL, NULL);
187                 sbuf_printf(sb, "      </config>\n");
188         }
189         LIST_FOREACH(cp2, &gp->consumer, consumer) {
190                 if (cp != NULL && cp != cp2)
191                         continue;
192                 g_conf_consumer(sb, cp2);
193         }
194
195         LIST_FOREACH(pp2, &gp->provider, provider) {
196                 if (pp != NULL && pp != pp2)
197                         continue;
198                 g_conf_provider(sb, pp2);
199         }
200         sbuf_printf(sb, "    </geom>\n");
201 }
202
203 static void
204 g_conf_class(struct sbuf *sb, struct g_class *mp, struct g_geom *gp, struct g_provider *pp, struct g_consumer *cp)
205 {
206         struct g_geom *gp2;
207
208         sbuf_printf(sb, "  <class id=\"%p\">\n", mp);
209         sbuf_printf(sb, "    <name>%s</name>\n", mp->name);
210         LIST_FOREACH(gp2, &mp->geom, geom) {
211                 if (gp != NULL && gp != gp2)
212                         continue;
213                 g_conf_geom(sb, gp2, pp, cp);
214         }
215         sbuf_printf(sb, "  </class>\n");
216 }
217
218 struct sbuf *
219 g_conf_specific(struct g_class *mp, struct g_geom *gp, struct g_provider *pp, struct g_consumer *cp)
220 {
221         struct g_class *mp2;
222         struct sbuf *sb;
223
224         sb = sbuf_new(NULL, NULL, 0, SBUF_AUTOEXTEND);
225         sbuf_clear(sb);
226         sbuf_printf(sb, "<mesh>\n");
227 #ifndef _KERNEL
228         sbuf_printf(sb, "  <FreeBSD>%cFreeBSD%c</FreeBSD>\n", '$', '$');
229 #endif
230         LIST_FOREACH(mp2, &g_classes, class) {
231                 if (mp != NULL && mp != mp2)
232                         continue;
233                 g_conf_class(sb, mp2, gp, pp, cp);
234         }
235         sbuf_printf(sb, "</mesh>\n");
236         sbuf_finish(sb);
237         return (sb);
238 }
239
240 struct sbuf *
241 g_conf()
242 {
243
244         return (g_conf_specific(NULL, NULL, NULL, NULL));
245 }
246
247
248 void
249 g_trace(int level, char *fmt, ...)
250 {
251         va_list ap;
252         struct sbuf *sb;
253
254         g_sanity(NULL);
255         if (!(g_debugflags & level))
256                 return;
257         va_start(ap, fmt);
258         mtx_lock(&Giant);
259         sb = sbuf_new(NULL, NULL, 0, SBUF_AUTOEXTEND);
260         sbuf_vprintf(sb, fmt, ap);
261         sbuf_finish(sb);
262         mtx_unlock(&Giant);
263         printf("%s\n", sbuf_data(sb));
264         sbuf_delete(sb);
265 }
266
267 void
268 g_hexdump(void *ptr, int length)
269 {
270         int i, j, k;
271         unsigned char *cp;
272
273         cp = ptr;
274         for (i = 0; i < length; i+= 16) {
275                 printf("%04x  ", i);
276                 for (j = 0; j < 16; j++) {
277                         k = i + j;
278                         if (k < length)
279                                 printf(" %02x", cp[k]);
280                         else
281                                 printf("   ");
282                 }
283                 printf("  |");
284                 for (j = 0; j < 16; j++) {
285                         k = i + j;
286                         if (k >= length)
287                                 printf(" ");
288                         else if (cp[k] >= ' ' && cp[k] <= '~')
289                                 printf("%c", cp[k]);
290                         else
291                                 printf(".");
292                 }
293                 printf("|\n");
294         }
295 }
296