git: 81174cd8e24a - main - vfs: employ vfs_ref_from_vp in statfs and fstatfs

Mateusz Guzik mjg at FreeBSD.org
Sun Feb 21 00:43:17 UTC 2021


The branch main has been updated by mjg:

URL: https://cgit.FreeBSD.org/src/commit/?id=81174cd8e24aa2bb27f6a8b41032abf59add479f

commit 81174cd8e24aa2bb27f6a8b41032abf59add479f
Author:     Mateusz Guzik <mjg at FreeBSD.org>
AuthorDate: 2021-02-15 22:08:20 +0000
Commit:     Mateusz Guzik <mjg at FreeBSD.org>
CommitDate: 2021-02-21 00:43:05 +0000

    vfs: employ vfs_ref_from_vp in statfs and fstatfs
    
    Avoids locking and unlocking the vnode.
    
    Reviewed by:    kib
    Differential Revision:  https://reviews.freebsd.org/D28695
---
 sys/kern/vfs_syscalls.c | 20 +++++++++-----------
 1 file changed, 9 insertions(+), 11 deletions(-)

diff --git a/sys/kern/vfs_syscalls.c b/sys/kern/vfs_syscalls.c
index a51d693446e3..11fcc7a3e10d 100644
--- a/sys/kern/vfs_syscalls.c
+++ b/sys/kern/vfs_syscalls.c
@@ -333,15 +333,13 @@ kern_statfs(struct thread *td, const char *path, enum uio_seg pathseg,
 	struct nameidata nd;
 	int error;
 
-	NDINIT(&nd, LOOKUP, FOLLOW | LOCKSHARED | LOCKLEAF | AUDITVNODE1,
-	    pathseg, path, td);
+	NDINIT(&nd, LOOKUP, FOLLOW | AUDITVNODE1, pathseg, path, td);
 	error = namei(&nd);
 	if (error != 0)
 		return (error);
-	mp = nd.ni_vp->v_mount;
-	vfs_ref(mp);
+	mp = vfs_ref_from_vp(nd.ni_vp);
 	NDFREE_NOTHING(&nd);
-	vput(nd.ni_vp);
+	vrele(nd.ni_vp);
 	return (kern_do_statfs(td, mp, buf));
 }
 
@@ -381,14 +379,14 @@ kern_fstatfs(struct thread *td, int fd, struct statfs *buf)
 	if (error != 0)
 		return (error);
 	vp = fp->f_vnode;
-	vn_lock(vp, LK_SHARED | LK_RETRY);
 #ifdef AUDIT
-	AUDIT_ARG_VNODE1(vp);
+	if (AUDITING_TD(td)) {
+		vn_lock(vp, LK_SHARED | LK_RETRY);
+		AUDIT_ARG_VNODE1(vp);
+		VOP_UNLOCK(vp);
+	}
 #endif
-	mp = vp->v_mount;
-	if (mp != NULL)
-		vfs_ref(mp);
-	VOP_UNLOCK(vp);
+	mp = vfs_ref_from_vp(vp);
 	fdrop(fp, td);
 	return (kern_do_statfs(td, mp, buf));
 }


More information about the dev-commits-src-all mailing list