git: 347a8e93fe68 - main - g_vfs_done: Only report ENXIO once

From: Warner Losh <imp_at_FreeBSD.org>
Date: Sun, 24 Apr 2022 20:02:28 UTC
The branch main has been updated by imp:

URL: https://cgit.FreeBSD.org/src/commit/?id=347a8e93fe687d55f65a4b58a394a5632deca7ba

commit 347a8e93fe687d55f65a4b58a394a5632deca7ba
Author:     Warner Losh <imp@FreeBSD.org>
AuthorDate: 2022-04-24 19:54:29 +0000
Commit:     Warner Losh <imp@FreeBSD.org>
CommitDate: 2022-04-24 20:01:33 +0000

    g_vfs_done: Only report ENXIO once
    
    The contract with the lower layers is that once ENXIO is reported, all
    further I/O to the device is not possible. This is reported when the
    device departs for good or changes in some material manner out from
    underneath the system. Since the lower layers terminate all pending I/O
    when this is detected with ENXIO, reporting more than one provides no
    extra value. ENXIO suppression done with atomics due to race described
    in e8827f4094cb. It's on the error path and a rare event, so this won't affect
    performance.
    
    Sponsored by:           Netflix
    Reviewed by:            mckusick, kib
    Differential Revision:  https://reviews.freebsd.org/D35034
---
 sys/geom/geom_vfs.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/sys/geom/geom_vfs.c b/sys/geom/geom_vfs.c
index b6f5916c386a..04d5fe883a8f 100644
--- a/sys/geom/geom_vfs.c
+++ b/sys/geom/geom_vfs.c
@@ -57,6 +57,7 @@ struct g_vfs_softc {
 	int		 sc_active;
 	bool		 sc_orphaned;
 	int		 sc_enxio_active;
+	int		 sc_enxio_reported;
 };
 
 static struct buf_ops __g_vfs_bufops = {
@@ -150,8 +151,13 @@ g_vfs_done(struct bio *bip)
 		}
 		if (sc->sc_enxio_active)
 			bip->bio_error = ENXIO;
-		g_print_bio("g_vfs_done():", bip, "error = %d",
-		    bip->bio_error);
+		if (bip->bio_error != ENXIO ||
+		    atomic_cmpset_int(&sc->sc_enxio_reported, 0, 1)) {
+			g_print_bio("g_vfs_done():", bip, "error = %d%s",
+			    bip->bio_error,
+			    bip->bio_error != ENXIO ? "" :
+			    " supressing further ENXIO");
+		}
 	}
 	bp->b_error = bip->bio_error;
 	bp->b_ioflags = bip->bio_flags;