From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1O4Khw-00076o-N6 for qemu-devel@nongnu.org; Tue, 20 Apr 2010 17:10:12 -0400 Received: from [140.186.70.92] (port=37256 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1O4Kht-00075C-8c for qemu-devel@nongnu.org; Tue, 20 Apr 2010 17:10:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1O4Khp-0003v3-Ko for qemu-devel@nongnu.org; Tue, 20 Apr 2010 17:10:09 -0400 Received: from mx1.redhat.com ([209.132.183.28]:59593) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1O4Kho-0003uq-K1 for qemu-devel@nongnu.org; Tue, 20 Apr 2010 17:10:05 -0400 Received: from int-mx04.intmail.prod.int.phx2.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.17]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o3KLA3kw016772 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 20 Apr 2010 17:10:04 -0400 From: Luiz Capitulino Date: Tue, 20 Apr 2010 18:09:33 -0300 Message-Id: <1271797792-24571-4-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> Subject: [Qemu-devel] [PATCH 03/22] savevm: Introduce delete_snapshot() and use it List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org, armbru@redhat.com, quintela@redhat.com, kwolf@redhat.com del_existing_snapshots() and do_delvm() can share some code as the two call bdrv_snapshot_delete() and print a message to the user if an error has happened. This commit introduces a new function to share this code. Please, note that while do_delvm() should stay the same, del_existing_snapshots() will now print a specific message for -ENOTSUP errors (instead of a generic one). Signed-off-by: Luiz Capitulino --- savevm.c | 39 ++++++++++++++++++++++++--------------- 1 files changed, 24 insertions(+), 15 deletions(-) diff --git a/savevm.c b/savevm.c index 254f9fc..cc6cbb2 100644 --- a/savevm.c +++ b/savevm.c @@ -1619,6 +1619,28 @@ static int bdrv_snapshot_find(BlockDriverState *bs, QEMUSnapshotInfo *sn_info, return ret; } +static int delete_snapshot(Monitor *mon, BlockDriverState *bs, + const char *name) +{ + int ret; + + ret = bdrv_snapshot_delete(bs, name); + if (ret < 0) { + switch (ret) { + case -ENOTSUP: + monitor_printf(mon, "Snapshots not supported on device '%s'\n", + bdrv_get_device_name(bs)); + break; + default: + monitor_printf(mon, "Error %d while deleting snapshot on '%s'\n", + ret, bdrv_get_device_name(bs)); + break; + } + } + + return ret; +} + /* * Deletes snapshots of a given name in all opened images. */ @@ -1634,11 +1656,8 @@ static int del_existing_snapshots(Monitor *mon, const char *name) if (bdrv_can_snapshot(bs) && bdrv_snapshot_find(bs, snapshot, name) >= 0) { - ret = bdrv_snapshot_delete(bs, name); + ret = delete_snapshot(mon, bs, name); if (ret < 0) { - monitor_printf(mon, - "Error while deleting snapshot on '%s'\n", - bdrv_get_device_name(bs)); return -1; } } @@ -1799,7 +1818,6 @@ void do_delvm(Monitor *mon, const QDict *qdict) { DriveInfo *dinfo; BlockDriverState *bs, *bs1; - int ret; const char *name = qdict_get_str(qdict, "name"); bs = get_bs_snapshots(); @@ -1811,16 +1829,7 @@ void do_delvm(Monitor *mon, const QDict *qdict) QTAILQ_FOREACH(dinfo, &drives, next) { bs1 = dinfo->bdrv; if (bdrv_has_snapshot(bs1)) { - ret = bdrv_snapshot_delete(bs1, name); - if (ret < 0) { - if (ret == -ENOTSUP) - monitor_printf(mon, - "Snapshots not supported on device '%s'\n", - bdrv_get_device_name(bs1)); - else - monitor_printf(mon, "Error %d while deleting snapshot on " - "'%s'\n", ret, bdrv_get_device_name(bs1)); - } + delete_snapshot(mon, bs1, name); } } } -- 1.7.1.rc1.12.ga6018