From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52550) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V6WHa-0005cF-GD for qemu-devel@nongnu.org; Mon, 05 Aug 2013 21:42:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1V6WHU-00078Q-I6 for qemu-devel@nongnu.org; Mon, 05 Aug 2013 21:41:54 -0400 Received: from mx1.redhat.com ([209.132.183.28]:24446) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V6WHU-00078K-9n for qemu-devel@nongnu.org; Mon, 05 Aug 2013 21:41:48 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r761flRB019302 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Mon, 5 Aug 2013 21:41:47 -0400 From: Fam Zheng Date: Tue, 6 Aug 2013 09:40:42 +0800 Message-Id: <1375753243-19530-10-git-send-email-famz@redhat.com> In-Reply-To: <1375753243-19530-1-git-send-email-famz@redhat.com> References: <1375753243-19530-1-git-send-email-famz@redhat.com> Subject: [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: qemu-devel@nongnu.org Cc: kwolf@redhat.com, pmatouse@redhat.com, jcody@redhat.com, armbru@redhat.com, stefanha@redhat.com, famz@redhat.com, asias@redhat.com, areis@redhat.com 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; + 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