Unix CM: Log reason for marking server up or down
[openafs.git] / src / afs / afs_server.c
index 3515164..b654015 100644 (file)
@@ -230,7 +230,7 @@ afs_MarkServerUpOrDown(struct srvAddr *sa, int a_isDown)
 
 
 afs_int32
-afs_ServerDown(struct srvAddr *sa)
+afs_ServerDown(struct srvAddr *sa, int code)
 {
     struct server *aserver = sa->server;
 
@@ -240,10 +240,10 @@ afs_ServerDown(struct srvAddr *sa)
     afs_MarkServerUpOrDown(sa, SRVR_ISDOWN);
     if (sa->sa_portal == aserver->cell->vlport)
        print_internet_address
-           ("afs: Lost contact with volume location server ", sa, "", 1);
+           ("afs: Lost contact with volume location server ", sa, "", 1, code);
     else
        print_internet_address("afs: Lost contact with file server ", sa, "",
-                              1);
+                              1, code);
     return 1;
 }                              /*ServerDown */
 
@@ -309,7 +309,7 @@ CheckVLServer(struct srvAddr *sa, struct vrequest *areq)
        if (tc->parent->srvr == sa) {
            afs_MarkServerUpOrDown(sa, 0);
            print_internet_address("afs: volume location server ", sa,
-                                  " is back up", 2);
+                                  " is back up", 2, code);
        }
     }
 
@@ -530,7 +530,8 @@ CkSrv_MarkUpDown(struct afs_conn **conns, int nconns, afs_int32 *results)
        if (( results[i] >= 0 ) && (sa->sa_flags & SRVADDR_ISDOWN) &&
            (tc->parent->srvr == sa)) {
            /* server back up */
-           print_internet_address("afs: file server ", sa, " is back up", 2);
+           print_internet_address("afs: file server ", sa, " is back up", 2,
+                                  results[i]);
 
            ObtainWriteLock(&afs_xserver, 244);
            ObtainWriteLock(&afs_xsrvAddr, 245);
@@ -544,7 +545,7 @@ CkSrv_MarkUpDown(struct afs_conn **conns, int nconns, afs_int32 *results)
        } else {
            if (results[i] < 0) {
                /* server crashed */
-               afs_ServerDown(sa);
+               afs_ServerDown(sa, results[i]);
                ForceNewConnections(sa);  /* multi homed clients */
            }
        }
@@ -552,19 +553,19 @@ CkSrv_MarkUpDown(struct afs_conn **conns, int nconns, afs_int32 *results)
 }
 
 void
-CkSrv_GetCaps(struct rx_connection **rxconns, int nconns, int nservers,
-             struct afs_conn **conns, struct srvAddr **addrs)
+CkSrv_GetCaps(int nconns, struct rx_connection **rxconns,
+             struct afs_conn **conns)
 {
     Capabilities *caps;
     afs_int32 *results;
     afs_int32 i;
     struct server *ts;
 
-    caps = afs_osi_Alloc(nservers * sizeof (Capabilities));
+    caps = afs_osi_Alloc(nconns * sizeof (Capabilities));
     osi_Assert(caps != NULL);
-    memset(caps, 0, nservers * sizeof(Capabilities));
+    memset(caps, 0, nconns * sizeof(Capabilities));
 
-    results = afs_osi_Alloc(nservers * sizeof (afs_int32));
+    results = afs_osi_Alloc(nconns * sizeof (afs_int32));
     osi_Assert(results != NULL);
 
     AFS_GUNLOCK();
@@ -576,7 +577,7 @@ CkSrv_GetCaps(struct rx_connection **rxconns, int nconns, int nservers,
     AFS_GLOCK();
 
     for ( i = 0 ; i < nconns ; i++ ) {
-       ts = addrs[i]->server;
+       ts = conns[i]->parent->srvr->server;
        if ( !ts )
            continue;
        ts->capabilities = 0;
@@ -597,8 +598,8 @@ CkSrv_GetCaps(struct rx_connection **rxconns, int nconns, int nservers,
     }
     CkSrv_MarkUpDown(conns, nconns, results);
 
-    afs_osi_Free(caps, nservers * sizeof(Capabilities));
-    afs_osi_Free(results, nservers * sizeof(afs_int32));
+    afs_osi_Free(caps, nconns * sizeof(Capabilities));
+    afs_osi_Free(results, nconns * sizeof(afs_int32));
 }
 
 /* check down servers (if adown), or running servers (if !adown) */
@@ -613,12 +614,10 @@ afs_CheckServers(int adown, struct cell *acellp)
  *        AFS_LS_ALL  - check all */
 void
 afs_LoopServers(int adown, struct cell *acellp, int vlalso,
-               void (*func1) (struct rx_connection **rxconns, int nconns,
-                              int nservers, struct afs_conn **conns,
-                              struct srvAddr **addrs),
-               void (*func2) (struct rx_connection **rxconns, int nconns,
-                              int nservers, struct afs_conn **conns,
-                              struct srvAddr **addrs))
+               void (*func1) (int nservers, struct rx_connection **rxconns,
+                              struct afs_conn **conns),
+               void (*func2) (int nservers, struct rx_connection **rxconns,
+                              struct afs_conn **conns))
 {
     struct vrequest treq;
     struct server *ts;
@@ -632,7 +631,7 @@ afs_LoopServers(int adown, struct cell *acellp, int vlalso,
     struct afs_conn **conns;
     int nconns;
     struct rx_connection **rxconns;
-    afs_int32 *conntimer, *results;
+    afs_int32 *conntimer;
 
     AFS_STATCNT(afs_CheckServers);
 
@@ -680,8 +679,6 @@ afs_LoopServers(int adown, struct cell *acellp, int vlalso,
     osi_Assert(rxconns != NULL);
     conntimer = afs_osi_Alloc(j * sizeof (afs_int32));
     osi_Assert(conntimer != NULL);
-    results = afs_osi_Alloc(j * sizeof (afs_int32));
-    osi_Assert(results != NULL);
 
     for (i = 0; i < j; i++) {
        struct rx_connection *rxconn;
@@ -731,10 +728,13 @@ afs_LoopServers(int adown, struct cell *acellp, int vlalso,
        }
     } /* Outer loop over addrs */
 
-    (*func1)(rxconns, nconns, j, conns, addrs);
+    afs_osi_Free(addrs, srvAddrCount * sizeof(*addrs));
+    addrs = NULL;
+
+    (*func1)(nconns, rxconns, conns);
 
     if (func2) {
-       (*func2)(rxconns, nconns, j, conns, addrs);
+       (*func2)(nconns, rxconns, conns);
     }
 
     for (i = 0; i < nconns; i++) {
@@ -743,11 +743,9 @@ afs_LoopServers(int adown, struct cell *acellp, int vlalso,
        afs_PutConn(conns[i], rxconns[i], SHARED_LOCK);     /* done with it now */
     }
 
-    afs_osi_Free(addrs, srvAddrCount * sizeof(*addrs));
     afs_osi_Free(conns, j * sizeof(struct afs_conn *));
     afs_osi_Free(rxconns, j * sizeof(struct rx_connection *));
     afs_osi_Free(conntimer, j * sizeof(afs_int32));
-    afs_osi_Free(results, j * sizeof(afs_int32));
 
 } /*afs_CheckServers*/
 
@@ -1028,7 +1026,7 @@ afsi_SetServerIPRank(struct srvAddr *sa, afs_int32 addr,
     return;
 }
 #else /* AFS_USERSPACE_IP_ADDR */
-#if (! defined(AFS_SUN5_ENV)) && (! defined(AFS_DARWIN_ENV)) && (! defined(AFS_OBSD47_ENV)) && defined(USEIFADDR)
+#if (! defined(AFS_SUN5_ENV)) && (! defined(AFS_DARWIN_ENV)) && (! defined(AFS_OBSD47_ENV)) && (! defined(AFS_FBSD_ENV)) && defined(USEIFADDR)
 void
 afsi_SetServerIPRank(struct srvAddr *sa, struct in_ifaddr *ifa)
 {
@@ -1065,7 +1063,7 @@ afsi_SetServerIPRank(struct srvAddr *sa, struct in_ifaddr *ifa)
 #endif /* IFF_POINTTOPOINT */
 }
 #endif /*(!defined(AFS_SUN5_ENV)) && defined(USEIFADDR) */
-#if (defined(AFS_DARWIN_ENV) || defined(AFS_OBSD47_ENV)) && defined(USEIFADDR)
+#if (defined(AFS_DARWIN_ENV) || defined(AFS_OBSD47_ENV) || defined(AFS_FBSD_ENV)) && defined(USEIFADDR)
 #ifndef afs_min
 #define afs_min(A,B) ((A)<(B)) ? (A) : (B)
 #endif
@@ -1074,7 +1072,11 @@ afsi_SetServerIPRank(struct srvAddr *sa, rx_ifaddr_t ifa)
 {
     struct sockaddr sout;
     struct sockaddr_in *sin;
+#if defined(AFS_DARWIN80_ENV) && !defined(UKERNEL)
     int t;
+#else
+    void *t;
+#endif
 
     afs_uint32 subnetmask, myAddr, myNet, myDstaddr, mySubnet, netMask;
     afs_uint32 serverAddr;
@@ -1396,7 +1398,7 @@ afs_SetServerPrefs(struct srvAddr *sa)
 #else
          TAILQ_FOREACH(ifa, &in_ifaddrhead, ia_link) {
 #endif
-           afsi_SetServerIPRank(sa, ifa);
+           afsi_SetServerIPRank(sa, &ifa->ia_ifa);
     }}
 #elif defined(AFS_OBSD_ENV)
     {
@@ -1557,7 +1559,7 @@ afs_GetCapabilities(struct server *ts)
     ObtainWriteLock(&afs_xserver, 723);
     /* we forced a conn above; important we mark it down if needed */
     if ((code < 0) && (code != RXGEN_OPCODE)) {
-       afs_ServerDown(tc->parent->srvr);
+       afs_ServerDown(tc->parent->srvr, code);
        ForceNewConnections(tc->parent->srvr); /* multi homed clients */
     }
     afs_PutConn(tc, rxconn, SHARED_LOCK);