[PATCH 19/33] cpu_x86: Introduce virCPUx86DataSetVendor

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

 



Signed-off-by: Jiri Denemark <jdenemar@xxxxxxxxxx>
---
 src/cpu/cpu_x86.c        | 45 +++++++++++++++++++++++++++++++++++----------
 src/cpu/cpu_x86.h        |  3 +++
 src/libvirt_private.syms |  1 +
 3 files changed, 39 insertions(+), 10 deletions(-)

diff --git a/src/cpu/cpu_x86.c b/src/cpu/cpu_x86.c
index e3f860bc6..ab5e5257d 100644
--- a/src/cpu/cpu_x86.c
+++ b/src/cpu/cpu_x86.c
@@ -478,6 +478,26 @@ x86DataToVendor(const virCPUx86Data *data,
 }
 
 
+static int
+virCPUx86VendorToCPUID(const char *vendor,
+                       virCPUx86CPUID *cpuid)
+{
+    if (strlen(vendor) != VENDOR_STRING_LENGTH) {
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       _("Invalid CPU vendor string '%s'"), vendor);
+        return -1;
+    }
+
+    cpuid->eax_in = 0;
+    cpuid->ecx_in = 0;
+    cpuid->ebx = virReadBufInt32LE(vendor);
+    cpuid->edx = virReadBufInt32LE(vendor + 4);
+    cpuid->ecx = virReadBufInt32LE(vendor + 8);
+
+    return 0;
+}
+
+
 static uint32_t
 x86MakeSignature(unsigned int family,
                  unsigned int model)
@@ -651,17 +671,9 @@ x86VendorParse(xmlXPathContextPtr ctxt,
                        vendor->name);
         goto error;
     }
-    if (strlen(string) != VENDOR_STRING_LENGTH) {
-        virReportError(VIR_ERR_INTERNAL_ERROR,
-                       _("Invalid CPU vendor string '%s'"), string);
-        goto error;
-    }
 
-    vendor->cpuid.eax_in = 0;
-    vendor->cpuid.ecx_in = 0;
-    vendor->cpuid.ebx = virReadBufInt32LE(string);
-    vendor->cpuid.edx = virReadBufInt32LE(string + 4);
-    vendor->cpuid.ecx = virReadBufInt32LE(string + 8);
+    if (virCPUx86VendorToCPUID(string, &vendor->cpuid) < 0)
+        goto error;
 
  cleanup:
     VIR_FREE(string);
@@ -2731,6 +2743,19 @@ virCPUx86DataSetSignature(virCPUDataPtr cpuData,
 }
 
 
+int
+virCPUx86DataSetVendor(virCPUDataPtr cpuData,
+                       const char *vendor)
+{
+    virCPUx86CPUID cpuid = { 0 };
+
+    if (virCPUx86VendorToCPUID(vendor, &cpuid) < 0)
+        return -1;
+
+    return virCPUx86DataAddCPUID(cpuData, &cpuid);
+}
+
+
 struct cpuArchDriver cpuDriverX86 = {
     .name = "x86",
     .arch = archs,
diff --git a/src/cpu/cpu_x86.h b/src/cpu/cpu_x86.h
index ffbd064b4..ab5394914 100644
--- a/src/cpu/cpu_x86.h
+++ b/src/cpu/cpu_x86.h
@@ -36,4 +36,7 @@ int virCPUx86DataSetSignature(virCPUDataPtr cpuData,
                               unsigned int family,
                               unsigned int model);
 
+int virCPUx86DataSetVendor(virCPUDataPtr cpuData,
+                           const char *vendor);
+
 #endif /* __VIR_CPU_X86_H__ */
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 6b2dddc95..7338c31e7 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1007,6 +1007,7 @@ virCPUUpdate;
 # cpu/cpu_x86.h
 virCPUx86DataAddCPUID;
 virCPUx86DataSetSignature;
+virCPUx86DataSetVendor;
 
 
 # datatypes.h
-- 
2.11.1

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