From a4cbfb14f8ee3e7d3bb1dfc268cedca1d64d407f Mon Sep 17 00:00:00 2001 Message-Id: In-Reply-To: <67968bc615637394c3ef7dfefa360dab90f33d5d.1429902956.git.jen@redhat.com> References: <67968bc615637394c3ef7dfefa360dab90f33d5d.1429902956.git.jen@redhat.com> From: Max Reitz Date: Wed, 18 Mar 2015 19:22:03 -0500 Subject: [CHANGE 20/42] block: Add qemu_{, try_}blockalign0() To: rhvirt-patches@redhat.com, jen@redhat.com RH-Author: Max Reitz Message-id: <1426706542-30384-21-git-send-email-mreitz@redhat.com> Patchwork-id: 64483 O-Subject: [RHEL-6.7 qemu-kvm PATCH v2 20/39] block: Add qemu_{, try_}blockalign0() Bugzilla: 1129892 RH-Acked-by: Jeffrey Cody RH-Acked-by: Kevin Wolf RH-Acked-by: Stefan Hajnoczi BZ: 1129892 These functions call their non-0-counterparts and then fill the allocated buffer with 0 (if the allocation has been successful). Signed-off-by: Max Reitz Reviewed-by: Eric Blake Signed-off-by: Kevin Wolf (cherry picked from commit 9ebd84480583bb6d9a7666c079d99ff3266c423d) Signed-off-by: Jeff E. Nelson Conflicts: include/block/block.h block_int.h Different files upstream and downstream. Signed-off-by: Max Reitz Signed-off-by: Jeff E. Nelson --- block.c | 16 ++++++++++++++++ block_int.h | 2 ++ 2 files changed, 18 insertions(+) diff --git a/block.c b/block.c index 1a77e3e..4aef5d0 100644 --- a/block.c +++ b/block.c @@ -4363,6 +4363,11 @@ void *qemu_blockalign(BlockDriverState *bs, size_t size) return qemu_memalign((bs && bs->buffer_alignment) ? bs->buffer_alignment : 512, size); } +void *qemu_blockalign0(BlockDriverState *bs, size_t size) +{ + return memset(qemu_blockalign(bs, size), 0, size); +} + void *qemu_try_blockalign(BlockDriverState *bs, size_t size) { size_t align = (bs && bs->buffer_alignment) ? bs->buffer_alignment : 512; @@ -4376,6 +4381,17 @@ void *qemu_try_blockalign(BlockDriverState *bs, size_t size) return qemu_try_memalign(align, size); } +void *qemu_try_blockalign0(BlockDriverState *bs, size_t size) +{ + void *mem = qemu_try_blockalign(bs, size); + + if (mem) { + memset(mem, 0, size); + } + + return mem; +} + /* * Check if all memory in this vector is sector aligned. */ diff --git a/block_int.h b/block_int.h index 7587bb8..32dbdbf 100644 --- a/block_int.h +++ b/block_int.h @@ -309,7 +309,9 @@ struct BlockDriverState { int get_tmp_filename(char *filename, int size); void *qemu_blockalign(BlockDriverState *bs, size_t size); +void *qemu_blockalign0(BlockDriverState *bs, size_t size); void *qemu_try_blockalign(BlockDriverState *bs, size_t size); +void *qemu_try_blockalign0(BlockDriverState *bs, size_t size); void bdrv_set_io_limits(BlockDriverState *bs, ThrottleConfig *cfg); -- 2.1.0