Daniel Veillard wrote:
  Are you disagreeing with the message (which your patch doesn't fix)
or with the semantic of the check (and then why allow to create a domain
reusing the UUID of another defined but not running domain, I can only
see confusion or security problems in doing so)

The act of creating a domain reusing the UUID of another defined but not running domain is presumably an action taken with intent to rename that other domain (and thus should undefine the prior domain holding that UUID in the process... which, admittedly, the given patch didn't explicitly do).

Anyhow, two patches attached; one revises the error messages, while the other improves behavior with the semantics I assumed, to explicitly undefine any duplicates found during a create; I'm happy with either.
diff --git a/src/qemu_driver.c b/src/qemu_driver.c
index b8fd11c..6ed4d8a 100644
--- a/src/qemu_driver.c
+++ b/src/qemu_driver.c
@@ -2014,22 +2014,38 @@ static virDomainPtr qemudDomainCreate(virConnectPtr conn, const char *xml,
 
     vm = virDomainFindByName(driver->domains, def->name);
     if (vm) {
-        qemudReportError(conn, NULL, NULL, VIR_ERR_OPERATION_FAILED,
-                         _("domain '%s' is already defined and running"),
-                         def->name);
-        virDomainDefFree(def);
-        return NULL;
+        if(virDomainIsActive(vm)) {
+            qemudReportError(conn, NULL, NULL, VIR_ERR_OPERATION_FAILED,
+                             _("domain '%s' is already defined and running"),
+                             def->name);
+            virDomainDefFree(def);
+            return NULL;
+        } else {
+            if(virDomainDeleteConfig(conn, vm) < -1) {
+                return NULL;
+            } else {
+                virDomainRemoveInactive(&driver->domains, vm);
+            }
+        }
     }
     vm = virDomainFindByUUID(driver->domains, def->uuid);
     if (vm) {
-        char uuidstr[VIR_UUID_STRING_BUFLEN];
+        if(virDomainIsActive(vm)) {
+            char uuidstr[VIR_UUID_STRING_BUFLEN];
 
-        virUUIDFormat(def->uuid, uuidstr);
-        qemudReportError(conn, NULL, NULL, VIR_ERR_OPERATION_FAILED,
-                         _("domain with uuid '%s' is already defined and running"),
-                         uuidstr);
-        virDomainDefFree(def);
-        return NULL;
+            virUUIDFormat(def->uuid, uuidstr);
+            qemudReportError(conn, NULL, NULL, VIR_ERR_OPERATION_FAILED,
+                             _("domain with uuid '%s' is already defined and running"),
+                             uuidstr);
+            virDomainDefFree(def);
+            return NULL;
+        } else {
+            if(virDomainDeleteConfig(conn, vm) < -1) {
+                return NULL;
+            } else {
+                virDomainRemoveInactive(&driver->domains, vm);
+            }
+        }
     }
 
     if (!(vm = virDomainAssignDef(conn,
diff --git a/src/qemu_driver.c b/src/qemu_driver.c
index 9d661d2..3790db8 100644
--- a/src/qemu_driver.c
+++ b/src/qemu_driver.c
@@ -2015,7 +2015,7 @@ static virDomainPtr qemudDomainCreate(virConnectPtr conn, const char *xml,
     vm = virDomainFindByName(driver->domains, def->name);
     if (vm) {
         qemudReportError(conn, NULL, NULL, VIR_ERR_OPERATION_FAILED,
-                         _("domain '%s' is already defined and running"),
+                         _("domain '%s' is already defined"),
                          def->name);
         virDomainDefFree(def);
         return NULL;
@@ -2026,7 +2026,7 @@ static virDomainPtr qemudDomainCreate(virConnectPtr conn, const char *xml,
 
         virUUIDFormat(def->uuid, uuidstr);
         qemudReportError(conn, NULL, NULL, VIR_ERR_OPERATION_FAILED,
-                         _("domain with uuid '%s' is already defined and running"),
+                         _("domain with uuid '%s' is already defined"),
                          uuidstr);
         virDomainDefFree(def);
         return NULL;
--
Libvir-list mailing list
Libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Reply via email to