[PATCH v4 13/13] qemu: Cancel p2p migration when connection breaks

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

 



If a connection to destination host is lost during peer-to-peer
migration (because keepalive protocol timed out), we won't be able to
finish the migration and it doesn't make sense to wait for qemu to
transmit all data. This patch automatically cancels such migration
without waiting for virDomainAbortJob to be called.
---
Notes:
    ACKed

    Version 4:
    - no changes
    
    Version 3:
    - no changes
    
    Version 2:
    - new patch

 src/qemu/qemu_migration.c |   39 +++++++++++++++++++++++++--------------
 1 files changed, 25 insertions(+), 14 deletions(-)

diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c
index 1cebefd..8463263 100644
--- a/src/qemu/qemu_migration.c
+++ b/src/qemu/qemu_migration.c
@@ -915,7 +915,8 @@ qemuMigrationUpdateJobStatus(struct qemud_driver *driver,
 
 static int
 qemuMigrationWaitForCompletion(struct qemud_driver *driver, virDomainObjPtr vm,
-                               enum qemuDomainAsyncJob asyncJob)
+                               enum qemuDomainAsyncJob asyncJob,
+                               virConnectPtr dconn)
 {
     qemuDomainObjPrivatePtr priv = vm->privateData;
     const char *job;
@@ -943,6 +944,12 @@ qemuMigrationWaitForCompletion(struct qemud_driver *driver, virDomainObjPtr vm,
         if (qemuMigrationUpdateJobStatus(driver, vm, job, asyncJob) < 0)
             goto cleanup;
 
+        if (dconn && virConnectIsAlive(dconn) <= 0) {
+            qemuReportError(VIR_ERR_OPERATION_FAILED, "%s",
+                            _("Lost connection to destination host"));
+            goto cleanup;
+        }
+
         virDomainObjUnlock(vm);
         qemuDriverUnlock(driver);
 
@@ -1521,7 +1528,8 @@ qemuMigrationRun(struct qemud_driver *driver,
                  int *cookieoutlen,
                  unsigned long flags,
                  unsigned long resource,
-                 qemuMigrationSpecPtr spec)
+                 qemuMigrationSpecPtr spec,
+                 virConnectPtr dconn)
 {
     int ret = -1;
     unsigned int migrate_flags = QEMU_MONITOR_MIGRATE_BACKGROUND;
@@ -1640,7 +1648,8 @@ qemuMigrationRun(struct qemud_driver *driver,
         goto cancel;
 
     if (qemuMigrationWaitForCompletion(driver, vm,
-                                       QEMU_ASYNC_JOB_MIGRATION_OUT) < 0)
+                                       QEMU_ASYNC_JOB_MIGRATION_OUT,
+                                       dconn) < 0)
         goto cleanup;
 
     /* When migration completed, QEMU will have paused the
@@ -1697,7 +1706,8 @@ static int doNativeMigrate(struct qemud_driver *driver,
                            char **cookieout,
                            int *cookieoutlen,
                            unsigned long flags,
-                           unsigned long resource)
+                           unsigned long resource,
+                           virConnectPtr dconn)
 {
     qemuDomainObjPrivatePtr priv = vm->privateData;
     xmlURIPtr uribits = NULL;
@@ -1755,7 +1765,7 @@ static int doNativeMigrate(struct qemud_driver *driver,
     }
 
     ret = qemuMigrationRun(driver, vm, cookiein, cookieinlen, cookieout,
-                           cookieoutlen, flags, resource, &spec);
+                           cookieoutlen, flags, resource, &spec, dconn);
 
 cleanup:
     if (spec.destType == MIGRATION_DEST_FD)
@@ -1776,7 +1786,8 @@ static int doTunnelMigrate(struct qemud_driver *driver,
                            char **cookieout,
                            int *cookieoutlen,
                            unsigned long flags,
-                           unsigned long resource)
+                           unsigned long resource,
+                           virConnectPtr dconn)
 {
     qemuDomainObjPrivatePtr priv = vm->privateData;
     virNetSocketPtr sock = NULL;
@@ -1839,7 +1850,7 @@ static int doTunnelMigrate(struct qemud_driver *driver,
     }
 
     ret = qemuMigrationRun(driver, vm, cookiein, cookieinlen, cookieout,
-                           cookieoutlen, flags, resource, &spec);
+                           cookieoutlen, flags, resource, &spec, dconn);
 
 cleanup:
     if (spec.destType == MIGRATION_DEST_FD) {
@@ -1942,12 +1953,12 @@ static int doPeer2PeerMigrate2(struct qemud_driver *driver,
     if (flags & VIR_MIGRATE_TUNNELLED)
         ret = doTunnelMigrate(driver, vm, st,
                               NULL, 0, NULL, NULL,
-                              flags, resource);
+                              flags, resource, dconn);
     else
         ret = doNativeMigrate(driver, vm, uri_out,
                               cookie, cookielen,
                               NULL, NULL, /* No out cookie with v2 migration */
-                              flags, resource);
+                              flags, resource, dconn);
 
     /* Perform failed. Make sure Finish doesn't overwrite the error */
     if (ret < 0)
@@ -2088,12 +2099,12 @@ static int doPeer2PeerMigrate3(struct qemud_driver *driver,
         ret = doTunnelMigrate(driver, vm, st,
                               cookiein, cookieinlen,
                               &cookieout, &cookieoutlen,
-                              flags, resource);
+                              flags, resource, dconn);
     else
         ret = doNativeMigrate(driver, vm, uri_out,
                               cookiein, cookieinlen,
                               &cookieout, &cookieoutlen,
-                              flags, resource);
+                              flags, resource, dconn);
 
     /* Perform failed. Make sure Finish doesn't overwrite the error */
     if (ret < 0) {
@@ -2325,7 +2336,7 @@ qemuMigrationPerformJob(struct qemud_driver *driver,
         qemuMigrationJobSetPhase(driver, vm, QEMU_MIGRATION_PHASE_PERFORM2);
         ret = doNativeMigrate(driver, vm, uri, cookiein, cookieinlen,
                               cookieout, cookieoutlen,
-                              flags, resource);
+                              flags, resource, NULL);
     }
     if (ret < 0)
         goto endjob;
@@ -2414,7 +2425,7 @@ qemuMigrationPerformPhase(struct qemud_driver *driver,
     resume = virDomainObjGetState(vm, NULL) == VIR_DOMAIN_RUNNING;
     ret = doNativeMigrate(driver, vm, uri, cookiein, cookieinlen,
                           cookieout, cookieoutlen,
-                          flags, resource);
+                          flags, resource, NULL);
 
     if (ret < 0 && resume &&
         virDomainObjGetState(vm, NULL) == VIR_DOMAIN_PAUSED) {
@@ -2939,7 +2950,7 @@ qemuMigrationToFile(struct qemud_driver *driver, virDomainObjPtr vm,
     if (rc < 0)
         goto cleanup;
 
-    rc = qemuMigrationWaitForCompletion(driver, vm, asyncJob);
+    rc = qemuMigrationWaitForCompletion(driver, vm, asyncJob, NULL);
 
     if (rc < 0)
         goto cleanup;
-- 
1.7.7.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]