OSDN Git Service

iotests: Test active commit with iothread and background I/O
[qmiga/qemu.git] / tests / qemu-iotests / 249
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
24 owner=berto@igalia.com
25
26 seq="$(basename $0)"
27 echo "QA output created by $seq"
28
29 status=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 }
37 trap "_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
49 IMG_SIZE=1M
50
51 # Create the images: base <- int <- active
52 TEST_IMG="$TEST_IMG.base" _make_test_img $IMG_SIZE
53 TEST_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
66 echo
67 echo '=== Send a write command to a drive opened in read-only mode (1)'
68 echo
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
74 echo
75 echo '=== Run block-commit on base using an invalid filter node name'
76 echo
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
83 echo
84 echo '=== Send a write command to a drive opened in read-only mode (2)'
85 echo
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
91 echo
92 echo '=== Run block-commit on base using the default filter node name'
93 echo
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
103 echo
104 echo '=== Send a write command to a drive opened in read-only mode (3)'
105 echo
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
114 echo "*** done"
115 rm -f $seq.full
116 status=0