Philippe Mathieu-Daudé | 11a82d1 | 2019-03-07 15:58:38 +0100 | [diff] [blame] | 1 | #!/usr/bin/env bash |
Vladimir Sementsov-Ogievskiy | 9dd003a | 2021-01-16 16:44:19 +0300 | [diff] [blame] | 2 | # group: rw auto quick |
Stefan Hajnoczi | dc68afe | 2012-07-27 09:05:24 +0100 | [diff] [blame] | 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 |
John Snow | 42a5009 | 2022-03-22 13:42:12 -0400 | [diff] [blame] | 26 | owner=stefanha@redhat.com |
Stefan Hajnoczi | dc68afe | 2012-07-27 09:05:24 +0100 | [diff] [blame] | 27 | |
| 28 | seq=`basename $0` |
| 29 | echo "QA output created by $seq" |
| 30 | |
Stefan Hajnoczi | dc68afe | 2012-07-27 09:05:24 +0100 | [diff] [blame] | 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 |
Max Reitz | 57284d2 | 2020-10-27 20:05:59 +0100 | [diff] [blame] | 44 | _supported_proto file fuse |
Stefan Hajnoczi | dc68afe | 2012-07-27 09:05:24 +0100 | [diff] [blame] | 45 | _supported_os Linux |
Nir Soffer | 755c5fe | 2019-08-27 20:34:32 +0300 | [diff] [blame] | 46 | _default_cache_mode writethrough |
| 47 | _supported_cache_modes writethrough |
Max Reitz | 3be2024 | 2019-11-07 17:37:07 +0100 | [diff] [blame] | 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 |
Stefan Hajnoczi | dc68afe | 2012-07-27 09:05:24 +0100 | [diff] [blame] | 51 | |
| 52 | size=128M |
| 53 | |
| 54 | echo |
| 55 | echo "== Checking that image is clean on shutdown ==" |
| 56 | |
Max Reitz | 407fb56 | 2019-11-07 17:36:57 +0100 | [diff] [blame] | 57 | _make_test_img -o "compat=1.1,lazy_refcounts=on" $size |
Stefan Hajnoczi | dc68afe | 2012-07-27 09:05:24 +0100 | [diff] [blame] | 58 | |
Jeff Cody | f897e39 | 2013-10-31 11:57:40 -0400 | [diff] [blame] | 59 | $QEMU_IO -c "write -P 0x5a 0 512" "$TEST_IMG" | _filter_qemu_io |
Stefan Hajnoczi | dc68afe | 2012-07-27 09:05:24 +0100 | [diff] [blame] | 60 | |
| 61 | # The dirty bit must not be set |
Vladimir Sementsov-Ogievskiy | 984d7a5 | 2021-12-23 17:01:39 +0100 | [diff] [blame] | 62 | _qcow2_dump_header | grep incompatible_features |
Stefan Hajnoczi | dc68afe | 2012-07-27 09:05:24 +0100 | [diff] [blame] | 63 | _check_test_img |
| 64 | |
| 65 | echo |
| 66 | echo "== Creating a dirty image file ==" |
| 67 | |
Max Reitz | 407fb56 | 2019-11-07 17:36:57 +0100 | [diff] [blame] | 68 | _make_test_img -o "compat=1.1,lazy_refcounts=on" $size |
Stefan Hajnoczi | dc68afe | 2012-07-27 09:05:24 +0100 | [diff] [blame] | 69 | |
Andrey Shinkevich | 8af224d | 2019-09-04 12:11:20 +0300 | [diff] [blame] | 70 | _NO_VALGRIND \ |
Max Reitz | 934659c | 2015-09-02 20:52:27 +0200 | [diff] [blame] | 71 | $QEMU_IO -c "write -P 0x5a 0 512" \ |
| 72 | -c "sigraise $(kill -l KILL)" "$TEST_IMG" 2>&1 \ |
Max Reitz | 3f39447 | 2014-12-08 10:48:12 +0100 | [diff] [blame] | 73 | | _filter_qemu_io |
Stefan Hajnoczi | dc68afe | 2012-07-27 09:05:24 +0100 | [diff] [blame] | 74 | |
| 75 | # The dirty bit must be set |
Vladimir Sementsov-Ogievskiy | 984d7a5 | 2021-12-23 17:01:39 +0100 | [diff] [blame] | 76 | _qcow2_dump_header | grep incompatible_features |
Stefan Hajnoczi | dc68afe | 2012-07-27 09:05:24 +0100 | [diff] [blame] | 77 | _check_test_img |
| 78 | |
| 79 | echo |
| 80 | echo "== Read-only access must still work ==" |
| 81 | |
Jeff Cody | fef9c19 | 2013-09-25 08:12:22 -0400 | [diff] [blame] | 82 | $QEMU_IO -r -c "read -P 0x5a 0 512" "$TEST_IMG" | _filter_qemu_io |
Stefan Hajnoczi | dc68afe | 2012-07-27 09:05:24 +0100 | [diff] [blame] | 83 | |
| 84 | # The dirty bit must be set |
Vladimir Sementsov-Ogievskiy | 984d7a5 | 2021-12-23 17:01:39 +0100 | [diff] [blame] | 85 | _qcow2_dump_header | grep incompatible_features |
Stefan Hajnoczi | dc68afe | 2012-07-27 09:05:24 +0100 | [diff] [blame] | 86 | |
| 87 | echo |
| 88 | echo "== Repairing the image file must succeed ==" |
| 89 | |
Federico Simoncelli | c6bb9ad | 2013-01-28 06:59:46 -0500 | [diff] [blame] | 90 | _check_test_img -r all |
Stefan Hajnoczi | dc68afe | 2012-07-27 09:05:24 +0100 | [diff] [blame] | 91 | |
| 92 | # The dirty bit must not be set |
Vladimir Sementsov-Ogievskiy | 984d7a5 | 2021-12-23 17:01:39 +0100 | [diff] [blame] | 93 | _qcow2_dump_header | grep incompatible_features |
Stefan Hajnoczi | dc68afe | 2012-07-27 09:05:24 +0100 | [diff] [blame] | 94 | |
| 95 | echo |
| 96 | echo "== Data should still be accessible after repair ==" |
| 97 | |
Jeff Cody | fef9c19 | 2013-09-25 08:12:22 -0400 | [diff] [blame] | 98 | $QEMU_IO -c "read -P 0x5a 0 512" "$TEST_IMG" | _filter_qemu_io |
Stefan Hajnoczi | dc68afe | 2012-07-27 09:05:24 +0100 | [diff] [blame] | 99 | |
| 100 | echo |
| 101 | echo "== Opening a dirty image read/write should repair it ==" |
| 102 | |
Max Reitz | 407fb56 | 2019-11-07 17:36:57 +0100 | [diff] [blame] | 103 | _make_test_img -o "compat=1.1,lazy_refcounts=on" $size |
Stefan Hajnoczi | dc68afe | 2012-07-27 09:05:24 +0100 | [diff] [blame] | 104 | |
Andrey Shinkevich | 8af224d | 2019-09-04 12:11:20 +0300 | [diff] [blame] | 105 | _NO_VALGRIND \ |
Max Reitz | 934659c | 2015-09-02 20:52:27 +0200 | [diff] [blame] | 106 | $QEMU_IO -c "write -P 0x5a 0 512" \ |
| 107 | -c "sigraise $(kill -l KILL)" "$TEST_IMG" 2>&1 \ |
Max Reitz | 3f39447 | 2014-12-08 10:48:12 +0100 | [diff] [blame] | 108 | | _filter_qemu_io |
Stefan Hajnoczi | dc68afe | 2012-07-27 09:05:24 +0100 | [diff] [blame] | 109 | |
| 110 | # The dirty bit must be set |
Vladimir Sementsov-Ogievskiy | 984d7a5 | 2021-12-23 17:01:39 +0100 | [diff] [blame] | 111 | _qcow2_dump_header | grep incompatible_features |
Stefan Hajnoczi | dc68afe | 2012-07-27 09:05:24 +0100 | [diff] [blame] | 112 | |
Jeff Cody | fef9c19 | 2013-09-25 08:12:22 -0400 | [diff] [blame] | 113 | $QEMU_IO -c "write 0 512" "$TEST_IMG" | _filter_qemu_io |
Stefan Hajnoczi | dc68afe | 2012-07-27 09:05:24 +0100 | [diff] [blame] | 114 | |
| 115 | # The dirty bit must not be set |
Vladimir Sementsov-Ogievskiy | 984d7a5 | 2021-12-23 17:01:39 +0100 | [diff] [blame] | 116 | _qcow2_dump_header | grep incompatible_features |
Stefan Hajnoczi | dc68afe | 2012-07-27 09:05:24 +0100 | [diff] [blame] | 117 | |
| 118 | echo |
| 119 | echo "== Creating an image file with lazy_refcounts=off ==" |
| 120 | |
Max Reitz | 407fb56 | 2019-11-07 17:36:57 +0100 | [diff] [blame] | 121 | _make_test_img -o "compat=1.1,lazy_refcounts=off" $size |
Stefan Hajnoczi | dc68afe | 2012-07-27 09:05:24 +0100 | [diff] [blame] | 122 | |
Andrey Shinkevich | 8af224d | 2019-09-04 12:11:20 +0300 | [diff] [blame] | 123 | _NO_VALGRIND \ |
Max Reitz | 934659c | 2015-09-02 20:52:27 +0200 | [diff] [blame] | 124 | $QEMU_IO -c "write -P 0x5a 0 512" \ |
| 125 | -c "sigraise $(kill -l KILL)" "$TEST_IMG" 2>&1 \ |
Max Reitz | 3f39447 | 2014-12-08 10:48:12 +0100 | [diff] [blame] | 126 | | _filter_qemu_io |
Stefan Hajnoczi | dc68afe | 2012-07-27 09:05:24 +0100 | [diff] [blame] | 127 | |
| 128 | # The dirty bit must not be set since lazy_refcounts=off |
Vladimir Sementsov-Ogievskiy | 984d7a5 | 2021-12-23 17:01:39 +0100 | [diff] [blame] | 129 | _qcow2_dump_header | grep incompatible_features |
Stefan Hajnoczi | dc68afe | 2012-07-27 09:05:24 +0100 | [diff] [blame] | 130 | _check_test_img |
| 131 | |
Kevin Wolf | 4c2e5f8 | 2014-04-03 13:47:50 +0200 | [diff] [blame] | 132 | echo |
| 133 | echo "== Committing to a backing file with lazy_refcounts=on ==" |
| 134 | |
Max Reitz | 407fb56 | 2019-11-07 17:36:57 +0100 | [diff] [blame] | 135 | TEST_IMG="$TEST_IMG".base _make_test_img -o "compat=1.1,lazy_refcounts=on" $size |
Kevin Wolf | 4c2e5f8 | 2014-04-03 13:47:50 +0200 | [diff] [blame] | 136 | |
Eric Blake | b66ff2c | 2020-07-06 15:39:52 -0500 | [diff] [blame] | 137 | _make_test_img -o "compat=1.1,lazy_refcounts=on,backing_file=$TEST_IMG.base" \ |
| 138 | -F $IMGFMT $size |
Kevin Wolf | 4c2e5f8 | 2014-04-03 13:47:50 +0200 | [diff] [blame] | 139 | |
| 140 | $QEMU_IO -c "write 0 512" "$TEST_IMG" | _filter_qemu_io |
| 141 | $QEMU_IMG commit "$TEST_IMG" |
| 142 | |
| 143 | # The dirty bit must not be set |
Vladimir Sementsov-Ogievskiy | 984d7a5 | 2021-12-23 17:01:39 +0100 | [diff] [blame] | 144 | _qcow2_dump_header | grep incompatible_features |
Vladimir Sementsov-Ogievskiy | 72be51d | 2021-12-23 17:01:40 +0100 | [diff] [blame] | 145 | _qcow2_dump_header "$TEST_IMG".base | grep incompatible_features |
Kevin Wolf | 4c2e5f8 | 2014-04-03 13:47:50 +0200 | [diff] [blame] | 146 | |
| 147 | _check_test_img |
| 148 | TEST_IMG="$TEST_IMG".base _check_test_img |
| 149 | |
Kevin Wolf | e615053 | 2015-09-04 18:26:09 +0200 | [diff] [blame] | 150 | echo |
| 151 | echo "== Changing lazy_refcounts setting at runtime ==" |
| 152 | |
Max Reitz | 407fb56 | 2019-11-07 17:36:57 +0100 | [diff] [blame] | 153 | _make_test_img -o "compat=1.1,lazy_refcounts=off" $size |
Kevin Wolf | e615053 | 2015-09-04 18:26:09 +0200 | [diff] [blame] | 154 | |
Andrey Shinkevich | 8af224d | 2019-09-04 12:11:20 +0300 | [diff] [blame] | 155 | _NO_VALGRIND \ |
Kevin Wolf | e615053 | 2015-09-04 18:26:09 +0200 | [diff] [blame] | 156 | $QEMU_IO -c "reopen -o lazy-refcounts=on" \ |
| 157 | -c "write -P 0x5a 0 512" \ |
| 158 | -c "sigraise $(kill -l KILL)" "$TEST_IMG" 2>&1 \ |
| 159 | | _filter_qemu_io |
| 160 | |
| 161 | # The dirty bit must be set |
Vladimir Sementsov-Ogievskiy | 984d7a5 | 2021-12-23 17:01:39 +0100 | [diff] [blame] | 162 | _qcow2_dump_header | grep incompatible_features |
Kevin Wolf | e615053 | 2015-09-04 18:26:09 +0200 | [diff] [blame] | 163 | _check_test_img |
| 164 | |
Max Reitz | 407fb56 | 2019-11-07 17:36:57 +0100 | [diff] [blame] | 165 | _make_test_img -o "compat=1.1,lazy_refcounts=on" $size |
Kevin Wolf | e615053 | 2015-09-04 18:26:09 +0200 | [diff] [blame] | 166 | |
Andrey Shinkevich | 8af224d | 2019-09-04 12:11:20 +0300 | [diff] [blame] | 167 | _NO_VALGRIND \ |
Kevin Wolf | e615053 | 2015-09-04 18:26:09 +0200 | [diff] [blame] | 168 | $QEMU_IO -c "reopen -o lazy-refcounts=off" \ |
| 169 | -c "write -P 0x5a 0 512" \ |
| 170 | -c "sigraise $(kill -l KILL)" "$TEST_IMG" 2>&1 \ |
| 171 | | _filter_qemu_io |
| 172 | |
| 173 | # The dirty bit must not be set |
Vladimir Sementsov-Ogievskiy | 984d7a5 | 2021-12-23 17:01:39 +0100 | [diff] [blame] | 174 | _qcow2_dump_header | grep incompatible_features |
Kevin Wolf | e615053 | 2015-09-04 18:26:09 +0200 | [diff] [blame] | 175 | _check_test_img |
| 176 | |
Kevin Wolf | 4c2e5f8 | 2014-04-03 13:47:50 +0200 | [diff] [blame] | 177 | |
Stefan Hajnoczi | dc68afe | 2012-07-27 09:05:24 +0100 | [diff] [blame] | 178 | # success, all done |
| 179 | echo "*** done" |
| 180 | rm -f $seq.full |
| 181 | status=0 |
| 182 | |