2002-03-11 21:42:35 +00:00
|
|
|
/*-
|
|
|
|
* Copyright (c) 2002 Poul-Henning Kamp
|
|
|
|
* Copyright (c) 2002 Networks Associates Technology, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This software was developed for the FreeBSD Project by Poul-Henning Kamp
|
|
|
|
* and NAI Labs, the Security Research Division of Network Associates, Inc.
|
|
|
|
* under DARPA/SPAWAR contract N66001-01-C-8035 ("CBOSS"), as part of the
|
|
|
|
* DARPA CHATS research program.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
* 3. The names of the authors may not be used to endorse or promote
|
|
|
|
* products derived from this software without specific prior written
|
|
|
|
* permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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.
|
|
|
|
*
|
|
|
|
* $FreeBSD$
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
2002-10-20 18:48:12 +00:00
|
|
|
#include <sys/stdint.h>
|
2002-03-11 21:42:35 +00:00
|
|
|
#ifndef _KERNEL
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <signal.h>
|
2002-05-19 18:59:39 +00:00
|
|
|
#include <string.h>
|
2002-03-11 21:42:35 +00:00
|
|
|
#include <err.h>
|
|
|
|
#else
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/bio.h>
|
|
|
|
#include <sys/sysctl.h>
|
|
|
|
#include <sys/proc.h>
|
|
|
|
#include <sys/kthread.h>
|
|
|
|
#include <sys/lock.h>
|
|
|
|
#include <sys/mutex.h>
|
|
|
|
#endif
|
|
|
|
#include <sys/errno.h>
|
|
|
|
#include <sys/sbuf.h>
|
|
|
|
#include <geom/geom.h>
|
|
|
|
#include <geom/geom_slice.h>
|
|
|
|
#include <machine/stdarg.h>
|
|
|
|
|
2002-04-04 09:54:13 +00:00
|
|
|
static g_orphan_t g_slice_orphan;
|
|
|
|
static g_access_t g_slice_access;
|
|
|
|
static g_start_t g_slice_start;
|
|
|
|
|
2002-04-23 19:03:03 +00:00
|
|
|
static struct g_slicer *
|
2002-03-11 21:42:35 +00:00
|
|
|
g_slice_init(unsigned nslice, unsigned scsize)
|
|
|
|
{
|
|
|
|
struct g_slicer *gsp;
|
|
|
|
|
2003-01-21 08:56:16 +00:00
|
|
|
gsp = g_malloc(sizeof *gsp, M_ZERO);
|
|
|
|
gsp->softc = g_malloc(scsize, M_ZERO);
|
2002-09-27 20:47:23 +00:00
|
|
|
gsp->slices = g_malloc(nslice * sizeof(struct g_slice),
|
2003-01-21 08:56:16 +00:00
|
|
|
M_ZERO);
|
2002-03-11 21:42:35 +00:00
|
|
|
gsp->nslice = nslice;
|
|
|
|
return (gsp);
|
|
|
|
}
|
|
|
|
|
2002-04-04 09:54:13 +00:00
|
|
|
static int
|
2002-03-11 21:42:35 +00:00
|
|
|
g_slice_access(struct g_provider *pp, int dr, int dw, int de)
|
|
|
|
{
|
2002-12-16 22:33:27 +00:00
|
|
|
int error;
|
|
|
|
u_int u;
|
2002-03-11 21:42:35 +00:00
|
|
|
struct g_geom *gp;
|
|
|
|
struct g_consumer *cp;
|
|
|
|
struct g_provider *pp2;
|
|
|
|
struct g_slicer *gsp;
|
|
|
|
struct g_slice *gsl, *gsl2;
|
|
|
|
|
|
|
|
gp = pp->geom;
|
|
|
|
cp = LIST_FIRST(&gp->consumer);
|
|
|
|
KASSERT (cp != NULL, ("g_slice_access but no consumer"));
|
|
|
|
gsp = gp->softc;
|
|
|
|
gsl = &gsp->slices[pp->index];
|
2002-12-16 22:33:27 +00:00
|
|
|
for (u = 0; u < gsp->nslice; u++) {
|
|
|
|
gsl2 = &gsp->slices[u];
|
2002-03-11 21:42:35 +00:00
|
|
|
if (gsl2->length == 0)
|
|
|
|
continue;
|
2002-12-16 22:33:27 +00:00
|
|
|
if (u == pp->index)
|
2002-03-11 21:42:35 +00:00
|
|
|
continue;
|
|
|
|
if (gsl->offset + gsl->length <= gsl2->offset)
|
|
|
|
continue;
|
|
|
|
if (gsl2->offset + gsl2->length <= gsl->offset)
|
|
|
|
continue;
|
|
|
|
/* overlap */
|
|
|
|
pp2 = gsl2->provider;
|
|
|
|
if ((pp->acw + dw) > 0 && pp2->ace > 0)
|
|
|
|
return (EPERM);
|
|
|
|
if ((pp->ace + de) > 0 && pp2->acw > 0)
|
|
|
|
return (EPERM);
|
|
|
|
}
|
|
|
|
/* On first open, grab an extra "exclusive" bit */
|
|
|
|
if (cp->acr == 0 && cp->acw == 0 && cp->ace == 0)
|
|
|
|
de++;
|
|
|
|
/* ... and let go of it on last close */
|
|
|
|
if ((cp->acr + dr) == 0 && (cp->acw + dw) == 0 && (cp->ace + de) == 1)
|
|
|
|
de--;
|
|
|
|
error = g_access_rel(cp, dr, dw, de);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
2002-12-02 19:59:25 +00:00
|
|
|
void
|
|
|
|
g_slice_finish_hot(struct bio *bp)
|
|
|
|
{
|
|
|
|
struct bio *bp2;
|
|
|
|
struct g_geom *gp;
|
|
|
|
struct g_consumer *cp;
|
|
|
|
struct g_slicer *gsp;
|
|
|
|
struct g_slice *gsl;
|
2002-12-16 22:33:27 +00:00
|
|
|
int idx;
|
2002-12-02 19:59:25 +00:00
|
|
|
|
|
|
|
KASSERT(bp->bio_to != NULL, ("NULL bio_to in g_slice_finish_hot(%p)", bp));
|
|
|
|
KASSERT(bp->bio_from != NULL, ("NULL bio_from in g_slice_finish_hot(%p)", bp));
|
|
|
|
gp = bp->bio_to->geom;
|
|
|
|
gsp = gp->softc;
|
|
|
|
cp = LIST_FIRST(&gp->consumer);
|
|
|
|
KASSERT(cp != NULL, ("NULL consumer in g_slice_finish_hot(%p)", bp));
|
2002-12-16 22:33:27 +00:00
|
|
|
idx = bp->bio_to->index;
|
|
|
|
gsl = &gsp->slices[idx];
|
2002-12-02 19:59:25 +00:00
|
|
|
|
|
|
|
bp2 = g_clone_bio(bp);
|
|
|
|
if (bp2 == NULL) {
|
|
|
|
g_io_deliver(bp, ENOMEM);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (bp2->bio_offset + bp2->bio_length > gsl->length)
|
|
|
|
bp2->bio_length = gsl->length - bp2->bio_offset;
|
|
|
|
bp2->bio_done = g_std_done;
|
|
|
|
bp2->bio_offset += gsl->offset;
|
|
|
|
g_io_request(bp2, cp);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2002-04-04 09:54:13 +00:00
|
|
|
static void
|
2002-03-11 21:42:35 +00:00
|
|
|
g_slice_start(struct bio *bp)
|
|
|
|
{
|
|
|
|
struct bio *bp2;
|
|
|
|
struct g_provider *pp;
|
|
|
|
struct g_geom *gp;
|
|
|
|
struct g_consumer *cp;
|
|
|
|
struct g_slicer *gsp;
|
2002-12-02 19:59:25 +00:00
|
|
|
struct g_slice *gsl, *gmp;
|
2002-12-16 22:33:27 +00:00
|
|
|
int idx, error;
|
2002-12-02 19:59:25 +00:00
|
|
|
u_int m_index;
|
2002-04-09 15:43:32 +00:00
|
|
|
off_t t;
|
2002-03-11 21:42:35 +00:00
|
|
|
|
|
|
|
pp = bp->bio_to;
|
|
|
|
gp = pp->geom;
|
|
|
|
gsp = gp->softc;
|
|
|
|
cp = LIST_FIRST(&gp->consumer);
|
2002-12-16 22:33:27 +00:00
|
|
|
idx = pp->index;
|
|
|
|
gsl = &gsp->slices[idx];
|
2002-03-11 21:42:35 +00:00
|
|
|
switch(bp->bio_cmd) {
|
|
|
|
case BIO_READ:
|
|
|
|
case BIO_WRITE:
|
|
|
|
case BIO_DELETE:
|
|
|
|
if (bp->bio_offset > gsl->length) {
|
2002-09-30 08:54:46 +00:00
|
|
|
g_io_deliver(bp, EINVAL); /* XXX: EWHAT ? */
|
2002-03-11 21:42:35 +00:00
|
|
|
return;
|
|
|
|
}
|
2002-12-02 19:59:25 +00:00
|
|
|
/*
|
|
|
|
* Check if we collide with any hot spaces, and call the
|
|
|
|
* method once if so.
|
|
|
|
*/
|
2002-12-13 21:31:13 +00:00
|
|
|
t = bp->bio_offset + gsl->offset;
|
2002-12-17 21:31:58 +00:00
|
|
|
/* .ctl devices may take us negative */
|
|
|
|
if (t < 0 || (t + bp->bio_length) < 0) {
|
|
|
|
g_io_deliver(bp, EINVAL);
|
|
|
|
return;
|
|
|
|
}
|
2002-12-02 19:59:25 +00:00
|
|
|
for (m_index = 0; m_index < gsp->nhot; m_index++) {
|
|
|
|
gmp = &gsp->hot[m_index];
|
2002-12-13 21:31:13 +00:00
|
|
|
if (t >= gmp->offset + gmp->length)
|
2002-12-02 19:59:25 +00:00
|
|
|
continue;
|
2002-12-13 21:31:13 +00:00
|
|
|
if (t + bp->bio_length <= gmp->offset)
|
2002-12-02 19:59:25 +00:00
|
|
|
continue;
|
|
|
|
error = gsp->start(bp);
|
|
|
|
if (error == EJUSTRETURN)
|
|
|
|
return;
|
|
|
|
else if (error) {
|
|
|
|
g_io_deliver(bp, error);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2002-03-11 21:42:35 +00:00
|
|
|
bp2 = g_clone_bio(bp);
|
2002-09-27 20:47:23 +00:00
|
|
|
if (bp2 == NULL) {
|
2002-09-30 08:54:46 +00:00
|
|
|
g_io_deliver(bp, ENOMEM);
|
2002-09-27 20:47:23 +00:00
|
|
|
return;
|
|
|
|
}
|
2002-03-11 21:42:35 +00:00
|
|
|
if (bp2->bio_offset + bp2->bio_length > gsl->length)
|
|
|
|
bp2->bio_length = gsl->length - bp2->bio_offset;
|
|
|
|
bp2->bio_done = g_std_done;
|
|
|
|
bp2->bio_offset += gsl->offset;
|
|
|
|
g_io_request(bp2, cp);
|
|
|
|
return;
|
|
|
|
case BIO_GETATTR:
|
|
|
|
case BIO_SETATTR:
|
2002-04-09 15:43:32 +00:00
|
|
|
/* Give the real method a chance to override */
|
|
|
|
if (gsp->start(bp))
|
|
|
|
return;
|
|
|
|
if (!strcmp("GEOM::frontstuff", bp->bio_attribute)) {
|
|
|
|
t = gsp->cfrontstuff;
|
|
|
|
if (gsp->frontstuff > t)
|
|
|
|
t = gsp->frontstuff;
|
|
|
|
t -= gsl->offset;
|
|
|
|
if (t < 0)
|
|
|
|
t = 0;
|
|
|
|
if (t > gsl->length)
|
|
|
|
t = gsl->length;
|
2002-06-09 10:57:34 +00:00
|
|
|
g_handleattr_off_t(bp, "GEOM::frontstuff", t);
|
2002-03-11 21:42:35 +00:00
|
|
|
return;
|
2002-04-09 15:43:32 +00:00
|
|
|
}
|
2002-04-23 11:48:45 +00:00
|
|
|
#ifdef _KERNEL
|
2002-04-19 09:24:12 +00:00
|
|
|
if (!strcmp("GEOM::kerneldump", bp->bio_attribute)) {
|
|
|
|
struct g_kerneldump *gkd;
|
|
|
|
|
|
|
|
gkd = (struct g_kerneldump *)bp->bio_data;
|
2002-12-16 22:33:27 +00:00
|
|
|
gkd->offset += gsp->slices[idx].offset;
|
|
|
|
if (gkd->length > gsp->slices[idx].length)
|
|
|
|
gkd->length = gsp->slices[idx].length;
|
2002-04-19 09:24:12 +00:00
|
|
|
/* now, pass it on downwards... */
|
|
|
|
}
|
2002-04-23 11:48:45 +00:00
|
|
|
#endif
|
2002-03-11 21:42:35 +00:00
|
|
|
bp2 = g_clone_bio(bp);
|
2002-09-28 08:16:50 +00:00
|
|
|
if (bp2 == NULL) {
|
2002-09-30 08:54:46 +00:00
|
|
|
g_io_deliver(bp, ENOMEM);
|
2002-09-28 08:16:50 +00:00
|
|
|
return;
|
|
|
|
}
|
2002-03-11 21:42:35 +00:00
|
|
|
bp2->bio_done = g_std_done;
|
|
|
|
g_io_request(bp2, cp);
|
|
|
|
break;
|
|
|
|
default:
|
2002-09-30 08:54:46 +00:00
|
|
|
g_io_deliver(bp, EOPNOTSUPP);
|
2002-03-11 21:42:35 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2002-12-16 22:33:27 +00:00
|
|
|
g_slice_dumpconf(struct sbuf *sb, const char *indent, struct g_geom *gp, struct g_consumer *cp, struct g_provider *pp)
|
2002-03-11 21:42:35 +00:00
|
|
|
{
|
|
|
|
struct g_slicer *gsp;
|
|
|
|
|
|
|
|
gsp = gp->softc;
|
2002-10-28 22:43:54 +00:00
|
|
|
if (indent == NULL) {
|
|
|
|
sbuf_printf(sb, " i %u", pp->index);
|
|
|
|
sbuf_printf(sb, " o %ju",
|
|
|
|
(uintmax_t)gsp->slices[pp->index].offset);
|
|
|
|
return;
|
|
|
|
}
|
2002-04-23 19:54:02 +00:00
|
|
|
if (gp != NULL && (pp == NULL && cp == NULL)) {
|
2002-10-20 18:48:12 +00:00
|
|
|
sbuf_printf(sb, "%s<frontstuff>%ju</frontstuff>\n",
|
|
|
|
indent, (intmax_t)gsp->frontstuff);
|
2002-04-09 15:43:32 +00:00
|
|
|
}
|
2002-03-11 21:42:35 +00:00
|
|
|
if (pp != NULL) {
|
|
|
|
sbuf_printf(sb, "%s<index>%u</index>\n", indent, pp->index);
|
2002-10-20 18:48:12 +00:00
|
|
|
sbuf_printf(sb, "%s<length>%ju</length>\n",
|
|
|
|
indent, (uintmax_t)gsp->slices[pp->index].length);
|
|
|
|
sbuf_printf(sb, "%s<seclength>%ju</seclength>\n", indent,
|
|
|
|
(uintmax_t)gsp->slices[pp->index].length / 512);
|
|
|
|
sbuf_printf(sb, "%s<offset>%ju</offset>\n", indent,
|
|
|
|
(uintmax_t)gsp->slices[pp->index].offset);
|
|
|
|
sbuf_printf(sb, "%s<secoffset>%ju</secoffset>\n", indent,
|
|
|
|
(uintmax_t)gsp->slices[pp->index].offset / 512);
|
2002-03-11 21:42:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-09-27 21:37:11 +00:00
|
|
|
int
|
2002-12-16 22:33:27 +00:00
|
|
|
g_slice_config(struct g_geom *gp, u_int idx, int how, off_t offset, off_t length, u_int sectorsize, const char *fmt, ...)
|
2002-09-27 21:37:11 +00:00
|
|
|
{
|
2003-02-11 14:57:34 +00:00
|
|
|
struct g_provider *pp, *pp2;
|
2002-09-27 21:37:11 +00:00
|
|
|
struct g_slicer *gsp;
|
|
|
|
struct g_slice *gsl;
|
|
|
|
va_list ap;
|
|
|
|
struct sbuf *sb;
|
|
|
|
int error, acc;
|
|
|
|
|
2002-09-30 08:54:46 +00:00
|
|
|
g_trace(G_T_TOPOLOGY, "g_slice_config(%s, %d, %d)",
|
2002-12-16 22:33:27 +00:00
|
|
|
gp->name, idx, how);
|
2002-09-27 21:37:11 +00:00
|
|
|
g_topology_assert();
|
|
|
|
gsp = gp->softc;
|
|
|
|
error = 0;
|
2002-12-16 22:33:27 +00:00
|
|
|
if (idx >= gsp->nslice)
|
2002-09-27 21:37:11 +00:00
|
|
|
return(EINVAL);
|
2002-12-16 22:33:27 +00:00
|
|
|
gsl = &gsp->slices[idx];
|
2002-09-27 21:37:11 +00:00
|
|
|
pp = gsl->provider;
|
|
|
|
if (pp != NULL)
|
|
|
|
acc = pp->acr + pp->acw + pp->ace;
|
|
|
|
else
|
|
|
|
acc = 0;
|
|
|
|
if (acc != 0 && how != G_SLICE_CONFIG_FORCE) {
|
|
|
|
if (length < gsl->length)
|
|
|
|
return(EBUSY);
|
|
|
|
if (offset != gsl->offset)
|
|
|
|
return(EBUSY);
|
|
|
|
}
|
|
|
|
/* XXX: check offset + length <= MEDIASIZE */
|
|
|
|
if (how == G_SLICE_CONFIG_CHECK)
|
|
|
|
return (0);
|
|
|
|
gsl->length = length;
|
|
|
|
gsl->offset = offset;
|
2002-10-20 19:18:07 +00:00
|
|
|
gsl->sectorsize = sectorsize;
|
2002-10-25 20:09:45 +00:00
|
|
|
if (length == 0) {
|
|
|
|
if (pp == NULL)
|
|
|
|
return (0);
|
|
|
|
if (bootverbose)
|
|
|
|
printf("GEOM: Deconfigure %s\n", pp->name);
|
2002-09-27 21:37:11 +00:00
|
|
|
g_orphan_provider(pp, ENXIO);
|
|
|
|
gsl->provider = NULL;
|
|
|
|
gsp->nprovider--;
|
|
|
|
return (0);
|
|
|
|
}
|
2002-10-25 20:09:45 +00:00
|
|
|
if (pp != NULL) {
|
|
|
|
if (bootverbose)
|
|
|
|
printf("GEOM: Reconfigure %s, start %jd length %jd end %jd\n",
|
|
|
|
pp->name, (intmax_t)offset, (intmax_t)length,
|
|
|
|
(intmax_t)(offset + length - 1));
|
2002-11-20 20:12:52 +00:00
|
|
|
pp->mediasize = gsl->length;
|
2002-10-25 20:09:45 +00:00
|
|
|
return (0);
|
|
|
|
}
|
2002-09-27 21:37:11 +00:00
|
|
|
va_start(ap, fmt);
|
|
|
|
sb = sbuf_new(NULL, NULL, 0, SBUF_AUTOEXTEND);
|
|
|
|
sbuf_vprintf(sb, fmt, ap);
|
|
|
|
sbuf_finish(sb);
|
|
|
|
pp = g_new_providerf(gp, sbuf_data(sb));
|
2003-02-11 14:57:34 +00:00
|
|
|
pp2 = LIST_FIRST(&gp->consumer)->provider;
|
|
|
|
pp->flags = pp2->flags & G_PF_CANDELETE;
|
2003-02-11 15:23:41 +00:00
|
|
|
if (pp2->stripesize > 0) {
|
|
|
|
pp->stripesize = pp2->stripesize;
|
|
|
|
pp->stripeoffset = (pp2->stripeoffset + offset) % pp->stripesize;
|
|
|
|
}
|
2002-10-25 20:09:45 +00:00
|
|
|
if (bootverbose)
|
|
|
|
printf("GEOM: Configure %s, start %jd length %jd end %jd\n",
|
|
|
|
pp->name, (intmax_t)offset, (intmax_t)length,
|
|
|
|
(intmax_t)(offset + length - 1));
|
2002-12-16 22:33:27 +00:00
|
|
|
pp->index = idx;
|
2002-10-20 19:18:07 +00:00
|
|
|
pp->mediasize = gsl->length;
|
|
|
|
pp->sectorsize = gsl->sectorsize;
|
2002-09-27 21:37:11 +00:00
|
|
|
gsl->provider = pp;
|
|
|
|
gsp->nprovider++;
|
|
|
|
g_error_provider(pp, 0);
|
|
|
|
sbuf_delete(sb);
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
2002-12-02 19:59:25 +00:00
|
|
|
int
|
2002-12-16 22:33:27 +00:00
|
|
|
g_slice_conf_hot(struct g_geom *gp, u_int idx, off_t offset, off_t length)
|
2002-12-02 19:59:25 +00:00
|
|
|
{
|
|
|
|
struct g_slicer *gsp;
|
|
|
|
struct g_slice *gsl, *gsl2;
|
|
|
|
|
|
|
|
g_trace(G_T_TOPOLOGY, "g_slice_conf_hot()");
|
|
|
|
g_topology_assert();
|
|
|
|
gsp = gp->softc;
|
|
|
|
gsl = gsp->hot;
|
2002-12-16 22:33:27 +00:00
|
|
|
if(idx >= gsp->nhot) {
|
2003-01-21 08:56:16 +00:00
|
|
|
gsl2 = g_malloc((idx + 1) * sizeof *gsl2, M_ZERO);
|
2002-12-02 19:59:25 +00:00
|
|
|
if (gsp->hot != NULL)
|
|
|
|
bcopy(gsp->hot, gsl2, gsp->nhot * sizeof *gsl2);
|
|
|
|
gsp->hot = gsl2;
|
|
|
|
if (gsp->hot != NULL)
|
|
|
|
g_free(gsl);
|
|
|
|
gsl = gsl2;
|
2002-12-16 22:33:27 +00:00
|
|
|
gsp->nhot = idx + 1;
|
2002-12-02 19:59:25 +00:00
|
|
|
}
|
|
|
|
if (bootverbose)
|
|
|
|
printf("GEOM: Add %s hot[%d] start %jd length %jd end %jd\n",
|
2002-12-16 22:33:27 +00:00
|
|
|
gp->name, idx, (intmax_t)offset, (intmax_t)length,
|
2002-12-02 19:59:25 +00:00
|
|
|
(intmax_t)(offset + length - 1));
|
2002-12-16 22:33:27 +00:00
|
|
|
gsl[idx].offset = offset;
|
|
|
|
gsl[idx].length = length;
|
2002-12-02 19:59:25 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2002-03-11 21:42:35 +00:00
|
|
|
struct g_geom *
|
2002-12-02 19:59:25 +00:00
|
|
|
g_slice_new(struct g_class *mp, u_int slices, struct g_provider *pp, struct g_consumer **cpp, void *extrap, int extra, g_slice_start_t *start)
|
2002-03-11 21:42:35 +00:00
|
|
|
{
|
|
|
|
struct g_geom *gp;
|
|
|
|
struct g_slicer *gsp;
|
|
|
|
struct g_consumer *cp;
|
|
|
|
void **vp;
|
2002-04-09 15:43:32 +00:00
|
|
|
int error, i;
|
2002-03-11 21:42:35 +00:00
|
|
|
|
|
|
|
g_topology_assert();
|
|
|
|
vp = (void **)extrap;
|
|
|
|
gp = g_new_geomf(mp, "%s", pp->name);
|
|
|
|
gsp = g_slice_init(slices, extra);
|
|
|
|
gsp->start = start;
|
2002-04-04 09:54:13 +00:00
|
|
|
gp->access = g_slice_access;
|
|
|
|
gp->orphan = g_slice_orphan;
|
2002-03-11 21:42:35 +00:00
|
|
|
gp->softc = gsp;
|
|
|
|
gp->start = g_slice_start;
|
|
|
|
gp->spoiled = g_std_spoiled;
|
|
|
|
gp->dumpconf = g_slice_dumpconf;
|
|
|
|
cp = g_new_consumer(gp);
|
2002-10-20 20:28:24 +00:00
|
|
|
error = g_attach(cp, pp);
|
|
|
|
if (error == 0)
|
|
|
|
error = g_access_rel(cp, 1, 0, 0);
|
2002-03-11 21:42:35 +00:00
|
|
|
if (error) {
|
2002-10-20 20:28:24 +00:00
|
|
|
if (cp->provider != NULL)
|
|
|
|
g_detach(cp);
|
2002-03-11 21:42:35 +00:00
|
|
|
g_destroy_consumer(cp);
|
2002-03-15 21:41:41 +00:00
|
|
|
g_free(gsp->slices);
|
2002-03-11 21:42:35 +00:00
|
|
|
g_free(gp->softc);
|
|
|
|
g_destroy_geom(gp);
|
|
|
|
return (NULL);
|
|
|
|
}
|
2002-04-09 15:43:32 +00:00
|
|
|
/* Find out if there are any magic bytes on the consumer */
|
|
|
|
i = sizeof gsp->cfrontstuff;
|
|
|
|
error = g_io_getattr("GEOM::frontstuff", cp, &i, &gsp->cfrontstuff);
|
|
|
|
if (error)
|
|
|
|
gsp->cfrontstuff = 0;
|
2002-03-11 21:42:35 +00:00
|
|
|
*vp = gsp->softc;
|
|
|
|
*cpp = cp;
|
|
|
|
return (gp);
|
|
|
|
}
|
|
|
|
|
2002-04-04 09:54:13 +00:00
|
|
|
static void
|
2002-03-26 22:07:38 +00:00
|
|
|
g_slice_orphan(struct g_consumer *cp)
|
2002-03-11 21:42:35 +00:00
|
|
|
{
|
|
|
|
struct g_geom *gp;
|
|
|
|
struct g_provider *pp;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
g_trace(G_T_TOPOLOGY, "g_slice_orphan(%p/%s)", cp, cp->provider->name);
|
|
|
|
g_topology_assert();
|
|
|
|
KASSERT(cp->provider->error != 0,
|
|
|
|
("g_slice_orphan with error == 0"));
|
|
|
|
|
|
|
|
gp = cp->geom;
|
2002-12-02 19:59:25 +00:00
|
|
|
/* XXX: Not good enough we leak the softc and its suballocations */
|
2002-03-11 21:42:35 +00:00
|
|
|
gp->flags |= G_GEOM_WITHER;
|
|
|
|
error = cp->provider->error;
|
|
|
|
LIST_FOREACH(pp, &gp->provider, provider)
|
|
|
|
g_orphan_provider(pp, error);
|
|
|
|
return;
|
|
|
|
}
|