]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
ctdb-recovery: Move recovery lock functions to recovery daemon code
authorMartin Schwenke <martin@meltin.net>
Wed, 17 Feb 2016 09:20:03 +0000 (20:20 +1100)
committerAmitay Isaacs <amitay@samba.org>
Thu, 28 Apr 2016 07:39:17 +0000 (09:39 +0200)
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 <martin@meltin.net>
Reviewed-by: Amitay Isaacs <amitay@gmail.com>
ctdb/include/ctdb_private.h
ctdb/server/ctdb_recover.c
ctdb/server/ctdb_recoverd.c

index edd451b2c1f106882f4b846664ad7f4facc9f8e4..f8889e025a820d2f1c7fb3c45a2c3164a8238f0e 100644 (file)
@@ -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);
index fe7e6e9cb35f86faa67dafd3a7e14f70a420fe72..e3dbb7c1ff29f3e1ec3d096792ca53b4d94198a6 100644 (file)
@@ -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
index 5d48fc3c4af51fbf370a2e27edfa64a63844649f..22eb8caf211cf5a3e4be9a7834e6fe3b862eb6f4 100644 (file)
@@ -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
 */