36 */ 37 38 39#include <sys/param.h> 40#include <sys/stdint.h> 41#include <sys/sbuf.h> 42#ifndef _KERNEL 43#include <stdio.h> 44#include <string.h> 45#include <unistd.h> 46#include <stdlib.h> 47#include <err.h> 48#else 49#include <sys/systm.h> 50#include <sys/malloc.h> 51#endif 52#include <machine/stdarg.h> 53 54#include <geom/geom.h> 55#include <geom/geom_int.h> 56 57 58static void 59g_confdot_consumer(struct sbuf *sb, struct g_consumer *cp) 60{ 61 62 sbuf_printf(sb, "z%p [label=\"r%dw%de%d\\nbio #%d\"];\n", 63 cp, cp->acr, cp->acw, cp->ace, cp->biocount); 64 if (cp->provider) 65 sbuf_printf(sb, "z%p -> z%p;\n", cp, cp->provider); 66} 67 68static void 69g_confdot_provider(struct sbuf *sb, struct g_provider *pp) 70{ 71 72 sbuf_printf(sb, "z%p [shape=hexagon,label=\"%s\\nr%dw%de%d\\nerr#%d\"];\n", 73 pp, pp->name, pp->acr, pp->acw, pp->ace, pp->error); 74} 75 76static void 77g_confdot_geom(struct sbuf *sb, struct g_geom *gp) 78{ 79 struct g_consumer *cp; 80 struct g_provider *pp; 81 82 sbuf_printf(sb, "z%p [shape=box,label=\"%s\\n%s\\nr#%d\"];\n", 83 gp, gp->class->name, gp->name, gp->rank); 84 LIST_FOREACH(cp, &gp->consumer, consumer) { 85 g_confdot_consumer(sb, cp); 86 sbuf_printf(sb, "z%p -> z%p;\n", gp, cp); 87 } 88 89 LIST_FOREACH(pp, &gp->provider, provider) { 90 g_confdot_provider(sb, pp); 91 sbuf_printf(sb, "z%p -> z%p;\n", pp, gp); 92 } 93} 94 95static void 96g_confdot_class(struct sbuf *sb, struct g_class *mp) 97{ 98 struct g_geom *gp; 99 100 LIST_FOREACH(gp, &mp->geom, geom) 101 g_confdot_geom(sb, gp); 102} 103 104void 105g_confdot(void *p) 106{ 107 struct g_class *mp; 108 struct sbuf *sb; 109 110 sb = p; 111 g_topology_assert(); 112 sbuf_printf(sb, "digraph geom {\n"); 113 LIST_FOREACH(mp, &g_classes, class) 114 g_confdot_class(sb, mp); 115 sbuf_printf(sb, "};\n"); 116 sbuf_finish(sb); 117 wakeup(p); 118} 119 120static void 121g_conftxt_geom(struct sbuf *sb, struct g_geom *gp, int level) 122{ 123 struct g_provider *pp; 124 struct g_consumer *cp; 125 126 LIST_FOREACH(pp, &gp->provider, provider) { 127 sbuf_printf(sb, "%d %s %s %ju %u", level, gp->class->name, 128 pp->name, (uintmax_t)pp->mediasize, pp->sectorsize); 129 if (gp->dumpconf != NULL) 130 gp->dumpconf(sb, NULL, gp, NULL, pp); 131 sbuf_printf(sb, "\n"); 132 LIST_FOREACH(cp, &pp->consumers, consumers) 133 g_conftxt_geom(sb, cp->geom, level + 1); 134 } 135} 136 137static void 138g_conftxt_class(struct sbuf *sb, struct g_class *mp) 139{ 140 struct g_geom *gp; 141 142 LIST_FOREACH(gp, &mp->geom, geom) 143 g_conftxt_geom(sb, gp, 0); 144} 145 146void 147g_conftxt(void *p) 148{ 149 struct g_class *mp; 150 struct sbuf *sb; 151 152 sb = p; 153 g_topology_assert(); 154 LIST_FOREACH(mp, &g_classes, class) 155 if (!strcmp(mp->name, "DISK")) 156 break; 157 if (mp != NULL) 158 g_conftxt_class(sb, mp); 159 sbuf_finish(sb); 160 wakeup(p); 161} 162 163 164static void 165g_conf_consumer(struct sbuf *sb, struct g_consumer *cp) 166{ 167 168 sbuf_printf(sb, "\t<consumer id=\"%p\">\n", cp); 169 sbuf_printf(sb, "\t <geom ref=\"%p\"/>\n", cp->geom); 170 if (cp->provider != NULL) 171 sbuf_printf(sb, "\t <provider ref=\"%p\"/>\n", cp->provider); 172 sbuf_printf(sb, "\t <mode>r%dw%de%d</mode>\n", 173 cp->acr, cp->acw, cp->ace); 174 if (cp->geom->dumpconf != NULL) { 175 sbuf_printf(sb, "\t <config>\n"); 176 cp->geom->dumpconf(sb, "\t ", cp->geom, cp, NULL); 177 sbuf_printf(sb, "\t </config>\n"); 178 } 179 sbuf_printf(sb, "\t</consumer>\n"); 180} 181 182static void 183g_conf_provider(struct sbuf *sb, struct g_provider *pp) 184{ 185 186 sbuf_printf(sb, "\t<provider id=\"%p\">\n", pp); 187 sbuf_printf(sb, "\t <geom ref=\"%p\"/>\n", pp->geom); 188 sbuf_printf(sb, "\t <mode>r%dw%de%d</mode>\n", 189 pp->acr, pp->acw, pp->ace); 190 sbuf_printf(sb, "\t <name>%s</name>\n", pp->name); 191 sbuf_printf(sb, "\t <mediasize>%jd</mediasize>\n", 192 (intmax_t)pp->mediasize); 193 sbuf_printf(sb, "\t <sectorsize>%u</sectorsize>\n", pp->sectorsize); 194 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->dumpconf != NULL) { 214 sbuf_printf(sb, " <config>\n"); 215 gp->dumpconf(sb, "\t", gp, NULL, NULL); 216 sbuf_printf(sb, " </config>\n"); 217 } 218 LIST_FOREACH(cp2, &gp->consumer, consumer) { 219 if (cp != NULL && cp != cp2) 220 continue; 221 g_conf_consumer(sb, cp2); 222 } 223 224 LIST_FOREACH(pp2, &gp->provider, provider) { 225 if (pp != NULL && pp != pp2) 226 continue; 227 g_conf_provider(sb, pp2); 228 } 229 sbuf_printf(sb, " </geom>\n"); 230} 231 232static void 233g_conf_class(struct sbuf *sb, struct g_class *mp, struct g_geom *gp, struct g_provider *pp, struct g_consumer *cp) 234{ 235 struct g_geom *gp2; 236 237 sbuf_printf(sb, " <class id=\"%p\">\n", mp); 238 sbuf_printf(sb, " <name>%s</name>\n", mp->name); 239 LIST_FOREACH(gp2, &mp->geom, geom) { 240 if (gp != NULL && gp != gp2) 241 continue; 242 g_conf_geom(sb, gp2, pp, cp); 243 } 244 sbuf_printf(sb, " </class>\n"); 245} 246 247void 248g_conf_specific(struct sbuf *sb, struct g_class *mp, struct g_geom *gp, struct g_provider *pp, struct g_consumer *cp) 249{ 250 struct g_class *mp2; 251 252 g_topology_assert(); 253 sbuf_printf(sb, "<mesh>\n"); 254#ifndef _KERNEL 255 sbuf_printf(sb, " <FreeBSD>%cFreeBSD%c</FreeBSD>\n", '$', '$'); 256#endif 257 LIST_FOREACH(mp2, &g_classes, class) { 258 if (mp != NULL && mp != mp2) 259 continue; 260 g_conf_class(sb, mp2, gp, pp, cp); 261 } 262 sbuf_printf(sb, "</mesh>\n"); 263 sbuf_finish(sb); 264} 265 266void 267g_confxml(void *p) 268{ 269 270 g_topology_assert(); 271 g_conf_specific(p, NULL, NULL, NULL, NULL); 272 wakeup(p); 273} 274 275void
|