From patchwork Thu Dec 13 15:40:46 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Hrdina X-Patchwork-Id: 206147 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id D28442C009F for ; Fri, 14 Dec 2012 03:16:19 +1100 (EST) Received: from localhost ([::1]:47494 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TjAuk-0001ol-S5 for incoming@patchwork.ozlabs.org; Thu, 13 Dec 2012 10:41:34 -0500 Received: from eggs.gnu.org ([208.118.235.92]:47415) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TjAuO-0001Yb-6y for qemu-devel@nongnu.org; Thu, 13 Dec 2012 10:41:14 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TjAuJ-0005w4-Pk for qemu-devel@nongnu.org; Thu, 13 Dec 2012 10:41:11 -0500 Received: from mx1.redhat.com ([209.132.183.28]:10993) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TjAuJ-0005vm-HQ for qemu-devel@nongnu.org; Thu, 13 Dec 2012 10:41:07 -0500 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id qBDFf6Zm012641 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 13 Dec 2012 10:41:06 -0500 Received: from localhost.localdomain.com (dhcp-27-184.brq.redhat.com [10.34.27.184]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id qBDFeqvP030229; Thu, 13 Dec 2012 10:41:05 -0500 From: Pavel Hrdina To: qemu-devel@nongnu.org Date: Thu, 13 Dec 2012 16:40:46 +0100 Message-Id: In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.68 on 10.5.11.25 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: phrdina@redhat.com Subject: [Qemu-devel] [PATCH v2 12/17] savevm: add error parameter to qemu_loadvm_state() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Signed-off-by: Pavel Hrdina --- migration.c | 8 ++++---- savevm.c | 39 +++++++++++++++++++++++---------------- sysemu.h | 3 ++- 3 files changed, 29 insertions(+), 21 deletions(-) diff --git a/migration.c b/migration.c index 3ae1db0..4c2d2d3 100644 --- a/migration.c +++ b/migration.c @@ -86,13 +86,13 @@ void qemu_start_incoming_migration(const char *uri, Error **errp) static void process_incoming_migration_co(void *opaque) { QEMUFile *f = opaque; - int ret; + Error **errp = NULL; - ret = qemu_loadvm_state(f); + qemu_loadvm_state(f, errp); qemu_set_fd_handler(qemu_get_fd(f), NULL, NULL, NULL); qemu_fclose(f); - if (ret < 0) { - fprintf(stderr, "load of migration failed\n"); + if (error_is_set(errp)) { + handle_error(errp); exit(0); } qemu_announce_self(); diff --git a/savevm.c b/savevm.c index 71c7df8..2c63aad 100644 --- a/savevm.c +++ b/savevm.c @@ -1962,7 +1962,8 @@ typedef struct LoadStateEntry { int version_id; } LoadStateEntry; -int qemu_loadvm_state(QEMUFile *f) +int qemu_loadvm_state(QEMUFile *f, + Error **errp) { QLIST_HEAD(, LoadStateEntry) loadvm_handlers = QLIST_HEAD_INITIALIZER(loadvm_handlers); @@ -1971,21 +1972,25 @@ int qemu_loadvm_state(QEMUFile *f) unsigned int v; int ret; - if (qemu_savevm_state_blocked(NULL)) { - return -EINVAL; + if (qemu_savevm_state_blocked(errp)) { + return -ENOTSUP; } v = qemu_get_be32(f); - if (v != QEMU_VM_FILE_MAGIC) + if (v != QEMU_VM_FILE_MAGIC) { + error_setg(errp, "Unknown vmstate file magic"); return -EINVAL; + } v = qemu_get_be32(f); if (v == QEMU_VM_FILE_VERSION_COMPAT) { - fprintf(stderr, "SaveVM v2 format is obsolete and don't work anymore\n"); + error_setg(errp, "Not supported."); return -ENOTSUP; } - if (v != QEMU_VM_FILE_VERSION) + if (v != QEMU_VM_FILE_VERSION) { + error_setg(errp, "Not supported."); return -ENOTSUP; + } while ((section_type = qemu_get_byte(f)) != QEMU_VM_EOF) { uint32_t instance_id, version_id, section_id; @@ -2007,15 +2012,16 @@ int qemu_loadvm_state(QEMUFile *f) /* Find savevm section */ se = find_se(idstr, instance_id); if (se == NULL) { - fprintf(stderr, "Unknown savevm section or instance '%s' %d\n", idstr, instance_id); + error_setg(errp, "Unknown savevm section or instance '%s' %d", + idstr, instance_id); ret = -EINVAL; goto out; } /* Validate version */ if (version_id > se->version_id) { - fprintf(stderr, "savevm: unsupported version %d for '%s' v%d\n", - version_id, idstr, se->version_id); + error_setg(errp, "savevm: unsupported version %d for '%s' v%d", + version_id, idstr, se->version_id); ret = -EINVAL; goto out; } @@ -2030,8 +2036,7 @@ int qemu_loadvm_state(QEMUFile *f) ret = vmstate_load(f, le->se, le->version_id); if (ret < 0) { - fprintf(stderr, "qemu: warning: error while loading state for instance 0x%x of device '%s'\n", - instance_id, idstr); + error_setg(errp, "Failed to load vmstate."); goto out; } break; @@ -2045,20 +2050,19 @@ int qemu_loadvm_state(QEMUFile *f) } } if (le == NULL) { - fprintf(stderr, "Unknown savevm section %d\n", section_id); + error_setg(errp, "Unknown savevm section %d", section_id); ret = -EINVAL; goto out; } ret = vmstate_load(f, le->se, le->version_id); if (ret < 0) { - fprintf(stderr, "qemu: warning: error while loading state section id %d\n", - section_id); + error_setg(errp, "Failed to load vmstate."); goto out; } break; default: - fprintf(stderr, "Unknown savevm section type %d\n", section_type); + error_setg(errp, "Unknown savevm section type %d", section_type); ret = -EINVAL; goto out; } @@ -2076,6 +2080,9 @@ out: if (ret == 0) { ret = qemu_file_get_error(f); + if (ret < 0) { + error_set(errp, QERR_GENERIC_ERROR, ret); + } } return ret; @@ -2342,7 +2349,7 @@ int load_vmstate(const char *name) } qemu_system_reset(VMRESET_SILENT); - ret = qemu_loadvm_state(f); + ret = qemu_loadvm_state(f, NULL); qemu_fclose(f); if (ret < 0) { diff --git a/sysemu.h b/sysemu.h index 11a4560..c08f7a3 100644 --- a/sysemu.h +++ b/sysemu.h @@ -81,7 +81,8 @@ int qemu_savevm_state_iterate(QEMUFile *f, int qemu_savevm_state_complete(QEMUFile *f, Error **errp); void qemu_savevm_state_cancel(QEMUFile *f); -int qemu_loadvm_state(QEMUFile *f); +int qemu_loadvm_state(QEMUFile *f, + Error **errp); /* SLIRP */ void do_info_slirp(Monitor *mon);