xref: /openbmc/qemu/tests/qemu-iotests/247 (revision ddda3748)
1#!/usr/bin/env bash
2#
3# Test for auto-read-only with commit block job
4#
5# Copyright (C) 2019 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
27status=1	# failure is the default!
28
29_cleanup()
30{
31    _cleanup_test_img
32    for img in "$TEST_IMG".[01234]; do
33        _rm_test_img "$img"
34    done
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
42# Requires backing files and .bdrv_change_backing_file support
43_supported_fmt qcow2 qed
44_supported_proto file
45
46size=128M
47
48echo
49echo "=== Try commit to backing file with auto-read-only ==="
50echo
51TEST_IMG="$TEST_IMG.0" _make_test_img $size
52TEST_IMG="$TEST_IMG.1" _make_test_img $size
53TEST_IMG="$TEST_IMG.2" _make_test_img $size
54TEST_IMG="$TEST_IMG.3" _make_test_img $size
55TEST_IMG="$TEST_IMG.4" _make_test_img $size
56
57(cat <<EOF
58{"execute":"qmp_capabilities"}
59{"execute":"block-commit",
60 "arguments":{"device":"format-4", "top-node": "format-2", "base-node":"format-0", "job-id":"job0"}}
61EOF
62if [ "${VALGRIND_QEMU}" == "y" ]; then
63    sleep 10
64else
65    sleep 1
66fi
67echo '{"execute":"quit"}'
68) | $QEMU -qmp stdio -nographic -nodefaults \
69    -blockdev file,node-name=file-0,filename=$TEST_IMG.0,auto-read-only=on \
70    -blockdev $IMGFMT,node-name=format-0,file=file-0,read-only=on \
71    -blockdev file,node-name=file-1,filename=$TEST_IMG.1,auto-read-only=on \
72    -blockdev $IMGFMT,node-name=format-1,file=file-1,read-only=on,backing=format-0 \
73    -blockdev file,node-name=file-2,filename=$TEST_IMG.2,auto-read-only=on \
74    -blockdev $IMGFMT,node-name=format-2,file=file-2,read-only=on,backing=format-1 \
75    -blockdev file,node-name=file-3,filename=$TEST_IMG.3,auto-read-only=on \
76    -blockdev $IMGFMT,node-name=format-3,file=file-3,read-only=on,backing=format-2 \
77    -blockdev file,node-name=file-4,filename=$TEST_IMG.4,auto-read-only=on \
78    -blockdev $IMGFMT,node-name=format-4,file=file-4,read-only=on,backing=format-3 |
79    _filter_qmp
80
81# success, all done
82echo "*** done"
83rm -f $seq.full
84status=0
85