[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v7 01/13] block: Add qemu_{, try_}blockalign0()
From: |
Max Reitz |
Subject: |
[Qemu-devel] [PATCH v7 01/13] block: Add qemu_{, try_}blockalign0() |
Date: |
Wed, 22 Oct 2014 10:08:32 +0200 |
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>
---
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.9.3
- [Qemu-devel] [PATCH v7 00/13] qcow2: Fix image repairing, Max Reitz, 2014/10/22
- [Qemu-devel] [PATCH v7 01/13] block: Add qemu_{, try_}blockalign0(),
Max Reitz <=
- [Qemu-devel] [PATCH v7 03/13] qcow2: Fix leaks in dirty images, Max Reitz, 2014/10/22
- [Qemu-devel] [PATCH v7 02/13] qcow2: Calculate refcount block entry count, Max Reitz, 2014/10/22
- [Qemu-devel] [PATCH v7 04/13] qcow2: Split qcow2_check_refcounts(), Max Reitz, 2014/10/22
- [Qemu-devel] [PATCH v7 05/13] qcow2: Use sizeof(**refcount_table), Max Reitz, 2014/10/22
- [Qemu-devel] [PATCH v7 06/13] qcow2: Pull check_refblocks() up, Max Reitz, 2014/10/22
- [Qemu-devel] [PATCH v7 07/13] qcow2: Reuse refcount table in calculate_refcounts(), Max Reitz, 2014/10/22
- [Qemu-devel] [PATCH v7 08/13] qcow2: Fix refcount blocks beyond image end, Max Reitz, 2014/10/22
- [Qemu-devel] [PATCH v7 09/13] qcow2: Do not perform potentially damaging repairs, Max Reitz, 2014/10/22