xref: /openbmc/qemu/tests/qemu-iotests/161 (revision 0065c455f9f03ef5e830ede804a7404a8892fbc7)
1*0065c455SAlberto Garcia#!/bin/bash
2*0065c455SAlberto Garcia#
3*0065c455SAlberto Garcia# Test reopening a backing image after block-stream
4*0065c455SAlberto Garcia#
5*0065c455SAlberto Garcia# Copyright (C) 2018 Igalia, S.L.
6*0065c455SAlberto Garcia#
7*0065c455SAlberto Garcia# This program is free software; you can redistribute it and/or modify
8*0065c455SAlberto Garcia# it under the terms of the GNU General Public License as published by
9*0065c455SAlberto Garcia# the Free Software Foundation; either version 2 of the License, or
10*0065c455SAlberto Garcia# (at your option) any later version.
11*0065c455SAlberto Garcia#
12*0065c455SAlberto Garcia# This program is distributed in the hope that it will be useful,
13*0065c455SAlberto Garcia# but WITHOUT ANY WARRANTY; without even the implied warranty of
14*0065c455SAlberto Garcia# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15*0065c455SAlberto Garcia# GNU General Public License for more details.
16*0065c455SAlberto Garcia#
17*0065c455SAlberto Garcia# You should have received a copy of the GNU General Public License
18*0065c455SAlberto Garcia# along with this program.  If not, see <http://www.gnu.org/licenses/>.
19*0065c455SAlberto Garcia#
20*0065c455SAlberto Garcia
21*0065c455SAlberto Garcia# creator
22*0065c455SAlberto Garciaowner=berto@igalia.com
23*0065c455SAlberto Garcia
24*0065c455SAlberto Garciaseq=`basename $0`
25*0065c455SAlberto Garciaecho "QA output created by $seq"
26*0065c455SAlberto Garcia
27*0065c455SAlberto Garciahere=`pwd`
28*0065c455SAlberto Garciastatus=1	# failure is the default!
29*0065c455SAlberto Garcia
30*0065c455SAlberto Garcia_cleanup()
31*0065c455SAlberto Garcia{
32*0065c455SAlberto Garcia    _cleanup_test_img
33*0065c455SAlberto Garcia    rm -f "$TEST_IMG.base"
34*0065c455SAlberto Garcia    rm -f "$TEST_IMG.int"
35*0065c455SAlberto Garcia}
36*0065c455SAlberto Garciatrap "_cleanup; exit \$status" 0 1 2 3 15
37*0065c455SAlberto Garcia
38*0065c455SAlberto Garcia# get standard environment, filters and checks
39*0065c455SAlberto Garcia. ./common.rc
40*0065c455SAlberto Garcia. ./common.filter
41*0065c455SAlberto Garcia. ./common.qemu
42*0065c455SAlberto Garcia
43*0065c455SAlberto Garcia# Any format implementing BlockDriver.bdrv_change_backing_file
44*0065c455SAlberto Garcia_supported_fmt qcow2 qed
45*0065c455SAlberto Garcia_supported_proto file
46*0065c455SAlberto Garcia_supported_os Linux
47*0065c455SAlberto Garcia
48*0065c455SAlberto GarciaIMG_SIZE=1M
49*0065c455SAlberto Garcia
50*0065c455SAlberto Garcia# Create the images
51*0065c455SAlberto GarciaTEST_IMG="$TEST_IMG.base" _make_test_img $IMG_SIZE | _filter_imgfmt
52*0065c455SAlberto GarciaTEST_IMG="$TEST_IMG.int" _make_test_img -b "$TEST_IMG.base" | _filter_imgfmt
53*0065c455SAlberto Garcia_make_test_img -b "$TEST_IMG.int" | _filter_imgfmt
54*0065c455SAlberto Garcia
55*0065c455SAlberto Garcia# First test: reopen $TEST.IMG changing the detect-zeroes option on
56*0065c455SAlberto Garcia# its backing file ($TEST_IMG.int).
57*0065c455SAlberto Garciaecho
58*0065c455SAlberto Garciaecho "*** Change an option on the backing file"
59*0065c455SAlberto Garciaecho
60*0065c455SAlberto Garcia_launch_qemu -drive if=none,file="${TEST_IMG}"
61*0065c455SAlberto Garcia_send_qemu_cmd $QEMU_HANDLE \
62*0065c455SAlberto Garcia    "{ 'execute': 'qmp_capabilities' }" \
63*0065c455SAlberto Garcia    'return'
64*0065c455SAlberto Garcia
65*0065c455SAlberto Garcia_send_qemu_cmd $QEMU_HANDLE \
66*0065c455SAlberto Garcia    "{ 'execute': 'human-monitor-command',
67*0065c455SAlberto Garcia       'arguments': { 'command-line':
68*0065c455SAlberto Garcia                      'qemu-io none0 \"reopen -o backing.detect-zeroes=on\"' } }" \
69*0065c455SAlberto Garcia    "return"
70*0065c455SAlberto Garcia
71*0065c455SAlberto Garcia_cleanup_qemu
72*0065c455SAlberto Garcia
73*0065c455SAlberto Garcia# Second test: stream $TEST_IMG.base into $TEST_IMG.int and then
74*0065c455SAlberto Garcia# reopen $TEST.IMG changing the detect-zeroes option on its new
75*0065c455SAlberto Garcia# backing file ($TEST_IMG.base).
76*0065c455SAlberto Garciaecho
77*0065c455SAlberto Garciaecho "*** Stream and then change an option on the backing file"
78*0065c455SAlberto Garciaecho
79*0065c455SAlberto Garcia_launch_qemu -drive if=none,file="${TEST_IMG}"
80*0065c455SAlberto Garcia_send_qemu_cmd $QEMU_HANDLE \
81*0065c455SAlberto Garcia    "{ 'execute': 'qmp_capabilities' }" \
82*0065c455SAlberto Garcia    'return'
83*0065c455SAlberto Garcia
84*0065c455SAlberto Garcia_send_qemu_cmd $QEMU_HANDLE \
85*0065c455SAlberto Garcia    "{ 'execute': 'block-stream', \
86*0065c455SAlberto Garcia       'arguments': { 'device': 'none0',
87*0065c455SAlberto Garcia                      'base': '${TEST_IMG}.base' } }" \
88*0065c455SAlberto Garcia    'return'
89*0065c455SAlberto Garcia
90*0065c455SAlberto Garcia# Wait for block-stream to finish
91*0065c455SAlberto Garciasleep 0.5
92*0065c455SAlberto Garcia
93*0065c455SAlberto Garcia_send_qemu_cmd $QEMU_HANDLE \
94*0065c455SAlberto Garcia    "{ 'execute': 'human-monitor-command',
95*0065c455SAlberto Garcia       'arguments': { 'command-line':
96*0065c455SAlberto Garcia                      'qemu-io none0 \"reopen -o backing.detect-zeroes=on\"' } }" \
97*0065c455SAlberto Garcia    "return"
98*0065c455SAlberto Garcia
99*0065c455SAlberto Garcia_cleanup_qemu
100*0065c455SAlberto Garcia
101*0065c455SAlberto Garcia# success, all done
102*0065c455SAlberto Garciaecho "*** done"
103*0065c455SAlberto Garciarm -f $seq.full
104*0065c455SAlberto Garciastatus=0
105