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

[Xen-changelog] [xen-3.4-testing] blktap: fix empty QCOW images (bug 1430 part 2)



# HG changeset patch
# User Keir Fraser <keir.fraser@xxxxxxxxxx>
# Date 1244038588 -3600
# Node ID 35a2fd9805f73d5f1c03d0b2257d5fe54c46a4f3
# Parent  69293fc2096f83943bc607a9456fcc383746e7a9
blktap: fix empty QCOW images (bug 1430 part 2)

Empty QCOW images consist of only the L1 table, this results in a
file size which is not sector-aligned. Since blktap uses O_DIRECT, the
block aligned read of the L1 table will go beyond the end of file and
thus returns the actual file size and not the expected length.
This patch checks whether at least the L1 table has been read.

This should fix bug 1430.

Signed-off-by: Andre Przywara <andre.przywara@xxxxxxx>
xen-unstable changeset:   19702:c5fb6374e79f
xen-unstable date:        Wed Jun 03 11:11:50 2009 +0100
---
 tools/blktap/drivers/block-qcow.c |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)

diff -r 69293fc2096f -r 35a2fd9805f7 tools/blktap/drivers/block-qcow.c
--- a/tools/blktap/drivers/block-qcow.c Wed Jun 03 15:16:07 2009 +0100
+++ b/tools/blktap/drivers/block-qcow.c Wed Jun 03 15:16:28 2009 +0100
@@ -824,7 +824,7 @@ static int tdqcow_open (struct disk_driv
        l1_table_block = ROUNDUP(l1_table_block, 512);
        ret = posix_memalign((void **)&buf2, 4096, l1_table_block);
        if (ret != 0) goto fail;
-       if (read(fd, buf2, l1_table_block) != l1_table_block)
+       if (read(fd, buf2, l1_table_block) < l1_table_size + s->l1_table_offset)
                goto fail;
        memcpy(s->l1_table, buf2 + s->l1_table_offset, l1_table_size);
 
@@ -878,7 +878,8 @@ static int tdqcow_open (struct disk_driv
 
                        memcpy(buf2 + s->l1_table_offset, s->l1_table, 
l1_table_size);
                        lseek(fd, 0, SEEK_SET);
-                       if (write(fd, buf2, l1_table_block) != l1_table_block) {
+                       if (write(fd, buf2, l1_table_block) < 
+                               l1_table_size + s->l1_table_offset) {
                                DPRINTF("qcow: Failed to write new L1 table\n");
                                goto fail;
                        }

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.