From patchwork Thu Dec 13 15:40:40 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Hrdina X-Patchwork-Id: 206175 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 6338D2C00A6 for ; Fri, 14 Dec 2012 04:04:22 +1100 (EST) Received: from localhost ([::1]:49080 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TjAv2-0002gH-KB for incoming@patchwork.ozlabs.org; Thu, 13 Dec 2012 10:41:52 -0500 Received: from eggs.gnu.org ([208.118.235.92]:47359) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TjAuJ-0001LZ-No 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 1TjAuD-0005sv-Ju for qemu-devel@nongnu.org; Thu, 13 Dec 2012 10:41:07 -0500 Received: from mx1.redhat.com ([209.132.183.28]:16904) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TjAuD-0005sk-CH for qemu-devel@nongnu.org; Thu, 13 Dec 2012 10:41:01 -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 qBDFf0Jv015175 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 13 Dec 2012 10:41:00 -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 qBDFeqvJ030229; Thu, 13 Dec 2012 10:40:59 -0500 From: Pavel Hrdina To: qemu-devel@nongnu.org Date: Thu, 13 Dec 2012 16:40:40 +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 06/17] block: add error parameter to bdrv_snapshot_find() 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 --- savevm.c | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/savevm.c b/savevm.c index e57c108..7ab7c7c 100644 --- a/savevm.c +++ b/savevm.c @@ -2061,16 +2061,21 @@ out: return ret; } -static int bdrv_snapshot_find(BlockDriverState *bs, QEMUSnapshotInfo *sn_info, - const char *name) +static int bdrv_snapshot_find(BlockDriverState *bs, + QEMUSnapshotInfo *sn_info, + const char *name, + Error **errp) { QEMUSnapshotInfo *sn_tab, *sn; int nb_sns, i, ret; + + nb_sns = bdrv_snapshot_list(bs, &sn_tab, errp); + if (error_is_set(errp)) { + return nb_sns; + } + ret = -ENOENT; - nb_sns = bdrv_snapshot_list(bs, &sn_tab, NULL); - if (nb_sns < 0) - return ret; for(i = 0; i < nb_sns; i++) { sn = &sn_tab[i]; if (!strcmp(sn->id_str, name) || !strcmp(sn->name, name)) { @@ -2080,6 +2085,9 @@ static int bdrv_snapshot_find(BlockDriverState *bs, QEMUSnapshotInfo *sn_info, } } g_free(sn_tab); + if (ret < 0) { + error_setg(errp, "Failed to find snapshot '%s'.", name); + } return ret; } @@ -2095,7 +2103,7 @@ static int del_existing_snapshots(Monitor *mon, const char *name) bs = NULL; while ((bs = bdrv_next(bs))) { if (bdrv_can_snapshot(bs) && - bdrv_snapshot_find(bs, snapshot, name) >= 0) + bdrv_snapshot_find(bs, snapshot, name, NULL) >= 0) { ret = bdrv_snapshot_delete(bs, name, NULL); if (ret < 0) { @@ -2166,7 +2174,7 @@ void do_savevm(Monitor *mon, const QDict *qdict) sn->vm_clock_nsec = qemu_get_clock_ns(vm_clock); if (name) { - ret = bdrv_snapshot_find(bs, old_sn, name); + ret = bdrv_snapshot_find(bs, old_sn, name, NULL); if (ret >= 0) { pstrcpy(sn->name, sizeof(sn->name), old_sn->name); pstrcpy(sn->id_str, sizeof(sn->id_str), old_sn->id_str); @@ -2263,7 +2271,7 @@ int load_vmstate(const char *name) } /* Don't even try to load empty VM states */ - ret = bdrv_snapshot_find(bs_vm_state, &sn, name); + ret = bdrv_snapshot_find(bs_vm_state, &sn, name, NULL); if (ret < 0) { return ret; } else if (sn.vm_state_size == 0) { @@ -2287,7 +2295,7 @@ int load_vmstate(const char *name) return -ENOTSUP; } - ret = bdrv_snapshot_find(bs, &sn, name); + ret = bdrv_snapshot_find(bs, &sn, name, NULL); if (ret < 0) { error_report("Device '%s' does not have the requested snapshot '%s'", bdrv_get_device_name(bs), name); @@ -2393,7 +2401,7 @@ void do_info_snapshots(Monitor *mon) while ((bs1 = bdrv_next(bs1))) { if (bdrv_can_snapshot(bs1) && bs1 != bs) { - ret = bdrv_snapshot_find(bs1, sn_info, sn->id_str); + ret = bdrv_snapshot_find(bs1, sn_info, sn->id_str, NULL); if (ret < 0) { available = 0; break;