From patchwork Tue Oct 18 15:47:38 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 120455 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id AE9EDB71AD for ; Wed, 19 Oct 2011 02:44:52 +1100 (EST) Received: from localhost ([::1]:54244 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RGBqR-0000X7-G5 for incoming@patchwork.ozlabs.org; Tue, 18 Oct 2011 11:44:47 -0400 Received: from eggs.gnu.org ([140.186.70.92]:51056) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RGBqL-0000Wo-Gg for qemu-devel@nongnu.org; Tue, 18 Oct 2011 11:44:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RGBqH-0003MU-Dm for qemu-devel@nongnu.org; Tue, 18 Oct 2011 11:44:41 -0400 Received: from mx1.redhat.com ([209.132.183.28]:24215) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RGBqH-0003MI-1A for qemu-devel@nongnu.org; Tue, 18 Oct 2011 11:44:37 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p9IFiaI4029327 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 18 Oct 2011 11:44:36 -0400 Received: from dhcp-5-188.str.redhat.com (dhcp-5-175.str.redhat.com [10.32.5.175]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id p9IFiXVN023692; Tue, 18 Oct 2011 11:44:35 -0400 From: Kevin Wolf To: qemu-devel@nongnu.org Date: Tue, 18 Oct 2011 17:47:38 +0200 Message-Id: <1318952858-18960-2-git-send-email-kwolf@redhat.com> In-Reply-To: <1318952858-18960-1-git-send-email-kwolf@redhat.com> References: <1318952858-18960-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 209.132.183.28 Cc: kwolf@redhat.com Subject: [Qemu-devel] [PATCH 2/2] qcow2: Fix bdrv_write_compressed error handling 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 If during allocation of compressed clusters the cluster was already allocated uncompressed, fail and properly release the l2_table (the latter avoids a failed assertion). While at it, make it return some real error numbers instead of -1. Signed-off-by: Kevin Wolf --- block/qcow2-cluster.c | 6 ++++-- block/qcow2.c | 11 ++++++----- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c index 2f76311..f4e049f 100644 --- a/block/qcow2-cluster.c +++ b/block/qcow2-cluster.c @@ -568,8 +568,10 @@ uint64_t qcow2_alloc_compressed_cluster_offset(BlockDriverState *bs, } cluster_offset = be64_to_cpu(l2_table[l2_index]); - if (cluster_offset & QCOW_OFLAG_COPIED) - return cluster_offset & ~QCOW_OFLAG_COPIED; + if (cluster_offset & QCOW_OFLAG_COPIED) { + qcow2_cache_put(bs, s->l2_table_cache, (void**) &l2_table); + return 0; + } if (cluster_offset) qcow2_free_any_clusters(bs, cluster_offset, 1); diff --git a/block/qcow2.c b/block/qcow2.c index 4dc980c..bf399f3 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -1054,7 +1054,7 @@ static int qcow2_write_compressed(BlockDriverState *bs, int64_t sector_num, 9, Z_DEFAULT_STRATEGY); if (ret != 0) { g_free(out_buf); - return -1; + return -EINVAL; } strm.avail_in = s->cluster_size; @@ -1066,7 +1066,7 @@ static int qcow2_write_compressed(BlockDriverState *bs, int64_t sector_num, if (ret != Z_STREAM_END && ret != Z_OK) { g_free(out_buf); deflateEnd(&strm); - return -1; + return -EINVAL; } out_len = strm.next_out - out_buf; @@ -1079,12 +1079,13 @@ static int qcow2_write_compressed(BlockDriverState *bs, int64_t sector_num, cluster_offset = qcow2_alloc_compressed_cluster_offset(bs, sector_num << 9, out_len); if (!cluster_offset) - return -1; + return -EIO; cluster_offset &= s->cluster_offset_mask; BLKDBG_EVENT(bs->file, BLKDBG_WRITE_COMPRESSED); - if (bdrv_pwrite(bs->file, cluster_offset, out_buf, out_len) != out_len) { + ret = bdrv_pwrite(bs->file, cluster_offset, out_buf, out_len); + if (ret < 0) { g_free(out_buf); - return -1; + return ret; } }