aboutsummaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorKonstantin Belousov <kib@FreeBSD.org>2017-02-09 23:36:50 +0000
committerKonstantin Belousov <kib@FreeBSD.org>2017-02-09 23:36:50 +0000
commite628e1b919cbfce77767eb2e6e91c917250d09bf (patch)
treefac4de17ae2d5063cf10e9e402d40690eafe4121 /sys
parent7903b00087edb0a0dffeabb04e351c5fa67c5a23 (diff)
downloadsrc-e628e1b919cbfce77767eb2e6e91c917250d09bf.tar.gz
src-e628e1b919cbfce77767eb2e6e91c917250d09bf.zip
Increase a chance of devfs_close() calling d_close cdevsw method.
If a file opened over a vnode has an advisory lock set at close, vn_closefile() acquires additional vnode use reference to prevent freeing the vnode in vn_close(). Side effect is that for device vnodes, devfs_close() sees that vnode reference count is greater than one and refuses to call d_close(). Create internal version of vn_close() which can avoid dropping the vnode reference if needed, and use this to execute VOP_CLOSE() without acquiring a new reference. Note that any parallel reference to the vnode would still prevent d_close call, if the reference is not from an opened file, e.g. due to stat(2). Tested by: pho Sponsored by: The FreeBSD Foundation MFC after: 2 weeks
Notes
Notes: svn path=/head/; revision=313496
Diffstat (limited to 'sys')
-rw-r--r--sys/kern/vfs_vnops.c33
1 files changed, 19 insertions, 14 deletions
diff --git a/sys/kern/vfs_vnops.c b/sys/kern/vfs_vnops.c
index dd5e3765e3a8..70cdcdc6f752 100644
--- a/sys/kern/vfs_vnops.c
+++ b/sys/kern/vfs_vnops.c
@@ -430,12 +430,9 @@ vn_writechk(vp)
/*
* Vnode close call
*/
-int
-vn_close(vp, flags, file_cred, td)
- register struct vnode *vp;
- int flags;
- struct ucred *file_cred;
- struct thread *td;
+static int
+vn_close1(struct vnode *vp, int flags, struct ucred *file_cred,
+ struct thread *td, bool keep_ref)
{
struct mount *mp;
int error, lock_flags;
@@ -457,11 +454,22 @@ vn_close(vp, flags, file_cred, td)
__func__, vp, vp->v_writecount);
}
error = VOP_CLOSE(vp, flags, file_cred, td);
- vput(vp);
+ if (keep_ref)
+ VOP_UNLOCK(vp, 0);
+ else
+ vput(vp);
vn_finished_write(mp);
return (error);
}
+int
+vn_close(struct vnode *vp, int flags, struct ucred *file_cred,
+ struct thread *td)
+{
+
+ return (vn_close1(vp, flags, file_cred, td, false));
+}
+
/*
* Heuristic to detect sequential operation.
*/
@@ -1573,18 +1581,15 @@ vn_closefile(struct file *fp, struct thread *td)
struct vnode *vp;
struct flock lf;
int error;
+ bool ref;
vp = fp->f_vnode;
fp->f_ops = &badfileops;
+ ref= (fp->f_flag & FHASLOCK) != 0 && fp->f_type == DTYPE_VNODE;
- if (__predict_false((fp->f_flag & FHASLOCK) != 0) &&
- fp->f_type == DTYPE_VNODE)
- vrefact(vp);
-
- error = vn_close(vp, fp->f_flag, fp->f_cred, td);
+ error = vn_close1(vp, fp->f_flag, fp->f_cred, td, ref);
- if (__predict_false((fp->f_flag & FHASLOCK) != 0) &&
- fp->f_type == DTYPE_VNODE) {
+ if (__predict_false(ref)) {
lf.l_whence = SEEK_SET;
lf.l_start = 0;
lf.l_len = 0;