[PATCH v3 37/52] qemu: Pass virDomainVirtType to APIs dealing with machine types

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Signed-off-by: Jiri Denemark <jdenemar@xxxxxxxxxx>
---

Notes:
    Version 3:
    - new patch

 src/qemu/qemu_capabilities.c | 64 +++++++++++++++++++++---------------
 src/qemu/qemu_capabilities.h |  8 ++++-
 src/qemu/qemu_domain.c       |  8 +++--
 tests/domaincapstest.c       | 10 ++++--
 4 files changed, 59 insertions(+), 31 deletions(-)

diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index 52a7248574..68ae8be5c3 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -2106,8 +2106,10 @@ virQEMUCapsIsCPUModeSupported(virQEMUCapsPtr qemuCaps,
  * Resolves aliased machine names to the actual machine name. If qemuCaps isn't
  * present @name is returned.
  */
-const char *virQEMUCapsGetCanonicalMachine(virQEMUCapsPtr qemuCaps,
-                                           const char *name)
+const char *
+virQEMUCapsGetCanonicalMachine(virQEMUCapsPtr qemuCaps,
+                               virDomainVirtType virtType G_GNUC_UNUSED,
+                               const char *name)
 {
     size_t i;
 
@@ -2125,8 +2127,10 @@ const char *virQEMUCapsGetCanonicalMachine(virQEMUCapsPtr qemuCaps,
 }
 
 
-int virQEMUCapsGetMachineMaxCpus(virQEMUCapsPtr qemuCaps,
-                                 const char *name)
+int
+virQEMUCapsGetMachineMaxCpus(virQEMUCapsPtr qemuCaps,
+                             virDomainVirtType virtType G_GNUC_UNUSED,
+                             const char *name)
 {
     size_t i;
 
@@ -2144,8 +2148,10 @@ int virQEMUCapsGetMachineMaxCpus(virQEMUCapsPtr qemuCaps,
 }
 
 
-bool virQEMUCapsGetMachineHotplugCpus(virQEMUCapsPtr qemuCaps,
-                                      const char *name)
+bool
+virQEMUCapsGetMachineHotplugCpus(virQEMUCapsPtr qemuCaps,
+                                 virDomainVirtType virtType G_GNUC_UNUSED,
+                                 const char *name)
 {
     size_t i;
 
@@ -2431,6 +2437,7 @@ virQEMUCapsProbeQMPMachineTypes(virQEMUCapsPtr qemuCaps,
 
 static bool
 virQEMUCapsIsMachineSupported(virQEMUCapsPtr qemuCaps,
+                              virDomainVirtType virtType G_GNUC_UNUSED,
                               const char *canonical_machine)
 {
     size_t i;
@@ -2445,6 +2452,7 @@ virQEMUCapsIsMachineSupported(virQEMUCapsPtr qemuCaps,
 
 static int
 virQEMUCapsProbeQMPMachineProps(virQEMUCapsPtr qemuCaps,
+                                virDomainVirtType virtType,
                                 qemuMonitorPtr mon)
 {
     char **values;
@@ -2456,10 +2464,10 @@ virQEMUCapsProbeQMPMachineProps(virQEMUCapsPtr qemuCaps,
 
     for (i = 0; i < G_N_ELEMENTS(virQEMUCapsMachineProps); i++) {
         virQEMUCapsObjectTypeProps props = virQEMUCapsMachineProps[i];
-        const char *canon = virQEMUCapsGetCanonicalMachine(qemuCaps, props.type);
+        const char *canon = virQEMUCapsGetCanonicalMachine(qemuCaps, virtType, props.type);
         g_autofree char *type = NULL;
 
-        if (!virQEMUCapsIsMachineSupported(qemuCaps, canon))
+        if (!virQEMUCapsIsMachineSupported(qemuCaps, virtType, canon))
             continue;
 
         /* The QOM type for machine types is the machine type name
@@ -4641,7 +4649,7 @@ virQEMUCapsInitQMPMonitor(virQEMUCapsPtr qemuCaps,
         return -1;
     if (virQEMUCapsProbeQMPMachineTypes(qemuCaps, mon) < 0)
         return -1;
-    if (virQEMUCapsProbeQMPMachineProps(qemuCaps, mon) < 0)
+    if (virQEMUCapsProbeQMPMachineProps(qemuCaps, type, mon) < 0)
         return -1;
     if (virQEMUCapsProbeQMPCPUDefinitions(qemuCaps, accel, mon) < 0)
         return -1;
@@ -4878,6 +4886,7 @@ static const struct virQEMUCapsMachineTypeFilter virQEMUCapsMachineFilter[] = {
 
 void
 virQEMUCapsFilterByMachineType(virQEMUCapsPtr qemuCaps,
+                               virDomainVirtType virtType,
                                const char *machineType)
 {
     size_t i;
@@ -4896,7 +4905,7 @@ virQEMUCapsFilterByMachineType(virQEMUCapsPtr qemuCaps,
             virQEMUCapsClear(qemuCaps, filter->flags[j]);
     }
 
-    if (!virQEMUCapsGetMachineHotplugCpus(qemuCaps, machineType))
+    if (!virQEMUCapsGetMachineHotplugCpus(qemuCaps, virtType, machineType))
         virQEMUCapsClear(qemuCaps, QEMU_CAPS_QUERY_HOTPLUGGABLE_CPUS);
 }
 
@@ -4972,6 +4981,7 @@ virQEMUCapsCacheLookup(virFileCachePtr cache,
 
 virQEMUCapsPtr
 virQEMUCapsCacheLookupCopy(virFileCachePtr cache,
+                           virDomainVirtType virtType,
                            const char *binary,
                            const char *machineType)
 {
@@ -4987,7 +4997,7 @@ virQEMUCapsCacheLookupCopy(virFileCachePtr cache,
     if (!ret)
         return NULL;
 
-    virQEMUCapsFilterByMachineType(ret, machineType);
+    virQEMUCapsFilterByMachineType(ret, virtType, machineType);
     return ret;
 }
 
@@ -5130,20 +5140,6 @@ virQEMUCapsCacheLookupDefault(virFileCachePtr cache,
         binary = virQEMUCapsGetBinary(qemuCaps);
     }
 
-    if (machine) {
-        /* Turn @machine into canonical name */
-        machine = virQEMUCapsGetCanonicalMachine(qemuCaps, machine);
-
-        if (!virQEMUCapsIsMachineSupported(qemuCaps, machine)) {
-            virReportError(VIR_ERR_INVALID_ARG,
-                           _("the machine '%s' is not supported by emulator '%s'"),
-                           machine, binary);
-            goto cleanup;
-        }
-    } else {
-        machine = virQEMUCapsGetPreferredMachine(qemuCaps);
-    }
-
     if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_KVM))
         capsType = VIR_DOMAIN_VIRT_KVM;
     else
@@ -5159,6 +5155,20 @@ virQEMUCapsCacheLookupDefault(virFileCachePtr cache,
         goto cleanup;
     }
 
+    if (machine) {
+        /* Turn @machine into canonical name */
+        machine = virQEMUCapsGetCanonicalMachine(qemuCaps, virttype, machine);
+
+        if (!virQEMUCapsIsMachineSupported(qemuCaps, virttype, machine)) {
+            virReportError(VIR_ERR_INVALID_ARG,
+                           _("the machine '%s' is not supported by emulator '%s'"),
+                           machine, binary);
+            goto cleanup;
+        }
+    } else {
+        machine = virQEMUCapsGetPreferredMachine(qemuCaps, virttype);
+    }
+
     if (retArch)
         *retArch = arch;
     if (retVirttype)
@@ -5191,7 +5201,8 @@ virQEMUCapsSupportsVmport(virQEMUCapsPtr qemuCaps,
  * Note that this may differ from QEMU's own default machine
  */
 const char *
-virQEMUCapsGetPreferredMachine(virQEMUCapsPtr qemuCaps)
+virQEMUCapsGetPreferredMachine(virQEMUCapsPtr qemuCaps,
+                               virDomainVirtType virtType G_GNUC_UNUSED)
 {
     if (!qemuCaps->nmachineTypes)
         return NULL;
@@ -5650,6 +5661,7 @@ virQEMUCapsFillDomainCaps(virCapsPtr caps,
     virDomainCapsDeviceRNGPtr rng = &domCaps->rng;
 
     domCaps->maxvcpus = virQEMUCapsGetMachineMaxCpus(qemuCaps,
+                                                     domCaps->virttype,
                                                      domCaps->machine);
     if (domCaps->virttype == VIR_DOMAIN_VIRT_KVM) {
         int hostmaxvcpus;
diff --git a/src/qemu/qemu_capabilities.h b/src/qemu/qemu_capabilities.h
index c0e1ce41e3..bc43b99579 100644
--- a/src/qemu/qemu_capabilities.h
+++ b/src/qemu/qemu_capabilities.h
@@ -601,13 +601,17 @@ bool virQEMUCapsIsCPUModeSupported(virQEMUCapsPtr qemuCaps,
                                    virDomainVirtType type,
                                    virCPUMode mode);
 const char *virQEMUCapsGetCanonicalMachine(virQEMUCapsPtr qemuCaps,
+                                           virDomainVirtType virtType,
                                            const char *name);
 int virQEMUCapsGetMachineMaxCpus(virQEMUCapsPtr qemuCaps,
+                                 virDomainVirtType virtType,
                                  const char *name);
 bool virQEMUCapsGetMachineHotplugCpus(virQEMUCapsPtr qemuCaps,
+                                      virDomainVirtType virtType,
                                       const char *name);
 
 void virQEMUCapsFilterByMachineType(virQEMUCapsPtr qemuCaps,
+                                    virDomainVirtType virtType,
                                     const char *machineType);
 
 virFileCachePtr virQEMUCapsCacheNew(const char *libDir,
@@ -617,6 +621,7 @@ virFileCachePtr virQEMUCapsCacheNew(const char *libDir,
 virQEMUCapsPtr virQEMUCapsCacheLookup(virFileCachePtr cache,
                                       const char *binary);
 virQEMUCapsPtr virQEMUCapsCacheLookupCopy(virFileCachePtr cache,
+                                          virDomainVirtType virtType,
                                           const char *binary,
                                           const char *machineType);
 virQEMUCapsPtr virQEMUCapsCacheLookupByArch(virFileCachePtr cache,
@@ -642,7 +647,8 @@ bool virQEMUCapsSupportsGICVersion(virQEMUCapsPtr qemuCaps,
                                    virDomainVirtType virtType,
                                    virGICVersion version);
 
-const char *virQEMUCapsGetPreferredMachine(virQEMUCapsPtr qemuCaps);
+const char *virQEMUCapsGetPreferredMachine(virQEMUCapsPtr qemuCaps,
+                                           virDomainVirtType virtType);
 
 int virQEMUCapsInitGuestFromBinary(virCapsPtr caps,
                                    const char *binary,
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 667cc89072..8627238c6a 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -4340,7 +4340,8 @@ qemuCanonicalizeMachine(virDomainDefPtr def, virQEMUCapsPtr qemuCaps)
 {
     const char *canon;
 
-    if (!(canon = virQEMUCapsGetCanonicalMachine(qemuCaps, def->os.machine)))
+    if (!(canon = virQEMUCapsGetCanonicalMachine(qemuCaps, def->virtType,
+                                                 def->os.machine)))
         return 0;
 
     if (STRNEQ(canon, def->os.machine)) {
@@ -4839,7 +4840,8 @@ static int
 qemuDomainValidateCpuCount(const virDomainDef *def,
                             virQEMUCapsPtr qemuCaps)
 {
-    unsigned int maxCpus = virQEMUCapsGetMachineMaxCpus(qemuCaps, def->os.machine);
+    unsigned int maxCpus = virQEMUCapsGetMachineMaxCpus(qemuCaps, def->virtType,
+                                                        def->os.machine);
 
     if (virDomainDefGetVcpus(def) == 0) {
         virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
@@ -8916,6 +8918,7 @@ qemuDomainDefFormatBufInternal(virQEMUDriverPtr driver,
             qCaps = virObjectRef(qemuCaps);
         } else {
             if (!(qCaps = virQEMUCapsCacheLookupCopy(driver->qemuCapsCache,
+                                                     def->virtType,
                                                      def->emulator,
                                                      def->os.machine)))
                 goto cleanup;
@@ -14992,6 +14995,7 @@ qemuDomainUpdateQEMUCaps(virDomainObjPtr vm,
 
     virObjectUnref(priv->qemuCaps);
     if (!(priv->qemuCaps = virQEMUCapsCacheLookupCopy(qemuCapsCache,
+                                                      vm->def->virtType,
                                                       vm->def->emulator,
                                                       vm->def->os.machine)))
         return -1;
diff --git a/tests/domaincapstest.c b/tests/domaincapstest.c
index f77accdb76..a3295cdd80 100644
--- a/tests/domaincapstest.c
+++ b/tests/domaincapstest.c
@@ -83,6 +83,7 @@ fillQemuCaps(virDomainCapsPtr domCaps,
     virCapsPtr caps = NULL;
     virQEMUCapsPtr qemuCaps = NULL;
     virDomainCapsLoaderPtr loader = &domCaps->os.loader;
+    virDomainVirtType virtType;
 
     if (!(caps = virCapabilitiesNew(domCaps->arch, false, false)) ||
         fakeHostCPU(caps, domCaps->arch) < 0)
@@ -93,13 +94,18 @@ fillQemuCaps(virDomainCapsPtr domCaps,
         !(qemuCaps = qemuTestParseCapabilities(caps, path)))
         goto cleanup;
 
+    if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_KVM))
+        virtType = VIR_DOMAIN_VIRT_KVM;
+    else
+        virtType = VIR_DOMAIN_VIRT_QEMU;
+
     if (machine) {
         VIR_FREE(domCaps->machine);
-        domCaps->machine = g_strdup(virQEMUCapsGetCanonicalMachine(qemuCaps, machine));
+        domCaps->machine = g_strdup(virQEMUCapsGetCanonicalMachine(qemuCaps, virtType, machine));
     }
 
     if (!domCaps->machine)
-        domCaps->machine = g_strdup(virQEMUCapsGetPreferredMachine(qemuCaps));
+        domCaps->machine = g_strdup(virQEMUCapsGetPreferredMachine(qemuCaps, virtType));
 
     if (virQEMUCapsFillDomainCaps(caps, domCaps, qemuCaps,
                                   false,
-- 
2.23.0

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list





[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux