qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH] Do not commit the same changes over and over again


From: Johannes Schindelin
Subject: [Qemu-devel] [PATCH] Do not commit the same changes over and over again
Date: Wed, 30 Nov 2005 18:56:19 +0100 (CET)

When bdrv_commit() was executed, it would write back the modified sectors
to the backing_hd, but would not forget about them in the qcow image.

This patch adds another member function to BlockDriver, bdrv_make_empty()
which can be used to make the qcow image empty. This function is then used
to clean up after a successful commit.

Signed-off-by: Johannes Schindelin <address@hidden>

---

 block-qcow.c |   19 +++++++++++++++++++
 block.c      |    4 ++++
 block_int.h  |    1 +
 3 files changed, 24 insertions(+), 0 deletions(-)

applies-to: eda838aecf494ccae7a893bb9d1891f4f3a1a5c8
afce60fc0d6968f29f28f45a9fef98cc281b66f1
diff --git a/block-qcow.c b/block-qcow.c
index ca05be8..4bc5f88 100644
--- a/block-qcow.c
+++ b/block-qcow.c
@@ -603,6 +603,24 @@ static int qcow_create(const char *filen
     return 0;
 }
 
+int qcow_make_empty(BlockDriverState *bs)
+{
+    BDRVQcowState *s = bs->opaque;
+    uint32_t l1_length = s->l1_size * sizeof(uint64_t);
+
+    memset(s->l1_table, 0, l1_length);
+    lseek(s->fd, s->l1_table_offset, SEEK_SET);
+    if (write(s->fd, s->l1_table, l1_length) < 0)
+       return -1;
+    ftruncate(s->fd, s->l1_table_offset + l1_length);
+
+    memset(s->l2_cache, 0, s->l2_size * L2_CACHE_SIZE * sizeof(uint64_t));
+    memset(s->l2_cache_offsets, 0, L2_CACHE_SIZE * sizeof(uint64_t));
+    memset(s->l2_cache_counts, 0, L2_CACHE_SIZE * sizeof(uint32_t));
+
+    return 0;
+}
+
 int qcow_get_cluster_size(BlockDriverState *bs)
 {
     BDRVQcowState *s = bs->opaque;
@@ -683,6 +701,7 @@ BlockDriver bdrv_qcow = {
     qcow_create,
     qcow_is_allocated,
     qcow_set_key,
+    qcow_make_empty
 };
 
 
diff --git a/block.c b/block.c
index efd96e6..b1a9c0d 100644
--- a/block.c
+++ b/block.c
@@ -394,6 +394,10 @@ int bdrv_commit(BlockDriverState *bs)
             i += n;
         }
     }
+
+    if (bs->drv->bdrv_make_empty)
+       return bs->drv->bdrv_make_empty(bs);
+
     return 0;
 }
 
diff --git a/block_int.h b/block_int.h
index 03744f7..ae8ac38 100644
--- a/block_int.h
+++ b/block_int.h
@@ -39,6 +39,7 @@ struct BlockDriver {
     int (*bdrv_is_allocated)(BlockDriverState *bs, int64_t sector_num,
                              int nb_sectors, int *pnum);
     int (*bdrv_set_key)(BlockDriverState *bs, const char *key);
+    int (*bdrv_make_empty)(BlockDriverState *bs);
     struct BlockDriver *next;
 };
 
---
0.99.9.GIT




reply via email to

[Prev in Thread] Current Thread [Next in Thread]