Get a count of the number of workers for all servers that are still
processing a job.
Signed-off-by: John Ferlan <jferlan(a)redhat.com>
---
src/libvirt_remote.syms | 1 +
src/rpc/virnetserver.c | 26 ++++++++++++++++++++++++++
src/rpc/virnetserver.h | 2 ++
3 files changed, 29 insertions(+)
diff --git a/src/libvirt_remote.syms b/src/libvirt_remote.syms
index 9ee983fdf2..a8f937f32e 100644
--- a/src/libvirt_remote.syms
+++ b/src/libvirt_remote.syms
@@ -136,6 +136,7 @@ virNetServerSetThreadPoolParameters;
virNetServerSetTLSContext;
virNetServerStart;
virNetServerUpdateServices;
+virNetServerWorkerCount;
# rpc/virnetserverclient.h
diff --git a/src/rpc/virnetserver.c b/src/rpc/virnetserver.c
index c426567d86..053ef8a5ab 100644
--- a/src/rpc/virnetserver.c
+++ b/src/rpc/virnetserver.c
@@ -842,6 +842,32 @@ virNetServerQuitRequested(virNetServerPtr srv)
}
+/* virNetServerWorkerCount:
+ * @srv: Netserver pointer
+ *
+ * Return the number of workers still waiting to be processed. This
+ * allows the quit requested code to wait for all worker jobs to be
+ * completed before actually quitting.
+ */
+size_t
+virNetServerWorkerCount(virNetServerPtr srv)
+{
+ size_t workerCount;
+
+ virObjectLock(srv);
+
+ workerCount = virThreadPoolGetCurrentWorkers(srv->workers) +
+ virThreadPoolGetPriorityWorkers(srv->workers);
+
+ if (workerCount > 0)
+ VIR_DEBUG("server '%s' still has %zd workers", srv->name,
workerCount);
+
+ virObjectUnlock(srv);
+
+ return workerCount;
+}
+
+
void virNetServerClose(virNetServerPtr srv)
{
size_t i;
diff --git a/src/rpc/virnetserver.h b/src/rpc/virnetserver.h
index fcaf48fe14..3b2582e15b 100644
--- a/src/rpc/virnetserver.h
+++ b/src/rpc/virnetserver.h
@@ -60,6 +60,8 @@ virNetServerPtr virNetServerNewPostExecRestart(virJSONValuePtr object,
void virNetServerQuitRequested(virNetServerPtr srv);
+size_t virNetServerWorkerCount(virNetServerPtr srv);
+
void virNetServerClose(virNetServerPtr srv);
virJSONValuePtr virNetServerPreExecRestart(virNetServerPtr srv);
--
2.17.1