xref: /openbmc/qemu/tests/qemu-iotests/191 (revision 7f709ce7)
1#!/bin/bash
2#
3# Test commit block job where top has two parents
4#
5# Copyright (C) 2017 Red Hat, Inc.
6#
7# This program is free software; you can redistribute it and/or modify
8# it under the terms of the GNU General Public License as published by
9# the Free Software Foundation; either version 2 of the License, or
10# (at your option) any later version.
11#
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15# GNU General Public License for more details.
16#
17# You should have received a copy of the GNU General Public License
18# along with this program.  If not, see <http://www.gnu.org/licenses/>.
19#
20
21# creator
22owner=kwolf@redhat.com
23
24seq=`basename $0`
25echo "QA output created by $seq"
26
27here=`pwd`
28status=1 # failure is the default!
29
30MIG_SOCKET="${TEST_DIR}/migrate"
31
32_cleanup()
33{
34    rm -f "${TEST_IMG}.mid"
35    rm -f "${TEST_IMG}.ovl2"
36    rm -f "${TEST_IMG}.ovl3"
37    _cleanup_test_img
38    _cleanup_qemu
39}
40trap "_cleanup; exit \$status" 0 1 2 3 15
41
42# get standard environment, filters and checks
43. ./common.rc
44. ./common.filter
45. ./common.qemu
46
47_supported_fmt qcow2
48_unsupported_imgopts compat=0.10
49_supported_proto file
50_supported_os Linux
51
52size=64M
53
54echo
55echo === Preparing and starting VM ===
56echo
57
58TEST_IMG="${TEST_IMG}.base" _make_test_img $size
59IMGOPTS=$(_optstr_add "$IMGOPTS" "backing_fmt=$IMGFMT") \
60    TEST_IMG="${TEST_IMG}.mid" _make_test_img -b "${TEST_IMG}.base"
61_make_test_img -b "${TEST_IMG}.mid"
62TEST_IMG="${TEST_IMG}.ovl2" _make_test_img -b "${TEST_IMG}.mid"
63
64$QEMU_IO -c 'write -P 0x55 1M 64k' "${TEST_IMG}.mid" | _filter_qemu_io
65
66qemu_comm_method="qmp"
67qmp_pretty="y"
68
69_launch_qemu \
70    -blockdev "driver=${IMGFMT},file.driver=file,file.filename=${TEST_IMG}.base,node-name=base" \
71    -blockdev "driver=${IMGFMT},file.driver=file,file.filename=${TEST_IMG}.mid,node-name=mid,backing=base" \
72    -blockdev "driver=${IMGFMT},file.driver=file,file.filename=${TEST_IMG},node-name=top,backing=mid" \
73    -blockdev "driver=${IMGFMT},file.driver=file,file.filename=${TEST_IMG}.ovl2,node-name=top2,backing=mid"
74h=$QEMU_HANDLE
75_send_qemu_cmd $h "{ 'execute': 'qmp_capabilities' }" '^}'
76
77echo
78echo === Perform commit job ===
79echo
80
81_send_qemu_cmd $h \
82    "{ 'execute': 'block-commit',
83       'arguments': { 'job-id': 'commit0',
84                      'device': 'top',
85                      'base':'$TEST_IMG.base',
86                      'top': '$TEST_IMG.mid' } }" \
87    "BLOCK_JOB_COMPLETED"
88_send_qemu_cmd $h "" "^}"
89
90echo
91echo === Check that both top and top2 point to base now ===
92echo
93
94_send_qemu_cmd $h "{ 'execute': 'query-named-block-nodes' }" "^}" |
95    _filter_generated_node_ids | _filter_actual_image_size
96
97_send_qemu_cmd $h "{ 'execute': 'quit' }" "^}"
98wait=1 _cleanup_qemu
99
100_img_info
101TEST_IMG="$TEST_IMG.ovl2" _img_info
102
103
104echo
105echo === Preparing and starting VM with -drive ===
106echo
107
108TEST_IMG="${TEST_IMG}.base" _make_test_img $size
109TEST_IMG="${TEST_IMG}.mid" _make_test_img -b "${TEST_IMG}.base"
110_make_test_img -b "${TEST_IMG}.mid"
111TEST_IMG="${TEST_IMG}.ovl2" _make_test_img -b "${TEST_IMG}.mid"
112TEST_IMG="${TEST_IMG}.ovl3" _make_test_img -b "${TEST_IMG}.ovl2"
113
114$QEMU_IO -c 'write -P 0x55 1M 64k' "${TEST_IMG}.mid" | _filter_qemu_io
115
116qemu_comm_method="qmp"
117qmp_pretty="y"
118
119_launch_qemu \
120    -drive "driver=${IMGFMT},file=${TEST_IMG},node-name=top,backing.node-name=mid" \
121    -drive "driver=${IMGFMT},file=${TEST_IMG}.ovl3,node-name=top2,backing.backing=mid"
122h=$QEMU_HANDLE
123_send_qemu_cmd $h "{ 'execute': 'qmp_capabilities' }" '^}'
124
125echo
126echo === Perform commit job ===
127echo
128
129_send_qemu_cmd $h \
130    "{ 'execute': 'block-commit',
131       'arguments': { 'job-id': 'commit0',
132                      'device': 'top',
133                      'base':'$TEST_IMG.base',
134                      'top': '$TEST_IMG.mid' } }" \
135    "BLOCK_JOB_COMPLETED"
136_send_qemu_cmd $h "" "^}"
137
138echo
139echo === Check that both top and top2 point to base now ===
140echo
141
142_send_qemu_cmd $h "{ 'execute': 'query-named-block-nodes' }" "^}" |
143    _filter_generated_node_ids | _filter_actual_image_size
144
145_send_qemu_cmd $h "{ 'execute': 'quit' }" "^}"
146wait=1 _cleanup_qemu
147
148_img_info
149TEST_IMG="$TEST_IMG.ovl2" _img_info
150
151# success, all done
152echo "*** done"
153rm -f $seq.full
154status=0
155