vol-volser-more-liberal-information-in-log-messages-20010602
[openafs.git] / src / vol / volume.c
index 9ffb550..0fb985e 100644 (file)
 #ifdef AFS_SUN5_ENV
 #include <sys/fs/ufs_fs.h>
 #else
+#if defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV)
+#include <ufs/ufs/dinode.h>
+#include <ufs/ffs/fs.h>
+#else
 #include <ufs/fs.h>
 #endif
+#endif
 #else /* AFS_VFSINCL_ENV */
-#if !defined(AFS_AIX_ENV) && !defined(AFS_LINUX20_ENV)
+#if !defined(AFS_AIX_ENV) && !defined(AFS_LINUX20_ENV) && !defined(AFS_FBSD_ENV)
 #include <sys/fs.h>
 #endif
 #endif /* AFS_VFSINCL_ENV */
 #if defined(AFS_SGI_ENV)
 #include <fcntl.h>
 #include <mntent.h>
-#ifndef AFS_SGI_XFS_IOPS_ENV
+#ifdef AFS_SGI_EFS_IOPS_ENV
 #define ROOTINO EFS_ROOTINO
-#endif
-/*
 #include <sys/fs/efs.h>
-*/
-#include "../sgiefs/efs.h" /* until 5.1 release */
+#include "../sgiefs/efs.h" /* until 5.1 release */ 
+#endif
+
 
 #else
 #ifndef AFS_LINUX20_ENV
@@ -547,11 +551,15 @@ VAttachVolumeByName_r(ec, partition, name, mode)
            if (vp->specialStatus == VBUSY)
                isbusy = 1;
            VDetachVolume_r(ec, vp);
+           if ( *ec ) {
+               Log("VAttachVolume: Error detaching volume (%s)\n", name);
+           }
        }
     }
 
     if (!(partp = VGetPartition_r(partition, 0))) {
        *ec = VNOVOL;
+       Log("VAttachVolume: Error getting partition (%s)\n", partition);
        goto done;
     }
 
@@ -563,6 +571,7 @@ VAttachVolumeByName_r(ec, partition, name, mode)
     if ((fd = open(path, O_RDONLY)) == -1 || fstat(fd,&status) == -1) {
        close(fd);
        VOL_LOCK
+       Log("VAttachVolume: Error opening/statting volume header file (%s)\n", path);
        *ec = VNOVOL;
        goto done;
     }
@@ -626,6 +635,7 @@ VAttachVolumeByName_r(ec, partition, name, mode)
 #endif
        VUpdateVolume_r(ec,vp);
        if (*ec) {
+           Log("VAttachVolume: Error updating volume\n");
            if (vp)
                VPutVolume_r(vp);
            goto done;
@@ -642,6 +652,7 @@ VAttachVolumeByName_r(ec, partition, name, mode)
            V_dontSalvage(vp) = DONT_SALVAGE;
            VAddToVolumeUpdateList_r(ec,vp);
            if (*ec) {
+               Log("VAttachVolume: Error adding volume to update list\n");
                if (vp)
                    VPutVolume_r(vp);
                goto done;
@@ -695,6 +706,10 @@ private Volume *attach2(ec, path, header, partp, isbusy)
                      (char *)&V_disk(vp), sizeof(V_disk(vp)), 
                      VOLUMEINFOMAGIC, VOLUMEINFOVERSION);
     VOL_LOCK
+    if (*ec) {
+      Log("VAttachVolume: Error reading diskDataHandle vol header %s; error=%d\n",
+        path, *ec);
+    }
     if (!*ec) {
        struct IndexFileHeader iHead;
 
@@ -714,6 +729,10 @@ private Volume *attach2(ec, path, header, partp, isbusy)
                          (char *)&iHead, sizeof(iHead), 
                          SMALLINDEXMAGIC, SMALLINDEXVERSION);
        VOL_LOCK
+       if (*ec) {
+           Log("VAttachVolume: Error reading smallVnode vol header %s; error=%d\n",
+               path, *ec);
+       }
     }
     if (!*ec) {
        struct IndexFileHeader iHead;
@@ -722,6 +741,10 @@ private Volume *attach2(ec, path, header, partp, isbusy)
                          (char *)&iHead, sizeof(iHead),
                          LARGEINDEXMAGIC, LARGEINDEXVERSION);
        VOL_LOCK
+       if (*ec) {
+           Log("VAttachVolume: Error reading largeVnode vol header %s; error=%d\n",
+               path, *ec);
+       }
     }
 #ifdef AFS_NAMEI_ENV
     if (!*ec) {
@@ -731,11 +754,15 @@ private Volume *attach2(ec, path, header, partp, isbusy)
                          (char *)&stamp, sizeof(stamp),
                          LINKTABLEMAGIC, LINKTABLEVERSION);
        VOL_LOCK
+       if (*ec) {
+           Log("VAttachVolume: Error reading namei vol header %s; error=%d\n",
+               path, *ec);
+       }
     }
 #endif
     if (*ec) {
-       Log("VAttachVolume: Error attaching volume %s; volume needs salvage\n",
-           path);
+       Log("VAttachVolume: Error attaching volume %s; volume needs salvage; error=%d\n",
+           path, *ec);
        FreeVolume(vp);
        return NULL;
     }
@@ -746,6 +773,7 @@ private Volume *attach2(ec, path, header, partp, isbusy)
        return NULL;
     }
     if (programType == fileServer) {
+#ifndef FAST_RESTART
        if (V_inUse(vp) && VolumeWriteable(vp)) {
            if (!V_needsSalvaged(vp)) {
                V_needsSalvaged(vp) = 1;
@@ -756,6 +784,7 @@ private Volume *attach2(ec, path, header, partp, isbusy)
            *ec = VSALVAGE;
            return NULL;
        }
+#endif /* FAST_RESTART */
        if (V_destroyMe(vp) == DESTROY_ME) {
            FreeVolume(vp);
            Log("VAttachVolume: volume %s is junk; it should be destroyed at next salvage\n", path);
@@ -767,6 +796,7 @@ private Volume *attach2(ec, path, header, partp, isbusy)
     AddVolumeToHashTable(vp, V_id(vp));
     vp->nextVnodeUnique = V_uniquifier(vp);
     vp->vnodeIndex[vSmall].bitmap = vp->vnodeIndex[vLarge].bitmap = NULL;
+#ifndef BITMAP_LATER
     if (programType == fileServer && VolumeWriteable(vp)) {
        int i;
        for (i = 0; i<nVNODECLASSES; i++) {
@@ -775,10 +805,12 @@ private Volume *attach2(ec, path, header, partp, isbusy)
            VOL_LOCK
            if (*ec) {
                FreeVolume(vp);
+               Log("VAttachVolume: error getting bitmap for volume (%s)\n", path);
                return NULL;
            }
        }
     }
+#endif /* BITMAP_LATER */
 
     if (programType == fileServer) {
         if (vp->specialStatus) vp->specialStatus = 0;
@@ -1209,6 +1241,43 @@ int VAllocBitmapEntry_r(ec,vp,index)
        *ec = VREADONLY;
        return 0;
     }
+#ifdef BITMAP_LATER
+    if ((programType == fileServer) && !index->bitmap) {
+        int i;
+        int wasVBUSY = 0;
+        if (vp->specialStatus == VBUSY) {
+            if (vp->goingOffline) { /* vos dump waiting for the volume to
+                                       go offline. We probably come here
+                                       from AddNewReadableResidency */
+                wasVBUSY = 1;
+            } else {
+                VOL_UNLOCK
+               while (vp->specialStatus == VBUSY)
+#ifdef AFS_PTHREAD_ENV
+                   sleep(2);
+#else /* AFS_PTHREAD_ENV */
+                   IOMGR_Sleep(2);
+#endif /* AFS_PTHREAD_ENV */
+                VOL_LOCK
+           }
+        }
+        if (!index->bitmap) {
+            vp->specialStatus = VBUSY; /* Stop anyone else from using it.*/
+            for (i = 0; i<nVNODECLASSES; i++) {
+                VOL_UNLOCK
+                GetBitmap(ec,vp,i);
+                VOL_LOCK
+                if (*ec) {
+                    vp->specialStatus = 0;
+                    vp->shuttingDown = 1; /* Let who has it free it. */
+                    return NULL;
+                }
+            }
+            if (!wasVBUSY)
+                vp->specialStatus = 0; /* Allow others to have access. */
+        }
+    }
+#endif /* BITMAP_LATER */
     bp = index->bitmap + index->bitmapOffset;
     ep = index->bitmap + index->bitmapSize;
     while (bp < ep) {
@@ -1253,6 +1322,9 @@ void VFreeBitMapEntry_r(Error *ec, register struct vnodeIndex *index,
 {
     unsigned int offset;
      *ec = 0;
+#ifdef BITMAP_LATER
+     if (!index->bitmap) return;
+#endif /* BITMAP_LATER */
      offset = bitNumber>>3;
      if (offset >= index->bitmapSize) {
        *ec = VNOVNODE;
@@ -1339,6 +1411,9 @@ static void GetBitmap(Error *ec, Volume *vp, VnodeClass class)
     struct VnodeDiskObject *vnode;
     unsigned int unique = 0;
     FdHandle_t *fdP;
+#ifdef BITMAP_LATER
+    byte *BitMap = 0;
+#endif /* BITMAP_LATER */
 
     *ec = 0;
 
@@ -1357,9 +1432,14 @@ static void GetBitmap(Error *ec, Volume *vp, VnodeClass class)
                                the whole thing is rounded up to nearest 4
                                bytes, because the bit map allocator likes
                                it that way */
+#ifdef BITMAP_LATER
+    BitMap = (byte *) calloc(1, vip->bitmapSize);
+    assert(BitMap != NULL);
+#else /* BITMAP_LATER */
     vip->bitmap = (byte *) calloc(1, vip->bitmapSize);
     assert(vip->bitmap != NULL);
     vip->bitmapOffset = 0;
+#endif /* BITMAP_LATER */
     if (STREAM_SEEK(file,vcp->diskSize,0) != -1) {
       int bitNumber = 0;
       for (bitNumber = 0; bitNumber < nVnodes+100; bitNumber++) {
@@ -1372,7 +1452,11 @@ static void GetBitmap(Error *ec, Volume *vp, VnodeClass class)
            *ec = VSALVAGE;
            break;
          }
+#ifdef BITMAP_LATER
+          *(BitMap + (bitNumber>>3)) |= (1 << (bitNumber & 0x7));
+#else /* BITMAP_LATER */
          *(vip->bitmap + (bitNumber>>3)) |= (1 << (bitNumber & 0x7));
+#endif /* BITMAP_LATER */
          if (unique <= vnode->uniquifier)
            unique = vnode->uniquifier + 1; 
        }
@@ -1394,6 +1478,17 @@ static void GetBitmap(Error *ec, Volume *vp, VnodeClass class)
     STREAM_CLOSE(file);
     FDH_CLOSE(fdP);
     free(vnode);
+#ifdef BITMAP_LATER
+    /* There may have been a racing condition with some other thread, both
+     * creating the bitmaps for this volume. If the other thread was faster
+     * the pointer to bitmap should already be filled and we can free ours.
+     */
+    if (vip->bitmap == NULL) {
+        vip->bitmap = BitMap;
+        vip->bitmapOffset = 0;
+    } else 
+       free((byte *)BitMap);
+#endif /* BITMAP_LATER */
 }
 
 static void GetVolumePath(Error *ec, VolId volumeId, char **partitionp,