ubik: log important messages at default log level
[openafs.git] / src / ubik / vote.c
index c89a00c..3b771f0 100644 (file)
 
 #include <roken.h>
 
+#include <afs/opr.h>
+#ifdef AFS_PTHREAD_ENV
+# include <opr/lock.h>
+#else
+# include <opr/lockstub.h>
+#endif
 #include <lock.h>
-#include <rx/xdr.h>
 #include <rx/rx.h>
 #include <afs/afsutil.h>
 
@@ -107,6 +112,10 @@ uvote_ShouldIRun(void)
     afs_int32 now;
     int code = 1; /* default to yes */
 
+    if (amIClone) {
+       return 0;               /* if we cannot be the sync-site, do not ask for votes */
+    }
+
     UBIK_VOTE_LOCK;
     now = FT_ApproxTime();
     if (BIGTIME + vote_globals.ubik_lastYesTime < now)
@@ -192,8 +201,8 @@ SVOTE_Beacon(struct rx_call * rxcall, afs_int32 astate,
        /* This is the identifier that ubik uses. */
        otherHost = ubikGetPrimaryInterfaceAddr(otherHost);
        if (!otherHost) {
-           ubik_dprint("Received beacon from unknown host %s\n",
-                       afs_inet_ntoa_r(rx_HostOf(rxp), hoststr));
+           ViceLog(5, ("Received beacon from unknown host %s\n",
+                       afs_inet_ntoa_r(rx_HostOf(rxp), hoststr)));
            return 0;           /* I don't know about you: vote no */
        }
        for (ts = ubik_servers; ts; ts = ts->next) {
@@ -201,7 +210,7 @@ SVOTE_Beacon(struct rx_call * rxcall, afs_int32 astate,
                break;
        }
        if (!ts)
-           ubik_dprint("Unknown host %x has sent a beacon\n", otherHost);
+           ViceLog(0, ("Unknown host %x has sent a beacon\n", otherHost));
        if (ts && ts->isClone)
            isClone = 1;
     } else {
@@ -209,8 +218,8 @@ SVOTE_Beacon(struct rx_call * rxcall, afs_int32 astate,
        isClone = amIClone;
     }
 
-    ubik_dprint("Received beacon type %d from host %s\n", astate,
-               afs_inet_ntoa_r(otherHost, hoststr));
+    ViceLog(5, ("Received beacon type %d from host %s\n", astate,
+               afs_inet_ntoa_r(otherHost, hoststr)));
 
     /* compute the lowest server we've heard from.  We'll try to only vote for
      * this dude if we don't already have a synchronization site.  Also, don't
@@ -260,9 +269,8 @@ SVOTE_Beacon(struct rx_call * rxcall, afs_int32 astate,
        vote_globals.syncTime = now;
     } else if (vote_globals.syncTime + BIGTIME < now) {
        if (vote_globals.syncHost) {
-           ubik_dprint
-               ("Ubik: Lost contact with sync-site %s (NOT in quorum)\n",
-                afs_inet_ntoa_r(vote_globals.syncHost, hoststr));
+           ViceLog(0, ("Ubik: Lost contact with sync-site %s (NOT in quorum)\n",
+                afs_inet_ntoa_r(vote_globals.syncHost, hoststr)));
        }
        vote_globals.syncHost = 0;
     }
@@ -307,9 +315,12 @@ SVOTE_Beacon(struct rx_call * rxcall, afs_int32 astate,
        if ((vote_globals.ubik_lastYesTime + BIGTIME < now) || (otherHost != vote_globals.lastYesHost)
            || (vote_globals.lastYesState != astate)) {
            /* A new vote or a change in the vote or changed quorum */
-           ubik_dprint("Ubik: vote 'yes' for %s %s\n",
+           /* XXX This should be at loglevel 0, but the conditionals
+            * ought to be reworked first to prevent excessive logging.
+            */
+           ViceLog(5, ("Ubik: vote 'yes' for %s %s\n",
                        afs_inet_ntoa_r(otherHost, hoststr),
-                       (astate ? "(in quorum)" : "(NOT in quorum)"));
+                       (astate ? "(in quorum)" : "(NOT in quorum)")));
        }
 
        vote = now;             /* vote yes */
@@ -543,42 +554,6 @@ SVOTE_GetSyncSite(struct rx_call * rxcall,
     return 0;
 }
 
-void
-ubik_dprint_25(const char *format, ...)
-{
-    va_list ap;
-
-    va_start(ap, format);
-    vViceLog(25, (format, ap));
-    va_end(ap);
-}
-
-void
-ubik_dprint(const char *format, ...)
-{
-    va_list ap;
-
-    va_start(ap, format);
-    vViceLog(5, (format, ap));
-    va_end(ap);
-}
-
-void
-ubik_vprint(const char *format, va_list ap)
-{
-    vViceLog(0, (format, ap));
-}
-
-void
-ubik_print(const char *format, ...)
-{
-    va_list ap;
-
-    va_start(ap, format);
-    ubik_vprint(format, ap);
-    va_end(ap);
-}
-
 /*!
  * \brief Called once/run to init the vote module
  */
@@ -590,7 +565,6 @@ uvote_Init(void)
     vote_globals.ubik_lastYesTime = FT_ApproxTime();
 
     /* Initialize globals */
-    vote_globals.ubik_lastYesTime = 0;
     vote_globals.lastYesHost = 0xffffffff;
     vote_globals.lastYesClaim = 0;
     vote_globals.lastYesState = 0;
@@ -622,3 +596,27 @@ uvote_eq_dbVersion(struct ubik_version version) {
     UBIK_VOTE_UNLOCK;
     return ret;
 }
+
+/*!
+ * \brief Check if there is a sync site and whether we have a given db version
+ *
+ * \return 1 if there is a valid sync site, and the given db version matches the sync site's
+ */
+
+int
+uvote_HaveSyncAndVersion(struct ubik_version version)
+{
+    afs_int32 now;
+    int code;
+
+    UBIK_VOTE_LOCK;
+    now = FT_ApproxTime();
+    if (!vote_globals.lastYesState || (SMALLTIME + vote_globals.lastYesClaim < now) ||
+                       vote_globals.ubik_dbVersion.epoch != version.epoch ||
+                       vote_globals.ubik_dbVersion.counter != version.counter)
+       code = 0;
+    else
+       code = 1;
+    UBIK_VOTE_UNLOCK;
+    return code;
+}