From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from [140.186.70.92] (port=45680 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OJu54-00058Y-3m for qemu-devel@nongnu.org; Wed, 02 Jun 2010 15:58:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OJu4x-0008Fn-4g for qemu-devel@nongnu.org; Wed, 02 Jun 2010 15:58:20 -0400 Received: from e31.co.us.ibm.com ([32.97.110.149]:43601) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OJu4w-0008FW-Vw for qemu-devel@nongnu.org; Wed, 02 Jun 2010 15:58:19 -0400 Received: from d03relay01.boulder.ibm.com (d03relay01.boulder.ibm.com [9.17.195.226]) by e31.co.us.ibm.com (8.14.4/8.13.1) with ESMTP id o52Jltaf019776 for ; Wed, 2 Jun 2010 13:47:55 -0600 Received: from d03av04.boulder.ibm.com (d03av04.boulder.ibm.com [9.17.195.170]) by d03relay01.boulder.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id o52JwBpr050750 for ; Wed, 2 Jun 2010 13:58:11 -0600 Received: from d03av04.boulder.ibm.com (loopback [127.0.0.1]) by d03av04.boulder.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id o52JwA4k011435 for ; Wed, 2 Jun 2010 13:58:10 -0600 From: Anthony Liguori Date: Wed, 2 Jun 2010 14:58:08 -0500 Message-Id: <1275508688-5229-1-git-send-email-aliguori@us.ibm.com> Subject: [Qemu-devel] [PATCH] migration: respect exit status with exec: List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Anthony Liguori This patch makes sure that if the exec: process exits with a non-zero return status, we treat the migration as failed. This fixes https://bugs.launchpad.net/qemu/+bug/391879 Signed-off-by: Anthony Liguori diff --git a/migration-exec.c b/migration-exec.c index 5435827..93bde62 100644 --- a/migration-exec.c +++ b/migration-exec.c @@ -43,13 +43,21 @@ static int file_write(FdMigrationState *s, const void * buf, size_t size) static int exec_close(FdMigrationState *s) { + int ret = 0; DPRINTF("exec_close\n"); if (s->opaque) { - qemu_fclose(s->opaque); + ret = qemu_fclose(s->opaque); s->opaque = NULL; s->fd = -1; + if (ret != -1 && + WIFEXITED(ret) + && WEXITSTATUS(ret) == 0) { + ret = 0; + } else { + ret = -1; + } } - return 0; + return ret; } MigrationState *exec_start_outgoing_migration(Monitor *mon, diff --git a/migration.c b/migration.c index 706fe55..fbf2339 100644 --- a/migration.c +++ b/migration.c @@ -252,13 +252,17 @@ void migrate_fd_error(FdMigrationState *s) migrate_fd_cleanup(s); } -void migrate_fd_cleanup(FdMigrationState *s) +int migrate_fd_cleanup(FdMigrationState *s) { + int ret = 0; + qemu_set_fd_handler2(s->fd, NULL, NULL, NULL, NULL); if (s->file) { DPRINTF("closing file\n"); - qemu_fclose(s->file); + if (qemu_fclose(s->file) != 0) { + ret = -1; + } s->file = NULL; } @@ -271,6 +275,8 @@ void migrate_fd_cleanup(FdMigrationState *s) } s->fd = -1; + + return ret; } void migrate_fd_put_notify(void *opaque) @@ -349,7 +355,12 @@ void migrate_fd_put_ready(void *opaque) } else { state = MIG_STATE_COMPLETED; } - migrate_fd_cleanup(s); + if (migrate_fd_cleanup(s) < 0) { + if (old_vm_running) { + vm_start(); + } + state = MIG_STATE_ERROR; + } s->state = state; } } diff --git a/migration.h b/migration.h index 385423f..97eef4a 100644 --- a/migration.h +++ b/migration.h @@ -107,7 +107,7 @@ void migrate_fd_monitor_suspend(FdMigrationState *s, Monitor *mon); void migrate_fd_error(FdMigrationState *s); -void migrate_fd_cleanup(FdMigrationState *s); +int migrate_fd_cleanup(FdMigrationState *s); void migrate_fd_put_notify(void *opaque); diff --git a/savevm.c b/savevm.c index dc20390..af92ba2 100644 --- a/savevm.c +++ b/savevm.c @@ -235,9 +235,10 @@ static int stdio_get_buffer(void *opaque, uint8_t *buf, int64_t pos, int size) static int stdio_pclose(void *opaque) { QEMUFileStdio *s = opaque; - pclose(s->stdio_file); + int ret; + ret = pclose(s->stdio_file); qemu_free(s); - return 0; + return ret; } static int stdio_fclose(void *opaque) -- 1.7.0.4