]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
ctdb-cluster-mutex: Register an extra handler for when mutex is lost
authorMartin Schwenke <martin@meltin.net>
Wed, 1 Jun 2016 09:05:47 +0000 (19:05 +1000)
committerMartin Schwenke <martins@samba.org>
Tue, 7 Jun 2016 22:51:29 +0000 (00:51 +0200)
Pass NULL if not needed.

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 fbeeb92fb6be1bbe7a5c858c30c7974a7bb14dac..fa70a001e811ae225b5eea6819bc0b591901f64b 100644 (file)
@@ -40,6 +40,8 @@ struct ctdb_cluster_mutex_handle {
        struct ctdb_context *ctdb;
        cluster_mutex_handler_t handler;
        void *private_data;
+       cluster_mutex_lost_handler_t lost_handler;
+       void *lost_data;
        int fd[2];
        struct tevent_timer *te;
        struct tevent_fd *fde;
@@ -94,6 +96,13 @@ static void cluster_mutex_handler(struct tevent_context *ev,
        /* Don't call the handler more than once.  It only exists to
         * process the initial response from the helper. */
        if (h->have_response) {
+               /* Only deal with EOF due to process exit.  Silently
+                * ignore any other output. */
+               if (ret == 0) {
+                       if (h->lost_handler != NULL) {
+                               h->lost_handler(h->lost_data);
+                       }
+               }
                return;
        }
        h->have_response = true;
@@ -180,7 +189,9 @@ ctdb_cluster_mutex(TALLOC_CTX *mem_ctx,
                   const char *argstring,
                   int timeout,
                   cluster_mutex_handler_t handler,
-                  void *private_data)
+                  void *private_data,
+                  cluster_mutex_lost_handler_t lost_handler,
+                  void *lost_data)
 {
        struct ctdb_cluster_mutex_handle *h;
        char **args;
@@ -264,6 +275,8 @@ ctdb_cluster_mutex(TALLOC_CTX *mem_ctx,
        h->ctdb = ctdb;
        h->handler = handler;
        h->private_data = private_data;
+       h->lost_handler = lost_handler;
+       h->lost_data = lost_data;
 
        return h;
 }
index 2f5de045e69cfeb815d51557afaa9c50467189a6..7ab00e16018af47f7acaa9da44d3f28d1d30babe 100644 (file)
@@ -36,12 +36,16 @@ typedef void (*cluster_mutex_handler_t) (
        double latency,
        void *private_data);
 
+typedef void (*cluster_mutex_lost_handler_t) (void *private_data);
+
 struct ctdb_cluster_mutex_handle *
 ctdb_cluster_mutex(TALLOC_CTX *mem_ctx,
                   struct ctdb_context *ctdb,
                   const char *argstring,
                   int timeout,
                   cluster_mutex_handler_t handler,
-                  void *private_data);
+                  void *private_data,
+                  cluster_mutex_lost_handler_t lost_handler,
+                  void *lost_data);
 
 #endif /* __CTDB_IPALLOC_H__ */
index fd44e1c75dc7b684b91e158f1deffb5bb43108a8..52734d179b80f4b75ad95f3fe9f435d534423ee4 100644 (file)
@@ -917,7 +917,7 @@ int32_t ctdb_control_set_recmode(struct ctdb_context *ctdb,
        state->c = NULL;
 
        h = ctdb_cluster_mutex(state, ctdb, ctdb->recovery_lock, 5,
-                              set_recmode_handler, state);
+                              set_recmode_handler, state, NULL, NULL);
        if (h == NULL) {
                talloc_free(state);
                return -1;
index 23d2d9ab6e76d81371eaba185c3f2479064f1eb1..34b506a27d0828f3b8c0a01ca40893b9244b6549 100644 (file)
@@ -1589,7 +1589,7 @@ static bool ctdb_recovery_lock(struct ctdb_recoverd *rec)
        };
 
        h = ctdb_cluster_mutex(rec, ctdb, ctdb->recovery_lock, 0,
-                              hold_reclock_handler, &s);
+                              hold_reclock_handler, &s, NULL, NULL);
        if (h == NULL) {
                return false;
        }