]>
Commit | Line | Data |
---|---|---|
3dd48fdc HR |
1 | #!/bin/bash |
2 | # | |
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 | |
12 | # | |
13 | # Copyright (C) 2016 Red Hat, Inc. | |
14 | # | |
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. | |
19 | # | |
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. | |
24 | # | |
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/>. | |
27 | # | |
28 | ||
29 | # creator | |
30 | [email protected] | |
31 | ||
32 | seq="$(basename $0)" | |
33 | echo "QA output created by $seq" | |
34 | ||
35 | here="$PWD" | |
36 | status=1 # failure is the default! | |
37 | ||
38 | _cleanup() | |
39 | { | |
ecfa1854 | 40 | _cleanup_qemu |
645acdc0 | 41 | rm -f "$TEST_IMG"{,.target}{,.backing,.overlay} |
3dd48fdc HR |
42 | } |
43 | trap "_cleanup; exit \$status" 0 1 2 3 15 | |
44 | ||
45 | # get standard environment, filters and checks | |
46 | . ./common.rc | |
47 | . ./common.filter | |
48 | . ./common.qemu | |
49 | ||
50 | _supported_fmt qcow2 qed | |
51 | _supported_proto generic | |
a98f49f4 | 52 | _unsupported_proto vxhs |
3dd48fdc HR |
53 | _supported_os Linux |
54 | ||
55 | # Create source disk | |
56 | TEST_IMG="$TEST_IMG.backing" _make_test_img 1M | |
57 | _make_test_img -b "$TEST_IMG.backing" 1M | |
58 | ||
59 | $QEMU_IO -c 'write -P 1 0 256k' "$TEST_IMG.backing" | _filter_qemu_io | |
60 | $QEMU_IO -c 'write -P 2 64k 192k' "$TEST_IMG" | _filter_qemu_io | |
61 | ||
62 | _launch_qemu -drive if=none,id=source,file="$TEST_IMG" | |
63 | ||
64 | _send_qemu_cmd $QEMU_HANDLE \ | |
65 | "{ 'execute': 'qmp_capabilities' }" \ | |
66 | 'return' | |
67 | ||
68 | # Create snapshot | |
6e6e55f5 | 69 | TEST_IMG="$TEST_IMG.overlay" _make_test_img -u -b "$TEST_IMG" 1M |
3dd48fdc HR |
70 | _send_qemu_cmd $QEMU_HANDLE \ |
71 | "{ 'execute': 'blockdev-snapshot-sync', | |
72 | 'arguments': { 'device': 'source', | |
73 | 'snapshot-file': '$TEST_IMG.overlay', | |
74 | 'format': '$IMGFMT', | |
75 | 'mode': 'existing' } }" \ | |
76 | 'return' | |
77 | ||
78 | # Write something to the snapshot | |
79 | _send_qemu_cmd $QEMU_HANDLE \ | |
80 | "{ 'execute': 'human-monitor-command', | |
81 | 'arguments': { 'command-line': | |
82 | 'qemu-io source \"write -P 3 128k 128k\"' } }" \ | |
83 | 'return' | |
84 | ||
85 | # Create target image | |
645acdc0 | 86 | TEST_IMG="$TEST_IMG.target.overlay" _make_test_img -u -b "$TEST_IMG.target" 1M |
3dd48fdc HR |
87 | |
88 | # Mirror snapshot | |
89 | _send_qemu_cmd $QEMU_HANDLE \ | |
90 | "{ 'execute': 'drive-mirror', | |
91 | 'arguments': { 'device': 'source', | |
92 | 'target': '$TEST_IMG.target.overlay', | |
93 | 'mode': 'existing', | |
94 | 'sync': 'top' } }" \ | |
95 | 'return' | |
96 | ||
97 | # Wait for convergence | |
98 | _send_qemu_cmd $QEMU_HANDLE \ | |
99 | '' \ | |
100 | 'BLOCK_JOB_READY' | |
101 | ||
102 | # Write some more | |
103 | _send_qemu_cmd $QEMU_HANDLE \ | |
104 | "{ 'execute': 'human-monitor-command', | |
105 | 'arguments': { 'command-line': | |
106 | 'qemu-io source \"write -P 4 192k 64k\"' } }" \ | |
107 | 'return' | |
108 | ||
109 | # Copy source backing chain to the target before completing the job | |
110 | cp "$TEST_IMG.backing" "$TEST_IMG.target.backing" | |
111 | cp "$TEST_IMG" "$TEST_IMG.target" | |
112 | $QEMU_IMG rebase -u -b "$TEST_IMG.target.backing" "$TEST_IMG.target" | |
113 | ||
114 | # Complete block job | |
115 | _send_qemu_cmd $QEMU_HANDLE \ | |
116 | "{ 'execute': 'block-job-complete', | |
117 | 'arguments': { 'device': 'source' } }" \ | |
118 | '' | |
119 | ||
120 | _send_qemu_cmd $QEMU_HANDLE \ | |
121 | '' \ | |
1dac83f1 | 122 | '"status": "null"' |
3dd48fdc HR |
123 | |
124 | # Remove the source images | |
125 | rm -f "$TEST_IMG{,.backing,.overlay}" | |
126 | ||
127 | echo | |
128 | ||
129 | # Check online disk contents | |
130 | _send_qemu_cmd $QEMU_HANDLE \ | |
131 | "{ 'execute': 'human-monitor-command', | |
132 | 'arguments': { 'command-line': | |
133 | 'qemu-io source \"read -P 1 0k 64k\"' } }" \ | |
134 | 'return' | |
135 | ||
136 | _send_qemu_cmd $QEMU_HANDLE \ | |
137 | "{ 'execute': 'human-monitor-command', | |
138 | 'arguments': { 'command-line': | |
139 | 'qemu-io source \"read -P 2 64k 64k\"' } }" \ | |
140 | 'return' | |
141 | ||
142 | _send_qemu_cmd $QEMU_HANDLE \ | |
143 | "{ 'execute': 'human-monitor-command', | |
144 | 'arguments': { 'command-line': | |
145 | 'qemu-io source \"read -P 3 128k 64k\"' } }" \ | |
146 | 'return' | |
147 | ||
148 | _send_qemu_cmd $QEMU_HANDLE \ | |
149 | "{ 'execute': 'human-monitor-command', | |
150 | 'arguments': { 'command-line': | |
151 | 'qemu-io source \"read -P 4 192k 64k\"' } }" \ | |
152 | 'return' | |
153 | ||
154 | echo | |
155 | ||
156 | _send_qemu_cmd $QEMU_HANDLE \ | |
157 | "{ 'execute': 'quit' }" \ | |
158 | 'return' | |
159 | ||
160 | wait=1 _cleanup_qemu | |
161 | ||
162 | echo | |
163 | ||
164 | # Check offline disk contents | |
165 | $QEMU_IO -c 'read -P 1 0k 64k' \ | |
166 | -c 'read -P 2 64k 64k' \ | |
167 | -c 'read -P 3 128k 64k' \ | |
168 | -c 'read -P 4 192k 64k' \ | |
169 | "$TEST_IMG.target.overlay" | _filter_qemu_io | |
170 | ||
171 | echo | |
172 | ||
173 | # success, all done | |
174 | echo '*** done' | |
175 | rm -f $seq.full | |
176 | status=0 |