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 | 39 +++++++++++++++++++++++++--------------
1 files changed, 25 insertions(+), 14 deletions(-)
diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c
index 301d8ba..fb3b411 100644
--- a/src/qemu/qemu_migration.c
+++ b/src/qemu/qemu_migration.c
@@ -901,7 +901,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;
@@ -929,6 +930,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);
@@ -1491,7 +1498,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;
@@ -1610,7 +1618,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
@@ -1667,7 +1676,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;
@@ -1725,7 +1735,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)
@@ -1746,7 +1756,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;
@@ -1809,7 +1820,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) {
@@ -1912,12 +1923,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)
@@ -2058,12 +2069,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) {
@@ -2301,7 +2312,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;
@@ -2390,7 +2401,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) {
@@ -2909,7 +2920,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.6.1