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

iotests: Repairing error during snapshot deletion

This adds a test for an I/O error during snapshot deletion, and maybe
more importantly, for how to repair the resulting image. If the
snapshot has been deleted before the error occurs, the only negative
result will be leaked clusters -- and those should be repairable with
qemu-img check -r leaks.

Signed-off-by: Max Reitz <mreitz@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-id: 20180509200059.31125-3-mreitz@redhat.com
Signed-off-by: Max Reitz <mreitz@redhat.com>

+133
+90
tests/qemu-iotests/217
··· 1 + #!/bin/bash 2 + # 3 + # I/O errors when working with internal qcow2 snapshots, and repairing 4 + # the result 5 + # 6 + # Copyright (C) 2018 Red Hat, Inc. 7 + # 8 + # This program is free software; you can redistribute it and/or modify 9 + # it under the terms of the GNU General Public License as published by 10 + # the Free Software Foundation; either version 2 of the License, or 11 + # (at your option) any later version. 12 + # 13 + # This program is distributed in the hope that it will be useful, 14 + # but WITHOUT ANY WARRANTY; without even the implied warranty of 15 + # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 + # GNU General Public License for more details. 17 + # 18 + # You should have received a copy of the GNU General Public License 19 + # along with this program. If not, see <http://www.gnu.org/licenses/>. 20 + 21 + seq=$(basename $0) 22 + echo "QA output created by $seq" 23 + 24 + status=1 # failure is the default! 25 + 26 + _cleanup() 27 + { 28 + _cleanup_test_img 29 + rm -f "$TEST_DIR/blkdebug.conf" 30 + } 31 + trap "_cleanup; exit \$status" 0 1 2 3 15 32 + 33 + # get standard environment, filters and checks 34 + . ./common.rc 35 + . ./common.filter 36 + 37 + # This test is specific to qcow2 38 + _supported_fmt qcow2 39 + _supported_proto file 40 + _supported_os Linux 41 + 42 + # This test needs clusters with at least a refcount of 2 so that 43 + # OFLAG_COPIED is not set. refcount_bits=1 is therefore unsupported. 44 + _unsupported_imgopts 'refcount_bits=1[^0-9]' 45 + 46 + echo 47 + echo '=== Simulating an I/O error during snapshot deletion ===' 48 + echo 49 + 50 + _make_test_img 64M 51 + $QEMU_IO -c 'write 0 64k' "$TEST_IMG" | _filter_qemu_io 52 + 53 + # Create the snapshot 54 + $QEMU_IMG snapshot -c foo "$TEST_IMG" 55 + 56 + # Verify the snapshot is there 57 + echo 58 + _img_info | grep 'Snapshot list' 59 + echo '(Snapshot filtered)' 60 + echo 61 + 62 + # Try to delete the snapshot (with an error happening when freeing the 63 + # then leaked clusters) 64 + cat > "$TEST_DIR/blkdebug.conf" <<EOF 65 + [inject-error] 66 + event = "cluster_free" 67 + errno = "5" 68 + EOF 69 + $QEMU_IMG snapshot -d foo "blkdebug:$TEST_DIR/blkdebug.conf:$TEST_IMG" 70 + 71 + # Verify the snapshot is gone 72 + echo 73 + _img_info | grep 'Snapshot list' 74 + 75 + # Should only show leaks 76 + echo '--- Checking test image ---' 77 + _check_test_img 78 + 79 + echo 80 + 81 + # As there are only leaks, this should be able to fully repair the 82 + # image 83 + echo '--- Repairing test image ---' 84 + _check_test_img -r leaks 85 + 86 + 87 + # success, all done 88 + echo '*** done' 89 + rm -f $seq.full 90 + status=0
+42
tests/qemu-iotests/217.out
··· 1 + QA output created by 217 2 + 3 + === Simulating an I/O error during snapshot deletion === 4 + 5 + Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864 6 + wrote 65536/65536 bytes at offset 0 7 + 64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) 8 + 9 + Snapshot list: 10 + (Snapshot filtered) 11 + 12 + qcow2_free_clusters failed: Input/output error 13 + qemu-img: Could not delete snapshot 'foo': Failed to free the cluster and L1 table: Input/output error 14 + 15 + --- Checking test image --- 16 + Leaked cluster 4 refcount=2 reference=1 17 + Leaked cluster 5 refcount=2 reference=1 18 + Leaked cluster 6 refcount=1 reference=0 19 + Leaked cluster 7 refcount=1 reference=0 20 + 21 + 4 leaked clusters were found on the image. 22 + This means waste of disk space, but no harm to data. 23 + 24 + --- Repairing test image --- 25 + Leaked cluster 4 refcount=2 reference=1 26 + Leaked cluster 5 refcount=2 reference=1 27 + Leaked cluster 6 refcount=1 reference=0 28 + Leaked cluster 7 refcount=1 reference=0 29 + Repairing cluster 4 refcount=2 reference=1 30 + Repairing cluster 5 refcount=2 reference=1 31 + Repairing cluster 6 refcount=1 reference=0 32 + Repairing cluster 7 refcount=1 reference=0 33 + Repairing OFLAG_COPIED L2 cluster: l1_index=0 l1_entry=40000 refcount=1 34 + Repairing OFLAG_COPIED data cluster: l2_entry=50000 refcount=1 35 + The following inconsistencies were found and repaired: 36 + 37 + 4 leaked clusters 38 + 2 corruptions 39 + 40 + Double checking the fixed image now... 41 + No errors were found on the image. 42 + *** done
+1
tests/qemu-iotests/group
··· 215 215 214 rw auto 216 216 215 rw auto quick 217 217 216 rw auto quick 218 + 217 rw auto quick 218 219 218 rw auto quick 219 220 219 rw auto