xref: /openbmc/qemu/tests/qemu-iotests/249 (revision 138ca49a)
1#!/usr/bin/env bash
2#
3# Test that a backing image is put back in read-only mode after
4# block-commit (both when it fails and when it succeeds).
5#
6# Copyright (C) 2019 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
28status=1	# failure is the default!
29
30_cleanup()
31{
32    _cleanup_test_img
33    _rm_test_img "$TEST_IMG.base"
34    _rm_test_img "$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 fuse
46_supported_os Linux
47
48IMG_SIZE=1M
49
50# Create the images: base <- int <- active
51TEST_IMG="$TEST_IMG.base" _make_test_img $IMG_SIZE
52TEST_IMG="$TEST_IMG.int" _make_test_img -b "$TEST_IMG.base" -F $IMGFMT
53_make_test_img -b "$TEST_IMG.int" -F $IMGFMT
54
55# Launch QEMU with these two drives:
56# none0: base (read-only)
57# none1: base <- int <- active
58_launch_qemu -drive if=none,file="${TEST_IMG}.base",node-name=base,read-only=on \
59             -drive if=none,file="${TEST_IMG}",backing.node-name=int,backing.backing=base
60
61_send_qemu_cmd $QEMU_HANDLE \
62    "{ 'execute': 'qmp_capabilities' }" \
63    'return'
64
65echo
66echo '=== Send a write command to a drive opened in read-only mode (1)'
67echo
68_send_qemu_cmd $QEMU_HANDLE \
69    "{ 'execute': 'human-monitor-command',
70       'arguments': {'command-line': 'qemu-io none0 \"aio_write 0 2k\"'}}" \
71    'return'
72
73echo
74echo '=== Run block-commit on base using an invalid filter node name'
75echo
76_send_qemu_cmd $QEMU_HANDLE \
77    "{ 'execute': 'block-commit',
78       'arguments': {'job-id': 'job0', 'device': 'none1', 'top-node': 'int',
79                     'filter-node-name': '1234'}}" \
80    'error'
81
82echo
83echo '=== Send a write command to a drive opened in read-only mode (2)'
84echo
85_send_qemu_cmd $QEMU_HANDLE \
86    "{ 'execute': 'human-monitor-command',
87       'arguments': {'command-line': 'qemu-io none0 \"aio_write 0 2k\"'}}" \
88    'return'
89
90echo
91echo '=== Run block-commit on base using the default filter node name'
92echo
93_send_qemu_cmd $QEMU_HANDLE \
94    "{ 'execute': 'block-commit',
95       'arguments': {'job-id': 'job0', 'device': 'none1', 'top-node': 'int'}}" \
96    'return'
97
98# Wait for block-commit to finish
99_send_qemu_cmd $QEMU_HANDLE '' \
100    '"status": "null"'
101
102echo
103echo '=== Send a write command to a drive opened in read-only mode (3)'
104echo
105_send_qemu_cmd $QEMU_HANDLE \
106    "{ 'execute': 'human-monitor-command',
107       'arguments': {'command-line': 'qemu-io none0 \"aio_write 0 2k\"'}}" \
108    'return'
109
110_cleanup_qemu
111
112# success, all done
113echo "*** done"
114rm -f $seq.full
115status=0
116