Commit 11212d8f authored by Paolo Bonzini's avatar Paolo Bonzini Committed by Stefan Hajnoczi
Browse files

block: make bdrv_has_zero_init return false for copy-on-write-images



This helps implementing is_allocated on top of get_block_status.
Reviewed-by: default avatarEric Blake <eblake@redhat.com>
Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
Signed-off-by: default avatarStefan Hajnoczi <stefanha@redhat.com>
parent e4a86f88
...@@ -3031,6 +3031,11 @@ int bdrv_has_zero_init(BlockDriverState *bs) ...@@ -3031,6 +3031,11 @@ int bdrv_has_zero_init(BlockDriverState *bs)
{ {
assert(bs->drv); assert(bs->drv);
/* If BS is a copy on write image, it is initialized to
the contents of the base image, which may not be zeroes. */
if (bs->backing_hd) {
return 0;
}
if (bs->drv->bdrv_has_zero_init) { if (bs->drv->bdrv_has_zero_init) {
return bs->drv->bdrv_has_zero_init(bs); return bs->drv->bdrv_has_zero_init(bs);
} }
......
...@@ -1537,14 +1537,7 @@ static int img_convert(int argc, char **argv) ...@@ -1537,14 +1537,7 @@ static int img_convert(int argc, char **argv)
should add a specific call to have the info to go faster */ should add a specific call to have the info to go faster */
buf1 = buf; buf1 = buf;
while (n > 0) { while (n > 0) {
/* If the output image is being created as a copy on write image, if (!has_zero_init ||
copy all sectors even the ones containing only NUL bytes,
because they may differ from the sectors in the base image.
If the output is to a host device, we also write out
sectors that are entirely 0, since whatever data was
already there is garbage, not 0s. */
if (!has_zero_init || out_baseimg ||
is_allocated_sectors_min(buf1, n, &n1, min_sparse)) { is_allocated_sectors_min(buf1, n, &n1, min_sparse)) {
ret = bdrv_write(out_bs, sector_num, buf1, n1); ret = bdrv_write(out_bs, sector_num, buf1, n1);
if (ret < 0) { if (ret < 0) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment