On 05/26/2017 11:55 AM, Max Reitz wrote: > This patch adds two new parameters to the preallocate() function so we > will be able to use it not just for preallocating a new image but also > for preallocated image growth. > > The offset parameter allows the caller to specify a virtual offset from > which to start preallocating. For newly created images this is always 0, > but for preallocating growth this will be the old image length. > > The new_length parameter specifies the supposed new length of the image > (basically the "end offset" for preallocation). During image truncation, > bdrv_getlength() will return the old image length so we cannot rely on > its return value then. bdrv_getlength() is (currently) always sector-aligned (rounding up as needed). new_length is passed from qcow2_create2()'s total_size, which in turn comes from qcow2_create()'s size, which can be user-supplied - but also appears that we round up to ensure it is always sector-aligned. Testing: 'qemu-img create -f qcow2 a.img 1' reports "size=1", but 'qemu-img info a.img' reports "virtual size: 512" - so we have a secondary bug worth fixing later in that we are rounding AFTER what we report to the user, but I'm not seeing a behavior change in this patch. > > Signed-off-by: Max Reitz > --- > block/qcow2.c | 17 ++++++++++++----- > 1 file changed, 12 insertions(+), 5 deletions(-) > Reviewed-by: Eric Blake -- Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org