[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-block] [PULL 14/15] qemu-img: Use zero writes after source backing
From: |
Kevin Wolf |
Subject: |
[Qemu-block] [PULL 14/15] qemu-img: Use zero writes after source backing EOF |
Date: |
Fri, 10 May 2019 18:16:13 +0200 |
From: Max Reitz <address@hidden>
Past the end of the source backing file, we memset() buf_old to zero, so
it is clearly easy to use blk_pwrite_zeroes() instead of blk_pwrite()
then.
Signed-off-by: Max Reitz <address@hidden>
Reviewed-by: Eric Blake <address@hidden>
Signed-off-by: Kevin Wolf <address@hidden>
---
qemu-img.c | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/qemu-img.c b/qemu-img.c
index cfa44b4153..28fba1e7a7 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -3432,6 +3432,8 @@ static int img_rebase(int argc, char **argv)
}
for (offset = 0; offset < size; offset += n) {
+ bool buf_old_is_zero = false;
+
/* How many bytes can we handle with the next read? */
n = MIN(IO_BUF_SIZE, size - offset);
@@ -3452,6 +3454,7 @@ static int img_rebase(int argc, char **argv)
*/
if (offset >= old_backing_size) {
memset(buf_old, 0, n);
+ buf_old_is_zero = true;
} else {
if (offset + n > old_backing_size) {
n = old_backing_size - offset;
@@ -3487,8 +3490,12 @@ static int img_rebase(int argc, char **argv)
if (compare_buffers(buf_old + written, buf_new + written,
n - written, &pnum))
{
- ret = blk_pwrite(blk, offset + written,
- buf_old + written, pnum, 0);
+ if (buf_old_is_zero) {
+ ret = blk_pwrite_zeroes(blk, offset + written, pnum,
0);
+ } else {
+ ret = blk_pwrite(blk, offset + written,
+ buf_old + written, pnum, 0);
+ }
if (ret < 0) {
error_report("Error while writing to COW image: %s",
strerror(-ret));
--
2.20.1
- [Qemu-block] [PULL 03/15] MAINTAINERS: Add an entry for the Parallel NOR Flash devices, (continued)
- [Qemu-block] [PULL 03/15] MAINTAINERS: Add an entry for the Parallel NOR Flash devices, Kevin Wolf, 2019/05/10
- [Qemu-block] [PULL 04/15] qemu-iotests: Fix cleanup for 192, Kevin Wolf, 2019/05/10
- [Qemu-block] [PULL 05/15] blockjob: Fix coroutine thread after AioContext change, Kevin Wolf, 2019/05/10
- [Qemu-block] [PULL 06/15] test-block-iothread: Job coroutine thread after AioContext switch, Kevin Wolf, 2019/05/10
- [Qemu-block] [PULL 08/15] qcow2: Replace bdrv_write() with bdrv_pwrite(), Kevin Wolf, 2019/05/10
- [Qemu-block] [PULL 07/15] qemu-img: Use IEC binary prefixes for size constants, Kevin Wolf, 2019/05/10
- [Qemu-block] [PULL 09/15] vdi: Replace bdrv_{read, write}() with bdrv_{pread, pwrite}(), Kevin Wolf, 2019/05/10
- [Qemu-block] [PULL 10/15] vvfat: Replace bdrv_{read, write}() with bdrv_{pread, pwrite}(), Kevin Wolf, 2019/05/10
- [Qemu-block] [PULL 11/15] block: Remove bdrv_read() and bdrv_write(), Kevin Wolf, 2019/05/10
- [Qemu-block] [PULL 12/15] qcow2: Remove BDRVQcow2State.cluster_sectors, Kevin Wolf, 2019/05/10
- [Qemu-block] [PULL 14/15] qemu-img: Use zero writes after source backing EOF,
Kevin Wolf <=
- [Qemu-block] [PULL 13/15] qemu-img: Allow rebase with no input base, Kevin Wolf, 2019/05/10
- [Qemu-block] [PULL 15/15] iotests: Add test for rebase without input base, Kevin Wolf, 2019/05/10
- Re: [Qemu-block] [Qemu-devel] [PULL 00/15] Block layer patches, Peter Maydell, 2019/05/13