From patchwork Thu Mar 15 12:47:19 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robert Wang X-Patchwork-Id: 146939 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 56E83B6FA3 for ; Thu, 15 Mar 2012 23:48:28 +1100 (EST) Received: from localhost ([::1]:44155 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S8A6U-0000Pl-9g for incoming@patchwork.ozlabs.org; Thu, 15 Mar 2012 08:48:26 -0400 Received: from eggs.gnu.org ([208.118.235.92]:46789) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S8A6F-0008JN-51 for qemu-devel@nongnu.org; Thu, 15 Mar 2012 08:48:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1S8A66-0000R2-Dg for qemu-devel@nongnu.org; Thu, 15 Mar 2012 08:48:10 -0400 Received: from e23smtp07.au.ibm.com ([202.81.31.140]:44632) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S8A65-0000QO-SW for qemu-devel@nongnu.org; Thu, 15 Mar 2012 08:48:02 -0400 Received: from /spool/local by e23smtp07.au.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 15 Mar 2012 12:42:14 +1000 Received: from d23relay04.au.ibm.com (202.81.31.246) by e23smtp07.au.ibm.com (202.81.31.204) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Thu, 15 Mar 2012 12:41:47 +1000 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 q2FCfeit3129454 for ; Thu, 15 Mar 2012 23:41:40 +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 q2FClS10020846 for ; Thu, 15 Mar 2012 23:47:28 +1100 Received: from wdongxu-T410.ibm.com ([9.125.29.1]) by d23av03.au.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id q2FClQSU020742; Thu, 15 Mar 2012 23:47:27 +1100 From: Dong Xu Wang To: qemu-devel@nongnu.org Date: Thu, 15 Mar 2012 20:47:19 +0800 Message-Id: <1331815641-4789-1-git-send-email-wdongxu@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.5.4 x-cbid: 12031502-0260-0000-0000-000000B2DDC8 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/4 v3] block: add image fragmentation statistics 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 Discussion can be found at: http://patchwork.ozlabs.org/patch/128730/ This patch add image fragmentation statistics while using qemu-img check. Signed-off-by: Dong Xu Wang --- block.h | 7 +++++++ qemu-img.c | 9 ++++++++- 2 files changed, 15 insertions(+), 1 deletions(-) diff --git a/block.h b/block.h index 415bb17..32e1e58 100644 --- a/block.h +++ b/block.h @@ -17,6 +17,12 @@ typedef struct BlockDriverInfo { int64_t vm_state_offset; } BlockDriverInfo; +typedef struct BlockFragInfo { + uint64_t allocated_clusters; + uint64_t total_clusters; + uint64_t fragmented_clusters; +} BlockFragInfo; + typedef struct QEMUSnapshotInfo { char id_str[128]; /* unique snapshot id */ /* the following fields are informative. They are not needed for @@ -175,6 +181,7 @@ typedef struct BdrvCheckResult { int corruptions; int leaks; int check_errors; + BlockFragInfo bfi; } BdrvCheckResult; int bdrv_check(BlockDriverState *bs, BdrvCheckResult *res); diff --git a/qemu-img.c b/qemu-img.c index 0e48b35..4de48ba 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -428,6 +428,13 @@ static int img_check(int argc, char **argv) } } + if (result.bfi.total_clusters != 0 && result.bfi.allocated_clusters != 0) { + printf("%" PRId64 "/%" PRId64 "= %0.2f%% allocated, %0.2f%% fragmented\n", + result.bfi.allocated_clusters, result.bfi.total_clusters, + result.bfi.allocated_clusters * 100.0 / result.bfi.total_clusters, + result.bfi.fragmented_clusters * 100.0 / result.bfi.allocated_clusters); + } + bdrv_delete(bs); if (ret < 0 || result.check_errors) { @@ -716,7 +723,7 @@ static int img_convert(int argc, char **argv) ret = -1; goto out; } - + qemu_progress_init(progress, 2.0); qemu_progress_print(0, 100);