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@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 dd7c07f6e2..dcd6ffb876 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -2797,7 +2797,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) {
@@ -2810,32 +2811,18 @@ virQEMUCapsInitCPUModelS390(virQEMUCapsPtr qemuCaps,
return 2;
}
- if (VIR_STRDUP(cpu->model, modelInfo->name) < 0 ||
- VIR_ALLOC_N(cpu->features, modelInfo->nprops) < 0)
- return -1;
-
- cpu->nfeatures_max = modelInfo->nprops;
- cpu->nfeatures = 0;
-
- for (i = 0; i < modelInfo->nprops; i++) {
- virCPUFeatureDefPtr feature = cpu->features + cpu->nfeatures;
- qemuMonitorCPUPropertyPtr prop = modelInfo->props + i;
+ if (!(tmp = virQEMUCapsCPUModelInfoToCPUDef(migratable, modelInfo)))
+ goto cleanup;
- if (prop->type != QEMU_MONITOR_CPU_PROPERTY_BOOLEAN)
- continue;
+ /* Free original then copy over model, vendor, vendor_id and features */
+ virCPUDefStealModel(cpu, tmp, true);
- if (VIR_STRDUP(feature->name, prop->name) < 0)
- return -1;
+ ret = 0;
- 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++;
- }
+ cleanup:
+ virCPUDefFree(tmp);
- return 0;
+ return ret;
}
@@ -3633,6 +3620,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 6bb9a2c8f0..a377d7b912 100644
--- a/src/qemu/qemu_capabilities.h
+++ b/src/qemu/qemu_capabilities.h
@@ -572,6 +572,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
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list