]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
cpu_x86: Introduce virCPUx86DataSetVendor
authorJiri Denemark <jdenemar@redhat.com>
Thu, 2 Feb 2017 19:12:38 +0000 (20:12 +0100)
committerJiri Denemark <jdenemar@redhat.com>
Fri, 24 Feb 2017 13:10:57 +0000 (14:10 +0100)
The API is useful for creating virCPUData in a hypervisor driver from
data we got by querying the hypervisor.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
src/cpu/cpu_x86.c
src/cpu/cpu_x86.h
src/libvirt_private.syms

index e3f860bc6a218e02ba08d44f7f6f2df849e55d6a..ab5e5257dbf4a2eecb10b5e1571f69700f9bd39c 100644 (file)
@@ -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,
index ffbd064b461e9bc78fcbe41db5c7a4f1e110601c..ab539491498011514a72ea63f201904cb69bdf59 100644 (file)
@@ -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__ */
index f92cb31f8ec4cc71dfb670329788817c88dd60e0..0dda65a2bce59614e15829a5ded67cac7775cde7 100644 (file)
@@ -1004,6 +1004,7 @@ virCPUUpdate;
 # cpu/cpu_x86.h
 virCPUx86DataAddCPUID;
 virCPUx86DataSetSignature;
+virCPUx86DataSetVendor;
 
 
 # datatypes.h