2005-01-06 18:27:30 +00:00
|
|
|
/*-
|
2003-01-18 10:08:27 +00:00
|
|
|
* Copyright (c) 2003 Poul-Henning Kamp.
|
1995-12-27 10:49:19 +00:00
|
|
|
* Copyright (c) 1995 Jason R. Thorpe.
|
2003-01-18 10:08:27 +00:00
|
|
|
* Copyright (c) 1990, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
1995-12-27 10:49:19 +00:00
|
|
|
* All rights reserved.
|
2003-01-18 10:08:27 +00:00
|
|
|
* Copyright (c) 1988 University of Utah.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to Berkeley by
|
|
|
|
* the Systems Programming Group of the University of Utah Computer
|
|
|
|
* Science Department.
|
1995-12-27 10:49:19 +00:00
|
|
|
*
|
|
|
|
* 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. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed for the NetBSD Project
|
|
|
|
* by Jason R. Thorpe.
|
2003-01-18 10:08:27 +00:00
|
|
|
* 4. The names of the authors may not be used to endorse or promote products
|
1995-12-27 10:49:19 +00:00
|
|
|
* derived from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 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.
|
|
|
|
*
|
|
|
|
* Dynamic configuration and disklabel support by:
|
|
|
|
* Jason R. Thorpe <thorpej@nas.nasa.gov>
|
|
|
|
* Numerical Aerodynamic Simulation Facility
|
|
|
|
* Mail Stop 258-6
|
|
|
|
* NASA Ames Research Center
|
|
|
|
* Moffett Field, CA 94035
|
2003-01-18 10:08:27 +00:00
|
|
|
*
|
|
|
|
* from: Utah $Hdr: cd.c 1.6 90/11/28$
|
|
|
|
* @(#)cd.c 8.2 (Berkeley) 11/16/93
|
|
|
|
* $NetBSD: ccd.c,v 1.22 1995/12/08 19:13:26 thorpej Exp $
|
1995-12-27 10:49:19 +00:00
|
|
|
*/
|
|
|
|
|
2003-06-11 06:49:16 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
1995-12-27 10:49:19 +00:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
1996-03-21 04:13:25 +00:00
|
|
|
#include <sys/kernel.h>
|
1999-01-22 22:38:28 +00:00
|
|
|
#include <sys/module.h>
|
2000-05-05 09:59:14 +00:00
|
|
|
#include <sys/bio.h>
|
1995-12-27 10:49:19 +00:00
|
|
|
#include <sys/malloc.h>
|
2003-06-02 20:50:03 +00:00
|
|
|
#include <geom/geom.h>
|
1995-12-27 10:49:19 +00:00
|
|
|
|
2003-06-02 21:29:04 +00:00
|
|
|
/*
|
2003-06-04 18:16:09 +00:00
|
|
|
* Number of blocks to untouched in front of a component partition.
|
|
|
|
* This is to avoid violating its disklabel area when it starts at the
|
|
|
|
* beginning of the slice.
|
2003-06-02 21:29:04 +00:00
|
|
|
*/
|
2003-06-04 18:16:09 +00:00
|
|
|
#if !defined(CCD_OFFSET)
|
|
|
|
#define CCD_OFFSET 16
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* sc_flags */
|
|
|
|
#define CCDF_UNIFORM 0x02 /* use LCCD of sizes for uniform interleave */
|
|
|
|
#define CCDF_MIRROR 0x04 /* use mirroring */
|
2006-04-13 20:35:31 +00:00
|
|
|
#define CCDF_NO_OFFSET 0x08 /* do not leave space in front */
|
|
|
|
#define CCDF_LINUX 0x10 /* use Linux compatibility mode */
|
2003-06-04 18:16:09 +00:00
|
|
|
|
|
|
|
/* Mask of user-settable ccd flags. */
|
|
|
|
#define CCDF_USERMASK (CCDF_UNIFORM|CCDF_MIRROR)
|
2003-06-02 21:29:04 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Interleave description table.
|
|
|
|
* Computed at boot time to speed irregular-interleave lookups.
|
|
|
|
* The idea is that we interleave in "groups". First we interleave
|
|
|
|
* evenly over all component disks up to the size of the smallest
|
|
|
|
* component (the first group), then we interleave evenly over all
|
|
|
|
* remaining disks up to the size of the next-smallest (second group),
|
|
|
|
* and so on.
|
|
|
|
*
|
|
|
|
* Each table entry describes the interleave characteristics of one
|
|
|
|
* of these groups. For example if a concatenated disk consisted of
|
|
|
|
* three components of 5, 3, and 7 DEV_BSIZE blocks interleaved at
|
|
|
|
* DEV_BSIZE (1), the table would have three entries:
|
|
|
|
*
|
|
|
|
* ndisk startblk startoff dev
|
|
|
|
* 3 0 0 0, 1, 2
|
|
|
|
* 2 9 3 0, 2
|
|
|
|
* 1 13 5 2
|
|
|
|
* 0 - - -
|
|
|
|
*
|
|
|
|
* which says that the first nine blocks (0-8) are interleaved over
|
|
|
|
* 3 disks (0, 1, 2) starting at block offset 0 on any component disk,
|
|
|
|
* the next 4 blocks (9-12) are interleaved over 2 disks (0, 2) starting
|
|
|
|
* at component block 3, and the remaining blocks (13-14) are on disk
|
|
|
|
* 2 starting at offset 5.
|
|
|
|
*/
|
|
|
|
struct ccdiinfo {
|
|
|
|
int ii_ndisk; /* # of disks range is interleaved over */
|
|
|
|
daddr_t ii_startblk; /* starting scaled block # for range */
|
|
|
|
daddr_t ii_startoff; /* starting component offset (block #) */
|
|
|
|
int *ii_index; /* ordered list of components in range */
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
2003-06-04 18:16:09 +00:00
|
|
|
* Component info table.
|
|
|
|
* Describes a single component of a concatenated disk.
|
2003-06-02 21:29:04 +00:00
|
|
|
*/
|
2003-06-04 18:16:09 +00:00
|
|
|
struct ccdcinfo {
|
2003-08-22 11:21:06 +00:00
|
|
|
daddr_t ci_size; /* size */
|
2003-06-04 18:16:09 +00:00
|
|
|
struct g_provider *ci_provider; /* provider */
|
|
|
|
struct g_consumer *ci_consumer; /* consumer */
|
2003-06-02 21:29:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* A concatenated disk is described by this structure.
|
|
|
|
*/
|
2003-06-04 18:16:09 +00:00
|
|
|
|
2003-06-02 21:29:04 +00:00
|
|
|
struct ccd_s {
|
|
|
|
LIST_ENTRY(ccd_s) list;
|
|
|
|
|
|
|
|
int sc_unit; /* logical unit number */
|
|
|
|
int sc_flags; /* flags */
|
2003-08-22 11:21:06 +00:00
|
|
|
daddr_t sc_size; /* size of ccd */
|
2003-06-02 21:29:04 +00:00
|
|
|
int sc_ileave; /* interleave */
|
2003-06-04 18:16:09 +00:00
|
|
|
u_int sc_ndisks; /* number of components */
|
2003-06-02 21:29:04 +00:00
|
|
|
struct ccdcinfo *sc_cinfo; /* component info */
|
|
|
|
struct ccdiinfo *sc_itable; /* interleave table */
|
2003-06-04 18:16:09 +00:00
|
|
|
u_int32_t sc_secsize; /* # bytes per sector */
|
2003-06-02 21:29:04 +00:00
|
|
|
int sc_pick; /* side of mirror picked */
|
|
|
|
daddr_t sc_blk[2]; /* mirror localization */
|
2006-04-13 20:35:31 +00:00
|
|
|
u_int32_t sc_offset; /* actual offset used */
|
1995-12-27 10:49:19 +00:00
|
|
|
};
|
|
|
|
|
2003-06-04 18:16:09 +00:00
|
|
|
static g_start_t g_ccd_start;
|
2001-09-04 08:33:30 +00:00
|
|
|
static void ccdiodone(struct bio *bp);
|
2003-06-04 18:16:09 +00:00
|
|
|
static void ccdinterleave(struct ccd_s *);
|
|
|
|
static int ccdinit(struct gctl_req *req, struct ccd_s *);
|
|
|
|
static int ccdbuffer(struct bio **ret, struct ccd_s *,
|
2001-09-04 08:33:30 +00:00
|
|
|
struct bio *, daddr_t, caddr_t, long);
|
|
|
|
|
2003-06-04 18:16:09 +00:00
|
|
|
static void
|
|
|
|
g_ccd_orphan(struct g_consumer *cp)
|
2001-09-04 08:33:30 +00:00
|
|
|
{
|
2003-06-07 11:06:44 +00:00
|
|
|
/*
|
|
|
|
* XXX: We don't do anything here. It is not obvious
|
|
|
|
* XXX: what DTRT would be, so we do what the previous
|
|
|
|
* XXX: code did: ignore it and let the user cope.
|
|
|
|
*/
|
2001-09-04 08:33:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2003-06-04 18:16:09 +00:00
|
|
|
g_ccd_access(struct g_provider *pp, int dr, int dw, int de)
|
2001-09-04 08:33:30 +00:00
|
|
|
{
|
2003-06-04 18:16:09 +00:00
|
|
|
struct g_geom *gp;
|
|
|
|
struct g_consumer *cp1, *cp2;
|
|
|
|
int error;
|
2001-09-04 08:33:30 +00:00
|
|
|
|
2003-06-04 18:16:09 +00:00
|
|
|
de += dr;
|
|
|
|
de += dw;
|
|
|
|
|
|
|
|
gp = pp->geom;
|
|
|
|
error = ENXIO;
|
|
|
|
LIST_FOREACH(cp1, &gp->consumer, consumer) {
|
2004-02-12 22:42:11 +00:00
|
|
|
error = g_access(cp1, dr, dw, de);
|
2003-06-04 18:16:09 +00:00
|
|
|
if (error) {
|
|
|
|
LIST_FOREACH(cp2, &gp->consumer, consumer) {
|
|
|
|
if (cp1 == cp2)
|
|
|
|
break;
|
2004-02-12 22:42:11 +00:00
|
|
|
g_access(cp2, -dr, -dw, -de);
|
2003-06-04 18:16:09 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return (error);
|
2001-09-04 08:33:30 +00:00
|
|
|
}
|
|
|
|
|
1995-12-27 10:49:19 +00:00
|
|
|
/*
|
2003-06-04 18:16:09 +00:00
|
|
|
* Free the softc and its substructures.
|
1995-12-27 10:49:19 +00:00
|
|
|
*/
|
1997-10-24 14:24:55 +00:00
|
|
|
static void
|
2003-06-04 18:16:09 +00:00
|
|
|
g_ccd_freesc(struct ccd_s *sc)
|
1995-12-27 10:49:19 +00:00
|
|
|
{
|
2003-06-04 18:16:09 +00:00
|
|
|
struct ccdiinfo *ii;
|
1995-12-27 10:49:19 +00:00
|
|
|
|
2003-06-04 18:16:09 +00:00
|
|
|
g_free(sc->sc_cinfo);
|
|
|
|
if (sc->sc_itable != NULL) {
|
|
|
|
for (ii = sc->sc_itable; ii->ii_ndisk > 0; ii++)
|
|
|
|
if (ii->ii_index != NULL)
|
|
|
|
g_free(ii->ii_index);
|
|
|
|
g_free(sc->sc_itable);
|
1996-03-21 04:13:25 +00:00
|
|
|
}
|
2003-06-04 18:16:09 +00:00
|
|
|
g_free(sc);
|
1995-12-27 10:49:19 +00:00
|
|
|
}
|
|
|
|
|
1999-01-22 22:38:28 +00:00
|
|
|
|
1995-12-27 10:49:19 +00:00
|
|
|
static int
|
2003-06-04 18:16:09 +00:00
|
|
|
ccdinit(struct gctl_req *req, struct ccd_s *cs)
|
1995-12-27 10:49:19 +00:00
|
|
|
{
|
2003-06-04 18:16:09 +00:00
|
|
|
struct ccdcinfo *ci;
|
2003-08-22 11:21:06 +00:00
|
|
|
daddr_t size;
|
1999-09-23 09:25:05 +00:00
|
|
|
int ix;
|
2003-08-22 11:21:06 +00:00
|
|
|
daddr_t minsize;
|
1995-12-27 10:49:19 +00:00
|
|
|
int maxsecsize;
|
2002-04-02 11:17:37 +00:00
|
|
|
off_t mediasize;
|
|
|
|
u_int sectorsize;
|
1995-12-27 10:49:19 +00:00
|
|
|
|
|
|
|
cs->sc_size = 0;
|
|
|
|
|
|
|
|
maxsecsize = 0;
|
|
|
|
minsize = 0;
|
2006-04-13 20:35:31 +00:00
|
|
|
|
|
|
|
if (cs->sc_flags & CCDF_LINUX) {
|
|
|
|
cs->sc_offset = 0;
|
|
|
|
cs->sc_ileave *= 2;
|
|
|
|
if (cs->sc_flags & CCDF_MIRROR && cs->sc_ndisks != 2)
|
|
|
|
gctl_error(req, "Mirror mode for Linux raids is "
|
|
|
|
"only supported with 2 devices");
|
|
|
|
} else {
|
|
|
|
if (cs->sc_flags & CCDF_NO_OFFSET)
|
|
|
|
cs->sc_offset = 0;
|
|
|
|
else
|
|
|
|
cs->sc_offset = CCD_OFFSET;
|
|
|
|
|
|
|
|
}
|
2003-06-04 18:16:09 +00:00
|
|
|
for (ix = 0; ix < cs->sc_ndisks; ix++) {
|
1995-12-27 10:49:19 +00:00
|
|
|
ci = &cs->sc_cinfo[ix];
|
|
|
|
|
2003-06-04 18:16:09 +00:00
|
|
|
mediasize = ci->ci_provider->mediasize;
|
|
|
|
sectorsize = ci->ci_provider->sectorsize;
|
2002-04-02 11:17:37 +00:00
|
|
|
if (sectorsize > maxsecsize)
|
|
|
|
maxsecsize = sectorsize;
|
2006-04-13 20:35:31 +00:00
|
|
|
size = mediasize / DEV_BSIZE - cs->sc_offset;
|
1995-12-27 10:49:19 +00:00
|
|
|
|
2003-06-04 18:16:09 +00:00
|
|
|
/* Truncate to interleave boundary */
|
1995-12-27 10:49:19 +00:00
|
|
|
|
|
|
|
if (cs->sc_ileave > 1)
|
|
|
|
size -= size % cs->sc_ileave;
|
|
|
|
|
|
|
|
if (size == 0) {
|
2003-06-04 18:16:09 +00:00
|
|
|
gctl_error(req, "Component %s has effective size zero",
|
|
|
|
ci->ci_provider->name);
|
|
|
|
return(ENODEV);
|
1995-12-27 10:49:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (minsize == 0 || size < minsize)
|
|
|
|
minsize = size;
|
|
|
|
ci->ci_size = size;
|
|
|
|
cs->sc_size += size;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Don't allow the interleave to be smaller than
|
|
|
|
* the biggest component sector.
|
|
|
|
*/
|
|
|
|
if ((cs->sc_ileave > 0) &&
|
|
|
|
(cs->sc_ileave < (maxsecsize / DEV_BSIZE))) {
|
2003-06-04 18:16:09 +00:00
|
|
|
gctl_error(req, "Interleave to small for sector size");
|
|
|
|
return(EINVAL);
|
1995-12-27 10:49:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If uniform interleave is desired set all sizes to that of
|
1999-09-23 09:25:05 +00:00
|
|
|
* the smallest component. This will guarentee that a single
|
|
|
|
* interleave table is generated.
|
|
|
|
*
|
|
|
|
* Lost space must be taken into account when calculating the
|
|
|
|
* overall size. Half the space is lost when CCDF_MIRROR is
|
2003-01-17 14:53:53 +00:00
|
|
|
* specified.
|
1995-12-27 10:49:19 +00:00
|
|
|
*/
|
2001-09-04 08:33:30 +00:00
|
|
|
if (cs->sc_flags & CCDF_UNIFORM) {
|
2003-06-04 18:16:09 +00:00
|
|
|
for (ix = 0; ix < cs->sc_ndisks; ix++) {
|
|
|
|
ci = &cs->sc_cinfo[ix];
|
1995-12-27 10:49:19 +00:00
|
|
|
ci->ci_size = minsize;
|
1999-09-23 09:25:05 +00:00
|
|
|
}
|
2003-06-04 18:16:09 +00:00
|
|
|
cs->sc_size = cs->sc_ndisks * minsize;
|
1995-12-27 10:49:19 +00:00
|
|
|
}
|
|
|
|
|
2003-06-04 18:16:09 +00:00
|
|
|
if (cs->sc_flags & CCDF_MIRROR) {
|
|
|
|
/*
|
|
|
|
* Check to see if an even number of components
|
|
|
|
* have been specified. The interleave must also
|
|
|
|
* be non-zero in order for us to be able to
|
|
|
|
* guarentee the topology.
|
|
|
|
*/
|
|
|
|
if (cs->sc_ndisks % 2) {
|
|
|
|
gctl_error(req,
|
|
|
|
"Mirroring requires an even number of disks");
|
|
|
|
return(EINVAL);
|
|
|
|
}
|
|
|
|
if (cs->sc_ileave == 0) {
|
|
|
|
gctl_error(req,
|
|
|
|
"An interleave must be specified when mirroring");
|
|
|
|
return(EINVAL);
|
|
|
|
}
|
|
|
|
cs->sc_size = (cs->sc_ndisks/2) * minsize;
|
|
|
|
}
|
|
|
|
|
1995-12-27 10:49:19 +00:00
|
|
|
/*
|
|
|
|
* Construct the interleave table.
|
|
|
|
*/
|
2003-06-04 18:16:09 +00:00
|
|
|
ccdinterleave(cs);
|
1995-12-27 10:49:19 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Create pseudo-geometry based on 1MB cylinders. It's
|
|
|
|
* pretty close.
|
|
|
|
*/
|
2003-06-04 18:16:09 +00:00
|
|
|
cs->sc_secsize = maxsecsize;
|
1995-12-27 10:49:19 +00:00
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2003-06-04 18:16:09 +00:00
|
|
|
ccdinterleave(struct ccd_s *cs)
|
1995-12-27 10:49:19 +00:00
|
|
|
{
|
1999-09-23 09:25:05 +00:00
|
|
|
struct ccdcinfo *ci, *smallci;
|
|
|
|
struct ccdiinfo *ii;
|
|
|
|
daddr_t bn, lbn;
|
|
|
|
int ix;
|
2003-08-22 11:21:06 +00:00
|
|
|
daddr_t size;
|
1995-12-27 10:49:19 +00:00
|
|
|
|
1999-09-23 09:25:05 +00:00
|
|
|
|
1995-12-27 10:49:19 +00:00
|
|
|
/*
|
1999-09-23 09:25:05 +00:00
|
|
|
* Allocate an interleave table. The worst case occurs when each
|
|
|
|
* of N disks is of a different size, resulting in N interleave
|
|
|
|
* tables.
|
|
|
|
*
|
1995-12-27 10:49:19 +00:00
|
|
|
* Chances are this is too big, but we don't care.
|
|
|
|
*/
|
2003-06-04 18:16:09 +00:00
|
|
|
size = (cs->sc_ndisks + 1) * sizeof(struct ccdiinfo);
|
|
|
|
cs->sc_itable = g_malloc(size, M_WAITOK | M_ZERO);
|
1995-12-27 10:49:19 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Trivial case: no interleave (actually interleave of disk size).
|
|
|
|
* Each table entry represents a single component in its entirety.
|
1999-09-23 09:25:05 +00:00
|
|
|
*
|
2003-01-17 14:53:53 +00:00
|
|
|
* An interleave of 0 may not be used with a mirror setup.
|
1995-12-27 10:49:19 +00:00
|
|
|
*/
|
|
|
|
if (cs->sc_ileave == 0) {
|
|
|
|
bn = 0;
|
|
|
|
ii = cs->sc_itable;
|
|
|
|
|
2003-06-04 18:16:09 +00:00
|
|
|
for (ix = 0; ix < cs->sc_ndisks; ix++) {
|
1995-12-27 10:49:19 +00:00
|
|
|
/* Allocate space for ii_index. */
|
2003-06-04 18:16:09 +00:00
|
|
|
ii->ii_index = g_malloc(sizeof(int), M_WAITOK);
|
1995-12-27 10:49:19 +00:00
|
|
|
ii->ii_ndisk = 1;
|
|
|
|
ii->ii_startblk = bn;
|
|
|
|
ii->ii_startoff = 0;
|
|
|
|
ii->ii_index[0] = ix;
|
|
|
|
bn += cs->sc_cinfo[ix].ci_size;
|
|
|
|
ii++;
|
|
|
|
}
|
|
|
|
ii->ii_ndisk = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The following isn't fast or pretty; it doesn't have to be.
|
|
|
|
*/
|
|
|
|
size = 0;
|
|
|
|
bn = lbn = 0;
|
|
|
|
for (ii = cs->sc_itable; ; ii++) {
|
1999-09-23 09:25:05 +00:00
|
|
|
/*
|
|
|
|
* Allocate space for ii_index. We might allocate more then
|
|
|
|
* we use.
|
|
|
|
*/
|
2003-06-04 18:16:09 +00:00
|
|
|
ii->ii_index = g_malloc((sizeof(int) * cs->sc_ndisks),
|
|
|
|
M_WAITOK);
|
1995-12-27 10:49:19 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Locate the smallest of the remaining components
|
|
|
|
*/
|
|
|
|
smallci = NULL;
|
2003-06-04 18:16:09 +00:00
|
|
|
for (ci = cs->sc_cinfo; ci < &cs->sc_cinfo[cs->sc_ndisks];
|
1999-09-23 09:25:05 +00:00
|
|
|
ci++) {
|
1995-12-27 10:49:19 +00:00
|
|
|
if (ci->ci_size > size &&
|
|
|
|
(smallci == NULL ||
|
1999-09-23 09:25:05 +00:00
|
|
|
ci->ci_size < smallci->ci_size)) {
|
1995-12-27 10:49:19 +00:00
|
|
|
smallci = ci;
|
1999-09-23 09:25:05 +00:00
|
|
|
}
|
|
|
|
}
|
1995-12-27 10:49:19 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Nobody left, all done
|
|
|
|
*/
|
|
|
|
if (smallci == NULL) {
|
|
|
|
ii->ii_ndisk = 0;
|
2003-06-04 18:16:09 +00:00
|
|
|
g_free(ii->ii_index);
|
|
|
|
ii->ii_index = NULL;
|
1995-12-27 10:49:19 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
1999-09-23 09:25:05 +00:00
|
|
|
* Record starting logical block using an sc_ileave blocksize.
|
1995-12-27 10:49:19 +00:00
|
|
|
*/
|
|
|
|
ii->ii_startblk = bn / cs->sc_ileave;
|
1999-09-23 09:25:05 +00:00
|
|
|
|
|
|
|
/*
|
2003-06-04 18:16:09 +00:00
|
|
|
* Record starting component block using an sc_ileave
|
1999-09-23 09:25:05 +00:00
|
|
|
* blocksize. This value is relative to the beginning of
|
|
|
|
* a component disk.
|
|
|
|
*/
|
1995-12-27 10:49:19 +00:00
|
|
|
ii->ii_startoff = lbn;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Determine how many disks take part in this interleave
|
|
|
|
* and record their indices.
|
|
|
|
*/
|
|
|
|
ix = 0;
|
1999-09-23 09:25:05 +00:00
|
|
|
for (ci = cs->sc_cinfo;
|
2003-06-04 18:16:09 +00:00
|
|
|
ci < &cs->sc_cinfo[cs->sc_ndisks]; ci++) {
|
1999-09-23 09:25:05 +00:00
|
|
|
if (ci->ci_size >= smallci->ci_size) {
|
1995-12-27 10:49:19 +00:00
|
|
|
ii->ii_index[ix++] = ci - cs->sc_cinfo;
|
1999-09-23 09:25:05 +00:00
|
|
|
}
|
|
|
|
}
|
1995-12-27 10:49:19 +00:00
|
|
|
ii->ii_ndisk = ix;
|
|
|
|
bn += ix * (smallci->ci_size - size);
|
|
|
|
lbn = smallci->ci_size / cs->sc_ileave;
|
|
|
|
size = smallci->ci_size;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1997-10-24 14:24:55 +00:00
|
|
|
static void
|
2003-06-04 18:16:09 +00:00
|
|
|
g_ccd_start(struct bio *bp)
|
1995-12-27 10:49:19 +00:00
|
|
|
{
|
1999-09-23 09:25:05 +00:00
|
|
|
long bcount, rcount;
|
2003-06-04 18:16:09 +00:00
|
|
|
struct bio *cbp[2];
|
1995-12-27 10:49:19 +00:00
|
|
|
caddr_t addr;
|
|
|
|
daddr_t bn;
|
2003-01-19 15:00:58 +00:00
|
|
|
int err;
|
2003-06-04 18:16:09 +00:00
|
|
|
struct ccd_s *cs;
|
|
|
|
|
|
|
|
cs = bp->bio_to->geom->softc;
|
1995-12-27 10:49:19 +00:00
|
|
|
|
2003-08-22 10:28:19 +00:00
|
|
|
/*
|
|
|
|
* Block all GETATTR requests, we wouldn't know which of our
|
|
|
|
* subdevices we should ship it off to.
|
|
|
|
* XXX: this may not be the right policy.
|
|
|
|
*/
|
|
|
|
if(bp->bio_cmd == BIO_GETATTR) {
|
|
|
|
g_io_deliver(bp, EINVAL);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
1995-12-27 10:49:19 +00:00
|
|
|
/*
|
|
|
|
* Translate the partition-relative block number to an absolute.
|
|
|
|
*/
|
2003-06-04 18:16:09 +00:00
|
|
|
bn = bp->bio_offset / cs->sc_secsize;
|
1995-12-27 10:49:19 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Allocate component buffers and fire off the requests
|
|
|
|
*/
|
2000-05-01 13:36:43 +00:00
|
|
|
addr = bp->bio_data;
|
2003-06-04 18:16:09 +00:00
|
|
|
for (bcount = bp->bio_length; bcount > 0; bcount -= rcount) {
|
2003-01-19 15:00:58 +00:00
|
|
|
err = ccdbuffer(cbp, cs, bp, bn, addr, bcount);
|
|
|
|
if (err) {
|
2003-06-09 19:12:19 +00:00
|
|
|
bp->bio_completed += bcount;
|
2003-11-12 09:46:54 +00:00
|
|
|
if (bp->bio_error == 0)
|
2003-04-14 08:49:54 +00:00
|
|
|
bp->bio_error = err;
|
2003-06-09 19:12:19 +00:00
|
|
|
if (bp->bio_completed == bp->bio_length)
|
|
|
|
g_io_deliver(bp, bp->bio_error);
|
2003-01-19 15:00:58 +00:00
|
|
|
return;
|
|
|
|
}
|
2003-06-04 18:16:09 +00:00
|
|
|
rcount = cbp[0]->bio_length;
|
1999-09-23 09:25:05 +00:00
|
|
|
|
2003-06-04 18:16:09 +00:00
|
|
|
if (cs->sc_flags & CCDF_MIRROR) {
|
1999-09-23 09:25:05 +00:00
|
|
|
/*
|
|
|
|
* Mirroring. Writes go to both disks, reads are
|
|
|
|
* taken from whichever disk seems most appropriate.
|
|
|
|
*
|
|
|
|
* We attempt to localize reads to the disk whos arm
|
|
|
|
* is nearest the read request. We ignore seeks due
|
|
|
|
* to writes when making this determination and we
|
|
|
|
* also try to avoid hogging.
|
|
|
|
*/
|
2003-06-04 18:16:09 +00:00
|
|
|
if (cbp[0]->bio_cmd != BIO_READ) {
|
|
|
|
g_io_request(cbp[0], cbp[0]->bio_from);
|
|
|
|
g_io_request(cbp[1], cbp[1]->bio_from);
|
1999-09-23 09:25:05 +00:00
|
|
|
} else {
|
|
|
|
int pick = cs->sc_pick;
|
|
|
|
daddr_t range = cs->sc_size / 16;
|
|
|
|
|
|
|
|
if (bn < cs->sc_blk[pick] - range ||
|
|
|
|
bn > cs->sc_blk[pick] + range
|
|
|
|
) {
|
|
|
|
cs->sc_pick = pick = 1 - pick;
|
|
|
|
}
|
|
|
|
cs->sc_blk[pick] = bn + btodb(rcount);
|
2003-06-04 18:16:09 +00:00
|
|
|
g_io_request(cbp[pick], cbp[pick]->bio_from);
|
1999-09-23 09:25:05 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Not mirroring
|
|
|
|
*/
|
2003-06-04 18:16:09 +00:00
|
|
|
g_io_request(cbp[0], cbp[0]->bio_from);
|
1996-01-31 03:28:21 +00:00
|
|
|
}
|
1995-12-27 10:49:19 +00:00
|
|
|
bn += btodb(rcount);
|
|
|
|
addr += rcount;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Build a component buffer header.
|
|
|
|
*/
|
2003-01-19 15:00:58 +00:00
|
|
|
static int
|
2003-06-04 18:16:09 +00:00
|
|
|
ccdbuffer(struct bio **cb, struct ccd_s *cs, struct bio *bp, daddr_t bn, caddr_t addr, long bcount)
|
1995-12-27 10:49:19 +00:00
|
|
|
{
|
2003-06-09 19:12:19 +00:00
|
|
|
struct ccdcinfo *ci, *ci2 = NULL;
|
2003-06-04 18:16:09 +00:00
|
|
|
struct bio *cbp;
|
1999-09-23 09:25:05 +00:00
|
|
|
daddr_t cbn, cboff;
|
|
|
|
off_t cbc;
|
1995-12-27 10:49:19 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Determine which component bn falls in.
|
|
|
|
*/
|
|
|
|
cbn = bn;
|
|
|
|
cboff = 0;
|
|
|
|
|
|
|
|
if (cs->sc_ileave == 0) {
|
1999-09-23 09:25:05 +00:00
|
|
|
/*
|
|
|
|
* Serially concatenated and neither a mirror nor a parity
|
|
|
|
* config. This is a special case.
|
|
|
|
*/
|
|
|
|
daddr_t sblk;
|
1995-12-27 10:49:19 +00:00
|
|
|
|
|
|
|
sblk = 0;
|
|
|
|
for (ci = cs->sc_cinfo; cbn >= sblk + ci->ci_size; ci++)
|
|
|
|
sblk += ci->ci_size;
|
|
|
|
cbn -= sblk;
|
1999-09-23 09:25:05 +00:00
|
|
|
} else {
|
|
|
|
struct ccdiinfo *ii;
|
1995-12-27 10:49:19 +00:00
|
|
|
int ccdisk, off;
|
|
|
|
|
1999-09-23 09:25:05 +00:00
|
|
|
/*
|
|
|
|
* Calculate cbn, the logical superblock (sc_ileave chunks),
|
|
|
|
* and cboff, a normal block offset (DEV_BSIZE chunks) relative
|
|
|
|
* to cbn.
|
|
|
|
*/
|
|
|
|
cboff = cbn % cs->sc_ileave; /* DEV_BSIZE gran */
|
|
|
|
cbn = cbn / cs->sc_ileave; /* DEV_BSIZE * ileave gran */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Figure out which interleave table to use.
|
|
|
|
*/
|
|
|
|
for (ii = cs->sc_itable; ii->ii_ndisk; ii++) {
|
1995-12-27 10:49:19 +00:00
|
|
|
if (ii->ii_startblk > cbn)
|
|
|
|
break;
|
1999-09-23 09:25:05 +00:00
|
|
|
}
|
1995-12-27 10:49:19 +00:00
|
|
|
ii--;
|
1999-09-23 09:25:05 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* off is the logical superblock relative to the beginning
|
|
|
|
* of this interleave block.
|
|
|
|
*/
|
1995-12-27 10:49:19 +00:00
|
|
|
off = cbn - ii->ii_startblk;
|
1999-09-23 09:25:05 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* We must calculate which disk component to use (ccdisk),
|
|
|
|
* and recalculate cbn to be the superblock relative to
|
|
|
|
* the beginning of the component. This is typically done by
|
|
|
|
* adding 'off' and ii->ii_startoff together. However, 'off'
|
|
|
|
* must typically be divided by the number of components in
|
|
|
|
* this interleave array to be properly convert it from a
|
|
|
|
* CCD-relative logical superblock number to a
|
|
|
|
* component-relative superblock number.
|
|
|
|
*/
|
1995-12-27 10:49:19 +00:00
|
|
|
if (ii->ii_ndisk == 1) {
|
1999-09-23 09:25:05 +00:00
|
|
|
/*
|
|
|
|
* When we have just one disk, it can't be a mirror
|
|
|
|
* or a parity config.
|
|
|
|
*/
|
1995-12-27 10:49:19 +00:00
|
|
|
ccdisk = ii->ii_index[0];
|
|
|
|
cbn = ii->ii_startoff + off;
|
|
|
|
} else {
|
2003-06-04 18:16:09 +00:00
|
|
|
if (cs->sc_flags & CCDF_MIRROR) {
|
1999-09-23 09:25:05 +00:00
|
|
|
/*
|
|
|
|
* We have forced a uniform mapping, resulting
|
|
|
|
* in a single interleave array. We double
|
|
|
|
* up on the first half of the available
|
|
|
|
* components and our mirror is in the second
|
|
|
|
* half. This only works with a single
|
|
|
|
* interleave array because doubling up
|
|
|
|
* doubles the number of sectors, so there
|
|
|
|
* cannot be another interleave array because
|
|
|
|
* the next interleave array's calculations
|
|
|
|
* would be off.
|
|
|
|
*/
|
|
|
|
int ndisk2 = ii->ii_ndisk / 2;
|
|
|
|
ccdisk = ii->ii_index[off % ndisk2];
|
|
|
|
cbn = ii->ii_startoff + off / ndisk2;
|
|
|
|
ci2 = &cs->sc_cinfo[ccdisk + ndisk2];
|
|
|
|
} else {
|
1996-01-02 23:32:54 +00:00
|
|
|
ccdisk = ii->ii_index[off % ii->ii_ndisk];
|
|
|
|
cbn = ii->ii_startoff + off / ii->ii_ndisk;
|
|
|
|
}
|
1995-12-27 10:49:19 +00:00
|
|
|
}
|
1999-09-23 09:25:05 +00:00
|
|
|
|
1995-12-27 10:49:19 +00:00
|
|
|
ci = &cs->sc_cinfo[ccdisk];
|
1999-09-23 09:25:05 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Convert cbn from a superblock to a normal block so it
|
|
|
|
* can be used to calculate (along with cboff) the normal
|
|
|
|
* block index into this particular disk.
|
|
|
|
*/
|
|
|
|
cbn *= cs->sc_ileave;
|
1995-12-27 10:49:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Fill in the component buf structure.
|
|
|
|
*/
|
2003-06-04 18:16:09 +00:00
|
|
|
cbp = g_clone_bio(bp);
|
2003-06-09 19:12:19 +00:00
|
|
|
if (cbp == NULL)
|
|
|
|
return (ENOMEM);
|
2003-06-04 18:16:09 +00:00
|
|
|
cbp->bio_done = g_std_done;
|
2006-04-13 20:35:31 +00:00
|
|
|
cbp->bio_offset = dbtob(cbn + cboff + cs->sc_offset);
|
2003-06-04 18:16:09 +00:00
|
|
|
cbp->bio_data = addr;
|
1995-12-27 10:49:19 +00:00
|
|
|
if (cs->sc_ileave == 0)
|
1999-03-11 18:50:39 +00:00
|
|
|
cbc = dbtob((off_t)(ci->ci_size - cbn));
|
1995-12-27 10:49:19 +00:00
|
|
|
else
|
1999-03-11 18:50:39 +00:00
|
|
|
cbc = dbtob((off_t)(cs->sc_ileave - cboff));
|
2003-06-04 18:16:09 +00:00
|
|
|
cbp->bio_length = (cbc < bcount) ? cbc : bcount;
|
1995-12-27 10:49:19 +00:00
|
|
|
|
2003-06-04 18:16:09 +00:00
|
|
|
cbp->bio_from = ci->ci_consumer;
|
1996-01-31 03:28:21 +00:00
|
|
|
cb[0] = cbp;
|
1999-09-23 09:25:05 +00:00
|
|
|
|
2003-06-04 18:16:09 +00:00
|
|
|
if (cs->sc_flags & CCDF_MIRROR) {
|
|
|
|
cbp = g_clone_bio(bp);
|
2003-06-09 19:12:19 +00:00
|
|
|
if (cbp == NULL)
|
|
|
|
return (ENOMEM);
|
2003-06-04 18:16:09 +00:00
|
|
|
cbp->bio_done = cb[0]->bio_done = ccdiodone;
|
|
|
|
cbp->bio_offset = cb[0]->bio_offset;
|
|
|
|
cbp->bio_data = cb[0]->bio_data;
|
|
|
|
cbp->bio_length = cb[0]->bio_length;
|
|
|
|
cbp->bio_from = ci2->ci_consumer;
|
|
|
|
cbp->bio_caller1 = cb[0];
|
|
|
|
cb[0]->bio_caller1 = cbp;
|
1996-01-31 03:28:21 +00:00
|
|
|
cb[1] = cbp;
|
|
|
|
}
|
2003-01-19 15:00:58 +00:00
|
|
|
return (0);
|
1995-12-27 10:49:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2003-06-07 11:06:44 +00:00
|
|
|
* Called only for mirrored operations.
|
1995-12-27 10:49:19 +00:00
|
|
|
*/
|
1997-10-24 14:24:55 +00:00
|
|
|
static void
|
2003-06-04 18:16:09 +00:00
|
|
|
ccdiodone(struct bio *cbp)
|
1995-12-27 10:49:19 +00:00
|
|
|
{
|
2003-06-04 18:16:09 +00:00
|
|
|
struct bio *mbp, *pbp;
|
1999-09-23 09:25:05 +00:00
|
|
|
|
2003-06-04 18:16:09 +00:00
|
|
|
mbp = cbp->bio_caller1;
|
|
|
|
pbp = cbp->bio_parent;
|
1999-09-23 09:25:05 +00:00
|
|
|
|
2003-06-04 18:16:09 +00:00
|
|
|
if (pbp->bio_cmd == BIO_READ) {
|
|
|
|
if (cbp->bio_error == 0) {
|
2003-06-07 11:06:44 +00:00
|
|
|
/* We will not be needing the partner bio */
|
|
|
|
if (mbp != NULL) {
|
|
|
|
pbp->bio_inbed++;
|
|
|
|
g_destroy_bio(mbp);
|
|
|
|
}
|
2003-06-04 18:16:09 +00:00
|
|
|
g_std_done(cbp);
|
|
|
|
return;
|
1996-03-26 02:29:11 +00:00
|
|
|
}
|
2003-06-04 18:16:09 +00:00
|
|
|
if (mbp != NULL) {
|
2003-06-07 11:06:44 +00:00
|
|
|
/* Try partner the bio instead */
|
2003-06-04 18:16:09 +00:00
|
|
|
mbp->bio_caller1 = NULL;
|
|
|
|
pbp->bio_inbed++;
|
|
|
|
g_destroy_bio(cbp);
|
|
|
|
g_io_request(mbp, mbp->bio_from);
|
2003-06-07 11:06:44 +00:00
|
|
|
/*
|
|
|
|
* XXX: If this comes back OK, we should actually
|
|
|
|
* try to write the good data on the failed mirror
|
|
|
|
*/
|
2003-06-04 18:16:09 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
g_std_done(cbp);
|
2003-07-29 20:04:06 +00:00
|
|
|
return;
|
1999-09-23 09:25:05 +00:00
|
|
|
}
|
2003-06-04 18:16:09 +00:00
|
|
|
if (mbp != NULL) {
|
|
|
|
mbp->bio_caller1 = NULL;
|
|
|
|
pbp->bio_inbed++;
|
2003-06-07 11:06:44 +00:00
|
|
|
if (cbp->bio_error != 0 && pbp->bio_error == 0)
|
2003-06-04 18:16:09 +00:00
|
|
|
pbp->bio_error = cbp->bio_error;
|
2003-07-29 20:04:06 +00:00
|
|
|
g_destroy_bio(cbp);
|
2003-06-04 18:16:09 +00:00
|
|
|
return;
|
2003-01-17 14:53:53 +00:00
|
|
|
}
|
2003-06-04 18:16:09 +00:00
|
|
|
g_std_done(cbp);
|
2003-01-17 14:53:53 +00:00
|
|
|
}
|
|
|
|
|
2003-06-04 18:16:09 +00:00
|
|
|
static void
|
|
|
|
g_ccd_create(struct gctl_req *req, struct g_class *mp)
|
2003-01-17 14:53:53 +00:00
|
|
|
{
|
2003-06-04 18:16:09 +00:00
|
|
|
int *unit, *ileave, *nprovider;
|
|
|
|
struct g_geom *gp;
|
|
|
|
struct g_consumer *cp;
|
|
|
|
struct g_provider *pp;
|
|
|
|
struct ccd_s *sc;
|
|
|
|
struct sbuf *sb;
|
|
|
|
char buf[20];
|
|
|
|
int i, error;
|
1995-12-27 10:49:19 +00:00
|
|
|
|
2003-06-04 18:16:09 +00:00
|
|
|
g_topology_assert();
|
|
|
|
unit = gctl_get_paraml(req, "unit", sizeof (*unit));
|
|
|
|
ileave = gctl_get_paraml(req, "ileave", sizeof (*ileave));
|
|
|
|
nprovider = gctl_get_paraml(req, "nprovider", sizeof (*nprovider));
|
|
|
|
|
|
|
|
/* Check for duplicate unit */
|
|
|
|
LIST_FOREACH(gp, &mp->geom, geom) {
|
|
|
|
sc = gp->softc;
|
2003-08-22 10:22:46 +00:00
|
|
|
if (sc != NULL && sc->sc_unit == *unit) {
|
2003-06-04 18:16:09 +00:00
|
|
|
gctl_error(req, "Unit %d already configured", *unit);
|
|
|
|
return;
|
1995-12-27 10:49:19 +00:00
|
|
|
}
|
2003-06-04 18:16:09 +00:00
|
|
|
}
|
1995-12-27 10:49:19 +00:00
|
|
|
|
2003-06-04 18:16:09 +00:00
|
|
|
if (*nprovider <= 0) {
|
|
|
|
gctl_error(req, "Bogus nprovider argument (= %d)", *nprovider);
|
|
|
|
return;
|
|
|
|
}
|
1995-12-27 10:49:19 +00:00
|
|
|
|
2003-06-04 18:16:09 +00:00
|
|
|
/* Check all providers are valid */
|
|
|
|
for (i = 0; i < *nprovider; i++) {
|
|
|
|
sprintf(buf, "provider%d", i);
|
|
|
|
pp = gctl_get_provider(req, buf);
|
|
|
|
if (pp == NULL)
|
|
|
|
return;
|
|
|
|
}
|
1995-12-27 10:49:19 +00:00
|
|
|
|
2003-06-04 18:16:09 +00:00
|
|
|
gp = g_new_geomf(mp, "ccd%d", *unit);
|
|
|
|
sc = g_malloc(sizeof *sc, M_WAITOK | M_ZERO);
|
|
|
|
gp->softc = sc;
|
|
|
|
sc->sc_ndisks = *nprovider;
|
1995-12-27 10:49:19 +00:00
|
|
|
|
2003-06-04 18:16:09 +00:00
|
|
|
/* Allocate space for the component info. */
|
|
|
|
sc->sc_cinfo = g_malloc(sc->sc_ndisks * sizeof(struct ccdcinfo),
|
|
|
|
M_WAITOK | M_ZERO);
|
2001-09-04 08:33:30 +00:00
|
|
|
|
2003-06-04 18:16:09 +00:00
|
|
|
/* Create consumers and attach to all providers */
|
|
|
|
for (i = 0; i < *nprovider; i++) {
|
|
|
|
sprintf(buf, "provider%d", i);
|
|
|
|
pp = gctl_get_provider(req, buf);
|
|
|
|
cp = g_new_consumer(gp);
|
|
|
|
error = g_attach(cp, pp);
|
|
|
|
KASSERT(error == 0, ("attach to %s failed", pp->name));
|
|
|
|
sc->sc_cinfo[i].ci_consumer = cp;
|
|
|
|
sc->sc_cinfo[i].ci_provider = pp;
|
1995-12-27 10:49:19 +00:00
|
|
|
}
|
|
|
|
|
2003-06-04 18:16:09 +00:00
|
|
|
sc->sc_unit = *unit;
|
|
|
|
sc->sc_ileave = *ileave;
|
1995-12-27 10:49:19 +00:00
|
|
|
|
2006-04-13 20:35:31 +00:00
|
|
|
if (gctl_get_param(req, "no_offset", NULL))
|
|
|
|
sc->sc_flags |= CCDF_NO_OFFSET;
|
|
|
|
if (gctl_get_param(req, "linux", NULL))
|
|
|
|
sc->sc_flags |= CCDF_LINUX;
|
|
|
|
|
2003-06-04 18:16:09 +00:00
|
|
|
if (gctl_get_param(req, "uniform", NULL))
|
|
|
|
sc->sc_flags |= CCDF_UNIFORM;
|
|
|
|
if (gctl_get_param(req, "mirror", NULL))
|
|
|
|
sc->sc_flags |= CCDF_MIRROR;
|
1995-12-27 10:49:19 +00:00
|
|
|
|
2003-06-04 18:16:09 +00:00
|
|
|
if (sc->sc_ileave == 0 && (sc->sc_flags & CCDF_MIRROR)) {
|
|
|
|
printf("%s: disabling mirror, interleave is 0\n", gp->name);
|
|
|
|
sc->sc_flags &= ~(CCDF_MIRROR);
|
1995-12-27 10:49:19 +00:00
|
|
|
}
|
|
|
|
|
2003-06-04 18:16:09 +00:00
|
|
|
if ((sc->sc_flags & CCDF_MIRROR) && !(sc->sc_flags & CCDF_UNIFORM)) {
|
|
|
|
printf("%s: mirror/parity forces uniform flag\n", gp->name);
|
|
|
|
sc->sc_flags |= CCDF_UNIFORM;
|
1995-12-27 10:49:19 +00:00
|
|
|
}
|
|
|
|
|
2003-06-04 18:16:09 +00:00
|
|
|
error = ccdinit(req, sc);
|
|
|
|
if (error != 0) {
|
|
|
|
g_ccd_freesc(sc);
|
|
|
|
gp->softc = NULL;
|
|
|
|
g_wither_geom(gp, ENXIO);
|
|
|
|
return;
|
|
|
|
}
|
1995-12-27 10:49:19 +00:00
|
|
|
|
2003-06-04 18:16:09 +00:00
|
|
|
pp = g_new_providerf(gp, "%s", gp->name);
|
|
|
|
pp->mediasize = sc->sc_size * (off_t)sc->sc_secsize;
|
|
|
|
pp->sectorsize = sc->sc_secsize;
|
|
|
|
g_error_provider(pp, 0);
|
1995-12-27 10:49:19 +00:00
|
|
|
|
2008-08-09 11:14:05 +00:00
|
|
|
sb = sbuf_new_auto();
|
2003-06-04 18:16:09 +00:00
|
|
|
sbuf_printf(sb, "ccd%d: %d components ", sc->sc_unit, *nprovider);
|
|
|
|
for (i = 0; i < *nprovider; i++) {
|
|
|
|
sbuf_printf(sb, "%s%s",
|
|
|
|
i == 0 ? "(" : ", ",
|
|
|
|
sc->sc_cinfo[i].ci_provider->name);
|
1995-12-27 10:49:19 +00:00
|
|
|
}
|
2003-06-04 18:16:09 +00:00
|
|
|
sbuf_printf(sb, "), %jd blocks ", (off_t)pp->mediasize / DEV_BSIZE);
|
|
|
|
if (sc->sc_ileave != 0)
|
|
|
|
sbuf_printf(sb, "interleaved at %d blocks\n",
|
|
|
|
sc->sc_ileave);
|
|
|
|
else
|
|
|
|
sbuf_printf(sb, "concatenated\n");
|
|
|
|
sbuf_finish(sb);
|
2006-04-07 16:19:48 +00:00
|
|
|
gctl_set_param_err(req, "output", sbuf_data(sb), sbuf_len(sb) + 1);
|
2003-06-04 18:16:09 +00:00
|
|
|
sbuf_delete(sb);
|
1995-12-27 10:49:19 +00:00
|
|
|
}
|
|
|
|
|
2003-08-22 11:04:47 +00:00
|
|
|
static int
|
|
|
|
g_ccd_destroy_geom(struct gctl_req *req, struct g_class *mp, struct g_geom *gp)
|
1995-12-27 10:49:19 +00:00
|
|
|
{
|
2003-06-04 18:16:09 +00:00
|
|
|
struct g_provider *pp;
|
|
|
|
struct ccd_s *sc;
|
1995-12-27 10:49:19 +00:00
|
|
|
|
2003-06-04 18:16:09 +00:00
|
|
|
g_topology_assert();
|
|
|
|
sc = gp->softc;
|
|
|
|
pp = LIST_FIRST(&gp->provider);
|
2003-08-22 11:04:47 +00:00
|
|
|
if (sc == NULL || pp == NULL)
|
|
|
|
return (EBUSY);
|
2003-06-04 18:16:09 +00:00
|
|
|
if (pp->acr != 0 || pp->acw != 0 || pp->ace != 0) {
|
|
|
|
gctl_error(req, "%s is open(r%dw%de%d)", gp->name,
|
|
|
|
pp->acr, pp->acw, pp->ace);
|
2003-08-22 11:04:47 +00:00
|
|
|
return (EBUSY);
|
1995-12-27 10:49:19 +00:00
|
|
|
}
|
2003-06-04 18:16:09 +00:00
|
|
|
g_ccd_freesc(sc);
|
|
|
|
gp->softc = NULL;
|
|
|
|
g_wither_geom(gp, ENXIO);
|
2003-08-22 11:04:47 +00:00
|
|
|
return (0);
|
1995-12-27 10:49:19 +00:00
|
|
|
}
|
2003-06-02 20:50:03 +00:00
|
|
|
|
2003-06-04 18:16:09 +00:00
|
|
|
static void
|
|
|
|
g_ccd_list(struct gctl_req *req, struct g_class *mp)
|
2003-06-02 20:50:03 +00:00
|
|
|
{
|
|
|
|
struct sbuf *sb;
|
|
|
|
struct ccd_s *cs;
|
2003-06-04 18:16:09 +00:00
|
|
|
struct g_geom *gp;
|
|
|
|
int i, unit, *up;
|
2003-06-02 20:50:03 +00:00
|
|
|
|
2003-06-04 18:16:09 +00:00
|
|
|
up = gctl_get_paraml(req, "unit", sizeof (int));
|
|
|
|
unit = *up;
|
2008-08-09 11:14:05 +00:00
|
|
|
sb = sbuf_new_auto();
|
2003-06-04 18:16:09 +00:00
|
|
|
LIST_FOREACH(gp, &mp->geom, geom) {
|
|
|
|
cs = gp->softc;
|
2003-08-22 10:22:46 +00:00
|
|
|
if (cs == NULL || (unit >= 0 && unit != cs->sc_unit))
|
2003-06-02 21:29:04 +00:00
|
|
|
continue;
|
2003-06-02 20:50:03 +00:00
|
|
|
sbuf_printf(sb, "ccd%d\t\t%d\t%d\t",
|
2003-06-04 18:16:09 +00:00
|
|
|
cs->sc_unit, cs->sc_ileave, cs->sc_flags & CCDF_USERMASK);
|
2003-06-02 20:50:03 +00:00
|
|
|
|
2003-06-04 18:16:09 +00:00
|
|
|
for (i = 0; i < cs->sc_ndisks; ++i) {
|
|
|
|
sbuf_printf(sb, "%s/dev/%s", i == 0 ? "" : " ",
|
|
|
|
cs->sc_cinfo[i].ci_provider->name);
|
2003-06-02 20:50:03 +00:00
|
|
|
}
|
|
|
|
sbuf_printf(sb, "\n");
|
|
|
|
}
|
|
|
|
sbuf_finish(sb);
|
2006-04-07 16:19:48 +00:00
|
|
|
gctl_set_param_err(req, "output", sbuf_data(sb), sbuf_len(sb) + 1);
|
2003-06-04 18:16:09 +00:00
|
|
|
sbuf_delete(sb);
|
2003-06-02 20:50:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
g_ccd_config(struct gctl_req *req, struct g_class *mp, char const *verb)
|
|
|
|
{
|
2003-08-22 11:04:47 +00:00
|
|
|
struct g_geom *gp;
|
2003-06-02 20:50:03 +00:00
|
|
|
|
|
|
|
g_topology_assert();
|
|
|
|
if (!strcmp(verb, "create geom")) {
|
2003-06-04 18:16:09 +00:00
|
|
|
g_ccd_create(req, mp);
|
2003-06-02 20:50:03 +00:00
|
|
|
} else if (!strcmp(verb, "destroy geom")) {
|
2003-08-22 11:04:47 +00:00
|
|
|
gp = gctl_get_geom(req, mp, "geom");
|
|
|
|
if (gp != NULL)
|
|
|
|
g_ccd_destroy_geom(req, mp, gp);
|
2003-06-02 20:50:03 +00:00
|
|
|
} else if (!strcmp(verb, "list")) {
|
2003-06-04 18:16:09 +00:00
|
|
|
g_ccd_list(req, mp);
|
2003-06-02 20:50:03 +00:00
|
|
|
} else {
|
|
|
|
gctl_error(req, "unknown verb");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct g_class g_ccd_class = {
|
|
|
|
.name = "CCD",
|
2004-08-08 07:57:53 +00:00
|
|
|
.version = G_VERSION,
|
2003-06-02 20:50:03 +00:00
|
|
|
.ctlreq = g_ccd_config,
|
2003-08-22 11:04:47 +00:00
|
|
|
.destroy_geom = g_ccd_destroy_geom,
|
2004-08-08 06:49:07 +00:00
|
|
|
.start = g_ccd_start,
|
|
|
|
.orphan = g_ccd_orphan,
|
|
|
|
.access = g_ccd_access,
|
2003-06-02 20:50:03 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
DECLARE_GEOM_CLASS(g_ccd_class, g_ccd);
|