[PATCH 12/21] qemu: Move internals of Begin phase to qemu_migration.c

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

 



---
 src/qemu/qemu_driver.c    | 99 +++++++----------------------------------------
 src/qemu/qemu_migration.c | 98 +++++++++++++++++++++++++++++++++++++++++-----
 src/qemu/qemu_migration.h |  1 +
 3 files changed, 105 insertions(+), 93 deletions(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index c040287..14397f5 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -9888,86 +9888,6 @@ cleanup:
  *******************************************************************/
 
 static char *
-qemuDomainMigrateBegin3Internal(virDomainPtr domain,
-                                const char *xmlin,
-                                const char *dname,
-                                char **cookieout,
-                                int *cookieoutlen,
-                                unsigned long flags)
-{
-    virQEMUDriverPtr driver = domain->conn->privateData;
-    virDomainObjPtr vm;
-    char *xml = NULL;
-    enum qemuDomainAsyncJob asyncJob;
-
-    if (!(vm = qemuDomObjFromDomain(domain)))
-        return NULL;
-
-    if ((flags & VIR_MIGRATE_CHANGE_PROTECTION)) {
-        if (qemuMigrationJobStart(driver, vm, QEMU_ASYNC_JOB_MIGRATION_OUT) < 0)
-            goto cleanup;
-        asyncJob = QEMU_ASYNC_JOB_MIGRATION_OUT;
-    } else {
-        if (qemuDomainObjBeginJob(driver, vm, QEMU_JOB_MODIFY) < 0)
-            goto cleanup;
-        asyncJob = QEMU_ASYNC_JOB_NONE;
-    }
-
-    if (!virDomainObjIsActive(vm) && !(flags & VIR_MIGRATE_OFFLINE)) {
-        virReportError(VIR_ERR_OPERATION_INVALID,
-                       "%s", _("domain is not running"));
-        goto endjob;
-    }
-
-    /* Check if there is any ejected media.
-     * We don't want to require them on the destination.
-     */
-    if (!(flags & VIR_MIGRATE_OFFLINE) &&
-        qemuDomainCheckEjectableMedia(driver, vm, asyncJob) < 0)
-        goto endjob;
-
-    if (!(xml = qemuMigrationBegin(driver, vm, xmlin, dname,
-                                   cookieout, cookieoutlen,
-                                   flags)))
-        goto endjob;
-
-    if ((flags & VIR_MIGRATE_CHANGE_PROTECTION)) {
-        /* We keep the job active across API calls until the confirm() call.
-         * This prevents any other APIs being invoked while migration is taking
-         * place.
-         */
-        if (virQEMUCloseCallbacksSet(driver->closeCallbacks, vm, domain->conn,
-                                     qemuMigrationCleanup) < 0)
-            goto endjob;
-        if (qemuMigrationJobContinue(vm) == 0) {
-            vm = NULL;
-            virReportError(VIR_ERR_OPERATION_FAILED,
-                           "%s", _("domain disappeared"));
-            VIR_FREE(xml);
-            if (cookieout)
-                VIR_FREE(*cookieout);
-        }
-    } else {
-        goto endjob;
-    }
-
-cleanup:
-    if (vm)
-        virObjectUnlock(vm);
-    return xml;
-
-endjob:
-    if ((flags & VIR_MIGRATE_CHANGE_PROTECTION)) {
-        if (qemuMigrationJobFinish(driver, vm) == 0)
-            vm = NULL;
-    } else {
-        if (qemuDomainObjEndJob(driver, vm) == 0)
-            vm = NULL;
-    }
-    goto cleanup;
-}
-
-static char *
 qemuDomainMigrateBegin3(virDomainPtr domain,
                         const char *xmlin,
                         char **cookieout,
@@ -9976,10 +9896,16 @@ qemuDomainMigrateBegin3(virDomainPtr domain,
                         const char *dname,
                         unsigned long resource ATTRIBUTE_UNUSED)
 {
+    virDomainObjPtr vm;
+
     virCheckFlags(QEMU_MIGRATION_FLAGS, NULL);
 
-    return qemuDomainMigrateBegin3Internal(domain, xmlin, dname,
-                                           cookieout, cookieoutlen, flags);
+    if (!(vm = qemuDomObjFromDomain(domain)))
+        return NULL;
+
+    return qemuMigrationBegin(domain->conn->privateData,
+                              domain->conn, vm, xmlin, dname,
+                              cookieout, cookieoutlen, flags);
 }
 
 static char *
@@ -9992,6 +9918,7 @@ qemuDomainMigrateBegin3Params(virDomainPtr domain,
 {
     const char *xmlin = NULL;
     const char *dname = NULL;
+    virDomainObjPtr vm;
 
     virCheckFlags(QEMU_MIGRATION_FLAGS, NULL);
     if (virTypedParamsValidate(params, nparams, QEMU_MIGRATION_PARAMETERS) < 0)
@@ -10005,8 +9932,12 @@ qemuDomainMigrateBegin3Params(virDomainPtr domain,
                                 &dname) < 0)
         return NULL;
 
-    return qemuDomainMigrateBegin3Internal(domain, xmlin, dname,
-                                           cookieout, cookieoutlen, flags);
+    if (!(vm = qemuDomObjFromDomain(domain)))
+        return NULL;
+
+    return qemuMigrationBegin(domain->conn->privateData,
+                              domain->conn, vm, xmlin, dname,
+                              cookieout, cookieoutlen, flags);
 }
 
 
diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c
index 6243d75..c0b721a 100644
--- a/src/qemu/qemu_migration.c
+++ b/src/qemu/qemu_migration.c
@@ -39,6 +39,7 @@
 #include "qemu_capabilities.h"
 #include "qemu_command.h"
 #include "qemu_cgroup.h"
+#include "qemu_hotplug.h"
 
 #include "domain_audit.h"
 #include "virlog.h"
@@ -1924,14 +1925,16 @@ cleanup:
     return vm;
 }
 
+
 /* The caller is supposed to lock the vm and start a migration job. */
-char *qemuMigrationBegin(virQEMUDriverPtr driver,
-                         virDomainObjPtr vm,
-                         const char *xmlin,
-                         const char *dname,
-                         char **cookieout,
-                         int *cookieoutlen,
-                         unsigned long flags)
+static char *
+qemuMigrationBeginPhase(virQEMUDriverPtr driver,
+                        virDomainObjPtr vm,
+                        const char *xmlin,
+                        const char *dname,
+                        char **cookieout,
+                        int *cookieoutlen,
+                        unsigned long flags)
 {
     char *rv = NULL;
     qemuMigrationCookiePtr mig = NULL;
@@ -2025,6 +2028,83 @@ cleanup:
     return rv;
 }
 
+char *
+qemuMigrationBegin(virQEMUDriverPtr driver,
+                   virConnectPtr conn,
+                   virDomainObjPtr vm,
+                   const char *xmlin,
+                   const char *dname,
+                   char **cookieout,
+                   int *cookieoutlen,
+                   unsigned long flags)
+{
+    char *xml = NULL;
+    enum qemuDomainAsyncJob asyncJob;
+
+    if ((flags & VIR_MIGRATE_CHANGE_PROTECTION)) {
+        if (qemuMigrationJobStart(driver, vm, QEMU_ASYNC_JOB_MIGRATION_OUT) < 0)
+            goto cleanup;
+        asyncJob = QEMU_ASYNC_JOB_MIGRATION_OUT;
+    } else {
+        if (qemuDomainObjBeginJob(driver, vm, QEMU_JOB_MODIFY) < 0)
+            goto cleanup;
+        asyncJob = QEMU_ASYNC_JOB_NONE;
+    }
+
+    if (!virDomainObjIsActive(vm) && !(flags & VIR_MIGRATE_OFFLINE)) {
+        virReportError(VIR_ERR_OPERATION_INVALID,
+                       "%s", _("domain is not running"));
+        goto endjob;
+    }
+
+    /* Check if there is any ejected media.
+     * We don't want to require them on the destination.
+     */
+    if (!(flags & VIR_MIGRATE_OFFLINE) &&
+        qemuDomainCheckEjectableMedia(driver, vm, asyncJob) < 0)
+        goto endjob;
+
+    if (!(xml = qemuMigrationBeginPhase(driver, vm, xmlin, dname,
+                                        cookieout, cookieoutlen,
+                                        flags)))
+        goto endjob;
+
+    if ((flags & VIR_MIGRATE_CHANGE_PROTECTION)) {
+        /* We keep the job active across API calls until the confirm() call.
+         * This prevents any other APIs being invoked while migration is taking
+         * place.
+         */
+        if (virQEMUCloseCallbacksSet(driver->closeCallbacks, vm, conn,
+                                     qemuMigrationCleanup) < 0)
+            goto endjob;
+        if (qemuMigrationJobContinue(vm) == 0) {
+            vm = NULL;
+            virReportError(VIR_ERR_OPERATION_FAILED,
+                           "%s", _("domain disappeared"));
+            VIR_FREE(xml);
+            if (cookieout)
+                VIR_FREE(*cookieout);
+        }
+    } else {
+        goto endjob;
+    }
+
+cleanup:
+    if (vm)
+        virObjectUnlock(vm);
+    return xml;
+
+endjob:
+    if ((flags & VIR_MIGRATE_CHANGE_PROTECTION)) {
+        if (qemuMigrationJobFinish(driver, vm) == 0)
+            vm = NULL;
+    } else {
+        if (qemuDomainObjEndJob(driver, vm) == 0)
+            vm = NULL;
+    }
+    goto cleanup;
+}
+
 
 /* Prepare is the first step, and it runs on the destination host.
  */
@@ -3347,8 +3427,8 @@ doPeer2PeerMigrate3(virQEMUDriverPtr driver,
      * bit here, because we are already running inside the context of
      * a single job.  */
 
-    dom_xml = qemuMigrationBegin(driver, vm, xmlin, dname,
-                                 &cookieout, &cookieoutlen, flags);
+    dom_xml = qemuMigrationBeginPhase(driver, vm, xmlin, dname,
+                                      &cookieout, &cookieoutlen, flags);
     if (!dom_xml)
         goto cleanup;
 
diff --git a/src/qemu/qemu_migration.h b/src/qemu/qemu_migration.h
index e44cf3b..ef7307e 100644
--- a/src/qemu/qemu_migration.h
+++ b/src/qemu/qemu_migration.h
@@ -94,6 +94,7 @@ virDomainObjPtr qemuMigrationCleanup(virQEMUDriverPtr driver,
                                      virConnectPtr conn);
 
 char *qemuMigrationBegin(virQEMUDriverPtr driver,
+                         virConnectPtr conn,
                          virDomainObjPtr vm,
                          const char *xmlin,
                          const char *dname,
-- 
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]