Received: from eggs.gnu.org ([2001:4830:134:3::10]:47529) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V6YJw-0007wg-E0 for qemu-devel@nongnu.org; Mon, 05 Aug 2013 23:52:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1V6YJn-00023y-LY for qemu-devel@nongnu.org; Mon, 05 Aug 2013 23:52:28 -0400 Received: from mx1.redhat.com ([209.132.183.28]:29247) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V6YJn-00023p-Cd for qemu-devel@nongnu.org; Mon, 05 Aug 2013 23:52:19 -0400 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r763qISW000769 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Mon, 5 Aug 2013 23:52:18 -0400 Date: Mon, 5 Aug 2013 23:52:15 -0400 From: Jeff Cody Message-ID: <20130806035215.GB12136@localhost.localdomain> References: <1375753243-19530-1-git-send-email-famz@redhat.com> <1375753243-19530-10-git-send-email-famz@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1375753243-19530-10-git-send-email-famz@redhat.com> Subject: Re: [Qemu-devel] [PATCH v3 09/10] vmdk: use heap allocation for whole_grain List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Fam Zheng Cc: kwolf@redhat.com, pmatouse@redhat.com, qemu-devel@nongnu.org, armbru@redhat.com, stefanha@redhat.com, asias@redhat.com, areis@redhat.com On Tue, Aug 06, 2013 at 09:40:42AM +0800, Fam Zheng wrote: > We should never grow the stack beyond 1 MB, otherwise we'll fall off the > end. Thread stacks and coroutine stacks (1 MB) do not grow. > get_cluster_offset() allocates a big stack offset, it will fail for big > cluster images, change to heap allocated buffer. > > Signed-off-by: Fam Zheng > --- > block/vmdk.c | 19 +++++++++++++------ > 1 file changed, 13 insertions(+), 6 deletions(-) > > diff --git a/block/vmdk.c b/block/vmdk.c > index 3bcab26..21610e3 100644 > --- a/block/vmdk.c > +++ b/block/vmdk.c > @@ -842,16 +842,19 @@ static int get_whole_cluster(BlockDriverState *bs, > uint64_t offset, > bool allocate) > { > - /* 128 sectors * 512 bytes each = grain size 64KB */ > - uint8_t whole_grain[extent->cluster_sectors * 512]; > + int ret = VMDK_OK; > + uint8_t *whole_grain = NULL; > > /* we will be here if it's first write on non-exist grain(cluster). > * try to read from parent image, if exist */ > if (bs->backing_hd) { > int ret; ^^^^^^ This above line should be removed; as it is this function will always return VMDK_OK with this here, due to the scoping of this 'ret' inside the if() block. > > + whole_grain = > + qemu_blockalign(bs, extent->cluster_sectors << BDRV_SECTOR_BITS); > if (!vmdk_is_cid_valid(bs)) { > - return VMDK_ERROR; > + ret = VMDK_ERROR; > + goto exit; > } > > /* floor offset to cluster */ > @@ -859,17 +862,21 @@ static int get_whole_cluster(BlockDriverState *bs, > ret = bdrv_read(bs->backing_hd, offset >> 9, whole_grain, > extent->cluster_sectors); > if (ret < 0) { > - return VMDK_ERROR; > + ret = VMDK_ERROR; > + goto exit; > } > > /* Write grain only into the active image */ > ret = bdrv_write(extent->file, cluster_offset, whole_grain, > extent->cluster_sectors); > if (ret < 0) { > - return VMDK_ERROR; > + ret = VMDK_ERROR; > + goto exit; > } > } > - return VMDK_OK; > +exit: > + qemu_vfree(whole_grain); > + return ret; > } > > static int vmdk_L2update(VmdkExtent *extent, VmdkMetaData *m_data) > -- > 1.8.3.4 >