Define updateUbikNetworkAddress static
[openafs.git] / src / ubik / beacon.c
index 9d836d1..ee68a9e 100644 (file)
 #include <afsconfig.h>
 #include <afs/param.h>
 
-RCSID
-    ("$Header$");
 
 #include <sys/types.h>
+#include <string.h>
+#include <stdarg.h>
+#include <errno.h>
+
 #ifdef AFS_NT40_ENV
 #include <winsock2.h>
 #include <time.h>
@@ -24,15 +26,8 @@ RCSID
 #include <netinet/in.h>
 #include <netdb.h>
 #endif
-#include <errno.h>
+
 #include <lock.h>
-#ifdef HAVE_STRING_H
-#include <string.h>
-#else
-#ifdef HAVE_STRINGS_H
-#include <strings.h>
-#endif
-#endif
 #include <rx/xdr.h>
 #include <rx/rx.h>
 #include <rx/rx_multi.h>
@@ -46,21 +41,30 @@ RCSID
 #include "ubik.h"
 #include "ubik_int.h"
 
-/* statics used to determine if we're the sync site */
-static afs_int32 syncSiteUntil = 0;    /* valid only if amSyncSite */
-int ubik_amSyncSite = 0;       /* flag telling if I'm sync site */
-static nServers;               /* total number of servers */
-static char amIMagic = 0;      /* is this host the magic host */
-char amIClone = 0;             /* is this a clone which doesn't vote */
+/*! \name statics used to determine if we're the sync site */
+static afs_int32 syncSiteUntil = 0;    /*!< valid only if amSyncSite */
+int ubik_amSyncSite = 0;       /*!< flag telling if I'm sync site */
+static int nServers;           /*!< total number of servers */
+static char amIMagic = 0;      /*!< is this host the magic host */
+char amIClone = 0;             /*!< is this a clone which doesn't vote */
 static char ubik_singleServer = 0;
-int (*ubik_CRXSecurityProc) ();
-char *ubik_CRXSecurityRock;
+/*\}*/
+int (*ubik_CRXSecurityProc) (void *rock, struct rx_securityClass **,
+                            afs_int32 *);
+void *ubik_CRXSecurityRock;
 afs_int32 ubikSecIndex;
 struct rx_securityClass *ubikSecClass;
-static verifyInterfaceAddress();
+static int ubeacon_InitServerListCommon(afs_int32 ame,
+                                       struct afsconf_cell *info,
+                                       char clones[],
+                                       afs_int32 aservers[]);
+static int verifyInterfaceAddress(afs_uint32 *ame, struct afsconf_cell *info,
+                                 afs_uint32 aservers[]);
+static int updateUbikNetworkAddress(afs_uint32 ubik_host[UBIK_MAX_INTERFACE_ADDR]);
 
 
-/* Module responsible for both deciding if we're currently the sync site,
+/*! \file
+ * Module responsible for both deciding if we're currently the sync site,
  * and keeping collecting votes so as to stay sync site.
  *
  * The basic module contacts all of the servers it can, trying to get them to vote
@@ -82,27 +86,33 @@ static verifyInterfaceAddress();
  * votes and decides for how long it is the synchronization site.
  */
 
-/* procedure called from debug rpc call to get this module's state for debugging */
-ubeacon_Debug(aparm)
-     register struct ubik_debug *aparm;
+/*! \brief procedure called from debug rpc call to get this module's state for debugging */
+void
+ubeacon_Debug(register struct ubik_debug *aparm)
 {
     /* fill in beacon's state fields in the ubik_debug structure */
     aparm->syncSiteUntil = syncSiteUntil;
     aparm->nServers = nServers;
 }
 
-/* procedure that determines whether this site has enough current votes to remain sync site.
- *  called from higher-level modules (everything but the vote module).
+/*!
+ * \brief Procedure that determines whether this site has enough current votes to remain sync site.
+ *
+ * Called from higher-level modules (everything but the vote module).
  *
- * If we're the sync site, check that our guarantees, obtained by the ubeacon_Interact
+ * If we're the sync site, check that our guarantees, obtained by the ubeacon_Interact()
  * light-weight process, haven't expired.  We're sync site as long as a majority of the
- * servers in existence have promised us unexpired guarantees.  The variable ubik_syncSiteUntil
+ * servers in existence have promised us unexpired guarantees.  The variable #ubik_syncSiteUntil
  * contains the time at which the latest of the majority of the sync site guarantees expires
- * (if the variable ubik_amSyncSite is true)
+ * (if the variable #ubik_amSyncSite is true)
  * This module also calls up to the recovery module if it thinks that the recovery module
- * may have to pick up a new database (which offucr sif we lose the sync site votes).
+ * may have to pick up a new database (which offucr sif [sic] we lose the sync site votes).
+ *
+ * \return 1 if local site is the sync site
+ * \return 0 if sync site is elsewhere
  */
-ubeacon_AmSyncSite()
+int
+ubeacon_AmSyncSite(void)
 {
     register afs_int32 now;
     register afs_int32 rcode;
@@ -131,25 +141,12 @@ ubeacon_AmSyncSite()
     return rcode;
 }
 
-/* setup server list; called with two parms, first is my address, second is list of other servers
- * called only at initialization to set up the list of servers to contact for votes.  Just creates
- * the server structure.  Note that there are two connections in every server structure, one for
- * vote calls (which must always go through quickly) and one for database operations, which
- * are subject to waiting for locks.  If we used only one, the votes would sometimes get
- * held up behind database operations, and the sync site guarantees would timeout
- * even though the host would be up for communication.
- *
- * The "magic" host is the one with the lowest internet address.  It is
- * magic because its vote counts epsilon more than the others.  This acts
- * as a tie-breaker when we have an even number of hosts in the system.
- * For example, if the "magic" host is up in a 2 site system, then it
- * is sync site.  Without the magic host hack, if anyone crashed in a 2
- * site system, we'd be out of business.
+/*!
+ * \see ubeacon_InitServerListCommon()
  */
-ubeacon_InitServerListByInfo(ame, info, clones)
-     afs_int32 ame;
-     struct afsconf_cell *info;
-     char clones[];
+int
+ubeacon_InitServerListByInfo(afs_int32 ame, struct afsconf_cell *info, 
+                            char clones[])
 {
     afs_int32 code;
 
@@ -157,9 +154,14 @@ ubeacon_InitServerListByInfo(ame, info, clones)
     return code;
 }
 
-ubeacon_InitServerList(ame, aservers)
-     afs_int32 ame;
-     register afs_int32 aservers[];
+/*!
+ * \param ame "address of me"
+ * \param aservers list of other servers
+ *
+ * \see ubeacon_InitServerListCommon()
+ */
+int
+ubeacon_InitServerList(afs_int32 ame, register afs_int32 aservers[])
 {
     afs_int32 code;
 
@@ -169,11 +171,34 @@ ubeacon_InitServerList(ame, aservers)
     return code;
 }
 
-ubeacon_InitServerListCommon(ame, info, clones, aservers)
-     afs_int32 ame;
-     struct afsconf_cell *info;
-     char clones[];
-     register afs_int32 aservers[];
+/*!
+ * \brief setup server list
+ *
+ * \param ame "address of me"
+ * \param aservers list of other servers
+ *
+ * called only at initialization to set up the list of servers to 
+ * contact for votes.  Just creates the server structure.  
+ *
+ * The "magic" host is the one with the lowest internet address.  It is
+ * magic because its vote counts epsilon more than the others.  This acts
+ * as a tie-breaker when we have an even number of hosts in the system.
+ * For example, if the "magic" host is up in a 2 site system, then it
+ * is sync site.  Without the magic host hack, if anyone crashed in a 2
+ * site system, we'd be out of business.
+ *
+ * \note There are two connections in every server structure, one for
+ * vote calls (which must always go through quickly) and one for database 
+ * operations, which are subject to waiting for locks.  If we used only 
+ * one, the votes would sometimes get held up behind database operations, 
+ * and the sync site guarantees would timeout even though the host would be 
+ * up for communication.
+ *
+ * \see ubeacon_InitServerList(), ubeacon_InitServerListByInfo()
+ */
+int
+ubeacon_InitServerListCommon(afs_int32 ame, struct afsconf_cell *info, 
+                            char clones[], register afs_int32 aservers[])
 {
     register struct ubik_server *ts;
     afs_int32 me = -1;
@@ -306,11 +331,14 @@ ubeacon_InitServerListCommon(ame, info, clones, aservers)
     return 0;
 }
 
-/* main lwp loop for code that sends out beacons.  This code only runs while
- * we're sync site or we want to be the sync site.  It runs in its very own light-weight
- * process.
+/*! 
+ * \brief main lwp loop for code that sends out beacons.
+ * 
+ * This code only runs while we're sync site or we want to be the sync site.
+ * It runs in its very own light-weight process.
  */
-ubeacon_Interact()
+void *
+ubeacon_Interact(void *dummy)
 {
     register afs_int32 code;
     struct timeval tt;
@@ -334,7 +362,11 @@ ubeacon_Interact()
                temp = POLLTIME;
            tt.tv_sec = temp;
            tt.tv_usec = 0;
+#ifdef AFS_PTHREAD_ENV
+           code = select(0, 0, 0, 0, &tt);
+#else
            code = IOMGR_Select(0, 0, 0, 0, &tt);
+#endif
        } else
            code = 0;
 
@@ -388,6 +420,7 @@ ubeacon_Interact()
         * Don't waste time using mult Rx calls if there are no connections out there
         */
        if (i > 0) {
+           char hoststr[16];
            multi_Rx(connections, i) {
                multi_VOTE_Beacon(syncsite, startTime, &ubik_dbase->version,
                                  &ttid);
@@ -410,19 +443,19 @@ ubeacon_Interact()
                    ts->up = 1; /* server is up (not really necessary: recovery does this for real) */
                    ts->beaconSinceDown = 1;
                    ubik_dprint("yes vote from host %s\n",
-                               afs_inet_ntoa(ts->addr[0]));
+                               afs_inet_ntoa_r(ts->addr[0], hoststr));
                } else if (code == 0) {
                    ts->lastVoteTime = temp;
                    ts->lastVote = 0;
                    ts->beaconSinceDown = 1;
                    ubik_dprint("no vote from %s\n",
-                               afs_inet_ntoa(ts->addr[0]));
+                               afs_inet_ntoa_r(ts->addr[0], hoststr));
                } else if (code < 0) {
                    ts->up = 0;
                    ts->beaconSinceDown = 0;
                    urecovery_LostServer();
                    ubik_dprint("time out from %s\n",
-                               afs_inet_ntoa(ts->addr[0]));
+                               afs_inet_ntoa_r(ts->addr[0], hoststr));
                }
            }
            multi_End;
@@ -450,7 +483,11 @@ ubeacon_Interact()
                ubik_dprint("Ubik: I am the sync site\n");
            ubik_amSyncSite = 1;
            syncSiteUntil = oldestYesVote + SMALLTIME;
-           LWP_NoYieldSignal(&ubik_amSyncSite);
+#ifndef AFS_PTHREAD_ENV
+               /* I did not find a corresponding LWP_WaitProcess(&ubik_amSyncSite) --
+                  this may be a spurious signal call -- sjenkins */
+               LWP_NoYieldSignal(&ubik_amSyncSite);
+#endif
        } else {
            if (ubik_amSyncSite)
                ubik_dprint("Ubik: I am no longer the sync site\n");
@@ -459,30 +496,32 @@ ubeacon_Interact()
        }
 
     }                          /* while loop */
+    return NULL;
 }
 
-/* 
-* Input Param   : ame is the pointer to my IP address specified in the
-*                 CellServDB file. aservers is an array containing IP 
-*                 addresses of remote ubik servers. The array is 
-*                 terminated by a zero address.
-*
-* Algorithm     : Verify that my IP addresses 'ame' does actually exist
-*                 on this machine.  If any of my IP addresses are there 
-*                 in the remote server list 'aserver', remove them from 
-*                 this list.  Update global variable ubik_host[] with 
-*                 my IP addresses.
-*
-* Return Values : 0 on success, non-zero on failure
-*/
-static
-verifyInterfaceAddress(ame, info, aservers)
-     afs_uint32 *ame;          /* one of my interface addr in net byte order */
-     struct afsconf_cell *info;
-     afs_uint32 aservers[];    /* list of all possible server addresses */
-{
+/*!
+ * \brief Verify that a given IP addresses does actually exist on this machine.
+ *
+ * \param ame      the pointer to my IP address specified in the
+ *                 CellServDB file. 
+ * \param aservers an array containing IP 
+ *                 addresses of remote ubik servers. The array is 
+ *                 terminated by a zero address.
+ *
+ * Algorithm     : Verify that my IP addresses \p ame does actually exist
+ *                 on this machine.  If any of my IP addresses are there 
+ *                 in the remote server list \p aserver, remove them from 
+ *                 this list.  Update global variable \p ubik_host[] with 
+ *                 my IP addresses.
+ *
+ * \return 0 on success, non-zero on failure
+ */
+static int
+verifyInterfaceAddress(afs_uint32 *ame, struct afsconf_cell *info,
+                      afs_uint32 aservers[]) {
     afs_uint32 myAddr[UBIK_MAX_INTERFACE_ADDR], *servList, tmpAddr;
     afs_uint32 myAddr2[UBIK_MAX_INTERFACE_ADDR];
+    char hoststr[16];
     int tcount, count, found, i, j, totalServers, start, end, usednetfiles =
        0;
 
@@ -493,10 +532,6 @@ verifyInterfaceAddress(ame, info, aservers)
            totalServers++;
     }
 
-#ifdef AFS_NT40_ENV
-       /* get all my interface addresses in net byte order */
-       count = rx_getAllAddr(myAddr, UBIK_MAX_INTERFACE_ADDR);
-#else
     if (AFSDIR_SERVER_NETRESTRICT_FILEPATH || AFSDIR_SERVER_NETINFO_FILEPATH) {
        /*
         * Find addresses we are supposed to register as per the netrestrict file
@@ -519,7 +554,6 @@ verifyInterfaceAddress(ame, info, aservers)
        /* get all my interface addresses in net byte order */
        count = rx_getAllAddr(myAddr, UBIK_MAX_INTERFACE_ADDR);
     }
-#endif
 
     if (count <= 0) {          /* no address found */
        ubik_print("ubik: No network addresses found, aborting..");
@@ -536,7 +570,7 @@ verifyInterfaceAddress(ame, info, aservers)
 
     if (!found) {
        ubik_print("ubik: primary address %s does not exist\n",
-                  afs_inet_ntoa(*ame));
+                  afs_inet_ntoa_r(*ame, hoststr));
        /* if we had the result of rx_getAllAddr already, avoid subverting
         * the "is gethostbyname(gethostname()) us" check. If we're
         * using NetInfo/NetRestrict, we assume they have enough clue
@@ -569,8 +603,7 @@ verifyInterfaceAddress(ame, info, aservers)
     for (j = 0, found = 0; j < count; j++) {
        for (i = 0; i < totalServers; i++) {
            if (info)
-               tmpAddr =
-                   ntohl((afs_uint32) info->hostAddr[i].sin_addr.s_addr);
+               tmpAddr = (afs_uint32) info->hostAddr[i].sin_addr.s_addr;
            else
                tmpAddr = aservers[i];
            if (myAddr[j] == tmpAddr) {
@@ -582,7 +615,7 @@ verifyInterfaceAddress(ame, info, aservers)
        }
     }
     if (found)
-       ubik_print("Using %s as my primary address\n", afs_inet_ntoa(*ame));
+       ubik_print("Using %s as my primary address\n", afs_inet_ntoa_r(*ame, hoststr));
 
     if (!info) {
        /* get rid of servers which were purged because all 
@@ -617,24 +650,26 @@ verifyInterfaceAddress(ame, info, aservers)
 }
 
 
-/* 
-* Input Param   : ubik_host is an array containing all my IP addresses.
-*
-* Algorithm     : Do an RPC to all remote ubik servers infroming them 
-*                 about my IP addresses. Get their IP addresses and
-*                 update my linked list of ubik servers 'ubik_servers'
-*
-* Return Values : 0 on success, non-zero on failure
-*/
-int
-updateUbikNetworkAddress(ubik_host)
-     afs_uint32 ubik_host[UBIK_MAX_INTERFACE_ADDR];
+/*! 
+ * \brief Exchange IP address information with remote servers.
+ *
+ * \param ubik_host an array containing all my IP addresses.
+ *
+ * Algorithm     : Do an RPC to all remote ubik servers infroming them 
+ *                 about my IP addresses. Get their IP addresses and
+ *                 update my linked list of ubik servers \p ubik_servers
+ *
+ * \return 0 on success, non-zero on failure
+ */
+static int
+updateUbikNetworkAddress(afs_uint32 ubik_host[UBIK_MAX_INTERFACE_ADDR])
 {
     int j, count, code = 0;
     UbikInterfaceAddr inAddr, outAddr;
     struct rx_connection *conns[MAXSERVERS];
     struct ubik_server *ts, *server[MAXSERVERS];
     char buffer[32];
+    char hoststr[16];
 
     for (count = 0, ts = ubik_servers; ts; count++, ts = ts->next) {
        conns[count] = ts->disk_rxcid;
@@ -658,9 +693,10 @@ updateUbikNetworkAddress(ubik_host)
            if (!multi_error) {
                if (ts->addr[0] != htonl(outAddr.hostAddr[0])) {
                    code = UBADHOST;
-                   strcpy(buffer, (char *)afs_inet_ntoa(ts->addr[0]));
+                   strcpy(buffer, afs_inet_ntoa_r(ts->addr[0], hoststr));
                    ubik_print("ubik:Two primary addresses for same server \
-                    %s %s\n", buffer, afs_inet_ntoa(htonl(outAddr.hostAddr[0])));
+                    %s %s\n", buffer,
+                   afs_inet_ntoa_r(htonl(outAddr.hostAddr[0]), hoststr));
                } else {
                    for (j = 1; j < UBIK_MAX_INTERFACE_ADDR; j++)
                        ts->addr[j] = htonl(outAddr.hostAddr[j]);
@@ -668,12 +704,12 @@ updateUbikNetworkAddress(ubik_host)
            } else if (multi_error == RXGEN_OPCODE) {   /* pre 3.5 remote server */
                ubik_print
                    ("ubik server %s does not support UpdateInterfaceAddr RPC\n",
-                    afs_inet_ntoa(ts->addr[0]));
+                    afs_inet_ntoa_r(ts->addr[0], hoststr));
            } else if (multi_error == UBADHOST) {
                code = UBADHOST;        /* remote CellServDB inconsistency */
                ubik_print("Inconsistent Cell Info on server: ");
                for (j = 0; j < UBIK_MAX_INTERFACE_ADDR && ts->addr[j]; j++)
-                   ubik_print("%s ", afs_inet_ntoa(ts->addr[j]));
+                   ubik_print("%s ", afs_inet_ntoa_r(ts->addr[j], hoststr));
                ubik_print("\n");
            } else {
                ts->up = 0;     /* mark the remote server as down */