ubik: add uvote_HaveSyncAndVersion
authorMarc Dionne <marc.c.dionne@gmail.com>
Sat, 23 Apr 2011 02:23:21 +0000 (22:23 -0400)
committerDerrick Brashear <shadow@dementia.org>
Wed, 27 Apr 2011 00:37:02 +0000 (17:37 -0700)
Add a new function uvote_HaveSyncAndVersion() that combines the
logic from uvote_GetSyncSite and uvote_eq_dbVersion, without
releasing the vote lock in between.  Make use of it in
urecovery_AllBetter.

Change-Id: Ia44337da0f4335bd312cd686904f633ac19f1b63
Reviewed-on: http://gerrit.openafs.org/4526
Reviewed-by: Jeffrey Altman <jaltman@openafs.org>
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Derrick Brashear <shadow@dementia.org>

src/ubik/recovery.c
src/ubik/ubik.p.h
src/ubik/vote.c

index 5110813..6c3a8cb 100644 (file)
@@ -119,7 +119,7 @@ urecovery_AllBetter(struct ubik_dbase *adbase, int areadAny)
      * that the sync site is still the sync site, 'cause it won't talk
      * to us until a timeout period has gone by.  When we recover, we
      * leave this clear until we get a new dbase */
-    else if ((uvote_GetSyncSite() && uvote_eq_dbVersion(ubik_dbase->version))) {       /* && order is important */
+    else if (uvote_HaveSyncAndVersion(ubik_dbase->version)) {
        rcode = 1;
     }
 
index 3c53d5a..109c766 100644 (file)
@@ -566,6 +566,7 @@ extern void ubik_dprint_25(const char *format, ...)
 extern struct vote_data vote_globals;
 extern void uvote_set_dbVersion(struct ubik_version);
 extern int uvote_eq_dbVersion(struct ubik_version);
+extern int uvote_HaveSyncAndVersion(struct ubik_version);
 /*\}*/
 
 #endif /* UBIK_INTERNALS */
index c89a00c..dc313dd 100644 (file)
@@ -622,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;
+}