From 6c3c7152302dce08b17b6fac14272fc435778145 Mon Sep 17 00:00:00 2001 From: Theo de Raadt Date: Fri, 12 Jan 1996 20:21:37 +0000 Subject: 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. --- sys/arch/sparc/dev/xy.c | 79 ++++++++++++++++++++++++++++++------------------- 1 file changed, 48 insertions(+), 31 deletions(-) (limited to 'sys/arch/sparc/dev/xy.c') diff --git a/sys/arch/sparc/dev/xy.c b/sys/arch/sparc/dev/xy.c index 1242776426a..eeda0e56703 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/15 13:56:29 deraadt Exp $ + * id: $Id: xy.c,v 1.3 1996/01/12 20:20:53 deraadt 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: -- cgit v1.2.3