]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
hyperv: ambiguous VM names will throw an error
authorMatt Coleman <mcoleman@datto.com>
Thu, 14 Jan 2021 13:03:32 +0000 (08:03 -0500)
committerMichal Privoznik <mprivozn@redhat.com>
Thu, 21 Jan 2021 09:18:21 +0000 (10:18 +0100)
Since Hyper-V allows multiple VMs to be created with the same name,
some commands produce unpredictable results due to
hypervDomainLookupByName's WMI query selecting the wrong domain.

For example, this prevents `virsh dumpxml` from outputting XML for the
wrong domain.

Signed-off-by: Matt Coleman <matt@datto.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
include/libvirt/virterror.h
src/hyperv/hyperv_driver.c
src/util/virerror.c

index b96fe250aae6e1bd1e252b773abc32e4924dbcb7..524a7bf9e8030b88582b92921ab767587185fafe 100644 (file)
@@ -333,6 +333,7 @@ typedef enum {
     VIR_ERR_NO_NETWORK_PORT = 107,      /* network port not found */
     VIR_ERR_NO_HOSTNAME = 108,          /* no domain's hostname found */
     VIR_ERR_CHECKPOINT_INCONSISTENT = 109, /* checkpoint can't be used */
+    VIR_ERR_MULTIPLE_DOMAINS = 110,     /* more than one matching domain found */
 
 # ifdef VIR_ENUM_SENTINELS
     VIR_ERR_NUMBER_LAST
index 1200bf02ff099fbf64940783168d89d62cbbe10d..2e18ef66912ab1ea17257bef5cd63f7c80eb4268 100644 (file)
@@ -1118,6 +1118,13 @@ hypervDomainLookupByName(virConnectPtr conn, const char *name)
     if (hypervGetVirtualSystemByName(priv, name, &computerSystem) < 0)
         goto cleanup;
 
+    if (computerSystem->next) {
+        virReportError(VIR_ERR_MULTIPLE_DOMAINS,
+                       _("Multiple domains exist with the name '%s': repeat the request using a UUID"),
+                       name);
+        goto cleanup;
+    }
+
     hypervMsvmComputerSystemToDomain(conn, computerSystem, &domain);
 
  cleanup:
index 9e3bad97eba44e4e7319f286aa4e33c5e28407ed..14054add41715ea8dd6cbf4993ff19ae1e4483ed 100644 (file)
@@ -1229,8 +1229,10 @@ static const virErrorMsgTuple virErrorMsgStrings[] = {
         N_("no hostname found: %s") },
     [VIR_ERR_CHECKPOINT_INCONSISTENT] = {
         N_("checkpoint inconsistent"),
-        N_("checkpoint inconsistent: %s")
-    },
+        N_("checkpoint inconsistent: %s") },
+    [VIR_ERR_MULTIPLE_DOMAINS] = {
+        N_("multiple matching domains found"),
+        N_("multiple matching domains found: %s") },
 };
 
 G_STATIC_ASSERT(G_N_ELEMENTS(virErrorMsgStrings) == VIR_ERR_NUMBER_LAST);