From patchwork Tue Apr 16 16:05:21 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Hrdina X-Patchwork-Id: 237024 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 5E47D2C011D for ; Wed, 17 Apr 2013 02:08:42 +1000 (EST) Received: from localhost ([::1]:58718 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1US8Qy-0001Nt-Dn for incoming@patchwork.ozlabs.org; Tue, 16 Apr 2013 12:08:40 -0400 Received: from eggs.gnu.org ([208.118.235.92]:39632) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1US8OD-0005pE-IE for qemu-devel@nongnu.org; Tue, 16 Apr 2013 12:05:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1US8O8-0006w6-9w for qemu-devel@nongnu.org; Tue, 16 Apr 2013 12:05:49 -0400 Received: from mx1.redhat.com ([209.132.183.28]:6249) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1US8O8-0006w1-31 for qemu-devel@nongnu.org; Tue, 16 Apr 2013 12:05:44 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r3GG5haL032410 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 16 Apr 2013 12:05:43 -0400 Received: from localhost.localdomain.com ([10.34.250.241]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r3GG5OMT019439; Tue, 16 Apr 2013 12:05:41 -0400 From: Pavel Hrdina To: qemu-devel@nongnu.org Date: Tue, 16 Apr 2013 18:05:21 +0200 Message-Id: In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: phrdina@redhat.com, armbru@redhat.com, lcapitulino@redhat.com Subject: [Qemu-devel] [PATCH 09/11] savevm: update error reporting off qemu_savevm_state() and related functions 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 Reviewed-by: Eric Blake --- include/sysemu/sysemu.h | 7 ++++--- migration.c | 6 +++--- savevm.c | 38 +++++++++++++++++++------------------- 3 files changed, 26 insertions(+), 25 deletions(-) diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h index 913f49f..0e3f30a 100644 --- a/include/sysemu/sysemu.h +++ b/include/sysemu/sysemu.h @@ -72,9 +72,10 @@ void qemu_announce_self(void); bool qemu_savevm_state_blocked(Error **errp); void qemu_savevm_state_begin(QEMUFile *f, - const MigrationParams *params); -int qemu_savevm_state_iterate(QEMUFile *f); -void qemu_savevm_state_complete(QEMUFile *f); + const MigrationParams *params, + Error **errp); +int qemu_savevm_state_iterate(QEMUFile *f, Error **errp); +void qemu_savevm_state_complete(QEMUFile *f, Error **errp); void qemu_savevm_state_cancel(void); uint64_t qemu_savevm_state_pending(QEMUFile *f, uint64_t max_size); void qemu_loadvm_state(QEMUFile *f, Error **errp); diff --git a/migration.c b/migration.c index fd8c869..d115262 100644 --- a/migration.c +++ b/migration.c @@ -506,7 +506,7 @@ static void *migration_thread(void *opaque) bool old_vm_running = false; DPRINTF("beginning savevm\n"); - qemu_savevm_state_begin(s->file, &s->params); + qemu_savevm_state_begin(s->file, &s->params, NULL); while (s->state == MIG_STATE_ACTIVE) { int64_t current_time; @@ -517,7 +517,7 @@ static void *migration_thread(void *opaque) pending_size = qemu_savevm_state_pending(s->file, max_size); DPRINTF("pending size %lu max %lu\n", pending_size, max_size); if (pending_size && pending_size >= max_size) { - qemu_savevm_state_iterate(s->file); + qemu_savevm_state_iterate(s->file, NULL); } else { DPRINTF("done iterating\n"); qemu_mutex_lock_iothread(); @@ -526,7 +526,7 @@ static void *migration_thread(void *opaque) old_vm_running = runstate_is_running(); vm_stop_force_state(RUN_STATE_FINISH_MIGRATE); qemu_file_set_rate_limit(s->file, INT_MAX); - qemu_savevm_state_complete(s->file); + qemu_savevm_state_complete(s->file, NULL); qemu_mutex_unlock_iothread(); if (!qemu_file_get_error(s->file)) { migrate_finish_set_state(s, MIG_STATE_COMPLETED); diff --git a/savevm.c b/savevm.c index a8e7d60..8736eb4 100644 --- a/savevm.c +++ b/savevm.c @@ -1728,7 +1728,8 @@ bool qemu_savevm_state_blocked(Error **errp) } void qemu_savevm_state_begin(QEMUFile *f, - const MigrationParams *params) + const MigrationParams *params, + Error **errp) { SaveStateEntry *se; int ret; @@ -1769,6 +1770,7 @@ void qemu_savevm_state_begin(QEMUFile *f, ret = se->ops->save_live_setup(f, se->opaque); if (ret < 0) { qemu_file_set_error(f, ret); + error_setg_errno(errp, -ret, "failed to begin vmstate save"); break; } } @@ -1780,7 +1782,7 @@ void qemu_savevm_state_begin(QEMUFile *f, * 0 : We haven't finished, caller have to go again * 1 : We have finished, we can go to complete phase */ -int qemu_savevm_state_iterate(QEMUFile *f) +int qemu_savevm_state_iterate(QEMUFile *f, Error **errp) { SaveStateEntry *se; int ret = 1; @@ -1807,6 +1809,7 @@ int qemu_savevm_state_iterate(QEMUFile *f) if (ret < 0) { qemu_file_set_error(f, ret); + error_setg_errno(errp, -ret, "failed to iterate vmstate save"); } if (ret <= 0) { /* Do not proceed to the next vmstate before this one reported @@ -1819,7 +1822,7 @@ int qemu_savevm_state_iterate(QEMUFile *f) return ret; } -void qemu_savevm_state_complete(QEMUFile *f) +void qemu_savevm_state_complete(QEMUFile *f, Error **errp) { SaveStateEntry *se; int ret; @@ -1844,6 +1847,7 @@ void qemu_savevm_state_complete(QEMUFile *f) trace_savevm_section_end(se->section_id); if (ret < 0) { qemu_file_set_error(f, ret); + error_setg_errno(errp, -ret, "failed to complete vmstate save"); return; } } @@ -1905,37 +1909,33 @@ void qemu_savevm_state_cancel(void) } } -static int qemu_savevm_state(QEMUFile *f) +static void qemu_savevm_state(QEMUFile *f, Error **errp) { - int ret; MigrationParams params = { .blk = 0, .shared = 0 }; - if (qemu_savevm_state_blocked(NULL)) { - return -EINVAL; + if (qemu_savevm_state_blocked(errp)) { + return; } qemu_mutex_unlock_iothread(); - qemu_savevm_state_begin(f, ¶ms); + qemu_savevm_state_begin(f, ¶ms, errp); qemu_mutex_lock_iothread(); while (qemu_file_get_error(f) == 0) { - if (qemu_savevm_state_iterate(f) > 0) { + if (qemu_savevm_state_iterate(f, errp) > 0) { break; } } - ret = qemu_file_get_error(f); - if (ret == 0) { - qemu_savevm_state_complete(f); - ret = qemu_file_get_error(f); + if (!qemu_file_get_error(f)) { + qemu_savevm_state_complete(f, errp); } - if (ret != 0) { + if (qemu_file_get_error(f)) { qemu_savevm_state_cancel(); } - return ret; } static int qemu_save_device_state(QEMUFile *f) @@ -2276,7 +2276,6 @@ void do_savevm(Monitor *mon, const QDict *qdict) { BlockDriverState *bs, *bs1; QEMUSnapshotInfo sn1, *sn = &sn1, old_sn1, *old_sn = &old_sn1; - int ret; QEMUFile *f; int saved_vm_running; uint64_t vm_state_size; @@ -2341,11 +2340,12 @@ void do_savevm(Monitor *mon, const QDict *qdict) monitor_printf(mon, "Could not open VM state file\n"); goto the_end; } - ret = qemu_savevm_state(f); + qemu_savevm_state(f, &local_err); vm_state_size = qemu_ftell(f); qemu_fclose(f); - if (ret < 0) { - monitor_printf(mon, "Error %d while writing VM\n", ret); + if (error_is_set(&local_err)) { + monitor_printf(mon, "%s\n", error_get_pretty(local_err)); + error_free(local_err); goto the_end; }