From patchwork Tue Feb 26 10:40:16 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wayne Xia X-Patchwork-Id: 223193 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 314932C031E for ; Tue, 26 Feb 2013 21:43:34 +1100 (EST) Received: from localhost ([::1]:35857 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UAI0S-0004fe-A6 for incoming@patchwork.ozlabs.org; Tue, 26 Feb 2013 05:43:32 -0500 Received: from eggs.gnu.org ([208.118.235.92]:54546) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UAHzr-0003iA-Af for qemu-devel@nongnu.org; Tue, 26 Feb 2013 05:42:56 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UAHzp-0003cZ-8w for qemu-devel@nongnu.org; Tue, 26 Feb 2013 05:42:55 -0500 Received: from e23smtp08.au.ibm.com ([202.81.31.141]:52898) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UAHzo-0003b5-K0 for qemu-devel@nongnu.org; Tue, 26 Feb 2013 05:42:53 -0500 Received: from /spool/local by e23smtp08.au.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 26 Feb 2013 20:41:01 +1000 Received: from d23dlp01.au.ibm.com (202.81.31.203) by e23smtp08.au.ibm.com (202.81.31.205) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Tue, 26 Feb 2013 20:40:59 +1000 Received: from d23relay03.au.ibm.com (d23relay03.au.ibm.com [9.190.235.21]) by d23dlp01.au.ibm.com (Postfix) with ESMTP id D897F2CE8023 for ; Tue, 26 Feb 2013 21:42:47 +1100 (EST) Received: from d23av01.au.ibm.com (d23av01.au.ibm.com [9.190.234.96]) by d23relay03.au.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id r1QAgjUA6750478 for ; Tue, 26 Feb 2013 21:42:45 +1100 Received: from d23av01.au.ibm.com (loopback [127.0.0.1]) by d23av01.au.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id r1QAglE2015848 for ; Tue, 26 Feb 2013 21:42:47 +1100 Received: from RH63Wenchao (wenchaox.cn.ibm.com [9.115.122.152]) by d23av01.au.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id r1QAeKO7012693; Tue, 26 Feb 2013 21:42:45 +1100 From: Wenchao Xia To: qemu-devel@nongnu.org Date: Tue, 26 Feb 2013 18:40:16 +0800 Message-Id: <1361875228-15769-3-git-send-email-xiawenc@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1361875228-15769-1-git-send-email-xiawenc@linux.vnet.ibm.com> References: <1361875228-15769-1-git-send-email-xiawenc@linux.vnet.ibm.com> X-Content-Scanned: Fidelis XPS MAILER x-cbid: 13022610-5140-0000-0000-000002D03B9E X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 202.81.31.141 Cc: kwolf@redhat.com, aliguori@us.ibm.com, stefanha@gmail.com, armbru@redhat.com, lcapitulino@redhat.com, pbonzini@redhat.com, Wenchao Xia Subject: [Qemu-devel] [PATCH V7 02/14] block: add bdrv_can_read_snapshot() function 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 Compared to bdrv_can_snapshot(), this function return whether bs* is ready to read snapshot info from instead of write. If yes, caller can then query snapshot information, but taking snapshot is not always possible for that *bs may be read only. Signed-off-by: Wenchao Xia Reviewed-by: Eric Blake --- block.c | 19 +++++++++++++++++++ include/block/block.h | 1 + 2 files changed, 20 insertions(+), 0 deletions(-) diff --git a/block.c b/block.c index 50dab8e..19c2d7b 100644 --- a/block.c +++ b/block.c @@ -3058,6 +3058,25 @@ bool bdrv_debug_is_suspended(BlockDriverState *bs, const char *tag) /**************************************************************/ /* handling of snapshots */ +/* return whether internal snapshot can be read on @bs */ +bool bdrv_can_read_snapshot(BlockDriverState *bs) +{ + BlockDriver *drv = bs->drv; + if (!drv || !bdrv_is_inserted(bs)) { + return false; + } + + if (!drv->bdrv_snapshot_create) { + if (bs->file != NULL) { + return bdrv_can_read_snapshot(bs->file); + } + return false; + } + + return true; +} + +/* return whether internal snapshot can be write on @bs */ int bdrv_can_snapshot(BlockDriverState *bs) { BlockDriver *drv = bs->drv; diff --git a/include/block/block.h b/include/block/block.h index 5c3b911..4c48052 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -321,6 +321,7 @@ void bdrv_get_full_backing_filename(BlockDriverState *bs, char *dest, size_t sz); BlockInfo *bdrv_query_info(BlockDriverState *s); BlockStats *bdrv_query_stats(const BlockDriverState *bs); +bool bdrv_can_read_snapshot(BlockDriverState *bs); int bdrv_can_snapshot(BlockDriverState *bs); int bdrv_is_snapshot(BlockDriverState *bs); BlockDriverState *bdrv_snapshots(void);