Create a helper API to disable new connections and request the worker threads to quit when a quit has been requested such as via a signal handler. Signed-off-by: John Ferlan <jferlan@xxxxxxxxxx> --- src/libvirt_remote.syms | 1 + src/rpc/virnetdaemon.c | 13 +++++++++++++ src/rpc/virnetserver.c | 24 ++++++++++++++++++++++++ src/rpc/virnetserver.h | 2 ++ 4 files changed, 40 insertions(+) diff --git a/src/libvirt_remote.syms b/src/libvirt_remote.syms index 9a33626ec6..9ee983fdf2 100644 --- a/src/libvirt_remote.syms +++ b/src/libvirt_remote.syms @@ -129,6 +129,7 @@ virNetServerNewPostExecRestart; virNetServerNextClientID; virNetServerPreExecRestart; virNetServerProcessClients; +virNetServerQuitRequested; virNetServerSetClientAuthenticated; virNetServerSetClientLimits; virNetServerSetThreadPoolParameters; diff --git a/src/rpc/virnetdaemon.c b/src/rpc/virnetdaemon.c index 31b687de12..329f116a6c 100644 --- a/src/rpc/virnetdaemon.c +++ b/src/rpc/virnetdaemon.c @@ -862,6 +862,18 @@ virNetDaemonRun(virNetDaemonPtr dmn) } +static int +daemonServerQuitRequested(void *payload, + const void *key ATTRIBUTE_UNUSED, + void *opaque ATTRIBUTE_UNUSED) +{ + virNetServerPtr srv = payload; + + virNetServerQuitRequested(srv); + return 0; +} + + void virNetDaemonQuit(virNetDaemonPtr dmn) { @@ -869,6 +881,7 @@ virNetDaemonQuit(virNetDaemonPtr dmn) VIR_DEBUG("Quit requested %p", dmn); dmn->quit = true; + virHashForEach(dmn->servers, daemonServerQuitRequested, NULL); virObjectUnlock(dmn); } diff --git a/src/rpc/virnetserver.c b/src/rpc/virnetserver.c index 5c7f7dd08f..c426567d86 100644 --- a/src/rpc/virnetserver.c +++ b/src/rpc/virnetserver.c @@ -818,6 +818,30 @@ void virNetServerDispose(void *obj) virNetServerMDNSFree(srv->mdns); } + +/* virNetServerQuitRequested: + * @srv: Netserver pointer + * + * Disable new connections and let the worker threads know that + * a quit has been requested. + */ +void +virNetServerQuitRequested(virNetServerPtr srv) +{ + size_t i; + + if (!srv) + return; + + VIR_DEBUG("Quit server requested '%s'", srv->name); + + for (i = 0; i < srv->nservices; i++) + virNetServerServiceToggle(srv->services[i], false); + + virThreadPoolQuitRequested(srv->workers); +} + + void virNetServerClose(virNetServerPtr srv) { size_t i; diff --git a/src/rpc/virnetserver.h b/src/rpc/virnetserver.h index 26cec43c22..fcaf48fe14 100644 --- a/src/rpc/virnetserver.h +++ b/src/rpc/virnetserver.h @@ -58,6 +58,8 @@ virNetServerPtr virNetServerNewPostExecRestart(virJSONValuePtr object, ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3) ATTRIBUTE_NONNULL(4) ATTRIBUTE_NONNULL(5) ATTRIBUTE_NONNULL(6); +void virNetServerQuitRequested(virNetServerPtr srv); + void virNetServerClose(virNetServerPtr srv); virJSONValuePtr virNetServerPreExecRestart(virNetServerPtr srv); -- 2.17.1 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list