2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Copyright (c) 2004-2005 Pawel Jakub Dawidek <pjd@FreeBSD.org>
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 #include <sys/cdefs.h>
30 __FBSDID("$FreeBSD$");
32 #include <sys/param.h>
33 #include <sys/systm.h>
34 #include <sys/kernel.h>
35 #include <sys/module.h>
37 #include <sys/mutex.h>
40 #include <sys/sysctl.h>
41 #include <sys/malloc.h>
42 #include <geom/geom.h>
43 #include <geom/concat/g_concat.h>
45 FEATURE(geom_concat, "GEOM concatenation support");
47 static MALLOC_DEFINE(M_CONCAT, "concat_data", "GEOM_CONCAT Data");
49 SYSCTL_DECL(_kern_geom);
50 static SYSCTL_NODE(_kern_geom, OID_AUTO, concat, CTLFLAG_RW, 0,
52 static u_int g_concat_debug = 0;
53 SYSCTL_UINT(_kern_geom_concat, OID_AUTO, debug, CTLFLAG_RWTUN, &g_concat_debug, 0,
56 static int g_concat_destroy(struct g_concat_softc *sc, boolean_t force);
57 static int g_concat_destroy_geom(struct gctl_req *req, struct g_class *mp,
60 static g_taste_t g_concat_taste;
61 static g_ctl_req_t g_concat_config;
62 static g_dumpconf_t g_concat_dumpconf;
64 struct g_class g_concat_class = {
65 .name = G_CONCAT_CLASS_NAME,
67 .ctlreq = g_concat_config,
68 .taste = g_concat_taste,
69 .destroy_geom = g_concat_destroy_geom
74 * Greatest Common Divisor.
90 * Least Common Multiple.
96 return ((a * b) / gcd(a, b));
100 * Return the number of valid disks.
103 g_concat_nvalid(struct g_concat_softc *sc)
108 for (i = 0; i < sc->sc_ndisks; i++) {
109 if (sc->sc_disks[i].d_consumer != NULL)
117 g_concat_remove_disk(struct g_concat_disk *disk)
119 struct g_consumer *cp;
120 struct g_concat_softc *sc;
123 KASSERT(disk->d_consumer != NULL, ("Non-valid disk in %s.", __func__));
125 cp = disk->d_consumer;
127 if (!disk->d_removed) {
128 G_CONCAT_DEBUG(0, "Disk %s removed from %s.",
129 cp->provider->name, sc->sc_name);
133 if (sc->sc_provider != NULL) {
134 G_CONCAT_DEBUG(0, "Device %s deactivated.",
135 sc->sc_provider->name);
136 g_wither_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_candelete(struct bio *bp)
211 struct g_concat_softc *sc;
212 struct g_concat_disk *disk;
215 val = (int *)bp->bio_data;
218 sc = bp->bio_to->geom->softc;
219 for (i = 0; i < sc->sc_ndisks; i++) {
220 disk = &sc->sc_disks[i];
221 if (!disk->d_removed && disk->d_candelete) {
230 g_concat_kernel_dump(struct bio *bp)
232 struct g_concat_softc *sc;
233 struct g_concat_disk *disk;
235 struct g_kerneldump *gkd;
238 sc = bp->bio_to->geom->softc;
239 gkd = (struct g_kerneldump *)bp->bio_data;
240 for (i = 0; i < sc->sc_ndisks; i++) {
241 if (sc->sc_disks[i].d_start <= gkd->offset &&
242 sc->sc_disks[i].d_end > gkd->offset)
245 if (i == sc->sc_ndisks)
246 g_io_deliver(bp, EOPNOTSUPP);
247 disk = &sc->sc_disks[i];
248 gkd->offset -= disk->d_start;
249 if (gkd->length > disk->d_end - disk->d_start - gkd->offset)
250 gkd->length = disk->d_end - disk->d_start - gkd->offset;
251 cbp = g_clone_bio(bp);
253 g_io_deliver(bp, ENOMEM);
256 cbp->bio_done = g_std_done;
257 g_io_request(cbp, disk->d_consumer);
258 G_CONCAT_DEBUG(1, "Kernel dump will go to %s.",
259 disk->d_consumer->provider->name);
263 g_concat_done(struct bio *bp)
265 struct g_concat_softc *sc;
268 pbp = bp->bio_parent;
269 sc = pbp->bio_to->geom->softc;
270 mtx_lock(&sc->sc_lock);
271 if (pbp->bio_error == 0)
272 pbp->bio_error = bp->bio_error;
273 pbp->bio_completed += bp->bio_completed;
275 if (pbp->bio_children == pbp->bio_inbed) {
276 mtx_unlock(&sc->sc_lock);
277 g_io_deliver(pbp, pbp->bio_error);
279 mtx_unlock(&sc->sc_lock);
284 g_concat_flush(struct g_concat_softc *sc, struct bio *bp)
286 struct bio_queue_head queue;
287 struct g_consumer *cp;
292 for (no = 0; no < sc->sc_ndisks; no++) {
293 cbp = g_clone_bio(bp);
295 while ((cbp = bioq_takefirst(&queue)) != NULL)
297 if (bp->bio_error == 0)
298 bp->bio_error = ENOMEM;
299 g_io_deliver(bp, bp->bio_error);
302 bioq_insert_tail(&queue, cbp);
303 cbp->bio_done = g_concat_done;
304 cbp->bio_caller1 = sc->sc_disks[no].d_consumer;
305 cbp->bio_to = sc->sc_disks[no].d_consumer->provider;
307 while ((cbp = bioq_takefirst(&queue)) != NULL) {
308 G_CONCAT_LOGREQ(cbp, "Sending request.");
309 cp = cbp->bio_caller1;
310 cbp->bio_caller1 = NULL;
311 g_io_request(cbp, cp);
316 g_concat_start(struct bio *bp)
318 struct bio_queue_head queue;
319 struct g_concat_softc *sc;
320 struct g_concat_disk *disk;
321 struct g_provider *pp;
322 off_t offset, end, length, off, len;
328 sc = pp->geom->softc;
330 * If sc == NULL, provider's error should be set and g_concat_start()
331 * should not be called at all.
334 ("Provider's error should be set (error=%d)(device=%s).",
335 bp->bio_to->error, bp->bio_to->name));
337 G_CONCAT_LOGREQ(bp, "Request received.");
339 switch (bp->bio_cmd) {
345 g_concat_flush(sc, bp);
348 if (strcmp("GEOM::kerneldump", bp->bio_attribute) == 0) {
349 g_concat_kernel_dump(bp);
351 } else if (strcmp("GEOM::candelete", bp->bio_attribute) == 0) {
352 g_concat_candelete(bp);
355 /* To which provider it should be delivered? */
358 g_io_deliver(bp, EOPNOTSUPP);
362 offset = bp->bio_offset;
363 length = bp->bio_length;
364 if ((bp->bio_flags & BIO_UNMAPPED) != 0)
368 end = offset + length;
371 for (no = 0; no < sc->sc_ndisks; no++) {
372 disk = &sc->sc_disks[no];
373 if (disk->d_end <= offset)
375 if (disk->d_start >= end)
378 off = offset - disk->d_start;
379 len = MIN(length, disk->d_end - offset);
383 cbp = g_clone_bio(bp);
385 while ((cbp = bioq_takefirst(&queue)) != NULL)
387 if (bp->bio_error == 0)
388 bp->bio_error = ENOMEM;
389 g_io_deliver(bp, bp->bio_error);
392 bioq_insert_tail(&queue, cbp);
394 * Fill in the component buf structure.
396 if (len == bp->bio_length)
397 cbp->bio_done = g_std_done;
399 cbp->bio_done = g_concat_done;
400 cbp->bio_offset = off;
401 cbp->bio_length = len;
402 if ((bp->bio_flags & BIO_UNMAPPED) != 0) {
403 cbp->bio_ma_offset += (uintptr_t)addr;
404 cbp->bio_ma += cbp->bio_ma_offset / PAGE_SIZE;
405 cbp->bio_ma_offset %= PAGE_SIZE;
406 cbp->bio_ma_n = round_page(cbp->bio_ma_offset +
407 cbp->bio_length) / PAGE_SIZE;
409 cbp->bio_data = addr;
411 cbp->bio_to = disk->d_consumer->provider;
412 cbp->bio_caller1 = disk;
418 ("Length is still greater than 0 (class=%s, name=%s).",
419 bp->bio_to->geom->class->name, bp->bio_to->geom->name));
420 while ((cbp = bioq_takefirst(&queue)) != NULL) {
421 G_CONCAT_LOGREQ(cbp, "Sending request.");
422 disk = cbp->bio_caller1;
423 cbp->bio_caller1 = NULL;
424 g_io_request(cbp, disk->d_consumer);
429 g_concat_check_and_run(struct g_concat_softc *sc)
431 struct g_concat_disk *disk;
432 struct g_provider *dp, *pp;
433 u_int no, sectorsize = 0;
438 if (g_concat_nvalid(sc) != sc->sc_ndisks)
441 pp = g_new_providerf(sc->sc_geom, "concat/%s", sc->sc_name);
442 pp->flags |= G_PF_DIRECT_SEND | G_PF_DIRECT_RECEIVE |
443 G_PF_ACCEPT_UNMAPPED;
445 for (no = 0; no < sc->sc_ndisks; no++) {
446 disk = &sc->sc_disks[no];
447 dp = disk->d_consumer->provider;
448 disk->d_start = start;
449 disk->d_end = disk->d_start + dp->mediasize;
450 if (sc->sc_type == G_CONCAT_TYPE_AUTOMATIC)
451 disk->d_end -= dp->sectorsize;
453 error = g_access(disk->d_consumer, 1, 0, 0);
455 error = g_getattr("GEOM::candelete", disk->d_consumer,
458 disk->d_candelete = 0;
459 (void)g_access(disk->d_consumer, -1, 0, 0);
461 G_CONCAT_DEBUG(1, "Failed to access disk %s, error %d.",
464 sectorsize = dp->sectorsize;
466 sectorsize = lcm(sectorsize, dp->sectorsize);
468 /* A provider underneath us doesn't support unmapped */
469 if ((dp->flags & G_PF_ACCEPT_UNMAPPED) == 0) {
470 G_CONCAT_DEBUG(1, "Cancelling unmapped "
471 "because of %s.", dp->name);
472 pp->flags &= ~G_PF_ACCEPT_UNMAPPED;
475 pp->sectorsize = sectorsize;
476 /* We have sc->sc_disks[sc->sc_ndisks - 1].d_end in 'start'. */
477 pp->mediasize = start;
478 pp->stripesize = sc->sc_disks[0].d_consumer->provider->stripesize;
479 pp->stripeoffset = sc->sc_disks[0].d_consumer->provider->stripeoffset;
480 sc->sc_provider = pp;
481 g_error_provider(pp, 0);
483 G_CONCAT_DEBUG(0, "Device %s activated.", sc->sc_provider->name);
487 g_concat_read_metadata(struct g_consumer *cp, struct g_concat_metadata *md)
489 struct g_provider *pp;
495 error = g_access(cp, 1, 0, 0);
500 buf = g_read_data(cp, pp->mediasize - pp->sectorsize, pp->sectorsize,
503 g_access(cp, -1, 0, 0);
507 /* Decode metadata. */
508 concat_metadata_decode(buf, md);
515 * Add disk to given device.
518 g_concat_add_disk(struct g_concat_softc *sc, struct g_provider *pp, u_int no)
520 struct g_concat_disk *disk;
521 struct g_consumer *cp, *fcp;
526 /* Metadata corrupted? */
527 if (no >= sc->sc_ndisks)
530 disk = &sc->sc_disks[no];
531 /* Check if disk is not already attached. */
532 if (disk->d_consumer != NULL)
536 fcp = LIST_FIRST(&gp->consumer);
538 cp = g_new_consumer(gp);
539 cp->flags |= G_CF_DIRECT_SEND | G_CF_DIRECT_RECEIVE;
540 error = g_attach(cp, pp);
542 g_destroy_consumer(cp);
546 if (fcp != NULL && (fcp->acr > 0 || fcp->acw > 0 || fcp->ace > 0)) {
547 error = g_access(cp, fcp->acr, fcp->acw, fcp->ace);
550 g_destroy_consumer(cp);
554 if (sc->sc_type == G_CONCAT_TYPE_AUTOMATIC) {
555 struct g_concat_metadata md;
557 /* Re-read metadata. */
558 error = g_concat_read_metadata(cp, &md);
562 if (strcmp(md.md_magic, G_CONCAT_MAGIC) != 0 ||
563 strcmp(md.md_name, sc->sc_name) != 0 ||
564 md.md_id != sc->sc_id) {
565 G_CONCAT_DEBUG(0, "Metadata on %s changed.", pp->name);
571 disk->d_consumer = cp;
573 disk->d_start = 0; /* not yet */
574 disk->d_end = 0; /* not yet */
577 G_CONCAT_DEBUG(0, "Disk %s attached to %s.", pp->name, sc->sc_name);
579 g_concat_check_and_run(sc);
583 if (fcp != NULL && (fcp->acr > 0 || fcp->acw > 0 || fcp->ace > 0))
584 g_access(cp, -fcp->acr, -fcp->acw, -fcp->ace);
586 g_destroy_consumer(cp);
590 static struct g_geom *
591 g_concat_create(struct g_class *mp, const struct g_concat_metadata *md,
594 struct g_concat_softc *sc;
598 G_CONCAT_DEBUG(1, "Creating device %s (id=%u).", md->md_name,
601 /* One disks is minimum. */
605 /* Check for duplicate unit */
606 LIST_FOREACH(gp, &mp->geom, geom) {
608 if (sc != NULL && strcmp(sc->sc_name, md->md_name) == 0) {
609 G_CONCAT_DEBUG(0, "Device %s already configured.",
614 gp = g_new_geomf(mp, "%s", md->md_name);
615 sc = malloc(sizeof(*sc), M_CONCAT, M_WAITOK | M_ZERO);
616 gp->start = g_concat_start;
617 gp->spoiled = g_concat_orphan;
618 gp->orphan = g_concat_orphan;
619 gp->access = g_concat_access;
620 gp->dumpconf = g_concat_dumpconf;
622 sc->sc_id = md->md_id;
623 sc->sc_ndisks = md->md_all;
624 sc->sc_disks = malloc(sizeof(struct g_concat_disk) * sc->sc_ndisks,
625 M_CONCAT, M_WAITOK | M_ZERO);
626 for (no = 0; no < sc->sc_ndisks; no++)
627 sc->sc_disks[no].d_consumer = NULL;
629 mtx_init(&sc->sc_lock, "gconcat lock", NULL, MTX_DEF);
633 sc->sc_provider = NULL;
635 G_CONCAT_DEBUG(0, "Device %s created (id=%u).", sc->sc_name, sc->sc_id);
641 g_concat_destroy(struct g_concat_softc *sc, boolean_t force)
643 struct g_provider *pp;
644 struct g_consumer *cp, *cp1;
652 pp = sc->sc_provider;
653 if (pp != NULL && (pp->acr != 0 || pp->acw != 0 || pp->ace != 0)) {
655 G_CONCAT_DEBUG(0, "Device %s is still open, so it "
656 "can't be definitely removed.", pp->name);
659 "Device %s is still open (r%dw%de%d).", pp->name,
660 pp->acr, pp->acw, pp->ace);
666 LIST_FOREACH_SAFE(cp, &gp->consumer, consumer, cp1) {
667 g_concat_remove_disk(cp->private);
669 return (0); /* Recursion happened. */
671 if (!LIST_EMPTY(&gp->consumer))
672 return (EINPROGRESS);
675 KASSERT(sc->sc_provider == NULL, ("Provider still exists? (device=%s)",
677 free(sc->sc_disks, M_CONCAT);
678 mtx_destroy(&sc->sc_lock);
681 G_CONCAT_DEBUG(0, "Device %s destroyed.", gp->name);
682 g_wither_geom(gp, ENXIO);
687 g_concat_destroy_geom(struct gctl_req *req __unused,
688 struct g_class *mp __unused, struct g_geom *gp)
690 struct g_concat_softc *sc;
693 return (g_concat_destroy(sc, 0));
696 static struct g_geom *
697 g_concat_taste(struct g_class *mp, struct g_provider *pp, int flags __unused)
699 struct g_concat_metadata md;
700 struct g_concat_softc *sc;
701 struct g_consumer *cp;
705 g_trace(G_T_TOPOLOGY, "%s(%s, %s)", __func__, mp->name, pp->name);
708 /* Skip providers that are already open for writing. */
712 G_CONCAT_DEBUG(3, "Tasting %s.", pp->name);
714 gp = g_new_geomf(mp, "concat:taste");
715 gp->start = g_concat_start;
716 gp->access = g_concat_access;
717 gp->orphan = g_concat_orphan;
718 cp = g_new_consumer(gp);
720 error = g_concat_read_metadata(cp, &md);
722 g_destroy_consumer(cp);
728 if (strcmp(md.md_magic, G_CONCAT_MAGIC) != 0)
730 if (md.md_version > G_CONCAT_VERSION) {
731 printf("geom_concat.ko module is too old to handle %s.\n",
736 * Backward compatibility:
738 /* There was no md_provider field in earlier versions of metadata. */
739 if (md.md_version < 3)
740 bzero(md.md_provider, sizeof(md.md_provider));
741 /* There was no md_provsize field in earlier versions of metadata. */
742 if (md.md_version < 4)
743 md.md_provsize = pp->mediasize;
745 if (md.md_provider[0] != '\0' &&
746 !g_compare_names(md.md_provider, pp->name))
748 if (md.md_provsize != pp->mediasize)
752 * Let's check if device already exists.
755 LIST_FOREACH(gp, &mp->geom, geom) {
759 if (sc->sc_type != G_CONCAT_TYPE_AUTOMATIC)
761 if (strcmp(md.md_name, sc->sc_name) != 0)
763 if (md.md_id != sc->sc_id)
768 G_CONCAT_DEBUG(1, "Adding disk %s to %s.", pp->name, gp->name);
769 error = g_concat_add_disk(sc, pp, md.md_no);
772 "Cannot add disk %s to %s (error=%d).", pp->name,
777 gp = g_concat_create(mp, &md, G_CONCAT_TYPE_AUTOMATIC);
779 G_CONCAT_DEBUG(0, "Cannot create device %s.",
784 G_CONCAT_DEBUG(1, "Adding disk %s to %s.", pp->name, gp->name);
785 error = g_concat_add_disk(sc, pp, md.md_no);
788 "Cannot add disk %s to %s (error=%d).", pp->name,
790 g_concat_destroy(sc, 1);
799 g_concat_ctl_create(struct gctl_req *req, struct g_class *mp)
802 struct g_concat_metadata md;
803 struct g_provider *pp;
804 struct g_concat_softc *sc;
812 nargs = gctl_get_paraml(req, "nargs", sizeof(*nargs));
814 gctl_error(req, "No '%s' argument.", "nargs");
818 gctl_error(req, "Too few arguments.");
822 strlcpy(md.md_magic, G_CONCAT_MAGIC, sizeof(md.md_magic));
823 md.md_version = G_CONCAT_VERSION;
824 name = gctl_get_asciiparam(req, "arg0");
826 gctl_error(req, "No 'arg%u' argument.", 0);
829 strlcpy(md.md_name, name, sizeof(md.md_name));
830 md.md_id = arc4random();
832 md.md_all = *nargs - 1;
833 bzero(md.md_provider, sizeof(md.md_provider));
834 /* This field is not important here. */
837 /* Check all providers are valid */
838 for (no = 1; no < *nargs; no++) {
839 snprintf(param, sizeof(param), "arg%u", no);
840 name = gctl_get_asciiparam(req, param);
842 gctl_error(req, "No 'arg%u' argument.", no);
845 if (strncmp(name, "/dev/", strlen("/dev/")) == 0)
846 name += strlen("/dev/");
847 pp = g_provider_by_name(name);
849 G_CONCAT_DEBUG(1, "Disk %s is invalid.", name);
850 gctl_error(req, "Disk %s is invalid.", name);
855 gp = g_concat_create(mp, &md, G_CONCAT_TYPE_MANUAL);
857 gctl_error(req, "Can't configure %s.", md.md_name);
862 sb = sbuf_new_auto();
863 sbuf_printf(sb, "Can't attach disk(s) to %s:", gp->name);
864 for (attached = 0, no = 1; no < *nargs; no++) {
865 snprintf(param, sizeof(param), "arg%u", no);
866 name = gctl_get_asciiparam(req, param);
868 gctl_error(req, "No 'arg%d' argument.", no);
871 if (strncmp(name, "/dev/", strlen("/dev/")) == 0)
872 name += strlen("/dev/");
873 pp = g_provider_by_name(name);
874 KASSERT(pp != NULL, ("Provider %s disappear?!", name));
875 if (g_concat_add_disk(sc, pp, no - 1) != 0) {
876 G_CONCAT_DEBUG(1, "Disk %u (%s) not attached to %s.",
877 no, pp->name, gp->name);
878 sbuf_printf(sb, " %s", pp->name);
884 if (md.md_all != attached) {
885 g_concat_destroy(gp->softc, 1);
886 gctl_error(req, "%s", sbuf_data(sb));
891 static struct g_concat_softc *
892 g_concat_find_device(struct g_class *mp, const char *name)
894 struct g_concat_softc *sc;
897 LIST_FOREACH(gp, &mp->geom, geom) {
901 if (strcmp(sc->sc_name, name) == 0)
908 g_concat_ctl_destroy(struct gctl_req *req, struct g_class *mp)
910 struct g_concat_softc *sc;
911 int *force, *nargs, error;
918 nargs = gctl_get_paraml(req, "nargs", sizeof(*nargs));
920 gctl_error(req, "No '%s' argument.", "nargs");
924 gctl_error(req, "Missing device(s).");
927 force = gctl_get_paraml(req, "force", sizeof(*force));
929 gctl_error(req, "No '%s' argument.", "force");
933 for (i = 0; i < (u_int)*nargs; i++) {
934 snprintf(param, sizeof(param), "arg%u", i);
935 name = gctl_get_asciiparam(req, param);
937 gctl_error(req, "No 'arg%u' argument.", i);
940 sc = g_concat_find_device(mp, name);
942 gctl_error(req, "No such device: %s.", name);
945 error = g_concat_destroy(sc, *force);
947 gctl_error(req, "Cannot destroy device %s (error=%d).",
955 g_concat_config(struct gctl_req *req, struct g_class *mp, const char *verb)
961 version = gctl_get_paraml(req, "version", sizeof(*version));
962 if (version == NULL) {
963 gctl_error(req, "No '%s' argument.", "version");
966 if (*version != G_CONCAT_VERSION) {
967 gctl_error(req, "Userland and kernel parts are out of sync.");
971 if (strcmp(verb, "create") == 0) {
972 g_concat_ctl_create(req, mp);
974 } else if (strcmp(verb, "destroy") == 0 ||
975 strcmp(verb, "stop") == 0) {
976 g_concat_ctl_destroy(req, mp);
979 gctl_error(req, "Unknown verb.");
983 g_concat_dumpconf(struct sbuf *sb, const char *indent, struct g_geom *gp,
984 struct g_consumer *cp, struct g_provider *pp)
986 struct g_concat_softc *sc;
994 } else if (cp != NULL) {
995 struct g_concat_disk *disk;
1000 sbuf_printf(sb, "%s<End>%jd</End>\n", indent,
1001 (intmax_t)disk->d_end);
1002 sbuf_printf(sb, "%s<Start>%jd</Start>\n", indent,
1003 (intmax_t)disk->d_start);
1005 sbuf_printf(sb, "%s<ID>%u</ID>\n", indent, (u_int)sc->sc_id);
1006 sbuf_printf(sb, "%s<Type>", indent);
1007 switch (sc->sc_type) {
1008 case G_CONCAT_TYPE_AUTOMATIC:
1009 sbuf_printf(sb, "AUTOMATIC");
1011 case G_CONCAT_TYPE_MANUAL:
1012 sbuf_printf(sb, "MANUAL");
1015 sbuf_printf(sb, "UNKNOWN");
1018 sbuf_printf(sb, "</Type>\n");
1019 sbuf_printf(sb, "%s<Status>Total=%u, Online=%u</Status>\n",
1020 indent, sc->sc_ndisks, g_concat_nvalid(sc));
1021 sbuf_printf(sb, "%s<State>", indent);
1022 if (sc->sc_provider != NULL && sc->sc_provider->error == 0)
1023 sbuf_printf(sb, "UP");
1025 sbuf_printf(sb, "DOWN");
1026 sbuf_printf(sb, "</State>\n");
1030 DECLARE_GEOM_CLASS(g_concat_class, g_concat);
1031 MODULE_VERSION(geom_concat, 0);