{
struct vnode *vp;
int code;
+ int evicted = 0;
vp = AFSTOV(avc);
if (!VI_TRYLOCK(vp))
- return 0;
+ return evicted;
code = osi_fbsd_checkinuse(avc);
if (code != 0) {
VI_UNLOCK(vp);
- return 0;
+ return evicted;
}
if ((vp->v_iflag & VI_DOOMED) != 0) {
VI_UNLOCK(vp);
- return 1;
+ evicted = 1;
+ return evicted;
}
- /* must hold the vnode before calling vgone()
- * This code largely copied from vfs_subr.c:vlrureclaim() */
vholdl(vp);
ReleaseWriteLock(&afs_xvcache);
AFS_GUNLOCK();
*slept = 1;
- /* use the interlock while locking, so no one else can DOOM this */
- vn_lock(vp, LK_INTERLOCK|LK_EXCLUSIVE|LK_RETRY);
- vgone(vp);
- VOP_UNLOCK(vp, 0);
+
+ if (vn_lock(vp, LK_INTERLOCK|LK_EXCLUSIVE|LK_NOWAIT) == 0) {
+ /*
+ * vrecycle() will vgone() only if its usecount is 0. If someone grabbed a
+ * new usecount ref just now, the vgone() will be skipped, and vrecycle
+ * will return 0.
+ */
+ if (vrecycle(vp) != 0) {
+ evicted = 1;
+ }
+
+ VOP_UNLOCK(vp, 0);
+ }
+
vdrop(vp);
AFS_GLOCK();
ObtainWriteLock(&afs_xvcache, 340);
- return 1;
+
+ return evicted;
}
struct vcache *
int
osi_vnhold(struct vcache *avc)
{
- vref(AFSTOV(avc));
+ struct vnode *vp = AFSTOV(avc);
+
+ VI_LOCK(vp);
+ if ((vp->v_iflag & VI_DOOMED) != 0) {
+ VI_UNLOCK(vp);
+ return ENOENT;
+ }
+
+ vrefl(AFSTOV(avc));
+ VI_UNLOCK(vp);
return 0;
}
static int
afs_vop_reclaim(struct vop_reclaim_args *ap)
{
- /* copied from ../OBSD/osi_vnodeops.c:afs_nbsd_reclaim() */
int code, slept;
struct vnode *vp = ap->a_vp;
struct vcache *avc = VTOAFS(vp);
int haveGlock = ISAFS_GLOCK();
- int haveVlock = CheckLock(&afs_xvcache);
+
+ /*
+ * In other code paths, we acquire the vnode lock while afs_xvcache is
+ * already held (e.g. afs_PutVCache() -> vrele()). Here, we already have
+ * the vnode lock, and we need afs_xvcache. So drop the vnode lock in order
+ * to hold afs_xvcache.
+ */
+ VOP_UNLOCK(vp, 0);
if (!haveGlock)
AFS_GLOCK();
- if (!haveVlock)
- ObtainWriteLock(&afs_xvcache, 901);
- /* reclaim the vnode and the in-memory vcache, but keep the on-disk vcache */
+ ObtainWriteLock(&afs_xvcache, 901);
+
+ /*
+ * Note that we deliberately call VOP_LOCK() instead of vn_lock() here.
+ * vn_lock() will return an error for VI_DOOMED vnodes, but we know this
+ * vnode is already VI_DOOMED. We just want to lock it again, and skip the
+ * VI_DOOMED check.
+ */
+ VOP_LOCK(vp, LK_EXCLUSIVE);
+
code = afs_FlushVCache(avc, &slept);
if (avc->f.states & CVInit) {
afs_osi_Wakeup(&avc->f.states);
}
- if (!haveVlock)
- ReleaseWriteLock(&afs_xvcache);
+ ReleaseWriteLock(&afs_xvcache);
if (!haveGlock)
AFS_GUNLOCK();
if (code) {
afs_warn("afs_vop_reclaim: afs_FlushVCache failed code %d vnode\n", code);
VOP_PRINT(vp);
+ panic("afs: afs_FlushVCache failed during reclaim");
}
- /* basically, it must not fail */
vnode_destroy_vobject(vp);
vp->v_data = 0;