Merge remote-tracking branch 'remotes/nvme/tags/nvme-fixes-20210407-pull-request...
[qemu/ar7.git] / tests / qemu-iotests / 039
blob12b2c7fa7b87d87db9c5f5688dfeba2ce5df7989
1 #!/usr/bin/env bash
2 # group: rw auto quick
4 # Test qcow2 lazy refcounts
6 # Copyright (C) 2012 Red Hat, Inc.
7 # Copyright IBM, Corp. 2010
9 # Based on test 038.
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.
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.
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/>.
25 # creator
26 owner=stefanha@linux.vnet.ibm.com
28 seq=`basename $0`
29 echo "QA output created by $seq"
31 status=1 # failure is the default!
33 _cleanup()
35 _cleanup_test_img
37 trap "_cleanup; exit \$status" 0 1 2 3 15
39 # get standard environment, filters and checks
40 . ./common.rc
41 . ./common.filter
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
52 size=128M
54 echo
55 echo "== Checking that image is clean on shutdown =="
57 _make_test_img -o "compat=1.1,lazy_refcounts=on" $size
59 $QEMU_IO -c "write -P 0x5a 0 512" "$TEST_IMG" | _filter_qemu_io
61 # The dirty bit must not be set
62 $PYTHON qcow2.py "$TEST_IMG" dump-header | grep incompatible_features
63 _check_test_img
65 echo
66 echo "== Creating a dirty image file =="
68 _make_test_img -o "compat=1.1,lazy_refcounts=on" $size
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
75 # The dirty bit must be set
76 $PYTHON qcow2.py "$TEST_IMG" dump-header | grep incompatible_features
77 _check_test_img
79 echo
80 echo "== Read-only access must still work =="
82 $QEMU_IO -r -c "read -P 0x5a 0 512" "$TEST_IMG" | _filter_qemu_io
84 # The dirty bit must be set
85 $PYTHON qcow2.py "$TEST_IMG" dump-header | grep incompatible_features
87 echo
88 echo "== Repairing the image file must succeed =="
90 _check_test_img -r all
92 # The dirty bit must not be set
93 $PYTHON qcow2.py "$TEST_IMG" dump-header | grep incompatible_features
95 echo
96 echo "== Data should still be accessible after repair =="
98 $QEMU_IO -c "read -P 0x5a 0 512" "$TEST_IMG" | _filter_qemu_io
100 echo
101 echo "== Opening a dirty image read/write should repair it =="
103 _make_test_img -o "compat=1.1,lazy_refcounts=on" $size
105 _NO_VALGRIND \
106 $QEMU_IO -c "write -P 0x5a 0 512" \
107 -c "sigraise $(kill -l KILL)" "$TEST_IMG" 2>&1 \
108 | _filter_qemu_io
110 # The dirty bit must be set
111 $PYTHON qcow2.py "$TEST_IMG" dump-header | grep incompatible_features
113 $QEMU_IO -c "write 0 512" "$TEST_IMG" | _filter_qemu_io
115 # The dirty bit must not be set
116 $PYTHON qcow2.py "$TEST_IMG" dump-header | grep incompatible_features
118 echo
119 echo "== Creating an image file with lazy_refcounts=off =="
121 _make_test_img -o "compat=1.1,lazy_refcounts=off" $size
123 _NO_VALGRIND \
124 $QEMU_IO -c "write -P 0x5a 0 512" \
125 -c "sigraise $(kill -l KILL)" "$TEST_IMG" 2>&1 \
126 | _filter_qemu_io
128 # The dirty bit must not be set since lazy_refcounts=off
129 $PYTHON qcow2.py "$TEST_IMG" dump-header | grep incompatible_features
130 _check_test_img
132 echo
133 echo "== Committing to a backing file with lazy_refcounts=on =="
135 TEST_IMG="$TEST_IMG".base _make_test_img -o "compat=1.1,lazy_refcounts=on" $size
137 _make_test_img -o "compat=1.1,lazy_refcounts=on,backing_file=$TEST_IMG.base" \
138 -F $IMGFMT $size
140 $QEMU_IO -c "write 0 512" "$TEST_IMG" | _filter_qemu_io
141 $QEMU_IMG commit "$TEST_IMG"
143 # The dirty bit must not be set
144 $PYTHON qcow2.py "$TEST_IMG" dump-header | grep incompatible_features
145 $PYTHON qcow2.py "$TEST_IMG".base dump-header | grep incompatible_features
147 _check_test_img
148 TEST_IMG="$TEST_IMG".base _check_test_img
150 echo
151 echo "== Changing lazy_refcounts setting at runtime =="
153 _make_test_img -o "compat=1.1,lazy_refcounts=off" $size
155 _NO_VALGRIND \
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
161 # The dirty bit must be set
162 $PYTHON qcow2.py "$TEST_IMG" dump-header | grep incompatible_features
163 _check_test_img
165 _make_test_img -o "compat=1.1,lazy_refcounts=on" $size
167 _NO_VALGRIND \
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
173 # The dirty bit must not be set
174 $PYTHON qcow2.py "$TEST_IMG" dump-header | grep incompatible_features
175 _check_test_img
178 # success, all done
179 echo "*** done"
180 rm -f $seq.full
181 status=0