Deleted Added
full compact
geom_dump.c (152342) geom_dump.c (202454)
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
36#include <sys/cdefs.h>
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
36#include <sys/cdefs.h>
37__FBSDID("$FreeBSD: head/sys/geom/geom_dump.c 152342 2005-11-12 20:02:02Z marcel $");
37__FBSDID("$FreeBSD: head/sys/geom/geom_dump.c 202454 2010-01-17 06:20:30Z delphij $");
38
39#include <sys/param.h>
40#include <sys/sbuf.h>
41#include <sys/systm.h>
42#include <sys/malloc.h>
43#include <machine/stdarg.h>
44
45#include <geom/geom.h>
46#include <geom/geom_int.h>
47
48
49static void
50g_confdot_consumer(struct sbuf *sb, struct g_consumer *cp)
51{
52
53 sbuf_printf(sb, "z%p [label=\"r%dw%de%d\"];\n",
54 cp, cp->acr, cp->acw, cp->ace);
55 if (cp->provider)
56 sbuf_printf(sb, "z%p -> z%p;\n", cp, cp->provider);
57}
58
59static void
60g_confdot_provider(struct sbuf *sb, struct g_provider *pp)
61{
62
63 sbuf_printf(sb, "z%p [shape=hexagon,label=\"%s\\nr%dw%de%d\\nerr#%d\"];\n",
64 pp, pp->name, pp->acr, pp->acw, pp->ace, pp->error);
65}
66
67static void
68g_confdot_geom(struct sbuf *sb, struct g_geom *gp)
69{
70 struct g_consumer *cp;
71 struct g_provider *pp;
72
73 sbuf_printf(sb, "z%p [shape=box,label=\"%s\\n%s\\nr#%d\"];\n",
74 gp, gp->class->name, gp->name, gp->rank);
75 LIST_FOREACH(cp, &gp->consumer, consumer) {
76 g_confdot_consumer(sb, cp);
77 sbuf_printf(sb, "z%p -> z%p;\n", gp, cp);
78 }
79
80 LIST_FOREACH(pp, &gp->provider, provider) {
81 g_confdot_provider(sb, pp);
82 sbuf_printf(sb, "z%p -> z%p;\n", pp, gp);
83 }
84}
85
86static void
87g_confdot_class(struct sbuf *sb, struct g_class *mp)
88{
89 struct g_geom *gp;
90
91 LIST_FOREACH(gp, &mp->geom, geom)
92 g_confdot_geom(sb, gp);
93}
94
95void
96g_confdot(void *p, int flag )
97{
98 struct g_class *mp;
99 struct sbuf *sb;
100
101 KASSERT(flag != EV_CANCEL, ("g_confdot was cancelled"));
102 sb = p;
103 g_topology_assert();
104 sbuf_printf(sb, "digraph geom {\n");
105 LIST_FOREACH(mp, &g_classes, class)
106 g_confdot_class(sb, mp);
107 sbuf_printf(sb, "};\n");
108 sbuf_finish(sb);
109}
110
111static void
112g_conftxt_geom(struct sbuf *sb, struct g_geom *gp, int level)
113{
114 struct g_provider *pp;
115 struct g_consumer *cp;
116
117 if (gp->flags & G_GEOM_WITHER)
118 return;
119 LIST_FOREACH(pp, &gp->provider, provider) {
120 sbuf_printf(sb, "%d %s %s %ju %u", level, gp->class->name,
121 pp->name, (uintmax_t)pp->mediasize, pp->sectorsize);
122 if (gp->dumpconf != NULL)
123 gp->dumpconf(sb, NULL, gp, NULL, pp);
124 sbuf_printf(sb, "\n");
125 LIST_FOREACH(cp, &pp->consumers, consumers)
126 g_conftxt_geom(sb, cp->geom, level + 1);
127 }
128}
129
130static void
131g_conftxt_class(struct sbuf *sb, struct g_class *mp)
132{
133 struct g_geom *gp;
134
135 LIST_FOREACH(gp, &mp->geom, geom)
136 g_conftxt_geom(sb, gp, 0);
137}
138
139void
140g_conftxt(void *p, int flag)
141{
142 struct g_class *mp;
143 struct sbuf *sb;
144
145 KASSERT(flag != EV_CANCEL, ("g_conftxt was cancelled"));
146 sb = p;
147 g_topology_assert();
148 LIST_FOREACH(mp, &g_classes, class) {
149 if (!strcmp(mp->name, "DISK") || !strcmp(mp->name, "MD"))
150 g_conftxt_class(sb, mp);
151 }
152 sbuf_finish(sb);
153}
154
155
156static void
157g_conf_consumer(struct sbuf *sb, struct g_consumer *cp)
158{
159
160 sbuf_printf(sb, "\t<consumer id=\"%p\">\n", cp);
161 sbuf_printf(sb, "\t <geom ref=\"%p\"/>\n", cp->geom);
162 if (cp->provider != NULL)
163 sbuf_printf(sb, "\t <provider ref=\"%p\"/>\n", cp->provider);
164 sbuf_printf(sb, "\t <mode>r%dw%de%d</mode>\n",
165 cp->acr, cp->acw, cp->ace);
166 if (cp->geom->flags & G_GEOM_WITHER)
167 ;
168 else if (cp->geom->dumpconf != NULL) {
169 sbuf_printf(sb, "\t <config>\n");
170 cp->geom->dumpconf(sb, "\t ", cp->geom, cp, NULL);
171 sbuf_printf(sb, "\t </config>\n");
172 }
173 sbuf_printf(sb, "\t</consumer>\n");
174}
175
176static void
177g_conf_provider(struct sbuf *sb, struct g_provider *pp)
178{
179
180 sbuf_printf(sb, "\t<provider id=\"%p\">\n", pp);
181 sbuf_printf(sb, "\t <geom ref=\"%p\"/>\n", pp->geom);
182 sbuf_printf(sb, "\t <mode>r%dw%de%d</mode>\n",
183 pp->acr, pp->acw, pp->ace);
184 sbuf_printf(sb, "\t <name>%s</name>\n", pp->name);
185 sbuf_printf(sb, "\t <mediasize>%jd</mediasize>\n",
186 (intmax_t)pp->mediasize);
187 sbuf_printf(sb, "\t <sectorsize>%u</sectorsize>\n", pp->sectorsize);
38
39#include <sys/param.h>
40#include <sys/sbuf.h>
41#include <sys/systm.h>
42#include <sys/malloc.h>
43#include <machine/stdarg.h>
44
45#include <geom/geom.h>
46#include <geom/geom_int.h>
47
48
49static void
50g_confdot_consumer(struct sbuf *sb, struct g_consumer *cp)
51{
52
53 sbuf_printf(sb, "z%p [label=\"r%dw%de%d\"];\n",
54 cp, cp->acr, cp->acw, cp->ace);
55 if (cp->provider)
56 sbuf_printf(sb, "z%p -> z%p;\n", cp, cp->provider);
57}
58
59static void
60g_confdot_provider(struct sbuf *sb, struct g_provider *pp)
61{
62
63 sbuf_printf(sb, "z%p [shape=hexagon,label=\"%s\\nr%dw%de%d\\nerr#%d\"];\n",
64 pp, pp->name, pp->acr, pp->acw, pp->ace, pp->error);
65}
66
67static void
68g_confdot_geom(struct sbuf *sb, struct g_geom *gp)
69{
70 struct g_consumer *cp;
71 struct g_provider *pp;
72
73 sbuf_printf(sb, "z%p [shape=box,label=\"%s\\n%s\\nr#%d\"];\n",
74 gp, gp->class->name, gp->name, gp->rank);
75 LIST_FOREACH(cp, &gp->consumer, consumer) {
76 g_confdot_consumer(sb, cp);
77 sbuf_printf(sb, "z%p -> z%p;\n", gp, cp);
78 }
79
80 LIST_FOREACH(pp, &gp->provider, provider) {
81 g_confdot_provider(sb, pp);
82 sbuf_printf(sb, "z%p -> z%p;\n", pp, gp);
83 }
84}
85
86static void
87g_confdot_class(struct sbuf *sb, struct g_class *mp)
88{
89 struct g_geom *gp;
90
91 LIST_FOREACH(gp, &mp->geom, geom)
92 g_confdot_geom(sb, gp);
93}
94
95void
96g_confdot(void *p, int flag )
97{
98 struct g_class *mp;
99 struct sbuf *sb;
100
101 KASSERT(flag != EV_CANCEL, ("g_confdot was cancelled"));
102 sb = p;
103 g_topology_assert();
104 sbuf_printf(sb, "digraph geom {\n");
105 LIST_FOREACH(mp, &g_classes, class)
106 g_confdot_class(sb, mp);
107 sbuf_printf(sb, "};\n");
108 sbuf_finish(sb);
109}
110
111static void
112g_conftxt_geom(struct sbuf *sb, struct g_geom *gp, int level)
113{
114 struct g_provider *pp;
115 struct g_consumer *cp;
116
117 if (gp->flags & G_GEOM_WITHER)
118 return;
119 LIST_FOREACH(pp, &gp->provider, provider) {
120 sbuf_printf(sb, "%d %s %s %ju %u", level, gp->class->name,
121 pp->name, (uintmax_t)pp->mediasize, pp->sectorsize);
122 if (gp->dumpconf != NULL)
123 gp->dumpconf(sb, NULL, gp, NULL, pp);
124 sbuf_printf(sb, "\n");
125 LIST_FOREACH(cp, &pp->consumers, consumers)
126 g_conftxt_geom(sb, cp->geom, level + 1);
127 }
128}
129
130static void
131g_conftxt_class(struct sbuf *sb, struct g_class *mp)
132{
133 struct g_geom *gp;
134
135 LIST_FOREACH(gp, &mp->geom, geom)
136 g_conftxt_geom(sb, gp, 0);
137}
138
139void
140g_conftxt(void *p, int flag)
141{
142 struct g_class *mp;
143 struct sbuf *sb;
144
145 KASSERT(flag != EV_CANCEL, ("g_conftxt was cancelled"));
146 sb = p;
147 g_topology_assert();
148 LIST_FOREACH(mp, &g_classes, class) {
149 if (!strcmp(mp->name, "DISK") || !strcmp(mp->name, "MD"))
150 g_conftxt_class(sb, mp);
151 }
152 sbuf_finish(sb);
153}
154
155
156static void
157g_conf_consumer(struct sbuf *sb, struct g_consumer *cp)
158{
159
160 sbuf_printf(sb, "\t<consumer id=\"%p\">\n", cp);
161 sbuf_printf(sb, "\t <geom ref=\"%p\"/>\n", cp->geom);
162 if (cp->provider != NULL)
163 sbuf_printf(sb, "\t <provider ref=\"%p\"/>\n", cp->provider);
164 sbuf_printf(sb, "\t <mode>r%dw%de%d</mode>\n",
165 cp->acr, cp->acw, cp->ace);
166 if (cp->geom->flags & G_GEOM_WITHER)
167 ;
168 else if (cp->geom->dumpconf != NULL) {
169 sbuf_printf(sb, "\t <config>\n");
170 cp->geom->dumpconf(sb, "\t ", cp->geom, cp, NULL);
171 sbuf_printf(sb, "\t </config>\n");
172 }
173 sbuf_printf(sb, "\t</consumer>\n");
174}
175
176static void
177g_conf_provider(struct sbuf *sb, struct g_provider *pp)
178{
179
180 sbuf_printf(sb, "\t<provider id=\"%p\">\n", pp);
181 sbuf_printf(sb, "\t <geom ref=\"%p\"/>\n", pp->geom);
182 sbuf_printf(sb, "\t <mode>r%dw%de%d</mode>\n",
183 pp->acr, pp->acw, pp->ace);
184 sbuf_printf(sb, "\t <name>%s</name>\n", pp->name);
185 sbuf_printf(sb, "\t <mediasize>%jd</mediasize>\n",
186 (intmax_t)pp->mediasize);
187 sbuf_printf(sb, "\t <sectorsize>%u</sectorsize>\n", pp->sectorsize);
188 if (pp->stripesize > 0) {
189 sbuf_printf(sb, "\t <stripesize>%u</stripesize>\n", pp->stripesize);
190 sbuf_printf(sb, "\t <stripeoffset>%u</stripeoffset>\n", pp->stripeoffset);
191 }
188 if (pp->geom->flags & G_GEOM_WITHER)
189 ;
190 else if (pp->geom->dumpconf != NULL) {
191 sbuf_printf(sb, "\t <config>\n");
192 pp->geom->dumpconf(sb, "\t ", pp->geom, NULL, pp);
193 sbuf_printf(sb, "\t </config>\n");
194 }
195 sbuf_printf(sb, "\t</provider>\n");
196}
197
198
199static void
200g_conf_geom(struct sbuf *sb, struct g_geom *gp, struct g_provider *pp, struct g_consumer *cp)
201{
202 struct g_consumer *cp2;
203 struct g_provider *pp2;
204
205 sbuf_printf(sb, " <geom id=\"%p\">\n", gp);
206 sbuf_printf(sb, " <class ref=\"%p\"/>\n", gp->class);
207 sbuf_printf(sb, " <name>%s</name>\n", gp->name);
208 sbuf_printf(sb, " <rank>%d</rank>\n", gp->rank);
209 if (gp->flags & G_GEOM_WITHER)
210 sbuf_printf(sb, " <wither/>\n");
211 else if (gp->dumpconf != NULL) {
212 sbuf_printf(sb, " <config>\n");
213 gp->dumpconf(sb, "\t", gp, NULL, NULL);
214 sbuf_printf(sb, " </config>\n");
215 }
216 LIST_FOREACH(cp2, &gp->consumer, consumer) {
217 if (cp != NULL && cp != cp2)
218 continue;
219 g_conf_consumer(sb, cp2);
220 }
221
222 LIST_FOREACH(pp2, &gp->provider, provider) {
223 if (pp != NULL && pp != pp2)
224 continue;
225 g_conf_provider(sb, pp2);
226 }
227 sbuf_printf(sb, " </geom>\n");
228}
229
230static void
231g_conf_class(struct sbuf *sb, struct g_class *mp, struct g_geom *gp, struct g_provider *pp, struct g_consumer *cp)
232{
233 struct g_geom *gp2;
234
235 sbuf_printf(sb, " <class id=\"%p\">\n", mp);
236 sbuf_printf(sb, " <name>%s</name>\n", mp->name);
237 LIST_FOREACH(gp2, &mp->geom, geom) {
238 if (gp != NULL && gp != gp2)
239 continue;
240 g_conf_geom(sb, gp2, pp, cp);
241 }
242 sbuf_printf(sb, " </class>\n");
243}
244
245void
246g_conf_specific(struct sbuf *sb, struct g_class *mp, struct g_geom *gp, struct g_provider *pp, struct g_consumer *cp)
247{
248 struct g_class *mp2;
249
250 g_topology_assert();
251 sbuf_printf(sb, "<mesh>\n");
252 LIST_FOREACH(mp2, &g_classes, class) {
253 if (mp != NULL && mp != mp2)
254 continue;
255 g_conf_class(sb, mp2, gp, pp, cp);
256 }
257 sbuf_printf(sb, "</mesh>\n");
258 sbuf_finish(sb);
259}
260
261void
262g_confxml(void *p, int flag)
263{
264
265 KASSERT(flag != EV_CANCEL, ("g_confxml was cancelled"));
266 g_topology_assert();
267 g_conf_specific(p, NULL, NULL, NULL, NULL);
268}
269
270void
271g_trace(int level, const char *fmt, ...)
272{
273 va_list ap;
274
275 if (!(g_debugflags & level))
276 return;
277 va_start(ap, fmt);
278 vprintf(fmt, ap);
279 va_end(ap);
280 printf("\n");
281}
192 if (pp->geom->flags & G_GEOM_WITHER)
193 ;
194 else if (pp->geom->dumpconf != NULL) {
195 sbuf_printf(sb, "\t <config>\n");
196 pp->geom->dumpconf(sb, "\t ", pp->geom, NULL, pp);
197 sbuf_printf(sb, "\t </config>\n");
198 }
199 sbuf_printf(sb, "\t</provider>\n");
200}
201
202
203static void
204g_conf_geom(struct sbuf *sb, struct g_geom *gp, struct g_provider *pp, struct g_consumer *cp)
205{
206 struct g_consumer *cp2;
207 struct g_provider *pp2;
208
209 sbuf_printf(sb, " <geom id=\"%p\">\n", gp);
210 sbuf_printf(sb, " <class ref=\"%p\"/>\n", gp->class);
211 sbuf_printf(sb, " <name>%s</name>\n", gp->name);
212 sbuf_printf(sb, " <rank>%d</rank>\n", gp->rank);
213 if (gp->flags & G_GEOM_WITHER)
214 sbuf_printf(sb, " <wither/>\n");
215 else if (gp->dumpconf != NULL) {
216 sbuf_printf(sb, " <config>\n");
217 gp->dumpconf(sb, "\t", gp, NULL, NULL);
218 sbuf_printf(sb, " </config>\n");
219 }
220 LIST_FOREACH(cp2, &gp->consumer, consumer) {
221 if (cp != NULL && cp != cp2)
222 continue;
223 g_conf_consumer(sb, cp2);
224 }
225
226 LIST_FOREACH(pp2, &gp->provider, provider) {
227 if (pp != NULL && pp != pp2)
228 continue;
229 g_conf_provider(sb, pp2);
230 }
231 sbuf_printf(sb, " </geom>\n");
232}
233
234static void
235g_conf_class(struct sbuf *sb, struct g_class *mp, struct g_geom *gp, struct g_provider *pp, struct g_consumer *cp)
236{
237 struct g_geom *gp2;
238
239 sbuf_printf(sb, " <class id=\"%p\">\n", mp);
240 sbuf_printf(sb, " <name>%s</name>\n", mp->name);
241 LIST_FOREACH(gp2, &mp->geom, geom) {
242 if (gp != NULL && gp != gp2)
243 continue;
244 g_conf_geom(sb, gp2, pp, cp);
245 }
246 sbuf_printf(sb, " </class>\n");
247}
248
249void
250g_conf_specific(struct sbuf *sb, struct g_class *mp, struct g_geom *gp, struct g_provider *pp, struct g_consumer *cp)
251{
252 struct g_class *mp2;
253
254 g_topology_assert();
255 sbuf_printf(sb, "<mesh>\n");
256 LIST_FOREACH(mp2, &g_classes, class) {
257 if (mp != NULL && mp != mp2)
258 continue;
259 g_conf_class(sb, mp2, gp, pp, cp);
260 }
261 sbuf_printf(sb, "</mesh>\n");
262 sbuf_finish(sb);
263}
264
265void
266g_confxml(void *p, int flag)
267{
268
269 KASSERT(flag != EV_CANCEL, ("g_confxml was cancelled"));
270 g_topology_assert();
271 g_conf_specific(p, NULL, NULL, NULL, NULL);
272}
273
274void
275g_trace(int level, const char *fmt, ...)
276{
277 va_list ap;
278
279 if (!(g_debugflags & level))
280 return;
281 va_start(ap, fmt);
282 vprintf(fmt, ap);
283 va_end(ap);
284 printf("\n");
285}