Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 26 Apr 2023 00:01:00 GMT
From:      Konstantin Belousov <kib@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   git: 37e6036b26cd - main - VOP_CLOSE(): MNTK_EXTENDED_SHARED filesystems do not need excl lock
Message-ID:  <202304260001.33Q010Hl084245@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch main has been updated by kib:

URL: https://cgit.FreeBSD.org/src/commit/?id=37e6036b26cdd2942344b6c69f9a10764c6209ba

commit 37e6036b26cdd2942344b6c69f9a10764c6209ba
Author:     Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2023-04-24 22:43:32 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2023-04-25 22:39:25 +0000

    VOP_CLOSE(): MNTK_EXTENDED_SHARED filesystems do not need excl lock
    
    All in-tree implementations of VOP_CLOSE() for filesystems proclaiming
    MNTK_EXTENDED_SHARED, are fine with the shared lock for the closed
    vnode.  I checked the following implementations:
            ffs
            ext2
            ufs
            null
            tmpfs
            devfs
            fdescfs
            cd9660
            zfs
    It seems that initial addition of FWRITE check was due to necessity of
    handling the VV_TEXT vnode vflag.  Since VOP_ADD_WRITECOUNT() only
    requires shared lock, we can relax the locking requirement there.
    
    Reviewed by:    markj, Olivier Certner <olce.freebsd@certner.fr>
    Tested by:      Olivier Certner
    Sponsored by:   The FreeBSD Foundation
    Differential revision:  https://reviews.freebsd.org/D39784
---
 sys/kern/vfs_vnops.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/sys/kern/vfs_vnops.c b/sys/kern/vfs_vnops.c
index e42d17ec2478..581d620e348e 100644
--- a/sys/kern/vfs_vnops.c
+++ b/sys/kern/vfs_vnops.c
@@ -483,7 +483,7 @@ vn_open_vnode(struct vnode *vp, int fmode, struct ucred *cred,
 			 * If there is no fp, due to kernel-mode open,
 			 * we can call VOP_CLOSE() now.
 			 */
-			if ((vp->v_type == VFIFO || (fmode & FWRITE) != 0 ||
+			if ((vp->v_type == VFIFO ||
 			    !MNT_EXTENDED_SHARED(vp->v_mount)) &&
 			    VOP_ISLOCKED(vp) != LK_EXCLUSIVE)
 				vn_lock(vp, LK_UPGRADE | LK_RETRY);
@@ -528,11 +528,8 @@ vn_close1(struct vnode *vp, int flags, struct ucred *file_cred,
 	struct mount *mp;
 	int error, lock_flags;
 
-	if (vp->v_type != VFIFO && (flags & FWRITE) == 0 &&
-	    MNT_EXTENDED_SHARED(vp->v_mount))
-		lock_flags = LK_SHARED;
-	else
-		lock_flags = LK_EXCLUSIVE;
+	lock_flags = vp->v_type != VFIFO && MNT_EXTENDED_SHARED(vp->v_mount) ?
+	    LK_SHARED : LK_EXCLUSIVE;
 
 	vn_start_write(vp, &mp, V_WAIT);
 	vn_lock(vp, lock_flags | LK_RETRY);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202304260001.33Q010Hl084245>