Merge remote-tracking branch 'remotes/maxreitz/tags/pull-block-2019-07-15' into staging
[qemu/ar7.git] / tests / qemu-iotests / 156
blob2ffa3ca942ac3d38865f9533b1d63a410a5afb99
1 #!/usr/bin/env bash
3 # Tests oVirt-like storage migration:
4 # - Create snapshot
5 # - Create target image with (not yet existing) target backing chain
6 # (i.e. just write the name of a soon-to-be-copied-over backing file into it)
7 # - drive-mirror the snapshot to the target with mode=existing and sync=top
8 # - In the meantime, copy the original source files to the destination via
9 # conventional means (i.e. outside of qemu)
10 # - Complete the drive-mirror job
11 # - Delete all source images
13 # Copyright (C) 2016 Red Hat, Inc.
15 # This program is free software; you can redistribute it and/or modify
16 # it under the terms of the GNU General Public License as published by
17 # the Free Software Foundation; either version 2 of the License, or
18 # (at your option) any later version.
20 # This program is distributed in the hope that it will be useful,
21 # but WITHOUT ANY WARRANTY; without even the implied warranty of
22 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 # GNU General Public License for more details.
25 # You should have received a copy of the GNU General Public License
26 # along with this program. If not, see <http://www.gnu.org/licenses/>.
29 # creator
30 owner=mreitz@redhat.com
32 seq="$(basename $0)"
33 echo "QA output created by $seq"
35 status=1 # failure is the default!
37 _cleanup()
39 _cleanup_qemu
40 rm -f "$TEST_IMG"{,.target}{,.backing,.overlay}
42 trap "_cleanup; exit \$status" 0 1 2 3 15
44 # get standard environment, filters and checks
45 . ./common.rc
46 . ./common.filter
47 . ./common.qemu
49 _supported_fmt qcow2 qed
50 _supported_proto generic
51 _unsupported_proto vxhs
53 # Create source disk
54 TEST_IMG="$TEST_IMG.backing" _make_test_img 1M
55 _make_test_img -b "$TEST_IMG.backing" 1M
57 $QEMU_IO -c 'write -P 1 0 256k' "$TEST_IMG.backing" | _filter_qemu_io
58 $QEMU_IO -c 'write -P 2 64k 192k' "$TEST_IMG" | _filter_qemu_io
60 _launch_qemu -drive if=none,id=source,file="$TEST_IMG"
62 _send_qemu_cmd $QEMU_HANDLE \
63 "{ 'execute': 'qmp_capabilities' }" \
64 'return'
66 # Create snapshot
67 TEST_IMG="$TEST_IMG.overlay" _make_test_img -u -b "$TEST_IMG" 1M
68 _send_qemu_cmd $QEMU_HANDLE \
69 "{ 'execute': 'blockdev-snapshot-sync',
70 'arguments': { 'device': 'source',
71 'snapshot-file': '$TEST_IMG.overlay',
72 'format': '$IMGFMT',
73 'mode': 'existing' } }" \
74 'return'
76 # Write something to the snapshot
77 _send_qemu_cmd $QEMU_HANDLE \
78 "{ 'execute': 'human-monitor-command',
79 'arguments': { 'command-line':
80 'qemu-io source \"write -P 3 128k 128k\"' } }" \
81 'return'
83 # Create target image
84 TEST_IMG="$TEST_IMG.target.overlay" _make_test_img -u -b "$TEST_IMG.target" 1M
86 # Mirror snapshot
87 _send_qemu_cmd $QEMU_HANDLE \
88 "{ 'execute': 'drive-mirror',
89 'arguments': { 'device': 'source',
90 'target': '$TEST_IMG.target.overlay',
91 'mode': 'existing',
92 'sync': 'top' } }" \
93 'return'
95 # Wait for convergence
96 _send_qemu_cmd $QEMU_HANDLE \
97 '' \
98 'BLOCK_JOB_READY'
100 # Write some more
101 _send_qemu_cmd $QEMU_HANDLE \
102 "{ 'execute': 'human-monitor-command',
103 'arguments': { 'command-line':
104 'qemu-io source \"write -P 4 192k 64k\"' } }" \
105 'return'
107 # Copy source backing chain to the target before completing the job
108 cp "$TEST_IMG.backing" "$TEST_IMG.target.backing"
109 cp "$TEST_IMG" "$TEST_IMG.target"
110 $QEMU_IMG rebase -u -b "$TEST_IMG.target.backing" "$TEST_IMG.target"
112 # Complete block job
113 _send_qemu_cmd $QEMU_HANDLE \
114 "{ 'execute': 'block-job-complete',
115 'arguments': { 'device': 'source' } }" \
118 _send_qemu_cmd $QEMU_HANDLE \
119 '' \
120 '"status": "null"'
122 # Remove the source images
123 rm -f "$TEST_IMG{,.backing,.overlay}"
125 echo
127 # Check online disk contents
128 _send_qemu_cmd $QEMU_HANDLE \
129 "{ 'execute': 'human-monitor-command',
130 'arguments': { 'command-line':
131 'qemu-io source \"read -P 1 0k 64k\"' } }" \
132 'return'
134 _send_qemu_cmd $QEMU_HANDLE \
135 "{ 'execute': 'human-monitor-command',
136 'arguments': { 'command-line':
137 'qemu-io source \"read -P 2 64k 64k\"' } }" \
138 'return'
140 _send_qemu_cmd $QEMU_HANDLE \
141 "{ 'execute': 'human-monitor-command',
142 'arguments': { 'command-line':
143 'qemu-io source \"read -P 3 128k 64k\"' } }" \
144 'return'
146 _send_qemu_cmd $QEMU_HANDLE \
147 "{ 'execute': 'human-monitor-command',
148 'arguments': { 'command-line':
149 'qemu-io source \"read -P 4 192k 64k\"' } }" \
150 'return'
152 echo
154 _send_qemu_cmd $QEMU_HANDLE \
155 "{ 'execute': 'quit' }" \
156 'return'
158 wait=1 _cleanup_qemu
160 echo
162 # Check offline disk contents
163 $QEMU_IO -c 'read -P 1 0k 64k' \
164 -c 'read -P 2 64k 64k' \
165 -c 'read -P 3 128k 64k' \
166 -c 'read -P 4 192k 64k' \
167 "$TEST_IMG.target.overlay" | _filter_qemu_io
169 echo
171 # success, all done
172 echo '*** done'
173 rm -f $seq.full
174 status=0