From patchwork Thu Dec 13 15:40:39 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Hrdina X-Patchwork-Id: 206163 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 6B8902C0092 for ; Fri, 14 Dec 2012 03:43:21 +1100 (EST) Received: from localhost ([::1]:50084 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TjAvL-0003Dt-98 for incoming@patchwork.ozlabs.org; Thu, 13 Dec 2012 10:42:11 -0500 Received: from eggs.gnu.org ([208.118.235.92]:47291) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TjAuF-00017S-BK 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 1TjAuB-0005sM-W8 for qemu-devel@nongnu.org; Thu, 13 Dec 2012 10:41:03 -0500 Received: from mx1.redhat.com ([209.132.183.28]:6030) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TjAuB-0005sD-Pl for qemu-devel@nongnu.org; Thu, 13 Dec 2012 10:40:59 -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 qBDFexUP012570 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 13 Dec 2012 10:40:59 -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 qBDFeqvI030229; Thu, 13 Dec 2012 10:40:58 -0500 From: Pavel Hrdina To: qemu-devel@nongnu.org Date: Thu, 13 Dec 2012 16:40:39 +0100 Message-Id: <3862c38764846da34728349cf0b5c3fec31a8660.1355404685.git.phrdina@redhat.com> 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 05/17] block: add error parameter to bdrv_snapshot_list() 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 --- block.c | 26 ++++++++++++++++++-------- block.h | 3 ++- block/qcow2-snapshot.c | 5 ++++- block/qcow2.h | 4 +++- block/rbd.c | 4 +++- block/sheepdog.c | 9 +++++++-- block_int.h | 3 ++- qemu-img.c | 8 ++++++-- savevm.c | 4 ++-- 9 files changed, 47 insertions(+), 19 deletions(-) diff --git a/block.c b/block.c index 1ec4d24..2983dda 100644 --- a/block.c +++ b/block.c @@ -3152,16 +3152,26 @@ int bdrv_snapshot_delete(BlockDriverState *bs, } int bdrv_snapshot_list(BlockDriverState *bs, - QEMUSnapshotInfo **psn_info) + QEMUSnapshotInfo **psn_info, + Error **errp) { BlockDriver *drv = bs->drv; - if (!drv) - return -ENOMEDIUM; - if (drv->bdrv_snapshot_list) - return drv->bdrv_snapshot_list(bs, psn_info); - if (bs->file) - return bdrv_snapshot_list(bs->file, psn_info); - return -ENOTSUP; + int ret; + + if (!drv) { + error_setg(errp, "Device '%s' has no medium.", + bdrv_get_device_name(bs)); + ret = -ENOMEDIUM; + } else if (drv->bdrv_snapshot_list) { + ret = drv->bdrv_snapshot_list(bs, psn_info, errp); + } else if (bs->file) { + ret = bdrv_snapshot_list(bs->file, psn_info, errp); + } else { + error_setg(errp, "Not supported."); + ret = -ENOTSUP; + } + + return ret; } int bdrv_snapshot_load_tmp(BlockDriverState *bs, diff --git a/block.h b/block.h index b6b25a7..ac28fff 100644 --- a/block.h +++ b/block.h @@ -330,7 +330,8 @@ int bdrv_snapshot_delete(BlockDriverState *bs, const char *snapshot_id, Error **errp); int bdrv_snapshot_list(BlockDriverState *bs, - QEMUSnapshotInfo **psn_info); + QEMUSnapshotInfo **psn_info, + Error **errp); int bdrv_snapshot_load_tmp(BlockDriverState *bs, const char *snapshot_name); char *bdrv_snapshot_dump(char *buf, int buf_size, QEMUSnapshotInfo *sn); diff --git a/block/qcow2-snapshot.c b/block/qcow2-snapshot.c index 0bd0d1f..c834605 100644 --- a/block/qcow2-snapshot.c +++ b/block/qcow2-snapshot.c @@ -614,7 +614,9 @@ int qcow2_snapshot_delete(BlockDriverState *bs, return 0; } -int qcow2_snapshot_list(BlockDriverState *bs, QEMUSnapshotInfo **psn_tab) +int qcow2_snapshot_list(BlockDriverState *bs, + QEMUSnapshotInfo **psn_tab, + Error **errp) { BDRVQcowState *s = bs->opaque; QEMUSnapshotInfo *sn_tab, *sn_info; @@ -623,6 +625,7 @@ int qcow2_snapshot_list(BlockDriverState *bs, QEMUSnapshotInfo **psn_tab) if (!s->nb_snapshots) { *psn_tab = NULL; + error_setg(errp, "No snapshot list find."); return s->nb_snapshots; } diff --git a/block/qcow2.h b/block/qcow2.h index 8dfdbb7..2fe5687 100644 --- a/block/qcow2.h +++ b/block/qcow2.h @@ -317,7 +317,9 @@ int qcow2_snapshot_goto(BlockDriverState *bs, int qcow2_snapshot_delete(BlockDriverState *bs, const char *snapshot_id, Error **errp); -int qcow2_snapshot_list(BlockDriverState *bs, QEMUSnapshotInfo **psn_tab); +int qcow2_snapshot_list(BlockDriverState *bs, + QEMUSnapshotInfo **psn_tab, + Error **errp); int qcow2_snapshot_load_tmp(BlockDriverState *bs, const char *snapshot_name); void qcow2_free_snapshots(BlockDriverState *bs); diff --git a/block/rbd.c b/block/rbd.c index f8fe938..d05e9d1 100644 --- a/block/rbd.c +++ b/block/rbd.c @@ -876,7 +876,8 @@ static int qemu_rbd_snap_rollback(BlockDriverState *bs, } static int qemu_rbd_snap_list(BlockDriverState *bs, - QEMUSnapshotInfo **psn_tab) + QEMUSnapshotInfo **psn_tab, + Error **errp) { BDRVRBDState *s = bs->opaque; QEMUSnapshotInfo *sn_info, *sn_tab = NULL; @@ -893,6 +894,7 @@ static int qemu_rbd_snap_list(BlockDriverState *bs, } while (snap_count == -ERANGE); if (snap_count <= 0) { + error_setg(errp, "No snapshot list find."); goto done; } diff --git a/block/sheepdog.c b/block/sheepdog.c index c7f8d9e..c2cd3ad 100644 --- a/block/sheepdog.c +++ b/block/sheepdog.c @@ -1887,7 +1887,9 @@ static int sd_snapshot_delete(BlockDriverState *bs, return 0; } -static int sd_snapshot_list(BlockDriverState *bs, QEMUSnapshotInfo **psn_tab) +static int sd_snapshot_list(BlockDriverState *bs, + QEMUSnapshotInfo **psn_tab, + Error **errp) { BDRVSheepdogState *s = bs->opaque; SheepdogReq req; @@ -1905,6 +1907,7 @@ static int sd_snapshot_list(BlockDriverState *bs, QEMUSnapshotInfo **psn_tab) fd = connect_to_sdog(s->addr, s->port); if (fd < 0) { + error_setg(errp, "Failed to connect to sdog."); ret = fd; goto out; } @@ -1921,6 +1924,7 @@ static int sd_snapshot_list(BlockDriverState *bs, QEMUSnapshotInfo **psn_tab) closesocket(fd); if (ret) { + error_setg(errp, "No snapshot list find."); goto out; } @@ -1932,7 +1936,7 @@ static int sd_snapshot_list(BlockDriverState *bs, QEMUSnapshotInfo **psn_tab) fd = connect_to_sdog(s->addr, s->port); if (fd < 0) { - error_report("failed to connect"); + error_setg(errp, "Failed to connect to sdog."); ret = fd; goto out; } @@ -1973,6 +1977,7 @@ out: g_free(vdi_inuse); if (ret < 0) { + error_setg(errp, "%s", strerror(errno)); return ret; } diff --git a/block_int.h b/block_int.h index 779e3cb..cc60f51 100644 --- a/block_int.h +++ b/block_int.h @@ -156,7 +156,8 @@ struct BlockDriver { const char *snapshot_id, Error **errp); int (*bdrv_snapshot_list)(BlockDriverState *bs, - QEMUSnapshotInfo **psn_info); + QEMUSnapshotInfo **psn_info, + Error **errp); int (*bdrv_snapshot_load_tmp)(BlockDriverState *bs, const char *snapshot_name); int (*bdrv_get_info)(BlockDriverState *bs, BlockDriverInfo *bdi); diff --git a/qemu-img.c b/qemu-img.c index fd9b525..d1690d4 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -1099,8 +1099,10 @@ static void dump_snapshots(BlockDriverState *bs) QEMUSnapshotInfo *sn_tab, *sn; int nb_sns, i; char buf[256]; + Error *err = NULL; - nb_sns = bdrv_snapshot_list(bs, &sn_tab); + nb_sns = bdrv_snapshot_list(bs, &sn_tab, &err); + handle_error(&err); if (nb_sns <= 0) return; printf("Snapshot list:\n"); @@ -1134,7 +1136,9 @@ static void collect_snapshots(BlockDriverState *bs , ImageInfo *info) int i, sn_count; QEMUSnapshotInfo *sn_tab = NULL; SnapshotInfoList *info_list, *cur_item = NULL; - sn_count = bdrv_snapshot_list(bs, &sn_tab); + Error *err = NULL; + sn_count = bdrv_snapshot_list(bs, &sn_tab, &err); + handle_error(&err); for (i = 0; i < sn_count; i++) { info->has_snapshots = true; diff --git a/savevm.c b/savevm.c index 2aaa08b..e57c108 100644 --- a/savevm.c +++ b/savevm.c @@ -2068,7 +2068,7 @@ static int bdrv_snapshot_find(BlockDriverState *bs, QEMUSnapshotInfo *sn_info, int nb_sns, i, ret; ret = -ENOENT; - nb_sns = bdrv_snapshot_list(bs, &sn_tab); + nb_sns = bdrv_snapshot_list(bs, &sn_tab, NULL); if (nb_sns < 0) return ret; for(i = 0; i < nb_sns; i++) { @@ -2373,7 +2373,7 @@ void do_info_snapshots(Monitor *mon) return; } - nb_sns = bdrv_snapshot_list(bs, &sn_tab); + nb_sns = bdrv_snapshot_list(bs, &sn_tab, NULL); if (nb_sns < 0) { monitor_printf(mon, "bdrv_snapshot_list: error %d\n", nb_sns); return;