2004-02-19 15:19:49 +00:00
|
|
|
/*-
|
2005-02-27 23:07:47 +00:00
|
|
|
* Copyright (c) 2004-2005 Pawel Jakub Dawidek <pjd@FreeBSD.org>
|
2004-02-19 15:19:49 +00:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
2006-02-01 12:06:01 +00:00
|
|
|
*
|
2004-02-19 15:19:49 +00:00
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/module.h>
|
|
|
|
#include <sys/lock.h>
|
|
|
|
#include <sys/mutex.h>
|
|
|
|
#include <sys/bio.h>
|
|
|
|
#include <sys/sysctl.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <geom/geom.h>
|
|
|
|
#include <geom/concat/g_concat.h>
|
|
|
|
|
|
|
|
|
2005-10-31 15:41:29 +00:00
|
|
|
static MALLOC_DEFINE(M_CONCAT, "concat_data", "GEOM_CONCAT Data");
|
2004-02-19 15:19:49 +00:00
|
|
|
|
2004-03-03 22:29:24 +00:00
|
|
|
SYSCTL_DECL(_kern_geom);
|
2004-02-19 15:19:49 +00:00
|
|
|
SYSCTL_NODE(_kern_geom, OID_AUTO, concat, CTLFLAG_RW, 0, "GEOM_CONCAT stuff");
|
|
|
|
static u_int g_concat_debug = 0;
|
2004-08-30 18:50:06 +00:00
|
|
|
TUNABLE_INT("kern.geom.concat.debug", &g_concat_debug);
|
2004-02-19 15:19:49 +00:00
|
|
|
SYSCTL_UINT(_kern_geom_concat, OID_AUTO, debug, CTLFLAG_RW, &g_concat_debug, 0,
|
|
|
|
"Debug level");
|
|
|
|
|
|
|
|
static int g_concat_destroy(struct g_concat_softc *sc, boolean_t force);
|
|
|
|
static int g_concat_destroy_geom(struct gctl_req *req, struct g_class *mp,
|
|
|
|
struct g_geom *gp);
|
|
|
|
|
|
|
|
static g_taste_t g_concat_taste;
|
|
|
|
static g_ctl_req_t g_concat_config;
|
|
|
|
static g_dumpconf_t g_concat_dumpconf;
|
|
|
|
|
|
|
|
struct g_class g_concat_class = {
|
|
|
|
.name = G_CONCAT_CLASS_NAME,
|
2004-08-08 07:57:53 +00:00
|
|
|
.version = G_VERSION,
|
2004-02-19 15:19:49 +00:00
|
|
|
.ctlreq = g_concat_config,
|
|
|
|
.taste = g_concat_taste,
|
|
|
|
.destroy_geom = g_concat_destroy_geom
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2004-03-09 11:18:53 +00:00
|
|
|
/*
|
|
|
|
* Greatest Common Divisor.
|
|
|
|
*/
|
|
|
|
static u_int
|
|
|
|
gcd(u_int a, u_int b)
|
|
|
|
{
|
|
|
|
u_int c;
|
|
|
|
|
|
|
|
while (b != 0) {
|
|
|
|
c = a;
|
|
|
|
a = b;
|
|
|
|
b = (c % b);
|
|
|
|
}
|
|
|
|
return (a);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Least Common Multiple.
|
|
|
|
*/
|
|
|
|
static u_int
|
|
|
|
lcm(u_int a, u_int b)
|
|
|
|
{
|
|
|
|
|
|
|
|
return ((a * b) / gcd(a, b));
|
|
|
|
}
|
|
|
|
|
2004-02-19 15:19:49 +00:00
|
|
|
/*
|
|
|
|
* Return the number of valid disks.
|
|
|
|
*/
|
|
|
|
static u_int
|
|
|
|
g_concat_nvalid(struct g_concat_softc *sc)
|
|
|
|
{
|
|
|
|
u_int i, no;
|
|
|
|
|
|
|
|
no = 0;
|
|
|
|
for (i = 0; i < sc->sc_ndisks; i++) {
|
2004-03-03 22:29:24 +00:00
|
|
|
if (sc->sc_disks[i].d_consumer != NULL)
|
2004-02-19 15:19:49 +00:00
|
|
|
no++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (no);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
g_concat_remove_disk(struct g_concat_disk *disk)
|
|
|
|
{
|
|
|
|
struct g_consumer *cp;
|
|
|
|
struct g_concat_softc *sc;
|
|
|
|
|
2004-03-03 22:29:24 +00:00
|
|
|
KASSERT(disk->d_consumer != NULL, ("Non-valid disk in %s.", __func__));
|
2004-02-19 15:19:49 +00:00
|
|
|
sc = disk->d_softc;
|
|
|
|
cp = disk->d_consumer;
|
|
|
|
|
2004-05-20 10:40:18 +00:00
|
|
|
G_CONCAT_DEBUG(0, "Disk %s removed from %s.", cp->provider->name,
|
2004-07-26 16:08:32 +00:00
|
|
|
sc->sc_name);
|
2004-02-19 15:19:49 +00:00
|
|
|
|
2004-03-03 22:29:24 +00:00
|
|
|
disk->d_consumer = NULL;
|
2004-05-20 10:40:18 +00:00
|
|
|
if (sc->sc_provider != NULL) {
|
2005-07-17 13:15:02 +00:00
|
|
|
sc->sc_provider->flags |= G_PF_WITHER;
|
2004-05-20 10:40:18 +00:00
|
|
|
g_orphan_provider(sc->sc_provider, ENXIO);
|
|
|
|
sc->sc_provider = NULL;
|
2004-07-26 16:08:32 +00:00
|
|
|
G_CONCAT_DEBUG(0, "Device %s removed.", sc->sc_name);
|
2004-05-20 10:40:18 +00:00
|
|
|
}
|
2004-02-19 15:19:49 +00:00
|
|
|
|
|
|
|
if (cp->acr > 0 || cp->acw > 0 || cp->ace > 0)
|
|
|
|
g_access(cp, -cp->acr, -cp->acw, -cp->ace);
|
|
|
|
g_detach(cp);
|
|
|
|
g_destroy_consumer(cp);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
g_concat_orphan(struct g_consumer *cp)
|
|
|
|
{
|
|
|
|
struct g_concat_softc *sc;
|
|
|
|
struct g_concat_disk *disk;
|
|
|
|
struct g_geom *gp;
|
|
|
|
|
|
|
|
g_topology_assert();
|
|
|
|
gp = cp->geom;
|
|
|
|
sc = gp->softc;
|
|
|
|
if (sc == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
disk = cp->private;
|
|
|
|
if (disk == NULL) /* Possible? */
|
|
|
|
return;
|
|
|
|
g_concat_remove_disk(disk);
|
|
|
|
|
|
|
|
/* If there are no valid disks anymore, remove device. */
|
|
|
|
if (g_concat_nvalid(sc) == 0)
|
|
|
|
g_concat_destroy(sc, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
g_concat_access(struct g_provider *pp, int dr, int dw, int de)
|
|
|
|
{
|
|
|
|
struct g_consumer *cp1, *cp2;
|
|
|
|
struct g_concat_softc *sc;
|
|
|
|
struct g_geom *gp;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
gp = pp->geom;
|
|
|
|
sc = gp->softc;
|
|
|
|
|
|
|
|
if (sc == NULL) {
|
|
|
|
/*
|
|
|
|
* It looks like geom is being withered.
|
|
|
|
* In that case we allow only negative requests.
|
|
|
|
*/
|
|
|
|
KASSERT(dr <= 0 && dw <= 0 && de <= 0,
|
|
|
|
("Positive access request (device=%s).", pp->name));
|
|
|
|
if ((pp->acr + dr) == 0 && (pp->acw + dw) == 0 &&
|
|
|
|
(pp->ace + de) == 0) {
|
|
|
|
G_CONCAT_DEBUG(0, "Device %s definitely destroyed.",
|
|
|
|
gp->name);
|
|
|
|
}
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* On first open, grab an extra "exclusive" bit */
|
|
|
|
if (pp->acr == 0 && pp->acw == 0 && pp->ace == 0)
|
|
|
|
de++;
|
|
|
|
/* ... and let go of it on last close */
|
2004-07-18 06:54:29 +00:00
|
|
|
if ((pp->acr + dr) == 0 && (pp->acw + dw) == 0 && (pp->ace + de) == 0)
|
2004-02-19 15:19:49 +00:00
|
|
|
de--;
|
|
|
|
|
|
|
|
error = ENXIO;
|
|
|
|
LIST_FOREACH(cp1, &gp->consumer, consumer) {
|
|
|
|
error = g_access(cp1, dr, dw, de);
|
|
|
|
if (error == 0)
|
|
|
|
continue;
|
|
|
|
/*
|
|
|
|
* If we fail here, backout all previous changes.
|
|
|
|
*/
|
|
|
|
LIST_FOREACH(cp2, &gp->consumer, consumer) {
|
|
|
|
if (cp1 == cp2)
|
|
|
|
return (error);
|
|
|
|
g_access(cp2, -dr, -dw, -de);
|
|
|
|
}
|
|
|
|
/* NOTREACHED */
|
|
|
|
}
|
|
|
|
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
2006-10-31 21:23:51 +00:00
|
|
|
static void
|
|
|
|
g_concat_flush(struct g_concat_softc *sc, struct bio *bp)
|
|
|
|
{
|
|
|
|
struct bio_queue_head queue;
|
|
|
|
struct g_consumer *cp;
|
|
|
|
struct bio *cbp;
|
|
|
|
u_int no;
|
|
|
|
|
|
|
|
bioq_init(&queue);
|
|
|
|
for (no = 0; no < sc->sc_ndisks; no++) {
|
|
|
|
cbp = g_clone_bio(bp);
|
|
|
|
if (cbp == NULL) {
|
|
|
|
for (cbp = bioq_first(&queue); cbp != NULL;
|
|
|
|
cbp = bioq_first(&queue)) {
|
|
|
|
bioq_remove(&queue, cbp);
|
|
|
|
g_destroy_bio(cbp);
|
|
|
|
}
|
|
|
|
if (bp->bio_error == 0)
|
|
|
|
bp->bio_error = ENOMEM;
|
|
|
|
g_io_deliver(bp, bp->bio_error);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
bioq_insert_tail(&queue, cbp);
|
|
|
|
cbp->bio_done = g_std_done;
|
|
|
|
cbp->bio_caller1 = sc->sc_disks[no].d_consumer;
|
|
|
|
cbp->bio_to = sc->sc_disks[no].d_consumer->provider;
|
|
|
|
}
|
|
|
|
for (cbp = bioq_first(&queue); cbp != NULL; cbp = bioq_first(&queue)) {
|
|
|
|
bioq_remove(&queue, cbp);
|
|
|
|
G_CONCAT_LOGREQ(cbp, "Sending request.");
|
|
|
|
cp = cbp->bio_caller1;
|
|
|
|
cbp->bio_caller1 = NULL;
|
|
|
|
g_io_request(cbp, cp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-02-19 15:19:49 +00:00
|
|
|
static void
|
|
|
|
g_concat_start(struct bio *bp)
|
|
|
|
{
|
2005-04-03 14:55:49 +00:00
|
|
|
struct bio_queue_head queue;
|
2004-02-19 15:19:49 +00:00
|
|
|
struct g_concat_softc *sc;
|
|
|
|
struct g_concat_disk *disk;
|
|
|
|
struct g_provider *pp;
|
|
|
|
off_t offset, end, length, off, len;
|
|
|
|
struct bio *cbp;
|
|
|
|
char *addr;
|
|
|
|
u_int no;
|
|
|
|
|
|
|
|
pp = bp->bio_to;
|
|
|
|
sc = pp->geom->softc;
|
|
|
|
/*
|
|
|
|
* If sc == NULL, provider's error should be set and g_concat_start()
|
|
|
|
* should not be called at all.
|
|
|
|
*/
|
|
|
|
KASSERT(sc != NULL,
|
|
|
|
("Provider's error should be set (error=%d)(device=%s).",
|
|
|
|
bp->bio_to->error, bp->bio_to->name));
|
|
|
|
|
|
|
|
G_CONCAT_LOGREQ(bp, "Request received.");
|
|
|
|
|
|
|
|
switch (bp->bio_cmd) {
|
|
|
|
case BIO_READ:
|
|
|
|
case BIO_WRITE:
|
|
|
|
case BIO_DELETE:
|
|
|
|
break;
|
2006-10-31 21:23:51 +00:00
|
|
|
case BIO_FLUSH:
|
|
|
|
g_concat_flush(sc, bp);
|
|
|
|
return;
|
2004-02-19 15:19:49 +00:00
|
|
|
case BIO_GETATTR:
|
|
|
|
/* To which provider it should be delivered? */
|
|
|
|
default:
|
|
|
|
g_io_deliver(bp, EOPNOTSUPP);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
offset = bp->bio_offset;
|
|
|
|
length = bp->bio_length;
|
|
|
|
addr = bp->bio_data;
|
|
|
|
end = offset + length;
|
|
|
|
|
2005-04-03 14:55:49 +00:00
|
|
|
bioq_init(&queue);
|
2004-02-19 15:19:49 +00:00
|
|
|
for (no = 0; no < sc->sc_ndisks; no++) {
|
|
|
|
disk = &sc->sc_disks[no];
|
|
|
|
if (disk->d_end <= offset)
|
|
|
|
continue;
|
|
|
|
if (disk->d_start >= end)
|
|
|
|
break;
|
|
|
|
|
|
|
|
off = offset - disk->d_start;
|
|
|
|
len = MIN(length, disk->d_end - offset);
|
|
|
|
length -= len;
|
|
|
|
offset += len;
|
|
|
|
|
|
|
|
cbp = g_clone_bio(bp);
|
|
|
|
if (cbp == NULL) {
|
2005-04-03 14:55:49 +00:00
|
|
|
for (cbp = bioq_first(&queue); cbp != NULL;
|
|
|
|
cbp = bioq_first(&queue)) {
|
|
|
|
bioq_remove(&queue, cbp);
|
|
|
|
g_destroy_bio(cbp);
|
|
|
|
}
|
2004-02-19 15:19:49 +00:00
|
|
|
if (bp->bio_error == 0)
|
|
|
|
bp->bio_error = ENOMEM;
|
2005-04-03 14:55:49 +00:00
|
|
|
g_io_deliver(bp, bp->bio_error);
|
2004-02-19 15:19:49 +00:00
|
|
|
return;
|
|
|
|
}
|
2005-04-03 14:55:49 +00:00
|
|
|
bioq_insert_tail(&queue, cbp);
|
2004-02-19 15:19:49 +00:00
|
|
|
/*
|
|
|
|
* Fill in the component buf structure.
|
|
|
|
*/
|
|
|
|
cbp->bio_done = g_std_done;
|
|
|
|
cbp->bio_offset = off;
|
|
|
|
cbp->bio_data = addr;
|
|
|
|
addr += len;
|
|
|
|
cbp->bio_length = len;
|
|
|
|
cbp->bio_to = disk->d_consumer->provider;
|
2005-04-03 14:55:49 +00:00
|
|
|
cbp->bio_caller1 = disk;
|
2004-02-19 15:19:49 +00:00
|
|
|
|
|
|
|
if (length == 0)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
KASSERT(length == 0,
|
|
|
|
("Length is still greater than 0 (class=%s, name=%s).",
|
|
|
|
bp->bio_to->geom->class->name, bp->bio_to->geom->name));
|
2005-04-03 14:55:49 +00:00
|
|
|
for (cbp = bioq_first(&queue); cbp != NULL; cbp = bioq_first(&queue)) {
|
|
|
|
bioq_remove(&queue, cbp);
|
|
|
|
G_CONCAT_LOGREQ(cbp, "Sending request.");
|
|
|
|
disk = cbp->bio_caller1;
|
|
|
|
cbp->bio_caller1 = NULL;
|
|
|
|
g_io_request(cbp, disk->d_consumer);
|
|
|
|
}
|
2004-02-19 15:19:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
g_concat_check_and_run(struct g_concat_softc *sc)
|
|
|
|
{
|
|
|
|
struct g_concat_disk *disk;
|
2009-12-24 14:32:21 +00:00
|
|
|
struct g_provider *pp;
|
2004-03-09 11:18:53 +00:00
|
|
|
u_int no, sectorsize = 0;
|
2004-02-19 15:19:49 +00:00
|
|
|
off_t start;
|
|
|
|
|
|
|
|
if (g_concat_nvalid(sc) != sc->sc_ndisks)
|
|
|
|
return;
|
|
|
|
|
2009-12-24 14:32:21 +00:00
|
|
|
pp = g_new_providerf(sc->sc_geom, "concat/%s", sc->sc_name);
|
2004-02-19 15:19:49 +00:00
|
|
|
start = 0;
|
|
|
|
for (no = 0; no < sc->sc_ndisks; no++) {
|
|
|
|
disk = &sc->sc_disks[no];
|
|
|
|
disk->d_start = start;
|
|
|
|
disk->d_end = disk->d_start +
|
|
|
|
disk->d_consumer->provider->mediasize;
|
|
|
|
if (sc->sc_type == G_CONCAT_TYPE_AUTOMATIC)
|
|
|
|
disk->d_end -= disk->d_consumer->provider->sectorsize;
|
|
|
|
start = disk->d_end;
|
2004-03-09 11:18:53 +00:00
|
|
|
if (no == 0)
|
|
|
|
sectorsize = disk->d_consumer->provider->sectorsize;
|
|
|
|
else {
|
|
|
|
sectorsize = lcm(sectorsize,
|
|
|
|
disk->d_consumer->provider->sectorsize);
|
|
|
|
}
|
2004-02-19 15:19:49 +00:00
|
|
|
}
|
2009-12-24 14:32:21 +00:00
|
|
|
pp->sectorsize = sectorsize;
|
2004-02-19 15:19:49 +00:00
|
|
|
/* We have sc->sc_disks[sc->sc_ndisks - 1].d_end in 'start'. */
|
2009-12-24 14:32:21 +00:00
|
|
|
pp->mediasize = start;
|
|
|
|
pp->stripesize = sc->sc_disks[0].d_consumer->provider->stripesize;
|
|
|
|
pp->stripeoffset = sc->sc_disks[0].d_consumer->provider->stripeoffset;
|
|
|
|
sc->sc_provider = pp;
|
|
|
|
g_error_provider(pp, 0);
|
2004-02-19 15:19:49 +00:00
|
|
|
|
2004-07-26 16:08:32 +00:00
|
|
|
G_CONCAT_DEBUG(0, "Device %s activated.", sc->sc_name);
|
2004-02-19 15:19:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
g_concat_read_metadata(struct g_consumer *cp, struct g_concat_metadata *md)
|
|
|
|
{
|
|
|
|
struct g_provider *pp;
|
|
|
|
u_char *buf;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
g_topology_assert();
|
|
|
|
|
|
|
|
error = g_access(cp, 1, 0, 0);
|
|
|
|
if (error != 0)
|
|
|
|
return (error);
|
|
|
|
pp = cp->provider;
|
|
|
|
g_topology_unlock();
|
|
|
|
buf = g_read_data(cp, pp->mediasize - pp->sectorsize, pp->sectorsize,
|
|
|
|
&error);
|
|
|
|
g_topology_lock();
|
|
|
|
g_access(cp, -1, 0, 0);
|
|
|
|
if (buf == NULL)
|
|
|
|
return (error);
|
|
|
|
|
|
|
|
/* Decode metadata. */
|
|
|
|
concat_metadata_decode(buf, md);
|
|
|
|
g_free(buf);
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Add disk to given device.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
g_concat_add_disk(struct g_concat_softc *sc, struct g_provider *pp, u_int no)
|
|
|
|
{
|
|
|
|
struct g_concat_disk *disk;
|
2004-05-20 10:40:18 +00:00
|
|
|
struct g_consumer *cp, *fcp;
|
2004-02-19 15:19:49 +00:00
|
|
|
struct g_geom *gp;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
/* Metadata corrupted? */
|
|
|
|
if (no >= sc->sc_ndisks)
|
|
|
|
return (EINVAL);
|
|
|
|
|
|
|
|
disk = &sc->sc_disks[no];
|
|
|
|
/* Check if disk is not already attached. */
|
2004-03-03 22:29:24 +00:00
|
|
|
if (disk->d_consumer != NULL)
|
2004-02-19 15:19:49 +00:00
|
|
|
return (EEXIST);
|
|
|
|
|
2004-05-20 10:40:18 +00:00
|
|
|
gp = sc->sc_geom;
|
|
|
|
fcp = LIST_FIRST(&gp->consumer);
|
2004-02-19 15:19:49 +00:00
|
|
|
|
|
|
|
cp = g_new_consumer(gp);
|
|
|
|
error = g_attach(cp, pp);
|
|
|
|
if (error != 0) {
|
|
|
|
g_destroy_consumer(cp);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
2004-05-20 10:40:18 +00:00
|
|
|
if (fcp != NULL && (fcp->acr > 0 || fcp->acw > 0 || fcp->ace > 0)) {
|
|
|
|
error = g_access(cp, fcp->acr, fcp->acw, fcp->ace);
|
2004-02-19 15:19:49 +00:00
|
|
|
if (error != 0) {
|
|
|
|
g_detach(cp);
|
|
|
|
g_destroy_consumer(cp);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (sc->sc_type == G_CONCAT_TYPE_AUTOMATIC) {
|
|
|
|
struct g_concat_metadata md;
|
|
|
|
|
2004-03-09 11:18:53 +00:00
|
|
|
/* Re-read metadata. */
|
2004-02-19 15:19:49 +00:00
|
|
|
error = g_concat_read_metadata(cp, &md);
|
|
|
|
if (error != 0)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
if (strcmp(md.md_magic, G_CONCAT_MAGIC) != 0 ||
|
|
|
|
strcmp(md.md_name, sc->sc_name) != 0 ||
|
|
|
|
md.md_id != sc->sc_id) {
|
|
|
|
G_CONCAT_DEBUG(0, "Metadata on %s changed.", pp->name);
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
cp->private = disk;
|
|
|
|
disk->d_consumer = cp;
|
|
|
|
disk->d_softc = sc;
|
|
|
|
disk->d_start = 0; /* not yet */
|
|
|
|
disk->d_end = 0; /* not yet */
|
|
|
|
|
2004-07-26 16:08:32 +00:00
|
|
|
G_CONCAT_DEBUG(0, "Disk %s attached to %s.", pp->name, sc->sc_name);
|
2004-02-19 15:19:49 +00:00
|
|
|
|
|
|
|
g_concat_check_and_run(sc);
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
fail:
|
2004-05-20 10:40:18 +00:00
|
|
|
if (fcp != NULL && (fcp->acr > 0 || fcp->acw > 0 || fcp->ace > 0))
|
|
|
|
g_access(cp, -fcp->acr, -fcp->acw, -fcp->ace);
|
2004-02-19 15:19:49 +00:00
|
|
|
g_detach(cp);
|
|
|
|
g_destroy_consumer(cp);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct g_geom *
|
|
|
|
g_concat_create(struct g_class *mp, const struct g_concat_metadata *md,
|
2004-03-09 11:18:53 +00:00
|
|
|
u_int type)
|
2004-02-19 15:19:49 +00:00
|
|
|
{
|
|
|
|
struct g_concat_softc *sc;
|
|
|
|
struct g_geom *gp;
|
|
|
|
u_int no;
|
|
|
|
|
2004-07-26 16:08:32 +00:00
|
|
|
G_CONCAT_DEBUG(1, "Creating device %s (id=%u).", md->md_name,
|
2004-02-19 15:19:49 +00:00
|
|
|
md->md_id);
|
|
|
|
|
2006-01-30 22:47:07 +00:00
|
|
|
/* One disks is minimum. */
|
|
|
|
if (md->md_all < 1)
|
2004-02-19 15:19:49 +00:00
|
|
|
return (NULL);
|
|
|
|
|
|
|
|
/* Check for duplicate unit */
|
|
|
|
LIST_FOREACH(gp, &mp->geom, geom) {
|
|
|
|
sc = gp->softc;
|
|
|
|
if (sc != NULL && strcmp(sc->sc_name, md->md_name) == 0) {
|
2004-05-20 10:40:18 +00:00
|
|
|
G_CONCAT_DEBUG(0, "Device %s already configured.",
|
2004-02-19 15:19:49 +00:00
|
|
|
gp->name);
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
}
|
2004-07-26 16:08:32 +00:00
|
|
|
gp = g_new_geomf(mp, "%s", md->md_name);
|
2004-02-19 15:19:49 +00:00
|
|
|
gp->softc = NULL; /* for a moment */
|
|
|
|
|
2004-07-26 15:35:04 +00:00
|
|
|
sc = malloc(sizeof(*sc), M_CONCAT, M_WAITOK | M_ZERO);
|
2004-02-19 15:19:49 +00:00
|
|
|
gp->start = g_concat_start;
|
|
|
|
gp->spoiled = g_concat_orphan;
|
|
|
|
gp->orphan = g_concat_orphan;
|
|
|
|
gp->access = g_concat_access;
|
|
|
|
gp->dumpconf = g_concat_dumpconf;
|
|
|
|
|
|
|
|
sc->sc_id = md->md_id;
|
|
|
|
sc->sc_ndisks = md->md_all;
|
|
|
|
sc->sc_disks = malloc(sizeof(struct g_concat_disk) * sc->sc_ndisks,
|
|
|
|
M_CONCAT, M_WAITOK | M_ZERO);
|
|
|
|
for (no = 0; no < sc->sc_ndisks; no++)
|
2004-03-03 22:29:24 +00:00
|
|
|
sc->sc_disks[no].d_consumer = NULL;
|
2004-02-19 15:19:49 +00:00
|
|
|
sc->sc_type = type;
|
|
|
|
|
|
|
|
gp->softc = sc;
|
2004-05-20 10:40:18 +00:00
|
|
|
sc->sc_geom = gp;
|
|
|
|
sc->sc_provider = NULL;
|
2004-02-19 15:19:49 +00:00
|
|
|
|
2004-07-26 16:08:32 +00:00
|
|
|
G_CONCAT_DEBUG(0, "Device %s created (id=%u).", sc->sc_name, sc->sc_id);
|
2004-02-19 15:19:49 +00:00
|
|
|
|
|
|
|
return (gp);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
g_concat_destroy(struct g_concat_softc *sc, boolean_t force)
|
|
|
|
{
|
|
|
|
struct g_provider *pp;
|
|
|
|
struct g_geom *gp;
|
|
|
|
u_int no;
|
|
|
|
|
|
|
|
g_topology_assert();
|
|
|
|
|
|
|
|
if (sc == NULL)
|
|
|
|
return (ENXIO);
|
|
|
|
|
|
|
|
pp = sc->sc_provider;
|
2004-05-20 10:40:18 +00:00
|
|
|
if (pp != NULL && (pp->acr != 0 || pp->acw != 0 || pp->ace != 0)) {
|
2004-02-19 15:19:49 +00:00
|
|
|
if (force) {
|
|
|
|
G_CONCAT_DEBUG(0, "Device %s is still open, so it "
|
2004-05-20 10:40:18 +00:00
|
|
|
"can't be definitely removed.", pp->name);
|
2004-02-19 15:19:49 +00:00
|
|
|
} else {
|
|
|
|
G_CONCAT_DEBUG(1,
|
2004-05-20 10:40:18 +00:00
|
|
|
"Device %s is still open (r%dw%de%d).", pp->name,
|
|
|
|
pp->acr, pp->acw, pp->ace);
|
2004-02-19 15:19:49 +00:00
|
|
|
return (EBUSY);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (no = 0; no < sc->sc_ndisks; no++) {
|
2004-03-03 22:29:24 +00:00
|
|
|
if (sc->sc_disks[no].d_consumer != NULL)
|
2004-02-19 15:19:49 +00:00
|
|
|
g_concat_remove_disk(&sc->sc_disks[no]);
|
|
|
|
}
|
|
|
|
|
2004-05-20 10:40:18 +00:00
|
|
|
gp = sc->sc_geom;
|
2004-02-19 15:19:49 +00:00
|
|
|
gp->softc = NULL;
|
2004-05-20 10:40:18 +00:00
|
|
|
KASSERT(sc->sc_provider == NULL, ("Provider still exists? (device=%s)",
|
|
|
|
gp->name));
|
2004-02-19 15:19:49 +00:00
|
|
|
free(sc->sc_disks, M_CONCAT);
|
|
|
|
free(sc, M_CONCAT);
|
|
|
|
|
2004-05-20 10:40:18 +00:00
|
|
|
pp = LIST_FIRST(&gp->provider);
|
|
|
|
if (pp == NULL || (pp->acr == 0 && pp->acw == 0 && pp->ace == 0))
|
|
|
|
G_CONCAT_DEBUG(0, "Device %s destroyed.", gp->name);
|
|
|
|
|
2004-02-19 15:19:49 +00:00
|
|
|
g_wither_geom(gp, ENXIO);
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2004-03-09 11:18:53 +00:00
|
|
|
g_concat_destroy_geom(struct gctl_req *req __unused,
|
|
|
|
struct g_class *mp __unused, struct g_geom *gp)
|
2004-02-19 15:19:49 +00:00
|
|
|
{
|
|
|
|
struct g_concat_softc *sc;
|
|
|
|
|
|
|
|
sc = gp->softc;
|
|
|
|
return (g_concat_destroy(sc, 0));
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct g_geom *
|
|
|
|
g_concat_taste(struct g_class *mp, struct g_provider *pp, int flags __unused)
|
|
|
|
{
|
|
|
|
struct g_concat_metadata md;
|
|
|
|
struct g_concat_softc *sc;
|
|
|
|
struct g_consumer *cp;
|
|
|
|
struct g_geom *gp;
|
|
|
|
int error;
|
|
|
|
|
2004-05-20 10:40:18 +00:00
|
|
|
g_trace(G_T_TOPOLOGY, "%s(%s, %s)", __func__, mp->name, pp->name);
|
2004-02-19 15:19:49 +00:00
|
|
|
g_topology_assert();
|
|
|
|
|
2009-10-09 09:42:22 +00:00
|
|
|
/* Skip providers that are already open for writing. */
|
|
|
|
if (pp->acw > 0)
|
|
|
|
return (NULL);
|
|
|
|
|
2004-02-19 15:19:49 +00:00
|
|
|
G_CONCAT_DEBUG(3, "Tasting %s.", pp->name);
|
|
|
|
|
|
|
|
gp = g_new_geomf(mp, "concat:taste");
|
|
|
|
gp->start = g_concat_start;
|
2004-02-27 15:34:21 +00:00
|
|
|
gp->access = g_concat_access;
|
|
|
|
gp->orphan = g_concat_orphan;
|
2004-02-19 15:19:49 +00:00
|
|
|
cp = g_new_consumer(gp);
|
|
|
|
g_attach(cp, pp);
|
|
|
|
error = g_concat_read_metadata(cp, &md);
|
2004-08-09 11:14:25 +00:00
|
|
|
g_detach(cp);
|
|
|
|
g_destroy_consumer(cp);
|
|
|
|
g_destroy_geom(gp);
|
2004-05-20 10:40:18 +00:00
|
|
|
if (error != 0)
|
|
|
|
return (NULL);
|
2004-02-19 15:19:49 +00:00
|
|
|
gp = NULL;
|
|
|
|
|
|
|
|
if (strcmp(md.md_magic, G_CONCAT_MAGIC) != 0)
|
|
|
|
return (NULL);
|
|
|
|
if (md.md_version > G_CONCAT_VERSION) {
|
|
|
|
printf("geom_concat.ko module is too old to handle %s.\n",
|
|
|
|
pp->name);
|
|
|
|
return (NULL);
|
|
|
|
}
|
2004-08-09 11:29:42 +00:00
|
|
|
/*
|
|
|
|
* Backward compatibility:
|
|
|
|
*/
|
2005-02-27 23:07:47 +00:00
|
|
|
/* There was no md_provider field in earlier versions of metadata. */
|
2004-08-09 11:29:42 +00:00
|
|
|
if (md.md_version < 3)
|
|
|
|
bzero(md.md_provider, sizeof(md.md_provider));
|
2005-02-27 23:07:47 +00:00
|
|
|
/* There was no md_provsize field in earlier versions of metadata. */
|
|
|
|
if (md.md_version < 4)
|
|
|
|
md.md_provsize = pp->mediasize;
|
2004-08-09 11:29:42 +00:00
|
|
|
|
|
|
|
if (md.md_provider[0] != '\0' && strcmp(md.md_provider, pp->name) != 0)
|
|
|
|
return (NULL);
|
2005-02-27 23:07:47 +00:00
|
|
|
if (md.md_provsize != pp->mediasize)
|
|
|
|
return (NULL);
|
2004-02-19 15:19:49 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Let's check if device already exists.
|
|
|
|
*/
|
2004-05-04 07:45:39 +00:00
|
|
|
sc = NULL;
|
2004-02-19 15:19:49 +00:00
|
|
|
LIST_FOREACH(gp, &mp->geom, geom) {
|
|
|
|
sc = gp->softc;
|
|
|
|
if (sc == NULL)
|
|
|
|
continue;
|
|
|
|
if (sc->sc_type != G_CONCAT_TYPE_AUTOMATIC)
|
|
|
|
continue;
|
|
|
|
if (strcmp(md.md_name, sc->sc_name) != 0)
|
|
|
|
continue;
|
|
|
|
if (md.md_id != sc->sc_id)
|
|
|
|
continue;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (gp != NULL) {
|
|
|
|
G_CONCAT_DEBUG(1, "Adding disk %s to %s.", pp->name, gp->name);
|
|
|
|
error = g_concat_add_disk(sc, pp, md.md_no);
|
|
|
|
if (error != 0) {
|
2004-05-20 10:40:18 +00:00
|
|
|
G_CONCAT_DEBUG(0,
|
|
|
|
"Cannot add disk %s to %s (error=%d).", pp->name,
|
|
|
|
gp->name, error);
|
2004-02-19 15:19:49 +00:00
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
} else {
|
2004-03-09 11:18:53 +00:00
|
|
|
gp = g_concat_create(mp, &md, G_CONCAT_TYPE_AUTOMATIC);
|
2004-02-19 15:19:49 +00:00
|
|
|
if (gp == NULL) {
|
2004-07-26 16:08:32 +00:00
|
|
|
G_CONCAT_DEBUG(0, "Cannot create device %s.",
|
2004-02-19 15:19:49 +00:00
|
|
|
md.md_name);
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
sc = gp->softc;
|
|
|
|
G_CONCAT_DEBUG(1, "Adding disk %s to %s.", pp->name, gp->name);
|
|
|
|
error = g_concat_add_disk(sc, pp, md.md_no);
|
|
|
|
if (error != 0) {
|
2004-05-20 10:40:18 +00:00
|
|
|
G_CONCAT_DEBUG(0,
|
|
|
|
"Cannot add disk %s to %s (error=%d).", pp->name,
|
|
|
|
gp->name, error);
|
2004-02-19 15:19:49 +00:00
|
|
|
g_concat_destroy(sc, 1);
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return (gp);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
g_concat_ctl_create(struct gctl_req *req, struct g_class *mp)
|
|
|
|
{
|
|
|
|
u_int attached, no;
|
2004-05-20 10:40:18 +00:00
|
|
|
struct g_concat_metadata md;
|
2004-02-19 15:19:49 +00:00
|
|
|
struct g_provider *pp;
|
|
|
|
struct g_concat_softc *sc;
|
|
|
|
struct g_geom *gp;
|
|
|
|
struct sbuf *sb;
|
2004-05-20 10:40:18 +00:00
|
|
|
const char *name;
|
|
|
|
char param[16];
|
|
|
|
int *nargs;
|
2004-02-19 15:19:49 +00:00
|
|
|
|
|
|
|
g_topology_assert();
|
2004-05-20 10:40:18 +00:00
|
|
|
nargs = gctl_get_paraml(req, "nargs", sizeof(*nargs));
|
|
|
|
if (nargs == NULL) {
|
|
|
|
gctl_error(req, "No '%s' argument.", "nargs");
|
2004-02-19 15:19:49 +00:00
|
|
|
return;
|
|
|
|
}
|
2006-01-30 22:47:07 +00:00
|
|
|
if (*nargs < 2) {
|
2004-05-20 10:40:18 +00:00
|
|
|
gctl_error(req, "Too few arguments.");
|
2004-02-19 15:19:49 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-05-20 10:40:18 +00:00
|
|
|
strlcpy(md.md_magic, G_CONCAT_MAGIC, sizeof(md.md_magic));
|
|
|
|
md.md_version = G_CONCAT_VERSION;
|
|
|
|
name = gctl_get_asciiparam(req, "arg0");
|
|
|
|
if (name == NULL) {
|
|
|
|
gctl_error(req, "No 'arg%u' argument.", 0);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
strlcpy(md.md_name, name, sizeof(md.md_name));
|
|
|
|
md.md_id = arc4random();
|
|
|
|
md.md_no = 0;
|
|
|
|
md.md_all = *nargs - 1;
|
2004-08-09 11:29:42 +00:00
|
|
|
bzero(md.md_provider, sizeof(md.md_provider));
|
2005-02-27 23:07:47 +00:00
|
|
|
/* This field is not important here. */
|
|
|
|
md.md_provsize = 0;
|
2004-05-20 10:40:18 +00:00
|
|
|
|
2004-02-19 15:19:49 +00:00
|
|
|
/* Check all providers are valid */
|
2004-05-20 10:40:18 +00:00
|
|
|
for (no = 1; no < *nargs; no++) {
|
|
|
|
snprintf(param, sizeof(param), "arg%u", no);
|
|
|
|
name = gctl_get_asciiparam(req, param);
|
|
|
|
if (name == NULL) {
|
|
|
|
gctl_error(req, "No 'arg%u' argument.", no);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (strncmp(name, "/dev/", strlen("/dev/")) == 0)
|
|
|
|
name += strlen("/dev/");
|
|
|
|
pp = g_provider_by_name(name);
|
2004-02-19 15:19:49 +00:00
|
|
|
if (pp == NULL) {
|
2004-05-20 10:40:18 +00:00
|
|
|
G_CONCAT_DEBUG(1, "Disk %s is invalid.", name);
|
|
|
|
gctl_error(req, "Disk %s is invalid.", name);
|
2004-02-19 15:19:49 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-05-20 10:40:18 +00:00
|
|
|
gp = g_concat_create(mp, &md, G_CONCAT_TYPE_MANUAL);
|
2004-02-19 15:19:49 +00:00
|
|
|
if (gp == NULL) {
|
2004-07-26 16:08:32 +00:00
|
|
|
gctl_error(req, "Can't configure %s.", md.md_name);
|
2004-02-19 15:19:49 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
sc = gp->softc;
|
2008-08-09 11:14:05 +00:00
|
|
|
sb = sbuf_new_auto();
|
2004-02-19 15:19:49 +00:00
|
|
|
sbuf_printf(sb, "Can't attach disk(s) to %s:", gp->name);
|
2004-05-20 10:40:18 +00:00
|
|
|
for (attached = 0, no = 1; no < *nargs; no++) {
|
|
|
|
snprintf(param, sizeof(param), "arg%u", no);
|
|
|
|
name = gctl_get_asciiparam(req, param);
|
2009-05-12 16:59:50 +00:00
|
|
|
if (name == NULL) {
|
|
|
|
gctl_error(req, "No 'arg%d' argument.", no);
|
|
|
|
return;
|
|
|
|
}
|
2004-05-20 10:40:18 +00:00
|
|
|
if (strncmp(name, "/dev/", strlen("/dev/")) == 0)
|
|
|
|
name += strlen("/dev/");
|
|
|
|
pp = g_provider_by_name(name);
|
|
|
|
KASSERT(pp != NULL, ("Provider %s disappear?!", name));
|
|
|
|
if (g_concat_add_disk(sc, pp, no - 1) != 0) {
|
2004-02-19 15:19:49 +00:00
|
|
|
G_CONCAT_DEBUG(1, "Disk %u (%s) not attached to %s.",
|
2004-05-20 10:40:18 +00:00
|
|
|
no, pp->name, gp->name);
|
2004-02-19 15:19:49 +00:00
|
|
|
sbuf_printf(sb, " %s", pp->name);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
attached++;
|
|
|
|
}
|
|
|
|
sbuf_finish(sb);
|
2004-05-20 10:40:18 +00:00
|
|
|
if (md.md_all != attached) {
|
2004-02-19 15:19:49 +00:00
|
|
|
g_concat_destroy(gp->softc, 1);
|
|
|
|
gctl_error(req, "%s", sbuf_data(sb));
|
|
|
|
}
|
|
|
|
sbuf_delete(sb);
|
|
|
|
}
|
|
|
|
|
2004-05-20 10:40:18 +00:00
|
|
|
static struct g_concat_softc *
|
|
|
|
g_concat_find_device(struct g_class *mp, const char *name)
|
|
|
|
{
|
|
|
|
struct g_concat_softc *sc;
|
|
|
|
struct g_geom *gp;
|
|
|
|
|
|
|
|
LIST_FOREACH(gp, &mp->geom, geom) {
|
|
|
|
sc = gp->softc;
|
|
|
|
if (sc == NULL)
|
|
|
|
continue;
|
2004-07-26 16:08:32 +00:00
|
|
|
if (strcmp(sc->sc_name, name) == 0)
|
2004-05-20 10:40:18 +00:00
|
|
|
return (sc);
|
|
|
|
}
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
|
2004-02-19 15:19:49 +00:00
|
|
|
static void
|
2004-05-20 10:40:18 +00:00
|
|
|
g_concat_ctl_destroy(struct gctl_req *req, struct g_class *mp)
|
2004-02-19 15:19:49 +00:00
|
|
|
{
|
|
|
|
struct g_concat_softc *sc;
|
2004-05-20 10:40:18 +00:00
|
|
|
int *force, *nargs, error;
|
|
|
|
const char *name;
|
|
|
|
char param[16];
|
|
|
|
u_int i;
|
2004-02-19 15:19:49 +00:00
|
|
|
|
|
|
|
g_topology_assert();
|
2004-03-09 11:18:53 +00:00
|
|
|
|
2004-05-20 10:40:18 +00:00
|
|
|
nargs = gctl_get_paraml(req, "nargs", sizeof(*nargs));
|
|
|
|
if (nargs == NULL) {
|
|
|
|
gctl_error(req, "No '%s' argument.", "nargs");
|
2004-02-19 15:19:49 +00:00
|
|
|
return;
|
|
|
|
}
|
2004-05-20 10:40:18 +00:00
|
|
|
if (*nargs <= 0) {
|
|
|
|
gctl_error(req, "Missing device(s).");
|
2004-02-19 15:19:49 +00:00
|
|
|
return;
|
|
|
|
}
|
2004-05-20 10:40:18 +00:00
|
|
|
force = gctl_get_paraml(req, "force", sizeof(*force));
|
|
|
|
if (force == NULL) {
|
|
|
|
gctl_error(req, "No '%s' argument.", "force");
|
2004-02-19 15:19:49 +00:00
|
|
|
return;
|
|
|
|
}
|
2004-05-20 10:40:18 +00:00
|
|
|
|
|
|
|
for (i = 0; i < (u_int)*nargs; i++) {
|
|
|
|
snprintf(param, sizeof(param), "arg%u", i);
|
|
|
|
name = gctl_get_asciiparam(req, param);
|
|
|
|
if (name == NULL) {
|
|
|
|
gctl_error(req, "No 'arg%u' argument.", i);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
sc = g_concat_find_device(mp, name);
|
|
|
|
if (sc == NULL) {
|
|
|
|
gctl_error(req, "No such device: %s.", name);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
error = g_concat_destroy(sc, *force);
|
|
|
|
if (error != 0) {
|
|
|
|
gctl_error(req, "Cannot destroy device %s (error=%d).",
|
2004-07-26 16:08:32 +00:00
|
|
|
sc->sc_name, error);
|
2004-05-20 10:40:18 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2004-02-19 15:19:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
g_concat_config(struct gctl_req *req, struct g_class *mp, const char *verb)
|
|
|
|
{
|
2004-05-20 10:40:18 +00:00
|
|
|
uint32_t *version;
|
2004-02-19 15:19:49 +00:00
|
|
|
|
|
|
|
g_topology_assert();
|
|
|
|
|
2004-05-20 10:40:18 +00:00
|
|
|
version = gctl_get_paraml(req, "version", sizeof(*version));
|
|
|
|
if (version == NULL) {
|
|
|
|
gctl_error(req, "No '%s' argument.", "version");
|
2004-02-19 15:19:49 +00:00
|
|
|
return;
|
|
|
|
}
|
2004-05-20 10:40:18 +00:00
|
|
|
if (*version != G_CONCAT_VERSION) {
|
|
|
|
gctl_error(req, "Userland and kernel parts are out of sync.");
|
2004-02-19 15:19:49 +00:00
|
|
|
return;
|
|
|
|
}
|
2004-05-20 10:40:18 +00:00
|
|
|
|
|
|
|
if (strcmp(verb, "create") == 0) {
|
|
|
|
g_concat_ctl_create(req, mp);
|
|
|
|
return;
|
2004-07-05 21:16:37 +00:00
|
|
|
} else if (strcmp(verb, "destroy") == 0 ||
|
|
|
|
strcmp(verb, "stop") == 0) {
|
2004-05-20 10:40:18 +00:00
|
|
|
g_concat_ctl_destroy(req, mp);
|
2004-02-19 15:19:49 +00:00
|
|
|
return;
|
|
|
|
}
|
2004-03-09 11:18:53 +00:00
|
|
|
gctl_error(req, "Unknown verb.");
|
2004-02-19 15:19:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
g_concat_dumpconf(struct sbuf *sb, const char *indent, struct g_geom *gp,
|
|
|
|
struct g_consumer *cp, struct g_provider *pp)
|
|
|
|
{
|
2004-04-20 17:07:55 +00:00
|
|
|
struct g_concat_softc *sc;
|
2004-02-19 15:19:49 +00:00
|
|
|
|
2004-05-26 11:36:27 +00:00
|
|
|
g_topology_assert();
|
2004-04-20 17:07:55 +00:00
|
|
|
sc = gp->softc;
|
2004-07-26 17:14:47 +00:00
|
|
|
if (sc == NULL)
|
2004-04-20 17:07:55 +00:00
|
|
|
return;
|
2004-07-26 17:14:47 +00:00
|
|
|
if (pp != NULL) {
|
|
|
|
/* Nothing here. */
|
|
|
|
} else if (cp != NULL) {
|
|
|
|
struct g_concat_disk *disk;
|
|
|
|
|
|
|
|
disk = cp->private;
|
|
|
|
if (disk == NULL)
|
|
|
|
return;
|
|
|
|
sbuf_printf(sb, "%s<End>%jd</End>\n", indent,
|
|
|
|
(intmax_t)disk->d_end);
|
|
|
|
sbuf_printf(sb, "%s<Start>%jd</Start>\n", indent,
|
|
|
|
(intmax_t)disk->d_start);
|
|
|
|
} else {
|
|
|
|
sbuf_printf(sb, "%s<ID>%u</ID>\n", indent, (u_int)sc->sc_id);
|
|
|
|
sbuf_printf(sb, "%s<Type>", indent);
|
|
|
|
switch (sc->sc_type) {
|
|
|
|
case G_CONCAT_TYPE_AUTOMATIC:
|
|
|
|
sbuf_printf(sb, "AUTOMATIC");
|
|
|
|
break;
|
|
|
|
case G_CONCAT_TYPE_MANUAL:
|
|
|
|
sbuf_printf(sb, "MANUAL");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
sbuf_printf(sb, "UNKNOWN");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
sbuf_printf(sb, "</Type>\n");
|
|
|
|
sbuf_printf(sb, "%s<Status>Total=%u, Online=%u</Status>\n",
|
|
|
|
indent, sc->sc_ndisks, g_concat_nvalid(sc));
|
|
|
|
sbuf_printf(sb, "%s<State>", indent);
|
|
|
|
if (sc->sc_provider != NULL && sc->sc_provider->error == 0)
|
|
|
|
sbuf_printf(sb, "UP");
|
|
|
|
else
|
|
|
|
sbuf_printf(sb, "DOWN");
|
|
|
|
sbuf_printf(sb, "</State>\n");
|
2004-04-20 17:07:55 +00:00
|
|
|
}
|
2004-02-19 15:19:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DECLARE_GEOM_CLASS(g_concat_class, g_concat);
|