diff options
author | Theo de Raadt <deraadt@cvs.openbsd.org> | 1996-01-12 20:21:37 +0000 |
---|---|---|
committer | Theo de Raadt <deraadt@cvs.openbsd.org> | 1996-01-12 20:21:37 +0000 |
commit | 6c3c7152302dce08b17b6fac14272fc435778145 (patch) | |
tree | cee094e02a544a7c9210d26eeda5c006c750989b /sys/arch/hp300/dev | |
parent | 484706ec2d7791c35fcf9aea53e46db186855c74 (diff) |
from netbsd;
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.
Diffstat (limited to 'sys/arch/hp300/dev')
-rw-r--r-- | sys/arch/hp300/dev/rd.c | 83 | ||||
-rw-r--r-- | sys/arch/hp300/dev/rd_compat.c | 3 | ||||
-rw-r--r-- | sys/arch/hp300/dev/rdvar.h | 12 | ||||
-rw-r--r-- | sys/arch/hp300/dev/sd.c | 65 | ||||
-rw-r--r-- | sys/arch/hp300/dev/sd_compat.c | 3 | ||||
-rw-r--r-- | sys/arch/hp300/dev/sdvar.h | 12 |
6 files changed, 115 insertions, 63 deletions
diff --git a/sys/arch/hp300/dev/rd.c b/sys/arch/hp300/dev/rd.c index 2b479345a3a..d1c480c72ea 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 <sys/systm.h> #include <sys/buf.h> #include <sys/stat.h> -#include <sys/dkstat.h> +#include <sys/dkstat.h> /* XXX */ #include <sys/disklabel.h> +#include <sys/disk.h> #include <sys/ioctl.h> #include <sys/fcntl.h> @@ -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 239dd4bc0e6..4adea53bcbd 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 <sys/param.h> #include <sys/disklabel.h> +#include <sys/disk.h> #include <hp300/dev/device.h> #include <hp300/dev/rdreg.h> #include <hp300/dev/rdvar.h> diff --git a/sys/arch/hp300/dev/rdvar.h b/sys/arch/hp300/dev/rdvar.h index 6d1214d46a7..97c21aa9b35 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 c6c26a42bbb..9355625f981 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 <sys/systm.h> #include <sys/buf.h> #include <sys/stat.h> -#include <sys/dkstat.h> +#include <sys/dkstat.h> /* XXX */ #include <sys/disklabel.h> +#include <sys/disk.h> #include <sys/malloc.h> #include <sys/proc.h> #include <sys/ioctl.h> @@ -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 106a2a518e2..60e25a63b81 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 <sys/param.h> #include <sys/disklabel.h> +#include <sys/disk.h> #include <hp300/dev/device.h> #include <hp300/dev/sdvar.h> diff --git a/sys/arch/hp300/dev/sdvar.h b/sys/arch/hp300/dev/sdvar.h index 13a74c6398a..e5933f53a8d 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 */ |