diff --git a/sbin/geom/class/concat/gconcat.8 b/sbin/geom/class/concat/gconcat.8 index 4b370dd16c64..eacccebcfa26 100644 --- a/sbin/geom/class/concat/gconcat.8 +++ b/sbin/geom/class/concat/gconcat.8 @@ -66,7 +66,7 @@ .Op Ar dev2 Op Ar ... .Nm .Cm list -.Op Ar prov Op Ar ... +.Op Ar name Op Ar ... .Nm .Cm load .Op Fl v diff --git a/sbin/geom/class/stripe/gstripe.8 b/sbin/geom/class/stripe/gstripe.8 index 9f3a2ba2adf4..7fe1082daffe 100644 --- a/sbin/geom/class/stripe/gstripe.8 +++ b/sbin/geom/class/stripe/gstripe.8 @@ -68,7 +68,7 @@ .Op Ar dev2 Op Ar ... .Nm .Cm list -.Op Ar prov Op Ar ... +.Op Ar name Op Ar ... .Nm .Cm load .Op Fl v diff --git a/sbin/geom/core/geom.8 b/sbin/geom/core/geom.8 index 875432f82cc3..46cbb8ae7467 100644 --- a/sbin/geom/core/geom.8 +++ b/sbin/geom/core/geom.8 @@ -50,8 +50,8 @@ Here is the list of standard commands: .It Cm help List all available commands for the given class. .It Cm list -Print detailed information (within the given class) about all providers -(if no additional arguments were specified) or the given providers. +Print detailed information (within the given class) about all geoms +(if no additional arguments were specified) or the given geoms. This command is only available if the given class exists in the kernel. .It Cm load Load the kernel module that implements the given class. diff --git a/sbin/geom/core/geom.c b/sbin/geom/core/geom.c index 4a2d1cc9320f..12959a335c80 100644 --- a/sbin/geom/core/geom.c +++ b/sbin/geom/core/geom.c @@ -548,57 +548,88 @@ find_class(struct gmesh *mesh, const char *name) return (NULL); } -static struct gprovider * -find_provider(struct gclass *classp, const char *name) +static struct ggeom * +find_geom(struct gclass *classp, const char *name) { struct ggeom *gp; - struct gprovider *pp; LIST_FOREACH(gp, &classp->lg_geom, lg_geom) { - LIST_FOREACH(pp, &gp->lg_provider, lg_provider) { - if (strcmp(pp->lg_name, name) == 0) - return (pp); - } + if (strcmp(gp->lg_name, name) == 0) + return (gp); } return (NULL); } -static char * -genspaces(const char *text, size_t len) -{ - static char spaces[256]; - size_t outlen; - - if (strlen(text) >= len) { - spaces[0] = '\0'; - return (spaces); - } - memset(spaces, ' ', sizeof(spaces)); - outlen = len - strlen(text); - if (outlen >= sizeof(spaces)) { - spaces[sizeof(spaces) - 1] = '\0'; - return (spaces); - } - spaces[outlen] = '\0'; - return (spaces); -} - static void -show_one(struct gprovider *pp) +show_one_provider(struct gprovider *pp, const char *prefix) { struct gconfig *conf; char buf[5]; - printf(" NAME: %s\n", pp->lg_name); - printf(" geom name: %s\n", pp->lg_geom->lg_name); + printf("Name: %s\n", pp->lg_name); humanize_number(buf, sizeof(buf), (int64_t)pp->lg_mediasize, "", HN_AUTOSCALE, HN_B | HN_NOSPACE | HN_DECIMAL); - printf(" mediasize: %jd (%s)\n", (intmax_t)pp->lg_mediasize, buf); - printf(" sectorsize: %u\n", pp->lg_sectorsize); - printf(" mode: %s\n", pp->lg_mode); + printf("%sMediasize: %jd (%s)\n", prefix, (intmax_t)pp->lg_mediasize, + buf); + printf("%sSectorsize: %u\n", prefix, pp->lg_sectorsize); + printf("%sMode: %s\n", prefix, pp->lg_mode); LIST_FOREACH(conf, &pp->lg_config, lg_config) { - printf("%s%s: %s\n", genspaces(conf->lg_name, 11), - conf->lg_name, conf->lg_val); + printf("%s%s: %s\n", prefix, conf->lg_name, conf->lg_val); + } +} + +static void +show_one_consumer(struct gconsumer *cp, const char *prefix) +{ + struct gprovider *pp; + struct gconfig *conf; + + pp = cp->lg_provider; + if (pp == NULL) + printf("[no provider]\n"); + else { + char buf[5]; + + printf("Name: %s\n", pp->lg_name); + humanize_number(buf, sizeof(buf), (int64_t)pp->lg_mediasize, "", + HN_AUTOSCALE, HN_B | HN_NOSPACE | HN_DECIMAL); + printf("%sMediasize: %jd (%s)\n", prefix, + (intmax_t)pp->lg_mediasize, buf); + printf("%sSectorsize: %u\n", prefix, pp->lg_sectorsize); + printf("%sMode: %s\n", prefix, cp->lg_mode); + } + LIST_FOREACH(conf, &cp->lg_config, lg_config) { + printf("%s%s: %s\n", prefix, conf->lg_name, conf->lg_val); + } +} + +static void +show_one_geom(struct ggeom *gp) +{ + struct gprovider *pp; + struct gconsumer *cp; + struct gconfig *conf; + unsigned n; + + printf("Geom name: %s\n", gp->lg_name); + LIST_FOREACH(conf, &gp->lg_config, lg_config) { + printf("%s: %s\n", conf->lg_name, conf->lg_val); + } + if (!LIST_EMPTY(&gp->lg_provider)) { + printf("Providers:\n"); + n = 1; + LIST_FOREACH(pp, &gp->lg_provider, lg_provider) { + printf("%u. ", n++); + show_one_provider(pp, " "); + } + } + if (!LIST_EMPTY(&gp->lg_consumer)) { + printf("Consumers:\n"); + n = 1; + LIST_FOREACH(cp, &gp->lg_consumer, lg_consumer) { + printf("%u. ", n++); + show_one_consumer(cp, " "); + } } printf("\n"); } @@ -632,7 +663,7 @@ std_list(struct gctl_req *req, unsigned flags __unused) { struct gmesh mesh; struct gclass *classp; - struct gprovider *pp; + struct ggeom *gp; int error, *nargs; error = geom_gettree(&mesh); @@ -660,21 +691,15 @@ std_list(struct gctl_req *req, unsigned flags __unused) snprintf(param, sizeof(param), "arg%d", i); name = gctl_get_asciiparam(req, param); assert(name != NULL); - pp = find_provider(classp, name); - if (pp != NULL) - show_one(pp); - else { - fprintf(stderr, "No such provider: %s.\n", - name); - } + gp = find_geom(classp, name); + if (gp != NULL) + show_one_geom(gp); + else + fprintf(stderr, "No such geom: %s.\n", name); } } else { - struct ggeom *gp; - LIST_FOREACH(gp, &classp->lg_geom, lg_geom) { - LIST_FOREACH(pp, &gp->lg_provider, lg_provider) { - show_one(pp); - } + show_one_geom(gp); } } geom_deletetree(&mesh); diff --git a/sys/geom/concat/g_concat.c b/sys/geom/concat/g_concat.c index 20a54c5a011f..c87839d1a863 100644 --- a/sys/geom/concat/g_concat.c +++ b/sys/geom/concat/g_concat.c @@ -798,35 +798,44 @@ g_concat_dumpconf(struct sbuf *sb, const char *indent, struct g_geom *gp, g_topology_assert(); sc = gp->softc; - if (sc == NULL || pp == NULL) + if (sc == NULL) return; - sbuf_printf(sb, "%s%u\n", indent, (u_int)sc->sc_id); - switch (sc->sc_type) { - case G_CONCAT_TYPE_AUTOMATIC: - sbuf_printf(sb, "%s%s\n", indent, "automatic"); - break; - case G_CONCAT_TYPE_MANUAL: - sbuf_printf(sb, "%s%s\n", indent, "manual"); - break; - default: - sbuf_printf(sb, "%s%s\n", indent, "unknown"); - break; + if (pp != NULL) { + /* Nothing here. */ + } else if (cp != NULL) { + struct g_concat_disk *disk; + + disk = cp->private; + if (disk == NULL) + return; + sbuf_printf(sb, "%s%jd\n", indent, + (intmax_t)disk->d_end); + sbuf_printf(sb, "%s%jd\n", indent, + (intmax_t)disk->d_start); + } else { + sbuf_printf(sb, "%s%u\n", indent, (u_int)sc->sc_id); + sbuf_printf(sb, "%s", indent); + switch (sc->sc_type) { + case G_CONCAT_TYPE_AUTOMATIC: + sbuf_printf(sb, "AUTOMATIC"); + break; + case G_CONCAT_TYPE_MANUAL: + sbuf_printf(sb, "MANUAL"); + break; + default: + sbuf_printf(sb, "UNKNOWN"); + break; + } + sbuf_printf(sb, "\n"); + sbuf_printf(sb, "%sTotal=%u, Online=%u\n", + indent, sc->sc_ndisks, g_concat_nvalid(sc)); + sbuf_printf(sb, "%s", indent); + if (sc->sc_provider != NULL && sc->sc_provider->error == 0) + sbuf_printf(sb, "UP"); + else + sbuf_printf(sb, "DOWN"); + sbuf_printf(sb, "\n"); } - sbuf_printf(sb, "%s", indent); - LIST_FOREACH(cp, &gp->consumer, consumer) { - if (cp->provider == NULL) - continue; - sbuf_printf(sb, "%s", cp->provider->name); - if (LIST_NEXT(cp, consumer) != NULL) - sbuf_printf(sb, " "); - } - sbuf_printf(sb, "\n"); - sbuf_printf(sb, "%stotal=%u, online=%u\n", indent, - sc->sc_ndisks, g_concat_nvalid(sc)); - if (pp->error == 0) - sbuf_printf(sb, "%sUP\n", indent); - else - sbuf_printf(sb, "%sDOWN\n", indent); } DECLARE_GEOM_CLASS(g_concat_class, g_concat); diff --git a/sys/geom/nop/g_nop.c b/sys/geom/nop/g_nop.c index 00860f12d228..88283eef3d21 100644 --- a/sys/geom/nop/g_nop.c +++ b/sys/geom/nop/g_nop.c @@ -468,12 +468,12 @@ g_nop_dumpconf(struct sbuf *sb, const char *indent, struct g_geom *gp, { struct g_nop_softc *sc; - if (pp == NULL) + if (pp != NULL || cp != NULL) return; sc = gp->softc; - sbuf_printf(sb, "%s%jd\n", indent, + sbuf_printf(sb, "%s%jd\n", indent, (intmax_t)sc->sc_offset); - sbuf_printf(sb, "%s%u\n", indent, sc->sc_failprob); + sbuf_printf(sb, "%s%u\n", indent, sc->sc_failprob); } DECLARE_GEOM_CLASS(g_nop_class, g_nop); diff --git a/sys/geom/stripe/g_stripe.c b/sys/geom/stripe/g_stripe.c index 9e642c0054e7..705a860cd682 100644 --- a/sys/geom/stripe/g_stripe.c +++ b/sys/geom/stripe/g_stripe.c @@ -1128,37 +1128,38 @@ g_stripe_dumpconf(struct sbuf *sb, const char *indent, struct g_geom *gp, struct g_stripe_softc *sc; sc = gp->softc; - if (sc == NULL || pp == NULL) + if (sc == NULL) return; - sbuf_printf(sb, "%s%u\n", indent, (u_int)sc->sc_id); - sbuf_printf(sb, "%s%u\n", indent, - (u_int)sc->sc_stripesize); - switch (sc->sc_type) { - case G_STRIPE_TYPE_AUTOMATIC: - sbuf_printf(sb, "%s%s\n", indent, "automatic"); - break; - case G_STRIPE_TYPE_MANUAL: - sbuf_printf(sb, "%s%s\n", indent, "manual"); - break; - default: - sbuf_printf(sb, "%s%s\n", indent, "unknown"); - break; + if (pp != NULL) { + /* Nothing here. */ + } else if (cp != NULL) { + /* Nothing here. */ + } else { + sbuf_printf(sb, "%s%u\n", indent, (u_int)sc->sc_id); + sbuf_printf(sb, "%s%u\n", indent, + (u_int)sc->sc_stripesize); + sbuf_printf(sb, "%s", indent); + switch (sc->sc_type) { + case G_STRIPE_TYPE_AUTOMATIC: + sbuf_printf(sb, "AUTOMATIC"); + break; + case G_STRIPE_TYPE_MANUAL: + sbuf_printf(sb, "MANUAL"); + break; + default: + sbuf_printf(sb, "UNKNOWN"); + break; + } + sbuf_printf(sb, "\n"); + sbuf_printf(sb, "%sTotal=%u, Online=%u\n", + indent, sc->sc_ndisks, g_stripe_nvalid(sc)); + sbuf_printf(sb, "%s", indent); + if (sc->sc_provider != NULL && sc->sc_provider->error == 0) + sbuf_printf(sb, "UP"); + else + sbuf_printf(sb, "DOWN"); + sbuf_printf(sb, "\n"); } - sbuf_printf(sb, "%s", indent); - LIST_FOREACH(cp, &gp->consumer, consumer) { - if (cp->provider == NULL) - continue; - sbuf_printf(sb, "%s", cp->provider->name); - if (LIST_NEXT(cp, consumer) != NULL) - sbuf_printf(sb, " "); - } - sbuf_printf(sb, "\n"); - sbuf_printf(sb, "%stotal=%u, online=%u\n", indent, - sc->sc_ndisks, g_stripe_nvalid(sc)); - if (pp->error == 0) - sbuf_printf(sb, "%sUP\n", indent); - else - sbuf_printf(sb, "%sDOWN\n", indent); } DECLARE_GEOM_CLASS(g_stripe_class, g_stripe);