qemu with hax to log dma reads & writes jcs.org/2018/11/12/vfio

iotests/138: Test leaks/corruptions fixed report

Test that qemu-img check reports the number of leaks and corruptions
fixed in its JSON report (after a successful run).

While touching the _unsupported_imgopts line, adjust the note on why
data_file does not work with this test: The current comment sounds a bit
like it is a mistake for qemu-img check not to check external data
files' refcounts. But there are no such refcounts, so it is no mistake.
Just say that qemu-img check does not do much for external data files,
and this is why this test does not work with them.

Signed-off-by: Max Reitz <mreitz@redhat.com>
Message-Id: <20200324172757.1173824-4-mreitz@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Max Reitz <mreitz@redhat.com>

+53 -2
+39 -2
tests/qemu-iotests/138
··· 41 41 _supported_proto file 42 42 _supported_os Linux 43 43 # With an external data file, data clusters are not refcounted 44 - # (and so qemu-img check does not check their refcount) 45 - _unsupported_imgopts data_file 44 + # (so qemu-img check would not do much); 45 + # we want to modify the refcounts, so we need them to have a specific 46 + # format (namely u16) 47 + _unsupported_imgopts data_file 'refcount_bits=\([^1]\|.\([^6]\|$\)\)' 46 48 47 49 echo 48 50 echo '=== Check on an image with a multiple of 2^32 clusters ===' ··· 64 66 # But starting from 4.0, qemu-img does this check, and instead of "Cannot 65 67 # allocate memory", we have an error showing that l2 entry is invalid. 66 68 _check_test_img 69 + 70 + echo 71 + echo '=== Check leaks-fixed/corruptions-fixed report' 72 + echo 73 + 74 + # After leaks and corruptions were fixed, those numbers should be 75 + # reported by qemu-img check 76 + _make_test_img 64k 77 + 78 + # Allocate data cluster 79 + $QEMU_IO -c 'write 0 64k' "$TEST_IMG" | _filter_qemu_io 80 + 81 + reftable_ofs=$(peek_file_be "$TEST_IMG" 48 8) 82 + refblock_ofs=$(peek_file_be "$TEST_IMG" $reftable_ofs 8) 83 + 84 + # Introduce a leak: Make the image header's refcount 2 85 + poke_file_be "$TEST_IMG" "$refblock_ofs" 2 2 86 + 87 + l1_ofs=$(peek_file_be "$TEST_IMG" 40 8) 88 + 89 + # Introduce a corruption: Drop the COPIED flag from the (first) L1 entry 90 + l1_entry=$(peek_file_be "$TEST_IMG" $l1_ofs 8) 91 + l1_entry=$((l1_entry & ~(1 << 63))) 92 + poke_file_be "$TEST_IMG" $l1_ofs 8 $l1_entry 93 + 94 + echo 95 + # Should print the number of corruptions and leaks fixed 96 + # (Filter out all JSON fields (recognizable by their four-space 97 + # indentation), but keep the "-fixed" fields (by removing two spaces 98 + # from their indentation)) 99 + # (Also filter out the L1 entry, because why not) 100 + _check_test_img -r all --output=json \ 101 + | sed -e 's/^ \(.*\)-fixed"/\1-fixed"/' \ 102 + -e '/^ /d' \ 103 + -e "s/\\([^0-9a-f]\\)$(printf %x $l1_entry)\\([^0-9a-f]\\)/\1L1_ENTRY_VALUE\2/" 67 104 68 105 # success, all done 69 106 echo "*** done"
+14
tests/qemu-iotests/138.out
··· 9 9 10 10 1 errors were found on the image. 11 11 Data may be corrupted, or further writes to the image may corrupt it. 12 + 13 + === Check leaks-fixed/corruptions-fixed report 14 + 15 + Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=65536 16 + wrote 65536/65536 bytes at offset 0 17 + 64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) 18 + 19 + Leaked cluster 0 refcount=2 reference=1 20 + Repairing cluster 0 refcount=2 reference=1 21 + Repairing OFLAG_COPIED L2 cluster: l1_index=0 l1_entry=L1_ENTRY_VALUE refcount=1 22 + { 23 + "corruptions-fixed": 1, 24 + "leaks-fixed": 1, 25 + } 12 26 *** done