| 1 | #!/usr/bin/env bash |
| 2 | # group: rw auto quick |
| 3 | # |
| 4 | # I/O errors when working with internal qcow2 snapshots, and repairing |
| 5 | # the result |
| 6 | # |
| 7 | # Copyright (C) 2018 Red Hat, Inc. |
| 8 | # |
| 9 | # This program is free software; you can redistribute it and/or modify |
| 10 | # it under the terms of the GNU General Public License as published by |
| 11 | # the Free Software Foundation; either version 2 of the License, or |
| 12 | # (at your option) any later version. |
| 13 | # |
| 14 | # This program is distributed in the hope that it will be useful, |
| 15 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | # GNU General Public License for more details. |
| 18 | # |
| 19 | # You should have received a copy of the GNU General Public License |
| 20 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 21 | |
| 22 | seq=$(basename $0) |
| 23 | echo "QA output created by $seq" |
| 24 | |
| 25 | status=1 # failure is the default! |
| 26 | |
| 27 | _cleanup() |
| 28 | { |
| 29 | _cleanup_test_img |
| 30 | rm -f "$TEST_DIR/blkdebug.conf" |
| 31 | } |
| 32 | trap "_cleanup; exit \$status" 0 1 2 3 15 |
| 33 | |
| 34 | # get standard environment, filters and checks |
| 35 | . ./common.rc |
| 36 | . ./common.filter |
| 37 | |
| 38 | # This test is specific to qcow2 |
| 39 | _supported_fmt qcow2 |
| 40 | _supported_proto file fuse |
| 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 | # (As are external data files.) |
| 45 | _unsupported_imgopts 'refcount_bits=1[^0-9]' data_file |
| 46 | |
| 47 | echo |
| 48 | echo '=== Simulating an I/O error during snapshot deletion ===' |
| 49 | echo |
| 50 | |
| 51 | _make_test_img 64M |
| 52 | $QEMU_IO -c 'write 0 64k' "$TEST_IMG" | _filter_qemu_io |
| 53 | |
| 54 | # Create the snapshot |
| 55 | $QEMU_IMG snapshot -c foo "$TEST_IMG" |
| 56 | |
| 57 | # Verify the snapshot is there |
| 58 | echo |
| 59 | _img_info | grep 'Snapshot list' |
| 60 | echo '(Snapshot filtered)' |
| 61 | echo |
| 62 | |
| 63 | # Try to delete the snapshot (with an error happening when freeing the |
| 64 | # then leaked clusters) |
| 65 | cat > "$TEST_DIR/blkdebug.conf" <<EOF |
| 66 | [inject-error] |
| 67 | event = "cluster_free" |
| 68 | errno = "5" |
| 69 | EOF |
| 70 | $QEMU_IMG snapshot -d foo "blkdebug:$TEST_DIR/blkdebug.conf:$TEST_IMG" |
| 71 | |
| 72 | # Verify the snapshot is gone |
| 73 | echo |
| 74 | _img_info | grep 'Snapshot list' |
| 75 | |
| 76 | # Should only show leaks |
| 77 | echo '--- Checking test image ---' |
| 78 | _check_test_img |
| 79 | |
| 80 | echo |
| 81 | |
| 82 | # As there are only leaks, this should be able to fully repair the |
| 83 | # image |
| 84 | echo '--- Repairing test image ---' |
| 85 | _check_test_img -r leaks |
| 86 | |
| 87 | |
| 88 | # success, all done |
| 89 | echo '*** done' |
| 90 | rm -f $seq.full |
| 91 | status=0 |