git: 3d68c4e17578 - main - syncer VOP_FSYNC(): unlock syncer vnode around call to VFS_SYNC()

From: Konstantin Belousov <kib_at_FreeBSD.org>
Date: Mon, 31 Jan 2022 02:46:55 UTC
The branch main has been updated by kib:

URL: https://cgit.FreeBSD.org/src/commit/?id=3d68c4e17578684cfdfd002fb6ab8554df525963

commit 3d68c4e17578684cfdfd002fb6ab8554df525963
Author:     Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2022-01-21 15:42:28 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2022-01-31 02:46:21 +0000

    syncer VOP_FSYNC(): unlock syncer vnode around call to VFS_SYNC()
    
    The lock is unneccessary since the mount point is busied, which prevents
    unmount and syncer vnode deallocation.  Having the vnode locked causes
    innocent LoRs and complicates debugging.
    
    Also stop starting write accounting around it.  Any caller of
    VOP_FSYNC() must do it already, and sync_vnode() does.
    
    Reported and tested by: pho
    Reviewed by:    markj, mckusick
    Sponsored by:   The FreeBSD Foundation
    MFC after:      1 week
    Differential revision:  https://reviews.freebsd.org/D34072
---
 sys/kern/vfs_subr.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/sys/kern/vfs_subr.c b/sys/kern/vfs_subr.c
index 3218a3f7b6a0..839282fe318f 100644
--- a/sys/kern/vfs_subr.c
+++ b/sys/kern/vfs_subr.c
@@ -5059,10 +5059,7 @@ sync_fsync(struct vop_fsync_args *ap)
 	 */
 	if (vfs_busy(mp, MBF_NOWAIT) != 0)
 		return (0);
-	if (vn_start_write(NULL, &mp, V_NOWAIT) != 0) {
-		vfs_unbusy(mp);
-		return (0);
-	}
+	VOP_UNLOCK(syncvp);
 	save = curthread_pflags_set(TDP_SYNCIO);
 	/*
 	 * The filesystem at hand may be idle with free vnodes stored in the
@@ -5071,7 +5068,7 @@ sync_fsync(struct vop_fsync_args *ap)
 	vfs_periodic(mp, MNT_NOWAIT);
 	error = VFS_SYNC(mp, MNT_LAZY);
 	curthread_pflags_restore(save);
-	vn_finished_write(mp);
+	vn_lock(syncvp, LK_EXCLUSIVE | LK_RETRY);
 	vfs_unbusy(mp);
 	return (error);
 }