xref: /openbmc/qemu/tests/qemu-iotests/232 (revision 12efe428c9e01f3e195e3ae801cfd9c814ee777d)
111a82d14SPhilippe Mathieu-Daudé#!/usr/bin/env bash
236f808faSKevin Wolf#
336f808faSKevin Wolf# Test for auto-read-only
436f808faSKevin Wolf#
536f808faSKevin Wolf# Copyright (C) 2018 Red Hat, Inc.
636f808faSKevin Wolf#
736f808faSKevin Wolf# This program is free software; you can redistribute it and/or modify
836f808faSKevin Wolf# it under the terms of the GNU General Public License as published by
936f808faSKevin Wolf# the Free Software Foundation; either version 2 of the License, or
1036f808faSKevin Wolf# (at your option) any later version.
1136f808faSKevin Wolf#
1236f808faSKevin Wolf# This program is distributed in the hope that it will be useful,
1336f808faSKevin Wolf# but WITHOUT ANY WARRANTY; without even the implied warranty of
1436f808faSKevin Wolf# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1536f808faSKevin Wolf# GNU General Public License for more details.
1636f808faSKevin Wolf#
1736f808faSKevin Wolf# You should have received a copy of the GNU General Public License
1836f808faSKevin Wolf# along with this program.  If not, see <http://www.gnu.org/licenses/>.
1936f808faSKevin Wolf#
2036f808faSKevin Wolf
2136f808faSKevin Wolf# creator
2236f808faSKevin Wolfowner=kwolf@redhat.com
2336f808faSKevin Wolf
2436f808faSKevin Wolfseq=`basename $0`
2536f808faSKevin Wolfecho "QA output created by $seq"
2636f808faSKevin Wolf
2736f808faSKevin Wolfstatus=1	# failure is the default!
2836f808faSKevin Wolf
2936f808faSKevin Wolf_cleanup()
3036f808faSKevin Wolf{
3136f808faSKevin Wolf    _cleanup_test_img
32*12efe428SKevin Wolf    rm -f $TEST_IMG.[01234]
3336f808faSKevin Wolf}
3436f808faSKevin Wolftrap "_cleanup; exit \$status" 0 1 2 3 15
3536f808faSKevin Wolf
3636f808faSKevin Wolf# get standard environment, filters and checks
3736f808faSKevin Wolf. ./common.rc
3836f808faSKevin Wolf. ./common.filter
3936f808faSKevin Wolf
4036f808faSKevin Wolf_supported_fmt generic
4136f808faSKevin Wolf_supported_proto file
4236f808faSKevin Wolf_supported_os Linux
4336f808faSKevin Wolf
448cedcffdSEric Blakedo_run_qemu()
4536f808faSKevin Wolf{
4636f808faSKevin Wolf    echo Testing: "$@"
4736f808faSKevin Wolf    (
4836f808faSKevin Wolf        if ! test -t 0; then
4936f808faSKevin Wolf            while read cmd; do
5036f808faSKevin Wolf                echo $cmd
5136f808faSKevin Wolf            done
5236f808faSKevin Wolf        fi
5336f808faSKevin Wolf        echo quit
5436f808faSKevin Wolf    ) | $QEMU -nographic -monitor stdio -nodefaults "$@"
5536f808faSKevin Wolf    echo
5636f808faSKevin Wolf}
5736f808faSKevin Wolf
588cedcffdSEric Blakerun_qemu()
5936f808faSKevin Wolf{
6036f808faSKevin Wolf    do_run_qemu "$@" 2>&1 | _filter_testdir | _filter_qemu | _filter_hmp |
6136f808faSKevin Wolf        _filter_generated_node_ids | _filter_imgfmt
6236f808faSKevin Wolf}
6336f808faSKevin Wolf
648cedcffdSEric Blakerun_qemu_info_block()
6536f808faSKevin Wolf{
6636f808faSKevin Wolf    echo "info block -n" | run_qemu "$@" | grep -e "(file" -e "QEMU_PROG"
6736f808faSKevin Wolf}
6836f808faSKevin Wolf
6936f808faSKevin Wolfsize=128M
7036f808faSKevin Wolf
7136f808faSKevin Wolf_make_test_img $size
7236f808faSKevin Wolf
73c48221aaSMax Reitzif [ -n "$TEST_IMG_FILE" ]; then
74c48221aaSMax Reitz    TEST_IMG=$TEST_IMG_FILE
75c48221aaSMax Reitzfi
76c48221aaSMax Reitz
7736f808faSKevin Wolfecho
7836f808faSKevin Wolfecho "=== -drive with read-write image: read-only/auto-read-only combinations ==="
7936f808faSKevin Wolfecho
8036f808faSKevin Wolf
8136f808faSKevin Wolfrun_qemu_info_block -drive driver=file,file="$TEST_IMG",if=none,read-only=on,auto-read-only=off
8236f808faSKevin Wolfrun_qemu_info_block -drive driver=file,file="$TEST_IMG",if=none,read-only=on,auto-read-only=on
8336f808faSKevin Wolfrun_qemu_info_block -drive driver=file,file="$TEST_IMG",if=none,read-only=on
8436f808faSKevin Wolfecho
8536f808faSKevin Wolfrun_qemu_info_block -drive driver=file,file="$TEST_IMG",if=none,read-only=off,auto-read-only=off
8636f808faSKevin Wolfrun_qemu_info_block -drive driver=file,file="$TEST_IMG",if=none,read-only=off,auto-read-only=on
8736f808faSKevin Wolfrun_qemu_info_block -drive driver=file,file="$TEST_IMG",if=none,read-only=off
8836f808faSKevin Wolfecho
8936f808faSKevin Wolfrun_qemu_info_block -drive driver=file,file="$TEST_IMG",if=none,auto-read-only=off
9036f808faSKevin Wolfrun_qemu_info_block -drive driver=file,file="$TEST_IMG",if=none,auto-read-only=on
9136f808faSKevin Wolfrun_qemu_info_block -drive driver=file,file="$TEST_IMG",if=none
9236f808faSKevin Wolf
9336f808faSKevin Wolfecho
9436f808faSKevin Wolfecho "=== -drive with read-only image: read-only/auto-read-only combinations ==="
9536f808faSKevin Wolfecho
9636f808faSKevin Wolf
9736f808faSKevin Wolfchmod a-w $TEST_IMG
9836f808faSKevin Wolf
9936f808faSKevin Wolfrun_qemu_info_block -drive driver=file,file="$TEST_IMG",if=none,read-only=on,auto-read-only=off
10036f808faSKevin Wolfrun_qemu_info_block -drive driver=file,file="$TEST_IMG",if=none,read-only=on,auto-read-only=on
10136f808faSKevin Wolfrun_qemu_info_block -drive driver=file,file="$TEST_IMG",if=none,read-only=on
10236f808faSKevin Wolfecho
10336f808faSKevin Wolfrun_qemu_info_block -drive driver=file,file="$TEST_IMG",if=none,read-only=off,auto-read-only=off
10436f808faSKevin Wolfrun_qemu_info_block -drive driver=file,file="$TEST_IMG",if=none,read-only=off,auto-read-only=on
10536f808faSKevin Wolfrun_qemu_info_block -drive driver=file,file="$TEST_IMG",if=none,read-only=off
10636f808faSKevin Wolfecho
10736f808faSKevin Wolfrun_qemu_info_block -drive driver=file,file="$TEST_IMG",if=none,auto-read-only=off
10836f808faSKevin Wolfrun_qemu_info_block -drive driver=file,file="$TEST_IMG",if=none,auto-read-only=on
10936f808faSKevin Wolfrun_qemu_info_block -drive driver=file,file="$TEST_IMG",if=none
11036f808faSKevin Wolf
11136f808faSKevin Wolfecho
11236f808faSKevin Wolfecho "=== -blockdev with read-write image: read-only/auto-read-only combinations ==="
11336f808faSKevin Wolfecho
11436f808faSKevin Wolf
11536f808faSKevin Wolfchmod a+w $TEST_IMG
11636f808faSKevin Wolf
11736f808faSKevin Wolfrun_qemu_info_block -blockdev driver=file,filename="$TEST_IMG",node-name=node0,read-only=on,auto-read-only=off
11836f808faSKevin Wolfrun_qemu_info_block -blockdev driver=file,filename="$TEST_IMG",node-name=node0,read-only=on,auto-read-only=on
11936f808faSKevin Wolfrun_qemu_info_block -blockdev driver=file,filename="$TEST_IMG",node-name=node0,read-only=on
12036f808faSKevin Wolfecho
12136f808faSKevin Wolfrun_qemu_info_block -blockdev driver=file,filename="$TEST_IMG",node-name=node0,read-only=off,auto-read-only=off
12236f808faSKevin Wolfrun_qemu_info_block -blockdev driver=file,filename="$TEST_IMG",node-name=node0,read-only=off,auto-read-only=on
12336f808faSKevin Wolfrun_qemu_info_block -blockdev driver=file,filename="$TEST_IMG",node-name=node0,read-only=off
12436f808faSKevin Wolfecho
12536f808faSKevin Wolfrun_qemu_info_block -blockdev driver=file,filename="$TEST_IMG",node-name=node0,auto-read-only=off
12636f808faSKevin Wolfrun_qemu_info_block -blockdev driver=file,filename="$TEST_IMG",node-name=node0,auto-read-only=on
12736f808faSKevin Wolfrun_qemu_info_block -blockdev driver=file,filename="$TEST_IMG",node-name=node0
12836f808faSKevin Wolf
12936f808faSKevin Wolfecho
13036f808faSKevin Wolfecho "=== -blockdev with read-only image: read-only/auto-read-only combinations ==="
13136f808faSKevin Wolfecho
13236f808faSKevin Wolf
13336f808faSKevin Wolfchmod a-w $TEST_IMG
13436f808faSKevin Wolf
13536f808faSKevin Wolfrun_qemu_info_block -blockdev driver=file,filename="$TEST_IMG",node-name=node0,read-only=on,auto-read-only=off
13636f808faSKevin Wolfrun_qemu_info_block -blockdev driver=file,filename="$TEST_IMG",node-name=node0,read-only=on,auto-read-only=on
13736f808faSKevin Wolfrun_qemu_info_block -blockdev driver=file,filename="$TEST_IMG",node-name=node0,read-only=on
13836f808faSKevin Wolfecho
13936f808faSKevin Wolfrun_qemu_info_block -blockdev driver=file,filename="$TEST_IMG",node-name=node0,read-only=off,auto-read-only=off
14036f808faSKevin Wolfrun_qemu_info_block -blockdev driver=file,filename="$TEST_IMG",node-name=node0,read-only=off,auto-read-only=on
14136f808faSKevin Wolfrun_qemu_info_block -blockdev driver=file,filename="$TEST_IMG",node-name=node0,read-only=off
14236f808faSKevin Wolfecho
14336f808faSKevin Wolfrun_qemu_info_block -blockdev driver=file,filename="$TEST_IMG",node-name=node0,auto-read-only=off
14436f808faSKevin Wolfrun_qemu_info_block -blockdev driver=file,filename="$TEST_IMG",node-name=node0,auto-read-only=on
14536f808faSKevin Wolfrun_qemu_info_block -blockdev driver=file,filename="$TEST_IMG",node-name=node0
14636f808faSKevin Wolf
147*12efe428SKevin Wolfecho
148*12efe428SKevin Wolfecho "=== Try commit to backing file with auto-read-only ==="
149*12efe428SKevin Wolfecho
150*12efe428SKevin Wolf
151*12efe428SKevin WolfTEST_IMG="$TEST_IMG.0" _make_test_img $size
152*12efe428SKevin WolfTEST_IMG="$TEST_IMG.1" _make_test_img $size
153*12efe428SKevin WolfTEST_IMG="$TEST_IMG.2" _make_test_img $size
154*12efe428SKevin WolfTEST_IMG="$TEST_IMG.3" _make_test_img $size
155*12efe428SKevin WolfTEST_IMG="$TEST_IMG.4" _make_test_img $size
156*12efe428SKevin Wolf
157*12efe428SKevin Wolf(cat <<EOF
158*12efe428SKevin Wolf{"execute":"qmp_capabilities"}
159*12efe428SKevin Wolf{"execute":"block-commit",
160*12efe428SKevin Wolf "arguments":{"device":"format-4", "top-node": "format-2", "base-node":"format-0", "job-id":"job0"}}
161*12efe428SKevin WolfEOF
162*12efe428SKevin Wolfsleep 1
163*12efe428SKevin Wolfecho '{"execute":"quit"}'
164*12efe428SKevin Wolf) | $QEMU -qmp stdio -nographic -nodefaults \
165*12efe428SKevin Wolf    -blockdev file,node-name=file-0,filename=$TEST_IMG.0,auto-read-only=on \
166*12efe428SKevin Wolf    -blockdev qcow2,node-name=format-0,file=file-0,read-only=on \
167*12efe428SKevin Wolf    -blockdev file,node-name=file-1,filename=$TEST_IMG.1,auto-read-only=on \
168*12efe428SKevin Wolf    -blockdev qcow2,node-name=format-1,file=file-1,read-only=on,backing=format-0 \
169*12efe428SKevin Wolf    -blockdev file,node-name=file-2,filename=$TEST_IMG.2,auto-read-only=on \
170*12efe428SKevin Wolf    -blockdev qcow2,node-name=format-2,file=file-2,read-only=on,backing=format-1 \
171*12efe428SKevin Wolf    -blockdev file,node-name=file-3,filename=$TEST_IMG.3,auto-read-only=on \
172*12efe428SKevin Wolf    -blockdev qcow2,node-name=format-3,file=file-3,read-only=on,backing=format-2 \
173*12efe428SKevin Wolf    -blockdev file,node-name=file-4,filename=$TEST_IMG.4,auto-read-only=on \
174*12efe428SKevin Wolf    -blockdev qcow2,node-name=format-4,file=file-4,read-only=on,backing=format-3 |
175*12efe428SKevin Wolf    _filter_qmp
176*12efe428SKevin Wolf
17736f808faSKevin Wolf# success, all done
17836f808faSKevin Wolfecho "*** done"
17936f808faSKevin Wolfrm -f $seq.full
18036f808faSKevin Wolfstatus=0
181