From: Nikolay Shirokovskiy Date: Thu, 9 Jul 2020 08:12:26 +0000 (+0300) Subject: qemu: implement driver's shutdown/shutdown wait methods X-Git-Tag: v6.8.0-rc1~275 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=399039a6b1d07610294cc810ac7a01b51ff6b5cf;p=thirdparty%2Flibvirt.git qemu: implement driver's shutdown/shutdown wait methods 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 Reviewed-by: Daniel P. Berrangé Reviewed-by: Daniel Henrique Barboza --- diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index ce72e1021d..5ae030affe 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -1090,6 +1090,36 @@ qemuStateStop(void) return ret; } + +static int +qemuStateShutdownPrepare(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: * @@ -20336,6 +20366,8 @@ static virStateDriver qemuStateDriver = { .stateCleanup = qemuStateCleanup, .stateReload = qemuStateReload, .stateStop = qemuStateStop, + .stateShutdownPrepare = qemuStateShutdownPrepare, + .stateShutdownWait = qemuStateShutdownWait, }; int qemuRegister(void)