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

[libvirt] [PATCH v4 03/37] qemu_capabilities: Introduce virQEMuCapsMigratablePropsDiff



Create an augmented CPUModelInfo identifying which props are/aren't
migratable based on a diff between migratable and non-migratable
inputs.

This patch pulls existing logic out of virQEMUCapsProbeQMPHostCPU
and wraps the existing logic in a standalone function hopefully
simplifying both functions and making the inputs and outputs clearer.

The patch also sets cpuData->info = NULL to make sure bad data does not
remain in failure cases.

Q) Can the right people quickly determine if they should review this?

Signed-off-by: Chris Venteicher <cventeic redhat com>
---
 src/qemu/qemu_capabilities.c | 131 ++++++++++++++++++++++++-----------
 1 file changed, 92 insertions(+), 39 deletions(-)

diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index eb9dca05f8..c8e9b8f65d 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -2355,14 +2355,91 @@ virQEMUCapsProbeQMPCPUDefinitions(virQEMUCapsPtr qemuCaps,
 }
 
 
+/* virQEMUCapsMigratablePropsDiff
+ * @migratable: input where all migratable props have value true
+ * and non-migratable and unsupported props have value false
+ *
+ * @nonMigratable: input where all migratable & non-migratable props
+ * have value true and unsupported props have value false
+ *
+ * @augmented: output including all props listed in @migratable but
+ * both migratable & non-migratable props have value true,
+ * unsupported props have value false,
+ * and prop->migratable is set to VIR_TRISTATE_BOOL_{YES/NO}
+ * for each supported prop
+ *
+ * Differences in expanded CPUModelInfo inputs @migratable and @nonMigratable are
+ * used to create output @augmented where individual props have prop->migratable
+ * set to indicate if prop is or isn't migratable.
+ */
+static int
+virQEMUCapsMigratablePropsDiff(qemuMonitorCPUModelInfoPtr migratable,
+                               qemuMonitorCPUModelInfoPtr nonMigratable,
+                               qemuMonitorCPUModelInfoPtr *augmented)
+{
+    int ret = -1;
+    qemuMonitorCPUModelInfoPtr tmp;
+    qemuMonitorCPUPropertyPtr prop;
+    qemuMonitorCPUPropertyPtr mProp;
+    qemuMonitorCPUPropertyPtr nmProp;
+    virHashTablePtr hash = NULL;
+    size_t i;
+
+    *augmented = NULL;
+
+    if (!(tmp = qemuMonitorCPUModelInfoCopy(migratable)))
+        goto cleanup;
+
+    if (!nonMigratable)
+        goto done;
+
+    if (!(hash = virHashCreate(0, NULL)))
+        goto cleanup;
+
+    for (i = 0; i < tmp->nprops; i++) {
+        prop = tmp->props + i;
+
+        if (virHashAddEntry(hash, prop->name, prop) < 0)
+            goto cleanup;
+    }
+
+    for (i = 0; i < nonMigratable->nprops; i++) {
+        nmProp = nonMigratable->props + i;
+
+        if (!(mProp = virHashLookup(hash, nmProp->name)) ||
+            mProp->type != QEMU_MONITOR_CPU_PROPERTY_BOOLEAN ||
+            mProp->type != nmProp->type)
+            continue;  /* In non-migratable list but not in migratable list */
+
+        if (mProp->value.boolean) {
+            mProp->migratable = VIR_TRISTATE_BOOL_YES;
+        } else if (nmProp->value.boolean) {
+            mProp->value.boolean = true;
+            mProp->migratable = VIR_TRISTATE_BOOL_NO;
+        }
+    }
+
+    tmp->migratability = true;
+
+ done:
+    VIR_STEAL_PTR(*augmented, tmp);
+    ret = 0;
+
+ cleanup:
+    qemuMonitorCPUModelInfoFree(tmp);
+    virHashFree(hash);
+    return ret;
+}
+
+
 static int
 virQEMUCapsProbeQMPHostCPU(virQEMUCapsPtr qemuCaps,
                            qemuMonitorPtr mon,
                            bool tcg)
 {
-    qemuMonitorCPUModelInfoPtr modelInfo = NULL;
+    qemuMonitorCPUModelInfoPtr migratable = NULL;
     qemuMonitorCPUModelInfoPtr nonMigratable = NULL;
-    virHashTablePtr hash = NULL;
+    qemuMonitorCPUModelInfoPtr augmented = NULL;
     const char *model;
     qemuMonitorCPUModelExpansionType type;
     virDomainVirtType virtType;
@@ -2381,6 +2458,7 @@ virQEMUCapsProbeQMPHostCPU(virQEMUCapsPtr qemuCaps,
     }
 
     cpuData = virQEMUCapsGetHostCPUData(qemuCaps, virtType);
+    cpuData->info = NULL;
 
     /* Some x86_64 features defined in cpu_map.xml use spelling which differ
      * from the one preferred by QEMU. Static expansion would give us only the
@@ -2392,54 +2470,29 @@ virQEMUCapsProbeQMPHostCPU(virQEMUCapsPtr qemuCaps,
     else
         type = QEMU_MONITOR_CPU_MODEL_EXPANSION_STATIC;
 
-    if (qemuMonitorGetCPUModelExpansion(mon, type, model, true, &modelInfo) < 0)
+    if (qemuMonitorGetCPUModelExpansion(mon, type, model, true, &migratable) < 0)
+        goto cleanup;
+
+    if (!migratable) {
+        ret = 0;      /* Qemu can't expand the model name, exit without error */
         goto cleanup;
+    }
 
     /* Try to check migratability of each feature. */
-    if (modelInfo &&
-        qemuMonitorGetCPUModelExpansion(mon, type, model, false,
+    if (qemuMonitorGetCPUModelExpansion(mon, type, model, false,
                                         &nonMigratable) < 0)
         goto cleanup;
 
-    if (nonMigratable) {
-        qemuMonitorCPUPropertyPtr prop;
-        qemuMonitorCPUPropertyPtr nmProp;
-        size_t i;
-
-        if (!(hash = virHashCreate(0, NULL)))
-            goto cleanup;
-
-        for (i = 0; i < modelInfo->nprops; i++) {
-            prop = modelInfo->props + i;
-            if (virHashAddEntry(hash, prop->name, prop) < 0)
-                goto cleanup;
-        }
-
-        for (i = 0; i < nonMigratable->nprops; i++) {
-            nmProp = nonMigratable->props + i;
-            if (!(prop = virHashLookup(hash, nmProp->name)) ||
-                prop->type != QEMU_MONITOR_CPU_PROPERTY_BOOLEAN ||
-                prop->type != nmProp->type)
-                continue;
-
-            if (prop->value.boolean) {
-                prop->migratable = VIR_TRISTATE_BOOL_YES;
-            } else if (nmProp->value.boolean) {
-                prop->value.boolean = true;
-                prop->migratable = VIR_TRISTATE_BOOL_NO;
-            }
-        }
-
-        modelInfo->migratability = true;
-    }
+    if (virQEMUCapsMigratablePropsDiff(migratable, nonMigratable, &augmented) < 0)
+        goto cleanup;
 
-    VIR_STEAL_PTR(cpuData->info, modelInfo);
+    VIR_STEAL_PTR(cpuData->info, augmented);
     ret = 0;
 
  cleanup:
-    virHashFree(hash);
+    qemuMonitorCPUModelInfoFree(migratable);
     qemuMonitorCPUModelInfoFree(nonMigratable);
-    qemuMonitorCPUModelInfoFree(modelInfo);
+    qemuMonitorCPUModelInfoFree(augmented);
 
     return ret;
 }
-- 
2.17.1


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