parallels: Add duplication check, refactor, fix bugs
cover parallels: Add duplication check, refactor, fix bugs
This patchset depends on the patchset
[PATCH v3 0/8] parallels: Refactor the code of images checks and fix a bug
Fix an incorrect condition in out-of-image check and incorrect data end calculation in parallels_open().
Add parallels_handle_leak() and highest_offset() helpers.
Add checking and repairing duplicate offsets in BAT.
Add tests for parallels format checks.
Refactor and fix old parallels tests.
Alexander Ivanov (10):
parallels: Incorrect condition in out-of-image check
parallels: Incorrect data end calculation in parallels_open
parallels: Create parallels_handle_leak() to truncate excess clusters
parallels: Add checking and repairing duplicate offsets in BAT
parallels: Use highest_offset() helper in leak check
iotests: Add out-of-image check test for parallels format
iotests: Add leak check test for parallels format
iotests: Add test for BAT entries duplication check
iotests: Refactor tests of parallels images checks (131)
iotests: Fix cluster size in parallels images tests (131)
block/parallels.c | 217 +++++++++++++++--- tests/qemu-iotests/131 | 32 +-- tests/qemu-iotests/131.out | 44 ++-- tests/qemu-iotests/tests/parallels-checks | 136 +++++++++++ tests/qemu-iotests/tests/parallels-checks.out | 75 ++++++ 5 files changed, 437 insertions(+), 67 deletions(-) create mode 100755 tests/qemu-iotests/tests/parallels-checks create mode 100644 tests/qemu-iotests/tests/parallels-checks.out
Signature · 1 line
2.34.1
PATCH 1/10 parallels: Incorrect condition in out-of-image check
All the offsets in the BAT must be at least one cluster away from the end of the data area.
Fix the check condition for correct check.
--- block/parallels.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
block/parallels.c +1 -1
@@ -455,7 +455,7 @@ static int parallels_check_outside_image(BlockDriverState *bs,for (i =0 ; i < s->bat_size; i++) { off =bat2sect (s, i) <<BDRV_SECTOR_BITS ; -if (off > size) { +if (off + s->cluster_size > size) {fprintf (stderr,"%s cluster %u is outside image\n" , fix &BDRV_FIX_ERRORS ?"Repairing" :"ERROR" , i); res->corruptions++;
Signature · 1 line
2.34.1
PATCH 2/10 parallels: Incorrect data end calculation in parallels_open
In reply to Alexander IvanovThe BDRVParallelsState structure contains data_end field that is measured in sectors.
In parallels_open() initially this field is set by data_off field from parallels image header.
According to the parallels format documentation,data_off field contains an offset, in sectors, from the start of the file to the start of the data area.
For "WithoutFreeSpace" images: if data_off is zero,
the offset is calculated as the end of the BAT table
plus some padding to ensure sector size alignment.
The parallels_open() function has code for handling zero value in data_off, but in the result data_end contains the offset in bytes.
Replace the alignment to sector size by division by sector size.
--- block/parallels.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
block/parallels.c +2 -1
@@ -850,7 +850,8 @@ static int parallels_open(BlockDriverState *bs, QDict *options, int flags, } s->data_end =le32_to_cpu (ph.data_off);if (s->data_end ==0 ) { - s->data_end =ROUND_UP (bat_entry_off (s->bat_size),BDRV_SECTOR_SIZE ); + s->data_end =DIV_ROUND_UP (bat_entry_off (s->bat_size), +BDRV_SECTOR_SIZE ); }if (s->data_end < s->header_size) {/* there is not enough unused space to fit to block align between BAT
Signature · 1 line
2.34.1
PATCH 3/10 parallels: Create parallels_handle_leak() to truncate excess clusters
In reply to Alexander IvanovThis helper will be reused in the next patch for duplications check.
--- block/parallels.c | 83 ++++++++++++++++++++++++++++++----------------- 1 file changed, 53 insertions(+), 30 deletions(-)
block/parallels.c +53 -30
@@ -469,19 +469,48 @@ static int parallels_check_outside_image(BlockDriverState *bs,return 0 ; } +static int64_t parallels_handle_leak (BlockDriverState *bs, +BdrvCheckResult *res, +int64_t high_off, +bool fix) +{ +BDRVParallelsState *s = bs->opaque; +int64_t size; +int ret; + + size =bdrv_getlength (bs->file->bs); +if (size <0 ) { +return size; + } + + res->image_end_offset = high_off + s->cluster_size; +if (size <= res->image_end_offset) { +return 0 ; + } + +if (fix) { +Error *local_err =NULL ; +/* +* In order to really repair the image, we must shrink it. +* That means we have to pass exact=true. +*/ + ret =bdrv_truncate (bs->file, res->image_end_offset, true, +PREALLOC_MODE_OFF ,0 , &local_err); +if (ret <0 ) { +error_report_err (local_err); +return ret; + } + } +return size - res->image_end_offset; +} +static int parallels_check_leak (BlockDriverState *bs,BdrvCheckResult *res,BdrvCheckMode fix) {BDRVParallelsState *s = bs->opaque; -int64_t size, off, high_off, count; -int i, ret; - - size =bdrv_getlength (bs->file->bs); -if (size <0 ) { - res->check_errors++; -return size; - } +int64_t off, high_off, count, cut_out; +int i; high_off =0 ;for (i =0 ; i < s->bat_size; i++) {
@@ -491,30 +520,24 @@ static int parallels_check_leak(BlockDriverState *bs, } } - res->image_end_offset = high_off + s->cluster_size; -if (size > res->image_end_offset) { - count =DIV_ROUND_UP (size - res->image_end_offset, s->cluster_size); -fprintf (stderr,"%s space leaked at the end of the image %" PRId64"\n" , - fix &BDRV_FIX_LEAKS ?"Repairing" :"ERROR" , - size - res->image_end_offset); - res->leaks += count; -if (fix &BDRV_FIX_LEAKS ) { -Error *local_err =NULL ; + cut_out =parallels_handle_leak (bs, res, high_off, fix &BDRV_FIX_LEAKS ); +if (cut_out <0 ) { + res->check_errors++; +return cut_out; + } +if (cut_out ==0 ) { +return 0 ; + } -/* -* In order to really repair the image, we must shrink it. -* That means we have to pass exact=true. -*/ - ret =bdrv_truncate (bs->file, res->image_end_offset, true, -PREALLOC_MODE_OFF ,0 , &local_err); -if (ret <0 ) { -error_report_err (local_err); - res->check_errors++; -return ret; - } - res->leaks_fixed += count; - } + count =DIV_ROUND_UP (cut_out, s->cluster_size); +fprintf (stderr,"%s space leaked at the end of the image %" PRId64"\n" , + fix &BDRV_FIX_LEAKS ?"Repairing" :"ERROR" , cut_out); + + res->leaks += count; +if (fix &BDRV_FIX_LEAKS ) { + res->leaks_fixed += count; } +return 0 ; }
Signature · 1 line
2.34.1
PATCH 4/10 parallels: Add checking and repairing duplicate offsets in BAT
In reply to Alexander IvanovCluster offsets must be unique among all BAT entries. Find duplicate offsets in the BAT.
If a duplicated offset is found fix it by copying the content of the relevant cluster to a new allocated cluster and set the new cluster offset to the duplicated entry.
Add host_cluster_index() helper to deduplicate the code. Add highest_offset() helper. It will be used for code deduplication in the next patch.
--- block/parallels.c | 136 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 136 insertions(+)
block/parallels.c +136 -0
@@ -136,6 +136,26 @@ static int cluster_remainder(BDRVParallelsState *s, int64_t sector_num,return MIN (nb_sectors, ret); } +static uint32_t host_cluster_index (BDRVParallelsState *s,int64_t off) +{ + off -= s->header->data_off <<BDRV_SECTOR_BITS ; +return off / s->cluster_size; +} + +static int64_t highest_offset (BDRVParallelsState *s) +{ +int64_t off, high_off =0 ; +int i; + +for (i =0 ; i < s->bat_size; i++) { + off =bat2sect (s, i) <<BDRV_SECTOR_BITS ; +if (off > high_off) { + high_off = off; + } + } +return high_off; +} +static int64_t block_status (BDRVParallelsState *s,int64_t sector_num,int nb_sectors,int *pnum) {
@@ -541,6 +561,114 @@ static int parallels_check_leak(BlockDriverState *bs,return 0 ; } +static int parallels_check_duplicate (BlockDriverState *bs, +BdrvCheckResult *res, +BdrvCheckMode fix) +{ +BDRVParallelsState *s = bs->opaque; +QEMUIOVector qiov; +int64_t off, high_off, sector; +unsigned long *bitmap; +uint32_t i, bitmap_size, cluster_index; +int n, ret =0 ; +uint64_t *buf =NULL ; +bool new_allocations = false; + + high_off =highest_offset (s); +if (high_off ==0 ) { +return 0 ; + } + +/* +* Create a bitmap of used clusters. +* If a bit is set, there is a BAT entry pointing to this cluster. +* Loop through the BAT entrues, check bits relevant to an entry offset. +* If bit is set, this entry is duplicated. Otherwise set the bit. +*/ + bitmap_size =host_cluster_index (s, high_off) +1 ; + bitmap =bitmap_new (bitmap_size); + + buf =g_malloc (s->cluster_size); +qemu_iovec_init (&qiov,0 ); +qemu_iovec_add (&qiov, buf, s->cluster_size); + +for (i =0 ; i < s->bat_size; i++) { + off =bat2sect (s, i) <<BDRV_SECTOR_BITS ; +if (off ==0 ) { +continue ; + } + + cluster_index =host_cluster_index (s, off); +if (test_bit (cluster_index, bitmap)) { +/* this cluster duplicates another one */ +fprintf (stderr, +"%s duplicate offset in BAT entry %u\n" , + fix &BDRV_FIX_ERRORS ?"Repairing" :"ERROR" , i); + + res->corruptions++; + +if (fix &BDRV_FIX_ERRORS ) { +/* +* Reset the entry and allocate a new cluster +* for the relevant guest offset. In this way we let +* the lower layer to place the new cluster properly. +* Copy the original cluster to the allocated one. +*/ +parallels_set_bat_entry (s, i,0 ); + + ret =bdrv_pread (bs->file, off, s->cluster_size, buf,0 ); +if (ret <0 ) { + res->check_errors++; + goto out; + } + + sector = (i * s->cluster_size) >>BDRV_SECTOR_BITS ; + off =allocate_clusters (bs, sector, s->tracks, &n); +if (off <0 ) { + res->check_errors++; + ret = off; + goto out; + } + off <<=BDRV_SECTOR_BITS ; +if (off > high_off) { + high_off = off; + } + + ret =bdrv_co_pwritev (bs->file, off, s->cluster_size, &qiov,0 ); +if (ret <0 ) { + res->check_errors++; + goto out; + } + + new_allocations = true; + res->corruptions_fixed++; + } + + }else { +bitmap_set (bitmap, cluster_index,1 ); + } + } + +if (new_allocations) { +/* +* When new clusters are allocated, file size increases +* by 128 Mb blocks. We need to truncate the file to the +* right size. +*/ + ret =parallels_handle_leak (bs, res, high_off, true); +if (ret <0 ) { + res->check_errors++; + goto out; + } + } + +out: +qemu_iovec_destroy (&qiov); +g_free (buf); +g_free (bitmap); +return ret; +} +static void parallels_collect_statistics (BlockDriverState *bs,BdrvCheckResult *res,BdrvCheckMode fix)
@@ -589,6 +717,14 @@ static int coroutine_fn parallels_co_check(BlockDriverState *bs,return ret; } +/* This checks only for "WithouFreSpacExt" format */ +if (!memcmp (s->header->magic,HEADER_MAGIC2 ,16 )) { + ret =parallels_check_duplicate (bs, res, fix); +if (ret <0 ) { +return ret; + } + } +parallels_collect_statistics (bs, res, fix); }
Signature · 1 line
2.34.1
PATCH 5/10 parallels: Use highest_offset() helper in leak check
In reply to Alexander IvanovDeduplicate code by using highest_offset() helper.
--- block/parallels.c | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-)
block/parallels.c +1 -8
@@ -530,15 +530,8 @@ static int parallels_check_leak(BlockDriverState *bs, {BDRVParallelsState *s = bs->opaque;int64_t off, high_off, count, cut_out; -int i; - high_off =0 ; -for (i =0 ; i < s->bat_size; i++) { - off =bat2sect (s, i) <<BDRV_SECTOR_BITS ; -if (off > high_off) { - high_off = off; - } - } + high_off =highest_offset (s); cut_out =parallels_handle_leak (bs, res, high_off, fix &BDRV_FIX_LEAKS );if (cut_out <0 ) {
Signature · 1 line
2.34.1
PATCH 6/10 iotests: Add out-of-image check test for parallels format
In reply to Alexander IvanovFill the image with a pattern to generate entries in the BAT, set the first BAT entry outside the image, try to read the corrupted image, repair and check for zeroes in the first cluster.
--- tests/qemu-iotests/tests/parallels-checks | 78 +++++++++++++++++++ tests/qemu-iotests/tests/parallels-checks.out | 22 ++++++ 2 files changed, 100 insertions(+) create mode 100755 tests/qemu-iotests/tests/parallels-checks create mode 100644 tests/qemu-iotests/tests/parallels-checks.out
tests/qemu-iotests/tests/parallels-checks new file +78 -0
@@ -0,0 +1,78 @@ +#!/usr/bin/env bash +# group: rw quick +# +# Test qemu-img check for parallels format +# +# Copyright (C) 2022 Virtuozzo International GmbH +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. +# + +# creator [email protected] + +seq=`basename $0` +echo "QA output created by $seq" + +status=1 # failure is the default! + +_cleanup() +{ + _cleanup_test_img +} +trap "_cleanup; exit \$status" 0 1 2 3 15 + +# get standard environment, filters and checks +. ../common.rc +. ../common.filter + +_supported_fmt parallels +_supported_proto file +_supported_os Linux + +SIZE=$((4 * 1024 * 1024)) +IMGFMT=parallels +CLUSTER_SIZE_OFFSET=28 +BAT_OFFSET=64 + +_make_test_img $SIZE + +CLUSTER_SIZE=$(peek_file_le $TEST_IMG $CLUSTER_SIZE_OFFSET 4) +CLUSTER_SIZE=$((CLUSTER_SIZE * 512)) +LAST_CLUSTER_OFF=$((SIZE - CLUSTER_SIZE)) +LAST_CLUSTER=$((LAST_CLUSTER_OFF/CLUSTER_SIZE)) + +echo "== TEST OUT OF IMAGE CHECK ==" + +echo "== write pattern ==" +{ $QEMU_IO -c "write -P 0x11 0 $SIZE" "$TEST_IMG"; } 2>&1 | _filter_qemu_io | _filter_testdir + +echo "== corrupt image ==" +cluster=$(($LAST_CLUSTER + 2)) +poke_file "$TEST_IMG" "$BAT_OFFSET" "\x$cluster\x00\x00\x00" + +echo "== read corrupted image ==" +{ $QEMU_IO -c "read -P 0x11 0 $CLUSTER_SIZE" "$TEST_IMG"; } 2>&1 | _filter_qemu_io | _filter_testdir + +echo "== repair image ==" +_check_test_img -r all + +echo "== read repaired image ==" +{ $QEMU_IO -c "read -P 0x00 0 $CLUSTER_SIZE" "$TEST_IMG"; } 2>&1 | _filter_qemu_io | _filter_testdir + + +# success, all done +echo "*** done" +rm -f $seq.full +status=0
tests/qemu-iotests/tests/parallels-checks.out new file +22 -0
@@ -0,0 +1,22 @@ +QA output created by parallels-checks +Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=4194304 +== TEST OUT OF IMAGE CHECK == +== write pattern == +wrote 4194304/4194304 bytes at offset 0 +4 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +== corrupt image == +== read corrupted image == +qemu-io: can't open device TEST_DIR/t.parallels: parallels: Offset in BAT is out of image +== repair image == +Repairing cluster 0 is outside image +The following inconsistencies were found and repaired: + + 0 leaked clusters + 1 corruptions + +Double checking the fixed image now... +No errors were found on the image. +== read repaired image == +read 1048576/1048576 bytes at offset 0 +1 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +*** done
Signature · 1 line
2.34.1
PATCH 7/10 iotests: Add leak check test for parallels format
In reply to Alexander IvanovWrite a pattern to the last cluster, extend the image by 1 claster, repair and check that the last cluster still has the same pattern.
--- tests/qemu-iotests/tests/parallels-checks | 27 +++++++++++++++++++ tests/qemu-iotests/tests/parallels-checks.out | 22 +++++++++++++++ 2 files changed, 49 insertions(+)
tests/qemu-iotests/tests/parallels-checks +27 -0
@@ -71,6 +71,33 @@ _check_test_img -r all echo "== read repaired image ==" { $QEMU_IO -c "read -P 0x00 0 $CLUSTER_SIZE" "$TEST_IMG"; } 2>&1 | _filter_qemu_io | _filter_testdir +# Clear image +_make_test_img $SIZE + +echo "== TEST LEAK CHECK ==" + +echo "== write pattern to last cluster ==" +echo "write -P 0x11 $LAST_CLUSTER_OFF $CLUSTER_SIZE" +{ $QEMU_IO -c "write -P 0x11 $LAST_CLUSTER_OFF $CLUSTER_SIZE" "$TEST_IMG"; } 2>&1 | _filter_qemu_io | _filter_testdir + +file_size=`stat --printf="%s" "$TEST_IMG"` +echo "file size: $file_size" + +echo "== extend image by 1 cluster ==" +fallocate -l $((file_size + CLUSTER_SIZE)) "$TEST_IMG" + +file_size=`stat --printf="%s" "$TEST_IMG"` +echo "file size: $file_size" + +echo "== repair image ==" +_check_test_img -r all + +file_size=`stat --printf="%s" "$TEST_IMG"` +echo "file size: $file_size" + +echo "== check last cluster ==" +{ $QEMU_IO -c "read -P 0x11 $LAST_CLUSTER_OFF $CLUSTER_SIZE" "$TEST_IMG"; } 2>&1 | _filter_qemu_io | _filter_testdir + # success, all done echo "*** done"
tests/qemu-iotests/tests/parallels-checks.out +22 -0
@@ -19,4 +19,26 @@ No errors were found on the image. == read repaired image == read 1048576/1048576 bytes at offset 0 1 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=4194304 +== TEST LEAK CHECK == +== write pattern to last cluster == +write -P 0x11 3145728 1048576 +wrote 1048576/1048576 bytes at offset 3145728 +1 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +file size: 2097152 +== extend image by 1 cluster == +file size: 3145728 +== repair image == +Repairing space leaked at the end of the image 1048576 +The following inconsistencies were found and repaired: + + 1 leaked clusters + 0 corruptions + +Double checking the fixed image now... +No errors were found on the image. +file size: 2097152 +== check last cluster == +read 1048576/1048576 bytes at offset 3145728 +1 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) *** done
Signature · 1 line
2.34.1
PATCH 8/10 iotests: Add test for BAT entries duplication check
In reply to Alexander IvanovFill the image with a pattern and write another pattern in the second cluster. Corrupt the image and check if the pattern changes. Repair the image and check the patterns on guest and host sides.
--- tests/qemu-iotests/tests/parallels-checks | 31 +++++++++++++++++++ tests/qemu-iotests/tests/parallels-checks.out | 31 +++++++++++++++++++ 2 files changed, 62 insertions(+)
tests/qemu-iotests/tests/parallels-checks +31 -0
@@ -98,6 +98,37 @@ echo "file size: $file_size" echo "== check last cluster ==" { $QEMU_IO -c "read -P 0x11 $LAST_CLUSTER_OFF $CLUSTER_SIZE" "$TEST_IMG"; } 2>&1 | _filter_qemu_io | _filter_testdir +# Clear image +_make_test_img $SIZE + +echo "== TEST DUPLICATION CHECK ==" + +echo "== write pattern to whole image ==" +{ $QEMU_IO -c "write -P 0x11 0 $SIZE" "$TEST_IMG"; } 2>&1 | _filter_qemu_io | _filter_testdir + +echo "== write another pattern to second cluster ==" +{ $QEMU_IO -c "write -P 0x55 $CLUSTER_SIZE $CLUSTER_SIZE" "$TEST_IMG"; } 2>&1 | _filter_qemu_io | _filter_testdir + +echo "== check second cluster ==" +{ $QEMU_IO -c "read -P 0x55 $CLUSTER_SIZE $CLUSTER_SIZE" "$TEST_IMG"; } 2>&1 | _filter_qemu_io | _filter_testdir + +echo "== corrupt image ==" +poke_file "$TEST_IMG" "$(($BAT_OFFSET + 4))" "\x01\x00\x00\x00" + +echo "== check second cluster ==" +{ $QEMU_IO -c "read -P 0x11 $CLUSTER_SIZE $CLUSTER_SIZE" "$TEST_IMG"; } 2>&1 | _filter_qemu_io | _filter_testdir + +echo "== repair image ==" +_check_test_img -r all + +echo "== check second cluster ==" +{ $QEMU_IO -c "read -P 0x11 $CLUSTER_SIZE $CLUSTER_SIZE" "$TEST_IMG"; } 2>&1 | _filter_qemu_io | _filter_testdir + +echo "== check first cluster on host ==" +printf "content: 0x%02x\n" `peek_file_le $TEST_IMG $(($CLUSTER_SIZE)) 1` + +echo "== check second cluster on host ==" +printf "content: 0x%02x\n" `peek_file_le $TEST_IMG $(($CLUSTER_SIZE)) 1` # success, all done echo "*** done"
tests/qemu-iotests/tests/parallels-checks.out +31 -0
@@ -41,4 +41,35 @@ file size: 2097152 == check last cluster == read 1048576/1048576 bytes at offset 3145728 1 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=4194304 +== TEST DUPLICATION CHECK == +== write pattern to whole image == +wrote 4194304/4194304 bytes at offset 0 +4 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +== write another pattern to second cluster == +wrote 1048576/1048576 bytes at offset 1048576 +1 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +== check second cluster == +read 1048576/1048576 bytes at offset 1048576 +1 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +== corrupt image == +== check second cluster == +read 1048576/1048576 bytes at offset 1048576 +1 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +== repair image == +Repairing duplicate offset in BAT entry 1 +The following inconsistencies were found and repaired: + + 0 leaked clusters + 1 corruptions + +Double checking the fixed image now... +No errors were found on the image. +== check second cluster == +read 1048576/1048576 bytes at offset 1048576 +1 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +== check first cluster on host == +content: 0x11 +== check second cluster on host == +content: 0x11 *** done
Signature · 1 line
2.34.1
PATCH 9/10 iotests: Refactor tests of parallels images checks (131)
In reply to Alexander IvanovReplace hardcoded numbers by variables.
--- tests/qemu-iotests/131 | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-)
tests/qemu-iotests/131 +16 -13
@@ -44,31 +44,34 @@ _supported_os Linux inuse_offset=$((0x2c)) size=$((64 * 1024 * 1024)) -CLUSTER_SIZE=64k +CLUSTER_SIZE=$((64 * 1024)) IMGFMT=parallels _make_test_img $size +CLUSTER_HALF_SIZE=$((CLUSTER_SIZE / 2)) +CLUSTER_DBL_SIZE=$((CLUSTER_SIZE * 2)) + echo == read empty image == -{ $QEMU_IO -c "read -P 0 32k 64k" "$TEST_IMG"; } 2>&1 | _filter_qemu_io | _filter_testdir +{ $QEMU_IO -c "read -P 0 $CLUSTER_HALF_SIZE $CLUSTER_SIZE" "$TEST_IMG"; } 2>&1 | _filter_qemu_io | _filter_testdir echo == write more than 1 block in a row == -{ $QEMU_IO -c "write -P 0x11 32k 128k" "$TEST_IMG"; } 2>&1 | _filter_qemu_io | _filter_testdir +{ $QEMU_IO -c "write -P 0x11 $CLUSTER_HALF_SIZE $CLUSTER_DBL_SIZE" "$TEST_IMG"; } 2>&1 | _filter_qemu_io | _filter_testdir echo == read less than block == -{ $QEMU_IO -c "read -P 0x11 32k 32k" "$TEST_IMG"; } 2>&1 | _filter_qemu_io | _filter_testdir +{ $QEMU_IO -c "read -P 0x11 $CLUSTER_HALF_SIZE $CLUSTER_HALF_SIZE" "$TEST_IMG"; } 2>&1 | _filter_qemu_io | _filter_testdir echo == read exactly 1 block == -{ $QEMU_IO -c "read -P 0x11 64k 64k" "$TEST_IMG"; } 2>&1 | _filter_qemu_io | _filter_testdir +{ $QEMU_IO -c "read -P 0x11 $CLUSTER_SIZE $CLUSTER_SIZE" "$TEST_IMG"; } 2>&1 | _filter_qemu_io | _filter_testdir echo == read more than 1 block == -{ $QEMU_IO -c "read -P 0x11 32k 128k" "$TEST_IMG"; } 2>&1 | _filter_qemu_io | _filter_testdir +{ $QEMU_IO -c "read -P 0x11 $CLUSTER_HALF_SIZE $CLUSTER_DBL_SIZE" "$TEST_IMG"; } 2>&1 | _filter_qemu_io | _filter_testdir echo == check that there is no trash after written == -{ $QEMU_IO -c "read -P 0 160k 32k" "$TEST_IMG"; } 2>&1 | _filter_qemu_io | _filter_testdir +{ $QEMU_IO -c "read -P 0 $((CLUSTER_HALF_SIZE + CLUSTER_DBL_SIZE)) $CLUSTER_HALF_SIZE" "$TEST_IMG"; } 2>&1 | _filter_qemu_io | _filter_testdir echo == check that there is no trash before written == -{ $QEMU_IO -c "read -P 0 0 32k" "$TEST_IMG"; } 2>&1 | _filter_qemu_io | _filter_testdir +{ $QEMU_IO -c "read -P 0 0 $CLUSTER_HALF_SIZE" "$TEST_IMG"; } 2>&1 | _filter_qemu_io | _filter_testdir echo "== Corrupt image ==" poke_file "$TEST_IMG" "$inuse_offset" "\x59\x6e\x6f\x74" -{ $QEMU_IO -c "read -P 0x11 64k 64k" "$TEST_IMG"; } 2>&1 | _filter_qemu_io | _filter_testdir +{ $QEMU_IO -c "read -P 0x11 $CLUSTER_SIZE $CLUSTER_SIZE" "$TEST_IMG"; } 2>&1 | _filter_qemu_io | _filter_testdir _check_test_img _check_test_img -r all -{ $QEMU_IO -c "read -P 0x11 64k 64k" "$TEST_IMG"; } 2>&1 | _filter_qemu_io | _filter_testdir +{ $QEMU_IO -c "read -P 0x11 $CLUSTER_SIZE $CLUSTER_SIZE" "$TEST_IMG"; } 2>&1 | _filter_qemu_io | _filter_testdir echo "== allocate with backing ==" # Verify that allocating clusters works fine even when there is a backing image.
@@ -83,7 +86,7 @@ TEST_IMG="$TEST_IMG.base" _make_test_img $size # Write some data to the base image (which would trigger an assertion failure if # interpreted as a QEMUIOVector) -$QEMU_IO -c 'write -P 42 0 64k' "$TEST_IMG.base" | _filter_qemu_io +$QEMU_IO -c "write -P 42 0 $CLUSTER_SIZE" "$TEST_IMG.base" | _filter_qemu_io # Parallels does not seem to support storing a backing filename in the image # itself, so we need to build our backing chain on the command line
@@ -99,8 +102,8 @@ QEMU_IO_OPTIONS=$QEMU_IO_OPTIONS_NO_FMT \ QEMU_IO_OPTIONS=$QEMU_IO_OPTIONS_NO_FMT \ $QEMU_IO --image-opts "$imgopts" \ -c 'read -P 1 0 64' \ - -c "read -P 42 64 $((64 * 1024 - 64))" \ - -c "read -P 0 64k $((size - 64 * 1024))" \ + -c "read -P 42 64 $((CLUSTER_SIZE - 64))" \ + -c "read -P 0 $CLUSTER_SIZE $((size - CLUSTER_SIZE))" \ | _filter_qemu_io # success, all done
Signature · 1 line
2.34.1
PATCH 10/10 iotests: Fix cluster size in parallels images tests (131)
In reply to Alexander IvanovIn this test cluster size is 64k, but modern tools generate images with cluster size 1M.
Calculate cluster size using track field from image header.
--- tests/qemu-iotests/131 | 5 ++++- tests/qemu-iotests/131.out | 44 +++++++++++++++++++------------------- 2 files changed, 26 insertions(+), 23 deletions(-)
tests/qemu-iotests/131 +4 -1
@@ -44,10 +44,13 @@ _supported_os Linux inuse_offset=$((0x2c)) size=$((64 * 1024 * 1024)) -CLUSTER_SIZE=$((64 * 1024)) IMGFMT=parallels _make_test_img $size +# get cluster size in sectros from "tracks" header field +CLUSTER_SIZE_OFFSET=28 +CLUSTER_SIZE=$(peek_file_le $TEST_IMG $CLUSTER_SIZE_OFFSET 4) +CLUSTER_SIZE=$((CLUSTER_SIZE * 512)) CLUSTER_HALF_SIZE=$((CLUSTER_SIZE / 2)) CLUSTER_DBL_SIZE=$((CLUSTER_SIZE * 2))
tests/qemu-iotests/131.out +22 -22
67 lines not on this page · raw message
Signature · 1 line
2.34.1