2 * SPDX-License-Identifier: BSD-3-Clause
4 * Copyright (c) 2002 Poul-Henning Kamp
5 * Copyright (c) 2002 Networks Associates Technology, Inc.
8 * This software was developed for the FreeBSD Project by Poul-Henning Kamp
9 * and NAI Labs, the Security Research Division of Network Associates, Inc.
10 * under DARPA/SPAWAR contract N66001-01-C-8035 ("CBOSS"), as part of the
11 * DARPA CHATS research program.
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions
16 * 1. Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution.
21 * 3. The names of the authors may not be used to endorse or promote
22 * products derived from this software without specific prior written
25 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
26 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38 #include <sys/cdefs.h>
39 __FBSDID("$FreeBSD$");
41 #include <sys/param.h>
43 #include <sys/systm.h>
44 #include <sys/malloc.h>
45 #include <machine/stdarg.h>
47 #include <geom/geom.h>
48 #include <geom/geom_int.h>
49 #include <geom/geom_disk.h>
53 g_confdot_consumer(struct sbuf *sb, struct g_consumer *cp)
56 sbuf_printf(sb, "z%p [label=\"r%dw%de%d\"];\n",
57 cp, cp->acr, cp->acw, cp->ace);
59 sbuf_printf(sb, "z%p -> z%p;\n", cp, cp->provider);
63 g_confdot_provider(struct sbuf *sb, struct g_provider *pp)
66 sbuf_printf(sb, "z%p [shape=hexagon,label=\"%s\\nr%dw%de%d\\nerr#%d\\n"
67 "sector=%u\\nstripe=%ju\"];\n", pp, pp->name, pp->acr, pp->acw,
68 pp->ace, pp->error, pp->sectorsize, (uintmax_t)pp->stripesize);
72 g_confdot_geom(struct sbuf *sb, struct g_geom *gp)
74 struct g_consumer *cp;
75 struct g_provider *pp;
77 sbuf_printf(sb, "z%p [shape=box,label=\"%s\\n%s\\nr#%d\"];\n",
78 gp, gp->class->name, gp->name, gp->rank);
79 LIST_FOREACH(cp, &gp->consumer, consumer) {
80 g_confdot_consumer(sb, cp);
81 sbuf_printf(sb, "z%p -> z%p;\n", gp, cp);
84 LIST_FOREACH(pp, &gp->provider, provider) {
85 g_confdot_provider(sb, pp);
86 sbuf_printf(sb, "z%p -> z%p;\n", pp, gp);
91 g_confdot_class(struct sbuf *sb, struct g_class *mp)
95 LIST_FOREACH(gp, &mp->geom, geom)
96 g_confdot_geom(sb, gp);
100 g_confdot(void *p, int flag )
105 KASSERT(flag != EV_CANCEL, ("g_confdot was cancelled"));
108 sbuf_cat(sb, "digraph geom {\n");
109 LIST_FOREACH(mp, &g_classes, class)
110 g_confdot_class(sb, mp);
116 g_conftxt_geom(struct sbuf *sb, struct g_geom *gp, int level)
118 struct g_provider *pp;
119 struct g_consumer *cp;
121 if (gp->flags & G_GEOM_WITHER)
123 LIST_FOREACH(pp, &gp->provider, provider) {
124 sbuf_printf(sb, "%d %s %s %ju %u", level, gp->class->name,
125 pp->name, (uintmax_t)pp->mediasize, pp->sectorsize);
126 if (gp->dumpconf != NULL)
127 gp->dumpconf(sb, NULL, gp, NULL, pp);
129 LIST_FOREACH(cp, &pp->consumers, consumers)
130 g_conftxt_geom(sb, cp->geom, level + 1);
135 g_conftxt_class(struct sbuf *sb, struct g_class *mp)
139 LIST_FOREACH(gp, &mp->geom, geom)
140 g_conftxt_geom(sb, gp, 0);
144 g_conftxt(void *p, int flag)
149 KASSERT(flag != EV_CANCEL, ("g_conftxt was cancelled"));
152 LIST_FOREACH(mp, &g_classes, class) {
153 if (!strcmp(mp->name, G_DISK_CLASS_NAME) || !strcmp(mp->name, "MD"))
154 g_conftxt_class(sb, mp);
160 g_conf_cat_escaped(struct sbuf *sb, const char *buf)
164 for (c = buf; *c != '\0'; c++) {
165 if (*c == '&' || *c == '<' || *c == '>' ||
166 *c == '\'' || *c == '"' || *c > 0x7e)
167 sbuf_printf(sb, "&#x%X;", *c);
168 else if (*c == '\t' || *c == '\n' || *c == '\r' || *c > 0x1f)
176 g_conf_printf_escaped(struct sbuf *sb, const char *fmt, ...)
183 sbuf_vprintf(s, fmt, ap);
187 g_conf_cat_escaped(sb, sbuf_data(s));
192 g_conf_consumer(struct sbuf *sb, struct g_consumer *cp)
195 sbuf_printf(sb, "\t<consumer id=\"%p\">\n", cp);
196 sbuf_printf(sb, "\t <geom ref=\"%p\"/>\n", cp->geom);
197 if (cp->provider != NULL)
198 sbuf_printf(sb, "\t <provider ref=\"%p\"/>\n", cp->provider);
199 sbuf_printf(sb, "\t <mode>r%dw%de%d</mode>\n",
200 cp->acr, cp->acw, cp->ace);
201 if (cp->geom->flags & G_GEOM_WITHER)
203 else if (cp->geom->dumpconf != NULL) {
204 sbuf_cat(sb, "\t <config>\n");
205 cp->geom->dumpconf(sb, "\t ", cp->geom, cp, NULL);
206 sbuf_cat(sb, "\t </config>\n");
208 sbuf_cat(sb, "\t</consumer>\n");
212 g_conf_provider(struct sbuf *sb, struct g_provider *pp)
215 sbuf_printf(sb, "\t<provider id=\"%p\">\n", pp);
216 sbuf_printf(sb, "\t <geom ref=\"%p\"/>\n", pp->geom);
217 sbuf_printf(sb, "\t <mode>r%dw%de%d</mode>\n",
218 pp->acr, pp->acw, pp->ace);
219 sbuf_cat(sb, "\t <name>");
220 g_conf_cat_escaped(sb, pp->name);
221 sbuf_cat(sb, "</name>\n");
222 sbuf_printf(sb, "\t <mediasize>%jd</mediasize>\n",
223 (intmax_t)pp->mediasize);
224 sbuf_printf(sb, "\t <sectorsize>%u</sectorsize>\n", pp->sectorsize);
225 sbuf_printf(sb, "\t <stripesize>%ju</stripesize>\n", (uintmax_t)pp->stripesize);
226 sbuf_printf(sb, "\t <stripeoffset>%ju</stripeoffset>\n", (uintmax_t)pp->stripeoffset);
227 if (pp->flags & G_PF_WITHER)
228 sbuf_cat(sb, "\t <wither/>\n");
229 else if (pp->geom->flags & G_GEOM_WITHER)
231 else if (pp->geom->dumpconf != NULL) {
232 sbuf_cat(sb, "\t <config>\n");
233 pp->geom->dumpconf(sb, "\t ", pp->geom, NULL, pp);
234 sbuf_cat(sb, "\t </config>\n");
236 sbuf_cat(sb, "\t</provider>\n");
241 g_conf_geom(struct sbuf *sb, struct g_geom *gp, struct g_provider *pp, struct g_consumer *cp)
243 struct g_consumer *cp2;
244 struct g_provider *pp2;
245 struct g_geom_alias *gap;
247 sbuf_printf(sb, " <geom id=\"%p\">\n", gp);
248 sbuf_printf(sb, " <class ref=\"%p\"/>\n", gp->class);
249 sbuf_cat(sb, " <name>");
250 g_conf_cat_escaped(sb, gp->name);
251 sbuf_cat(sb, "</name>\n");
252 sbuf_printf(sb, " <rank>%d</rank>\n", gp->rank);
253 if (gp->flags & G_GEOM_WITHER)
254 sbuf_cat(sb, " <wither/>\n");
255 else if (gp->dumpconf != NULL) {
256 sbuf_cat(sb, " <config>\n");
257 gp->dumpconf(sb, "\t", gp, NULL, NULL);
258 sbuf_cat(sb, " </config>\n");
260 LIST_FOREACH(cp2, &gp->consumer, consumer) {
261 if (cp != NULL && cp != cp2)
263 g_conf_consumer(sb, cp2);
266 LIST_FOREACH(pp2, &gp->provider, provider) {
267 if (pp != NULL && pp != pp2)
269 g_conf_provider(sb, pp2);
271 LIST_FOREACH(gap, &gp->aliases, ga_next) {
272 sbuf_cat(sb, " <alias>\n");
273 g_conf_cat_escaped(sb, gap->ga_alias);
274 sbuf_cat(sb, " </alias>\n");
276 sbuf_cat(sb, " </geom>\n");
280 g_conf_class(struct sbuf *sb, struct g_class *mp, struct g_geom *gp, struct g_provider *pp, struct g_consumer *cp)
284 sbuf_printf(sb, " <class id=\"%p\">\n", mp);
285 sbuf_cat(sb, " <name>");
286 g_conf_cat_escaped(sb, mp->name);
287 sbuf_cat(sb, "</name>\n");
288 LIST_FOREACH(gp2, &mp->geom, geom) {
289 if (gp != NULL && gp != gp2)
291 g_conf_geom(sb, gp2, pp, cp);
293 sbuf_cat(sb, " </class>\n");
297 g_conf_specific(struct sbuf *sb, struct g_class *mp, struct g_geom *gp, struct g_provider *pp, struct g_consumer *cp)
302 sbuf_cat(sb, "<mesh>\n");
303 LIST_FOREACH(mp2, &g_classes, class) {
304 if (mp != NULL && mp != mp2)
306 g_conf_class(sb, mp2, gp, pp, cp);
308 sbuf_cat(sb, "</mesh>\n");
313 g_confxml(void *p, int flag)
316 KASSERT(flag != EV_CANCEL, ("g_confxml was cancelled"));
318 g_conf_specific(p, NULL, NULL, NULL, NULL);
322 g_trace(int level, const char *fmt, ...)
326 if (!(g_debugflags & level))