[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v3 07/21] iscsi: Handle failure for potentially larg
From: |
Kevin Wolf |
Subject: |
[Qemu-devel] [PATCH v3 07/21] iscsi: Handle failure for potentially large allocations |
Date: |
Tue, 3 Jun 2014 15:10:48 +0200 |
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 <address@hidden>
Acked-by: Paolo Bonzini <address@hidden>
Reviewed-by: Benoit Canet <address@hidden>
Reviewed-by: Eric Blake <address@hidden>
---
block/iscsi.c | 17 ++++++++++++++---
1 file changed, 14 insertions(+), 3 deletions(-)
diff --git a/block/iscsi.c b/block/iscsi.c
index 3892cc5..b3e9bdd 100644
--- a/block/iscsi.c
+++ b/block/iscsi.c
@@ -335,7 +335,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 (size && buf == NULL) {
+ return -ENOMEM;
+ }
qemu_iovec_to_buf(iov, 0, buf, size);
data = buf;
}
@@ -721,7 +724,12 @@ 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->ioh->dxfer_len && acb->buf == NULL) {
+ free(acb->task);
+ 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);
@@ -902,7 +910,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);
--
1.8.3.1
- [Qemu-devel] [PATCH v3 00/21] block: Handle failure for potentially large allocations, Kevin Wolf, 2014/06/03
- [Qemu-devel] [PATCH v3 03/21] bochs: Handle failure for potentially large allocations, Kevin Wolf, 2014/06/03
- [Qemu-devel] [PATCH v3 01/21] block: Introduce qemu_try_blockalign(), Kevin Wolf, 2014/06/03
- [Qemu-devel] [PATCH v3 02/21] block: Handle failure for potentially large allocations, Kevin Wolf, 2014/06/03
- [Qemu-devel] [PATCH v3 04/21] cloop: Handle failure for potentially large allocations, Kevin Wolf, 2014/06/03
- [Qemu-devel] [PATCH v3 05/21] curl: Handle failure for potentially large allocations, Kevin Wolf, 2014/06/03
- [Qemu-devel] [PATCH v3 06/21] dmg: Handle failure for potentially large allocations, Kevin Wolf, 2014/06/03
- [Qemu-devel] [PATCH v3 07/21] iscsi: Handle failure for potentially large allocations,
Kevin Wolf <=
- [Qemu-devel] [PATCH v3 09/21] parallels: Handle failure for potentially large allocations, Kevin Wolf, 2014/06/03
- [Qemu-devel] [PATCH v3 08/21] nfs: Handle failure for potentially large allocations, Kevin Wolf, 2014/06/03
- [Qemu-devel] [PATCH v3 10/21] qcow1: Handle failure for potentially large allocations, Kevin Wolf, 2014/06/03
- [Qemu-devel] [PATCH v3 11/21] qcow2: Handle failure for potentially large allocations, Kevin Wolf, 2014/06/03
- [Qemu-devel] [PATCH v3 12/21] qed: Handle failure for potentially large allocations, Kevin Wolf, 2014/06/03
- [Qemu-devel] [PATCH v3 13/21] raw-posix: Handle failure for potentially large allocations, Kevin Wolf, 2014/06/03
- [Qemu-devel] [PATCH v3 14/21] raw-win32: Handle failure for potentially large allocations, Kevin Wolf, 2014/06/03