iotests: add iotest 236 for testing bitmap merge
[qemu/ar7.git] / tests / qemu-iotests / 153
blob3120a61da472b9ebc56157762e0d7e45d904ba7f
1 #!/bin/bash
3 # Test image locking
5 # Copyright 2016, 2017 Red Hat, Inc.
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
21 # creator
22 owner=famz@redhat.com
24 seq="$(basename $0)"
25 echo "QA output created by $seq"
27 tmp=/tmp/$$
28 status=1 # failure is the default!
30 _cleanup()
32 _cleanup_test_img
33 rm -f "${TEST_IMG}.base"
34 rm -f "${TEST_IMG}.overlay"
35 rm -f "${TEST_IMG}.convert"
36 rm -f "${TEST_IMG}.a"
37 rm -f "${TEST_IMG}.b"
38 rm -f "${TEST_IMG}.c"
39 rm -f "${TEST_IMG}.lnk"
41 trap "_cleanup; exit \$status" 0 1 2 3 15
43 # get standard environment, filters and checks
44 . ./common.rc
45 . ./common.filter
46 . ./common.qemu
48 size=32M
50 _check_ofd()
52 _make_test_img $size >/dev/null
53 if $QEMU_IMG_PROG info --image-opts "driver=file,locking=on,filename=$TEST_IMG" 2>&1 |
54 grep -q 'falling back to POSIX file'; then
55 return 1
56 else
57 return 0
61 _check_ofd || _notrun "OFD lock not available"
63 _supported_fmt qcow2
64 _supported_proto file
65 _supported_os Linux
67 _run_cmd()
69 echo
70 (echo "$@"; "$@" 2>&1 1>/dev/null) | _filter_testdir
73 _do_run_qemu()
76 if ! test -t 0; then
77 while read cmd; do
78 echo $cmd
79 done
81 echo quit
82 ) | $QEMU -nographic -monitor stdio -serial none "$@" 1>/dev/null
85 _run_qemu_with_images()
87 _do_run_qemu \
88 $(for i in $@; do echo "-drive if=none,file=$i"; done) 2>&1 \
89 | _filter_testdir | _filter_qemu
92 echo "== readonly=off,force-share=on should be rejected =="
93 _run_qemu_with_images null-co://,readonly=off,force-share=on
95 for opts1 in "" "read-only=on" "read-only=on,force-share=on"; do
96 echo
97 echo "== Creating base image =="
98 TEST_IMG="${TEST_IMG}.base" _make_test_img $size
100 echo
101 echo "== Creating test image =="
102 $QEMU_IMG create -f $IMGFMT "${TEST_IMG}" -b ${TEST_IMG}.base | _filter_img_create
104 echo
105 echo "== Launching QEMU, opts: '$opts1' =="
106 _launch_qemu -drive file="${TEST_IMG}",if=none,$opts1
107 h=$QEMU_HANDLE
109 for opts2 in "" "read-only=on" "read-only=on,force-share=on"; do
110 echo
111 echo "== Launching another QEMU, opts: '$opts2' =="
112 echo "quit" | \
113 $QEMU -nographic -monitor stdio \
114 -drive file="${TEST_IMG}",if=none,$opts2 2>&1 1>/dev/null | \
115 _filter_testdir | _filter_qemu
116 done
118 for L in "" "-U"; do
120 echo
121 echo "== Running utility commands $L =="
122 _run_cmd $QEMU_IO $L -c "read 0 512" "${TEST_IMG}"
123 _run_cmd $QEMU_IO $L -r -c "read 0 512" "${TEST_IMG}"
124 _run_cmd $QEMU_IO -c "open $L ${TEST_IMG}" -c "read 0 512"
125 _run_cmd $QEMU_IO -c "open -r $L ${TEST_IMG}" -c "read 0 512"
126 _run_cmd $QEMU_IMG info $L "${TEST_IMG}"
127 _run_cmd $QEMU_IMG check $L "${TEST_IMG}"
128 _run_cmd $QEMU_IMG compare $L "${TEST_IMG}" "${TEST_IMG}"
129 _run_cmd $QEMU_IMG map $L "${TEST_IMG}"
130 _run_cmd $QEMU_IMG amend -o "" $L "${TEST_IMG}"
131 _run_cmd $QEMU_IMG commit $L "${TEST_IMG}"
132 _run_cmd $QEMU_IMG resize $L "${TEST_IMG}" $size
133 _run_cmd $QEMU_IMG rebase $L "${TEST_IMG}" -b "${TEST_IMG}.base"
134 _run_cmd $QEMU_IMG snapshot -l $L "${TEST_IMG}"
135 _run_cmd $QEMU_IMG convert $L "${TEST_IMG}" "${TEST_IMG}.convert"
136 _run_cmd $QEMU_IMG dd $L if="${TEST_IMG}" of="${TEST_IMG}.convert" bs=512 count=1
137 _run_cmd $QEMU_IMG bench $L -c 1 "${TEST_IMG}"
138 _run_cmd $QEMU_IMG bench $L -w -c 1 "${TEST_IMG}"
140 # qemu-img create does not support -U
141 if [ -z "$L" ]; then
142 _run_cmd $QEMU_IMG create -f $IMGFMT "${TEST_IMG}" \
143 -b ${TEST_IMG}.base
144 # Read the file format. It used to be the case that
145 # file-posix simply truncated the file, but the qcow2
146 # driver then failed to format it because it was unable
147 # to acquire the necessary WRITE permission. However, the
148 # truncation was already wrong, and the whole process
149 # resulted in the file being completely empty and thus its
150 # format would be detected to be raw.
151 # So we read it here to see that creation either completed
152 # successfully (thus the format is qcow2) or it aborted
153 # before the file was changed at all (thus the format stays
154 # qcow2).
155 _img_info -U | grep 'file format'
157 done
158 _send_qemu_cmd $h "{ 'execute': 'quit', }" ""
159 echo
160 echo "Round done"
161 _cleanup_qemu
162 done
164 test_opts="read-only=off read-only=on read-only=on,force-share=on"
165 for opt1 in $test_opts; do
166 for opt2 in $test_opts; do
167 echo
168 echo "== Two devices with the same image ($opt1 - $opt2) =="
169 _run_qemu_with_images "${TEST_IMG},$opt1" "${TEST_IMG},$opt2"
170 done
171 done
173 echo
174 echo "== Creating ${TEST_IMG}.[abc] ==" | _filter_testdir
176 $QEMU_IMG create -f qcow2 "${TEST_IMG}.a" -b "${TEST_IMG}"
177 $QEMU_IMG create -f qcow2 "${TEST_IMG}.b" -b "${TEST_IMG}"
178 $QEMU_IMG create -f qcow2 "${TEST_IMG}.c" -b "${TEST_IMG}.b"
179 ) | _filter_img_create
181 echo
182 echo "== Two devices sharing the same file in backing chain =="
183 _run_qemu_with_images "${TEST_IMG}.a" "${TEST_IMG}.b"
184 _run_qemu_with_images "${TEST_IMG}.a" "${TEST_IMG}.c"
186 echo
187 echo "== Backing image also as an active device =="
188 _run_qemu_with_images "${TEST_IMG}.a" "${TEST_IMG}"
190 echo
191 echo "== Backing image also as an active device (ro) =="
192 _run_qemu_with_images "${TEST_IMG}.a" "${TEST_IMG},readonly=on"
194 echo
195 echo "== Symbolic link =="
196 rm -f "${TEST_IMG}.lnk" &>/dev/null
197 ln -s ${TEST_IMG} "${TEST_IMG}.lnk" || echo "Failed to create link"
198 _run_qemu_with_images "${TEST_IMG}.lnk" "${TEST_IMG}"
200 echo
201 echo "== Active commit to intermediate layer should work when base in use =="
202 _launch_qemu -drive format=$IMGFMT,file="${TEST_IMG}.a",id=drive0,if=none \
203 -device virtio-blk,drive=drive0
205 _send_qemu_cmd $QEMU_HANDLE \
206 "{ 'execute': 'qmp_capabilities' }" \
207 'return'
208 _run_cmd $QEMU_IMG commit -b "${TEST_IMG}.b" "${TEST_IMG}.c"
210 _cleanup_qemu
212 _launch_qemu
214 _send_qemu_cmd $QEMU_HANDLE \
215 "{ 'execute': 'qmp_capabilities' }" \
216 'return'
218 echo "Adding drive"
219 _send_qemu_cmd $QEMU_HANDLE \
220 "{ 'execute': 'human-monitor-command',
221 'arguments': { 'command-line': 'drive_add 0 if=none,id=d0,file=${TEST_IMG}' } }" \
224 _run_cmd $QEMU_IO "${TEST_IMG}" -c 'write 0 512'
226 echo "Creating overlay with qemu-img when the guest is running should be allowed"
227 _run_cmd $QEMU_IMG create -f $IMGFMT -b "${TEST_IMG}" "${TEST_IMG}.overlay"
229 echo "== Closing an image should unlock it =="
230 _send_qemu_cmd $QEMU_HANDLE \
231 "{ 'execute': 'human-monitor-command',
232 'arguments': { 'command-line': 'drive_del d0' } }" \
235 _run_cmd $QEMU_IO "${TEST_IMG}" -c 'write 0 512'
237 echo "Adding two and closing one"
238 for d in d0 d1; do
239 _send_qemu_cmd $QEMU_HANDLE \
240 "{ 'execute': 'human-monitor-command',
241 'arguments': { 'command-line': 'drive_add 0 if=none,id=$d,file=${TEST_IMG},readonly=on' } }" \
243 done
245 _run_cmd $QEMU_IMG info "${TEST_IMG}"
247 _send_qemu_cmd $QEMU_HANDLE \
248 "{ 'execute': 'human-monitor-command',
249 'arguments': { 'command-line': 'drive_del d0' } }" \
252 _run_cmd $QEMU_IO "${TEST_IMG}" -c 'write 0 512'
254 echo "Closing the other"
255 _send_qemu_cmd $QEMU_HANDLE \
256 "{ 'execute': 'human-monitor-command',
257 'arguments': { 'command-line': 'drive_del d1' } }" \
260 _run_cmd $QEMU_IO "${TEST_IMG}" -c 'write 0 512'
262 _cleanup_qemu
264 echo
265 echo "== Detecting -U and force-share conflicts =="
267 echo
268 echo 'No conflict:'
269 $QEMU_IMG info -U --image-opts driver=null-co,force-share=on
270 echo
271 echo 'Conflict:'
272 $QEMU_IMG info -U --image-opts driver=null-co,force-share=off
274 echo
275 echo 'No conflict:'
276 $QEMU_IO -c 'open -r -U -o driver=null-co,force-share=on'
277 echo
278 echo 'Conflict:'
279 $QEMU_IO -c 'open -r -U -o driver=null-co,force-share=off'
281 # success, all done
282 echo "*** done"
283 rm -f $seq.full
284 status=0