vol: relocate some comments
[openafs.git] / src / vol / vnode.c
index 53eba88..d9f8c1f 100644 (file)
@@ -27,6 +27,9 @@
 #endif
 
 #include <afs/opr.h>
+#ifdef AFS_PTHREAD_ENV
+#include <opr/lock.h>
+#endif
 #include "rx/rx_queue.h"
 #include <afs/afsint.h>
 #include "nfs.h"
@@ -52,33 +55,6 @@ void VNLog(afs_int32 aop, afs_int32 anparms, ... );
 
 extern int LogLevel;
 
-
-
-
-#define BAD_IGET       -1000
-
-/* There are two separate vnode queue types defined here:
- * Each hash conflict chain -- is singly linked, with a single head
- * pointer. New entries are added at the beginning. Old
- * entries are removed by linear search, which generally
- * only occurs after a disk read).
- * LRU chain -- is doubly linked, single head pointer.
- * Entries are added at the head, reclaimed from the tail,
- * or removed from anywhere in the queue.
- */
-
-
-/* Vnode hash table.  Find hash chain by taking lower bits of
- * (volume_hash_offset + vnode).
- * This distributes the root inodes of the volumes over the
- * hash table entries and also distributes the vnodes of
- * volumes reasonably fairly.  The volume_hash_offset field
- * for each volume is established as the volume comes on line
- * by using the VOLUME_HASH_OFFSET macro.  This distributes the
- * volumes fairly among the cache entries, both when servicing
- * a small number of volumes and when servicing a large number.
- */
-
 /* logging stuff for finding bugs */
 #define        THELOGSIZE      5120
 static afs_int32 theLog[THELOGSIZE];
@@ -106,6 +82,20 @@ VNLog(afs_int32 aop, afs_int32 anparms, ... )
     va_end(ap);
 }
 
+
+
+
+/* Vnode hash table.  Find hash chain by taking lower bits of
+ * (volume_hash_offset + vnode).
+ * This distributes the root inodes of the volumes over the
+ * hash table entries and also distributes the vnodes of
+ * volumes reasonably fairly.  The volume_hash_offset field
+ * for each volume is established as the volume comes on line
+ * by using the VOLUME_HASH_OFFSET macro.  This distributes the
+ * volumes fairly among the cache entries, both when servicing
+ * a small number of volumes and when servicing a large number.
+ */
+
 /* VolumeHashOffset -- returns a new value to be stored in the
  * volumeHashOffset of a Volume structure.  Called when a
  * volume is initialized.  Sets the volumeHashOffset so that
@@ -138,6 +128,19 @@ private Vnode *VnodeHashTable[VNODE_HASH_TABLE_SIZE];
     ((volumeptr->vnodeHashOffset + vnodenumber)&(VNODE_HASH_TABLE_SIZE-1))
 
 
+
+#define BAD_IGET       -1000
+
+/* There are two separate vnode queue types defined here:
+ * Each hash conflict chain -- is singly linked, with a single head
+ * pointer. New entries are added at the beginning. Old
+ * entries are removed by linear search, which generally
+ * only occurs after a disk read).
+ * LRU chain -- is doubly linked, single head pointer.
+ * Entries are added at the head, reclaimed from the tail,
+ * or removed from anywhere in the queue.
+ */
+
 /**
  * add a vnode to the volume's vnode list.
  *
@@ -648,11 +651,16 @@ VAllocVnode_r(Error * ec, Volume * vp, VnodeType type, VnodeId in_vnode, Unique
      */
 
     if (!in_vnode) {
+       int rollover = 0;
+
        unique = vp->nextVnodeUnique++;
-       if (!unique)
+       if (unique == 0) {
+           rollover = 1;       /* nextVnodeUnique rolled over */
+           vp->nextVnodeUnique = 2;    /* 1 is reserved for the root vnode */
            unique = vp->nextVnodeUnique++;
+       }
 
-       if (vp->nextVnodeUnique > V_uniquifier(vp)) {
+       if (vp->nextVnodeUnique > V_uniquifier(vp) || rollover) {
            VUpdateVolume_r(ec, vp, 0);
            if (*ec)
                return NULL;
@@ -758,8 +766,8 @@ VAllocVnode_r(Error * ec, Volume * vp, VnodeType type, VnodeId in_vnode, Unique
         * 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,
+           Log("VAllocVnode:  addled bitmap or vnode object! (vol %" AFS_VOLID_FMT ", "
+               "vnode %p, number %ld, type %ld)\n", afs_printable_VolumeId_lu(vp->hashid), vnp,
                (long)Vn_id(vnp), (long)vnp->disk.type);
            *ec = EIO;
            VFreeBitMapEntry_r(&tmp, vp, &vp->vnodeIndex[class], bitNumber,
@@ -905,7 +913,7 @@ VAllocVnode_r(Error * ec, Volume * vp, VnodeType type, VnodeId in_vnode, Unique
     vnp->disk.uniquifier = unique;
     vnp->handle = NULL;
     vcp->allocs++;
-    vp->header->diskstuff.filecount++;
+    V_filecount(vp)++;
 #ifdef AFS_DEMAND_ATTACH_FS
     VnChangeState_r(vnp, VN_STATE_EXCLUSIVE);
 #endif
@@ -970,13 +978,13 @@ VnLoad(Error * ec, Volume * vp, Vnode * vnp,
            dosalv = 0;
        } else if (nBytes == -1 && errno == EIO) {
            /* disk error; salvage */
-           Log("VnLoad: Couldn't read vnode %u, volume %u (%s); volume needs salvage\n", Vn_id(vnp), V_id(vp), V_name(vp));
+           Log("VnLoad: Couldn't read vnode %u, volume %" AFS_VOLID_FMT " (%s); volume needs salvage\n", Vn_id(vnp), afs_printable_VolumeId_lu(V_id(vp)), V_name(vp));
        } else {
            /* vnode is not allocated */
            if (LogLevel >= 5)
-               Log("VnLoad: Couldn't read vnode %u, volume %u (%s); read %d bytes, errno %d\n",
-                   Vn_id(vnp), V_id(vp), V_name(vp), (int)nBytes, errno);
-           *ec = VIO;
+               Log("VnLoad: Couldn't read vnode %u, volume %" AFS_VOLID_FMT " (%s); read %d bytes, errno %d\n",
+                   Vn_id(vnp), afs_printable_VolumeId_lu(V_id(vp)), V_name(vp), (int)nBytes, errno);
+           *ec = VNOVNODE;
            dosalv = 0;
        }
        goto error_encountered_nolock;
@@ -1004,17 +1012,17 @@ VnLoad(Error * ec, Volume * vp, Vnode * vnp,
            if ((offset >= index->bitmapSize)
                || ((*(index->bitmap + offset) & (1 << (bitNumber & 0x7)))
                    == 0)) {
-               Log("VnLoad: Request for unallocated vnode %u, volume %u (%s) denied.\n", Vn_id(vnp), V_id(vp), V_name(vp));
+               Log("VnLoad: Request for unallocated vnode %u, volume %" AFS_VOLID_FMT " (%s) denied.\n", Vn_id(vnp), afs_printable_VolumeId_lu(V_id(vp)), V_name(vp));
                *ec = VNOVNODE;
                dosalv = 0;
            } else {
-               Log("VnLoad: Bad magic number, vnode %u, volume %u (%s); volume needs salvage\n", Vn_id(vnp), V_id(vp), V_name(vp));
+               Log("VnLoad: Bad magic number, vnode %u, volume %" AFS_VOLID_FMT " (%s); volume needs salvage\n", Vn_id(vnp), afs_printable_VolumeId_lu(V_id(vp)), V_name(vp));
            }
        }
        goto error_encountered;
     }
 
-    IH_INIT(vnp->handle, V_device(vp), V_parentId(vp), VN_GET_INO(vnp));
+    IH_INIT(vnp->handle, V_device(vp), afs_printable_VolumeId_lu(V_parentId(vp)), VN_GET_INO(vnp));
     VnUnlock(vnp, WRITE_LOCK);
 #ifdef AFS_DEMAND_ATTACH_FS
     VnChangeState_r(vnp, VN_STATE_ONLINE);
@@ -1103,7 +1111,7 @@ VnStore(Error * ec, Volume * vp, Vnode * vnp,
            VnChangeState_r(vnp, VN_STATE_ERROR);
 #endif
        } else {
-           Log("VnStore: Couldn't write vnode %u, volume %u (%s) (error %d)\n", Vn_id(vnp), V_id(Vn_volume(vnp)), V_name(Vn_volume(vnp)), (int)nBytes);
+           Log("VnStore: Couldn't write vnode %u, volume %" AFS_VOLID_FMT " (%s) (error %d)\n", Vn_id(vnp), afs_printable_VolumeId_lu(V_id(Vn_volume(vnp))), V_name(Vn_volume(vnp)), (int)nBytes);
 #ifdef AFS_DEMAND_ATTACH_FS
            goto error_encountered;
 #else
@@ -1420,8 +1428,8 @@ VPutVnode_r(Error * ec, Vnode * vnp)
            if (vnp->changed_newTime)
            {
                V_updateDate(vp) = vp->updateTime = now;
-               if(V_volUpCounter(vp)< UINT_MAX)
-                       V_volUpCounter(vp)++;
+               if(V_volUpdateCounter(vp)< UINT_MAX)
+                       V_volUpdateCounter(vp)++;
            }
 
            /* The vnode has been changed. Write it out to disk */
@@ -1441,8 +1449,8 @@ VPutVnode_r(Error * ec, Vnode * vnp)
                 * (doing so could cause a "addled bitmap" message).
                 */
                if (vnp->delete && !*ec) {
-                   if (Vn_volume(vnp)->header->diskstuff.filecount-- < 1)
-                       Vn_volume(vnp)->header->diskstuff.filecount = 0;
+                 if (V_filecount(Vn_volume(vnp))-- < 1)
+                     V_filecount(Vn_volume(vnp)) = 0;
                    VFreeBitMapEntry_r(ec, vp, &vp->vnodeIndex[class],
                                       vnodeIdToBitNumber(Vn_id(vnp)),
                                       VOL_FREE_BITMAP_WAIT);