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 <[email protected]> --- 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
