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

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

 



Create public function to convert virCPUDef data structure into
qemuMonitorCPUModelInfoPtr data structure.

There was no existing code to reuse to create this function
so this new virQEMUCapsCPUModelInfoFromCPUDef function was based on
reversing the action of the existing virQEMUCapsCPUModelInfoToCPUDef
function.

Signed-off-by: Chris Venteicher <cventeic@xxxxxxxxxx>
---
 src/qemu/qemu_capabilities.c | 52 ++++++++++++++++++++++++++++++++++++
 src/qemu/qemu_capabilities.h |  1 +
 2 files changed, 53 insertions(+)

diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index 2bb56763b0..d0a2a42c97 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -3664,6 +3664,58 @@ virQEMUCapsLoadCache(virArch hostArch,
 }
 
 
+/**
+ * virQEMUCapsCPUModelInfoFromCPUDef:
+ * @cpuDef: input model
+ *
+ * virCPUDef model => qemuMonitorCPUModelInfo name
+ * virCPUDef features => qemuMonitorCPUModelInfo boolean properties
+ *
+ * property have true value if feature policy is undefined (-1), FORCE or REQUIRE
+ * These semantics may need to be modified for other cases.
+ */
+qemuMonitorCPUModelInfoPtr
+virQEMUCapsCPUModelInfoFromCPUDef(const virCPUDef *cpuDef)
+{
+    size_t i;
+    qemuMonitorCPUModelInfoPtr cpuModel = NULL;
+    qemuMonitorCPUModelInfoPtr ret = NULL;
+
+    VIR_DEBUG("cpuDef = %p, cpuDef->model = %s", cpuDef, NULLSTR(cpuDef ? cpuDef->model : NULL));
+
+    if (!cpuDef || (VIR_ALLOC(cpuModel) < 0))
+        goto cleanup;
+
+    if (VIR_STRDUP(cpuModel->name, cpuDef->model) < 0 ||
+        VIR_ALLOC_N(cpuModel->props, cpuDef->nfeatures) < 0)
+        goto cleanup;
+
+    cpuModel->nprops = 0;
+
+    for (i = 0; i < cpuDef->nfeatures; i++) {
+        qemuMonitorCPUPropertyPtr prop = &(cpuModel->props[cpuModel->nprops]);
+        virCPUFeatureDefPtr feature = &(cpuDef->features[i]);
+
+        if (VIR_STRDUP(prop->name, feature->name) < 0)
+            goto cleanup;
+
+        prop->type = QEMU_MONITOR_CPU_PROPERTY_BOOLEAN;
+
+        prop->value.boolean = feature->policy == -1 || /* policy undefined */
+                              feature->policy == VIR_CPU_FEATURE_FORCE ||
+                              feature->policy == VIR_CPU_FEATURE_REQUIRE;
+
+        cpuModel->nprops++;
+    }
+
+    VIR_STEAL_PTR(ret, cpuModel);
+
+ cleanup:
+    qemuMonitorCPUModelInfoFree(cpuModel);
+    return ret;
+}
+
+
 /**
  * virQEMUCapsCPUModelInfoToCPUDef:
  * @model: input model
diff --git a/src/qemu/qemu_capabilities.h b/src/qemu/qemu_capabilities.h
index 834844c1be..e05596ae06 100644
--- a/src/qemu/qemu_capabilities.h
+++ b/src/qemu/qemu_capabilities.h
@@ -583,6 +583,7 @@ int virQEMUCapsGetMachineTypesCaps(virQEMUCapsPtr qemuCaps,
 void virQEMUCapsFilterByMachineType(virQEMUCapsPtr qemuCaps,
                                     const char *machineType);
 
+qemuMonitorCPUModelInfoPtr virQEMUCapsCPUModelInfoFromCPUDef(const virCPUDef *cpuDef);
 virCPUDefPtr virQEMUCapsCPUModelInfoToCPUDef(qemuMonitorCPUModelInfoPtr model,
                                              bool migratable);
 
-- 
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