From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:53334) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RGP63-0008Co-Mr for qemu-devel@nongnu.org; Wed, 19 Oct 2011 01:53:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RGP62-00045E-J3 for qemu-devel@nongnu.org; Wed, 19 Oct 2011 01:53:47 -0400 Received: from e28smtp09.in.ibm.com ([122.248.162.9]:49387) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RGP61-0003aa-RQ for qemu-devel@nongnu.org; Wed, 19 Oct 2011 01:53:46 -0400 Received: from /spool/local by in.ibm.com with XMail ESMTP for from ; Wed, 19 Oct 2011 11:23:04 +0530 Received: from d28av02.in.ibm.com (d28av02.in.ibm.com [9.184.220.64]) by d28relay05.in.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id p9J5qwkK3457216 for ; Wed, 19 Oct 2011 11:23:00 +0530 Received: from d28av02.in.ibm.com (loopback [127.0.0.1]) by d28av02.in.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id p9J5qwiN006277 for ; Wed, 19 Oct 2011 16:52:58 +1100 Message-ID: <4E9E6592.20900@linux.vnet.ibm.com> Date: Wed, 19 Oct 2011 13:52:18 +0800 From: Dong Xu Wang MIME-Version: 1.0 Content-Type: text/plain; charset=GB2312 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH 2/2] qcow2: Fix bdrv_write_compressed error handling List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Kevin Wolf Cc: qemu-devel@nongnu.org On Tue, Oct 18, 2011 at 11:47 PM, Kevin Wolf wrote: > 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; Should free out_buf here? > 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; > } > } > > -- > 1.7.6.4 > > >