From d63f0754e3a1340114bad3a1e5e918b75e972910 Mon Sep 17 00:00:00 2001 From: Jiri Denemark Date: Fri, 20 Apr 2012 14:07:49 +0200 Subject: [PATCH] qemu: Preserve original error during migration In some cases (spotted with broken connection during tunneled migration) we were overwriting the original error with worse or even misleading errors generated when we were cleaning up after failed migration. --- src/qemu/qemu_migration.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c index 07f5edb44b..85907a6ee3 100644 --- a/src/qemu/qemu_migration.c +++ b/src/qemu/qemu_migration.c @@ -1732,6 +1732,7 @@ qemuMigrationRun(struct qemud_driver *driver, qemuMigrationIOThreadPtr iothread = NULL; int fd = -1; unsigned long migrate_speed = resource ? resource : priv->migMaxBandwidth; + virErrorPtr orig_err = NULL; VIR_DEBUG("driver=%p, vm=%p, cookiein=%s, cookieinlen=%d, " "cookieout=%p, cookieoutlen=%p, flags=%lx, resource=%lu, " @@ -1873,6 +1874,9 @@ qemuMigrationRun(struct qemud_driver *driver, ret = 0; cleanup: + if (ret < 0 && !orig_err) + orig_err = virSaveLastError(); + if (spec->fwdType != MIGRATION_FWD_DIRECT) { /* Close now to ensure the IO thread quits & is joinable */ VIR_FORCE_CLOSE(fd); @@ -1887,9 +1891,16 @@ cleanup: qemuMigrationCookieFree(mig); + if (orig_err) { + virSetError(orig_err); + virFreeError(orig_err); + } + return ret; cancel: + orig_err = virSaveLastError(); + if (virDomainObjIsActive(vm)) { if (qemuDomainObjEnterMonitorAsync(driver, vm, QEMU_ASYNC_JOB_MIGRATION_OUT) == 0) { @@ -2494,6 +2505,7 @@ qemuMigrationPerformJob(struct qemud_driver *driver, virDomainEventPtr event = NULL; int ret = -1; int resume = 0; + virErrorPtr orig_err = NULL; if (qemuMigrationJobStart(driver, vm, QEMU_ASYNC_JOB_MIGRATION_OUT) < 0) goto cleanup; @@ -2539,6 +2551,9 @@ qemuMigrationPerformJob(struct qemud_driver *driver, resume = 0; endjob: + if (ret < 0) + orig_err = virSaveLastError(); + if (resume && virDomainObjGetState(vm, NULL) == VIR_DOMAIN_PAUSED) { /* we got here through some sort of failure; start the domain again */ if (qemuProcessStartCPUs(driver, vm, conn, @@ -2568,6 +2583,11 @@ endjob: vm = NULL; } + if (orig_err) { + virSetError(orig_err); + virFreeError(orig_err); + } + cleanup: if (vm) virDomainObjUnlock(vm);