]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemu: Cancel p2p migration when connection breaks
authorJiri Denemark <jdenemar@redhat.com>
Fri, 23 Sep 2011 06:56:56 +0000 (08:56 +0200)
committerJiri Denemark <jdenemar@redhat.com>
Thu, 24 Nov 2011 11:00:10 +0000 (12:00 +0100)
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.

src/qemu/qemu_migration.c

index ee9a84e3aadc368330718fbaf1d8a6b4f5741426..8ae989a93b1949fae1b356ad76abfe742a7138dc 100644 (file)
@@ -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) {
@@ -2924,7 +2935,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;