From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53195) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wrqjg-0005x5-Dn for qemu-devel@nongnu.org; Tue, 03 Jun 2014 11:34:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WrqjX-0007pm-V0 for qemu-devel@nongnu.org; Tue, 03 Jun 2014 11:34:48 -0400 Received: from lputeaux-656-01-25-125.w80-12.abo.wanadoo.fr ([80.12.84.125]:38745 helo=paradis.irqsave.net) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WrqjX-0007pg-OA for qemu-devel@nongnu.org; Tue, 03 Jun 2014 11:34:39 -0400 Date: Tue, 3 Jun 2014 17:34:39 +0200 From: =?iso-8859-1?Q?Beno=EEt?= Canet Message-ID: <20140603153438.GI21314@irqsave.net> References: <1401801062-9154-1-git-send-email-kwolf@redhat.com> <1401801062-9154-18-git-send-email-kwolf@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline In-Reply-To: <1401801062-9154-18-git-send-email-kwolf@redhat.com> Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH v3 17/21] vhdx: Handle failure for potentially large allocations List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Kevin Wolf Cc: benoit.canet@irqsave.net, mreitz@redhat.com, qemu-devel@nongnu.org, stefanha@redhat.com, armbru@redhat.com The Tuesday 03 Jun 2014 =E0 15:10:58 (+0200), Kevin Wolf wrote : > Some code in the block layer makes potentially huge allocations. Failur= e > is not completely unexpected there, so avoid aborting qemu and handle > out-of-memory situations gracefully. >=20 > This patch addresses the allocations in the vhdx block driver. >=20 > Signed-off-by: Kevin Wolf > Reviewed-by: Stefan Hajnoczi > --- > block/vhdx-log.c | 6 +++++- > block/vhdx.c | 12 ++++++++++-- > 2 files changed, 15 insertions(+), 3 deletions(-) >=20 > diff --git a/block/vhdx-log.c b/block/vhdx-log.c > index a77c040..3eb7e68 100644 > --- a/block/vhdx-log.c > +++ b/block/vhdx-log.c > @@ -349,7 +349,11 @@ static int vhdx_log_read_desc(BlockDriverState *bs= , BDRVVHDXState *s, > } > =20 > desc_sectors =3D vhdx_compute_desc_sectors(hdr.descriptor_count); > - desc_entries =3D qemu_blockalign(bs, desc_sectors * VHDX_LOG_SECTO= R_SIZE); > + desc_entries =3D qemu_try_blockalign(bs, desc_sectors * VHDX_LOG_S= ECTOR_SIZE); > + if (desc_entries =3D=3D NULL) { > + ret =3D -ENOMEM; > + goto exit; > + } > =20 > ret =3D vhdx_log_read_sectors(bs, log, §ors_read, desc_entries= , > desc_sectors, false); > diff --git a/block/vhdx.c b/block/vhdx.c > index 353c74d..0922f55 100644 > --- a/block/vhdx.c > +++ b/block/vhdx.c > @@ -950,7 +950,11 @@ static int vhdx_open(BlockDriverState *bs, QDict *= options, int flags, > } > =20 > /* s->bat is freed in vhdx_close() */ > - s->bat =3D qemu_blockalign(bs, s->bat_rt.length); > + s->bat =3D qemu_try_blockalign(bs, s->bat_rt.length); > + if (s->bat =3D=3D NULL) { > + ret =3D -ENOMEM; > + goto fail; > + } > =20 > ret =3D bdrv_pread(bs->file, s->bat_offset, s->bat, s->bat_rt.leng= th); > if (ret < 0) { > @@ -1579,7 +1583,11 @@ static int vhdx_create_bat(BlockDriverState *bs,= BDRVVHDXState *s, > use_zero_blocks || > bdrv_has_zero_init(bs) =3D=3D 0) { > /* for a fixed file, the default BAT entry is not zero */ > - s->bat =3D g_malloc0(rt_bat->length); > + s->bat =3D g_try_malloc0(rt_bat->length); > + if (rt_bat->length && s->bat !=3D NULL) { > + ret =3D -ENOMEM; > + goto exit; > + } > block_state =3D type =3D=3D VHDX_TYPE_FIXED ? PAYLOAD_BLOCK_FU= LLY_PRESENT : > PAYLOAD_BLOCK_NOT_PRES= ENT; > block_state =3D use_zero_blocks ? PAYLOAD_BLOCK_ZERO : block_s= tate; > --=20 > 1.8.3.1 >=20 >=20 Reviewed-by: Benoit Canet