]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
cpu: Introduce virCPUCheckFeature
authorJiri Denemark <jdenemar@redhat.com>
Fri, 16 Sep 2016 12:13:09 +0000 (14:13 +0200)
committerJiri Denemark <jdenemar@redhat.com>
Thu, 22 Sep 2016 13:40:09 +0000 (15:40 +0200)
The function is similar to virCPUDataCheckFeature, but it works directly
on CPU definition rather than requiring it to be transformed into CPU
data first.

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

index cc7d03ccc7bbbba05ecd5d1daa2bf7fa2abafb60..2ab61d73e7ea8c8e2aa85d5ce1dcf8ad2a4c0354 100644 (file)
@@ -647,6 +647,42 @@ virCPUUpdate(virArch arch,
 }
 
 
+/**
+ * virCPUCheckFeature:
+ *
+ * @arch: CPU architecture
+ * @cpu: CPU definition
+ * @feature: feature to be checked for
+ *
+ * Checks whether @feature is supported by the CPU described by @cpu.
+ *
+ * Returns 1 if the feature is supported, 0 if it's not supported, or
+ * -1 on error.
+ */
+int
+virCPUCheckFeature(virArch arch,
+                   const virCPUDef *cpu,
+                   const char *feature)
+{
+    struct cpuArchDriver *driver;
+
+    VIR_DEBUG("arch=%s, cpu=%p, feature=%s",
+              virArchToString(arch), cpu, feature);
+
+    if (!(driver = cpuGetSubDriver(arch)))
+        return -1;
+
+    if (!driver->checkFeature) {
+        virReportError(VIR_ERR_NO_SUPPORT,
+                       _("cannot check guest CPU feature for %s architecture"),
+                       virArchToString(arch));
+        return -1;
+    }
+
+    return driver->checkFeature(cpu, feature);
+}
+
+
 /**
  * virCPUDataCheckFeature:
  *
index 71fa2dafe5ee876b95176234ad2300b08a0247b5..f14c2c85771928eb1af429344de6737419cbe0d1 100644 (file)
@@ -90,6 +90,10 @@ typedef int
 (*virCPUArchUpdate)(virCPUDefPtr guest,
                     const virCPUDef *host);
 
+typedef int
+(*virCPUArchCheckFeature)(const virCPUDef *cpu,
+                          const char *feature);
+
 typedef int
 (*virCPUArchDataCheckFeature)(const virCPUData *data,
                               const char *feature);
@@ -120,6 +124,7 @@ struct cpuArchDriver {
     cpuArchGuestData    guestData;
     cpuArchBaseline     baseline;
     virCPUArchUpdate    update;
+    virCPUArchCheckFeature checkFeature;
     virCPUArchDataCheckFeature dataCheckFeature;
     cpuArchDataFormat   dataFormat;
     cpuArchDataParse    dataParse;
@@ -193,6 +198,14 @@ virCPUUpdate(virArch arch,
              const virCPUDef *host)
     ATTRIBUTE_NONNULL(2);
 
+
+int
+virCPUCheckFeature(virArch arch,
+                   const virCPUDef *cpu,
+                   const char *feature)
+    ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3);
+
+
 int
 virCPUDataCheckFeature(const virCPUData *data,
                        const char *feature)
index ae552ac247921b79e57d136f859f415fc6a41f8b..7224d76bcc44ecf72b6317b27e148a8a95c60d8d 100644 (file)
@@ -2601,6 +2601,28 @@ virCPUx86Update(virCPUDefPtr guest,
 }
 
 
+static int
+virCPUx86CheckFeature(const virCPUDef *cpu,
+                      const char *name)
+{
+    int ret = -1;
+    virCPUx86MapPtr map;
+    virCPUx86ModelPtr model = NULL;
+
+    if (!(map = virCPUx86GetMap()))
+        return -1;
+
+    if (!(model = x86ModelFromCPU(cpu, map, -1)))
+        goto cleanup;
+
+    ret = x86FeatureInData(name, &model->data, map);
+
+ cleanup:
+    x86ModelFree(model);
+    return ret;
+}
+
+
 static int
 virCPUx86DataCheckFeature(const virCPUData *data,
                           const char *name)
@@ -2709,6 +2731,7 @@ struct cpuArchDriver cpuDriverX86 = {
     .guestData  = x86GuestData,
     .baseline   = x86Baseline,
     .update     = virCPUx86Update,
+    .checkFeature = virCPUx86CheckFeature,
     .dataCheckFeature = virCPUx86DataCheckFeature,
     .dataFormat = x86CPUDataFormat,
     .dataParse  = x86CPUDataParse,
index ab2b693cc9868dd1d6e6eb5ac775b96c13b253ee..4825ab7cc480726d0e6c0cf33f2ace7b8d2e538e 100644 (file)
@@ -980,6 +980,7 @@ cpuEncode;
 cpuGetModels;
 cpuGuestData;
 cpuNodeData;
+virCPUCheckFeature;
 virCPUDataCheckFeature;
 virCPUTranslate;
 virCPUUpdate;
index ce8f8c0062b1760859f8a9fd9a50bcab6374382d..72f00b6254c04a94af165a8405b7306dcfa800ff 100644 (file)
@@ -430,7 +430,11 @@ cpuTestHasFeature(const void *arg)
                   NULL, NULL, NULL, NULL) < 0)
         goto cleanup;
 
-    result = virCPUDataCheckFeature(hostData, data->name);
+    result = virCPUCheckFeature(host->arch, host, data->name);
+
+    if (data->result == result)
+        result = virCPUDataCheckFeature(hostData, data->name);
+
     if (data->result == -1)
         virResetLastError();