[libvirt] [PATCH 1/5] qemu: save image: Split out user provided XML checker

Peter Krempa pkrempa at redhat.com
Wed Sep 17 15:18:35 UTC 2014


Extract code used to check save image XMLs provided by users to separate
use.
---
 src/qemu/qemu_driver.c | 100 ++++++++++++++++++++++++++++++++-----------------
 1 file changed, 66 insertions(+), 34 deletions(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 15ad64d..e41a08e 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -5311,6 +5311,68 @@ static int qemuNodeGetSecurityModel(virConnectPtr conn,
     return ret;
 }

+
+/**
+ * qemuDomainSaveImageUpdateDef:
+ * @driver: qemu driver data
+ * @def: def of the domain from the save image
+ * @newxml: user provided replacement XML
+ *
+ * Returns the new domain definition in case @newxml is ABI compatible with the
+ * guest.
+ */
+static virDomainDefPtr
+qemuDomainSaveImageUpdateDef(virQEMUDriverPtr driver,
+                             virDomainDefPtr def,
+                             const char *newxml)
+{
+    virDomainDefPtr ret = NULL;
+    virDomainDefPtr newdef_migr = NULL;
+    virDomainDefPtr newdef = NULL;
+    virCapsPtr caps = NULL;
+
+    if (!(caps = virQEMUDriverGetCapabilities(driver, false)))
+        goto cleanup;
+
+    if (!(newdef = virDomainDefParseString(newxml, caps, driver->xmlopt,
+                                           QEMU_EXPECTED_VIRT_TYPES,
+                                           VIR_DOMAIN_XML_INACTIVE)))
+        goto cleanup;
+
+    if (!(newdef_migr = qemuDomainDefCopy(driver,
+                                          newdef,
+                                          VIR_DOMAIN_XML_MIGRATABLE)))
+        goto cleanup;
+
+    if (!virDomainDefCheckABIStability(def, newdef_migr)) {
+        virResetLastError();
+
+        /* Due to a bug in older version of external snapshot creation
+         * code, the XML saved in the save image was not a migratable
+         * XML. To ensure backwards compatibility with the change of the
+         * saved XML type, we need to check the ABI compatibility against
+         * the user provided XML if the check against the migratable XML
+         * fails. Snapshots created prior to v1.1.3 have this issue. */
+        if (!virDomainDefCheckABIStability(def, newdef))
+            goto cleanup;
+
+        /* use the user provided XML */
+        ret = newdef;
+        newdef = NULL;
+    } else {
+        ret = newdef_migr;
+        newdef_migr = NULL;
+    }
+
+ cleanup:
+    virObjectUnref(caps);
+    virDomainDefFree(newdef);
+    virDomainDefFree(newdef_migr);
+
+    return ret;
+}
+
+
 /* Return -1 on most failures after raising error, -2 if edit was specified
  * but xmlin and state (-1 for no change, 0 for paused, 1 for running) do
  * not represent any changes (no error raised), -3 if corrupt image was
@@ -5431,45 +5493,15 @@ qemuDomainSaveImageOpen(virQEMUDriverPtr driver,
                                         QEMU_EXPECTED_VIRT_TYPES,
                                         VIR_DOMAIN_XML_INACTIVE)))
         goto error;
-    if (xmlin) {
-        virDomainDefPtr def2 = NULL;
-        virDomainDefPtr newdef = NULL;

-        if (!(def2 = virDomainDefParseString(xmlin, caps, driver->xmlopt,
-                                             QEMU_EXPECTED_VIRT_TYPES,
-                                             VIR_DOMAIN_XML_INACTIVE)))
-            goto error;
+    if (xmlin) {
+        virDomainDefPtr tmp;

-        newdef = qemuDomainDefCopy(driver, def2, VIR_DOMAIN_XML_MIGRATABLE);
-        if (!newdef) {
-            virDomainDefFree(def2);
+        if (!(tmp = qemuDomainSaveImageUpdateDef(driver, def, xmlin)))
             goto error;
-        }
-
-        if (!virDomainDefCheckABIStability(def, newdef)) {
-            virDomainDefFree(newdef);
-            virResetLastError();
-
-            /* Due to a bug in older version of external snapshot creation
-             * code, the XML saved in the save image was not a migratable
-             * XML. To ensure backwards compatibility with the change of the
-             * saved XML type, we need to check the ABI compatibility against
-             * the user provided XML if the check against the migratable XML
-             * fails. Snapshots created prior to v1.1.3 have this issue. */
-            if (!virDomainDefCheckABIStability(def, def2)) {
-                virDomainDefFree(def2);
-                goto error;
-            }
-
-            /* use the user provided XML */
-            newdef = def2;
-            def2 = NULL;
-        } else {
-            virDomainDefFree(def2);
-        }

         virDomainDefFree(def);
-        def = newdef;
+        def = tmp;
     }

     VIR_FREE(xml);
-- 
2.1.0




More information about the libvir-list mailing list