xref: /openbmc/qemu/tests/qemu-iotests/161 (revision 24496b8d)
1#!/usr/bin/env bash
2#
3# Test reopening a backing image after block-stream and block-commit
4#
5# Copyright (C) 2018 Igalia, S.L.
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=berto@igalia.com
23
24seq=`basename $0`
25echo "QA output created by $seq"
26
27here=`pwd`
28status=1	# failure is the default!
29
30_cleanup()
31{
32    _cleanup_test_img
33    rm -f "$TEST_IMG.base"
34    rm -f "$TEST_IMG.int"
35}
36trap "_cleanup; exit \$status" 0 1 2 3 15
37
38# get standard environment, filters and checks
39. ./common.rc
40. ./common.filter
41. ./common.qemu
42
43# Any format implementing BlockDriver.bdrv_change_backing_file
44_supported_fmt qcow2 qed
45_supported_proto file
46_supported_os Linux
47
48IMG_SIZE=1M
49
50# Create the images
51TEST_IMG="$TEST_IMG.base" _make_test_img $IMG_SIZE | _filter_imgfmt
52TEST_IMG="$TEST_IMG.int" _make_test_img -b "$TEST_IMG.base" | _filter_imgfmt
53_make_test_img -b "$TEST_IMG.int" | _filter_imgfmt
54
55# First test: reopen $TEST.IMG changing the detect-zeroes option on
56# its backing file ($TEST_IMG.int).
57echo
58echo "*** Change an option on the backing file"
59echo
60_launch_qemu -drive if=none,file="${TEST_IMG}"
61_send_qemu_cmd $QEMU_HANDLE \
62    "{ 'execute': 'qmp_capabilities' }" \
63    'return'
64
65_send_qemu_cmd $QEMU_HANDLE \
66    "{ 'execute': 'human-monitor-command',
67       'arguments': { 'command-line':
68                      'qemu-io none0 \"reopen -o backing.detect-zeroes=on\"' } }" \
69    "return"
70
71_cleanup_qemu
72
73# Second test: stream $TEST_IMG.base into $TEST_IMG.int and then
74# reopen $TEST.IMG changing the detect-zeroes option on its new
75# backing file ($TEST_IMG.base).
76echo
77echo "*** Stream and then change an option on the backing file"
78echo
79_launch_qemu -drive if=none,file="${TEST_IMG}"
80_send_qemu_cmd $QEMU_HANDLE \
81    "{ 'execute': 'qmp_capabilities' }" \
82    'return'
83
84_send_qemu_cmd $QEMU_HANDLE \
85    "{ 'execute': 'block-stream', \
86       'arguments': { 'device': 'none0',
87                      'base': '${TEST_IMG}.base' } }" \
88    'return'
89
90# Wait for block-stream to finish
91sleep 0.5
92
93_send_qemu_cmd $QEMU_HANDLE \
94    "{ 'execute': 'human-monitor-command',
95       'arguments': { 'command-line':
96                      'qemu-io none0 \"reopen -o backing.detect-zeroes=on\"' } }" \
97    "return"
98
99_cleanup_qemu
100
101# Third test: commit $TEST_IMG.int into $TEST_IMG.base and then reopen
102# $TEST.IMG changing the detect-zeroes option on its new backing file
103# ($TEST_IMG.base).
104echo
105echo "*** Commit and then change an option on the backing file"
106echo
107# Create the images again
108TEST_IMG="$TEST_IMG.base" _make_test_img $IMG_SIZE | _filter_imgfmt
109TEST_IMG="$TEST_IMG.int" _make_test_img -b "$TEST_IMG.base" | _filter_imgfmt
110_make_test_img -b "$TEST_IMG.int" | _filter_imgfmt
111
112_launch_qemu -drive if=none,file="${TEST_IMG}"
113_send_qemu_cmd $QEMU_HANDLE \
114    "{ 'execute': 'qmp_capabilities' }" \
115    'return'
116
117_send_qemu_cmd $QEMU_HANDLE \
118    "{ 'execute': 'block-commit', \
119       'arguments': { 'device': 'none0',
120                      'top': '${TEST_IMG}.int' } }" \
121    'return'
122
123# Wait for block-commit to finish
124sleep 0.5
125
126_send_qemu_cmd $QEMU_HANDLE \
127    "{ 'execute': 'human-monitor-command',
128       'arguments': { 'command-line':
129                      'qemu-io none0 \"reopen -o backing.detect-zeroes=on\"' } }" \
130    "return"
131
132_cleanup_qemu
133
134# success, all done
135echo "*** done"
136rm -f $seq.full
137status=0
138