[PATCH 08/10] qemu: implement driver's shutdown/shutdown wait methods

Nikolay Shirokovskiy posted 10 patches 5 years, 6 months ago
There is a newer version of this series
[PATCH 08/10] qemu: implement driver's shutdown/shutdown wait methods
Posted by Nikolay Shirokovskiy 5 years, 6 months ago
On shutdown we just stop accepting new jobs for worker thread so that on
shutdown wait we can exit worker thread faster. Yes we basically stop
processing of events for VMs but we are going to do so anyway in case of daemon
shutdown.

At the same time synchronous event processing that some API calls may require
are still possible as per VM event loop is still running and we don't need
worker thread for synchronous event processing.

Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy@virtuozzo.com>
---
 src/qemu/qemu_driver.c | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index d185666..f7ff0fb 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -1098,6 +1098,36 @@ qemuStateStop(void)
     return ret;
 }
 
+
+static int
+qemuStateShutdown(void)
+{
+    virThreadPoolStop(qemu_driver->workerPool);
+    return 0;
+}
+
+
+static int
+qemuDomainObjStopWorkerIter(virDomainObjPtr vm,
+                            void *opaque G_GNUC_UNUSED)
+{
+    virObjectLock(vm);
+    qemuDomainObjStopWorker(vm);
+    virObjectUnlock(vm);
+    return 0;
+}
+
+
+static int
+qemuStateShutdownWait(void)
+{
+    virDomainObjListForEach(qemu_driver->domains, false,
+                            qemuDomainObjStopWorkerIter, NULL);
+    virThreadPoolDrain(qemu_driver->workerPool);
+    return 0;
+}
+
+
 /**
  * qemuStateCleanup:
  *
@@ -23413,6 +23443,8 @@ static virStateDriver qemuStateDriver = {
     .stateCleanup = qemuStateCleanup,
     .stateReload = qemuStateReload,
     .stateStop = qemuStateStop,
+    .stateShutdown = qemuStateShutdown,
+    .stateShutdownWait = qemuStateShutdownWait,
 };
 
 int qemuRegister(void)
-- 
1.8.3.1

Re: [PATCH 08/10] qemu: implement driver's shutdown/shutdown wait methods
Posted by Daniel P. Berrangé 5 years, 6 months ago
On Tue, Jul 14, 2020 at 12:32:59PM +0300, Nikolay Shirokovskiy wrote:
> On shutdown we just stop accepting new jobs for worker thread so that on
> shutdown wait we can exit worker thread faster. Yes we basically stop
> processing of events for VMs but we are going to do so anyway in case of daemon
> shutdown.
> 
> At the same time synchronous event processing that some API calls may require
> are still possible as per VM event loop is still running and we don't need
> worker thread for synchronous event processing.
> 
> Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy@virtuozzo.com>
> ---
>  src/qemu/qemu_driver.c | 32 ++++++++++++++++++++++++++++++++
>  1 file changed, 32 insertions(+)
> 
> diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
> index d185666..f7ff0fb 100644
> --- a/src/qemu/qemu_driver.c
> +++ b/src/qemu/qemu_driver.c
> @@ -1098,6 +1098,36 @@ qemuStateStop(void)
>      return ret;
>  }
>  
> +
> +static int
> +qemuStateShutdown(void)
> +{
> +    virThreadPoolStop(qemu_driver->workerPool);
> +    return 0;
> +}
> +
> +
> +static int
> +qemuDomainObjStopWorkerIter(virDomainObjPtr vm,
> +                            void *opaque G_GNUC_UNUSED)
> +{
> +    virObjectLock(vm);
> +    qemuDomainObjStopWorker(vm);

My comment on the previous patch makes me slightly concerned about
this too but

Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>


Regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|