From patchwork Wed Nov 25 11:33:24 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 39305 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id CCE9F1007D1 for ; Wed, 25 Nov 2009 22:35:34 +1100 (EST) Received: from localhost ([127.0.0.1]:58723 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NDG9j-00048U-45 for incoming@patchwork.ozlabs.org; Wed, 25 Nov 2009 06:35:31 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NDG8s-00047M-Ls for qemu-devel@nongnu.org; Wed, 25 Nov 2009 06:34:38 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NDG8m-00043h-Ux for qemu-devel@nongnu.org; Wed, 25 Nov 2009 06:34:37 -0500 Received: from [199.232.76.173] (port=60937 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NDG8l-00043K-Hr for qemu-devel@nongnu.org; Wed, 25 Nov 2009 06:34:31 -0500 Received: from mx1.redhat.com ([209.132.183.28]:63819) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NDG8l-0000QY-2Q for qemu-devel@nongnu.org; Wed, 25 Nov 2009 06:34:31 -0500 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id nAPBYTK9022359 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 25 Nov 2009 06:34:29 -0500 Received: from localhost.localdomain (dhcp-5-175.str.redhat.com [10.32.5.175]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id nAPBYRhJ001461; Wed, 25 Nov 2009 06:34:28 -0500 From: Kevin Wolf To: qemu-devel@nongnu.org Date: Wed, 25 Nov 2009 12:33:24 +0100 Message-Id: <1259148804-8583-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11 X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. Cc: Kevin Wolf Subject: [Qemu-devel] [PATCH] qcow2: Store exact backing format length X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 --- block/qcow2.c | 8 +++++--- 1 files changed, 5 insertions(+), 3 deletions(-) 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);