[libvirt PATCH] qemu: Avoid segfault when driver initialization fails

In case qemuStateInitialize fails for any reason (e.g., a typo in qemu.conf), it properly cleans up after itself and sets qemu_driver back to NULL. A tiny bit later the daemon asks all drivers to shutdown by calling their stateShutdown* APIs. But the implementation of these APIs in QEMU driver expected qemu_driver to be initialized at this point causing a segfault otherwise. Signed-off-by: Jiri Denemark <jdenemar@redhat.com> --- src/qemu/qemu_driver.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index ed966cf7e3..a68ebe5259 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -1075,6 +1075,9 @@ qemuStateStop(void) static int qemuStateShutdownPrepare(void) { + if (!qemu_driver) + return 0; + virThreadPoolStop(qemu_driver->workerPool); return 0; } @@ -1094,6 +1097,9 @@ qemuDomainObjStopWorkerIter(virDomainObjPtr vm, static int qemuStateShutdownWait(void) { + if (!qemu_driver) + return 0; + virDomainObjListForEach(qemu_driver->domains, false, qemuDomainObjStopWorkerIter, NULL); virThreadPoolDrain(qemu_driver->workerPool); -- 2.30.0

On 1/26/21 5:08 PM, Jiri Denemark wrote:
In case qemuStateInitialize fails for any reason (e.g., a typo in qemu.conf), it properly cleans up after itself and sets qemu_driver back to NULL. A tiny bit later the daemon asks all drivers to shutdown by calling their stateShutdown* APIs. But the implementation of these APIs in QEMU driver expected qemu_driver to be initialized at this point causing a segfault otherwise.
Signed-off-by: Jiri Denemark <jdenemar@redhat.com> --- src/qemu/qemu_driver.c | 6 ++++++ 1 file changed, 6 insertions(+)
This patch looks familiar :-) https://www.redhat.com/archives/libvir-list/2021-January/msg00955.html I'm working on alternative approach. Will send shortly. Michal

On Tue, Jan 26, 2021 at 17:41:54 +0100, Michal Privoznik wrote:
On 1/26/21 5:08 PM, Jiri Denemark wrote:
In case qemuStateInitialize fails for any reason (e.g., a typo in qemu.conf), it properly cleans up after itself and sets qemu_driver back to NULL. A tiny bit later the daemon asks all drivers to shutdown by calling their stateShutdown* APIs. But the implementation of these APIs in QEMU driver expected qemu_driver to be initialized at this point causing a segfault otherwise.
Signed-off-by: Jiri Denemark <jdenemar@redhat.com> --- src/qemu/qemu_driver.c | 6 ++++++ 1 file changed, 6 insertions(+)
This patch looks familiar :-)
https://www.redhat.com/archives/libvir-list/2021-January/msg00955.html
I'm working on alternative approach. Will send shortly.
Oops, I knew something similar was discussed, but I didn't realize it was the exact same thing... Not to mention I was too lazy to search for it (mostly because my memory didn't tell me what exactly to search for) :-) Jirka
participants (2)
-
Jiri Denemark
-
Michal Privoznik