From patchwork Tue Mar 9 22:53:34 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Capitulino X-Patchwork-Id: 47192 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 4A1A9B7D29 for ; Wed, 10 Mar 2010 09:56:18 +1100 (EST) Received: from localhost ([127.0.0.1]:49875 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Np8KX-0004c8-Ce for incoming@patchwork.ozlabs.org; Tue, 09 Mar 2010 17:55:13 -0500 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 Received: from localhost (vpn-11-176.rdu.redhat.com [10.11.11.176]) by int-mx05.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o29Mrg4E018086; Tue, 9 Mar 2010 17:53:42 -0500 From: Luiz Capitulino To: qemu-devel@nongnu.org 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> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.18 X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. Cc: kwolf@redhat.com, uril@redhat.com Subject: [Qemu-devel] [PATCH 1/3] block-qcow2: keep highest allocated offset X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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;