Hello Jean-Louis,

On 10/29/26 4:58 PM, Jean-Louis Dupond wrote:
> 
> On 27/10/2026 11:44, Andrey Drobyshev wrote:
>> We basically fill 2 images with identical data and perform discard
>> operations with and without 'discard-no-unref' enabled.  Then we check
>> that images still read identically, that their disk usage is the same
>> (i.e. fallocate(FALLOC_FL_PUNCH_HOLE|FALLOC_FL_KEEP_SIZE) is called for
>> both) and that with the option enabled cluster is still marked as
>> allocated in "qemu-img map" output.  We also check that the option
>> doesn't work with qcow2 v2 images.
>>
>> Signed-off-by: Andrey Drobyshev <[email protected]>
>> Reviewed-by: Alexander Ivanov <[email protected]>
>> Reviewed-by: Alberto Garcia <[email protected]>
>> ---
>>   tests/qemu-iotests/290     | 34 ++++++++++++++++++++++++++++++++++
>>   tests/qemu-iotests/290.out | 28 ++++++++++++++++++++++++++++
>>   2 files changed, 62 insertions(+)
>>
>> diff --git a/tests/qemu-iotests/290 b/tests/qemu-iotests/290
>> index 341a25f96b5..152fd7c5d1f 100755
>> --- a/tests/qemu-iotests/290
>> +++ b/tests/qemu-iotests/290
>> @@ -90,6 +90,40 @@ for qcow2_compat in 0.10 1.1; do
>>       $QEMU_IMG map "$TEST_IMG" | _filter_testdir
>>   done
>>   
>> +echo
>> +echo "### Test 'qemu-io -c discard' with 'discard-no-unref' option enabled"
>> +echo
>> +
>> +echo "# Check that qcow2 v2 images don't support 'discard-no-unref' option"
>> +NOUNREF_IMG="$TEST_IMG.nounref"
> 
> This file should be cleaned in '_cleanup()'.
> Happens in test 289 for example.

Agreed.
>> +TEST_IMG="$NOUNREF_IMG" _make_test_img -o "compat=0.10" 128k
>> +# This should immediately fail with an error
>> +$QEMU_IO -c 'reopen -o discard-no-unref=on' "$NOUNREF_IMG" | _filter_qemu_io
>> +
>> +echo "# Create two compat=1.1 images and fill them with identical data"
>> +_make_test_img -o "compat=1.1" 128k
>> +TEST_IMG="$NOUNREF_IMG" _make_test_img -o "compat=1.1" 128k
>> +$QEMU_IO -c 'write -P 0xaa 0 128k' "$TEST_IMG" | _filter_qemu_io
>> +$QEMU_IO -c 'write -P 0xaa 0 128k' "$NOUNREF_IMG" | _filter_qemu_io
>> +
>> +echo "# Enable 'discard-no-unref' in one of them, discard 2nd cluster in 
>> both"
>> +$QEMU_IO -c 'discard 64k 64k' "$TEST_IMG" | _filter_qemu_io
>> +$QEMU_IO -c 'reopen -o discard-no-unref=on' \
>> +         -c 'discard 64k 64k' "$NOUNREF_IMG" | _filter_qemu_io
>> +
>> +echo "# Compare disk usage of the 2 images"
>> +# Don't check the exact disk usage values but rather that they're equal
>> +echo "disk_usage(`basename $TEST_IMG`) - disk_usage(`basename 
>> $NOUNREF_IMG`)" \
>> +     "= $(( `disk_usage $TEST_IMG` - `disk_usage $NOUNREF_IMG`))"
> Shouldn't we call _require_disk_usage in the test? Otherwise the test 
> might be invalid.
> Also something like the following would be cleaner:
> img1=$(basename "$TEST_IMG")
> img2=$(basename "$NOUNREF_IMG")
> usage1=$(disk_usage "$TEST_IMG")
> usage2=$(disk_usage "$NOUNREF_IMG")
> echo "disk_usage($img1) - disk_usage($img2) = $((usage1 - usage2))"

You're right, we should add the check.

Thanks,
Andrey


Reply via email to