]> git.michaelhowe.org Git - packages/o/openafs.git/commitdiff
DEVEL15-windows-cell-alloc-20080902
authorJeffrey Altman <jaltman@secure-endpoints.com>
Tue, 2 Sep 2008 16:21:39 +0000 (16:21 +0000)
committerJeffrey Altman <jaltman@secure-endpoints.com>
Tue, 2 Sep 2008 16:21:39 +0000 (16:21 +0000)
LICENSE MIT

Perform the initial cm_SearchCellXXX call using a temporary cm_cell_t
object in case the search fails.

(cherry picked from commit ef64f50fb9f477a0acbe1223ee2b0c9981f9324e)

src/WINNT/afsd/cm_cell.c

index d8c588887b86452da6fd642bb0a2ac550e429e5e..1a8cad6ce7552f6be52ca3d14240fded85016fe5 100644 (file)
@@ -145,7 +145,7 @@ cm_cell_t *cm_GetCell(char *namep, afs_uint32 flags)
 
 cm_cell_t *cm_GetCell_Gen(char *namep, char *newnamep, afs_uint32 flags)
 {
-    cm_cell_t *cp, *cp2;
+    cm_cell_t *cp = NULL, *cp2;
     long code;
     char fullname[CELL_MAXNAMELEN]="";
     int  hasWriteLock = 0;
@@ -180,6 +180,8 @@ cm_cell_t *cm_GetCell_Gen(char *namep, char *newnamep, afs_uint32 flags)
         lock_ReleaseRead(&cm_cellLock);
         cm_UpdateCell(cp, flags);
     } else if (flags & CM_FLAG_CREATE) {
+        cm_cell_t tmpcell;
+
         lock_ConvertRToW(&cm_cellLock);
         hasWriteLock = 1;
 
@@ -208,28 +210,15 @@ cm_cell_t *cm_GetCell_Gen(char *namep, char *newnamep, afs_uint32 flags)
         if (cp)
             goto done;
 
-        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 
-         */
-        cp = &cm_data.cellBaseAddress[cm_data.currentCells];
-        memset(cp, 0, sizeof(cm_cell_t));
-        cp->magic = CM_CELL_MAGIC;
-
-        /* the cellID cannot be 0 */
-        cp->cellID = ++cm_data.currentCells;
-
-        /* otherwise we found the cell, and so we're nearly done */
-        lock_InitializeMutex(&cp->mx, "cm_cell_t mutex", LOCK_HIERARCHY_CELL);
-
-        cp->name[0] = '\0';     /* No name yet */
-
         lock_ReleaseWrite(&cm_cellLock);
         hasWriteLock = 0;
 
-        rock.cellp = cp;
+        /* 
+         * Use a temporary cell object for the cm_SearchCellXXX calls
+         * in case the search fails and we have to discard this entry.
+         */
+        memset(&tmpcell, 0, sizeof(cm_cell_t));
+        rock.cellp = &tmpcell;
         rock.flags = flags;
         code = cm_SearchCellFile(namep, fullname, cm_AddCellProc, &rock);
         if (code) {
@@ -244,26 +233,23 @@ cm_cell_t *cm_GetCell_Gen(char *namep, char *newnamep, afs_uint32 flags)
                 if ( code ) {
                     osi_Log3(afsd_logp,"in cm_GetCell_gen cm_SearchCellByDNS(%s) returns code= %d fullname= %s", 
                              osi_LogSaveString(afsd_logp,namep), code, osi_LogSaveString(afsd_logp,fullname));
-                    cp = NULL;
                     goto done;
                 } else {   /* got cell from DNS */
                     lock_ObtainWrite(&cm_cellLock);
                     hasWriteLock = 1;
-                    cp->flags |= CM_CELLFLAG_DNS;
-                    cp->flags &= ~CM_CELLFLAG_VLSERVER_INVALID;
-                    cp->timeout = time(0) + ttl;
+                    tmpcell.flags |= CM_CELLFLAG_DNS;
+                    tmpcell.flags &= ~CM_CELLFLAG_VLSERVER_INVALID;
+                    tmpcell.timeout = time(0) + ttl;
                 }
-            } else {
-#endif
-                cp = NULL;
+           } else 
+#endif /* AFS_AFSDB_ENV */            
+            {
                 goto done;
-#ifdef AFS_AFSDB_ENV
-           }
-#endif
+            }
         } else {
             lock_ObtainWrite(&cm_cellLock);
             hasWriteLock = 1;
-           cp->timeout = time(0) + 7200;       /* two hour timeout */
+           tmpcell.timeout = time(0) + 7200;   /* two hour timeout */
        }
 
         /* we have now been given the fullname of the cell.  It may
@@ -272,18 +258,32 @@ cm_cell_t *cm_GetCell_Gen(char *namep, char *newnamep, afs_uint32 flags)
          * of a new cm_cell_t 
          */
         hash = CM_CELL_NAME_HASH(fullname);
-        for (cp2 = cm_data.cellNameHashTablep[hash]; cp2; cp2=cp2->nameNextp) {
-            if (cm_stricmp_utf8(fullname, cp2->name) == 0) {
+        for (cp = cm_data.cellNameHashTablep[hash]; cp; cp=cp->nameNextp) {
+            if (cm_stricmp_utf8(fullname, cp->name) == 0) {
                 break;
             }
         }   
 
-        if (cp2) {
-            cm_FreeServerList(&cp->vlServersp, CM_FREESERVERLIST_DELETE);
-            cp = cp2;
+        if (cp) {
+            cm_FreeServerList(&tmpcell.vlServersp, CM_FREESERVERLIST_DELETE);
             goto done;
         }
 
+        if ( cm_data.currentCells >= cm_data.maxCells )
+            osi_panic("Exceeded Max Cells", __FILE__, __LINE__);
+
+        /* 
+         * allocate a cell object that we can keep and initialize 
+         * it using the vldb server list obtained during the cm_SearchCellXXX 
+         * calls.
+         */
+        cp = &cm_data.cellBaseAddress[cm_data.currentCells++];
+        memcpy(cp, &tmpcell, sizeof(cm_cell_t));
+        cp->magic = CM_CELL_MAGIC;
+        cp->cellID = cm_data.currentCells;
+
+        /* otherwise we found the cell, and so we're nearly done */
+        lock_InitializeMutex(&cp->mx, "cm_cell_t mutex", LOCK_HIERARCHY_CELL);
 
         /* randomise among those vlservers having the same rank*/ 
         cm_RandomizeServer(&cp->vlServersp);