[libvirt] [PATCH v3 17/20] cpu: Implement backwards compatibility in the ppc64 driver

Andrea Bolognani abologna at redhat.com
Mon Aug 10 08:55:59 UTC 2015


All previously recognized CPU models (POWER7_v2.1, POWER7_v2.3,
POWER7+_v2.1 and POWER8_v1.0) are internally converted to the
corrisponding generation name so that existing guests don't stop
working.
---
 src/cpu/cpu_ppc64.c | 36 ++++++++++++++++++++++++++++++++++--
 1 file changed, 34 insertions(+), 2 deletions(-)

diff --git a/src/cpu/cpu_ppc64.c b/src/cpu/cpu_ppc64.c
index bf8f4da..d87e0d1 100644
--- a/src/cpu/cpu_ppc64.c
+++ b/src/cpu/cpu_ppc64.c
@@ -57,6 +57,33 @@ struct ppc64_map {
     struct ppc64_model *models;
 };
 
+/* Convert a legacy CPU definition by transforming
+ * model names to generation names:
+ *   POWER7_v2.1  => POWER7
+ *   POWER7_v2.3  => POWER7
+ *   POWER7+_v2.1 => POWER7
+ *   POWER8_v1.0  => POWER8 */
+static virCPUDefPtr
+ppc64LegacyConvertCPUDef(const virCPUDef *legacy)
+{
+    virCPUDefPtr cpu;
+
+    if (!(cpu = virCPUDefCopy(legacy)))
+        goto out;
+
+    if (!(STREQ(cpu->model, "POWER7_v2.1") ||
+          STREQ(cpu->model, "POWER7_v2.3") ||
+          STREQ(cpu->model, "POWER7+_v2.1") ||
+          STREQ(cpu->model, "POWER8_v1.0"))) {
+        goto out;
+    }
+
+    cpu->model[strlen("POWERx")] = 0;
+
+ out:
+    return cpu;
+}
+
 static void
 ppc64DataFree(virCPUppc64Data *data)
 {
@@ -426,18 +453,22 @@ ppc64MakeCPUData(virArch arch,
 
 static virCPUCompareResult
 ppc64Compute(virCPUDefPtr host,
-             const virCPUDef *cpu,
+             const virCPUDef *other,
              virCPUDataPtr *guestData,
              char **message)
 {
     struct ppc64_map *map = NULL;
     struct ppc64_model *host_model = NULL;
     struct ppc64_model *guest_model = NULL;
-
+    virCPUDefPtr cpu = NULL;
     virCPUCompareResult ret = VIR_CPU_COMPARE_ERROR;
     virArch arch;
     size_t i;
 
+    /* Ensure existing configurations are handled correctly */
+    if (!(cpu = ppc64LegacyConvertCPUDef(other)))
+        goto cleanup;
+
     if (cpu->arch != VIR_ARCH_NONE) {
         bool found = false;
 
@@ -506,6 +537,7 @@ ppc64Compute(virCPUDefPtr host,
     ret = VIR_CPU_COMPARE_IDENTICAL;
 
  cleanup:
+    virCPUDefFree(cpu);
     ppc64MapFree(map);
     ppc64ModelFree(host_model);
     ppc64ModelFree(guest_model);
-- 
2.4.3




More information about the libvir-list mailing list