From patchwork Mon Feb 18 14:09:26 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wayne Xia X-Patchwork-Id: 221436 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 6C82E2C007B for ; Tue, 19 Feb 2013 05:14:45 +1100 (EST) Received: from localhost ([::1]:39383 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U7RTK-0007dv-Qv for incoming@patchwork.ozlabs.org; Mon, 18 Feb 2013 09:13:34 -0500 Received: from eggs.gnu.org ([208.118.235.92]:60478) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U7RSc-0006L1-Ku for qemu-devel@nongnu.org; Mon, 18 Feb 2013 09:12:55 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1U7RSX-0002Gm-7u for qemu-devel@nongnu.org; Mon, 18 Feb 2013 09:12:50 -0500 Received: from e28smtp07.in.ibm.com ([122.248.162.7]:46323) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U7RSW-0002G6-Nd for qemu-devel@nongnu.org; Mon, 18 Feb 2013 09:12:45 -0500 Received: from /spool/local by e28smtp07.in.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 18 Feb 2013 19:39:56 +0530 Received: from d28dlp02.in.ibm.com (9.184.220.127) by e28smtp07.in.ibm.com (192.168.1.137) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Mon, 18 Feb 2013 19:39:54 +0530 Received: from d28relay02.in.ibm.com (d28relay02.in.ibm.com [9.184.220.59]) by d28dlp02.in.ibm.com (Postfix) with ESMTP id E66FC394004F for ; Mon, 18 Feb 2013 19:42:38 +0530 (IST) Received: from d28av02.in.ibm.com (d28av02.in.ibm.com [9.184.220.64]) by d28relay02.in.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id r1IECaic24117372 for ; Mon, 18 Feb 2013 19:42:36 +0530 Received: from d28av02.in.ibm.com (loopback [127.0.0.1]) by d28av02.in.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id r1IECcxR008340 for ; Tue, 19 Feb 2013 01:12:38 +1100 Received: from RH63Wenchao ([9.77.177.33]) by d28av02.in.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id r1IEA8vn030211; Tue, 19 Feb 2013 01:12:35 +1100 From: Wenchao Xia To: qemu-devel@nongnu.org Date: Mon, 18 Feb 2013 22:09:26 +0800 Message-Id: <1361196578-19016-3-git-send-email-xiawenc@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1361196578-19016-1-git-send-email-xiawenc@linux.vnet.ibm.com> References: <1361196578-19016-1-git-send-email-xiawenc@linux.vnet.ibm.com> X-Content-Scanned: Fidelis XPS MAILER x-cbid: 13021814-8878-0000-0000-000005F0060C X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 122.248.162.7 Cc: kwolf@redhat.com, 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 V6 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 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);