1995-12-27 10:49:19 +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 $
|
|
|
|
*
|
|
|
|
* $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>
|
1995-12-27 10:49:19 +00:00
|
|
|
#include <sys/proc.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>
|
|
|
|
#include <sys/namei.h>
|
|
|
|
#include <sys/conf.h>
|
|
|
|
#include <sys/stat.h>
|
1997-10-24 14:24:55 +00:00
|
|
|
#include <sys/sysctl.h>
|
2002-04-08 09:20:07 +00:00
|
|
|
#include <sys/disk.h>
|
1995-12-27 10:49:19 +00:00
|
|
|
#include <sys/fcntl.h>
|
|
|
|
#include <sys/vnode.h>
|
2003-04-01 15:06:26 +00:00
|
|
|
#include <geom/geom_disk.h>
|
1995-12-27 10:49:19 +00:00
|
|
|
|
1995-12-27 10:53:21 +00:00
|
|
|
#include <sys/ccdvar.h>
|
1995-12-27 10:49:19 +00:00
|
|
|
|
2001-09-04 08:33:30 +00:00
|
|
|
MALLOC_DEFINE(M_CCD, "CCD driver", "Concatenated Disk driver");
|
|
|
|
|
1996-03-26 02:29:11 +00:00
|
|
|
/*
|
|
|
|
This is how mirroring works (only writes are special):
|
|
|
|
|
|
|
|
When initiating a write, ccdbuffer() returns two "struct ccdbuf *"s
|
|
|
|
linked together by the cb_mirror field. "cb_pflags &
|
|
|
|
CCDPF_MIRROR_DONE" is set to 0 on both of them.
|
|
|
|
|
|
|
|
When a component returns to ccdiodone(), it checks if "cb_pflags &
|
|
|
|
CCDPF_MIRROR_DONE" is set or not. If not, it sets the partner's
|
|
|
|
flag and returns. If it is, it means its partner has already
|
|
|
|
returned, so it will go to the regular cleanup.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
1995-12-27 10:49:19 +00:00
|
|
|
struct ccdbuf {
|
2000-05-01 13:36:43 +00:00
|
|
|
struct bio cb_buf; /* new I/O buf */
|
|
|
|
struct bio *cb_obp; /* ptr. to original I/O buf */
|
1999-09-23 09:25:05 +00:00
|
|
|
struct ccdbuf *cb_freenext; /* free list link */
|
2003-01-19 15:00:58 +00:00
|
|
|
struct ccd_s *cb_softc;
|
1995-12-27 10:49:19 +00:00
|
|
|
int cb_comp; /* target component */
|
1996-03-26 02:29:11 +00:00
|
|
|
int cb_pflags; /* mirror/parity status flag */
|
|
|
|
struct ccdbuf *cb_mirror; /* mirror counterpart */
|
1995-12-27 10:49:19 +00:00
|
|
|
};
|
|
|
|
|
1996-03-26 02:29:11 +00:00
|
|
|
/* bits in cb_pflags */
|
|
|
|
#define CCDPF_MIRROR_DONE 1 /* if set, mirror counterpart is done */
|
|
|
|
|
2001-09-04 08:33:30 +00:00
|
|
|
/* convinient macros for often-used statements */
|
|
|
|
#define IS_ALLOCATED(unit) (ccdfind(unit) != NULL)
|
|
|
|
#define IS_INITED(cs) (((cs)->sc_flags & CCDF_INITED) != 0)
|
|
|
|
|
2003-01-17 14:53:53 +00:00
|
|
|
static dev_t ccdctldev;
|
|
|
|
|
2003-02-21 23:25:43 +00:00
|
|
|
static disk_strategy_t ccdstrategy;
|
2003-01-19 15:00:58 +00:00
|
|
|
static d_ioctl_t ccdctlioctl;
|
1996-03-21 04:13:25 +00:00
|
|
|
|
1999-09-23 09:25:05 +00:00
|
|
|
#define NCCDFREEHIWAT 16
|
|
|
|
|
1996-03-21 04:13:25 +00:00
|
|
|
#define CDEV_MAJOR 74
|
|
|
|
|
2003-01-19 15:00:58 +00:00
|
|
|
static struct cdevsw ccdctl_cdevsw = {
|
2003-03-03 12:15:54 +00:00
|
|
|
.d_open = nullopen,
|
|
|
|
.d_close = nullclose,
|
|
|
|
.d_ioctl = ccdctlioctl,
|
|
|
|
.d_name = "ccdctl",
|
|
|
|
.d_maj = CDEV_MAJOR,
|
2003-01-19 15:00:58 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static LIST_HEAD(, ccd_s) ccd_softc_list =
|
|
|
|
LIST_HEAD_INITIALIZER(&ccd_softc_list);
|
2001-09-04 08:33:30 +00:00
|
|
|
|
|
|
|
static struct ccd_s *ccdfind(int);
|
|
|
|
static struct ccd_s *ccdnew(int);
|
2003-01-19 15:00:58 +00:00
|
|
|
static int ccddestroy(struct ccd_s *);
|
1995-12-27 10:53:21 +00:00
|
|
|
|
1999-01-22 22:38:28 +00:00
|
|
|
/* called during module initialization */
|
2001-09-04 08:33:30 +00:00
|
|
|
static void ccdattach(void);
|
|
|
|
static int ccd_modevent(module_t, int, void *);
|
1995-12-27 10:49:19 +00:00
|
|
|
|
|
|
|
/* called by biodone() at interrupt time */
|
2001-09-04 08:33:30 +00:00
|
|
|
static void ccdiodone(struct bio *bp);
|
|
|
|
|
|
|
|
static void ccdstart(struct ccd_s *, struct bio *);
|
|
|
|
static void ccdinterleave(struct ccd_s *, int);
|
2001-09-12 08:38:13 +00:00
|
|
|
static int ccdinit(struct ccd_s *, char **, struct thread *);
|
|
|
|
static int ccdlookup(char *, struct thread *p, struct vnode **);
|
2003-01-19 15:00:58 +00:00
|
|
|
static int ccdbuffer(struct ccdbuf **ret, struct ccd_s *,
|
2001-09-04 08:33:30 +00:00
|
|
|
struct bio *, daddr_t, caddr_t, long);
|
|
|
|
static int ccdlock(struct ccd_s *);
|
|
|
|
static void ccdunlock(struct ccd_s *);
|
1995-12-27 10:49:19 +00:00
|
|
|
|
|
|
|
|
1996-05-13 08:38:15 +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.
|
|
|
|
*/
|
1996-05-13 09:17:42 +00:00
|
|
|
#if !defined(CCD_OFFSET)
|
1996-05-13 08:38:15 +00:00
|
|
|
#define CCD_OFFSET 16
|
1996-05-13 09:17:42 +00:00
|
|
|
#endif
|
1996-05-13 08:38:15 +00:00
|
|
|
|
2001-09-04 08:33:30 +00:00
|
|
|
static struct ccd_s *
|
|
|
|
ccdfind(int unit)
|
|
|
|
{
|
|
|
|
struct ccd_s *sc = NULL;
|
|
|
|
|
|
|
|
/* XXX: LOCK(unique unit numbers) */
|
|
|
|
LIST_FOREACH(sc, &ccd_softc_list, list) {
|
|
|
|
if (sc->sc_unit == unit)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* XXX: UNLOCK(unique unit numbers) */
|
|
|
|
return ((sc == NULL) || (sc->sc_unit != unit) ? NULL : sc);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct ccd_s *
|
|
|
|
ccdnew(int unit)
|
|
|
|
{
|
|
|
|
struct ccd_s *sc;
|
|
|
|
|
|
|
|
/* XXX: LOCK(unique unit numbers) */
|
2003-01-19 15:00:58 +00:00
|
|
|
if (IS_ALLOCATED(unit) || unit > 32)
|
2001-09-04 08:33:30 +00:00
|
|
|
return (NULL);
|
|
|
|
|
2003-02-19 05:47:46 +00:00
|
|
|
MALLOC(sc, struct ccd_s *, sizeof(*sc), M_CCD, M_WAITOK | M_ZERO);
|
2001-09-04 08:33:30 +00:00
|
|
|
sc->sc_unit = unit;
|
|
|
|
LIST_INSERT_HEAD(&ccd_softc_list, sc, list);
|
|
|
|
/* XXX: UNLOCK(unique unit numbers) */
|
|
|
|
return (sc);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2003-01-19 15:00:58 +00:00
|
|
|
ccddestroy(struct ccd_s *sc)
|
2001-09-04 08:33:30 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
/* XXX: LOCK(unique unit numbers) */
|
|
|
|
LIST_REMOVE(sc, list);
|
|
|
|
/* XXX: UNLOCK(unique unit numbers) */
|
|
|
|
FREE(sc, M_CCD);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
1995-12-27 10:49:19 +00:00
|
|
|
/*
|
|
|
|
* Called by main() during pseudo-device attachment. All we need
|
2001-09-04 08:33:30 +00:00
|
|
|
* to do is to add devsw entries.
|
1995-12-27 10:49:19 +00:00
|
|
|
*/
|
1997-10-24 14:24:55 +00:00
|
|
|
static void
|
1999-01-22 22:38:28 +00:00
|
|
|
ccdattach()
|
1995-12-27 10:49:19 +00:00
|
|
|
{
|
|
|
|
|
2003-01-19 15:00:58 +00:00
|
|
|
ccdctldev = make_dev(&ccdctl_cdevsw, 0xffff00ff,
|
2003-01-17 14:53:53 +00:00
|
|
|
UID_ROOT, GID_OPERATOR, 0640, "ccd.ctl");
|
|
|
|
ccdctldev->si_drv1 = ccdctldev;
|
1999-01-22 22:38:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2001-09-04 08:33:30 +00:00
|
|
|
ccd_modevent(module_t mod, int type, void *data)
|
1999-01-22 22:38:28 +00:00
|
|
|
{
|
|
|
|
int error = 0;
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case MOD_LOAD:
|
|
|
|
ccdattach();
|
|
|
|
break;
|
1995-12-27 10:53:21 +00:00
|
|
|
|
1999-01-22 22:38:28 +00:00
|
|
|
case MOD_UNLOAD:
|
|
|
|
printf("ccd0: Unload not supported!\n");
|
|
|
|
error = EOPNOTSUPP;
|
|
|
|
break;
|
|
|
|
|
2001-11-17 00:46:08 +00:00
|
|
|
case MOD_SHUTDOWN:
|
1999-01-22 22:38:28 +00:00
|
|
|
break;
|
2001-11-17 00:46:08 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
error = EOPNOTSUPP;
|
1996-03-21 04:13:25 +00:00
|
|
|
}
|
1999-01-22 22:38:28 +00:00
|
|
|
return (error);
|
1995-12-27 10:49:19 +00:00
|
|
|
}
|
|
|
|
|
1999-11-07 10:01:17 +00:00
|
|
|
DEV_MODULE(ccd, ccd_modevent, NULL);
|
1999-01-22 22:38:28 +00:00
|
|
|
|
1995-12-27 10:49:19 +00:00
|
|
|
static int
|
2001-09-12 08:38:13 +00:00
|
|
|
ccdinit(struct ccd_s *cs, char **cpaths, struct thread *td)
|
1995-12-27 10:49:19 +00:00
|
|
|
{
|
1999-09-23 09:25:05 +00:00
|
|
|
struct ccdcinfo *ci = NULL; /* XXX */
|
|
|
|
size_t size;
|
|
|
|
int ix;
|
1995-12-27 10:49:19 +00:00
|
|
|
struct vnode *vp;
|
|
|
|
size_t minsize;
|
|
|
|
int maxsecsize;
|
|
|
|
struct ccdgeom *ccg = &cs->sc_geom;
|
2001-12-30 17:34:19 +00:00
|
|
|
char *tmppath = NULL;
|
1999-09-23 09:25:05 +00:00
|
|
|
int error = 0;
|
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;
|
|
|
|
|
|
|
|
/* Allocate space for the component info. */
|
|
|
|
cs->sc_cinfo = malloc(cs->sc_nccdisks * sizeof(struct ccdcinfo),
|
2003-02-19 05:47:46 +00:00
|
|
|
M_CCD, M_WAITOK);
|
1995-12-27 10:49:19 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Verify that each component piece exists and record
|
|
|
|
* relevant information about it.
|
|
|
|
*/
|
|
|
|
maxsecsize = 0;
|
|
|
|
minsize = 0;
|
2003-02-19 05:47:46 +00:00
|
|
|
tmppath = malloc(MAXPATHLEN, M_CCD, M_WAITOK);
|
1995-12-27 10:49:19 +00:00
|
|
|
for (ix = 0; ix < cs->sc_nccdisks; ix++) {
|
2001-09-04 08:33:30 +00:00
|
|
|
vp = cs->sc_vpp[ix];
|
1995-12-27 10:49:19 +00:00
|
|
|
ci = &cs->sc_cinfo[ix];
|
|
|
|
ci->ci_vp = vp;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copy in the pathname of the component.
|
|
|
|
*/
|
1999-01-27 20:09:21 +00:00
|
|
|
if ((error = copyinstr(cpaths[ix], tmppath,
|
|
|
|
MAXPATHLEN, &ci->ci_pathlen)) != 0) {
|
1999-09-23 09:25:05 +00:00
|
|
|
goto fail;
|
1995-12-27 10:49:19 +00:00
|
|
|
}
|
2003-02-19 05:47:46 +00:00
|
|
|
ci->ci_path = malloc(ci->ci_pathlen, M_CCD, M_WAITOK);
|
1995-12-27 10:49:19 +00:00
|
|
|
bcopy(tmppath, ci->ci_path, ci->ci_pathlen);
|
|
|
|
|
1999-07-18 14:31:01 +00:00
|
|
|
ci->ci_dev = vn_todev(vp);
|
1995-12-27 10:49:19 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Get partition information for the component.
|
|
|
|
*/
|
2002-04-02 11:17:37 +00:00
|
|
|
error = VOP_IOCTL(vp, DIOCGMEDIASIZE, (caddr_t)&mediasize,
|
|
|
|
FREAD, td->td_ucred, td);
|
|
|
|
if (error != 0) {
|
1999-09-23 09:25:05 +00:00
|
|
|
goto fail;
|
1995-12-27 10:49:19 +00:00
|
|
|
}
|
2002-04-02 11:17:37 +00:00
|
|
|
/*
|
|
|
|
* Get partition information for the component.
|
|
|
|
*/
|
|
|
|
error = VOP_IOCTL(vp, DIOCGSECTORSIZE, (caddr_t)§orsize,
|
|
|
|
FREAD, td->td_ucred, td);
|
|
|
|
if (error != 0) {
|
1999-09-23 09:25:05 +00:00
|
|
|
goto fail;
|
1995-12-27 10:49:19 +00:00
|
|
|
}
|
2002-04-02 11:17:37 +00:00
|
|
|
if (sectorsize > maxsecsize)
|
|
|
|
maxsecsize = sectorsize;
|
|
|
|
size = mediasize / DEV_BSIZE - CCD_OFFSET;
|
1995-12-27 10:49:19 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Calculate the size, truncating to an interleave
|
|
|
|
* boundary if necessary.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (cs->sc_ileave > 1)
|
|
|
|
size -= size % cs->sc_ileave;
|
|
|
|
|
|
|
|
if (size == 0) {
|
1999-09-23 09:25:05 +00:00
|
|
|
error = ENODEV;
|
|
|
|
goto fail;
|
1995-12-27 10:49:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (minsize == 0 || size < minsize)
|
|
|
|
minsize = size;
|
|
|
|
ci->ci_size = size;
|
|
|
|
cs->sc_size += size;
|
|
|
|
}
|
|
|
|
|
2003-01-18 11:04:41 +00:00
|
|
|
free(tmppath, M_CCD);
|
2001-12-30 17:34:19 +00:00
|
|
|
tmppath = NULL;
|
|
|
|
|
1995-12-27 10:49:19 +00:00
|
|
|
/*
|
|
|
|
* Don't allow the interleave to be smaller than
|
|
|
|
* the biggest component sector.
|
|
|
|
*/
|
|
|
|
if ((cs->sc_ileave > 0) &&
|
|
|
|
(cs->sc_ileave < (maxsecsize / DEV_BSIZE))) {
|
1999-09-23 09:25:05 +00:00
|
|
|
error = EINVAL;
|
|
|
|
goto fail;
|
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) {
|
1995-12-27 10:49:19 +00:00
|
|
|
for (ci = cs->sc_cinfo;
|
1999-09-23 09:25:05 +00:00
|
|
|
ci < &cs->sc_cinfo[cs->sc_nccdisks]; ci++) {
|
1995-12-27 10:49:19 +00:00
|
|
|
ci->ci_size = minsize;
|
1999-09-23 09:25:05 +00:00
|
|
|
}
|
2001-09-04 08:33:30 +00:00
|
|
|
if (cs->sc_flags & CCDF_MIRROR) {
|
1996-07-24 23:45:24 +00:00
|
|
|
/*
|
|
|
|
* Check to see if an even number of components
|
1999-09-23 09:25:05 +00:00
|
|
|
* have been specified. The interleave must also
|
|
|
|
* be non-zero in order for us to be able to
|
|
|
|
* guarentee the topology.
|
1996-07-24 23:45:24 +00:00
|
|
|
*/
|
1996-01-30 22:34:53 +00:00
|
|
|
if (cs->sc_nccdisks % 2) {
|
2001-09-04 08:33:30 +00:00
|
|
|
printf("ccd%d: mirroring requires an even number of disks\n", cs->sc_unit );
|
1999-09-23 09:25:05 +00:00
|
|
|
error = EINVAL;
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
if (cs->sc_ileave == 0) {
|
2001-09-04 08:33:30 +00:00
|
|
|
printf("ccd%d: an interleave must be specified when mirroring\n", cs->sc_unit);
|
1999-09-23 09:25:05 +00:00
|
|
|
error = EINVAL;
|
|
|
|
goto fail;
|
1996-01-30 22:34:53 +00:00
|
|
|
}
|
|
|
|
cs->sc_size = (cs->sc_nccdisks/2) * minsize;
|
1999-09-23 09:25:05 +00:00
|
|
|
} else {
|
|
|
|
if (cs->sc_ileave == 0) {
|
2001-09-04 08:33:30 +00:00
|
|
|
printf("ccd%d: an interleave must be specified when using parity\n", cs->sc_unit);
|
1999-09-23 09:25:05 +00:00
|
|
|
error = EINVAL;
|
|
|
|
goto fail;
|
|
|
|
}
|
1996-01-30 22:34:53 +00:00
|
|
|
cs->sc_size = cs->sc_nccdisks * minsize;
|
1999-09-23 09:25:05 +00:00
|
|
|
}
|
1995-12-27 10:49:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Construct the interleave table.
|
|
|
|
*/
|
2001-09-04 08:33:30 +00:00
|
|
|
ccdinterleave(cs, cs->sc_unit);
|
1995-12-27 10:49:19 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Create pseudo-geometry based on 1MB cylinders. It's
|
|
|
|
* pretty close.
|
|
|
|
*/
|
1997-05-01 19:18:40 +00:00
|
|
|
ccg->ccg_secsize = maxsecsize;
|
1995-12-27 10:49:19 +00:00
|
|
|
ccg->ccg_ntracks = 1;
|
1999-09-23 00:09:08 +00:00
|
|
|
ccg->ccg_nsectors = 1024 * 1024 / ccg->ccg_secsize;
|
1995-12-27 10:49:19 +00:00
|
|
|
ccg->ccg_ncylinders = cs->sc_size / ccg->ccg_nsectors;
|
|
|
|
|
|
|
|
cs->sc_flags |= CCDF_INITED;
|
2001-09-04 08:33:30 +00:00
|
|
|
cs->sc_cflags = cs->sc_flags; /* So we can find out later... */
|
1995-12-27 10:49:19 +00:00
|
|
|
return (0);
|
1999-09-23 09:25:05 +00:00
|
|
|
fail:
|
|
|
|
while (ci > cs->sc_cinfo) {
|
|
|
|
ci--;
|
2003-01-18 11:04:41 +00:00
|
|
|
free(ci->ci_path, M_CCD);
|
1999-09-23 09:25:05 +00:00
|
|
|
}
|
2001-12-30 17:34:19 +00:00
|
|
|
if (tmppath != NULL)
|
2003-01-18 11:04:41 +00:00
|
|
|
free(tmppath, M_CCD);
|
|
|
|
free(cs->sc_cinfo, M_CCD);
|
2003-01-19 15:00:58 +00:00
|
|
|
ccddestroy(cs);
|
1999-09-23 09:25:05 +00:00
|
|
|
return (error);
|
1995-12-27 10:49:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2001-09-04 08:33:30 +00:00
|
|
|
ccdinterleave(struct ccd_s *cs, int unit)
|
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;
|
1995-12-27 10:49:19 +00:00
|
|
|
u_long size;
|
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
size = (cs->sc_nccdisks + 1) * sizeof(struct ccdiinfo);
|
2003-01-18 11:04:41 +00:00
|
|
|
cs->sc_itable = (struct ccdiinfo *)malloc(size, M_CCD,
|
2003-02-19 05:47:46 +00:00
|
|
|
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;
|
|
|
|
|
|
|
|
for (ix = 0; ix < cs->sc_nccdisks; ix++) {
|
|
|
|
/* Allocate space for ii_index. */
|
2003-02-19 05:47:46 +00:00
|
|
|
ii->ii_index = malloc(sizeof(int), M_CCD, 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.
|
|
|
|
*/
|
1995-12-27 10:49:19 +00:00
|
|
|
ii->ii_index = malloc((sizeof(int) * cs->sc_nccdisks),
|
2003-02-19 05:47:46 +00:00
|
|
|
M_CCD, M_WAITOK);
|
1995-12-27 10:49:19 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Locate the smallest of the remaining components
|
|
|
|
*/
|
|
|
|
smallci = NULL;
|
1999-09-23 09:25:05 +00:00
|
|
|
for (ci = cs->sc_cinfo; ci < &cs->sc_cinfo[cs->sc_nccdisks];
|
|
|
|
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-01-18 12:23:49 +00:00
|
|
|
free(ii->ii_index, M_CCD);
|
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
|
|
|
|
|
|
|
/*
|
|
|
|
* Record starting comopnent block using an sc_ileave
|
|
|
|
* 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;
|
|
|
|
ci < &cs->sc_cinfo[cs->sc_nccdisks]; ci++) {
|
|
|
|
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
|
2001-09-04 08:33:30 +00:00
|
|
|
ccdstrategy(struct bio *bp)
|
1995-12-27 10:49:19 +00:00
|
|
|
{
|
2003-01-19 15:00:58 +00:00
|
|
|
struct ccd_s *cs;
|
|
|
|
int pbn; /* in sc_secsize chunks */
|
|
|
|
long sz; /* in sc_secsize chunks */
|
1995-12-27 10:49:19 +00:00
|
|
|
|
2003-02-21 23:25:43 +00:00
|
|
|
cs = bp->bio_disk->d_drv1;
|
1995-12-27 10:49:19 +00:00
|
|
|
|
2003-01-19 15:00:58 +00:00
|
|
|
pbn = bp->bio_blkno / (cs->sc_geom.ccg_secsize / DEV_BSIZE);
|
|
|
|
sz = howmany(bp->bio_bcount, cs->sc_geom.ccg_secsize);
|
1995-12-27 10:49:19 +00:00
|
|
|
|
|
|
|
/*
|
2003-01-19 15:00:58 +00:00
|
|
|
* If out of bounds return an error. If at the EOF point,
|
|
|
|
* simply read or write less.
|
1995-12-27 10:49:19 +00:00
|
|
|
*/
|
1999-09-27 00:12:36 +00:00
|
|
|
|
2003-01-19 15:00:58 +00:00
|
|
|
if (pbn < 0 || pbn >= cs->sc_size) {
|
|
|
|
bp->bio_resid = bp->bio_bcount;
|
|
|
|
if (pbn != cs->sc_size)
|
|
|
|
biofinish(bp, NULL, EINVAL);
|
|
|
|
else
|
|
|
|
biodone(bp);
|
|
|
|
return;
|
|
|
|
}
|
1999-09-27 00:12:36 +00:00
|
|
|
|
2003-01-19 15:00:58 +00:00
|
|
|
/*
|
|
|
|
* If the request crosses EOF, truncate the request.
|
|
|
|
*/
|
|
|
|
if (pbn + sz > cs->sc_size) {
|
|
|
|
bp->bio_bcount = (cs->sc_size - pbn) *
|
|
|
|
cs->sc_geom.ccg_secsize;
|
1999-09-27 00:12:36 +00:00
|
|
|
}
|
1995-12-27 10:49:19 +00:00
|
|
|
|
2000-05-01 13:36:43 +00:00
|
|
|
bp->bio_resid = bp->bio_bcount;
|
1995-12-27 10:49:19 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* "Start" the unit.
|
|
|
|
*/
|
|
|
|
ccdstart(cs, bp);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2001-09-04 08:33:30 +00:00
|
|
|
ccdstart(struct ccd_s *cs, struct bio *bp)
|
1995-12-27 10:49:19 +00:00
|
|
|
{
|
1999-09-23 09:25:05 +00:00
|
|
|
long bcount, rcount;
|
2003-01-19 15:00:58 +00:00
|
|
|
struct ccdbuf *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-04-14 08:49:54 +00:00
|
|
|
int sent;
|
1995-12-27 10:49:19 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Translate the partition-relative block number to an absolute.
|
|
|
|
*/
|
2000-05-01 13:36:43 +00:00
|
|
|
bn = bp->bio_blkno;
|
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-04-14 08:49:54 +00:00
|
|
|
sent = 0;
|
2000-05-01 13:36:43 +00:00
|
|
|
for (bcount = bp->bio_bcount; bcount > 0; bcount -= rcount) {
|
2003-01-19 15:00:58 +00:00
|
|
|
err = ccdbuffer(cbp, cs, bp, bn, addr, bcount);
|
|
|
|
if (err) {
|
|
|
|
printf("ccdbuffer error %d\n", err);
|
2003-04-14 08:49:54 +00:00
|
|
|
if (!sent)
|
|
|
|
biofinish(bp, NULL, err);
|
|
|
|
else {
|
|
|
|
/*
|
|
|
|
* XXX: maybe a race where the partners
|
|
|
|
* XXX: we sent already have been in
|
|
|
|
* XXX: ccdiodone(). Single-threaded g_down
|
|
|
|
* XXX: may protect against this.
|
|
|
|
*/
|
|
|
|
bp->bio_resid -= bcount;
|
|
|
|
bp->bio_error = err;
|
|
|
|
bp->bio_flags |= BIO_ERROR;
|
|
|
|
}
|
2003-01-19 15:00:58 +00:00
|
|
|
return;
|
|
|
|
}
|
2000-05-01 13:36:43 +00:00
|
|
|
rcount = cbp[0]->cb_buf.bio_bcount;
|
1999-09-23 09:25:05 +00:00
|
|
|
|
|
|
|
if (cs->sc_cflags & CCDF_MIRROR) {
|
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
2000-05-01 13:36:43 +00:00
|
|
|
if (cbp[0]->cb_buf.bio_cmd == BIO_WRITE) {
|
2003-01-03 05:51:11 +00:00
|
|
|
BIO_STRATEGY(&cbp[0]->cb_buf);
|
|
|
|
BIO_STRATEGY(&cbp[1]->cb_buf);
|
2003-04-14 08:49:54 +00:00
|
|
|
sent++;
|
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-01-03 05:51:11 +00:00
|
|
|
BIO_STRATEGY(&cbp[pick]->cb_buf);
|
2003-04-14 08:49:54 +00:00
|
|
|
sent++;
|
1999-09-23 09:25:05 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Not mirroring
|
|
|
|
*/
|
2003-01-03 05:51:11 +00:00
|
|
|
BIO_STRATEGY(&cbp[0]->cb_buf);
|
2003-04-14 08:49:54 +00:00
|
|
|
sent++;
|
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
|
2001-09-04 08:33:30 +00:00
|
|
|
ccdbuffer(struct ccdbuf **cb, struct ccd_s *cs, struct bio *bp, daddr_t bn, caddr_t addr, long bcount)
|
1995-12-27 10:49:19 +00:00
|
|
|
{
|
1999-09-23 09:25:05 +00:00
|
|
|
struct ccdcinfo *ci, *ci2 = NULL; /* XXX */
|
|
|
|
struct ccdbuf *cbp;
|
|
|
|
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 {
|
1996-01-30 22:34:53 +00:00
|
|
|
if (cs->sc_cflags & 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-01-19 15:00:58 +00:00
|
|
|
cbp = malloc(sizeof(struct ccdbuf), M_CCD, M_NOWAIT | M_ZERO);
|
|
|
|
if (cbp == NULL)
|
|
|
|
return (ENOMEM);
|
2000-05-01 13:36:43 +00:00
|
|
|
cbp->cb_buf.bio_cmd = bp->bio_cmd;
|
|
|
|
cbp->cb_buf.bio_done = ccdiodone;
|
|
|
|
cbp->cb_buf.bio_dev = ci->ci_dev; /* XXX */
|
|
|
|
cbp->cb_buf.bio_blkno = cbn + cboff + CCD_OFFSET;
|
|
|
|
cbp->cb_buf.bio_offset = dbtob(cbn + cboff + CCD_OFFSET);
|
|
|
|
cbp->cb_buf.bio_data = addr;
|
2003-01-19 15:00:58 +00:00
|
|
|
cbp->cb_buf.bio_caller2 = cbp;
|
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));
|
2000-05-01 13:36:43 +00:00
|
|
|
cbp->cb_buf.bio_bcount = (cbc < bcount) ? cbc : bcount;
|
|
|
|
cbp->cb_buf.bio_caller1 = (void*)cbp->cb_buf.bio_bcount;
|
1997-01-10 04:09:13 +00:00
|
|
|
|
1995-12-27 10:49:19 +00:00
|
|
|
/*
|
|
|
|
* context for ccdiodone
|
|
|
|
*/
|
|
|
|
cbp->cb_obp = bp;
|
2003-01-19 15:00:58 +00:00
|
|
|
cbp->cb_softc = cs;
|
1995-12-27 10:49:19 +00:00
|
|
|
cbp->cb_comp = ci - cs->sc_cinfo;
|
|
|
|
|
1996-01-31 03:28:21 +00:00
|
|
|
cb[0] = cbp;
|
1999-09-23 09:25:05 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Note: both I/O's setup when reading from mirror, but only one
|
|
|
|
* will be executed.
|
|
|
|
*/
|
|
|
|
if (cs->sc_cflags & CCDF_MIRROR) {
|
|
|
|
/* mirror, setup second I/O */
|
2003-01-19 15:00:58 +00:00
|
|
|
cbp = malloc(sizeof(struct ccdbuf), M_CCD, M_NOWAIT);
|
|
|
|
if (cbp == NULL) {
|
|
|
|
free(cb[0], M_CCD);
|
|
|
|
cb[0] = NULL;
|
|
|
|
return (ENOMEM);
|
|
|
|
}
|
2003-01-18 12:23:49 +00:00
|
|
|
bcopy(cb[0], cbp, sizeof(struct ccdbuf));
|
2003-03-04 10:15:19 +00:00
|
|
|
cbp->cb_buf.bio_caller2 = cbp;
|
2000-05-01 13:36:43 +00:00
|
|
|
cbp->cb_buf.bio_dev = ci2->ci_dev;
|
1996-01-31 03:28:21 +00:00
|
|
|
cbp->cb_comp = ci2 - cs->sc_cinfo;
|
|
|
|
cb[1] = cbp;
|
1996-03-26 02:29:11 +00:00
|
|
|
/* link together the ccdbuf's and clear "mirror done" flag */
|
|
|
|
cb[0]->cb_mirror = cb[1];
|
|
|
|
cb[1]->cb_mirror = cb[0];
|
|
|
|
cb[0]->cb_pflags &= ~CCDPF_MIRROR_DONE;
|
|
|
|
cb[1]->cb_pflags &= ~CCDPF_MIRROR_DONE;
|
1996-01-31 03:28:21 +00:00
|
|
|
}
|
2003-01-19 15:00:58 +00:00
|
|
|
return (0);
|
1995-12-27 10:49:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Called at interrupt time.
|
|
|
|
* Mark the component as done and if all components are done,
|
|
|
|
* take a ccd interrupt.
|
|
|
|
*/
|
1997-10-24 14:24:55 +00:00
|
|
|
static void
|
2001-09-04 08:33:30 +00:00
|
|
|
ccdiodone(struct bio *ibp)
|
1995-12-27 10:49:19 +00:00
|
|
|
{
|
2003-01-19 15:00:58 +00:00
|
|
|
struct ccdbuf *cbp;
|
|
|
|
struct bio *bp;
|
2003-01-18 10:44:17 +00:00
|
|
|
struct ccd_s *cs;
|
2003-01-19 15:00:58 +00:00
|
|
|
int count;
|
1995-12-27 10:49:19 +00:00
|
|
|
|
2003-01-19 15:00:58 +00:00
|
|
|
cbp = ibp->bio_caller2;
|
|
|
|
cs = cbp->cb_softc;
|
|
|
|
bp = cbp->cb_obp;
|
1999-09-23 09:25:05 +00:00
|
|
|
/*
|
|
|
|
* If an error occured, report it. If this is a mirrored
|
|
|
|
* configuration and the first of two possible reads, do not
|
|
|
|
* set the error in the bp yet because the second read may
|
|
|
|
* succeed.
|
|
|
|
*/
|
1995-12-27 10:49:19 +00:00
|
|
|
|
2000-05-01 13:36:43 +00:00
|
|
|
if (cbp->cb_buf.bio_flags & BIO_ERROR) {
|
1999-09-23 09:25:05 +00:00
|
|
|
const char *msg = "";
|
|
|
|
|
2003-01-18 10:44:17 +00:00
|
|
|
if ((cs->sc_cflags & CCDF_MIRROR) &&
|
2000-05-01 13:36:43 +00:00
|
|
|
(cbp->cb_buf.bio_cmd == BIO_READ) &&
|
1999-09-23 09:25:05 +00:00
|
|
|
(cbp->cb_pflags & CCDPF_MIRROR_DONE) == 0) {
|
|
|
|
/*
|
|
|
|
* We will try our read on the other disk down
|
|
|
|
* below, also reverse the default pick so if we
|
|
|
|
* are doing a scan we do not keep hitting the
|
|
|
|
* bad disk first.
|
|
|
|
*/
|
|
|
|
|
|
|
|
msg = ", trying other disk";
|
|
|
|
cs->sc_pick = 1 - cs->sc_pick;
|
2000-05-01 13:36:43 +00:00
|
|
|
cs->sc_blk[cs->sc_pick] = bp->bio_blkno;
|
1999-09-23 09:25:05 +00:00
|
|
|
} else {
|
2000-05-01 13:36:43 +00:00
|
|
|
bp->bio_flags |= BIO_ERROR;
|
|
|
|
bp->bio_error = cbp->cb_buf.bio_error ?
|
|
|
|
cbp->cb_buf.bio_error : EIO;
|
1999-09-23 09:25:05 +00:00
|
|
|
}
|
2002-09-13 09:19:55 +00:00
|
|
|
printf("ccd%d: error %d on component %d block %jd "
|
2003-01-19 15:00:58 +00:00
|
|
|
"(ccd block %jd)%s\n", cs->sc_unit, bp->bio_error,
|
|
|
|
cbp->cb_comp,
|
2002-09-13 09:19:55 +00:00
|
|
|
(intmax_t)cbp->cb_buf.bio_blkno, (intmax_t)bp->bio_blkno,
|
|
|
|
msg);
|
1995-12-27 10:49:19 +00:00
|
|
|
}
|
1996-03-26 02:29:11 +00:00
|
|
|
|
1999-09-23 09:25:05 +00:00
|
|
|
/*
|
|
|
|
* Process mirror. If we are writing, I/O has been initiated on both
|
|
|
|
* buffers and we fall through only after both are finished.
|
|
|
|
*
|
|
|
|
* If we are reading only one I/O is initiated at a time. If an
|
|
|
|
* error occurs we initiate the second I/O and return, otherwise
|
|
|
|
* we free the second I/O without initiating it.
|
|
|
|
*/
|
|
|
|
|
2003-01-18 10:44:17 +00:00
|
|
|
if (cs->sc_cflags & CCDF_MIRROR) {
|
2000-05-01 13:36:43 +00:00
|
|
|
if (cbp->cb_buf.bio_cmd == BIO_WRITE) {
|
1999-09-23 09:25:05 +00:00
|
|
|
/*
|
|
|
|
* When writing, handshake with the second buffer
|
|
|
|
* to determine when both are done. If both are not
|
|
|
|
* done, return here.
|
|
|
|
*/
|
|
|
|
if ((cbp->cb_pflags & CCDPF_MIRROR_DONE) == 0) {
|
|
|
|
cbp->cb_mirror->cb_pflags |= CCDPF_MIRROR_DONE;
|
2003-01-18 12:23:49 +00:00
|
|
|
free(cbp, M_CCD);
|
1999-09-23 09:25:05 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* When reading, either dispose of the second buffer
|
|
|
|
* or initiate I/O on the second buffer if an error
|
|
|
|
* occured with this one.
|
|
|
|
*/
|
|
|
|
if ((cbp->cb_pflags & CCDPF_MIRROR_DONE) == 0) {
|
2000-05-01 13:36:43 +00:00
|
|
|
if (cbp->cb_buf.bio_flags & BIO_ERROR) {
|
1999-09-23 09:25:05 +00:00
|
|
|
cbp->cb_mirror->cb_pflags |=
|
|
|
|
CCDPF_MIRROR_DONE;
|
2003-01-03 05:51:11 +00:00
|
|
|
BIO_STRATEGY(&cbp->cb_mirror->cb_buf);
|
2003-01-18 12:23:49 +00:00
|
|
|
free(cbp, M_CCD);
|
1999-09-23 09:25:05 +00:00
|
|
|
return;
|
|
|
|
} else {
|
2003-01-18 12:23:49 +00:00
|
|
|
free(cbp->cb_mirror, M_CCD);
|
1999-09-23 09:25:05 +00:00
|
|
|
}
|
|
|
|
}
|
1996-03-26 02:29:11 +00:00
|
|
|
}
|
1999-09-23 09:25:05 +00:00
|
|
|
}
|
|
|
|
|
1999-09-23 08:41:48 +00:00
|
|
|
/*
|
2000-05-01 13:36:43 +00:00
|
|
|
* use bio_caller1 to determine how big the original request was rather
|
|
|
|
* then bio_bcount, because bio_bcount may have been truncated for EOF.
|
1999-09-23 08:41:48 +00:00
|
|
|
*
|
|
|
|
* XXX We check for an error, but we do not test the resid for an
|
|
|
|
* aligned EOF condition. This may result in character & block
|
|
|
|
* device access not recognizing EOF properly when read or written
|
|
|
|
* sequentially, but will not effect filesystems.
|
|
|
|
*/
|
2000-05-01 13:36:43 +00:00
|
|
|
count = (long)cbp->cb_buf.bio_caller1;
|
2003-01-18 12:23:49 +00:00
|
|
|
free(cbp, M_CCD);
|
1995-12-27 10:49:19 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If all done, "interrupt".
|
|
|
|
*/
|
2000-05-01 13:36:43 +00:00
|
|
|
bp->bio_resid -= count;
|
|
|
|
if (bp->bio_resid < 0)
|
1995-12-27 10:49:19 +00:00
|
|
|
panic("ccdiodone: count");
|
2003-01-18 10:44:17 +00:00
|
|
|
if (bp->bio_resid == 0) {
|
|
|
|
if (bp->bio_flags & BIO_ERROR)
|
|
|
|
bp->bio_resid = bp->bio_bcount;
|
2003-03-08 08:01:31 +00:00
|
|
|
biodone(bp);
|
2003-01-18 10:44:17 +00:00
|
|
|
}
|
1995-12-27 10:49:19 +00:00
|
|
|
}
|
|
|
|
|
2003-01-19 15:00:58 +00:00
|
|
|
static int ccdioctltoo(int unit, u_long cmd, caddr_t data, int flag, struct thread *td);
|
|
|
|
|
1997-10-24 14:24:55 +00:00
|
|
|
static int
|
2003-01-19 15:00:58 +00:00
|
|
|
ccdctlioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct thread *td)
|
1995-12-27 10:49:19 +00:00
|
|
|
{
|
2003-01-17 14:53:53 +00:00
|
|
|
struct ccd_ioctl *ccio;
|
|
|
|
u_int unit;
|
|
|
|
dev_t dev2;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
case CCDIOCSET:
|
|
|
|
case CCDIOCCLR:
|
|
|
|
ccio = (struct ccd_ioctl *)data;
|
|
|
|
unit = ccio->ccio_size;
|
2003-01-19 15:00:58 +00:00
|
|
|
return (ccdioctltoo(unit, cmd, data, flag, td));
|
2003-01-17 14:53:53 +00:00
|
|
|
case CCDCONFINFO:
|
|
|
|
{
|
|
|
|
int ninit = 0;
|
|
|
|
struct ccdconf *conf = (struct ccdconf *)data;
|
|
|
|
struct ccd_s *tmpcs;
|
|
|
|
struct ccd_s *ubuf = conf->buffer;
|
|
|
|
|
|
|
|
/* XXX: LOCK(unique unit numbers) */
|
|
|
|
LIST_FOREACH(tmpcs, &ccd_softc_list, list)
|
|
|
|
if (IS_INITED(tmpcs))
|
|
|
|
ninit++;
|
|
|
|
|
|
|
|
if (conf->size == 0) {
|
|
|
|
conf->size = sizeof(struct ccd_s) * ninit;
|
|
|
|
return (0);
|
|
|
|
} else if ((conf->size / sizeof(struct ccd_s) != ninit) ||
|
|
|
|
(conf->size % sizeof(struct ccd_s) != 0)) {
|
|
|
|
/* XXX: UNLOCK(unique unit numbers) */
|
|
|
|
return (EINVAL);
|
|
|
|
}
|
|
|
|
|
|
|
|
ubuf += ninit;
|
|
|
|
LIST_FOREACH(tmpcs, &ccd_softc_list, list) {
|
|
|
|
if (!IS_INITED(tmpcs))
|
|
|
|
continue;
|
|
|
|
error = copyout(tmpcs, --ubuf,
|
|
|
|
sizeof(struct ccd_s));
|
|
|
|
if (error != 0)
|
|
|
|
/* XXX: UNLOCK(unique unit numbers) */
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
/* XXX: UNLOCK(unique unit numbers) */
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
case CCDCPPINFO:
|
|
|
|
{
|
|
|
|
struct ccdcpps *cpps = (struct ccdcpps *)data;
|
|
|
|
char *ubuf = cpps->buffer;
|
2003-01-19 15:00:58 +00:00
|
|
|
struct ccd_s *cs;
|
2003-01-17 14:53:53 +00:00
|
|
|
|
|
|
|
|
|
|
|
error = copyin(ubuf, &unit, sizeof (unit));
|
|
|
|
if (error)
|
|
|
|
return (error);
|
|
|
|
|
|
|
|
if (!IS_ALLOCATED(unit))
|
|
|
|
return (ENXIO);
|
|
|
|
dev2 = makedev(CDEV_MAJOR, unit * 8 + 2);
|
2003-01-19 15:00:58 +00:00
|
|
|
cs = ccdfind(unit);
|
|
|
|
if (!IS_INITED(cs))
|
|
|
|
return (ENXIO);
|
|
|
|
|
|
|
|
{
|
|
|
|
int len = 0, i;
|
|
|
|
struct ccdcpps *cpps = (struct ccdcpps *)data;
|
|
|
|
char *ubuf = cpps->buffer;
|
|
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < cs->sc_nccdisks; ++i)
|
|
|
|
len += cs->sc_cinfo[i].ci_pathlen;
|
|
|
|
|
|
|
|
if (cpps->size < len)
|
|
|
|
return (ENOMEM);
|
|
|
|
|
|
|
|
for (i = 0; i < cs->sc_nccdisks; ++i) {
|
|
|
|
len = cs->sc_cinfo[i].ci_pathlen;
|
|
|
|
error = copyout(cs->sc_cinfo[i].ci_path, ubuf,
|
|
|
|
len);
|
|
|
|
if (error != 0)
|
|
|
|
return (error);
|
|
|
|
ubuf += len;
|
|
|
|
}
|
|
|
|
return(copyout("", ubuf, 1));
|
|
|
|
}
|
|
|
|
break;
|
2003-01-17 14:53:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
return (ENXIO);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2003-01-19 15:00:58 +00:00
|
|
|
ccdioctltoo(int unit, u_long cmd, caddr_t data, int flag, struct thread *td)
|
2003-01-17 14:53:53 +00:00
|
|
|
{
|
1995-12-27 10:49:19 +00:00
|
|
|
int i, j, lookedup = 0, error = 0;
|
2001-09-04 08:33:30 +00:00
|
|
|
struct ccd_s *cs;
|
1995-12-27 10:49:19 +00:00
|
|
|
struct ccd_ioctl *ccio = (struct ccd_ioctl *)data;
|
2003-01-19 15:00:58 +00:00
|
|
|
struct ccdgeom *ccg;
|
1995-12-27 10:49:19 +00:00
|
|
|
char **cpp;
|
|
|
|
struct vnode **vpp;
|
|
|
|
|
2001-09-04 08:33:30 +00:00
|
|
|
cs = ccdfind(unit);
|
1995-12-27 10:49:19 +00:00
|
|
|
switch (cmd) {
|
|
|
|
case CCDIOCSET:
|
2003-01-19 15:00:58 +00:00
|
|
|
if (cs == NULL)
|
|
|
|
cs = ccdnew(unit);
|
2001-09-04 08:33:30 +00:00
|
|
|
if (IS_INITED(cs))
|
1995-12-27 10:49:19 +00:00
|
|
|
return (EBUSY);
|
|
|
|
|
|
|
|
if ((flag & FWRITE) == 0)
|
|
|
|
return (EBADF);
|
|
|
|
|
1999-01-27 20:09:21 +00:00
|
|
|
if ((error = ccdlock(cs)) != 0)
|
1995-12-27 10:49:19 +00:00
|
|
|
return (error);
|
|
|
|
|
2001-09-10 11:28:07 +00:00
|
|
|
if (ccio->ccio_ndisks > CCD_MAXNDISKS)
|
|
|
|
return (EINVAL);
|
|
|
|
|
1995-12-27 10:49:19 +00:00
|
|
|
/* Fill in some important bits. */
|
2001-09-04 08:33:30 +00:00
|
|
|
cs->sc_ileave = ccio->ccio_ileave;
|
2003-01-03 08:57:40 +00:00
|
|
|
if (cs->sc_ileave == 0 && (ccio->ccio_flags & CCDF_MIRROR)) {
|
|
|
|
printf("ccd%d: disabling mirror, interleave is 0\n",
|
|
|
|
unit);
|
|
|
|
ccio->ccio_flags &= ~(CCDF_MIRROR);
|
1996-01-31 11:25:46 +00:00
|
|
|
}
|
1996-01-30 22:34:53 +00:00
|
|
|
if ((ccio->ccio_flags & CCDF_MIRROR) &&
|
1996-01-02 23:32:54 +00:00
|
|
|
!(ccio->ccio_flags & CCDF_UNIFORM)) {
|
1996-01-30 22:34:53 +00:00
|
|
|
printf("ccd%d: mirror/parity forces uniform flag\n",
|
|
|
|
unit);
|
1996-01-02 23:32:54 +00:00
|
|
|
ccio->ccio_flags |= CCDF_UNIFORM;
|
|
|
|
}
|
2001-09-04 08:33:30 +00:00
|
|
|
cs->sc_flags = ccio->ccio_flags & CCDF_USERMASK;
|
1995-12-27 10:49:19 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Allocate space for and copy in the array of
|
|
|
|
* componet pathnames and device numbers.
|
|
|
|
*/
|
|
|
|
cpp = malloc(ccio->ccio_ndisks * sizeof(char *),
|
2003-02-19 05:47:46 +00:00
|
|
|
M_CCD, M_WAITOK);
|
1995-12-27 10:49:19 +00:00
|
|
|
vpp = malloc(ccio->ccio_ndisks * sizeof(struct vnode *),
|
2003-02-19 05:47:46 +00:00
|
|
|
M_CCD, M_WAITOK);
|
1995-12-27 10:49:19 +00:00
|
|
|
|
|
|
|
error = copyin((caddr_t)ccio->ccio_disks, (caddr_t)cpp,
|
|
|
|
ccio->ccio_ndisks * sizeof(char **));
|
|
|
|
if (error) {
|
2003-01-18 11:04:41 +00:00
|
|
|
free(vpp, M_CCD);
|
|
|
|
free(cpp, M_CCD);
|
1995-12-27 10:49:19 +00:00
|
|
|
ccdunlock(cs);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < ccio->ccio_ndisks; ++i) {
|
2001-09-12 08:38:13 +00:00
|
|
|
if ((error = ccdlookup(cpp[i], td, &vpp[i])) != 0) {
|
1995-12-27 10:49:19 +00:00
|
|
|
for (j = 0; j < lookedup; ++j)
|
|
|
|
(void)vn_close(vpp[j], FREAD|FWRITE,
|
2002-02-27 18:32:23 +00:00
|
|
|
td->td_ucred, td);
|
2003-01-18 11:04:41 +00:00
|
|
|
free(vpp, M_CCD);
|
|
|
|
free(cpp, M_CCD);
|
1995-12-27 10:49:19 +00:00
|
|
|
ccdunlock(cs);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
++lookedup;
|
|
|
|
}
|
2001-09-04 08:33:30 +00:00
|
|
|
cs->sc_vpp = vpp;
|
|
|
|
cs->sc_nccdisks = ccio->ccio_ndisks;
|
1995-12-27 10:49:19 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialize the ccd. Fills in the softc for us.
|
|
|
|
*/
|
2001-09-12 08:38:13 +00:00
|
|
|
if ((error = ccdinit(cs, cpp, td)) != 0) {
|
1995-12-27 10:49:19 +00:00
|
|
|
for (j = 0; j < lookedup; ++j)
|
2001-01-27 00:01:31 +00:00
|
|
|
(void)vn_close(vpp[j], FREAD|FWRITE,
|
2002-02-27 18:32:23 +00:00
|
|
|
td->td_ucred, td);
|
2001-09-04 08:33:30 +00:00
|
|
|
/*
|
|
|
|
* We can't ccddestroy() cs just yet, because nothing
|
|
|
|
* prevents user-level app to do another ioctl()
|
|
|
|
* without closing the device first, therefore
|
|
|
|
* declare unit null and void and let ccdclose()
|
|
|
|
* destroy it when it is safe to do so.
|
|
|
|
*/
|
|
|
|
cs->sc_flags &= (CCDF_WANTED | CCDF_LOCKED);
|
2003-01-18 11:04:41 +00:00
|
|
|
free(vpp, M_CCD);
|
|
|
|
free(cpp, M_CCD);
|
1995-12-27 10:49:19 +00:00
|
|
|
ccdunlock(cs);
|
|
|
|
return (error);
|
|
|
|
}
|
2003-01-18 11:33:06 +00:00
|
|
|
free(cpp, M_CCD);
|
1995-12-27 10:49:19 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* The ccd has been successfully initialized, so
|
|
|
|
* we can place it into the array and read the disklabel.
|
|
|
|
*/
|
|
|
|
ccio->ccio_unit = unit;
|
|
|
|
ccio->ccio_size = cs->sc_size;
|
2003-01-19 15:00:58 +00:00
|
|
|
ccg = &cs->sc_geom;
|
2003-02-19 05:47:46 +00:00
|
|
|
cs->sc_disk = malloc(sizeof(struct disk), M_CCD,
|
|
|
|
M_ZERO | M_WAITOK);
|
2003-02-01 11:17:22 +00:00
|
|
|
cs->sc_disk->d_strategy = ccdstrategy;
|
|
|
|
cs->sc_disk->d_name = "ccd";
|
2003-01-19 15:00:58 +00:00
|
|
|
cs->sc_disk->d_sectorsize = ccg->ccg_secsize;
|
|
|
|
cs->sc_disk->d_mediasize =
|
|
|
|
cs->sc_size * (off_t)ccg->ccg_secsize;
|
|
|
|
cs->sc_disk->d_fwsectors = ccg->ccg_nsectors;
|
|
|
|
cs->sc_disk->d_fwheads = ccg->ccg_ntracks;
|
2003-02-21 23:25:43 +00:00
|
|
|
cs->sc_disk->d_drv1 = cs;
|
|
|
|
cs->sc_disk->d_maxsize = MAXPHYS;
|
|
|
|
disk_create(unit, cs->sc_disk, 0, NULL, NULL);
|
1995-12-27 10:49:19 +00:00
|
|
|
|
|
|
|
ccdunlock(cs);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CCDIOCCLR:
|
2003-01-19 15:00:58 +00:00
|
|
|
if (cs == NULL)
|
|
|
|
return (ENXIO);
|
|
|
|
|
2001-09-04 08:33:30 +00:00
|
|
|
if (!IS_INITED(cs))
|
1995-12-27 10:49:19 +00:00
|
|
|
return (ENXIO);
|
|
|
|
|
|
|
|
if ((flag & FWRITE) == 0)
|
|
|
|
return (EBADF);
|
|
|
|
|
1999-01-27 20:09:21 +00:00
|
|
|
if ((error = ccdlock(cs)) != 0)
|
1995-12-27 10:49:19 +00:00
|
|
|
return (error);
|
|
|
|
|
2000-01-16 09:25:10 +00:00
|
|
|
/* Don't unconfigure if any other partitions are open */
|
2003-02-01 11:17:22 +00:00
|
|
|
if (cs->sc_disk->d_flags & DISKFLAG_OPEN) {
|
1995-12-27 10:49:19 +00:00
|
|
|
ccdunlock(cs);
|
|
|
|
return (EBUSY);
|
|
|
|
}
|
|
|
|
|
2003-02-21 15:13:26 +00:00
|
|
|
disk_destroy(cs->sc_disk);
|
2003-01-19 15:00:58 +00:00
|
|
|
free(cs->sc_disk, M_CCD);
|
|
|
|
cs->sc_disk = NULL;
|
2001-09-04 08:33:30 +00:00
|
|
|
/* Declare unit null and void (reset all flags) */
|
|
|
|
cs->sc_flags &= (CCDF_WANTED | CCDF_LOCKED);
|
1995-12-27 10:49:19 +00:00
|
|
|
|
|
|
|
/* Close the components and free their pathnames. */
|
|
|
|
for (i = 0; i < cs->sc_nccdisks; ++i) {
|
|
|
|
/*
|
|
|
|
* XXX: this close could potentially fail and
|
|
|
|
* cause Bad Things. Maybe we need to force
|
|
|
|
* the close to happen?
|
|
|
|
*/
|
|
|
|
(void)vn_close(cs->sc_cinfo[i].ci_vp, FREAD|FWRITE,
|
2002-02-27 18:32:23 +00:00
|
|
|
td->td_ucred, td);
|
2003-01-18 11:04:41 +00:00
|
|
|
free(cs->sc_cinfo[i].ci_path, M_CCD);
|
1995-12-27 10:49:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Free interleave index. */
|
|
|
|
for (i = 0; cs->sc_itable[i].ii_ndisk; ++i)
|
2003-01-18 11:04:41 +00:00
|
|
|
free(cs->sc_itable[i].ii_index, M_CCD);
|
1995-12-27 10:49:19 +00:00
|
|
|
|
|
|
|
/* Free component info and interleave table. */
|
2003-01-18 11:04:41 +00:00
|
|
|
free(cs->sc_cinfo, M_CCD);
|
|
|
|
free(cs->sc_itable, M_CCD);
|
|
|
|
free(cs->sc_vpp, M_CCD);
|
1995-12-27 10:49:19 +00:00
|
|
|
|
|
|
|
/* This must be atomic. */
|
|
|
|
ccdunlock(cs);
|
2003-01-19 15:00:58 +00:00
|
|
|
ccddestroy(cs);
|
2001-09-04 08:33:30 +00:00
|
|
|
|
|
|
|
break;
|
1995-12-27 10:49:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Lookup the provided name in the filesystem. If the file exists,
|
|
|
|
* is a valid block device, and isn't being used by anyone else,
|
|
|
|
* set *vpp to the file's vnode.
|
|
|
|
*/
|
|
|
|
static int
|
2001-09-12 08:38:13 +00:00
|
|
|
ccdlookup(char *path, struct thread *td, struct vnode **vpp)
|
1995-12-27 10:49:19 +00:00
|
|
|
{
|
|
|
|
struct nameidata nd;
|
|
|
|
struct vnode *vp;
|
2000-07-04 03:34:11 +00:00
|
|
|
int error, flags;
|
1995-12-27 10:49:19 +00:00
|
|
|
|
2001-09-12 08:38:13 +00:00
|
|
|
NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, path, td);
|
2000-07-04 03:34:11 +00:00
|
|
|
flags = FREAD | FWRITE;
|
|
|
|
if ((error = vn_open(&nd, &flags, 0)) != 0) {
|
1995-12-27 10:49:19 +00:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
vp = nd.ni_vp;
|
|
|
|
|
2002-09-25 02:42:43 +00:00
|
|
|
if (vrefcnt(vp) > 1) {
|
1999-12-15 23:02:35 +00:00
|
|
|
error = EBUSY;
|
|
|
|
goto bad;
|
1995-12-27 10:49:19 +00:00
|
|
|
}
|
|
|
|
|
2000-01-10 12:04:27 +00:00
|
|
|
if (!vn_isdisk(vp, &error))
|
1999-12-15 23:02:35 +00:00
|
|
|
goto bad;
|
1995-12-27 10:49:19 +00:00
|
|
|
|
|
|
|
|
2001-09-12 08:38:13 +00:00
|
|
|
VOP_UNLOCK(vp, 0, td);
|
1999-12-15 23:02:35 +00:00
|
|
|
NDFREE(&nd, NDF_ONLY_PNBUF);
|
1995-12-27 10:49:19 +00:00
|
|
|
*vpp = vp;
|
|
|
|
return (0);
|
1999-12-15 23:02:35 +00:00
|
|
|
bad:
|
2001-09-12 08:38:13 +00:00
|
|
|
VOP_UNLOCK(vp, 0, td);
|
1999-12-15 23:02:35 +00:00
|
|
|
NDFREE(&nd, NDF_ONLY_PNBUF);
|
|
|
|
/* vn_close does vrele() for vp */
|
2002-02-27 18:32:23 +00:00
|
|
|
(void)vn_close(vp, FREAD|FWRITE, td->td_ucred, td);
|
1999-12-15 23:02:35 +00:00
|
|
|
return (error);
|
1995-12-27 10:49:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
* Wait interruptibly for an exclusive lock.
|
|
|
|
*
|
|
|
|
* XXX
|
|
|
|
* Several drivers do this; it should be abstracted and made MP-safe.
|
|
|
|
*/
|
|
|
|
static int
|
2001-09-04 08:33:30 +00:00
|
|
|
ccdlock(struct ccd_s *cs)
|
1995-12-27 10:49:19 +00:00
|
|
|
{
|
|
|
|
int error;
|
|
|
|
|
|
|
|
while ((cs->sc_flags & CCDF_LOCKED) != 0) {
|
|
|
|
cs->sc_flags |= CCDF_WANTED;
|
|
|
|
if ((error = tsleep(cs, PRIBIO | PCATCH, "ccdlck", 0)) != 0)
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
cs->sc_flags |= CCDF_LOCKED;
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Unlock and wake up any waiters.
|
|
|
|
*/
|
|
|
|
static void
|
2001-09-04 08:33:30 +00:00
|
|
|
ccdunlock(struct ccd_s *cs)
|
1995-12-27 10:49:19 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
cs->sc_flags &= ~CCDF_LOCKED;
|
|
|
|
if ((cs->sc_flags & CCDF_WANTED) != 0) {
|
|
|
|
cs->sc_flags &= ~CCDF_WANTED;
|
|
|
|
wakeup(cs);
|
|
|
|
}
|
|
|
|
}
|