[libvirt PATCH 3/5] cpu_x86: Implement virCPUDataIsIdentical for x86

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

 



Signed-off-by: Tim Wiederhake <twiederh@xxxxxxxxxx>
---
 src/cpu/cpu_x86.c | 69 +++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 69 insertions(+)

diff --git a/src/cpu/cpu_x86.c b/src/cpu/cpu_x86.c
index 1b829e5658..55da407ec4 100644
--- a/src/cpu/cpu_x86.c
+++ b/src/cpu/cpu_x86.c
@@ -3369,6 +3369,74 @@ virCPUx86DataAddFeature(virCPUData *cpuData,
 }
 
 
+static bool
+virCPUx86DataItemIsIdentical(const virCPUx86DataItem *a,
+                             const virCPUx86DataItem *b)
+{
+    if (a->type != b->type)
+        return false;
+
+    switch (a->type) {
+    case VIR_CPU_X86_DATA_NONE:
+        break;
+
+    case VIR_CPU_X86_DATA_CPUID:
+        return a->data.cpuid.eax_in == b->data.cpuid.eax_in &&
+               a->data.cpuid.ecx_in == b->data.cpuid.ecx_in &&
+               a->data.cpuid.eax == b->data.cpuid.eax &&
+               a->data.cpuid.ebx == b->data.cpuid.ebx &&
+               a->data.cpuid.ecx == b->data.cpuid.ecx &&
+               a->data.cpuid.edx == b->data.cpuid.edx;
+
+    case VIR_CPU_X86_DATA_MSR:
+        return a->data.msr.index == b->data.msr.index &&
+               a->data.msr.eax == b->data.msr.eax &&
+               a->data.msr.edx == b->data.msr.edx;
+    }
+
+    return true;
+}
+
+static virCPUCompareResult
+virCPUx86DataIsIdentical(const virCPUData *a,
+                         const virCPUData *b)
+{
+    const virCPUx86Data *adata;
+    const virCPUx86Data *bdata;
+    size_t i;
+    size_t j;
+
+    if (!a || !b)
+        return VIR_CPU_COMPARE_ERROR;
+
+    if (a->arch != b->arch)
+        return VIR_CPU_COMPARE_INCOMPATIBLE;
+
+    if (!((adata = &a->data.x86) && (bdata = &b->data.x86)))
+        return VIR_CPU_COMPARE_ERROR;
+
+    if (adata->len != bdata->len)
+        return VIR_CPU_COMPARE_INCOMPATIBLE;
+
+    for (i = 0; i < adata->len; ++i) {
+        bool found = false;
+
+        for (j = 0; j < bdata->len; ++j) {
+            if (!virCPUx86DataItemIsIdentical(&adata->items[i],
+                                              &bdata->items[j]))
+                continue;
+
+            found = true;
+            break;
+        }
+
+        if (!found)
+            return VIR_CPU_COMPARE_INCOMPATIBLE;
+    }
+
+    return VIR_CPU_COMPARE_IDENTICAL;
+}
+
 static bool
 virCPUx86FeatureIsMSR(const char *name)
 {
@@ -3452,4 +3520,5 @@ struct cpuArchDriver cpuDriverX86 = {
     .copyMigratable = virCPUx86CopyMigratable,
     .validateFeatures = virCPUx86ValidateFeatures,
     .dataAddFeature = virCPUx86DataAddFeature,
+    .dataIsIdentical = virCPUx86DataIsIdentical,
 };
-- 
2.31.1




[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