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(a)redhat.com>
---
src/qemu/qemu_capabilities.c | 84 ++++++++++++++++++++++++++----------
src/qemu/qemu_capabilities.h | 3 ++
2 files changed, 64 insertions(+), 23 deletions(-)
diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index 8c5ec4cc9a..74f670459f 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -2819,7 +2819,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) {
@@ -2832,32 +2833,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(migratable, modelInfo)))
+ 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;
}
@@ -3655,6 +3642,57 @@ virQEMUCapsLoadCache(virArch hostArch,
}
+/* qemuMonitorCPUModelInfo name => virCPUDef model
+ * qemuMonitorCPUModelInfo boolean properties => virCPUDef features
+ *
+ * migratable true: mark non-migratable features as disabled
+ * false: allow all features as required
+ */
+virCPUDefPtr
+virQEMUCapsCPUModelInfoToCPUDef(bool migratable, qemuMonitorCPUModelInfoPtr model)
+{
+ virCPUDefPtr cpu = NULL;
+ virCPUDefPtr ret = NULL;
+ size_t i;
+
+ if (!model || VIR_ALLOC(cpu) < 0)
+ goto cleanup;
+
+ VIR_DEBUG("model->name= %s", NULLSTR(model->name));
+
+ 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 b1990b6bb8..52e36e76b6 100644
--- a/src/qemu/qemu_capabilities.h
+++ b/src/qemu/qemu_capabilities.h
@@ -579,6 +579,9 @@ int virQEMUCapsGetMachineTypesCaps(virQEMUCapsPtr qemuCaps,
void virQEMUCapsFilterByMachineType(virQEMUCapsPtr qemuCaps,
const char *machineType);
+virCPUDefPtr virQEMUCapsCPUModelInfoToCPUDef(bool migratable,
+ qemuMonitorCPUModelInfoPtr model);
+
virFileCachePtr virQEMUCapsCacheNew(const char *libDir,
const char *cacheDir,
uid_t uid,
--
2.17.1