git: 5adc7b1c9141 - stable/15 - vfs_busy(): add MBF_PCATCH flag to allow interrupting the sleep

Konstantin Belousov <[email protected]>
Newsgroups gmane.os.freebsd.devel.cvs.src
Message-ID <6a72d697.2650d.28bab8cf__22981.1517566972$1785910973$gmane$org@gitrepo.freebsd.org>
The branch stable/15 has been updated by kib:

URL: https://cgit.FreeBSD.org/src/commit/?id=5adc7b1c9141cd002d5b3864c707530a5cce52f1

commit 5adc7b1c9141cd002d5b3864c707530a5cce52f1
Author:     Konstantin Belousov <[email protected]>
AuthorDate: 2026-07-27 13:40:23 +0000
Commit:     Konstantin Belousov <[email protected]>
CommitDate: 2026-08-05 06:12:48 +0000

    vfs_busy(): add MBF_PCATCH flag to allow interrupting the sleep
    
    (cherry picked from commit fb4d7bd4b7676963f9f37ff47f315f8c3652538b)
---
 sys/kern/vfs_subr.c | 17 ++++++++++++++++-
 sys/sys/mount.h     |  3 ++-
 2 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/sys/kern/vfs_subr.c b/sys/kern/vfs_subr.c
index 00795bdd08e7..0e3376929cdb 100644
--- a/sys/kern/vfs_subr.c
+++ b/sys/kern/vfs_subr.c
@@ -875,6 +875,7 @@ int
 vfs_busy(struct mount *mp, int flags)
 {
 	struct mount_pcpu *mpcpu;
+	int error;
 
 	MPASS((flags & ~MBF_MASK) == 0);
 	CTR3(KTR_VFS, "%s: mp %p with flags %d", __func__, mp, flags);
@@ -919,10 +920,24 @@ vfs_busy(struct mount *mp, int flags)
 		if (flags & MBF_MNTLSTLOCK)
 			mtx_unlock(&mountlist_mtx);
 		mp->mnt_kern_flag |= MNTK_MWAIT;
-		msleep(mp, MNT_MTX(mp), PVFS | PDROP, "vfs_busy", 0);
+		error = msleep(mp, MNT_MTX(mp), ((flags & MBF_PCATCH) != 0 ?
+		    PCATCH : 0) | PVFS | PDROP, "vfs_busy", 0);
 		if (flags & MBF_MNTLSTLOCK)
 			mtx_lock(&mountlist_mtx);
 		MNT_ILOCK(mp);
+		if (error != 0) {
+			MNT_REL(mp);
+
+			/*
+			 * Clearing MNTK_MWAIT might cause spurious
+			 * wakeups, but better clear our flag there
+			 * then leak it.
+			 */
+			mp->mnt_kern_flag &= ~MNTK_MWAIT;
+			wakeup(mp);
+			MNT_IUNLOCK(mp);
+			return (error);
+		}
 	}
 	if (flags & MBF_MNTLSTLOCK)
 		mtx_unlock(&mountlist_mtx);
diff --git a/sys/sys/mount.h b/sys/sys/mount.h
index a1e5e4efd460..8636443226e7 100644
--- a/sys/sys/mount.h
+++ b/sys/sys/mount.h
@@ -768,7 +768,8 @@ struct uio;
  */
 #define	MBF_NOWAIT	0x01
 #define	MBF_MNTLSTLOCK	0x02
-#define	MBF_MASK	(MBF_NOWAIT | MBF_MNTLSTLOCK)
+#define	MBF_PCATCH	0x04
+#define	MBF_MASK	(MBF_NOWAIT | MBF_MNTLSTLOCK | MBF_PCATCH)
 
 #ifdef MALLOC_DECLARE
 MALLOC_DECLARE(M_MOUNT);
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.