[PATCH 1/7] qemu: Split qemuMigrationFinish

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

 



Separate code which makes incoming domain persistent into
qemuMigrationPersist.

Signed-off-by: Jiri Denemark <jdenemar@xxxxxxxxxx>
---
 src/qemu/qemu_migration.c | 75 ++++++++++++++++++++++++++++++-----------------
 1 file changed, 48 insertions(+), 27 deletions(-)

diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c
index 97901c6..6b06e79 100644
--- a/src/qemu/qemu_migration.c
+++ b/src/qemu/qemu_migration.c
@@ -5526,6 +5526,51 @@ qemuMigrationVPAssociatePortProfiles(virDomainDefPtr def)
 }
 
 
+static int
+qemuMigrationPersist(virQEMUDriverPtr driver,
+                     virDomainObjPtr vm,
+                     qemuMigrationCookiePtr mig)
+{
+    virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
+    virCapsPtr caps = NULL;
+    virDomainDefPtr vmdef;
+    virObjectEventPtr event;
+    bool newVM;
+    int ret = -1;
+
+    if (!(caps = virQEMUDriverGetCapabilities(driver, false)))
+        goto cleanup;
+
+    newVM = !vm->persistent;
+    vm->persistent = 1;
+
+    if (mig->persistent)
+        vm->newDef = mig->persistent;
+
+    vmdef = virDomainObjGetPersistentDef(caps, driver->xmlopt, vm);
+    if (!vmdef)
+        goto cleanup;
+
+    if (virDomainSaveConfig(cfg->configDir, vmdef) < 0)
+        goto cleanup;
+
+    event = virDomainEventLifecycleNewFromObj(vm,
+                                     VIR_DOMAIN_EVENT_DEFINED,
+                                     newVM ?
+                                     VIR_DOMAIN_EVENT_DEFINED_ADDED :
+                                     VIR_DOMAIN_EVENT_DEFINED_UPDATED);
+    if (event)
+        qemuDomainEventQueue(driver, event);
+
+    ret = 0;
+
+ cleanup:
+    virObjectUnref(caps);
+    virObjectUnref(cfg);
+    return ret;
+}
+
+
 virDomainPtr
 qemuMigrationFinish(virQEMUDriverPtr driver,
                     virConnectPtr dconn,
@@ -5540,13 +5585,11 @@ qemuMigrationFinish(virQEMUDriverPtr driver,
 {
     virDomainPtr dom = NULL;
     virObjectEventPtr event = NULL;
-    bool newVM = true;
     qemuMigrationCookiePtr mig = NULL;
     virErrorPtr orig_err = NULL;
     int cookie_flags = 0;
     qemuDomainObjPrivatePtr priv = vm->privateData;
     virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
-    virCapsPtr caps = NULL;
     unsigned short port;
 
     VIR_DEBUG("driver=%p, dconn=%p, vm=%p, cookiein=%s, cookieinlen=%d, "
@@ -5557,9 +5600,6 @@ qemuMigrationFinish(virQEMUDriverPtr driver,
     port = priv->migrationPort;
     priv->migrationPort = 0;
 
-    if (!(caps = virQEMUDriverGetCapabilities(driver, false)))
-        goto cleanup;
-
     if (!qemuMigrationJobIsActive(vm, QEMU_ASYNC_JOB_MIGRATION_IN)) {
         qemuMigrationErrorReport(driver, vm->def->name);
         goto cleanup;
@@ -5622,15 +5662,9 @@ qemuMigrationFinish(virQEMUDriverPtr driver,
             goto endjob;
 
         if (flags & VIR_MIGRATE_PERSIST_DEST) {
-            virDomainDefPtr vmdef;
-            if (vm->persistent)
-                newVM = false;
-            vm->persistent = 1;
-            if (mig->persistent)
-                vm->newDef = vmdef = mig->persistent;
-            else
-                vmdef = virDomainObjGetPersistentDef(caps, driver->xmlopt, vm);
-            if (!vmdef || virDomainSaveConfig(cfg->configDir, vmdef) < 0) {
+            bool newVM = !vm->persistent;
+
+            if (qemuMigrationPersist(driver, vm, mig) < 0) {
                 /* Hmpf.  Migration was successful, but making it persistent
                  * was not.  If we report successful, then when this domain
                  * shuts down, management tools are in for a surprise.  On the
@@ -5654,20 +5688,8 @@ qemuMigrationFinish(virQEMUDriverPtr driver,
                     if (newVM)
                         vm->persistent = 0;
                 }
-                if (!vmdef)
-                    virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-                                   _("can't get vmdef"));
                 goto endjob;
             }
-
-            event = virDomainEventLifecycleNewFromObj(vm,
-                                             VIR_DOMAIN_EVENT_DEFINED,
-                                             newVM ?
-                                             VIR_DOMAIN_EVENT_DEFINED_ADDED :
-                                             VIR_DOMAIN_EVENT_DEFINED_UPDATED);
-            if (event)
-                qemuDomainEventQueue(driver, event);
-            event = NULL;
         }
 
         if (!(flags & VIR_MIGRATE_PAUSED) && !(flags & VIR_MIGRATE_OFFLINE)) {
@@ -5775,7 +5797,6 @@ qemuMigrationFinish(virQEMUDriverPtr driver,
         virSetError(orig_err);
         virFreeError(orig_err);
     }
-    virObjectUnref(caps);
     virObjectUnref(cfg);
 
     /* Set a special error if Finish is expected to return NULL as a result of
-- 
2.4.5

--
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]