]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
kvm tools, qcow: Delayed L1 table writeout
authorPekka Enberg <penberg@kernel.org>
Sat, 9 Jul 2011 07:23:07 +0000 (10:23 +0300)
committerPekka Enberg <penberg@kernel.org>
Sun, 10 Jul 2011 12:23:22 +0000 (15:23 +0300)
This patch moves L1 table writeout to qcow_disk_flush(). The rationale here is
that while writes to clusters that don't have L2 table allocated on-disk are
volatile until VIRTIO_BLK_T_FLUSH is issued, we never corrupt the disk image.

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

index 1a6a969dbc61aaf92e1bf905fc92cfabdcfa4d91..0fef92f5b703f239a635c11c4f6b566435062daf 100644 (file)
@@ -421,17 +421,6 @@ static ssize_t qcow_write_cluster(struct qcow *q, u64 offset, void *buf, u32 src
                if (!l2t_off)
                        goto free_cache;
 
-               /* Metadata update: update on disk level 1 table */
-               t               = cpu_to_be64(l2t_off);
-
-               if (qcow_pwrite_sync(q->fd, &t, sizeof(t), header->l1_table_offset + l1t_idx * sizeof(u64)) < 0) {
-                       /* restore file to consistent state */
-                       if (ftruncate(q->fd, f_sz) < 0)
-                               goto free_cache;
-
-                       goto free_cache;
-               }
-
                if (cache_table(q, l2t) < 0) {
                        if (ftruncate(q->fd, f_sz) < 0)
                                goto free_cache;
@@ -522,6 +511,19 @@ static ssize_t qcow_nowrite_sector(struct disk_image *disk, u64 sector, void *sr
 
 static int qcow_disk_flush(struct disk_image *disk)
 {
+       struct qcow *q = disk->priv;
+       struct qcow_header *header;
+       struct qcow_table *table;
+
+       if (fdatasync(disk->fd) < 0)
+               return -1;
+
+       header  = q->header;
+       table   = &q->table;
+
+       if (pwrite_in_full(disk->fd, table->l1_table, table->table_size * sizeof(u64), header->l1_table_offset) < 0)
+               return -1;
+
        return fsync(disk->fd);
 }