From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Np8J9-0004bI-Al for qemu-devel@nongnu.org; Tue, 09 Mar 2010 17:53:47 -0500 Received: from [199.232.76.173] (port=36550 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Np8J8-0004b5-Sx for qemu-devel@nongnu.org; Tue, 09 Mar 2010 17:53:46 -0500 Received: from Debian-exim by monty-python.gnu.org with spam-scanned (Exim 4.60) (envelope-from ) id 1Np8J7-0004HG-DH for qemu-devel@nongnu.org; Tue, 09 Mar 2010 17:53:46 -0500 Received: from mx1.redhat.com ([209.132.183.28]:51678) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1Np8J6-0004H8-Vi for qemu-devel@nongnu.org; Tue, 09 Mar 2010 17:53:45 -0500 Received: from int-mx05.intmail.prod.int.phx2.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.18]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o29Mritk021526 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 9 Mar 2010 17:53:44 -0500 From: Luiz Capitulino Date: Tue, 9 Mar 2010 19:53:34 -0300 Message-Id: <1268175216-3600-2-git-send-email-lcapitulino@redhat.com> In-Reply-To: <1268175216-3600-1-git-send-email-lcapitulino@redhat.com> References: <1268175216-3600-1-git-send-email-lcapitulino@redhat.com> Subject: [Qemu-devel] [PATCH 1/3] block-qcow2: keep highest allocated offset List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: kwolf@redhat.com, uril@redhat.com From: Uri Lublin We want to know the highest allocated offset for qcow2 images. It can be useful for allocating more diskspace for an image (e.g. an lvm logical volume) before we run out-of-disk-space. In this version image refcount table is not scanned. Also highest-alloc is not kept when the process exits. Thus it only keeps the highest offset of the current run. Signed-off-by: Uri Lublin Signed-off-by: Luiz Capitulino --- block/qcow2-refcount.c | 3 +++ block/qcow2.c | 2 ++ block/qcow2.h | 3 +++ 3 files changed, 8 insertions(+), 0 deletions(-) diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c index 917fc88..9cb38c8 100644 --- a/block/qcow2-refcount.c +++ b/block/qcow2-refcount.c @@ -550,6 +550,9 @@ retry: size, (s->free_cluster_index - nb_clusters) << s->cluster_bits); #endif + if (s->highest_alloc < s->free_cluster_index) { + s->highest_alloc = s->free_cluster_index; + } return (s->free_cluster_index - nb_clusters) << s->cluster_bits; } diff --git a/block/qcow2.c b/block/qcow2.c index 5b6dad9..d9af90b 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -230,6 +230,8 @@ static int qcow_open(BlockDriverState *bs, const char *filename, int flags) if (qcow_read_extensions(bs, sizeof(header), ext_end)) goto fail; + s->highest_alloc = 0; + /* read the backing file name */ if (header.backing_file_offset != 0) { len = header.backing_file_size; diff --git a/block/qcow2.h b/block/qcow2.h index de9397a..6cc50e6 100644 --- a/block/qcow2.h +++ b/block/qcow2.h @@ -112,6 +112,9 @@ typedef struct BDRVQcowState { uint32_t crypt_method_header; AES_KEY aes_encrypt_key; AES_KEY aes_decrypt_key; + + int64_t highest_alloc; /* highest cluester allocated (in clusters) */ + uint64_t snapshots_offset; int snapshots_size; int nb_snapshots; -- 1.7.0.1