Module Name:    src
Committed By:   hannken
Date:           Wed Aug 29 09:05:17 UTC 2018

Modified Files:
        src/sys/kern: vfs_bio.c

Log Message:
Make sure getnewbuf() runs bawrite() inside fstrans.
Use fstrans_start_nowait() to skip buffers that would block.


To generate a diff of this commit:
cvs rdiff -u -r1.276 -r1.277 src/sys/kern/vfs_bio.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/kern/vfs_bio.c
diff -u src/sys/kern/vfs_bio.c:1.276 src/sys/kern/vfs_bio.c:1.277
--- src/sys/kern/vfs_bio.c:1.276	Sat Oct 28 00:37:11 2017
+++ src/sys/kern/vfs_bio.c	Wed Aug 29 09:05:17 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: vfs_bio.c,v 1.276 2017/10/28 00:37:11 pgoyette Exp $	*/
+/*	$NetBSD: vfs_bio.c,v 1.277 2018/08/29 09:05:17 hannken Exp $	*/
 
 /*-
  * Copyright (c) 2007, 2008, 2009 The NetBSD Foundation, Inc.
@@ -123,7 +123,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: vfs_bio.c,v 1.276 2017/10/28 00:37:11 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfs_bio.c,v 1.277 2018/08/29 09:05:17 hannken Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_bufcache.h"
@@ -1360,11 +1360,12 @@ allocbuf(buf_t *bp, int size, int preser
  * Called with the buffer queues locked.
  * Return buffer locked.
  */
-buf_t *
+static buf_t *
 getnewbuf(int slpflag, int slptimeo, int from_bufq)
 {
 	buf_t *bp;
 	struct vnode *vp;
+	struct mount *transmp = NULL;
 
  start:
 	KASSERT(mutex_owned(&bufcache_lock));
@@ -1389,8 +1390,21 @@ getnewbuf(int slpflag, int slptimeo, int
 	}
 
 	KASSERT(mutex_owned(&bufcache_lock));
-	if ((bp = TAILQ_FIRST(&bufqueues[BQ_AGE].bq_queue)) != NULL ||
-	    (bp = TAILQ_FIRST(&bufqueues[BQ_LRU].bq_queue)) != NULL) {
+	if ((bp = TAILQ_FIRST(&bufqueues[BQ_AGE].bq_queue)) != NULL) {
+		KASSERT(!ISSET(bp->b_oflags, BO_DELWRI));
+	} else {
+		TAILQ_FOREACH(bp, &bufqueues[BQ_LRU].bq_queue, b_freelist) {
+			if (ISSET(bp->b_cflags, BC_VFLUSH) ||
+			    !ISSET(bp->b_oflags, BO_DELWRI))
+				break;
+			if (fstrans_start_nowait(bp->b_vp->v_mount) == 0) {
+				KASSERT(transmp == NULL);
+				transmp = bp->b_vp->v_mount;
+				break;
+			}
+		}
+	}
+	if (bp != NULL) {
 	    	KASSERT(!ISSET(bp->b_cflags, BC_BUSY) || ISSET(bp->b_cflags, BC_VFLUSH));
 		bremfree(bp);
 
@@ -1444,10 +1458,14 @@ getnewbuf(int slpflag, int slptimeo, int
 		SET(bp->b_cflags, BC_AGE);
 		mutex_exit(&bufcache_lock);
 		bawrite(bp);
+		KASSERT(transmp != NULL);
+		fstrans_done(transmp);
 		mutex_enter(&bufcache_lock);
 		return (NULL);
 	}
 
+	KASSERT(transmp == NULL);
+
 	vp = bp->b_vp;
 
 	/* clear out various other fields */

Reply via email to