From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:35294) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SEeqM-0003uW-Nc for qemu-devel@nongnu.org; Mon, 02 Apr 2012 06:50:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SEeqD-0003jB-CS for qemu-devel@nongnu.org; Mon, 02 Apr 2012 06:50:38 -0400 Received: from mx1.redhat.com ([209.132.183.28]:10820) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SEeqD-0003ir-4Q for qemu-devel@nongnu.org; Mon, 02 Apr 2012 06:50:29 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q32AoRBp020644 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Mon, 2 Apr 2012 06:50:27 -0400 From: "Daniel P. Berrange" Date: Mon, 2 Apr 2012 11:50:11 +0100 Message-Id: <1333363816-1691-5-git-send-email-berrange@redhat.com> In-Reply-To: <1333363816-1691-1-git-send-email-berrange@redhat.com> References: <1333363816-1691-1-git-send-email-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PATCH 4/9] Remove 4 MB stack frame usage from sheepdog List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org From: "Daniel P. Berrange" The sheepdog driver declares an instance of BDRVSheepdogState in the stack. This struct is 4 MB in size. While the default Linux stack size may be 10 MB, we should not assume that since QEMU needs to be portable to other OS. block/sheepdog.c: In function =E2=80=98sd_create=E2=80=99: block/sheepdog.c:1240:1: error: the frame size of 4199888 bytes is larger= than 131072 bytes [-Werror=3Dframe-larger-than=3D] * block/sheepdog.c: Allow BDRVSheepdogState on the heap instead of stack * configure: Add -Wframe-larger-than to validate stack size does not exceed 128k Signed-off-by: Daniel P. Berrange --- block/sheepdog.c | 43 ++++++++++++++++++++++++++----------------- configure | 1 + 2 files changed, 27 insertions(+), 17 deletions(-) diff --git a/block/sheepdog.c b/block/sheepdog.c index 00276f6f..ff6f3d2 100644 --- a/block/sheepdog.c +++ b/block/sheepdog.c @@ -1163,20 +1163,22 @@ static int sd_create(const char *filename, QEMUOp= tionParameter *options) uint32_t vid =3D 0, base_vid =3D 0; int64_t vdi_size =3D 0; char *backing_file =3D NULL; - BDRVSheepdogState s; + BDRVSheepdogState *s1; char vdi[SD_MAX_VDI_LEN], tag[SD_MAX_VDI_TAG_LEN]; uint32_t snapid; int prealloc =3D 0; const char *vdiname; + int rv =3D -EINVAL; + + s1 =3D g_new0(BDRVSheepdogState, 1); =20 strstart(filename, "sheepdog:", &vdiname); =20 - memset(&s, 0, sizeof(s)); memset(vdi, 0, sizeof(vdi)); memset(tag, 0, sizeof(tag)); - if (parse_vdiname(&s, vdiname, vdi, &snapid, tag) < 0) { + if (parse_vdiname(s1, vdiname, vdi, &snapid, tag) < 0) { error_report("invalid filename"); - return -EINVAL; + goto cleanup; } =20 while (options && options->name) { @@ -1192,7 +1194,7 @@ static int sd_create(const char *filename, QEMUOpti= onParameter *options) } else { error_report("Invalid preallocation mode: '%s'", options->value.s); - return -EINVAL; + goto cleanup; } } options++; @@ -1200,43 +1202,50 @@ static int sd_create(const char *filename, QEMUOp= tionParameter *options) =20 if (vdi_size > SD_MAX_VDI_SIZE) { error_report("too big image size"); - return -EINVAL; + goto cleanup; } =20 if (backing_file) { BlockDriverState *bs; - BDRVSheepdogState *s; + BDRVSheepdogState *s2; BlockDriver *drv; =20 /* Currently, only Sheepdog backing image is supported. */ drv =3D bdrv_find_protocol(backing_file); if (!drv || strcmp(drv->protocol_name, "sheepdog") !=3D 0) { error_report("backing_file must be a sheepdog image"); - return -EINVAL; + goto cleanup; } =20 ret =3D bdrv_file_open(&bs, backing_file, 0); - if (ret < 0) - return -EIO; + if (ret < 0) { + rv =3D -EIO; + goto cleanup; + } =20 - s =3D bs->opaque; + s2 =3D bs->opaque; =20 - if (!is_snapshot(&s->inode)) { + if (!is_snapshot(&s2->inode)) { error_report("cannot clone from a non snapshot vdi"); bdrv_delete(bs); - return -EINVAL; + goto cleanup; } =20 - base_vid =3D s->inode.vdi_id; + base_vid =3D s2->inode.vdi_id; bdrv_delete(bs); } =20 - ret =3D do_sd_create(vdi, vdi_size, base_vid, &vid, 0, s.addr, s.por= t); + ret =3D do_sd_create(vdi, vdi_size, base_vid, &vid, 0, s1->addr, s1-= >port); if (!prealloc || ret) { - return ret; + rv =3D ret; + goto cleanup; } =20 - return sd_prealloc(filename); + rv =3D sd_prealloc(filename); + + cleanup: + g_free(s1); + return rv; } =20 static void sd_close(BlockDriverState *bs) diff --git a/configure b/configure index 44b28c8..28b5dd5 100755 --- a/configure +++ b/configure @@ -1165,6 +1165,7 @@ gcc_flags=3D"$gcc_flags -Wmissing-include-dirs" gcc_flags=3D"$gcc_flags -Wempty-body" gcc_flags=3D"$gcc_flags -Wnested-externs" gcc_flags=3D"$gcc_flags -Wendif-labels" +gcc_flags=3D"$gcc_flags -Wframe-larger-than=3D131072" cat > $TMPC << EOF int main(void) { return 0; } EOF --=20 1.7.7.6