[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 06/32] block: Add qemu_{,try_}blockalign0()
From: |
Kevin Wolf |
Subject: |
[Qemu-devel] [PULL 06/32] block: Add qemu_{,try_}blockalign0() |
Date: |
Thu, 23 Oct 2014 22:42:13 +0200 |
From: Max Reitz <address@hidden>
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 <address@hidden>
Reviewed-by: Eric Blake <address@hidden>
Signed-off-by: Kevin Wolf <address@hidden>
---
block.c | 16 ++++++++++++++++
include/block/block.h | 2 ++
2 files changed, 18 insertions(+)
diff --git a/block.c b/block.c
index 773e87e..bbb04e7 100644
--- a/block.c
+++ b/block.c
@@ -5200,6 +5200,11 @@ void *qemu_blockalign(BlockDriverState *bs, size_t size)
return qemu_memalign(bdrv_opt_mem_align(bs), 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 = bdrv_opt_mem_align(bs);
@@ -5213,6 +5218,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/include/block/block.h b/include/block/block.h
index c9ec0ab..341054d 100644
--- a/include/block/block.h
+++ b/include/block/block.h
@@ -412,7 +412,9 @@ void bdrv_img_create(const char *filename, const char *fmt,
size_t bdrv_opt_mem_align(BlockDriverState *bs);
void bdrv_set_guest_block_size(BlockDriverState *bs, int align);
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);
bool bdrv_qiov_is_aligned(BlockDriverState *bs, QEMUIOVector *qiov);
struct HBitmapIter;
--
1.8.3.1
- [Qemu-devel] [PULL 00/32] Block patches, Kevin Wolf, 2014/10/23
- [Qemu-devel] [PULL 03/32] MAINTAINERS: add the image fuzzer to the block layer, Kevin Wolf, 2014/10/23
- [Qemu-devel] [PULL 01/32] MAINTAINERS: add aio to block layer, Kevin Wolf, 2014/10/23
- [Qemu-devel] [PULL 05/32] block: qemu-iotests change _supported_proto to file once more., Kevin Wolf, 2014/10/23
- [Qemu-devel] [PULL 02/32] MAINTAINERS: qemu-iotests belongs to the block layer, Kevin Wolf, 2014/10/23
- [Qemu-devel] [PULL 06/32] block: Add qemu_{,try_}blockalign0(),
Kevin Wolf <=
- [Qemu-devel] [PULL 04/32] block/vdi: Use {DIV_,}ROUND_UP, Kevin Wolf, 2014/10/23
- [Qemu-devel] [PULL 08/32] qcow2: Fix leaks in dirty images, Kevin Wolf, 2014/10/23
- [Qemu-devel] [PULL 07/32] qcow2: Calculate refcount block entry count, Kevin Wolf, 2014/10/23
- [Qemu-devel] [PULL 09/32] qcow2: Split qcow2_check_refcounts(), Kevin Wolf, 2014/10/23
- [Qemu-devel] [PULL 10/32] qcow2: Use sizeof(**refcount_table), Kevin Wolf, 2014/10/23
- [Qemu-devel] [PULL 11/32] qcow2: Pull check_refblocks() up, Kevin Wolf, 2014/10/23
- [Qemu-devel] [PULL 13/32] qcow2: Split fail code in L1 and L2 checks, Kevin Wolf, 2014/10/23
- [Qemu-devel] [PULL 12/32] qcow2: Use int64_t for in-memory reftable size, Kevin Wolf, 2014/10/23
- [Qemu-devel] [PULL 14/32] qcow2: Let inc_refcounts() return -errno, Kevin Wolf, 2014/10/23
- [Qemu-devel] [PULL 16/32] qcow2: Reuse refcount table in calculate_refcounts(), Kevin Wolf, 2014/10/23