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:
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 1aa98ab..50174f5 100644
--- a/src/qemu/qemu_migration.c
+++ b/src/qemu/qemu_migration.c
@@ -907,7 +907,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;
@@ -935,6 +936,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);
@@ -1502,7 +1509,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;
@@ -1621,7 +1629,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
@@ -1678,7 +1687,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;
@@ -1736,7 +1746,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)
@@ -1757,7 +1767,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;
@@ -1820,7 +1831,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) {
@@ -1923,12 +1934,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)
@@ -2069,12 +2080,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) {
@@ -2306,7 +2317,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;
@@ -2395,7 +2406,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) {
@@ -2920,7 +2931,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