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/sparc/dev/xd.c | |
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/sparc/dev/xd.c')
-rw-r--r-- | sys/arch/sparc/dev/xd.c | 80 |
1 files changed, 49 insertions, 31 deletions
diff --git a/sys/arch/sparc/dev/xd.c b/sys/arch/sparc/dev/xd.c index c4b9d55880e..2cf9bcef713 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 <chuck@ccrc.wustl.edu> - * id: $Id: xd.c,v 1.2 1995/12/15 13:56:27 deraadt Exp $ + * id: $Id: xd.c,v 1.3 1996/01/12 20:20:51 deraadt 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: |