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

[libvirt] [PATCH V2] Expose all CPU features in host definition



[V2 - Improve the error handling]

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 dugger intel com>

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

diff --git a/src/cpu/cpu_x86.c b/src/cpu/cpu_x86.c
index 5d479c2..098ab05 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 int
+x86AddFeatures(virCPUDefPtr cpu,
+               struct x86_map *map)
+{
+    int ret;
+    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) {
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       "Odd, %s not a known CPU model\n", cpu->model);
+        return -1;
+    }
+    while (feature != NULL) {
+        if (x86DataIsSubset(candidate->data, feature->data)) {
+            if ((ret = virCPUDefAddFeature(cpu, feature->name, VIR_CPU_FEATURE_DISABLE)) < 0)
+                return ret;
+        }
+        feature = feature->next;
+    }
+    return 0;
+}
+
 
 static int
 x86Decode(virCPUDefPtr cpu,
@@ -1383,6 +1412,8 @@ x86Decode(virCPUDefPtr cpu,
         goto out;
     }
 
+    if (x86AddFeatures(cpuModel, map) < 0)
+        goto out;
     cpu->model = cpuModel->model;
     cpu->vendor = cpuModel->vendor;
     cpu->nfeatures = cpuModel->nfeatures;
-- 
1.7.10.4


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