From 2f0183bf9ee1a71099763f7fe9b654d8d06cf85f Mon Sep 17 00:00:00 2001 From: Artur Grabowski Date: Tue, 29 May 2007 18:50:09 +0000 Subject: Change getnewbuf from taking lots of sleep arguments and then doing magic with them and trying to pass an error back after sleep, to just fail with NULL and let the caller wait for buffers. Introduce buf_wait() that does all the sleep magic and use buf_wait in the getnewbuf callers where it matters. pedro@ beck@ ok --- sys/kern/vfs_bio.c | 44 ++++++++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 20 deletions(-) (limited to 'sys') diff --git a/sys/kern/vfs_bio.c b/sys/kern/vfs_bio.c index ce7ca9740c5..8efe5916313 100644 --- a/sys/kern/vfs_bio.c +++ b/sys/kern/vfs_bio.c @@ -1,4 +1,4 @@ -/* $OpenBSD: vfs_bio.c,v 1.90 2007/05/28 22:18:48 thib Exp $ */ +/* $OpenBSD: vfs_bio.c,v 1.91 2007/05/29 18:50:08 art Exp $ */ /* $NetBSD: vfs_bio.c,v 1.44 1996/06/11 11:15:36 pk Exp $ */ /*- @@ -104,7 +104,8 @@ void buf_put(struct buf *); #define binstailfree(bp, dp) TAILQ_INSERT_TAIL(dp, bp, b_freelist) static __inline struct buf *bio_doread(struct vnode *, daddr64_t, int, int); -struct buf *getnewbuf(size_t, int, int, int *); +struct buf *getnewbuf(size_t); +int buf_wait(int, int); void buf_init(struct buf *, int); void bread_cluster_callback(struct buf *); @@ -501,7 +502,7 @@ bread_cluster(struct vnode *vp, daddr64_t blkno, int size, struct buf **rbpp) xbpp[howmany] = 0; - bp = getnewbuf(howmany * size, 0, 0, NULL); + bp = getnewbuf(howmany * size); if (bp == NULL) { for (i = 0; i < howmany; i++) { SET(xbpp[i]->b_flags, B_INVAL); @@ -899,8 +900,9 @@ start: nb = NULL; } if (bp == NULL && nb == NULL) { - nb = getnewbuf(size, slpflag, slptimeo, &error); + nb = getnewbuf(size); if (nb == NULL) { + error = buf_wait(slpflag, slptimeo); if (error == ERESTART || error == EINTR) return (NULL); } @@ -925,8 +927,8 @@ geteblk(int size) { struct buf *bp; - while ((bp = getnewbuf(size, 0, 0, NULL)) == NULL) - ; + while ((bp = getnewbuf(size)) == NULL) + buf_wait(0, 0); SET(bp->b_flags, B_INVAL); binshash(bp, &invalhash); @@ -937,10 +939,10 @@ geteblk(int size) * Find a buffer which is available for use. */ struct buf * -getnewbuf(size_t size, int slpflag, int slptimeo, int *ep) +getnewbuf(size_t size) { struct buf *bp; - int s, error, queue, qs; + int s, queue, qs; #if 0 /* we would really like this but sblock update kills it */ KASSERT(curproc != syncerproc && curproc != cleanerproc); @@ -994,18 +996,7 @@ getsome: goto getsome; } if (bp == NULL) { - /* wait for a free buffer of any kind */ - needbuffer++; - error = tsleep(&needbuffer, slpflag | (PRIBIO + 1), - "getnewbuf", slptimeo); - if (ep != NULL) { - *ep = error; - if (error) { - splx(s); - return (NULL); - } - } - goto getsome; + return (NULL); } bremfree(bp); @@ -1044,6 +1035,19 @@ getsome: return (bp); } +int +buf_wait(int flag, int timeo) +{ + int s, error; + + s = splbio(); + needbuffer++; + error = tsleep(&needbuffer, flag | (PRIBIO + 1), "buf_wait", timeo); + splx(s); + + return (error); +} + /* * Buffer cleaning daemon. */ -- cgit v1.2.3