2002-03-11 21:42:35 +00:00
|
|
|
/*-
|
2017-11-27 15:17:37 +00:00
|
|
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
*
|
2002-03-11 21:42:35 +00:00
|
|
|
* Copyright (c) 2002 Poul-Henning Kamp
|
|
|
|
* Copyright (c) 2002 Networks Associates Technology, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This software was developed for the FreeBSD Project by Poul-Henning Kamp
|
|
|
|
* and NAI Labs, the Security Research Division of Network Associates, Inc.
|
|
|
|
* under DARPA/SPAWAR contract N66001-01-C-8035 ("CBOSS"), as part of the
|
|
|
|
* DARPA CHATS research program.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. The names of the authors may not be used to endorse or promote
|
|
|
|
* products derived from this software without specific prior written
|
|
|
|
* permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2003-06-11 06:49:16 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
2002-03-11 21:42:35 +00:00
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/sbuf.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <machine/stdarg.h>
|
|
|
|
|
|
|
|
#include <geom/geom.h>
|
2002-03-26 22:07:38 +00:00
|
|
|
#include <geom/geom_int.h>
|
2013-04-15 15:55:40 +00:00
|
|
|
#include <geom/geom_disk.h>
|
2002-03-11 21:42:35 +00:00
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
g_confdot_consumer(struct sbuf *sb, struct g_consumer *cp)
|
|
|
|
{
|
|
|
|
|
2003-02-07 23:08:24 +00:00
|
|
|
sbuf_printf(sb, "z%p [label=\"r%dw%de%d\"];\n",
|
|
|
|
cp, cp->acr, cp->acw, cp->ace);
|
2002-03-11 21:42:35 +00:00
|
|
|
if (cp->provider)
|
|
|
|
sbuf_printf(sb, "z%p -> z%p;\n", cp, cp->provider);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
g_confdot_provider(struct sbuf *sb, struct g_provider *pp)
|
|
|
|
{
|
|
|
|
|
2014-10-17 06:58:04 +00:00
|
|
|
sbuf_printf(sb, "z%p [shape=hexagon,label=\"%s\\nr%dw%de%d\\nerr#%d\\n"
|
2018-10-27 16:14:42 +00:00
|
|
|
"sector=%u\\nstripe=%ju\"];\n", pp, pp->name, pp->acr, pp->acw,
|
|
|
|
pp->ace, pp->error, pp->sectorsize, (uintmax_t)pp->stripesize);
|
2002-03-11 21:42:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
g_confdot_geom(struct sbuf *sb, struct g_geom *gp)
|
|
|
|
{
|
|
|
|
struct g_consumer *cp;
|
|
|
|
struct g_provider *pp;
|
|
|
|
|
|
|
|
sbuf_printf(sb, "z%p [shape=box,label=\"%s\\n%s\\nr#%d\"];\n",
|
2002-03-26 21:40:06 +00:00
|
|
|
gp, gp->class->name, gp->name, gp->rank);
|
2002-03-11 21:42:35 +00:00
|
|
|
LIST_FOREACH(cp, &gp->consumer, consumer) {
|
|
|
|
g_confdot_consumer(sb, cp);
|
|
|
|
sbuf_printf(sb, "z%p -> z%p;\n", gp, cp);
|
|
|
|
}
|
|
|
|
|
|
|
|
LIST_FOREACH(pp, &gp->provider, provider) {
|
|
|
|
g_confdot_provider(sb, pp);
|
|
|
|
sbuf_printf(sb, "z%p -> z%p;\n", pp, gp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2002-03-26 21:40:06 +00:00
|
|
|
g_confdot_class(struct sbuf *sb, struct g_class *mp)
|
2002-03-11 21:42:35 +00:00
|
|
|
{
|
|
|
|
struct g_geom *gp;
|
|
|
|
|
|
|
|
LIST_FOREACH(gp, &mp->geom, geom)
|
|
|
|
g_confdot_geom(sb, gp);
|
|
|
|
}
|
|
|
|
|
2002-10-04 10:38:36 +00:00
|
|
|
void
|
2003-04-02 21:10:04 +00:00
|
|
|
g_confdot(void *p, int flag )
|
2002-03-11 21:42:35 +00:00
|
|
|
{
|
2002-03-26 21:40:06 +00:00
|
|
|
struct g_class *mp;
|
2002-03-11 21:42:35 +00:00
|
|
|
struct sbuf *sb;
|
|
|
|
|
2003-04-02 21:10:04 +00:00
|
|
|
KASSERT(flag != EV_CANCEL, ("g_confdot was cancelled"));
|
2002-10-04 10:38:36 +00:00
|
|
|
sb = p;
|
|
|
|
g_topology_assert();
|
2019-06-19 15:36:02 +00:00
|
|
|
sbuf_cat(sb, "digraph geom {\n");
|
2002-04-04 09:41:47 +00:00
|
|
|
LIST_FOREACH(mp, &g_classes, class)
|
2002-03-26 21:40:06 +00:00
|
|
|
g_confdot_class(sb, mp);
|
2019-06-19 15:36:02 +00:00
|
|
|
sbuf_cat(sb, "}\n");
|
2002-03-11 21:42:35 +00:00
|
|
|
sbuf_finish(sb);
|
|
|
|
}
|
|
|
|
|
2002-10-28 22:43:54 +00:00
|
|
|
static void
|
|
|
|
g_conftxt_geom(struct sbuf *sb, struct g_geom *gp, int level)
|
|
|
|
{
|
|
|
|
struct g_provider *pp;
|
|
|
|
struct g_consumer *cp;
|
|
|
|
|
2003-07-08 21:12:40 +00:00
|
|
|
if (gp->flags & G_GEOM_WITHER)
|
|
|
|
return;
|
2002-10-28 22:43:54 +00:00
|
|
|
LIST_FOREACH(pp, &gp->provider, provider) {
|
|
|
|
sbuf_printf(sb, "%d %s %s %ju %u", level, gp->class->name,
|
|
|
|
pp->name, (uintmax_t)pp->mediasize, pp->sectorsize);
|
2002-11-20 18:10:42 +00:00
|
|
|
if (gp->dumpconf != NULL)
|
|
|
|
gp->dumpconf(sb, NULL, gp, NULL, pp);
|
2019-06-19 15:36:02 +00:00
|
|
|
sbuf_cat(sb, "\n");
|
2002-10-28 22:43:54 +00:00
|
|
|
LIST_FOREACH(cp, &pp->consumers, consumers)
|
|
|
|
g_conftxt_geom(sb, cp->geom, level + 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
g_conftxt_class(struct sbuf *sb, struct g_class *mp)
|
|
|
|
{
|
|
|
|
struct g_geom *gp;
|
|
|
|
|
|
|
|
LIST_FOREACH(gp, &mp->geom, geom)
|
|
|
|
g_conftxt_geom(sb, gp, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2003-04-02 21:10:04 +00:00
|
|
|
g_conftxt(void *p, int flag)
|
2002-10-28 22:43:54 +00:00
|
|
|
{
|
|
|
|
struct g_class *mp;
|
|
|
|
struct sbuf *sb;
|
|
|
|
|
2003-04-02 21:10:04 +00:00
|
|
|
KASSERT(flag != EV_CANCEL, ("g_conftxt was cancelled"));
|
2002-10-28 22:43:54 +00:00
|
|
|
sb = p;
|
|
|
|
g_topology_assert();
|
2005-11-12 20:02:02 +00:00
|
|
|
LIST_FOREACH(mp, &g_classes, class) {
|
2013-04-15 15:55:40 +00:00
|
|
|
if (!strcmp(mp->name, G_DISK_CLASS_NAME) || !strcmp(mp->name, "MD"))
|
2005-11-12 20:02:02 +00:00
|
|
|
g_conftxt_class(sb, mp);
|
|
|
|
}
|
2002-10-28 22:43:54 +00:00
|
|
|
sbuf_finish(sb);
|
|
|
|
}
|
|
|
|
|
2019-06-19 15:36:02 +00:00
|
|
|
void
|
|
|
|
g_conf_cat_escaped(struct sbuf *sb, const char *buf)
|
|
|
|
{
|
|
|
|
const u_char *c;
|
|
|
|
|
|
|
|
for (c = buf; *c != '\0'; c++) {
|
|
|
|
if (*c == '&' || *c == '<' || *c == '>' ||
|
|
|
|
*c == '\'' || *c == '"' || *c > 0x7e)
|
|
|
|
sbuf_printf(sb, "&#x%X;", *c);
|
|
|
|
else if (*c == '\t' || *c == '\n' || *c == '\r' || *c > 0x1f)
|
|
|
|
sbuf_putc(sb, *c);
|
|
|
|
else
|
|
|
|
sbuf_putc(sb, '?');
|
|
|
|
}
|
|
|
|
}
|
2002-03-11 21:42:35 +00:00
|
|
|
|
2013-11-27 14:25:06 +00:00
|
|
|
void
|
|
|
|
g_conf_printf_escaped(struct sbuf *sb, const char *fmt, ...)
|
2010-03-20 16:16:13 +00:00
|
|
|
{
|
|
|
|
struct sbuf *s;
|
2013-11-27 14:25:06 +00:00
|
|
|
va_list ap;
|
2010-03-20 16:16:13 +00:00
|
|
|
|
|
|
|
s = sbuf_new_auto();
|
2013-11-27 14:25:06 +00:00
|
|
|
va_start(ap, fmt);
|
|
|
|
sbuf_vprintf(s, fmt, ap);
|
|
|
|
va_end(ap);
|
|
|
|
sbuf_finish(s);
|
2010-03-20 16:16:13 +00:00
|
|
|
|
2019-06-19 15:36:02 +00:00
|
|
|
g_conf_cat_escaped(sb, sbuf_data(s));
|
2010-03-20 16:16:13 +00:00
|
|
|
sbuf_delete(s);
|
|
|
|
}
|
|
|
|
|
2002-03-11 21:42:35 +00:00
|
|
|
static void
|
|
|
|
g_conf_consumer(struct sbuf *sb, struct g_consumer *cp)
|
|
|
|
{
|
|
|
|
|
2002-04-24 21:02:28 +00:00
|
|
|
sbuf_printf(sb, "\t<consumer id=\"%p\">\n", cp);
|
|
|
|
sbuf_printf(sb, "\t <geom ref=\"%p\"/>\n", cp->geom);
|
|
|
|
if (cp->provider != NULL)
|
|
|
|
sbuf_printf(sb, "\t <provider ref=\"%p\"/>\n", cp->provider);
|
2002-03-11 21:42:35 +00:00
|
|
|
sbuf_printf(sb, "\t <mode>r%dw%de%d</mode>\n",
|
|
|
|
cp->acr, cp->acw, cp->ace);
|
2003-07-08 21:12:40 +00:00
|
|
|
if (cp->geom->flags & G_GEOM_WITHER)
|
|
|
|
;
|
|
|
|
else if (cp->geom->dumpconf != NULL) {
|
2019-06-19 15:36:02 +00:00
|
|
|
sbuf_cat(sb, "\t <config>\n");
|
2002-03-11 21:42:35 +00:00
|
|
|
cp->geom->dumpconf(sb, "\t ", cp->geom, cp, NULL);
|
2019-06-19 15:36:02 +00:00
|
|
|
sbuf_cat(sb, "\t </config>\n");
|
2002-03-11 21:42:35 +00:00
|
|
|
}
|
2019-06-19 15:36:02 +00:00
|
|
|
sbuf_cat(sb, "\t</consumer>\n");
|
2002-03-11 21:42:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
g_conf_provider(struct sbuf *sb, struct g_provider *pp)
|
|
|
|
{
|
|
|
|
|
2002-04-24 21:02:28 +00:00
|
|
|
sbuf_printf(sb, "\t<provider id=\"%p\">\n", pp);
|
|
|
|
sbuf_printf(sb, "\t <geom ref=\"%p\"/>\n", pp->geom);
|
2002-03-11 21:42:35 +00:00
|
|
|
sbuf_printf(sb, "\t <mode>r%dw%de%d</mode>\n",
|
|
|
|
pp->acr, pp->acw, pp->ace);
|
2019-06-19 15:36:02 +00:00
|
|
|
sbuf_cat(sb, "\t <name>");
|
|
|
|
g_conf_cat_escaped(sb, pp->name);
|
|
|
|
sbuf_cat(sb, "</name>\n");
|
2002-10-20 18:48:12 +00:00
|
|
|
sbuf_printf(sb, "\t <mediasize>%jd</mediasize>\n",
|
|
|
|
(intmax_t)pp->mediasize);
|
2002-10-20 19:18:07 +00:00
|
|
|
sbuf_printf(sb, "\t <sectorsize>%u</sectorsize>\n", pp->sectorsize);
|
2018-10-27 16:14:42 +00:00
|
|
|
sbuf_printf(sb, "\t <stripesize>%ju</stripesize>\n", (uintmax_t)pp->stripesize);
|
|
|
|
sbuf_printf(sb, "\t <stripeoffset>%ju</stripeoffset>\n", (uintmax_t)pp->stripeoffset);
|
2015-03-26 11:19:24 +00:00
|
|
|
if (pp->flags & G_PF_WITHER)
|
2019-06-19 15:36:02 +00:00
|
|
|
sbuf_cat(sb, "\t <wither/>\n");
|
2015-03-26 11:19:24 +00:00
|
|
|
else if (pp->geom->flags & G_GEOM_WITHER)
|
2003-07-08 21:12:40 +00:00
|
|
|
;
|
|
|
|
else if (pp->geom->dumpconf != NULL) {
|
2019-06-19 15:36:02 +00:00
|
|
|
sbuf_cat(sb, "\t <config>\n");
|
2002-03-11 21:42:35 +00:00
|
|
|
pp->geom->dumpconf(sb, "\t ", pp->geom, NULL, pp);
|
2019-06-19 15:36:02 +00:00
|
|
|
sbuf_cat(sb, "\t </config>\n");
|
2002-03-11 21:42:35 +00:00
|
|
|
}
|
2019-06-19 15:36:02 +00:00
|
|
|
sbuf_cat(sb, "\t</provider>\n");
|
2002-03-11 21:42:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
g_conf_geom(struct sbuf *sb, struct g_geom *gp, struct g_provider *pp, struct g_consumer *cp)
|
|
|
|
{
|
|
|
|
struct g_consumer *cp2;
|
|
|
|
struct g_provider *pp2;
|
2017-08-07 21:12:28 +00:00
|
|
|
struct g_geom_alias *gap;
|
2002-03-11 21:42:35 +00:00
|
|
|
|
2002-04-24 21:02:28 +00:00
|
|
|
sbuf_printf(sb, " <geom id=\"%p\">\n", gp);
|
|
|
|
sbuf_printf(sb, " <class ref=\"%p\"/>\n", gp->class);
|
2019-06-19 15:36:02 +00:00
|
|
|
sbuf_cat(sb, " <name>");
|
|
|
|
g_conf_cat_escaped(sb, gp->name);
|
|
|
|
sbuf_cat(sb, "</name>\n");
|
2002-03-11 21:42:35 +00:00
|
|
|
sbuf_printf(sb, " <rank>%d</rank>\n", gp->rank);
|
2003-07-08 21:12:40 +00:00
|
|
|
if (gp->flags & G_GEOM_WITHER)
|
2019-06-19 15:36:02 +00:00
|
|
|
sbuf_cat(sb, " <wither/>\n");
|
2003-07-08 21:12:40 +00:00
|
|
|
else if (gp->dumpconf != NULL) {
|
2019-06-19 15:36:02 +00:00
|
|
|
sbuf_cat(sb, " <config>\n");
|
2002-03-11 21:42:35 +00:00
|
|
|
gp->dumpconf(sb, "\t", gp, NULL, NULL);
|
2019-06-19 15:36:02 +00:00
|
|
|
sbuf_cat(sb, " </config>\n");
|
2002-03-11 21:42:35 +00:00
|
|
|
}
|
|
|
|
LIST_FOREACH(cp2, &gp->consumer, consumer) {
|
|
|
|
if (cp != NULL && cp != cp2)
|
|
|
|
continue;
|
|
|
|
g_conf_consumer(sb, cp2);
|
|
|
|
}
|
|
|
|
|
|
|
|
LIST_FOREACH(pp2, &gp->provider, provider) {
|
|
|
|
if (pp != NULL && pp != pp2)
|
|
|
|
continue;
|
|
|
|
g_conf_provider(sb, pp2);
|
|
|
|
}
|
2017-08-07 21:12:28 +00:00
|
|
|
LIST_FOREACH(gap, &gp->aliases, ga_next) {
|
2019-06-19 15:36:02 +00:00
|
|
|
sbuf_cat(sb, " <alias>\n");
|
|
|
|
g_conf_cat_escaped(sb, gap->ga_alias);
|
|
|
|
sbuf_cat(sb, " </alias>\n");
|
2017-08-07 21:12:28 +00:00
|
|
|
}
|
2019-06-19 15:36:02 +00:00
|
|
|
sbuf_cat(sb, " </geom>\n");
|
2002-03-11 21:42:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2002-03-26 21:40:06 +00:00
|
|
|
g_conf_class(struct sbuf *sb, struct g_class *mp, struct g_geom *gp, struct g_provider *pp, struct g_consumer *cp)
|
2002-03-11 21:42:35 +00:00
|
|
|
{
|
|
|
|
struct g_geom *gp2;
|
|
|
|
|
2002-04-24 21:02:28 +00:00
|
|
|
sbuf_printf(sb, " <class id=\"%p\">\n", mp);
|
2019-06-19 15:36:02 +00:00
|
|
|
sbuf_cat(sb, " <name>");
|
|
|
|
g_conf_cat_escaped(sb, mp->name);
|
|
|
|
sbuf_cat(sb, "</name>\n");
|
2002-03-11 21:42:35 +00:00
|
|
|
LIST_FOREACH(gp2, &mp->geom, geom) {
|
|
|
|
if (gp != NULL && gp != gp2)
|
|
|
|
continue;
|
|
|
|
g_conf_geom(sb, gp2, pp, cp);
|
|
|
|
}
|
2019-06-19 15:36:02 +00:00
|
|
|
sbuf_cat(sb, " </class>\n");
|
2002-03-11 21:42:35 +00:00
|
|
|
}
|
|
|
|
|
2002-10-04 10:38:36 +00:00
|
|
|
void
|
|
|
|
g_conf_specific(struct sbuf *sb, struct g_class *mp, struct g_geom *gp, struct g_provider *pp, struct g_consumer *cp)
|
2002-03-11 21:42:35 +00:00
|
|
|
{
|
2002-03-26 21:40:06 +00:00
|
|
|
struct g_class *mp2;
|
2002-03-11 21:42:35 +00:00
|
|
|
|
2002-10-04 10:38:36 +00:00
|
|
|
g_topology_assert();
|
2019-06-19 15:36:02 +00:00
|
|
|
sbuf_cat(sb, "<mesh>\n");
|
2002-04-04 09:41:47 +00:00
|
|
|
LIST_FOREACH(mp2, &g_classes, class) {
|
2002-03-11 21:42:35 +00:00
|
|
|
if (mp != NULL && mp != mp2)
|
|
|
|
continue;
|
2002-03-26 21:40:06 +00:00
|
|
|
g_conf_class(sb, mp2, gp, pp, cp);
|
2002-03-11 21:42:35 +00:00
|
|
|
}
|
2019-06-19 15:36:02 +00:00
|
|
|
sbuf_cat(sb, "</mesh>\n");
|
2002-03-11 21:42:35 +00:00
|
|
|
sbuf_finish(sb);
|
|
|
|
}
|
|
|
|
|
2002-10-04 10:38:36 +00:00
|
|
|
void
|
2003-04-02 21:10:04 +00:00
|
|
|
g_confxml(void *p, int flag)
|
2002-03-11 21:42:35 +00:00
|
|
|
{
|
|
|
|
|
2003-04-02 21:10:04 +00:00
|
|
|
KASSERT(flag != EV_CANCEL, ("g_confxml was cancelled"));
|
2002-10-14 10:02:24 +00:00
|
|
|
g_topology_assert();
|
2002-10-04 10:38:36 +00:00
|
|
|
g_conf_specific(p, NULL, NULL, NULL, NULL);
|
2002-03-11 21:42:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2019-12-05 04:52:19 +00:00
|
|
|
(g_trace)(int level, const char *fmt, ...)
|
2002-03-11 21:42:35 +00:00
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
if (!(g_debugflags & level))
|
|
|
|
return;
|
|
|
|
va_start(ap, fmt);
|
2002-09-30 08:54:46 +00:00
|
|
|
vprintf(fmt, ap);
|
2003-06-07 10:16:53 +00:00
|
|
|
va_end(ap);
|
2002-09-30 08:54:46 +00:00
|
|
|
printf("\n");
|
2002-03-11 21:42:35 +00:00
|
|
|
}
|