From patchwork Thu Apr 12 15:01:06 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 152118 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id A7C6AB70FB for ; Fri, 13 Apr 2012 02:03:50 +1000 (EST) Received: from localhost ([::1]:35393 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SILU4-0000ak-50 for incoming@patchwork.ozlabs.org; Thu, 12 Apr 2012 10:58:52 -0400 Received: from eggs.gnu.org ([208.118.235.92]:51527) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SILT9-0007Hk-4Q for qemu-devel@nongnu.org; Thu, 12 Apr 2012 10:57:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SILT2-0008Hw-EE for qemu-devel@nongnu.org; Thu, 12 Apr 2012 10:57:54 -0400 Received: from mx1.redhat.com ([209.132.183.28]:12694) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SILT2-0008Ha-3z for qemu-devel@nongnu.org; Thu, 12 Apr 2012 10:57:48 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q3CEvjF9029936 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 12 Apr 2012 10:57:45 -0400 Received: from dhcp-5-188.str.redhat.com (dhcp-5-175.str.redhat.com [10.32.5.175]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id q3CEvbxO032333; Thu, 12 Apr 2012 10:57:44 -0400 From: Kevin Wolf To: qemu-devel@nongnu.org Date: Thu, 12 Apr 2012 17:01:06 +0200 Message-Id: <1334242880-28433-6-git-send-email-kwolf@redhat.com> In-Reply-To: <1334242880-28433-1-git-send-email-kwolf@redhat.com> References: <1334242880-28433-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.132.183.28 Cc: kwolf@redhat.com, stefanha@gmail.com, pbonzini@redhat.com Subject: [Qemu-devel] [PATCH 05/19] qcow2: Fail write_compressed when overwriting data X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org qcow2_alloc_compressed_cluster_offset() already fails if the copied flag is set, because qcow2_write_compressed() doesn't perform COW as it would have to do to allow this. However, what we really want to check here is whether the cluster is allocated or not. With internal snapshots the copied flag may not be set on allocated clusters. Check the cluster offset instead. Signed-off-by: Kevin Wolf --- block/qcow2-cluster.c | 7 +++---- 1 files changed, 3 insertions(+), 4 deletions(-) diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c index 9547fa9..b26028c 100644 --- a/block/qcow2-cluster.c +++ b/block/qcow2-cluster.c @@ -571,15 +571,14 @@ uint64_t qcow2_alloc_compressed_cluster_offset(BlockDriverState *bs, return 0; } + /* Compression can't overwrite anything. Fail if the cluster was already + * allocated. */ cluster_offset = be64_to_cpu(l2_table[l2_index]); - if (cluster_offset & QCOW_OFLAG_COPIED) { + if (cluster_offset & L2E_OFFSET_MASK) { qcow2_cache_put(bs, s->l2_table_cache, (void**) &l2_table); return 0; } - if (cluster_offset) - qcow2_free_any_clusters(bs, cluster_offset, 1); - cluster_offset = qcow2_alloc_bytes(bs, compressed_size); if (cluster_offset < 0) { qcow2_cache_put(bs, s->l2_table_cache, (void**) &l2_table);