Windows: cm_GetNewSCache init mpDV to BAD
[openafs.git] / src / WINNT / afsd / cm_scache.c
index dbfe277..1c07b12 100644 (file)
@@ -66,11 +66,8 @@ cm_RootSCachep(cm_user_t *userp, cm_req_t *reqp)
 void cm_AdjustScacheLRU(cm_scache_t *scp)
 {
     lock_AssertWrite(&cm_scacheLock);
-    osi_QRemoveHT((osi_queue_t **) &cm_data.scacheLRUFirstp, (osi_queue_t **) &cm_data.scacheLRULastp, &scp->q);
-    if (scp->flags & CM_SCACHEFLAG_DELETED) {
-        /* Since it has been deleted make it the first to be recycled. */
-        osi_QAddT((osi_queue_t **) &cm_data.scacheLRUFirstp, (osi_queue_t **) &cm_data.scacheLRULastp, &scp->q);
-    } else {
+    if (!(scp->flags & CM_SCACHEFLAG_DELETED)) {
+        osi_QRemoveHT((osi_queue_t **) &cm_data.scacheLRUFirstp, (osi_queue_t **) &cm_data.scacheLRULastp, &scp->q);
         osi_QAddH((osi_queue_t **) &cm_data.scacheLRUFirstp, (osi_queue_t **) &cm_data.scacheLRULastp, &scp->q);
     }
 }
@@ -390,7 +387,7 @@ cm_GetNewSCache(afs_uint32 locked)
     /* if we get here, we should allocate a new scache entry.  We either are below
      * quota or we have a leak and need to allocate a new one to avoid panicing.
      */
-    scp = cm_data.scacheBaseAddress + cm_data.currentSCaches;
+    scp = cm_data.scacheBaseAddress + InterlockedIncrement(&cm_data.currentSCaches) - 1;
     osi_assertx(scp >= cm_data.scacheBaseAddress && scp < (cm_scache_t *)cm_data.scacheHashTablep,
                 "invalid cm_scache_t address");
     memset(scp, 0, sizeof(cm_scache_t));
@@ -406,10 +403,10 @@ cm_GetNewSCache(afs_uint32 locked)
     scp->dataVersion = CM_SCACHE_VERSION_BAD;
     scp->bufDataVersionLow = CM_SCACHE_VERSION_BAD;
     scp->lockDataVersion = CM_SCACHE_VERSION_BAD;
+    scp->mpDataVersion = CM_SCACHE_VERSION_BAD;
 
     /* and put it in the LRU queue */
     osi_QAddH((osi_queue_t **) &cm_data.scacheLRUFirstp, (osi_queue_t **)&cm_data.scacheLRULastp, &scp->q);
-    cm_data.currentSCaches++;
     cm_dnlcPurgedp(scp); /* make doubly sure that this is not in dnlc */
     cm_dnlcPurgevp(scp);
     scp->allNextp = cm_data.allSCachesp;
@@ -1611,6 +1608,17 @@ dv_diff(afs_uint64 dv1, afs_uint64 dv2)
         return (afs_uint32)(dv1 - dv2);
 }
 
+long
+cm_IsStatusValid(AFSFetchStatus *statusp)
+{
+    if (statusp->InterfaceVersion != 0x1 ||
+        !(statusp->FileType > 0 && statusp->FileType <= SymbolicLink)) {
+        return 0;
+    }
+
+    return 1;
+}
+
 /* merge in a response from an RPC.  The scp must be locked, and the callback
  * is optional.
  *
@@ -1624,7 +1632,7 @@ dv_diff(afs_uint64 dv1, afs_uint64 dv2)
  * handled after the callback breaking is done, but only one of whose calls
  * started before that, can cause old info to be merged from the first call.
  */
-void cm_MergeStatus(cm_scache_t *dscp,
+long cm_MergeStatus(cm_scache_t *dscp,
                    cm_scache_t *scp, AFSFetchStatus *statusp,
                    AFSVolSync *volsyncp,
                     cm_user_t *userp, cm_req_t *reqp, afs_uint32 flags)
@@ -1675,10 +1683,10 @@ void cm_MergeStatus(cm_scache_t *dscp,
     }
 #endif /* AFS_FREELANCE_CLIENT */
 
-    if (statusp->InterfaceVersion != 0x1) {
-        osi_Log2(afsd_logp, "Merge, Failure scp 0x%p Invalid InterfaceVersion %u",
-                 scp, statusp->InterfaceVersion);
-        return;
+    if (!cm_IsStatusValid(statusp)) {
+        osi_Log3(afsd_logp, "Merge: Bad Status scp 0x%p Invalid InterfaceVersion %d FileType %d",
+                 scp, statusp->InterfaceVersion, statusp->FileType);
+        return CM_ERROR_INVAL;
     }
 
     if (statusp->errorCode != 0) {
@@ -1694,7 +1702,7 @@ void cm_MergeStatus(cm_scache_t *dscp,
         if (scp->fid.vnode & 0x1)
             scp->fileType = CM_SCACHETYPE_DIRECTORY;
         else
-            scp->fileType = 0; /* unknown */
+            scp->fileType = CM_SCACHETYPE_UNKNOWN;
 
        scp->serverModTime = 0;
        scp->clientModTime = 0;
@@ -2010,6 +2018,8 @@ void cm_MergeStatus(cm_scache_t *dscp,
                              scp->fileType, AFS_INVALIDATE_DATA_VERSION);
         lock_ObtainWrite(&scp->rw);
     }
+
+    return 0;
 }
 
 /* note that our stat cache info is incorrect, so force us eventually