#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>
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)
/* 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) {
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 {
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
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;
}
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 */
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
*/
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;
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;
+}