From patchwork Fri Mar 15 15:14:12 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Hajnoczi X-Patchwork-Id: 228070 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 529982C00B4 for ; Sat, 16 Mar 2013 02:33:03 +1100 (EST) Received: from localhost ([::1]:33507 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UGWT3-0002Vn-En for incoming@patchwork.ozlabs.org; Fri, 15 Mar 2013 11:22:49 -0400 Received: from eggs.gnu.org ([208.118.235.92]:43021) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UGWLX-0008Bn-8j for qemu-devel@nongnu.org; Fri, 15 Mar 2013 11:15:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UGWLT-0004Cj-Gi for qemu-devel@nongnu.org; Fri, 15 Mar 2013 11:15:03 -0400 Received: from mx1.redhat.com ([209.132.183.28]:1642) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UGWLT-0004CZ-89 for qemu-devel@nongnu.org; Fri, 15 Mar 2013 11:14:59 -0400 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.14.4/8.14.4) with ESMTP id r2FFEulb001061 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 15 Mar 2013 11:14:58 -0400 Received: from localhost (ovpn-112-50.ams2.redhat.com [10.36.112.50]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id r2FFEslK004155; Fri, 15 Mar 2013 11:14:55 -0400 From: Stefan Hajnoczi To: Date: Fri, 15 Mar 2013 16:14:12 +0100 Message-Id: <1363360465-5247-16-git-send-email-stefanha@redhat.com> In-Reply-To: <1363360465-5247-1-git-send-email-stefanha@redhat.com> References: <1363360465-5247-1-git-send-email-stefanha@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Anthony Liguori Subject: [Qemu-devel] [PATCH 15/28] qcow2: make is_allocated return true for zero clusters 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 From: Paolo Bonzini Otherwise, live migration of the top layer will miss zero clusters and let the backing file show through. This also matches what is done in qed. QCOW2_CLUSTER_ZERO clusters are invalid in v2 image files. Check this directly in qcow2_get_cluster_offset instead of replicating the test everywhere. Cc: qemu-stable@nongnu.org Signed-off-by: Paolo Bonzini Signed-off-by: Stefan Hajnoczi --- block/qcow2-cluster.c | 3 +++ block/qcow2.c | 6 +----- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c index ff9ae18..d72d063 100644 --- a/block/qcow2-cluster.c +++ b/block/qcow2-cluster.c @@ -454,6 +454,9 @@ int qcow2_get_cluster_offset(BlockDriverState *bs, uint64_t offset, *cluster_offset &= L2E_COMPRESSED_OFFSET_SIZE_MASK; break; case QCOW2_CLUSTER_ZERO: + if (s->qcow_version < 3) { + return -EIO; + } c = count_contiguous_clusters(nb_clusters, s->cluster_size, &l2_table[l2_index], 0, QCOW_OFLAG_COMPRESSED | QCOW_OFLAG_ZERO); diff --git a/block/qcow2.c b/block/qcow2.c index ad43a13..1f99866 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -621,7 +621,7 @@ static int coroutine_fn qcow2_co_is_allocated(BlockDriverState *bs, *pnum = 0; } - return (cluster_offset != 0); + return (cluster_offset != 0) || (ret == QCOW2_CLUSTER_ZERO); } /* handle reading after the end of the backing file */ @@ -702,10 +702,6 @@ static coroutine_fn int qcow2_co_readv(BlockDriverState *bs, int64_t sector_num, break; case QCOW2_CLUSTER_ZERO: - if (s->qcow_version < 3) { - ret = -EIO; - goto fail; - } qemu_iovec_memset(&hd_qiov, 0, 0, 512 * cur_nr_sectors); break;