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

iotests: Test qemu-img convert --salvage

This test converts a simple image to another, but blkdebug injects
block_status and read faults at some offsets. The resulting image
should be the same as the input image, except that sectors that could
not be read have to be 0.

Signed-off-by: Max Reitz <mreitz@redhat.com>
Message-id: 20190507203508.18026-7-mreitz@redhat.com
Tested-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
[mreitz: Dropped superfluous printf from _filter_offsets, as suggested
by Vladimir; disable test for VDI and IMGOPTSSYNTAX]
Signed-off-by: Max Reitz <mreitz@redhat.com>

+214
+170
tests/qemu-iotests/251
··· 1 + #!/usr/bin/env bash 2 + # 3 + # Test qemu-img convert --salvage 4 + # 5 + # Copyright (C) 2019 Red Hat, Inc. 6 + # 7 + # This program is free software; you can redistribute it and/or modify 8 + # it under the terms of the GNU General Public License as published by 9 + # the Free Software Foundation; either version 2 of the License, or 10 + # (at your option) any later version. 11 + # 12 + # This program is distributed in the hope that it will be useful, 13 + # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 + # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 + # GNU General Public License for more details. 16 + # 17 + # You should have received a copy of the GNU General Public License 18 + # along with this program. If not, see <http://www.gnu.org/licenses/>. 19 + # 20 + 21 + # creator 22 + owner=mreitz@redhat.com 23 + 24 + seq=$(basename $0) 25 + echo "QA output created by $seq" 26 + 27 + status=1 # failure is the default! 28 + 29 + _cleanup() 30 + { 31 + _cleanup_test_img 32 + } 33 + trap "_cleanup; exit \$status" 0 1 2 3 15 34 + 35 + # get standard environment, filters and checks 36 + . ./common.rc 37 + . ./common.filter 38 + . ./common.qemu 39 + 40 + _supported_fmt generic 41 + _supported_proto file 42 + _supported_os Linux 43 + 44 + if [ "$IMGOPTSSYNTAX" = "true" ]; then 45 + # We use json:{} filenames here, so we cannot work with additional options. 46 + _unsupported_fmt $IMGFMT 47 + else 48 + # With VDI, the output is ordered differently. Just disable it. 49 + _unsupported_fmt vdi 50 + fi 51 + 52 + 53 + TEST_IMG="$TEST_IMG.orig" _make_test_img 64M 54 + 55 + $QEMU_IO -c 'write -P 42 0 64M' "$TEST_IMG.orig" | _filter_qemu_io 56 + 57 + 58 + sector_size=512 59 + 60 + # Offsets on which to fail block-status. Keep in ascending order so 61 + # the indexing done by _filter_offsets will appear in ascending order 62 + # in the output as well. 63 + status_fail_offsets="$((16 * 1024 * 1024 + 8192)) 64 + $((33 * 1024 * 1024 + 512))" 65 + 66 + # Offsets on which to fail reads. Keep in ascending order for the 67 + # same reason. 68 + # The second element is shared with $status_fail_offsets on purpose. 69 + # Starting with the third element, we test what happens when a 70 + # continuous range of sectors is inaccessible. 71 + read_fail_offsets="$((32 * 1024 * 1024 - 65536)) 72 + $((33 * 1024 * 1024 + 512)) 73 + $(seq $((34 * 1024 * 1024)) $sector_size \ 74 + $((34 * 1024 * 1024 + 4096 - $sector_size)))" 75 + 76 + 77 + # blkdebug must be above the format layer so it can intercept all 78 + # block-status events 79 + source_img="json:{'driver': 'blkdebug', 80 + 'image': { 81 + 'driver': '$IMGFMT', 82 + 'file': { 83 + 'driver': 'file', 84 + 'filename': '$TEST_IMG.orig' 85 + } 86 + }, 87 + 'inject-error': [" 88 + 89 + for ofs in $status_fail_offsets 90 + do 91 + source_img+="{ 'event': 'none', 92 + 'iotype': 'block-status', 93 + 'errno': 5, 94 + 'sector': $((ofs / sector_size)) }," 95 + done 96 + 97 + for ofs in $read_fail_offsets 98 + do 99 + source_img+="{ 'event': 'none', 100 + 'iotype': 'read', 101 + 'errno': 5, 102 + 'sector': $((ofs / sector_size)) }," 103 + done 104 + 105 + # Remove the trailing comma and terminate @inject-error and json:{} 106 + source_img="${source_img%,} ] }" 107 + 108 + 109 + echo 110 + 111 + 112 + _filter_offsets() { 113 + filters= 114 + 115 + index=0 116 + for ofs in $1 117 + do 118 + filters+=" -e s/$ofs/status_fail_offset_$index/" 119 + index=$((index + 1)) 120 + done 121 + 122 + index=0 123 + for ofs in $2 124 + do 125 + filters+=" -e s/$ofs/read_fail_offset_$index/" 126 + index=$((index + 1)) 127 + done 128 + 129 + sed $filters 130 + } 131 + 132 + # While determining the number of allocated sectors in the input 133 + # image, we should see one block status warning per element of 134 + # $status_fail_offsets. 135 + # 136 + # Then, the image is read. Since the block status is queried in 137 + # basically the same way, the same warnings as in the previous step 138 + # should reappear. Interleaved with those we should see a read 139 + # warning per element of $read_fail_offsets. 140 + # Note that $read_fail_offsets and $status_fail_offsets share an 141 + # element (read_fail_offset_1 == status_fail_offset_1), so 142 + # "status_fail_offset_1" in the output is the same as 143 + # "read_fail_offset_1". 144 + $QEMU_IMG convert --salvage "$source_img" "$TEST_IMG" 2>&1 \ 145 + | _filter_offsets "$status_fail_offsets" "$read_fail_offsets" 146 + 147 + echo 148 + 149 + # The offsets where the block status could not be determined should 150 + # have been treated as containing data and thus should be correct in 151 + # the output image. 152 + # The offsets where reading failed altogether should be 0. Make them 153 + # 0 in the input image, too, so we can compare both images. 154 + for ofs in $read_fail_offsets 155 + do 156 + $QEMU_IO -c "write -z $ofs $sector_size" "$TEST_IMG.orig" \ 157 + | _filter_qemu_io \ 158 + | _filter_offsets '' "$read_fail_offsets" 159 + done 160 + 161 + echo 162 + 163 + # These should be equal now. 164 + $QEMU_IMG compare "$TEST_IMG.orig" "$TEST_IMG" 165 + 166 + 167 + # success, all done 168 + echo "*** done" 169 + rm -f $seq.full 170 + status=0
+43
tests/qemu-iotests/251.out
··· 1 + QA output created by 251 2 + Formatting 'TEST_DIR/t.IMGFMT.orig', fmt=IMGFMT size=67108864 3 + wrote 67108864/67108864 bytes at offset 0 4 + 64 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) 5 + 6 + qemu-img: warning: error while reading block status at offset status_fail_offset_0: Input/output error 7 + qemu-img: warning: error while reading block status at offset status_fail_offset_1: Input/output error 8 + qemu-img: warning: error while reading block status at offset status_fail_offset_0: Input/output error 9 + qemu-img: warning: error while reading offset read_fail_offset_0: Input/output error 10 + qemu-img: warning: error while reading block status at offset status_fail_offset_1: Input/output error 11 + qemu-img: warning: error while reading offset status_fail_offset_1: Input/output error 12 + qemu-img: warning: error while reading offset read_fail_offset_2: Input/output error 13 + qemu-img: warning: error while reading offset read_fail_offset_3: Input/output error 14 + qemu-img: warning: error while reading offset read_fail_offset_4: Input/output error 15 + qemu-img: warning: error while reading offset read_fail_offset_5: Input/output error 16 + qemu-img: warning: error while reading offset read_fail_offset_6: Input/output error 17 + qemu-img: warning: error while reading offset read_fail_offset_7: Input/output error 18 + qemu-img: warning: error while reading offset read_fail_offset_8: Input/output error 19 + qemu-img: warning: error while reading offset read_fail_offset_9: Input/output error 20 + 21 + wrote 512/512 bytes at offset read_fail_offset_0 22 + 512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) 23 + wrote 512/512 bytes at offset read_fail_offset_1 24 + 512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) 25 + wrote 512/512 bytes at offset read_fail_offset_2 26 + 512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) 27 + wrote 512/512 bytes at offset read_fail_offset_3 28 + 512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) 29 + wrote 512/512 bytes at offset read_fail_offset_4 30 + 512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) 31 + wrote 512/512 bytes at offset read_fail_offset_5 32 + 512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) 33 + wrote 512/512 bytes at offset read_fail_offset_6 34 + 512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) 35 + wrote 512/512 bytes at offset read_fail_offset_7 36 + 512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) 37 + wrote 512/512 bytes at offset read_fail_offset_8 38 + 512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) 39 + wrote 512/512 bytes at offset read_fail_offset_9 40 + 512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) 41 + 42 + Images are identical. 43 + *** done
+1
tests/qemu-iotests/group
··· 263 263 248 rw quick 264 264 249 rw auto quick 265 265 250 rw auto quick 266 + 251 rw auto quick 266 267 252 rw auto backing quick 267 268 253 rw auto quick 268 269 254 rw auto backing quick