[PATCH 3/3] cpu: Store arch in virCPUData

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

 



---
 src/cpu/cpu.c                | 11 +++++------
 src/cpu/cpu.h                | 19 +++++++++++--------
 src/cpu/cpu_powerpc.c        |  4 ++--
 src/cpu/cpu_x86.c            | 34 ++++++++++++++++++++--------------
 src/qemu/qemu_capabilities.c |  2 +-
 src/qemu/qemu_command.c      |  5 ++---
 src/vmware/vmware_conf.c     |  3 +--
 tests/cputest.c              |  6 ++----
 8 files changed, 44 insertions(+), 40 deletions(-)

diff --git a/src/cpu/cpu.c b/src/cpu/cpu.c
index a2d797d..a4e1840 100644
--- a/src/cpu/cpu.c
+++ b/src/cpu/cpu.c
@@ -198,29 +198,28 @@ cpuEncode(virArch arch,
         return -1;
     }
 
-    return driver->encode(cpu, forced, required,
+    return driver->encode(arch, cpu, forced, required,
                           optional, disabled, forbidden, vendor);
 }
 
 
 void
-cpuDataFree(virArch arch,
-            virCPUDataPtr data)
+cpuDataFree(virCPUDataPtr data)
 {
     struct cpuArchDriver *driver;
 
-    VIR_DEBUG("arch=%s, data=%p", virArchToString(arch), data);
+    VIR_DEBUG("data=%p", data);
 
     if (data == NULL)
         return;
 
-    if ((driver = cpuGetSubDriver(arch)) == NULL)
+    if ((driver = cpuGetSubDriver(data->arch)) == NULL)
         return;
 
     if (driver->free == NULL) {
         virReportError(VIR_ERR_NO_SUPPORT,
                        _("cannot free CPU data for %s architecture"),
-                       virArchToString(arch));
+                       virArchToString(data->arch));
         return;
     }
 
diff --git a/src/cpu/cpu.h b/src/cpu/cpu.h
index 1c67489..1feca82 100644
--- a/src/cpu/cpu.h
+++ b/src/cpu/cpu.h
@@ -32,12 +32,15 @@
 # include "cpu_ppc_data.h"
 
 
-typedef union _virCPUData virCPUData;
+typedef struct _virCPUData virCPUData;
 typedef virCPUData *virCPUDataPtr;
-union _virCPUData {
-    struct cpuX86Data *x86;
-    struct cpuPPCData ppc;
-    /* generic driver needs no data */
+struct _virCPUData {
+    virArch arch;
+    union {
+        struct cpuX86Data *x86;
+        struct cpuPPCData ppc;
+        /* generic driver needs no data */
+    } data;
 };
 
 
@@ -53,7 +56,8 @@ typedef int
                      const char *preferred);
 
 typedef int
-(*cpuArchEncode)    (const virCPUDefPtr cpu,
+(*cpuArchEncode)    (virArch arch,
+                     const virCPUDefPtr cpu,
                      virCPUDataPtr *forced,
                      virCPUDataPtr *required,
                      virCPUDataPtr *optional,
@@ -130,8 +134,7 @@ cpuEncode   (virArch arch,
              virCPUDataPtr *vendor);
 
 extern void
-cpuDataFree (virArch arch,
-             virCPUDataPtr data);
+cpuDataFree (virCPUDataPtr data);
 
 extern virCPUDataPtr
 cpuNodeData (virArch arch);
diff --git a/src/cpu/cpu_powerpc.c b/src/cpu/cpu_powerpc.c
index 0d319f4..62437d3 100644
--- a/src/cpu/cpu_powerpc.c
+++ b/src/cpu/cpu_powerpc.c
@@ -313,10 +313,10 @@ ppcDecode(virCPUDefPtr cpu,
     if (data == NULL || (map = ppcLoadMap()) == NULL)
         return -1;
 
-    if (!(model = ppcModelFindPVR(map, data->ppc.pvr))) {
+    if (!(model = ppcModelFindPVR(map, data->data.ppc.pvr))) {
         virReportError(VIR_ERR_OPERATION_FAILED,
                        _("Cannot find CPU model with PVR 0x%08x"),
-                       data->ppc.pvr);
+                       data->data.ppc.pvr);
         goto cleanup;
     }
 
diff --git a/src/cpu/cpu_x86.c b/src/cpu/cpu_x86.c
index 75ad647..4564bd4 100644
--- a/src/cpu/cpu_x86.c
+++ b/src/cpu/cpu_x86.c
@@ -216,14 +216,15 @@ x86DataFree(struct cpuX86Data *data)
 
 
 static virCPUDataPtr
-x86MakeCPUData(struct cpuX86Data **data)
+x86MakeCPUData(virArch arch, struct cpuX86Data **data)
 {
     virCPUDataPtr cpuData;
 
     if (VIR_ALLOC(cpuData) < 0)
         return NULL;
 
-    cpuData->x86 = *data;
+    cpuData->arch = arch;
+    cpuData->data.x86 = *data;
     *data = NULL;
 
     return cpuData;
@@ -235,7 +236,7 @@ x86FreeCPUData(virCPUDataPtr data)
     if (!data)
         return;
 
-    x86DataFree(data->x86);
+    x86DataFree(data->data.x86);
     VIR_FREE(data);
 }
 
@@ -1165,6 +1166,7 @@ x86Compute(virCPUDefPtr host,
     struct x86_model *guest_model = NULL;
     virCPUCompareResult ret;
     enum compare_result result;
+    virArch arch;
     size_t i;
 
     if (cpu->arch != VIR_ARCH_NONE) {
@@ -1187,6 +1189,9 @@ x86Compute(virCPUDefPtr host,
                 goto error;
             return VIR_CPU_COMPARE_INCOMPATIBLE;
         }
+        arch = cpu->arch;
+    } else {
+        arch = host->arch;
     }
 
     if (cpu->vendor &&
@@ -1266,7 +1271,7 @@ x86Compute(virCPUDefPtr host,
         x86DataSubtract(guest_model->data, cpu_disable->data);
 
         if (!(guestData = x86DataCopy(guest_model->data)) ||
-            !(*guest = x86MakeCPUData(&guestData))) {
+            !(*guest = x86MakeCPUData(arch, &guestData))) {
             x86DataFree(guestData);
             goto error;
         }
@@ -1418,7 +1423,7 @@ x86DecodeCPUData(virCPUDefPtr cpu,
                  unsigned int nmodels,
                  const char *preferred)
 {
-    return x86Decode(cpu, data->x86, models, nmodels, preferred);
+    return x86Decode(cpu, data->data.x86, models, nmodels, preferred);
 }
 
 
@@ -1442,7 +1447,8 @@ x86EncodePolicy(const virCPUDefPtr cpu,
 
 
 static int
-x86Encode(const virCPUDefPtr cpu,
+x86Encode(virArch arch,
+          const virCPUDefPtr cpu,
           virCPUDataPtr *forced,
           virCPUDataPtr *required,
           virCPUDataPtr *optional,
@@ -1522,22 +1528,22 @@ x86Encode(const virCPUDefPtr cpu,
     }
 
     if (forced &&
-        !(*forced = x86MakeCPUData(&data_forced)))
+        !(*forced = x86MakeCPUData(arch, &data_forced)))
         goto error;
     if (required &&
-        !(*required = x86MakeCPUData(&data_required)))
+        !(*required = x86MakeCPUData(arch, &data_required)))
         goto error;
     if (optional &&
-        !(*optional = x86MakeCPUData(&data_optional)))
+        !(*optional = x86MakeCPUData(arch, &data_optional)))
         goto error;
     if (disabled &&
-        !(*disabled = x86MakeCPUData(&data_disabled)))
+        !(*disabled = x86MakeCPUData(arch, &data_disabled)))
         goto error;
     if (forbidden &&
-        !(*forbidden = x86MakeCPUData(&data_forbidden)))
+        !(*forbidden = x86MakeCPUData(arch, &data_forbidden)))
         goto error;
     if (vendor &&
-        !(*vendor = x86MakeCPUData(&data_vendor)))
+        !(*vendor = x86MakeCPUData(arch, &data_vendor)))
         goto error;
 
     ret = 0;
@@ -1646,7 +1652,7 @@ x86NodeData(void)
         goto error;
     data->extended_len = ret;
 
-    if (!(cpuData = x86MakeCPUData(&data)))
+    if (!(cpuData = x86MakeCPUData(virArchFromHost(), &data)))
         goto error;
 
     return cpuData;
@@ -1885,7 +1891,7 @@ static int x86HasFeature(const virCPUDataPtr data,
     if (!(feature = x86FeatureFind(map, name)))
         goto cleanup;
 
-    ret = x86DataIsSubset(data->x86, feature->data) ? 1 : 0;
+    ret = x86DataIsSubset(data->data.x86, feature->data) ? 1 : 0;
 
 cleanup:
     x86MapFree(map);
diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index 8d40f25..5dc3c9e 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -857,7 +857,7 @@ virQEMUCapsInitCPU(virCapsPtr caps,
     ret = 0;
 
 cleanup:
-    cpuDataFree(arch, data);
+    cpuDataFree(data);
 
     return ret;
 
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 30b7bc0..a7c978f 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -5853,8 +5853,7 @@ qemuBuildCpuArgStr(const virQEMUDriverPtr driver,
 
 cleanup:
     VIR_FREE(compare_msg);
-    if (host)
-        cpuDataFree(host->arch, data);
+    cpuDataFree(data);
     virCPUDefFree(guest);
     virCPUDefFree(cpu);
     virObjectUnref(caps);
@@ -9909,7 +9908,7 @@ qemuParseCommandLineCPU(virDomainDefPtr dom,
                 goto cleanup;
 
             is_32bit = (cpuHasFeature(VIR_ARCH_X86_64, cpuData, "lm") != 1);
-            cpuDataFree(VIR_ARCH_X86_64, cpuData);
+            cpuDataFree(cpuData);
         } else if (model) {
             is_32bit = STREQ(model, "qemu32");
         }
diff --git a/src/vmware/vmware_conf.c b/src/vmware/vmware_conf.c
index bb88899..6ef02a9 100644
--- a/src/vmware/vmware_conf.c
+++ b/src/vmware/vmware_conf.c
@@ -115,8 +115,7 @@ vmwareCapsInit(void)
 
 cleanup:
     virCPUDefFree(cpu);
-    if (caps)
-        cpuDataFree(caps->host.arch, data);
+    cpuDataFree(data);
 
     return caps;
 
diff --git a/tests/cputest.c b/tests/cputest.c
index 6708bcf..d3865c4 100644
--- a/tests/cputest.c
+++ b/tests/cputest.c
@@ -308,8 +308,7 @@ cpuTestGuestData(const void *arg)
 
 cleanup:
     VIR_FREE(result);
-    if (host)
-        cpuDataFree(host->arch, guestData);
+    cpuDataFree(guestData);
     virCPUDefFree(host);
     virCPUDefFree(cpu);
     virCPUDefFree(guest);
@@ -445,8 +444,7 @@ cpuTestHasFeature(const void *arg)
     ret = 0;
 
 cleanup:
-    if (host)
-        cpuDataFree(host->arch, hostData);
+    cpuDataFree(hostData);
     virCPUDefFree(host);
     return ret;
 }
-- 
1.8.3.2

--
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]