git: 098500b79e17 - stable/14 - kcmp(2): implement for vnode files

From: Konstantin Belousov <kib_at_FreeBSD.org>
Date: Wed, 31 Jan 2024 00:46:11 UTC
The branch stable/14 has been updated by kib:

URL: https://cgit.FreeBSD.org/src/commit/?id=098500b79e1734f269743eabb624c854804c67ac

commit 098500b79e1734f269743eabb624c854804c67ac
Author:     Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2024-01-19 21:24:31 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2024-01-30 20:24:42 +0000

    kcmp(2): implement for vnode files
    
    (cherry picked from commit f04220c1b0641fa68d01dc85d9fef706b02f4079)
---
 sys/kern/kern_descrip.c | 1 +
 sys/kern/vfs_vnops.c    | 9 +++++++++
 sys/sys/vnode.h         | 1 +
 3 files changed, 11 insertions(+)

diff --git a/sys/kern/kern_descrip.c b/sys/kern/kern_descrip.c
index 7bb392eee6b2..30d82f74d725 100644
--- a/sys/kern/kern_descrip.c
+++ b/sys/kern/kern_descrip.c
@@ -5287,6 +5287,7 @@ struct fileops path_fileops = {
 	.fo_chown = badfo_chown,
 	.fo_sendfile = badfo_sendfile,
 	.fo_fill_kinfo = vn_fill_kinfo,
+	.fo_cmp = vn_cmp,
 	.fo_flags = DFLAG_PASSABLE,
 };
 
diff --git a/sys/kern/vfs_vnops.c b/sys/kern/vfs_vnops.c
index 50f202d6ea1a..b650b32ccc55 100644
--- a/sys/kern/vfs_vnops.c
+++ b/sys/kern/vfs_vnops.c
@@ -125,6 +125,7 @@ struct 	fileops vnops = {
 	.fo_mmap = vn_mmap,
 	.fo_fallocate = vn_fallocate,
 	.fo_fspacectl = vn_fspacectl,
+	.fo_cmp = vn_cmp,
 	.fo_flags = DFLAG_PASSABLE | DFLAG_SEEKABLE
 };
 
@@ -4230,3 +4231,11 @@ vn_lktype_write(struct mount *mp, struct vnode *vp)
 		return (LK_SHARED);
 	return (LK_EXCLUSIVE);
 }
+
+int
+vn_cmp(struct file *fp1, struct file *fp2, struct thread *td)
+{
+	if (fp2->f_type != DTYPE_VNODE)
+		return (3);
+	return (kcmp_cmp((uintptr_t)fp1->f_vnode, (uintptr_t)fp2->f_vnode));
+}
diff --git a/sys/sys/vnode.h b/sys/sys/vnode.h
index 07b1a419b916..2667b77d7c52 100644
--- a/sys/sys/vnode.h
+++ b/sys/sys/vnode.h
@@ -820,6 +820,7 @@ int	vn_vget_ino_gen(struct vnode *vp, vn_get_ino_t alloc,
 	    void *alloc_arg, int lkflags, struct vnode **rvp);
 int	vn_utimes_perm(struct vnode *vp, struct vattr *vap,
 	    struct ucred *cred, struct thread *td);
+int	vn_cmp(struct file *, struct file *, struct thread *td);
 
 int	vn_io_fault_uiomove(char *data, int xfersize, struct uio *uio);
 int	vn_io_fault_pgmove(vm_page_t ma[], vm_offset_t offset, int xfersize,