DAFS: VnLock after VnWaitQuiescent in VAllocVnode
[openafs.git] / src / vol / vnode.c
index a111cc7..532fe83 100644 (file)
@@ -17,6 +17,9 @@
  */
 #include <afsconfig.h>
 #include <afs/param.h>
+
+#include <roken.h>
+
 #define MAXINT     (~(1<<((sizeof(int)*8)-1)))
 
 
@@ -666,9 +669,6 @@ VAllocVnode_r(Error * ec, Volume * vp, VnodeType type)
            /* This won't block */
            VnLock(vnp, WRITE_LOCK, VOL_LOCK_HELD, WILL_NOT_DEADLOCK);
        } else {
-           /* other users present; follow locking hierarchy */
-           VnLock(vnp, WRITE_LOCK, VOL_LOCK_HELD, MIGHT_DEADLOCK);
-
 #ifdef AFS_DEMAND_ATTACH_FS
            /*
             * DAFS:
@@ -686,6 +686,9 @@ VAllocVnode_r(Error * ec, Volume * vp, VnodeType type)
            }
 #endif
 
+           /* other users present; follow locking hierarchy */
+           VnLock(vnp, WRITE_LOCK, VOL_LOCK_HELD, MIGHT_DEADLOCK);
+
            /*
             * verify state of the world hasn't changed
             *
@@ -810,7 +813,7 @@ VAllocVnode_r(Error * ec, Volume * vp, VnodeType type)
            if (fdP)
                FDH_CLOSE(fdP);
            VOL_LOCK;
-           VFreeBitMapEntry_r(&tmp, &vp->vnodeIndex[class], bitNumber);
+           VFreeBitMapEntry_r(&tmp, vp, &vp->vnodeIndex[class], bitNumber, 0 /*flags*/);
            VInvalidateVnode_r(vnp);
            VnUnlock(vnp, WRITE_LOCK);
            VnCancelReservation_r(vnp);
@@ -928,6 +931,12 @@ VnLoad(Error * ec, Volume * vp, Vnode * vnp,
            unsigned int bitNumber = vnodeIdToBitNumber(Vn_id(vnp));
            unsigned int offset = bitNumber >> 3;
 
+#ifdef AFS_DEMAND_ATTACH_FS
+           /* Make sure the volume bitmap isn't getting updated while we are
+            * checking it */
+           VWaitExclusiveState_r(vp);
+#endif
+
            /* Test to see if vnode number is valid. */
            if ((offset >= index->bitmapSize)
                || ((*(index->bitmap + offset) & (1 << (bitNumber & 0x7)))
@@ -1377,8 +1386,9 @@ VPutVnode_r(Error * ec, Vnode * vnp)
                if (vnp->delete && !*ec) {
                    if (Vn_volume(vnp)->header->diskstuff.filecount-- < 1)
                        Vn_volume(vnp)->header->diskstuff.filecount = 0;
-                   VFreeBitMapEntry_r(ec, &vp->vnodeIndex[class],
-                                      vnodeIdToBitNumber(Vn_id(vnp)));
+                   VFreeBitMapEntry_r(ec, vp, &vp->vnodeIndex[class],
+                                      vnodeIdToBitNumber(Vn_id(vnp)),
+                                      VOL_FREE_BITMAP_WAIT);
                }
            }
            vcp->writes++;