From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1LKrxC-0001J9-Qw for qemu-devel@nongnu.org; Thu, 08 Jan 2009 05:17:30 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1LKrxB-0001I8-Pa for qemu-devel@nongnu.org; Thu, 08 Jan 2009 05:17:30 -0500 Received: from [199.232.76.173] (port=48779 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LKrxB-0001Hw-J1 for qemu-devel@nongnu.org; Thu, 08 Jan 2009 05:17:29 -0500 Received: from ns.suse.de ([195.135.220.2]:49802 helo=mx1.suse.de) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1LKrxA-0003Tt-Po for qemu-devel@nongnu.org; Thu, 08 Jan 2009 05:17:29 -0500 Received: from Relay1.suse.de (relay-ext.suse.de [195.135.221.8]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.suse.de (Postfix) with ESMTP id ECEF145703 for ; Thu, 8 Jan 2009 11:17:25 +0100 (CET) Message-ID: <4965D3FC.1090508@suse.de> Date: Thu, 08 Jan 2009 11:22:52 +0100 From: Kevin Wolf MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="------------060402010504030706080002" Subject: [Qemu-devel] [PATCH] qcow1: Fix compressed images Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org This is a multi-part message in MIME format. --------------060402010504030706080002 Content-Type: text/plain; charset=ISO-8859-15 Content-Transfer-Encoding: 7bit Revert r4673, the removed dead code wasn't dead in fact. Additionally, change the misleading else which tricks the reader into believing that allocate is a boolean to else if (allocate == 2). Signed-off-by: Kevin Wolf --------------060402010504030706080002 Content-Type: text/x-patch; name="fix-compressed-qcow1.patch" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="fix-compressed-qcow1.patch" Index: qemu-svn/block-qcow.c =================================================================== --- qemu-svn.orig/block-qcow.c +++ qemu-svn/block-qcow.c @@ -339,28 +339,33 @@ static uint64_t get_cluster_offset(Block return -1; } else { cluster_offset = bdrv_getlength(s->hd); - /* round to cluster size */ - cluster_offset = (cluster_offset + s->cluster_size - 1) & - ~(s->cluster_size - 1); - bdrv_truncate(s->hd, cluster_offset + s->cluster_size); - /* if encrypted, we must initialize the cluster - content which won't be written */ - if (s->crypt_method && - (n_end - n_start) < s->cluster_sectors) { - uint64_t start_sect; - start_sect = (offset & ~(s->cluster_size - 1)) >> 9; - memset(s->cluster_data + 512, 0x00, 512); - for(i = 0; i < s->cluster_sectors; i++) { - if (i < n_start || i >= n_end) { - encrypt_sectors(s, start_sect + i, - s->cluster_data, - s->cluster_data + 512, 1, 1, - &s->aes_encrypt_key); - if (bdrv_pwrite(s->hd, cluster_offset + i * 512, - s->cluster_data, 512) != 512) - return -1; + if (allocate == 1) { + /* round to cluster size */ + cluster_offset = (cluster_offset + s->cluster_size - 1) & + ~(s->cluster_size - 1); + bdrv_truncate(s->hd, cluster_offset + s->cluster_size); + /* if encrypted, we must initialize the cluster + content which won't be written */ + if (s->crypt_method && + (n_end - n_start) < s->cluster_sectors) { + uint64_t start_sect; + start_sect = (offset & ~(s->cluster_size - 1)) >> 9; + memset(s->cluster_data + 512, 0x00, 512); + for(i = 0; i < s->cluster_sectors; i++) { + if (i < n_start || i >= n_end) { + encrypt_sectors(s, start_sect + i, + s->cluster_data, + s->cluster_data + 512, 1, 1, + &s->aes_encrypt_key); + if (bdrv_pwrite(s->hd, cluster_offset + i * 512, + s->cluster_data, 512) != 512) + return -1; + } } } + } else if (allocate == 2) { + cluster_offset |= QCOW_OFLAG_COMPRESSED | + (uint64_t)compressed_size << (63 - s->cluster_bits); } } /* update L2 table */ --------------060402010504030706080002--