Subject: Gather buf initializtion into a macro
To: None <tech-kern@netbsd.org>
From: Jason R Thorpe <thorpej@wasabisystems.com>
List: tech-kern
Date: 02/25/2003 12:23:36
--a8Wt8u1KmwUX3Y2C
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
The following patch gathers initialization of buf structures into
a macro, BUF_INIT(). Currently, this means initializing the b_dep
list and the b_interlock simplelock. This fixes a few places that
were missing b_interlock initialization, and yet a few more places
that were missing b_dep initialization.
I noticed a few other problems related to use of bufpool along the
way, but I will address that in a separate patch.
This should fix the LOCKDEBUG problems that Allen Briggs noticed.
--
-- Jason R. Thorpe <thorpej@wasabisystems.com>
--a8Wt8u1KmwUX3Y2C
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="buf_init.patch"
Index: arch/hp300/dev/sd.c
===================================================================
RCS file: /cvsroot/src/sys/arch/hp300/dev/sd.c,v
retrieving revision 1.58
diff -u -r1.58 sd.c
--- arch/hp300/dev/sd.c 2003/01/17 22:53:07 1.58
+++ arch/hp300/dev/sd.c 2003/02/25 19:41:35
@@ -352,11 +352,11 @@
bp = malloc(sizeof *bp, M_DEVBUF, M_WAITOK);
sc->sc_format_pid = curproc->p_pid;
memcpy(&sc->sc_cmdstore, &cap, sizeof cap);
+ BUF_INIT(bp);
bp->b_dev = dev;
bp->b_flags = B_READ | B_BUSY;
bp->b_data = (caddr_t)capbuf;
bp->b_bcount = capbufsize;
- LIST_INIT(&bp->b_dep);
sdstrategy(bp);
i = biowait(bp) ? sc->sc_sensestore.status : 0;
free(bp, M_DEVBUF);
@@ -631,6 +631,7 @@
M_WAITOK | M_ZERO);
cbuf = (caddr_t)malloc(bsize, M_DEVBUF, M_WAITOK);
+ BUF_INIT(cbp);
cbp->b_proc = curproc; /* XXX */
cbp->b_dev = bp->b_dev;
bn = bp->b_blkno;
Index: arch/sparc/dev/fd.c
===================================================================
RCS file: /cvsroot/src/sys/arch/sparc/dev/fd.c,v
retrieving revision 1.103
diff -u -r1.103 fd.c
--- arch/sparc/dev/fd.c 2003/02/05 21:38:38 1.103
+++ arch/sparc/dev/fd.c 2003/02/25 19:42:02
@@ -2115,7 +2115,7 @@
return (ENOBUFS);
memset((void *)bp, 0, sizeof(struct buf));
- simple_lock_init(&bp->b_interlock);
+ BUF_INIT(bp);
bp->b_flags = B_BUSY | B_PHYS | B_FORMAT;
bp->b_proc = p;
bp->b_dev = dev;
Index: dev/ccd.c
===================================================================
RCS file: /cvsroot/src/sys/dev/ccd.c,v
retrieving revision 1.82
diff -u -r1.82 ccd.c
--- dev/ccd.c 2003/02/05 21:38:39 1.82
+++ dev/ccd.c 2003/02/25 19:42:17
@@ -802,7 +802,7 @@
cbp = CCD_GETBUF();
if (cbp == NULL)
return (NULL);
- simple_lock_init(&cbp->cb_buf.b_interlock);
+ BUF_INIT(&cbp->cb_buf);
cbp->cb_buf.b_flags = bp->b_flags | B_CALL;
cbp->cb_buf.b_iodone = ccdiodone;
cbp->cb_buf.b_proc = bp->b_proc;
@@ -810,7 +810,6 @@
cbp->cb_buf.b_blkno = cbn + cboff;
cbp->cb_buf.b_data = addr;
cbp->cb_buf.b_vp = ci->ci_vp;
- LIST_INIT(&cbp->cb_buf.b_dep);
if (cs->sc_ileave == 0)
cbc = dbtob((u_int64_t)(ci->ci_size - cbn));
else
Index: dev/cgd.c
===================================================================
RCS file: /cvsroot/src/sys/dev/cgd.c,v
retrieving revision 1.7
diff -u -r1.7 cgd.c
--- dev/cgd.c 2003/02/05 21:38:40 1.7
+++ dev/cgd.c 2003/02/25 19:42:18
@@ -307,7 +307,7 @@
disk_unbusy(&dksc->sc_dkdev, 0, (bp->b_flags & B_READ));
return;
}
- simple_lock_init(&cbp->cb_buf.b_interlock);
+ BUF_INIT(&cbp->cb_buf);
cbp->cb_buf.b_data = newaddr;
cbp->cb_buf.b_flags = bp->b_flags | B_CALL;
cbp->cb_buf.b_iodone = cgdiodone;
@@ -315,7 +315,6 @@
cbp->cb_buf.b_dev = cs->sc_tdev;
cbp->cb_buf.b_blkno = bn;
cbp->cb_buf.b_vp = cs->sc_tvn;
- LIST_INIT(&cbp->cb_buf.b_dep);
cbp->cb_buf.b_bcount = bp->b_bcount;
/* context for cgdiodone */
Index: dev/vnd.c
===================================================================
RCS file: /cvsroot/src/sys/dev/vnd.c,v
retrieving revision 1.91
diff -u -r1.91 vnd.c
--- dev/vnd.c 2003/02/05 21:38:39 1.91
+++ dev/vnd.c 2003/02/25 19:42:19
@@ -490,7 +490,7 @@
s = splbio();
nbp = VND_GETBUF(vnd);
splx(s);
- simple_lock_init(&nbp->vb_buf.b_interlock);
+ BUF_INIT(&nbp->vb_buf);
nbp->vb_buf.b_flags = flags;
nbp->vb_buf.b_bcount = sz;
nbp->vb_buf.b_bufsize = round_page((ulong)addr + sz)
@@ -501,7 +501,6 @@
nbp->vb_buf.b_proc = bp->b_proc;
nbp->vb_buf.b_iodone = vndiodone;
nbp->vb_buf.b_vp = NULLVP;
- LIST_INIT(&nbp->vb_buf.b_dep);
nbp->vb_xfer = vnx;
Index: dev/ata/ata_raid.c
===================================================================
RCS file: /cvsroot/src/sys/dev/ata/ata_raid.c,v
retrieving revision 1.2
diff -u -r1.2 ata_raid.c
--- dev/ata/ata_raid.c 2003/02/05 21:38:40 1.2
+++ dev/ata/ata_raid.c 2003/02/25 19:42:20
@@ -296,8 +296,7 @@
int error;
bp = pool_get(&bufpool, PR_WAITOK);
- simple_lock_init(&bp->b_interlock);
- LIST_INIT(&bp->b_dep);
+ BUF_INIT(bp);
bp->b_vp = vp;
bp->b_dev = vp->v_rdev;
Index: dev/ata/ld_ataraid.c
===================================================================
RCS file: /cvsroot/src/sys/dev/ata/ld_ataraid.c,v
retrieving revision 1.3
diff -u -r1.3 ld_ataraid.c
--- dev/ata/ld_ataraid.c 2003/01/29 16:50:37 1.3
+++ dev/ata/ld_ataraid.c 2003/02/25 19:42:20
@@ -231,6 +231,7 @@
cbp = CBUF_GET();
if (cbp == NULL)
return (NULL);
+ BUF_INIT(&cbp->cb_buf);
cbp->cb_buf.b_flags = bp->b_flags | B_CALL;
cbp->cb_buf.b_iodone = sc->sc_iodone;
cbp->cb_buf.b_proc = bp->b_proc;
@@ -238,7 +239,6 @@
cbp->cb_buf.b_dev = sc->sc_vnodes[comp]->v_rdev;
cbp->cb_buf.b_blkno = bn + sc->sc_aai->aai_offset;
cbp->cb_buf.b_data = addr;
- LIST_INIT(&cbp->cb_buf.b_dep);
cbp->cb_buf.b_bcount = bcount;
/* Context for iodone */
Index: dev/isa/fd.c
===================================================================
RCS file: /cvsroot/src/sys/dev/isa/fd.c,v
retrieving revision 1.38
diff -u -r1.38 fd.c
--- dev/isa/fd.c 2003/02/05 22:14:01 1.38
+++ dev/isa/fd.c 2003/02/25 19:42:25
@@ -1491,7 +1491,7 @@
return ENOBUFS;
memset((void *)bp, 0, sizeof(struct buf));
- simple_lock_init(&bp->b_interlock);
+ BUF_INIT(bp);
bp->b_flags = B_BUSY | B_PHYS | B_FORMAT;
bp->b_proc = p;
bp->b_dev = dev;
Index: dev/raidframe/rf_netbsdkintf.c
===================================================================
RCS file: /cvsroot/src/sys/dev/raidframe/rf_netbsdkintf.c,v
retrieving revision 1.154
diff -u -r1.154 rf_netbsdkintf.c
--- dev/raidframe/rf_netbsdkintf.c 2003/02/05 21:38:40 1.154
+++ dev/raidframe/rf_netbsdkintf.c 2003/02/25 19:42:38
@@ -1840,15 +1840,13 @@
bp->b_error = ENOMEM;
return (ENOMEM);
}
- simple_lock_init(&raidbp->rf_buf.b_interlock);
+ BUF_INIT(&raidbp->rf_buf);
/*
* context for raidiodone
*/
raidbp->rf_obp = bp;
raidbp->req = req;
-
- LIST_INIT(&raidbp->rf_buf.b_dep);
switch (req->type) {
case RF_IO_TYPE_NOP: /* used primarily to unlock a locked queue */
Index: dev/scsipi/cd.c
===================================================================
RCS file: /cvsroot/src/sys/dev/scsipi/cd.c,v
retrieving revision 1.178
diff -u -r1.178 cd.c
--- dev/scsipi/cd.c 2003/02/05 21:38:41 1.178
+++ dev/scsipi/cd.c 2003/02/25 19:42:42
@@ -647,7 +647,7 @@
}
/* Set up the IOP to the bounce buffer. */
- simple_lock_init(&nbp->b_interlock);
+ BUF_INIT(nbp);
nbp->b_error = 0;
nbp->b_proc = bp->b_proc;
nbp->b_vp = NULLVP;
@@ -656,7 +656,6 @@
nbp->b_bufsize = count;
nbp->b_data = bounce;
- LIST_INIT(&nbp->b_dep);
nbp->b_rawblkno = blkno;
/* We need to do a read-modify-write operation */
@@ -889,6 +888,7 @@
}
/* Set up the IOP to the bounce buffer. */
+ BUF_INIT(nbp);
nbp->b_error = 0;
nbp->b_proc = bp->b_proc;
nbp->b_vp = NULLVP;
@@ -897,7 +897,6 @@
nbp->b_bufsize = bp->b_bufsize;
nbp->b_data = bp->b_data;
- LIST_INIT(&nbp->b_dep);
nbp->b_rawblkno = bp->b_rawblkno;
/* We need to do a read-modify-write operation */
Index: kern/kern_physio.c
===================================================================
RCS file: /cvsroot/src/sys/kern/kern_physio.c,v
retrieving revision 1.55
diff -u -r1.55 kern_physio.c
--- kern/kern_physio.c 2003/02/05 21:38:42 1.55
+++ kern/kern_physio.c 2003/02/25 19:42:43
@@ -275,7 +275,7 @@
bp = pool_get(&bufpool, PR_WAITOK);
splx(s);
memset(bp, 0, sizeof(*bp));
- simple_lock_init(&bp->b_interlock);
+ BUF_INIT(bp);
return(bp);
}
Index: kern/vfs_bio.c
===================================================================
RCS file: /cvsroot/src/sys/kern/vfs_bio.c,v
retrieving revision 1.90
diff -u -r1.90 vfs_bio.c
--- kern/vfs_bio.c 2003/02/06 11:46:49 1.90
+++ kern/vfs_bio.c 2003/02/25 19:42:47
@@ -175,10 +175,9 @@
for (i = 0; i < nbuf; i++) {
bp = &buf[i];
memset((char *)bp, 0, sizeof(*bp));
- simple_lock_init(&bp->b_interlock);
+ BUF_INIT(bp);
bp->b_dev = NODEV;
bp->b_vnbufs.le_next = NOLIST;
- LIST_INIT(&bp->b_dep);
bp->b_data = buffers + i * MAXBSIZE;
if (i < residual)
bp->b_bufsize = (base + 1) * PAGE_SIZE;
Index: miscfs/genfs/genfs_vnops.c
===================================================================
RCS file: /cvsroot/src/sys/miscfs/genfs/genfs_vnops.c,v
retrieving revision 1.72
diff -u -r1.72 genfs_vnops.c
--- miscfs/genfs/genfs_vnops.c 2003/02/17 23:48:11 1.72
+++ miscfs/genfs/genfs_vnops.c 2003/02/25 19:42:50
@@ -653,14 +653,13 @@
s = splbio();
mbp = pool_get(&bufpool, PR_WAITOK);
splx(s);
- simple_lock_init(&mbp->b_interlock);
+ BUF_INIT(mbp);
mbp->b_bufsize = totalbytes;
mbp->b_data = (void *)kva;
mbp->b_resid = mbp->b_bcount = bytes;
mbp->b_flags = B_BUSY|B_READ| (async ? B_CALL|B_ASYNC : 0);
mbp->b_iodone = (async ? uvm_aio_biodone : 0);
mbp->b_vp = vp;
- LIST_INIT(&mbp->b_dep);
/*
* if EOF is in the middle of the range, zero the part past EOF.
@@ -787,14 +786,13 @@
s = splbio();
bp = pool_get(&bufpool, PR_WAITOK);
splx(s);
- simple_lock_init(&bp->b_interlock);
+ BUF_INIT(bp);
bp->b_data = (char *)kva + offset - startoffset;
bp->b_resid = bp->b_bcount = iobytes;
bp->b_flags = B_BUSY|B_READ|B_CALL|B_ASYNC;
bp->b_iodone = uvm_aio_biodone1;
bp->b_vp = vp;
bp->b_proc = NULL;
- LIST_INIT(&bp->b_dep);
}
bp->b_lblkno = 0;
bp->b_private = mbp;
@@ -1409,7 +1407,7 @@
vp->v_numoutput += 2;
simple_unlock(&global_v_numoutput_slock);
mbp = pool_get(&bufpool, PR_WAITOK);
- simple_lock_init(&mbp->b_interlock);
+ BUF_INIT(mbp);
UVMHIST_LOG(ubchist, "vp %p mbp %p num now %d bytes 0x%x",
vp, mbp, vp->v_numoutput, bytes);
splx(s);
@@ -1419,7 +1417,6 @@
mbp->b_flags = B_BUSY|B_WRITE|B_AGE| (async ? (B_CALL|B_ASYNC) : 0);
mbp->b_iodone = uvm_aio_biodone;
mbp->b_vp = vp;
- LIST_INIT(&mbp->b_dep);
bp = NULL;
for (offset = startoffset;
@@ -1451,14 +1448,13 @@
UVMHIST_LOG(ubchist, "vp %p bp %p num now %d",
vp, bp, vp->v_numoutput, 0);
splx(s);
- simple_lock_init(&bp->b_interlock);
+ BUF_INIT(bp);
bp->b_data = (char *)kva +
(vaddr_t)(offset - pg->offset);
bp->b_resid = bp->b_bcount = iobytes;
bp->b_flags = B_BUSY|B_WRITE|B_CALL|B_ASYNC;
bp->b_iodone = uvm_aio_biodone1;
bp->b_vp = vp;
- LIST_INIT(&bp->b_dep);
}
bp->b_lblkno = 0;
bp->b_private = mbp;
@@ -1658,7 +1654,7 @@
bp = pool_get(&bufpool, PR_WAITOK);
splx(s);
- simple_lock_init(&bp->b_interlock);
+ BUF_INIT(bp);
bp->b_flags = B_BUSY | B_WRITE | B_AGE;
bp->b_vp = vp;
bp->b_lblkno = offset >> vp->v_mount->mnt_fs_bshift;
@@ -1666,7 +1662,6 @@
bp->b_bcount = npages << PAGE_SHIFT;
bp->b_bufsize = npages << PAGE_SHIFT;
bp->b_resid = 0;
- LIST_INIT(&bp->b_dep);
if (error) {
bp->b_flags |= B_ERROR;
bp->b_error = error;
Index: sys/buf.h
===================================================================
RCS file: /cvsroot/src/sys/sys/buf.h,v
retrieving revision 1.57
diff -u -r1.57 buf.h
--- sys/buf.h 2003/02/05 21:38:43 1.57
+++ sys/buf.h 2003/02/25 19:42:52
@@ -182,6 +182,12 @@
struct workhead b_dep; /* List of filesystem dependencies. */
};
+#define BUF_INIT(bp) \
+do { \
+ LIST_INIT(&(bp)->b_dep); \
+ simple_lock_init(&(bp)->b_interlock); \
+} while (/*CONSTCOND*/0)
+
/*
* For portability with historic industry practice, the cylinder number has
* to be maintained in the `b_resid' field.
Index: ufs/lfs/lfs_bio.c
===================================================================
RCS file: /cvsroot/src/sys/ufs/lfs/lfs_bio.c,v
retrieving revision 1.61
diff -u -r1.61 lfs_bio.c
--- ufs/lfs/lfs_bio.c 2003/02/20 04:27:23 1.61
+++ ufs/lfs/lfs_bio.c 2003/02/25 19:42:56
@@ -646,7 +646,7 @@
bp = pool_get(&bufpool, PR_WAITOK);
splx(s);
memset(bp, 0, sizeof(struct buf));
- simple_lock_init(&bp->b_interlock);
+ BUF_INIT(bp);
if (nbytes) {
bp->b_data = lfs_malloc(fs, nbytes, type);
/* memset(bp->b_data, 0, nbytes); */
@@ -657,7 +657,6 @@
if (bp == NULL)
panic("bp is NULL after malloc in lfs_newbuf");
#endif
- simple_lock_init(&bp->b_interlock);
s = splbio();
bgetvp(vp, bp);
splx(s);
Index: ufs/lfs/lfs_vfsops.c
===================================================================
RCS file: /cvsroot/src/sys/ufs/lfs/lfs_vfsops.c,v
retrieving revision 1.98
diff -u -r1.98 lfs_vfsops.c
--- ufs/lfs/lfs_vfsops.c 2003/02/25 13:47:44 1.98
+++ ufs/lfs/lfs_vfsops.c 2003/02/25 19:42:58
@@ -1875,7 +1875,7 @@
splx(s);
memset(mbp, 0, sizeof(*bp));
- simple_lock_init(&mbp->b_interlock);
+ BUF_INIT(mbp);
UVMHIST_LOG(ubchist, "vp %p mbp %p num now %d bytes 0x%x",
vp, mbp, vp->v_numoutput, bytes);
mbp->b_bufsize = npages << PAGE_SHIFT;
@@ -1884,7 +1884,6 @@
mbp->b_flags = B_BUSY|B_WRITE|B_AGE|B_CALL;
mbp->b_iodone = uvm_aio_biodone;
mbp->b_vp = vp;
- LIST_INIT(&mbp->b_dep);
bp = NULL;
for (offset = startoffset;
@@ -1950,13 +1949,12 @@
vp, bp, vp->v_numoutput, 0);
splx(s);
memset(bp, 0, sizeof(*bp));
- simple_lock_init(&bp->b_interlock);
+ BUF_INIT(bp);
bp->b_data = (char *)kva +
(vaddr_t)(offset - pg->offset);
bp->b_resid = bp->b_bcount = iobytes;
bp->b_flags = B_BUSY|B_WRITE|B_CALL;
bp->b_iodone = uvm_aio_biodone1;
- LIST_INIT(&bp->b_dep);
}
/* XXX This is silly ... is this necessary? */
Index: uvm/uvm_swap.c
===================================================================
RCS file: /cvsroot/src/sys/uvm/uvm_swap.c,v
retrieving revision 1.76
diff -u -r1.76 uvm_swap.c
--- uvm/uvm_swap.c 2003/02/05 21:38:46 1.76
+++ uvm/uvm_swap.c 2003/02/25 19:43:00
@@ -1286,7 +1286,7 @@
* cast pointers between the two structure easily.
*/
getvndbuf(nbp);
- simple_lock_init(&nbp->vb_buf.b_interlock);
+ BUF_INIT(&nbp->vb_buf);
nbp->vb_buf.b_flags = bp->b_flags | B_CALL;
nbp->vb_buf.b_bcount = sz;
nbp->vb_buf.b_bufsize = sz;
@@ -1300,7 +1300,6 @@
if (vp->v_type == VBLK) {
nbp->vb_buf.b_dev = vp->v_rdev;
}
- LIST_INIT(&nbp->vb_buf.b_dep);
nbp->vb_xfer = vnx; /* patch it back in to vnx */
@@ -1699,7 +1698,7 @@
* /dev/drum's vnode [swapdev_vp].
*/
- simple_lock_init(&bp->b_interlock);
+ BUF_INIT(bp);
bp->b_flags = B_BUSY | B_NOCACHE | (flags & (B_READ|B_ASYNC));
bp->b_proc = &proc0; /* XXX */
bp->b_vnbufs.le_next = NOLIST;
@@ -1708,7 +1707,6 @@
bp->b_vp = swapdev_vp;
bp->b_dev = swapdev_vp->v_rdev;
bp->b_bufsize = bp->b_bcount = npages << PAGE_SHIFT;
- LIST_INIT(&bp->b_dep);
/*
* bump v_numoutput (counter of number of active outputs).
--a8Wt8u1KmwUX3Y2C--