pass-pointers-for-uuid-printing-20030422
[openafs.git] / src / viced / host.c
index 36d718e..b233197 100644 (file)
@@ -499,15 +499,15 @@ h_gethostcps_r(register struct host *host, register afs_int32 now)
 void h_flushhostcps(register afs_uint32 hostaddr, register afs_uint32 hport)
 {
     register struct host *host;
-    int held;
+    int held = 0;
     
     H_LOCK
     host = h_Lookup_r(hostaddr, hport, &held);
     if (host) {
-      host->hcpsfailed = 1;
+       host->hcpsfailed = 1;
+       if (!held)
+           h_Release_r(host);
     }
-    if (!held)
-      h_Release_r(host);
     H_UNLOCK
 
     return;
@@ -943,8 +943,8 @@ retry:
     caps.Capabilities_len = 0;
 
     code = 0;
-    identP = (struct Identity *)rx_GetSpecific(tcon, rxcon_ident_key);
     host = h_Lookup_r(haddr, hport, &held);
+    identP = (struct Identity *)rx_GetSpecific(tcon, rxcon_ident_key);
     if (host && !identP && !(host->Console&1)) {
        /* This is a new connection, and we already have a host
         * structure for this address. Verify that the identity
@@ -1050,9 +1050,9 @@ retry:
        {
            char uuid1[128], uuid2[128];
            if (identP->valid)
-               afsUUID_to_string(identP->uuid, uuid1, 127);
+               afsUUID_to_string(&identP->uuid, uuid1, 127);
            if (host->interface)
-               afsUUID_to_string(host->interface->uuid, uuid2, 127);
+               afsUUID_to_string(&host->interface->uuid, uuid2, 127);
            ViceLog(0, 
                    ("CB: new identity for host %s:%d, deleting(%x %x %s %s)\n", 
                     afs_inet_ntoa_r(host->host, hoststr), ntohs(host->port), 
@@ -1069,38 +1069,49 @@ retry:
        host = h_Alloc_r(tcon); /* returned held and locked */
        h_gethostcps_r(host,FT_ApproxTime());
         if (!(host->Console&1)) {
-           if (!identP || !interfValid) {
-               H_UNLOCK
-               code = RXAFSCB_TellMeAboutYourself(host->callback_rxcon, 
-                                                  &interf, &caps);
-               if ( code == RXGEN_OPCODE ) 
-                   code = RXAFSCB_WhoAreYou(host->callback_rxcon, &interf);
-               H_LOCK
-               if ( code == RXGEN_OPCODE ) {
+           int pident = 0;
+           H_UNLOCK
+           code = RXAFSCB_TellMeAboutYourself(host->callback_rxcon, 
+                                              &interf, &caps);
+           if ( code == RXGEN_OPCODE ) 
+               code = RXAFSCB_WhoAreYou(host->callback_rxcon, &interf);
+           H_LOCK
+           if ( code == RXGEN_OPCODE ) {
+               if (!identP)
                    identP = (struct Identity *)malloc(sizeof(struct Identity));
-                   if (!identP) {
-                       ViceLog(0, ("Failed malloc in h_GetHost_r\n"));
-                       assert(0);
-                   }
-                   identP->valid = 0;
+               else
+                   pident = 1;
+
+               if (!identP) {
+                   ViceLog(0, ("Failed malloc in h_GetHost_r\n"));
+                   assert(0);
+               }
+               identP->valid = 0;
+               if (!pident)
                    rx_SetSpecific(tcon, rxcon_ident_key, identP);
-                   ViceLog(25,
-                           ("Host %s:%d does not support WhoAreYou.\n",
-                           afs_inet_ntoa_r(host->host, hoststr), ntohs(host->port)));
-                   code = 0;
-               } else if (code == 0) {
-                   interfValid = 1;
+               ViceLog(25,
+                       ("Host %s:%d does not support WhoAreYou.\n",
+                        afs_inet_ntoa_r(host->host, hoststr), 
+                        ntohs(host->port)));
+               code = 0;
+           } else if (code == 0) {
+               if (!identP)
                    identP = (struct Identity *)malloc(sizeof(struct Identity));
-                   if (!identP) {
-                       ViceLog(0, ("Failed malloc in h_GetHost_r\n"));
-                       assert(0);
-                   }
-                   identP->valid = 1;
-                   identP->uuid = interf.uuid;
-                   rx_SetSpecific(tcon, rxcon_ident_key, identP);
-                   ViceLog(25, ("WhoAreYou success on %s:%d\n",
-                               afs_inet_ntoa_r(host->host, hoststr), ntohs(host->port)));
+               else 
+                   pident = 1;
+
+               if (!identP) {
+                   ViceLog(0, ("Failed malloc in h_GetHost_r\n"));
+                   assert(0);
                }
+               identP->valid = 1;
+               interfValid = 1;
+               identP->uuid = interf.uuid;
+               if (!pident)
+                   rx_SetSpecific(tcon, rxcon_ident_key, identP);
+               ViceLog(25, ("WhoAreYou success on %s:%d\n",
+                            afs_inet_ntoa_r(host->host, hoststr), 
+                            ntohs(host->port)));
            }
            if (code == 0 && !identP->valid) {
                H_UNLOCK
@@ -1509,6 +1520,19 @@ int GetClient(struct rx_connection * tcon, struct client **cp)
     H_LOCK
 
     *cp = client = (struct client *) rx_GetSpecific(tcon, rxcon_client_key);
+    if (client == NULL || client->tcon == NULL) {
+       ViceLog(0, ("GetClient: no client in conn %x (host %x), VBUSYING\n", 
+                   tcon, rx_HostOf(rx_PeerOf(tcon))));
+       H_UNLOCK
+       return VBUSY;
+    }
+    if (rxr_CidOf(client->tcon) != client->sid) {
+       ViceLog(0, ("GetClient: tcon %x tcon sid %d client sid %d\n",
+                   client->tcon, rxr_CidOf(client->tcon),
+                   client->sid));
+       H_UNLOCK
+       return VBUSY;
+    }
     if (!(client && client->tcon && rxr_CidOf(client->tcon) == client->sid)) {
        if (!client)
            ViceLog(0, ("GetClient: no client in conn %x\n", tcon));