Windows: Do not double increment cm_data.currentCells
authorJeffrey Altman <jaltman@your-file-system.com>
Mon, 11 Feb 2013 21:40:36 +0000 (16:40 -0500)
committerJeffrey Altman <jaltman@your-file-system.com>
Tue, 12 Feb 2013 04:20:53 +0000 (20:20 -0800)
During cm_cell generation the cm_data.currentCells value was
incremented twice.  As a result cm_currentCells did not equal the
number of cm_cell objects allocated.  Upon restart the AFSCache
contents would be discarded.

Change-Id: I2b62cb8268789e46f5ada4aa039e41c7ea8b47a5
Reviewed-on: http://gerrit.openafs.org/9090
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Jeffrey Altman <jaltman@your-file-system.com>
Tested-by: Jeffrey Altman <jaltman@your-file-system.com>

src/WINNT/afsd/cm_cell.c
src/WINNT/afsd/cm_memmap.h

index f9c3ed4..2fd0237 100644 (file)
@@ -180,6 +180,7 @@ cm_cell_t *cm_GetCell_Gen(char *namep, char *newnamep, afs_uint32 flags)
     afs_uint32 hash;
     cm_cell_rock_t rock;
     size_t len;
+    afs_int32 cellID;
 
     if (namep == NULL || !namep[0] || !strcmp(namep,CM_IOCTL_FILENAME_NOSLASH))
         return NULL;
@@ -269,15 +270,16 @@ cm_cell_t *cm_GetCell_Gen(char *namep, char *newnamep, afs_uint32 flags)
             if ( cm_data.currentCells >= cm_data.maxCells )
                 osi_panic("Exceeded Max Cells", __FILE__, __LINE__);
 
-            /* don't increment currentCells until we know that we
-             * are going to keep this entry
+            /*
+             * the cellID cannot be 0.
+             * If there is a name collision, one of the entries
+             * will end up on cm_data.freeCellsp for reuse.
              */
-            cp = &cm_data.cellBaseAddress[InterlockedIncrement(&cm_data.currentCells) - 1];
+            cellID = InterlockedIncrement(&cm_data.currentCells);
+            cp = &cm_data.cellBaseAddress[cellID - 1];
             memset(cp, 0, sizeof(cm_cell_t));
             cp->magic = CM_CELL_MAGIC;
-
-            /* the cellID cannot be 0 */
-            cp->cellID = ++cm_data.currentCells;
+            cp->cellID = cellID;
 
             /* otherwise we found the cell, and so we're nearly done */
             lock_InitializeMutex(&cp->mx, "cm_cell_t mutex", LOCK_HIERARCHY_CELL);
index 6cd2332..d37667b 100644 (file)
@@ -40,8 +40,8 @@ typedef struct cm_config_data {
 
     cm_cell_t  *       allCellsp;
     cm_cell_t   *       freeCellsp;
-    afs_uint32          currentCells;
-    afs_uint32          maxCells;
+    afs_int32           currentCells;
+    afs_int32           maxCells;
 
     cm_volume_t        *       rootVolumep;
     cm_cell_t   *       rootCellp;