From patchwork Thu Jan 12 08:56:01 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robert Wang X-Patchwork-Id: 135596 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 8D785B6EF1 for ; Thu, 12 Jan 2012 19:57:05 +1100 (EST) Received: from localhost ([::1]:56546 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RlGSw-0006Y9-5I for incoming@patchwork.ozlabs.org; Thu, 12 Jan 2012 03:56:58 -0500 Received: from eggs.gnu.org ([140.186.70.92]:45696) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RlGSb-0005ti-JG for qemu-devel@nongnu.org; Thu, 12 Jan 2012 03:56:43 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RlGSa-0005Bp-71 for qemu-devel@nongnu.org; Thu, 12 Jan 2012 03:56:37 -0500 Received: from e23smtp07.au.ibm.com ([202.81.31.140]:56216) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RlGSZ-0005BP-KI for qemu-devel@nongnu.org; Thu, 12 Jan 2012 03:56:36 -0500 Received: from /spool/local by e23smtp07.au.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 12 Jan 2012 08:52:41 +1000 Received: from d23relay03.au.ibm.com ([202.81.31.245]) by e23smtp07.au.ibm.com ([202.81.31.204]) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Thu, 12 Jan 2012 08:52:39 +1000 Received: from d23av02.au.ibm.com (d23av02.au.ibm.com [9.190.235.138]) by d23relay03.au.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id q0C8uCpD5087462 for ; Thu, 12 Jan 2012 19:56:15 +1100 Received: from d23av02.au.ibm.com (loopback [127.0.0.1]) by d23av02.au.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id q0C8uCKv022344 for ; Thu, 12 Jan 2012 19:56:12 +1100 Received: from wdongxu-T410.cn.ibm.com (wdongxu-t410.cn.ibm.com [9.115.118.147] (may be forged)) by d23av02.au.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id q0C8uAI5022298; Thu, 12 Jan 2012 19:56:10 +1100 From: Dong Xu Wang To: qemu-devel@nongnu.org Date: Thu, 12 Jan 2012 16:56:01 +0800 Message-Id: <1326358562-20525-1-git-send-email-wdongxu@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.5.4 x-cbid: 12011122-0260-0000-0000-0000005E0D59 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 202.81.31.140 Cc: kwolf@redhat.com, Dong Xu Wang , stefanha@linux.vnet.ibm.com Subject: [Qemu-devel] [PATCH 1/2 v2] block: add dirty flag status to qemu-img 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 From: Dong Xu Wang Some block drivers can verify their image files are clean or not. So we can show it while using "qemu-img info. Signed-off-by: Dong Xu Wang Reviewed-by: Kevin Wolf Reviewed-by: Stefan Hajnoczi --- Changes from v1: 1. rename bdrv_is_dirty to bdrv_not_cleanly_down, and change its return value from int to bool. 2. Change description from "dirty,need check: yes" to "cleanly shut down: no" block.c | 14 ++++++++++++++ block.h | 2 ++ block_int.h | 1 + qemu-img.c | 3 +++ 4 files changed, 20 insertions(+), 0 deletions(-) diff --git a/block.c b/block.c index 3f072f6..0718466 100644 --- a/block.c +++ b/block.c @@ -186,6 +186,20 @@ static void bdrv_io_limits_intercept(BlockDriverState *bs, qemu_co_queue_next(&bs->throttled_reqs); } +/* check if the image was cleanly shut down */ +bool bdrv_not_cleanly_down(BlockDriverState *bs) +{ + BlockDriver *drv = bs->drv; + + if (!drv) { + return 0; + } + if (!drv->bdrv_not_cleanly_down) { + return 0; + } + return drv->bdrv_not_cleanly_down(bs); +} + /* check if the path starts with ":" */ static int path_has_protocol(const char *path) { diff --git a/block.h b/block.h index 3bd4398..72cf744 100644 --- a/block.h +++ b/block.h @@ -104,6 +104,8 @@ void bdrv_io_limits_enable(BlockDriverState *bs); void bdrv_io_limits_disable(BlockDriverState *bs); bool bdrv_io_limits_enabled(BlockDriverState *bs); +bool bdrv_not_cleanly_down(BlockDriverState *bs); + void bdrv_init(void); void bdrv_init_with_whitelist(void); BlockDriver *bdrv_find_protocol(const char *filename); diff --git a/block_int.h b/block_int.h index 311bd2a..f5168f6 100644 --- a/block_int.h +++ b/block_int.h @@ -84,6 +84,7 @@ struct BlockDriver { int (*bdrv_create)(const char *filename, QEMUOptionParameter *options); int (*bdrv_set_key)(BlockDriverState *bs, const char *key); int (*bdrv_make_empty)(BlockDriverState *bs); + bool (*bdrv_not_cleanly_down)(BlockDriverState *bs); /* aio */ BlockDriverAIOCB *(*bdrv_aio_readv)(BlockDriverState *bs, int64_t sector_num, QEMUIOVector *qiov, int nb_sectors, diff --git a/qemu-img.c b/qemu-img.c index 01cc0d3..d19cae1 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -1153,6 +1153,9 @@ static int img_info(int argc, char **argv) if (bdrv_is_encrypted(bs)) { printf("encrypted: yes\n"); } + if (bdrv_not_cleanly_down(bs)) { + printf("cleanly shut down: no\n"); + } if (bdrv_get_info(bs, &bdi) >= 0) { if (bdi.cluster_size != 0) { printf("cluster_size: %d\n", bdi.cluster_size);