1
0
mirror of https://git.FreeBSD.org/src.git synced 2024-11-25 07:49:18 +00:00

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
This commit is contained in:
Konstantin Belousov 2020-09-15 21:55:21 +00:00
parent a3b9a7366e
commit 96474d2a3f
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=365783
6 changed files with 15 additions and 12 deletions

View File

@ -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));
}

View File

@ -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)

View File

@ -2622,6 +2622,15 @@ finit(struct file *fp, u_int flag, short type, void *data, struct fileops *ops)
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)

View File

@ -1163,10 +1163,7 @@ kern_openat(struct thread *td, int fd, const char *path, enum uio_seg pathseg,
*/
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 @@ kern_getdirentries(struct thread *td, int fd, char *buf, size_t count,
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);

View File

@ -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,

View File

@ -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);