diff mbox

qcow2: Store exact backing format length

Message ID 1259148804-8583-1-git-send-email-kwolf@redhat.com
State New
Headers show

Commit Message

Kevin Wolf Nov. 25, 2009, 11:33 a.m. UTC
Currently qcow2 unnecessarily rounds up the length of the backing format string
to the next multiple of 8. At the same time, the array in BlockDriverState can
only hold 15 characters, so in effect backing formats with 9 characters or more
don't work (e.g. host_device).

Save the real string length and things start to work for all valid image format
names.

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
 block/qcow2.c |    8 +++++---
 1 files changed, 5 insertions(+), 3 deletions(-)
diff mbox

Patch

diff --git a/block/qcow2.c b/block/qcow2.c
index 3954cf1..4309a95 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -738,6 +738,7 @@  static int qcow_create2(const char *filename, int64_t total_size,
 
     int fd, header_size, backing_filename_len, l1_size, i, shift, l2_bits;
     int ref_clusters, backing_format_len = 0;
+    int rounded_bfmt_len = 0;
     QCowHeader header;
     uint64_t tmp, offset;
     QCowCreateState s1, *s = &s1;
@@ -759,8 +760,9 @@  static int qcow_create2(const char *filename, int64_t total_size,
         if (backing_format) {
             ext_bf.magic = QCOW_EXT_MAGIC_BACKING_FORMAT;
             backing_format_len = strlen(backing_format);
-            ext_bf.len = (backing_format_len + 7) & ~7;
-            header_size += ((sizeof(ext_bf) + ext_bf.len + 7) & ~7);
+            rounded_bfmt_len = (backing_format_len + 7) & ~7;
+            ext_bf.len = backing_format_len;
+            header_size += ((sizeof(ext_bf) + rounded_bfmt_len + 7) & ~7);
         }
         header.backing_file_offset = cpu_to_be64(header_size);
         backing_filename_len = strlen(backing_file);
@@ -828,7 +830,7 @@  static int qcow_create2(const char *filename, int64_t total_size,
     if (backing_file) {
         if (backing_format_len) {
             char zero[16];
-            int d = ext_bf.len - backing_format_len;
+            int d = rounded_bfmt_len - backing_format_len;
 
             memset(zero, 0, sizeof(zero));
             cpu_to_be32s(&ext_bf.magic);