Windows: mark volume status online during cm_MergeStatus
[openafs.git] / src / WINNT / afsd / cm_scache.c
index c86453f..bee91c4 100644 (file)
@@ -208,6 +208,7 @@ long cm_RecycleSCache(cm_scache_t *scp, afs_int32 flags)
         scp->cbServerp = NULL;
     }
     scp->cbExpires = 0;
+    scp->volumeCreationDate = 0;
 
     scp->fid.vnode = 0;
     scp->fid.volume = 0;
@@ -619,6 +620,7 @@ void cm_InitSCache(int newFile, long maxSCaches)
 #endif
                 scp->cbServerp = NULL;
                 scp->cbExpires = 0;
+                scp->volumeCreationDate = 0;
                 scp->fileLocksH = NULL;
                 scp->fileLocksT = NULL;
                 scp->serverLock = (-1);
@@ -1512,6 +1514,8 @@ void cm_MergeStatus(cm_scache_t *dscp,
                     cm_user_t *userp, cm_req_t *reqp, afs_uint32 flags)
 {
     afs_uint64 dataVersion;
+    struct cm_volume *volp = NULL;
+    struct cm_cell *cellp = NULL;
 
     // yj: i want to create some fake status for the /afs directory and the
     // entries under that directory
@@ -1577,7 +1581,7 @@ void cm_MergeStatus(cm_scache_t *dscp,
             scp->parentVnode = 0;
             scp->parentUnique = 0;
        }
-       return;
+       goto done;
     } else {
        scp->flags &= ~CM_SCACHEFLAG_EACCESS;
     }
@@ -1589,18 +1593,14 @@ void cm_MergeStatus(cm_scache_t *dscp,
     if (!(flags & CM_MERGEFLAG_FORCE) && 
         dataVersion < scp->dataVersion &&
         scp->dataVersion != CM_SCACHE_VERSION_BAD) {
-        struct cm_cell *cellp;
 
         cellp = cm_FindCellByID(scp->fid.cell, 0);
         if (scp->cbServerp) {
-            struct cm_volume *volp = NULL;
             cm_FindVolumeByID(cellp, scp->fid.volume, userp,
                               reqp, CM_GETVOL_FLAG_CREATE, &volp);
             osi_Log2(afsd_logp, "old data from server %x volume %s",
                       scp->cbServerp->addr.sin_addr.s_addr,
                       volp ? volp->namep : "(unknown)");
-            if (volp)
-                cm_PutVolume(volp);
         }
         osi_Log3(afsd_logp, "Bad merge, scp %x, scp dv %d, RPC dv %d",
                   scp, scp->dataVersion, dataVersion);
@@ -1632,9 +1632,11 @@ void cm_MergeStatus(cm_scache_t *dscp,
          * infinite loop.  So we just grin and bear it.
          */
         if (!(scp->flags & CM_SCACHEFLAG_RO))
-            return;
+            goto done;
     }       
 
+    scp->volumeCreationDate = volsyncp->spare1;       /* volume creation date */
+
     scp->serverModTime = statusp->ServerModTime;
 
     if (!(scp->mask & CM_SCACHEMASK_CLIENTMODTIME)) {
@@ -1762,6 +1764,29 @@ void cm_MergeStatus(cm_scache_t *dscp,
      * have completed yet.
      */
     cm_SyncOpDone(scp, NULL, CM_SCACHESYNC_FETCHSTATUS);
+
+    /*
+     * We just successfully merged status on the stat cache object.
+     * This means that the associated volume must be online.
+     */
+    if (!volp) {
+        if (!cellp)
+            cellp = cm_FindCellByID(scp->fid.cell, 0);
+        cm_FindVolumeByID(cellp, scp->fid.volume, userp, reqp, 0, &volp);
+    }
+    if (volp) {
+        cm_vol_state_t *statep = cm_VolumeStateByID(volp, scp->fid.volume);
+        if (statep->state != vl_online) {
+            lock_ObtainWrite(&volp->rw);
+            cm_VolumeStatusNotification(volp, statep->ID, statep->state, vl_online);
+            statep->state = vl_online;
+            lock_ReleaseWrite(&volp->rw);
+        }
+    }
+  done:
+    if (volp)
+        cm_PutVolume(volp);
+
 }
 
 /* note that our stat cache info is incorrect, so force us eventually
@@ -1963,11 +1988,44 @@ int cm_DumpSCache(FILE *outputFile, char *cookie, int lock)
   
     for (scp = cm_data.allSCachesp; scp; scp = scp->allNextp) 
     {
-        sprintf(output, "%s scp=0x%p, fid (cell=%d, volume=%d, vnode=%d, unique=%d) type=%d dv=%I64d len=0x%I64x mp='%s' Locks (server=0x%x shared=%u excl=%u clnt=%u) lockCount=%d flags=0x%x cb=0x%x refCount=%u\r\n",
-                cookie, scp, scp->fid.cell, scp->fid.volume, scp->fid.vnode, scp->fid.unique, 
-                scp->fileType, scp->dataVersion, scp->length.QuadPart, scp->mountPointStringp, 
+        time_t t;
+        char *srvStr = NULL;
+        afs_uint32 srvStrRpc = TRUE;
+        char *cbt = NULL;
+        char *cdrot = NULL;
+
+        if (scp->cbServerp) {
+            if (!((scp->cbServerp->flags & CM_SERVERFLAG_UUID) &&
+                UuidToString((UUID *)&scp->cbServerp->uuid, &srvStr) == RPC_S_OK)) {
+                afs_asprintf(&srvStr, "%.0I", scp->cbServerp->addr.sin_addr.s_addr);
+                srvStrRpc = FALSE;
+            }
+        }
+        if (scp->cbExpires) {
+            t = scp->cbExpires;
+            cbt = ctime(&t);
+            if (cbt) {
+                cbt = strdup(cbt);
+                cbt[strlen(cbt)-1] = '\0';
+            }
+        }
+        if (scp->volumeCreationDate) {
+            t = scp->volumeCreationDate;
+            cdrot = ctime(&t);
+            if (cdrot) {
+                cdrot = strdup(cdrot);
+                cdrot[strlen(cdrot)-1] = '\0';
+            }
+        }
+        sprintf(output,
+                "%s scp=0x%p, fid (cell=%d, volume=%d, vnode=%d, unique=%d) type=%d dv=%I64d len=0x%I64x "
+                "mp='%s' Locks (server=0x%x shared=%d excl=%d clnt=%d) fsLockCount=%d linkCount=%d anyAccess=0x%x "
+                "flags=0x%x cbServer='%s' cbExpires='%s' volumeCreationDate='%s' refCount=%u\r\n",
+                cookie, scp, scp->fid.cell, scp->fid.volume, scp->fid.vnode, scp->fid.unique,
+                scp->fileType, scp->dataVersion, scp->length.QuadPart, scp->mountPointStringp,
                 scp->serverLock, scp->sharedLocks, scp->exclusiveLocks, scp->clientLocks, scp->fsLockCount,
-                scp->flags, (unsigned long)scp->cbExpires, scp->refCount);
+                scp->linkCount, scp->anyAccess, scp->flags, srvStr ? srvStr : "<none>", cbt ? cbt : "<none>",
+                cdrot ? cdrot : "<none>", scp->refCount);
         WriteFile(outputFile, output, (DWORD)strlen(output), &zilch, NULL);
 
         if (scp->fileLocksH) {
@@ -1976,20 +2034,33 @@ int cm_DumpSCache(FILE *outputFile, char *cookie, int lock)
 
             for (q = scp->fileLocksH; q; q = osi_QNext(q)) {
                 cm_file_lock_t * lockp = (cm_file_lock_t *)((char *) q - offsetof(cm_file_lock_t, fileq));
-                sprintf(output, "  %s lockp=0x%p scp=0x%p, cm_userp=0x%p offset=0x%I64x len=0x%08I64x type=0x%x key=0x%I64x flags=0x%x update=0x%I64u\r\n", 
-                         cookie, lockp, lockp->scp, lockp->userp, lockp->range.offset, lockp->range.length, 
-                         lockp->lockType, lockp->key, lockp->flags, (afs_uint64)lockp->lastUpdate);
+                sprintf(output, "  %s lockp=0x%p scp=0x%p, cm_userp=0x%p offset=0x%I64x len=0x%08I64x type=0x%x "
+                        "key=0x%I64x flags=0x%x update=0x%I64u\r\n",
+                        cookie, lockp, lockp->scp, lockp->userp, lockp->range.offset, lockp->range.length,
+                        lockp->lockType, lockp->key, lockp->flags, (afs_uint64)lockp->lastUpdate);
                 WriteFile(outputFile, output, (DWORD)strlen(output), &zilch, NULL);
             }       
 
             sprintf(output, "  %s - done dumping scp locks\r\n", cookie);
             WriteFile(outputFile, output, (DWORD)strlen(output), &zilch, NULL);
         }
+
+        if (srvStr) {
+            if (srvStrRpc)
+                RpcStringFree(&srvStr);
+            else
+                free(srvStr);
+        }
+        if (cbt)
+            free(cbt);
+        if (cdrot)
+            free(cdrot);
     }
   
     sprintf(output, "%s - Done dumping all scache.\r\n", cookie);
     WriteFile(outputFile, output, (DWORD)strlen(output), &zilch, NULL);
-    sprintf(output, "%s - dumping cm_data.scacheHashTable - cm_data.scacheHashTableSize=%d\r\n", cookie, cm_data.scacheHashTableSize);
+    sprintf(output, "%s - dumping cm_data.scacheHashTable - cm_data.scacheHashTableSize=%d\r\n",
+            cookie, cm_data.scacheHashTableSize);
     WriteFile(outputFile, output, (DWORD)strlen(output), &zilch, NULL);
   
     for (i = 0; i < cm_data.scacheHashTableSize; i++)