]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
kvm tools, qcow: Flush only dirty L2 tables
authorPekka Enberg <penberg@kernel.org>
Sat, 9 Jul 2011 12:15:52 +0000 (15:15 +0300)
committerPekka Enberg <penberg@kernel.org>
Sun, 10 Jul 2011 12:23:23 +0000 (15:23 +0300)
This patch improves qcow_l2_cache_write() to only flush dirty L2 tables.

Cc: Asias He <asias.hejun@gmail.com>
Cc: Cyrill Gorcunov <gorcunov@gmail.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Prasad Joshi <prasadjoshi124@gmail.com>
Cc: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
tools/kvm/disk/qcow.c
tools/kvm/include/kvm/qcow.h

index b71762f27d3ee976568c871c1af14ab577391339..13c8bea496f621c1b88eb5eed3f8b3eef3c738e0 100644 (file)
@@ -93,9 +93,17 @@ static int qcow_l2_cache_write(struct qcow *q, struct qcow_l2_table *c)
        struct qcow_header *header = q->header;
        u64 size;
 
+       if (!c->dirty)
+               return 0;
+
        size = 1 << header->l2_bits;
 
-       return pwrite_in_full(q->fd, c->table, size * sizeof(u64), c->offset);
+       if (pwrite_in_full(q->fd, c->table, size * sizeof(u64), c->offset) < 0)
+               return -1;
+
+       c->dirty = 0;
+
+       return 0;
 }
 
 static int cache_table(struct qcow *q, struct qcow_l2_table *c)
@@ -447,6 +455,7 @@ static ssize_t qcow_write_cluster(struct qcow *q, u64 offset, void *buf, u32 src
        if (!clust_start) {
                clust_start             = ALIGN(f_sz, clust_sz);
                l2t->table[l2t_idx]     = cpu_to_be64(clust_start);
+               l2t->dirty              = 1;
        }
 
        mutex_unlock(&q->mutex);
index d44c64ada85001b9c6472a1dda0c8ae25b949df5..650d3c290fd73b9afc8e18c7828059308b8f8e31 100644 (file)
@@ -27,6 +27,7 @@ struct qcow_l2_table {
        u64                     offset;
        struct rb_node          node;
        struct list_head        list;
+       u8                      dirty;
        u64                     table[];
 };