git: 7dcb5db451b6 - stable/12 - vinvalbuf: do not panic if we were unable to flush dirty buffers

From: Alan Somers <asomers_at_FreeBSD.org>
Date: Thu, 07 Oct 2021 19:41:48 UTC
The branch stable/12 has been updated by asomers:

URL: https://cgit.FreeBSD.org/src/commit/?id=7dcb5db451b66aa277bd59c61c18a5053c658915

commit 7dcb5db451b66aa277bd59c61c18a5053c658915
Author:     Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2021-05-30 16:52:42 +0000
Commit:     Alan Somers <asomers@FreeBSD.org>
CommitDate: 2021-10-07 19:34:19 +0000

    vinvalbuf: do not panic if we were unable to flush dirty buffers
    
    Return EBUSY instead and let caller to handle the issue.
    
    For vgone()/vnode reclamation, caller first does vinvalbuf(V_SAVE),
    which return EBUSY in case dirty buffers where not flushed. Then caller
    calls vinvalbuf(0) due to non-zero return, which gets rid of all dirty
    buffers without dependencies.
    
    PR:     238565
    Reviewed by:    asomers, mckusick
    Sponsored by:   The FreeBSD Foundation
    Differential revision:  https://reviews.freebsd.org/D30555
    
    (cherry picked from commit 27006229f7a40a18a61a0e8fd270bc583326b690)
    
    fusefs: reenable the WriteCluster.cluster_write_err test
    
    The underlying panic was just fixed by
    revision 27006229f7a40a18a61a0e8fd270bc583326b690
    
    PR:             238565
    (cherry picked from commit 425bbe9e64f7af6bdb30a099bd90a32885de1ab8)
---
 sys/kern/vfs_subr.c          | 10 ++++------
 tests/sys/fs/fusefs/write.cc |  4 ++--
 2 files changed, 6 insertions(+), 8 deletions(-)

diff --git a/sys/kern/vfs_subr.c b/sys/kern/vfs_subr.c
index 15ea8a1275c9..5f0c467c87e6 100644
--- a/sys/kern/vfs_subr.c
+++ b/sys/kern/vfs_subr.c
@@ -1742,13 +1742,11 @@ bufobj_invalbuf(struct bufobj *bo, int flags, int slpflag, int slptimeo)
 			BO_UNLOCK(bo);
 			if ((error = BO_SYNC(bo, MNT_WAIT)) != 0)
 				return (error);
-			/*
-			 * XXX We could save a lock/unlock if this was only
-			 * enabled under INVARIANTS
-			 */
 			BO_LOCK(bo);
-			if (bo->bo_numoutput > 0 || bo->bo_dirty.bv_cnt > 0)
-				panic("vinvalbuf: dirty bufs");
+			if (bo->bo_numoutput > 0 || bo->bo_dirty.bv_cnt > 0) {
+				BO_UNLOCK(bo);
+				return (EBUSY);
+			}
 		}
 	}
 	/*
diff --git a/tests/sys/fs/fusefs/write.cc b/tests/sys/fs/fusefs/write.cc
index e9bf17c5c4d6..e3fbbf072911 100644
--- a/tests/sys/fs/fusefs/write.cc
+++ b/tests/sys/fs/fusefs/write.cc
@@ -793,10 +793,10 @@ TEST_F(WriteCluster, clustering)
  * not panic the system on unmount
  */
 /*
- * Disabled because it panics.
+ * Regression test for bug 238585
  * https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=238565
  */
-TEST_F(WriteCluster, DISABLED_cluster_write_err)
+TEST_F(WriteCluster, cluster_write_err)
 {
 	const char FULLPATH[] = "mountpoint/some_file.txt";
 	const char RELPATH[] = "some_file.txt";