[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [PATCH] qemudDomainCreate check if domain is already active



Hi,
currently virsh create foo.xml overwrites running domains. In case of
qemu this leaves detached qemu processes around and the domain creation
fails later on being unable to start other domains afterwards - not
nice.
Attached patch checks if we already have a running domain by that name
and in this case refuses to create a new domain from xml by that name.

Probably this check needs to be pushed further upward since this might
affect other hypervisors too, haven't checked that though.
Cheers,
 -- Guido
[PATCH] qemudDomainCreate: check if domain is already active

otherwise we overwrite a running domain which lets libvirtd disconnect
from the running qemu.
---
 src/qemu_driver.c |    9 +++++++++
 1 files changed, 9 insertions(+), 0 deletions(-)

diff --git a/src/qemu_driver.c b/src/qemu_driver.c
index b84bdf4..0ad72ae 100644
--- a/src/qemu_driver.c
+++ b/src/qemu_driver.c
@@ -1978,6 +1978,15 @@ static virDomainPtr qemudDomainCreate(virConnectPtr conn, const char *xml,
     if (!(def = virDomainDefParseString(conn, driver->caps, xml)))
         return NULL;
 
+    vm = virDomainFindByName(driver->domains, def->name);
+    if (vm && virDomainIsActive(vm)) {
+        qemudReportError(conn, NULL, NULL, VIR_ERR_OPERATION_FAILED,
+                         _("domain %s is already defined and running"),
+			 def->name);
+        virDomainDefFree(def);
+        return NULL;
+    }
+
     if (!(vm = virDomainAssignDef(conn,
                                   &driver->domains,
                                   def))) {
-- 
1.5.6.3


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]