Module Name:    src
Committed By:   jdolecek
Date:           Sun Apr 12 17:02:52 UTC 2020

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

Log Message:
fix wapbl_discard() to actually discard the queued bufs properly - need
to set BC_INVAL for them, and also need to explicitly remove them
from the BQ_LOCKED queue

fixes DIAGNOSTIC panic when force unmounting unresponsive disk device
PR kern/51178 by Michael van Elst


To generate a diff of this commit:
cvs rdiff -u -r1.107 -r1.108 src/sys/kern/vfs_wapbl.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_wapbl.c
diff -u src/sys/kern/vfs_wapbl.c:1.107 src/sys/kern/vfs_wapbl.c:1.108
--- src/sys/kern/vfs_wapbl.c:1.107	Sun Apr 12 08:51:41 2020
+++ src/sys/kern/vfs_wapbl.c	Sun Apr 12 17:02:52 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: vfs_wapbl.c,v 1.107 2020/04/12 08:51:41 jdolecek Exp $	*/
+/*	$NetBSD: vfs_wapbl.c,v 1.108 2020/04/12 17:02:52 jdolecek Exp $	*/
 
 /*-
  * Copyright (c) 2003, 2008, 2009 The NetBSD Foundation, Inc.
@@ -36,7 +36,7 @@
 #define WAPBL_INTERNAL
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: vfs_wapbl.c,v 1.107 2020/04/12 08:51:41 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfs_wapbl.c,v 1.108 2020/04/12 17:02:52 jdolecek Exp $");
 
 #include <sys/param.h>
 #include <sys/bitops.h>
@@ -777,12 +777,16 @@ wapbl_discard(struct wapbl *wl)
 	mutex_enter(&wl->wl_mtx);
 	while ((bp = TAILQ_FIRST(&wl->wl_bufs)) != NULL) {
 		if (bbusy(bp, 0, 0, &wl->wl_mtx) == 0) {
+			KASSERT(bp->b_flags & B_LOCKED);
+			KASSERT(bp->b_oflags & BO_DELWRI);
 			/*
+			 * Buffer is already on BQ_LOCKED queue.
 			 * The buffer will be unlocked and
-			 * removed from the transaction in brelse
+			 * removed from the transaction in brelsel()
 			 */
 			mutex_exit(&wl->wl_mtx);
-			brelsel(bp, 0);
+			bremfree(bp);
+			brelsel(bp, BC_INVAL);
 			mutex_enter(&wl->wl_mtx);
 		}
 	}

Reply via email to