newuuid-20070612
[openafs.git] / src / afs / afs_server.c
index 8b594a1..90fbd11 100644 (file)
@@ -488,6 +488,42 @@ afs_CountServers(void)
 }                              /*afs_CountServers */
 
 
+void
+ForceAllNewConnections()
+{
+    int srvAddrCount;
+    struct srvAddr **addrs;
+    struct srvAddr *sa;
+    afs_int32 i, j;
+
+    ObtainReadLock(&afs_xserver);      /* Necessary? */
+    ObtainReadLock(&afs_xsrvAddr);
+
+    srvAddrCount = 0;
+    for (i = 0; i < NSERVERS; i++) {
+       for (sa = afs_srvAddrs[i]; sa; sa = sa->next_bkt) {
+           srvAddrCount++;
+       }
+    }
+
+    addrs = afs_osi_Alloc(srvAddrCount * sizeof(*addrs));
+    j = 0;
+    for (i = 0; i < NSERVERS; i++) {
+       for (sa = afs_srvAddrs[i]; sa; sa = sa->next_bkt) {
+           if (j >= srvAddrCount)
+               break;
+           addrs[j++] = sa;
+       }
+    }
+
+    ReleaseReadLock(&afs_xsrvAddr);
+    ReleaseReadLock(&afs_xserver);
+    for (i = 0; i < j; i++) {
+        sa = addrs[i];
+       ForceNewConnections(sa);
+    }
+}
+
 /* check down servers (if adown), or running servers (if !adown) */
 void
 afs_CheckServers(int adown, struct cell *acellp)
@@ -499,7 +535,6 @@ afs_CheckServers(int adown, struct cell *acellp)
     afs_int32 i, j;
     afs_int32 code;
     afs_int32 start, end = 0, delta;
-    afs_int32 m_error;
     osi_timeval_t tv;
     struct unixuser *tu;
     char tbuffer[CVBS];
@@ -508,7 +543,7 @@ afs_CheckServers(int adown, struct cell *acellp)
     struct conn **conns;
     int nconns;
     struct rx_connection **rxconns;      
-    afs_int32 *conntimer, *deltas;
+    afs_int32 *conntimer, *deltas, *results;
 
     AFS_STATCNT(afs_CheckServers);
 
@@ -546,6 +581,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;
@@ -603,10 +639,10 @@ afs_CheckServers(int adown, struct cell *acellp)
        multi_RXAFS_GetTime(&tv.tv_sec, &tv.tv_usec);
        tc = conns[multi_i];
        sa = tc->srvr;
-       if (conntimer[multi_i] == 0)
+       if (conntimer[multi_i] == 1)
          rx_SetConnDeadTime(tc->id, afs_rx_deadtime);
        end = osi_Time();
-       m_error=multi_error;
+       results[multi_i]=multi_error;
        if ((start == end) && !multi_error)
          deltas[multi_i] = end - tv.tv_sec;
        
@@ -617,7 +653,7 @@ afs_CheckServers(int adown, struct cell *acellp)
       tc = conns[i];
       sa = tc->srvr;
       
-      if (( m_error >= 0 ) && (sa->sa_flags & SRVADDR_ISDOWN) && (tc->srvr == sa)) {
+      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);
        
@@ -631,7 +667,7 @@ afs_CheckServers(int adown, struct cell *acellp)
          afs_osi_Wakeup(&afs_waitForever);
        }
       } else {
-       if (m_error < 0) {
+       if (results[i] < 0) {
          /* server crashed */
          afs_ServerDown(sa);
          ForceNewConnections(sa);  /* multi homed clients */
@@ -713,6 +749,7 @@ 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*/
 
@@ -1138,24 +1175,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;
@@ -1174,20 +1230,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)
+    if ((ifnet_flags(ifaddr_ifnet(ifa)) & IFF_POINTOPOINT)
        && (myDstaddr == serverAddr)) {
-       if (ifa->ia_ifp->if_metric >= (MAXDEFRANK - MED) / PPWEIGHT)
+       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;
        }
@@ -1360,6 +1416,27 @@ 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;
+       unsigned int count;
+       int cnt=0, m, j;
+       ifaddr_t *ifads;
+       ifnet_t *ifn;
+
+       if (!ifnet_list_get(AF_INET, &ifn, &count)) {
+           for (m = 0; m < count; m++) {
+               if (!ifnet_get_address_list(ifn[m], &ifads)) {
+                   for (j = 0; ifads[j] != NULL && cnt < ADDRSPERSITE; j++) {
+                       afsi_SetServerIPRank(sa, ifads[j]);
+                       cnt++;
+                   }
+                   ifnet_free_address_list(ifads);
+               }
+           }
+           ifnet_list_free(ifn);
+       }
+    }
 #elif defined(AFS_DARWIN60_ENV)
     {
        struct ifnet *ifn;
@@ -1620,11 +1697,7 @@ struct server *afs_GetServer(afs_uint32 * aserverp, afs_int32 nservers,
 
        /* Compute preference values and resort */
        if (!newsa->sa_iprank) {
-           if (aport == fsport) {
-               afs_SetServerPrefs(newsa);      /* new fileserver rank */
-           } else {
-               newsa->sa_iprank = 10000 + afs_randomMod127();  /* new vlserver rank */
-           }
+           afs_SetServerPrefs(newsa);  /* new server rank */
        }
     }
     afs_SortOneServer(newts);  /* Sort by rank */