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=%u\"];\n", pp, pp->name, pp->acr, pp->acw,
68 pp->ace, pp->error, pp->sectorsize, 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_printf(sb, "digraph geom {\n");
109 LIST_FOREACH(mp, &g_classes, class)
110 g_confdot_class(sb, mp);
111 sbuf_printf(sb, "}\n");
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);
128 sbuf_printf(sb, "\n");
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);
161 g_conf_printf_escaped(struct sbuf *sb, const char *fmt, ...)
169 sbuf_vprintf(s, fmt, ap);
173 for (c = sbuf_data(s); *c != '\0'; c++) {
174 if (*c == '&' || *c == '<' || *c == '>' ||
175 *c == '\'' || *c == '"' || *c > 0x7e)
176 sbuf_printf(sb, "&#x%X;", *c);
177 else if (*c == '\t' || *c == '\n' || *c == '\r' || *c > 0x1f)
186 g_conf_consumer(struct sbuf *sb, struct g_consumer *cp)
189 sbuf_printf(sb, "\t<consumer id=\"%p\">\n", cp);
190 sbuf_printf(sb, "\t <geom ref=\"%p\"/>\n", cp->geom);
191 if (cp->provider != NULL)
192 sbuf_printf(sb, "\t <provider ref=\"%p\"/>\n", cp->provider);
193 sbuf_printf(sb, "\t <mode>r%dw%de%d</mode>\n",
194 cp->acr, cp->acw, cp->ace);
195 if (cp->geom->flags & G_GEOM_WITHER)
197 else if (cp->geom->dumpconf != NULL) {
198 sbuf_printf(sb, "\t <config>\n");
199 cp->geom->dumpconf(sb, "\t ", cp->geom, cp, NULL);
200 sbuf_printf(sb, "\t </config>\n");
202 sbuf_printf(sb, "\t</consumer>\n");
206 g_conf_provider(struct sbuf *sb, struct g_provider *pp)
209 sbuf_printf(sb, "\t<provider id=\"%p\">\n", pp);
210 sbuf_printf(sb, "\t <geom ref=\"%p\"/>\n", pp->geom);
211 sbuf_printf(sb, "\t <mode>r%dw%de%d</mode>\n",
212 pp->acr, pp->acw, pp->ace);
213 sbuf_printf(sb, "\t <name>");
214 g_conf_printf_escaped(sb, "%s", pp->name);
215 sbuf_printf(sb, "</name>\n");
216 sbuf_printf(sb, "\t <mediasize>%jd</mediasize>\n",
217 (intmax_t)pp->mediasize);
218 sbuf_printf(sb, "\t <sectorsize>%u</sectorsize>\n", pp->sectorsize);
219 sbuf_printf(sb, "\t <stripesize>%u</stripesize>\n", pp->stripesize);
220 sbuf_printf(sb, "\t <stripeoffset>%u</stripeoffset>\n", pp->stripeoffset);
221 if (pp->flags & G_PF_WITHER)
222 sbuf_printf(sb, "\t <wither/>\n");
223 else if (pp->geom->flags & G_GEOM_WITHER)
225 else if (pp->geom->dumpconf != NULL) {
226 sbuf_printf(sb, "\t <config>\n");
227 pp->geom->dumpconf(sb, "\t ", pp->geom, NULL, pp);
228 sbuf_printf(sb, "\t </config>\n");
230 sbuf_printf(sb, "\t</provider>\n");
235 g_conf_geom(struct sbuf *sb, struct g_geom *gp, struct g_provider *pp, struct g_consumer *cp)
237 struct g_consumer *cp2;
238 struct g_provider *pp2;
239 struct g_geom_alias *gap;
241 sbuf_printf(sb, " <geom id=\"%p\">\n", gp);
242 sbuf_printf(sb, " <class ref=\"%p\"/>\n", gp->class);
243 sbuf_printf(sb, " <name>");
244 g_conf_printf_escaped(sb, "%s", gp->name);
245 sbuf_printf(sb, "</name>\n");
246 sbuf_printf(sb, " <rank>%d</rank>\n", gp->rank);
247 if (gp->flags & G_GEOM_WITHER)
248 sbuf_printf(sb, " <wither/>\n");
249 else if (gp->dumpconf != NULL) {
250 sbuf_printf(sb, " <config>\n");
251 gp->dumpconf(sb, "\t", gp, NULL, NULL);
252 sbuf_printf(sb, " </config>\n");
254 LIST_FOREACH(cp2, &gp->consumer, consumer) {
255 if (cp != NULL && cp != cp2)
257 g_conf_consumer(sb, cp2);
260 LIST_FOREACH(pp2, &gp->provider, provider) {
261 if (pp != NULL && pp != pp2)
263 g_conf_provider(sb, pp2);
265 LIST_FOREACH(gap, &gp->aliases, ga_next) {
266 sbuf_printf(sb, " <alias>\n");
267 g_conf_printf_escaped(sb, "%s", gap->ga_alias);
268 sbuf_printf(sb, " </alias>\n");
270 sbuf_printf(sb, " </geom>\n");
274 g_conf_class(struct sbuf *sb, struct g_class *mp, struct g_geom *gp, struct g_provider *pp, struct g_consumer *cp)
278 sbuf_printf(sb, " <class id=\"%p\">\n", mp);
279 sbuf_printf(sb, " <name>");
280 g_conf_printf_escaped(sb, "%s", mp->name);
281 sbuf_printf(sb, "</name>\n");
282 LIST_FOREACH(gp2, &mp->geom, geom) {
283 if (gp != NULL && gp != gp2)
285 g_conf_geom(sb, gp2, pp, cp);
287 sbuf_printf(sb, " </class>\n");
291 g_conf_specific(struct sbuf *sb, struct g_class *mp, struct g_geom *gp, struct g_provider *pp, struct g_consumer *cp)
296 sbuf_printf(sb, "<mesh>\n");
297 LIST_FOREACH(mp2, &g_classes, class) {
298 if (mp != NULL && mp != mp2)
300 g_conf_class(sb, mp2, gp, pp, cp);
302 sbuf_printf(sb, "</mesh>\n");
307 g_confxml(void *p, int flag)
310 KASSERT(flag != EV_CANCEL, ("g_confxml was cancelled"));
312 g_conf_specific(p, NULL, NULL, NULL, NULL);
316 g_trace(int level, const char *fmt, ...)
320 if (!(g_debugflags & level))