ctdb-cluster-mutex: ctdb_cluster_mutex() registers handler and private data
authorMartin Schwenke <martin@meltin.net>
Wed, 1 Jun 2016 08:56:33 +0000 (18:56 +1000)
committerMartin Schwenke <martins@samba.org>
Tue, 7 Jun 2016 22:51:29 +0000 (00:51 +0200)
Signed-off-by: Martin Schwenke <martin@meltin.net>
Reviewed-by: Amitay Isaacs <amitay@gmail.com>
ctdb/server/ctdb_cluster_mutex.c
ctdb/server/ctdb_cluster_mutex.h
ctdb/server/ctdb_recover.c
ctdb/server/ctdb_recoverd.c

index cef64166aa869f579a1ee5c4e08bed804bdd6dea..fbeeb92fb6be1bbe7a5c858c30c7974a7bb14dac 100644 (file)
@@ -48,14 +48,6 @@ struct ctdb_cluster_mutex_handle {
        bool have_response;
 };
 
-void ctdb_cluster_mutex_set_handler(struct ctdb_cluster_mutex_handle *h,
-                                   cluster_mutex_handler_t handler,
-                                   void *private_data)
-{
-       h->handler = handler;
-       h->private_data = private_data;
-}
-
 static void cluster_mutex_timeout(struct tevent_context *ev,
                                  struct tevent_timer *te,
                                  struct timeval t, void *private_data)
@@ -186,7 +178,9 @@ struct ctdb_cluster_mutex_handle *
 ctdb_cluster_mutex(TALLOC_CTX *mem_ctx,
                   struct ctdb_context *ctdb,
                   const char *argstring,
-                  int timeout)
+                  int timeout,
+                  cluster_mutex_handler_t handler,
+                  void *private_data)
 {
        struct ctdb_cluster_mutex_handle *h;
        char **args;
@@ -268,8 +262,8 @@ ctdb_cluster_mutex(TALLOC_CTX *mem_ctx,
        tevent_fd_set_auto_close(h->fde);
 
        h->ctdb = ctdb;
-       h->handler = NULL;
-       h->private_data = NULL;
+       h->handler = handler;
+       h->private_data = private_data;
 
        return h;
 }
index efe089261bd0a3e1a7844fb5b07d9372523c3b24..2f5de045e69cfeb815d51557afaa9c50467189a6 100644 (file)
@@ -36,14 +36,12 @@ typedef void (*cluster_mutex_handler_t) (
        double latency,
        void *private_data);
 
-void ctdb_cluster_mutex_set_handler(struct ctdb_cluster_mutex_handle *h,
-                                   cluster_mutex_handler_t handler,
-                                   void *private_data);
-
 struct ctdb_cluster_mutex_handle *
 ctdb_cluster_mutex(TALLOC_CTX *mem_ctx,
                   struct ctdb_context *ctdb,
                   const char *argstring,
-                  int timeout);
+                  int timeout,
+                  cluster_mutex_handler_t handler,
+                  void *private_data);
 
 #endif /* __CTDB_IPALLOC_H__ */
index 1742e34bb268593cb7940e00af63ae8939f4b06e..fd44e1c75dc7b684b91e158f1deffb5bb43108a8 100644 (file)
@@ -916,18 +916,14 @@ int32_t ctdb_control_set_recmode(struct ctdb_context *ctdb,
        state->ctdb = ctdb;
        state->c = NULL;
 
-       h = ctdb_cluster_mutex(state, ctdb, ctdb->recovery_lock, 5);
+       h = ctdb_cluster_mutex(state, ctdb, ctdb->recovery_lock, 5,
+                              set_recmode_handler, state);
        if (h == NULL) {
                talloc_free(state);
                return -1;
        }
 
        state->c = talloc_steal(state, c);
-
-       /* set_recmode_handler() frees state/h */
-       ctdb_cluster_mutex_set_handler(h,
-                                      set_recmode_handler,
-                                      state);
        *async_reply = true;
 
        return 0;
index f22a11b3afe1635aa89e7a5fa12f3e345cd64c17..23d2d9ab6e76d81371eaba185c3f2479064f1eb1 100644 (file)
@@ -1588,13 +1588,12 @@ static bool ctdb_recovery_lock(struct ctdb_recoverd *rec)
                .latency = 0,
        };
 
-       h = ctdb_cluster_mutex(rec, ctdb, ctdb->recovery_lock, 0);
+       h = ctdb_cluster_mutex(rec, ctdb, ctdb->recovery_lock, 0,
+                              hold_reclock_handler, &s);
        if (h == NULL) {
                return false;
        }
 
-       ctdb_cluster_mutex_set_handler(h, hold_reclock_handler, &s);
-
        while (!s.done) {
                tevent_loop_once(ctdb->ev);
        }