]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
virDomainCreateXML: Don't remove persistent domains on error
authorMichal Privoznik <mprivozn@redhat.com>
Tue, 22 Sep 2015 14:52:03 +0000 (16:52 +0200)
committerCole Robinson <crobinso@redhat.com>
Wed, 23 Dec 2015 23:14:21 +0000 (18:14 -0500)
https://bugzilla.redhat.com/show_bug.cgi?id=871452

Okay, so we allow users to 'virsh create' an already existing
domain, providing completely different XML than the one stored in
Libvirt. Well, as long as name and UUID matches. However, in some
drivers the code that handles errors unconditionally removes the
domain that failed to start even though the domain might have
been persistent. Fortunately, the domain is removed just from the
internal list of domains and the config file is kept around.

Steps to reproduce:

1) virsh dumpxml $dom > /tmp/dom.xml
2) change XML so that it is still parse-able but won't boot, e.g.
change guest agent path to /foo/bar
3) virsh create /tmp/dom.xml
4) virsh dumpxml $dom
5) Observe "No such domain" error

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
(cherry picked from commit 37405b910907bd1ad338fb0d6a967bfd23529cf6)

src/lxc/lxc_driver.c
src/qemu/qemu_driver.c
src/test/test_driver.c
src/uml/uml_driver.c
src/vmware/vmware_driver.c

index 4d4488173160252b71b64629f76bd0c057607ffb..a08946b0ffe11dad16f098fe13c4066cf2072dc9 100644 (file)
@@ -1239,8 +1239,10 @@ lxcDomainCreateXMLWithFiles(virConnectPtr conn,
                            (flags & VIR_DOMAIN_START_AUTODESTROY),
                            VIR_DOMAIN_RUNNING_BOOTED) < 0) {
         virDomainAuditStart(vm, "booted", false);
-        virDomainObjListRemove(driver->domains, vm);
-        vm = NULL;
+        if (!vm->persistent) {
+            virDomainObjListRemove(driver->domains, vm);
+            vm = NULL;
+        }
         goto cleanup;
     }
 
index fda9cd917d9714b83eaa39f29cbaa9dcd3ebdfc8..a0aee8f173e4f1f05df65e7b0f64117c24aac000 100644 (file)
@@ -1751,7 +1751,8 @@ static virDomainPtr qemuDomainCreateXML(virConnectPtr conn,
     def = NULL;
 
     if (qemuDomainObjBeginJob(driver, vm, QEMU_JOB_MODIFY) < 0) {
-        qemuDomainRemoveInactive(driver, vm);
+        if (!vm->persistent)
+            qemuDomainRemoveInactive(driver, vm);
         goto cleanup;
     }
 
@@ -1761,7 +1762,8 @@ static virDomainPtr qemuDomainCreateXML(virConnectPtr conn,
                          start_flags) < 0) {
         virDomainAuditStart(vm, "booted", false);
         qemuDomainObjEndJob(driver, vm);
-        qemuDomainRemoveInactive(driver, vm);
+        if (!vm->persistent)
+            qemuDomainRemoveInactive(driver, vm);
         goto cleanup;
     }
 
index 90ab09f723048a58f42756e26bad315826b23285..3809f72b9b8f67bc87e029e832b689aa1262e019 100644 (file)
@@ -1621,8 +1621,13 @@ testDomainCreateXML(virConnectPtr conn, const char *xml,
         goto cleanup;
     def = NULL;
 
-    if (testDomainStartState(privconn, dom, VIR_DOMAIN_RUNNING_BOOTED) < 0)
+    if (testDomainStartState(privconn, dom, VIR_DOMAIN_RUNNING_BOOTED) < 0) {
+        if (!dom->persistent) {
+            virDomainObjListRemove(privconn->domains, dom);
+            dom = NULL;
+        }
         goto cleanup;
+    }
 
     event = virDomainEventLifecycleNewFromObj(dom,
                                      VIR_DOMAIN_EVENT_STARTED,
index c3c5fa7d9ac523e472ade4b2aeacfc34377078e3..337b792250be7c9da6a91042a311dfb030bbf993 100644 (file)
@@ -1623,9 +1623,10 @@ static virDomainPtr umlDomainCreateXML(virConnectPtr conn, const char *xml,
     if (umlStartVMDaemon(conn, driver, vm,
                          (flags & VIR_DOMAIN_START_AUTODESTROY)) < 0) {
         virDomainAuditStart(vm, "booted", false);
-        virDomainObjListRemove(driver->domains,
-                               vm);
-        vm = NULL;
+        if (!vm->persistent) {
+            virDomainObjListRemove(driver->domains, vm);
+            vm = NULL;
+        }
         goto cleanup;
     }
     virDomainAuditStart(vm, "booted", true);
index ec74fe3831e5ca8018c2bfc22b88fdbd7667a9fd..ce50d789db794cbf930fee0235caae503886c3fe 100644 (file)
@@ -710,8 +710,10 @@ vmwareDomainCreateXML(virConnectPtr conn, const char *xml,
     vmdef = NULL;
 
     if (vmwareStartVM(driver, vm) < 0) {
-        virDomainObjListRemove(driver->domains, vm);
-        vm = NULL;
+        if (!vm->persistent) {
+            virDomainObjListRemove(driver->domains, vm);
+            vm = NULL;
+        }
         goto cleanup;
     }