diff options
Diffstat (limited to 'sys/dev/ccd')
-rw-r--r-- | sys/dev/ccd/ccd.c | 1014 |
1 files changed, 675 insertions, 339 deletions
diff --git a/sys/dev/ccd/ccd.c b/sys/dev/ccd/ccd.c index c8d33a4..b70f8c2 100644 --- a/sys/dev/ccd/ccd.c +++ b/sys/dev/ccd/ccd.c @@ -1,3 +1,5 @@ +/* $FreeBSD$ */ + /* $NetBSD: ccd.c,v 1.22 1995/12/08 19:13:26 thorpej Exp $ */ /* @@ -85,77 +87,122 @@ * Moffett Field, CA 94035 */ +#include "ccd.h" +#if NCCD > 0 + #include <sys/param.h> #include <sys/systm.h> +#include <sys/kernel.h> +#include <sys/module.h> #include <sys/proc.h> -#include <sys/errno.h> -#include <sys/dkstat.h> #include <sys/buf.h> #include <sys/malloc.h> #include <sys/namei.h> #include <sys/conf.h> #include <sys/stat.h> -#include <sys/ioctl.h> +#include <sys/sysctl.h> #include <sys/disklabel.h> -#include <sys/device.h> -#include <sys/disk.h> -#include <sys/syslog.h> +#include <ufs/ffs/fs.h> +#include <sys/devicestat.h> #include <sys/fcntl.h> #include <sys/vnode.h> -#include <dev/ccdvar.h> +#include <sys/ccdvar.h> + +#include <vm/vm_zone.h> #if defined(CCDDEBUG) && !defined(DEBUG) #define DEBUG #endif #ifdef DEBUG -int ccddebug = 0x00; #define CCDB_FOLLOW 0x01 #define CCDB_INIT 0x02 #define CCDB_IO 0x04 #define CCDB_LABEL 0x08 #define CCDB_VNODE 0x10 +static int ccddebug = CCDB_FOLLOW | CCDB_INIT | CCDB_IO | CCDB_LABEL | + CCDB_VNODE; +SYSCTL_INT(_debug, OID_AUTO, ccddebug, CTLFLAG_RW, &ccddebug, 0, ""); +#undef DEBUG #endif -#define ccdunit(x) DISKUNIT(x) +#define ccdunit(x) dkunit(x) +#define ccdpart(x) dkpart(x) + +/* + 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. + + */ struct ccdbuf { struct buf cb_buf; /* new I/O buf */ struct buf *cb_obp; /* ptr. to original I/O buf */ + struct ccdbuf *cb_freenext; /* free list link */ int cb_unit; /* target unit */ int cb_comp; /* target component */ + int cb_pflags; /* mirror/parity status flag */ + struct ccdbuf *cb_mirror; /* mirror counterpart */ }; -#define getccdbuf() \ - ((struct ccdbuf *)malloc(sizeof(struct ccdbuf), M_DEVBUF, M_WAITOK)) -#define putccdbuf(cbp) \ - free((caddr_t)(cbp), M_DEVBUF) +/* bits in cb_pflags */ +#define CCDPF_MIRROR_DONE 1 /* if set, mirror counterpart is done */ #define CCDLABELDEV(dev) \ - (MAKEDISKDEV(major((dev)), ccdunit((dev)), RAW_PART)) - -/* {b,c}devsw[] function prototypes */ -dev_type_open(ccdopen); -dev_type_close(ccdclose); -dev_type_strategy(ccdstrategy); -dev_type_ioctl(ccdioctl); -dev_type_read(ccdread); -dev_type_write(ccdwrite); + (makedev(major((dev)), dkmakeminor(ccdunit((dev)), 0, RAW_PART))) + +static d_open_t ccdopen; +static d_close_t ccdclose; +static d_strategy_t ccdstrategy; +static d_ioctl_t ccdioctl; +static d_dump_t ccddump; +static d_psize_t ccdsize; + +#define NCCDFREEHIWAT 16 + +#define CDEV_MAJOR 74 +#define BDEV_MAJOR 21 + +static struct cdevsw ccd_cdevsw = { + /* open */ ccdopen, + /* close */ ccdclose, + /* read */ physread, + /* write */ physwrite, + /* ioctl */ ccdioctl, + /* poll */ nopoll, + /* mmap */ nommap, + /* strategy */ ccdstrategy, + /* name */ "ccd", + /* maj */ CDEV_MAJOR, + /* dump */ ccddump, + /* psize */ ccdsize, + /* flags */ D_DISK, + /* bmaj */ BDEV_MAJOR +}; -/* called by main() at boot time */ -void ccdattach __P((int)); +/* called during module initialization */ +static void ccdattach __P((void)); +static int ccd_modevent __P((module_t, int, void *)); /* called by biodone() at interrupt time */ -void ccdiodone __P((struct ccdbuf *cbp)); +static void ccdiodone __P((struct ccdbuf *cbp)); static void ccdstart __P((struct ccd_softc *, struct buf *)); static void ccdinterleave __P((struct ccd_softc *, int)); static void ccdintr __P((struct ccd_softc *, struct buf *)); static int ccdinit __P((struct ccddevice *, char **, struct proc *)); static int ccdlookup __P((char *, struct proc *p, struct vnode **)); -static struct ccdbuf *ccdbuffer __P((struct ccd_softc *, struct buf *, - daddr_t, caddr_t, long)); +static void ccdbuffer __P((struct ccdbuf **ret, struct ccd_softc *, + struct buf *, daddr_t, caddr_t, long)); static void ccdgetdisklabel __P((dev_t)); static void ccdmakedisklabel __P((struct ccd_softc *)); static int ccdlock __P((struct ccd_softc *)); @@ -168,24 +215,98 @@ static void printiinfo __P((struct ccdiinfo *)); /* Non-private for the benefit of libkvm. */ struct ccd_softc *ccd_softc; struct ccddevice *ccddevs; -int numccd = 0; +struct ccdbuf *ccdfreebufs; +static int numccdfreebufs; +static int numccd = 0; /* - * Called by main() during pseudo-device attachment. All we need - * to do is allocate enough space for devices to be configured later. + * getccdbuf() - Allocate and zero a ccd buffer. + * + * This routine is called at splbio(). */ + +static __inline +struct ccdbuf * +getccdbuf(struct ccdbuf *cpy) +{ + struct ccdbuf *cbp; + + /* + * Allocate from freelist or malloc as necessary + */ + if ((cbp = ccdfreebufs) != NULL) { + ccdfreebufs = cbp->cb_freenext; + --numccdfreebufs; + } else { + cbp = malloc(sizeof(struct ccdbuf), M_DEVBUF, M_WAITOK); + } + + /* + * Used by mirroring code + */ + if (cpy) + bcopy(cpy, cbp, sizeof(struct ccdbuf)); + else + bzero(cbp, sizeof(struct ccdbuf)); + + /* + * independant struct buf initialization + */ + LIST_INIT(&cbp->cb_buf.b_dep); + BUF_LOCKINIT(&cbp->cb_buf); + BUF_LOCK(&cbp->cb_buf, LK_EXCLUSIVE); + BUF_KERNPROC(&cbp->cb_buf); + + return(cbp); +} + +/* + * putccdbuf() - Free a ccd buffer. + * + * This routine is called at splbio(). + */ + +static __inline void -ccdattach(num) - int num; +putccdbuf(struct ccdbuf *cbp) { - int i; + BUF_UNLOCK(&cbp->cb_buf); + BUF_LOCKFREE(&cbp->cb_buf); + + if (numccdfreebufs < NCCDFREEHIWAT) { + cbp->cb_freenext = ccdfreebufs; + ccdfreebufs = cbp; + ++numccdfreebufs; + } else { + free((caddr_t)cbp, M_DEVBUF); + } +} + - if (num <= 0) { -#ifdef DIAGNOSTIC - panic("ccdattach: count <= 0"); +/* + * 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. + */ +#if !defined(CCD_OFFSET) +#define CCD_OFFSET 16 #endif - return; - } + +/* + * Called by main() during pseudo-device attachment. All we need + * to do is allocate enough space for devices to be configured later, and + * add devsw entries. + */ +static void +ccdattach() +{ + int i; + int num = NCCD; + + if (num > 1) + printf("ccd0-%d: Concatenated disk drivers\n", num-1); + else + printf("ccd0: Concatenated disk driver\n"); ccd_softc = (struct ccd_softc *)malloc(num * sizeof(struct ccd_softc), M_DEVBUF, M_NOWAIT); @@ -203,38 +324,61 @@ ccdattach(num) bzero(ccd_softc, num * sizeof(struct ccd_softc)); bzero(ccddevs, num * sizeof(struct ccddevice)); + cdevsw_add(&ccd_cdevsw); /* XXX: is this necessary? */ for (i = 0; i < numccd; ++i) ccddevs[i].ccd_dk = -1; } static int +ccd_modevent(mod, type, data) + module_t mod; + int type; + void *data; +{ + int error = 0; + + switch (type) { + case MOD_LOAD: + ccdattach(); + break; + + case MOD_UNLOAD: + printf("ccd0: Unload not supported!\n"); + error = EOPNOTSUPP; + break; + + default: /* MOD_SHUTDOWN etc */ + break; + } + return (error); +} + +DEV_MODULE(ccd, ccd_modevent, NULL); + +static int ccdinit(ccd, cpaths, p) struct ccddevice *ccd; char **cpaths; struct proc *p; { - register struct ccd_softc *cs = &ccd_softc[ccd->ccd_unit]; - register struct ccdcinfo *ci; - register size_t size; - register int ix; + struct ccd_softc *cs = &ccd_softc[ccd->ccd_unit]; + struct ccdcinfo *ci = NULL; /* XXX */ + size_t size; + int ix; struct vnode *vp; - struct vattr va; size_t minsize; int maxsecsize; struct partinfo dpart; struct ccdgeom *ccg = &cs->sc_geom; char tmppath[MAXPATHLEN]; - int error; + int error = 0; #ifdef DEBUG if (ccddebug & (CCDB_FOLLOW|CCDB_INIT)) printf("ccdinit: unit %d\n", ccd->ccd_unit); #endif -#ifdef WORKING_DISK_STATISTICS /* XXX !! */ - cs->sc_dk = ccd->ccd_dk; -#endif cs->sc_size = 0; cs->sc_ileave = ccd->ccd_interleave; cs->sc_nccdisks = ccd->ccd_ndev; @@ -258,71 +402,51 @@ ccdinit(ccd, cpaths, p) * Copy in the pathname of the component. */ bzero(tmppath, sizeof(tmppath)); /* sanity */ - if (error = copyinstr(cpaths[ix], tmppath, - MAXPATHLEN, &ci->ci_pathlen)) { + if ((error = copyinstr(cpaths[ix], tmppath, + MAXPATHLEN, &ci->ci_pathlen)) != 0) { #ifdef DEBUG if (ccddebug & (CCDB_FOLLOW|CCDB_INIT)) printf("ccd%d: can't copy path, error = %d\n", ccd->ccd_unit, error); #endif - free(cs->sc_cinfo, M_DEVBUF); - return (error); + goto fail; } ci->ci_path = malloc(ci->ci_pathlen, M_DEVBUF, M_WAITOK); bcopy(tmppath, ci->ci_path, ci->ci_pathlen); - /* - * XXX: Cache the component's dev_t. - */ - if (error = VOP_GETATTR(vp, &va, p->p_ucred, p)) { -#ifdef DEBUG - if (ccddebug & (CCDB_FOLLOW|CCDB_INIT)) - printf("ccd%d: %s: getattr failed %s = %d\n", - ccd->ccd_unit, ci->ci_path, - "error", error); -#endif - free(ci->ci_path, M_DEVBUF); - free(cs->sc_cinfo, M_DEVBUF); - return (error); - } - ci->ci_dev = va.va_rdev; + ci->ci_dev = vn_todev(vp); /* * Get partition information for the component. */ - if (error = VOP_IOCTL(vp, DIOCGPART, (caddr_t)&dpart, - FREAD, p->p_ucred, p)) { + if ((error = VOP_IOCTL(vp, DIOCGPART, (caddr_t)&dpart, + FREAD, p->p_ucred, p)) != 0) { #ifdef DEBUG if (ccddebug & (CCDB_FOLLOW|CCDB_INIT)) printf("ccd%d: %s: ioctl failed, error = %d\n", ccd->ccd_unit, ci->ci_path, error); #endif - free(ci->ci_path, M_DEVBUF); - free(cs->sc_cinfo, M_DEVBUF); - return (error); + goto fail; } if (dpart.part->p_fstype == FS_BSDFFS) { maxsecsize = ((dpart.disklab->d_secsize > maxsecsize) ? dpart.disklab->d_secsize : maxsecsize); - size = dpart.part->p_size; + size = dpart.part->p_size - CCD_OFFSET; } else { #ifdef DEBUG if (ccddebug & (CCDB_FOLLOW|CCDB_INIT)) printf("ccd%d: %s: incorrect partition type\n", ccd->ccd_unit, ci->ci_path); #endif - free(ci->ci_path, M_DEVBUF); - free(cs->sc_cinfo, M_DEVBUF); - return (EFTYPE); + error = EFTYPE; + goto fail; } /* * Calculate the size, truncating to an interleave * boundary if necessary. */ - if (size < 0) - size = 0; if (cs->sc_ileave > 1) size -= size % cs->sc_ileave; @@ -333,9 +457,8 @@ ccdinit(ccd, cpaths, p) printf("ccd%d: %s: size == 0\n", ccd->ccd_unit, ci->ci_path); #endif - free(ci->ci_path, M_DEVBUF); - free(cs->sc_cinfo, M_DEVBUF); - return (ENODEV); + error = ENODEV; + goto fail; } if (minsize == 0 || size < minsize) @@ -355,20 +478,52 @@ ccdinit(ccd, cpaths, p) printf("ccd%d: interleave must be at least %d\n", ccd->ccd_unit, (maxsecsize / DEV_BSIZE)); #endif - free(ci->ci_path, M_DEVBUF); - free(cs->sc_cinfo, M_DEVBUF); - return (EINVAL); + error = EINVAL; + goto fail; } /* * If uniform interleave is desired set all sizes to that of - * the smallest component. + * 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 + * specified. One disk is lost when CCDF_PARITY is specified. */ if (ccd->ccd_flags & CCDF_UNIFORM) { for (ci = cs->sc_cinfo; - ci < &cs->sc_cinfo[cs->sc_nccdisks]; ci++) + ci < &cs->sc_cinfo[cs->sc_nccdisks]; ci++) { ci->ci_size = minsize; - cs->sc_size = cs->sc_nccdisks * minsize; + } + if (ccd->ccd_flags & CCDF_MIRROR) { + /* + * Check to see if an even number of components + * have been specified. The interleave must also + * be non-zero in order for us to be able to + * guarentee the topology. + */ + if (cs->sc_nccdisks % 2) { + printf("ccd%d: mirroring requires an even number of disks\n", ccd->ccd_unit ); + error = EINVAL; + goto fail; + } + if (cs->sc_ileave == 0) { + printf("ccd%d: an interleave must be specified when mirroring\n", ccd->ccd_unit); + error = EINVAL; + goto fail; + } + cs->sc_size = (cs->sc_nccdisks/2) * minsize; + } else if (ccd->ccd_flags & CCDF_PARITY) { + cs->sc_size = (cs->sc_nccdisks-1) * minsize; + } else { + if (cs->sc_ileave == 0) { + printf("ccd%d: an interleave must be specified when using parity\n", ccd->ccd_unit); + error = EINVAL; + goto fail; + } + cs->sc_size = cs->sc_nccdisks * minsize; + } } /* @@ -380,39 +535,53 @@ ccdinit(ccd, cpaths, p) * Create pseudo-geometry based on 1MB cylinders. It's * pretty close. */ - ccg->ccg_secsize = DEV_BSIZE; + ccg->ccg_secsize = maxsecsize; ccg->ccg_ntracks = 1; - ccg->ccg_nsectors = 1024 * (1024 / ccg->ccg_secsize); + ccg->ccg_nsectors = 1024 * 1024 / ccg->ccg_secsize; ccg->ccg_ncylinders = cs->sc_size / ccg->ccg_nsectors; -#ifdef WORKING_DISK_STATISTICS /* XXX !! */ - if (ccd->ccd_dk >= 0) - dk_wpms[ccd->ccd_dk] = 32 * (60 * DEV_BSIZE / 2); /* XXX */ -#endif + /* + * Add an devstat entry for this device. + */ + devstat_add_entry(&cs->device_stats, "ccd", ccd->ccd_unit, + ccg->ccg_secsize, DEVSTAT_ALL_SUPPORTED, + DEVSTAT_TYPE_STORARRAY |DEVSTAT_TYPE_IF_OTHER, + DEVSTAT_PRIORITY_ARRAY); cs->sc_flags |= CCDF_INITED; cs->sc_cflags = ccd->ccd_flags; /* So we can find out later... */ cs->sc_unit = ccd->ccd_unit; return (0); +fail: + while (ci > cs->sc_cinfo) { + ci--; + free(ci->ci_path, M_DEVBUF); + } + free(cs->sc_cinfo, M_DEVBUF); + return (error); } static void ccdinterleave(cs, unit) - register struct ccd_softc *cs; + struct ccd_softc *cs; int unit; { - register struct ccdcinfo *ci, *smallci; - register struct ccdiinfo *ii; - register daddr_t bn, lbn; - register int ix; + struct ccdcinfo *ci, *smallci; + struct ccdiinfo *ii; + daddr_t bn, lbn; + int ix; u_long size; #ifdef DEBUG if (ccddebug & CCDB_INIT) printf("ccdinterleave(%x): ileave %d\n", cs, cs->sc_ileave); #endif + /* - * Allocate an interleave table. + * Allocate an interleave table. The worst case occurs when each + * of N disks is of a different size, resulting in N interleave + * tables. + * * Chances are this is too big, but we don't care. */ size = (cs->sc_nccdisks + 1) * sizeof(struct ccdiinfo); @@ -422,6 +591,8 @@ ccdinterleave(cs, unit) /* * Trivial case: no interleave (actually interleave of disk size). * Each table entry represents a single component in its entirety. + * + * An interleave of 0 may not be used with a mirror or parity setup. */ if (cs->sc_ileave == 0) { bn = 0; @@ -451,7 +622,10 @@ ccdinterleave(cs, unit) size = 0; bn = lbn = 0; for (ii = cs->sc_itable; ; ii++) { - /* Allocate space for ii_index. */ + /* + * Allocate space for ii_index. We might allocate more then + * we use. + */ ii->ii_index = malloc((sizeof(int) * cs->sc_nccdisks), M_DEVBUF, M_WAITOK); @@ -459,12 +633,14 @@ ccdinterleave(cs, unit) * Locate the smallest of the remaining components */ smallci = NULL; - for (ci = cs->sc_cinfo; - ci < &cs->sc_cinfo[cs->sc_nccdisks]; ci++) + 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)) + ci->ci_size < smallci->ci_size)) { smallci = ci; + } + } /* * Nobody left, all done @@ -475,9 +651,15 @@ ccdinterleave(cs, unit) } /* - * Record starting logical block and component offset + * Record starting logical block using an sc_ileave blocksize. */ ii->ii_startblk = bn / cs->sc_ileave; + + /* + * Record starting comopnent block using an sc_ileave + * blocksize. This value is relative to the beginning of + * a component disk. + */ ii->ii_startoff = lbn; /* @@ -485,10 +667,12 @@ ccdinterleave(cs, unit) * 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) + 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; @@ -501,7 +685,7 @@ ccdinterleave(cs, unit) } /* ARGSUSED */ -int +static int ccdopen(dev, flags, fmt, p) dev_t dev; int flags, fmt; @@ -520,12 +704,12 @@ ccdopen(dev, flags, fmt, p) return (ENXIO); cs = &ccd_softc[unit]; - if (error = ccdlock(cs)) + if ((error = ccdlock(cs)) != 0) return (error); - lp = &cs->sc_dkdev.dk_label; + lp = &cs->sc_label; - part = DISKPART(dev); + part = ccdpart(dev); pmask = (1 << part); /* @@ -533,11 +717,11 @@ ccdopen(dev, flags, fmt, p) * 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)) + if ((cs->sc_flags & CCDF_INITED) && (cs->sc_openmask == 0)) ccdgetdisklabel(dev); /* Check that the partition exists. */ - if (part != RAW_PART && ((part > lp->d_npartitions) || + if (part != RAW_PART && ((part >= lp->d_npartitions) || (lp->d_partitions[part].p_fstype == FS_UNUSED))) { error = ENXIO; goto done; @@ -546,15 +730,15 @@ ccdopen(dev, flags, fmt, p) /* Prevent our unit from being unconfigured while open. */ switch (fmt) { case S_IFCHR: - cs->sc_dkdev.dk_copenmask |= pmask; + cs->sc_copenmask |= pmask; break; case S_IFBLK: - cs->sc_dkdev.dk_bopenmask |= pmask; + cs->sc_bopenmask |= pmask; break; } - cs->sc_dkdev.dk_openmask = - cs->sc_dkdev.dk_copenmask | cs->sc_dkdev.dk_bopenmask; + cs->sc_openmask = + cs->sc_copenmask | cs->sc_bopenmask; done: ccdunlock(cs); @@ -562,7 +746,7 @@ ccdopen(dev, flags, fmt, p) } /* ARGSUSED */ -int +static int ccdclose(dev, flags, fmt, p) dev_t dev; int flags, fmt; @@ -581,36 +765,35 @@ ccdclose(dev, flags, fmt, p) return (ENXIO); cs = &ccd_softc[unit]; - if (error = ccdlock(cs)) + if ((error = ccdlock(cs)) != 0) return (error); - part = DISKPART(dev); + part = ccdpart(dev); /* ...that much closer to allowing unconfiguration... */ switch (fmt) { case S_IFCHR: - cs->sc_dkdev.dk_copenmask &= ~(1 << part); + cs->sc_copenmask &= ~(1 << part); break; case S_IFBLK: - cs->sc_dkdev.dk_bopenmask &= ~(1 << part); + cs->sc_bopenmask &= ~(1 << part); break; } - cs->sc_dkdev.dk_openmask = - cs->sc_dkdev.dk_copenmask | cs->sc_dkdev.dk_bopenmask; + cs->sc_openmask = + cs->sc_copenmask | cs->sc_bopenmask; ccdunlock(cs); return (0); } -void +static void ccdstrategy(bp) - register struct buf *bp; + struct buf *bp; { - register int unit = ccdunit(bp->b_dev); - register struct ccd_softc *cs = &ccd_softc[unit]; - register daddr_t bn; - register int sz, s; + int unit = ccdunit(bp->b_dev); + struct ccd_softc *cs = &ccd_softc[unit]; + int s; int wlabel; struct disklabel *lp; @@ -628,16 +811,45 @@ ccdstrategy(bp) if (bp->b_bcount == 0) goto done; - lp = &cs->sc_dkdev.dk_label; + lp = &cs->sc_label; /* * Do bounds checking and adjust transfer. If there's an * error, the bounds check will flag that for us. */ wlabel = cs->sc_flags & (CCDF_WLABEL|CCDF_LABELLING); - if (DISKPART(bp->b_dev) != RAW_PART) + if (ccdpart(bp->b_dev) != RAW_PART) { if (bounds_check_with_label(bp, lp, wlabel) <= 0) goto done; + } else { + int pbn; /* in sc_secsize chunks */ + long sz; /* in sc_secsize chunks */ + + pbn = bp->b_blkno / (cs->sc_geom.ccg_secsize / DEV_BSIZE); + sz = howmany(bp->b_bcount, cs->sc_geom.ccg_secsize); + + /* + * If out of bounds return an error. If at the EOF point, + * simply read or write less. + */ + + if (pbn < 0 || pbn >= cs->sc_size) { + bp->b_resid = bp->b_bcount; + if (pbn != cs->sc_size) { + bp->b_error = EINVAL; + bp->b_flags |= B_ERROR | B_INVAL; + } + goto done; + } + + /* + * If the request crosses EOF, truncate the request. + */ + if (pbn + sz > cs->sc_size) { + bp->b_bcount = (cs->sc_size - pbn) * + cs->sc_geom.ccg_secsize; + } + } bp->b_resid = bp->b_bcount; @@ -654,11 +866,12 @@ done: static void ccdstart(cs, bp) - register struct ccd_softc *cs; - register struct buf *bp; + struct ccd_softc *cs; + struct buf *bp; { - register long bcount, rcount; - struct ccdbuf *cbp; + long bcount, rcount; + struct ccdbuf *cbp[4]; + /* XXX! : 2 reads and 2 writes for RAID 4/5 */ caddr_t addr; daddr_t bn; struct partition *pp; @@ -668,24 +881,15 @@ ccdstart(cs, bp) printf("ccdstart(%x, %x)\n", cs, bp); #endif -#ifdef WORKING_DISK_STATISTICS /* XXX !! */ - /* - * Instrumentation (not very meaningful) - */ - cs->sc_nactive++; - if (cs->sc_dk >= 0) { - dk_busy |= 1 << cs->sc_dk; - dk_xfer[cs->sc_dk]++; - dk_wds[cs->sc_dk] += bp->b_bcount >> 6; - } -#endif + /* Record the transaction start */ + devstat_start_transaction(&cs->device_stats); /* * Translate the partition-relative block number to an absolute. */ bn = bp->b_blkno; - if (DISKPART(bp->b_dev) != RAW_PART) { - pp = &cs->sc_dkdev.dk_label.d_partitions[DISKPART(bp->b_dev)]; + if (ccdpart(bp->b_dev) != RAW_PART) { + pp = &cs->sc_label.d_partitions[ccdpart(bp->b_dev)]; bn += pp->p_offset; } @@ -694,11 +898,47 @@ ccdstart(cs, bp) */ addr = bp->b_data; for (bcount = bp->b_bcount; bcount > 0; bcount -= rcount) { - cbp = ccdbuffer(cs, bp, bn, addr, bcount); - rcount = cbp->cb_buf.b_bcount; - if ((cbp->cb_buf.b_flags & B_READ) == 0) - cbp->cb_buf.b_vp->v_numoutput++; - VOP_STRATEGY(&cbp->cb_buf); + ccdbuffer(cbp, cs, bp, bn, addr, bcount); + rcount = cbp[0]->cb_buf.b_bcount; + + 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. + */ + if ((cbp[0]->cb_buf.b_flags & B_READ) == 0) { + cbp[0]->cb_buf.b_vp->v_numoutput++; + cbp[1]->cb_buf.b_vp->v_numoutput++; + VOP_STRATEGY(cbp[0]->cb_buf.b_vp, + &cbp[0]->cb_buf); + VOP_STRATEGY(cbp[1]->cb_buf.b_vp, + &cbp[1]->cb_buf); + } 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); + VOP_STRATEGY(cbp[pick]->cb_buf.b_vp, + &cbp[pick]->cb_buf); + } + } else { + /* + * Not mirroring + */ + if ((cbp[0]->cb_buf.b_flags & B_READ) == 0) + cbp[0]->cb_buf.b_vp->v_numoutput++; + VOP_STRATEGY(cbp[0]->cb_buf.b_vp, &cbp[0]->cb_buf); + } bn += btodb(rcount); addr += rcount; } @@ -707,17 +947,19 @@ ccdstart(cs, bp) /* * Build a component buffer header. */ -static struct ccdbuf * -ccdbuffer(cs, bp, bn, addr, bcount) - register struct ccd_softc *cs; +static void +ccdbuffer(cb, cs, bp, bn, addr, bcount) + struct ccdbuf **cb; + struct ccd_softc *cs; struct buf *bp; daddr_t bn; caddr_t addr; long bcount; { - register struct ccdcinfo *ci; - register struct ccdbuf *cbp; - register daddr_t cbn, cboff; + struct ccdcinfo *ci, *ci2 = NULL; /* XXX */ + struct ccdbuf *cbp; + daddr_t cbn, cboff; + off_t cbc; #ifdef DEBUG if (ccddebug & CCDB_IO) @@ -730,59 +972,121 @@ ccdbuffer(cs, bp, bn, addr, bcount) cbn = bn; cboff = 0; - /* - * Serially concatenated - */ if (cs->sc_ileave == 0) { - register daddr_t sblk; + /* + * Serially concatenated and neither a mirror nor a parity + * config. This is a special case. + */ + daddr_t sblk; sblk = 0; for (ci = cs->sc_cinfo; cbn >= sblk + ci->ci_size; ci++) sblk += ci->ci_size; cbn -= sblk; - } - /* - * Interleaved - */ - else { - register struct ccdiinfo *ii; + } else { + struct ccdiinfo *ii; int ccdisk, off; - cboff = cbn % cs->sc_ileave; - cbn /= cs->sc_ileave; - for (ii = cs->sc_itable; ii->ii_ndisk; ii++) + /* + * 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++) { if (ii->ii_startblk > cbn) break; + } ii--; + + /* + * off is the logical superblock relative to the beginning + * of this interleave block. + */ off = cbn - ii->ii_startblk; + + /* + * 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. + */ if (ii->ii_ndisk == 1) { + /* + * When we have just one disk, it can't be a mirror + * or a parity config. + */ ccdisk = ii->ii_index[0]; cbn = ii->ii_startoff + off; } else { - ccdisk = ii->ii_index[off % ii->ii_ndisk]; - cbn = ii->ii_startoff + off / ii->ii_ndisk; + if (cs->sc_cflags & CCDF_MIRROR) { + /* + * 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 if (cs->sc_cflags & CCDF_PARITY) { + /* + * XXX not implemented yet + */ + int ndisk2 = ii->ii_ndisk - 1; + ccdisk = ii->ii_index[off % ndisk2]; + cbn = ii->ii_startoff + off / ndisk2; + if (cbn % ii->ii_ndisk <= ccdisk) + ccdisk++; + } else { + ccdisk = ii->ii_index[off % ii->ii_ndisk]; + cbn = ii->ii_startoff + off / ii->ii_ndisk; + } } - cbn *= cs->sc_ileave; + ci = &cs->sc_cinfo[ccdisk]; + + /* + * 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; } /* * Fill in the component buf structure. */ - cbp = getccdbuf(); + cbp = getccdbuf(NULL); cbp->cb_buf.b_flags = bp->b_flags | B_CALL; - cbp->cb_buf.b_iodone = (void (*)())ccdiodone; - cbp->cb_buf.b_proc = bp->b_proc; + cbp->cb_buf.b_iodone = (void (*)(struct buf *))ccdiodone; cbp->cb_buf.b_dev = ci->ci_dev; /* XXX */ - cbp->cb_buf.b_blkno = cbn + cboff; + cbp->cb_buf.b_blkno = cbn + cboff + CCD_OFFSET; + cbp->cb_buf.b_offset = dbtob(cbn + cboff + CCD_OFFSET); cbp->cb_buf.b_data = addr; cbp->cb_buf.b_vp = ci->ci_vp; if (cs->sc_ileave == 0) - cbp->cb_buf.b_bcount = dbtob(ci->ci_size - cbn); + cbc = dbtob((off_t)(ci->ci_size - cbn)); else - cbp->cb_buf.b_bcount = dbtob(cs->sc_ileave - cboff); - if (cbp->cb_buf.b_bcount > bcount) - cbp->cb_buf.b_bcount = bcount; + cbc = dbtob((off_t)(cs->sc_ileave - cboff)); + cbp->cb_buf.b_bcount = (cbc < bcount) ? cbc : bcount; + cbp->cb_buf.b_bufsize = cbp->cb_buf.b_bcount; /* * context for ccdiodone @@ -797,15 +1101,32 @@ ccdbuffer(cs, bp, bn, addr, bcount) ci->ci_dev, ci-cs->sc_cinfo, cbp, cbp->cb_buf.b_blkno, cbp->cb_buf.b_data, cbp->cb_buf.b_bcount); #endif - return (cbp); + cb[0] = cbp; + + /* + * 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 */ + cbp = getccdbuf(cb[0]); + cbp->cb_buf.b_dev = ci2->ci_dev; + cbp->cb_buf.b_vp = ci2->ci_vp; + cbp->cb_comp = ci2 - cs->sc_cinfo; + cb[1] = cbp; + /* 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; + } } static void ccdintr(cs, bp) - register struct ccd_softc *cs; - register struct buf *bp; + struct ccd_softc *cs; + struct buf *bp; { - #ifdef DEBUG if (ccddebug & CCDB_FOLLOW) printf("ccdintr(%x, %x)\n", cs, bp); @@ -813,18 +1134,9 @@ ccdintr(cs, bp) /* * Request is done for better or worse, wakeup the top half. */ -#ifdef WORKING_DISK_STATISTICS /* XXX !! */ - --cs->sc_nactive; -#ifdef DIAGNOSTIC - if (cs->sc_nactive < 0) - panic("ccdintr: ccd%d: sc_nactive < 0", cs->sc_unit); -#endif - - if (cs->sc_nactive == 0 && cs->sc_dk >= 0) - dk_busy &= ~(1 << cs->sc_dk); -#endif if (bp->b_flags & B_ERROR) bp->b_resid = bp->b_bcount; + devstat_end_transaction_buf(&cs->device_stats, bp); biodone(bp); } @@ -833,12 +1145,12 @@ ccdintr(cs, bp) * Mark the component as done and if all components are done, * take a ccd interrupt. */ -void +static void ccdiodone(cbp) struct ccdbuf *cbp; { - register struct buf *bp = cbp->cb_obp; - register int unit = cbp->cb_unit; + struct buf *bp = cbp->cb_obp; + int unit = cbp->cb_unit; int count, s; s = splbio(); @@ -854,16 +1166,97 @@ ccdiodone(cbp) cbp->cb_buf.b_bcount); } #endif + /* + * 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. + */ if (cbp->cb_buf.b_flags & B_ERROR) { - bp->b_flags |= B_ERROR; - bp->b_error = cbp->cb_buf.b_error ? cbp->cb_buf.b_error : EIO; -#ifdef DEBUG - printf("ccd%d: error %d on component %d\n", - unit, bp->b_error, cbp->cb_comp); -#endif + const char *msg = ""; + + if ((ccd_softc[unit].sc_cflags & CCDF_MIRROR) && + (cbp->cb_buf.b_flags & B_READ) && + (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. + */ + struct ccd_softc *cs = &ccd_softc[unit]; + + msg = ", trying other disk"; + cs->sc_pick = 1 - cs->sc_pick; + cs->sc_blk[cs->sc_pick] = bp->b_blkno; + } else { + bp->b_flags |= B_ERROR; + bp->b_error = cbp->cb_buf.b_error ? + cbp->cb_buf.b_error : EIO; + } + printf("ccd%d: error %d on component %d block %d (ccd block %d)%s\n", + unit, bp->b_error, cbp->cb_comp, + (int)cbp->cb_buf.b_blkno, bp->b_blkno, msg); + } + + /* + * 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. + */ + + if (ccd_softc[unit].sc_cflags & CCDF_MIRROR) { + if ((cbp->cb_buf.b_flags & B_READ) == 0) { + /* + * 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; + putccdbuf(cbp); + splx(s); + 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) { + if (cbp->cb_buf.b_flags & B_ERROR) { + cbp->cb_mirror->cb_pflags |= + CCDPF_MIRROR_DONE; + VOP_STRATEGY( + cbp->cb_mirror->cb_buf.b_vp, + &cbp->cb_mirror->cb_buf + ); + putccdbuf(cbp); + splx(s); + return; + } else { + putccdbuf(cbp->cb_mirror); + /* fall through */ + } + } + } } - count = cbp->cb_buf.b_bcount; + + /* + * use b_bufsize to determine how big the original request was rather + * then b_bcount, because b_bcount may have been truncated for EOF. + * + * 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. + */ + count = cbp->cb_buf.b_bufsize; putccdbuf(cbp); /* @@ -877,65 +1270,7 @@ ccdiodone(cbp) splx(s); } -/* ARGSUSED */ -int -ccdread(dev, uio, flags) - dev_t dev; - struct uio *uio; - int flags; -{ - int unit = ccdunit(dev); - struct ccd_softc *cs; - -#ifdef DEBUG - if (ccddebug & CCDB_FOLLOW) - printf("ccdread(%x, %x)\n", dev, uio); -#endif - 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. - */ - return (physio(ccdstrategy, NULL, dev, B_READ, minphys, uio)); -} - -/* ARGSUSED */ -int -ccdwrite(dev, uio, flags) - dev_t dev; - struct uio *uio; - int flags; -{ - int unit = ccdunit(dev); - struct ccd_softc *cs; - -#ifdef DEBUG - if (ccddebug & CCDB_FOLLOW) - printf("ccdwrite(%x, %x)\n", dev, uio); -#endif - 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. - */ - return (physio(ccdstrategy, NULL, dev, B_WRITE, minphys, uio)); -} - -int +static int ccdioctl(dev, cmd, data, flag, p) dev_t dev; u_long cmd; @@ -951,9 +1286,6 @@ ccdioctl(dev, cmd, data, flag, p) struct ccddevice ccd; char **cpp; struct vnode **vpp; -#ifdef WORKING_DISK_STATISTICS /* XXX !! */ - extern int dkn; -#endif if (unit >= numccd) return (ENXIO); @@ -969,12 +1301,29 @@ ccdioctl(dev, cmd, data, flag, p) if ((flag & FWRITE) == 0) return (EBADF); - if (error = ccdlock(cs)) + if ((error = ccdlock(cs)) != 0) return (error); /* Fill in some important bits. */ ccd.ccd_unit = unit; ccd.ccd_interleave = ccio->ccio_ileave; + if (ccd.ccd_interleave == 0 && + ((ccio->ccio_flags & CCDF_MIRROR) || + (ccio->ccio_flags & CCDF_PARITY))) { + printf("ccd%d: disabling mirror/parity, interleave is 0\n", unit); + ccio->ccio_flags &= ~(CCDF_MIRROR | CCDF_PARITY); + } + if ((ccio->ccio_flags & CCDF_MIRROR) && + (ccio->ccio_flags & CCDF_PARITY)) { + printf("ccd%d: can't specify both mirror and parity, using mirror\n", unit); + ccio->ccio_flags &= ~CCDF_PARITY; + } + if ((ccio->ccio_flags & (CCDF_MIRROR | CCDF_PARITY)) && + !(ccio->ccio_flags & CCDF_UNIFORM)) { + printf("ccd%d: mirror/parity forces uniform flag\n", + unit); + ccio->ccio_flags |= CCDF_UNIFORM; + } ccd.ccd_flags = ccio->ccio_flags & CCDF_USERMASK; /* @@ -1007,7 +1356,7 @@ ccdioctl(dev, cmd, data, flag, p) if (ccddebug & CCDB_INIT) printf("ccdioctl: lookedup = %d\n", lookedup); #endif - if (error = ccdlookup(cpp[i], p, &vpp[i])) { + if ((error = ccdlookup(cpp[i], p, &vpp[i])) != 0) { for (j = 0; j < lookedup; ++j) (void)vn_close(vpp[j], FREAD|FWRITE, p->p_ucred, p); @@ -1022,27 +1371,10 @@ ccdioctl(dev, cmd, data, flag, p) ccd.ccd_vpp = vpp; ccd.ccd_ndev = ccio->ccio_ndisks; -#ifdef WORKING_DISK_STATISTICS /* XXX !! */ - /* - * Assign disk index first so that init routine - * can use it (saves having the driver drag around - * the ccddevice pointer just to set up the dk_* - * info in the open routine). - */ - if (dkn < DK_NDRIVE) - ccd.ccd_dk = dkn++; - else - ccd.ccd_dk = -1; -#endif - /* * Initialize the ccd. Fills in the softc for us. */ - if (error = ccdinit(&ccd, cpp, p)) { -#ifdef WORKING_DISK_STATISTICS /* XXX !! */ - if (ccd.ccd_dk >= 0) - --dkn; -#endif + if ((error = ccdinit(&ccd, cpp, p)) != 0) { for (j = 0; j < lookedup; ++j) (void)vn_close(vpp[j], FREAD|FWRITE, p->p_ucred, p); @@ -1073,7 +1405,7 @@ ccdioctl(dev, cmd, data, flag, p) if ((flag & FWRITE) == 0) return (EBADF); - if (error = ccdlock(cs)) + if ((error = ccdlock(cs)) != 0) return (error); /* @@ -1081,11 +1413,11 @@ ccdioctl(dev, cmd, data, flag, p) * or if both the character and block flavors of this * partition are open. */ - part = DISKPART(dev); + part = ccdpart(dev); pmask = (1 << part); - if ((cs->sc_dkdev.dk_openmask & ~pmask) || - ((cs->sc_dkdev.dk_bopenmask & pmask) && - (cs->sc_dkdev.dk_copenmask & pmask))) { + if ((cs->sc_openmask & ~pmask) || + ((cs->sc_bopenmask & pmask) && + (cs->sc_copenmask & pmask))) { ccdunlock(cs); return (EBUSY); } @@ -1128,6 +1460,11 @@ ccdioctl(dev, cmd, data, flag, p) ccd.ccd_dk = -1; bcopy(&ccd, &ccddevs[unit], sizeof(ccd)); + /* + * And remove the devstat entry. + */ + devstat_remove_entry(&cs->device_stats); + /* This must be atomic. */ s = splhigh(); ccdunlock(cs); @@ -1140,16 +1477,16 @@ ccdioctl(dev, cmd, data, flag, p) if ((cs->sc_flags & CCDF_INITED) == 0) return (ENXIO); - *(struct disklabel *)data = cs->sc_dkdev.dk_label; + *(struct disklabel *)data = cs->sc_label; break; case DIOCGPART: if ((cs->sc_flags & CCDF_INITED) == 0) return (ENXIO); - ((struct partinfo *)data)->disklab = &cs->sc_dkdev.dk_label; + ((struct partinfo *)data)->disklab = &cs->sc_label; ((struct partinfo *)data)->part = - &cs->sc_dkdev.dk_label.d_partitions[DISKPART(dev)]; + &cs->sc_label.d_partitions[ccdpart(dev)]; break; case DIOCWDINFO: @@ -1160,18 +1497,17 @@ ccdioctl(dev, cmd, data, flag, p) if ((flag & FWRITE) == 0) return (EBADF); - if (error = ccdlock(cs)) + if ((error = ccdlock(cs)) != 0) return (error); cs->sc_flags |= CCDF_LABELLING; - error = setdisklabel(&cs->sc_dkdev.dk_label, - (struct disklabel *)data, 0, &cs->sc_dkdev.dk_cpulabel); + error = setdisklabel(&cs->sc_label, + (struct disklabel *)data, 0); if (error == 0) { if (cmd == DIOCWDINFO) error = writedisklabel(CCDLABELDEV(dev), - ccdstrategy, &cs->sc_dkdev.dk_label, - &cs->sc_dkdev.dk_cpulabel); + &cs->sc_label); } cs->sc_flags &= ~CCDF_LABELLING; @@ -1201,7 +1537,7 @@ ccdioctl(dev, cmd, data, flag, p) return (0); } -int +static int ccdsize(dev) dev_t dev; { @@ -1212,15 +1548,15 @@ ccdsize(dev) return (-1); cs = &ccd_softc[ccdunit(dev)]; - part = DISKPART(dev); + part = ccdpart(dev); if ((cs->sc_flags & CCDF_INITED) == 0) return (-1); - if (cs->sc_dkdev.dk_label.d_partitions[part].p_fstype != FS_SWAP) + if (cs->sc_label.d_partitions[part].p_fstype != FS_SWAP) size = -1; else - size = cs->sc_dkdev.dk_label.d_partitions[part].p_size; + size = cs->sc_label.d_partitions[part].p_size; if (ccdclose(dev, 0, S_IFBLK, curproc)) return (-1); @@ -1228,12 +1564,9 @@ ccdsize(dev) return (size); } -int -ccddump(dev, blkno, va, size) +static int +ccddump(dev) dev_t dev; - daddr_t blkno; - caddr_t va; - size_t size; { /* Not implemented. */ @@ -1257,7 +1590,7 @@ ccdlookup(path, p, vpp) int error; NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, path, p); - if (error = vn_open(&nd, FREAD|FWRITE, 0)) { + if ((error = vn_open(&nd, FREAD|FWRITE, 0)) != 0) { #ifdef DEBUG if (ccddebug & CCDB_FOLLOW|CCDB_INIT) printf("ccdlookup: vn_open error = %d\n", error); @@ -1267,26 +1600,13 @@ ccdlookup(path, p, vpp) vp = nd.ni_vp; if (vp->v_usecount > 1) { - VOP_UNLOCK(vp); - (void)vn_close(vp, FREAD|FWRITE, p->p_ucred, p); - return (EBUSY); + error = EBUSY; + goto bad; } - if (error = VOP_GETATTR(vp, &va, p->p_ucred, p)) { -#ifdef DEBUG - if (ccddebug & CCDB_FOLLOW|CCDB_INIT) - printf("ccdlookup: getattr error = %d\n", error); -#endif - VOP_UNLOCK(vp); - (void)vn_close(vp, FREAD|FWRITE, p->p_ucred, p); - return (error); - } - - /* XXX: eventually we should handle VREG, too. */ - if (va.va_type != VBLK) { - VOP_UNLOCK(vp); - (void)vn_close(vp, FREAD|FWRITE, p->p_ucred, p); - return (ENOTBLK); + if (!vn_isdisk(vp)) { + error = ENOTBLK; + goto bad; } #ifdef DEBUG @@ -1294,9 +1614,16 @@ ccdlookup(path, p, vpp) vprint("ccdlookup: vnode info", vp); #endif - VOP_UNLOCK(vp); + VOP_UNLOCK(vp, 0, p); + NDFREE(&nd, NDF_ONLY_PNBUF); *vpp = vp; return (0); +bad: + VOP_UNLOCK(vp, 0, p); + NDFREE(&nd, NDF_ONLY_PNBUF); + /* vn_close does vrele() for vp */ + (void)vn_close(vp, FREAD|FWRITE, p->p_ucred, p); + return (error); } /* @@ -1310,12 +1637,10 @@ ccdgetdisklabel(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; + struct disklabel *lp = &cs->sc_label; struct ccdgeom *ccg = &cs->sc_geom; bzero(lp, sizeof(*lp)); - bzero(clp, sizeof(*clp)); lp->d_secperunit = cs->sc_size; lp->d_secsize = ccg->ccg_secsize; @@ -1336,15 +1661,18 @@ ccdgetdisklabel(dev) lp->d_partitions[RAW_PART].p_fstype = FS_UNUSED; lp->d_npartitions = RAW_PART + 1; + lp->d_bbsize = BBSIZE; /* XXX */ + lp->d_sbsize = SBSIZE; /* XXX */ + lp->d_magic = DISKMAGIC; lp->d_magic2 = DISKMAGIC; - lp->d_checksum = dkcksum(&cs->sc_dkdev.dk_label); + lp->d_checksum = dkcksum(&cs->sc_label); /* * Call the generic disklabel extraction routine. */ - if (errstring = readdisklabel(CCDLABELDEV(dev), ccdstrategy, - &cs->sc_dkdev.dk_label, &cs->sc_dkdev.dk_cpulabel)) + errstring = readdisklabel(CCDLABELDEV(dev), &cs->sc_label); + if (errstring != NULL) ccdmakedisklabel(cs); #ifdef DEBUG @@ -1363,7 +1691,7 @@ static void ccdmakedisklabel(cs) struct ccd_softc *cs; { - struct disklabel *lp = &cs->sc_dkdev.dk_label; + struct disklabel *lp = &cs->sc_label; /* * For historical reasons, if there's no disklabel present @@ -1415,7 +1743,7 @@ static void printiinfo(ii) struct ccdiinfo *ii; { - register int ix, i; + int ix, i; for (ix = 0; ii->ii_ndisk; ix++, ii++) { printf(" itab[%d]: #dk %d sblk %d soff %d", @@ -1426,3 +1754,11 @@ printiinfo(ii) } } #endif + +#endif /* NCCD > 0 */ + +/* Local Variables: */ +/* c-argdecl-indent: 8 */ +/* c-continued-statement-offset: 8 */ +/* c-indent-level: 8 */ +/* End: */ |