macos104-not-yet-20050511
[openafs.git] / src / afs / afs_server.c
index 6643c1e..ed0ff1d 100644 (file)
@@ -259,8 +259,8 @@ afs_ServerDown(struct srvAddr *sa)
 
 
 /* return true if we have any callback promises from this server */
-static int
-HaveCallBacksFrom(struct server *aserver)
+int
+afs_HaveCallBacksFrom(struct server *aserver)
 {
     register afs_int32 now;
     register int i;
@@ -498,9 +498,8 @@ afs_CheckServers(int adown, struct cell *acellp)
     struct conn *tc;
     afs_int32 i, j;
     afs_int32 code;
-    afs_int32 start, end, delta;
+    afs_int32 start, end = 0, delta;
     osi_timeval_t tv;
-    int setTimer;
     struct unixuser *tu;
     char tbuffer[CVBS];
     int srvAddrCount;
@@ -508,9 +507,7 @@ afs_CheckServers(int adown, struct cell *acellp)
     struct conn **conns;
     int nconns;
     struct rx_connection **rxconns;      
-    int nrxconns;
-    afs_int32 *conntimer, *deltas;
-    XSTATS_DECLS;
+    afs_int32 *conntimer, *deltas, *results;
 
     AFS_STATCNT(afs_CheckServers);
 
@@ -548,6 +545,7 @@ afs_CheckServers(int adown, struct cell *acellp)
     rxconns = (struct rx_connection **)afs_osi_Alloc(j * sizeof(struct rx_connection *));
     conntimer = (afs_int32 *)afs_osi_Alloc(j * sizeof (afs_int32));
     deltas = (afs_int32 *)afs_osi_Alloc(j * sizeof (afs_int32));
+    results = (afs_int32 *)afs_osi_Alloc(j * sizeof (afs_int32));
 
     for (i = 0; i < j; i++) {
        deltas[i] = 0;
@@ -583,7 +581,7 @@ afs_CheckServers(int adown, struct cell *acellp)
        if (!tc)
            continue;
 
-       if ((sa->sa_flags & SRVADDR_ISDOWN) || HaveCallBacksFrom(sa->server)
+       if ((sa->sa_flags & SRVADDR_ISDOWN) || afs_HaveCallBacksFrom(sa->server)
            || (tc->srvr->server == afs_setTimeHost)) {
            conns[nconns]=tc; 
            rxconns[nconns]=tc->id;
@@ -600,40 +598,47 @@ afs_CheckServers(int adown, struct cell *acellp)
     start = osi_Time();         /* time the gettimeofday call */
     AFS_GUNLOCK(); 
     multi_Rx(rxconns,nconns)
-       {
-           tv.tv_sec = tv.tv_usec = 0;
-           multi_RXAFS_GetTime(&tv.tv_sec, &tv.tv_usec);
-           tc = conns[multi_i];
-           sa = tc->srvr;
-           if (conntimer[multi_i] == 0)
-               rx_SetConnDeadTime(tc->id, AFS_RXDEADTIME);
-           end = osi_Time();
-           if ((start == end) && !multi_error)
-               deltas[multi_i] = end - tv.tv_sec;
-           if (( multi_error >= 0 ) && (sa->sa_flags & SRVADDR_ISDOWN) && (tc->srvr == sa)) {
-               /* server back up */
-               print_internet_address("afs: file server ", sa, " is back up", 2);
-               
-                ObtainWriteLock(&afs_xserver, 244);
-                ObtainWriteLock(&afs_xsrvAddr, 245);        
-                afs_MarkServerUpOrDown(sa, 0);
-                ReleaseWriteLock(&afs_xsrvAddr);
-                ReleaseWriteLock(&afs_xserver);
-               
-               if (afs_waitForeverCount) {
-                   afs_osi_Wakeup(&afs_waitForever);
-               }
-           } else {
-               if (multi_error < 0) {
-                               /* server crashed */
-                   afs_ServerDown(sa);
-                   ForceNewConnections(sa);  /* multi homed clients */
-               }
-           }
-           
-       } multi_End;
+      {
+       tv.tv_sec = tv.tv_usec = 0;
+       multi_RXAFS_GetTime(&tv.tv_sec, &tv.tv_usec);
+       tc = conns[multi_i];
+       sa = tc->srvr;
+       if (conntimer[multi_i] == 0)
+         rx_SetConnDeadTime(tc->id, afs_rx_deadtime);
+       end = osi_Time();
+       results[multi_i]=multi_error;
+       if ((start == end) && !multi_error)
+         deltas[multi_i] = end - tv.tv_sec;
+       
+      } multi_End;
     AFS_GLOCK(); 
+    
+    for(i=0;i<nconns;i++){
+      tc = conns[i];
+      sa = tc->srvr;
+      
+      if (( results[i] >= 0 ) && (sa->sa_flags & SRVADDR_ISDOWN) && (tc->srvr == sa)) {
+       /* server back up */
+       print_internet_address("afs: file server ", sa, " is back up", 2);
+       
+       ObtainWriteLock(&afs_xserver, 244);
+       ObtainWriteLock(&afs_xsrvAddr, 245);        
+       afs_MarkServerUpOrDown(sa, 0);
+       ReleaseWriteLock(&afs_xsrvAddr);
+       ReleaseWriteLock(&afs_xserver);
+       
+       if (afs_waitForeverCount) {
+         afs_osi_Wakeup(&afs_waitForever);
+       }
+      } else {
+       if (results[i] < 0) {
+         /* server crashed */
+         afs_ServerDown(sa);
+         ForceNewConnections(sa);  /* multi homed clients */
+       }
+      }
+    }
+
     /*
      * If we're supposed to set the time, and the call worked
      * quickly (same second response) and this is the host we
@@ -708,13 +713,14 @@ afs_CheckServers(int adown, struct cell *acellp)
     afs_osi_Free(rxconns, j * sizeof(struct rx_connection *));
     afs_osi_Free(conntimer, j * sizeof(afs_int32));
     afs_osi_Free(deltas, j * sizeof(afs_int32));
+    afs_osi_Free(results, j * sizeof(afs_int32));
     
 } /*afs_CheckServers*/
 
 
 /* find a server structure given the host address */
 struct server *
-afs_FindServer(afs_int32 aserver, ushort aport, afsUUID * uuidp,
+afs_FindServer(afs_int32 aserver, afs_uint16 aport, afsUUID * uuidp,
               afs_int32 locktype)
 {
     struct server *ts;
@@ -1053,7 +1059,7 @@ typedef struct ill_s {
  * afs_uint32 subnetmask;         subnet mask of local addr in net order
  *
  */
-int
+void
 afsi_SetServerIPRank(struct srvAddr *sa, afs_int32 addr,
                     afs_uint32 subnetmask)
 {
@@ -1133,24 +1139,43 @@ afsi_SetServerIPRank(struct srvAddr *sa, struct in_ifaddr *ifa)
 void
 afsi_SetServerIPRank(sa, ifa)
      struct srvAddr *sa;
+#ifdef AFS_DARWIN80_ENV
+     ifaddr_t ifa;
+#else
      struct ifaddr *ifa;
+#endif
 {
+    struct sockaddr sout;
     struct sockaddr_in *sin;
     int t;
 
     afs_uint32 subnetmask, myAddr, myNet, myDstaddr, mySubnet, netMask;
     afs_uint32 serverAddr;
 
-    if (ifa->ifa_addr->sa_family != AF_INET)
+    if (ifaddr_address_family(ifa) != AF_INET)
        return;
-    sin = (struct sockaddr_in *)ifa->ifa_addr;
-    myAddr = ntohl(sin->sin_addr.s_addr);      /* one of my IP addr in host order */
+    t = ifaddr_address(ifa, &sout, sizeof(sout));
+    if (t == 0) {
+       sin = (struct sockaddr_in *)&sout;
+       myAddr = ntohl(sin->sin_addr.s_addr);   /* one of my IP addr in host order */
+    } else {
+       myAddr = 0;
+    }
     serverAddr = ntohl(sa->sa_ip);     /* server's IP addr in host order */
-    sin = (struct sockaddr_in *)ifa->ifa_netmask;
-    subnetmask = ntohl(sin->sin_addr.s_addr);  /* subnet mask in host order */
-    sin = (struct sockaddr_in *)ifa->ifa_dstaddr;
-    if (sin)
+    t = ifaddr_netmask(ifa, &sout, sizeof(sout));
+    if (t == 0) {
+       sin = (struct sockaddr_in *)&sout;
+       subnetmask = ntohl(sin->sin_addr.s_addr);       /* subnet mask in host order */
+    } else {
+       subnetmask = 0;
+    }
+    t = ifaddr_dstaddress(ifa, &sout, sizeof(sout));
+    if (t == 0) {
+       sin = (struct sockaddr_in *)&sout;
        myDstaddr = sin->sin_addr.s_addr;
+    } else {
+       myDstaddr = 0;
+    }
 
     if (IN_CLASSA(myAddr))
        netMask = IN_CLASSA_NET;
@@ -1169,21 +1194,20 @@ afsi_SetServerIPRank(sa, ifa)
            if (serverAddr == myAddr) { /* same machine */
                sa->sa_iprank = afs_min(sa->sa_iprank, TOPR);
            } else {            /* same subnet */
-               sa->sa_iprank = afs_min(sa->sa_iprank, HI + ifa->ifa_metric);
+               sa->sa_iprank = afs_min(sa->sa_iprank, HI + ifnet_metric(ifaddr_ifnet(ifa)));
            }
        } else {                /* same net */
-           sa->sa_iprank = afs_min(sa->sa_iprank, MED + ifa->ifa_metric);
+           sa->sa_iprank = afs_min(sa->sa_iprank, MED + ifnet_metric(ifaddr_ifnet(ifa)));
        }
     }
 #ifdef  IFF_POINTTOPOINT
     /* check for case #4 -- point-to-point link */
-    if ((ifa->ia_ifp->if_flags & IFF_POINTOPOINT)
-       && (myDstaddr == serverAddr))
-       ) {
-       if (ifa->ia_ifp->if_metric >= (MAXDEFRANK - MED) / PPWEIGHT)
+    if ((ifnet_flags(ifaddr_ifnet(ifa)) & IFF_POINTOPOINT)
+       && (myDstaddr == serverAddr)) {
+       if (ifnet_metric(ifaddr_ifnet(ifa)) >= (MAXDEFRANK - MED) / PPWEIGHT)
            t = MAXDEFRANK;
        else
-           t = MED + (PPWEIGHT << ifa->->ifa_metric);
+           t = MED + (PPWEIGHT << ifnet_metric(ifaddr_ifnet(ifa)));
        if (sa->sa_iprank > t)
            sa->sa_iprank = t;
        }
@@ -1212,16 +1236,24 @@ static int afs_SetServerPrefs(struct srvAddr *sa) {
     }
 #else                          /* AFS_USERSPACE_IP_ADDR */
 #if    defined(AFS_SUN5_ENV)
+#ifdef AFS_SUN510_ENV
+    ill_walk_context_t ctx;
+#else
     extern struct ill_s *ill_g_headp;
+    long *addr = (long *)ill_g_headp;
+#endif
     ill_t *ill;
     ipif_t *ipif;
     int subnet, subnetmask, net, netmask;
-    long *addr = (long *)ill_g_headp;
 
     if (sa)
          sa->sa_iprank = 0;
+#ifdef AFS_SUN510_ENV
+    for (ill = ILL_START_WALK_ALL(&ctx) ; ill ; ill = ill_next(&ctx, ill)) {
+#else
     for (ill = (struct ill_s *)*addr /*ill_g_headp */ ; ill;
         ill = ill->ill_next) {
+#endif
 #ifdef AFS_SUN58_ENV
        /* Make sure this is an IPv4 ILL */
        if (ill->ill_isv6)
@@ -1348,6 +1380,20 @@ static int afs_SetServerPrefs(struct srvAddr *sa) {
 #ifdef AFS_SGI62_ENV
     (void)hash_enum(&hashinfo_inaddr, afsi_enum_set_rank, HTF_INET, NULL,
                    (caddr_t) sa, NULL);
+#elif defined(AFS_DARWIN80_ENV)
+    {
+       errno_t t;
+       int cnt=0;
+       ifaddr_t *addresses, address;
+       t = ifnet_get_address_list_family(NULL, &addresses, AF_INET);
+       if (t == 0) {
+           while(addresses[cnt] != NULL) {
+               afsi_SetServerIPRank(sa, address);
+               cnt++;
+           }
+           ifnet_free_address_list(addresses);
+       }
+    }
 #elif defined(AFS_DARWIN60_ENV)
     {
        struct ifnet *ifn;