From 5b39541e48a9cf8889c0a67a4621ef28a9d4102d Mon Sep 17 00:00:00 2001 From: thorpej Date: Sun, 7 Jan 1996 22:01:38 +0000 Subject: [PATCH] New generic disk framework. Highlights: - New metrics handling. Metrics are now kept in the new `struct disk'. Busy time is now stored as a timeval, and transfer count in bytes. - Storage for disklabels is now dynamically allocated, so that the size of the disk structure is not machine-dependent. - Several new functions for attaching and detaching disks, and handling metrics calculation. Old-style instrumentation is still supported in drivers that did it before. However, old-style instrumentation is being deprecated, and will go away once the userland utilities are updated for the new framework. For usage and architectural details, see the forthcoming disk(9) manual page. --- sys/arch/alpha/alpha/disksubr.c | 4 +- sys/arch/amiga/amiga/disksubr.c | 4 +- sys/arch/amiga/amiga/swapgeneric.c | 19 ++- sys/arch/amiga/dev/fd.c | 47 ++++--- sys/arch/amiga/dev/idesc.c | 6 +- sys/arch/amiga/dev/sbic.c | 6 +- sys/arch/amiga/dev/sci.c | 6 +- sys/arch/amiga/dev/siop.c | 8 +- sys/arch/atari/atari/swapgeneric.c | 23 ++-- sys/arch/atari/dev/fd.c | 26 +++- sys/arch/atari/dev/ramd.c | 29 +++- sys/arch/hp300/dev/rd.c | 83 +++++++---- sys/arch/hp300/dev/rd_compat.c | 3 +- sys/arch/hp300/dev/rdvar.h | 12 +- sys/arch/hp300/dev/sd.c | 65 ++++++--- sys/arch/hp300/dev/sd_compat.c | 3 +- sys/arch/hp300/dev/sdvar.h | 12 +- sys/arch/i386/isa/fd.c | 17 ++- sys/arch/mac68k/mac68k/autoconf.c | 25 +++- sys/arch/pc532/dev/rd.c | 24 +++- sys/arch/pmax/dev/rz.c | 83 +++++++---- sys/arch/pmax/pmax/disksubr.c | 4 +- sys/arch/sparc/dev/fd.c | 78 ++++++----- sys/arch/sparc/dev/xd.c | 80 ++++++----- sys/arch/sparc/dev/xdvar.h | 4 +- sys/arch/sparc/dev/xy.c | 79 ++++++----- sys/arch/sparc/dev/xyvar.h | 4 +- sys/arch/sparc/include/sun_disklabel.h | 4 +- sys/arch/sparc/sparc/disksubr.c | 30 ++-- sys/arch/sun3/dev/xd.c | 77 ++++++----- sys/arch/sun3/dev/xdvar.h | 4 +- sys/arch/sun3/dev/xy.c | 78 ++++++----- sys/arch/sun3/dev/xyvar.h | 4 +- sys/dev/ata/wd.c | 101 +++++++------- sys/dev/ccd.c | 141 +++++++------------ sys/dev/ccdvar.h | 8 +- sys/dev/isa/mcd.c | 42 ++++-- sys/dev/isa/wd.c | 101 +++++++------- sys/dev/md.c | 18 ++- sys/dev/ramdisk.c | 18 ++- sys/dev/scsipi/cd.c | 60 +++++--- sys/dev/scsipi/sd.c | 83 +++++++---- sys/dev/vnd.c | 21 ++- sys/kern/init_main.c | 4 +- sys/kern/subr_disk.c | 184 ++++++++++++++++++++++++- sys/scsi/cd.c | 60 +++++--- sys/scsi/sd.c | 83 +++++++---- sys/sys/disk.h | 77 ++++++++--- 48 files changed, 1288 insertions(+), 664 deletions(-) diff --git a/sys/arch/alpha/alpha/disksubr.c b/sys/arch/alpha/alpha/disksubr.c index fcf9b0a05f1b..cec12b153df3 100644 --- a/sys/arch/alpha/alpha/disksubr.c +++ b/sys/arch/alpha/alpha/disksubr.c @@ -1,4 +1,4 @@ -/* $NetBSD: disksubr.c,v 1.3 1995/04/22 12:43:22 cgd Exp $ */ +/* $NetBSD: disksubr.c,v 1.4 1996/01/07 22:01:38 thorpej Exp $ */ /* * Copyright (c) 1994, 1995 Carnegie-Mellon University. @@ -45,7 +45,7 @@ extern struct device *bootdv; /* was this the boot device ? */ int dk_establish(dk, dev) - struct dkdevice *dk; + struct disk *dk; struct device *dev; { #ifdef NOTDEF diff --git a/sys/arch/amiga/amiga/disksubr.c b/sys/arch/amiga/amiga/disksubr.c index d1d3dabfded7..157132dcef40 100644 --- a/sys/arch/amiga/amiga/disksubr.c +++ b/sys/arch/amiga/amiga/disksubr.c @@ -1,4 +1,4 @@ -/* $NetBSD: disksubr.c,v 1.20 1995/09/29 13:51:33 chopps Exp $ */ +/* $NetBSD: disksubr.c,v 1.21 1996/01/07 22:01:44 thorpej Exp $ */ /* * Copyright (c) 1994 Christian E. Hopps @@ -80,7 +80,7 @@ struct rdbmap *getrdbmap __P((dev_t, void (*)(), struct disklabel *, /* XXX unknown function but needed for /sys/scsi to link */ int dk_establish(dk, dev) - struct dkdevice *dk; + struct disk *dk; struct device *dev; { return(-1); diff --git a/sys/arch/amiga/amiga/swapgeneric.c b/sys/arch/amiga/amiga/swapgeneric.c index 22197693d937..3cb570e0f75c 100644 --- a/sys/arch/amiga/amiga/swapgeneric.c +++ b/sys/arch/amiga/amiga/swapgeneric.c @@ -1,4 +1,4 @@ -/* $NetBSD: swapgeneric.c,v 1.19 1995/04/19 13:02:57 chopps Exp $ */ +/* $NetBSD: swapgeneric.c,v 1.20 1996/01/07 22:01:46 thorpej Exp $ */ /* * Copyright (c) 1982, 1986 Regents of the University of California. @@ -133,7 +133,8 @@ getgenconf(bp) setconf() { - struct dkdevice *dkp; + struct disk *dkp; + struct device **devpp; struct partition *pp; struct genericconf *gc; struct bdevsw *bdp; @@ -157,16 +158,20 @@ setconf() unit &= 0x7; goto found; } + for (gc = genericconf; gc->gc_driver; gc++) { for (unit = gc->gc_driver->cd_ndevs - 1; unit >= 0; unit--) { if (gc->gc_driver->cd_devs[unit] == NULL) continue; + /* - * this is a hack these drivers should use - * dk_dev and not another instance directly above. + * Find the disk corresponding to the current + * device. */ - dkp = (struct dkdevice *) - ((struct device *)gc->gc_driver->cd_devs[unit] + 1); + devpp = (struct device **)gc->gc_driver->cd_devs; + if ((dkp = disk_find(devpp[unit]->dv_xname)) == NULL) + continue; + if (dkp->dk_driver == NULL || dkp->dk_driver->d_strategy == NULL) continue; @@ -179,7 +184,7 @@ setconf() continue; bdp->d_close(MAKEDISKDEV(major(gc->gc_root), unit, 0), FREAD | FNONBLOCK, 0, curproc); - pp = &dkp->dk_label.d_partitions[0]; + pp = &dkp->dk_label->d_partitions[0]; if (pp->p_size == 0 || pp->p_fstype != FS_BSDFFS) continue; goto found; diff --git a/sys/arch/amiga/dev/fd.c b/sys/arch/amiga/dev/fd.c index 800131ef2435..849a76010e58 100644 --- a/sys/arch/amiga/dev/fd.c +++ b/sys/arch/amiga/dev/fd.c @@ -1,4 +1,4 @@ -/* $NetBSD: fd.c,v 1.21 1995/08/12 20:30:45 mycroft Exp $ */ +/* $NetBSD: fd.c,v 1.22 1996/01/07 22:01:50 thorpej Exp $ */ /* * Copyright (c) 1994 Christian E. Hopps @@ -110,7 +110,8 @@ struct fdtype { * floppy disk device data */ struct fd_softc { - struct dkdevice dkdev; + struct device sc_dv; /* generic device info; must come first */ + struct disk dkdev; /* generic disk info */ struct buf bufq; /* queue of buf's */ struct fdtype *type; void *cachep; /* cached track data (write through) */ @@ -336,12 +337,18 @@ fdattach(pdp, dp, auxp) sc->hwunit = ap->unit; sc->unitmask = 1 << (3 + ap->unit); sc->retries = FDRETRIES; - sc->dkdev.dk_driver = &fddkdriver; sc->stepdelay = FDSTEPDELAY; printf(": %s %d cyl, %d head, %d sec [%d sec], 512 bytes/sec\n", sc->type->desc, sc->type->ncylinders, FDNHEADS, sc->type->amiga_nsectors, sc->type->msdos_nsectors); + /* + * Initialize and attach the disk structure. + */ + sc->dkdev.dk_name = sc->sc_dv.dv_xname; + sc->dkdev.dk_driver = &fddkdriver; + disk_attach(&sc->dkdev); + /* * calibrate the drive */ @@ -491,15 +498,15 @@ fdioctl(dev, cmd, addr, flag, p) case DIOCSSTEP: if (*(int *)addr < FDSTEPDELAY) return(EINVAL); - sc->dkdev.dk_label.d_trkseek = sc->stepdelay = *(int *)addr; + sc->dkdev.dk_label->d_trkseek = sc->stepdelay = *(int *)addr; return(0); case DIOCGDINFO: - *(struct disklabel *)addr = sc->dkdev.dk_label; + *(struct disklabel *)addr = *(sc->dkdev.dk_label); return(0); case DIOCGPART: - ((struct partinfo *)addr)->disklab = &sc->dkdev.dk_label; + ((struct partinfo *)addr)->disklab = sc->dkdev.dk_label; ((struct partinfo *)addr)->part = - &sc->dkdev.dk_label.d_partitions[FDPART(dev)]; + &sc->dkdev.dk_label->d_partitions[FDPART(dev)]; return(0); case DIOCSDINFO: if ((flag & FWRITE) == 0) @@ -582,7 +589,7 @@ fdstrategy(bp) /* * check for valid partition and bounds */ - lp = &sc->dkdev.dk_label; + lp = sc->dkdev.dk_label; if ((sc->flags & FDF_HAVELABEL) == 0) { bp->b_error = EIO; goto bad; @@ -667,8 +674,8 @@ fdgetdisklabel(sc, dev) printf("fdgetdisklabel()\n"); #endif part = FDPART(dev); - lp = &sc->dkdev.dk_label; - clp = &sc->dkdev.dk_cpulabel; + lp = sc->dkdev.dk_label; + clp = sc->dkdev.dk_cpulabel; bzero(lp, sizeof(struct disklabel)); bzero(clp, sizeof(struct cpu_disklabel)); @@ -748,7 +755,7 @@ fdsetdisklabel(sc, lp) */ if ((sc->flags & FDF_HAVELABEL) == 0) return(EINVAL); - clp = &sc->dkdev.dk_label; + clp = sc->dkdev.dk_label; /* * make sure things check out and we only have one valid * partition @@ -814,7 +821,7 @@ fdputdisklabel(sc, dev) /* * get buf and read in sector 0 */ - lp = &sc->dkdev.dk_label; + lp = sc->dkdev.dk_label; bp = (void *)geteblk((int)lp->d_secsize); bp->b_dev = FDMAKEDEV(major(dev), FDUNIT(dev), RAW_PART); bp->b_blkno = 0; @@ -1163,6 +1170,9 @@ fdstart(sc) */ trk = bp->b_blkno / sc->nsectors; + /* Instrumentation. */ + disk_busy(&sc->dkdev); + /* * check to see if same as currently cached track * if so we need to do no dma read. @@ -1377,7 +1387,7 @@ fddmadone(sc, timeo) sc->flags &= ~FDF_DIRTY; if (timeo) printf("%s: write of track cache timed out.\n", - sc->dkdev.dk_dev.dv_xname); + sc->dv.dv_xname); if (sc->flags & FDF_JUSTFLUSH) { sc->flags &= ~FDF_JUSTFLUSH; /* @@ -1406,7 +1416,7 @@ fddmadone(sc, timeo) #ifdef FDDEBUG if (timeo) printf("%s: fddmadone: cache load timed out.\n", - sc->dkdev.dk_dev.dv_xname); + sc->sc_dv.dv_xname); #endif if (sc->retried >= sc->retries) { sc->retried = 0; @@ -1484,9 +1494,12 @@ fddone(sc) * remove from queue. */ dp->b_actf = bp->b_actf; + + disk_unbusy(&sc->dkdev, (bp->b_bcount - bp->b_resid)); + biodone(bp); nobuf: - fdfindwork(sc->dkdev.dk_dev.dv_unit); + fdfindwork(sc->sc_dv.dv_unit); } void @@ -1684,7 +1697,7 @@ again: if (doagain == 0 || (rp = srp = fdfindsync(srp, erp)) == NULL) { #ifdef DIAGNOSTIC printf("%s: corrupted track (%d) data.\n", - sc->dkdev.dk_dev.dv_xname, sc->cachetrk); + sc->sc_dv.dv_xname, sc->cachetrk); #endif return(-1); } @@ -1707,7 +1720,7 @@ again: if (((info >> 16) & 0xff) != sc->cachetrk) { #ifdef DEBUG printf("%s: incorrect track found: 0x%0x %d\n", - sc->dkdev.dk_dev.dv_xname, info, sc->cachetrk); + sc->sc_dv.dv_xname, info, sc->cachetrk); #endif goto again; } diff --git a/sys/arch/amiga/dev/idesc.c b/sys/arch/amiga/dev/idesc.c index ae0cb7d995e2..d27d5c250432 100644 --- a/sys/arch/amiga/dev/idesc.c +++ b/sys/arch/amiga/dev/idesc.c @@ -1,4 +1,4 @@ -/* $NetBSD: idesc.c,v 1.14 1995/10/05 12:41:22 chopps Exp $ */ +/* $NetBSD: idesc.c,v 1.15 1996/01/07 22:01:53 thorpej Exp $ */ /* * Copyright (c) 1994 Michael L. Hitch @@ -528,6 +528,10 @@ ide_scsidone(dev, stat) panic("ide_scsidone"); #endif #if 1 + /* + * XXX Support old-style instrumentation for now. + * IS THIS REALLY THE RIGHT PLACE FOR THIS? --thorpej + */ if (xs->sc_link && xs->sc_link->device_softc && ((struct device *)(xs->sc_link->device_softc))->dv_unit < dk_ndrive) ++dk_xfer[((struct device *)(xs->sc_link->device_softc))->dv_unit]; diff --git a/sys/arch/amiga/dev/sbic.c b/sys/arch/amiga/dev/sbic.c index 753293c62714..dbf6c7ec3b92 100644 --- a/sys/arch/amiga/dev/sbic.c +++ b/sys/arch/amiga/dev/sbic.c @@ -1,4 +1,4 @@ -/* $NetBSD: sbic.c,v 1.20 1995/11/30 00:57:13 jtc Exp $ */ +/* $NetBSD: sbic.c,v 1.21 1996/01/07 22:01:54 thorpej Exp $ */ /* * Copyright (c) 1994 Christian E. Hopps @@ -562,6 +562,10 @@ sbic_scsidone(acb, stat) return; } #endif + /* + * XXX Support old-style instrumentation for now. + * IS THIS REALLY THE RIGHT PLACE FOR THIS? --thorpej + */ if (slp->device_softc && ((struct device *)(slp->device_softc))->dv_unit < dk_ndrive) ++dk_xfer[((struct device *)(slp->device_softc))->dv_unit]; diff --git a/sys/arch/amiga/dev/sci.c b/sys/arch/amiga/dev/sci.c index 7b53b76eb7e0..91cd5a1b78f3 100644 --- a/sys/arch/amiga/dev/sci.c +++ b/sys/arch/amiga/dev/sci.c @@ -1,4 +1,4 @@ -/* $NetBSD: sci.c,v 1.14 1995/09/29 13:52:02 chopps Exp $ */ +/* $NetBSD: sci.c,v 1.15 1996/01/07 22:01:56 thorpej Exp $ */ /* * Copyright (c) 1994 Michael L. Hitch @@ -215,6 +215,10 @@ sci_scsidone(dev, stat) if (xs == NULL) panic("sci_scsidone"); #endif + /* + * XXX Support old-style instrumentation for now. + * IS THIS REALLY THE RIGHT PLACE FOR THIS? --thorpej + */ if (xs->sc_link->device_softc && ((struct device *)(xs->sc_link->device_softc))->dv_unit < dk_ndrive) ++dk_xfer[((struct device *)(xs->sc_link->device_softc))->dv_unit]; diff --git a/sys/arch/amiga/dev/siop.c b/sys/arch/amiga/dev/siop.c index 72d6417d613c..ebbd360fbe8b 100644 --- a/sys/arch/amiga/dev/siop.c +++ b/sys/arch/amiga/dev/siop.c @@ -1,4 +1,4 @@ -/* $NetBSD: siop.c,v 1.26 1995/11/30 00:57:23 jtc Exp $ */ +/* $NetBSD: siop.c,v 1.27 1996/01/07 22:01:58 thorpej Exp $ */ /* * Copyright (c) 1994 Michael L. Hitch @@ -365,7 +365,11 @@ siop_scsidone(acb, stat) if (acb == NULL || xs == NULL) panic("siop_scsidone"); #endif - if (slp->device_softc && + /* + * XXX Support old-style instrumentation for now. + * IS THIS REALLY THE RIGHT PLACE FOR THIS? --thorpej + */ + if (slp->device_softc && ((struct device *)(slp->device_softc))->dv_unit < dk_ndrive) ++dk_xfer[((struct device *)(slp->device_softc))->dv_unit]; /* diff --git a/sys/arch/atari/atari/swapgeneric.c b/sys/arch/atari/atari/swapgeneric.c index 5ed756f32d02..76a148dbed63 100644 --- a/sys/arch/atari/atari/swapgeneric.c +++ b/sys/arch/atari/atari/swapgeneric.c @@ -1,4 +1,4 @@ -/* $NetBSD: swapgeneric.c,v 1.2 1995/11/30 21:55:01 leo Exp $ */ +/* $NetBSD: swapgeneric.c,v 1.3 1996/01/07 22:02:02 thorpej Exp $ */ /* * Copyright (c) 1995 Leo Weppelman @@ -259,7 +259,8 @@ int *rv_unit; { struct genericconf *gc; struct partition *pp; - struct dkdevice *dkp; + struct disk *dkp; + struct device **devpp; struct bdevsw *bdp; int unit; @@ -267,13 +268,17 @@ int *rv_unit; for (unit = 0; unit < gc->gc_driver->cd_ndevs; unit++) { if (gc->gc_driver->cd_devs[unit] == NULL) continue; + /* - * this is a hack these drivers should use - * dk_dev and not another instance directly above. + * Find the disk corresponding to the current + * device. */ - dkp = (struct dkdevice *) - ((struct device *)gc->gc_driver->cd_devs[unit] + 1); - if (dkp->dk_driver==NULL || dkp->dk_driver->d_strategy==NULL) + devpp = (struct device **)gc->gc_driver->cd_devs; + if ((dkp = disk_find(devpp[unit]->dv_xname)) == NULL) + continue; + + if ((dkp->dk_driver == NULL) || + (dkp->dk_driver->d_strategy == NULL)) continue; for (bdp = bdevsw; bdp < (bdevsw + nblkdev); bdp++) if (bdp->d_strategy == dkp->dk_driver->d_strategy) @@ -284,12 +289,12 @@ int *rv_unit; bdp->d_close(MAKEDISKDEV(major(gc->gc_root), unit, 3), FREAD | FNONBLOCK, 0, curproc); if (search_root) { - pp = &dkp->dk_label.d_partitions[0]; + pp = &dkp->dk_label->d_partitions[0]; if (pp->p_size == 0 || pp->p_fstype != FS_BSDFFS) continue; } else { /* must be swap */ - pp = &dkp->dk_label.d_partitions[1]; + pp = &dkp->dk_label->d_partitions[1]; if (pp->p_size == 0 || pp->p_fstype != FS_SWAP) continue; } diff --git a/sys/arch/atari/dev/fd.c b/sys/arch/atari/dev/fd.c index 8a7369e89dac..e7f8dba61e16 100644 --- a/sys/arch/atari/dev/fd.c +++ b/sys/arch/atari/dev/fd.c @@ -1,4 +1,4 @@ -/* $NetBSD: fd.c,v 1.12 1995/12/10 14:25:12 leo Exp $ */ +/* $NetBSD: fd.c,v 1.13 1996/01/07 22:02:05 thorpej Exp $ */ /* * Copyright (c) 1995 Leo Weppelman. @@ -125,7 +125,8 @@ static char *fd_error= NULL; /* error from fd_xfer_ok() */ * Private per device data */ struct fd_softc { - struct dkdevice dkdev; + struct device sc_dv; /* generic device info */ + struct disk dkdev; /* generic disk info */ struct buf bufq; /* queue of buf's */ int unit; /* unit for atari controlling hw*/ int nheads; /* number of heads in use */ @@ -315,7 +316,12 @@ void *auxp; printf("\n"); + /* + * Initialize and attach the disk structure. + */ + sc->dkdev.dk_name = sc->sc_dv.dv_xname; sc->dkdev.dk_driver = &fddkdriver; + disk_attach(&sc->dkdev); } fdioctl(dev, cmd, addr, flag, p) @@ -337,13 +343,13 @@ struct proc *p; case DIOCSBAD: return(EINVAL); case DIOCGDINFO: - *(struct disklabel *)addr = sc->dkdev.dk_label; + *(struct disklabel *)addr = *(sc->dkdev.dk_label); return(0); case DIOCGPART: ((struct partinfo *)addr)->disklab = - &sc->dkdev.dk_label; + sc->dkdev.dk_label; ((struct partinfo *)addr)->part = - &sc->dkdev.dk_label.d_partitions[DISKPART(dev)]; + &sc->dkdev.dk_label->d_partitions[DISKPART(dev)]; return(0); #ifdef notyet /* XXX LWP */ case DIOCSRETRIES: @@ -497,7 +503,7 @@ struct buf *bp; /* * check for valid partition and bounds */ - lp = &sc->dkdev.dk_label; + lp = sc->dkdev.dk_label; if ((sc->flags & FLPF_HAVELAB) == 0) { bp->b_error = EIO; goto bad; @@ -599,6 +605,9 @@ struct fd_softc *sc; sc->errcnt = 0; /* No errors yet */ fd_state = FLP_XFER; /* Yes, we're going to transfer */ + /* Instrumentation. */ + disk_busy(&sc->dkdev); + fd_xfer(sc); } @@ -638,6 +647,9 @@ register struct fd_softc *sc; sc->io_bytes); #endif bp->b_resid = sc->io_bytes; + + disk_unbusy(&sc->dkdev, (bp->b_bcount - bp->b_resid)); + biodone(bp); } fd_state = FLP_MON; @@ -1219,7 +1231,7 @@ dev_t dev; #endif part = DISKPART(dev); - lp = &sc->dkdev.dk_label; + lp = sc->dkdev.dk_label; bzero(lp, sizeof(struct disklabel)); lp->d_secsize = SECTOR_SIZE; diff --git a/sys/arch/atari/dev/ramd.c b/sys/arch/atari/dev/ramd.c index 46f7fab41bf4..1f833c2257bf 100644 --- a/sys/arch/atari/dev/ramd.c +++ b/sys/arch/atari/dev/ramd.c @@ -1,4 +1,4 @@ -/* $NetBSD: ramd.c,v 1.5 1995/08/12 20:31:02 mycroft Exp $ */ +/* $NetBSD: ramd.c,v 1.6 1996/01/07 22:02:06 thorpej Exp $ */ /* * Copyright (c) 1995 Leo Weppelman. @@ -101,6 +101,8 @@ struct read_info { void (*strat)(); /* strategy function for read */ }; +static struct disk ramd_disks[RAMD_NDEV]; /* XXX Ick. */ + /* * Autoconfig stuff.... */ @@ -112,6 +114,10 @@ struct cfdriver ramdcd = { NULL, "rd", (cfmatch_t)ramdmatch, ramdattach, DV_DULL, sizeof(struct device), NULL, 0 }; +void rdstrategy __P((struct buf *)); + +struct dkdriver ramddkdriver = { rdstrategy }; + static int ramdmatch(pdp, cfp, auxp) struct device *pdp; @@ -129,9 +135,28 @@ struct device *pdp, *dp; void *auxp; { int i; + struct disk *diskp; + + /* + * XXX It's not really clear to me _exactly_ what's going + * on here, so this might need to be adjusted. --thorpej + */ + + for(i = 0; i < RAMD_NDEV; i++) { + /* + * Initialize and attach the disk structure. + */ + diskp = &ramd_disks[i]; + bzero(diskp, sizeof(struct disk)); + if ((diskp->dk_name = malloc(8, M_DEVBUF, M_NOWAIT)) == NULL) + panic("ramdattach: can't allocate space for name"); + bzero(diskp->dk_name, 8); + sprintf(diskp->dk_name, "rd%d", i); + diskp->dk_driver = &ramddkdriver; + disk_attach(diskp); - for(i = 0; i < RAMD_NDEV; i++) config_found(dp, (void*)i, ramdprint); + } } static int diff --git a/sys/arch/hp300/dev/rd.c b/sys/arch/hp300/dev/rd.c index 2b479345a3a6..d1c480c72ea8 100644 --- a/sys/arch/hp300/dev/rd.c +++ b/sys/arch/hp300/dev/rd.c @@ -1,4 +1,4 @@ -/* $NetBSD: rd.c,v 1.16 1995/12/09 07:31:07 thorpej Exp $ */ +/* $NetBSD: rd.c,v 1.17 1996/01/07 22:02:12 thorpej Exp $ */ /* * Copyright (c) 1988 University of Utah. @@ -52,8 +52,9 @@ #include #include #include -#include +#include /* XXX */ #include +#include #include #include @@ -231,6 +232,19 @@ rdmatch(hd) rs->sc_punit = rdpunit(hd->hp_flags); rs->sc_type = rdident(rs, hd, 0); if (rs->sc_type < 0) + return(0); + + /* XXX set up the external name */ + bzero(rs->sc_xname, sizeof(rs->sc_xname)); + sprintf(rs->sc_xname, "rd%d", hd->hp_unit); + + /* + * Initialize and attach the disk structure. + */ + bzero(&rs->sc_dkdev, sizeof(rs->sc_dkdev)); + rs->sc_dkdev.dk_name = rs->sc_xname; + disk_attach(&rs->sc_dkdev); + return (0); return (1); @@ -420,7 +434,7 @@ rdgetinfo(dev) { int unit = rdunit(dev); register struct rd_softc *rs = &rd_softc[unit]; - register struct disklabel *lp = &rs->sc_info.ri_label; + register struct disklabel *lp = rs->sc_dkdev.dk_label; register struct partition *pi; char *msg, *readdisklabel(); @@ -485,7 +499,7 @@ rdopen(dev, flags, mode, p) * We may block reading the label, so be careful * to stop any other opens. */ - if (rs->sc_info.ri_open == 0) { + if (rs->sc_dkdev.dk_openmask == 0) { rs->sc_flags |= RDF_OPENING; error = rdgetinfo(dev); rs->sc_flags &= ~RDF_OPENING; @@ -496,17 +510,19 @@ rdopen(dev, flags, mode, p) if (rs->sc_hd->hp_dk >= 0) { /* guess at xfer rate based on 3600 rpm (60 rps) */ if (rs->sc_wpms == 0) - rs->sc_wpms = 60 * rs->sc_info.ri_label.d_nsectors + rs->sc_wpms = 60 * rs->sc_dkdev.dk_label->d_nsectors * DEV_BSIZE / 2; + + /* XXX Support old-style instrumentation for now. */ dk_wpms[rs->sc_hd->hp_dk] = rs->sc_wpms; } mask = 1 << rdpart(dev); if (mode == S_IFCHR) - rs->sc_info.ri_copen |= mask; + rs->sc_dkdev.dk_copenmask |= mask; else - rs->sc_info.ri_bopen |= mask; - rs->sc_info.ri_open |= mask; + rs->sc_dkdev.dk_bopenmask |= mask; + rs->sc_dkdev.dk_openmask |= mask; return(0); } @@ -518,15 +534,15 @@ rdclose(dev, flag, mode, p) { int unit = rdunit(dev); register struct rd_softc *rs = &rd_softc[unit]; - register struct rdinfo *ri = &rs->sc_info; + register struct disk *dk = &rs->sc_dkdev; int mask, s; mask = 1 << rdpart(dev); if (mode == S_IFCHR) - ri->ri_copen &= ~mask; + dk->dk_copenmask &= ~mask; else - ri->ri_bopen &= ~mask; - ri->ri_open = ri->ri_bopen | ri->ri_copen; + dk->dk_bopenmask &= ~mask; + dk->dk_openmask = dk->dk_copenmask | dk->dk_bopenmask; /* * On last close, we wait for all activity to cease since * the label/parition info will become invalid. Since we @@ -534,7 +550,7 @@ rdclose(dev, flag, mode, p) * Note we don't have to about other closes since we know * we are the last one. */ - if (ri->ri_open == 0) { + if (dk->dk_openmask == 0) { rs->sc_flags |= RDF_CLOSING; s = splbio(); while (rdtab[unit].b_active) { @@ -567,7 +583,7 @@ rdstrategy(bp) #endif bn = bp->b_blkno; sz = howmany(bp->b_bcount, DEV_BSIZE); - pinfo = &rs->sc_info.ri_label.d_partitions[rdpart(bp->b_dev)]; + pinfo = &rs->sc_dkdev.dk_label->d_partitions[rdpart(bp->b_dev)]; if (bn < 0 || bn + sz > pinfo->p_size) { sz = pinfo->p_size - bn; if (sz == 0) { @@ -687,10 +703,17 @@ again: #endif if (hpibsend(hp->hp_ctlr, hp->hp_slave, C_CMD, &rs->sc_ioc.c_unit, sizeof(rs->sc_ioc)-2) == sizeof(rs->sc_ioc)-2) { + + /* XXX Support old-style instrumentation for now. */ if (hp->hp_dk >= 0) { - dk_busy |= 1 << hp->hp_dk; - dk_seek[hp->hp_dk]++; + dk_busy |= 1 << hp->hp_dk; + dk_seek[hp->hp_dk]++; } + + /* Instrumentation. */ + disk_busy(&rs->sc_dkdev); + rs->sc_dkdev.dk_seek++; + #ifdef DEBUG if (rddebug & RDB_IO) printf("rdstart: hpibawait(%x)\n", hp->hp_ctlr); @@ -739,11 +762,16 @@ rdgo(unit) rw = bp->b_flags & B_READ; + /* XXX Support old-style instrumentation for now. */ if (hp->hp_dk >= 0) { dk_busy |= 1 << hp->hp_dk; dk_xfer[hp->hp_dk]++; dk_wds[hp->hp_dk] += rs->sc_resid >> 6; } + + /* Instrumentation. */ + disk_busy(&rs->sc_dkdev); + #ifdef USELEDS if (inledcontrol == 0) ledcontrol(0, 0, LED_DISK); @@ -770,8 +798,12 @@ rdintr(unit) return; } #endif + /* XXX Support old-style instrumentation for now. */ if (hp->hp_dk >= 0) dk_busy &= ~(1 << hp->hp_dk); + + disk_unbusy(&rs->sc_dkdev, (bp->b_bcount - bp->b_resid)); + if (rs->sc_flags & RDF_SEEK) { rs->sc_flags &= ~RDF_SEEK; if (hpibustart(hp->hp_ctlr)) @@ -786,8 +818,13 @@ rdintr(unit) #ifdef DEBUG rdstats[unit].rdpollwaits++; #endif + + /* XXX Support old-style instrumentation for now. */ if (hp->hp_dk >= 0) dk_busy |= 1 << hp->hp_dk; + + /* Instrumentation. */ + disk_busy(&rs->sc_dkdev); rs->sc_flags |= RDF_SWAIT; hpibawait(hp->hp_ctlr); return; @@ -920,7 +957,7 @@ rderror(unit) * we just use b_blkno. */ bp = rdtab[unit].b_actf; - pbn = rs->sc_info.ri_label.d_partitions[rdpart(bp->b_dev)].p_offset; + pbn = rs->sc_dkdev.dk_label->d_partitions[rdpart(bp->b_dev)].p_offset; if ((sp->c_fef & FEF_CU) || (sp->c_fef & FEF_DR) || (sp->c_ief & IEF_RRMASK)) { hwbn = RDBTOS(pbn + bp->b_blkno); @@ -1007,7 +1044,7 @@ rdioctl(dev, cmd, data, flag, p) { int unit = rdunit(dev); register struct rd_softc *sc = &rd_softc[unit]; - register struct disklabel *lp = &sc->sc_info.ri_label; + register struct disklabel *lp = sc->sc_dkdev.dk_label; int error, flags; switch (cmd) { @@ -1035,7 +1072,7 @@ rdioctl(dev, cmd, data, flag, p) return (EBADF); return (setdisklabel(lp, (struct disklabel *)data, (sc->sc_flags & RDF_WLABEL) ? 0 - : sc->sc_info.ri_open, + : sc->sc_dkdev.dk_openmask, (struct cpu_disklabel *)0)); case DIOCWDINFO: @@ -1043,7 +1080,7 @@ rdioctl(dev, cmd, data, flag, p) return (EBADF); error = setdisklabel(lp, (struct disklabel *)data, (sc->sc_flags & RDF_WLABEL) ? 0 - : sc->sc_info.ri_open, + : sc->sc_dkdev.dk_openmask, (struct cpu_disklabel *)0); if (error) return (error); @@ -1073,12 +1110,12 @@ rdsize(dev) * without the device being open so we may need * to handle it here. */ - if (rs->sc_info.ri_open == 0) { + if (rs->sc_dkdev.dk_openmask == 0) { if (rdopen(dev, FREAD|FWRITE, S_IFBLK, NULL)) return(-1); didopen = 1; } - psize = rs->sc_info.ri_label.d_partitions[rdpart(dev)].p_size; + psize = rs->sc_dkdev.dk_label->d_partitions[rdpart(dev)].p_size; if (didopen) (void) rdclose(dev, FREAD|FWRITE, S_IFBLK, NULL); return (psize); @@ -1128,7 +1165,7 @@ rddump(dev) /* is drive ok? */ if (unit >= NRD || (rs->sc_flags & RDF_ALIVE) == 0) return (ENXIO); - pinfo = &rs->sc_info.ri_label.d_partitions[part]; + pinfo = &rs->sc_dkdev.dk_label->d_partitions[part]; /* dump parameters in range? */ if (dumplo < 0 || dumplo >= pinfo->p_size || pinfo->p_fstype != FS_SWAP) diff --git a/sys/arch/hp300/dev/rd_compat.c b/sys/arch/hp300/dev/rd_compat.c index 239dd4bc0e67..4adea53bcbdf 100644 --- a/sys/arch/hp300/dev/rd_compat.c +++ b/sys/arch/hp300/dev/rd_compat.c @@ -1,4 +1,4 @@ -/* $NetBSD: rd_compat.c,v 1.4 1995/11/19 19:07:20 thorpej Exp $ */ +/* $NetBSD: rd_compat.c,v 1.5 1996/01/07 22:02:14 thorpej Exp $ */ /* * Copyright (c) 1988 University of Utah. @@ -50,6 +50,7 @@ #include #include +#include #include #include #include diff --git a/sys/arch/hp300/dev/rdvar.h b/sys/arch/hp300/dev/rdvar.h index 6d1214d46a7d..97c21aa9b35e 100644 --- a/sys/arch/hp300/dev/rdvar.h +++ b/sys/arch/hp300/dev/rdvar.h @@ -1,4 +1,4 @@ -/* $NetBSD: rdvar.h,v 1.3 1995/11/19 19:07:21 thorpej Exp $ */ +/* $NetBSD: rdvar.h,v 1.4 1996/01/07 22:02:16 thorpej Exp $ */ /* * Copyright (c) 1988 University of Utah. @@ -52,22 +52,16 @@ struct rdidentinfo { int ri_nblocks; /* DEV_BSIZE blocks on disk */ }; -struct rdinfo { - struct disklabel ri_label; /* label */ - int ri_bopen; /* mask of open block devs */ - int ri_copen; /* mask of open char devs */ - int ri_open; /* composite mask of open devs */ -}; - struct rd_softc { struct hp_device *sc_hd; + struct disk sc_dkdev; + char sc_xname[8]; int sc_flags; short sc_type; short sc_punit; char *sc_addr; int sc_resid; u_int sc_wpms; - struct rdinfo sc_info; struct rd_describe sc_rddesc; struct devqueue sc_dq; struct rd_iocmd sc_ioc; diff --git a/sys/arch/hp300/dev/sd.c b/sys/arch/hp300/dev/sd.c index c6c26a42bbbc..9355625f981d 100644 --- a/sys/arch/hp300/dev/sd.c +++ b/sys/arch/hp300/dev/sd.c @@ -1,4 +1,4 @@ -/* $NetBSD: sd.c,v 1.20 1995/12/09 07:31:03 thorpej Exp $ */ +/* $NetBSD: sd.c,v 1.21 1996/01/07 22:02:18 thorpej Exp $ */ /* * Copyright (c) 1990, 1993 @@ -48,8 +48,9 @@ #include #include #include -#include +#include /* XXX */ #include +#include #include #include #include @@ -326,6 +327,14 @@ sdmatch(hd) { register struct sd_softc *sc = &sd_softc[hd->hp_unit]; + /* XXX set up external name */ + bzero(sc->sc_xname, sizeof(sc->sc_xname)); + sprintf(sc->sc_xname, "sd%d", hd->hp_unit); + + /* Initialize the disk structure. */ + bzero(&sc->sc_dkdev, sizeof(sc->sc_dkdev)); + sc->sc_dkdev.dk_name = sc->sc_xname; + sc->sc_hd = hd; sc->sc_flags = 0; /* @@ -354,6 +363,9 @@ sdattach(hd) sc->sc_dq.dq_slave = hd->hp_slave; sc->sc_dq.dq_driver = &sddriver; + /* Attach the disk. */ + disk_attach(&sc->sc_dkdev); + sc->sc_flags |= SDF_ALIVE; } @@ -474,7 +486,7 @@ sdgetinfo(dev) { int unit = sdunit(dev); register struct sd_softc *sc = &sd_softc[unit]; - register struct disklabel *lp = &sc->sc_info.si_label; + register struct disklabel *lp = sc->sc_dkdev.dk_label; register struct partition *pi; char *msg, *readdisklabel(); #ifdef COMPAT_NOLABEL @@ -584,7 +596,7 @@ sdopen(dev, flags, mode, p) * We may block reading the label, so be careful * to stop any other opens. */ - if (sc->sc_info.si_open == 0) { + if (sc->sc_dkdev.dk_openmask == 0) { sc->sc_flags |= SDF_OPENING; error = sdgetinfo(dev); sc->sc_flags &= ~SDF_OPENING; @@ -592,15 +604,17 @@ sdopen(dev, flags, mode, p) if (error) return(error); } + + /* XXX Support old-style instrumentation for now. */ if (sc->sc_hd->hp_dk >= 0) dk_wpms[sc->sc_hd->hp_dk] = sc->sc_wpms; mask = 1 << sdpart(dev); if (mode == S_IFCHR) - sc->sc_info.si_copen |= mask; + sc->sc_dkdev.dk_copenmask |= mask; else - sc->sc_info.si_bopen |= mask; - sc->sc_info.si_open |= mask; + sc->sc_dkdev.dk_bopenmask |= mask; + sc->sc_dkdev.dk_openmask |= mask; return(0); } @@ -612,15 +626,15 @@ sdclose(dev, flag, mode, p) { int unit = sdunit(dev); register struct sd_softc *sc = &sd_softc[unit]; - register struct sdinfo *si = &sc->sc_info; + register struct disk *dk = &sc->sc_dkdev; int mask, s; mask = 1 << sdpart(dev); if (mode == S_IFCHR) - si->si_copen &= ~mask; + dk->dk_copenmask &= ~mask; else - si->si_bopen &= ~mask; - si->si_open = si->si_bopen | si->si_copen; + dk->dk_bopenmask &= ~mask; + dk->dk_openmask = dk->dk_copenmask | dk->dk_bopenmask; /* * On last close, we wait for all activity to cease since * the label/parition info will become invalid. Since we @@ -628,7 +642,7 @@ sdclose(dev, flag, mode, p) * Note we don't have to about other closes since we know * we are the last one. */ - if (si->si_open == 0) { + if (dk->dk_openmask == 0) { sc->sc_flags |= SDF_CLOSING; s = splbio(); while (sdtab[unit].b_active) { @@ -765,7 +779,7 @@ sdstrategy(bp) } bn = bp->b_blkno; sz = howmany(bp->b_bcount, DEV_BSIZE); - pinfo = &sc->sc_info.si_label.d_partitions[sdpart(bp->b_dev)]; + pinfo = &sc->sc_dkdev.dk_label->d_partitions[sdpart(bp->b_dev)]; if (bn < 0 || bn + sz > pinfo->p_size) { sz = pinfo->p_size - bn; if (sz == 0) { @@ -982,13 +996,19 @@ sdgo(unit) if (inledcontrol == 0) ledcontrol(0, 0, LED_DISK); #endif - if (scsigo(hp->hp_ctlr, hp->hp_slave, sc->sc_punit, bp, cmd, pad) == 0) { + if (scsigo(hp->hp_ctlr, hp->hp_slave, sc->sc_punit, + bp, cmd, pad) == 0) { + /* XXX Support old-style instrumentation for now. */ if (hp->hp_dk >= 0) { dk_busy |= 1 << hp->hp_dk; ++dk_seek[hp->hp_dk]; ++dk_xfer[hp->hp_dk]; dk_wds[hp->hp_dk] += bp->b_bcount >> 6; } + + /* Instrumentation. */ + disk_busy(&sc->sc_dkdev); + sc->sc_dkdev.dk_seek++; /* XXX */ return; } #ifdef DEBUG @@ -1018,8 +1038,13 @@ sdintr(unit, stat) printf("%s: bp == NULL\n", sc->sc_hd->hp_xname); return; } + + /* XXX Support old-style instrumentation for now. */ if (hp->hp_dk >= 0) dk_busy &=~ (1 << hp->hp_dk); + + disk_unbusy(&sc->sc_dkdev, (bp->b_bcount - bp->b_resid)); + if (stat) { #ifdef DEBUG if (sddebug & SDB_ERROR) @@ -1087,7 +1112,7 @@ sdioctl(dev, cmd, data, flag, p) { int unit = sdunit(dev); register struct sd_softc *sc = &sd_softc[unit]; - register struct disklabel *lp = &sc->sc_info.si_label; + register struct disklabel *lp = sc->sc_dkdev.dk_label; int error, flags; switch (cmd) { @@ -1118,7 +1143,7 @@ sdioctl(dev, cmd, data, flag, p) return (EBADF); error = setdisklabel(lp, (struct disklabel *)data, (sc->sc_flags & SDF_WLABEL) ? 0 - : sc->sc_info.si_open, + : sc->sc_dkdev.dk_openmask, (struct cpu_disklabel *)0); return (error); @@ -1127,7 +1152,7 @@ sdioctl(dev, cmd, data, flag, p) return (EBADF); error = setdisklabel(lp, (struct disklabel *)data, (sc->sc_flags & SDF_WLABEL) ? 0 - : sc->sc_info.si_open, + : sc->sc_dkdev.dk_openmask, (struct cpu_disklabel *)0); if (error) return (error); @@ -1196,12 +1221,12 @@ sdsize(dev) * without the device being open so we may need * to handle it here. */ - if (sc->sc_info.si_open == 0) { + if (sc->sc_dkdev.dk_openmask == 0) { if (sdopen(dev, FREAD|FWRITE, S_IFBLK, NULL)) return(-1); didopen = 1; } - psize = sc->sc_info.si_label.d_partitions[sdpart(dev)].p_size; + psize = sc->sc_dkdev.dk_label->d_partitions[sdpart(dev)].p_size; if (didopen) (void) sdclose(dev, FREAD|FWRITE, S_IFBLK, NULL); return (psize); @@ -1228,7 +1253,7 @@ sddump(dev) /* is drive ok? */ if (unit >= NSD || (sc->sc_flags & SDF_ALIVE) == 0) return (ENXIO); - pinfo = &sc->sc_info.si_label.d_partitions[part]; + pinfo = &sc->sc_dkdev.dk_label->d_partitions[part]; /* dump parameters in range? */ if (dumplo < 0 || dumplo >= pinfo->p_size || pinfo->p_fstype != FS_SWAP) diff --git a/sys/arch/hp300/dev/sd_compat.c b/sys/arch/hp300/dev/sd_compat.c index 106a2a518e29..60e25a63b810 100644 --- a/sys/arch/hp300/dev/sd_compat.c +++ b/sys/arch/hp300/dev/sd_compat.c @@ -1,4 +1,4 @@ -/* $NetBSD: sd_compat.c,v 1.3 1994/10/26 07:25:08 cgd Exp $ */ +/* $NetBSD: sd_compat.c,v 1.4 1996/01/07 22:02:20 thorpej Exp $ */ /* * Copyright (c) 1990, 1993 @@ -46,6 +46,7 @@ #include #include +#include #include #include diff --git a/sys/arch/hp300/dev/sdvar.h b/sys/arch/hp300/dev/sdvar.h index 13a74c6398a2..e5933f53a8d6 100644 --- a/sys/arch/hp300/dev/sdvar.h +++ b/sys/arch/hp300/dev/sdvar.h @@ -1,4 +1,4 @@ -/* $NetBSD: sdvar.h,v 1.3 1995/10/15 10:03:20 thorpej Exp $ */ +/* $NetBSD: sdvar.h,v 1.4 1996/01/07 22:02:21 thorpej Exp $ */ /* * Copyright (c) 1990, 1993 @@ -38,15 +38,10 @@ * @(#)sdvar.h 8.1 (Berkeley) 6/10/93 */ -struct sdinfo { - struct disklabel si_label; /* label */ - int si_bopen; /* mask of open block devs */ - int si_copen; /* mask of open char devs */ - int si_open; /* composite mask of open devs */ -}; - struct sd_softc { struct hp_device *sc_hd; + struct disk sc_dkdev; + char sc_xname[8]; struct devqueue sc_dq; int sc_format_pid; /* process using "format" mode */ short sc_flags; @@ -58,7 +53,6 @@ struct sd_softc { u_int sc_heads; /* number of heads (tracks) */ u_int sc_cyls; /* number of cylinders */ u_int sc_wpms; /* average xfer rate in 16 bit wds/sec. */ - struct sdinfo sc_info; /* disklabel and related info */ }; /* sc_flags values */ diff --git a/sys/arch/i386/isa/fd.c b/sys/arch/i386/isa/fd.c index 57815d204bfa..2f3e384e1029 100644 --- a/sys/arch/i386/isa/fd.c +++ b/sys/arch/i386/isa/fd.c @@ -1,4 +1,4 @@ -/* $NetBSD: fd.c,v 1.81 1995/12/28 15:48:57 perry Exp $ */ +/* $NetBSD: fd.c,v 1.82 1996/01/07 22:02:28 thorpej Exp $ */ /*- * Copyright (c) 1993, 1994, 1995 Charles Hannum. @@ -149,7 +149,7 @@ struct fd_type fd_types[] = { /* software state, per disk (with up to 4 disks per ctlr) */ struct fd_softc { struct device sc_dev; - struct dkdevice sc_dk; + struct disk sc_dk; struct fd_type *sc_deftype; /* default type descriptor */ struct fd_type *sc_type; /* current type descriptor */ @@ -405,7 +405,14 @@ fdattach(parent, self, aux) fd->sc_drive = drive; fd->sc_deftype = type; fdc->sc_fd[drive] = fd; + + /* + * Initialize and attach the disk structure. + */ + fd->sc_dk.dk_name = fd->sc_dev.dv_xname; fd->sc_dk.dk_driver = &fddkdriver; + disk_attach(&fd->sc_dk); + #ifdef NEWCONFIG /* XXX Need to do some more fiddling with sc_dk. */ dk_establish(&fd->sc_dk, &fd->sc_dev); @@ -542,6 +549,9 @@ fdstart(fd) fd->sc_q.b_active = 1; TAILQ_INSERT_TAIL(&fdc->sc_drives, fd, sc_drivechain); + /* Instrumentation. */ + disk_busy(&fd->sc_dk); + /* If controller not already active, start it. */ if (!active) fdcstart(fdc); @@ -571,6 +581,9 @@ fdfinish(fd, bp) bp->b_resid = fd->sc_bcount; fd->sc_skip = 0; fd->sc_q.b_actf = bp->b_actf; + + disk_unbusy(&fd->sc_dk, (bp->b_bcount - bp->b_resid)); + biodone(bp); /* turn off motor 5s from now */ timeout(fd_motor_off, fd, 5 * hz); diff --git a/sys/arch/mac68k/mac68k/autoconf.c b/sys/arch/mac68k/mac68k/autoconf.c index edc9439ec04e..90f673867f06 100644 --- a/sys/arch/mac68k/mac68k/autoconf.c +++ b/sys/arch/mac68k/mac68k/autoconf.c @@ -1,4 +1,4 @@ -/* $NetBSD: autoconf.c,v 1.20 1995/11/01 04:59:31 briggs Exp $ */ +/* $NetBSD: autoconf.c,v 1.21 1996/01/07 22:02:39 thorpej Exp $ */ /* * Copyright (c) 1988 University of Utah. @@ -239,7 +239,7 @@ extern struct cfdriver scsibuscd; /* swiped from sparc/sparc/autoconf.c */ static int -findblkmajor(register struct dkdevice *dv) +findblkmajor(register struct disk *dv) { register int i; @@ -258,6 +258,7 @@ void findbootdev() { register struct device *dv; + register struct disk *diskp; register int unit; int major; @@ -271,12 +272,22 @@ findbootdev() unit = target_to_unit(-1, unit, 0); bootdev |= (unit << B_UNITSHIFT); + if (disk_count <= 0) + return; + for (dv = alldevs ; dv ; dv = dv->dv_next) { - if ( (dv->dv_class == DV_DISK) - && (unit == dv->dv_unit) - && (major == findblkmajor((struct dkdevice *) (dv+1)))) { - bootdv = dv; - return; + if ((dv->dv_class == DV_DISK) && (unit == dv->dv_unit)) { + /* + * Find the disk corresponding to the current + * device. + */ + if ((diskp = disk_find(dv->dv_xname)) == NULL) + continue; + + if (major == findblkmajor(diskp)) { + bootdv = dv; + return; + } } } } diff --git a/sys/arch/pc532/dev/rd.c b/sys/arch/pc532/dev/rd.c index fe03b39e589e..e736a4d8b81e 100644 --- a/sys/arch/pc532/dev/rd.c +++ b/sys/arch/pc532/dev/rd.c @@ -27,7 +27,7 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * - * $Id: rd.c,v 1.1 1995/09/26 20:16:14 phil Exp $ + * $Id: rd.c,v 1.2 1996/01/07 22:02:46 thorpej Exp $ */ #include @@ -36,21 +36,31 @@ #include #include #include +#include static int rdmatch(struct device *parent, void *cf, void *aux); static void rdattach(struct device *parent, struct device *self, void *aux); +struct rdsoftc { + struct device sc_dev; /* generic device glue */ + struct disk sc_dkdev; /* generic disk glue */ +}; + struct cfdriver rdcd = { NULL, "rd", rdmatch, rdattach, DV_DISK, - sizeof(struct device), + sizeof(struct rdsoftc), NULL, 0 }; +void rdstrategy __P((struct buf *)); + +struct dkdriver rddkdriver = { rdstrategy }; + #if !defined(RD_SIZE) # define RD_SIZE 0x200000 #endif @@ -70,7 +80,17 @@ rdattach(parent, self, aux) struct device *parent, *self; void *aux; { + struct rdsoftc *sc = (struct rdsoftc *)self; + printf(" addr 0x%x, size 0x%x\n", ram_disk, RD_SIZE); + + /* + * Initialize and attach the disk structure. + */ + bzero(&sc->sc_dkdev, sizeof(sc->sc_dkdev)); + sc->sc_dkdev.dk_driver = &rddkdriver; + sc->sc_dkdev.dk_name = sc->sc_dev.dv_xname; + disk_attach(&sc->sc_dkdev); } diff --git a/sys/arch/pmax/dev/rz.c b/sys/arch/pmax/dev/rz.c index c091b3abefa7..3de5bea69da1 100644 --- a/sys/arch/pmax/dev/rz.c +++ b/sys/arch/pmax/dev/rz.c @@ -1,4 +1,4 @@ -/* $NetBSD: rz.c,v 1.12 1995/09/13 19:35:56 jonathan Exp $ */ +/* $NetBSD: rz.c,v 1.13 1996/01/07 22:02:52 thorpej Exp $ */ /* * Copyright (c) 1992, 1993 @@ -52,8 +52,9 @@ #include #include #include -#include +#include /* XXX */ #include +#include #include #include #include @@ -139,16 +140,18 @@ struct rzstats { struct rz_softc { struct pmax_scsi_device *sc_sd; /* physical unit info */ pid_t sc_format_pid; /* process using "format" mode */ - u_long sc_openpart; /* partitions open */ - u_long sc_bopenpart; /* block partitions open */ - u_long sc_copenpart; /* character partitions open */ short sc_flags; /* see below */ short sc_type; /* drive type from INQUIRY cmd */ u_int sc_blks; /* number of blocks on device */ int sc_blksize; /* device block size in bytes */ - int sc_bshift; /* convert device blocks to DEV_BSIZE */ + struct disk sc_dkdev; /* generic disk device info */ +#define sc_label sc_dkdev.dk_label /* XXX compat */ +#define sc_openpart sc_dkdev.dk_openmask /* XXX compat */ +#define sc_bopenpart sc_dkdev.dk_bopenmask /* XXX compat */ +#define sc_copenpart sc_dkdev.dk_copenmask /* XXX compat */ +#define sc_bshift sc_dkdev.dk_blkshift /* XXX compat */ + char sc_xname[8]; /* XXX external name */ u_int sc_wpms; /* average xfer rate in 16bit wds/sec */ - struct disklabel sc_label; /* disk label for this disk */ struct rzstats sc_stats; /* statisic counts */ struct buf sc_tab; /* queue of pending operations */ struct buf sc_buf; /* buf for doing I/O */ @@ -242,6 +245,7 @@ rzready(sc) else sc->sc_cmd.flags = 0; + disk_busy(&sc->sc_dkdev); /* XXX */ (*sc->sc_sd->sd_cdriver->d_start)(&sc->sc_cmd); if (!biowait(&sc->sc_buf)) break; @@ -335,6 +339,14 @@ rzprobe(sd) sc->sc_cmd.unit = sd->sd_unit; sc->sc_rwcmd.unitNumber = sd->sd_slave; + /* XXX set up the external name */ + bzero(sc->sc_xname, sizeof(sc->sc_xname)); /* XXX */ + sprintf(sc->sc_xname, "rz%d", sd->sd_unit); /* XXX */ + + /* Initialize the disk structure. */ + bzero(&sc->sc_dkdev, sizeof(sc->sc_dkdev)); + sc->sc_dkdev.dk_name = sc->sc_xname; + /* try to find out what type of device this is */ sc->sc_format_pid = 1; /* force use of sc_cdb */ sc->sc_flags = RZF_NOERR; /* don't print SCSI errors */ @@ -407,7 +419,13 @@ rzprobe(sd) goto bad; } } - sc->sc_wpms = 32 * (60 * DEV_BSIZE / 2); /* XXX */ + + /* XXX Support old-style instrumentation for now. */ + sc->sc_wpms = 32 * (60 * DEV_BSIZE / 2); + + /* Attach the disk. */ + disk_attach(&sc->sc_dkdev); + sc->sc_format_pid = 0; sc->sc_flags |= RZF_ALIVE; if (inqbuf.rmb) @@ -528,7 +546,7 @@ rzstrategy(bp) register int unit = rzunit(bp->b_dev); register int part = rzpart(bp->b_dev); register struct rz_softc *sc = &rz_softc[unit]; - register struct partition *pp = &sc->sc_label.d_partitions[part]; + register struct partition *pp = &sc->sc_label->d_partitions[part]; register daddr_t bn; register long sz, s; @@ -633,6 +651,8 @@ rzstart(unit) unit, bp->b_bcount); #endif sc->sc_stats.rztransfers++; + + /* XXX Support old-style instrumentation for now. */ if ((n = sc->sc_sd->sd_dk) >= 0) { dk_busy |= 1 << n; ++dk_seek[n]; @@ -641,6 +661,11 @@ rzstart(unit) } } + + /* Instrumentation. */ + disk_busy(&sc->sc_dkdev); + sc->sc_dkdev.dk_seek++; /* XXX */ + /* tell controller to start this command */ (*sc->sc_sd->sd_cdriver->d_start)(&sc->sc_cmd); } @@ -663,8 +688,13 @@ rzdone(unit, error, resid, status) printf("rz%d: bp == NULL\n", unit); return; } + + /* XXX Support old-style instrumentation for now. */ if (sd->sd_dk >= 0) dk_busy &= ~(1 << sd->sd_dk); + + disk_unbusy(&sc->sc_dkdev, (bp->b_bcount - bp->b_resid)); + if (sc->sc_flags & RZF_SENSEINPROGRESS) { sc->sc_flags &= ~RZF_SENSEINPROGRESS; sc->sc_tab.b_actf = bp = bp->b_actf; /* remove sc_errbuf */ @@ -745,7 +775,7 @@ rzgetinfo(dev) { register int unit = rzunit(dev); register struct rz_softc *sc = &rz_softc[unit]; - register struct disklabel *lp = &sc->sc_label; + register struct disklabel *lp = sc->sc_label; register int i; char *msg; int part; @@ -834,7 +864,7 @@ rzopen(dev, flags, mode, p) register struct disklabel *lp; register int i; int part; - u_long mask; + int mask; if (unit >= NRZ || !(sc->sc_flags & RZF_ALIVE)) return (ENXIO); @@ -850,7 +880,7 @@ rzopen(dev, flags, mode, p) if (!(sc->sc_flags & RZF_HAVELABEL)) rzgetinfo(dev); - lp = &sc->sc_label; + lp = sc->sc_label; if (part >= lp->d_npartitions || lp->d_partitions[part].p_size == 0) { printf("rzopen: ENXIO on rz%d%c unit %d part %d\n", @@ -894,8 +924,11 @@ rzopen(dev, flags, mode, p) break; } sc->sc_openpart |= mask; + + /* XXX Support old-style instrumentation for now. */ if (sc->sc_sd->sd_dk >= 0) dk_wpms[sc->sc_sd->sd_dk] = sc->sc_wpms; + return (0); } @@ -904,7 +937,7 @@ rzclose(dev, flags, mode) int flags, mode; { register struct rz_softc *sc = &rz_softc[rzunit(dev)]; - u_long mask = (1 << rzpart(dev)); + int mask = (1 << rzpart(dev)); int s; switch (mode) { @@ -1019,14 +1052,14 @@ rzioctl(dev, cmd, data, flag, p) case DIOCGDINFO: /* get the current disk label */ - *(struct disklabel *)data = sc->sc_label; + *(struct disklabel *)data = *(sc->sc_label); return (0); case DIOCSDINFO: /* set the current disk label */ if (!(flag & FWRITE)) return (EBADF); - error = setdisklabel(&sc->sc_label, + error = setdisklabel(sc->sc_label, (struct disklabel *)data, (sc->sc_flags & RZF_WLABEL) ? 0 : sc->sc_openpart, &cd); @@ -1034,9 +1067,9 @@ rzioctl(dev, cmd, data, flag, p) case DIOCGPART: /* return the disk partition data */ - ((struct partinfo *)data)->disklab = &sc->sc_label; + ((struct partinfo *)data)->disklab = sc->sc_label; ((struct partinfo *)data)->part = - &sc->sc_label.d_partitions[rzpart(dev)]; + &sc->sc_label->d_partitions[rzpart(dev)]; return (0); case DIOCWLABEL: @@ -1052,7 +1085,7 @@ rzioctl(dev, cmd, data, flag, p) /* write the disk label to disk */ if (!(flag & FWRITE)) return (EBADF); - error = setdisklabel(&sc->sc_label, + error = setdisklabel(sc->sc_label, (struct disklabel *)data, (sc->sc_flags & RZF_WLABEL) ? 0 : sc->sc_openpart, @@ -1063,7 +1096,7 @@ rzioctl(dev, cmd, data, flag, p) /* simulate opening partition 0 so write succeeds */ flags = sc->sc_flags; sc->sc_flags = RZF_ALIVE | RZF_WLABEL; - error = writedisklabel(dev, rzstrategy, &sc->sc_label, &cd); + error = writedisklabel(dev, rzstrategy, sc->sc_label, &cd); sc->sc_flags = flags; return (error); } @@ -1089,9 +1122,9 @@ rzsize(dev) if (!(sc->sc_flags & RZF_HAVELABEL)) rzgetinfo(dev); - if (part >= sc->sc_label.d_npartitions) + if (part >= sc->sc_label->d_npartitions) return (-1); - return (sc->sc_label.d_partitions[part].p_size); + return (sc->sc_label->d_partitions[part].p_size); } /* @@ -1123,12 +1156,12 @@ rzdump(dev) if (unit >= NRZ || (sc->sc_flags & RZF_ALIVE) == 0) return (ENXIO); /* dump parameters in range? */ - if (dumplo < 0 || dumplo >= sc->sc_label.d_partitions[part].p_size) + if (dumplo < 0 || dumplo >= sc->sc_label->d_partitions[part].p_size) return (EINVAL); - if (dumplo + ctod(pages) > sc->sc_label.d_partitions[part].p_size) - pages = dtoc(sc->sc_label.d_partitions[part].p_size - dumplo); + if (dumplo + ctod(pages) > sc->sc_label->d_partitions[part].p_size) + pages = dtoc(sc->sc_label->d_partitions[part].p_size - dumplo); maddr = lowram; - baddr = dumplo + sc->sc_label.d_partitions[part].p_offset; + baddr = dumplo + sc->sc_label->d_partitions[part].p_offset; #ifdef notdef /*XXX -- bogus code, from Mach perhaps? */ /* scsi bus idle? */ diff --git a/sys/arch/pmax/pmax/disksubr.c b/sys/arch/pmax/pmax/disksubr.c index 0db5dc476a4c..9336a85cd7a6 100644 --- a/sys/arch/pmax/pmax/disksubr.c +++ b/sys/arch/pmax/pmax/disksubr.c @@ -1,4 +1,4 @@ -/* $NetBSD: disksubr.c,v 1.6 1995/08/04 02:34:24 jonathan Exp $ */ +/* $NetBSD: disksubr.c,v 1.7 1996/01/07 22:02:55 thorpej Exp $ */ /* * Copyright (c) 1982, 1986, 1988 Regents of the University of California. @@ -283,7 +283,7 @@ done: */ int dk_establish(dk, dev) - struct dkdevice *dk; + struct disk *dk; struct device *dev; { /* see also arch/alpha/alpha/disksubr.c */ diff --git a/sys/arch/sparc/dev/fd.c b/sys/arch/sparc/dev/fd.c index dedaa245b830..1aada85184e5 100644 --- a/sys/arch/sparc/dev/fd.c +++ b/sys/arch/sparc/dev/fd.c @@ -1,4 +1,4 @@ -/* $NetBSD: fd.c,v 1.15 1995/12/11 12:43:24 pk Exp $ */ +/* $NetBSD: fd.c,v 1.16 1996/01/07 22:02:59 thorpej Exp $ */ /*- * Copyright (c) 1993, 1994, 1995 Charles Hannum. @@ -164,7 +164,8 @@ struct fd_type fd_types[] = { /* software state, per disk (with up to 4 disks per ctlr) */ struct fd_softc { - struct dkdevice sc_dk; + struct device sc_dv; /* generic device info */ + struct disk sc_dk; /* generic disk info */ struct fd_type *sc_deftype; /* default type descriptor */ struct fd_type *sc_type; /* current type descriptor */ @@ -410,6 +411,8 @@ fdcattach(parent, self, aux) fa.fa_deftype = &fd_types[0]; /* XXX */ (void)config_found(self, (void *)&fa, fdprint); } + + bootpath_store(1, NULL); } int @@ -505,16 +508,22 @@ fdattach(parent, self, aux) fd->sc_drive = drive; fd->sc_deftype = type; fdc->sc_fd[drive] = fd; + + /* + * Initialize and attach the disk structure. + */ + fd->sc_dk.dk_name = fd->sc_dv.dv_xname; fd->sc_dk.dk_driver = &fddkdriver; + disk_attach(&fd->sc_dk); /* * We're told if we're the boot device in fdcattach(). */ if (fa->fa_bootdev) - bootdv = &fd->sc_dk.dk_dev; + bootdv = &fd->sc_dv; /* XXX Need to do some more fiddling with sc_dk. */ - dk_establish(&fd->sc_dk, &fd->sc_dk.dk_dev); + dk_establish(&fd->sc_dk, &fd->sc_dv); } inline struct fd_type * @@ -585,7 +594,7 @@ fdstrategy(bp) fdstart(fd); #ifdef DIAGNOSTIC else { - struct fdc_softc *fdc = (void *)fd->sc_dk.dk_dev.dv_parent; + struct fdc_softc *fdc = (void *)fd->sc_dv.dv_parent; if (fdc->sc_state == DEVIDLE) { printf("fdstrategy: controller inactive\n"); fdcstart(fdc); @@ -606,13 +615,16 @@ void fdstart(fd) struct fd_softc *fd; { - struct fdc_softc *fdc = (void *)fd->sc_dk.dk_dev.dv_parent; + struct fdc_softc *fdc = (void *)fd->sc_dv.dv_parent; int active = fdc->sc_drives.tqh_first != 0; /* Link into controller queue. */ fd->sc_q.b_active = 1; TAILQ_INSERT_TAIL(&fdc->sc_drives, fd, sc_drivechain); + /* Instrumentation. */ + disk_busy(&fd->sc_dk); + /* If controller not already active, start it. */ if (!active) fdcstart(fdc); @@ -623,7 +635,7 @@ fdfinish(fd, bp) struct fd_softc *fd; struct buf *bp; { - struct fdc_softc *fdc = (void *)fd->sc_dk.dk_dev.dv_parent; + struct fdc_softc *fdc = (void *)fd->sc_dv.dv_parent; /* * Move this drive to the end of the queue to give others a `fair' @@ -642,6 +654,9 @@ fdfinish(fd, bp) bp->b_resid = fd->sc_bcount; fd->sc_skip = 0; fd->sc_q.b_actf = bp->b_actf; + + disk_unbusy(&fd->sc_dk, (bp->b_bcount - bp->b_resid)); + biodone(bp); /* turn off motor 5s from now */ timeout(fd_motor_off, fd, 5 * hz); @@ -705,7 +720,7 @@ fd_motor_off(arg) s = splbio(); fd->sc_flags &= ~(FD_MOTOR | FD_MOTOR_WAIT); - fd_set_motor((struct fdc_softc *)fd->sc_dk.dk_dev.dv_parent); + fd_set_motor((struct fdc_softc *)fd->sc_dv.dv_parent); splx(s); } @@ -714,7 +729,7 @@ fd_motor_on(arg) void *arg; { struct fd_softc *fd = arg; - struct fdc_softc *fdc = (void *)fd->sc_dk.dk_dev.dv_parent; + struct fdc_softc *fdc = (void *)fd->sc_dv.dv_parent; int s; s = splbio(); @@ -896,7 +911,7 @@ fdctimeout(arg) int s; s = splbio(); - fdcstatus(&fd->sc_dk.dk_dev, 0, "timeout"); + fdcstatus(&fd->sc_dv, 0, "timeout"); if (fd->sc_q.b_actf) fdc->sc_state++; @@ -1174,7 +1189,7 @@ loop: cyl != bp->b_cylin * fd->sc_type->step) { #ifdef FD_DEBUG if (fdc_debug) - fdcstatus(&fd->sc_dk.dk_dev, 2, "seek failed"); + fdcstatus(&fd->sc_dv, 2, "seek failed"); #endif fdcretry(fdc); goto loop; @@ -1198,7 +1213,7 @@ loop: if (fdc->sc_nstat != 7 || (st0 & 0xf8) != 0 || st1 != 0) { #ifdef FD_DEBUG if (fdc_debug) { - fdcstatus(&fd->sc_dk.dk_dev, 7, + fdcstatus(&fd->sc_dv, 7, bp->b_flags & B_READ ? "read failed" : "write failed"); printf("blkno %d nblks %d tc %d\n", @@ -1302,7 +1317,7 @@ loop: if (fdc->sc_nstat != 2 || (st0 & 0xf8) != 0x20 || cyl != 0) { #ifdef FD_DEBUG if (fdc_debug) - fdcstatus(&fd->sc_dk.dk_dev, 2, "recalibrate failed"); + fdcstatus(&fd->sc_dv, 2, "recalibrate failed"); #endif fdcretry(fdc); goto loop; @@ -1316,7 +1331,7 @@ loop: goto doseek; default: - fdcstatus(&fd->sc_dk.dk_dev, 0, "stray interrupt"); + fdcstatus(&fd->sc_dv, 0, "stray interrupt"); return 1; } #ifdef DIAGNOSTIC @@ -1402,18 +1417,18 @@ fdioctl(dev, cmd, addr, flag) switch (cmd) { case DIOCGDINFO: - bzero(&fd->sc_dk.dk_label, sizeof(struct disklabel)); + bzero(fd->sc_dk.dk_label, sizeof(struct disklabel)); - fd->sc_dk.dk_label.d_secpercyl = fd->sc_type->seccyl; - fd->sc_dk.dk_label.d_type = DTYPE_FLOPPY; - fd->sc_dk.dk_label.d_secsize = FDC_BSIZE; + fd->sc_dk.dk_label->d_secpercyl = fd->sc_type->seccyl; + fd->sc_dk.dk_label->d_type = DTYPE_FLOPPY; + fd->sc_dk.dk_label->d_secsize = FDC_BSIZE; if (readdisklabel(dev, fdstrategy, - &fd->sc_dk.dk_label, - &fd->sc_dk.dk_cpulabel) != NULL) + fd->sc_dk.dk_label, + fd->sc_dk.dk_cpulabel) != NULL) return EINVAL; - *(struct disklabel *)addr = fd->sc_dk.dk_label; + *(struct disklabel *)addr = *(fd->sc_dk.dk_label); return 0; case DIOCWLABEL: @@ -1426,28 +1441,29 @@ fdioctl(dev, cmd, addr, flag) if ((flag & FWRITE) == 0) return EBADF; - error = setdisklabel(&fd->sc_dk.dk_label, + error = setdisklabel(fd->sc_dk.dk_label, (struct disklabel *)addr, 0, - &fd->sc_dk.dk_cpulabel); + fd->sc_dk.dk_cpulabel); if (error) return error; error = writedisklabel(dev, fdstrategy, - &fd->sc_dk.dk_label, - &fd->sc_dk.dk_cpulabel); + fd->sc_dk.dk_label, + fd->sc_dk.dk_cpulabel); return error; case DIOCEJECT: auxregbisc(AUXIO_FDS, AUXIO_FEJ); delay(10); auxregbisc(AUXIO_FEJ, AUXIO_FDS); - return 0; + /* FALLTHROUGH */ + #ifdef DEBUG case _IO('f', 100): { int i; struct fdc_softc *fdc = (struct fdc_softc *) - fd->sc_dk.dk_dev.dv_parent; + fd->sc_dv.dv_parent; out_fdc(fdc, NE7CMD_DUMPREG); fdcresult(fdc); @@ -1459,17 +1475,17 @@ fdioctl(dev, cmd, addr, flag) return 0; case _IOW('f', 101, int): - ((struct fdc_softc *)fd->sc_dk.dk_dev.dv_parent)->sc_cfg &= + ((struct fdc_softc *)fd->sc_dv.dv_parent)->sc_cfg &= ~CFG_THRHLD_MASK; - ((struct fdc_softc *)fd->sc_dk.dk_dev.dv_parent)->sc_cfg |= + ((struct fdc_softc *)fd->sc_dv.dv_parent)->sc_cfg |= (*(int *)addr & CFG_THRHLD_MASK); - fdconf(fd->sc_dk.dk_dev.dv_parent); + fdconf(fd->sc_dv.dv_parent); return 0; case _IO('f', 102): { int i; struct fdc_softc *fdc = (struct fdc_softc *) - fd->sc_dk.dk_dev.dv_parent; + fd->sc_dv.dv_parent; out_fdc(fdc, NE7CMD_SENSEI); fdcresult(fdc); printf("sensei(%d regs): <", fdc->sc_nstat); diff --git a/sys/arch/sparc/dev/xd.c b/sys/arch/sparc/dev/xd.c index c900a33a27bb..d59eb66b7381 100644 --- a/sys/arch/sparc/dev/xd.c +++ b/sys/arch/sparc/dev/xd.c @@ -1,4 +1,4 @@ -/* $NetBSD: xd.c,v 1.10 1995/12/11 12:40:20 pk Exp $ */ +/* $NetBSD: xd.c,v 1.11 1996/01/07 22:03:02 thorpej Exp $ */ /* * @@ -36,7 +36,7 @@ * x d . c x y l o g i c s 7 5 3 / 7 0 5 3 v m e / s m d d r i v e r * * author: Chuck Cranor - * id: $Id: xd.c,v 1.10 1995/12/11 12:40:20 pk Exp $ + * id: $Id: xd.c,v 1.11 1996/01/07 22:03:02 thorpej Exp $ * started: 27-Feb-95 * references: [1] Xylogics Model 753 User's Manual * part number: 166-753-001, Revision B, May 21, 1988. @@ -298,35 +298,35 @@ xdgetdisklabel(xd, b) xd_labeldata = b; /* Required parameter for readdisklabel() */ - xd->sc_dk.dk_label.d_secsize = XDFM_BPS; + xd->sc_dk.dk_label->d_secsize = XDFM_BPS; err = readdisklabel(MAKEDISKDEV(0, xd->sc_dev.dv_unit, RAW_PART), xddummystrat, - &xd->sc_dk.dk_label, &xd->sc_dk.dk_cpulabel); + xd->sc_dk.dk_label, xd->sc_dk.dk_cpulabel); if (err) { printf("%s: %s\n", xd->sc_dev.dv_xname, err); return(XD_ERR_FAIL); } /* Ok, we have the label; fill in `pcyl' if there's SunOS magic */ - sdl = (struct sun_disklabel *)xd->sc_dk.dk_cpulabel.cd_block; + sdl = (struct sun_disklabel *)xd->sc_dk.dk_cpulabel->cd_block; if (sdl->sl_magic == SUN_DKMAGIC) xd->pcyl = sdl->sl_pcylinders; else { printf("%s: WARNING: no `pcyl' in disk label.\n", xd->sc_dev.dv_xname); - xd->pcyl = xd->sc_dk.dk_label.d_ncylinders + - xd->sc_dk.dk_label.d_acylinders; + xd->pcyl = xd->sc_dk.dk_label->d_ncylinders + + xd->sc_dk.dk_label->d_acylinders; printf("%s: WARNING: guessing pcyl=%d (ncyl+acyl)\n", xd->sc_dev.dv_xname, xd->pcyl); } - xd->ncyl = xd->sc_dk.dk_label.d_ncylinders; - xd->acyl = xd->sc_dk.dk_label.d_acylinders; - xd->nhead = xd->sc_dk.dk_label.d_ntracks; - xd->nsect = xd->sc_dk.dk_label.d_nsectors; + xd->ncyl = xd->sc_dk.dk_label->d_ncylinders; + xd->acyl = xd->sc_dk.dk_label->d_acylinders; + xd->nhead = xd->sc_dk.dk_label->d_ntracks; + xd->nsect = xd->sc_dk.dk_label->d_nsectors; xd->sectpercyl = xd->nhead * xd->nsect; - xd->sc_dk.dk_label.d_secsize = XDFM_BPS; /* not handled by + xd->sc_dk.dk_label->d_secsize = XDFM_BPS; /* not handled by * sun->bsd */ return(XD_ERR_AOK); } @@ -555,6 +555,14 @@ xdattach(parent, self, aux) struct dkbad *dkb; struct bootpath *bp; + /* + * Always re-initialize the disk structure. We want statistics + * to start with a clean slate. + */ + bzero(&xd->sc_dk, sizeof(xd->sc_dk)); + xd->sc_dk.dk_driver = &xddkdriver; + xd->sc_dk.dk_name = xd->sc_dev.dv_xname; + /* if booting, init the xd_softc */ if (xa->booting) { @@ -711,8 +719,6 @@ xdattach(parent, self, aux) } if (xa->booting) { - xd->sc_dk.dk_driver = &xddkdriver; /* link in dkdriver */ - /* restore bootpath! (do this via attach_args again?)*/ bp = bootpath_store(0, NULL); if (bp && strcmp("xd", bp->name) == 0 && @@ -720,7 +726,10 @@ xdattach(parent, self, aux) bootdv = &xd->sc_dev; } - dk_establish(&xd->sc_dk, &xd->sc_dev); + /* Attach the disk. */ + disk_attach(&xd->sc_dk); + + dk_establish(&xd->sc_dk, &xd->sc_dev); /* XXX */ done: xd->state = newstate; @@ -835,21 +844,21 @@ xdioctl(dev, command, addr, flag, p) return 0; case DIOCGDINFO: /* get disk label */ - bcopy(&xd->sc_dk.dk_label, addr, sizeof(struct disklabel)); + bcopy(xd->sc_dk.dk_label, addr, sizeof(struct disklabel)); return 0; case DIOCGPART: /* get partition info */ - ((struct partinfo *) addr)->disklab = &xd->sc_dk.dk_label; + ((struct partinfo *) addr)->disklab = xd->sc_dk.dk_label; ((struct partinfo *) addr)->part = - &xd->sc_dk.dk_label.d_partitions[DISKPART(dev)]; + &xd->sc_dk.dk_label->d_partitions[DISKPART(dev)]; return 0; case DIOCSDINFO: /* set disk label */ if ((flag & FWRITE) == 0) return EBADF; - error = setdisklabel(&xd->sc_dk.dk_label, + error = setdisklabel(xd->sc_dk.dk_label, (struct disklabel *) addr, /* xd->sc_dk.dk_openmask : */ 0, - &xd->sc_dk.dk_cpulabel); + xd->sc_dk.dk_cpulabel); if (error == 0) { if (xd->state == XD_DRIVE_NOLABEL) xd->state = XD_DRIVE_ONLINE; @@ -868,9 +877,9 @@ xdioctl(dev, command, addr, flag, p) case DIOCWDINFO: /* write disk label */ if ((flag & FWRITE) == 0) return EBADF; - error = setdisklabel(&xd->sc_dk.dk_label, + error = setdisklabel(xd->sc_dk.dk_label, (struct disklabel *) addr, /* xd->sc_dk.dk_openmask : */ 0, - &xd->sc_dk.dk_cpulabel); + xd->sc_dk.dk_cpulabel); if (error == 0) { if (xd->state == XD_DRIVE_NOLABEL) xd->state = XD_DRIVE_ONLINE; @@ -878,8 +887,8 @@ xdioctl(dev, command, addr, flag, p) /* Simulate opening partition 0 so write succeeds. */ xd->sc_dk.dk_openmask |= (1 << 0); error = writedisklabel(MAKEDISKDEV(major(dev), DISKUNIT(dev), RAW_PART), - xdstrategy, &xd->sc_dk.dk_label, - &xd->sc_dk.dk_cpulabel); + xdstrategy, xd->sc_dk.dk_label, + xd->sc_dk.dk_cpulabel); xd->sc_dk.dk_openmask = xd->sc_dk.dk_copenmask | xd->sc_dk.dk_bopenmask; } @@ -932,8 +941,8 @@ xdopen(dev, flag, fmt) /* check for partition */ if (part != RAW_PART && - (part >= xd->sc_dk.dk_label.d_npartitions || - xd->sc_dk.dk_label.d_partitions[part].p_fstype == FS_UNUSED)) { + (part >= xd->sc_dk.dk_label->d_npartitions || + xd->sc_dk.dk_label->d_partitions[part].p_fstype == FS_UNUSED)) { return (ENXIO); } /* set open masks */ @@ -991,10 +1000,10 @@ xdsize(dev) xdsc = xdcd.cd_devs[DISKUNIT(dev)]; part = DISKPART(dev); - if (xdsc->sc_dk.dk_label.d_partitions[part].p_fstype != FS_SWAP) + if (xdsc->sc_dk.dk_label->d_partitions[part].p_fstype != FS_SWAP) size = -1; /* only give valid size for swap partitions */ else - size = xdsc->sc_dk.dk_label.d_partitions[part].p_size; + size = xdsc->sc_dk.dk_label->d_partitions[part].p_size; if (xdclose(dev, 0, S_IFBLK) != 0) return -1; return size; @@ -1020,7 +1029,7 @@ xdstrategy(bp) if (unit >= xdcd.cd_ndevs || (xd = xdcd.cd_devs[unit]) == 0 || bp->b_blkno < 0 || - (bp->b_bcount % xd->sc_dk.dk_label.d_secsize) != 0) { + (bp->b_bcount % xd->sc_dk.dk_label->d_secsize) != 0) { bp->b_error = EINVAL; goto bad; } @@ -1053,7 +1062,7 @@ xdstrategy(bp) * partition. Adjust transfer if needed, and signal errors or early * completion. */ - if (bounds_check_with_label(bp, &xd->sc_dk.dk_label, + if (bounds_check_with_label(bp, xd->sc_dk.dk_label, (xd->flags & XD_WLABEL) != 0) <= 0) goto done; @@ -1091,6 +1100,10 @@ xdstrategy(bp) if (xdc_startbuf(parent, xd, bp) != XD_ERR_AOK) { return; } + + /* Instrumentation. */ + disk_busy(&xd->sc_dk); + /* done! */ splx(s); @@ -1412,7 +1425,7 @@ xdc_startbuf(xdcsc, xdsc, bp) */ block = bp->b_blkno + ((partno == RAW_PART) ? 0 : - xdsc->sc_dk.dk_label.d_partitions[partno].p_offset); + xdsc->sc_dk.dk_label->d_partitions[partno].p_offset); dbuf = kdvma_mapin(bp->b_data, bp->b_bcount, 0); if (dbuf == NULL) { /* out of DVMA space */ @@ -1715,6 +1728,9 @@ xdc_reset(xdcsc, quiet, blastmode, error, xdsc) (vm_offset_t)iorq->dbufbase, (vm_offset_t)iorq->buf->b_un.b_addr, iorq->buf->b_bcount); + disk_unbusy(&xdcsc->reqs[lcv].xd->sc_dk, + (xdcsc->reqs[lcv].buf->b_bcount - + xdcsc->reqs[lcv].buf->b_resid)); biodone(iorq->buf); XDC_FREE(xdcsc, lcv); /* add to free list */ break; @@ -1920,6 +1936,8 @@ xdc_remove_iorq(xdcsc) (vm_offset_t) bp->b_un.b_addr, bp->b_bcount); XDC_FREE(xdcsc, rqno); + disk_unbusy(&iorq->xd->sc_dk, + (bp->b_bcount - bp->b_resid)); biodone(bp); break; case XD_SUB_WAIT: diff --git a/sys/arch/sparc/dev/xdvar.h b/sys/arch/sparc/dev/xdvar.h index 5ff3f7c7914e..5417e3953ac3 100644 --- a/sys/arch/sparc/dev/xdvar.h +++ b/sys/arch/sparc/dev/xdvar.h @@ -1,4 +1,4 @@ -/* $NetBSD: xdvar.h,v 1.1 1995/06/26 23:07:19 pk Exp $ */ +/* $NetBSD: xdvar.h,v 1.2 1996/01/07 22:03:04 thorpej Exp $ */ /* * @@ -101,7 +101,7 @@ struct xd_iorq { struct xd_softc { struct device sc_dev; /* device struct, reqd by autoconf */ - struct dkdevice sc_dk; /* dkdevice: hook for iostat */ + struct disk sc_dk; /* generic disk info */ struct xdc_softc *parent; /* parent */ u_short flags; /* flags */ u_short state; /* device state */ diff --git a/sys/arch/sparc/dev/xy.c b/sys/arch/sparc/dev/xy.c index 89b544ee61af..7e7ec851a7f0 100644 --- a/sys/arch/sparc/dev/xy.c +++ b/sys/arch/sparc/dev/xy.c @@ -1,4 +1,4 @@ -/* $NetBSD: xy.c,v 1.2 1995/12/11 12:40:25 pk Exp $ */ +/* $NetBSD: xy.c,v 1.3 1996/01/07 22:03:05 thorpej Exp $ */ /* * @@ -36,7 +36,7 @@ * x y . c x y l o g i c s 4 5 0 / 4 5 1 s m d d r i v e r * * author: Chuck Cranor - * id: $Id: xy.c,v 1.2 1995/12/11 12:40:25 pk Exp $ + * id: $Id: xy.c,v 1.3 1996/01/07 22:03:05 thorpej Exp $ * started: 14-Sep-95 * references: [1] Xylogics Model 753 User's Manual * part number: 166-753-001, Revision B, May 21, 1988. @@ -241,35 +241,35 @@ xygetdisklabel(xy, b) xy_labeldata = b; /* Required parameter for readdisklabel() */ - xy->sc_dk.dk_label.d_secsize = XYFM_BPS; + xy->sc_dk.dk_label->d_secsize = XYFM_BPS; err = readdisklabel(MAKEDISKDEV(0, xy->sc_dev.dv_unit, RAW_PART), xydummystrat, - &xy->sc_dk.dk_label, &xy->sc_dk.dk_cpulabel); + xy->sc_dk.dk_label, xy->sc_dk.dk_cpulabel); if (err) { printf("%s: %s\n", xy->sc_dev.dv_xname, err); return(XY_ERR_FAIL); } /* Ok, we have the label; fill in `pcyl' if there's SunOS magic */ - sdl = (struct sun_disklabel *)xy->sc_dk.dk_cpulabel.cd_block; + sdl = (struct sun_disklabel *)xy->sc_dk.dk_cpulabel->cd_block; if (sdl->sl_magic == SUN_DKMAGIC) xy->pcyl = sdl->sl_pcylinders; else { printf("%s: WARNING: no `pcyl' in disk label.\n", xy->sc_dev.dv_xname); - xy->pcyl = xy->sc_dk.dk_label.d_ncylinders + - xy->sc_dk.dk_label.d_acylinders; + xy->pcyl = xy->sc_dk.dk_label->d_ncylinders + + xy->sc_dk.dk_label->d_acylinders; printf("%s: WARNING: guessing pcyl=%d (ncyl+acyl)\n", xy->sc_dev.dv_xname, xy->pcyl); } - xy->ncyl = xy->sc_dk.dk_label.d_ncylinders; - xy->acyl = xy->sc_dk.dk_label.d_acylinders; - xy->nhead = xy->sc_dk.dk_label.d_ntracks; - xy->nsect = xy->sc_dk.dk_label.d_nsectors; + xy->ncyl = xy->sc_dk.dk_label->d_ncylinders; + xy->acyl = xy->sc_dk.dk_label->d_acylinders; + xy->nhead = xy->sc_dk.dk_label->d_ntracks; + xy->nsect = xy->sc_dk.dk_label->d_nsectors; xy->sectpercyl = xy->nhead * xy->nsect; - xy->sc_dk.dk_label.d_secsize = XYFM_BPS; /* not handled by + xy->sc_dk.dk_label->d_secsize = XYFM_BPS; /* not handled by * sun->bsd */ return(XY_ERR_AOK); } @@ -501,6 +501,14 @@ xyattach(parent, self, aux) struct dkbad *dkb; struct bootpath *bp; + /* + * Always re-initialize the disk structure. We want statistics + * to start with a clean slate. + */ + bzero(&xy->sc_dk, sizeof(xy->sc_dk)); + xy->sc_dk.dk_driver = &xydkdriver; + xy->sc_dk.dk_name = xy->sc_dev.dv_xname; + /* if booting, init the xy_softc */ if (xa->booting) { @@ -675,8 +683,6 @@ xyattach(parent, self, aux) } if (xa->booting) { - xy->sc_dk.dk_driver = &xydkdriver; /* link in dkdriver */ - /* restore bootpath! (do this via attach_args again?)*/ bp = bootpath_store(0, NULL); if (bp && strcmp("xy", bp->name) == 0 && @@ -684,7 +690,10 @@ xyattach(parent, self, aux) bootdv = &xy->sc_dev; } - dk_establish(&xy->sc_dk, &xy->sc_dev); + /* Attach the disk. */ + disk_attach(&xy->sc_dk); + + dk_establish(&xy->sc_dk, &xy->sc_dev); /* XXX */ done: xy->state = newstate; @@ -799,21 +808,21 @@ xyioctl(dev, command, addr, flag, p) return 0; case DIOCGDINFO: /* get disk label */ - bcopy(&xy->sc_dk.dk_label, addr, sizeof(struct disklabel)); + bcopy(xy->sc_dk.dk_label, addr, sizeof(struct disklabel)); return 0; case DIOCGPART: /* get partition info */ - ((struct partinfo *) addr)->disklab = &xy->sc_dk.dk_label; + ((struct partinfo *) addr)->disklab = xy->sc_dk.dk_label; ((struct partinfo *) addr)->part = - &xy->sc_dk.dk_label.d_partitions[DISKPART(dev)]; + &xy->sc_dk.dk_label->d_partitions[DISKPART(dev)]; return 0; case DIOCSDINFO: /* set disk label */ if ((flag & FWRITE) == 0) return EBADF; - error = setdisklabel(&xy->sc_dk.dk_label, + error = setdisklabel(xy->sc_dk.dk_label, (struct disklabel *) addr, /* xy->sc_dk.dk_openmask : */ 0, - &xy->sc_dk.dk_cpulabel); + xy->sc_dk.dk_cpulabel); if (error == 0) { if (xy->state == XY_DRIVE_NOLABEL) xy->state = XY_DRIVE_ONLINE; @@ -832,9 +841,9 @@ xyioctl(dev, command, addr, flag, p) case DIOCWDINFO: /* write disk label */ if ((flag & FWRITE) == 0) return EBADF; - error = setdisklabel(&xy->sc_dk.dk_label, + error = setdisklabel(xy->sc_dk.dk_label, (struct disklabel *) addr, /* xy->sc_dk.dk_openmask : */ 0, - &xy->sc_dk.dk_cpulabel); + xy->sc_dk.dk_cpulabel); if (error == 0) { if (xy->state == XY_DRIVE_NOLABEL) xy->state = XY_DRIVE_ONLINE; @@ -842,8 +851,8 @@ xyioctl(dev, command, addr, flag, p) /* Simulate opening partition 0 so write succeeds. */ xy->sc_dk.dk_openmask |= (1 << 0); error = writedisklabel(MAKEDISKDEV(major(dev), DISKUNIT(dev), RAW_PART), - xystrategy, &xy->sc_dk.dk_label, - &xy->sc_dk.dk_cpulabel); + xystrategy, xy->sc_dk.dk_label, + xy->sc_dk.dk_cpulabel); xy->sc_dk.dk_openmask = xy->sc_dk.dk_copenmask | xy->sc_dk.dk_bopenmask; } @@ -898,8 +907,8 @@ xyopen(dev, flag, fmt) /* check for partition */ if (part != RAW_PART && - (part >= xy->sc_dk.dk_label.d_npartitions || - xy->sc_dk.dk_label.d_partitions[part].p_fstype == FS_UNUSED)) { + (part >= xy->sc_dk.dk_label->d_npartitions || + xy->sc_dk.dk_label->d_partitions[part].p_fstype == FS_UNUSED)) { return (ENXIO); } /* set open masks */ @@ -957,10 +966,10 @@ xysize(dev) xysc = xycd.cd_devs[DISKUNIT(dev)]; part = DISKPART(dev); - if (xysc->sc_dk.dk_label.d_partitions[part].p_fstype != FS_SWAP) + if (xysc->sc_dk.dk_label->d_partitions[part].p_fstype != FS_SWAP) size = -1; /* only give valid size for swap partitions */ else - size = xysc->sc_dk.dk_label.d_partitions[part].p_size; + size = xysc->sc_dk.dk_label->d_partitions[part].p_size; if (xyclose(dev, 0, S_IFBLK) != 0) return -1; return size; @@ -987,7 +996,7 @@ xystrategy(bp) if (unit >= xycd.cd_ndevs || (xy = xycd.cd_devs[unit]) == 0 || bp->b_blkno < 0 || - (bp->b_bcount % xy->sc_dk.dk_label.d_secsize) != 0) { + (bp->b_bcount % xy->sc_dk.dk_label->d_secsize) != 0) { bp->b_error = EINVAL; goto bad; } @@ -1020,7 +1029,7 @@ xystrategy(bp) * partition. Adjust transfer if needed, and signal errors or early * completion. */ - if (bounds_check_with_label(bp, &xy->sc_dk.dk_label, + if (bounds_check_with_label(bp, xy->sc_dk.dk_label, (xy->flags & XY_WLABEL) != 0) <= 0) goto done; @@ -1036,6 +1045,9 @@ xystrategy(bp) xyc_start(xy->parent, NULL); + /* Instrumentation. */ + disk_busy(&xy->sc_dk); + /* done! */ splx(s); @@ -1277,7 +1289,7 @@ xyc_startbuf(xycsc, xysc, bp) */ block = bp->b_blkno + ((partno == RAW_PART) ? 0 : - xysc->sc_dk.dk_label.d_partitions[partno].p_offset); + xysc->sc_dk.dk_label->d_partitions[partno].p_offset); dbuf = kdvma_mapin(bp->b_data, bp->b_bcount, 0); if (dbuf == NULL) { /* out of DVMA space */ @@ -1628,6 +1640,9 @@ xyc_reset(xycsc, quiet, blastmode, error, xysc) (vm_offset_t)iorq->buf->b_un.b_addr, iorq->buf->b_bcount); iorq->xy->xyq.b_actf = iorq->buf->b_actf; + disk_unbusy(&xycsc->reqs[lcv].xy->sc_dk, + (xycsc->reqs[lcv].buf->b_bcount - + xycsc->reqs[lcv].buf->b_resid)); biodone(iorq->buf); iorq->mode = XY_SUB_FREE; break; @@ -1804,6 +1819,8 @@ xyc_remove_iorq(xycsc) bp->b_bcount); iorq->mode = XY_SUB_FREE; iorq->xy->xyq.b_actf = bp->b_actf; + disk_unbusy(&iorq->xy->sc_dk, + (bp->b_bcount - bp->b_resid)); biodone(bp); break; case XY_SUB_WAIT: diff --git a/sys/arch/sparc/dev/xyvar.h b/sys/arch/sparc/dev/xyvar.h index 245cab63f0a6..5296d9fa2021 100644 --- a/sys/arch/sparc/dev/xyvar.h +++ b/sys/arch/sparc/dev/xyvar.h @@ -1,4 +1,4 @@ -/* $NetBSD: xyvar.h,v 1.1 1995/09/25 20:35:17 chuck Exp $ */ +/* $NetBSD: xyvar.h,v 1.2 1996/01/07 22:03:06 thorpej Exp $ */ /* * @@ -101,7 +101,7 @@ struct xy_iorq { struct xy_softc { struct device sc_dev; /* device struct, reqd by autoconf */ - struct dkdevice sc_dk; /* dkdevice: hook for iostat */ + struct disk sc_dk; /* generic disk info */ struct xyc_softc *parent; /* parent */ u_short flags; /* flags */ u_short state; /* device state */ diff --git a/sys/arch/sparc/include/sun_disklabel.h b/sys/arch/sparc/include/sun_disklabel.h index 90fc6803c2e0..8f01b84115d6 100644 --- a/sys/arch/sparc/include/sun_disklabel.h +++ b/sys/arch/sparc/include/sun_disklabel.h @@ -1,4 +1,4 @@ -/* $NetBSD: sun_disklabel.h,v 1.5 1995/06/26 22:09:47 pk Exp $ */ +/* $NetBSD: sun_disklabel.h,v 1.6 1996/01/07 22:03:09 thorpej Exp $ */ /* * Copyright (c) 1992, 1993 @@ -111,5 +111,5 @@ struct sun_disklabel { /* total size = 512 bytes */ int sun_disklabel __P((caddr_t, struct disklabel *)); /* true on success */ /* compatability dk ioctl's */ -int sun_dkioctl __P((struct dkdevice *, u_long, caddr_t, int)); +int sun_dkioctl __P((struct disk *, u_long, caddr_t, int)); #endif diff --git a/sys/arch/sparc/sparc/disksubr.c b/sys/arch/sparc/sparc/disksubr.c index 8c46f7ba03ad..cc5f25e32aa5 100644 --- a/sys/arch/sparc/sparc/disksubr.c +++ b/sys/arch/sparc/sparc/disksubr.c @@ -1,4 +1,4 @@ -/* $NetBSD: disksubr.c,v 1.10 1995/11/29 23:43:42 pk Exp $ */ +/* $NetBSD: disksubr.c,v 1.11 1996/01/07 22:03:12 thorpej Exp $ */ /* * Copyright (c) 1994, 1995 Gordon W. Ross @@ -68,7 +68,7 @@ extern struct device *bootdv; int dk_establish(dk, dev) - struct dkdevice *dk; + struct disk *dk; struct device *dev; { struct bootpath *bp = bootpath_store(0, NULL); /* restore bootpath! */ @@ -488,7 +488,7 @@ disklabel_bsd_to_sun(lp, cp) /* move this to compat/sunos */ int sun_dkioctl(dk, cmd, data, partition) - struct dkdevice *dk; + struct disk *dk; u_long cmd; caddr_t data; int partition; @@ -499,15 +499,15 @@ sun_dkioctl(dk, cmd, data, partition) case DKIOCGGEOM: #define geom ((struct sun_dkgeom *)data) bzero(data, sizeof(*geom)); - geom->sdkc_ncylinders = dk->dk_label.d_ncylinders; - geom->sdkc_acylinders = dk->dk_label.d_acylinders; - geom->sdkc_ntracks = dk->dk_label.d_ntracks; - geom->sdkc_nsectors = dk->dk_label.d_nsectors; - geom->sdkc_interleave = dk->dk_label.d_interleave; - geom->sdkc_sparespercyl = dk->dk_label.d_sparespercyl; - geom->sdkc_rpm = dk->dk_label.d_rpm; + geom->sdkc_ncylinders = dk->dk_label->d_ncylinders; + geom->sdkc_acylinders = dk->dk_label->d_acylinders; + geom->sdkc_ntracks = dk->dk_label->d_ntracks; + geom->sdkc_nsectors = dk->dk_label->d_nsectors; + geom->sdkc_interleave = dk->dk_label->d_interleave; + geom->sdkc_sparespercyl = dk->dk_label->d_sparespercyl; + geom->sdkc_rpm = dk->dk_label->d_rpm; geom->sdkc_pcylinders = - dk->dk_label.d_ncylinders + dk->dk_label.d_acylinders; + dk->dk_label->d_ncylinders + dk->dk_label->d_acylinders; #undef geom break; case DKIOCINFO: @@ -515,13 +515,13 @@ sun_dkioctl(dk, cmd, data, partition) bzero(data, sizeof(struct sun_dkctlr)); break; case DKIOCGPART: - if (dk->dk_label.d_secpercyl == 0) + if (dk->dk_label->d_secpercyl == 0) return (ERANGE); /* XXX */ - p = &dk->dk_label.d_partitions[partition]; - if (p->p_offset % dk->dk_label.d_secpercyl != 0) + p = &dk->dk_label->d_partitions[partition]; + if (p->p_offset % dk->dk_label->d_secpercyl != 0) return (ERANGE); /* XXX */ #define part ((struct sun_dkpart *)data) - part->sdkp_cyloffset = p->p_offset / dk->dk_label.d_secpercyl; + part->sdkp_cyloffset = p->p_offset / dk->dk_label->d_secpercyl; part->sdkp_nsectors = p->p_size; #undef part break; diff --git a/sys/arch/sun3/dev/xd.c b/sys/arch/sun3/dev/xd.c index 0b2b54beb987..2ba20e9f7c68 100644 --- a/sys/arch/sun3/dev/xd.c +++ b/sys/arch/sun3/dev/xd.c @@ -1,4 +1,4 @@ -/* $NetBSD: xd.c,v 1.1 1995/10/30 20:58:17 gwr Exp $ */ +/* $NetBSD: xd.c,v 1.2 1996/01/07 22:03:17 thorpej Exp $ */ /* * @@ -36,7 +36,7 @@ * x d . c x y l o g i c s 7 5 3 / 7 0 5 3 v m e / s m d d r i v e r * * author: Chuck Cranor - * id: $Id: xd.c,v 1.1 1995/10/30 20:58:17 gwr Exp $ + * id: $Id: xd.c,v 1.2 1996/01/07 22:03:17 thorpej Exp $ * started: 27-Feb-95 * references: [1] Xylogics Model 753 User's Manual * part number: 166-753-001, Revision B, May 21, 1988. @@ -295,35 +295,35 @@ xdgetdisklabel(xd, b) xd_labeldata = b; /* Required parameter for readdisklabel() */ - xd->sc_dk.dk_label.d_secsize = XDFM_BPS; + xd->sc_dk.dk_label->d_secsize = XDFM_BPS; err = readdisklabel(MAKEDISKDEV(0, xd->sc_dev.dv_unit, RAW_PART), xddummystrat, - &xd->sc_dk.dk_label, &xd->sc_dk.dk_cpulabel); + xd->sc_dk.dk_label, xd->sc_dk.dk_cpulabel); if (err) { printf("%s: %s\n", xd->sc_dev.dv_xname, err); return(XD_ERR_FAIL); } /* Ok, we have the label; fill in `pcyl' if there's SunOS magic */ - sdl = (struct sun_disklabel *)xd->sc_dk.dk_cpulabel.cd_block; + sdl = (struct sun_disklabel *)xd->sc_dk.dk_cpulabel->cd_block; if (sdl->sl_magic == SUN_DKMAGIC) xd->pcyl = sdl->sl_pcyl; else { printf("%s: WARNING: no `pcyl' in disk label.\n", xd->sc_dev.dv_xname); - xd->pcyl = xd->sc_dk.dk_label.d_ncylinders + - xd->sc_dk.dk_label.d_acylinders; + xd->pcyl = xd->sc_dk.dk_label->d_ncylinders + + xd->sc_dk.dk_label->d_acylinders; printf("%s: WARNING: guessing pcyl=%d (ncyl+acyl)\n", xd->sc_dev.dv_xname, xd->pcyl); } - xd->ncyl = xd->sc_dk.dk_label.d_ncylinders; - xd->acyl = xd->sc_dk.dk_label.d_acylinders; - xd->nhead = xd->sc_dk.dk_label.d_ntracks; - xd->nsect = xd->sc_dk.dk_label.d_nsectors; + xd->ncyl = xd->sc_dk.dk_label->d_ncylinders; + xd->acyl = xd->sc_dk.dk_label->d_acylinders; + xd->nhead = xd->sc_dk.dk_label->d_ntracks; + xd->nsect = xd->sc_dk.dk_label->d_nsectors; xd->sectpercyl = xd->nhead * xd->nsect; - xd->sc_dk.dk_label.d_secsize = XDFM_BPS; /* not handled by + xd->sc_dk.dk_label->d_secsize = XDFM_BPS; /* not handled by * sun->bsd */ return(XD_ERR_AOK); } @@ -525,6 +525,14 @@ xdattach(parent, self, aux) struct dkbad *dkb; struct bootpath *bp; + /* + * Always re-initialize the disk structure. We want statistics + * to start with a clean slate. + */ + bzero(&xd->sc_dk, sizeof(xd->sc_dk)); + xd->sc_dk.dk_driver = &xddkdriver; + xd->sc_dk.dk_name = xd->sc_dev.dv_xname; + /* if booting, init the xd_softc */ if (xa->booting) { @@ -683,9 +691,8 @@ xdattach(parent, self, aux) bcopy(xa->dvmabuf, &xd->dkb, XDFM_BPS); } - if (xa->booting) { - xd->sc_dk.dk_driver = &xddkdriver; /* link in dkdriver */ - } + /* Attach the disk. */ + disk_attach(&xd->sc_dk); /* XXX - Where is this and what does it do? -gwr */ dk_establish(&xd->sc_dk, &xd->sc_dev); @@ -803,21 +810,21 @@ xdioctl(dev, command, addr, flag, p) return 0; case DIOCGDINFO: /* get disk label */ - bcopy(&xd->sc_dk.dk_label, addr, sizeof(struct disklabel)); + bcopy(xd->sc_dk.dk_label, addr, sizeof(struct disklabel)); return 0; case DIOCGPART: /* get partition info */ - ((struct partinfo *) addr)->disklab = &xd->sc_dk.dk_label; + ((struct partinfo *) addr)->disklab = xd->sc_dk.dk_label; ((struct partinfo *) addr)->part = - &xd->sc_dk.dk_label.d_partitions[DISKPART(dev)]; + &xd->sc_dk.dk_label->d_partitions[DISKPART(dev)]; return 0; case DIOCSDINFO: /* set disk label */ if ((flag & FWRITE) == 0) return EBADF; - error = setdisklabel(&xd->sc_dk.dk_label, + error = setdisklabel(xd->sc_dk.dk_label, (struct disklabel *) addr, /* xd->sc_dk.dk_openmask : */ 0, - &xd->sc_dk.dk_cpulabel); + xd->sc_dk.dk_cpulabel); if (error == 0) { if (xd->state == XD_DRIVE_NOLABEL) xd->state = XD_DRIVE_ONLINE; @@ -836,9 +843,9 @@ xdioctl(dev, command, addr, flag, p) case DIOCWDINFO: /* write disk label */ if ((flag & FWRITE) == 0) return EBADF; - error = setdisklabel(&xd->sc_dk.dk_label, + error = setdisklabel(xd->sc_dk.dk_label, (struct disklabel *) addr, /* xd->sc_dk.dk_openmask : */ 0, - &xd->sc_dk.dk_cpulabel); + xd->sc_dk.dk_cpulabel); if (error == 0) { if (xd->state == XD_DRIVE_NOLABEL) xd->state = XD_DRIVE_ONLINE; @@ -846,8 +853,8 @@ xdioctl(dev, command, addr, flag, p) /* Simulate opening partition 0 so write succeeds. */ xd->sc_dk.dk_openmask |= (1 << 0); error = writedisklabel(MAKEDISKDEV(major(dev), DISKUNIT(dev), RAW_PART), - xdstrategy, &xd->sc_dk.dk_label, - &xd->sc_dk.dk_cpulabel); + xdstrategy, xd->sc_dk.dk_label, + xd->sc_dk.dk_cpulabel); xd->sc_dk.dk_openmask = xd->sc_dk.dk_copenmask | xd->sc_dk.dk_bopenmask; } @@ -900,8 +907,8 @@ xdopen(dev, flag, fmt) /* check for partition */ if (part != RAW_PART && - (part >= xd->sc_dk.dk_label.d_npartitions || - xd->sc_dk.dk_label.d_partitions[part].p_fstype == FS_UNUSED)) { + (part >= xd->sc_dk.dk_label->d_npartitions || + xd->sc_dk.dk_label->d_partitions[part].p_fstype == FS_UNUSED)) { return (ENXIO); } /* set open masks */ @@ -959,10 +966,10 @@ xdsize(dev) xdsc = xdcd.cd_devs[DISKUNIT(dev)]; part = DISKPART(dev); - if (xdsc->sc_dk.dk_label.d_partitions[part].p_fstype != FS_SWAP) + if (xdsc->sc_dk.dk_label->d_partitions[part].p_fstype != FS_SWAP) size = -1; /* only give valid size for swap partitions */ else - size = xdsc->sc_dk.dk_label.d_partitions[part].p_size; + size = xdsc->sc_dk.dk_label->d_partitions[part].p_size; if (xdclose(dev, 0, S_IFBLK) != 0) return -1; return size; @@ -988,7 +995,7 @@ xdstrategy(bp) if (unit >= xdcd.cd_ndevs || (xd = xdcd.cd_devs[unit]) == 0 || bp->b_blkno < 0 || - (bp->b_bcount % xd->sc_dk.dk_label.d_secsize) != 0) { + (bp->b_bcount % xd->sc_dk.dk_label->d_secsize) != 0) { bp->b_error = EINVAL; goto bad; } @@ -1021,7 +1028,7 @@ xdstrategy(bp) * partition. Adjust transfer if needed, and signal errors or early * completion. */ - if (bounds_check_with_label(bp, &xd->sc_dk.dk_label, + if (bounds_check_with_label(bp, xd->sc_dk.dk_label, (xd->flags & XD_WLABEL) != 0) <= 0) goto done; @@ -1059,6 +1066,10 @@ xdstrategy(bp) if (xdc_startbuf(parent, xd, bp) != XD_ERR_AOK) { return; } + + /* Instrumentation. */ + disk_busy(&xd->sc_dk); + /* done! */ splx(s); @@ -1392,7 +1403,7 @@ xdc_startbuf(xdcsc, xdsc, bp) */ block = bp->b_blkno + ((partno == RAW_PART) ? 0 : - xdsc->sc_dk.dk_label.d_partitions[partno].p_offset); + xdsc->sc_dk.dk_label->d_partitions[partno].p_offset); dbuf = dvma_mapin(bp->b_data, bp->b_bcount); if (dbuf == NULL) { /* out of DVMA space */ @@ -1694,6 +1705,8 @@ xdc_reset(xdcsc, quiet, blastmode, error, xdsc) /* Sun3: map/unmap regardless of B_PHYS */ dvma_mapout(iorq->dbufbase, iorq->buf->b_bcount); + disk_unbusy(&iorq->xd->sc_dk, + (iorq->buf->b_bcount - iorq->buf->b_resid)); biodone(iorq->buf); XDC_FREE(xdcsc, lcv); /* add to free list */ break; @@ -1899,6 +1912,8 @@ xdc_remove_iorq(xdcsc) dvma_mapout(iorq->dbufbase, iorq->buf->b_bcount); XDC_FREE(xdcsc, rqno); + disk_unbusy(&iorq->xd->sc_dk, + (bp->b_bcount - bp->b_resid)); biodone(bp); break; case XD_SUB_WAIT: diff --git a/sys/arch/sun3/dev/xdvar.h b/sys/arch/sun3/dev/xdvar.h index 918c22d1f3d7..096d01e05660 100644 --- a/sys/arch/sun3/dev/xdvar.h +++ b/sys/arch/sun3/dev/xdvar.h @@ -1,4 +1,4 @@ -/* $NetBSD: xdvar.h,v 1.1 1995/10/30 20:58:19 gwr Exp $ */ +/* $NetBSD: xdvar.h,v 1.2 1996/01/07 22:03:18 thorpej Exp $ */ /* * @@ -101,7 +101,7 @@ struct xd_iorq { struct xd_softc { struct device sc_dev; /* device struct, reqd by autoconf */ - struct dkdevice sc_dk; /* dkdevice: hook for iostat */ + struct disk sc_dk; /* generic disk info */ struct xdc_softc *parent; /* parent */ u_short flags; /* flags */ u_short state; /* device state */ diff --git a/sys/arch/sun3/dev/xy.c b/sys/arch/sun3/dev/xy.c index a85e58250805..c004cb0da622 100644 --- a/sys/arch/sun3/dev/xy.c +++ b/sys/arch/sun3/dev/xy.c @@ -1,4 +1,4 @@ -/* $NetBSD: xy.c,v 1.1 1995/10/30 20:58:21 gwr Exp $ */ +/* $NetBSD: xy.c,v 1.2 1996/01/07 22:03:20 thorpej Exp $ */ /* * @@ -36,7 +36,7 @@ * x y . c x y l o g i c s 4 5 0 / 4 5 1 s m d d r i v e r * * author: Chuck Cranor - * id: $Id: xy.c,v 1.1 1995/10/30 20:58:21 gwr Exp $ + * id: $Id: xy.c,v 1.2 1996/01/07 22:03:20 thorpej Exp $ * started: 14-Sep-95 * references: [1] Xylogics Model 753 User's Manual * part number: 166-753-001, Revision B, May 21, 1988. @@ -238,35 +238,35 @@ xygetdisklabel(xy, b) xy_labeldata = b; /* Required parameter for readdisklabel() */ - xy->sc_dk.dk_label.d_secsize = XYFM_BPS; + xy->sc_dk.dk_label->d_secsize = XYFM_BPS; err = readdisklabel(MAKEDISKDEV(0, xy->sc_dev.dv_unit, RAW_PART), xydummystrat, - &xy->sc_dk.dk_label, &xy->sc_dk.dk_cpulabel); + xy->sc_dk.dk_label, xy->sc_dk.dk_cpulabel); if (err) { printf("%s: %s\n", xy->sc_dev.dv_xname, err); return(XY_ERR_FAIL); } /* Ok, we have the label; fill in `pcyl' if there's SunOS magic */ - sdl = (struct sun_disklabel *)xy->sc_dk.dk_cpulabel.cd_block; + sdl = (struct sun_disklabel *)xy->sc_dk.dk_cpulabel->cd_block; if (sdl->sl_magic == SUN_DKMAGIC) xy->pcyl = sdl->sl_pcyl; else { printf("%s: WARNING: no `pcyl' in disk label.\n", xy->sc_dev.dv_xname); - xy->pcyl = xy->sc_dk.dk_label.d_ncylinders + - xy->sc_dk.dk_label.d_acylinders; + xy->pcyl = xy->sc_dk.dk_label->d_ncylinders + + xy->sc_dk.dk_label->d_acylinders; printf("%s: WARNING: guessing pcyl=%d (ncyl+acyl)\n", xy->sc_dev.dv_xname, xy->pcyl); } - xy->ncyl = xy->sc_dk.dk_label.d_ncylinders; - xy->acyl = xy->sc_dk.dk_label.d_acylinders; - xy->nhead = xy->sc_dk.dk_label.d_ntracks; - xy->nsect = xy->sc_dk.dk_label.d_nsectors; + xy->ncyl = xy->sc_dk.dk_label->d_ncylinders; + xy->acyl = xy->sc_dk.dk_label->d_acylinders; + xy->nhead = xy->sc_dk.dk_label->d_ntracks; + xy->nsect = xy->sc_dk.dk_label->d_nsectors; xy->sectpercyl = xy->nhead * xy->nsect; - xy->sc_dk.dk_label.d_secsize = XYFM_BPS; /* not handled by + xy->sc_dk.dk_label->d_secsize = XYFM_BPS; /* not handled by * sun->bsd */ return(XY_ERR_AOK); } @@ -472,6 +472,14 @@ xyattach(parent, self, aux) struct dkbad *dkb; struct bootpath *bp; + /* + * Always re-initialize the disk structure. We want statistics + * to start with a clean slate. + */ + bzero(&xy->sc_dk, sizeof(xy->sc_dk)); + xy->sc_dk.dk_driver = &xydkdriver; + xy->sc_dk.dk_name = xy->sc_dev.dv_xname; + /* if booting, init the xy_softc */ if (xa->booting) { @@ -645,11 +653,10 @@ xyattach(parent, self, aux) bcopy(xa->dvmabuf, &xy->dkb, XYFM_BPS); } - if (xa->booting) { - xy->sc_dk.dk_driver = &xydkdriver; /* link in dkdriver */ - } + /* Attach the disk. */ + disk_attach(&xy->sc_dk); - dk_establish(&xy->sc_dk, &xy->sc_dev); + dk_establish(&xy->sc_dk, &xy->sc_dev); /* XXX */ done: xy->state = newstate; @@ -764,21 +771,21 @@ xyioctl(dev, command, addr, flag, p) return 0; case DIOCGDINFO: /* get disk label */ - bcopy(&xy->sc_dk.dk_label, addr, sizeof(struct disklabel)); + bcopy(xy->sc_dk.dk_label, addr, sizeof(struct disklabel)); return 0; case DIOCGPART: /* get partition info */ - ((struct partinfo *) addr)->disklab = &xy->sc_dk.dk_label; + ((struct partinfo *) addr)->disklab = xy->sc_dk.dk_label; ((struct partinfo *) addr)->part = - &xy->sc_dk.dk_label.d_partitions[DISKPART(dev)]; + &xy->sc_dk.dk_label->d_partitions[DISKPART(dev)]; return 0; case DIOCSDINFO: /* set disk label */ if ((flag & FWRITE) == 0) return EBADF; - error = setdisklabel(&xy->sc_dk.dk_label, + error = setdisklabel(xy->sc_dk.dk_label, (struct disklabel *) addr, /* xy->sc_dk.dk_openmask : */ 0, - &xy->sc_dk.dk_cpulabel); + xy->sc_dk.dk_cpulabel); if (error == 0) { if (xy->state == XY_DRIVE_NOLABEL) xy->state = XY_DRIVE_ONLINE; @@ -797,9 +804,9 @@ xyioctl(dev, command, addr, flag, p) case DIOCWDINFO: /* write disk label */ if ((flag & FWRITE) == 0) return EBADF; - error = setdisklabel(&xy->sc_dk.dk_label, + error = setdisklabel(xy->sc_dk.dk_label, (struct disklabel *) addr, /* xy->sc_dk.dk_openmask : */ 0, - &xy->sc_dk.dk_cpulabel); + xy->sc_dk.dk_cpulabel); if (error == 0) { if (xy->state == XY_DRIVE_NOLABEL) xy->state = XY_DRIVE_ONLINE; @@ -807,8 +814,8 @@ xyioctl(dev, command, addr, flag, p) /* Simulate opening partition 0 so write succeeds. */ xy->sc_dk.dk_openmask |= (1 << 0); error = writedisklabel(MAKEDISKDEV(major(dev), DISKUNIT(dev), RAW_PART), - xystrategy, &xy->sc_dk.dk_label, - &xy->sc_dk.dk_cpulabel); + xystrategy, xy->sc_dk.dk_label, + xy->sc_dk.dk_cpulabel); xy->sc_dk.dk_openmask = xy->sc_dk.dk_copenmask | xy->sc_dk.dk_bopenmask; } @@ -863,8 +870,8 @@ xyopen(dev, flag, fmt) /* check for partition */ if (part != RAW_PART && - (part >= xy->sc_dk.dk_label.d_npartitions || - xy->sc_dk.dk_label.d_partitions[part].p_fstype == FS_UNUSED)) { + (part >= xy->sc_dk.dk_label->d_npartitions || + xy->sc_dk.dk_label->d_partitions[part].p_fstype == FS_UNUSED)) { return (ENXIO); } /* set open masks */ @@ -922,10 +929,10 @@ xysize(dev) xysc = xycd.cd_devs[DISKUNIT(dev)]; part = DISKPART(dev); - if (xysc->sc_dk.dk_label.d_partitions[part].p_fstype != FS_SWAP) + if (xysc->sc_dk.dk_label->d_partitions[part].p_fstype != FS_SWAP) size = -1; /* only give valid size for swap partitions */ else - size = xysc->sc_dk.dk_label.d_partitions[part].p_size; + size = xysc->sc_dk.dk_label->d_partitions[part].p_size; if (xyclose(dev, 0, S_IFBLK) != 0) return -1; return size; @@ -952,7 +959,7 @@ xystrategy(bp) if (unit >= xycd.cd_ndevs || (xy = xycd.cd_devs[unit]) == 0 || bp->b_blkno < 0 || - (bp->b_bcount % xy->sc_dk.dk_label.d_secsize) != 0) { + (bp->b_bcount % xy->sc_dk.dk_label->d_secsize) != 0) { bp->b_error = EINVAL; goto bad; } @@ -985,7 +992,7 @@ xystrategy(bp) * partition. Adjust transfer if needed, and signal errors or early * completion. */ - if (bounds_check_with_label(bp, &xy->sc_dk.dk_label, + if (bounds_check_with_label(bp, xy->sc_dk.dk_label, (xy->flags & XY_WLABEL) != 0) <= 0) goto done; @@ -1002,6 +1009,9 @@ xystrategy(bp) xyc_start(xy->parent, NULL); + /* Instrumentation. */ + disk_busy(&xy->sc_dk); + /* done! */ splx(s); @@ -1257,7 +1267,7 @@ xyc_startbuf(xycsc, xysc, bp) */ block = bp->b_blkno + ((partno == RAW_PART) ? 0 : - xysc->sc_dk.dk_label.d_partitions[partno].p_offset); + xysc->sc_dk.dk_label->d_partitions[partno].p_offset); dbuf = dvma_mapin(bp->b_data, bp->b_bcount); if (dbuf == NULL) { /* out of DVMA space */ @@ -1612,6 +1622,8 @@ xyc_reset(xycsc, quiet, blastmode, error, xysc) iorq->buf->b_bcount); iorq->xy->xyq.b_actf = iorq->buf->b_actf; + disk_unbusy(&iorq->xy->sc_dk, + (iorq->buf->b_bcount - iorq->buf->b_resid)); biodone(iorq->buf); iorq->mode = XY_SUB_FREE; break; @@ -1788,6 +1800,8 @@ xyc_remove_iorq(xycsc) iorq->buf->b_bcount); iorq->mode = XY_SUB_FREE; iorq->xy->xyq.b_actf = bp->b_actf; + disk_unbusy(&iorq->xy->sc_dk, + (bp->b_bcount - bp->b_resid)); biodone(bp); break; case XY_SUB_WAIT: diff --git a/sys/arch/sun3/dev/xyvar.h b/sys/arch/sun3/dev/xyvar.h index 02fe755dc722..e54175d02e7f 100644 --- a/sys/arch/sun3/dev/xyvar.h +++ b/sys/arch/sun3/dev/xyvar.h @@ -1,4 +1,4 @@ -/* $NetBSD: xyvar.h,v 1.1 1995/10/30 20:58:23 gwr Exp $ */ +/* $NetBSD: xyvar.h,v 1.2 1996/01/07 22:03:22 thorpej Exp $ */ /* * @@ -101,7 +101,7 @@ struct xy_iorq { struct xy_softc { struct device sc_dev; /* device struct, reqd by autoconf */ - struct dkdevice sc_dk; /* dkdevice: hook for iostat */ + struct disk sc_dk; /* generic disk info */ struct xyc_softc *parent; /* parent */ u_short flags; /* flags */ u_short state; /* device state */ diff --git a/sys/dev/ata/wd.c b/sys/dev/ata/wd.c index bcc4a55d4d91..6b94916a7d42 100644 --- a/sys/dev/ata/wd.c +++ b/sys/dev/ata/wd.c @@ -1,4 +1,4 @@ -/* $NetBSD: wd.c,v 1.143 1995/12/24 02:31:59 mycroft Exp $ */ +/* $NetBSD: wd.c,v 1.144 1996/01/07 22:03:41 thorpej Exp $ */ /* * Copyright (c) 1994, 1995 Charles M. Hannum. All rights reserved. @@ -32,8 +32,6 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#define INSTRUMENT /* instrumentation stuff by Brad Parker */ - #include #include #include @@ -77,7 +75,7 @@ struct wd_softc { struct device sc_dev; - struct dkdevice sc_dk; + struct disk sc_dk; /* Information about the current transfer: */ daddr_t sc_blkno; /* starting block number */ @@ -289,6 +287,13 @@ wdattach(parent, self, aux) wd->sc_drive = wa->wa_drive; + /* + * Initialize and attach the disk structure. + */ + wd->sc_dk.dk_driver = &wddkdriver; + wd->sc_dk.dk_name = wd->sc_dev.dv_xname; + disk_attach(&wd->sc_dk); + wd_get_parms(wd); for (blank = 0, p = wd->sc_params.wdp_model, q = buf, i = 0; i < sizeof(wd->sc_params.wdp_model); i++) { @@ -337,8 +342,6 @@ wdattach(parent, self, aux) printf(" lba addressing\n"); else printf(" chs addressing\n"); - - wd->sc_dk.dk_driver = &wddkdriver; } /* @@ -354,8 +357,8 @@ wdstrategy(bp) /* Valid request? */ if (bp->b_blkno < 0 || - (bp->b_bcount % wd->sc_dk.dk_label.d_secsize) != 0 || - (bp->b_bcount / wd->sc_dk.dk_label.d_secsize) >= (1 << NBBY)) { + (bp->b_bcount % wd->sc_dk.dk_label->d_secsize) != 0 || + (bp->b_bcount / wd->sc_dk.dk_label->d_secsize) >= (1 << NBBY)) { bp->b_error = EINVAL; goto bad; } @@ -375,7 +378,7 @@ wdstrategy(bp) * If end of partition, just return. */ if (WDPART(bp->b_dev) != RAW_PART && - bounds_check_with_label(bp, &wd->sc_dk.dk_label, + bounds_check_with_label(bp, wd->sc_dk.dk_label, (wd->sc_flags & (WDF_WLABEL|WDF_LABELLING)) != 0) <= 0) goto done; @@ -417,6 +420,9 @@ wdstart(wd) /* Link onto controller queue. */ wd->sc_q.b_active = 1; TAILQ_INSERT_TAIL(&wdc->sc_drives, wd, sc_drivechain); + + /* Instrumentation. */ + disk_busy(&wd->sc_dk); /* If controller not already active, start it. */ if (!active) @@ -450,6 +456,9 @@ wdfinish(wd, bp) bp->b_resid = wd->sc_bcount; wd->sc_skip = 0; wd->sc_q.b_actf = bp->b_actf; + + disk_unbusy(&wd->sc_dk, (bp->b_bcount - bp->b_resid)); + biodone(bp); } @@ -549,7 +558,7 @@ loop: } } - lp = &wd->sc_dk.dk_label; + lp = wd->sc_dk.dk_label; /* When starting a transfer... */ if (wd->sc_skip == 0) { @@ -914,8 +923,8 @@ wdopen(dev, flag, fmt) /* Check that the partition exists. */ if (part != RAW_PART && - (part >= wd->sc_dk.dk_label.d_npartitions || - wd->sc_dk.dk_label.d_partitions[part].p_fstype == FS_UNUSED)) { + (part >= wd->sc_dk.dk_label->d_npartitions || + wd->sc_dk.dk_label->d_partitions[part].p_fstype == FS_UNUSED)) { error = ENXIO; goto bad; } @@ -983,11 +992,11 @@ void wdgetdisklabel(wd) struct wd_softc *wd; { - struct disklabel *lp = &wd->sc_dk.dk_label; + struct disklabel *lp = wd->sc_dk.dk_label; char *errstring; bzero(lp, sizeof(struct disklabel)); - bzero(&wd->sc_dk.dk_cpulabel, sizeof(struct cpu_disklabel)); + bzero(wd->sc_dk.dk_cpulabel, sizeof(struct cpu_disklabel)); lp->d_secsize = DEV_BSIZE; lp->d_ntracks = wd->sc_params.wdp_heads; @@ -1020,7 +1029,7 @@ wdgetdisklabel(wd) if (wd->sc_state > RECAL) wd->sc_state = RECAL; errstring = readdisklabel(MAKEWDDEV(0, wd->sc_dev.dv_unit, RAW_PART), - wdstrategy, lp, &wd->sc_dk.dk_cpulabel); + wdstrategy, lp, wd->sc_dk.dk_cpulabel); if (errstring) { /* * This probably happened because the drive's default @@ -1031,7 +1040,7 @@ wdgetdisklabel(wd) if (wd->sc_state > GEOMETRY) wd->sc_state = GEOMETRY; errstring = readdisklabel(MAKEWDDEV(0, wd->sc_dev.dv_unit, RAW_PART), - wdstrategy, lp, &wd->sc_dk.dk_cpulabel); + wdstrategy, lp, wd->sc_dk.dk_cpulabel); } if (errstring) { printf("%s: %s\n", wd->sc_dev.dv_xname, errstring); @@ -1149,8 +1158,8 @@ wdcommand(wd, command, cylin, head, sector, count) return -1; /* Load parameters. */ - if (wd->sc_dk.dk_label.d_type == DTYPE_ST506) - outb(iobase+wd_precomp, wd->sc_dk.dk_label.d_precompcyl / 4); + if (wd->sc_dk.dk_label->d_type == DTYPE_ST506) + outb(iobase+wd_precomp, wd->sc_dk.dk_label->d_precompcyl / 4); else outb(iobase+wd_features, 0); outb(iobase+wd_cyl_lo, cylin); @@ -1197,13 +1206,13 @@ wdsetctlr(wd) #ifdef WDDEBUG printf("wd(%d,%d) C%dH%dS%d\n", wd->sc_dev.dv_unit, wd->sc_drive, - wd->sc_dk.dk_label.d_ncylinders, wd->sc_dk.dk_label.d_ntracks, - wd->sc_dk.dk_label.d_nsectors); + wd->sc_dk.dk_label->d_ncylinders, wd->sc_dk.dk_label->d_ntracks, + wd->sc_dk.dk_label->d_nsectors); #endif - if (wdcommand(wd, WDCC_IDP, wd->sc_dk.dk_label.d_ncylinders, - wd->sc_dk.dk_label.d_ntracks - 1, 0, wd->sc_dk.dk_label.d_nsectors) - != 0) { + if (wdcommand(wd, WDCC_IDP, wd->sc_dk.dk_label->d_ncylinders, + wd->sc_dk.dk_label->d_ntracks - 1, 0, + wd->sc_dk.dk_label->d_nsectors) != 0) { wderror(wd, NULL, "wdsetctlr: geometry upload failed"); return -1; } @@ -1248,9 +1257,9 @@ wd_get_parms(wd) * This geometry is only used to read the MBR and print a * (false) attach message. */ - strncpy(wd->sc_dk.dk_label.d_typename, "ST506", - sizeof wd->sc_dk.dk_label.d_typename); - wd->sc_dk.dk_label.d_type = DTYPE_ST506; + strncpy(wd->sc_dk.dk_label->d_typename, "ST506", + sizeof wd->sc_dk.dk_label->d_typename); + wd->sc_dk.dk_label->d_type = DTYPE_ST506; strncpy(wd->sc_params.wdp_model, "unknown", sizeof wd->sc_params.wdp_model); @@ -1262,9 +1271,9 @@ wd_get_parms(wd) wd->sc_params.wdp_usedmovsd = 0; wd->sc_params.wdp_capabilities = 0; } else { - strncpy(wd->sc_dk.dk_label.d_typename, "ESDI/IDE", - sizeof wd->sc_dk.dk_label.d_typename); - wd->sc_dk.dk_label.d_type = DTYPE_ESDI; + strncpy(wd->sc_dk.dk_label->d_typename, "ESDI/IDE", + sizeof wd->sc_dk.dk_label->d_typename); + wd->sc_dk.dk_label->d_type = DTYPE_ESDI; /* Read in parameter block. */ insw(wdc->sc_iobase+wd_data, tb, sizeof(tb) / sizeof(short)); @@ -1306,19 +1315,19 @@ wdioctl(dev, cmd, addr, flag, p) case DIOCSBAD: if ((flag & FWRITE) == 0) return EBADF; - wd->sc_dk.dk_cpulabel.bad = *(struct dkbad *)addr; - wd->sc_dk.dk_label.d_flags |= D_BADSECT; + wd->sc_dk.dk_cpulabel->bad = *(struct dkbad *)addr; + wd->sc_dk.dk_label->d_flags |= D_BADSECT; bad144intern(wd); return 0; case DIOCGDINFO: - *(struct disklabel *)addr = wd->sc_dk.dk_label; + *(struct disklabel *)addr = *(wd->sc_dk.dk_label); return 0; case DIOCGPART: - ((struct partinfo *)addr)->disklab = &wd->sc_dk.dk_label; + ((struct partinfo *)addr)->disklab = wd->sc_dk.dk_label; ((struct partinfo *)addr)->part = - &wd->sc_dk.dk_label.d_partitions[WDPART(dev)]; + &wd->sc_dk.dk_label->d_partitions[WDPART(dev)]; return 0; case DIOCWDINFO: @@ -1330,16 +1339,16 @@ wdioctl(dev, cmd, addr, flag, p) return error; wd->sc_flags |= WDF_LABELLING; - error = setdisklabel(&wd->sc_dk.dk_label, + error = setdisklabel(wd->sc_dk.dk_label, (struct disklabel *)addr, /*wd->sc_dk.dk_openmask : */0, - &wd->sc_dk.dk_cpulabel); + wd->sc_dk.dk_cpulabel); if (error == 0) { if (wd->sc_state > GEOMETRY) wd->sc_state = GEOMETRY; if (cmd == DIOCWDINFO) error = writedisklabel(WDLABELDEV(dev), - wdstrategy, &wd->sc_dk.dk_label, - &wd->sc_dk.dk_cpulabel); + wdstrategy, wd->sc_dk.dk_label, + wd->sc_dk.dk_cpulabel); } wd->sc_flags &= ~WDF_LABELLING; @@ -1372,7 +1381,7 @@ wdioctl(dev, cmd, addr, flag, p) auio.uio_resid = fop->df_count; auio.uio_segflg = 0; auio.uio_offset = - fop->df_startblk * wd->sc_dk.dk_label.d_secsize; + fop->df_startblk * wd->sc_dk.dk_label->d_secsize; auio.uio_procp = p; error = physio(wdformat, NULL, dev, B_WRITE, minphys, &auio); @@ -1382,7 +1391,7 @@ wdioctl(dev, cmd, addr, flag, p) return error; } #endif - + default: return ENOTTY; } @@ -1414,10 +1423,10 @@ wdsize(dev) return -1; wd = wdcd.cd_devs[WDUNIT(dev)]; part = WDPART(dev); - if (wd->sc_dk.dk_label.d_partitions[part].p_fstype != FS_SWAP) + if (wd->sc_dk.dk_label->d_partitions[part].p_fstype != FS_SWAP) size = -1; else - size = wd->sc_dk.dk_label.d_partitions[part].p_size; + size = wd->sc_dk.dk_label->d_partitions[part].p_size; if (wdclose(dev, 0, S_IFBLK) != 0) return -1; return size; @@ -1466,7 +1475,7 @@ wddump(dev, blkno, va, size) wdc = (void *)wd->sc_dev.dv_parent; /* Convert to disk sectors. Request must be a multiple of size. */ - lp = &wd->sc_dk.dk_label; + lp = wd->sc_dk.dk_label; if ((size % lp->d_secsize) != 0) return EFAULT; nblks = size / lp->d_secsize; @@ -1578,8 +1587,8 @@ void bad144intern(wd) struct wd_softc *wd; { - struct dkbad *bt = &wd->sc_dk.dk_cpulabel.bad; - struct disklabel *lp = &wd->sc_dk.dk_label; + struct dkbad *bt = &wd->sc_dk.dk_cpulabel->bad; + struct disklabel *lp = wd->sc_dk.dk_label; int i = 0; for (; i < 126; i++) { @@ -1719,7 +1728,7 @@ wderror(dev, bp, msg) if (bp) { diskerr(bp, "wd", msg, LOG_PRINTF, wd->sc_skip / DEV_BSIZE, - &wd->sc_dk.dk_label); + wd->sc_dk.dk_label); printf("\n"); } else printf("%s: %s: status %b error %b\n", wdc->sc_dev.dv_xname, diff --git a/sys/dev/ccd.c b/sys/dev/ccd.c index c8d33a4b867e..6d657fa7844a 100644 --- a/sys/dev/ccd.c +++ b/sys/dev/ccd.c @@ -1,4 +1,4 @@ -/* $NetBSD: ccd.c,v 1.22 1995/12/08 19:13:26 thorpej Exp $ */ +/* $NetBSD: ccd.c,v 1.23 1996/01/07 22:03:28 thorpej Exp $ */ /* * Copyright (c) 1995 Jason R. Thorpe. @@ -89,7 +89,6 @@ #include #include #include -#include #include #include #include @@ -202,10 +201,6 @@ ccdattach(num) numccd = num; bzero(ccd_softc, num * sizeof(struct ccd_softc)); bzero(ccddevs, num * sizeof(struct ccddevice)); - - /* XXX: is this necessary? */ - for (i = 0; i < numccd; ++i) - ccddevs[i].ccd_dk = -1; } static int @@ -232,12 +227,10 @@ ccdinit(ccd, cpaths, p) 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; + sprintf(cs->sc_xname, "ccd%d", ccd->ccd_unit); /* XXX */ /* Allocate space for the component info. */ cs->sc_cinfo = malloc(cs->sc_nccdisks * sizeof(struct ccdcinfo), @@ -262,8 +255,8 @@ ccdinit(ccd, cpaths, p) MAXPATHLEN, &ci->ci_pathlen)) { #ifdef DEBUG if (ccddebug & (CCDB_FOLLOW|CCDB_INIT)) - printf("ccd%d: can't copy path, error = %d\n", - ccd->ccd_unit, error); + printf("%s: can't copy path, error = %d\n", + cs->sc_xname, error); #endif free(cs->sc_cinfo, M_DEVBUF); return (error); @@ -277,8 +270,8 @@ ccdinit(ccd, cpaths, p) 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, + printf("%s: %s: getattr failed %s = %d\n", + cs->sc_xname, ci->ci_path, "error", error); #endif free(ci->ci_path, M_DEVBUF); @@ -294,8 +287,8 @@ ccdinit(ccd, cpaths, p) FREAD, p->p_ucred, p)) { #ifdef DEBUG if (ccddebug & (CCDB_FOLLOW|CCDB_INIT)) - printf("ccd%d: %s: ioctl failed, error = %d\n", - ccd->ccd_unit, ci->ci_path, error); + printf("%s: %s: ioctl failed, error = %d\n", + cs->sc_xname, ci->ci_path, error); #endif free(ci->ci_path, M_DEVBUF); free(cs->sc_cinfo, M_DEVBUF); @@ -309,8 +302,8 @@ ccdinit(ccd, cpaths, p) } else { #ifdef DEBUG if (ccddebug & (CCDB_FOLLOW|CCDB_INIT)) - printf("ccd%d: %s: incorrect partition type\n", - ccd->ccd_unit, ci->ci_path); + printf("%s: %s: incorrect partition type\n", + cs->sc_xname, ci->ci_path); #endif free(ci->ci_path, M_DEVBUF); free(cs->sc_cinfo, M_DEVBUF); @@ -330,8 +323,8 @@ ccdinit(ccd, cpaths, p) if (size == 0) { #ifdef DEBUG if (ccddebug & (CCDB_FOLLOW|CCDB_INIT)) - printf("ccd%d: %s: size == 0\n", - ccd->ccd_unit, ci->ci_path); + printf("%s: %s: size == 0\n", + cs->sc_xname, ci->ci_path); #endif free(ci->ci_path, M_DEVBUF); free(cs->sc_cinfo, M_DEVBUF); @@ -352,8 +345,8 @@ ccdinit(ccd, cpaths, p) (cs->sc_ileave < (maxsecsize / DEV_BSIZE))) { #ifdef DEBUG if (ccddebug & (CCDB_FOLLOW|CCDB_INIT)) - printf("ccd%d: interleave must be at least %d\n", - ccd->ccd_unit, (maxsecsize / DEV_BSIZE)); + printf("%s: interleave must be at least %d\n", + cs->sc_xname, (maxsecsize / DEV_BSIZE)); #endif free(ci->ci_path, M_DEVBUF); free(cs->sc_cinfo, M_DEVBUF); @@ -385,14 +378,10 @@ ccdinit(ccd, cpaths, p) 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 - 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); } @@ -523,7 +512,7 @@ ccdopen(dev, flags, fmt, p) if (error = ccdlock(cs)) return (error); - lp = &cs->sc_dkdev.dk_label; + lp = cs->sc_dkdev.dk_label; part = DISKPART(dev); pmask = (1 << part); @@ -628,7 +617,7 @@ ccdstrategy(bp) if (bp->b_bcount == 0) goto done; - lp = &cs->sc_dkdev.dk_label; + lp = cs->sc_dkdev.dk_label; /* * Do bounds checking and adjust transfer. If there's an @@ -668,24 +657,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 + /* Instrumentation. */ + disk_busy(&cs->sc_dkdev); /* * 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)]; + pp = &cs->sc_dkdev.dk_label->d_partitions[DISKPART(bp->b_dev)]; bn += pp->p_offset; } @@ -813,18 +793,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; + disk_unbusy(&cs->sc_dkdev, (bp->b_bcount - bp->b_resid)); biodone(bp); } @@ -839,6 +810,7 @@ ccdiodone(cbp) { register struct buf *bp = cbp->cb_obp; register int unit = cbp->cb_unit; + struct ccd_softc *cs = &ccd_softc[unit]; int count, s; s = splbio(); @@ -859,8 +831,8 @@ ccdiodone(cbp) 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); + printf("%s: error %d on component %d\n", + cs->sc_xname, bp->b_error, cbp->cb_comp); #endif } count = cbp->cb_buf.b_bcount; @@ -951,9 +923,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); @@ -1022,27 +991,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 for (j = 0; j < lookedup; ++j) (void)vn_close(vpp[j], FREAD|FWRITE, p->p_ucred, p); @@ -1055,11 +1007,20 @@ ccdioctl(dev, cmd, data, flag, p) /* * The ccd has been successfully initialized, so - * we can place it into the array and read the disklabel. + * 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(); */ bcopy(&ccd, &ccddevs[unit], sizeof(ccd)); ccio->ccio_unit = unit; ccio->ccio_size = cs->sc_size; + + /* Attach the disk. */ + cs->sc_dkdev.dk_name = cs->sc_xname; + disk_attach(&cs->sc_dkdev); + + /* Try and read the disklabel. */ ccdgetdisklabel(dev); ccdunlock(cs); @@ -1125,9 +1086,11 @@ ccdioctl(dev, cmd, data, flag, p) */ free(ccddevs[unit].ccd_cpp, M_DEVBUF); free(ccddevs[unit].ccd_vpp, M_DEVBUF); - ccd.ccd_dk = -1; bcopy(&ccd, &ccddevs[unit], sizeof(ccd)); + /* Detatch the disk. */ + disk_detatch(&cs->sc_dkdev); + /* This must be atomic. */ s = splhigh(); ccdunlock(cs); @@ -1140,16 +1103,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_dkdev.dk_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_dkdev.dk_label; ((struct partinfo *)data)->part = - &cs->sc_dkdev.dk_label.d_partitions[DISKPART(dev)]; + &cs->sc_dkdev.dk_label->d_partitions[DISKPART(dev)]; break; case DIOCWDINFO: @@ -1165,13 +1128,13 @@ ccdioctl(dev, cmd, data, flag, p) 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_dkdev.dk_label, + (struct disklabel *)data, 0, cs->sc_dkdev.dk_cpulabel); if (error == 0) { if (cmd == DIOCWDINFO) error = writedisklabel(CCDLABELDEV(dev), - ccdstrategy, &cs->sc_dkdev.dk_label, - &cs->sc_dkdev.dk_cpulabel); + ccdstrategy, cs->sc_dkdev.dk_label, + cs->sc_dkdev.dk_cpulabel); } cs->sc_flags &= ~CCDF_LABELLING; @@ -1217,10 +1180,10 @@ ccdsize(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_dkdev.dk_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_dkdev.dk_label->d_partitions[part].p_size; if (ccdclose(dev, 0, S_IFBLK, curproc)) return (-1); @@ -1310,8 +1273,8 @@ 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_dkdev.dk_label; + struct cpu_disklabel *clp = cs->sc_dkdev.dk_cpulabel; struct ccdgeom *ccg = &cs->sc_geom; bzero(lp, sizeof(*lp)); @@ -1338,20 +1301,20 @@ ccdgetdisklabel(dev) lp->d_magic = DISKMAGIC; lp->d_magic2 = DISKMAGIC; - lp->d_checksum = dkcksum(&cs->sc_dkdev.dk_label); + lp->d_checksum = dkcksum(cs->sc_dkdev.dk_label); /* * Call the generic disklabel extraction routine. */ if (errstring = readdisklabel(CCDLABELDEV(dev), ccdstrategy, - &cs->sc_dkdev.dk_label, &cs->sc_dkdev.dk_cpulabel)) + cs->sc_dkdev.dk_label, cs->sc_dkdev.dk_cpulabel)) ccdmakedisklabel(cs); #ifdef DEBUG /* It's actually extremely common to have unlabeled ccds. */ if (ccddebug & CCDB_LABEL) if (errstring != NULL) - printf("ccd%d: %s\n", unit, errstring); + printf("%s: %s\n", cs->sc_xname, errstring); #endif } @@ -1363,7 +1326,7 @@ static void ccdmakedisklabel(cs) struct ccd_softc *cs; { - struct disklabel *lp = &cs->sc_dkdev.dk_label; + struct disklabel *lp = cs->sc_dkdev.dk_label; /* * For historical reasons, if there's no disklabel present diff --git a/sys/dev/ccdvar.h b/sys/dev/ccdvar.h index e5862d6f6b10..0c10ecbccabf 100644 --- a/sys/dev/ccdvar.h +++ b/sys/dev/ccdvar.h @@ -1,4 +1,4 @@ -/* $NetBSD: ccdvar.h,v 1.8 1995/10/12 21:28:35 thorpej Exp $ */ +/* $NetBSD: ccdvar.h,v 1.9 1996/01/07 22:03:30 thorpej Exp $ */ /* * Copyright (c) 1995 Jason R. Thorpe. @@ -90,7 +90,6 @@ struct ccddevice { int ccd_unit; /* logical unit of this ccd */ int ccd_interleave; /* interleave (DEV_BSIZE blocks) */ int ccd_flags; /* misc. information */ - int ccd_dk; /* disk number */ struct vnode **ccd_vpp; /* array of component vnodes */ char **ccd_cpp; /* array of component pathnames */ int ccd_ndev; /* number of component devices */ @@ -182,10 +181,9 @@ struct ccd_softc { int sc_nccdisks; /* number of components */ struct ccdcinfo *sc_cinfo; /* component info */ struct ccdiinfo *sc_itable; /* interleave table */ - int sc_nactive; /* number of requests active */ - int sc_dk; /* disk index */ struct ccdgeom sc_geom; /* pseudo geometry info */ - struct dkdevice sc_dkdev; /* generic disk device info */ + char sc_xname[8]; /* XXX external name */ + struct disk sc_dkdev; /* generic disk device info */ }; /* sc_flags */ diff --git a/sys/dev/isa/mcd.c b/sys/dev/isa/mcd.c index 6b6dd1787728..34182b505085 100644 --- a/sys/dev/isa/mcd.c +++ b/sys/dev/isa/mcd.c @@ -1,4 +1,4 @@ -/* $NetBSD: mcd.c,v 1.43 1995/12/24 02:31:42 mycroft Exp $ */ +/* $NetBSD: mcd.c,v 1.44 1996/01/07 22:03:37 thorpej Exp $ */ /* * Copyright (c) 1993, 1994, 1995 Charles M. Hannum. All rights reserved. @@ -107,7 +107,7 @@ struct mcd_mbx { struct mcd_softc { struct device sc_dev; - struct dkdevice sc_dk; + struct disk sc_dk; void *sc_ih; int iobase; @@ -207,6 +207,13 @@ mcdattach(parent, self, aux) struct isa_attach_args *ia = aux; struct mcd_mbox mbx; + /* + * Initialize and attach the disk structure. + */ + sc->sc_dk.dk_driver = &mcddkdriver; + sc->sc_dk.dk_name = sc->sc_dev.dv_xname; + disk_attach(&sc->sc_dk); + printf(": model %s\n", sc->type != 0 ? sc->type : "unknown"); (void) mcd_setlock(sc, MCD_LK_UNLOCK); @@ -220,8 +227,6 @@ mcdattach(parent, self, aux) mcd_soft_reset(sc); - sc->sc_dk.dk_driver = &mcddkdriver; - sc->sc_ih = isa_intr_establish(ia->ia_irq, IST_EDGE, IPL_BIO, mcdintr, sc); } @@ -332,8 +337,8 @@ mcdopen(dev, flag, fmt, p) /* Check that the partition exists. */ if (part != RAW_PART && - (part >= sc->sc_dk.dk_label.d_npartitions || - sc->sc_dk.dk_label.d_partitions[part].p_fstype == FS_UNUSED)) { + (part >= sc->sc_dk.dk_label->d_npartitions || + sc->sc_dk.dk_label->d_partitions[part].p_fstype == FS_UNUSED)) { error = ENXIO; goto bad; } @@ -439,7 +444,7 @@ mcdstrategy(bp) * If end of partition, just return. */ if (MCDPART(bp->b_dev) != RAW_PART && - bounds_check_with_label(bp, &sc->sc_dk.dk_label, + bounds_check_with_label(bp, sc->sc_dk.dk_label, (sc->flags & (MCDF_WLABEL|MCDF_LABELLING)) != 0) <= 0) goto done; @@ -492,12 +497,17 @@ loop: dp->b_active = 1; + /* Instrumentation. */ + s = splbio(); + disk_busy(&sc->sc_dk); + splx(s); + sc->mbx.retry = MCD_RDRETRIES; sc->mbx.bp = bp; sc->mbx.blkno = bp->b_blkno / (sc->blksize / DEV_BSIZE); if (MCDPART(bp->b_dev) != RAW_PART) { struct partition *p; - p = &sc->sc_dk.dk_label.d_partitions[MCDPART(bp->b_dev)]; + p = &sc->sc_dk.dk_label->d_partitions[MCDPART(bp->b_dev)]; sc->mbx.blkno += p->p_offset; } sc->mbx.nblk = bp->b_bcount / sc->blksize; @@ -547,13 +557,13 @@ mcdioctl(dev, cmd, addr, flag, p) switch (cmd) { case DIOCGDINFO: - *(struct disklabel *)addr = sc->sc_dk.dk_label; + *(struct disklabel *)addr = *(sc->sc_dk.dk_label); return 0; case DIOCGPART: - ((struct partinfo *)addr)->disklab = &sc->sc_dk.dk_label; + ((struct partinfo *)addr)->disklab = sc->sc_dk.dk_label; ((struct partinfo *)addr)->part = - &sc->sc_dk.dk_label.d_partitions[MCDPART(dev)]; + &sc->sc_dk.dk_label->d_partitions[MCDPART(dev)]; return 0; case DIOCWDINFO: @@ -565,9 +575,9 @@ mcdioctl(dev, cmd, addr, flag, p) return error; sc->flags |= MCDF_LABELLING; - error = setdisklabel(&sc->sc_dk.dk_label, + error = setdisklabel(sc->sc_dk.dk_label, (struct disklabel *)addr, /*sc->sc_dk.dk_openmask : */0, - &sc->sc_dk.dk_cpulabel); + sc->sc_dk.dk_cpulabel); if (error == 0) { } @@ -639,10 +649,10 @@ void mcdgetdisklabel(sc) struct mcd_softc *sc; { - struct disklabel *lp = &sc->sc_dk.dk_label; + struct disklabel *lp = sc->sc_dk.dk_label; bzero(lp, sizeof(struct disklabel)); - bzero(&sc->sc_dk.dk_cpulabel, sizeof(struct cpu_disklabel)); + bzero(sc->sc_dk.dk_cpulabel, sizeof(struct cpu_disklabel)); lp->d_secsize = sc->blksize; lp->d_ntracks = 1; @@ -1111,6 +1121,7 @@ mcdintr(arg) /* Return buffer. */ bp->b_resid = 0; + disk_unbusy(&sc->sc_dk, bp->b_bcount); biodone(bp); mcdstart(sc); @@ -1143,6 +1154,7 @@ harderr: /* Invalidate the buffer. */ bp->b_flags |= B_ERROR; bp->b_resid = bp->b_bcount - mbx->skip; + disk_unbusy(&sc->sc_dk, (bp->b_bcount - bp->b_resid)); biodone(bp); mcdstart(sc); diff --git a/sys/dev/isa/wd.c b/sys/dev/isa/wd.c index bcc4a55d4d91..6b94916a7d42 100644 --- a/sys/dev/isa/wd.c +++ b/sys/dev/isa/wd.c @@ -1,4 +1,4 @@ -/* $NetBSD: wd.c,v 1.143 1995/12/24 02:31:59 mycroft Exp $ */ +/* $NetBSD: wd.c,v 1.144 1996/01/07 22:03:41 thorpej Exp $ */ /* * Copyright (c) 1994, 1995 Charles M. Hannum. All rights reserved. @@ -32,8 +32,6 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#define INSTRUMENT /* instrumentation stuff by Brad Parker */ - #include #include #include @@ -77,7 +75,7 @@ struct wd_softc { struct device sc_dev; - struct dkdevice sc_dk; + struct disk sc_dk; /* Information about the current transfer: */ daddr_t sc_blkno; /* starting block number */ @@ -289,6 +287,13 @@ wdattach(parent, self, aux) wd->sc_drive = wa->wa_drive; + /* + * Initialize and attach the disk structure. + */ + wd->sc_dk.dk_driver = &wddkdriver; + wd->sc_dk.dk_name = wd->sc_dev.dv_xname; + disk_attach(&wd->sc_dk); + wd_get_parms(wd); for (blank = 0, p = wd->sc_params.wdp_model, q = buf, i = 0; i < sizeof(wd->sc_params.wdp_model); i++) { @@ -337,8 +342,6 @@ wdattach(parent, self, aux) printf(" lba addressing\n"); else printf(" chs addressing\n"); - - wd->sc_dk.dk_driver = &wddkdriver; } /* @@ -354,8 +357,8 @@ wdstrategy(bp) /* Valid request? */ if (bp->b_blkno < 0 || - (bp->b_bcount % wd->sc_dk.dk_label.d_secsize) != 0 || - (bp->b_bcount / wd->sc_dk.dk_label.d_secsize) >= (1 << NBBY)) { + (bp->b_bcount % wd->sc_dk.dk_label->d_secsize) != 0 || + (bp->b_bcount / wd->sc_dk.dk_label->d_secsize) >= (1 << NBBY)) { bp->b_error = EINVAL; goto bad; } @@ -375,7 +378,7 @@ wdstrategy(bp) * If end of partition, just return. */ if (WDPART(bp->b_dev) != RAW_PART && - bounds_check_with_label(bp, &wd->sc_dk.dk_label, + bounds_check_with_label(bp, wd->sc_dk.dk_label, (wd->sc_flags & (WDF_WLABEL|WDF_LABELLING)) != 0) <= 0) goto done; @@ -417,6 +420,9 @@ wdstart(wd) /* Link onto controller queue. */ wd->sc_q.b_active = 1; TAILQ_INSERT_TAIL(&wdc->sc_drives, wd, sc_drivechain); + + /* Instrumentation. */ + disk_busy(&wd->sc_dk); /* If controller not already active, start it. */ if (!active) @@ -450,6 +456,9 @@ wdfinish(wd, bp) bp->b_resid = wd->sc_bcount; wd->sc_skip = 0; wd->sc_q.b_actf = bp->b_actf; + + disk_unbusy(&wd->sc_dk, (bp->b_bcount - bp->b_resid)); + biodone(bp); } @@ -549,7 +558,7 @@ loop: } } - lp = &wd->sc_dk.dk_label; + lp = wd->sc_dk.dk_label; /* When starting a transfer... */ if (wd->sc_skip == 0) { @@ -914,8 +923,8 @@ wdopen(dev, flag, fmt) /* Check that the partition exists. */ if (part != RAW_PART && - (part >= wd->sc_dk.dk_label.d_npartitions || - wd->sc_dk.dk_label.d_partitions[part].p_fstype == FS_UNUSED)) { + (part >= wd->sc_dk.dk_label->d_npartitions || + wd->sc_dk.dk_label->d_partitions[part].p_fstype == FS_UNUSED)) { error = ENXIO; goto bad; } @@ -983,11 +992,11 @@ void wdgetdisklabel(wd) struct wd_softc *wd; { - struct disklabel *lp = &wd->sc_dk.dk_label; + struct disklabel *lp = wd->sc_dk.dk_label; char *errstring; bzero(lp, sizeof(struct disklabel)); - bzero(&wd->sc_dk.dk_cpulabel, sizeof(struct cpu_disklabel)); + bzero(wd->sc_dk.dk_cpulabel, sizeof(struct cpu_disklabel)); lp->d_secsize = DEV_BSIZE; lp->d_ntracks = wd->sc_params.wdp_heads; @@ -1020,7 +1029,7 @@ wdgetdisklabel(wd) if (wd->sc_state > RECAL) wd->sc_state = RECAL; errstring = readdisklabel(MAKEWDDEV(0, wd->sc_dev.dv_unit, RAW_PART), - wdstrategy, lp, &wd->sc_dk.dk_cpulabel); + wdstrategy, lp, wd->sc_dk.dk_cpulabel); if (errstring) { /* * This probably happened because the drive's default @@ -1031,7 +1040,7 @@ wdgetdisklabel(wd) if (wd->sc_state > GEOMETRY) wd->sc_state = GEOMETRY; errstring = readdisklabel(MAKEWDDEV(0, wd->sc_dev.dv_unit, RAW_PART), - wdstrategy, lp, &wd->sc_dk.dk_cpulabel); + wdstrategy, lp, wd->sc_dk.dk_cpulabel); } if (errstring) { printf("%s: %s\n", wd->sc_dev.dv_xname, errstring); @@ -1149,8 +1158,8 @@ wdcommand(wd, command, cylin, head, sector, count) return -1; /* Load parameters. */ - if (wd->sc_dk.dk_label.d_type == DTYPE_ST506) - outb(iobase+wd_precomp, wd->sc_dk.dk_label.d_precompcyl / 4); + if (wd->sc_dk.dk_label->d_type == DTYPE_ST506) + outb(iobase+wd_precomp, wd->sc_dk.dk_label->d_precompcyl / 4); else outb(iobase+wd_features, 0); outb(iobase+wd_cyl_lo, cylin); @@ -1197,13 +1206,13 @@ wdsetctlr(wd) #ifdef WDDEBUG printf("wd(%d,%d) C%dH%dS%d\n", wd->sc_dev.dv_unit, wd->sc_drive, - wd->sc_dk.dk_label.d_ncylinders, wd->sc_dk.dk_label.d_ntracks, - wd->sc_dk.dk_label.d_nsectors); + wd->sc_dk.dk_label->d_ncylinders, wd->sc_dk.dk_label->d_ntracks, + wd->sc_dk.dk_label->d_nsectors); #endif - if (wdcommand(wd, WDCC_IDP, wd->sc_dk.dk_label.d_ncylinders, - wd->sc_dk.dk_label.d_ntracks - 1, 0, wd->sc_dk.dk_label.d_nsectors) - != 0) { + if (wdcommand(wd, WDCC_IDP, wd->sc_dk.dk_label->d_ncylinders, + wd->sc_dk.dk_label->d_ntracks - 1, 0, + wd->sc_dk.dk_label->d_nsectors) != 0) { wderror(wd, NULL, "wdsetctlr: geometry upload failed"); return -1; } @@ -1248,9 +1257,9 @@ wd_get_parms(wd) * This geometry is only used to read the MBR and print a * (false) attach message. */ - strncpy(wd->sc_dk.dk_label.d_typename, "ST506", - sizeof wd->sc_dk.dk_label.d_typename); - wd->sc_dk.dk_label.d_type = DTYPE_ST506; + strncpy(wd->sc_dk.dk_label->d_typename, "ST506", + sizeof wd->sc_dk.dk_label->d_typename); + wd->sc_dk.dk_label->d_type = DTYPE_ST506; strncpy(wd->sc_params.wdp_model, "unknown", sizeof wd->sc_params.wdp_model); @@ -1262,9 +1271,9 @@ wd_get_parms(wd) wd->sc_params.wdp_usedmovsd = 0; wd->sc_params.wdp_capabilities = 0; } else { - strncpy(wd->sc_dk.dk_label.d_typename, "ESDI/IDE", - sizeof wd->sc_dk.dk_label.d_typename); - wd->sc_dk.dk_label.d_type = DTYPE_ESDI; + strncpy(wd->sc_dk.dk_label->d_typename, "ESDI/IDE", + sizeof wd->sc_dk.dk_label->d_typename); + wd->sc_dk.dk_label->d_type = DTYPE_ESDI; /* Read in parameter block. */ insw(wdc->sc_iobase+wd_data, tb, sizeof(tb) / sizeof(short)); @@ -1306,19 +1315,19 @@ wdioctl(dev, cmd, addr, flag, p) case DIOCSBAD: if ((flag & FWRITE) == 0) return EBADF; - wd->sc_dk.dk_cpulabel.bad = *(struct dkbad *)addr; - wd->sc_dk.dk_label.d_flags |= D_BADSECT; + wd->sc_dk.dk_cpulabel->bad = *(struct dkbad *)addr; + wd->sc_dk.dk_label->d_flags |= D_BADSECT; bad144intern(wd); return 0; case DIOCGDINFO: - *(struct disklabel *)addr = wd->sc_dk.dk_label; + *(struct disklabel *)addr = *(wd->sc_dk.dk_label); return 0; case DIOCGPART: - ((struct partinfo *)addr)->disklab = &wd->sc_dk.dk_label; + ((struct partinfo *)addr)->disklab = wd->sc_dk.dk_label; ((struct partinfo *)addr)->part = - &wd->sc_dk.dk_label.d_partitions[WDPART(dev)]; + &wd->sc_dk.dk_label->d_partitions[WDPART(dev)]; return 0; case DIOCWDINFO: @@ -1330,16 +1339,16 @@ wdioctl(dev, cmd, addr, flag, p) return error; wd->sc_flags |= WDF_LABELLING; - error = setdisklabel(&wd->sc_dk.dk_label, + error = setdisklabel(wd->sc_dk.dk_label, (struct disklabel *)addr, /*wd->sc_dk.dk_openmask : */0, - &wd->sc_dk.dk_cpulabel); + wd->sc_dk.dk_cpulabel); if (error == 0) { if (wd->sc_state > GEOMETRY) wd->sc_state = GEOMETRY; if (cmd == DIOCWDINFO) error = writedisklabel(WDLABELDEV(dev), - wdstrategy, &wd->sc_dk.dk_label, - &wd->sc_dk.dk_cpulabel); + wdstrategy, wd->sc_dk.dk_label, + wd->sc_dk.dk_cpulabel); } wd->sc_flags &= ~WDF_LABELLING; @@ -1372,7 +1381,7 @@ wdioctl(dev, cmd, addr, flag, p) auio.uio_resid = fop->df_count; auio.uio_segflg = 0; auio.uio_offset = - fop->df_startblk * wd->sc_dk.dk_label.d_secsize; + fop->df_startblk * wd->sc_dk.dk_label->d_secsize; auio.uio_procp = p; error = physio(wdformat, NULL, dev, B_WRITE, minphys, &auio); @@ -1382,7 +1391,7 @@ wdioctl(dev, cmd, addr, flag, p) return error; } #endif - + default: return ENOTTY; } @@ -1414,10 +1423,10 @@ wdsize(dev) return -1; wd = wdcd.cd_devs[WDUNIT(dev)]; part = WDPART(dev); - if (wd->sc_dk.dk_label.d_partitions[part].p_fstype != FS_SWAP) + if (wd->sc_dk.dk_label->d_partitions[part].p_fstype != FS_SWAP) size = -1; else - size = wd->sc_dk.dk_label.d_partitions[part].p_size; + size = wd->sc_dk.dk_label->d_partitions[part].p_size; if (wdclose(dev, 0, S_IFBLK) != 0) return -1; return size; @@ -1466,7 +1475,7 @@ wddump(dev, blkno, va, size) wdc = (void *)wd->sc_dev.dv_parent; /* Convert to disk sectors. Request must be a multiple of size. */ - lp = &wd->sc_dk.dk_label; + lp = wd->sc_dk.dk_label; if ((size % lp->d_secsize) != 0) return EFAULT; nblks = size / lp->d_secsize; @@ -1578,8 +1587,8 @@ void bad144intern(wd) struct wd_softc *wd; { - struct dkbad *bt = &wd->sc_dk.dk_cpulabel.bad; - struct disklabel *lp = &wd->sc_dk.dk_label; + struct dkbad *bt = &wd->sc_dk.dk_cpulabel->bad; + struct disklabel *lp = wd->sc_dk.dk_label; int i = 0; for (; i < 126; i++) { @@ -1719,7 +1728,7 @@ wderror(dev, bp, msg) if (bp) { diskerr(bp, "wd", msg, LOG_PRINTF, wd->sc_skip / DEV_BSIZE, - &wd->sc_dk.dk_label); + wd->sc_dk.dk_label); printf("\n"); } else printf("%s: %s: status %b error %b\n", wdc->sc_dev.dv_xname, diff --git a/sys/dev/md.c b/sys/dev/md.c index 87166c91e2c6..ba786ba2b2e3 100644 --- a/sys/dev/md.c +++ b/sys/dev/md.c @@ -1,4 +1,4 @@ -/* $NetBSD: md.c,v 1.3 1995/11/17 23:33:34 gwr Exp $ */ +/* $NetBSD: md.c,v 1.4 1996/01/07 22:03:31 thorpej Exp $ */ /* * Copyright (c) 1995 Gordon W. Ross, Leo Weppelman. @@ -49,6 +49,7 @@ #include #include #include +#include #include #include @@ -86,6 +87,7 @@ extern vm_offset_t kmem_alloc __P((vm_map_t, vm_size_t)); struct rd_softc { struct device sc_dev; /* REQUIRED first entry */ + struct disk sc_dkdev; /* hook for generic disk handling */ struct rd_conf sc_rd; struct buf *sc_buflist; int sc_flags; @@ -105,6 +107,10 @@ struct cfdriver rdcd = { NULL, "rd", rd_match, rd_attach, DV_DULL, sizeof(struct rd_softc), NULL, 0 }; +void rdstrategy __P((struct buf *bp)); + +struct dkdriver rddkdriver = { rdstrategy }; + static int rd_match(parent, self, aux) struct device *parent; @@ -131,6 +137,14 @@ rd_attach(parent, self, aux) rd_attach_hook(sc->sc_dev.dv_unit, &sc->sc_rd); #endif printf("\n"); + + /* + * Initialize and attach the disk structure. + */ + bzero(&sc->sc_dkdev, sizeof(sc->sc_dkdev)); + sc->sc_dkdev.dk_driver = &rddkdriver; + sc->sc_dkdev.dk_name = sc->sc_dev.dv_xname; + disk_attach(&sc->sc_dkdev); } /* @@ -139,8 +153,6 @@ rd_attach(parent, self, aux) * ioctl, dump, size */ -void rdstrategy __P((struct buf *bp)); - #if RAMDISK_SERVER static int rd_server_loop __P((struct rd_softc *sc)); static int rd_ioctl_server __P((struct rd_softc *sc, diff --git a/sys/dev/ramdisk.c b/sys/dev/ramdisk.c index 08d361b9d4c0..381080985514 100644 --- a/sys/dev/ramdisk.c +++ b/sys/dev/ramdisk.c @@ -1,4 +1,4 @@ -/* $NetBSD: ramdisk.c,v 1.3 1995/11/17 23:33:34 gwr Exp $ */ +/* $NetBSD: ramdisk.c,v 1.4 1996/01/07 22:03:31 thorpej Exp $ */ /* * Copyright (c) 1995 Gordon W. Ross, Leo Weppelman. @@ -49,6 +49,7 @@ #include #include #include +#include #include #include @@ -86,6 +87,7 @@ extern vm_offset_t kmem_alloc __P((vm_map_t, vm_size_t)); struct rd_softc { struct device sc_dev; /* REQUIRED first entry */ + struct disk sc_dkdev; /* hook for generic disk handling */ struct rd_conf sc_rd; struct buf *sc_buflist; int sc_flags; @@ -105,6 +107,10 @@ struct cfdriver rdcd = { NULL, "rd", rd_match, rd_attach, DV_DULL, sizeof(struct rd_softc), NULL, 0 }; +void rdstrategy __P((struct buf *bp)); + +struct dkdriver rddkdriver = { rdstrategy }; + static int rd_match(parent, self, aux) struct device *parent; @@ -131,6 +137,14 @@ rd_attach(parent, self, aux) rd_attach_hook(sc->sc_dev.dv_unit, &sc->sc_rd); #endif printf("\n"); + + /* + * Initialize and attach the disk structure. + */ + bzero(&sc->sc_dkdev, sizeof(sc->sc_dkdev)); + sc->sc_dkdev.dk_driver = &rddkdriver; + sc->sc_dkdev.dk_name = sc->sc_dev.dv_xname; + disk_attach(&sc->sc_dkdev); } /* @@ -139,8 +153,6 @@ rd_attach(parent, self, aux) * ioctl, dump, size */ -void rdstrategy __P((struct buf *bp)); - #if RAMDISK_SERVER static int rd_server_loop __P((struct rd_softc *sc)); static int rd_ioctl_server __P((struct rd_softc *sc, diff --git a/sys/dev/scsipi/cd.c b/sys/dev/scsipi/cd.c index ff08454ae2f4..5645837e2e16 100644 --- a/sys/dev/scsipi/cd.c +++ b/sys/dev/scsipi/cd.c @@ -1,4 +1,4 @@ -/* $NetBSD: cd.c,v 1.78 1995/12/07 19:11:32 thorpej Exp $ */ +/* $NetBSD: cd.c,v 1.79 1996/01/07 22:03:58 thorpej Exp $ */ /* * Copyright (c) 1994, 1995 Charles M. Hannum. All rights reserved. @@ -77,7 +77,7 @@ struct cd_softc { struct device sc_dev; - struct dkdevice sc_dk; + struct disk sc_dk; int flags; #define CDF_LOCKED 0x01 @@ -103,6 +103,7 @@ void cdgetdisklabel __P((struct cd_softc *)); int cd_get_parms __P((struct cd_softc *, int)); void cdstrategy __P((struct buf *)); void cdstart __P((struct cd_softc *)); +int cddone __P((struct scsi_xfer *)); struct dkdriver cddkdriver = { cdstrategy }; @@ -110,7 +111,7 @@ struct scsi_device cd_switch = { NULL, /* use default error handler */ cdstart, /* we have a queue, which is started by this */ NULL, /* we do not have an async handler */ - NULL, /* use default 'done' routine */ + cddone, /* deal with stats at interrupt time */ }; struct scsi_inquiry_pattern cd_patterns[] = { @@ -162,9 +163,15 @@ cdattach(parent, self, aux) if (sc_link->openings > CDOUTSTANDING) sc_link->openings = CDOUTSTANDING; + /* + * Initialize and attach the disk structure. + */ cd->sc_dk.dk_driver = &cddkdriver; + cd->sc_dk.dk_name = cd->sc_dev.dv_xname; + disk_attach(&cd->sc_dk); + #if !defined(i386) || defined(NEWCONFIG) - dk_establish(&cd->sc_dk, &cd->sc_dev); + dk_establish(&cd->sc_dk, &cd->sc_dev); /* XXX */ #endif printf("\n"); @@ -282,8 +289,8 @@ cdopen(dev, flag, fmt) /* Check that the partition exists. */ if (part != RAW_PART && - (part >= cd->sc_dk.dk_label.d_npartitions || - cd->sc_dk.dk_label.d_partitions[part].p_fstype == FS_UNUSED)) { + (part >= cd->sc_dk.dk_label->d_npartitions || + cd->sc_dk.dk_label->d_partitions[part].p_fstype == FS_UNUSED)) { error = ENXIO; goto bad; } @@ -374,7 +381,7 @@ cdstrategy(bp) /* * The transfer must be a whole number of blocks. */ - if ((bp->b_bcount % cd->sc_dk.dk_label.d_secsize) != 0) { + if ((bp->b_bcount % cd->sc_dk.dk_label->d_secsize) != 0) { bp->b_error = EINVAL; goto bad; } @@ -397,7 +404,7 @@ cdstrategy(bp) * If end of partition, just return. */ if (CDPART(bp->b_dev) != RAW_PART && - bounds_check_with_label(bp, &cd->sc_dk.dk_label, + bounds_check_with_label(bp, cd->sc_dk.dk_label, (cd->flags & (CDF_WLABEL|CDF_LABELLING)) != 0) <= 0) goto done; @@ -499,12 +506,12 @@ cdstart(cd) * of the logical blocksize of the device. */ blkno = - bp->b_blkno / (cd->sc_dk.dk_label.d_secsize / DEV_BSIZE); + bp->b_blkno / (cd->sc_dk.dk_label->d_secsize / DEV_BSIZE); if (CDPART(bp->b_dev) != RAW_PART) { - p = &cd->sc_dk.dk_label.d_partitions[CDPART(bp->b_dev)]; - blkno += p->p_offset; + p = &cd->sc_dk.dk_label->d_partitions[CDPART(bp->b_dev)]; + blkno += p->p_offset; } - nblks = howmany(bp->b_bcount, cd->sc_dk.dk_label.d_secsize); + nblks = howmany(bp->b_bcount, cd->sc_dk.dk_label->d_secsize); /* * Fill out the scsi command. If the transfer will @@ -541,6 +548,9 @@ cdstart(cd) cmdp = (struct scsi_generic *)&cmd_big; } + /* Instrumentation. */ + disk_busy(&cd->sc_dk); + /* * Call the routine that chats with the adapter. * Note: we cannot sleep as we may be an interrupt @@ -553,6 +563,18 @@ cdstart(cd) } } +int +cddone(xs) + struct scsi_xfer *xs; +{ + struct cd_softc *cd = xs->sc_link->device_softc; + + if (xs->bp != NULL) + disk_unbusy(&cd->sc_dk, (xs->bp->b_bcount - xs->bp->b_resid)); + + return (0); +} + int cdread(dev, uio) dev_t dev; @@ -600,13 +622,13 @@ cdioctl(dev, cmd, addr, flag, p) switch (cmd) { case DIOCGDINFO: - *(struct disklabel *)addr = cd->sc_dk.dk_label; + *(struct disklabel *)addr = *(cd->sc_dk.dk_label); return 0; case DIOCGPART: - ((struct partinfo *)addr)->disklab = &cd->sc_dk.dk_label; + ((struct partinfo *)addr)->disklab = cd->sc_dk.dk_label; ((struct partinfo *)addr)->part = - &cd->sc_dk.dk_label.d_partitions[CDPART(dev)]; + &cd->sc_dk.dk_label->d_partitions[CDPART(dev)]; return 0; case DIOCWDINFO: @@ -618,9 +640,9 @@ cdioctl(dev, cmd, addr, flag, p) return error; cd->flags |= CDF_LABELLING; - error = setdisklabel(&cd->sc_dk.dk_label, + error = setdisklabel(cd->sc_dk.dk_label, (struct disklabel *)addr, /*cd->sc_dk.dk_openmask : */0, - &cd->sc_dk.dk_cpulabel); + cd->sc_dk.dk_cpulabel); if (error == 0) { } @@ -851,10 +873,10 @@ void cdgetdisklabel(cd) struct cd_softc *cd; { - struct disklabel *lp = &cd->sc_dk.dk_label; + struct disklabel *lp = cd->sc_dk.dk_label; bzero(lp, sizeof(struct disklabel)); - bzero(&cd->sc_dk.dk_cpulabel, sizeof(struct cpu_disklabel)); + bzero(cd->sc_dk.dk_cpulabel, sizeof(struct cpu_disklabel)); lp->d_secsize = cd->params.blksize; lp->d_ntracks = 1; diff --git a/sys/dev/scsipi/sd.c b/sys/dev/scsipi/sd.c index 474ae5d0281d..f67911b16abf 100644 --- a/sys/dev/scsipi/sd.c +++ b/sys/dev/scsipi/sd.c @@ -1,4 +1,4 @@ -/* $NetBSD: sd.c,v 1.83 1995/12/07 21:54:24 thorpej Exp $ */ +/* $NetBSD: sd.c,v 1.84 1996/01/07 22:04:02 thorpej Exp $ */ /* * Copyright (c) 1994, 1995 Charles M. Hannum. All rights reserved. @@ -77,7 +77,7 @@ struct sd_softc { struct device sc_dev; - struct dkdevice sc_dk; + struct disk sc_dk; int flags; #define SDF_LOCKED 0x01 @@ -107,6 +107,7 @@ void sdgetdisklabel __P((struct sd_softc *)); int sd_get_parms __P((struct sd_softc *, int)); void sdstrategy __P((struct buf *)); void sdstart __P((struct sd_softc *)); +int sddone __P((struct scsi_xfer *)); void sdminphys __P((struct buf *)); struct dkdriver sddkdriver = { sdstrategy }; @@ -115,7 +116,7 @@ struct scsi_device sd_switch = { NULL, /* Use default error handler */ sdstart, /* have a queue, served by this */ NULL, /* have no async handler */ - NULL, /* Use default 'done' routine */ + sddone, /* deal with stats at interrupt time */ }; struct scsi_inquiry_pattern sd_patterns[] = { @@ -169,17 +170,24 @@ sdattach(parent, self, aux) if (sc_link->openings > SDOUTSTANDING) sc_link->openings = SDOUTSTANDING; + /* + * Initialize and attach the disk structure. + */ + sd->sc_dk.dk_driver = &sddkdriver; + sd->sc_dk.dk_name = sd->sc_dev.dv_xname; + disk_attach(&sd->sc_dk); + + sd->sc_dk.dk_driver = &sddkdriver; +#if !defined(i386) || defined(NEWCONFIG) + dk_establish(&sd->sc_dk, &sd->sc_dev); /* XXX */ +#endif + /* * Note if this device is ancient. This is used in sdminphys(). */ if ((sa->sa_inqbuf->version & SID_ANSII) == 0) sd->flags |= SDF_ANCIENT; - sd->sc_dk.dk_driver = &sddkdriver; -#if !defined(i386) || defined(NEWCONFIG) - dk_establish(&sd->sc_dk, &sd->sc_dev); -#endif - /* * Use the subdriver to request information regarding * the drive. We cannot use interrupts yet, so the @@ -307,8 +315,8 @@ sdopen(dev, flag, fmt) /* Check that the partition exists. */ if (part != RAW_PART && - (part >= sd->sc_dk.dk_label.d_npartitions || - sd->sc_dk.dk_label.d_partitions[part].p_fstype == FS_UNUSED)) { + (part >= sd->sc_dk.dk_label->d_npartitions || + sd->sc_dk.dk_label->d_partitions[part].p_fstype == FS_UNUSED)) { error = ENXIO; goto bad; } @@ -399,7 +407,7 @@ sdstrategy(bp) /* * The transfer must be a whole number of blocks. */ - if ((bp->b_bcount % sd->sc_dk.dk_label.d_secsize) != 0) { + if ((bp->b_bcount % sd->sc_dk.dk_label->d_secsize) != 0) { bp->b_error = EINVAL; goto bad; } @@ -421,7 +429,7 @@ sdstrategy(bp) * If end of partition, just return. */ if (SDPART(bp->b_dev) != RAW_PART && - bounds_check_with_label(bp, &sd->sc_dk.dk_label, + bounds_check_with_label(bp, sd->sc_dk.dk_label, (sd->flags & (SDF_WLABEL|SDF_LABELLING)) != 0) <= 0) goto done; @@ -523,12 +531,12 @@ sdstart(sd) * of the logical blocksize of the device. */ blkno = - bp->b_blkno / (sd->sc_dk.dk_label.d_secsize / DEV_BSIZE); + bp->b_blkno / (sd->sc_dk.dk_label->d_secsize / DEV_BSIZE); if (SDPART(bp->b_dev) != RAW_PART) { - p = &sd->sc_dk.dk_label.d_partitions[SDPART(bp->b_dev)]; - blkno += p->p_offset; + p = &sd->sc_dk.dk_label->d_partitions[SDPART(bp->b_dev)]; + blkno += p->p_offset; } - nblks = howmany(bp->b_bcount, sd->sc_dk.dk_label.d_secsize); + nblks = howmany(bp->b_bcount, sd->sc_dk.dk_label->d_secsize); /* * Fill out the scsi command. If the transfer will @@ -565,6 +573,9 @@ sdstart(sd) cmdp = (struct scsi_generic *)&cmd_big; } + /* Instrumentation. */ + disk_busy(&sd->sc_dk); + /* * Call the routine that chats with the adapter. * Note: we cannot sleep as we may be an interrupt @@ -577,6 +588,18 @@ sdstart(sd) } } +int +sddone(xs) + struct scsi_xfer *xs; +{ + struct sd_softc *sd = xs->sc_link->device_softc; + + if (xs->bp != NULL) + disk_unbusy(&sd->sc_dk, (xs->bp->b_bcount - xs->bp->b_resid)); + + return (0); +} + void sdminphys(bp) struct buf *bp; @@ -596,7 +619,7 @@ sdminphys(bp) * in a 10-byte read/write actually means 0 blocks. */ if (sd->flags & SDF_ANCIENT) { - max = sd->sc_dk.dk_label.d_secsize * 0xff; + max = sd->sc_dk.dk_label->d_secsize * 0xff; if (bp->b_bcount > max) bp->b_bcount = max; @@ -648,13 +671,13 @@ sdioctl(dev, cmd, addr, flag, p) switch (cmd) { case DIOCGDINFO: - *(struct disklabel *)addr = sd->sc_dk.dk_label; + *(struct disklabel *)addr = *(sd->sc_dk.dk_label); return 0; case DIOCGPART: - ((struct partinfo *)addr)->disklab = &sd->sc_dk.dk_label; + ((struct partinfo *)addr)->disklab = sd->sc_dk.dk_label; ((struct partinfo *)addr)->part = - &sd->sc_dk.dk_label.d_partitions[SDPART(dev)]; + &sd->sc_dk.dk_label->d_partitions[SDPART(dev)]; return 0; case DIOCWDINFO: @@ -666,14 +689,14 @@ sdioctl(dev, cmd, addr, flag, p) return error; sd->flags |= SDF_LABELLING; - error = setdisklabel(&sd->sc_dk.dk_label, + error = setdisklabel(sd->sc_dk.dk_label, (struct disklabel *)addr, /*sd->sc_dk.dk_openmask : */0, - &sd->sc_dk.dk_cpulabel); + sd->sc_dk.dk_cpulabel); if (error == 0) { if (cmd == DIOCWDINFO) error = writedisklabel(SDLABELDEV(dev), - sdstrategy, &sd->sc_dk.dk_label, - &sd->sc_dk.dk_cpulabel); + sdstrategy, sd->sc_dk.dk_label, + sd->sc_dk.dk_cpulabel); } sd->flags &= ~SDF_LABELLING; @@ -707,11 +730,11 @@ void sdgetdisklabel(sd) struct sd_softc *sd; { - struct disklabel *lp = &sd->sc_dk.dk_label; + struct disklabel *lp = sd->sc_dk.dk_label; char *errstring; bzero(lp, sizeof(struct disklabel)); - bzero(&sd->sc_dk.dk_cpulabel, sizeof(struct cpu_disklabel)); + bzero(sd->sc_dk.dk_cpulabel, sizeof(struct cpu_disklabel)); lp->d_secsize = sd->params.blksize; lp->d_ntracks = sd->params.heads; @@ -745,7 +768,7 @@ sdgetdisklabel(sd) * Call the generic disklabel extraction routine */ if (errstring = readdisklabel(MAKESDDEV(0, sd->sc_dev.dv_unit, - RAW_PART), sdstrategy, lp, &sd->sc_dk.dk_cpulabel)) { + RAW_PART), sdstrategy, lp, sd->sc_dk.dk_cpulabel)) { printf("%s: %s\n", sd->sc_dev.dv_xname, errstring); return; } @@ -910,10 +933,10 @@ sdsize(dev) return -1; sd = sdcd.cd_devs[SDUNIT(dev)]; part = SDPART(dev); - if (sd->sc_dk.dk_label.d_partitions[part].p_fstype != FS_SWAP) + if (sd->sc_dk.dk_label->d_partitions[part].p_fstype != FS_SWAP) size = -1; else - size = sd->sc_dk.dk_label.d_partitions[part].p_size; + size = sd->sc_dk.dk_label->d_partitions[part].p_size; if (sdclose(dev, 0, S_IFBLK) != 0) return -1; return size; @@ -966,7 +989,7 @@ sddump(dev, blkno, va, size) return ENXIO; /* Convert to disk sectors. Request must be a multiple of size. */ - lp = &sd->sc_dk.dk_label; + lp = sd->sc_dk.dk_label; sectorsize = lp->d_secsize; if ((size % sectorsize) != 0) return EFAULT; diff --git a/sys/dev/vnd.c b/sys/dev/vnd.c index 52b32f5eca80..921ca9981cb2 100644 --- a/sys/dev/vnd.c +++ b/sys/dev/vnd.c @@ -1,4 +1,4 @@ -/* $NetBSD: vnd.c,v 1.22 1995/11/06 20:28:09 thorpej Exp $ */ +/* $NetBSD: vnd.c,v 1.23 1996/01/07 22:03:33 thorpej Exp $ */ /* * Copyright (c) 1988 University of Utah. @@ -66,7 +66,6 @@ #include #include #include -#include #include #include #include @@ -113,7 +112,8 @@ struct vnd_softc { struct ucred *sc_cred; /* credentials */ int sc_maxactive; /* max # of active requests */ struct buf sc_tab; /* transfer queue */ - struct dkdevice sc_dkdev; /* generic disk device info */ + char sc_xname[8]; /* XXX external name */ + struct disk sc_dkdev; /* generic disk device info */ }; /* sc_flags */ @@ -400,6 +400,10 @@ vndstart(vnd) vnd-vnd_softc, bp, bp->b_vp, bp->b_blkno, bp->b_data, bp->b_bcount); #endif + + /* Instrumentation. */ + disk_busy(&vnd->sc_dkdev); + if ((bp->b_flags & B_READ) == 0) bp->b_vp->v_numoutput++; VOP_STRATEGY(bp); @@ -420,6 +424,7 @@ vndiodone(vbp) vnd-vnd_softc, vbp, vbp->vb_buf.b_vp, vbp->vb_buf.b_blkno, vbp->vb_buf.b_data, vbp->vb_buf.b_bcount); #endif + if (vbp->vb_buf.b_error) { #ifdef DEBUG if (vnddebug & VDB_IO) @@ -431,6 +436,7 @@ vndiodone(vbp) } pbp->b_resid -= vbp->vb_buf.b_bcount; putvndbuf(vbp); + disk_unbusy(&vnd->sc_dkdev, (pbp->b_bcount - pbp->b_resid)); if (pbp->b_resid == 0) { #ifdef DEBUG if (vnddebug & VDB_IO) @@ -567,6 +573,12 @@ vndioctl(dev, cmd, data, flag, p) vnd->sc_vp, vnd->sc_size); #endif + /* Attach the disk. */ + bzero(vnd->sc_xname, sizeof(vnd->sc_xname)); /* XXX */ + sprintf(vnd->sc_xname, "vnd%d", unit); /* XXX */ + vnd->sc_dkdev.dk_name = vnd->sc_xname; + disk_attach(&vnd->sc_dkdev); + vndunlock(vnd); break; @@ -598,6 +610,9 @@ vndioctl(dev, cmd, data, flag, p) printf("vndioctl: CLRed\n"); #endif + /* Detatch the disk. */ + disk_detatch(&vnd->sc_dkdev); + /* This must be atomic. */ s = splhigh(); vndunlock(vnd); diff --git a/sys/kern/init_main.c b/sys/kern/init_main.c index 4fb77e634f90..f439beda9807 100644 --- a/sys/kern/init_main.c +++ b/sys/kern/init_main.c @@ -1,4 +1,4 @@ -/* $NetBSD: init_main.c,v 1.79 1995/12/09 04:07:41 mycroft Exp $ */ +/* $NetBSD: init_main.c,v 1.80 1996/01/07 22:03:47 thorpej Exp $ */ /* * Copyright (c) 1995 Christopher G. Demetriou. All rights reserved. @@ -144,6 +144,7 @@ main(framep) extern struct pdevinit pdevinit[]; extern void roundrobin __P((void *)); extern void schedcpu __P((void *)); + extern void disk_init __P((void)); /* * Initialize the current process pointer (curproc) before @@ -160,6 +161,7 @@ main(framep) vm_mem_init(); kmeminit(); + disk_init(); /* must come before autoconfiguration */ cpu_startup(); /* diff --git a/sys/kern/subr_disk.c b/sys/kern/subr_disk.c index f3615211358f..8ec8d7d9d10b 100644 --- a/sys/kern/subr_disk.c +++ b/sys/kern/subr_disk.c @@ -1,6 +1,7 @@ -/* $NetBSD: subr_disk.c,v 1.14 1995/12/28 19:16:39 thorpej Exp $ */ +/* $NetBSD: subr_disk.c,v 1.15 1996/01/07 22:03:49 thorpej Exp $ */ /* + * Copyright (c) 1995 Jason R. Thorpe. All rights reserved. * Copyright (c) 1982, 1986, 1988, 1993 * The Regents of the University of California. All rights reserved. * (c) UNIX System Laboratories, Inc. @@ -42,11 +43,22 @@ #include #include +#include +#include #include -#include #include +#include +#include +#include #include /* XXX */ +/* + * A global list of all disks attached to the system. May grow or + * shrink over time. + */ +struct disklist_head disklist; /* TAILQ_HEAD */ +int disk_count; /* number of drives in global disklist */ + /* * Old-style disk instrumentation structures. These will go away * someday. @@ -57,7 +69,7 @@ long dk_wds[DK_NDRIVE]; long dk_wpms[DK_NDRIVE]; long dk_xfer[DK_NDRIVE]; int dk_busy; -int dk_ndrive = DK_NDRIVE; +int dk_ndrive; int dkn; /* number of slots filled so far */ /* @@ -231,3 +243,169 @@ diskerr(bp, dname, what, pri, blkdone, lp) (*pr)(" tn %d sn %d)", sn / lp->d_nsectors, sn % lp->d_nsectors); } } + +/* + * Initialize the disklist. Called by main() before autoconfiguration. + */ +void +disk_init() +{ + + TAILQ_INIT(&disklist); + disk_count = 0; + dk_ndrive = DK_NDRIVE; /* XXX */ +} + +/* + * Searches the disklist for the disk corresponding to the + * name provided. + */ +struct disk * +disk_find(name) + char *name; +{ + struct disk *diskp; + + if ((name == NULL) || (disk_count <= 0)) + return (NULL); + + for (diskp = disklist.tqh_first; diskp != NULL; + diskp = diskp->dk_link.tqe_next) + if (strcmp(diskp->dk_name, name) == 0) + return (diskp); + + return (NULL); +} + +/* + * Attach a disk. + */ +void +disk_attach(diskp) + struct disk *diskp; +{ + int s; + + /* + * Allocate and initialize the disklabel structures. Note that + * it's not safe to sleep here, since we're probably going to be + * called during autoconfiguration. + */ + diskp->dk_label = malloc(sizeof(struct disklabel), M_DEVBUF, M_NOWAIT); + diskp->dk_cpulabel = malloc(sizeof(struct cpu_disklabel), M_DEVBUF, + M_NOWAIT); + if ((diskp->dk_label == NULL) || (diskp->dk_cpulabel == NULL)) + panic("disk_attach: can't allocate storage for disklabel"); + + bzero(diskp->dk_label, sizeof(struct disklabel)); + bzero(diskp->dk_cpulabel, sizeof(struct cpu_disklabel)); + + /* + * Set the attached timestamp. + */ + s = splclock(); + diskp->dk_attachtime = mono_time; + splx(s); + + /* + * Link into the disklist. + */ + TAILQ_INSERT_TAIL(&disklist, diskp, dk_link); + ++disk_count; +} + +/* + * Detatch a disk. + */ +void +disk_detatch(diskp) + struct disk *diskp; +{ + + /* + * Free the space used by the disklabel structures. + */ + free(diskp->dk_label, M_DEVBUF); + free(diskp->dk_cpulabel, M_DEVBUF); + + /* + * Remove from the disklist. + */ + TAILQ_REMOVE(&disklist, diskp, dk_link); + if (--disk_count < 0) + panic("disk_detatch: disk_count < 0"); +} + +/* + * Increment a disk's busy counter. If the counter is going from + * 0 to 1, set the timestamp. + */ +void +disk_busy(diskp) + struct disk *diskp; +{ + int s; + + /* + * XXX We'd like to use something as accurate as microtime(), + * but that doesn't depend on the system TOD clock. + */ + if (diskp->dk_busy++ == 0) { + s = splclock(); + diskp->dk_timestamp = mono_time; + splx(s); + } +} + +/* + * Decrement a disk's busy counter, increment the byte count, total busy + * time, and reset the timestamp. + */ +void +disk_unbusy(diskp, bcount) + struct disk *diskp; + long bcount; +{ + int s; + struct timeval dv_time, diff_time; + + if (diskp->dk_busy-- == 0) + panic("disk_unbusy: %s: dk_busy < 0", diskp->dk_name); + + s = splclock(); + dv_time = mono_time; + splx(s); + + timersub(&dv_time, &diskp->dk_timestamp, &diff_time); + timeradd(&diskp->dk_time, &diff_time, &diskp->dk_time); + + diskp->dk_timestamp = dv_time; + if (bcount > 0) { + diskp->dk_bytes += bcount; + diskp->dk_xfer++; + } +} + +/* + * Reset the metrics counters on the given disk. Note that we cannot + * reset the busy counter, as it may case a panic in disk_unbusy(). + * We also must avoid playing with the timestamp information, as it + * may skew any pending transfer results. + */ +void +disk_resetstat(diskp) + struct disk *diskp; +{ + int s = splbio(), t; + + diskp->dk_xfer = 0; + diskp->dk_bytes = 0; + + t = splclock(); + diskp->dk_attachtime = mono_time; + splx(t); + + timerclear(&diskp->dk_time); + + splx(s); +} diff --git a/sys/scsi/cd.c b/sys/scsi/cd.c index ff08454ae2f4..5645837e2e16 100644 --- a/sys/scsi/cd.c +++ b/sys/scsi/cd.c @@ -1,4 +1,4 @@ -/* $NetBSD: cd.c,v 1.78 1995/12/07 19:11:32 thorpej Exp $ */ +/* $NetBSD: cd.c,v 1.79 1996/01/07 22:03:58 thorpej Exp $ */ /* * Copyright (c) 1994, 1995 Charles M. Hannum. All rights reserved. @@ -77,7 +77,7 @@ struct cd_softc { struct device sc_dev; - struct dkdevice sc_dk; + struct disk sc_dk; int flags; #define CDF_LOCKED 0x01 @@ -103,6 +103,7 @@ void cdgetdisklabel __P((struct cd_softc *)); int cd_get_parms __P((struct cd_softc *, int)); void cdstrategy __P((struct buf *)); void cdstart __P((struct cd_softc *)); +int cddone __P((struct scsi_xfer *)); struct dkdriver cddkdriver = { cdstrategy }; @@ -110,7 +111,7 @@ struct scsi_device cd_switch = { NULL, /* use default error handler */ cdstart, /* we have a queue, which is started by this */ NULL, /* we do not have an async handler */ - NULL, /* use default 'done' routine */ + cddone, /* deal with stats at interrupt time */ }; struct scsi_inquiry_pattern cd_patterns[] = { @@ -162,9 +163,15 @@ cdattach(parent, self, aux) if (sc_link->openings > CDOUTSTANDING) sc_link->openings = CDOUTSTANDING; + /* + * Initialize and attach the disk structure. + */ cd->sc_dk.dk_driver = &cddkdriver; + cd->sc_dk.dk_name = cd->sc_dev.dv_xname; + disk_attach(&cd->sc_dk); + #if !defined(i386) || defined(NEWCONFIG) - dk_establish(&cd->sc_dk, &cd->sc_dev); + dk_establish(&cd->sc_dk, &cd->sc_dev); /* XXX */ #endif printf("\n"); @@ -282,8 +289,8 @@ cdopen(dev, flag, fmt) /* Check that the partition exists. */ if (part != RAW_PART && - (part >= cd->sc_dk.dk_label.d_npartitions || - cd->sc_dk.dk_label.d_partitions[part].p_fstype == FS_UNUSED)) { + (part >= cd->sc_dk.dk_label->d_npartitions || + cd->sc_dk.dk_label->d_partitions[part].p_fstype == FS_UNUSED)) { error = ENXIO; goto bad; } @@ -374,7 +381,7 @@ cdstrategy(bp) /* * The transfer must be a whole number of blocks. */ - if ((bp->b_bcount % cd->sc_dk.dk_label.d_secsize) != 0) { + if ((bp->b_bcount % cd->sc_dk.dk_label->d_secsize) != 0) { bp->b_error = EINVAL; goto bad; } @@ -397,7 +404,7 @@ cdstrategy(bp) * If end of partition, just return. */ if (CDPART(bp->b_dev) != RAW_PART && - bounds_check_with_label(bp, &cd->sc_dk.dk_label, + bounds_check_with_label(bp, cd->sc_dk.dk_label, (cd->flags & (CDF_WLABEL|CDF_LABELLING)) != 0) <= 0) goto done; @@ -499,12 +506,12 @@ cdstart(cd) * of the logical blocksize of the device. */ blkno = - bp->b_blkno / (cd->sc_dk.dk_label.d_secsize / DEV_BSIZE); + bp->b_blkno / (cd->sc_dk.dk_label->d_secsize / DEV_BSIZE); if (CDPART(bp->b_dev) != RAW_PART) { - p = &cd->sc_dk.dk_label.d_partitions[CDPART(bp->b_dev)]; - blkno += p->p_offset; + p = &cd->sc_dk.dk_label->d_partitions[CDPART(bp->b_dev)]; + blkno += p->p_offset; } - nblks = howmany(bp->b_bcount, cd->sc_dk.dk_label.d_secsize); + nblks = howmany(bp->b_bcount, cd->sc_dk.dk_label->d_secsize); /* * Fill out the scsi command. If the transfer will @@ -541,6 +548,9 @@ cdstart(cd) cmdp = (struct scsi_generic *)&cmd_big; } + /* Instrumentation. */ + disk_busy(&cd->sc_dk); + /* * Call the routine that chats with the adapter. * Note: we cannot sleep as we may be an interrupt @@ -553,6 +563,18 @@ cdstart(cd) } } +int +cddone(xs) + struct scsi_xfer *xs; +{ + struct cd_softc *cd = xs->sc_link->device_softc; + + if (xs->bp != NULL) + disk_unbusy(&cd->sc_dk, (xs->bp->b_bcount - xs->bp->b_resid)); + + return (0); +} + int cdread(dev, uio) dev_t dev; @@ -600,13 +622,13 @@ cdioctl(dev, cmd, addr, flag, p) switch (cmd) { case DIOCGDINFO: - *(struct disklabel *)addr = cd->sc_dk.dk_label; + *(struct disklabel *)addr = *(cd->sc_dk.dk_label); return 0; case DIOCGPART: - ((struct partinfo *)addr)->disklab = &cd->sc_dk.dk_label; + ((struct partinfo *)addr)->disklab = cd->sc_dk.dk_label; ((struct partinfo *)addr)->part = - &cd->sc_dk.dk_label.d_partitions[CDPART(dev)]; + &cd->sc_dk.dk_label->d_partitions[CDPART(dev)]; return 0; case DIOCWDINFO: @@ -618,9 +640,9 @@ cdioctl(dev, cmd, addr, flag, p) return error; cd->flags |= CDF_LABELLING; - error = setdisklabel(&cd->sc_dk.dk_label, + error = setdisklabel(cd->sc_dk.dk_label, (struct disklabel *)addr, /*cd->sc_dk.dk_openmask : */0, - &cd->sc_dk.dk_cpulabel); + cd->sc_dk.dk_cpulabel); if (error == 0) { } @@ -851,10 +873,10 @@ void cdgetdisklabel(cd) struct cd_softc *cd; { - struct disklabel *lp = &cd->sc_dk.dk_label; + struct disklabel *lp = cd->sc_dk.dk_label; bzero(lp, sizeof(struct disklabel)); - bzero(&cd->sc_dk.dk_cpulabel, sizeof(struct cpu_disklabel)); + bzero(cd->sc_dk.dk_cpulabel, sizeof(struct cpu_disklabel)); lp->d_secsize = cd->params.blksize; lp->d_ntracks = 1; diff --git a/sys/scsi/sd.c b/sys/scsi/sd.c index 474ae5d0281d..f67911b16abf 100644 --- a/sys/scsi/sd.c +++ b/sys/scsi/sd.c @@ -1,4 +1,4 @@ -/* $NetBSD: sd.c,v 1.83 1995/12/07 21:54:24 thorpej Exp $ */ +/* $NetBSD: sd.c,v 1.84 1996/01/07 22:04:02 thorpej Exp $ */ /* * Copyright (c) 1994, 1995 Charles M. Hannum. All rights reserved. @@ -77,7 +77,7 @@ struct sd_softc { struct device sc_dev; - struct dkdevice sc_dk; + struct disk sc_dk; int flags; #define SDF_LOCKED 0x01 @@ -107,6 +107,7 @@ void sdgetdisklabel __P((struct sd_softc *)); int sd_get_parms __P((struct sd_softc *, int)); void sdstrategy __P((struct buf *)); void sdstart __P((struct sd_softc *)); +int sddone __P((struct scsi_xfer *)); void sdminphys __P((struct buf *)); struct dkdriver sddkdriver = { sdstrategy }; @@ -115,7 +116,7 @@ struct scsi_device sd_switch = { NULL, /* Use default error handler */ sdstart, /* have a queue, served by this */ NULL, /* have no async handler */ - NULL, /* Use default 'done' routine */ + sddone, /* deal with stats at interrupt time */ }; struct scsi_inquiry_pattern sd_patterns[] = { @@ -169,17 +170,24 @@ sdattach(parent, self, aux) if (sc_link->openings > SDOUTSTANDING) sc_link->openings = SDOUTSTANDING; + /* + * Initialize and attach the disk structure. + */ + sd->sc_dk.dk_driver = &sddkdriver; + sd->sc_dk.dk_name = sd->sc_dev.dv_xname; + disk_attach(&sd->sc_dk); + + sd->sc_dk.dk_driver = &sddkdriver; +#if !defined(i386) || defined(NEWCONFIG) + dk_establish(&sd->sc_dk, &sd->sc_dev); /* XXX */ +#endif + /* * Note if this device is ancient. This is used in sdminphys(). */ if ((sa->sa_inqbuf->version & SID_ANSII) == 0) sd->flags |= SDF_ANCIENT; - sd->sc_dk.dk_driver = &sddkdriver; -#if !defined(i386) || defined(NEWCONFIG) - dk_establish(&sd->sc_dk, &sd->sc_dev); -#endif - /* * Use the subdriver to request information regarding * the drive. We cannot use interrupts yet, so the @@ -307,8 +315,8 @@ sdopen(dev, flag, fmt) /* Check that the partition exists. */ if (part != RAW_PART && - (part >= sd->sc_dk.dk_label.d_npartitions || - sd->sc_dk.dk_label.d_partitions[part].p_fstype == FS_UNUSED)) { + (part >= sd->sc_dk.dk_label->d_npartitions || + sd->sc_dk.dk_label->d_partitions[part].p_fstype == FS_UNUSED)) { error = ENXIO; goto bad; } @@ -399,7 +407,7 @@ sdstrategy(bp) /* * The transfer must be a whole number of blocks. */ - if ((bp->b_bcount % sd->sc_dk.dk_label.d_secsize) != 0) { + if ((bp->b_bcount % sd->sc_dk.dk_label->d_secsize) != 0) { bp->b_error = EINVAL; goto bad; } @@ -421,7 +429,7 @@ sdstrategy(bp) * If end of partition, just return. */ if (SDPART(bp->b_dev) != RAW_PART && - bounds_check_with_label(bp, &sd->sc_dk.dk_label, + bounds_check_with_label(bp, sd->sc_dk.dk_label, (sd->flags & (SDF_WLABEL|SDF_LABELLING)) != 0) <= 0) goto done; @@ -523,12 +531,12 @@ sdstart(sd) * of the logical blocksize of the device. */ blkno = - bp->b_blkno / (sd->sc_dk.dk_label.d_secsize / DEV_BSIZE); + bp->b_blkno / (sd->sc_dk.dk_label->d_secsize / DEV_BSIZE); if (SDPART(bp->b_dev) != RAW_PART) { - p = &sd->sc_dk.dk_label.d_partitions[SDPART(bp->b_dev)]; - blkno += p->p_offset; + p = &sd->sc_dk.dk_label->d_partitions[SDPART(bp->b_dev)]; + blkno += p->p_offset; } - nblks = howmany(bp->b_bcount, sd->sc_dk.dk_label.d_secsize); + nblks = howmany(bp->b_bcount, sd->sc_dk.dk_label->d_secsize); /* * Fill out the scsi command. If the transfer will @@ -565,6 +573,9 @@ sdstart(sd) cmdp = (struct scsi_generic *)&cmd_big; } + /* Instrumentation. */ + disk_busy(&sd->sc_dk); + /* * Call the routine that chats with the adapter. * Note: we cannot sleep as we may be an interrupt @@ -577,6 +588,18 @@ sdstart(sd) } } +int +sddone(xs) + struct scsi_xfer *xs; +{ + struct sd_softc *sd = xs->sc_link->device_softc; + + if (xs->bp != NULL) + disk_unbusy(&sd->sc_dk, (xs->bp->b_bcount - xs->bp->b_resid)); + + return (0); +} + void sdminphys(bp) struct buf *bp; @@ -596,7 +619,7 @@ sdminphys(bp) * in a 10-byte read/write actually means 0 blocks. */ if (sd->flags & SDF_ANCIENT) { - max = sd->sc_dk.dk_label.d_secsize * 0xff; + max = sd->sc_dk.dk_label->d_secsize * 0xff; if (bp->b_bcount > max) bp->b_bcount = max; @@ -648,13 +671,13 @@ sdioctl(dev, cmd, addr, flag, p) switch (cmd) { case DIOCGDINFO: - *(struct disklabel *)addr = sd->sc_dk.dk_label; + *(struct disklabel *)addr = *(sd->sc_dk.dk_label); return 0; case DIOCGPART: - ((struct partinfo *)addr)->disklab = &sd->sc_dk.dk_label; + ((struct partinfo *)addr)->disklab = sd->sc_dk.dk_label; ((struct partinfo *)addr)->part = - &sd->sc_dk.dk_label.d_partitions[SDPART(dev)]; + &sd->sc_dk.dk_label->d_partitions[SDPART(dev)]; return 0; case DIOCWDINFO: @@ -666,14 +689,14 @@ sdioctl(dev, cmd, addr, flag, p) return error; sd->flags |= SDF_LABELLING; - error = setdisklabel(&sd->sc_dk.dk_label, + error = setdisklabel(sd->sc_dk.dk_label, (struct disklabel *)addr, /*sd->sc_dk.dk_openmask : */0, - &sd->sc_dk.dk_cpulabel); + sd->sc_dk.dk_cpulabel); if (error == 0) { if (cmd == DIOCWDINFO) error = writedisklabel(SDLABELDEV(dev), - sdstrategy, &sd->sc_dk.dk_label, - &sd->sc_dk.dk_cpulabel); + sdstrategy, sd->sc_dk.dk_label, + sd->sc_dk.dk_cpulabel); } sd->flags &= ~SDF_LABELLING; @@ -707,11 +730,11 @@ void sdgetdisklabel(sd) struct sd_softc *sd; { - struct disklabel *lp = &sd->sc_dk.dk_label; + struct disklabel *lp = sd->sc_dk.dk_label; char *errstring; bzero(lp, sizeof(struct disklabel)); - bzero(&sd->sc_dk.dk_cpulabel, sizeof(struct cpu_disklabel)); + bzero(sd->sc_dk.dk_cpulabel, sizeof(struct cpu_disklabel)); lp->d_secsize = sd->params.blksize; lp->d_ntracks = sd->params.heads; @@ -745,7 +768,7 @@ sdgetdisklabel(sd) * Call the generic disklabel extraction routine */ if (errstring = readdisklabel(MAKESDDEV(0, sd->sc_dev.dv_unit, - RAW_PART), sdstrategy, lp, &sd->sc_dk.dk_cpulabel)) { + RAW_PART), sdstrategy, lp, sd->sc_dk.dk_cpulabel)) { printf("%s: %s\n", sd->sc_dev.dv_xname, errstring); return; } @@ -910,10 +933,10 @@ sdsize(dev) return -1; sd = sdcd.cd_devs[SDUNIT(dev)]; part = SDPART(dev); - if (sd->sc_dk.dk_label.d_partitions[part].p_fstype != FS_SWAP) + if (sd->sc_dk.dk_label->d_partitions[part].p_fstype != FS_SWAP) size = -1; else - size = sd->sc_dk.dk_label.d_partitions[part].p_size; + size = sd->sc_dk.dk_label->d_partitions[part].p_size; if (sdclose(dev, 0, S_IFBLK) != 0) return -1; return size; @@ -966,7 +989,7 @@ sddump(dev, blkno, va, size) return ENXIO; /* Convert to disk sectors. Request must be a multiple of size. */ - lp = &sd->sc_dk.dk_label; + lp = sd->sc_dk.dk_label; sectorsize = lp->d_secsize; if ((size % sectorsize) != 0) return EFAULT; diff --git a/sys/sys/disk.h b/sys/sys/disk.h index 9644c9a02ad5..9dd2afc75c3c 100644 --- a/sys/sys/disk.h +++ b/sys/sys/disk.h @@ -1,6 +1,7 @@ -/* $NetBSD: disk.h,v 1.8 1994/10/30 21:49:49 cgd Exp $ */ +/* $NetBSD: disk.h,v 1.9 1996/01/07 22:04:07 thorpej Exp $ */ /* + * Copyright (c) 1995 Jason R. Thorpe. All rights reserved. * Copyright (c) 1992, 1993 * The Regents of the University of California. All rights reserved. * @@ -48,26 +49,47 @@ /* * Disk device structures. - * - * Note that this is only a preliminary outline. The final disk structures - * may be somewhat different. */ -struct buf; -struct dkdevice { - struct device dk_dev; /* base device */ - struct dkdevice *dk_next; /* list of disks; not yet used */ - int dk_bps; /* xfer rate: bytes per second */ - int dk_bopenmask; /* block devices open */ - int dk_copenmask; /* character devices open */ - int dk_openmask; /* composite (bopen|copen) */ - int dk_state; /* label state ### */ - int dk_blkshift; /* shift to convert DEV_BSIZE to blks */ - int dk_byteshift; /* shift to convert bytes to blks */ +#include +#include + +struct buf; +struct disklabel; +struct cpu_disklabel; + +struct disk { + TAILQ_ENTRY(disk) dk_link; /* link in global disklist */ + char *dk_name; /* disk name */ + int dk_bopenmask; /* block devices open */ + int dk_copenmask; /* character devices open */ + int dk_openmask; /* composite (bopen|copen) */ + int dk_state; /* label state ### */ + int dk_blkshift; /* shift to convert DEV_BSIZE to blks */ + int dk_byteshift; /* shift to convert bytes to blks */ + + /* + * Metrics data; note that some metrics may have no meaning + * on certain types of disks. + */ + int dk_busy; /* busy counter */ + u_int64_t dk_xfer; /* total number of transfers */ + u_int64_t dk_seek; /* total independent seek operations */ + u_int64_t dk_bytes; /* total bytes transfered */ + struct timeval dk_attachtime; /* time disk was attached */ + struct timeval dk_timestamp; /* timestamp of last unbusy */ + struct timeval dk_time; /* total time spent busy */ + struct dkdriver *dk_driver; /* pointer to driver */ - daddr_t dk_labelsector; /* sector containing label */ - struct disklabel dk_label; /* label */ - struct cpu_disklabel dk_cpulabel; + + /* + * Disk label information. Storage for the in-core disk label + * must be dynamically allocated, otherwise the size of this + * structure becomes machine-dependent. + */ + daddr_t dk_labelsector; /* sector containing label */ + struct disklabel *dk_label; /* label */ + struct cpu_disklabel *dk_cpulabel; }; struct dkdriver { @@ -79,7 +101,7 @@ struct dkdriver { struct proc *)); int (*d_dump) __P((dev_t)); void (*d_start) __P((struct buf *, daddr_t)); - int (*d_mklabel) __P((struct dkdevice *)); + int (*d_mklabel) __P((struct disk *)); #endif }; @@ -105,3 +127,20 @@ struct disksort_stats { long ds_endsecond; /* # insertions at end of 2nd list */ }; #endif + +/* + * disklist_head is defined here so that user-land has access to it. + */ +TAILQ_HEAD(disklist_head, disk); /* the disklist is a TAILQ */ + +#ifdef _KERNEL +extern int disk_count; /* number of disks in global disklist */ + +void disk_init __P((void)); +void disk_attach __P((struct disk *)); +void disk_detach __P((struct disk *)); +void disk_busy __P((struct disk *)); +void disk_unbusy __P((struct disk *, long)); +void disk_resetstat __P((struct disk *)); +struct disk *disk_find __P((char *)); +#endif