From mboxrd@z Thu Jan 1 00:00:00 1970 From: Laurent Vivier Subject: Re: [PATCH] qemu: use statically allocate 512 byte buffer in the stack for sector in bdrv_commit Date: Mon, 07 Jan 2008 11:22:38 +0100 Message-ID: <1199701358.19008.1.camel@frecb07144> References: <20080104071138.GB9285@tapir> <4781F08E.8060407@qumranet.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="===============1831699267==" Cc: kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org, Carlo Marcelo Arenas Belon To: Avi Kivity Return-path: In-Reply-To: <4781F08E.8060407-atKUWr5tajBWk0Htik3J/w@public.gmane.org> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: kvm-devel-bounces-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org Errors-To: kvm-devel-bounces-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org List-Id: kvm.vger.kernel.org --===============1831699267== Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="=-yjDhmx6xvfxWDlVADTno" --=-yjDhmx6xvfxWDlVADTno Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Le lundi 07 janvier 2008 =C3=A0 11:27 +0200, Avi Kivity a =C3=A9crit : > Carlo Marcelo Arenas Belon wrote: > > revert a merge conflict from 075da586c92f09bd9a7401f1e80d72fde27c173 th= at > > redefined sector as an array of pointers to char, instead of a statical= ly > > allocated buffer of chars, that was triggering the following warnings : > > > > block.c: In function `bdrv_commit': > > block.c:480: warning: passing arg 3 of `bdrv_read' from incompatible po= inter type > > block.c:484: warning: passing arg 3 of `bdrv_write' from incompatible p= ointer type > > > > Signed-off-by: Carlo Marcelo Arenas Belon > > =20 >=20 > Doesn't the cache=3Doff option warrant an allocation here to ensure=20 > alignment (or perhaps a 1K stack buffer with runtime adjustment)? You're right, a good patch should be something like this (it is not tested or even compiled) : Signed-off-by: Laurent Vivier diff --git a/qemu/block.c b/qemu/block.c index 519be24..c198659 100644 --- a/qemu/block.c +++ b/qemu/block.c @@ -460,7 +460,7 @@ int bdrv_commit(BlockDriverState *bs) BlockDriver *drv =3D bs->drv; int64_t i, total_sectors; int n, j; - unsigned char *sector[512]; + unsigned char *sector; =20 if (!drv) return -ENOMEDIUM; @@ -473,15 +473,21 @@ int bdrv_commit(BlockDriverState *bs) return -ENOTSUP; } =20 + sector =3D qemu_memalign(512,512); + if (sector =3D=3D NULL) + return -ENOMEM; + total_sectors =3D bdrv_getlength(bs) >> SECTOR_BITS; for (i =3D 0; i < total_sectors;) { if (drv->bdrv_is_allocated(bs, i, 65536, &n)) { for(j =3D 0; j < n; j++) { if (bdrv_read(bs, i, sector, 1) !=3D 0) { + qemu_free(sector); return -EIO; } =20 if (bdrv_write(bs->backing_hd, i, sector, 1) !=3D 0) { + qemu_free(sector); return -EIO; } i++; @@ -491,6 +497,7 @@ int bdrv_commit(BlockDriverState *bs) } } =20 + qemu_free(sector); if (drv->bdrv_make_empty) return drv->bdrv_make_empty(bs); --=20 ----------------- Laurent.Vivier-6ktuUTfB/bM@public.gmane.org ------------------ "La perfection est atteinte non quand il ne reste rien =C3=A0 ajouter mais quand il ne reste rien =C3=A0 enlever." Saint Exup=C3=A9ry --=-yjDhmx6xvfxWDlVADTno Content-Type: application/pgp-signature; name=signature.asc Content-Description: Ceci est une partie de message =?ISO-8859-1?Q?num=E9riquement?= =?ISO-8859-1?Q?_sign=E9e?= -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.6 (GNU/Linux) iD8DBQBHgf1u9Kffa9pFVzwRAgraAJ9KG/2knjmqDm+ANO5m9njbjpuBvACg01yP YvQ/sJoIWThzcgOXWq4tP4Q= =7jik -----END PGP SIGNATURE----- --=-yjDhmx6xvfxWDlVADTno-- --===============1831699267== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline ------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2005. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ --===============1831699267== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ kvm-devel mailing list kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org https://lists.sourceforge.net/lists/listinfo/kvm-devel --===============1831699267==--