The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/geom/geom_dump.c

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    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$");
   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 
   49 static void
   50 g_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 
   59 static void
   60 g_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 
   67 static void
   68 g_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 
   86 static void
   87 g_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 
   95 void
   96 g_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 
  111 static void
  112 g_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 
  130 static void
  131 g_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 
  139 void
  140 g_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 
  156 void
  157 g_conf_printf_escaped(struct sbuf *sb, const char *fmt, ...)
  158 {
  159         struct sbuf *s;
  160         const u_char *c;
  161         va_list ap;
  162 
  163         s = sbuf_new_auto();
  164         va_start(ap, fmt);
  165         sbuf_vprintf(s, fmt, ap);
  166         va_end(ap);
  167         sbuf_finish(s);
  168 
  169         for (c = sbuf_data(s); *c != '\0'; c++) {
  170                 if (*c == '&' || *c == '<' || *c == '>' ||
  171                     *c == '\'' || *c == '"' || *c > 0x7e)
  172                         sbuf_printf(sb, "&#x%X;", *c);
  173                 else if (*c == '\t' || *c == '\n' || *c == '\r' || *c > 0x1f)
  174                         sbuf_putc(sb, *c);
  175                 else
  176                         sbuf_putc(sb, '?');
  177         }
  178         sbuf_delete(s);
  179 }
  180 
  181 static void
  182 g_conf_consumer(struct sbuf *sb, struct g_consumer *cp)
  183 {
  184 
  185         sbuf_printf(sb, "\t<consumer id=\"%p\">\n", cp);
  186         sbuf_printf(sb, "\t  <geom ref=\"%p\"/>\n", cp->geom);
  187         if (cp->provider != NULL)
  188                 sbuf_printf(sb, "\t  <provider ref=\"%p\"/>\n", cp->provider);
  189         sbuf_printf(sb, "\t  <mode>r%dw%de%d</mode>\n",
  190             cp->acr, cp->acw, cp->ace);
  191         if (cp->geom->flags & G_GEOM_WITHER)
  192                 ;
  193         else if (cp->geom->dumpconf != NULL) {
  194                 sbuf_printf(sb, "\t  <config>\n");
  195                 cp->geom->dumpconf(sb, "\t    ", cp->geom, cp, NULL);
  196                 sbuf_printf(sb, "\t  </config>\n");
  197         }
  198         sbuf_printf(sb, "\t</consumer>\n");
  199 }
  200 
  201 static void
  202 g_conf_provider(struct sbuf *sb, struct g_provider *pp)
  203 {
  204 
  205         sbuf_printf(sb, "\t<provider id=\"%p\">\n", pp);
  206         sbuf_printf(sb, "\t  <geom ref=\"%p\"/>\n", pp->geom);
  207         sbuf_printf(sb, "\t  <mode>r%dw%de%d</mode>\n",
  208             pp->acr, pp->acw, pp->ace);
  209         sbuf_printf(sb, "\t  <name>");
  210         g_conf_printf_escaped(sb, "%s", pp->name);
  211         sbuf_printf(sb, "</name>\n");
  212         sbuf_printf(sb, "\t  <mediasize>%jd</mediasize>\n",
  213             (intmax_t)pp->mediasize);
  214         sbuf_printf(sb, "\t  <sectorsize>%u</sectorsize>\n", pp->sectorsize);
  215         sbuf_printf(sb, "\t  <stripesize>%u</stripesize>\n", pp->stripesize);
  216         sbuf_printf(sb, "\t  <stripeoffset>%u</stripeoffset>\n", pp->stripeoffset);
  217         if (pp->flags & G_PF_WITHER)
  218                 sbuf_printf(sb, "\t  <wither/>\n");
  219         else if (pp->geom->flags & G_GEOM_WITHER)
  220                 ;
  221         else if (pp->geom->dumpconf != NULL) {
  222                 sbuf_printf(sb, "\t  <config>\n");
  223                 pp->geom->dumpconf(sb, "\t    ", pp->geom, NULL, pp);
  224                 sbuf_printf(sb, "\t  </config>\n");
  225         }
  226         sbuf_printf(sb, "\t</provider>\n");
  227 }
  228 
  229 
  230 static void
  231 g_conf_geom(struct sbuf *sb, struct g_geom *gp, struct g_provider *pp, struct g_consumer *cp)
  232 {
  233         struct g_consumer *cp2;
  234         struct g_provider *pp2;
  235 
  236         sbuf_printf(sb, "    <geom id=\"%p\">\n", gp);
  237         sbuf_printf(sb, "      <class ref=\"%p\"/>\n", gp->class);
  238         sbuf_printf(sb, "      <name>");
  239         g_conf_printf_escaped(sb, "%s", gp->name);
  240         sbuf_printf(sb, "</name>\n");
  241         sbuf_printf(sb, "      <rank>%d</rank>\n", gp->rank);
  242         if (gp->flags & G_GEOM_WITHER)
  243                 sbuf_printf(sb, "      <wither/>\n");
  244         else if (gp->dumpconf != NULL) {
  245                 sbuf_printf(sb, "      <config>\n");
  246                 gp->dumpconf(sb, "\t", gp, NULL, NULL);
  247                 sbuf_printf(sb, "      </config>\n");
  248         }
  249         LIST_FOREACH(cp2, &gp->consumer, consumer) {
  250                 if (cp != NULL && cp != cp2)
  251                         continue;
  252                 g_conf_consumer(sb, cp2);
  253         }
  254 
  255         LIST_FOREACH(pp2, &gp->provider, provider) {
  256                 if (pp != NULL && pp != pp2)
  257                         continue;
  258                 g_conf_provider(sb, pp2);
  259         }
  260         sbuf_printf(sb, "    </geom>\n");
  261 }
  262 
  263 static void
  264 g_conf_class(struct sbuf *sb, struct g_class *mp, struct g_geom *gp, struct g_provider *pp, struct g_consumer *cp)
  265 {
  266         struct g_geom *gp2;
  267 
  268         sbuf_printf(sb, "  <class id=\"%p\">\n", mp);
  269         sbuf_printf(sb, "    <name>");
  270         g_conf_printf_escaped(sb, "%s", mp->name);
  271         sbuf_printf(sb, "</name>\n");
  272         LIST_FOREACH(gp2, &mp->geom, geom) {
  273                 if (gp != NULL && gp != gp2)
  274                         continue;
  275                 g_conf_geom(sb, gp2, pp, cp);
  276         }
  277         sbuf_printf(sb, "  </class>\n");
  278 }
  279 
  280 void
  281 g_conf_specific(struct sbuf *sb, struct g_class *mp, struct g_geom *gp, struct g_provider *pp, struct g_consumer *cp)
  282 {
  283         struct g_class *mp2;
  284 
  285         g_topology_assert();
  286         sbuf_printf(sb, "<mesh>\n");
  287         LIST_FOREACH(mp2, &g_classes, class) {
  288                 if (mp != NULL && mp != mp2)
  289                         continue;
  290                 g_conf_class(sb, mp2, gp, pp, cp);
  291         }
  292         sbuf_printf(sb, "</mesh>\n");
  293         sbuf_finish(sb);
  294 }
  295 
  296 void
  297 g_confxml(void *p, int flag)
  298 {
  299 
  300         KASSERT(flag != EV_CANCEL, ("g_confxml was cancelled"));
  301         g_topology_assert();
  302         g_conf_specific(p, NULL, NULL, NULL, NULL);
  303 }
  304 
  305 void
  306 g_trace(int level, const char *fmt, ...)
  307 {
  308         va_list ap;
  309 
  310         if (!(g_debugflags & level))
  311                 return;
  312         va_start(ap, fmt);
  313         vprintf(fmt, ap);
  314         va_end(ap);
  315         printf("\n");
  316 }

Cache object: 71655df0a2c0e238277d1f22b7f9df0c


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.