From d8ec5096bc57f59aa0e84330f97ea00a7e950983 Mon Sep 17 00:00:00 2001 From: Kevin Wolf <kwolf@redhat.com> Date: Wed, 25 Nov 2009 12:03:30 -0200 Subject: [PATCH 1/2] qcow2: Store exact backing format length RH-Author: Kevin Wolf <kwolf@redhat.com> Message-id: <1259150610-10141-1-git-send-email-kwolf@redhat.com> Patchwork-id: 3786 O-Subject: [RHEL-5.5 KVM PATCH] qcow2: Store exact backing format length Bugzilla: 540893 RH-Acked-by: Uri Lublin <uril@redhat.com> RH-Acked-by: Juan Quintela <quintela@redhat.com> RH-Acked-by: Markus Armbruster <armbru@redhat.com> Bugzilla: 540893 Upstream status: Submitted 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> --- qemu/block-qcow2.c | 8 +++++--- 1 files changed, 5 insertions(+), 3 deletions(-) Signed-off-by: Eduardo Habkost <ehabkost@redhat.com> --- qemu/block-qcow2.c | 8 +++++--- 1 files changed, 5 insertions(+), 3 deletions(-) diff --git a/qemu/block-qcow2.c b/qemu/block-qcow2.c index 413291f..dc37832 100644 --- a/qemu/block-qcow2.c +++ b/qemu/block-qcow2.c @@ -1637,6 +1637,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; @@ -1658,8 +1659,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); @@ -1713,7 +1715,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); -- 1.6.3.rc4.29.g8146