target/arm: Convert ARM_TBFLAG_* to FIELDs
[qemu/ar7.git] / tests / qemu-iotests / 085
blobade68ef853b4424fa321317cf79e426710f69b56
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 status=1 # failure is the default!
34 snapshot_virt0="snapshot-v0.qcow2"
35 snapshot_virt1="snapshot-v1.qcow2"
37 SNAPSHOTS=10
39 _cleanup()
41 _cleanup_qemu
42 for i in $(seq 1 ${SNAPSHOTS})
44 rm -f "${TEST_DIR}/${i}-${snapshot_virt0}"
45 rm -f "${TEST_DIR}/${i}-${snapshot_virt1}"
46 done
47 rm -f "${TEST_IMG}" "${TEST_IMG}.1" "${TEST_IMG}.2" "${TEST_IMG}.base"
50 trap "_cleanup; exit \$status" 0 1 2 3 15
52 # get standard environment, filters and checks
53 . ./common.rc
54 . ./common.filter
55 . ./common.qemu
57 _supported_fmt qcow2
58 _supported_proto file
59 _supported_os Linux
62 # ${1}: unique identifier for the snapshot filename
63 create_single_snapshot()
65 cmd="{ 'execute': 'blockdev-snapshot-sync',
66 'arguments': { 'device': 'virtio0',
67 'snapshot-file':'${TEST_DIR}/${1}-${snapshot_virt0}',
68 'format': 'qcow2' } }"
69 _send_qemu_cmd $h "${cmd}" "return"
72 # ${1}: unique identifier for the snapshot filename
73 create_group_snapshot()
75 cmd="{ 'execute': 'transaction', 'arguments':
76 {'actions': [
77 { 'type': 'blockdev-snapshot-sync', 'data' :
78 { 'device': 'virtio0',
79 'snapshot-file': '${TEST_DIR}/${1}-${snapshot_virt0}' } },
80 { 'type': 'blockdev-snapshot-sync', 'data' :
81 { 'device': 'virtio1',
82 'snapshot-file': '${TEST_DIR}/${1}-${snapshot_virt1}' } } ]
83 } }"
85 _send_qemu_cmd $h "${cmd}" "return"
88 # ${1}: unique identifier for the snapshot filename
89 # ${2}: extra_params to the blockdev-add command
90 # ${3}: filename
91 do_blockdev_add()
93 cmd="{ 'execute': 'blockdev-add', 'arguments':
94 { 'driver': 'qcow2', 'node-name': 'snap_${1}', ${2}
95 'file':
96 { 'driver': 'file', 'filename': '${3}',
97 'node-name': 'file_${1}' } } }"
98 _send_qemu_cmd $h "${cmd}" "return"
101 # ${1}: unique identifier for the snapshot filename
102 add_snapshot_image()
104 base_image="${TEST_DIR}/$((${1}-1))-${snapshot_virt0}"
105 snapshot_file="${TEST_DIR}/${1}-${snapshot_virt0}"
106 _make_test_img -u -b "${base_image}" "$size"
107 mv "${TEST_IMG}" "${snapshot_file}"
108 do_blockdev_add "$1" "'backing': null, " "${snapshot_file}"
111 # ${1}: unique identifier for the snapshot filename
112 # ${2}: expected response, defaults to 'return'
113 blockdev_snapshot()
115 cmd="{ 'execute': 'blockdev-snapshot',
116 'arguments': { 'node': 'virtio0',
117 'overlay':'snap_${1}' } }"
118 _send_qemu_cmd $h "${cmd}" "${2:-return}"
121 size=128M
123 _make_test_img $size
124 mv "${TEST_IMG}" "${TEST_IMG}.1"
125 _make_test_img $size
126 mv "${TEST_IMG}" "${TEST_IMG}.2"
128 echo
129 echo === Running QEMU ===
130 echo
132 qemu_comm_method="qmp"
133 _launch_qemu -drive file="${TEST_IMG}.1",if=virtio -drive file="${TEST_IMG}.2",if=virtio
134 h=$QEMU_HANDLE
136 echo
137 echo === Sending capabilities ===
138 echo
140 _send_qemu_cmd $h "{ 'execute': 'qmp_capabilities' }" "return"
142 # Tests for the blockdev-snapshot-sync command
144 echo
145 echo === Create a single snapshot on virtio0 ===
146 echo
148 create_single_snapshot 1
151 echo
152 echo === Invalid command - missing device and nodename ===
153 echo
155 _send_qemu_cmd $h "{ 'execute': 'blockdev-snapshot-sync',
156 'arguments': { 'snapshot-file':'${TEST_DIR}/1-${snapshot_virt0}',
157 'format': 'qcow2' } }" "error"
159 echo
160 echo === Invalid command - missing snapshot-file ===
161 echo
163 _send_qemu_cmd $h "{ 'execute': 'blockdev-snapshot-sync',
164 'arguments': { 'device': 'virtio0',
165 'format': 'qcow2' } }" "error"
166 echo
167 echo
168 echo === Create several transactional group snapshots ===
169 echo
171 for i in $(seq 2 ${SNAPSHOTS})
173 create_group_snapshot ${i}
174 done
176 # Tests for the blockdev-snapshot command
178 echo
179 echo === Create a couple of snapshots using blockdev-snapshot ===
180 echo
182 SNAPSHOTS=$((${SNAPSHOTS}+1))
183 add_snapshot_image ${SNAPSHOTS}
184 blockdev_snapshot ${SNAPSHOTS}
186 SNAPSHOTS=$((${SNAPSHOTS}+1))
187 add_snapshot_image ${SNAPSHOTS}
188 blockdev_snapshot ${SNAPSHOTS}
190 echo
191 echo === Invalid command - cannot create a snapshot using a file BDS ===
192 echo
194 _send_qemu_cmd $h "{ 'execute': 'blockdev-snapshot',
195 'arguments': { 'node':'virtio0',
196 'overlay':'file_${SNAPSHOTS}' }
197 }" "error"
199 echo
200 echo === Invalid command - snapshot node used as active layer ===
201 echo
203 blockdev_snapshot ${SNAPSHOTS} error
205 _send_qemu_cmd $h "{ 'execute': 'blockdev-snapshot',
206 'arguments': { 'node':'virtio0',
207 'overlay':'virtio0' }
208 }" "error"
210 _send_qemu_cmd $h "{ 'execute': 'blockdev-snapshot',
211 'arguments': { 'node':'virtio0',
212 'overlay':'virtio1' }
213 }" "error"
215 echo
216 echo === Invalid command - snapshot node used as backing hd ===
217 echo
219 blockdev_snapshot $((${SNAPSHOTS}-1)) error
221 echo
222 echo === Invalid command - snapshot node has a backing image ===
223 echo
225 SNAPSHOTS=$((${SNAPSHOTS}+1))
227 TEST_IMG="$TEST_IMG.base" _make_test_img "$size"
228 _make_test_img -b "${TEST_IMG}.base" "$size"
229 do_blockdev_add ${SNAPSHOTS} "" "${TEST_IMG}"
230 blockdev_snapshot ${SNAPSHOTS} error
232 echo
233 echo === Invalid command - The node does not exist ===
234 echo
236 blockdev_snapshot $((${SNAPSHOTS}+1)) error
238 _send_qemu_cmd $h "{ 'execute': 'blockdev-snapshot',
239 'arguments': { 'node':'nodevice',
240 'overlay':'snap_${SNAPSHOTS}' }
241 }" "error"
243 # success, all done
244 echo "*** done"
245 rm -f $seq.full
246 status=0