From 7558592d15fa4911fa8d2061aa56e2b151f516a2 Mon Sep 17 00:00:00 2001 From: Amitay Isaacs Date: Fri, 17 Nov 2017 12:36:29 +1100 Subject: ctdb-common: Add async version of startup in sock_daemon Signed-off-by: Amitay Isaacs Reviewed-by: Martin Schwenke --- ctdb/common/sock_daemon.c | 40 ++++++++++++++++++++++++++++ ctdb/common/sock_daemon.h | 8 ++++++ ctdb/tests/cunit/sock_daemon_test_001.sh | 2 ++ ctdb/tests/src/sock_daemon_test.c | 45 ++++++++++++++++++++++++++++++++ 4 files changed, 95 insertions(+) (limited to 'ctdb') diff --git a/ctdb/common/sock_daemon.c b/ctdb/common/sock_daemon.c index 0ef01666883..6b05e2462f9 100644 --- a/ctdb/common/sock_daemon.c +++ b/ctdb/common/sock_daemon.c @@ -527,6 +527,7 @@ struct sock_daemon_run_state { }; static void sock_daemon_run_started(struct tevent_req *subreq); +static void sock_daemon_run_startup_done(struct tevent_req *subreq); static void sock_daemon_run_signal_handler(struct tevent_context *ev, struct tevent_signal *se, int signum, int count, void *siginfo, @@ -634,6 +635,18 @@ static void sock_daemon_run_started(struct tevent_req *subreq) D_NOTICE("daemon started, pid=%u\n", getpid()); + if (sockd->funcs != NULL && sockd->funcs->startup_send != NULL && + sockd->funcs->startup_recv != NULL) { + subreq = sockd->funcs->startup_send(state, state->ev, + sockd->private_data); + if (tevent_req_nomem(subreq, req)) { + return; + } + tevent_req_set_callback(subreq, sock_daemon_run_startup_done, + req); + return; + } + if (sockd->funcs != NULL && sockd->funcs->startup != NULL) { int ret; @@ -654,6 +667,33 @@ static void sock_daemon_run_started(struct tevent_req *subreq) sock_daemon_run_wait(req); } +static void sock_daemon_run_startup_done(struct tevent_req *subreq) +{ + struct tevent_req *req = tevent_req_callback_data( + subreq, struct tevent_req); + struct sock_daemon_run_state *state = tevent_req_data( + req, struct sock_daemon_run_state); + struct sock_daemon_context *sockd = state->sockd; + int ret; + bool status; + + status = sockd->funcs->startup_recv(subreq, &ret); + TALLOC_FREE(subreq); + if (! status) { + D_ERR("startup failed, ret=%d\n", ret); + tevent_req_error(req, EIO); + return; + } + + D_NOTICE("startup completed succesfully\n"); + + status = sock_daemon_run_socket_listen(req); + if (! status) { + return; + } + sock_daemon_run_wait(req); +} + static void sock_daemon_run_signal_handler(struct tevent_context *ev, struct tevent_signal *se, int signum, int count, void *siginfo, diff --git a/ctdb/common/sock_daemon.h b/ctdb/common/sock_daemon.h index 190a4ef172f..7f19b32dcd4 100644 --- a/ctdb/common/sock_daemon.h +++ b/ctdb/common/sock_daemon.h @@ -52,6 +52,8 @@ struct sock_client_context; * startup() should return 0 for success, non-zero value on failure * On failure, sock_daemon_run() will return error. * + * startup_send()/startup_recv() is the async version of startup() + * * reconfigure() is called when the daemon receives SIGUSR1 or SIGHUP * reconfigure() should return 0 for success, non-zero value on failure * On failure, sock_daemon_run() will continue to run. @@ -67,6 +69,12 @@ struct sock_client_context; */ struct sock_daemon_funcs { int (*startup)(void *private_data); + + struct tevent_req * (*startup_send)(TALLOC_CTX *mem_ctx, + struct tevent_context *ev, + void *private_data); + bool (*startup_recv)(struct tevent_req *req, int *perr); + int (*reconfigure)(void *private_data); void (*shutdown)(void *private_data); diff --git a/ctdb/tests/cunit/sock_daemon_test_001.sh b/ctdb/tests/cunit/sock_daemon_test_001.sh index bf925fbe2ab..aa1d6b471db 100755 --- a/ctdb/tests/cunit/sock_daemon_test_001.sh +++ b/ctdb/tests/cunit/sock_daemon_test_001.sh @@ -26,6 +26,8 @@ ok <