[PATCH 3/7] cpu: Add virCPUType parameter to virCPUGetHost

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

 



The parameter can be used to request either VIR_CPU_TYPE_HOST (which has
been assumed so far) or VIR_CPU_TYPE_GUEST definition.

Signed-off-by: Jiri Denemark <jdenemar@xxxxxxxxxx>
---
 src/bhyve/bhyve_capabilities.c |  2 +-
 src/cpu/cpu.c                  | 41 ++++++++++++++++++++++++++++++++++++-----
 src/cpu/cpu.h                  |  1 +
 src/qemu/qemu_capabilities.c   |  2 +-
 src/vmware/vmware_conf.c       |  2 +-
 src/vz/vz_driver.c             |  3 ++-
 6 files changed, 42 insertions(+), 9 deletions(-)

diff --git a/src/bhyve/bhyve_capabilities.c b/src/bhyve/bhyve_capabilities.c
index c2c9303d7..33e670c5c 100644
--- a/src/bhyve/bhyve_capabilities.c
+++ b/src/bhyve/bhyve_capabilities.c
@@ -47,7 +47,7 @@ virBhyveCapsInitCPU(virCapsPtr caps,
     if (nodeGetInfo(&nodeinfo))
         return -1;
 
-    if (!(caps->host.cpu = virCPUGetHost(arch, &nodeinfo)))
+    if (!(caps->host.cpu = virCPUGetHost(arch, VIR_CPU_TYPE_HOST, &nodeinfo)))
         return -1;
 
     return 0;
diff --git a/src/cpu/cpu.c b/src/cpu/cpu.c
index c1666ed3b..110bb240c 100644
--- a/src/cpu/cpu.c
+++ b/src/cpu/cpu.c
@@ -360,9 +360,18 @@ virCPUDataFree(virCPUDataPtr data)
  * virCPUGetHost:
  *
  * @arch: CPU architecture
+ * @type: requested type of the CPU
  * @nodeInfo: simplified CPU topology (optional)
  *
- * Create CPU definition describing the host's CPU. If @nodeInfo is not NULL,
+ * Create CPU definition describing the host's CPU.
+ *
+ * The @type (either VIR_CPU_TYPE_HOST or VIR_CPU_TYPE_GUEST) specifies what
+ * type of CPU definition should be created. Specifically, VIR_CPU_TYPE_HOST
+ * CPUs may contain only features without any policy attribute. Requesting
+ * VIR_CPU_TYPE_GUEST provides better results because the CPU is allowed to
+ * contain disabled features.
+ *
+ * If @nodeInfo is not NULL (which is only allowed for VIR_CPU_TYPE_HOST CPUs),
  * the CPU definition will have topology (sockets, cores, threads) filled in
  * according to the content of @nodeInfo. The function fails only if @nodeInfo
  * was not passed in and the assigned CPU driver was not able to detect the
@@ -373,13 +382,14 @@ virCPUDataFree(virCPUDataPtr data)
  */
 virCPUDefPtr
 virCPUGetHost(virArch arch,
+              virCPUType type,
               virNodeInfoPtr nodeInfo)
 {
     struct cpuArchDriver *driver;
     virCPUDefPtr cpu = NULL;
 
-    VIR_DEBUG("arch=%s, nodeInfo=%p",
-              virArchToString(arch), nodeInfo);
+    VIR_DEBUG("arch=%s, type=%s, nodeInfo=%p",
+              virArchToString(arch), virCPUTypeToString(type), nodeInfo);
 
     if (!(driver = cpuGetSubDriver(arch)))
         return NULL;
@@ -387,8 +397,29 @@ virCPUGetHost(virArch arch,
     if (VIR_ALLOC(cpu) < 0)
         return NULL;
 
-    cpu->arch = arch;
-    cpu->type = VIR_CPU_TYPE_HOST;
+    switch (type) {
+    case VIR_CPU_TYPE_HOST:
+        cpu->arch = arch;
+        cpu->type = type;
+        break;
+
+    case VIR_CPU_TYPE_GUEST:
+        if (nodeInfo) {
+            virReportError(VIR_ERR_INVALID_ARG,
+                           _("cannot set topology for CPU type '%s'"),
+                           virCPUTypeToString(type));
+            goto error;
+        }
+        cpu->type = type;
+        break;
+
+    case VIR_CPU_TYPE_AUTO:
+    case VIR_CPU_TYPE_LAST:
+        virReportError(VIR_ERR_INVALID_ARG,
+                       _("unsupported CPU type: %s"),
+                       virCPUTypeToString(type));
+        goto error;
+    }
 
     if (nodeInfo) {
         cpu->sockets = nodeInfo->sockets;
diff --git a/src/cpu/cpu.h b/src/cpu/cpu.h
index cbbb45223..e5eca08c3 100644
--- a/src/cpu/cpu.h
+++ b/src/cpu/cpu.h
@@ -170,6 +170,7 @@ virCPUDataFree(virCPUDataPtr data);
 
 virCPUDefPtr
 virCPUGetHost(virArch arch,
+              virCPUType type,
               virNodeInfoPtr nodeInfo);
 
 char *
diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index b0a4861c3..b39014224 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -1070,7 +1070,7 @@ virQEMUCapsInitCPU(virCapsPtr caps,
     if (nodeGetInfo(&nodeinfo))
         return -1;
 
-    if (!(caps->host.cpu = virCPUGetHost(arch, &nodeinfo)))
+    if (!(caps->host.cpu = virCPUGetHost(arch, VIR_CPU_TYPE_HOST, &nodeinfo)))
         return -1;
 
     return 0;
diff --git a/src/vmware/vmware_conf.c b/src/vmware/vmware_conf.c
index d1444e462..cb6d60724 100644
--- a/src/vmware/vmware_conf.c
+++ b/src/vmware/vmware_conf.c
@@ -82,7 +82,7 @@ vmwareCapsInit(void)
                                       NULL, NULL, 0, NULL) == NULL)
         goto error;
 
-    if (!(cpu = virCPUGetHost(caps->host.arch, NULL)))
+    if (!(cpu = virCPUGetHost(caps->host.arch, VIR_CPU_TYPE_HOST, NULL)))
         goto error;
 
     /* x86_64 guests are supported if
diff --git a/src/vz/vz_driver.c b/src/vz/vz_driver.c
index f97a2045b..67ec2727b 100644
--- a/src/vz/vz_driver.c
+++ b/src/vz/vz_driver.c
@@ -129,7 +129,8 @@ vzBuildCapabilities(void)
     if (nodeGetInfo(&nodeinfo))
         goto error;
 
-    if (!(caps->host.cpu = virCPUGetHost(caps->host.arch, &nodeinfo)))
+    if (!(caps->host.cpu = virCPUGetHost(caps->host.arch, VIR_CPU_TYPE_HOST,
+                                         &nodeinfo)))
         goto error;
 
     if (virCapabilitiesAddHostMigrateTransport(caps, "vzmigr") < 0)
-- 
2.12.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