viced-log-refd-client-while-deleting-20030215
[openafs.git] / src / viced / host.c
index 209a006..65d1f4e 100644 (file)
@@ -417,19 +417,14 @@ static char h_AddrInSameNetwork(afs_uint32 a_targetAddr, afs_uint32 a_candAddr)
 #endif /* FS_STATS_DETAILED */
 
 
-
+/* Assumptions: called with held host */
 void
 h_gethostcps_r(register struct host *host, register afs_int32 now)
 {
     register int code;
-    int  slept=0, held;
-
-    /* at this point, the host might not be locked, nor held */
-    /* make sure that we do not disappear behind the RPC     */
-    if ( !(held = h_Held_r(host)) )
-               h_Hold_r(host);
+    int  slept=0;
 
-       /* wait if somebody else is already doing the getCPS call */
+    /* wait if somebody else is already doing the getCPS call */
     while ( host->hostFlags & HCPS_INPROGRESS ) 
     {
        slept = 1;              /* I did sleep */
@@ -498,14 +493,10 @@ h_gethostcps_r(register struct host *host, register afs_int32 now)
                ViceLog(0, ("LWP_NoYieldSignal returns %d\n", code));
 #endif /* AFS_PTHREAD_ENV */
     }
-
-    /* if we had held the  host, release it now */
-    if ( !held ) 
-       h_Release_r(host);
 }
 
-void h_flushhostcps(hostaddr, hport)
-    register afs_uint32  hostaddr, hport;  /* net byte order */
+/* args in net byte order */
+void h_flushhostcps(register afs_uint32 hostaddr, register afs_uint32 hport)
 {
     register struct host *host;
     int held;
@@ -519,7 +510,7 @@ void h_flushhostcps(hostaddr, hport)
       h_Release_r(host);
     H_UNLOCK
 
-return;
+    return;
 }
 
 
@@ -582,11 +573,10 @@ struct host *h_Alloc_r(register struct rx_connection *r_con)
     host->hostFlags = 0;
     host->hcps.prlist_val = NULL;
     host->hcps.prlist_len = 0;
-    host->hcps.prlist_val = NULL;
     host->interface = 0;
 #ifdef undef
     host->hcpsfailed = 0;      /* save cycles */
-    h_gethostcps(host);      /* do this under host lock */
+    h_gethostcps(host);      /* do this under host hold/lock */
 #endif
     host->FirstClient = 0;      
     h_Hold_r(host);
@@ -642,8 +632,10 @@ restart:
                 * membership list for the host.  Note this could be the
                 * first time that the host is added to a group.  Also
                 * here we also retry on previous legitimate hcps failures.
+                *
+                * If we get here we still have a host hold.
                 */
-               h_gethostcps_r(host,now);
+               h_gethostcps_r(host,now); 
            }
            break;
        }
@@ -706,13 +698,20 @@ int h_TossStuff_r(register struct host *host)
        h_Unlock_r(host);
     }
 
-    /* ASSUMPTION: r_FreeConnection() does not yield */
+    /* ASSUMPTION: rxi_FreeConnection() does not yield */
     for (cp = &host->FirstClient; (client = *cp); ) {
        if ((host->hostFlags & HOSTDELETED) || client->deleted) {
+           if (client->refCount) {
+               char hoststr[16];
+               ViceLog(0, ("Warning: Host %s:%d client %x refcount %d while deleting.\n",
+                           afs_inet_ntoa_r(host->host, hoststr), host->port,
+                   client, client->refCount)); 
+           }
            if ((client->ViceId != ANONYMOUSID) && client->CPS.prlist_val) {
                free(client->CPS.prlist_val);
                 client->CPS.prlist_val = NULL;
            }
+           client->CPS.prlist_len = 0;
            if (client->tcon) {
                rx_SetSpecific(client->tcon, rxcon_client_key, (void *)0);
            }
@@ -1376,6 +1375,7 @@ ticket name length != 64
        if (!client) {
          client = GetCE();
          ObtainWriteLock(&client->lock);
+         client->refCount = 1;
          client->host = host;
          client->next = host->FirstClient;
          host->FirstClient = client;
@@ -1388,7 +1388,7 @@ ticket name length != 64
          client->sid = rxr_CidOf(tcon);
          client->VenusEpoch = rxr_GetEpoch(tcon);
          client->CPS.prlist_val = 0;
-         client->refCount = 1;
+         client->CPS.prlist_len = 0;
          CurrentConnections++; /* increment number of connections */
        }
     }
@@ -1399,6 +1399,7 @@ ticket name length != 64
           free(client->CPS.prlist_val);
        }
        client->CPS.prlist_val = NULL;
+       client->CPS.prlist_len = 0;
         client->ViceId = viceid;
        client->expTime = expTime;