summaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorArtur Grabowski <art@cvs.openbsd.org>2001-10-28 00:42:44 +0000
committerArtur Grabowski <art@cvs.openbsd.org>2001-10-28 00:42:44 +0000
commitb456a5c5be6b43b5b49bd6e7b1e2ae4311096c2b (patch)
tree86d29d7f7a225b38b0a6cf69d91f2241fb4a7d19 /sys
parentd9db08bd116ac703aaafdc5cc7dfbb366b43b1c2 (diff)
Sprinkle some assertions in the buffer code.
Add a new DEBUG function "buf_print" that prints the contents of struct buf.
Diffstat (limited to 'sys')
-rw-r--r--sys/kern/vfs_bio.c72
-rw-r--r--sys/sys/buf.h6
2 files changed, 73 insertions, 5 deletions
diff --git a/sys/kern/vfs_bio.c b/sys/kern/vfs_bio.c
index 97be296ac4d..27d8a10fd33 100644
--- a/sys/kern/vfs_bio.c
+++ b/sys/kern/vfs_bio.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: vfs_bio.c,v 1.45 2001/10/11 14:44:10 art Exp $ */
+/* $OpenBSD: vfs_bio.c,v 1.46 2001/10/28 00:42:43 art Exp $ */
/* $NetBSD: vfs_bio.c,v 1.44 1996/06/11 11:15:36 pk Exp $ */
/*-
@@ -524,6 +524,8 @@ brelse(bp)
/* Block disk interrupts. */
s = splbio();
+ KASSERT(ISSET(bp->b_flags, B_BUSY));
+
/*
* Determine which queue the buffer should be on, then put it there.
*/
@@ -757,6 +759,7 @@ allocbuf(bp, size)
if (bp->b_bufsize == desired_size)
goto out;
+ KASSERT(!ISSET(bp->b_flags, (B_CACHE|B_DONE|B_DELWRI)));
/*
* If the buffer is smaller than the desired size, we need to snarf
* it from other buffers. Get buffers (via getnewbuf()), and
@@ -797,7 +800,7 @@ allocbuf(bp, size)
*/
if (bp->b_bufsize > desired_size) {
s = splbio();
- if ((nbp = bufqueues[BQ_EMPTY].tqh_first) == NULL) {
+ if ((nbp = TAILQ_FIRST(&bufqueues[BQ_EMPTY])) == NULL) {
/* No free buffer head */
splx(s);
goto out;
@@ -873,6 +876,8 @@ start:
bremfree(bp);
+ KASSERT(!ISSET(bp->b_flags, B_BUSY));
+
/* Buffer is no longer on free lists. */
SET(bp->b_flags, B_BUSY);
@@ -1041,9 +1046,11 @@ biodone(bp)
CLR(bp->b_flags, B_CALL); /* but note callout done */
(*bp->b_iodone)(bp);
} else {
- if (ISSET(bp->b_flags, B_ASYNC)) {/* if async, release it */
+ if (ISSET(bp->b_flags, B_ASYNC)) {
+ /* if async, release it */
brelse(bp);
- } else { /* or just wakeup the buffer */
+ } else {
+ /* or just wakeup the buffer */
CLR(bp->b_flags, B_WANTED);
wakeup(bp);
}
@@ -1052,6 +1059,63 @@ biodone(bp)
#ifdef DEBUG
/*
+ * Print as much as possible about a buffer.
+ */
+void
+buf_print(struct buf *bp)
+{
+ int f = 1;
+
+#define FLAG(fl) if (bp->b_flags & (fl)) { if (!f) printf(", "); else f = 0; printf(#fl); }
+
+ printf("b_proc: %p\n", bp->b_proc);
+ printf("b_error: %d\n", bp->b_error);
+ printf("b_bufsize: %ld\n", bp->b_bufsize);
+ printf("b_bcount: %ld\n", bp->b_bcount);
+ printf("b_resid: %ld\n", (long)bp->b_resid);
+ printf("b_dev: (%d,%d)\n", minor(bp->b_dev), major(bp->b_dev));
+ printf("b_data: %p\n", bp->b_data);
+ printf("b_blkno: %ld\n", (long)bp->b_blkno);
+ printf("b_lblkno: %ld\n", (long)bp->b_lblkno);
+
+ printf("b_flags: ");
+
+ FLAG(B_AGE);
+ FLAG(B_NEEDCOMMIT);
+ FLAG(B_ASYNC);
+ FLAG(B_BAD);
+ FLAG(B_BUSY);
+ FLAG(B_CACHE);
+ FLAG(B_CALL);
+ FLAG(B_DELWRI);
+ FLAG(B_DIRTY);
+ FLAG(B_DONE);
+ FLAG(B_EINTR);
+ FLAG(B_ERROR);
+ FLAG(B_GATHERED);
+ FLAG(B_INVAL);
+ FLAG(B_LOCKED);
+ FLAG(B_NOCACHE);
+ FLAG(B_PAGET);
+ FLAG(B_PGIN);
+ FLAG(B_PHYS);
+ FLAG(B_RAW);
+ FLAG(B_READ);
+ FLAG(B_TAPE);
+ FLAG(B_UAREA);
+ FLAG(B_WANTED);
+ FLAG(B_WRITE);
+ FLAG(B_WRITEINPROG);
+ FLAG(B_XXX);
+ FLAG(B_DEFERRED);
+ FLAG(B_SCANNED);
+
+ printf("\n");
+
+#undef FLAG
+}
+
+/*
* Print out statistics on the current allocation of the buffer pool.
* Can be enabled to print out on every ``sync'' by setting "syncprt"
* in vfs_syscalls.c using sysctl.
diff --git a/sys/sys/buf.h b/sys/sys/buf.h
index f8f5cf70b0f..1894209a978 100644
--- a/sys/sys/buf.h
+++ b/sys/sys/buf.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: buf.h,v 1.29 2001/09/20 08:22:26 gluk Exp $ */
+/* $OpenBSD: buf.h,v 1.30 2001/10/28 00:42:43 art Exp $ */
/* $NetBSD: buf.h,v 1.25 1997/04/09 21:12:17 mycroft Exp $ */
/*
@@ -227,6 +227,10 @@ void bgetvp __P((struct vnode *, struct buf *));
void buf_replacevnode __P((struct buf *, struct vnode *));
void buf_daemon __P((struct proc *));
+#ifdef DEBUG
+void buf_print(struct buf *);
+#endif
+
static __inline void
buf_start(struct buf *bp)
{