From patchwork Tue Apr 20 21:09:51 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Capitulino X-Patchwork-Id: 50596 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id B98B9B7D0B for ; Wed, 21 Apr 2010 08:05:02 +1000 (EST) Received: from localhost ([127.0.0.1]:48299 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1O4LUJ-0005n0-7Y for incoming@patchwork.ozlabs.org; Tue, 20 Apr 2010 18:00:11 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1O4KiY-0007Q3-MS for qemu-devel@nongnu.org; Tue, 20 Apr 2010 17:10:50 -0400 Received: from [140.186.70.92] (port=37599 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1O4KiW-0007Nr-8q for qemu-devel@nongnu.org; Tue, 20 Apr 2010 17:10:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1O4KiU-00044b-HZ for qemu-devel@nongnu.org; Tue, 20 Apr 2010 17:10:48 -0400 Received: from mx1.redhat.com ([209.132.183.28]:53517) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1O4KiU-00044O-AI for qemu-devel@nongnu.org; Tue, 20 Apr 2010 17:10:46 -0400 Received: from int-mx05.intmail.prod.int.phx2.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.18]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o3KLAjI0017102 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 20 Apr 2010 17:10:45 -0400 Received: from localhost (vpn-9-57.rdu.redhat.com [10.11.9.57]) by int-mx05.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o3KLAh8q027315; Tue, 20 Apr 2010 17:10:44 -0400 From: Luiz Capitulino To: qemu-devel@nongnu.org, armbru@redhat.com, quintela@redhat.com, kwolf@redhat.com Date: Tue, 20 Apr 2010 18:09:51 -0300 Message-Id: <1271797792-24571-22-git-send-email-lcapitulino@redhat.com> In-Reply-To: <1271797792-24571-1-git-send-email-lcapitulino@redhat.com> References: <1271797792-24571-1-git-send-email-lcapitulino@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.18 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. Cc: Subject: [Qemu-devel] [PATCH 21/22] savevm: Convert do_loadvm() to QError X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Note that the current code (switch statement) reports errors and warnings. In QMP though, only errors can be reported. To fix this we introduce two functions: load_vmstate_warn() and load_vmstate_error(). So that we maintain the user monitor behavior, and do the right thing for QMP. Signed-off-by: Luiz Capitulino --- savevm.c | 67 ++++++++++++++++++++++++++++++++++++++++++------------------- 1 files changed, 46 insertions(+), 21 deletions(-) diff --git a/savevm.c b/savevm.c index 39a935d..8473833 100644 --- a/savevm.c +++ b/savevm.c @@ -1753,6 +1753,42 @@ int do_savevm(Monitor *mon, const QDict *qdict, QObject **ret_data) return (ret < 0 ? -1 : 0); } +static void load_vmstate_warn(int err_code, BlockDriverState *bs1, + const char *name) +{ + switch (err_code) { + case -ENOTSUP: + error_report("Warning: Snapshots not supported on device '%s'", + bdrv_get_device_name(bs1)); + break; + case -ENOENT: + error_report("Warning: Could not find snapshot '%s' on device '%s'", + name, bdrv_get_device_name(bs1)); + break; + default: + error_report("Warning: Error %d while activating snapshot on '%s'", + err_code, bdrv_get_device_name(bs1)); + break; + } +} + +static void load_vmstate_error(int err_code, BlockDriverState *bs1, + const char *name) +{ + switch (err_code) { + case -ENOTSUP: + qerror_report(QERR_DEVICE_NO_SNAPSHOT, bdrv_get_device_name(bs1)); + break; + case -ENOENT: + qerror_report(QERR_SNAPSHOT_NOT_FOUND, bdrv_get_device_name(bs1), name); + break; + default: + qerror_report(QERR_SNAPSHOT_ACTIVATE_FAILED, + bdrv_get_device_name(bs1), get_errno_string(err_code)); + break; + } +} + int load_vmstate(const char *name) { DriveInfo *dinfo; @@ -1763,7 +1799,7 @@ int load_vmstate(const char *name) bs = get_bs_snapshots(); if (!bs) { - error_report("No block device supports snapshots"); + qerror_report(QERR_SNAPSHOT_NO_DEVICE); return -EINVAL; } @@ -1775,26 +1811,13 @@ int load_vmstate(const char *name) if (bdrv_has_snapshot(bs1)) { ret = bdrv_snapshot_goto(bs1, name); if (ret < 0) { - switch(ret) { - case -ENOTSUP: - error_report("%sSnapshots not supported on device '%s'", - bs != bs1 ? "Warning: " : "", - bdrv_get_device_name(bs1)); - break; - case -ENOENT: - error_report("%sCould not find snapshot '%s' on device '%s'", - bs != bs1 ? "Warning: " : "", - name, bdrv_get_device_name(bs1)); - break; - default: - error_report("%sError %d while activating snapshot on '%s'", - bs != bs1 ? "Warning: " : "", - ret, bdrv_get_device_name(bs1)); - break; - } - /* fatal on snapshot block device */ - if (bs == bs1) + if (bs != bs1) { + load_vmstate_warn(ret, bs1, name); + } else { + /* fatal on snapshot block device */ + load_vmstate_error(ret, bs1, name); return ret; + } } } } @@ -1802,8 +1825,10 @@ int load_vmstate(const char *name) /* Don't even try to load empty VM states */ ret = bdrv_snapshot_find(bs, &sn, name); if (ret < 0) { + qerror_report(QERR_SNAPSHOT_NOT_FOUND, bdrv_get_device_name(bs), name); return ret; } else if (sn.vm_state_size == 0) { + qerror_report(QERR_STATEVM_LOAD_FAILED, get_errno_string(-EINVAL)); return -EINVAL; } @@ -1812,7 +1837,7 @@ int load_vmstate(const char *name) ret = qemu_loadvm_state(f); qemu_fclose(f); if (ret < 0) { - error_report("Error %d while loading VM state", ret); + qerror_report(QERR_STATEVM_LOAD_FAILED, get_errno_string(ret)); return ret; } return 0;