coroutine: Extract qemu_aio_coroutine_enter
[qemu/ar7.git] / tests / qemu-iotests / 085
blobc53e97f067bba22652bcc8eb073f97592b4b045f
1 #!/bin/bash
3 # Live snapshot tests
5 # This tests live snapshots of images on a running QEMU instance, using
6 # QMP commands. Both single disk snapshots, and transactional group
7 # snapshots are performed.
9 # Copyright (C) 2014 Red Hat, Inc.
10 # Copyright (C) 2015 Igalia, S.L.
12 # This program is free software; you can redistribute it and/or modify
13 # it under the terms of the GNU General Public License as published by
14 # the Free Software Foundation; either version 2 of the License, or
15 # (at your option) any later version.
17 # This program is distributed in the hope that it will be useful,
18 # but WITHOUT ANY WARRANTY; without even the implied warranty of
19 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 # GNU General Public License for more details.
22 # You should have received a copy of the GNU General Public License
23 # along with this program. If not, see <http://www.gnu.org/licenses/>.
26 # creator
27 owner=jcody@redhat.com
29 seq=`basename $0`
30 echo "QA output created by $seq"
32 here=`pwd`
33 status=1 # failure is the default!
35 snapshot_virt0="snapshot-v0.qcow2"
36 snapshot_virt1="snapshot-v1.qcow2"
38 SNAPSHOTS=10
40 _cleanup()
42 _cleanup_qemu
43 for i in $(seq 1 ${SNAPSHOTS})
45 rm -f "${TEST_DIR}/${i}-${snapshot_virt0}"
46 rm -f "${TEST_DIR}/${i}-${snapshot_virt1}"
47 done
48 rm -f "${TEST_IMG}.1" "${TEST_IMG}.2"
51 trap "_cleanup; exit \$status" 0 1 2 3 15
53 # get standard environment, filters and checks
54 . ./common.rc
55 . ./common.filter
56 . ./common.qemu
58 _supported_fmt qcow2
59 _supported_proto file
60 _supported_os Linux
63 # ${1}: unique identifier for the snapshot filename
64 function create_single_snapshot()
66 cmd="{ 'execute': 'blockdev-snapshot-sync',
67 'arguments': { 'device': 'virtio0',
68 'snapshot-file':'${TEST_DIR}/${1}-${snapshot_virt0}',
69 'format': 'qcow2' } }"
70 _send_qemu_cmd $h "${cmd}" "return"
73 # ${1}: unique identifier for the snapshot filename
74 function create_group_snapshot()
76 cmd="{ 'execute': 'transaction', 'arguments':
77 {'actions': [
78 { 'type': 'blockdev-snapshot-sync', 'data' :
79 { 'device': 'virtio0',
80 'snapshot-file': '${TEST_DIR}/${1}-${snapshot_virt0}' } },
81 { 'type': 'blockdev-snapshot-sync', 'data' :
82 { 'device': 'virtio1',
83 'snapshot-file': '${TEST_DIR}/${1}-${snapshot_virt1}' } } ]
84 } }"
86 _send_qemu_cmd $h "${cmd}" "return"
89 # ${1}: unique identifier for the snapshot filename
90 # ${2}: true: open backing images; false: don't open them (default)
91 function add_snapshot_image()
93 if [ "${2}" = "true" ]; then
94 extra_params=""
95 else
96 extra_params="'backing': '', "
98 base_image="${TEST_DIR}/$((${1}-1))-${snapshot_virt0}"
99 snapshot_file="${TEST_DIR}/${1}-${snapshot_virt0}"
100 _make_test_img -b "${base_image}" "$size"
101 mv "${TEST_IMG}" "${snapshot_file}"
102 cmd="{ 'execute': 'blockdev-add', 'arguments':
103 { 'driver': 'qcow2', 'node-name': 'snap_${1}', ${extra_params}
104 'file':
105 { 'driver': 'file', 'filename': '${snapshot_file}',
106 'node-name': 'file_${1}' } } }"
107 _send_qemu_cmd $h "${cmd}" "return"
110 # ${1}: unique identifier for the snapshot filename
111 # ${2}: expected response, defaults to 'return'
112 function blockdev_snapshot()
114 cmd="{ 'execute': 'blockdev-snapshot',
115 'arguments': { 'node': 'virtio0',
116 'overlay':'snap_${1}' } }"
117 _send_qemu_cmd $h "${cmd}" "${2:-return}"
120 size=128M
122 _make_test_img $size
123 mv "${TEST_IMG}" "${TEST_IMG}.1"
124 _make_test_img $size
125 mv "${TEST_IMG}" "${TEST_IMG}.2"
127 echo
128 echo === Running QEMU ===
129 echo
131 qemu_comm_method="qmp"
132 _launch_qemu -drive file="${TEST_IMG}.1",if=virtio -drive file="${TEST_IMG}.2",if=virtio
133 h=$QEMU_HANDLE
135 echo
136 echo === Sending capabilities ===
137 echo
139 _send_qemu_cmd $h "{ 'execute': 'qmp_capabilities' }" "return"
141 # Tests for the blockdev-snapshot-sync command
143 echo
144 echo === Create a single snapshot on virtio0 ===
145 echo
147 create_single_snapshot 1
150 echo
151 echo === Invalid command - missing device and nodename ===
152 echo
154 _send_qemu_cmd $h "{ 'execute': 'blockdev-snapshot-sync',
155 'arguments': { 'snapshot-file':'${TEST_DIR}/1-${snapshot_virt0}',
156 'format': 'qcow2' } }" "error"
158 echo
159 echo === Invalid command - missing snapshot-file ===
160 echo
162 _send_qemu_cmd $h "{ 'execute': 'blockdev-snapshot-sync',
163 'arguments': { 'device': 'virtio0',
164 'format': 'qcow2' } }" "error"
165 echo
166 echo
167 echo === Create several transactional group snapshots ===
168 echo
170 for i in $(seq 2 ${SNAPSHOTS})
172 create_group_snapshot ${i}
173 done
175 # Tests for the blockdev-snapshot command
177 echo
178 echo === Create a couple of snapshots using blockdev-snapshot ===
179 echo
181 SNAPSHOTS=$((${SNAPSHOTS}+1))
182 add_snapshot_image ${SNAPSHOTS}
183 blockdev_snapshot ${SNAPSHOTS}
185 SNAPSHOTS=$((${SNAPSHOTS}+1))
186 add_snapshot_image ${SNAPSHOTS}
187 blockdev_snapshot ${SNAPSHOTS}
189 echo
190 echo === Invalid command - cannot create a snapshot using a file BDS ===
191 echo
193 _send_qemu_cmd $h "{ 'execute': 'blockdev-snapshot',
194 'arguments': { 'node':'virtio0',
195 'overlay':'file_${SNAPSHOTS}' }
196 }" "error"
198 echo
199 echo === Invalid command - snapshot node used as active layer ===
200 echo
202 blockdev_snapshot ${SNAPSHOTS} error
204 _send_qemu_cmd $h "{ 'execute': 'blockdev-snapshot',
205 'arguments': { 'node':'virtio0',
206 'overlay':'virtio0' }
207 }" "error"
209 _send_qemu_cmd $h "{ 'execute': 'blockdev-snapshot',
210 'arguments': { 'node':'virtio0',
211 'overlay':'virtio1' }
212 }" "error"
214 echo
215 echo === Invalid command - snapshot node used as backing hd ===
216 echo
218 blockdev_snapshot $((${SNAPSHOTS}-1)) error
220 echo
221 echo === Invalid command - snapshot node has a backing image ===
222 echo
224 SNAPSHOTS=$((${SNAPSHOTS}+1))
225 add_snapshot_image ${SNAPSHOTS} true
226 blockdev_snapshot ${SNAPSHOTS} error
228 echo
229 echo === Invalid command - The node does not exist ===
230 echo
232 blockdev_snapshot $((${SNAPSHOTS}+1)) error
234 _send_qemu_cmd $h "{ 'execute': 'blockdev-snapshot',
235 'arguments': { 'node':'nodevice',
236 'overlay':'snap_${SNAPSHOTS}' }
237 }" "error"
239 # success, all done
240 echo "*** done"
241 rm -f $seq.full
242 status=0