| 1 | #!/usr/bin/env bash |
| 2 | # group: rw auto quick |
| 3 | # |
| 4 | # Test qcow2 lazy refcounts |
| 5 | # |
| 6 | # Copyright (C) 2012 Red Hat, Inc. |
| 7 | # Copyright IBM, Corp. 2010 |
| 8 | # |
| 9 | # Based on test 038. |
| 10 | # |
| 11 | # This program is free software; you can redistribute it and/or modify |
| 12 | # it under the terms of the GNU General Public License as published by |
| 13 | # the Free Software Foundation; either version 2 of the License, or |
| 14 | # (at your option) any later version. |
| 15 | # |
| 16 | # This program is distributed in the hope that it will be useful, |
| 17 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 19 | # GNU General Public License for more details. |
| 20 | # |
| 21 | # You should have received a copy of the GNU General Public License |
| 22 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 23 | # |
| 24 | |
| 25 | # creator |
| 26 | owner=stefanha@redhat.com |
| 27 | |
| 28 | seq=`basename $0` |
| 29 | echo "QA output created by $seq" |
| 30 | |
| 31 | status=1 # failure is the default! |
| 32 | |
| 33 | _cleanup() |
| 34 | { |
| 35 | _cleanup_test_img |
| 36 | } |
| 37 | trap "_cleanup; exit \$status" 0 1 2 3 15 |
| 38 | |
| 39 | # get standard environment, filters and checks |
| 40 | . ./common.rc |
| 41 | . ./common.filter |
| 42 | |
| 43 | _supported_fmt qcow2 |
| 44 | _supported_proto file fuse |
| 45 | _supported_os Linux |
| 46 | _default_cache_mode writethrough |
| 47 | _supported_cache_modes writethrough |
| 48 | # Some of these test cases expect no external data file so that all |
| 49 | # clusters are part of the qcow2 image and refcounted |
| 50 | _unsupported_imgopts data_file |
| 51 | |
| 52 | size=128M |
| 53 | |
| 54 | echo |
| 55 | echo "== Checking that image is clean on shutdown ==" |
| 56 | |
| 57 | _make_test_img -o "compat=1.1,lazy_refcounts=on" $size |
| 58 | |
| 59 | $QEMU_IO -c "write -P 0x5a 0 512" "$TEST_IMG" | _filter_qemu_io |
| 60 | |
| 61 | # The dirty bit must not be set |
| 62 | _qcow2_dump_header | grep incompatible_features |
| 63 | _check_test_img |
| 64 | |
| 65 | echo |
| 66 | echo "== Creating a dirty image file ==" |
| 67 | |
| 68 | _make_test_img -o "compat=1.1,lazy_refcounts=on" $size |
| 69 | |
| 70 | _NO_VALGRIND \ |
| 71 | $QEMU_IO -c "write -P 0x5a 0 512" \ |
| 72 | -c "sigraise $(kill -l KILL)" "$TEST_IMG" 2>&1 \ |
| 73 | | _filter_qemu_io |
| 74 | |
| 75 | # The dirty bit must be set |
| 76 | _qcow2_dump_header | grep incompatible_features |
| 77 | _check_test_img |
| 78 | |
| 79 | echo |
| 80 | echo "== Read-only access must still work ==" |
| 81 | |
| 82 | $QEMU_IO -r -c "read -P 0x5a 0 512" "$TEST_IMG" | _filter_qemu_io |
| 83 | |
| 84 | # The dirty bit must be set |
| 85 | _qcow2_dump_header | grep incompatible_features |
| 86 | |
| 87 | echo |
| 88 | echo "== Read-only open must not crash on close ==" |
| 89 | |
| 90 | # We must not try to write the QCOW2 header to a read-only image. |
| 91 | $QEMU_IMG info --image-opts \ |
| 92 | "driver=$IMGFMT,read-only=on,file.driver=file,file.filename=$TEST_IMG,file.read-only=off" \ |
| 93 | > /dev/null |
| 94 | |
| 95 | # The dirty bit must still be set: this open never wrote any guest data |
| 96 | _qcow2_dump_header | grep incompatible_features |
| 97 | |
| 98 | echo |
| 99 | echo "== Repairing the image file must succeed ==" |
| 100 | |
| 101 | _check_test_img -r all |
| 102 | |
| 103 | # The dirty bit must not be set |
| 104 | _qcow2_dump_header | grep incompatible_features |
| 105 | |
| 106 | echo |
| 107 | echo "== Data should still be accessible after repair ==" |
| 108 | |
| 109 | $QEMU_IO -c "read -P 0x5a 0 512" "$TEST_IMG" | _filter_qemu_io |
| 110 | |
| 111 | echo |
| 112 | echo "== Opening a dirty image read/write should repair it ==" |
| 113 | |
| 114 | _make_test_img -o "compat=1.1,lazy_refcounts=on" $size |
| 115 | |
| 116 | _NO_VALGRIND \ |
| 117 | $QEMU_IO -c "write -P 0x5a 0 512" \ |
| 118 | -c "sigraise $(kill -l KILL)" "$TEST_IMG" 2>&1 \ |
| 119 | | _filter_qemu_io |
| 120 | |
| 121 | # The dirty bit must be set |
| 122 | _qcow2_dump_header | grep incompatible_features |
| 123 | |
| 124 | $QEMU_IO -c "write 0 512" "$TEST_IMG" | _filter_qemu_io |
| 125 | |
| 126 | # The dirty bit must not be set |
| 127 | _qcow2_dump_header | grep incompatible_features |
| 128 | |
| 129 | echo |
| 130 | echo "== Creating an image file with lazy_refcounts=off ==" |
| 131 | |
| 132 | _make_test_img -o "compat=1.1,lazy_refcounts=off" $size |
| 133 | |
| 134 | _NO_VALGRIND \ |
| 135 | $QEMU_IO -c "write -P 0x5a 0 512" \ |
| 136 | -c "sigraise $(kill -l KILL)" "$TEST_IMG" 2>&1 \ |
| 137 | | _filter_qemu_io |
| 138 | |
| 139 | # The dirty bit must not be set since lazy_refcounts=off |
| 140 | _qcow2_dump_header | grep incompatible_features |
| 141 | _check_test_img |
| 142 | |
| 143 | echo |
| 144 | echo "== Committing to a backing file with lazy_refcounts=on ==" |
| 145 | |
| 146 | TEST_IMG="$TEST_IMG".base _make_test_img -o "compat=1.1,lazy_refcounts=on" $size |
| 147 | |
| 148 | _make_test_img -o "compat=1.1,lazy_refcounts=on,backing_file=$TEST_IMG.base" \ |
| 149 | -F $IMGFMT $size |
| 150 | |
| 151 | $QEMU_IO -c "write 0 512" "$TEST_IMG" | _filter_qemu_io |
| 152 | $QEMU_IMG commit "$TEST_IMG" |
| 153 | |
| 154 | # The dirty bit must not be set |
| 155 | _qcow2_dump_header | grep incompatible_features |
| 156 | _qcow2_dump_header "$TEST_IMG".base | grep incompatible_features |
| 157 | |
| 158 | _check_test_img |
| 159 | TEST_IMG="$TEST_IMG".base _check_test_img |
| 160 | |
| 161 | echo |
| 162 | echo "== Changing lazy_refcounts setting at runtime ==" |
| 163 | |
| 164 | _make_test_img -o "compat=1.1,lazy_refcounts=off" $size |
| 165 | |
| 166 | _NO_VALGRIND \ |
| 167 | $QEMU_IO -c "reopen -o lazy-refcounts=on" \ |
| 168 | -c "write -P 0x5a 0 512" \ |
| 169 | -c "sigraise $(kill -l KILL)" "$TEST_IMG" 2>&1 \ |
| 170 | | _filter_qemu_io |
| 171 | |
| 172 | # The dirty bit must be set |
| 173 | _qcow2_dump_header | grep incompatible_features |
| 174 | _check_test_img |
| 175 | |
| 176 | _make_test_img -o "compat=1.1,lazy_refcounts=on" $size |
| 177 | |
| 178 | _NO_VALGRIND \ |
| 179 | $QEMU_IO -c "reopen -o lazy-refcounts=off" \ |
| 180 | -c "write -P 0x5a 0 512" \ |
| 181 | -c "sigraise $(kill -l KILL)" "$TEST_IMG" 2>&1 \ |
| 182 | | _filter_qemu_io |
| 183 | |
| 184 | # The dirty bit must not be set |
| 185 | _qcow2_dump_header | grep incompatible_features |
| 186 | _check_test_img |
| 187 | |
| 188 | |
| 189 | # success, all done |
| 190 | echo "*** done" |
| 191 | rm -f $seq.full |
| 192 | status=0 |
| 193 |