From c77a6aac71fe7811e361a79ab6dc41841b9f5c43 Mon Sep 17 00:00:00 2001 From: beck Date: Wed, 23 Jul 2008 16:24:42 +0000 Subject: [PATCH] Correct cases of mishandling of pending reads and writes to prevent them going negative - this consists of identifying a number of cases of IO not going through the buffer cache and marking those buffers with B_RAW - as well as fixing nfs_bio to show pending writes and reads through the buffer cache via NFS still has a problem with mishandling the counters I believe in the async/sync fallback case where counters stay positive which will be addressed seperately. ok tedu@ deraadt@ --- share/man/man9/buffercache.9 | 11 ++++++++--- sys/arch/aviion/aviion/disksubr.c | 4 ++-- sys/dev/raidframe/rf_openbsdkintf.c | 6 +++--- sys/dev/vnd.c | 4 +++- sys/isofs/cd9660/cd9660_vfsops.c | 4 ++-- sys/isofs/udf/udf_subr.c | 6 +++--- sys/nfs/nfs_bio.c | 7 ++++++- sys/nfs/nfs_vnops.c | 3 ++- 8 files changed, 29 insertions(+), 16 deletions(-) diff --git a/share/man/man9/buffercache.9 b/share/man/man9/buffercache.9 index dc6d02ec441..6b855defed8 100644 --- a/share/man/man9/buffercache.9 +++ b/share/man/man9/buffercache.9 @@ -1,4 +1,4 @@ -.\" $OpenBSD: buffercache.9,v 1.5 2007/05/31 19:20:00 jmc Exp $ +.\" $OpenBSD: buffercache.9,v 1.6 2008/07/23 16:24:43 beck Exp $ .\" $NetBSD: buffercache.9,v 1.13 2004/06/25 15:31:37 wiz Exp $ .\" .\" Copyright (c)2003 YAMAMOTO Takashi, @@ -102,7 +102,7 @@ .\" .\" .\" ------------------------------------------------------------ -.Dd $Mdocdate: May 31 2007 $ +.Dd $Mdocdate: July 23 2008 $ .Dt BUFFERCACHE 9 .Os .Sh NAME @@ -327,7 +327,12 @@ Otherwise, wake up the waiting processes. .\" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - .It Fn biowait "bp" Wait for operations on the buffer to complete. -When they do, extract and return the I/O's error value. +When they do, extract and return the I/O's error value. +If the operation on the buffer is being done via a direct call to a +.Fn strategy +type function, then the buffer must be previously initialized with the +.Dv B_RAW +flag. .El .\" ------------------------------------------------------------ .Sh CODE REFERENCES diff --git a/sys/arch/aviion/aviion/disksubr.c b/sys/arch/aviion/aviion/disksubr.c index 575ae057f1c..e9cc38389f5 100644 --- a/sys/arch/aviion/aviion/disksubr.c +++ b/sys/arch/aviion/aviion/disksubr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: disksubr.c,v 1.43 2008/06/12 06:58:33 deraadt Exp $ */ +/* $OpenBSD: disksubr.c,v 1.44 2008/07/23 16:24:42 beck Exp $ */ /* $NetBSD: disksubr.c,v 1.21 1996/05/03 19:42:03 christos Exp $ */ /* @@ -114,7 +114,7 @@ writedisklabel(dev_t dev, void (*strat)(struct buf *), struct disklabel *lp) /* Read it in, slap the new label in, and write it back out */ bp->b_blkno = partoff + LABELSECTOR; bp->b_bcount = lp->d_secsize; - bp->b_flags = B_BUSY | B_READ; + bp->b_flags = B_BUSY | B_READ | B_RAW; (*strat)(bp); if ((error = biowait(bp)) != 0) goto done; diff --git a/sys/dev/raidframe/rf_openbsdkintf.c b/sys/dev/raidframe/rf_openbsdkintf.c index 46f9f9b8054..cac048abce7 100644 --- a/sys/dev/raidframe/rf_openbsdkintf.c +++ b/sys/dev/raidframe/rf_openbsdkintf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rf_openbsdkintf.c,v 1.49 2008/06/26 05:42:17 ray Exp $ */ +/* $OpenBSD: rf_openbsdkintf.c,v 1.50 2008/07/23 16:24:43 beck Exp $ */ /* $NetBSD: rf_netbsdkintf.c,v 1.109 2001/07/27 03:30:07 oster Exp $ */ /*- @@ -2285,7 +2285,7 @@ raidread_component_label(dev_t dev, struct vnode *b_vp, /* Get our ducks in a row for the read. */ bp->b_blkno = RF_COMPONENT_INFO_OFFSET / DEV_BSIZE; bp->b_bcount = RF_COMPONENT_INFO_SIZE; - bp->b_flags |= B_READ; + bp->b_flags |= (B_READ | B_RAW); bp->b_resid = RF_COMPONENT_INFO_SIZE / DEV_BSIZE; (*bdevsw[major(bp->b_dev)].d_strategy)(bp); @@ -2320,7 +2320,7 @@ raidwrite_component_label(dev_t dev, struct vnode *b_vp, /* Get our ducks in a row for the write. */ bp->b_blkno = RF_COMPONENT_INFO_OFFSET / DEV_BSIZE; bp->b_bcount = RF_COMPONENT_INFO_SIZE; - bp->b_flags |= B_WRITE; + bp->b_flags |= (B_WRITE | B_RAW); bp->b_resid = RF_COMPONENT_INFO_SIZE / DEV_BSIZE; memset(bp->b_data, 0, RF_COMPONENT_INFO_SIZE ); diff --git a/sys/dev/vnd.c b/sys/dev/vnd.c index 85be177912d..602f56f2006 100644 --- a/sys/dev/vnd.c +++ b/sys/dev/vnd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: vnd.c,v 1.87 2008/07/20 01:53:43 krw Exp $ */ +/* $OpenBSD: vnd.c,v 1.88 2008/07/23 16:24:43 beck Exp $ */ /* $NetBSD: vnd.c,v 1.26 1996/03/30 23:06:11 christos Exp $ */ /* @@ -652,6 +652,8 @@ vndiodone(struct buf *bp) vbp->vb_buf.b_error); pbp->b_flags |= B_ERROR; + /* XXX does this matter here? */ + (&vbp->vb_buf)->b_flags |= B_RAW; pbp->b_error = biowait(&vbp->vb_buf); } pbp->b_resid -= vbp->vb_buf.b_bcount; diff --git a/sys/isofs/cd9660/cd9660_vfsops.c b/sys/isofs/cd9660/cd9660_vfsops.c index 7a162c87f6e..8e9b64f36e8 100644 --- a/sys/isofs/cd9660/cd9660_vfsops.c +++ b/sys/isofs/cd9660/cd9660_vfsops.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cd9660_vfsops.c,v 1.47 2007/10/03 10:52:11 krw Exp $ */ +/* $OpenBSD: cd9660_vfsops.c,v 1.48 2008/07/23 16:24:43 beck Exp $ */ /* $NetBSD: cd9660_vfsops.c,v 1.26 1997/06/13 15:38:58 pk Exp $ */ /*- @@ -476,7 +476,7 @@ iso_disklabelspoof(dev, strat, lp) for (iso_blknum = 16; iso_blknum < 100; iso_blknum++) { bp->b_blkno = iso_blknum * btodb(ISO_DEFAULT_BLOCK_SIZE); bp->b_bcount = ISO_DEFAULT_BLOCK_SIZE; - bp->b_flags = B_BUSY | B_READ; + bp->b_flags = B_BUSY | B_READ | B_RAW; bp->b_cylinder = bp->b_blkno / lp->d_secpercyl; /*printf("d_secsize %d iso_blknum %d b_blkno %d bcount %d\n", diff --git a/sys/isofs/udf/udf_subr.c b/sys/isofs/udf/udf_subr.c index 3ffa57e28eb..794d69c4f26 100644 --- a/sys/isofs/udf/udf_subr.c +++ b/sys/isofs/udf/udf_subr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: udf_subr.c,v 1.17 2008/06/12 06:58:39 deraadt Exp $ */ +/* $OpenBSD: udf_subr.c,v 1.18 2008/07/23 16:24:43 beck Exp $ */ /* * Copyright (c) 2006, Miodrag Vallat @@ -110,7 +110,7 @@ udf_disklabelspoof(dev_t dev, void (*strat)(struct buf *), */ bp->b_blkno = sector * btodb(bsize); bp->b_bcount = bsize; - bp->b_flags |= B_READ; + bp->b_flags |= (B_READ | B_RAW); bp->b_resid = bp->b_blkno / lp->d_secpercyl; (*strat)(bp); @@ -130,7 +130,7 @@ udf_disklabelspoof(dev_t dev, void (*strat)(struct buf *), for (sector = mvds_start; sector < mvds_end; sector++) { bp->b_blkno = sector * btodb(bsize); bp->b_bcount = bsize; - bp->b_flags |= B_READ; + bp->b_flags |= (B_READ | B_RAW); bp->b_resid = bp->b_blkno / lp->d_secpercyl; (*strat)(bp); diff --git a/sys/nfs/nfs_bio.c b/sys/nfs/nfs_bio.c index 929152321e0..70e6e3fc398 100644 --- a/sys/nfs/nfs_bio.c +++ b/sys/nfs/nfs_bio.c @@ -1,4 +1,4 @@ -/* $OpenBSD: nfs_bio.c,v 1.51 2008/06/14 19:33:58 beck Exp $ */ +/* $OpenBSD: nfs_bio.c,v 1.52 2008/07/23 16:24:43 beck Exp $ */ /* $NetBSD: nfs_bio.c,v 1.25.4.2 1996/07/08 20:47:04 jtc Exp $ */ /* @@ -607,11 +607,13 @@ nfs_doio(bp, p) if (bp->b_flags & B_READ) { uiop->uio_rw = UIO_READ; nfsstats.read_physios++; + bcstats.pendingreads++; /* XXX */ error = nfs_readrpc(vp, uiop); } else { iomode = NFSV3WRITE_DATASYNC; uiop->uio_rw = UIO_WRITE; nfsstats.write_physios++; + bcstats.pendingwrites++; /* XXX */ error = nfs_writerpc(vp, uiop, &iomode, &must_commit); } if (error) { @@ -626,6 +628,7 @@ nfs_doio(bp, p) case VREG: uiop->uio_offset = ((off_t)bp->b_blkno) << DEV_BSHIFT; nfsstats.read_bios++; + bcstats.pendingreads++; error = nfs_readrpc(vp, uiop); if (!error) { bp->b_validoff = 0; @@ -657,6 +660,7 @@ nfs_doio(bp, p) case VLNK: uiop->uio_offset = (off_t)0; nfsstats.readlink_bios++; + bcstats.pendingreads++; /* XXX */ error = nfs_readlinkrpc(vp, uiop, curproc->p_ucred); break; default: @@ -675,6 +679,7 @@ nfs_doio(bp, p) io.iov_base = (char *)bp->b_data + bp->b_dirtyoff; uiop->uio_rw = UIO_WRITE; nfsstats.write_bios++; + bcstats.pendingwrites++; /* XXX */ if ((bp->b_flags & (B_ASYNC | B_NEEDCOMMIT | B_NOCACHE)) == B_ASYNC) iomode = NFSV3WRITE_UNSTABLE; else diff --git a/sys/nfs/nfs_vnops.c b/sys/nfs/nfs_vnops.c index 2741ca34473..bc1e604c86a 100644 --- a/sys/nfs/nfs_vnops.c +++ b/sys/nfs/nfs_vnops.c @@ -1,4 +1,4 @@ -/* $OpenBSD: nfs_vnops.c,v 1.95 2008/07/23 11:53:07 art Exp $ */ +/* $OpenBSD: nfs_vnops.c,v 1.96 2008/07/23 16:24:43 beck Exp $ */ /* $NetBSD: nfs_vnops.c,v 1.62.4.1 1996/07/08 20:26:52 jtc Exp $ */ /* @@ -2997,6 +2997,7 @@ nfs_writebp(bp, force) } if( (oldflags & B_ASYNC) == 0) { + bp->b_flags |= B_RAW; int rtval = biowait(bp); if (!(oldflags & B_DELWRI) && p) { ++p->p_stats->p_ru.ru_oublock; -- 2.20.1