qemu-img: Fix convert -n -B for backing-less targets
authorMax Reitz <mreitz@redhat.com>
Tue, 21 Jan 2020 15:59:14 +0000 (16:59 +0100)
committerMax Reitz <mreitz@redhat.com>
Thu, 20 Feb 2020 15:43:42 +0000 (16:43 +0100)
commitc69291e712ae4ef95f628424db6586473da61d43
tree3fe0ab0a4a164126771be606da85a88b75a44b18
parent4dddeac115c5a2c5f74731fda0afd031a0b45490
qemu-img: Fix convert -n -B for backing-less targets

s.target_has_backing does not reflect whether the target BDS has a
backing file; it only tells whether we should use a backing file during
conversion (specified by -B).

As such, if you use convert -n, the target does not necessarily actually
have a backing file, and then dereferencing out_bs->backing fails here.

When converting to an existing file, we should set
target_backing_sectors to a negative value, because first, as the
comment explains, this value is only used for optimization, so it is
always fine to do that.

Second, we use this value to determine where the target must be
initialized to zeroes (overlays are initialized to zero after the end of
their backing file).  When converting to an existing file, we cannot
assume that to be true.

Cc: qemu-stable@nongnu.org
Fixes: 351c8efff9ad809c822d55620df54d575d536f68
       ("qemu-img: Special post-backing convert handling")
Signed-off-by: Max Reitz <mreitz@redhat.com>
Message-Id: <20200121155915.98232-2-mreitz@redhat.com>
Reviewed-by: John Snow <jsnow@redhat.com>
Signed-off-by: Max Reitz <mreitz@redhat.com>
qemu-img.c