From 3260065941c65434c9124fb51559b0519e77fa9b Mon Sep 17 00:00:00 2001 From: Andrew Deason Date: Fri, 25 Feb 2011 16:58:30 -0600 Subject: [PATCH] vol: Check for blank vnode in VAllocVnode_r When we alloc a vnode in VAllocVnode_r, we look up that vnode in the vnode cache, to see if a vnode struct already exists for it. If it doesn't, we check the vnode index to ensure that the vnode actually is not in use (among other things). However, we do not perform the same check for a vnode already in the cache. Add this check, to make sure that we don't allocate an already-used vnode number, even if the bitmap is screwed up. Reviewed-on: http://gerrit.openafs.org/4060 Tested-by: BuildBot Reviewed-by: Michael Meffie Reviewed-by: Derrick Brashear (cherry picked from commit 974e95302a312c03cd735c0fdaa67fb02d254e26) Change-Id: Ie75dc32c2a2c1ff05a96a1a14650e41ada07609d Reviewed-on: http://gerrit.openafs.org/4170 Tested-by: BuildBot Reviewed-by: Derrick Brashear --- src/vol/vnode.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/vol/vnode.c b/src/vol/vnode.c index 3687a1b2c..1ab6702ef 100644 --- a/src/vol/vnode.c +++ b/src/vol/vnode.c @@ -700,6 +700,28 @@ VAllocVnode_r(Error * ec, Volume * vp, VnodeType type) } } + /* sanity check: vnode should be blank if it was deleted. If it's + * not blank, it is still in use somewhere; but the bitmap told us + * this vnode number was free, so something is wrong. */ + if (vnp->disk.type != vNull) { + Error tmp; + Log("VAllocVnode: addled bitmap or vnode object! (vol %ld, " + "vnode %p, number %ld, type %ld)\n", (long)vp->hashid, vnp, + (long)Vn_id(vnp), (long)vnp->disk.type); + *ec = EIO; + VFreeBitMapEntry_r(&tmp, vp, &vp->vnodeIndex[class], bitNumber, + VOL_FREE_BITMAP_WAIT); + VInvalidateVnode_r(vnp); + VnUnlock(vnp, WRITE_LOCK); + VnCancelReservation_r(vnp); +#ifdef AFS_DEMAND_ATTACH_FS + VRequestSalvage_r(ec, vp, SALVSYNC_ERROR, 0); +#else + VForceOffline_r(vp, 0); +#endif + return NULL; + } + } else { /* no such vnode in the cache */ -- 2.39.5