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