]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
Fix race condition reconnecting to vms & loading configs
authorDaniel P. Berrange <berrange@redhat.com>
Mon, 28 Oct 2013 11:49:18 +0000 (11:49 +0000)
committerCole Robinson <crobinso@redhat.com>
Wed, 6 Nov 2013 16:45:03 +0000 (11:45 -0500)
The following sequence

 1. Define a persistent QMEU guest
 2. Start the QEMU guest
 3. Stop libvirtd
 4. Kill the QEMU process
 5. Start libvirtd
 6. List persistent guests

At the last step, the previously running persistent guest
will be missing. This is because of a race condition in the
QEMU driver startup code. It does

 1. Load all VM state files
 2. Spawn thread to reconnect to each VM
 3. Load all VM config files

Only at the end of step 3, does the 'virDomainObjPtr' get
marked as "persistent". There is therefore a window where
the thread reconnecting to the VM will remove the persistent
VM from the list.

The easy fix is to simply switch the order of steps 2 & 3.

In addition to this though, we must only attempt to reconnect
to a VM which had a non-zero PID loaded from its state file.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
(cherry picked from commit f26701f565525dd402df021d8923489e62412158)

src/qemu/qemu_driver.c
src/qemu/qemu_process.c

index 5b594a849a222abf40ee1bae0ee9452d8c281b2b..491dfc7db09495bceff990b334d95b9d89ec5034 100644 (file)
@@ -811,8 +811,6 @@ qemuStateInitialize(bool privileged,
 
     conn = virConnectOpen(cfg->uri);
 
-    qemuProcessReconnectAll(conn, qemu_driver);
-
     /* Then inactive persistent configs */
     if (virDomainObjListLoadAllConfigs(qemu_driver->domains,
                                        cfg->configDir,
@@ -823,6 +821,7 @@ qemuStateInitialize(bool privileged,
                                        NULL, NULL) < 0)
         goto error;
 
+    qemuProcessReconnectAll(conn, qemu_driver);
 
     virDomainObjListForEach(qemu_driver->domains,
                             qemuDomainSnapshotLoad,
index 393110b735d97943962186b416f4d8b9d32f5979..43a9156034cac96150d5394116a989068ccfd129 100644 (file)
@@ -3253,6 +3253,9 @@ qemuProcessReconnectHelper(virDomainObjPtr obj,
     struct qemuProcessReconnectData *src = opaque;
     struct qemuProcessReconnectData *data;
 
+    if (!obj->pid)
+        return 0;
+
     if (VIR_ALLOC(data) < 0)
         return -1;