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/geom_dbg.h>
44 #include <geom/concat/g_concat.h>
46 FEATURE(geom_concat, "GEOM concatenation support");
48 static MALLOC_DEFINE(M_CONCAT, "concat_data", "GEOM_CONCAT Data");
50 SYSCTL_DECL(_kern_geom);
51 static SYSCTL_NODE(_kern_geom, OID_AUTO, concat, CTLFLAG_RW | CTLFLAG_MPSAFE, 0,
53 static u_int g_concat_debug = 0;
54 SYSCTL_UINT(_kern_geom_concat, OID_AUTO, debug, CTLFLAG_RWTUN, &g_concat_debug, 0,
57 static int g_concat_destroy(struct g_concat_softc *sc, boolean_t force);
58 static int g_concat_destroy_geom(struct gctl_req *req, struct g_class *mp,
61 static g_taste_t g_concat_taste;
62 static g_ctl_req_t g_concat_config;
63 static g_dumpconf_t g_concat_dumpconf;
65 struct g_class g_concat_class = {
66 .name = G_CONCAT_CLASS_NAME,
68 .ctlreq = g_concat_config,
69 .taste = g_concat_taste,
70 .destroy_geom = g_concat_destroy_geom
75 * Greatest Common Divisor.
91 * Least Common Multiple.
97 return ((a * b) / gcd(a, b));
101 * Return the number of valid disks.
104 g_concat_nvalid(struct g_concat_softc *sc)
109 for (i = 0; i < sc->sc_ndisks; i++) {
110 if (sc->sc_disks[i].d_consumer != NULL)
118 g_concat_remove_disk(struct g_concat_disk *disk)
120 struct g_consumer *cp;
121 struct g_concat_softc *sc;
124 KASSERT(disk->d_consumer != NULL, ("Non-valid disk in %s.", __func__));
126 cp = disk->d_consumer;
128 if (!disk->d_removed) {
129 G_CONCAT_DEBUG(0, "Disk %s removed from %s.",
130 cp->provider->name, sc->sc_name);
134 if (sc->sc_provider != NULL) {
135 G_CONCAT_DEBUG(0, "Device %s deactivated.",
136 sc->sc_provider->name);
137 g_wither_provider(sc->sc_provider, ENXIO);
138 sc->sc_provider = NULL;
141 if (cp->acr > 0 || cp->acw > 0 || cp->ace > 0)
143 disk->d_consumer = NULL;
145 g_destroy_consumer(cp);
146 /* If there are no valid disks anymore, remove device. */
147 if (LIST_EMPTY(&sc->sc_geom->consumer))
148 g_concat_destroy(sc, 1);
152 g_concat_orphan(struct g_consumer *cp)
154 struct g_concat_softc *sc;
155 struct g_concat_disk *disk;
165 if (disk == NULL) /* Possible? */
167 g_concat_remove_disk(disk);
171 g_concat_access(struct g_provider *pp, int dr, int dw, int de)
173 struct g_consumer *cp1, *cp2, *tmp;
174 struct g_concat_disk *disk;
181 /* On first open, grab an extra "exclusive" bit */
182 if (pp->acr == 0 && pp->acw == 0 && pp->ace == 0)
184 /* ... and let go of it on last close */
185 if ((pp->acr + dr) == 0 && (pp->acw + dw) == 0 && (pp->ace + de) == 0)
188 LIST_FOREACH_SAFE(cp1, &gp->consumer, consumer, tmp) {
189 error = g_access(cp1, dr, dw, de);
193 if (cp1->acr == 0 && cp1->acw == 0 && cp1->ace == 0 &&
195 g_concat_remove_disk(disk); /* May destroy geom. */
201 LIST_FOREACH(cp2, &gp->consumer, consumer) {
204 g_access(cp2, -dr, -dw, -de);
210 g_concat_candelete(struct bio *bp)
212 struct g_concat_softc *sc;
213 struct g_concat_disk *disk;
216 sc = bp->bio_to->geom->softc;
217 for (i = 0; i < sc->sc_ndisks; i++) {
218 disk = &sc->sc_disks[i];
219 if (!disk->d_removed && disk->d_candelete)
222 val = i < sc->sc_ndisks;
223 g_handleattr(bp, "GEOM::candelete", &val, sizeof(val));
227 g_concat_kernel_dump(struct bio *bp)
229 struct g_concat_softc *sc;
230 struct g_concat_disk *disk;
232 struct g_kerneldump *gkd;
235 sc = bp->bio_to->geom->softc;
236 gkd = (struct g_kerneldump *)bp->bio_data;
237 for (i = 0; i < sc->sc_ndisks; i++) {
238 if (sc->sc_disks[i].d_start <= gkd->offset &&
239 sc->sc_disks[i].d_end > gkd->offset)
242 if (i == sc->sc_ndisks) {
243 g_io_deliver(bp, EOPNOTSUPP);
246 disk = &sc->sc_disks[i];
247 gkd->offset -= disk->d_start;
248 if (gkd->length > disk->d_end - disk->d_start - gkd->offset)
249 gkd->length = disk->d_end - disk->d_start - gkd->offset;
250 cbp = g_clone_bio(bp);
252 g_io_deliver(bp, ENOMEM);
255 cbp->bio_done = g_std_done;
256 g_io_request(cbp, disk->d_consumer);
257 G_CONCAT_DEBUG(1, "Kernel dump will go to %s.",
258 disk->d_consumer->provider->name);
262 g_concat_done(struct bio *bp)
264 struct g_concat_softc *sc;
267 pbp = bp->bio_parent;
268 sc = pbp->bio_to->geom->softc;
269 mtx_lock(&sc->sc_lock);
270 if (pbp->bio_error == 0)
271 pbp->bio_error = bp->bio_error;
272 pbp->bio_completed += bp->bio_completed;
274 if (pbp->bio_children == pbp->bio_inbed) {
275 mtx_unlock(&sc->sc_lock);
276 g_io_deliver(pbp, pbp->bio_error);
278 mtx_unlock(&sc->sc_lock);
283 * Called for both BIO_FLUSH and BIO_SPEEDUP. Just pass the call down
286 g_concat_passdown(struct g_concat_softc *sc, struct bio *bp)
288 struct bio_queue_head queue;
289 struct g_consumer *cp;
294 for (no = 0; no < sc->sc_ndisks; no++) {
295 cbp = g_clone_bio(bp);
297 while ((cbp = bioq_takefirst(&queue)) != NULL)
299 if (bp->bio_error == 0)
300 bp->bio_error = ENOMEM;
301 g_io_deliver(bp, bp->bio_error);
304 bioq_insert_tail(&queue, cbp);
305 cbp->bio_done = g_concat_done;
306 cbp->bio_caller1 = sc->sc_disks[no].d_consumer;
307 cbp->bio_to = sc->sc_disks[no].d_consumer->provider;
309 while ((cbp = bioq_takefirst(&queue)) != NULL) {
310 G_CONCAT_LOGREQ(cbp, "Sending request.");
311 cp = cbp->bio_caller1;
312 cbp->bio_caller1 = NULL;
313 g_io_request(cbp, cp);
318 g_concat_start(struct bio *bp)
320 struct bio_queue_head queue;
321 struct g_concat_softc *sc;
322 struct g_concat_disk *disk;
323 struct g_provider *pp;
324 off_t offset, end, length, off, len;
330 sc = pp->geom->softc;
332 * If sc == NULL, provider's error should be set and g_concat_start()
333 * should not be called at all.
336 ("Provider's error should be set (error=%d)(device=%s).",
337 bp->bio_to->error, bp->bio_to->name));
339 G_CONCAT_LOGREQ(bp, "Request received.");
341 switch (bp->bio_cmd) {
348 g_concat_passdown(sc, bp);
351 if (strcmp("GEOM::kerneldump", bp->bio_attribute) == 0) {
352 g_concat_kernel_dump(bp);
354 } else if (strcmp("GEOM::candelete", bp->bio_attribute) == 0) {
355 g_concat_candelete(bp);
358 /* To which provider it should be delivered? */
361 g_io_deliver(bp, EOPNOTSUPP);
365 offset = bp->bio_offset;
366 length = bp->bio_length;
367 if ((bp->bio_flags & BIO_UNMAPPED) != 0)
371 end = offset + length;
374 for (no = 0; no < sc->sc_ndisks; no++) {
375 disk = &sc->sc_disks[no];
376 if (disk->d_end <= offset)
378 if (disk->d_start >= end)
381 off = offset - disk->d_start;
382 len = MIN(length, disk->d_end - offset);
386 cbp = g_clone_bio(bp);
388 while ((cbp = bioq_takefirst(&queue)) != NULL)
390 if (bp->bio_error == 0)
391 bp->bio_error = ENOMEM;
392 g_io_deliver(bp, bp->bio_error);
395 bioq_insert_tail(&queue, cbp);
397 * Fill in the component buf structure.
399 if (len == bp->bio_length)
400 cbp->bio_done = g_std_done;
402 cbp->bio_done = g_concat_done;
403 cbp->bio_offset = off;
404 cbp->bio_length = len;
405 if ((bp->bio_flags & BIO_UNMAPPED) != 0) {
406 cbp->bio_ma_offset += (uintptr_t)addr;
407 cbp->bio_ma += cbp->bio_ma_offset / PAGE_SIZE;
408 cbp->bio_ma_offset %= PAGE_SIZE;
409 cbp->bio_ma_n = round_page(cbp->bio_ma_offset +
410 cbp->bio_length) / PAGE_SIZE;
412 cbp->bio_data = addr;
414 cbp->bio_to = disk->d_consumer->provider;
415 cbp->bio_caller1 = disk;
421 ("Length is still greater than 0 (class=%s, name=%s).",
422 bp->bio_to->geom->class->name, bp->bio_to->geom->name));
423 while ((cbp = bioq_takefirst(&queue)) != NULL) {
424 G_CONCAT_LOGREQ(cbp, "Sending request.");
425 disk = cbp->bio_caller1;
426 cbp->bio_caller1 = NULL;
427 g_io_request(cbp, disk->d_consumer);
432 g_concat_check_and_run(struct g_concat_softc *sc)
434 struct g_concat_disk *disk;
435 struct g_provider *dp, *pp;
436 u_int no, sectorsize = 0;
441 if (g_concat_nvalid(sc) != sc->sc_ndisks)
444 pp = g_new_providerf(sc->sc_geom, "concat/%s", sc->sc_name);
445 pp->flags |= G_PF_DIRECT_SEND | G_PF_DIRECT_RECEIVE |
446 G_PF_ACCEPT_UNMAPPED;
448 for (no = 0; no < sc->sc_ndisks; no++) {
449 disk = &sc->sc_disks[no];
450 dp = disk->d_consumer->provider;
451 disk->d_start = start;
452 disk->d_end = disk->d_start + dp->mediasize;
453 if (sc->sc_type == G_CONCAT_TYPE_AUTOMATIC)
454 disk->d_end -= dp->sectorsize;
456 error = g_access(disk->d_consumer, 1, 0, 0);
458 error = g_getattr("GEOM::candelete", disk->d_consumer,
461 disk->d_candelete = 0;
462 (void)g_access(disk->d_consumer, -1, 0, 0);
464 G_CONCAT_DEBUG(1, "Failed to access disk %s, error %d.",
467 sectorsize = dp->sectorsize;
469 sectorsize = lcm(sectorsize, dp->sectorsize);
471 /* A provider underneath us doesn't support unmapped */
472 if ((dp->flags & G_PF_ACCEPT_UNMAPPED) == 0) {
473 G_CONCAT_DEBUG(1, "Cancelling unmapped "
474 "because of %s.", dp->name);
475 pp->flags &= ~G_PF_ACCEPT_UNMAPPED;
478 pp->sectorsize = sectorsize;
479 /* We have sc->sc_disks[sc->sc_ndisks - 1].d_end in 'start'. */
480 pp->mediasize = start;
481 pp->stripesize = sc->sc_disks[0].d_consumer->provider->stripesize;
482 pp->stripeoffset = sc->sc_disks[0].d_consumer->provider->stripeoffset;
483 sc->sc_provider = pp;
484 g_error_provider(pp, 0);
486 G_CONCAT_DEBUG(0, "Device %s activated.", sc->sc_provider->name);
490 g_concat_read_metadata(struct g_consumer *cp, struct g_concat_metadata *md)
492 struct g_provider *pp;
498 error = g_access(cp, 1, 0, 0);
503 buf = g_read_data(cp, pp->mediasize - pp->sectorsize, pp->sectorsize,
506 g_access(cp, -1, 0, 0);
510 /* Decode metadata. */
511 concat_metadata_decode(buf, md);
518 * Add disk to given device.
521 g_concat_add_disk(struct g_concat_softc *sc, struct g_provider *pp, u_int no)
523 struct g_concat_disk *disk;
524 struct g_consumer *cp, *fcp;
529 /* Metadata corrupted? */
530 if (no >= sc->sc_ndisks)
533 disk = &sc->sc_disks[no];
534 /* Check if disk is not already attached. */
535 if (disk->d_consumer != NULL)
539 fcp = LIST_FIRST(&gp->consumer);
541 cp = g_new_consumer(gp);
542 cp->flags |= G_CF_DIRECT_SEND | G_CF_DIRECT_RECEIVE;
543 error = g_attach(cp, pp);
545 g_destroy_consumer(cp);
549 if (fcp != NULL && (fcp->acr > 0 || fcp->acw > 0 || fcp->ace > 0)) {
550 error = g_access(cp, fcp->acr, fcp->acw, fcp->ace);
553 g_destroy_consumer(cp);
557 if (sc->sc_type == G_CONCAT_TYPE_AUTOMATIC) {
558 struct g_concat_metadata md;
560 /* Re-read metadata. */
561 error = g_concat_read_metadata(cp, &md);
565 if (strcmp(md.md_magic, G_CONCAT_MAGIC) != 0 ||
566 strcmp(md.md_name, sc->sc_name) != 0 ||
567 md.md_id != sc->sc_id) {
568 G_CONCAT_DEBUG(0, "Metadata on %s changed.", pp->name);
574 disk->d_consumer = cp;
576 disk->d_start = 0; /* not yet */
577 disk->d_end = 0; /* not yet */
580 G_CONCAT_DEBUG(0, "Disk %s attached to %s.", pp->name, sc->sc_name);
582 g_concat_check_and_run(sc);
586 if (fcp != NULL && (fcp->acr > 0 || fcp->acw > 0 || fcp->ace > 0))
587 g_access(cp, -fcp->acr, -fcp->acw, -fcp->ace);
589 g_destroy_consumer(cp);
593 static struct g_geom *
594 g_concat_create(struct g_class *mp, const struct g_concat_metadata *md,
597 struct g_concat_softc *sc;
601 G_CONCAT_DEBUG(1, "Creating device %s (id=%u).", md->md_name,
604 /* One disks is minimum. */
608 /* Check for duplicate unit */
609 LIST_FOREACH(gp, &mp->geom, geom) {
611 if (sc != NULL && strcmp(sc->sc_name, md->md_name) == 0) {
612 G_CONCAT_DEBUG(0, "Device %s already configured.",
617 gp = g_new_geomf(mp, "%s", md->md_name);
618 sc = malloc(sizeof(*sc), M_CONCAT, M_WAITOK | M_ZERO);
619 gp->start = g_concat_start;
620 gp->spoiled = g_concat_orphan;
621 gp->orphan = g_concat_orphan;
622 gp->access = g_concat_access;
623 gp->dumpconf = g_concat_dumpconf;
625 sc->sc_id = md->md_id;
626 sc->sc_ndisks = md->md_all;
627 sc->sc_disks = malloc(sizeof(struct g_concat_disk) * sc->sc_ndisks,
628 M_CONCAT, M_WAITOK | M_ZERO);
629 for (no = 0; no < sc->sc_ndisks; no++)
630 sc->sc_disks[no].d_consumer = NULL;
632 mtx_init(&sc->sc_lock, "gconcat lock", NULL, MTX_DEF);
636 sc->sc_provider = NULL;
638 G_CONCAT_DEBUG(0, "Device %s created (id=%u).", sc->sc_name, sc->sc_id);
644 g_concat_destroy(struct g_concat_softc *sc, boolean_t force)
646 struct g_provider *pp;
647 struct g_consumer *cp, *cp1;
655 pp = sc->sc_provider;
656 if (pp != NULL && (pp->acr != 0 || pp->acw != 0 || pp->ace != 0)) {
658 G_CONCAT_DEBUG(0, "Device %s is still open, so it "
659 "can't be definitely removed.", pp->name);
662 "Device %s is still open (r%dw%de%d).", pp->name,
663 pp->acr, pp->acw, pp->ace);
669 LIST_FOREACH_SAFE(cp, &gp->consumer, consumer, cp1) {
670 g_concat_remove_disk(cp->private);
672 return (0); /* Recursion happened. */
674 if (!LIST_EMPTY(&gp->consumer))
675 return (EINPROGRESS);
678 KASSERT(sc->sc_provider == NULL, ("Provider still exists? (device=%s)",
680 free(sc->sc_disks, M_CONCAT);
681 mtx_destroy(&sc->sc_lock);
684 G_CONCAT_DEBUG(0, "Device %s destroyed.", gp->name);
685 g_wither_geom(gp, ENXIO);
690 g_concat_destroy_geom(struct gctl_req *req __unused,
691 struct g_class *mp __unused, struct g_geom *gp)
693 struct g_concat_softc *sc;
696 return (g_concat_destroy(sc, 0));
699 static struct g_geom *
700 g_concat_taste(struct g_class *mp, struct g_provider *pp, int flags __unused)
702 struct g_concat_metadata md;
703 struct g_concat_softc *sc;
704 struct g_consumer *cp;
708 g_trace(G_T_TOPOLOGY, "%s(%s, %s)", __func__, mp->name, pp->name);
711 /* Skip providers that are already open for writing. */
715 G_CONCAT_DEBUG(3, "Tasting %s.", pp->name);
717 gp = g_new_geomf(mp, "concat:taste");
718 gp->start = g_concat_start;
719 gp->access = g_concat_access;
720 gp->orphan = g_concat_orphan;
721 cp = g_new_consumer(gp);
723 error = g_concat_read_metadata(cp, &md);
725 g_destroy_consumer(cp);
731 if (strcmp(md.md_magic, G_CONCAT_MAGIC) != 0)
733 if (md.md_version > G_CONCAT_VERSION) {
734 printf("geom_concat.ko module is too old to handle %s.\n",
739 * Backward compatibility:
741 /* There was no md_provider field in earlier versions of metadata. */
742 if (md.md_version < 3)
743 bzero(md.md_provider, sizeof(md.md_provider));
744 /* There was no md_provsize field in earlier versions of metadata. */
745 if (md.md_version < 4)
746 md.md_provsize = pp->mediasize;
748 if (md.md_provider[0] != '\0' &&
749 !g_compare_names(md.md_provider, pp->name))
751 if (md.md_provsize != pp->mediasize)
755 * Let's check if device already exists.
758 LIST_FOREACH(gp, &mp->geom, geom) {
762 if (sc->sc_type != G_CONCAT_TYPE_AUTOMATIC)
764 if (strcmp(md.md_name, sc->sc_name) != 0)
766 if (md.md_id != sc->sc_id)
771 G_CONCAT_DEBUG(1, "Adding disk %s to %s.", pp->name, gp->name);
772 error = g_concat_add_disk(sc, pp, md.md_no);
775 "Cannot add disk %s to %s (error=%d).", pp->name,
780 gp = g_concat_create(mp, &md, G_CONCAT_TYPE_AUTOMATIC);
782 G_CONCAT_DEBUG(0, "Cannot create device %s.",
787 G_CONCAT_DEBUG(1, "Adding disk %s to %s.", pp->name, gp->name);
788 error = g_concat_add_disk(sc, pp, md.md_no);
791 "Cannot add disk %s to %s (error=%d).", pp->name,
793 g_concat_destroy(sc, 1);
802 g_concat_ctl_create(struct gctl_req *req, struct g_class *mp)
805 struct g_concat_metadata md;
806 struct g_provider *pp;
807 struct g_concat_softc *sc;
815 nargs = gctl_get_paraml(req, "nargs", sizeof(*nargs));
817 gctl_error(req, "No '%s' argument.", "nargs");
821 gctl_error(req, "Too few arguments.");
825 strlcpy(md.md_magic, G_CONCAT_MAGIC, sizeof(md.md_magic));
826 md.md_version = G_CONCAT_VERSION;
827 name = gctl_get_asciiparam(req, "arg0");
829 gctl_error(req, "No 'arg%u' argument.", 0);
832 strlcpy(md.md_name, name, sizeof(md.md_name));
833 md.md_id = arc4random();
835 md.md_all = *nargs - 1;
836 bzero(md.md_provider, sizeof(md.md_provider));
837 /* This field is not important here. */
840 /* Check all providers are valid */
841 for (no = 1; no < *nargs; no++) {
842 snprintf(param, sizeof(param), "arg%u", no);
843 pp = gctl_get_provider(req, param);
848 gp = g_concat_create(mp, &md, G_CONCAT_TYPE_MANUAL);
850 gctl_error(req, "Can't configure %s.", md.md_name);
855 sb = sbuf_new_auto();
856 sbuf_printf(sb, "Can't attach disk(s) to %s:", gp->name);
857 for (attached = 0, no = 1; no < *nargs; no++) {
858 snprintf(param, sizeof(param), "arg%u", no);
859 pp = gctl_get_provider(req, param);
861 name = gctl_get_asciiparam(req, param);
863 sbuf_printf(sb, " %s", name);
866 if (g_concat_add_disk(sc, pp, no - 1) != 0) {
867 G_CONCAT_DEBUG(1, "Disk %u (%s) not attached to %s.",
868 no, pp->name, gp->name);
869 sbuf_printf(sb, " %s", pp->name);
875 if (md.md_all != attached) {
876 g_concat_destroy(gp->softc, 1);
877 gctl_error(req, "%s", sbuf_data(sb));
882 static struct g_concat_softc *
883 g_concat_find_device(struct g_class *mp, const char *name)
885 struct g_concat_softc *sc;
888 if (strncmp(name, _PATH_DEV, strlen(_PATH_DEV)) == 0)
889 name += strlen(_PATH_DEV);
891 LIST_FOREACH(gp, &mp->geom, geom) {
895 if (strcmp(sc->sc_name, name) == 0)
902 g_concat_ctl_destroy(struct gctl_req *req, struct g_class *mp)
904 struct g_concat_softc *sc;
905 int *force, *nargs, error;
912 nargs = gctl_get_paraml(req, "nargs", sizeof(*nargs));
914 gctl_error(req, "No '%s' argument.", "nargs");
918 gctl_error(req, "Missing device(s).");
921 force = gctl_get_paraml(req, "force", sizeof(*force));
923 gctl_error(req, "No '%s' argument.", "force");
927 for (i = 0; i < (u_int)*nargs; i++) {
928 snprintf(param, sizeof(param), "arg%u", i);
929 name = gctl_get_asciiparam(req, param);
931 gctl_error(req, "No 'arg%u' argument.", i);
934 sc = g_concat_find_device(mp, name);
936 gctl_error(req, "No such device: %s.", name);
939 error = g_concat_destroy(sc, *force);
941 gctl_error(req, "Cannot destroy device %s (error=%d).",
949 g_concat_config(struct gctl_req *req, struct g_class *mp, const char *verb)
955 version = gctl_get_paraml(req, "version", sizeof(*version));
956 if (version == NULL) {
957 gctl_error(req, "No '%s' argument.", "version");
960 if (*version != G_CONCAT_VERSION) {
961 gctl_error(req, "Userland and kernel parts are out of sync.");
965 if (strcmp(verb, "create") == 0) {
966 g_concat_ctl_create(req, mp);
968 } else if (strcmp(verb, "destroy") == 0 ||
969 strcmp(verb, "stop") == 0) {
970 g_concat_ctl_destroy(req, mp);
973 gctl_error(req, "Unknown verb.");
977 g_concat_dumpconf(struct sbuf *sb, const char *indent, struct g_geom *gp,
978 struct g_consumer *cp, struct g_provider *pp)
980 struct g_concat_softc *sc;
988 } else if (cp != NULL) {
989 struct g_concat_disk *disk;
994 sbuf_printf(sb, "%s<End>%jd</End>\n", indent,
995 (intmax_t)disk->d_end);
996 sbuf_printf(sb, "%s<Start>%jd</Start>\n", indent,
997 (intmax_t)disk->d_start);
999 sbuf_printf(sb, "%s<ID>%u</ID>\n", indent, (u_int)sc->sc_id);
1000 sbuf_printf(sb, "%s<Type>", indent);
1001 switch (sc->sc_type) {
1002 case G_CONCAT_TYPE_AUTOMATIC:
1003 sbuf_cat(sb, "AUTOMATIC");
1005 case G_CONCAT_TYPE_MANUAL:
1006 sbuf_cat(sb, "MANUAL");
1009 sbuf_cat(sb, "UNKNOWN");
1012 sbuf_cat(sb, "</Type>\n");
1013 sbuf_printf(sb, "%s<Status>Total=%u, Online=%u</Status>\n",
1014 indent, sc->sc_ndisks, g_concat_nvalid(sc));
1015 sbuf_printf(sb, "%s<State>", indent);
1016 if (sc->sc_provider != NULL && sc->sc_provider->error == 0)
1019 sbuf_cat(sb, "DOWN");
1020 sbuf_cat(sb, "</State>\n");
1024 DECLARE_GEOM_CLASS(g_concat_class, g_concat);
1025 MODULE_VERSION(geom_concat, 0);