Author: kib
Date: Tue Sep 15 21:55:21 2020
New Revision: 365783
URL: https://svnweb.freebsd.org/changeset/base/365783

Log:
  Do not copy vp into f_data for DTYPE_VNODE files.
  
  The pointer to vnode is already stored into f_vnode, so f_data can be
  reused.  Fix all found users of f_data for DTYPE_VNODE.
  
  Provide finit_vnode() helper to initialize file of DTYPE_VNODE type.
  
  Reviewed by:  markj (previous version)
  Discussed with:       freqlabs (openzfs chunk)
  Tested by:    pho (previous version)
  Sponsored by: The FreeBSD Foundation
  Differential revision:        https://reviews.freebsd.org/D26346

Modified:
  head/sys/contrib/openzfs/module/os/freebsd/zfs/zfs_file_os.c
  head/sys/fs/nfs/nfsdport.h
  head/sys/kern/kern_descrip.c
  head/sys/kern/vfs_syscalls.c
  head/sys/sys/file.h
  head/sys/ufs/ffs/ffs_alloc.c

Modified: head/sys/contrib/openzfs/module/os/freebsd/zfs/zfs_file_os.c
==============================================================================
--- head/sys/contrib/openzfs/module/os/freebsd/zfs/zfs_file_os.c        Tue Sep 
15 21:48:24 2020        (r365782)
+++ head/sys/contrib/openzfs/module/os/freebsd/zfs/zfs_file_os.c        Tue Sep 
15 21:55:21 2020        (r365783)
@@ -239,7 +239,7 @@ zfs_file_fsync(zfs_file_t *fp, int flags)
        if (fp->f_type != DTYPE_VNODE)
                return (EINVAL);
 
-       v = fp->f_data;
+       v = fp->f_vnode;
        return (zfs_vop_fsync(v));
 }
 

Modified: head/sys/fs/nfs/nfsdport.h
==============================================================================
--- head/sys/fs/nfs/nfsdport.h  Tue Sep 15 21:48:24 2020        (r365782)
+++ head/sys/fs/nfs/nfsdport.h  Tue Sep 15 21:55:21 2020        (r365783)
@@ -94,7 +94,7 @@ struct nfsexstuff {
 #define        NFSLOCKHASH(f)                                                  
\
        (&nfslockhash[nfsrv_hashfh(f) % nfsrv_lockhashsize])
 
-#define        NFSFPVNODE(f)   ((struct vnode *)((f)->f_data))
+#define        NFSFPVNODE(f)   ((f)->f_vnode)
 #define        NFSFPCRED(f)    ((f)->f_cred)
 #define        NFSFPFLAG(f)    ((f)->f_flag)
 

Modified: head/sys/kern/kern_descrip.c
==============================================================================
--- head/sys/kern/kern_descrip.c        Tue Sep 15 21:48:24 2020        
(r365782)
+++ head/sys/kern/kern_descrip.c        Tue Sep 15 21:55:21 2020        
(r365783)
@@ -2622,6 +2622,15 @@ finit(struct file *fp, u_int flag, short type, void *d
        atomic_store_rel_ptr((volatile uintptr_t *)&fp->f_ops, (uintptr_t)ops);
 }
 
+void
+finit_vnode(struct file *fp, u_int flag, void *data, struct fileops *ops)
+{
+       fp->f_seqcount[UIO_READ] = 1;
+       fp->f_seqcount[UIO_WRITE] = 1;
+       finit(fp, (flag & FMASK) | (fp->f_flag & FHASLOCK), DTYPE_VNODE,
+           data, ops);
+}
+
 int
 fget_cap_locked(struct filedesc *fdp, int fd, cap_rights_t *needrightsp,
     struct file **fpp, struct filecaps *havecapsp)

Modified: head/sys/kern/vfs_syscalls.c
==============================================================================
--- head/sys/kern/vfs_syscalls.c        Tue Sep 15 21:48:24 2020        
(r365782)
+++ head/sys/kern/vfs_syscalls.c        Tue Sep 15 21:55:21 2020        
(r365783)
@@ -1163,10 +1163,7 @@ kern_openat(struct thread *td, int fd, const char *pat
         */
        if (fp->f_ops == &badfileops) {
                KASSERT(vp->v_type != VFIFO, ("Unexpected fifo."));
-               fp->f_seqcount[UIO_READ] = 1;
-               fp->f_seqcount[UIO_WRITE] = 1;
-               finit(fp, (flags & FMASK) | (fp->f_flag & FHASLOCK),
-                   DTYPE_VNODE, vp, &vnops);
+               finit_vnode(fp, flags, NULL, &vnops);
        }
 
        VOP_UNLOCK(vp);
@@ -4138,7 +4135,6 @@ unionread:
                vp = vp->v_mount->mnt_vnodecovered;
                VREF(vp);
                fp->f_vnode = vp;
-               fp->f_data = vp;
                foffset = 0;
                vput(tvp);
                goto unionread;
@@ -4502,10 +4498,7 @@ sys_fhopen(struct thread *td, struct fhopen_args *uap)
        td->td_dupfd = 0;
 #endif
        fp->f_vnode = vp;
-       fp->f_seqcount[UIO_READ] = 1;
-       fp->f_seqcount[UIO_WRITE] = 1;
-       finit(fp, (fmode & FMASK) | (fp->f_flag & FHASLOCK), DTYPE_VNODE, vp,
-           &vnops);
+       finit_vnode(fp, fmode, NULL, &vnops);
        VOP_UNLOCK(vp);
        if ((fmode & O_TRUNC) != 0) {
                error = fo_truncate(fp, 0, td->td_ucred, td);

Modified: head/sys/sys/file.h
==============================================================================
--- head/sys/sys/file.h Tue Sep 15 21:48:24 2020        (r365782)
+++ head/sys/sys/file.h Tue Sep 15 21:55:21 2020        (r365783)
@@ -268,6 +268,7 @@ fo_fill_kinfo_t     vn_fill_kinfo;
 int vn_fill_kinfo_vnode(struct vnode *vp, struct kinfo_file *kif);
 
 void finit(struct file *, u_int, short, void *, struct fileops *);
+void finit_vnode(struct file *, u_int, void *, struct fileops *);
 int fgetvp(struct thread *td, int fd, cap_rights_t *rightsp,
     struct vnode **vpp);
 int fgetvp_exec(struct thread *td, int fd, cap_rights_t *rightsp,

Modified: head/sys/ufs/ffs/ffs_alloc.c
==============================================================================
--- head/sys/ufs/ffs/ffs_alloc.c        Tue Sep 15 21:48:24 2020        
(r365782)
+++ head/sys/ufs/ffs/ffs_alloc.c        Tue Sep 15 21:55:21 2020        
(r365783)
@@ -3220,7 +3220,7 @@ sysctl_ffs_fsck(SYSCTL_HANDLER_ARGS)
        if ((error = getvnode(td, cmd.handle,
            cap_rights_init(&rights, CAP_FSCK), &fp)) != 0)
                return (error);
-       vp = fp->f_data;
+       vp = fp->f_vnode;
        if (vp->v_type != VREG && vp->v_type != VDIR) {
                fdrop(fp, td);
                return (EINVAL);
_______________________________________________
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to