From patchwork Thu Jan 24 02:57:54 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wayne Xia X-Patchwork-Id: 215190 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 208012C0079 for ; Thu, 24 Jan 2013 14:51:14 +1100 (EST) Received: from localhost ([::1]:46536 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TyCkg-0006wP-Cw for incoming@patchwork.ozlabs.org; Wed, 23 Jan 2013 21:41:18 -0500 Received: from eggs.gnu.org ([208.118.235.92]:59316) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TyCkJ-0006ka-6d for qemu-devel@nongnu.org; Wed, 23 Jan 2013 21:40:56 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TyCkF-00063F-NB for qemu-devel@nongnu.org; Wed, 23 Jan 2013 21:40:55 -0500 Received: from e23smtp09.au.ibm.com ([202.81.31.142]:56825) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TyCkF-00062z-04 for qemu-devel@nongnu.org; Wed, 23 Jan 2013 21:40:51 -0500 Received: from /spool/local by e23smtp09.au.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 24 Jan 2013 12:34:32 +1000 Received: from d23dlp03.au.ibm.com (202.81.31.214) by e23smtp09.au.ibm.com (202.81.31.206) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Thu, 24 Jan 2013 12:34:30 +1000 Received: from d23relay04.au.ibm.com (d23relay04.au.ibm.com [9.190.234.120]) by d23dlp03.au.ibm.com (Postfix) with ESMTP id 105A9357804D for ; Thu, 24 Jan 2013 13:40:45 +1100 (EST) Received: from d23av03.au.ibm.com (d23av03.au.ibm.com [9.190.234.97]) by d23relay04.au.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id r0O2Sver6816236 for ; Thu, 24 Jan 2013 13:28:57 +1100 Received: from d23av03.au.ibm.com (loopback [127.0.0.1]) by d23av03.au.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id r0O2eg6V015258 for ; Thu, 24 Jan 2013 13:40:44 +1100 Received: from RH63Wenchao (wenchaox.cn.ibm.com [9.115.122.253]) by d23av03.au.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id r0O2cfjU012627; Thu, 24 Jan 2013 13:40:40 +1100 From: Wenchao Xia To: qemu-devel@nongnu.org Date: Thu, 24 Jan 2013 10:57:54 +0800 Message-Id: <1358996283-32441-5-git-send-email-xiawenc@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1358996283-32441-1-git-send-email-xiawenc@linux.vnet.ibm.com> References: <1358996283-32441-1-git-send-email-xiawenc@linux.vnet.ibm.com> X-Content-Scanned: Fidelis XPS MAILER x-cbid: 13012402-3568-0000-0000-00000312294F X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 202.81.31.142 Cc: aliguori@us.ibm.com, phrdina@redhat.com, stefanha@gmail.com, armbru@redhat.com, lcapitulino@redhat.com, pbonzini@redhat.com, Wenchao Xia Subject: [Qemu-devel] [PATCH V5 04/13] block: add snapshot info query function bdrv_query_snapshot_infolist() 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 This patch add function bdrv_query_snapshot_infolist(), which will return snapshot info of an image in qmp object format. The implementation code are mostly copied from qemu-img.c with modification to fit more for qmp based block layer API. To help filter out snapshot info not needed, a call back function is added in bdrv_query_snapshot_infolist(). bdrv_can_read_snapshot() should be called before call this function, to avoid got *errp set unexpectedly. Signed-off-by: Wenchao Xia Reviewed-by: Eric Blake --- block.c | 60 +++++++++++++++++++++++++++++++++++++++++++++++++ include/block/block.h | 7 +++++ 2 files changed, 67 insertions(+), 0 deletions(-) diff --git a/block.c b/block.c index 934bb3f..7cdb6c6 100644 --- a/block.c +++ b/block.c @@ -2842,6 +2842,66 @@ int coroutine_fn bdrv_co_is_allocated_above(BlockDriverState *top, return 0; } +SnapshotInfoList *bdrv_query_snapshot_infolist(BlockDriverState *bs, + SnapshotFilterFunc filter, + void *opaque, + Error **errp) +{ + int i, sn_count; + QEMUSnapshotInfo *sn_tab = NULL; + SnapshotInfoList *info_list, *cur_item = NULL, *head = NULL; + + sn_count = bdrv_snapshot_list(bs, &sn_tab); + if (sn_count < 0) { + /* Now bdrv_snapshot_list() use negative value to tip error, so a check + * of it was done here. In future errp can be set by that function + * itself, by changing the call back functions in c files in ./block. + */ + const char *dev = bdrv_get_device_name(bs); + if (sn_count == -ENOMEDIUM) { + error_setg(errp, "Device '%s' is not inserted.", dev); + } else if (sn_count == -ENOTSUP) { + error_setg(errp, + "Device '%s' does not support internal snapshot.", + dev); + } else { + error_setg(errp, + "Device '%s' got %d for bdrv_snapshot_list().", + dev, sn_count); + } + return NULL; + } + + for (i = 0; i < sn_count; i++) { + if (filter && filter(&sn_tab[i], opaque) != 0) { + continue; + } + + info_list = g_new0(SnapshotInfoList, 1); + + info_list->value = g_new0(SnapshotInfo, 1); + info_list->value->id = g_strdup(sn_tab[i].id_str); + info_list->value->name = g_strdup(sn_tab[i].name); + info_list->value->vm_state_size = sn_tab[i].vm_state_size; + info_list->value->date_sec = sn_tab[i].date_sec; + info_list->value->date_nsec = sn_tab[i].date_nsec; + info_list->value->vm_clock_sec = sn_tab[i].vm_clock_nsec / 1000000000; + info_list->value->vm_clock_nsec = sn_tab[i].vm_clock_nsec % 1000000000; + + /* XXX: waiting for the qapi to support qemu-queue.h types */ + if (!cur_item) { + head = cur_item = info_list; + } else { + cur_item->next = info_list; + cur_item = info_list; + } + + } + + g_free(sn_tab); + return head; +} + BlockInfo *bdrv_query_info(BlockDriverState *bs) { BlockInfo *info = g_malloc0(sizeof(*info)); diff --git a/include/block/block.h b/include/block/block.h index b4c1612..ce18d4b 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -316,6 +316,13 @@ void bdrv_get_backing_filename(BlockDriverState *bs, char *filename, int filename_size); void bdrv_get_full_backing_filename(BlockDriverState *bs, char *dest, size_t sz); + +typedef int (*SnapshotFilterFunc)(const QEMUSnapshotInfo *sn, void *opaque); +/* assume bs is already opened, use qapi_free_* to free returned value. */ +SnapshotInfoList *bdrv_query_snapshot_infolist(BlockDriverState *bs, + SnapshotFilterFunc filter, + void *opaque, + Error **errp); BlockInfo *bdrv_query_info(BlockDriverState *s); BlockStats *bdrv_query_stats(const BlockDriverState *bs); int bdrv_can_read_snapshot(BlockDriverState *bs);