Sophie

Sophie

distrib > Scientific%20Linux > 5x > x86_64 > media > main-src > by-pkgid > aadbe78a25743146bb784eee19f007c5 > files > 241

kvm-83-164.el5_5.9.src.rpm

From e5f0a502935fd3029cc1895d615882ca455d6f9f Mon Sep 17 00:00:00 2001
From: Uri Lublin <uril@redhat.com>
Date: Mon, 30 Mar 2009 23:15:51 +0300
Subject: [PATCH 10/12] block-qcow2: keep highest allocated offset

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 <uril@redhat.com>
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
Bugzilla: 489964
RH-Upstream-status: pending
Acked-by: Eduardo Habkost <ehabkost@redhat.com>
Acked-by: john cooper <john.cooper@redhat.com>
---
 qemu/block-qcow2.c |   10 ++++++++++
 1 files changed, 10 insertions(+), 0 deletions(-)

diff --git a/qemu/block-qcow2.c b/qemu/block-qcow2.c
index f9c3021..8ef4f1b 100644
--- a/qemu/block-qcow2.c
+++ b/qemu/block-qcow2.c
@@ -153,6 +153,9 @@ typedef struct BDRVQcowState {
     uint32_t crypt_method_header;
     AES_CBC_CIPHER aes_encrypt_cipher;
     AES_CBC_CIPHER aes_decrypt_cipher;
+
+    int64_t highest_alloc; /* highest cluester allocated (in clusters) */
+
     uint64_t snapshots_offset;
     int snapshots_size;
     int nb_snapshots;
@@ -369,6 +372,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;
@@ -2370,6 +2375,11 @@ 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;
 }
 
-- 
1.6.1