[PATCH v6 25/33] qemu_capabilities: Introduce CPUModelInfo to virCPUDef function

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

 



Move existing code to convert between cpu model info structures
(qemuMonitorCPUModelInfoPtr into virCPUDef)
into a reusable function.

The new function is used in this and future patches.

Signed-off-by: Chris Venteicher <cventeic@xxxxxxxxxx>
---
 src/qemu/qemu_capabilities.c | 88 ++++++++++++++++++++++++++----------
 src/qemu/qemu_capabilities.h |  3 ++
 2 files changed, 68 insertions(+), 23 deletions(-)

diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index 463c803416..2bb56763b0 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -2834,7 +2834,8 @@ virQEMUCapsInitCPUModelS390(virQEMUCapsPtr qemuCaps,
                             virCPUDefPtr cpu,
                             bool migratable)
 {
-    size_t i;
+    virCPUDefPtr tmp = NULL;
+    int ret = -1;
 
     if (!modelInfo) {
         if (type == VIR_DOMAIN_VIRT_KVM) {
@@ -2847,32 +2848,18 @@ virQEMUCapsInitCPUModelS390(virQEMUCapsPtr qemuCaps,
         return 2;
     }
 
-    if (VIR_STRDUP(cpu->model, modelInfo->name) < 0 ||
-        VIR_ALLOC_N(cpu->features, modelInfo->nprops) < 0)
-        return -1;
+    if (!(tmp = virQEMUCapsCPUModelInfoToCPUDef(modelInfo, migratable)))
+        goto cleanup;
 
-    cpu->nfeatures_max = modelInfo->nprops;
-    cpu->nfeatures = 0;
+    /* Free original then copy over model, vendor, vendor_id and features */
+    virCPUDefStealModel(cpu, tmp, true);
 
-    for (i = 0; i < modelInfo->nprops; i++) {
-        virCPUFeatureDefPtr feature = cpu->features + cpu->nfeatures;
-        qemuMonitorCPUPropertyPtr prop = modelInfo->props + i;
+    ret = 0;
 
-        if (prop->type != QEMU_MONITOR_CPU_PROPERTY_BOOLEAN)
-            continue;
+ cleanup:
+    virCPUDefFree(tmp);
 
-        if (VIR_STRDUP(feature->name, prop->name) < 0)
-            return -1;
-
-        if (!prop->value.boolean ||
-            (migratable && prop->migratable == VIR_TRISTATE_BOOL_NO))
-            feature->policy = VIR_CPU_FEATURE_DISABLE;
-        else
-            feature->policy = VIR_CPU_FEATURE_REQUIRE;
-        cpu->nfeatures++;
-    }
-
-    return 0;
+    return ret;
 }
 
 
@@ -3677,6 +3664,61 @@ virQEMUCapsLoadCache(virArch hostArch,
 }
 
 
+/**
+ * virQEMUCapsCPUModelInfoToCPUDef:
+ * @model: input model
+ * @migratable: mark non-migratable features as disabled if true else allow all
+ *
+ * qemuMonitorCPUModelInfo name => virCPUDef model
+ * qemuMonitorCPUModelInfo boolean properties => virCPUDef features
+ */
+virCPUDefPtr
+virQEMUCapsCPUModelInfoToCPUDef(qemuMonitorCPUModelInfoPtr model,
+                                bool migratable)
+{
+    virCPUDefPtr cpu = NULL;
+    virCPUDefPtr ret = NULL;
+    size_t i;
+
+    VIR_DEBUG("model= %p, model->name= %s", model, NULLSTR(model ? model->name : NULL));
+
+    if (!model || VIR_ALLOC(cpu) < 0)
+        goto cleanup;
+
+    if (VIR_STRDUP(cpu->model, model->name) < 0 ||
+        VIR_ALLOC_N(cpu->features, model->nprops) < 0)
+        goto cleanup;
+
+    cpu->nfeatures_max = model->nprops;
+    cpu->nfeatures = 0;
+
+    for (i = 0; i < model->nprops; i++) {
+        virCPUFeatureDefPtr feature = cpu->features + cpu->nfeatures;
+        qemuMonitorCPUPropertyPtr prop = model->props + i;
+
+        if (prop->type != QEMU_MONITOR_CPU_PROPERTY_BOOLEAN)
+            continue;
+
+        if (VIR_STRDUP(feature->name, prop->name) < 0)
+            goto cleanup;
+
+        if (!prop->value.boolean ||
+            (migratable && prop->migratable == VIR_TRISTATE_BOOL_NO))
+            feature->policy = VIR_CPU_FEATURE_DISABLE;
+        else
+            feature->policy = VIR_CPU_FEATURE_REQUIRE;
+
+        cpu->nfeatures++;
+    }
+
+    VIR_STEAL_PTR(ret, cpu);
+
+ cleanup:
+    virCPUDefFree(cpu);
+    return ret;
+}
+
+
 static void
 virQEMUCapsFormatHostCPUModelInfo(virQEMUCapsPtr qemuCaps,
                                   virBufferPtr buf,
diff --git a/src/qemu/qemu_capabilities.h b/src/qemu/qemu_capabilities.h
index 6d5ed8a3cc..834844c1be 100644
--- a/src/qemu/qemu_capabilities.h
+++ b/src/qemu/qemu_capabilities.h
@@ -583,6 +583,9 @@ int virQEMUCapsGetMachineTypesCaps(virQEMUCapsPtr qemuCaps,
 void virQEMUCapsFilterByMachineType(virQEMUCapsPtr qemuCaps,
                                     const char *machineType);
 
+virCPUDefPtr virQEMUCapsCPUModelInfoToCPUDef(qemuMonitorCPUModelInfoPtr model,
+                                             bool migratable);
+
 virFileCachePtr virQEMUCapsCacheNew(const char *libDir,
                                     const char *cacheDir,
                                     uid_t uid,
-- 
2.17.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