From patchwork Mon Dec 10 09:13:53 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Federico Simoncelli X-Patchwork-Id: 204834 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 B3E012C0193 for ; Mon, 10 Dec 2012 20:15:07 +1100 (EST) Received: from localhost ([::1]:60279 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ThzS4-00051l-DN for incoming@patchwork.ozlabs.org; Mon, 10 Dec 2012 04:15:04 -0500 Received: from eggs.gnu.org ([208.118.235.92]:39520) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ThzRw-00051V-MA for qemu-devel@nongnu.org; Mon, 10 Dec 2012 04:14:57 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ThzRr-00087O-Ht for qemu-devel@nongnu.org; Mon, 10 Dec 2012 04:14:56 -0500 Received: from mx1.redhat.com ([209.132.183.28]:48298) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ThzRr-00087E-9b for qemu-devel@nongnu.org; Mon, 10 Dec 2012 04:14:51 -0500 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id qBA9EnWu011304 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Mon, 10 Dec 2012 04:14:50 -0500 Received: from vm-rhdev1.in1.bytenix.com (ovpn-116-55.ams2.redhat.com [10.36.116.55]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id qBA9ElQh024237; Mon, 10 Dec 2012 04:14:48 -0500 From: Federico Simoncelli To: qemu-devel@nongnu.org Date: Mon, 10 Dec 2012 04:13:53 -0500 Message-Id: <1355130833-4639-1-git-send-email-fsimonce@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Federico Simoncelli Subject: [Qemu-devel] [PATCH] qemu-img: find the highest offset in use during check 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 adds the support for reporting the highest offset in use by an image. This is particularly useful after a conversion (or a rebase) where the destination is a block device in order to find the actual amount of space in use. Signed-off-by: Federico Simoncelli --- block.h | 1 + block/qcow2-refcount.c | 10 ++++++++-- qemu-img.c | 4 ++++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/block.h b/block.h index 722c620..de42e8c 100644 --- a/block.h +++ b/block.h @@ -213,6 +213,7 @@ typedef struct BdrvCheckResult { int check_errors; int corruptions_fixed; int leaks_fixed; + int64_t highest_offset; BlockFragInfo bfi; } BdrvCheckResult; diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c index 96224d1..017439d 100644 --- a/block/qcow2-refcount.c +++ b/block/qcow2-refcount.c @@ -1116,7 +1116,7 @@ int qcow2_check_refcounts(BlockDriverState *bs, BdrvCheckResult *res, BdrvCheckMode fix) { BDRVQcowState *s = bs->opaque; - int64_t size, i; + int64_t size, i, highest_cluster; int nb_clusters, refcount1, refcount2; QCowSnapshot *sn; uint16_t *refcount_table; @@ -1154,7 +1154,7 @@ int qcow2_check_refcounts(BlockDriverState *bs, BdrvCheckResult *res, s->refcount_table_offset, s->refcount_table_size * sizeof(uint64_t)); - for(i = 0; i < s->refcount_table_size; i++) { + for(i = 0, highest_cluster = 0; i < s->refcount_table_size; i++) { uint64_t offset, cluster; offset = s->refcount_table[i]; cluster = offset >> s->cluster_bits; @@ -1197,6 +1197,11 @@ int qcow2_check_refcounts(BlockDriverState *bs, BdrvCheckResult *res, } refcount2 = refcount_table[i]; + + if (refcount1 > 0 || refcount2 > 0) { + highest_cluster = i; + } + if (refcount1 != refcount2) { /* Check if we're allowed to fix the mismatch */ @@ -1231,6 +1236,7 @@ int qcow2_check_refcounts(BlockDriverState *bs, BdrvCheckResult *res, } } + res->highest_offset = (highest_cluster + 1) * s->cluster_size; ret = 0; fail: diff --git a/qemu-img.c b/qemu-img.c index e29e01b..3a8090b 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -470,6 +470,10 @@ static int img_check(int argc, char **argv) result.bfi.fragmented_clusters * 100.0 / result.bfi.allocated_clusters); } + if (result.highest_offset > 0) { + printf("Highest offset in use: %lu\n", result.highest_offset); + } + bdrv_delete(bs); if (ret < 0 || result.check_errors) {