119d16e2fSPawel Jakub Dawidek /*- 2e6890985SPawel Jakub Dawidek * Copyright (c) 2004-2005 Pawel Jakub Dawidek <pjd@FreeBSD.org> 319d16e2fSPawel Jakub Dawidek * All rights reserved. 419d16e2fSPawel Jakub Dawidek * 519d16e2fSPawel Jakub Dawidek * Redistribution and use in source and binary forms, with or without 619d16e2fSPawel Jakub Dawidek * modification, are permitted provided that the following conditions 719d16e2fSPawel Jakub Dawidek * are met: 819d16e2fSPawel Jakub Dawidek * 1. Redistributions of source code must retain the above copyright 919d16e2fSPawel Jakub Dawidek * notice, this list of conditions and the following disclaimer. 1019d16e2fSPawel Jakub Dawidek * 2. Redistributions in binary form must reproduce the above copyright 1119d16e2fSPawel Jakub Dawidek * notice, this list of conditions and the following disclaimer in the 1219d16e2fSPawel Jakub Dawidek * documentation and/or other materials provided with the distribution. 1319d16e2fSPawel Jakub Dawidek * 1419d16e2fSPawel Jakub Dawidek * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND 1519d16e2fSPawel Jakub Dawidek * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1619d16e2fSPawel Jakub Dawidek * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1719d16e2fSPawel Jakub Dawidek * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE 1819d16e2fSPawel Jakub Dawidek * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 1919d16e2fSPawel Jakub Dawidek * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2019d16e2fSPawel Jakub Dawidek * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2119d16e2fSPawel Jakub Dawidek * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2219d16e2fSPawel Jakub Dawidek * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2319d16e2fSPawel Jakub Dawidek * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2419d16e2fSPawel Jakub Dawidek * SUCH DAMAGE. 2519d16e2fSPawel Jakub Dawidek */ 2619d16e2fSPawel Jakub Dawidek 2719d16e2fSPawel Jakub Dawidek #include <sys/cdefs.h> 2819d16e2fSPawel Jakub Dawidek __FBSDID("$FreeBSD$"); 2919d16e2fSPawel Jakub Dawidek 3019d16e2fSPawel Jakub Dawidek #include <sys/param.h> 3119d16e2fSPawel Jakub Dawidek #include <sys/systm.h> 3219d16e2fSPawel Jakub Dawidek #include <sys/kernel.h> 3319d16e2fSPawel Jakub Dawidek #include <sys/module.h> 3419d16e2fSPawel Jakub Dawidek #include <sys/lock.h> 3519d16e2fSPawel Jakub Dawidek #include <sys/mutex.h> 3619d16e2fSPawel Jakub Dawidek #include <sys/bio.h> 375d807a0eSAndrey V. Elsukov #include <sys/sbuf.h> 3819d16e2fSPawel Jakub Dawidek #include <sys/sysctl.h> 3919d16e2fSPawel Jakub Dawidek #include <sys/malloc.h> 4019d16e2fSPawel Jakub Dawidek #include <geom/geom.h> 4119d16e2fSPawel Jakub Dawidek #include <geom/concat/g_concat.h> 4219d16e2fSPawel Jakub Dawidek 43cb08c2ccSAlexander Leidinger FEATURE(geom_concat, "GEOM concatenation support"); 4419d16e2fSPawel Jakub Dawidek 455bb84bc8SRobert Watson static MALLOC_DEFINE(M_CONCAT, "concat_data", "GEOM_CONCAT Data"); 4619d16e2fSPawel Jakub Dawidek 47a88ae49fSPawel Jakub Dawidek SYSCTL_DECL(_kern_geom); 4819d16e2fSPawel Jakub Dawidek SYSCTL_NODE(_kern_geom, OID_AUTO, concat, CTLFLAG_RW, 0, "GEOM_CONCAT stuff"); 4919d16e2fSPawel Jakub Dawidek static u_int g_concat_debug = 0; 506d7b8aecSPawel Jakub Dawidek TUNABLE_INT("kern.geom.concat.debug", &g_concat_debug); 5119d16e2fSPawel Jakub Dawidek SYSCTL_UINT(_kern_geom_concat, OID_AUTO, debug, CTLFLAG_RW, &g_concat_debug, 0, 5219d16e2fSPawel Jakub Dawidek "Debug level"); 5319d16e2fSPawel Jakub Dawidek 5419d16e2fSPawel Jakub Dawidek static int g_concat_destroy(struct g_concat_softc *sc, boolean_t force); 5519d16e2fSPawel Jakub Dawidek static int g_concat_destroy_geom(struct gctl_req *req, struct g_class *mp, 5619d16e2fSPawel Jakub Dawidek struct g_geom *gp); 5719d16e2fSPawel Jakub Dawidek 5819d16e2fSPawel Jakub Dawidek static g_taste_t g_concat_taste; 5919d16e2fSPawel Jakub Dawidek static g_ctl_req_t g_concat_config; 6019d16e2fSPawel Jakub Dawidek static g_dumpconf_t g_concat_dumpconf; 6119d16e2fSPawel Jakub Dawidek 6219d16e2fSPawel Jakub Dawidek struct g_class g_concat_class = { 6319d16e2fSPawel Jakub Dawidek .name = G_CONCAT_CLASS_NAME, 645721c9c7SPoul-Henning Kamp .version = G_VERSION, 6519d16e2fSPawel Jakub Dawidek .ctlreq = g_concat_config, 6619d16e2fSPawel Jakub Dawidek .taste = g_concat_taste, 6719d16e2fSPawel Jakub Dawidek .destroy_geom = g_concat_destroy_geom 6819d16e2fSPawel Jakub Dawidek }; 6919d16e2fSPawel Jakub Dawidek 7019d16e2fSPawel Jakub Dawidek 7119d16e2fSPawel Jakub Dawidek /* 7248fbd94bSPawel Jakub Dawidek * Greatest Common Divisor. 7348fbd94bSPawel Jakub Dawidek */ 7448fbd94bSPawel Jakub Dawidek static u_int 7548fbd94bSPawel Jakub Dawidek gcd(u_int a, u_int b) 7648fbd94bSPawel Jakub Dawidek { 7748fbd94bSPawel Jakub Dawidek u_int c; 7848fbd94bSPawel Jakub Dawidek 7948fbd94bSPawel Jakub Dawidek while (b != 0) { 8048fbd94bSPawel Jakub Dawidek c = a; 8148fbd94bSPawel Jakub Dawidek a = b; 8248fbd94bSPawel Jakub Dawidek b = (c % b); 8348fbd94bSPawel Jakub Dawidek } 8448fbd94bSPawel Jakub Dawidek return (a); 8548fbd94bSPawel Jakub Dawidek } 8648fbd94bSPawel Jakub Dawidek 8748fbd94bSPawel Jakub Dawidek /* 8848fbd94bSPawel Jakub Dawidek * Least Common Multiple. 8948fbd94bSPawel Jakub Dawidek */ 9048fbd94bSPawel Jakub Dawidek static u_int 9148fbd94bSPawel Jakub Dawidek lcm(u_int a, u_int b) 9248fbd94bSPawel Jakub Dawidek { 9348fbd94bSPawel Jakub Dawidek 9448fbd94bSPawel Jakub Dawidek return ((a * b) / gcd(a, b)); 9548fbd94bSPawel Jakub Dawidek } 9648fbd94bSPawel Jakub Dawidek 9748fbd94bSPawel Jakub Dawidek /* 9819d16e2fSPawel Jakub Dawidek * Return the number of valid disks. 9919d16e2fSPawel Jakub Dawidek */ 10019d16e2fSPawel Jakub Dawidek static u_int 10119d16e2fSPawel Jakub Dawidek g_concat_nvalid(struct g_concat_softc *sc) 10219d16e2fSPawel Jakub Dawidek { 10319d16e2fSPawel Jakub Dawidek u_int i, no; 10419d16e2fSPawel Jakub Dawidek 10519d16e2fSPawel Jakub Dawidek no = 0; 10619d16e2fSPawel Jakub Dawidek for (i = 0; i < sc->sc_ndisks; i++) { 107a88ae49fSPawel Jakub Dawidek if (sc->sc_disks[i].d_consumer != NULL) 10819d16e2fSPawel Jakub Dawidek no++; 10919d16e2fSPawel Jakub Dawidek } 11019d16e2fSPawel Jakub Dawidek 11119d16e2fSPawel Jakub Dawidek return (no); 11219d16e2fSPawel Jakub Dawidek } 11319d16e2fSPawel Jakub Dawidek 11419d16e2fSPawel Jakub Dawidek static void 11519d16e2fSPawel Jakub Dawidek g_concat_remove_disk(struct g_concat_disk *disk) 11619d16e2fSPawel Jakub Dawidek { 11719d16e2fSPawel Jakub Dawidek struct g_consumer *cp; 11819d16e2fSPawel Jakub Dawidek struct g_concat_softc *sc; 11919d16e2fSPawel Jakub Dawidek 120*df96fd6eSAlexander Motin g_topology_assert(); 121a88ae49fSPawel Jakub Dawidek KASSERT(disk->d_consumer != NULL, ("Non-valid disk in %s.", __func__)); 12219d16e2fSPawel Jakub Dawidek sc = disk->d_softc; 12319d16e2fSPawel Jakub Dawidek cp = disk->d_consumer; 12419d16e2fSPawel Jakub Dawidek 125*df96fd6eSAlexander Motin if (!disk->d_removed) { 126*df96fd6eSAlexander Motin G_CONCAT_DEBUG(0, "Disk %s removed from %s.", 127*df96fd6eSAlexander Motin cp->provider->name, sc->sc_name); 128*df96fd6eSAlexander Motin disk->d_removed = 1; 129*df96fd6eSAlexander Motin } 13019d16e2fSPawel Jakub Dawidek 13102637cdcSPawel Jakub Dawidek if (sc->sc_provider != NULL) { 1320499edf4SPawel Jakub Dawidek sc->sc_provider->flags |= G_PF_WITHER; 133*df96fd6eSAlexander Motin G_CONCAT_DEBUG(0, "Device %s deactivated.", 134*df96fd6eSAlexander Motin sc->sc_provider->name); 13502637cdcSPawel Jakub Dawidek g_orphan_provider(sc->sc_provider, ENXIO); 13602637cdcSPawel Jakub Dawidek sc->sc_provider = NULL; 13702637cdcSPawel Jakub Dawidek } 13819d16e2fSPawel Jakub Dawidek 13919d16e2fSPawel Jakub Dawidek if (cp->acr > 0 || cp->acw > 0 || cp->ace > 0) 140*df96fd6eSAlexander Motin return; 141*df96fd6eSAlexander Motin disk->d_consumer = NULL; 14219d16e2fSPawel Jakub Dawidek g_detach(cp); 14319d16e2fSPawel Jakub Dawidek g_destroy_consumer(cp); 144*df96fd6eSAlexander Motin /* If there are no valid disks anymore, remove device. */ 145*df96fd6eSAlexander Motin if (LIST_EMPTY(&sc->sc_geom->consumer)) 146*df96fd6eSAlexander Motin g_concat_destroy(sc, 1); 14719d16e2fSPawel Jakub Dawidek } 14819d16e2fSPawel Jakub Dawidek 14919d16e2fSPawel Jakub Dawidek static void 15019d16e2fSPawel Jakub Dawidek g_concat_orphan(struct g_consumer *cp) 15119d16e2fSPawel Jakub Dawidek { 15219d16e2fSPawel Jakub Dawidek struct g_concat_softc *sc; 15319d16e2fSPawel Jakub Dawidek struct g_concat_disk *disk; 15419d16e2fSPawel Jakub Dawidek struct g_geom *gp; 15519d16e2fSPawel Jakub Dawidek 15619d16e2fSPawel Jakub Dawidek g_topology_assert(); 15719d16e2fSPawel Jakub Dawidek gp = cp->geom; 15819d16e2fSPawel Jakub Dawidek sc = gp->softc; 15919d16e2fSPawel Jakub Dawidek if (sc == NULL) 16019d16e2fSPawel Jakub Dawidek return; 16119d16e2fSPawel Jakub Dawidek 16219d16e2fSPawel Jakub Dawidek disk = cp->private; 16319d16e2fSPawel Jakub Dawidek if (disk == NULL) /* Possible? */ 16419d16e2fSPawel Jakub Dawidek return; 16519d16e2fSPawel Jakub Dawidek g_concat_remove_disk(disk); 16619d16e2fSPawel Jakub Dawidek } 16719d16e2fSPawel Jakub Dawidek 16819d16e2fSPawel Jakub Dawidek static int 16919d16e2fSPawel Jakub Dawidek g_concat_access(struct g_provider *pp, int dr, int dw, int de) 17019d16e2fSPawel Jakub Dawidek { 171*df96fd6eSAlexander Motin struct g_consumer *cp1, *cp2, *tmp; 172*df96fd6eSAlexander Motin struct g_concat_disk *disk; 17319d16e2fSPawel Jakub Dawidek struct g_geom *gp; 17419d16e2fSPawel Jakub Dawidek int error; 17519d16e2fSPawel Jakub Dawidek 176*df96fd6eSAlexander Motin g_topology_assert(); 17719d16e2fSPawel Jakub Dawidek gp = pp->geom; 17819d16e2fSPawel Jakub Dawidek 17919d16e2fSPawel Jakub Dawidek /* On first open, grab an extra "exclusive" bit */ 18019d16e2fSPawel Jakub Dawidek if (pp->acr == 0 && pp->acw == 0 && pp->ace == 0) 18119d16e2fSPawel Jakub Dawidek de++; 18219d16e2fSPawel Jakub Dawidek /* ... and let go of it on last close */ 183be7695cfSPawel Jakub Dawidek if ((pp->acr + dr) == 0 && (pp->acw + dw) == 0 && (pp->ace + de) == 0) 18419d16e2fSPawel Jakub Dawidek de--; 18519d16e2fSPawel Jakub Dawidek 186*df96fd6eSAlexander Motin LIST_FOREACH_SAFE(cp1, &gp->consumer, consumer, tmp) { 18719d16e2fSPawel Jakub Dawidek error = g_access(cp1, dr, dw, de); 188*df96fd6eSAlexander Motin if (error != 0) 189*df96fd6eSAlexander Motin goto fail; 190*df96fd6eSAlexander Motin disk = cp1->private; 191*df96fd6eSAlexander Motin if (cp1->acr == 0 && cp1->acw == 0 && cp1->ace == 0 && 192*df96fd6eSAlexander Motin disk->d_removed) { 193*df96fd6eSAlexander Motin g_concat_remove_disk(disk); /* May destroy geom. */ 194*df96fd6eSAlexander Motin } 195*df96fd6eSAlexander Motin } 196*df96fd6eSAlexander Motin return (0); 197*df96fd6eSAlexander Motin 198*df96fd6eSAlexander Motin fail: 19919d16e2fSPawel Jakub Dawidek LIST_FOREACH(cp2, &gp->consumer, consumer) { 20019d16e2fSPawel Jakub Dawidek if (cp1 == cp2) 201*df96fd6eSAlexander Motin break; 20219d16e2fSPawel Jakub Dawidek g_access(cp2, -dr, -dw, -de); 20319d16e2fSPawel Jakub Dawidek } 20419d16e2fSPawel Jakub Dawidek return (error); 20519d16e2fSPawel Jakub Dawidek } 20619d16e2fSPawel Jakub Dawidek 20719d16e2fSPawel Jakub Dawidek static void 208659f684eSAlexander Motin g_concat_kernel_dump(struct bio *bp) 209659f684eSAlexander Motin { 210659f684eSAlexander Motin struct g_concat_softc *sc; 211659f684eSAlexander Motin struct g_concat_disk *disk; 212659f684eSAlexander Motin struct bio *cbp; 213659f684eSAlexander Motin struct g_kerneldump *gkd; 214659f684eSAlexander Motin u_int i; 215659f684eSAlexander Motin 216659f684eSAlexander Motin sc = bp->bio_to->geom->softc; 217659f684eSAlexander Motin gkd = (struct g_kerneldump *)bp->bio_data; 218659f684eSAlexander Motin for (i = 0; i < sc->sc_ndisks; i++) { 219659f684eSAlexander Motin if (sc->sc_disks[i].d_start <= gkd->offset && 220659f684eSAlexander Motin sc->sc_disks[i].d_end > gkd->offset) 221659f684eSAlexander Motin break; 222659f684eSAlexander Motin } 223659f684eSAlexander Motin if (i == sc->sc_ndisks) 224659f684eSAlexander Motin g_io_deliver(bp, EOPNOTSUPP); 225659f684eSAlexander Motin disk = &sc->sc_disks[i]; 226659f684eSAlexander Motin gkd->offset -= disk->d_start; 227659f684eSAlexander Motin if (gkd->length > disk->d_end - disk->d_start - gkd->offset) 228659f684eSAlexander Motin gkd->length = disk->d_end - disk->d_start - gkd->offset; 229659f684eSAlexander Motin cbp = g_clone_bio(bp); 230659f684eSAlexander Motin if (cbp == NULL) { 231659f684eSAlexander Motin g_io_deliver(bp, ENOMEM); 232659f684eSAlexander Motin return; 233659f684eSAlexander Motin } 234659f684eSAlexander Motin cbp->bio_done = g_std_done; 235659f684eSAlexander Motin g_io_request(cbp, disk->d_consumer); 236659f684eSAlexander Motin G_CONCAT_DEBUG(1, "Kernel dump will go to %s.", 237659f684eSAlexander Motin disk->d_consumer->provider->name); 238659f684eSAlexander Motin } 239659f684eSAlexander Motin 240659f684eSAlexander Motin static void 24142461fbaSPawel Jakub Dawidek g_concat_flush(struct g_concat_softc *sc, struct bio *bp) 24242461fbaSPawel Jakub Dawidek { 24342461fbaSPawel Jakub Dawidek struct bio_queue_head queue; 24442461fbaSPawel Jakub Dawidek struct g_consumer *cp; 24542461fbaSPawel Jakub Dawidek struct bio *cbp; 24642461fbaSPawel Jakub Dawidek u_int no; 24742461fbaSPawel Jakub Dawidek 24842461fbaSPawel Jakub Dawidek bioq_init(&queue); 24942461fbaSPawel Jakub Dawidek for (no = 0; no < sc->sc_ndisks; no++) { 25042461fbaSPawel Jakub Dawidek cbp = g_clone_bio(bp); 25142461fbaSPawel Jakub Dawidek if (cbp == NULL) { 25242461fbaSPawel Jakub Dawidek for (cbp = bioq_first(&queue); cbp != NULL; 25342461fbaSPawel Jakub Dawidek cbp = bioq_first(&queue)) { 25442461fbaSPawel Jakub Dawidek bioq_remove(&queue, cbp); 25542461fbaSPawel Jakub Dawidek g_destroy_bio(cbp); 25642461fbaSPawel Jakub Dawidek } 25742461fbaSPawel Jakub Dawidek if (bp->bio_error == 0) 25842461fbaSPawel Jakub Dawidek bp->bio_error = ENOMEM; 25942461fbaSPawel Jakub Dawidek g_io_deliver(bp, bp->bio_error); 26042461fbaSPawel Jakub Dawidek return; 26142461fbaSPawel Jakub Dawidek } 26242461fbaSPawel Jakub Dawidek bioq_insert_tail(&queue, cbp); 26342461fbaSPawel Jakub Dawidek cbp->bio_done = g_std_done; 26442461fbaSPawel Jakub Dawidek cbp->bio_caller1 = sc->sc_disks[no].d_consumer; 26542461fbaSPawel Jakub Dawidek cbp->bio_to = sc->sc_disks[no].d_consumer->provider; 26642461fbaSPawel Jakub Dawidek } 26742461fbaSPawel Jakub Dawidek for (cbp = bioq_first(&queue); cbp != NULL; cbp = bioq_first(&queue)) { 26842461fbaSPawel Jakub Dawidek bioq_remove(&queue, cbp); 26942461fbaSPawel Jakub Dawidek G_CONCAT_LOGREQ(cbp, "Sending request."); 27042461fbaSPawel Jakub Dawidek cp = cbp->bio_caller1; 27142461fbaSPawel Jakub Dawidek cbp->bio_caller1 = NULL; 27242461fbaSPawel Jakub Dawidek g_io_request(cbp, cp); 27342461fbaSPawel Jakub Dawidek } 27442461fbaSPawel Jakub Dawidek } 27542461fbaSPawel Jakub Dawidek 27642461fbaSPawel Jakub Dawidek static void 27719d16e2fSPawel Jakub Dawidek g_concat_start(struct bio *bp) 27819d16e2fSPawel Jakub Dawidek { 2797e0b3120SPawel Jakub Dawidek struct bio_queue_head queue; 28019d16e2fSPawel Jakub Dawidek struct g_concat_softc *sc; 28119d16e2fSPawel Jakub Dawidek struct g_concat_disk *disk; 28219d16e2fSPawel Jakub Dawidek struct g_provider *pp; 28319d16e2fSPawel Jakub Dawidek off_t offset, end, length, off, len; 28419d16e2fSPawel Jakub Dawidek struct bio *cbp; 28519d16e2fSPawel Jakub Dawidek char *addr; 28619d16e2fSPawel Jakub Dawidek u_int no; 28719d16e2fSPawel Jakub Dawidek 28819d16e2fSPawel Jakub Dawidek pp = bp->bio_to; 28919d16e2fSPawel Jakub Dawidek sc = pp->geom->softc; 29019d16e2fSPawel Jakub Dawidek /* 29119d16e2fSPawel Jakub Dawidek * If sc == NULL, provider's error should be set and g_concat_start() 29219d16e2fSPawel Jakub Dawidek * should not be called at all. 29319d16e2fSPawel Jakub Dawidek */ 29419d16e2fSPawel Jakub Dawidek KASSERT(sc != NULL, 29519d16e2fSPawel Jakub Dawidek ("Provider's error should be set (error=%d)(device=%s).", 29619d16e2fSPawel Jakub Dawidek bp->bio_to->error, bp->bio_to->name)); 29719d16e2fSPawel Jakub Dawidek 29819d16e2fSPawel Jakub Dawidek G_CONCAT_LOGREQ(bp, "Request received."); 29919d16e2fSPawel Jakub Dawidek 30019d16e2fSPawel Jakub Dawidek switch (bp->bio_cmd) { 30119d16e2fSPawel Jakub Dawidek case BIO_READ: 30219d16e2fSPawel Jakub Dawidek case BIO_WRITE: 30319d16e2fSPawel Jakub Dawidek case BIO_DELETE: 30419d16e2fSPawel Jakub Dawidek break; 30542461fbaSPawel Jakub Dawidek case BIO_FLUSH: 30642461fbaSPawel Jakub Dawidek g_concat_flush(sc, bp); 30742461fbaSPawel Jakub Dawidek return; 30819d16e2fSPawel Jakub Dawidek case BIO_GETATTR: 309659f684eSAlexander Motin if (strcmp("GEOM::kerneldump", bp->bio_attribute) == 0) { 310659f684eSAlexander Motin g_concat_kernel_dump(bp); 311659f684eSAlexander Motin return; 312659f684eSAlexander Motin } 31319d16e2fSPawel Jakub Dawidek /* To which provider it should be delivered? */ 314659f684eSAlexander Motin /* FALLTHROUGH */ 31519d16e2fSPawel Jakub Dawidek default: 31619d16e2fSPawel Jakub Dawidek g_io_deliver(bp, EOPNOTSUPP); 31719d16e2fSPawel Jakub Dawidek return; 31819d16e2fSPawel Jakub Dawidek } 31919d16e2fSPawel Jakub Dawidek 32019d16e2fSPawel Jakub Dawidek offset = bp->bio_offset; 32119d16e2fSPawel Jakub Dawidek length = bp->bio_length; 32219d16e2fSPawel Jakub Dawidek addr = bp->bio_data; 32319d16e2fSPawel Jakub Dawidek end = offset + length; 32419d16e2fSPawel Jakub Dawidek 3257e0b3120SPawel Jakub Dawidek bioq_init(&queue); 32619d16e2fSPawel Jakub Dawidek for (no = 0; no < sc->sc_ndisks; no++) { 32719d16e2fSPawel Jakub Dawidek disk = &sc->sc_disks[no]; 32819d16e2fSPawel Jakub Dawidek if (disk->d_end <= offset) 32919d16e2fSPawel Jakub Dawidek continue; 33019d16e2fSPawel Jakub Dawidek if (disk->d_start >= end) 33119d16e2fSPawel Jakub Dawidek break; 33219d16e2fSPawel Jakub Dawidek 33319d16e2fSPawel Jakub Dawidek off = offset - disk->d_start; 33419d16e2fSPawel Jakub Dawidek len = MIN(length, disk->d_end - offset); 33519d16e2fSPawel Jakub Dawidek length -= len; 33619d16e2fSPawel Jakub Dawidek offset += len; 33719d16e2fSPawel Jakub Dawidek 33819d16e2fSPawel Jakub Dawidek cbp = g_clone_bio(bp); 33919d16e2fSPawel Jakub Dawidek if (cbp == NULL) { 3407e0b3120SPawel Jakub Dawidek for (cbp = bioq_first(&queue); cbp != NULL; 3417e0b3120SPawel Jakub Dawidek cbp = bioq_first(&queue)) { 3427e0b3120SPawel Jakub Dawidek bioq_remove(&queue, cbp); 3437e0b3120SPawel Jakub Dawidek g_destroy_bio(cbp); 3447e0b3120SPawel Jakub Dawidek } 34519d16e2fSPawel Jakub Dawidek if (bp->bio_error == 0) 34619d16e2fSPawel Jakub Dawidek bp->bio_error = ENOMEM; 3477e0b3120SPawel Jakub Dawidek g_io_deliver(bp, bp->bio_error); 34819d16e2fSPawel Jakub Dawidek return; 34919d16e2fSPawel Jakub Dawidek } 3507e0b3120SPawel Jakub Dawidek bioq_insert_tail(&queue, cbp); 35119d16e2fSPawel Jakub Dawidek /* 35219d16e2fSPawel Jakub Dawidek * Fill in the component buf structure. 35319d16e2fSPawel Jakub Dawidek */ 35419d16e2fSPawel Jakub Dawidek cbp->bio_done = g_std_done; 35519d16e2fSPawel Jakub Dawidek cbp->bio_offset = off; 35619d16e2fSPawel Jakub Dawidek cbp->bio_data = addr; 35719d16e2fSPawel Jakub Dawidek addr += len; 35819d16e2fSPawel Jakub Dawidek cbp->bio_length = len; 35919d16e2fSPawel Jakub Dawidek cbp->bio_to = disk->d_consumer->provider; 3607e0b3120SPawel Jakub Dawidek cbp->bio_caller1 = disk; 36119d16e2fSPawel Jakub Dawidek 36219d16e2fSPawel Jakub Dawidek if (length == 0) 36319d16e2fSPawel Jakub Dawidek break; 36419d16e2fSPawel Jakub Dawidek } 36519d16e2fSPawel Jakub Dawidek KASSERT(length == 0, 36619d16e2fSPawel Jakub Dawidek ("Length is still greater than 0 (class=%s, name=%s).", 36719d16e2fSPawel Jakub Dawidek bp->bio_to->geom->class->name, bp->bio_to->geom->name)); 3687e0b3120SPawel Jakub Dawidek for (cbp = bioq_first(&queue); cbp != NULL; cbp = bioq_first(&queue)) { 3697e0b3120SPawel Jakub Dawidek bioq_remove(&queue, cbp); 3707e0b3120SPawel Jakub Dawidek G_CONCAT_LOGREQ(cbp, "Sending request."); 3717e0b3120SPawel Jakub Dawidek disk = cbp->bio_caller1; 3727e0b3120SPawel Jakub Dawidek cbp->bio_caller1 = NULL; 3737e0b3120SPawel Jakub Dawidek g_io_request(cbp, disk->d_consumer); 3747e0b3120SPawel Jakub Dawidek } 37519d16e2fSPawel Jakub Dawidek } 37619d16e2fSPawel Jakub Dawidek 37719d16e2fSPawel Jakub Dawidek static void 37819d16e2fSPawel Jakub Dawidek g_concat_check_and_run(struct g_concat_softc *sc) 37919d16e2fSPawel Jakub Dawidek { 38019d16e2fSPawel Jakub Dawidek struct g_concat_disk *disk; 3815f9b1143SAlexander Motin struct g_provider *pp; 38248fbd94bSPawel Jakub Dawidek u_int no, sectorsize = 0; 38319d16e2fSPawel Jakub Dawidek off_t start; 38419d16e2fSPawel Jakub Dawidek 385*df96fd6eSAlexander Motin g_topology_assert(); 38619d16e2fSPawel Jakub Dawidek if (g_concat_nvalid(sc) != sc->sc_ndisks) 38719d16e2fSPawel Jakub Dawidek return; 38819d16e2fSPawel Jakub Dawidek 3895f9b1143SAlexander Motin pp = g_new_providerf(sc->sc_geom, "concat/%s", sc->sc_name); 39019d16e2fSPawel Jakub Dawidek start = 0; 39119d16e2fSPawel Jakub Dawidek for (no = 0; no < sc->sc_ndisks; no++) { 39219d16e2fSPawel Jakub Dawidek disk = &sc->sc_disks[no]; 39319d16e2fSPawel Jakub Dawidek disk->d_start = start; 39419d16e2fSPawel Jakub Dawidek disk->d_end = disk->d_start + 39519d16e2fSPawel Jakub Dawidek disk->d_consumer->provider->mediasize; 39619d16e2fSPawel Jakub Dawidek if (sc->sc_type == G_CONCAT_TYPE_AUTOMATIC) 39719d16e2fSPawel Jakub Dawidek disk->d_end -= disk->d_consumer->provider->sectorsize; 39819d16e2fSPawel Jakub Dawidek start = disk->d_end; 39948fbd94bSPawel Jakub Dawidek if (no == 0) 40048fbd94bSPawel Jakub Dawidek sectorsize = disk->d_consumer->provider->sectorsize; 40148fbd94bSPawel Jakub Dawidek else { 40248fbd94bSPawel Jakub Dawidek sectorsize = lcm(sectorsize, 40348fbd94bSPawel Jakub Dawidek disk->d_consumer->provider->sectorsize); 40419d16e2fSPawel Jakub Dawidek } 40548fbd94bSPawel Jakub Dawidek } 4065f9b1143SAlexander Motin pp->sectorsize = sectorsize; 40719d16e2fSPawel Jakub Dawidek /* We have sc->sc_disks[sc->sc_ndisks - 1].d_end in 'start'. */ 4085f9b1143SAlexander Motin pp->mediasize = start; 4095f9b1143SAlexander Motin pp->stripesize = sc->sc_disks[0].d_consumer->provider->stripesize; 4105f9b1143SAlexander Motin pp->stripeoffset = sc->sc_disks[0].d_consumer->provider->stripeoffset; 4115f9b1143SAlexander Motin sc->sc_provider = pp; 4125f9b1143SAlexander Motin g_error_provider(pp, 0); 41319d16e2fSPawel Jakub Dawidek 414*df96fd6eSAlexander Motin G_CONCAT_DEBUG(0, "Device %s activated.", sc->sc_provider->name); 41519d16e2fSPawel Jakub Dawidek } 41619d16e2fSPawel Jakub Dawidek 41719d16e2fSPawel Jakub Dawidek static int 41819d16e2fSPawel Jakub Dawidek g_concat_read_metadata(struct g_consumer *cp, struct g_concat_metadata *md) 41919d16e2fSPawel Jakub Dawidek { 42019d16e2fSPawel Jakub Dawidek struct g_provider *pp; 42119d16e2fSPawel Jakub Dawidek u_char *buf; 42219d16e2fSPawel Jakub Dawidek int error; 42319d16e2fSPawel Jakub Dawidek 42419d16e2fSPawel Jakub Dawidek g_topology_assert(); 42519d16e2fSPawel Jakub Dawidek 42619d16e2fSPawel Jakub Dawidek error = g_access(cp, 1, 0, 0); 42719d16e2fSPawel Jakub Dawidek if (error != 0) 42819d16e2fSPawel Jakub Dawidek return (error); 42919d16e2fSPawel Jakub Dawidek pp = cp->provider; 43019d16e2fSPawel Jakub Dawidek g_topology_unlock(); 43119d16e2fSPawel Jakub Dawidek buf = g_read_data(cp, pp->mediasize - pp->sectorsize, pp->sectorsize, 43219d16e2fSPawel Jakub Dawidek &error); 43319d16e2fSPawel Jakub Dawidek g_topology_lock(); 43419d16e2fSPawel Jakub Dawidek g_access(cp, -1, 0, 0); 43519d16e2fSPawel Jakub Dawidek if (buf == NULL) 43619d16e2fSPawel Jakub Dawidek return (error); 43719d16e2fSPawel Jakub Dawidek 43819d16e2fSPawel Jakub Dawidek /* Decode metadata. */ 43919d16e2fSPawel Jakub Dawidek concat_metadata_decode(buf, md); 44019d16e2fSPawel Jakub Dawidek g_free(buf); 44119d16e2fSPawel Jakub Dawidek 44219d16e2fSPawel Jakub Dawidek return (0); 44319d16e2fSPawel Jakub Dawidek } 44419d16e2fSPawel Jakub Dawidek 44519d16e2fSPawel Jakub Dawidek /* 44619d16e2fSPawel Jakub Dawidek * Add disk to given device. 44719d16e2fSPawel Jakub Dawidek */ 44819d16e2fSPawel Jakub Dawidek static int 44919d16e2fSPawel Jakub Dawidek g_concat_add_disk(struct g_concat_softc *sc, struct g_provider *pp, u_int no) 45019d16e2fSPawel Jakub Dawidek { 45119d16e2fSPawel Jakub Dawidek struct g_concat_disk *disk; 45202637cdcSPawel Jakub Dawidek struct g_consumer *cp, *fcp; 45319d16e2fSPawel Jakub Dawidek struct g_geom *gp; 45419d16e2fSPawel Jakub Dawidek int error; 45519d16e2fSPawel Jakub Dawidek 456*df96fd6eSAlexander Motin g_topology_assert(); 45719d16e2fSPawel Jakub Dawidek /* Metadata corrupted? */ 45819d16e2fSPawel Jakub Dawidek if (no >= sc->sc_ndisks) 45919d16e2fSPawel Jakub Dawidek return (EINVAL); 46019d16e2fSPawel Jakub Dawidek 46119d16e2fSPawel Jakub Dawidek disk = &sc->sc_disks[no]; 46219d16e2fSPawel Jakub Dawidek /* Check if disk is not already attached. */ 463a88ae49fSPawel Jakub Dawidek if (disk->d_consumer != NULL) 46419d16e2fSPawel Jakub Dawidek return (EEXIST); 46519d16e2fSPawel Jakub Dawidek 46602637cdcSPawel Jakub Dawidek gp = sc->sc_geom; 46702637cdcSPawel Jakub Dawidek fcp = LIST_FIRST(&gp->consumer); 46819d16e2fSPawel Jakub Dawidek 46919d16e2fSPawel Jakub Dawidek cp = g_new_consumer(gp); 47019d16e2fSPawel Jakub Dawidek error = g_attach(cp, pp); 47119d16e2fSPawel Jakub Dawidek if (error != 0) { 47219d16e2fSPawel Jakub Dawidek g_destroy_consumer(cp); 47319d16e2fSPawel Jakub Dawidek return (error); 47419d16e2fSPawel Jakub Dawidek } 47519d16e2fSPawel Jakub Dawidek 47602637cdcSPawel Jakub Dawidek if (fcp != NULL && (fcp->acr > 0 || fcp->acw > 0 || fcp->ace > 0)) { 47702637cdcSPawel Jakub Dawidek error = g_access(cp, fcp->acr, fcp->acw, fcp->ace); 47819d16e2fSPawel Jakub Dawidek if (error != 0) { 47919d16e2fSPawel Jakub Dawidek g_detach(cp); 48019d16e2fSPawel Jakub Dawidek g_destroy_consumer(cp); 48119d16e2fSPawel Jakub Dawidek return (error); 48219d16e2fSPawel Jakub Dawidek } 48319d16e2fSPawel Jakub Dawidek } 48419d16e2fSPawel Jakub Dawidek if (sc->sc_type == G_CONCAT_TYPE_AUTOMATIC) { 48519d16e2fSPawel Jakub Dawidek struct g_concat_metadata md; 48619d16e2fSPawel Jakub Dawidek 48748fbd94bSPawel Jakub Dawidek /* Re-read metadata. */ 48819d16e2fSPawel Jakub Dawidek error = g_concat_read_metadata(cp, &md); 48919d16e2fSPawel Jakub Dawidek if (error != 0) 49019d16e2fSPawel Jakub Dawidek goto fail; 49119d16e2fSPawel Jakub Dawidek 49219d16e2fSPawel Jakub Dawidek if (strcmp(md.md_magic, G_CONCAT_MAGIC) != 0 || 49319d16e2fSPawel Jakub Dawidek strcmp(md.md_name, sc->sc_name) != 0 || 49419d16e2fSPawel Jakub Dawidek md.md_id != sc->sc_id) { 49519d16e2fSPawel Jakub Dawidek G_CONCAT_DEBUG(0, "Metadata on %s changed.", pp->name); 49619d16e2fSPawel Jakub Dawidek goto fail; 49719d16e2fSPawel Jakub Dawidek } 49819d16e2fSPawel Jakub Dawidek } 49919d16e2fSPawel Jakub Dawidek 50019d16e2fSPawel Jakub Dawidek cp->private = disk; 50119d16e2fSPawel Jakub Dawidek disk->d_consumer = cp; 50219d16e2fSPawel Jakub Dawidek disk->d_softc = sc; 50319d16e2fSPawel Jakub Dawidek disk->d_start = 0; /* not yet */ 50419d16e2fSPawel Jakub Dawidek disk->d_end = 0; /* not yet */ 505*df96fd6eSAlexander Motin disk->d_removed = 0; 50619d16e2fSPawel Jakub Dawidek 507ba385d00SPawel Jakub Dawidek G_CONCAT_DEBUG(0, "Disk %s attached to %s.", pp->name, sc->sc_name); 50819d16e2fSPawel Jakub Dawidek 50919d16e2fSPawel Jakub Dawidek g_concat_check_and_run(sc); 51019d16e2fSPawel Jakub Dawidek 51119d16e2fSPawel Jakub Dawidek return (0); 51219d16e2fSPawel Jakub Dawidek fail: 51302637cdcSPawel Jakub Dawidek if (fcp != NULL && (fcp->acr > 0 || fcp->acw > 0 || fcp->ace > 0)) 51402637cdcSPawel Jakub Dawidek g_access(cp, -fcp->acr, -fcp->acw, -fcp->ace); 51519d16e2fSPawel Jakub Dawidek g_detach(cp); 51619d16e2fSPawel Jakub Dawidek g_destroy_consumer(cp); 51719d16e2fSPawel Jakub Dawidek return (error); 51819d16e2fSPawel Jakub Dawidek } 51919d16e2fSPawel Jakub Dawidek 52019d16e2fSPawel Jakub Dawidek static struct g_geom * 52119d16e2fSPawel Jakub Dawidek g_concat_create(struct g_class *mp, const struct g_concat_metadata *md, 52248fbd94bSPawel Jakub Dawidek u_int type) 52319d16e2fSPawel Jakub Dawidek { 52419d16e2fSPawel Jakub Dawidek struct g_concat_softc *sc; 52519d16e2fSPawel Jakub Dawidek struct g_geom *gp; 52619d16e2fSPawel Jakub Dawidek u_int no; 52719d16e2fSPawel Jakub Dawidek 528ba385d00SPawel Jakub Dawidek G_CONCAT_DEBUG(1, "Creating device %s (id=%u).", md->md_name, 52919d16e2fSPawel Jakub Dawidek md->md_id); 53019d16e2fSPawel Jakub Dawidek 531aaf8e186SPawel Jakub Dawidek /* One disks is minimum. */ 532aaf8e186SPawel Jakub Dawidek if (md->md_all < 1) 53319d16e2fSPawel Jakub Dawidek return (NULL); 53419d16e2fSPawel Jakub Dawidek 53519d16e2fSPawel Jakub Dawidek /* Check for duplicate unit */ 53619d16e2fSPawel Jakub Dawidek LIST_FOREACH(gp, &mp->geom, geom) { 53719d16e2fSPawel Jakub Dawidek sc = gp->softc; 53819d16e2fSPawel Jakub Dawidek if (sc != NULL && strcmp(sc->sc_name, md->md_name) == 0) { 53902637cdcSPawel Jakub Dawidek G_CONCAT_DEBUG(0, "Device %s already configured.", 54019d16e2fSPawel Jakub Dawidek gp->name); 54119d16e2fSPawel Jakub Dawidek return (NULL); 54219d16e2fSPawel Jakub Dawidek } 54319d16e2fSPawel Jakub Dawidek } 544ba385d00SPawel Jakub Dawidek gp = g_new_geomf(mp, "%s", md->md_name); 54575cc259dSPawel Jakub Dawidek sc = malloc(sizeof(*sc), M_CONCAT, M_WAITOK | M_ZERO); 54619d16e2fSPawel Jakub Dawidek gp->start = g_concat_start; 54719d16e2fSPawel Jakub Dawidek gp->spoiled = g_concat_orphan; 54819d16e2fSPawel Jakub Dawidek gp->orphan = g_concat_orphan; 54919d16e2fSPawel Jakub Dawidek gp->access = g_concat_access; 55019d16e2fSPawel Jakub Dawidek gp->dumpconf = g_concat_dumpconf; 55119d16e2fSPawel Jakub Dawidek 55219d16e2fSPawel Jakub Dawidek sc->sc_id = md->md_id; 55319d16e2fSPawel Jakub Dawidek sc->sc_ndisks = md->md_all; 55419d16e2fSPawel Jakub Dawidek sc->sc_disks = malloc(sizeof(struct g_concat_disk) * sc->sc_ndisks, 55519d16e2fSPawel Jakub Dawidek M_CONCAT, M_WAITOK | M_ZERO); 55619d16e2fSPawel Jakub Dawidek for (no = 0; no < sc->sc_ndisks; no++) 557a88ae49fSPawel Jakub Dawidek sc->sc_disks[no].d_consumer = NULL; 55819d16e2fSPawel Jakub Dawidek sc->sc_type = type; 55919d16e2fSPawel Jakub Dawidek 56019d16e2fSPawel Jakub Dawidek gp->softc = sc; 56102637cdcSPawel Jakub Dawidek sc->sc_geom = gp; 56202637cdcSPawel Jakub Dawidek sc->sc_provider = NULL; 56319d16e2fSPawel Jakub Dawidek 564ba385d00SPawel Jakub Dawidek G_CONCAT_DEBUG(0, "Device %s created (id=%u).", sc->sc_name, sc->sc_id); 56519d16e2fSPawel Jakub Dawidek 56619d16e2fSPawel Jakub Dawidek return (gp); 56719d16e2fSPawel Jakub Dawidek } 56819d16e2fSPawel Jakub Dawidek 56919d16e2fSPawel Jakub Dawidek static int 57019d16e2fSPawel Jakub Dawidek g_concat_destroy(struct g_concat_softc *sc, boolean_t force) 57119d16e2fSPawel Jakub Dawidek { 57219d16e2fSPawel Jakub Dawidek struct g_provider *pp; 573*df96fd6eSAlexander Motin struct g_consumer *cp, *cp1; 57419d16e2fSPawel Jakub Dawidek struct g_geom *gp; 57519d16e2fSPawel Jakub Dawidek 57619d16e2fSPawel Jakub Dawidek g_topology_assert(); 57719d16e2fSPawel Jakub Dawidek 57819d16e2fSPawel Jakub Dawidek if (sc == NULL) 57919d16e2fSPawel Jakub Dawidek return (ENXIO); 58019d16e2fSPawel Jakub Dawidek 58119d16e2fSPawel Jakub Dawidek pp = sc->sc_provider; 58202637cdcSPawel Jakub Dawidek if (pp != NULL && (pp->acr != 0 || pp->acw != 0 || pp->ace != 0)) { 58319d16e2fSPawel Jakub Dawidek if (force) { 58419d16e2fSPawel Jakub Dawidek G_CONCAT_DEBUG(0, "Device %s is still open, so it " 58502637cdcSPawel Jakub Dawidek "can't be definitely removed.", pp->name); 58619d16e2fSPawel Jakub Dawidek } else { 58719d16e2fSPawel Jakub Dawidek G_CONCAT_DEBUG(1, 58802637cdcSPawel Jakub Dawidek "Device %s is still open (r%dw%de%d).", pp->name, 58902637cdcSPawel Jakub Dawidek pp->acr, pp->acw, pp->ace); 59019d16e2fSPawel Jakub Dawidek return (EBUSY); 59119d16e2fSPawel Jakub Dawidek } 59219d16e2fSPawel Jakub Dawidek } 59319d16e2fSPawel Jakub Dawidek 59402637cdcSPawel Jakub Dawidek gp = sc->sc_geom; 595*df96fd6eSAlexander Motin LIST_FOREACH_SAFE(cp, &gp->consumer, consumer, cp1) { 596*df96fd6eSAlexander Motin g_concat_remove_disk(cp->private); 597*df96fd6eSAlexander Motin if (cp1 == NULL) 598*df96fd6eSAlexander Motin return (0); /* Recursion happened. */ 599*df96fd6eSAlexander Motin } 600*df96fd6eSAlexander Motin if (!LIST_EMPTY(&gp->consumer)) 601*df96fd6eSAlexander Motin return (EINPROGRESS); 602*df96fd6eSAlexander Motin 60319d16e2fSPawel Jakub Dawidek gp->softc = NULL; 60402637cdcSPawel Jakub Dawidek KASSERT(sc->sc_provider == NULL, ("Provider still exists? (device=%s)", 60502637cdcSPawel Jakub Dawidek gp->name)); 60619d16e2fSPawel Jakub Dawidek free(sc->sc_disks, M_CONCAT); 60719d16e2fSPawel Jakub Dawidek free(sc, M_CONCAT); 60819d16e2fSPawel Jakub Dawidek 60902637cdcSPawel Jakub Dawidek G_CONCAT_DEBUG(0, "Device %s destroyed.", gp->name); 61019d16e2fSPawel Jakub Dawidek g_wither_geom(gp, ENXIO); 61119d16e2fSPawel Jakub Dawidek return (0); 61219d16e2fSPawel Jakub Dawidek } 61319d16e2fSPawel Jakub Dawidek 61419d16e2fSPawel Jakub Dawidek static int 61548fbd94bSPawel Jakub Dawidek g_concat_destroy_geom(struct gctl_req *req __unused, 61648fbd94bSPawel Jakub Dawidek struct g_class *mp __unused, struct g_geom *gp) 61719d16e2fSPawel Jakub Dawidek { 61819d16e2fSPawel Jakub Dawidek struct g_concat_softc *sc; 61919d16e2fSPawel Jakub Dawidek 62019d16e2fSPawel Jakub Dawidek sc = gp->softc; 62119d16e2fSPawel Jakub Dawidek return (g_concat_destroy(sc, 0)); 62219d16e2fSPawel Jakub Dawidek } 62319d16e2fSPawel Jakub Dawidek 62419d16e2fSPawel Jakub Dawidek static struct g_geom * 62519d16e2fSPawel Jakub Dawidek g_concat_taste(struct g_class *mp, struct g_provider *pp, int flags __unused) 62619d16e2fSPawel Jakub Dawidek { 62719d16e2fSPawel Jakub Dawidek struct g_concat_metadata md; 62819d16e2fSPawel Jakub Dawidek struct g_concat_softc *sc; 62919d16e2fSPawel Jakub Dawidek struct g_consumer *cp; 63019d16e2fSPawel Jakub Dawidek struct g_geom *gp; 63119d16e2fSPawel Jakub Dawidek int error; 63219d16e2fSPawel Jakub Dawidek 63302637cdcSPawel Jakub Dawidek g_trace(G_T_TOPOLOGY, "%s(%s, %s)", __func__, mp->name, pp->name); 63419d16e2fSPawel Jakub Dawidek g_topology_assert(); 63519d16e2fSPawel Jakub Dawidek 636f8727e71SPawel Jakub Dawidek /* Skip providers that are already open for writing. */ 637f8727e71SPawel Jakub Dawidek if (pp->acw > 0) 638f8727e71SPawel Jakub Dawidek return (NULL); 639f8727e71SPawel Jakub Dawidek 64019d16e2fSPawel Jakub Dawidek G_CONCAT_DEBUG(3, "Tasting %s.", pp->name); 64119d16e2fSPawel Jakub Dawidek 64219d16e2fSPawel Jakub Dawidek gp = g_new_geomf(mp, "concat:taste"); 64319d16e2fSPawel Jakub Dawidek gp->start = g_concat_start; 64419d16e2fSPawel Jakub Dawidek gp->access = g_concat_access; 6450e2ff283SPawel Jakub Dawidek gp->orphan = g_concat_orphan; 64619d16e2fSPawel Jakub Dawidek cp = g_new_consumer(gp); 64719d16e2fSPawel Jakub Dawidek g_attach(cp, pp); 64819d16e2fSPawel Jakub Dawidek error = g_concat_read_metadata(cp, &md); 6497e72a708SPawel Jakub Dawidek g_detach(cp); 6507e72a708SPawel Jakub Dawidek g_destroy_consumer(cp); 6517e72a708SPawel Jakub Dawidek g_destroy_geom(gp); 65202637cdcSPawel Jakub Dawidek if (error != 0) 65319d16e2fSPawel Jakub Dawidek return (NULL); 65419d16e2fSPawel Jakub Dawidek gp = NULL; 65519d16e2fSPawel Jakub Dawidek 65619d16e2fSPawel Jakub Dawidek if (strcmp(md.md_magic, G_CONCAT_MAGIC) != 0) 65719d16e2fSPawel Jakub Dawidek return (NULL); 65819d16e2fSPawel Jakub Dawidek if (md.md_version > G_CONCAT_VERSION) { 65919d16e2fSPawel Jakub Dawidek printf("geom_concat.ko module is too old to handle %s.\n", 66019d16e2fSPawel Jakub Dawidek pp->name); 66119d16e2fSPawel Jakub Dawidek return (NULL); 66219d16e2fSPawel Jakub Dawidek } 6636c74f517SPawel Jakub Dawidek /* 6646c74f517SPawel Jakub Dawidek * Backward compatibility: 6656c74f517SPawel Jakub Dawidek */ 666e6890985SPawel Jakub Dawidek /* There was no md_provider field in earlier versions of metadata. */ 6676c74f517SPawel Jakub Dawidek if (md.md_version < 3) 6686c74f517SPawel Jakub Dawidek bzero(md.md_provider, sizeof(md.md_provider)); 669e6890985SPawel Jakub Dawidek /* There was no md_provsize field in earlier versions of metadata. */ 670e6890985SPawel Jakub Dawidek if (md.md_version < 4) 671e6890985SPawel Jakub Dawidek md.md_provsize = pp->mediasize; 6726c74f517SPawel Jakub Dawidek 67390f2be24SAlexander Motin if (md.md_provider[0] != '\0' && 67490f2be24SAlexander Motin !g_compare_names(md.md_provider, pp->name)) 6756c74f517SPawel Jakub Dawidek return (NULL); 676e6890985SPawel Jakub Dawidek if (md.md_provsize != pp->mediasize) 677e6890985SPawel Jakub Dawidek return (NULL); 67819d16e2fSPawel Jakub Dawidek 67919d16e2fSPawel Jakub Dawidek /* 68019d16e2fSPawel Jakub Dawidek * Let's check if device already exists. 68119d16e2fSPawel Jakub Dawidek */ 682c2496c87SPawel Jakub Dawidek sc = NULL; 68319d16e2fSPawel Jakub Dawidek LIST_FOREACH(gp, &mp->geom, geom) { 68419d16e2fSPawel Jakub Dawidek sc = gp->softc; 68519d16e2fSPawel Jakub Dawidek if (sc == NULL) 68619d16e2fSPawel Jakub Dawidek continue; 68719d16e2fSPawel Jakub Dawidek if (sc->sc_type != G_CONCAT_TYPE_AUTOMATIC) 68819d16e2fSPawel Jakub Dawidek continue; 68919d16e2fSPawel Jakub Dawidek if (strcmp(md.md_name, sc->sc_name) != 0) 69019d16e2fSPawel Jakub Dawidek continue; 69119d16e2fSPawel Jakub Dawidek if (md.md_id != sc->sc_id) 69219d16e2fSPawel Jakub Dawidek continue; 69319d16e2fSPawel Jakub Dawidek break; 69419d16e2fSPawel Jakub Dawidek } 69519d16e2fSPawel Jakub Dawidek if (gp != NULL) { 69619d16e2fSPawel Jakub Dawidek G_CONCAT_DEBUG(1, "Adding disk %s to %s.", pp->name, gp->name); 69719d16e2fSPawel Jakub Dawidek error = g_concat_add_disk(sc, pp, md.md_no); 69819d16e2fSPawel Jakub Dawidek if (error != 0) { 69902637cdcSPawel Jakub Dawidek G_CONCAT_DEBUG(0, 70002637cdcSPawel Jakub Dawidek "Cannot add disk %s to %s (error=%d).", pp->name, 70102637cdcSPawel Jakub Dawidek gp->name, error); 70219d16e2fSPawel Jakub Dawidek return (NULL); 70319d16e2fSPawel Jakub Dawidek } 70419d16e2fSPawel Jakub Dawidek } else { 70548fbd94bSPawel Jakub Dawidek gp = g_concat_create(mp, &md, G_CONCAT_TYPE_AUTOMATIC); 70619d16e2fSPawel Jakub Dawidek if (gp == NULL) { 707ba385d00SPawel Jakub Dawidek G_CONCAT_DEBUG(0, "Cannot create device %s.", 70819d16e2fSPawel Jakub Dawidek md.md_name); 70919d16e2fSPawel Jakub Dawidek return (NULL); 71019d16e2fSPawel Jakub Dawidek } 71119d16e2fSPawel Jakub Dawidek sc = gp->softc; 71219d16e2fSPawel Jakub Dawidek G_CONCAT_DEBUG(1, "Adding disk %s to %s.", pp->name, gp->name); 71319d16e2fSPawel Jakub Dawidek error = g_concat_add_disk(sc, pp, md.md_no); 71419d16e2fSPawel Jakub Dawidek if (error != 0) { 71502637cdcSPawel Jakub Dawidek G_CONCAT_DEBUG(0, 71602637cdcSPawel Jakub Dawidek "Cannot add disk %s to %s (error=%d).", pp->name, 71702637cdcSPawel Jakub Dawidek gp->name, error); 71819d16e2fSPawel Jakub Dawidek g_concat_destroy(sc, 1); 71919d16e2fSPawel Jakub Dawidek return (NULL); 72019d16e2fSPawel Jakub Dawidek } 72119d16e2fSPawel Jakub Dawidek } 72219d16e2fSPawel Jakub Dawidek 72319d16e2fSPawel Jakub Dawidek return (gp); 72419d16e2fSPawel Jakub Dawidek } 72519d16e2fSPawel Jakub Dawidek 72619d16e2fSPawel Jakub Dawidek static void 72719d16e2fSPawel Jakub Dawidek g_concat_ctl_create(struct gctl_req *req, struct g_class *mp) 72819d16e2fSPawel Jakub Dawidek { 72919d16e2fSPawel Jakub Dawidek u_int attached, no; 73002637cdcSPawel Jakub Dawidek struct g_concat_metadata md; 73119d16e2fSPawel Jakub Dawidek struct g_provider *pp; 73219d16e2fSPawel Jakub Dawidek struct g_concat_softc *sc; 73319d16e2fSPawel Jakub Dawidek struct g_geom *gp; 73419d16e2fSPawel Jakub Dawidek struct sbuf *sb; 73502637cdcSPawel Jakub Dawidek const char *name; 73602637cdcSPawel Jakub Dawidek char param[16]; 73702637cdcSPawel Jakub Dawidek int *nargs; 73819d16e2fSPawel Jakub Dawidek 73919d16e2fSPawel Jakub Dawidek g_topology_assert(); 74002637cdcSPawel Jakub Dawidek nargs = gctl_get_paraml(req, "nargs", sizeof(*nargs)); 74102637cdcSPawel Jakub Dawidek if (nargs == NULL) { 74202637cdcSPawel Jakub Dawidek gctl_error(req, "No '%s' argument.", "nargs"); 74319d16e2fSPawel Jakub Dawidek return; 74419d16e2fSPawel Jakub Dawidek } 745aaf8e186SPawel Jakub Dawidek if (*nargs < 2) { 74602637cdcSPawel Jakub Dawidek gctl_error(req, "Too few arguments."); 74719d16e2fSPawel Jakub Dawidek return; 74819d16e2fSPawel Jakub Dawidek } 74919d16e2fSPawel Jakub Dawidek 75002637cdcSPawel Jakub Dawidek strlcpy(md.md_magic, G_CONCAT_MAGIC, sizeof(md.md_magic)); 75102637cdcSPawel Jakub Dawidek md.md_version = G_CONCAT_VERSION; 75202637cdcSPawel Jakub Dawidek name = gctl_get_asciiparam(req, "arg0"); 75302637cdcSPawel Jakub Dawidek if (name == NULL) { 75402637cdcSPawel Jakub Dawidek gctl_error(req, "No 'arg%u' argument.", 0); 75502637cdcSPawel Jakub Dawidek return; 75602637cdcSPawel Jakub Dawidek } 75702637cdcSPawel Jakub Dawidek strlcpy(md.md_name, name, sizeof(md.md_name)); 75802637cdcSPawel Jakub Dawidek md.md_id = arc4random(); 75902637cdcSPawel Jakub Dawidek md.md_no = 0; 76002637cdcSPawel Jakub Dawidek md.md_all = *nargs - 1; 7616c74f517SPawel Jakub Dawidek bzero(md.md_provider, sizeof(md.md_provider)); 762e6890985SPawel Jakub Dawidek /* This field is not important here. */ 763e6890985SPawel Jakub Dawidek md.md_provsize = 0; 76402637cdcSPawel Jakub Dawidek 76519d16e2fSPawel Jakub Dawidek /* Check all providers are valid */ 76602637cdcSPawel Jakub Dawidek for (no = 1; no < *nargs; no++) { 76702637cdcSPawel Jakub Dawidek snprintf(param, sizeof(param), "arg%u", no); 76802637cdcSPawel Jakub Dawidek name = gctl_get_asciiparam(req, param); 76902637cdcSPawel Jakub Dawidek if (name == NULL) { 77002637cdcSPawel Jakub Dawidek gctl_error(req, "No 'arg%u' argument.", no); 77102637cdcSPawel Jakub Dawidek return; 77202637cdcSPawel Jakub Dawidek } 77302637cdcSPawel Jakub Dawidek if (strncmp(name, "/dev/", strlen("/dev/")) == 0) 77402637cdcSPawel Jakub Dawidek name += strlen("/dev/"); 77502637cdcSPawel Jakub Dawidek pp = g_provider_by_name(name); 77619d16e2fSPawel Jakub Dawidek if (pp == NULL) { 77702637cdcSPawel Jakub Dawidek G_CONCAT_DEBUG(1, "Disk %s is invalid.", name); 77802637cdcSPawel Jakub Dawidek gctl_error(req, "Disk %s is invalid.", name); 77919d16e2fSPawel Jakub Dawidek return; 78019d16e2fSPawel Jakub Dawidek } 78119d16e2fSPawel Jakub Dawidek } 78219d16e2fSPawel Jakub Dawidek 78302637cdcSPawel Jakub Dawidek gp = g_concat_create(mp, &md, G_CONCAT_TYPE_MANUAL); 78419d16e2fSPawel Jakub Dawidek if (gp == NULL) { 785ba385d00SPawel Jakub Dawidek gctl_error(req, "Can't configure %s.", md.md_name); 78619d16e2fSPawel Jakub Dawidek return; 78719d16e2fSPawel Jakub Dawidek } 78819d16e2fSPawel Jakub Dawidek 78919d16e2fSPawel Jakub Dawidek sc = gp->softc; 7902616144eSDag-Erling Smørgrav sb = sbuf_new_auto(); 79119d16e2fSPawel Jakub Dawidek sbuf_printf(sb, "Can't attach disk(s) to %s:", gp->name); 79202637cdcSPawel Jakub Dawidek for (attached = 0, no = 1; no < *nargs; no++) { 79302637cdcSPawel Jakub Dawidek snprintf(param, sizeof(param), "arg%u", no); 79402637cdcSPawel Jakub Dawidek name = gctl_get_asciiparam(req, param); 795916cd41cSEdward Tomasz Napierala if (name == NULL) { 796916cd41cSEdward Tomasz Napierala gctl_error(req, "No 'arg%d' argument.", no); 797916cd41cSEdward Tomasz Napierala return; 798916cd41cSEdward Tomasz Napierala } 79902637cdcSPawel Jakub Dawidek if (strncmp(name, "/dev/", strlen("/dev/")) == 0) 80002637cdcSPawel Jakub Dawidek name += strlen("/dev/"); 80102637cdcSPawel Jakub Dawidek pp = g_provider_by_name(name); 80202637cdcSPawel Jakub Dawidek KASSERT(pp != NULL, ("Provider %s disappear?!", name)); 80302637cdcSPawel Jakub Dawidek if (g_concat_add_disk(sc, pp, no - 1) != 0) { 80419d16e2fSPawel Jakub Dawidek G_CONCAT_DEBUG(1, "Disk %u (%s) not attached to %s.", 80502637cdcSPawel Jakub Dawidek no, pp->name, gp->name); 80619d16e2fSPawel Jakub Dawidek sbuf_printf(sb, " %s", pp->name); 80719d16e2fSPawel Jakub Dawidek continue; 80819d16e2fSPawel Jakub Dawidek } 80919d16e2fSPawel Jakub Dawidek attached++; 81019d16e2fSPawel Jakub Dawidek } 81119d16e2fSPawel Jakub Dawidek sbuf_finish(sb); 81202637cdcSPawel Jakub Dawidek if (md.md_all != attached) { 81319d16e2fSPawel Jakub Dawidek g_concat_destroy(gp->softc, 1); 81419d16e2fSPawel Jakub Dawidek gctl_error(req, "%s", sbuf_data(sb)); 81519d16e2fSPawel Jakub Dawidek } 81619d16e2fSPawel Jakub Dawidek sbuf_delete(sb); 81719d16e2fSPawel Jakub Dawidek } 81819d16e2fSPawel Jakub Dawidek 81902637cdcSPawel Jakub Dawidek static struct g_concat_softc * 82002637cdcSPawel Jakub Dawidek g_concat_find_device(struct g_class *mp, const char *name) 82119d16e2fSPawel Jakub Dawidek { 82219d16e2fSPawel Jakub Dawidek struct g_concat_softc *sc; 82302637cdcSPawel Jakub Dawidek struct g_geom *gp; 82402637cdcSPawel Jakub Dawidek 82502637cdcSPawel Jakub Dawidek LIST_FOREACH(gp, &mp->geom, geom) { 82602637cdcSPawel Jakub Dawidek sc = gp->softc; 82702637cdcSPawel Jakub Dawidek if (sc == NULL) 82802637cdcSPawel Jakub Dawidek continue; 829ba385d00SPawel Jakub Dawidek if (strcmp(sc->sc_name, name) == 0) 83002637cdcSPawel Jakub Dawidek return (sc); 83102637cdcSPawel Jakub Dawidek } 83202637cdcSPawel Jakub Dawidek return (NULL); 83302637cdcSPawel Jakub Dawidek } 83402637cdcSPawel Jakub Dawidek 83502637cdcSPawel Jakub Dawidek static void 83602637cdcSPawel Jakub Dawidek g_concat_ctl_destroy(struct gctl_req *req, struct g_class *mp) 83702637cdcSPawel Jakub Dawidek { 83802637cdcSPawel Jakub Dawidek struct g_concat_softc *sc; 83902637cdcSPawel Jakub Dawidek int *force, *nargs, error; 84002637cdcSPawel Jakub Dawidek const char *name; 84102637cdcSPawel Jakub Dawidek char param[16]; 84202637cdcSPawel Jakub Dawidek u_int i; 84319d16e2fSPawel Jakub Dawidek 84419d16e2fSPawel Jakub Dawidek g_topology_assert(); 84548fbd94bSPawel Jakub Dawidek 84602637cdcSPawel Jakub Dawidek nargs = gctl_get_paraml(req, "nargs", sizeof(*nargs)); 84702637cdcSPawel Jakub Dawidek if (nargs == NULL) { 84802637cdcSPawel Jakub Dawidek gctl_error(req, "No '%s' argument.", "nargs"); 84902637cdcSPawel Jakub Dawidek return; 85002637cdcSPawel Jakub Dawidek } 85102637cdcSPawel Jakub Dawidek if (*nargs <= 0) { 85202637cdcSPawel Jakub Dawidek gctl_error(req, "Missing device(s)."); 85302637cdcSPawel Jakub Dawidek return; 85402637cdcSPawel Jakub Dawidek } 85519d16e2fSPawel Jakub Dawidek force = gctl_get_paraml(req, "force", sizeof(*force)); 85619d16e2fSPawel Jakub Dawidek if (force == NULL) { 85748fbd94bSPawel Jakub Dawidek gctl_error(req, "No '%s' argument.", "force"); 85819d16e2fSPawel Jakub Dawidek return; 85919d16e2fSPawel Jakub Dawidek } 86002637cdcSPawel Jakub Dawidek 86102637cdcSPawel Jakub Dawidek for (i = 0; i < (u_int)*nargs; i++) { 86202637cdcSPawel Jakub Dawidek snprintf(param, sizeof(param), "arg%u", i); 86302637cdcSPawel Jakub Dawidek name = gctl_get_asciiparam(req, param); 86402637cdcSPawel Jakub Dawidek if (name == NULL) { 86502637cdcSPawel Jakub Dawidek gctl_error(req, "No 'arg%u' argument.", i); 86602637cdcSPawel Jakub Dawidek return; 86702637cdcSPawel Jakub Dawidek } 86802637cdcSPawel Jakub Dawidek sc = g_concat_find_device(mp, name); 86919d16e2fSPawel Jakub Dawidek if (sc == NULL) { 87002637cdcSPawel Jakub Dawidek gctl_error(req, "No such device: %s.", name); 87119d16e2fSPawel Jakub Dawidek return; 87219d16e2fSPawel Jakub Dawidek } 87319d16e2fSPawel Jakub Dawidek error = g_concat_destroy(sc, *force); 87419d16e2fSPawel Jakub Dawidek if (error != 0) { 87519d16e2fSPawel Jakub Dawidek gctl_error(req, "Cannot destroy device %s (error=%d).", 876ba385d00SPawel Jakub Dawidek sc->sc_name, error); 87719d16e2fSPawel Jakub Dawidek return; 87819d16e2fSPawel Jakub Dawidek } 87919d16e2fSPawel Jakub Dawidek } 88002637cdcSPawel Jakub Dawidek } 88119d16e2fSPawel Jakub Dawidek 88219d16e2fSPawel Jakub Dawidek static void 88319d16e2fSPawel Jakub Dawidek g_concat_config(struct gctl_req *req, struct g_class *mp, const char *verb) 88419d16e2fSPawel Jakub Dawidek { 88502637cdcSPawel Jakub Dawidek uint32_t *version; 88619d16e2fSPawel Jakub Dawidek 88719d16e2fSPawel Jakub Dawidek g_topology_assert(); 88819d16e2fSPawel Jakub Dawidek 88902637cdcSPawel Jakub Dawidek version = gctl_get_paraml(req, "version", sizeof(*version)); 89002637cdcSPawel Jakub Dawidek if (version == NULL) { 89102637cdcSPawel Jakub Dawidek gctl_error(req, "No '%s' argument.", "version"); 89202637cdcSPawel Jakub Dawidek return; 89302637cdcSPawel Jakub Dawidek } 89402637cdcSPawel Jakub Dawidek if (*version != G_CONCAT_VERSION) { 89502637cdcSPawel Jakub Dawidek gctl_error(req, "Userland and kernel parts are out of sync."); 89619d16e2fSPawel Jakub Dawidek return; 89719d16e2fSPawel Jakub Dawidek } 89819d16e2fSPawel Jakub Dawidek 89902637cdcSPawel Jakub Dawidek if (strcmp(verb, "create") == 0) { 90002637cdcSPawel Jakub Dawidek g_concat_ctl_create(req, mp); 90119d16e2fSPawel Jakub Dawidek return; 902a2e31b8bSPawel Jakub Dawidek } else if (strcmp(verb, "destroy") == 0 || 903a2e31b8bSPawel Jakub Dawidek strcmp(verb, "stop") == 0) { 90402637cdcSPawel Jakub Dawidek g_concat_ctl_destroy(req, mp); 90519d16e2fSPawel Jakub Dawidek return; 90619d16e2fSPawel Jakub Dawidek } 90748fbd94bSPawel Jakub Dawidek gctl_error(req, "Unknown verb."); 90819d16e2fSPawel Jakub Dawidek } 90919d16e2fSPawel Jakub Dawidek 91019d16e2fSPawel Jakub Dawidek static void 91119d16e2fSPawel Jakub Dawidek g_concat_dumpconf(struct sbuf *sb, const char *indent, struct g_geom *gp, 91219d16e2fSPawel Jakub Dawidek struct g_consumer *cp, struct g_provider *pp) 91319d16e2fSPawel Jakub Dawidek { 91419d16e2fSPawel Jakub Dawidek struct g_concat_softc *sc; 91519d16e2fSPawel Jakub Dawidek 9163fb17452SPawel Jakub Dawidek g_topology_assert(); 91719d16e2fSPawel Jakub Dawidek sc = gp->softc; 9181d723f1dSPawel Jakub Dawidek if (sc == NULL) 91919d16e2fSPawel Jakub Dawidek return; 9201d723f1dSPawel Jakub Dawidek if (pp != NULL) { 9211d723f1dSPawel Jakub Dawidek /* Nothing here. */ 9221d723f1dSPawel Jakub Dawidek } else if (cp != NULL) { 9231d723f1dSPawel Jakub Dawidek struct g_concat_disk *disk; 9241d723f1dSPawel Jakub Dawidek 9251d723f1dSPawel Jakub Dawidek disk = cp->private; 9261d723f1dSPawel Jakub Dawidek if (disk == NULL) 9271d723f1dSPawel Jakub Dawidek return; 9281d723f1dSPawel Jakub Dawidek sbuf_printf(sb, "%s<End>%jd</End>\n", indent, 9291d723f1dSPawel Jakub Dawidek (intmax_t)disk->d_end); 9301d723f1dSPawel Jakub Dawidek sbuf_printf(sb, "%s<Start>%jd</Start>\n", indent, 9311d723f1dSPawel Jakub Dawidek (intmax_t)disk->d_start); 9321d723f1dSPawel Jakub Dawidek } else { 9331d723f1dSPawel Jakub Dawidek sbuf_printf(sb, "%s<ID>%u</ID>\n", indent, (u_int)sc->sc_id); 9341d723f1dSPawel Jakub Dawidek sbuf_printf(sb, "%s<Type>", indent); 93519d16e2fSPawel Jakub Dawidek switch (sc->sc_type) { 93619d16e2fSPawel Jakub Dawidek case G_CONCAT_TYPE_AUTOMATIC: 9371d723f1dSPawel Jakub Dawidek sbuf_printf(sb, "AUTOMATIC"); 93819d16e2fSPawel Jakub Dawidek break; 93919d16e2fSPawel Jakub Dawidek case G_CONCAT_TYPE_MANUAL: 9401d723f1dSPawel Jakub Dawidek sbuf_printf(sb, "MANUAL"); 94119d16e2fSPawel Jakub Dawidek break; 94219d16e2fSPawel Jakub Dawidek default: 9431d723f1dSPawel Jakub Dawidek sbuf_printf(sb, "UNKNOWN"); 94419d16e2fSPawel Jakub Dawidek break; 94519d16e2fSPawel Jakub Dawidek } 9461d723f1dSPawel Jakub Dawidek sbuf_printf(sb, "</Type>\n"); 9471d723f1dSPawel Jakub Dawidek sbuf_printf(sb, "%s<Status>Total=%u, Online=%u</Status>\n", 9481d723f1dSPawel Jakub Dawidek indent, sc->sc_ndisks, g_concat_nvalid(sc)); 9491d723f1dSPawel Jakub Dawidek sbuf_printf(sb, "%s<State>", indent); 9501d723f1dSPawel Jakub Dawidek if (sc->sc_provider != NULL && sc->sc_provider->error == 0) 9511d723f1dSPawel Jakub Dawidek sbuf_printf(sb, "UP"); 9523fb17452SPawel Jakub Dawidek else 9531d723f1dSPawel Jakub Dawidek sbuf_printf(sb, "DOWN"); 9541d723f1dSPawel Jakub Dawidek sbuf_printf(sb, "</State>\n"); 9551d723f1dSPawel Jakub Dawidek } 95619d16e2fSPawel Jakub Dawidek } 95719d16e2fSPawel Jakub Dawidek 95819d16e2fSPawel Jakub Dawidek DECLARE_GEOM_CLASS(g_concat_class, g_concat); 959