xref: /openbmc/qemu/tests/qemu-iotests/249 (revision 7c08eefc)
1#!/usr/bin/env bash
2# group: rw auto quick
3#
4# Test that a backing image is put back in read-only mode after
5# block-commit (both when it fails and when it succeeds).
6#
7# Copyright (C) 2019 Igalia, S.L.
8#
9# This program is free software; you can redistribute it and/or modify
10# it under the terms of the GNU General Public License as published by
11# the Free Software Foundation; either version 2 of the License, or
12# (at your option) any later version.
13#
14# This program is distributed in the hope that it will be useful,
15# but WITHOUT ANY WARRANTY; without even the implied warranty of
16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17# GNU General Public License for more details.
18#
19# You should have received a copy of the GNU General Public License
20# along with this program.  If not, see <http://www.gnu.org/licenses/>.
21#
22
23# creator
24owner=berto@igalia.com
25
26seq="$(basename $0)"
27echo "QA output created by $seq"
28
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: base <- int <- active
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
55
56# Launch QEMU with these two drives:
57# none0: base (read-only)
58# none1: base <- int <- active
59_launch_qemu -drive if=none,file="${TEST_IMG}.base",node-name=base,read-only=on \
60             -drive if=none,file="${TEST_IMG}",backing.node-name=int,backing.backing=base
61
62_send_qemu_cmd $QEMU_HANDLE \
63    "{ 'execute': 'qmp_capabilities' }" \
64    'return'
65
66echo
67echo '=== Send a write command to a drive opened in read-only mode (1)'
68echo
69_send_qemu_cmd $QEMU_HANDLE \
70    "{ 'execute': 'human-monitor-command',
71       'arguments': {'command-line': 'qemu-io none0 \"aio_write 0 2k\"'}}" \
72    'return'
73
74echo
75echo '=== Run block-commit on base using an invalid filter node name'
76echo
77_send_qemu_cmd $QEMU_HANDLE \
78    "{ 'execute': 'block-commit',
79       'arguments': {'job-id': 'job0', 'device': 'none1', 'top-node': 'int',
80                     'filter-node-name': '1234'}}" \
81    'error'
82
83echo
84echo '=== Send a write command to a drive opened in read-only mode (2)'
85echo
86_send_qemu_cmd $QEMU_HANDLE \
87    "{ 'execute': 'human-monitor-command',
88       'arguments': {'command-line': 'qemu-io none0 \"aio_write 0 2k\"'}}" \
89    'return'
90
91echo
92echo '=== Run block-commit on base using the default filter node name'
93echo
94_send_qemu_cmd $QEMU_HANDLE \
95    "{ 'execute': 'block-commit',
96       'arguments': {'job-id': 'job0', 'device': 'none1', 'top-node': 'int'}}" \
97    'return'
98
99# Wait for block-commit to finish
100_send_qemu_cmd $QEMU_HANDLE '' \
101    '"status": "null"'
102
103echo
104echo '=== Send a write command to a drive opened in read-only mode (3)'
105echo
106_send_qemu_cmd $QEMU_HANDLE \
107    "{ 'execute': 'human-monitor-command',
108       'arguments': {'command-line': 'qemu-io none0 \"aio_write 0 2k\"'}}" \
109    'return'
110
111_cleanup_qemu
112
113# success, all done
114echo "*** done"
115rm -f $seq.full
116status=0
117