Windows: interlocked refCount increment in cm_GetSCache
authorJeffrey Altman <jaltman@your-file-system.com>
Mon, 14 Nov 2011 22:49:45 +0000 (17:49 -0500)
committerJeffrey Altman <jaltman@secure-endpoints.com>
Tue, 15 Nov 2011 14:10:09 +0000 (06:10 -0800)
Failure to use interlocked operations in cm_GetSCache can
result in an under count

Change-Id: I370bcb9ac8b40f1c1b7ea3b7647fc76e3a554e2c
Reviewed-on: http://gerrit.openafs.org/6046
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Jeffrey Altman <jaltman@secure-endpoints.com>
Tested-by: Jeffrey Altman <jaltman@secure-endpoints.com>

src/WINNT/afsd/cm_scache.c

index e556908..9410c7f 100644 (file)
@@ -680,6 +680,7 @@ long cm_GetSCache(cm_fid_t *fidp, cm_scache_t **outScpp, cm_user_t *userp,
     int special = 0; // yj: boolean variable to test if file is on root.afs
     int isRoot = 0;
     extern cm_fid_t cm_rootFid;
+    afs_int32 refCount;
 
     hash = CM_SCACHE_HASH(fidp);
 
@@ -766,8 +767,8 @@ long cm_GetSCache(cm_fid_t *fidp, cm_scache_t **outScpp, cm_user_t *userp,
             cm_data.scacheHashTablep[hash] = scp;
             _InterlockedOr(&scp->flags, CM_SCACHEFLAG_INHASH);
         }
-        scp->refCount = 1;
-       osi_Log1(afsd_logp,"cm_GetSCache (freelance) sets refCount to 1 scp 0x%p", scp);
+        refCount = InterlockedIncrement(&scp->refCount);
+       osi_Log2(afsd_logp,"cm_GetSCache (freelance) sets refCount to 1 scp 0x%p refCount %d", scp, refCount);
         lock_ReleaseWrite(&cm_scacheLock);
 
         /* must be called after the scp->fid is set */
@@ -889,13 +890,13 @@ long cm_GetSCache(cm_fid_t *fidp, cm_scache_t **outScpp, cm_user_t *userp,
     scp->nextp = cm_data.scacheHashTablep[hash];
     cm_data.scacheHashTablep[hash] = scp;
     _InterlockedOr(&scp->flags, CM_SCACHEFLAG_INHASH);
+    refCount = InterlockedIncrement(&scp->refCount);
     lock_ReleaseWrite(&cm_scacheLock);
     lock_ReleaseWrite(&scp->rw);
-    scp->refCount = 1;
 #ifdef DEBUG_REFCOUNT
-    afsi_log("%s:%d cm_GetSCache sets refCount to 1 scp 0x%p", file, line, scp);
+    afsi_log("%s:%d cm_GetSCache sets refCount to 1 scp 0x%p refCount %d", file, line, scp, refCount);
 #endif
-    osi_Log1(afsd_logp,"cm_GetSCache sets refCount to 1 scp 0x%p", scp);
+    osi_Log2(afsd_logp,"cm_GetSCache sets refCount to 1 scp 0x%p refCount %d", scp, refCount);
 
     /* XXX - The following fields in the cm_scache are
      * uninitialized: