mirror of https://github.com/xemu-project/xemu.git
qemu-img: Use zero writes after source backing EOF
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 <mreitz@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
This commit is contained in:
parent
35ddd9300b
commit
1c6e877992
11
qemu-img.c
11
qemu-img.c
|
@ -3432,6 +3432,8 @@ static int img_rebase(int argc, char **argv)
|
||||||
}
|
}
|
||||||
|
|
||||||
for (offset = 0; offset < size; offset += n) {
|
for (offset = 0; offset < size; offset += n) {
|
||||||
|
bool buf_old_is_zero = false;
|
||||||
|
|
||||||
/* How many bytes can we handle with the next read? */
|
/* How many bytes can we handle with the next read? */
|
||||||
n = MIN(IO_BUF_SIZE, size - offset);
|
n = MIN(IO_BUF_SIZE, size - offset);
|
||||||
|
|
||||||
|
@ -3452,6 +3454,7 @@ static int img_rebase(int argc, char **argv)
|
||||||
*/
|
*/
|
||||||
if (offset >= old_backing_size) {
|
if (offset >= old_backing_size) {
|
||||||
memset(buf_old, 0, n);
|
memset(buf_old, 0, n);
|
||||||
|
buf_old_is_zero = true;
|
||||||
} else {
|
} else {
|
||||||
if (offset + n > old_backing_size) {
|
if (offset + n > old_backing_size) {
|
||||||
n = old_backing_size - offset;
|
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,
|
if (compare_buffers(buf_old + written, buf_new + written,
|
||||||
n - written, &pnum))
|
n - written, &pnum))
|
||||||
{
|
{
|
||||||
ret = blk_pwrite(blk, offset + written,
|
if (buf_old_is_zero) {
|
||||||
buf_old + written, pnum, 0);
|
ret = blk_pwrite_zeroes(blk, offset + written, pnum, 0);
|
||||||
|
} else {
|
||||||
|
ret = blk_pwrite(blk, offset + written,
|
||||||
|
buf_old + written, pnum, 0);
|
||||||
|
}
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
error_report("Error while writing to COW image: %s",
|
error_report("Error while writing to COW image: %s",
|
||||||
strerror(-ret));
|
strerror(-ret));
|
||||||
|
|
Loading…
Reference in New Issue