Commit 2c060c0f authored by Vladimir Sementsov-Ogievskiy's avatar Vladimir Sementsov-Ogievskiy Committed by Max Reitz
Browse files

block/vpc: return ZERO block-status when appropriate



In case when get_image_offset() returns -1, we do zero out the
corresponding chunk of qiov. So, this should be reported as ZERO.

Note that this changes visible output of "qemu-img map --output=json"
and "qemu-io -c map" commands. For qemu-img map, the change is obvious:
we just mark as zero what is really zero. For qemu-io it's less
obvious: what was unallocated now is allocated.

There is an inconsistency in understanding of unallocated regions in
Qemu: backing-supporting format-drivers return 0 block-status to report
go-to-backing logic for this area. Some protocol-drivers (iscsi) return
0 to report fs-unallocated-non-zero status (i.e., don't occupy space on
disk, read result is undefined).

BDRV_BLOCK_ALLOCATED is defined as something more close to
go-to-backing logic. Still it is calculated as ZERO | DATA, so 0 from
iscsi is treated as unallocated. It doesn't influence backing-chain
behavior, as iscsi can't have backing file. But it does influence
"qemu-io -c map".

We should solve this inconsistency at some future point. Now, let's
just make backing-not-supporting format drivers (vdi in the previous
patch and vpc now) to behave more like backing-supporting drivers
and not report 0 block-status. More over, returning ZERO status is
absolutely valid thing, and again, corresponds to how the other
format-drivers (backing-supporting) work.

After block-status update, it never reports 0, so setting
unallocated_blocks_are_zero doesn't make sense (as the only user of it
is bdrv_co_block_status and it checks unallocated_blocks_are_zero only
for unallocated areas). Drop it.

Signed-off-by: default avatarVladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Reviewed-by: default avatarEric Blake <eblake@redhat.com>
Message-Id: <20200528094405.145708-5-vsementsov@virtuozzo.com>
[mreitz: qemu-io -c map as used by iotest 146 now reports everything as
         allocated; in order to make the test do something useful, we
         use qemu-img map --output=json now]
Signed-off-by: default avatarMax Reitz <mreitz@redhat.com>
parent 2ea0332f
Loading
Loading
Loading
Loading
+1 −2
Original line number Diff line number Diff line
@@ -606,7 +606,6 @@ static int vpc_get_info(BlockDriverState *bs, BlockDriverInfo *bdi)
        bdi->cluster_size = s->block_size;
    }

    bdi->unallocated_blocks_are_zero = true;
    return 0;
}

@@ -745,7 +744,7 @@ static int coroutine_fn vpc_co_block_status(BlockDriverState *bs,
    image_offset = get_image_offset(bs, offset, false, NULL);
    allocated = (image_offset != -1);
    *pnum = 0;
    ret = 0;
    ret = BDRV_BLOCK_ZERO;

    do {
        /* All sectors in a block are contiguous (without using the bitmap) */
+45 −15
Original line number Diff line number Diff line
@@ -51,19 +51,25 @@ echo === Testing VPC Autodetect ===
echo
_use_sample_img virtualpc-dynamic.vhd.bz2

${QEMU_IO} -c "open -o driver=vpc ${TEST_IMG}" -c 'map'
$QEMU_IMG map --output=json --image-opts \
    "driver=vpc,file.filename=$TEST_IMG" \
    | _filter_qemu_img_map

echo
echo === Testing VPC with current_size force ===
echo

${QEMU_IO} -c "open -o driver=vpc,force_size_calc=current_size ${TEST_IMG}" -c 'map'
$QEMU_IMG map --output=json --image-opts \
    "driver=vpc,force_size_calc=current_size,file.filename=$TEST_IMG" \
    | _filter_qemu_img_map

echo
echo === Testing VPC with chs force ===
echo

${QEMU_IO} -c "open -o driver=vpc,force_size_calc=chs ${TEST_IMG}" -c 'map'
$QEMU_IMG map --output=json --image-opts \
    "driver=vpc,force_size_calc=chs,file.filename=$TEST_IMG" \
    | _filter_qemu_img_map

_cleanup_test_img

@@ -72,19 +78,25 @@ echo === Testing Hyper-V Autodetect ===
echo
_use_sample_img hyperv2012r2-dynamic.vhd.bz2

${QEMU_IO} -c "open -o driver=vpc ${TEST_IMG}" -c 'map'
$QEMU_IMG map --output=json --image-opts \
    "driver=vpc,file.filename=$TEST_IMG" \
    | _filter_qemu_img_map

echo
echo === Testing Hyper-V with current_size force ===
echo

${QEMU_IO} -c "open -o driver=vpc,force_size_calc=current_size ${TEST_IMG}" -c 'map'
$QEMU_IMG map --output=json --image-opts \
    "driver=vpc,force_size_calc=current_size,file.filename=$TEST_IMG" \
    | _filter_qemu_img_map

echo
echo === Testing Hyper-V with chs force ===
echo

${QEMU_IO} -c "open -o driver=vpc,force_size_calc=chs ${TEST_IMG}" -c 'map'
$QEMU_IMG map --output=json --image-opts \
    "driver=vpc,force_size_calc=chs,file.filename=$TEST_IMG" \
    | _filter_qemu_img_map

_cleanup_test_img

@@ -93,19 +105,25 @@ echo === Testing d2v Autodetect ===
echo
_use_sample_img d2v-zerofilled.vhd.bz2

${QEMU_IO} -c "open -o driver=vpc ${TEST_IMG}" -c 'map'
$QEMU_IMG map --output=json --image-opts \
    "driver=vpc,file.filename=$TEST_IMG" \
    | _filter_qemu_img_map

echo
echo === Testing d2v with current_size force ===
echo

${QEMU_IO} -c "open -o driver=vpc,force_size_calc=current_size ${TEST_IMG}" -c 'map'
$QEMU_IMG map --output=json --image-opts \
    "driver=vpc,force_size_calc=current_size,file.filename=$TEST_IMG" \
    | _filter_qemu_img_map

echo
echo === Testing d2v with chs force ===
echo

${QEMU_IO} -c "open -o driver=vpc,force_size_calc=chs ${TEST_IMG}" -c 'map'
$QEMU_IMG map --output=json --image-opts \
    "driver=vpc,force_size_calc=chs,file.filename=$TEST_IMG" \
    | _filter_qemu_img_map

_cleanup_test_img

@@ -121,19 +139,25 @@ echo
echo === Read created image, default opts ====
echo

${QEMU_IO} -c "open -o driver=vpc ${TEST_IMG}" -c 'map'
$QEMU_IMG map --output=json --image-opts \
    "driver=vpc,file.filename=$TEST_IMG" \
    | _filter_qemu_img_map

echo
echo === Read created image, force_size_calc=chs ====
echo

${QEMU_IO} -c "open -o driver=vpc,force_size_calc=chs ${TEST_IMG}" -c 'map'
$QEMU_IMG map --output=json --image-opts \
    "driver=vpc,force_size_calc=chs,file.filename=$TEST_IMG" \
    | _filter_qemu_img_map

echo
echo === Read created image, force_size_calc=current_size ====
echo

${QEMU_IO} -c "open -o driver=vpc,force_size_calc=current_size ${TEST_IMG}" -c 'map'
$QEMU_IMG map --output=json --image-opts \
    "driver=vpc,force_size_calc=current_size,file.filename=$TEST_IMG" \
    | _filter_qemu_img_map

echo
echo === Testing Image create, force_size ===
@@ -145,19 +169,25 @@ echo
echo === Read created image, default opts ====
echo

${QEMU_IO} -c "open -o driver=vpc ${TEST_IMG}" -c 'map'
$QEMU_IMG map --output=json --image-opts \
    "driver=vpc,file.filename=$TEST_IMG" \
    | _filter_qemu_img_map

echo
echo === Read created image, force_size_calc=chs ====
echo

${QEMU_IO} -c "open -o driver=vpc,force_size_calc=chs ${TEST_IMG}" -c 'map'
$QEMU_IMG map --output=json --image-opts \
    "driver=vpc,force_size_calc=chs,file.filename=$TEST_IMG" \
    | _filter_qemu_img_map

echo
echo === Read created image, force_size_calc=current_size ====
echo

${QEMU_IO} -c "open -o driver=vpc,force_size_calc=current_size ${TEST_IMG}" -c 'map'
$QEMU_IMG map --output=json --image-opts \
    "driver=vpc,force_size_calc=current_size,file.filename=$TEST_IMG" \
    | _filter_qemu_img_map

echo "*** done"
rm -f $seq.full
+390 −15

File changed.

Preview size limit exceeded, changes collapsed.