vfs: refactor _vn_lock

Stop testing for LK_RETRY and error multiple times. Also postpone the
VI_DOOMED until after LK_RETRY was seen as it reads from the vnode.

No functional changes.
This commit is contained in:
Mateusz Guzik 2017-01-21 18:38:16 +00:00
parent 21dff1801f
commit 1091fb52c1
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=312600

View File

@ -1539,27 +1539,24 @@ _vn_lock(struct vnode *vp, int flags, char *file, int line)
VNASSERT((flags & LK_TYPE_MASK) != 0, vp,
("vn_lock called with no locktype."));
do {
#ifdef DEBUG_VFS_LOCKS
KASSERT(vp->v_holdcnt != 0,
("vn_lock %p: zero hold count", vp));
KASSERT(vp->v_holdcnt != 0,
("vn_lock %p: zero hold count", vp));
#endif
error = VOP_LOCK1(vp, flags, file, line);
flags &= ~LK_INTERLOCK; /* Interlock is always dropped. */
KASSERT((flags & LK_RETRY) == 0 || error == 0,
("LK_RETRY set with incompatible flags (0x%x) or an error occurred (%d)",
flags, error));
/*
* Callers specify LK_RETRY if they wish to get dead vnodes.
* If RETRY is not set, we return ENOENT instead.
*/
if (error == 0 && vp->v_iflag & VI_DOOMED &&
(flags & LK_RETRY) == 0) {
retry:
error = VOP_LOCK1(vp, flags, file, line);
flags &= ~LK_INTERLOCK; /* Interlock is always dropped. */
KASSERT((flags & LK_RETRY) == 0 || error == 0,
("LK_RETRY set with incompatible flags (0x%x) or an error occurred (%d)",
flags, error));
if (flags & LK_RETRY) {
if ((error != 0))
goto retry;
if ((vp->v_iflag & VI_DOOMED)) {
VOP_UNLOCK(vp, 0);
error = ENOENT;
break;
}
} while (flags & LK_RETRY && error != 0);
}
return (error);
}