From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56854) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WrqwY-00040O-UZ for qemu-devel@nongnu.org; Tue, 03 Jun 2014 11:48:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WrqwS-0004PK-KH for qemu-devel@nongnu.org; Tue, 03 Jun 2014 11:48:06 -0400 Received: from lputeaux-656-01-25-125.w80-12.abo.wanadoo.fr ([80.12.84.125]:38757 helo=paradis.irqsave.net) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WrqwS-0004PE-DS for qemu-devel@nongnu.org; Tue, 03 Jun 2014 11:48:00 -0400 Date: Tue, 3 Jun 2014 17:47:59 +0200 From: =?iso-8859-1?Q?Beno=EEt?= Canet Message-ID: <20140603154759.GM21314@irqsave.net> References: <1401801062-9154-1-git-send-email-kwolf@redhat.com> <1401801062-9154-13-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-13-git-send-email-kwolf@redhat.com> Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH v3 12/21] qed: 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:53 (+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 qed block driver. >=20 > Signed-off-by: Kevin Wolf > Reviewed-by: Stefan Hajnoczi > --- > block/qed-check.c | 7 +++++-- > block/qed.c | 6 +++++- > 2 files changed, 10 insertions(+), 3 deletions(-) >=20 > diff --git a/block/qed-check.c b/block/qed-check.c > index b473dcd..40a882c 100644 > --- a/block/qed-check.c > +++ b/block/qed-check.c > @@ -227,8 +227,11 @@ int qed_check(BDRVQEDState *s, BdrvCheckResult *re= sult, bool fix) > }; > int ret; > =20 > - check.used_clusters =3D g_malloc0(((check.nclusters + 31) / 32) * > - sizeof(check.used_clusters[0]))= ; > + check.used_clusters =3D g_try_malloc0(((check.nclusters + 31) / 32= ) * > + sizeof(check.used_clusters[0])= ); > + if (check.nclusters && check.used_clusters =3D=3D NULL) { > + return -ENOMEM; > + } > =20 > check.result->bfi.total_clusters =3D > (s->header.image_size + s->header.cluster_size - 1) / > diff --git a/block/qed.c b/block/qed.c > index c130e42..f0943d6 100644 > --- a/block/qed.c > +++ b/block/qed.c > @@ -1208,7 +1208,11 @@ static void qed_aio_write_inplace(QEDAIOCB *acb,= uint64_t offset, size_t len) > struct iovec *iov =3D acb->qiov->iov; > =20 > if (!iov->iov_base) { > - iov->iov_base =3D qemu_blockalign(acb->common.bs, iov->iov= _len); > + iov->iov_base =3D qemu_try_blockalign(acb->common.bs, iov-= >iov_len); > + if (iov->iov_base =3D=3D NULL) { > + qed_aio_complete(acb, -ENOMEM); > + return; > + } > memset(iov->iov_base, 0, iov->iov_len); > } > } > --=20 > 1.8.3.1 >=20 Reviewed-by: Benoit Canet