2 * Copyright (c) 2002 Poul-Henning Kamp
3 * Copyright (c) 2002 Networks Associates Technology, Inc.
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.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
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
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
39 #include <sys/param.h>
47 #include <sys/systm.h>
48 #include <sys/malloc.h>
50 #include <machine/stdarg.h>
52 #include <geom/geom.h>
53 #include <geom/geom_int.h>
57 g_confdot_consumer(struct sbuf *sb, struct g_consumer *cp)
60 sbuf_printf(sb, "z%p [label=\"r%dw%de%d\\nbio #%d\"];\n",
61 cp, cp->acr, cp->acw, cp->ace, cp->biocount);
63 sbuf_printf(sb, "z%p -> z%p;\n", cp, cp->provider);
67 g_confdot_provider(struct sbuf *sb, struct g_provider *pp)
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);
75 g_confdot_geom(struct sbuf *sb, struct g_geom *gp)
77 struct g_consumer *cp;
78 struct g_provider *pp;
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);
87 LIST_FOREACH(pp, &gp->provider, provider) {
88 g_confdot_provider(sb, pp);
89 sbuf_printf(sb, "z%p -> z%p;\n", pp, gp);
94 g_confdot_class(struct sbuf *sb, struct g_class *mp)
98 LIST_FOREACH(gp, &mp->geom, geom)
99 g_confdot_geom(sb, gp);
108 sb = sbuf_new(NULL, NULL, 0, SBUF_AUTOEXTEND);
110 sbuf_printf(sb, "digraph geom {\n");
111 LIST_FOREACH(mp, &g_classs, class)
112 g_confdot_class(sb, mp);
113 sbuf_printf(sb, "};\n");
120 g_conf_consumer(struct sbuf *sb, struct g_consumer *cp)
123 sbuf_printf(sb, "\t<consumer>\n");
124 sbuf_printf(sb, "\t <ref>%p</ref>\n", cp);
125 sbuf_printf(sb, "\t <geom><ref>%p</ref></geom>\n", cp->geom);
126 sbuf_printf(sb, "\t <provider><ref>%p</ref></provider>\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");
134 sbuf_printf(sb, "\t</consumer>\n");
138 g_conf_provider(struct sbuf *sb, struct g_provider *pp)
141 sbuf_printf(sb, "\t<provider>\n");
142 sbuf_printf(sb, "\t <ref>%p</ref>\n", pp);
143 sbuf_printf(sb, "\t <geom><ref>%p</ref></geom>\n", pp->geom);
144 sbuf_printf(sb, "\t <mode>r%dw%de%d</mode>\n",
145 pp->acr, pp->acw, pp->ace);
146 sbuf_printf(sb, "\t <name>%s</name>\n", pp->name);
147 if (pp->geom->dumpconf) {
148 sbuf_printf(sb, "\t <config>\n");
149 pp->geom->dumpconf(sb, "\t ", pp->geom, NULL, pp);
150 sbuf_printf(sb, "\t </config>\n");
152 sbuf_printf(sb, "\t</provider>\n");
157 g_conf_geom(struct sbuf *sb, struct g_geom *gp, struct g_provider *pp, struct g_consumer *cp)
159 struct g_consumer *cp2;
160 struct g_provider *pp2;
162 sbuf_printf(sb, " <geom>\n");
163 sbuf_printf(sb, " <ref>%p</ref>\n", gp);
164 sbuf_printf(sb, " <class><ref>%p</ref></class>\n", gp->class);
165 sbuf_printf(sb, " <name>%s</name>\n", gp->name);
166 sbuf_printf(sb, " <rank>%d</rank>\n", gp->rank);
168 sbuf_printf(sb, " <config>\n");
169 gp->dumpconf(sb, "\t", gp, NULL, NULL);
170 sbuf_printf(sb, " </config>\n");
172 LIST_FOREACH(cp2, &gp->consumer, consumer) {
173 if (cp != NULL && cp != cp2)
175 g_conf_consumer(sb, cp2);
178 LIST_FOREACH(pp2, &gp->provider, provider) {
179 if (pp != NULL && pp != pp2)
181 g_conf_provider(sb, pp2);
183 sbuf_printf(sb, " </geom>\n");
187 g_conf_class(struct sbuf *sb, struct g_class *mp, struct g_geom *gp, struct g_provider *pp, struct g_consumer *cp)
191 sbuf_printf(sb, " <class>\n");
192 sbuf_printf(sb, " <ref>%p</ref>\n", mp);
193 sbuf_printf(sb, " <name>%s</name>\n", mp->name);
194 LIST_FOREACH(gp2, &mp->geom, geom) {
195 if (gp != NULL && gp != gp2)
197 g_conf_geom(sb, gp2, pp, cp);
199 sbuf_printf(sb, " </class>\n");
203 g_conf_specific(struct g_class *mp, struct g_geom *gp, struct g_provider *pp, struct g_consumer *cp)
208 sb = sbuf_new(NULL, NULL, 0, SBUF_AUTOEXTEND);
210 sbuf_printf(sb, "<mesh>\n");
211 LIST_FOREACH(mp2, &g_classs, class) {
212 if (mp != NULL && mp != mp2)
214 g_conf_class(sb, mp2, gp, pp, cp);
216 sbuf_printf(sb, "</mesh>\n");
225 return (g_conf_specific(NULL, NULL, NULL, NULL));
230 g_trace(int level, char *fmt, ...)
235 if (!(g_debugflags & level))
239 sb = sbuf_new(NULL, NULL, 0, SBUF_AUTOEXTEND);
240 sbuf_vprintf(sb, fmt, ap);
243 printf("%s\n", sbuf_data(sb));
248 g_hexdump(void *ptr, int length)
254 for (i = 0; i < length; i+= 16) {
256 for (j = 0; j < 16; j++) {
259 printf(" %02x", cp[k]);
264 for (j = 0; j < 16; j++) {
268 else if (cp[k] >= ' ' && cp[k] <= '~')