From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49682) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WnD5y-00018c-Tc for qemu-devel@nongnu.org; Wed, 21 May 2014 16:26:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WnD5p-000633-TF for qemu-devel@nongnu.org; Wed, 21 May 2014 16:26:38 -0400 Received: from mail-ee0-x229.google.com ([2a00:1450:4013:c00::229]:44788) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WnD5p-00062Z-N5 for qemu-devel@nongnu.org; Wed, 21 May 2014 16:26:29 -0400 Received: by mail-ee0-f41.google.com with SMTP id t10so1946589eei.14 for ; Wed, 21 May 2014 13:26:28 -0700 (PDT) Sender: Paolo Bonzini Message-ID: <537D0BEE.4070608@redhat.com> Date: Wed, 21 May 2014 22:26:22 +0200 From: Paolo Bonzini MIME-Version: 1.0 References: <1400689698-3096-1-git-send-email-kwolf@redhat.com> <1400689698-3096-8-git-send-email-kwolf@redhat.com> In-Reply-To: <1400689698-3096-8-git-send-email-kwolf@redhat.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH 07/20] iscsi: Handle failure for potentially large allocations List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Kevin Wolf , qemu-devel@nongnu.org Cc: stefanha@redhat.com Il 21/05/2014 18:28, Kevin Wolf ha scritto: > Some code in the block layer makes potentially huge allocations. Failure > is not completely unexpected there, so avoid aborting qemu and handle > out-of-memory situations gracefully. > > This patch addresses the allocations in the iscsi block driver. > > Signed-off-by: Kevin Wolf > --- > block/iscsi.c | 16 +++++++++++++--- > 1 file changed, 13 insertions(+), 3 deletions(-) > > diff --git a/block/iscsi.c b/block/iscsi.c > index 52355b8..c047ca8 100644 > --- a/block/iscsi.c > +++ b/block/iscsi.c > @@ -296,7 +296,10 @@ static int coroutine_fn iscsi_co_writev(BlockDriverState *bs, > data = iov->iov[0].iov_base; > } else { > size_t size = MIN(nb_sectors * BDRV_SECTOR_SIZE, iov->size); > - buf = g_malloc(size); > + buf = g_try_malloc(size); > + if (buf == NULL) { > + return -ENOMEM; > + } > qemu_iovec_to_buf(iov, 0, buf, size); > data = buf; > } > @@ -550,7 +553,11 @@ static BlockDriverAIOCB *iscsi_aio_ioctl(BlockDriverState *bs, > #else > struct iovec *iov = (struct iovec *)acb->ioh->dxferp; > > - acb->buf = g_malloc(acb->ioh->dxfer_len); > + acb->buf = g_try_malloc(acb->ioh->dxfer_len); > + if (acb->buf == NULL) { > + qemu_aio_release(acb); > + return NULL; > + } > data.data = acb->buf; > data.size = iov_to_buf(iov, acb->ioh->iovec_count, 0, > acb->buf, acb->ioh->dxfer_len); > @@ -823,7 +830,10 @@ coroutine_fn iscsi_co_write_zeroes(BlockDriverState *bs, int64_t sector_num, > nb_blocks = sector_qemu2lun(nb_sectors, iscsilun); > > if (iscsilun->zeroblock == NULL) { > - iscsilun->zeroblock = g_malloc0(iscsilun->block_size); > + iscsilun->zeroblock = g_try_malloc0(iscsilun->block_size); > + if (iscsilun->zeroblock == NULL) { > + return -ENOMEM; > + } > } > > iscsi_co_init_iscsitask(iscsilun, &iTask); > Acked-by: Paolo Bonzini