ctdb-recovery: Factor out setting of cluster mutex handler
authorMartin Schwenke <martin@meltin.net>
Wed, 17 Feb 2016 08:40:54 +0000 (19:40 +1100)
committerAmitay Isaacs <amitay@samba.org>
Thu, 28 Apr 2016 07:39:17 +0000 (09:39 +0200)
This means that the cluster mutex handle can now be treated as opaque.

Signed-off-by: Martin Schwenke <martin@meltin.net>
Reviewed-by: Amitay Isaacs <amitay@gmail.com>
ctdb/server/ctdb_recover.c

index d90174e37609b9d60f392cbb7ab3303e5ee528f4..b8f71ff537769d0f00a31049103cb80d1cdda89d 100644 (file)
@@ -768,6 +768,14 @@ struct ctdb_cluster_mutex_handle {
        struct timeval start_time;
 };
 
+static 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 set_recmode_handler(struct ctdb_context *ctdb,
                                char status,
                                double latency,
@@ -1152,9 +1160,9 @@ int32_t ctdb_control_set_recmode(struct ctdb_context *ctdb,
        }
 
        /* set_recmode_handler() frees h */
-       h->handler = set_recmode_handler;
-       h->private_data = talloc_steal(h, c);
-
+       ctdb_cluster_mutex_set_handler(h,
+                                      set_recmode_handler,
+                                      talloc_steal(h, c));
        *async_reply = true;
 
        return 0;
@@ -1213,14 +1221,14 @@ bool ctdb_recovery_lock(struct ctdb_context *ctdb)
                return -1;
        }
 
-       h->handler = hold_reclock_handler;
-       h->private_data = &s;
+       ctdb_cluster_mutex_set_handler(h, hold_reclock_handler, &s);
 
        while (!s.done) {
                tevent_loop_once(ctdb->ev);
        }
 
-       h->private_data = NULL;
+       /* Ensure no attempts to access to s after function return */
+       ctdb_cluster_mutex_set_handler(h, hold_reclock_handler, NULL);
 
        return (s.status == '0');
 }