The current error message results in something like the following when running `virsh define` for an existing domain: `domain Domain already exists with UUID '$UUID' exists already` Improve the error message and make it behave like the esx driver and indicate that we do not yet support redefining existing domains in hyperv. Also avoid using the public LookupByUUID() API to check for existance, which requires unnecessarily allocating and de-allocating a virDomainPtr object. Signed-off-by: Jonathon Jongsma <jjongsma@redhat.com> --- src/hyperv/hyperv_driver.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/hyperv/hyperv_driver.c b/src/hyperv/hyperv_driver.c index b01b4919fe..6e9917f92a 100644 --- a/src/hyperv/hyperv_driver.c +++ b/src/hyperv/hyperv_driver.c @@ -2933,6 +2933,8 @@ hypervDomainDefineXML(virConnectPtr conn, const char *xml) virDomainPtr domain = NULL; g_autoptr(hypervInvokeParamsList) params = NULL; g_autoptr(GHashTable) defineSystemParam = NULL; + g_autoptr(Msvm_ComputerSystem) existing = NULL; + char uuid_string[VIR_UUID_STRING_BUFLEN]; size_t i = 0; /* parse xml */ @@ -2943,13 +2945,10 @@ hypervDomainDefineXML(virConnectPtr conn, const char *xml) goto error; /* abort if a domain with this UUID already exists */ - if ((domain = hypervDomainLookupByUUID(conn, def->uuid))) { - char uuid_string[VIR_UUID_STRING_BUFLEN]; - virUUIDFormat(domain->uuid, uuid_string); - virReportError(VIR_ERR_DOM_EXIST, _("Domain already exists with UUID '%1$s'"), uuid_string); - - // Don't use the 'exit' label, since we don't want to delete the existing domain. - virObjectUnref(domain); + virUUIDFormat(def->uuid, uuid_string); + if (hypervMsvmComputerSystemFromUUID(priv, uuid_string, &existing) == 0 && existing != NULL) { + virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s", + _("Domain already exists, editing existing domains is not supported yet")); return NULL; } -- 2.53.0