From e9ac2cdf0125b802f4de4fffa1863a5b557dc807 Mon Sep 17 00:00:00 2001 From: Marc Dionne Date: Fri, 22 Apr 2011 22:23:21 -0400 Subject: [PATCH] ubik: add uvote_HaveSyncAndVersion 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 Tested-by: BuildBot Reviewed-by: Derrick Brashear --- src/ubik/recovery.c | 2 +- src/ubik/ubik.p.h | 1 + src/ubik/vote.c | 24 ++++++++++++++++++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/ubik/recovery.c b/src/ubik/recovery.c index 511081322..6c3a8cb88 100644 --- a/src/ubik/recovery.c +++ b/src/ubik/recovery.c @@ -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; } diff --git a/src/ubik/ubik.p.h b/src/ubik/ubik.p.h index 3c53d5a25..109c766a4 100644 --- a/src/ubik/ubik.p.h +++ b/src/ubik/ubik.p.h @@ -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 */ diff --git a/src/ubik/vote.c b/src/ubik/vote.c index c89a00c3b..dc313dd0f 100644 --- a/src/ubik/vote.c +++ b/src/ubik/vote.c @@ -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; +} -- 2.39.5