[PATCH v2 2/5] qemu: Move common parts of Prepare phase to qemu_migration.c

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

 



---
 src/qemu/qemu_driver.c    | 120 +++++++---------------------------------------
 src/qemu/qemu_migration.c |  44 +++++++++++++++++
 src/qemu/qemu_migration.h |   4 ++
 3 files changed, 65 insertions(+), 103 deletions(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 863923d..4a17b64 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -9962,25 +9962,14 @@ qemuDomainMigratePrepareTunnel(virConnectPtr dconn,
                                const char *dom_xml)
 {
     virQEMUDriverPtr driver = dconn->privateData;
-    virCapsPtr caps = NULL;
     virDomainDefPtr def = NULL;
     int ret = -1;
 
     virCheckFlags(QEMU_MIGRATION_FLAGS, -1);
 
-    if (!dom_xml) {
-        virReportError(VIR_ERR_INTERNAL_ERROR,
-                       "%s", _("no domain XML passed"));
-        goto cleanup;
-    }
     if (!(flags & VIR_MIGRATE_TUNNELLED)) {
-        virReportError(VIR_ERR_INTERNAL_ERROR,
-                       "%s", _("PrepareTunnel called but no TUNNELLED flag set"));
-        goto cleanup;
-    }
-    if (st == NULL) {
-        virReportError(VIR_ERR_INTERNAL_ERROR,
-                       "%s", _("tunnelled migration requested but NULL stream passed"));
+        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                       _("PrepareTunnel called but no TUNNELLED flag set"));
         goto cleanup;
     }
 
@@ -9991,20 +9980,9 @@ qemuDomainMigratePrepareTunnel(virConnectPtr dconn,
         goto cleanup;
     }
 
-    if (!(caps = virQEMUDriverGetCapabilities(driver, false)))
+    if (!(def = qemuMigrationPrepareDef(driver, dom_xml, dname)))
         goto cleanup;
 
-    if (!(def = virDomainDefParseString(dom_xml, caps, driver->xmlopt,
-                                        QEMU_EXPECTED_VIRT_TYPES,
-                                        VIR_DOMAIN_XML_INACTIVE)))
-        goto cleanup;
-
-    if (dname) {
-        VIR_FREE(def->name);
-        if (VIR_STRDUP(def->name, dname) < 0)
-            goto cleanup;
-    }
-
     if (virDomainMigratePrepareTunnelEnsureACL(dconn, def) < 0)
         goto cleanup;
 
@@ -10014,7 +9992,6 @@ qemuDomainMigratePrepareTunnel(virConnectPtr dconn,
 
 cleanup:
     virDomainDefFree(def);
-    virObjectUnref(caps);
     return ret;
 }
 
@@ -10034,50 +10011,31 @@ qemuDomainMigratePrepare2(virConnectPtr dconn,
                           const char *dom_xml)
 {
     virQEMUDriverPtr driver = dconn->privateData;
-    virCapsPtr caps = NULL;
     virDomainDefPtr def = NULL;
     int ret = -1;
 
     virCheckFlags(QEMU_MIGRATION_FLAGS, -1);
 
-    *uri_out = NULL;
-
-    if (virLockManagerPluginUsesState(driver->lockManager)) {
-        virReportError(VIR_ERR_INTERNAL_ERROR,
-                       _("Cannot use migrate v2 protocol with lock manager %s"),
-                       virLockManagerPluginGetName(driver->lockManager));
-        goto cleanup;
-    }
-
     if (flags & VIR_MIGRATE_TUNNELLED) {
         /* this is a logical error; we never should have gotten here with
          * VIR_MIGRATE_TUNNELLED set
          */
-        virReportError(VIR_ERR_INTERNAL_ERROR,
-                       "%s", _("Tunnelled migration requested but invalid RPC method called"));
+        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                       _("Tunnelled migration requested but invalid "
+                         "RPC method called"));
         goto cleanup;
     }
 
-    if (!dom_xml) {
+    if (virLockManagerPluginUsesState(driver->lockManager)) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
-                       "%s", _("no domain XML passed"));
+                       _("Cannot use migrate v2 protocol with lock manager %s"),
+                       virLockManagerPluginGetName(driver->lockManager));
         goto cleanup;
     }
 
-    if (!(caps = virQEMUDriverGetCapabilities(driver, false)))
+    if (!(def = qemuMigrationPrepareDef(driver, dom_xml, dname)))
         goto cleanup;
 
-    if (!(def = virDomainDefParseString(dom_xml, caps, driver->xmlopt,
-                                        QEMU_EXPECTED_VIRT_TYPES,
-                                        VIR_DOMAIN_XML_INACTIVE)))
-        goto cleanup;
-
-    if (dname) {
-        VIR_FREE(def->name);
-        if (VIR_STRDUP(def->name, dname) < 0)
-            goto cleanup;
-    }
-
     if (virDomainMigratePrepare2EnsureACL(dconn, def) < 0)
         goto cleanup;
 
@@ -10092,7 +10050,6 @@ qemuDomainMigratePrepare2(virConnectPtr dconn,
 
 cleanup:
     virDomainDefFree(def);
-    virObjectUnref(caps);
     return ret;
 }
 
@@ -10230,43 +10187,24 @@ qemuDomainMigratePrepare3(virConnectPtr dconn,
                           const char *dom_xml)
 {
     virQEMUDriverPtr driver = dconn->privateData;
-    virCapsPtr caps = NULL;
     virDomainDefPtr def = NULL;
     int ret = -1;
 
     virCheckFlags(QEMU_MIGRATION_FLAGS, -1);
 
-    *uri_out = NULL;
-
     if (flags & VIR_MIGRATE_TUNNELLED) {
         /* this is a logical error; we never should have gotten here with
          * VIR_MIGRATE_TUNNELLED set
          */
-        virReportError(VIR_ERR_INTERNAL_ERROR,
-                       "%s", _("Tunnelled migration requested but invalid RPC method called"));
-        goto cleanup;
-    }
-
-    if (!dom_xml) {
-        virReportError(VIR_ERR_INTERNAL_ERROR,
-                       "%s", _("no domain XML passed"));
+        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                       _("Tunnelled migration requested but invalid "
+                         "RPC method called"));
         goto cleanup;
     }
 
-    if (!(caps = virQEMUDriverGetCapabilities(driver, false)))
+    if (!(def = qemuMigrationPrepareDef(driver, dom_xml, dname)))
         goto cleanup;
 
-    if (!(def = virDomainDefParseString(dom_xml, caps, driver->xmlopt,
-                                        QEMU_EXPECTED_VIRT_TYPES,
-                                        VIR_DOMAIN_XML_INACTIVE)))
-        goto cleanup;
-
-    if (dname) {
-        VIR_FREE(def->name);
-        if (VIR_STRDUP(def->name, dname) < 0)
-            goto cleanup;
-    }
-
     if (virDomainMigratePrepare3EnsureACL(dconn, def) < 0)
         goto cleanup;
 
@@ -10278,7 +10216,6 @@ qemuDomainMigratePrepare3(virConnectPtr dconn,
 
 cleanup:
     virDomainDefFree(def);
-    virObjectUnref(caps);
     return ret;
 }
 
@@ -10296,42 +10233,20 @@ qemuDomainMigratePrepareTunnel3(virConnectPtr dconn,
                                 const char *dom_xml)
 {
     virQEMUDriverPtr driver = dconn->privateData;
-    virCapsPtr caps = NULL;
     virDomainDefPtr def = NULL;
     int ret = -1;
 
     virCheckFlags(QEMU_MIGRATION_FLAGS, -1);
 
-    if (!dom_xml) {
-        virReportError(VIR_ERR_INTERNAL_ERROR,
-                       "%s", _("no domain XML passed"));
-        goto cleanup;
-    }
     if (!(flags & VIR_MIGRATE_TUNNELLED)) {
-        virReportError(VIR_ERR_INTERNAL_ERROR,
-                       "%s", _("PrepareTunnel called but no TUNNELLED flag set"));
-        goto cleanup;
-    }
-    if (st == NULL) {
-        virReportError(VIR_ERR_INTERNAL_ERROR,
-                       "%s", _("tunnelled migration requested but NULL stream passed"));
+        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                       _("PrepareTunnel called but no TUNNELLED flag set"));
         goto cleanup;
     }
 
-    if (!(caps = virQEMUDriverGetCapabilities(driver, false)))
-        goto cleanup;
-
-    if (!(def = virDomainDefParseString(dom_xml, caps, driver->xmlopt,
-                                        QEMU_EXPECTED_VIRT_TYPES,
-                                        VIR_DOMAIN_XML_INACTIVE)))
+    if (!(def = qemuMigrationPrepareDef(driver, dom_xml, dname)))
         goto cleanup;
 
-    if (dname) {
-        VIR_FREE(def->name);
-        if (VIR_STRDUP(def->name, dname) < 0)
-            goto cleanup;
-    }
-
     if (virDomainMigratePrepareTunnel3EnsureACL(dconn, def) < 0)
         goto cleanup;
 
@@ -10342,7 +10257,6 @@ qemuDomainMigratePrepareTunnel3(virConnectPtr dconn,
 
 cleanup:
     virDomainDefFree(def);
-    virObjectUnref(caps);
     return ret;
 }
 
diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c
index 9e2d043..5d3b3c9 100644
--- a/src/qemu/qemu_migration.c
+++ b/src/qemu/qemu_migration.c
@@ -2442,6 +2442,12 @@ qemuMigrationPrepareTunnel(virQEMUDriverPtr driver,
               driver, dconn, NULLSTR(cookiein), cookieinlen,
               cookieout, cookieoutlen, st, *def, flags);
 
+    if (st == NULL) {
+        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                       _("tunnelled migration requested but NULL stream passed"));
+        return -1;
+    }
+
     ret = qemuMigrationPrepareAny(driver, dconn, cookiein, cookieinlen,
                                   cookieout, cookieoutlen, def,
                                   st, 0, flags);
@@ -2476,6 +2482,8 @@ qemuMigrationPrepareDirect(virQEMUDriverPtr driver,
               cookieout, cookieoutlen, NULLSTR(uri_in), uri_out,
               *def, flags);
 
+    *uri_out = NULL;
+
     /* The URI passed in may be NULL or a string "tcp://somehostname:port".
      *
      * If the URI passed in is NULL then we allocate a port number
@@ -2580,6 +2588,42 @@ cleanup:
 }
 
 
+virDomainDefPtr
+qemuMigrationPrepareDef(virQEMUDriverPtr driver,
+                        const char *dom_xml,
+                        const char *dname)
+{
+    virCapsPtr caps = NULL;
+    virDomainDefPtr def;
+
+    if (!dom_xml) {
+        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                       _("no domain XML passed"));
+        return NULL;
+    }
+
+    if (!(caps = virQEMUDriverGetCapabilities(driver, false)))
+        return NULL;
+
+    if (!(def = virDomainDefParseString(dom_xml, caps, driver->xmlopt,
+                                        QEMU_EXPECTED_VIRT_TYPES,
+                                        VIR_DOMAIN_XML_INACTIVE)))
+        goto cleanup;
+
+    if (dname) {
+        VIR_FREE(def->name);
+        if (VIR_STRDUP(def->name, dname) < 0) {
+            virDomainDefFree(def);
+            def = NULL;
+        }
+    }
+
+cleanup:
+    virObjectUnref(caps);
+    return def;
+}
+
+
 enum qemuMigrationDestinationType {
     MIGRATION_DEST_HOST,
     MIGRATION_DEST_CONNECT_HOST,
diff --git a/src/qemu/qemu_migration.h b/src/qemu/qemu_migration.h
index 09b5b1a..fdca583 100644
--- a/src/qemu/qemu_migration.h
+++ b/src/qemu/qemu_migration.h
@@ -92,6 +92,10 @@ char *qemuMigrationBegin(virConnectPtr conn,
                          int *cookieoutlen,
                          unsigned long flags);
 
+virDomainDefPtr qemuMigrationPrepareDef(virQEMUDriverPtr driver,
+                                        const char *dom_xml,
+                                        const char *dname);
+
 int qemuMigrationPrepareTunnel(virQEMUDriverPtr driver,
                                virConnectPtr dconn,
                                const char *cookiein,
-- 
1.8.2.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]