[PATCH 1/2] hyperv: improve error message when redefining domain
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
Right now if we run `virsh define domain.xml` multiple times, it will result in multiple domains being defined with the same name. This violates libvirt assumptions about name uniqueness, so prevent this from happening by returning an error. There's not much we can do about vms that may have been created outside of libvirt that might have the same name (unless we switch to using something like the UUID as the name for hyperv domains, which would not be very user-friendly), but at least we can not contribute to the problem. Signed-off-by: Jonathon Jongsma <jjongsma@redhat.com> --- src/hyperv/hyperv_driver.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/hyperv/hyperv_driver.c b/src/hyperv/hyperv_driver.c index 6e9917f92a..f717499ba9 100644 --- a/src/hyperv/hyperv_driver.c +++ b/src/hyperv/hyperv_driver.c @@ -2952,6 +2952,13 @@ hypervDomainDefineXML(virConnectPtr conn, const char *xml) return NULL; } + /* abort if a domain with this name already exists */ + if (hypervGetVirtualSystemByName(priv, def->name, &existing) == 0 && + existing != NULL) { + virReportError(VIR_ERR_DOM_EXIST, "%s", def->name); + return NULL; + } + /* prepare params: only set the VM's name for now */ params = hypervCreateInvokeParamsList("DefineSystem", MSVM_VIRTUALSYSTEMMANAGEMENTSERVICE_SELECTOR, -- 2.53.0
participants (1)
-
Jonathon Jongsma