callback-rxcon-use-safely-20041108
[openafs.git] / src / viced / host.c
index 0fba00f..8193a68 100644 (file)
@@ -781,6 +781,7 @@ h_TossStuff_r(register struct host *host)
                    *hp = th->next;
                    h_DeleteList_r(host);
                    FreeHT(host);
+                   free(th);
                    break;
                }
            }
@@ -832,6 +833,7 @@ h_FreeConnection(struct rx_connection *tcon)
            client->tcon = (struct rx_connection *)0;
        H_UNLOCK;
     }
+    return 0;
 }                              /*h_FreeConnection */
 
 
@@ -945,6 +947,7 @@ h_GetHost_r(struct rx_connection *tcon)
     afs_int32 hport;
     char hoststr[16], hoststr2[16];
     Capabilities caps;
+    struct rx_connection *cb_conn = NULL;
 
     caps.Capabilities_val = NULL;
 
@@ -977,11 +980,15 @@ h_GetHost_r(struct rx_connection *tcon)
            goto retry;
        }
        host->hostFlags &= ~ALTADDR;
+       cb_conn = host->callback_rxcon;
+       rx_GetConnection(cb_conn);
        H_UNLOCK;
        code =
-           RXAFSCB_TellMeAboutYourself(host->callback_rxcon, &interf, &caps);
+           RXAFSCB_TellMeAboutYourself(cb_conn, &interf, &caps);
        if (code == RXGEN_OPCODE)
-           code = RXAFSCB_WhoAreYou(host->callback_rxcon, &interf);
+           code = RXAFSCB_WhoAreYou(cb_conn, &interf);
+       rx_PutConnection(cb_conn);
+       cb_conn=NULL;
        H_LOCK;
        if (code == RXGEN_OPCODE) {
            identP = (struct Identity *)malloc(sizeof(struct Identity));
@@ -1096,12 +1103,15 @@ h_GetHost_r(struct rx_connection *tcon)
        h_gethostcps_r(host, FT_ApproxTime());
        if (!(host->Console & 1)) {
            int pident = 0;
+           cb_conn = host->callback_rxcon;
+           rx_GetConnection(cb_conn);
            H_UNLOCK;
            code =
-               RXAFSCB_TellMeAboutYourself(host->callback_rxcon, &interf,
-                                           &caps);
+               RXAFSCB_TellMeAboutYourself(cb_conn, &interf, &caps);
            if (code == RXGEN_OPCODE)
-               code = RXAFSCB_WhoAreYou(host->callback_rxcon, &interf);
+               code = RXAFSCB_WhoAreYou(cb_conn, &interf);
+           rx_PutConnection(cb_conn);
+           cb_conn=NULL;
            H_LOCK;
            if (code == RXGEN_OPCODE) {
                if (!identP)
@@ -1144,8 +1154,12 @@ h_GetHost_r(struct rx_connection *tcon)
                         ntohs(host->port)));
            }
            if (code == 0 && !identP->valid) {
+               cb_conn = host->callback_rxcon;
+               rx_GetConnection(cb_conn);
                H_UNLOCK;
-               code = RXAFSCB_InitCallBackState(host->callback_rxcon);
+               code = RXAFSCB_InitCallBackState(cb_conn);
+               rx_PutConnection(cb_conn);
+               cb_conn=NULL;
                H_LOCK;
            } else if (code == 0) {
                oldHost = h_LookupUuid_r(&identP->uuid);
@@ -1170,10 +1184,14 @@ h_GetHost_r(struct rx_connection *tcon)
                } else {
                    /* This really is a new host */
                    hashInsertUuid_r(&identP->uuid, host);
+                   cb_conn = host->callback_rxcon;
+                   rx_GetConnection(cb_conn);          
                    H_UNLOCK;
                    code =
-                       RXAFSCB_InitCallBackState3(host->callback_rxcon,
+                       RXAFSCB_InitCallBackState3(cb_conn,
                                                   &FS_HostUUID);
+                   rx_PutConnection(cb_conn);
+                   cb_conn=NULL;
                    H_LOCK;
                    if (code == 0) {
                        ViceLog(25,
@@ -1544,6 +1562,9 @@ h_FindClient_r(struct rx_connection *tcon)
     oldClient = (struct client *)rx_GetSpecific(tcon, rxcon_client_key);
     if (oldClient && oldClient->tcon == tcon) {
        oldClient->tcon = (struct rx_connection *)0;
+       ViceLog(0, ("FindClient: client %x(%x) already had conn %x (host %x), stolen by client %x(%x)\n", 
+                   oldClient, oldClient->sid, tcon, 
+                   rx_HostOf(rx_PeerOf(tcon)), client, client->sid));
        /* rx_SetSpecific will be done immediately below */
     }
     client->tcon = tcon;
@@ -2038,6 +2059,7 @@ int
 CheckHost(register struct host *host, int held)
 {
     register struct client *client;
+    struct rx_connection *cb_conn = NULL;
     int code;
 
     /* Host is held by h_Enumerate */
@@ -2050,6 +2072,8 @@ CheckHost(register struct host *host, int held)
     }
     if (host->LastCall < checktime) {
        h_Lock_r(host);
+       cb_conn = host->callback_rxcon;
+       rx_GetConnection(cb_conn);
        if (!(host->hostFlags & HOSTDELETED)) {
            if (host->LastCall < clientdeletetime) {
                host->hostFlags |= HOSTDELETED;
@@ -2058,13 +2082,13 @@ CheckHost(register struct host *host, int held)
                    if (host->interface) {
                        H_UNLOCK;
                        code =
-                           RXAFSCB_InitCallBackState3(host->callback_rxcon,
+                           RXAFSCB_InitCallBackState3(cb_conn,
                                                       &FS_HostUUID);
                        H_LOCK;
                    } else {
                        H_UNLOCK;
                        code =
-                           RXAFSCB_InitCallBackState(host->callback_rxcon);
+                           RXAFSCB_InitCallBackState(cb_conn);
                        H_LOCK;
                    }
                    host->hostFlags |= ALTADDR; /* alternate addresses valid */
@@ -2088,7 +2112,7 @@ CheckHost(register struct host *host, int held)
                    if (host->interface) {
                        afsUUID uuid = host->interface->uuid;
                        H_UNLOCK;
-                       code = RXAFSCB_ProbeUuid(host->callback_rxcon, &uuid);
+                       code = RXAFSCB_ProbeUuid(cb_conn, &uuid);
                        H_LOCK;
                        if (code) {
                            if (MultiProbeAlternateAddress_r(host)) {
@@ -2102,7 +2126,7 @@ CheckHost(register struct host *host, int held)
                        }
                    } else {
                        H_UNLOCK;
-                       code = RXAFSCB_Probe(host->callback_rxcon);
+                       code = RXAFSCB_Probe(cb_conn);
                        H_LOCK;
                        if (code) {
                            char hoststr[16];
@@ -2116,6 +2140,10 @@ CheckHost(register struct host *host, int held)
                }
            }
        }
+       H_UNLOCK;
+       rx_PutConnection(cb_conn);
+       cb_conn=NULL;
+       H_LOCK;
        h_Unlock_r(host);
     }
     H_UNLOCK;