aboutsummaryrefslogtreecommitdiff
path: root/sys/kern/vfs_subr.c
diff options
context:
space:
mode:
authorKonstantin Belousov <kib@FreeBSD.org>2021-01-30 19:17:29 +0000
committerKonstantin Belousov <kib@FreeBSD.org>2021-02-12 01:02:21 +0000
commitb59a8e63d6bf9092419b7a421c655d0ae2099662 (patch)
treebc59d2f1a5f960afee30030b8f2a48dfece3873c /sys/kern/vfs_subr.c
parent6aed2435c8bf1fa55891c7d30186c9ad91064da8 (diff)
downloadsrc-b59a8e63d6bf9092419b7a421c655d0ae2099662.tar.gz
src-b59a8e63d6bf9092419b7a421c655d0ae2099662.zip
Stop ignoring ERELOOKUP from VOP_INACTIVE()
When possible, relock the vnode and retry inactivation. Only vunref() is required not to drop the vnode lock, so handle it specially by not retrying. This is a part of the efforts to ensure that unlinked not referenced vnode does not prevent inode from reusing. Reviewed by: chs, mckusick Tested by: pho MFC after: 2 weeks Sponsored by: The FreeBSD Foundation
Diffstat (limited to 'sys/kern/vfs_subr.c')
-rw-r--r--sys/kern/vfs_subr.c47
1 files changed, 33 insertions, 14 deletions
diff --git a/sys/kern/vfs_subr.c b/sys/kern/vfs_subr.c
index 047e4c54f0c5..04cd0e0175f9 100644
--- a/sys/kern/vfs_subr.c
+++ b/sys/kern/vfs_subr.c
@@ -3159,9 +3159,21 @@ vput_final(struct vnode *vp, enum vput_op func)
break;
}
if (error == 0) {
- vinactive(vp);
- if (want_unlock)
- VOP_UNLOCK(vp);
+ if (func == VUNREF) {
+ VNASSERT((vp->v_vflag & VV_UNREF) == 0, vp,
+ ("recursive vunref"));
+ vp->v_vflag |= VV_UNREF;
+ }
+ for (;;) {
+ error = vinactive(vp);
+ if (want_unlock)
+ VOP_UNLOCK(vp);
+ if (error != ERELOOKUP || !want_unlock)
+ break;
+ VOP_LOCK(vp, LK_EXCLUSIVE);
+ }
+ if (func == VUNREF)
+ vp->v_vflag &= ~VV_UNREF;
vdropl(vp);
} else {
vdefer_inactive(vp);
@@ -3546,10 +3558,11 @@ vdropl(struct vnode *vp)
* Call VOP_INACTIVE on the vnode and manage the DOINGINACT and OWEINACT
* flags. DOINGINACT prevents us from recursing in calls to vinactive.
*/
-static void
+static int
vinactivef(struct vnode *vp)
{
struct vm_object *obj;
+ int error;
ASSERT_VOP_ELOCKED(vp, "vinactive");
ASSERT_VI_LOCKED(vp, "vinactive");
@@ -3575,14 +3588,15 @@ vinactivef(struct vnode *vp)
vm_object_page_clean(obj, 0, 0, 0);
VM_OBJECT_WUNLOCK(obj);
}
- VOP_INACTIVE(vp);
+ error = VOP_INACTIVE(vp);
VI_LOCK(vp);
VNASSERT(vp->v_iflag & VI_DOINGINACT, vp,
("vinactive: lost VI_DOINGINACT"));
vp->v_iflag &= ~VI_DOINGINACT;
+ return (error);
}
-void
+int
vinactive(struct vnode *vp)
{
@@ -3591,14 +3605,14 @@ vinactive(struct vnode *vp)
CTR2(KTR_VFS, "%s: vp %p", __func__, vp);
if ((vp->v_iflag & VI_OWEINACT) == 0)
- return;
+ return (0);
if (vp->v_iflag & VI_DOINGINACT)
- return;
+ return (0);
if (vp->v_usecount > 0) {
vp->v_iflag &= ~VI_OWEINACT;
- return;
+ return (0);
}
- vinactivef(vp);
+ return (vinactivef(vp));
}
/*
@@ -3911,10 +3925,15 @@ vgonel(struct vnode *vp)
*/
if (active)
VOP_CLOSE(vp, FNONBLOCK, NOCRED, td);
- if ((oweinact || active) && !doinginact) {
- VI_LOCK(vp);
- vinactivef(vp);
- VI_UNLOCK(vp);
+ if (!doinginact) {
+ do {
+ if (oweinact || active) {
+ VI_LOCK(vp);
+ vinactivef(vp);
+ oweinact = (vp->v_iflag & VI_OWEINACT) != 0;
+ VI_UNLOCK(vp);
+ }
+ } while (oweinact);
}
if (vp->v_type == VSOCK)
vfs_unp_reclaim(vp);