diff mbox

[1/3] block-qcow2: keep highest allocated offset

Message ID 1268175216-3600-2-git-send-email-lcapitulino@redhat.com
State New
Headers show

Commit Message

Luiz Capitulino March 9, 2010, 10:53 p.m. UTC
From: Uri Lublin <uril@redhat.com>

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: Luiz Capitulino <lcapitulino@redhat.com>
---
 block/qcow2-refcount.c |    3 +++
 block/qcow2.c          |    2 ++
 block/qcow2.h          |    3 +++
 3 files changed, 8 insertions(+), 0 deletions(-)
diff mbox

Patch

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;