git: 08bb51f8d60c - main - shutdown: unmount filesystems after swapoff

From: Konstantin Belousov <kib_at_FreeBSD.org>
Date: Mon, 29 Nov 2021 16:39:18 UTC
The branch main has been updated by kib:

URL: https://cgit.FreeBSD.org/src/commit/?id=08bb51f8d60c552d1f7c202cc2eb267ed480e541

commit 08bb51f8d60c552d1f7c202cc2eb267ed480e541
Author:     Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2021-11-28 01:52:46 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2021-11-29 16:38:02 +0000

    shutdown: unmount filesystems after swapoff
    
    Swap on file requires operational underlying mount, otherwise
    swapoff_all() is guaranteed to panic due to the default strategy VOP for
    reclaimed vnodes.
    
    Reported and tested by: peterj
    Reviewed by:    markj
    Sponsored by:   The FreeBSD Foundation
    MFC after:      1 week
    Differential revision:  https://reviews.freebsd.org/D33147
---
 sys/kern/vfs_bio.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/sys/kern/vfs_bio.c b/sys/kern/vfs_bio.c
index 4b746a269171..8d6eac800caf 100644
--- a/sys/kern/vfs_bio.c
+++ b/sys/kern/vfs_bio.c
@@ -1452,16 +1452,21 @@ bufshutdown(int show_busybufs)
 		 */
 		printf("Giving up on %d buffers\n", nbusy);
 		DELAY(5000000);	/* 5 seconds */
+		swapoff_all();
 	} else {
 		if (!first_buf_printf)
 			printf("Final sync complete\n");
+
 		/*
-		 * Unmount filesystems
+		 * Unmount filesystems.  Swapoff before unmount,
+		 * because file-backed swap is non-operational after unmount
+		 * of the underlying filesystem.
 		 */
-		if (!KERNEL_PANICKED())
+		if (!KERNEL_PANICKED()) {
+			swapoff_all();
 			vfs_unmountall();
+		}
 	}
-	swapoff_all();
 	DELAY(100000);		/* wait for console output to finish */
 }