]> git.michaelhowe.org Git - packages/o/openafs.git/commitdiff
callback-function-fixes-20020317
authorDerrick Brashear <shadow@dementia.org>
Sun, 17 Mar 2002 17:53:00 +0000 (17:53 +0000)
committerDerrick Brashear <shadow@dementia.org>
Sun, 17 Mar 2002 17:53:00 +0000 (17:53 +0000)
suggested by lha@stacken.kth.se

drop locks when rxi_Alloc fails, and rework SRXAFSCB_GetCellServDB to use
afs_GetCellByIndex. He suggested same for GetLocalCell, and as long as cell 1
and not CPrimary is the local cell indicator that works, but I left that part
of the code as is for now.

src/afs/afs_callback.c

index 69a010b25a05ca6c0adec954c6f5220bc7aa1bca..cf7da16d71cba35cb4b605f9d818f0eb4fcd6269 100644 (file)
@@ -1189,23 +1189,22 @@ int SRXAFSCB_GetCellServDB(
 
     /* search the list for the cell with this index */
     ObtainReadLock(&afs_xcell);
-    for (i=0, cq = CellLRU.next; cq != &CellLRU && i<= a_index; cq = tq, i++) {
-        tq = QNext(cq);
-       if (i == a_index) {
-           tcell = QTOC(cq);
-           p_name = tcell->cellName;
-           for (j = 0 ; j < AFSMAXCELLHOSTS && tcell->cellHosts[j] ; j++) {
-               a_hosts[j] = ntohl(tcell->cellHosts[j]->addr->sa_ip);
-           }
+
+    tcell = afs_GetCellByIndex(a_index, READ_LOCK, 0);
+
+    if (!tcell) {
+       i = 0;
+    } else {
+       p_name = tcell->cellName;
+       for (j = 0 ; j < AFSMAXCELLHOSTS && tcell->cellHosts[j] ; j++) {
+           a_hosts[j] = ntohl(tcell->cellHosts[j]->addr->sa_ip);
        }
+       i = strlen(p_name);
     }
 
-    if (p_name)
-       i = strlen(p_name);
-    else
-       i = 0;
     t_name = (char *)rxi_Alloc(i+1);
     if (t_name == NULL) {
+       ReleaseReadLock(&afs_xcell);
        RX_AFS_GUNLOCK();
        return ENOMEM;
     }
@@ -1259,6 +1258,7 @@ int SRXAFSCB_GetLocalCell(
      * the primary cell is when no other cell is explicitly marked as
      * the primary cell.  */
     ObtainReadLock(&afs_xcell);
+
     for (cq = CellLRU.next; cq != &CellLRU; cq = tq) {
         tq = QNext(cq);
        tcell = QTOC(cq);
@@ -1277,6 +1277,7 @@ int SRXAFSCB_GetLocalCell(
        plen = 0;
     t_name = (char *)rxi_Alloc(plen+1);
     if (t_name == NULL) {
+       ReleaseReadLock(&afs_xcell);
        RX_AFS_GUNLOCK();
        return ENOMEM;
     }