I've opened BZ 697141 on this as I would consider it more
a bug than a feature request.  Anyway, to re-iterate my
rationale from the BZ:


The virConnectGetCapabilities API describes the host capabilities
by returning an XML description that includes the CPU model name
and a set of CPU features.  The problem is that any features that
are part of the CPU model are not explicitly listed, they are
assumed to be part of the definition of that CPU model.  This
makes it extremely difficult for the caller of this API to check
for the presence of a specific CPU feature, the caller would have
to know what features are part of which CPU models, a very
daunting task.

This patch solves this problem by having the API return a model
name, as it currently does, but it will also explicitly list all
of the CPU features that are present.  This would make it much
easier for a caller of this API to check for specific features.

Signed-off-by: Don Dugger <donald.d.dug...@intel.com>

---
 src/cpu/cpu_x86.c |   30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)

diff --git a/src/cpu/cpu_x86.c b/src/cpu/cpu_x86.c
index 5d479c2..b2e16df 100644
--- a/src/cpu/cpu_x86.c
+++ b/src/cpu/cpu_x86.c
@@ -1296,6 +1296,35 @@ x86GuestData(virCPUDefPtr host,
     return x86Compute(host, guest, data, message);
 }
 
+static void
+x86AddFeatures(virCPUDefPtr cpu,
+              struct x86_map *map)
+{
+    const struct x86_model *candidate;
+    const struct x86_feature *feature = map->features;
+
+    candidate = map->models;
+    while (candidate != NULL) {
+       if (STREQ(cpu->model, candidate->name))
+           break;
+       candidate = candidate->next;
+    }
+    if (!candidate) {
+       VIR_WARN("Odd, %s not a known CPU model\n", cpu->model);
+       return;
+    }
+    while (feature != NULL) {
+       if (x86DataIsSubset(candidate->data, feature->data)) {
+           if (virCPUDefAddFeature(cpu, feature->name, 
VIR_CPU_FEATURE_DISABLE) < 0) {
+               VIR_WARN("CPU model %s, no room for feature %s", cpu->model, 
feature->name);
+               return;
+           }
+       }
+       feature = feature->next;
+    }
+    return;
+}
+
 
 static int
 x86Decode(virCPUDefPtr cpu,
@@ -1383,6 +1412,7 @@ x86Decode(virCPUDefPtr cpu,
         goto out;
     }
 
+    x86AddFeatures(cpuModel, map);
     cpu->model = cpuModel->model;
     cpu->vendor = cpuModel->vendor;
     cpu->nfeatures = cpuModel->nfeatures;
-- 
1.7.10.4

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Reply via email to