xref: /openbmc/qemu/tests/qemu-iotests/161 (revision e9e51b71)
1#!/usr/bin/env bash
2# group: rw auto quick
3#
4# Test reopening a backing image after block-stream and block-commit
5#
6# Copyright (C) 2018 Igalia, S.L.
7#
8# This program is free software; you can redistribute it and/or modify
9# it under the terms of the GNU General Public License as published by
10# the Free Software Foundation; either version 2 of the License, or
11# (at your option) any later version.
12#
13# This program is distributed in the hope that it will be useful,
14# but WITHOUT ANY WARRANTY; without even the implied warranty of
15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16# GNU General Public License for more details.
17#
18# You should have received a copy of the GNU General Public License
19# along with this program.  If not, see <http://www.gnu.org/licenses/>.
20#
21
22# creator
23owner=berto@igalia.com
24
25seq=`basename $0`
26echo "QA output created by $seq"
27
28here=`pwd`
29status=1	# failure is the default!
30
31_cleanup()
32{
33    _cleanup_test_img
34    _rm_test_img "$TEST_IMG.base"
35    _rm_test_img "$TEST_IMG.int"
36}
37trap "_cleanup; exit \$status" 0 1 2 3 15
38
39# get standard environment, filters and checks
40. ./common.rc
41. ./common.filter
42. ./common.qemu
43
44# Any format implementing BlockDriver.bdrv_change_backing_file
45_supported_fmt qcow2 qed
46_supported_proto file fuse
47_supported_os Linux
48
49IMG_SIZE=1M
50
51# Create the images
52TEST_IMG="$TEST_IMG.base" _make_test_img $IMG_SIZE
53TEST_IMG="$TEST_IMG.int" _make_test_img -b "$TEST_IMG.base" -F $IMGFMT
54_make_test_img -b "$TEST_IMG.int" -F $IMGFMT -F $IMGFMT
55
56# First test: reopen $TEST.IMG changing the detect-zeroes option on
57# its backing file ($TEST_IMG.int).
58echo
59echo "*** Change an option on the backing file"
60echo
61_launch_qemu -drive if=none,file="${TEST_IMG}"
62_send_qemu_cmd $QEMU_HANDLE \
63    "{ 'execute': 'qmp_capabilities' }" \
64    'return'
65
66_send_qemu_cmd $QEMU_HANDLE \
67    "{ 'execute': 'human-monitor-command',
68       'arguments': { 'command-line':
69                      'qemu-io none0 \"reopen -o backing.detect-zeroes=on\"' } }" \
70    "return"
71
72_cleanup_qemu
73
74# Second test: stream $TEST_IMG.base into $TEST_IMG.int and then
75# reopen $TEST.IMG changing the detect-zeroes option on its new
76# backing file ($TEST_IMG.base).
77echo
78echo "*** Stream and then change an option on the backing file"
79echo
80_launch_qemu -drive if=none,file="${TEST_IMG}"
81_send_qemu_cmd $QEMU_HANDLE \
82    "{ 'execute': 'qmp_capabilities' }" \
83    'return'
84
85_send_qemu_cmd $QEMU_HANDLE \
86    "{ 'execute': 'block-stream', \
87       'arguments': { 'device': 'none0',
88                      'base': '${TEST_IMG}.base' } }" \
89    'return'
90
91# Wait for block-stream to finish
92sleep 0.5
93
94_send_qemu_cmd $QEMU_HANDLE \
95    "{ 'execute': 'human-monitor-command',
96       'arguments': { 'command-line':
97                      'qemu-io none0 \"reopen -o backing.detect-zeroes=on\"' } }" \
98    "return"
99
100_cleanup_qemu
101
102# Third test: commit $TEST_IMG.int into $TEST_IMG.base and then reopen
103# $TEST.IMG changing the detect-zeroes option on its new backing file
104# ($TEST_IMG.base).
105echo
106echo "*** Commit and then change an option on the backing file"
107echo
108# Create the images again
109TEST_IMG="$TEST_IMG.base" _make_test_img $IMG_SIZE
110TEST_IMG="$TEST_IMG.int" _make_test_img -b "$TEST_IMG.base" -F $IMGFMT
111_make_test_img -b "$TEST_IMG.int" -F $IMGFMT
112
113_launch_qemu -drive if=none,file="${TEST_IMG}"
114_send_qemu_cmd $QEMU_HANDLE \
115    "{ 'execute': 'qmp_capabilities' }" \
116    'return'
117
118_send_qemu_cmd $QEMU_HANDLE \
119    "{ 'execute': 'block-commit', \
120       'arguments': { 'device': 'none0',
121                      'top': '${TEST_IMG}.int' } }" \
122    'return'
123
124# Wait for block-commit to finish
125sleep 0.5
126
127_send_qemu_cmd $QEMU_HANDLE \
128    "{ 'execute': 'human-monitor-command',
129       'arguments': { 'command-line':
130                      'qemu-io none0 \"reopen -o backing.detect-zeroes=on\"' } }" \
131    "return"
132
133_cleanup_qemu
134
135# success, all done
136echo "*** done"
137rm -f $seq.full
138status=0
139