tests: fix a memory in test_socket_unix_abstract_good
[qemu/ar7.git] / tests / qemu-iotests / 156
blob9c7878dd2dd30e8226c78125c72cefc43bce3f51
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 for img in "$TEST_IMG"{,.target}{,.backing,.overlay}; do
41 _rm_test_img "$img"
42 done
44 trap "_cleanup; exit \$status" 0 1 2 3 15
46 # get standard environment, filters and checks
47 . ./common.rc
48 . ./common.filter
49 . ./common.qemu
51 _supported_fmt qcow2 qed
52 _supported_proto generic
53 # Copying files around with cp does not work with external data files
54 _unsupported_imgopts data_file
56 # Create source disk
57 TEST_IMG="$TEST_IMG.backing" _make_test_img 1M
58 _make_test_img -b "$TEST_IMG.backing" -F $IMGFMT 1M
60 $QEMU_IO -c 'write -P 1 0 256k' "$TEST_IMG.backing" | _filter_qemu_io
61 $QEMU_IO -c 'write -P 2 64k 192k' "$TEST_IMG" | _filter_qemu_io
63 _launch_qemu -drive if=none,id=source,file="$TEST_IMG"
65 _send_qemu_cmd $QEMU_HANDLE \
66 "{ 'execute': 'qmp_capabilities' }" \
67 'return'
69 # Create snapshot
70 TEST_IMG="$TEST_IMG.overlay" _make_test_img -u -b "$TEST_IMG" -F $IMGFMT 1M
71 _send_qemu_cmd $QEMU_HANDLE \
72 "{ 'execute': 'blockdev-snapshot-sync',
73 'arguments': { 'device': 'source',
74 'snapshot-file': '$TEST_IMG.overlay',
75 'format': '$IMGFMT',
76 'mode': 'existing' } }" \
77 'return'
79 # Write something to the snapshot
80 _send_qemu_cmd $QEMU_HANDLE \
81 "{ 'execute': 'human-monitor-command',
82 'arguments': { 'command-line':
83 'qemu-io source \"write -P 3 128k 128k\"' } }" \
84 'return'
86 # Create target image
87 TEST_IMG="$TEST_IMG.target.overlay" _make_test_img -u -b "$TEST_IMG.target" \
88 -F $IMGFMT 1M
90 # Mirror snapshot
91 _send_qemu_cmd $QEMU_HANDLE \
92 "{ 'execute': 'drive-mirror',
93 'arguments': { 'device': 'source',
94 'target': '$TEST_IMG.target.overlay',
95 'mode': 'existing',
96 'sync': 'top' } }" \
97 'return'
99 # Wait for convergence
100 _send_qemu_cmd $QEMU_HANDLE \
101 '' \
102 'BLOCK_JOB_READY'
104 # Write some more
105 _send_qemu_cmd $QEMU_HANDLE \
106 "{ 'execute': 'human-monitor-command',
107 'arguments': { 'command-line':
108 'qemu-io source \"write -P 4 192k 64k\"' } }" \
109 'return'
111 # Copy source backing chain to the target before completing the job
112 cp "$TEST_IMG.backing" "$TEST_IMG.target.backing"
113 cp "$TEST_IMG" "$TEST_IMG.target"
114 $QEMU_IMG rebase -u -b "$TEST_IMG.target.backing" -F $IMGFMT "$TEST_IMG.target"
116 # Complete block job
117 _send_qemu_cmd $QEMU_HANDLE \
118 "{ 'execute': 'block-job-complete',
119 'arguments': { 'device': 'source' } }" \
122 _send_qemu_cmd $QEMU_HANDLE \
123 '' \
124 '"status": "null"'
126 # Remove the source images
127 for img in "$TEST_IMG{,.backing,.overlay}"; do
128 _rm_test_img "$img"
129 done
131 echo
133 # Check online disk contents
134 _send_qemu_cmd $QEMU_HANDLE \
135 "{ 'execute': 'human-monitor-command',
136 'arguments': { 'command-line':
137 'qemu-io source \"read -P 1 0k 64k\"' } }" \
138 'return'
140 _send_qemu_cmd $QEMU_HANDLE \
141 "{ 'execute': 'human-monitor-command',
142 'arguments': { 'command-line':
143 'qemu-io source \"read -P 2 64k 64k\"' } }" \
144 'return'
146 _send_qemu_cmd $QEMU_HANDLE \
147 "{ 'execute': 'human-monitor-command',
148 'arguments': { 'command-line':
149 'qemu-io source \"read -P 3 128k 64k\"' } }" \
150 'return'
152 _send_qemu_cmd $QEMU_HANDLE \
153 "{ 'execute': 'human-monitor-command',
154 'arguments': { 'command-line':
155 'qemu-io source \"read -P 4 192k 64k\"' } }" \
156 'return'
158 echo
160 _send_qemu_cmd $QEMU_HANDLE \
161 "{ 'execute': 'quit' }" \
162 'return'
164 wait=1 _cleanup_qemu
166 echo
168 # Check offline disk contents
169 $QEMU_IO -c 'read -P 1 0k 64k' \
170 -c 'read -P 2 64k 64k' \
171 -c 'read -P 3 128k 64k' \
172 -c 'read -P 4 192k 64k' \
173 "$TEST_IMG.target.overlay" | _filter_qemu_io
175 echo
177 # success, all done
178 echo '*** done'
179 rm -f $seq.full
180 status=0