From: Martin Schwenke Date: Wed, 17 Feb 2016 09:20:03 +0000 (+1100) Subject: ctdb-recovery: Move recovery lock functions to recovery daemon code X-Git-Tag: talloc-2.1.7~101 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=bcb838ba1e5414bb6162fdb0b30f3adc8ccef932;p=thirdparty%2Fsamba.git ctdb-recovery: Move recovery lock functions to recovery daemon code ctdb_recovery_have_lock(), ctdb_recovery_lock(), ctdb_recovery_unlock() are only used by recovery daemon, so move them there. Signed-off-by: Martin Schwenke Reviewed-by: Amitay Isaacs --- diff --git a/ctdb/include/ctdb_private.h b/ctdb/include/ctdb_private.h index edd451b2c1f..f8889e025a8 100644 --- a/ctdb/include/ctdb_private.h +++ b/ctdb/include/ctdb_private.h @@ -889,10 +889,6 @@ int32_t ctdb_control_set_recmode(struct ctdb_context *ctdb, TDB_DATA indata, bool *async_reply, const char **errormsg); -bool ctdb_recovery_have_lock(struct ctdb_context *ctdb); -bool ctdb_recovery_lock(struct ctdb_context *ctdb); -void ctdb_recovery_unlock(struct ctdb_context *ctdb); - int32_t ctdb_control_end_recovery(struct ctdb_context *ctdb, struct ctdb_req_control_old *c, bool *async_reply); diff --git a/ctdb/server/ctdb_recover.c b/ctdb/server/ctdb_recover.c index fe7e6e9cb35..e3dbb7c1ff2 100644 --- a/ctdb/server/ctdb_recover.c +++ b/ctdb/server/ctdb_recover.c @@ -927,78 +927,6 @@ int32_t ctdb_control_set_recmode(struct ctdb_context *ctdb, } -bool ctdb_recovery_have_lock(struct ctdb_context *ctdb) -{ - return (ctdb->recovery_lock_handle != NULL); -} - -struct hold_reclock_state { - bool done; - char status; -}; - -static void hold_reclock_handler(struct ctdb_context *ctdb, - char status, - double latency, - struct ctdb_cluster_mutex_handle *h, - void *private_data) -{ - struct hold_reclock_state *s = - (struct hold_reclock_state *) private_data; - - switch (status) { - case '0': - ctdb->recovery_lock_handle = h; - break; - - case '1': - DEBUG(DEBUG_ERR, - ("Unable to take recovery lock - contention\n")); - talloc_free(h); - break; - - default: - DEBUG(DEBUG_ERR, ("ERROR: when taking recovery lock\n")); - talloc_free(h); - } - - s->done = true; - s->status = status; -} - -bool ctdb_recovery_lock(struct ctdb_context *ctdb) -{ - struct ctdb_cluster_mutex_handle *h; - struct hold_reclock_state s = { - .done = false, - .status = '0', - }; - - h = ctdb_cluster_mutex(ctdb, ctdb->recovery_lock_file, 0); - if (h == NULL) { - return -1; - } - - ctdb_cluster_mutex_set_handler(h, hold_reclock_handler, &s); - - while (!s.done) { - tevent_loop_once(ctdb->ev); - } - - /* Ensure no attempts to access to s after function return */ - ctdb_cluster_mutex_set_handler(h, hold_reclock_handler, NULL); - - return (s.status == '0'); -} - -void ctdb_recovery_unlock(struct ctdb_context *ctdb) -{ - if (ctdb->recovery_lock_handle != NULL) { - DEBUG(DEBUG_NOTICE, ("Releasing recovery lock\n")); - TALLOC_FREE(ctdb->recovery_lock_handle); - } -} - /* delete a record as part of the vacuum process only delete if we are not lmaster or dmaster, and our rsn is <= the provided rsn diff --git a/ctdb/server/ctdb_recoverd.c b/ctdb/server/ctdb_recoverd.c index 5d48fc3c4af..22eb8caf211 100644 --- a/ctdb/server/ctdb_recoverd.c +++ b/ctdb/server/ctdb_recoverd.c @@ -42,6 +42,7 @@ #include "common/common.h" #include "common/logging.h" +#include "ctdb_cluster_mutex.h" /* List of SRVID requests that need to be processed */ struct srvid_list { @@ -1535,6 +1536,78 @@ static int recover_database(struct ctdb_recoverd *rec, return 0; } +static bool ctdb_recovery_have_lock(struct ctdb_context *ctdb) +{ + return (ctdb->recovery_lock_handle != NULL); +} + +struct hold_reclock_state { + bool done; + char status; +}; + +static void hold_reclock_handler(struct ctdb_context *ctdb, + char status, + double latency, + struct ctdb_cluster_mutex_handle *h, + void *private_data) +{ + struct hold_reclock_state *s = + (struct hold_reclock_state *) private_data; + + switch (status) { + case '0': + ctdb->recovery_lock_handle = h; + break; + + case '1': + DEBUG(DEBUG_ERR, + ("Unable to take recovery lock - contention\n")); + talloc_free(h); + break; + + default: + DEBUG(DEBUG_ERR, ("ERROR: when taking recovery lock\n")); + talloc_free(h); + } + + s->done = true; + s->status = status; +} + +static bool ctdb_recovery_lock(struct ctdb_context *ctdb) +{ + struct ctdb_cluster_mutex_handle *h; + struct hold_reclock_state s = { + .done = false, + .status = '0', + }; + + h = ctdb_cluster_mutex(ctdb, ctdb->recovery_lock_file, 0); + if (h == NULL) { + return -1; + } + + ctdb_cluster_mutex_set_handler(h, hold_reclock_handler, &s); + + while (!s.done) { + tevent_loop_once(ctdb->ev); + } + + /* Ensure no attempts to access to s after function return */ + ctdb_cluster_mutex_set_handler(h, hold_reclock_handler, NULL); + + return (s.status == '0'); +} + +static void ctdb_recovery_unlock(struct ctdb_context *ctdb) +{ + if (ctdb->recovery_lock_handle != NULL) { + DEBUG(DEBUG_NOTICE, ("Releasing recovery lock\n")); + TALLOC_FREE(ctdb->recovery_lock_handle); + } +} + /* when we start a recovery, make sure all nodes use the same reclock file setting */