]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
ctdb-mutex: Add an intermediate asynchronous computation for waiting
authorMartin Schwenke <martin@meltin.net>
Thu, 27 Jun 2019 04:13:50 +0000 (14:13 +1000)
committerMartin Schwenke <martins@samba.org>
Fri, 26 Jul 2019 03:34:17 +0000 (03:34 +0000)
This will allow more conditions to be waited on via additional
sub-requests.  At the moment this just completes when the parent wait
completes.

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

index 85095c64c719306b22d28eba5533b250e6ff468d..bfd78565c6a2af3c068064bcd783e5c7415207a8 100644 (file)
@@ -157,6 +157,63 @@ static bool wait_for_parent_recv(struct tevent_req *req)
        return true;
 }
 
+/*
+ * Wait for a reason to exit, indicating that the lock is lost
+ */
+
+struct wait_for_exit_state {
+};
+
+static void wait_for_exit_parent_done(struct tevent_req *subreq);
+
+static struct tevent_req *wait_for_exit_send(TALLOC_CTX *mem_ctx,
+                                            struct tevent_context *ev,
+                                            pid_t ppid)
+{
+       struct tevent_req *req, *subreq;
+       struct wait_for_exit_state *state;
+
+       req = tevent_req_create(mem_ctx, &state, struct wait_for_exit_state);
+       if (req == NULL) {
+               return NULL;
+       }
+
+       subreq = wait_for_parent_send(state, ev, ppid);
+       if (tevent_req_nomem(subreq, req)) {
+               return tevent_req_post(req, ev);
+       }
+       tevent_req_set_callback(subreq, wait_for_exit_parent_done, req);
+
+       return req;
+}
+
+static void wait_for_exit_parent_done(struct tevent_req *subreq)
+{
+       struct tevent_req *req = tevent_req_callback_data(
+               subreq, struct tevent_req);
+       bool status;
+
+       status = wait_for_parent_recv(subreq);
+       TALLOC_FREE(subreq);
+       if (! status) {
+               /* Ignore error */
+               fprintf(stderr,
+                       "ctdb_mutex_fcntl_helper: "
+                       "wait_for_parent_recv() failed\n");
+       }
+
+       tevent_req_done(req);
+}
+
+static bool wait_for_exit_recv(struct tevent_req *req)
+{
+       if (tevent_req_is_unix_error(req, NULL)) {
+               return false;
+       }
+
+       return true;
+}
+
 int main(int argc, char *argv[])
 {
        struct tevent_context *ev;
@@ -191,20 +248,20 @@ int main(int argc, char *argv[])
                return 0;
        }
 
-       req = wait_for_parent_send(ev, ev, ppid);
+       req = wait_for_exit_send(ev, ev, ppid);
        if (req == NULL) {
                fprintf(stderr,
-                       "%s: wait_for_parent_send() failed\n",
+                       "%s: wait_for_exit_send() failed\n",
                        progname);
                exit(1);
        }
 
        tevent_req_poll(req, ev);
 
-       status = wait_for_parent_recv(req);
+       status = wait_for_exit_recv(req);
        if (! status) {
                fprintf(stderr,
-                       "%s: wait_for_parent_recv() failed\n",
+                       "%s: wait_for_exit_recv() failed\n",
                        progname);
        }