ubik: add uvote_HaveSyncAndVersion
[openafs.git] / src / ubik / vote.c
index b59eb62..dc313dd 100644 (file)
@@ -320,7 +320,9 @@ SVOTE_Beacon(struct rx_call * rxcall, afs_int32 astate,
        vote_globals.ubik_dbVersion = *avers;   /* resync value */
        vote_globals.ubik_dbTid = *atid;        /* transaction id, if any, of active trans */
        UBIK_VOTE_UNLOCK;
+       DBHOLD(ubik_dbase);
        urecovery_CheckTid(atid, 0);    /* check if current write trans needs aborted */
+       DBRELE(ubik_dbase);
     } else {
        UBIK_VOTE_UNLOCK;
     }
@@ -620,3 +622,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;
+}