1999-02-12 03:46:11 +03:00
|
|
|
/* $NetBSD: ccd.c,v 1.60 1999/02/12 00:48:07 thorpej Exp $ */
|
1995-08-17 20:31:30 +04:00
|
|
|
|
1996-02-28 04:01:17 +03:00
|
|
|
/*-
|
1999-01-21 03:35:15 +03:00
|
|
|
* Copyright (c) 1996, 1997, 1998, 1999 The NetBSD Foundation, Inc.
|
1995-08-17 20:31:30 +04:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
1996-02-28 04:01:17 +03:00
|
|
|
* This code is derived from software contributed to The NetBSD Foundation
|
|
|
|
* by Jason R. Thorpe.
|
|
|
|
*
|
1995-08-17 20:31:30 +04: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:
|
1996-02-28 04:01:17 +03:00
|
|
|
* This product includes software developed by the NetBSD
|
|
|
|
* Foundation, Inc. and its contributors.
|
|
|
|
* 4. Neither the name of The NetBSD Foundation nor the names of its
|
|
|
|
* contributors may be used to endorse or promote products derived
|
|
|
|
* from this software without specific prior written permission.
|
1995-08-17 20:31:30 +04:00
|
|
|
*
|
1996-02-28 04:01:17 +03:00
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. 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
|
1997-10-09 12:03:42 +04:00
|
|
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
|
|
|
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
1996-02-28 04:01:17 +03:00
|
|
|
* 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.
|
1995-08-17 20:31:30 +04:00
|
|
|
*/
|
1994-06-29 10:29:24 +04:00
|
|
|
|
1994-06-24 18:11:02 +04:00
|
|
|
/*
|
|
|
|
* Copyright (c) 1988 University of Utah.
|
1994-07-02 10:03:47 +04:00
|
|
|
* Copyright (c) 1990, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
1994-06-24 18:11:02 +04:00
|
|
|
*
|
|
|
|
* This code is derived from software contributed to Berkeley by
|
|
|
|
* the Systems Programming Group of the University of Utah Computer
|
|
|
|
* Science Department.
|
|
|
|
*
|
|
|
|
* 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 by the University of
|
|
|
|
* California, Berkeley and its contributors.
|
|
|
|
* 4. Neither the name of the University nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
|
|
|
|
*
|
1994-06-29 10:29:24 +04:00
|
|
|
* from: Utah $Hdr: cd.c 1.6 90/11/28$
|
|
|
|
*
|
1994-07-02 10:03:47 +04:00
|
|
|
* @(#)cd.c 8.2 (Berkeley) 11/16/93
|
1994-06-24 18:11:02 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* "Concatenated" disk driver.
|
1995-08-17 20:31:30 +04:00
|
|
|
*
|
|
|
|
* 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
|
1994-06-24 18:11:02 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
1994-07-02 10:03:47 +04:00
|
|
|
#include <sys/proc.h>
|
1994-06-24 18:11:02 +04:00
|
|
|
#include <sys/errno.h>
|
|
|
|
#include <sys/buf.h>
|
|
|
|
#include <sys/malloc.h>
|
1995-08-17 20:31:30 +04:00
|
|
|
#include <sys/namei.h>
|
1994-07-02 10:03:47 +04:00
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <sys/disklabel.h>
|
1995-08-17 20:31:30 +04:00
|
|
|
#include <sys/device.h>
|
|
|
|
#include <sys/disk.h>
|
|
|
|
#include <sys/syslog.h>
|
1994-07-02 10:03:47 +04:00
|
|
|
#include <sys/fcntl.h>
|
1995-08-17 20:31:30 +04:00
|
|
|
#include <sys/vnode.h>
|
1996-03-31 03:05:46 +04:00
|
|
|
#include <sys/conf.h>
|
1999-01-12 03:21:47 +03:00
|
|
|
#include <sys/lock.h>
|
1998-11-13 04:00:15 +03:00
|
|
|
#include <sys/queue.h>
|
1994-06-24 18:11:02 +04:00
|
|
|
|
|
|
|
#include <dev/ccdvar.h>
|
|
|
|
|
1995-08-17 20:31:30 +04:00
|
|
|
#if defined(CCDDEBUG) && !defined(DEBUG)
|
|
|
|
#define DEBUG
|
|
|
|
#endif
|
|
|
|
|
1994-06-24 18:11:02 +04:00
|
|
|
#ifdef DEBUG
|
1994-07-02 10:03:47 +04:00
|
|
|
#define CCDB_FOLLOW 0x01
|
|
|
|
#define CCDB_INIT 0x02
|
|
|
|
#define CCDB_IO 0x04
|
1995-08-17 20:31:30 +04:00
|
|
|
#define CCDB_LABEL 0x08
|
|
|
|
#define CCDB_VNODE 0x10
|
1996-02-01 23:47:13 +03:00
|
|
|
int ccddebug = 0x00;
|
1994-06-24 18:11:02 +04:00
|
|
|
#endif
|
|
|
|
|
1995-03-02 09:38:11 +03:00
|
|
|
#define ccdunit(x) DISKUNIT(x)
|
1994-06-24 18:11:02 +04:00
|
|
|
|
1995-03-02 09:38:11 +03:00
|
|
|
struct ccdbuf {
|
|
|
|
struct buf cb_buf; /* new I/O buf */
|
|
|
|
struct buf *cb_obp; /* ptr. to original I/O buf */
|
1999-01-21 03:35:15 +03:00
|
|
|
struct ccd_softc *cb_sc; /* pointer to ccd softc */
|
1995-03-02 09:38:11 +03:00
|
|
|
int cb_comp; /* target component */
|
1998-11-13 04:00:15 +03:00
|
|
|
SIMPLEQ_ENTRY(ccdbuf) cb_q; /* fifo of component buffers */
|
1997-01-30 07:00:52 +03:00
|
|
|
};
|
1996-02-01 23:47:13 +03:00
|
|
|
|
1998-11-13 01:39:57 +03:00
|
|
|
#define CCD_GETBUF(cs) pool_get(&(cs)->sc_cbufpool, PR_NOWAIT)
|
1998-07-31 05:23:56 +04:00
|
|
|
#define CCD_PUTBUF(cs, cbp) pool_put(&(cs)->sc_cbufpool, cbp)
|
1994-06-24 18:11:02 +04:00
|
|
|
|
1995-08-17 20:31:30 +04:00
|
|
|
#define CCDLABELDEV(dev) \
|
|
|
|
(MAKEDISKDEV(major((dev)), ccdunit((dev)), RAW_PART))
|
|
|
|
|
|
|
|
/* called by main() at boot time */
|
|
|
|
void ccdattach __P((int));
|
1995-03-02 09:38:11 +03:00
|
|
|
|
1995-08-17 20:31:30 +04:00
|
|
|
/* called by biodone() at interrupt time */
|
1996-03-07 18:00:07 +03:00
|
|
|
void ccdiodone __P((struct buf *));
|
|
|
|
int ccdsize __P((dev_t));
|
1994-06-24 18:11:02 +04:00
|
|
|
|
1995-08-17 20:31:30 +04:00
|
|
|
static void ccdstart __P((struct ccd_softc *, struct buf *));
|
1999-01-12 03:21:47 +03:00
|
|
|
static void ccdinterleave __P((struct ccd_softc *));
|
1995-08-17 20:31:30 +04:00
|
|
|
static void ccdintr __P((struct ccd_softc *, struct buf *));
|
1999-01-12 03:21:47 +03:00
|
|
|
static int ccdinit __P((struct ccd_softc *, char **, struct vnode **,
|
|
|
|
struct proc *));
|
1995-08-17 20:31:30 +04:00
|
|
|
static int ccdlookup __P((char *, struct proc *p, struct vnode **));
|
1998-11-13 03:35:57 +03:00
|
|
|
static struct ccdbuf *ccdbuffer __P((struct ccd_softc *, struct buf *,
|
|
|
|
daddr_t, caddr_t, long));
|
1997-10-09 03:05:22 +04:00
|
|
|
static void ccdgetdefaultlabel __P((struct ccd_softc *, struct disklabel *));
|
1995-08-17 20:31:30 +04:00
|
|
|
static void ccdgetdisklabel __P((dev_t));
|
|
|
|
static void ccdmakedisklabel __P((struct ccd_softc *));
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
static void printiinfo __P((struct ccdiinfo *));
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Non-private for the benefit of libkvm. */
|
|
|
|
struct ccd_softc *ccd_softc;
|
|
|
|
int numccd = 0;
|
1994-06-24 18:11:02 +04:00
|
|
|
|
1994-07-02 10:03:47 +04:00
|
|
|
/*
|
1995-08-17 20:31:30 +04:00
|
|
|
* Called by main() during pseudo-device attachment. All we need
|
|
|
|
* to do is allocate enough space for devices to be configured later.
|
1994-07-02 10:03:47 +04:00
|
|
|
*/
|
1994-06-24 18:11:02 +04:00
|
|
|
void
|
1994-07-02 10:03:47 +04:00
|
|
|
ccdattach(num)
|
|
|
|
int num;
|
|
|
|
{
|
1999-01-12 03:21:47 +03:00
|
|
|
struct ccd_softc *cs;
|
|
|
|
int i;
|
|
|
|
|
1995-08-17 20:31:30 +04:00
|
|
|
if (num <= 0) {
|
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
panic("ccdattach: count <= 0");
|
|
|
|
#endif
|
1994-07-02 10:03:47 +04:00
|
|
|
return;
|
1995-08-17 20:31:30 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
ccd_softc = (struct ccd_softc *)malloc(num * sizeof(struct ccd_softc),
|
|
|
|
M_DEVBUF, M_NOWAIT);
|
1999-01-12 03:21:47 +03:00
|
|
|
if (ccd_softc == NULL) {
|
1996-10-13 05:37:04 +04:00
|
|
|
printf("WARNING: no memory for concatenated disks\n");
|
1995-08-17 20:31:30 +04:00
|
|
|
if (ccd_softc != NULL)
|
|
|
|
free(ccd_softc, M_DEVBUF);
|
1994-07-02 10:03:47 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
numccd = num;
|
1995-08-17 20:31:30 +04:00
|
|
|
bzero(ccd_softc, num * sizeof(struct ccd_softc));
|
1999-01-12 03:21:47 +03:00
|
|
|
|
|
|
|
/* Initialize per-softc structures. */
|
|
|
|
for (i = 0; i < num; i++) {
|
|
|
|
cs = &ccd_softc[i];
|
|
|
|
sprintf(cs->sc_xname, "ccd%d", i); /* XXX */
|
|
|
|
cs->sc_dkdev.dk_name = cs->sc_xname; /* XXX */
|
|
|
|
lockinit(&cs->sc_lock, PRIBIO, "ccdlk", 0, 0);
|
|
|
|
}
|
1994-06-24 18:11:02 +04:00
|
|
|
}
|
|
|
|
|
1995-08-17 20:31:30 +04:00
|
|
|
static int
|
1999-01-12 03:21:47 +03:00
|
|
|
ccdinit(cs, cpaths, vpp, p)
|
|
|
|
struct ccd_softc *cs;
|
1995-08-17 20:31:30 +04:00
|
|
|
char **cpaths;
|
1999-01-12 03:21:47 +03:00
|
|
|
struct vnode **vpp;
|
1995-08-17 20:31:30 +04:00
|
|
|
struct proc *p;
|
1994-06-24 18:11:02 +04:00
|
|
|
{
|
1996-03-07 18:00:07 +03:00
|
|
|
register struct ccdcinfo *ci = NULL;
|
1994-06-24 18:11:02 +04:00
|
|
|
register size_t size;
|
|
|
|
register int ix;
|
1995-08-17 20:31:30 +04:00
|
|
|
struct vattr va;
|
1994-06-24 18:11:02 +04:00
|
|
|
size_t minsize;
|
1995-08-17 20:31:30 +04:00
|
|
|
int maxsecsize;
|
1995-03-02 09:40:38 +03:00
|
|
|
struct partinfo dpart;
|
1995-08-17 20:31:30 +04:00
|
|
|
struct ccdgeom *ccg = &cs->sc_geom;
|
|
|
|
char tmppath[MAXPATHLEN];
|
|
|
|
int error;
|
1994-06-24 18:11:02 +04:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
1994-07-02 10:03:47 +04:00
|
|
|
if (ccddebug & (CCDB_FOLLOW|CCDB_INIT))
|
1999-01-21 03:35:15 +03:00
|
|
|
printf("%s: ccdinit\n", cs->sc_xname);
|
1994-06-24 18:11:02 +04:00
|
|
|
#endif
|
1995-08-17 20:31:30 +04:00
|
|
|
|
|
|
|
/* Allocate space for the component info. */
|
|
|
|
cs->sc_cinfo = malloc(cs->sc_nccdisks * sizeof(struct ccdcinfo),
|
|
|
|
M_DEVBUF, M_WAITOK);
|
|
|
|
|
1999-01-12 03:21:47 +03:00
|
|
|
cs->sc_size = 0;
|
|
|
|
|
1994-06-24 18:11:02 +04:00
|
|
|
/*
|
|
|
|
* Verify that each component piece exists and record
|
|
|
|
* relevant information about it.
|
|
|
|
*/
|
1995-08-17 20:31:30 +04:00
|
|
|
maxsecsize = 0;
|
1994-06-24 18:11:02 +04:00
|
|
|
minsize = 0;
|
1995-08-17 20:31:30 +04:00
|
|
|
for (ix = 0; ix < cs->sc_nccdisks; ix++) {
|
1994-06-24 18:11:02 +04:00
|
|
|
ci = &cs->sc_cinfo[ix];
|
1999-01-12 03:21:47 +03:00
|
|
|
ci->ci_vp = vpp[ix];
|
1995-08-17 20:31:30 +04:00
|
|
|
|
1994-07-02 10:03:47 +04:00
|
|
|
/*
|
1995-08-17 20:31:30 +04:00
|
|
|
* Copy in the pathname of the component.
|
1994-07-02 10:03:47 +04:00
|
|
|
*/
|
1995-08-17 20:31:30 +04:00
|
|
|
bzero(tmppath, sizeof(tmppath)); /* sanity */
|
1996-03-07 18:00:07 +03:00
|
|
|
error = copyinstr(cpaths[ix], tmppath,
|
|
|
|
MAXPATHLEN, &ci->ci_pathlen);
|
|
|
|
if (error) {
|
1995-08-17 20:31:30 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
if (ccddebug & (CCDB_FOLLOW|CCDB_INIT))
|
1996-10-13 05:37:04 +04:00
|
|
|
printf("%s: can't copy path, error = %d\n",
|
1996-01-08 01:01:38 +03:00
|
|
|
cs->sc_xname, error);
|
1995-08-17 20:31:30 +04:00
|
|
|
#endif
|
|
|
|
free(cs->sc_cinfo, M_DEVBUF);
|
|
|
|
return (error);
|
1994-07-02 10:03:47 +04:00
|
|
|
}
|
1995-08-17 20:31:30 +04:00
|
|
|
ci->ci_path = malloc(ci->ci_pathlen, M_DEVBUF, M_WAITOK);
|
|
|
|
bcopy(tmppath, ci->ci_path, ci->ci_pathlen);
|
|
|
|
|
1994-06-24 18:11:02 +04:00
|
|
|
/*
|
1995-08-17 20:31:30 +04:00
|
|
|
* XXX: Cache the component's dev_t.
|
1994-06-24 18:11:02 +04:00
|
|
|
*/
|
1999-01-12 03:21:47 +03:00
|
|
|
if ((error = VOP_GETATTR(vpp[ix], &va, p->p_ucred, p)) != 0) {
|
1995-08-17 20:31:30 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
if (ccddebug & (CCDB_FOLLOW|CCDB_INIT))
|
1996-10-13 05:37:04 +04:00
|
|
|
printf("%s: %s: getattr failed %s = %d\n",
|
1996-01-08 01:01:38 +03:00
|
|
|
cs->sc_xname, ci->ci_path,
|
1995-08-17 20:31:30 +04:00
|
|
|
"error", error);
|
|
|
|
#endif
|
|
|
|
free(ci->ci_path, M_DEVBUF);
|
|
|
|
free(cs->sc_cinfo, M_DEVBUF);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
ci->ci_dev = va.va_rdev;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get partition information for the component.
|
|
|
|
*/
|
1999-01-12 03:21:47 +03:00
|
|
|
error = VOP_IOCTL(vpp[ix], DIOCGPART, (caddr_t)&dpart,
|
1996-03-07 18:00:07 +03:00
|
|
|
FREAD, p->p_ucred, p);
|
|
|
|
if (error) {
|
1995-08-17 20:31:30 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
if (ccddebug & (CCDB_FOLLOW|CCDB_INIT))
|
1996-10-13 05:37:04 +04:00
|
|
|
printf("%s: %s: ioctl failed, error = %d\n",
|
1996-01-08 01:01:38 +03:00
|
|
|
cs->sc_xname, ci->ci_path, error);
|
1995-08-17 20:31:30 +04:00
|
|
|
#endif
|
|
|
|
free(ci->ci_path, M_DEVBUF);
|
|
|
|
free(cs->sc_cinfo, M_DEVBUF);
|
|
|
|
return (error);
|
|
|
|
}
|
1995-03-02 09:40:38 +03:00
|
|
|
|
1995-08-17 20:31:30 +04:00
|
|
|
/*
|
|
|
|
* Calculate the size, truncating to an interleave
|
|
|
|
* boundary if necessary.
|
|
|
|
*/
|
1998-02-06 11:13:07 +03:00
|
|
|
maxsecsize =
|
|
|
|
((dpart.disklab->d_secsize > maxsecsize) ?
|
|
|
|
dpart.disklab->d_secsize : maxsecsize);
|
|
|
|
size = dpart.part->p_size;
|
1994-06-24 18:11:02 +04:00
|
|
|
if (cs->sc_ileave > 1)
|
|
|
|
size -= size % cs->sc_ileave;
|
1995-08-17 20:31:30 +04:00
|
|
|
|
1994-06-24 18:11:02 +04:00
|
|
|
if (size == 0) {
|
1995-08-17 20:31:30 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
if (ccddebug & (CCDB_FOLLOW|CCDB_INIT))
|
1996-10-13 05:37:04 +04:00
|
|
|
printf("%s: %s: size == 0\n",
|
1996-01-08 01:01:38 +03:00
|
|
|
cs->sc_xname, ci->ci_path);
|
1994-07-02 10:03:47 +04:00
|
|
|
#endif
|
1995-08-17 20:31:30 +04:00
|
|
|
free(ci->ci_path, M_DEVBUF);
|
|
|
|
free(cs->sc_cinfo, M_DEVBUF);
|
|
|
|
return (ENODEV);
|
|
|
|
}
|
|
|
|
|
1994-06-24 18:11:02 +04:00
|
|
|
if (minsize == 0 || size < minsize)
|
|
|
|
minsize = size;
|
|
|
|
ci->ci_size = size;
|
|
|
|
cs->sc_size += size;
|
|
|
|
}
|
1995-08-17 20:31:30 +04: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))) {
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (ccddebug & (CCDB_FOLLOW|CCDB_INIT))
|
1996-10-13 05:37:04 +04:00
|
|
|
printf("%s: interleave must be at least %d\n",
|
1996-01-08 01:01:38 +03:00
|
|
|
cs->sc_xname, (maxsecsize / DEV_BSIZE));
|
1995-08-17 20:31:30 +04:00
|
|
|
#endif
|
|
|
|
free(ci->ci_path, M_DEVBUF);
|
|
|
|
free(cs->sc_cinfo, M_DEVBUF);
|
|
|
|
return (EINVAL);
|
|
|
|
}
|
|
|
|
|
1994-06-24 18:11:02 +04:00
|
|
|
/*
|
|
|
|
* If uniform interleave is desired set all sizes to that of
|
|
|
|
* the smallest component.
|
|
|
|
*/
|
1999-01-12 03:21:47 +03:00
|
|
|
if (cs->sc_flags & CCDF_UNIFORM) {
|
1994-06-24 18:11:02 +04:00
|
|
|
for (ci = cs->sc_cinfo;
|
|
|
|
ci < &cs->sc_cinfo[cs->sc_nccdisks]; ci++)
|
|
|
|
ci->ci_size = minsize;
|
1996-02-01 23:47:13 +03:00
|
|
|
|
1998-11-13 03:26:19 +03:00
|
|
|
cs->sc_size = cs->sc_nccdisks * minsize;
|
1994-06-24 18:11:02 +04:00
|
|
|
}
|
1995-08-17 20:31:30 +04:00
|
|
|
|
1994-06-24 18:11:02 +04:00
|
|
|
/*
|
1995-08-17 20:31:30 +04:00
|
|
|
* Construct the interleave table.
|
1994-06-24 18:11:02 +04:00
|
|
|
*/
|
1999-01-12 03:21:47 +03:00
|
|
|
ccdinterleave(cs);
|
1994-06-24 18:11:02 +04:00
|
|
|
|
1995-08-17 20:31:30 +04:00
|
|
|
/*
|
|
|
|
* Create pseudo-geometry based on 1MB cylinders. It's
|
|
|
|
* pretty close.
|
|
|
|
*/
|
|
|
|
ccg->ccg_secsize = DEV_BSIZE;
|
1995-10-13 00:28:32 +03:00
|
|
|
ccg->ccg_ntracks = 1;
|
1995-08-17 20:31:30 +04:00
|
|
|
ccg->ccg_nsectors = 1024 * (1024 / ccg->ccg_secsize);
|
|
|
|
ccg->ccg_ncylinders = cs->sc_size / ccg->ccg_nsectors;
|
1994-06-24 18:11:02 +04:00
|
|
|
|
1995-08-17 20:31:30 +04:00
|
|
|
cs->sc_flags |= CCDF_INITED;
|
1996-01-08 01:01:38 +03:00
|
|
|
|
1995-08-17 20:31:30 +04:00
|
|
|
return (0);
|
1994-06-24 18:11:02 +04:00
|
|
|
}
|
|
|
|
|
1995-08-17 20:31:30 +04:00
|
|
|
static void
|
1999-01-12 03:21:47 +03:00
|
|
|
ccdinterleave(cs)
|
1994-06-24 18:11:02 +04:00
|
|
|
register struct ccd_softc *cs;
|
|
|
|
{
|
|
|
|
register struct ccdcinfo *ci, *smallci;
|
|
|
|
register struct ccdiinfo *ii;
|
|
|
|
register daddr_t bn, lbn;
|
|
|
|
register int ix;
|
|
|
|
u_long size;
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
1994-07-02 10:03:47 +04:00
|
|
|
if (ccddebug & CCDB_INIT)
|
1996-10-13 05:37:04 +04:00
|
|
|
printf("ccdinterleave(%p): ileave %d\n", cs, cs->sc_ileave);
|
1994-06-24 18:11:02 +04:00
|
|
|
#endif
|
|
|
|
/*
|
|
|
|
* Allocate an interleave table.
|
|
|
|
* Chances are this is too big, but we don't care.
|
|
|
|
*/
|
|
|
|
size = (cs->sc_nccdisks + 1) * sizeof(struct ccdiinfo);
|
|
|
|
cs->sc_itable = (struct ccdiinfo *)malloc(size, M_DEVBUF, M_WAITOK);
|
|
|
|
bzero((caddr_t)cs->sc_itable, size);
|
1995-08-17 20:31:30 +04:00
|
|
|
|
1994-06-24 18:11:02 +04:00
|
|
|
/*
|
|
|
|
* Trivial case: no interleave (actually interleave of disk size).
|
1995-08-17 20:31:30 +04:00
|
|
|
* Each table entry represents a single component in its entirety.
|
1994-06-24 18:11:02 +04:00
|
|
|
*/
|
|
|
|
if (cs->sc_ileave == 0) {
|
|
|
|
bn = 0;
|
|
|
|
ii = cs->sc_itable;
|
1995-08-17 20:31:30 +04:00
|
|
|
|
1994-06-24 18:11:02 +04:00
|
|
|
for (ix = 0; ix < cs->sc_nccdisks; ix++) {
|
1995-10-13 00:28:32 +03:00
|
|
|
/* Allocate space for ii_index. */
|
|
|
|
ii->ii_index = malloc(sizeof(int), M_DEVBUF, M_WAITOK);
|
1994-06-24 18:11:02 +04: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;
|
|
|
|
#ifdef DEBUG
|
1994-07-02 10:03:47 +04:00
|
|
|
if (ccddebug & CCDB_INIT)
|
1994-06-24 18:11:02 +04:00
|
|
|
printiinfo(cs->sc_itable);
|
|
|
|
#endif
|
1995-08-17 20:31:30 +04:00
|
|
|
return;
|
1994-06-24 18:11:02 +04:00
|
|
|
}
|
1995-08-17 20:31:30 +04:00
|
|
|
|
1994-06-24 18:11:02 +04:00
|
|
|
/*
|
|
|
|
* The following isn't fast or pretty; it doesn't have to be.
|
|
|
|
*/
|
|
|
|
size = 0;
|
|
|
|
bn = lbn = 0;
|
|
|
|
for (ii = cs->sc_itable; ; ii++) {
|
1995-08-17 20:31:30 +04:00
|
|
|
/* Allocate space for ii_index. */
|
1995-10-13 00:28:32 +03:00
|
|
|
ii->ii_index = malloc((sizeof(int) * cs->sc_nccdisks),
|
|
|
|
M_DEVBUF, M_WAITOK);
|
1995-08-17 20:31:30 +04:00
|
|
|
|
1994-06-24 18:11:02 +04:00
|
|
|
/*
|
|
|
|
* Locate the smallest of the remaining components
|
|
|
|
*/
|
|
|
|
smallci = NULL;
|
|
|
|
for (ci = cs->sc_cinfo;
|
|
|
|
ci < &cs->sc_cinfo[cs->sc_nccdisks]; ci++)
|
|
|
|
if (ci->ci_size > size &&
|
|
|
|
(smallci == NULL ||
|
|
|
|
ci->ci_size < smallci->ci_size))
|
|
|
|
smallci = ci;
|
1995-08-17 20:31:30 +04:00
|
|
|
|
1994-06-24 18:11:02 +04:00
|
|
|
/*
|
|
|
|
* Nobody left, all done
|
|
|
|
*/
|
|
|
|
if (smallci == NULL) {
|
|
|
|
ii->ii_ndisk = 0;
|
|
|
|
break;
|
|
|
|
}
|
1995-08-17 20:31:30 +04:00
|
|
|
|
1994-06-24 18:11:02 +04:00
|
|
|
/*
|
|
|
|
* Record starting logical block and component offset
|
|
|
|
*/
|
|
|
|
ii->ii_startblk = bn / cs->sc_ileave;
|
|
|
|
ii->ii_startoff = lbn;
|
1995-08-17 20:31:30 +04:00
|
|
|
|
1994-06-24 18:11:02 +04:00
|
|
|
/*
|
|
|
|
* Determine how many disks take part in this interleave
|
|
|
|
* and record their indices.
|
|
|
|
*/
|
|
|
|
ix = 0;
|
|
|
|
for (ci = cs->sc_cinfo;
|
|
|
|
ci < &cs->sc_cinfo[cs->sc_nccdisks]; ci++)
|
|
|
|
if (ci->ci_size >= smallci->ci_size)
|
|
|
|
ii->ii_index[ix++] = ci - cs->sc_cinfo;
|
|
|
|
ii->ii_ndisk = ix;
|
|
|
|
bn += ix * (smallci->ci_size - size);
|
|
|
|
lbn = smallci->ci_size / cs->sc_ileave;
|
|
|
|
size = smallci->ci_size;
|
|
|
|
}
|
|
|
|
#ifdef DEBUG
|
1994-07-02 10:03:47 +04:00
|
|
|
if (ccddebug & CCDB_INIT)
|
1994-06-24 18:11:02 +04:00
|
|
|
printiinfo(cs->sc_itable);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
1995-08-17 20:31:30 +04:00
|
|
|
/* ARGSUSED */
|
|
|
|
int
|
|
|
|
ccdopen(dev, flags, fmt, p)
|
1994-06-24 18:11:02 +04:00
|
|
|
dev_t dev;
|
1995-08-17 20:31:30 +04:00
|
|
|
int flags, fmt;
|
|
|
|
struct proc *p;
|
1994-06-24 18:11:02 +04:00
|
|
|
{
|
|
|
|
int unit = ccdunit(dev);
|
1995-08-17 20:31:30 +04:00
|
|
|
struct ccd_softc *cs;
|
|
|
|
struct disklabel *lp;
|
1995-10-09 03:46:45 +03:00
|
|
|
int error = 0, part, pmask;
|
1994-06-24 18:11:02 +04:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
1994-07-02 10:03:47 +04:00
|
|
|
if (ccddebug & CCDB_FOLLOW)
|
1997-08-04 14:00:11 +04:00
|
|
|
printf("ccdopen(0x%x, 0x%x)\n", dev, flags);
|
1994-06-24 18:11:02 +04:00
|
|
|
#endif
|
1995-08-17 20:31:30 +04:00
|
|
|
if (unit >= numccd)
|
|
|
|
return (ENXIO);
|
|
|
|
cs = &ccd_softc[unit];
|
|
|
|
|
1999-01-12 03:21:47 +03:00
|
|
|
if ((error = lockmgr(&cs->sc_lock, LK_EXCLUSIVE, NULL)) != 0)
|
1995-10-09 03:46:45 +03:00
|
|
|
return (error);
|
|
|
|
|
1996-01-08 01:01:38 +03:00
|
|
|
lp = cs->sc_dkdev.dk_label;
|
1995-08-17 20:31:30 +04:00
|
|
|
|
|
|
|
part = DISKPART(dev);
|
|
|
|
pmask = (1 << part);
|
|
|
|
|
1995-10-09 03:46:45 +03:00
|
|
|
/*
|
|
|
|
* If we're initialized, check to see if there are any other
|
|
|
|
* open partitions. If not, then it's safe to update
|
|
|
|
* the in-core disklabel.
|
|
|
|
*/
|
|
|
|
if ((cs->sc_flags & CCDF_INITED) && (cs->sc_dkdev.dk_openmask == 0))
|
|
|
|
ccdgetdisklabel(dev);
|
|
|
|
|
1995-08-17 20:31:30 +04:00
|
|
|
/* Check that the partition exists. */
|
1996-02-11 21:04:01 +03:00
|
|
|
if (part != RAW_PART) {
|
|
|
|
if (((cs->sc_flags & CCDF_INITED) == 0) ||
|
1997-01-30 06:32:56 +03:00
|
|
|
((part >= lp->d_npartitions) ||
|
1996-02-11 21:04:01 +03:00
|
|
|
(lp->d_partitions[part].p_fstype == FS_UNUSED))) {
|
|
|
|
error = ENXIO;
|
|
|
|
goto done;
|
|
|
|
}
|
1995-10-09 03:46:45 +03:00
|
|
|
}
|
1995-08-17 20:31:30 +04:00
|
|
|
|
|
|
|
/* Prevent our unit from being unconfigured while open. */
|
|
|
|
switch (fmt) {
|
|
|
|
case S_IFCHR:
|
|
|
|
cs->sc_dkdev.dk_copenmask |= pmask;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case S_IFBLK:
|
|
|
|
cs->sc_dkdev.dk_bopenmask |= pmask;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
cs->sc_dkdev.dk_openmask =
|
|
|
|
cs->sc_dkdev.dk_copenmask | cs->sc_dkdev.dk_bopenmask;
|
|
|
|
|
1995-10-09 03:46:45 +03:00
|
|
|
done:
|
1999-01-12 03:21:47 +03:00
|
|
|
(void) lockmgr(&cs->sc_lock, LK_RELEASE, NULL);
|
1996-05-05 08:21:14 +04:00
|
|
|
return (error);
|
1994-06-24 18:11:02 +04:00
|
|
|
}
|
|
|
|
|
1995-08-17 20:31:30 +04:00
|
|
|
/* ARGSUSED */
|
|
|
|
int
|
|
|
|
ccdclose(dev, flags, fmt, p)
|
1995-03-02 09:40:38 +03:00
|
|
|
dev_t dev;
|
1995-08-17 20:31:30 +04:00
|
|
|
int flags, fmt;
|
|
|
|
struct proc *p;
|
1995-03-02 09:40:38 +03:00
|
|
|
{
|
1995-08-17 20:31:30 +04:00
|
|
|
int unit = ccdunit(dev);
|
|
|
|
struct ccd_softc *cs;
|
1995-10-09 03:46:45 +03:00
|
|
|
int error = 0, part;
|
1995-08-17 20:31:30 +04:00
|
|
|
|
1995-03-02 09:40:38 +03:00
|
|
|
#ifdef DEBUG
|
|
|
|
if (ccddebug & CCDB_FOLLOW)
|
1997-08-04 14:00:11 +04:00
|
|
|
printf("ccdclose(0x%x, 0x%x)\n", dev, flags);
|
1995-03-02 09:40:38 +03:00
|
|
|
#endif
|
1995-08-17 20:31:30 +04:00
|
|
|
|
|
|
|
if (unit >= numccd)
|
|
|
|
return (ENXIO);
|
|
|
|
cs = &ccd_softc[unit];
|
1995-10-09 03:46:45 +03:00
|
|
|
|
1999-01-12 03:21:47 +03:00
|
|
|
if ((error = lockmgr(&cs->sc_lock, LK_EXCLUSIVE, NULL)) != 0)
|
1995-10-09 03:46:45 +03:00
|
|
|
return (error);
|
|
|
|
|
1995-08-17 20:31:30 +04:00
|
|
|
part = DISKPART(dev);
|
|
|
|
|
|
|
|
/* ...that much closer to allowing unconfiguration... */
|
|
|
|
switch (fmt) {
|
|
|
|
case S_IFCHR:
|
|
|
|
cs->sc_dkdev.dk_copenmask &= ~(1 << part);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case S_IFBLK:
|
|
|
|
cs->sc_dkdev.dk_bopenmask &= ~(1 << part);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
cs->sc_dkdev.dk_openmask =
|
|
|
|
cs->sc_dkdev.dk_copenmask | cs->sc_dkdev.dk_bopenmask;
|
|
|
|
|
1999-01-12 03:21:47 +03:00
|
|
|
(void) lockmgr(&cs->sc_lock, LK_RELEASE, NULL);
|
1995-03-02 09:40:38 +03:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
1995-08-17 20:31:30 +04:00
|
|
|
void
|
1994-06-24 18:11:02 +04:00
|
|
|
ccdstrategy(bp)
|
|
|
|
register struct buf *bp;
|
|
|
|
{
|
|
|
|
register int unit = ccdunit(bp->b_dev);
|
|
|
|
register struct ccd_softc *cs = &ccd_softc[unit];
|
1996-03-07 18:00:07 +03:00
|
|
|
register int s;
|
1995-08-17 20:31:30 +04:00
|
|
|
int wlabel;
|
1995-10-09 03:46:45 +03:00
|
|
|
struct disklabel *lp;
|
1994-06-24 18:11:02 +04:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
1994-07-02 10:03:47 +04:00
|
|
|
if (ccddebug & CCDB_FOLLOW)
|
1996-10-13 05:37:04 +04:00
|
|
|
printf("ccdstrategy(%p): unit %d\n", bp, unit);
|
1994-06-24 18:11:02 +04:00
|
|
|
#endif
|
1994-07-02 10:03:47 +04:00
|
|
|
if ((cs->sc_flags & CCDF_INITED) == 0) {
|
1999-01-21 03:35:15 +03:00
|
|
|
#ifdef DEBUG
|
|
|
|
if (ccddebug & CCDB_FOLLOW)
|
|
|
|
printf("ccdstrategy: unit %d: not inited\n", unit);
|
|
|
|
#endif
|
1994-06-24 18:11:02 +04:00
|
|
|
bp->b_error = ENXIO;
|
|
|
|
bp->b_flags |= B_ERROR;
|
|
|
|
goto done;
|
|
|
|
}
|
1995-08-17 20:31:30 +04:00
|
|
|
|
|
|
|
/* If it's a nil transfer, wake up the top half now. */
|
|
|
|
if (bp->b_bcount == 0)
|
|
|
|
goto done;
|
|
|
|
|
1996-01-08 01:01:38 +03:00
|
|
|
lp = cs->sc_dkdev.dk_label;
|
1995-10-09 03:46:45 +03:00
|
|
|
|
1995-08-17 20:31:30 +04:00
|
|
|
/*
|
1995-10-09 08:21:09 +03:00
|
|
|
* Do bounds checking and adjust transfer. If there's an
|
1995-08-17 20:31:30 +04:00
|
|
|
* error, the bounds check will flag that for us.
|
|
|
|
*/
|
|
|
|
wlabel = cs->sc_flags & (CCDF_WLABEL|CCDF_LABELLING);
|
1995-10-09 04:45:34 +03:00
|
|
|
if (DISKPART(bp->b_dev) != RAW_PART)
|
1995-10-09 03:46:45 +03:00
|
|
|
if (bounds_check_with_label(bp, lp, wlabel) <= 0)
|
1994-06-24 18:11:02 +04:00
|
|
|
goto done;
|
1995-08-17 20:31:30 +04:00
|
|
|
|
1994-06-24 18:11:02 +04:00
|
|
|
bp->b_resid = bp->b_bcount;
|
1995-08-17 20:31:30 +04:00
|
|
|
|
1994-06-24 18:11:02 +04:00
|
|
|
/*
|
|
|
|
* "Start" the unit.
|
|
|
|
*/
|
|
|
|
s = splbio();
|
1994-07-02 10:03:47 +04:00
|
|
|
ccdstart(cs, bp);
|
1994-06-24 18:11:02 +04:00
|
|
|
splx(s);
|
1998-11-13 04:00:15 +03:00
|
|
|
if (bp->b_flags & B_ERROR)
|
|
|
|
goto done;
|
1994-06-24 18:11:02 +04:00
|
|
|
return;
|
|
|
|
done:
|
|
|
|
biodone(bp);
|
|
|
|
}
|
|
|
|
|
1995-08-17 20:31:30 +04:00
|
|
|
static void
|
1994-07-02 10:03:47 +04:00
|
|
|
ccdstart(cs, bp)
|
|
|
|
register struct ccd_softc *cs;
|
|
|
|
register struct buf *bp;
|
1994-06-24 18:11:02 +04:00
|
|
|
{
|
|
|
|
register long bcount, rcount;
|
1998-11-13 03:35:57 +03:00
|
|
|
struct ccdbuf *cbp;
|
1994-06-24 18:11:02 +04:00
|
|
|
caddr_t addr;
|
|
|
|
daddr_t bn;
|
1995-11-03 05:35:54 +03:00
|
|
|
struct partition *pp;
|
1998-11-13 04:00:15 +03:00
|
|
|
SIMPLEQ_HEAD(, ccdbuf) cbufq;
|
1994-06-24 18:11:02 +04:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
1994-07-02 10:03:47 +04:00
|
|
|
if (ccddebug & CCDB_FOLLOW)
|
1996-10-13 05:37:04 +04:00
|
|
|
printf("ccdstart(%p, %p)\n", cs, bp);
|
1994-06-24 18:11:02 +04:00
|
|
|
#endif
|
1995-08-17 20:31:30 +04:00
|
|
|
|
1996-01-08 01:01:38 +03:00
|
|
|
/* Instrumentation. */
|
|
|
|
disk_busy(&cs->sc_dkdev);
|
1995-08-17 20:31:30 +04:00
|
|
|
|
1994-06-24 18:11:02 +04:00
|
|
|
/*
|
1995-10-09 08:21:09 +03:00
|
|
|
* Translate the partition-relative block number to an absolute.
|
1994-06-24 18:11:02 +04:00
|
|
|
*/
|
1995-11-03 05:35:54 +03:00
|
|
|
bn = bp->b_blkno;
|
|
|
|
if (DISKPART(bp->b_dev) != RAW_PART) {
|
1996-01-08 01:01:38 +03:00
|
|
|
pp = &cs->sc_dkdev.dk_label->d_partitions[DISKPART(bp->b_dev)];
|
1995-11-03 05:35:54 +03:00
|
|
|
bn += pp->p_offset;
|
|
|
|
}
|
1995-10-09 08:21:09 +03:00
|
|
|
|
|
|
|
/*
|
1998-11-13 04:00:15 +03:00
|
|
|
* Allocate the component buffers.
|
1995-10-09 08:21:09 +03:00
|
|
|
*/
|
1998-11-13 04:00:15 +03:00
|
|
|
SIMPLEQ_INIT(&cbufq);
|
1994-07-02 10:03:47 +04:00
|
|
|
addr = bp->b_data;
|
1994-06-24 18:11:02 +04:00
|
|
|
for (bcount = bp->b_bcount; bcount > 0; bcount -= rcount) {
|
1998-11-13 03:35:57 +03:00
|
|
|
cbp = ccdbuffer(cs, bp, bn, addr, bcount);
|
1998-11-13 04:00:15 +03:00
|
|
|
if (cbp == NULL) {
|
|
|
|
/* Free the already allocated component buffers. */
|
|
|
|
while ((cbp = SIMPLEQ_FIRST(&cbufq)) != NULL) {
|
|
|
|
SIMPLEQ_REMOVE_HEAD(&cbufq, cbp, cb_q);
|
|
|
|
CCD_PUTBUF(cs, cbp);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Notify the upper layer we are out of memory. */
|
|
|
|
bp->b_error = ENOMEM;
|
|
|
|
bp->b_flags |= B_ERROR;
|
1999-01-21 03:35:15 +03:00
|
|
|
disk_unbusy(&cs->sc_dkdev, 0);
|
1998-11-13 04:00:15 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
SIMPLEQ_INSERT_TAIL(&cbufq, cbp, cb_q);
|
1998-11-13 03:35:57 +03:00
|
|
|
rcount = cbp->cb_buf.b_bcount;
|
1998-11-13 04:00:15 +03:00
|
|
|
bn += btodb(rcount);
|
|
|
|
addr += rcount;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Now fire off the requests. */
|
|
|
|
while ((cbp = SIMPLEQ_FIRST(&cbufq)) != NULL) {
|
|
|
|
SIMPLEQ_REMOVE_HEAD(&cbufq, cbp, cb_q);
|
1998-11-13 03:35:57 +03:00
|
|
|
if ((cbp->cb_buf.b_flags & B_READ) == 0)
|
|
|
|
cbp->cb_buf.b_vp->v_numoutput++;
|
|
|
|
VOP_STRATEGY(&cbp->cb_buf);
|
1994-06-24 18:11:02 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Build a component buffer header.
|
|
|
|
*/
|
1998-11-13 03:35:57 +03:00
|
|
|
static struct ccdbuf *
|
|
|
|
ccdbuffer(cs, bp, bn, addr, bcount)
|
1994-06-24 18:11:02 +04:00
|
|
|
register struct ccd_softc *cs;
|
|
|
|
struct buf *bp;
|
|
|
|
daddr_t bn;
|
|
|
|
caddr_t addr;
|
|
|
|
long bcount;
|
|
|
|
{
|
1998-11-13 03:26:19 +03:00
|
|
|
register struct ccdcinfo *ci;
|
1995-03-02 09:38:11 +03:00
|
|
|
register struct ccdbuf *cbp;
|
1994-06-24 18:11:02 +04:00
|
|
|
register daddr_t cbn, cboff;
|
1998-07-10 00:56:12 +04:00
|
|
|
register u_int64_t cbc;
|
1996-12-18 22:22:46 +03:00
|
|
|
int ccdisk;
|
1994-06-24 18:11:02 +04:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
1994-07-02 10:03:47 +04:00
|
|
|
if (ccddebug & CCDB_IO)
|
1996-10-13 05:37:04 +04:00
|
|
|
printf("ccdbuffer(%p, %p, %d, %p, %ld)\n",
|
1994-06-24 18:11:02 +04:00
|
|
|
cs, bp, bn, addr, bcount);
|
|
|
|
#endif
|
|
|
|
/*
|
|
|
|
* Determine which component bn falls in.
|
|
|
|
*/
|
|
|
|
cbn = bn;
|
|
|
|
cboff = 0;
|
1995-08-17 20:31:30 +04:00
|
|
|
|
1994-06-24 18:11:02 +04:00
|
|
|
/*
|
|
|
|
* Serially concatenated
|
|
|
|
*/
|
|
|
|
if (cs->sc_ileave == 0) {
|
|
|
|
register daddr_t sblk;
|
|
|
|
|
|
|
|
sblk = 0;
|
1996-12-18 22:22:46 +03:00
|
|
|
for (ccdisk = 0, ci = &cs->sc_cinfo[ccdisk];
|
|
|
|
cbn >= sblk + ci->ci_size;
|
|
|
|
ccdisk++, ci = &cs->sc_cinfo[ccdisk])
|
1994-06-24 18:11:02 +04:00
|
|
|
sblk += ci->ci_size;
|
|
|
|
cbn -= sblk;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Interleaved
|
|
|
|
*/
|
|
|
|
else {
|
|
|
|
register struct ccdiinfo *ii;
|
1996-12-18 22:22:46 +03:00
|
|
|
int off;
|
1994-06-24 18:11:02 +04:00
|
|
|
|
|
|
|
cboff = cbn % cs->sc_ileave;
|
|
|
|
cbn /= cs->sc_ileave;
|
|
|
|
for (ii = cs->sc_itable; ii->ii_ndisk; ii++)
|
|
|
|
if (ii->ii_startblk > cbn)
|
|
|
|
break;
|
|
|
|
ii--;
|
|
|
|
off = cbn - ii->ii_startblk;
|
|
|
|
if (ii->ii_ndisk == 1) {
|
|
|
|
ccdisk = ii->ii_index[0];
|
|
|
|
cbn = ii->ii_startoff + off;
|
|
|
|
} else {
|
1998-11-13 03:26:19 +03:00
|
|
|
ccdisk = ii->ii_index[off % ii->ii_ndisk];
|
|
|
|
cbn = ii->ii_startoff + off / ii->ii_ndisk;
|
1994-06-24 18:11:02 +04:00
|
|
|
}
|
|
|
|
cbn *= cs->sc_ileave;
|
|
|
|
ci = &cs->sc_cinfo[ccdisk];
|
|
|
|
}
|
1995-08-17 20:31:30 +04:00
|
|
|
|
1994-06-24 18:11:02 +04:00
|
|
|
/*
|
|
|
|
* Fill in the component buf structure.
|
|
|
|
*/
|
1998-07-31 05:23:56 +04:00
|
|
|
cbp = CCD_GETBUF(cs);
|
1998-11-13 03:35:57 +03:00
|
|
|
if (cbp == NULL)
|
|
|
|
return (NULL);
|
1995-03-02 09:38:11 +03:00
|
|
|
cbp->cb_buf.b_flags = bp->b_flags | B_CALL;
|
1996-03-07 18:00:07 +03:00
|
|
|
cbp->cb_buf.b_iodone = ccdiodone;
|
1995-03-02 09:38:11 +03:00
|
|
|
cbp->cb_buf.b_proc = bp->b_proc;
|
1995-08-17 20:31:30 +04:00
|
|
|
cbp->cb_buf.b_dev = ci->ci_dev; /* XXX */
|
1995-03-02 09:38:11 +03:00
|
|
|
cbp->cb_buf.b_blkno = cbn + cboff;
|
|
|
|
cbp->cb_buf.b_data = addr;
|
1995-08-17 20:31:30 +04:00
|
|
|
cbp->cb_buf.b_vp = ci->ci_vp;
|
1994-06-24 18:11:02 +04:00
|
|
|
if (cs->sc_ileave == 0)
|
1998-07-10 00:56:12 +04:00
|
|
|
cbc = dbtob((u_int64_t)(ci->ci_size - cbn));
|
1994-06-24 18:11:02 +04:00
|
|
|
else
|
1998-07-10 00:56:12 +04:00
|
|
|
cbc = dbtob((u_int64_t)(cs->sc_ileave - cboff));
|
|
|
|
cbp->cb_buf.b_bcount = cbc < bcount ? cbc : bcount;
|
1995-03-02 09:38:11 +03:00
|
|
|
|
1994-06-24 18:11:02 +04:00
|
|
|
/*
|
1995-03-02 09:38:11 +03:00
|
|
|
* context for ccdiodone
|
1994-06-24 18:11:02 +04:00
|
|
|
*/
|
1995-03-02 09:38:11 +03:00
|
|
|
cbp->cb_obp = bp;
|
1999-01-21 03:35:15 +03:00
|
|
|
cbp->cb_sc = cs;
|
1996-12-18 22:22:46 +03:00
|
|
|
cbp->cb_comp = ccdisk;
|
1995-03-02 09:38:11 +03:00
|
|
|
|
1994-06-24 18:11:02 +04:00
|
|
|
#ifdef DEBUG
|
1994-07-02 10:03:47 +04:00
|
|
|
if (ccddebug & CCDB_IO)
|
1997-08-04 14:00:11 +04:00
|
|
|
printf(" dev 0x%x(u%d): cbp %p bn %d addr %p bcnt %ld\n",
|
1996-10-11 02:25:05 +04:00
|
|
|
ci->ci_dev, ci-cs->sc_cinfo, cbp, cbp->cb_buf.b_blkno,
|
|
|
|
cbp->cb_buf.b_data, cbp->cb_buf.b_bcount);
|
1994-06-24 18:11:02 +04:00
|
|
|
#endif
|
1998-11-13 03:35:57 +03:00
|
|
|
|
|
|
|
return (cbp);
|
1994-06-24 18:11:02 +04:00
|
|
|
}
|
|
|
|
|
1995-08-17 20:31:30 +04:00
|
|
|
static void
|
1994-07-02 10:03:47 +04:00
|
|
|
ccdintr(cs, bp)
|
|
|
|
register struct ccd_softc *cs;
|
|
|
|
register struct buf *bp;
|
1994-06-24 18:11:02 +04:00
|
|
|
{
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
1994-07-02 10:03:47 +04:00
|
|
|
if (ccddebug & CCDB_FOLLOW)
|
1996-10-13 05:37:04 +04:00
|
|
|
printf("ccdintr(%p, %p)\n", cs, bp);
|
1994-06-24 18:11:02 +04:00
|
|
|
#endif
|
|
|
|
/*
|
|
|
|
* Request is done for better or worse, wakeup the top half.
|
|
|
|
*/
|
|
|
|
if (bp->b_flags & B_ERROR)
|
|
|
|
bp->b_resid = bp->b_bcount;
|
1996-01-08 01:01:38 +03:00
|
|
|
disk_unbusy(&cs->sc_dkdev, (bp->b_bcount - bp->b_resid));
|
1994-06-24 18:11:02 +04:00
|
|
|
biodone(bp);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
1995-08-17 20:31:30 +04:00
|
|
|
* Called at interrupt time.
|
1994-06-24 18:11:02 +04:00
|
|
|
* Mark the component as done and if all components are done,
|
|
|
|
* take a ccd interrupt.
|
|
|
|
*/
|
1994-07-02 10:03:47 +04:00
|
|
|
void
|
1996-03-07 18:00:07 +03:00
|
|
|
ccdiodone(vbp)
|
|
|
|
struct buf *vbp;
|
1994-06-24 18:11:02 +04:00
|
|
|
{
|
1996-03-07 18:00:07 +03:00
|
|
|
struct ccdbuf *cbp = (struct ccdbuf *) vbp;
|
1999-01-21 03:35:15 +03:00
|
|
|
struct buf *bp = cbp->cb_obp;
|
|
|
|
struct ccd_softc *cs = cbp->cb_sc;
|
1998-11-13 03:26:19 +03:00
|
|
|
int count, s;
|
1994-06-24 18:11:02 +04:00
|
|
|
|
|
|
|
s = splbio();
|
|
|
|
#ifdef DEBUG
|
1994-07-02 10:03:47 +04:00
|
|
|
if (ccddebug & CCDB_FOLLOW)
|
1996-10-13 05:37:04 +04:00
|
|
|
printf("ccdiodone(%p)\n", cbp);
|
1994-07-02 10:03:47 +04:00
|
|
|
if (ccddebug & CCDB_IO) {
|
1998-11-13 03:26:19 +03:00
|
|
|
printf("ccdiodone: bp %p bcount %ld resid %ld\n",
|
|
|
|
bp, bp->b_bcount, bp->b_resid);
|
1997-08-04 14:00:11 +04:00
|
|
|
printf(" dev 0x%x(u%d), cbp %p bn %d addr %p bcnt %ld\n",
|
1995-03-02 09:38:11 +03:00
|
|
|
cbp->cb_buf.b_dev, cbp->cb_comp, cbp,
|
|
|
|
cbp->cb_buf.b_blkno, cbp->cb_buf.b_data,
|
|
|
|
cbp->cb_buf.b_bcount);
|
1994-06-24 18:11:02 +04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
1995-03-02 09:38:11 +03:00
|
|
|
if (cbp->cb_buf.b_flags & B_ERROR) {
|
1998-11-13 03:26:19 +03:00
|
|
|
bp->b_flags |= B_ERROR;
|
|
|
|
bp->b_error = cbp->cb_buf.b_error ?
|
|
|
|
cbp->cb_buf.b_error : EIO;
|
1996-02-01 23:47:13 +03:00
|
|
|
|
1998-11-13 03:26:19 +03:00
|
|
|
printf("%s: error %d on component %d\n",
|
|
|
|
cs->sc_xname, bp->b_error, cbp->cb_comp);
|
1994-06-24 18:11:02 +04:00
|
|
|
}
|
1995-03-02 09:38:11 +03:00
|
|
|
count = cbp->cb_buf.b_bcount;
|
1998-07-31 05:23:56 +04:00
|
|
|
CCD_PUTBUF(cs, cbp);
|
1994-06-24 18:11:02 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If all done, "interrupt".
|
|
|
|
*/
|
1998-11-13 03:26:19 +03:00
|
|
|
bp->b_resid -= count;
|
|
|
|
if (bp->b_resid < 0)
|
|
|
|
panic("ccdiodone: count");
|
|
|
|
if (bp->b_resid == 0)
|
1999-01-21 03:35:15 +03:00
|
|
|
ccdintr(cs, bp);
|
1994-06-24 18:11:02 +04:00
|
|
|
splx(s);
|
|
|
|
}
|
|
|
|
|
1995-08-17 20:31:30 +04:00
|
|
|
/* ARGSUSED */
|
1995-07-04 11:15:28 +04:00
|
|
|
int
|
1995-08-17 20:31:30 +04:00
|
|
|
ccdread(dev, uio, flags)
|
1994-07-02 10:03:47 +04:00
|
|
|
dev_t dev;
|
|
|
|
struct uio *uio;
|
1995-08-17 20:31:30 +04:00
|
|
|
int flags;
|
1994-07-02 10:03:47 +04:00
|
|
|
{
|
1995-08-17 20:31:30 +04:00
|
|
|
int unit = ccdunit(dev);
|
|
|
|
struct ccd_softc *cs;
|
1994-07-02 10:03:47 +04:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (ccddebug & CCDB_FOLLOW)
|
1997-08-04 14:00:11 +04:00
|
|
|
printf("ccdread(0x%x, %p)\n", dev, uio);
|
1994-07-02 10:03:47 +04:00
|
|
|
#endif
|
1995-08-17 20:31:30 +04:00
|
|
|
if (unit >= numccd)
|
|
|
|
return (ENXIO);
|
|
|
|
cs = &ccd_softc[unit];
|
|
|
|
|
|
|
|
if ((cs->sc_flags & CCDF_INITED) == 0)
|
|
|
|
return (ENXIO);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* XXX: It's not clear that using minphys() is completely safe,
|
|
|
|
* in particular, for raw I/O. Underlying devices might have some
|
|
|
|
* non-obvious limits, because of the copy to user-space.
|
|
|
|
*/
|
1995-07-04 11:15:28 +04:00
|
|
|
return (physio(ccdstrategy, NULL, dev, B_READ, minphys, uio));
|
1994-07-02 10:03:47 +04:00
|
|
|
}
|
|
|
|
|
1995-08-17 20:31:30 +04:00
|
|
|
/* ARGSUSED */
|
1995-07-04 11:15:28 +04:00
|
|
|
int
|
1995-08-17 20:31:30 +04:00
|
|
|
ccdwrite(dev, uio, flags)
|
1994-07-02 10:03:47 +04:00
|
|
|
dev_t dev;
|
|
|
|
struct uio *uio;
|
1995-08-17 20:31:30 +04:00
|
|
|
int flags;
|
1994-07-02 10:03:47 +04:00
|
|
|
{
|
1995-08-17 20:31:30 +04:00
|
|
|
int unit = ccdunit(dev);
|
|
|
|
struct ccd_softc *cs;
|
1994-07-02 10:03:47 +04:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (ccddebug & CCDB_FOLLOW)
|
1997-08-04 14:00:11 +04:00
|
|
|
printf("ccdwrite(0x%x, %p)\n", dev, uio);
|
1994-07-02 10:03:47 +04:00
|
|
|
#endif
|
1995-08-17 20:31:30 +04:00
|
|
|
if (unit >= numccd)
|
|
|
|
return (ENXIO);
|
|
|
|
cs = &ccd_softc[unit];
|
|
|
|
|
|
|
|
if ((cs->sc_flags & CCDF_INITED) == 0)
|
|
|
|
return (ENXIO);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* XXX: It's not clear that using minphys() is completely safe,
|
|
|
|
* in particular, for raw I/O. Underlying devices might have some
|
|
|
|
* non-obvious limits, because of the copy to user-space.
|
|
|
|
*/
|
1995-07-04 11:15:28 +04:00
|
|
|
return (physio(ccdstrategy, NULL, dev, B_WRITE, minphys, uio));
|
1994-07-02 10:03:47 +04:00
|
|
|
}
|
|
|
|
|
1995-08-17 20:31:30 +04:00
|
|
|
int
|
|
|
|
ccdioctl(dev, cmd, data, flag, p)
|
1994-06-24 18:11:02 +04:00
|
|
|
dev_t dev;
|
1994-10-31 00:43:03 +03:00
|
|
|
u_long cmd;
|
1994-06-24 18:11:02 +04:00
|
|
|
caddr_t data;
|
|
|
|
int flag;
|
1995-08-17 20:31:30 +04:00
|
|
|
struct proc *p;
|
1994-06-24 18:11:02 +04:00
|
|
|
{
|
1995-08-17 20:31:30 +04:00
|
|
|
int unit = ccdunit(dev);
|
1999-01-12 03:21:47 +03:00
|
|
|
int i, j, lookedup = 0, error;
|
1997-03-13 01:31:37 +03:00
|
|
|
int part, pmask;
|
1995-08-17 20:31:30 +04:00
|
|
|
struct ccd_softc *cs;
|
|
|
|
struct ccd_ioctl *ccio = (struct ccd_ioctl *)data;
|
|
|
|
char **cpp;
|
|
|
|
struct vnode **vpp;
|
|
|
|
|
|
|
|
if (unit >= numccd)
|
|
|
|
return (ENXIO);
|
|
|
|
cs = &ccd_softc[unit];
|
|
|
|
|
1997-06-26 08:25:50 +04:00
|
|
|
/* Must be open for writes for these commands... */
|
1995-08-17 20:31:30 +04:00
|
|
|
switch (cmd) {
|
|
|
|
case CCDIOCSET:
|
1997-06-26 08:25:50 +04:00
|
|
|
case CCDIOCCLR:
|
|
|
|
case DIOCSDINFO:
|
|
|
|
case DIOCWDINFO:
|
|
|
|
case DIOCWLABEL:
|
1995-08-17 20:31:30 +04:00
|
|
|
if ((flag & FWRITE) == 0)
|
|
|
|
return (EBADF);
|
1997-06-26 08:25:50 +04:00
|
|
|
}
|
|
|
|
|
1999-01-12 03:21:47 +03:00
|
|
|
if ((error = lockmgr(&cs->sc_lock, LK_EXCLUSIVE, NULL)) != 0)
|
|
|
|
return (error);
|
|
|
|
|
1997-06-26 08:25:50 +04:00
|
|
|
/* Must be initialized for these... */
|
|
|
|
switch (cmd) {
|
|
|
|
case CCDIOCCLR:
|
1997-06-26 20:28:34 +04:00
|
|
|
case DIOCGDINFO:
|
|
|
|
case DIOCSDINFO:
|
|
|
|
case DIOCWDINFO:
|
|
|
|
case DIOCGPART:
|
1997-06-26 08:25:50 +04:00
|
|
|
case DIOCWLABEL:
|
1997-10-09 03:05:22 +04:00
|
|
|
case DIOCGDEFLABEL:
|
1999-01-12 03:21:47 +03:00
|
|
|
if ((cs->sc_flags & CCDF_INITED) == 0) {
|
|
|
|
error = ENXIO;
|
|
|
|
goto out;
|
|
|
|
}
|
1997-06-26 08:25:50 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
case CCDIOCSET:
|
1999-01-12 03:21:47 +03:00
|
|
|
if (cs->sc_flags & CCDF_INITED) {
|
|
|
|
error = EBUSY;
|
|
|
|
goto out;
|
|
|
|
}
|
1995-10-09 03:46:45 +03:00
|
|
|
|
1998-11-13 03:31:02 +03:00
|
|
|
/* Validate the flags. */
|
1999-01-12 03:21:47 +03:00
|
|
|
if ((ccio->ccio_flags & CCDF_USERMASK) != ccio->ccio_flags) {
|
|
|
|
error = EINVAL;
|
|
|
|
goto out;
|
|
|
|
}
|
1998-11-13 03:31:02 +03:00
|
|
|
|
1995-08-17 20:31:30 +04:00
|
|
|
/* Fill in some important bits. */
|
1999-01-12 03:21:47 +03:00
|
|
|
cs->sc_ileave = ccio->ccio_ileave;
|
|
|
|
cs->sc_nccdisks = ccio->ccio_ndisks;
|
|
|
|
cs->sc_flags = ccio->ccio_flags & CCDF_USERMASK;
|
1995-08-17 20:31:30 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Allocate space for and copy in the array of
|
|
|
|
* componet pathnames and device numbers.
|
|
|
|
*/
|
|
|
|
cpp = malloc(ccio->ccio_ndisks * sizeof(char *),
|
|
|
|
M_DEVBUF, M_WAITOK);
|
|
|
|
vpp = malloc(ccio->ccio_ndisks * sizeof(struct vnode *),
|
|
|
|
M_DEVBUF, M_WAITOK);
|
|
|
|
|
|
|
|
error = copyin((caddr_t)ccio->ccio_disks, (caddr_t)cpp,
|
|
|
|
ccio->ccio_ndisks * sizeof(char **));
|
|
|
|
if (error) {
|
|
|
|
free(vpp, M_DEVBUF);
|
|
|
|
free(cpp, M_DEVBUF);
|
1999-01-12 03:21:47 +03:00
|
|
|
goto out;
|
1995-08-17 20:31:30 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (ccddebug & CCDB_INIT)
|
|
|
|
for (i = 0; i < ccio->ccio_ndisks; ++i)
|
1996-10-13 05:37:04 +04:00
|
|
|
printf("ccdioctl: component %d: 0x%p\n",
|
1995-08-17 20:31:30 +04:00
|
|
|
i, cpp[i]);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
for (i = 0; i < ccio->ccio_ndisks; ++i) {
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (ccddebug & CCDB_INIT)
|
1996-10-13 05:37:04 +04:00
|
|
|
printf("ccdioctl: lookedup = %d\n", lookedup);
|
1995-08-17 20:31:30 +04:00
|
|
|
#endif
|
1996-03-07 18:00:07 +03:00
|
|
|
if ((error = ccdlookup(cpp[i], p, &vpp[i])) != 0) {
|
1995-08-17 20:31:30 +04:00
|
|
|
for (j = 0; j < lookedup; ++j)
|
1995-08-21 22:25:52 +04:00
|
|
|
(void)vn_close(vpp[j], FREAD|FWRITE,
|
1995-08-17 20:31:30 +04:00
|
|
|
p->p_ucred, p);
|
|
|
|
free(vpp, M_DEVBUF);
|
|
|
|
free(cpp, M_DEVBUF);
|
1999-01-12 03:21:47 +03:00
|
|
|
goto out;
|
1995-08-17 20:31:30 +04:00
|
|
|
}
|
|
|
|
++lookedup;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialize the ccd. Fills in the softc for us.
|
|
|
|
*/
|
1999-01-12 03:21:47 +03:00
|
|
|
if ((error = ccdinit(cs, cpp, vpp, p)) != 0) {
|
1995-08-17 20:31:30 +04:00
|
|
|
for (j = 0; j < lookedup; ++j)
|
1995-10-09 08:37:57 +03:00
|
|
|
(void)vn_close(vpp[j], FREAD|FWRITE,
|
1995-08-17 20:31:30 +04:00
|
|
|
p->p_ucred, p);
|
|
|
|
free(vpp, M_DEVBUF);
|
|
|
|
free(cpp, M_DEVBUF);
|
1999-01-12 03:21:47 +03:00
|
|
|
goto out;
|
1995-08-17 20:31:30 +04:00
|
|
|
}
|
|
|
|
|
1999-01-12 03:21:47 +03:00
|
|
|
/* We can free the temporary variables now. */
|
|
|
|
free(vpp, M_DEVBUF);
|
|
|
|
free(cpp, M_DEVBUF);
|
|
|
|
|
1995-08-17 20:31:30 +04:00
|
|
|
/*
|
|
|
|
* The ccd has been successfully initialized, so
|
1996-01-08 01:01:38 +03:00
|
|
|
* we can place it into the array. Don't try to
|
|
|
|
* read the disklabel until the disk has been attached,
|
|
|
|
* because space for the disklabel is allocated
|
|
|
|
* in disk_attach();
|
1995-08-17 20:31:30 +04:00
|
|
|
*/
|
|
|
|
ccio->ccio_unit = unit;
|
|
|
|
ccio->ccio_size = cs->sc_size;
|
1996-01-08 01:01:38 +03:00
|
|
|
|
|
|
|
/* Attach the disk. */
|
|
|
|
disk_attach(&cs->sc_dkdev);
|
|
|
|
|
1998-07-31 05:23:56 +04:00
|
|
|
/* Initialize the component buffer pool. */
|
|
|
|
pool_init(&cs->sc_cbufpool, sizeof(struct ccdbuf), 0,
|
|
|
|
0, 0, "ccdpl", 0, NULL, NULL, M_DEVBUF);
|
|
|
|
|
1996-01-08 01:01:38 +03:00
|
|
|
/* Try and read the disklabel. */
|
1995-08-17 20:31:30 +04:00
|
|
|
ccdgetdisklabel(dev);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CCDIOCCLR:
|
|
|
|
/*
|
|
|
|
* Don't unconfigure if any other partitions are open
|
|
|
|
* or if both the character and block flavors of this
|
|
|
|
* partition are open.
|
|
|
|
*/
|
|
|
|
part = DISKPART(dev);
|
|
|
|
pmask = (1 << part);
|
|
|
|
if ((cs->sc_dkdev.dk_openmask & ~pmask) ||
|
|
|
|
((cs->sc_dkdev.dk_bopenmask & pmask) &&
|
1995-10-09 03:46:45 +03:00
|
|
|
(cs->sc_dkdev.dk_copenmask & pmask))) {
|
1999-01-12 03:21:47 +03:00
|
|
|
error = EBUSY;
|
|
|
|
goto out;
|
1995-10-09 03:46:45 +03:00
|
|
|
}
|
1995-08-17 20:31:30 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Free ccd_softc information and clear entry.
|
|
|
|
*/
|
1995-12-08 22:13:26 +03:00
|
|
|
|
|
|
|
/* Close the components and free their pathnames. */
|
1995-08-17 20:31:30 +04:00
|
|
|
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?
|
|
|
|
*/
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (ccddebug & CCDB_VNODE)
|
|
|
|
vprint("CCDIOCCLR: vnode info",
|
|
|
|
cs->sc_cinfo[i].ci_vp);
|
|
|
|
#endif
|
|
|
|
(void)vn_close(cs->sc_cinfo[i].ci_vp, FREAD|FWRITE,
|
|
|
|
p->p_ucred, p);
|
|
|
|
free(cs->sc_cinfo[i].ci_path, M_DEVBUF);
|
|
|
|
}
|
1995-12-08 22:13:26 +03:00
|
|
|
|
|
|
|
/* Free interleave index. */
|
|
|
|
for (i = 0; cs->sc_itable[i].ii_ndisk; ++i)
|
|
|
|
free(cs->sc_itable[i].ii_index, M_DEVBUF);
|
|
|
|
|
|
|
|
/* Free component info and interleave table. */
|
1995-08-17 20:31:30 +04:00
|
|
|
free(cs->sc_cinfo, M_DEVBUF);
|
|
|
|
free(cs->sc_itable, M_DEVBUF);
|
1995-11-06 22:58:01 +03:00
|
|
|
cs->sc_flags &= ~CCDF_INITED;
|
1995-08-17 20:31:30 +04:00
|
|
|
|
1998-07-31 05:23:56 +04:00
|
|
|
/* Free the component buffer pool. */
|
|
|
|
pool_destroy(&cs->sc_cbufpool);
|
|
|
|
|
1996-01-08 01:01:38 +03:00
|
|
|
/* Detatch the disk. */
|
1996-02-11 01:27:22 +03:00
|
|
|
disk_detach(&cs->sc_dkdev);
|
1995-08-17 20:31:30 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case DIOCGDINFO:
|
1996-01-08 01:01:38 +03:00
|
|
|
*(struct disklabel *)data = *(cs->sc_dkdev.dk_label);
|
1995-08-17 20:31:30 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case DIOCGPART:
|
1996-01-08 01:01:38 +03:00
|
|
|
((struct partinfo *)data)->disklab = cs->sc_dkdev.dk_label;
|
1995-08-17 20:31:30 +04:00
|
|
|
((struct partinfo *)data)->part =
|
1996-01-08 01:01:38 +03:00
|
|
|
&cs->sc_dkdev.dk_label->d_partitions[DISKPART(dev)];
|
1995-08-17 20:31:30 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case DIOCWDINFO:
|
|
|
|
case DIOCSDINFO:
|
|
|
|
cs->sc_flags |= CCDF_LABELLING;
|
|
|
|
|
1996-01-08 01:01:38 +03:00
|
|
|
error = setdisklabel(cs->sc_dkdev.dk_label,
|
|
|
|
(struct disklabel *)data, 0, cs->sc_dkdev.dk_cpulabel);
|
1995-08-17 20:31:30 +04:00
|
|
|
if (error == 0) {
|
|
|
|
if (cmd == DIOCWDINFO)
|
|
|
|
error = writedisklabel(CCDLABELDEV(dev),
|
1996-01-08 01:01:38 +03:00
|
|
|
ccdstrategy, cs->sc_dkdev.dk_label,
|
|
|
|
cs->sc_dkdev.dk_cpulabel);
|
1995-08-17 20:31:30 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
cs->sc_flags &= ~CCDF_LABELLING;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DIOCWLABEL:
|
|
|
|
if (*(int *)data != 0)
|
|
|
|
cs->sc_flags |= CCDF_WLABEL;
|
|
|
|
else
|
|
|
|
cs->sc_flags &= ~CCDF_WLABEL;
|
|
|
|
break;
|
|
|
|
|
1997-10-09 03:05:22 +04:00
|
|
|
case DIOCGDEFLABEL:
|
|
|
|
ccdgetdefaultlabel(cs, (struct disklabel *)data);
|
|
|
|
break;
|
|
|
|
|
1995-08-17 20:31:30 +04:00
|
|
|
default:
|
1999-01-12 03:21:47 +03:00
|
|
|
error = ENOTTY;
|
1995-08-17 20:31:30 +04:00
|
|
|
}
|
|
|
|
|
1999-01-12 03:21:47 +03:00
|
|
|
out:
|
|
|
|
(void) lockmgr(&cs->sc_lock, LK_RELEASE, NULL);
|
|
|
|
return (error);
|
1994-06-24 18:11:02 +04:00
|
|
|
}
|
|
|
|
|
1995-08-17 20:31:30 +04:00
|
|
|
int
|
1994-06-24 18:11:02 +04:00
|
|
|
ccdsize(dev)
|
|
|
|
dev_t dev;
|
|
|
|
{
|
1995-08-17 20:31:30 +04:00
|
|
|
struct ccd_softc *cs;
|
1997-06-24 03:59:53 +04:00
|
|
|
struct disklabel *lp;
|
|
|
|
int part, unit, omask, size;
|
|
|
|
|
|
|
|
unit = ccdunit(dev);
|
|
|
|
if (unit >= numccd)
|
|
|
|
return (-1);
|
|
|
|
cs = &ccd_softc[unit];
|
1995-08-17 20:31:30 +04:00
|
|
|
|
1997-06-24 03:59:53 +04:00
|
|
|
if ((cs->sc_flags & CCDF_INITED) == 0)
|
1995-08-17 20:31:30 +04:00
|
|
|
return (-1);
|
|
|
|
|
|
|
|
part = DISKPART(dev);
|
1997-06-24 03:59:53 +04:00
|
|
|
omask = cs->sc_dkdev.dk_openmask & (1 << part);
|
|
|
|
lp = cs->sc_dkdev.dk_label;
|
1994-06-24 18:11:02 +04:00
|
|
|
|
1997-06-24 03:59:53 +04:00
|
|
|
if (omask == 0 && ccdopen(dev, 0, S_IFBLK, curproc))
|
1995-08-17 20:31:30 +04:00
|
|
|
return (-1);
|
|
|
|
|
1997-06-24 03:59:53 +04:00
|
|
|
if (lp->d_partitions[part].p_fstype != FS_SWAP)
|
1995-08-17 20:31:30 +04:00
|
|
|
size = -1;
|
|
|
|
else
|
1997-06-24 03:59:53 +04:00
|
|
|
size = lp->d_partitions[part].p_size *
|
|
|
|
(lp->d_secsize / DEV_BSIZE);
|
1995-08-17 20:31:30 +04:00
|
|
|
|
1997-06-24 03:59:53 +04:00
|
|
|
if (omask == 0 && ccdclose(dev, 0, S_IFBLK, curproc))
|
1995-08-17 20:31:30 +04:00
|
|
|
return (-1);
|
|
|
|
|
|
|
|
return (size);
|
1994-06-24 18:11:02 +04:00
|
|
|
}
|
|
|
|
|
1995-06-26 09:34:44 +04:00
|
|
|
int
|
|
|
|
ccddump(dev, blkno, va, size)
|
|
|
|
dev_t dev;
|
|
|
|
daddr_t blkno;
|
|
|
|
caddr_t va;
|
|
|
|
size_t size;
|
1994-06-24 18:11:02 +04:00
|
|
|
{
|
1995-06-26 09:34:44 +04:00
|
|
|
|
|
|
|
/* Not implemented. */
|
|
|
|
return ENXIO;
|
1994-06-24 18:11:02 +04:00
|
|
|
}
|
1995-08-17 20:31:30 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 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
|
|
|
|
ccdlookup(path, p, vpp)
|
|
|
|
char *path;
|
|
|
|
struct proc *p;
|
|
|
|
struct vnode **vpp; /* result */
|
|
|
|
{
|
|
|
|
struct nameidata nd;
|
|
|
|
struct vnode *vp;
|
|
|
|
struct vattr va;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, path, p);
|
1996-03-07 18:00:07 +03:00
|
|
|
if ((error = vn_open(&nd, FREAD|FWRITE, 0)) != 0) {
|
1995-08-17 20:31:30 +04:00
|
|
|
#ifdef DEBUG
|
1996-03-07 18:00:07 +03:00
|
|
|
if (ccddebug & (CCDB_FOLLOW|CCDB_INIT))
|
1996-10-13 05:37:04 +04:00
|
|
|
printf("ccdlookup: vn_open error = %d\n", error);
|
1995-08-17 20:31:30 +04:00
|
|
|
#endif
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
vp = nd.ni_vp;
|
|
|
|
|
|
|
|
if (vp->v_usecount > 1) {
|
1998-03-01 10:15:39 +03:00
|
|
|
VOP_UNLOCK(vp, 0);
|
1995-08-17 20:31:30 +04:00
|
|
|
(void)vn_close(vp, FREAD|FWRITE, p->p_ucred, p);
|
|
|
|
return (EBUSY);
|
|
|
|
}
|
|
|
|
|
1996-03-07 18:00:07 +03:00
|
|
|
if ((error = VOP_GETATTR(vp, &va, p->p_ucred, p)) != 0) {
|
1995-08-17 20:31:30 +04:00
|
|
|
#ifdef DEBUG
|
1996-03-07 18:00:07 +03:00
|
|
|
if (ccddebug & (CCDB_FOLLOW|CCDB_INIT))
|
1996-10-13 05:37:04 +04:00
|
|
|
printf("ccdlookup: getattr error = %d\n", error);
|
1995-08-17 20:31:30 +04:00
|
|
|
#endif
|
1998-03-01 10:15:39 +03:00
|
|
|
VOP_UNLOCK(vp, 0);
|
1995-08-17 20:31:30 +04:00
|
|
|
(void)vn_close(vp, FREAD|FWRITE, p->p_ucred, p);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* XXX: eventually we should handle VREG, too. */
|
|
|
|
if (va.va_type != VBLK) {
|
1998-03-01 10:15:39 +03:00
|
|
|
VOP_UNLOCK(vp, 0);
|
1995-08-17 20:31:30 +04:00
|
|
|
(void)vn_close(vp, FREAD|FWRITE, p->p_ucred, p);
|
|
|
|
return (ENOTBLK);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (ccddebug & CCDB_VNODE)
|
|
|
|
vprint("ccdlookup: vnode info", vp);
|
|
|
|
#endif
|
|
|
|
|
1998-03-01 10:15:39 +03:00
|
|
|
VOP_UNLOCK(vp, 0);
|
1995-08-17 20:31:30 +04:00
|
|
|
*vpp = vp;
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
1997-10-09 03:05:22 +04:00
|
|
|
ccdgetdefaultlabel(cs, lp)
|
|
|
|
struct ccd_softc *cs;
|
|
|
|
struct disklabel *lp;
|
1995-08-17 20:31:30 +04:00
|
|
|
{
|
|
|
|
struct ccdgeom *ccg = &cs->sc_geom;
|
|
|
|
|
|
|
|
bzero(lp, sizeof(*lp));
|
|
|
|
|
|
|
|
lp->d_secperunit = cs->sc_size;
|
|
|
|
lp->d_secsize = ccg->ccg_secsize;
|
|
|
|
lp->d_nsectors = ccg->ccg_nsectors;
|
|
|
|
lp->d_ntracks = ccg->ccg_ntracks;
|
|
|
|
lp->d_ncylinders = ccg->ccg_ncylinders;
|
1995-10-13 00:28:32 +03:00
|
|
|
lp->d_secpercyl = lp->d_ntracks * lp->d_nsectors;
|
1995-08-17 20:31:30 +04:00
|
|
|
|
|
|
|
strncpy(lp->d_typename, "ccd", sizeof(lp->d_typename));
|
|
|
|
lp->d_type = DTYPE_CCD;
|
|
|
|
strncpy(lp->d_packname, "fictitious", sizeof(lp->d_packname));
|
|
|
|
lp->d_rpm = 3600;
|
|
|
|
lp->d_interleave = 1;
|
|
|
|
lp->d_flags = 0;
|
|
|
|
|
|
|
|
lp->d_partitions[RAW_PART].p_offset = 0;
|
|
|
|
lp->d_partitions[RAW_PART].p_size = cs->sc_size;
|
|
|
|
lp->d_partitions[RAW_PART].p_fstype = FS_UNUSED;
|
|
|
|
lp->d_npartitions = RAW_PART + 1;
|
|
|
|
|
|
|
|
lp->d_magic = DISKMAGIC;
|
|
|
|
lp->d_magic2 = DISKMAGIC;
|
1996-01-08 01:01:38 +03:00
|
|
|
lp->d_checksum = dkcksum(cs->sc_dkdev.dk_label);
|
1997-10-09 03:05:22 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Read the disklabel from the ccd. If one is not present, fake one
|
|
|
|
* up.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
ccdgetdisklabel(dev)
|
|
|
|
dev_t dev;
|
|
|
|
{
|
|
|
|
int unit = ccdunit(dev);
|
|
|
|
struct ccd_softc *cs = &ccd_softc[unit];
|
|
|
|
char *errstring;
|
|
|
|
struct disklabel *lp = cs->sc_dkdev.dk_label;
|
|
|
|
struct cpu_disklabel *clp = cs->sc_dkdev.dk_cpulabel;
|
|
|
|
|
|
|
|
bzero(clp, sizeof(*clp));
|
|
|
|
|
|
|
|
ccdgetdefaultlabel(cs, lp);
|
1995-08-17 20:31:30 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Call the generic disklabel extraction routine.
|
|
|
|
*/
|
1996-03-07 18:00:07 +03:00
|
|
|
errstring = readdisklabel(CCDLABELDEV(dev), ccdstrategy,
|
|
|
|
cs->sc_dkdev.dk_label, cs->sc_dkdev.dk_cpulabel);
|
|
|
|
if (errstring)
|
1995-08-17 20:31:30 +04:00
|
|
|
ccdmakedisklabel(cs);
|
1998-02-22 09:50:08 +03:00
|
|
|
else {
|
|
|
|
int i;
|
|
|
|
struct partition *pp;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Sanity check whether the found disklabel is valid.
|
|
|
|
*
|
|
|
|
* This is necessary since total size of ccd may vary
|
|
|
|
* when an interleave is changed even though exactly
|
|
|
|
* same componets are used, and old disklabel may used
|
|
|
|
* if that is found.
|
|
|
|
*/
|
|
|
|
if (lp->d_secperunit != cs->sc_size)
|
|
|
|
printf("WARNING: %s: "
|
|
|
|
"total sector size in disklabel (%d) != "
|
1999-02-12 03:46:11 +03:00
|
|
|
"the size of ccd (%lu)\n", cs->sc_xname,
|
|
|
|
lp->d_secperunit, (u_long)cs->sc_size);
|
1998-02-22 09:50:08 +03:00
|
|
|
for (i = 0; i < lp->d_npartitions; i++) {
|
|
|
|
pp = &lp->d_partitions[i];
|
|
|
|
if (pp->p_offset + pp->p_size > cs->sc_size)
|
1998-02-22 10:14:30 +03:00
|
|
|
printf("WARNING: %s: end of partition `%c' "
|
1999-02-12 03:46:11 +03:00
|
|
|
"exceeds the size of ccd (%lu)\n",
|
|
|
|
cs->sc_xname, 'a' + i, (u_long)cs->sc_size);
|
1998-02-22 09:50:08 +03:00
|
|
|
}
|
|
|
|
}
|
1995-08-17 20:31:30 +04:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
/* It's actually extremely common to have unlabeled ccds. */
|
|
|
|
if (ccddebug & CCDB_LABEL)
|
|
|
|
if (errstring != NULL)
|
1996-10-13 05:37:04 +04:00
|
|
|
printf("%s: %s\n", cs->sc_xname, errstring);
|
1995-08-17 20:31:30 +04:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Take care of things one might want to take care of in the event
|
|
|
|
* that a disklabel isn't present.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
ccdmakedisklabel(cs)
|
|
|
|
struct ccd_softc *cs;
|
|
|
|
{
|
1996-01-08 01:01:38 +03:00
|
|
|
struct disklabel *lp = cs->sc_dkdev.dk_label;
|
1995-08-17 20:31:30 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* For historical reasons, if there's no disklabel present
|
|
|
|
* the raw partition must be marked FS_BSDFFS.
|
|
|
|
*/
|
|
|
|
lp->d_partitions[RAW_PART].p_fstype = FS_BSDFFS;
|
|
|
|
|
|
|
|
strncpy(lp->d_packname, "default label", sizeof(lp->d_packname));
|
1997-10-09 03:05:22 +04:00
|
|
|
|
|
|
|
lp->d_checksum = dkcksum(lp);
|
1995-08-17 20:31:30 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
static void
|
|
|
|
printiinfo(ii)
|
|
|
|
struct ccdiinfo *ii;
|
|
|
|
{
|
|
|
|
register int ix, i;
|
|
|
|
|
|
|
|
for (ix = 0; ii->ii_ndisk; ix++, ii++) {
|
1996-10-13 05:37:04 +04:00
|
|
|
printf(" itab[%d]: #dk %d sblk %d soff %d",
|
1996-10-11 02:25:05 +04:00
|
|
|
ix, ii->ii_ndisk, ii->ii_startblk, ii->ii_startoff);
|
1995-08-17 20:31:30 +04:00
|
|
|
for (i = 0; i < ii->ii_ndisk; i++)
|
1996-10-13 05:37:04 +04:00
|
|
|
printf(" %d", ii->ii_index[i]);
|
|
|
|
printf("\n");
|
1995-08-17 20:31:30 +04:00
|
|
|
}
|
|
|
|
}
|
1994-06-24 18:11:02 +04:00
|
|
|
#endif
|