2 * Copyright (c) 2004-2005 Pawel Jakub Dawidek <pjd@FreeBSD.org>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 #include <sys/cdefs.h>
28 __FBSDID("$FreeBSD$");
30 #include <sys/param.h>
31 #include <sys/systm.h>
32 #include <sys/kernel.h>
33 #include <sys/module.h>
35 #include <sys/mutex.h>
38 #include <sys/sysctl.h>
39 #include <sys/malloc.h>
40 #include <geom/geom.h>
41 #include <geom/concat/g_concat.h>
43 FEATURE(geom_concat, "GEOM concatenation support");
45 static MALLOC_DEFINE(M_CONCAT, "concat_data", "GEOM_CONCAT Data");
47 SYSCTL_DECL(_kern_geom);
48 static SYSCTL_NODE(_kern_geom, OID_AUTO, concat, CTLFLAG_RW, 0,
50 static u_int g_concat_debug = 0;
51 TUNABLE_INT("kern.geom.concat.debug", &g_concat_debug);
52 SYSCTL_UINT(_kern_geom_concat, OID_AUTO, debug, CTLFLAG_RW, &g_concat_debug, 0,
55 static int g_concat_destroy(struct g_concat_softc *sc, boolean_t force);
56 static int g_concat_destroy_geom(struct gctl_req *req, struct g_class *mp,
59 static g_taste_t g_concat_taste;
60 static g_ctl_req_t g_concat_config;
61 static g_dumpconf_t g_concat_dumpconf;
63 struct g_class g_concat_class = {
64 .name = G_CONCAT_CLASS_NAME,
66 .ctlreq = g_concat_config,
67 .taste = g_concat_taste,
68 .destroy_geom = g_concat_destroy_geom
73 * Greatest Common Divisor.
89 * Least Common Multiple.
95 return ((a * b) / gcd(a, b));
99 * Return the number of valid disks.
102 g_concat_nvalid(struct g_concat_softc *sc)
107 for (i = 0; i < sc->sc_ndisks; i++) {
108 if (sc->sc_disks[i].d_consumer != NULL)
116 g_concat_remove_disk(struct g_concat_disk *disk)
118 struct g_consumer *cp;
119 struct g_concat_softc *sc;
122 KASSERT(disk->d_consumer != NULL, ("Non-valid disk in %s.", __func__));
124 cp = disk->d_consumer;
126 if (!disk->d_removed) {
127 G_CONCAT_DEBUG(0, "Disk %s removed from %s.",
128 cp->provider->name, sc->sc_name);
132 if (sc->sc_provider != NULL) {
133 sc->sc_provider->flags |= G_PF_WITHER;
134 G_CONCAT_DEBUG(0, "Device %s deactivated.",
135 sc->sc_provider->name);
136 g_orphan_provider(sc->sc_provider, ENXIO);
137 sc->sc_provider = NULL;
140 if (cp->acr > 0 || cp->acw > 0 || cp->ace > 0)
142 disk->d_consumer = NULL;
144 g_destroy_consumer(cp);
145 /* If there are no valid disks anymore, remove device. */
146 if (LIST_EMPTY(&sc->sc_geom->consumer))
147 g_concat_destroy(sc, 1);
151 g_concat_orphan(struct g_consumer *cp)
153 struct g_concat_softc *sc;
154 struct g_concat_disk *disk;
164 if (disk == NULL) /* Possible? */
166 g_concat_remove_disk(disk);
170 g_concat_access(struct g_provider *pp, int dr, int dw, int de)
172 struct g_consumer *cp1, *cp2, *tmp;
173 struct g_concat_disk *disk;
180 /* On first open, grab an extra "exclusive" bit */
181 if (pp->acr == 0 && pp->acw == 0 && pp->ace == 0)
183 /* ... and let go of it on last close */
184 if ((pp->acr + dr) == 0 && (pp->acw + dw) == 0 && (pp->ace + de) == 0)
187 LIST_FOREACH_SAFE(cp1, &gp->consumer, consumer, tmp) {
188 error = g_access(cp1, dr, dw, de);
192 if (cp1->acr == 0 && cp1->acw == 0 && cp1->ace == 0 &&
194 g_concat_remove_disk(disk); /* May destroy geom. */
200 LIST_FOREACH(cp2, &gp->consumer, consumer) {
203 g_access(cp2, -dr, -dw, -de);
209 g_concat_kernel_dump(struct bio *bp)
211 struct g_concat_softc *sc;
212 struct g_concat_disk *disk;
214 struct g_kerneldump *gkd;
217 sc = bp->bio_to->geom->softc;
218 gkd = (struct g_kerneldump *)bp->bio_data;
219 for (i = 0; i < sc->sc_ndisks; i++) {
220 if (sc->sc_disks[i].d_start <= gkd->offset &&
221 sc->sc_disks[i].d_end > gkd->offset)
224 if (i == sc->sc_ndisks)
225 g_io_deliver(bp, EOPNOTSUPP);
226 disk = &sc->sc_disks[i];
227 gkd->offset -= disk->d_start;
228 if (gkd->length > disk->d_end - disk->d_start - gkd->offset)
229 gkd->length = disk->d_end - disk->d_start - gkd->offset;
230 cbp = g_clone_bio(bp);
232 g_io_deliver(bp, ENOMEM);
235 cbp->bio_done = g_std_done;
236 g_io_request(cbp, disk->d_consumer);
237 G_CONCAT_DEBUG(1, "Kernel dump will go to %s.",
238 disk->d_consumer->provider->name);
242 g_concat_done(struct bio *bp)
244 struct g_concat_softc *sc;
247 pbp = bp->bio_parent;
248 sc = pbp->bio_to->geom->softc;
249 mtx_lock(&sc->sc_lock);
250 if (pbp->bio_error == 0)
251 pbp->bio_error = bp->bio_error;
252 pbp->bio_completed += bp->bio_completed;
254 if (pbp->bio_children == pbp->bio_inbed) {
255 mtx_unlock(&sc->sc_lock);
256 g_io_deliver(pbp, pbp->bio_error);
258 mtx_unlock(&sc->sc_lock);
263 g_concat_flush(struct g_concat_softc *sc, struct bio *bp)
265 struct bio_queue_head queue;
266 struct g_consumer *cp;
271 for (no = 0; no < sc->sc_ndisks; no++) {
272 cbp = g_clone_bio(bp);
274 while ((cbp = bioq_takefirst(&queue)) != NULL)
276 if (bp->bio_error == 0)
277 bp->bio_error = ENOMEM;
278 g_io_deliver(bp, bp->bio_error);
281 bioq_insert_tail(&queue, cbp);
282 cbp->bio_done = g_concat_done;
283 cbp->bio_caller1 = sc->sc_disks[no].d_consumer;
284 cbp->bio_to = sc->sc_disks[no].d_consumer->provider;
286 while ((cbp = bioq_takefirst(&queue)) != NULL) {
287 G_CONCAT_LOGREQ(cbp, "Sending request.");
288 cp = cbp->bio_caller1;
289 cbp->bio_caller1 = NULL;
290 g_io_request(cbp, cp);
295 g_concat_start(struct bio *bp)
297 struct bio_queue_head queue;
298 struct g_concat_softc *sc;
299 struct g_concat_disk *disk;
300 struct g_provider *pp;
301 off_t offset, end, length, off, len;
307 sc = pp->geom->softc;
309 * If sc == NULL, provider's error should be set and g_concat_start()
310 * should not be called at all.
313 ("Provider's error should be set (error=%d)(device=%s).",
314 bp->bio_to->error, bp->bio_to->name));
316 G_CONCAT_LOGREQ(bp, "Request received.");
318 switch (bp->bio_cmd) {
324 g_concat_flush(sc, bp);
327 if (strcmp("GEOM::kerneldump", bp->bio_attribute) == 0) {
328 g_concat_kernel_dump(bp);
331 /* To which provider it should be delivered? */
334 g_io_deliver(bp, EOPNOTSUPP);
338 offset = bp->bio_offset;
339 length = bp->bio_length;
340 if ((bp->bio_flags & BIO_UNMAPPED) != 0)
344 end = offset + length;
347 for (no = 0; no < sc->sc_ndisks; no++) {
348 disk = &sc->sc_disks[no];
349 if (disk->d_end <= offset)
351 if (disk->d_start >= end)
354 off = offset - disk->d_start;
355 len = MIN(length, disk->d_end - offset);
359 cbp = g_clone_bio(bp);
361 while ((cbp = bioq_takefirst(&queue)) != NULL)
363 if (bp->bio_error == 0)
364 bp->bio_error = ENOMEM;
365 g_io_deliver(bp, bp->bio_error);
368 bioq_insert_tail(&queue, cbp);
370 * Fill in the component buf structure.
372 if (len == bp->bio_length)
373 cbp->bio_done = g_std_done;
375 cbp->bio_done = g_concat_done;
376 cbp->bio_offset = off;
377 cbp->bio_length = len;
378 if ((bp->bio_flags & BIO_UNMAPPED) != 0) {
379 cbp->bio_ma_offset += (uintptr_t)addr;
380 cbp->bio_ma += cbp->bio_ma_offset / PAGE_SIZE;
381 cbp->bio_ma_offset %= PAGE_SIZE;
382 cbp->bio_ma_n = round_page(cbp->bio_ma_offset +
383 cbp->bio_length) / PAGE_SIZE;
385 cbp->bio_data = addr;
387 cbp->bio_to = disk->d_consumer->provider;
388 cbp->bio_caller1 = disk;
394 ("Length is still greater than 0 (class=%s, name=%s).",
395 bp->bio_to->geom->class->name, bp->bio_to->geom->name));
396 while ((cbp = bioq_takefirst(&queue)) != NULL) {
397 G_CONCAT_LOGREQ(cbp, "Sending request.");
398 disk = cbp->bio_caller1;
399 cbp->bio_caller1 = NULL;
400 g_io_request(cbp, disk->d_consumer);
405 g_concat_check_and_run(struct g_concat_softc *sc)
407 struct g_concat_disk *disk;
408 struct g_provider *dp, *pp;
409 u_int no, sectorsize = 0;
413 if (g_concat_nvalid(sc) != sc->sc_ndisks)
416 pp = g_new_providerf(sc->sc_geom, "concat/%s", sc->sc_name);
417 pp->flags |= G_PF_DIRECT_SEND | G_PF_DIRECT_RECEIVE |
418 G_PF_ACCEPT_UNMAPPED;
420 for (no = 0; no < sc->sc_ndisks; no++) {
421 disk = &sc->sc_disks[no];
422 dp = disk->d_consumer->provider;
423 disk->d_start = start;
424 disk->d_end = disk->d_start + dp->mediasize;
425 if (sc->sc_type == G_CONCAT_TYPE_AUTOMATIC)
426 disk->d_end -= dp->sectorsize;
429 sectorsize = dp->sectorsize;
431 sectorsize = lcm(sectorsize, dp->sectorsize);
433 /* A provider underneath us doesn't support unmapped */
434 if ((dp->flags & G_PF_ACCEPT_UNMAPPED) == 0) {
435 G_CONCAT_DEBUG(1, "Cancelling unmapped "
436 "because of %s.", dp->name);
437 pp->flags &= ~G_PF_ACCEPT_UNMAPPED;
440 pp->sectorsize = sectorsize;
441 /* We have sc->sc_disks[sc->sc_ndisks - 1].d_end in 'start'. */
442 pp->mediasize = start;
443 pp->stripesize = sc->sc_disks[0].d_consumer->provider->stripesize;
444 pp->stripeoffset = sc->sc_disks[0].d_consumer->provider->stripeoffset;
445 sc->sc_provider = pp;
446 g_error_provider(pp, 0);
448 G_CONCAT_DEBUG(0, "Device %s activated.", sc->sc_provider->name);
452 g_concat_read_metadata(struct g_consumer *cp, struct g_concat_metadata *md)
454 struct g_provider *pp;
460 error = g_access(cp, 1, 0, 0);
465 buf = g_read_data(cp, pp->mediasize - pp->sectorsize, pp->sectorsize,
468 g_access(cp, -1, 0, 0);
472 /* Decode metadata. */
473 concat_metadata_decode(buf, md);
480 * Add disk to given device.
483 g_concat_add_disk(struct g_concat_softc *sc, struct g_provider *pp, u_int no)
485 struct g_concat_disk *disk;
486 struct g_consumer *cp, *fcp;
491 /* Metadata corrupted? */
492 if (no >= sc->sc_ndisks)
495 disk = &sc->sc_disks[no];
496 /* Check if disk is not already attached. */
497 if (disk->d_consumer != NULL)
501 fcp = LIST_FIRST(&gp->consumer);
503 cp = g_new_consumer(gp);
504 cp->flags |= G_CF_DIRECT_SEND | G_CF_DIRECT_RECEIVE;
505 error = g_attach(cp, pp);
507 g_destroy_consumer(cp);
511 if (fcp != NULL && (fcp->acr > 0 || fcp->acw > 0 || fcp->ace > 0)) {
512 error = g_access(cp, fcp->acr, fcp->acw, fcp->ace);
515 g_destroy_consumer(cp);
519 if (sc->sc_type == G_CONCAT_TYPE_AUTOMATIC) {
520 struct g_concat_metadata md;
522 /* Re-read metadata. */
523 error = g_concat_read_metadata(cp, &md);
527 if (strcmp(md.md_magic, G_CONCAT_MAGIC) != 0 ||
528 strcmp(md.md_name, sc->sc_name) != 0 ||
529 md.md_id != sc->sc_id) {
530 G_CONCAT_DEBUG(0, "Metadata on %s changed.", pp->name);
536 disk->d_consumer = cp;
538 disk->d_start = 0; /* not yet */
539 disk->d_end = 0; /* not yet */
542 G_CONCAT_DEBUG(0, "Disk %s attached to %s.", pp->name, sc->sc_name);
544 g_concat_check_and_run(sc);
548 if (fcp != NULL && (fcp->acr > 0 || fcp->acw > 0 || fcp->ace > 0))
549 g_access(cp, -fcp->acr, -fcp->acw, -fcp->ace);
551 g_destroy_consumer(cp);
555 static struct g_geom *
556 g_concat_create(struct g_class *mp, const struct g_concat_metadata *md,
559 struct g_concat_softc *sc;
563 G_CONCAT_DEBUG(1, "Creating device %s (id=%u).", md->md_name,
566 /* One disks is minimum. */
570 /* Check for duplicate unit */
571 LIST_FOREACH(gp, &mp->geom, geom) {
573 if (sc != NULL && strcmp(sc->sc_name, md->md_name) == 0) {
574 G_CONCAT_DEBUG(0, "Device %s already configured.",
579 gp = g_new_geomf(mp, "%s", md->md_name);
580 sc = malloc(sizeof(*sc), M_CONCAT, M_WAITOK | M_ZERO);
581 gp->start = g_concat_start;
582 gp->spoiled = g_concat_orphan;
583 gp->orphan = g_concat_orphan;
584 gp->access = g_concat_access;
585 gp->dumpconf = g_concat_dumpconf;
587 sc->sc_id = md->md_id;
588 sc->sc_ndisks = md->md_all;
589 sc->sc_disks = malloc(sizeof(struct g_concat_disk) * sc->sc_ndisks,
590 M_CONCAT, M_WAITOK | M_ZERO);
591 for (no = 0; no < sc->sc_ndisks; no++)
592 sc->sc_disks[no].d_consumer = NULL;
594 mtx_init(&sc->sc_lock, "gconcat lock", NULL, MTX_DEF);
598 sc->sc_provider = NULL;
600 G_CONCAT_DEBUG(0, "Device %s created (id=%u).", sc->sc_name, sc->sc_id);
606 g_concat_destroy(struct g_concat_softc *sc, boolean_t force)
608 struct g_provider *pp;
609 struct g_consumer *cp, *cp1;
617 pp = sc->sc_provider;
618 if (pp != NULL && (pp->acr != 0 || pp->acw != 0 || pp->ace != 0)) {
620 G_CONCAT_DEBUG(0, "Device %s is still open, so it "
621 "can't be definitely removed.", pp->name);
624 "Device %s is still open (r%dw%de%d).", pp->name,
625 pp->acr, pp->acw, pp->ace);
631 LIST_FOREACH_SAFE(cp, &gp->consumer, consumer, cp1) {
632 g_concat_remove_disk(cp->private);
634 return (0); /* Recursion happened. */
636 if (!LIST_EMPTY(&gp->consumer))
637 return (EINPROGRESS);
640 KASSERT(sc->sc_provider == NULL, ("Provider still exists? (device=%s)",
642 free(sc->sc_disks, M_CONCAT);
643 mtx_destroy(&sc->sc_lock);
646 G_CONCAT_DEBUG(0, "Device %s destroyed.", gp->name);
647 g_wither_geom(gp, ENXIO);
652 g_concat_destroy_geom(struct gctl_req *req __unused,
653 struct g_class *mp __unused, struct g_geom *gp)
655 struct g_concat_softc *sc;
658 return (g_concat_destroy(sc, 0));
661 static struct g_geom *
662 g_concat_taste(struct g_class *mp, struct g_provider *pp, int flags __unused)
664 struct g_concat_metadata md;
665 struct g_concat_softc *sc;
666 struct g_consumer *cp;
670 g_trace(G_T_TOPOLOGY, "%s(%s, %s)", __func__, mp->name, pp->name);
673 /* Skip providers that are already open for writing. */
677 G_CONCAT_DEBUG(3, "Tasting %s.", pp->name);
679 gp = g_new_geomf(mp, "concat:taste");
680 gp->start = g_concat_start;
681 gp->access = g_concat_access;
682 gp->orphan = g_concat_orphan;
683 cp = g_new_consumer(gp);
685 error = g_concat_read_metadata(cp, &md);
687 g_destroy_consumer(cp);
693 if (strcmp(md.md_magic, G_CONCAT_MAGIC) != 0)
695 if (md.md_version > G_CONCAT_VERSION) {
696 printf("geom_concat.ko module is too old to handle %s.\n",
701 * Backward compatibility:
703 /* There was no md_provider field in earlier versions of metadata. */
704 if (md.md_version < 3)
705 bzero(md.md_provider, sizeof(md.md_provider));
706 /* There was no md_provsize field in earlier versions of metadata. */
707 if (md.md_version < 4)
708 md.md_provsize = pp->mediasize;
710 if (md.md_provider[0] != '\0' &&
711 !g_compare_names(md.md_provider, pp->name))
713 if (md.md_provsize != pp->mediasize)
717 * Let's check if device already exists.
720 LIST_FOREACH(gp, &mp->geom, geom) {
724 if (sc->sc_type != G_CONCAT_TYPE_AUTOMATIC)
726 if (strcmp(md.md_name, sc->sc_name) != 0)
728 if (md.md_id != sc->sc_id)
733 G_CONCAT_DEBUG(1, "Adding disk %s to %s.", pp->name, gp->name);
734 error = g_concat_add_disk(sc, pp, md.md_no);
737 "Cannot add disk %s to %s (error=%d).", pp->name,
742 gp = g_concat_create(mp, &md, G_CONCAT_TYPE_AUTOMATIC);
744 G_CONCAT_DEBUG(0, "Cannot create device %s.",
749 G_CONCAT_DEBUG(1, "Adding disk %s to %s.", pp->name, gp->name);
750 error = g_concat_add_disk(sc, pp, md.md_no);
753 "Cannot add disk %s to %s (error=%d).", pp->name,
755 g_concat_destroy(sc, 1);
764 g_concat_ctl_create(struct gctl_req *req, struct g_class *mp)
767 struct g_concat_metadata md;
768 struct g_provider *pp;
769 struct g_concat_softc *sc;
777 nargs = gctl_get_paraml(req, "nargs", sizeof(*nargs));
779 gctl_error(req, "No '%s' argument.", "nargs");
783 gctl_error(req, "Too few arguments.");
787 strlcpy(md.md_magic, G_CONCAT_MAGIC, sizeof(md.md_magic));
788 md.md_version = G_CONCAT_VERSION;
789 name = gctl_get_asciiparam(req, "arg0");
791 gctl_error(req, "No 'arg%u' argument.", 0);
794 strlcpy(md.md_name, name, sizeof(md.md_name));
795 md.md_id = arc4random();
797 md.md_all = *nargs - 1;
798 bzero(md.md_provider, sizeof(md.md_provider));
799 /* This field is not important here. */
802 /* Check all providers are valid */
803 for (no = 1; no < *nargs; no++) {
804 snprintf(param, sizeof(param), "arg%u", no);
805 name = gctl_get_asciiparam(req, param);
807 gctl_error(req, "No 'arg%u' argument.", no);
810 if (strncmp(name, "/dev/", strlen("/dev/")) == 0)
811 name += strlen("/dev/");
812 pp = g_provider_by_name(name);
814 G_CONCAT_DEBUG(1, "Disk %s is invalid.", name);
815 gctl_error(req, "Disk %s is invalid.", name);
820 gp = g_concat_create(mp, &md, G_CONCAT_TYPE_MANUAL);
822 gctl_error(req, "Can't configure %s.", md.md_name);
827 sb = sbuf_new_auto();
828 sbuf_printf(sb, "Can't attach disk(s) to %s:", gp->name);
829 for (attached = 0, no = 1; no < *nargs; no++) {
830 snprintf(param, sizeof(param), "arg%u", no);
831 name = gctl_get_asciiparam(req, param);
833 gctl_error(req, "No 'arg%d' argument.", no);
836 if (strncmp(name, "/dev/", strlen("/dev/")) == 0)
837 name += strlen("/dev/");
838 pp = g_provider_by_name(name);
839 KASSERT(pp != NULL, ("Provider %s disappear?!", name));
840 if (g_concat_add_disk(sc, pp, no - 1) != 0) {
841 G_CONCAT_DEBUG(1, "Disk %u (%s) not attached to %s.",
842 no, pp->name, gp->name);
843 sbuf_printf(sb, " %s", pp->name);
849 if (md.md_all != attached) {
850 g_concat_destroy(gp->softc, 1);
851 gctl_error(req, "%s", sbuf_data(sb));
856 static struct g_concat_softc *
857 g_concat_find_device(struct g_class *mp, const char *name)
859 struct g_concat_softc *sc;
862 LIST_FOREACH(gp, &mp->geom, geom) {
866 if (strcmp(sc->sc_name, name) == 0)
873 g_concat_ctl_destroy(struct gctl_req *req, struct g_class *mp)
875 struct g_concat_softc *sc;
876 int *force, *nargs, error;
883 nargs = gctl_get_paraml(req, "nargs", sizeof(*nargs));
885 gctl_error(req, "No '%s' argument.", "nargs");
889 gctl_error(req, "Missing device(s).");
892 force = gctl_get_paraml(req, "force", sizeof(*force));
894 gctl_error(req, "No '%s' argument.", "force");
898 for (i = 0; i < (u_int)*nargs; i++) {
899 snprintf(param, sizeof(param), "arg%u", i);
900 name = gctl_get_asciiparam(req, param);
902 gctl_error(req, "No 'arg%u' argument.", i);
905 sc = g_concat_find_device(mp, name);
907 gctl_error(req, "No such device: %s.", name);
910 error = g_concat_destroy(sc, *force);
912 gctl_error(req, "Cannot destroy device %s (error=%d).",
920 g_concat_config(struct gctl_req *req, struct g_class *mp, const char *verb)
926 version = gctl_get_paraml(req, "version", sizeof(*version));
927 if (version == NULL) {
928 gctl_error(req, "No '%s' argument.", "version");
931 if (*version != G_CONCAT_VERSION) {
932 gctl_error(req, "Userland and kernel parts are out of sync.");
936 if (strcmp(verb, "create") == 0) {
937 g_concat_ctl_create(req, mp);
939 } else if (strcmp(verb, "destroy") == 0 ||
940 strcmp(verb, "stop") == 0) {
941 g_concat_ctl_destroy(req, mp);
944 gctl_error(req, "Unknown verb.");
948 g_concat_dumpconf(struct sbuf *sb, const char *indent, struct g_geom *gp,
949 struct g_consumer *cp, struct g_provider *pp)
951 struct g_concat_softc *sc;
959 } else if (cp != NULL) {
960 struct g_concat_disk *disk;
965 sbuf_printf(sb, "%s<End>%jd</End>\n", indent,
966 (intmax_t)disk->d_end);
967 sbuf_printf(sb, "%s<Start>%jd</Start>\n", indent,
968 (intmax_t)disk->d_start);
970 sbuf_printf(sb, "%s<ID>%u</ID>\n", indent, (u_int)sc->sc_id);
971 sbuf_printf(sb, "%s<Type>", indent);
972 switch (sc->sc_type) {
973 case G_CONCAT_TYPE_AUTOMATIC:
974 sbuf_printf(sb, "AUTOMATIC");
976 case G_CONCAT_TYPE_MANUAL:
977 sbuf_printf(sb, "MANUAL");
980 sbuf_printf(sb, "UNKNOWN");
983 sbuf_printf(sb, "</Type>\n");
984 sbuf_printf(sb, "%s<Status>Total=%u, Online=%u</Status>\n",
985 indent, sc->sc_ndisks, g_concat_nvalid(sc));
986 sbuf_printf(sb, "%s<State>", indent);
987 if (sc->sc_provider != NULL && sc->sc_provider->error == 0)
988 sbuf_printf(sb, "UP");
990 sbuf_printf(sb, "DOWN");
991 sbuf_printf(sb, "</State>\n");
995 DECLARE_GEOM_CLASS(g_concat_class, g_concat);