Message ID | 1373992168-26043-9-git-send-email-pbonzini@redhat.com |
---|---|
State | New |
Headers | show |
On 07/16/2013 10:29 AM, Paolo Bonzini wrote: > This helps implementing is_allocated on top of get_block_status. > > Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> > --- > block.c | 5 +++++ > qemu-img.c | 9 +-------- > 2 files changed, 6 insertions(+), 8 deletions(-) Reviewed-by: Eric Blake <eblake@redhat.com> > +++ b/block.c > @@ -2934,6 +2934,11 @@ int bdrv_has_zero_init(BlockDriverState *bs) > { > 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; Question (more for my understanding, not that you need to change code): must we blindly return 0 in the presence of a backing file, or is it possible to recursively query the backing_hd's zero_init status, allowing us to return 1 iff all files in the chain support zero_init.
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Il 19/07/2013 15:21, Eric Blake ha scritto: > Question (more for my understanding, not that you need to change > code): must we blindly return 0 in the presence of a backing file, > or is it possible to recursively query the backing_hd's zero_init > status, allowing us to return 1 iff all files in the chain support > zero_init. No, it's really blind. bdrv_has_zero_init is like "was the image all zeros at creation time", and the answer is no because the content of the image used to be the same as the backing_hd. Paolo -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.19 (GNU/Linux) Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQIcBAEBAgAGBQJR6T3bAAoJEBvWZb6bTYbyraEP/04nt2HxFsX+na7q/Ax7bGYn Z0RvyP2zTukfv8dM9aJVjmQEvLRnp7ROQlSOXPbxF3gzr2nh67nb27Xi+vF0B3N0 fDQTnnUX/8Zz2jigolDCSSFp0ggDWRtVID+W/olfIQMAJI1PkRdt0VJQp9aeLGZV 7tae/Fl5AQtfZfAW6Ji4FZzJcmLDyM7HoveZxnAawGy9e17opKGFmKUmBNutew0C LoKDkakWRrW/k4IzXB0TJOtQ5hOn5yoG16VjYG1YKblewRqaciFba62T+Z4ClJB0 TKJEr3fuGokI9mPoyPCpuZF0ZPEFFI26Mwocag8TpCS5IYJzJjC7RcGDW5CV4zzC Lzr3fGeTTtEOCJfdF4GtqeSp2S+1QWuagLLr31cV1KpnuKVLItsQ95gDpZMtqjC0 FKLkF7g/BQrE/UgGzJ16YuF4h+Ct8+2Ihiz0BS6OD6ie2g9Ds/u1l/TCn/jfj+ID PJhDUcDPynBqy+i1V475w+ZY7lLpE7oOg1HPJvQLqFgc6XkPTI75EttpWB01NOoO vKfugwxKJBfLFCX/oWbTk04P69dysLJLeb/WedTrqWAdn/to0bhD1aKX2rV+aYx3 Rs+7DescTrGV+n6qcdx2TUEqswCyMrBoStBUwEGuM+S+EVFQ7KitAY83puNUO3zX qAEpAOUWyqE0WXG3s7Ee =ltDY -----END PGP SIGNATURE-----
diff --git a/block.c b/block.c index ae87cba..0fb409b 100644 --- a/block.c +++ b/block.c @@ -2934,6 +2934,11 @@ int bdrv_has_zero_init(BlockDriverState *bs) { 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) { return bs->drv->bdrv_has_zero_init(bs); } diff --git a/qemu-img.c b/qemu-img.c index 3faffee..c5c8ebc 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -1504,14 +1504,7 @@ static int img_convert(int argc, char **argv) should add a specific call to have the info to go faster */ buf1 = buf; while (n > 0) { - /* If the output image is being created as a copy on write image, - 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 || + if (!has_zero_init || is_allocated_sectors_min(buf1, n, &n1, min_sparse)) { ret = bdrv_write(out_bs, sector_num, buf1, n1); if (ret < 0) {
This helps implementing is_allocated on top of get_block_status. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> --- block.c | 5 +++++ qemu-img.c | 9 +-------- 2 files changed, 6 insertions(+), 8 deletions(-)