aboutsummaryrefslogtreecommitdiff
path: root/block.c
diff options
context:
space:
mode:
authorKevin Wolf <kwolf@redhat.com>2014-05-20 12:24:05 +0200
committerKevin Wolf <kwolf@redhat.com>2014-08-15 15:07:15 +0200
commit7d2a35cc921ea4832083a7e8598461868bb538ce (patch)
tree0aabab68f9ae59485bba04d9fe374ed0e603af1e /block.c
parent23d20b5b4fb7bde102e6779b7a13b88375e4db66 (diff)
block: Introduce qemu_try_blockalign()
This function returns NULL instead of aborting when an allocation fails. Signed-off-by: Kevin Wolf <kwolf@redhat.com> Reviewed-by: Benoit Canet <benoit@irqsave.net>
Diffstat (limited to 'block.c')
-rw-r--r--block.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/block.c b/block.c
index d7cb7d48fa..3365c05b9d 100644
--- a/block.c
+++ b/block.c
@@ -5258,6 +5258,19 @@ void *qemu_blockalign(BlockDriverState *bs, size_t size)
return qemu_memalign(bdrv_opt_mem_align(bs), size);
}
+void *qemu_try_blockalign(BlockDriverState *bs, size_t size)
+{
+ size_t align = bdrv_opt_mem_align(bs);
+
+ /* Ensure that NULL is never returned on success */
+ assert(align > 0);
+ if (size == 0) {
+ size = align;
+ }
+
+ return qemu_try_memalign(align, size);
+}
+
/*
* Check if all memory in this vector is sector aligned.
*/