master
text 117 lines 3.29 KB
Raw
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 _require_hmp
49
50 IMG_SIZE=1M
51
52 # Create the images: base <- int <- active
53 TEST_IMG="$TEST_IMG.base" _make_test_img $IMG_SIZE
54 TEST_IMG="$TEST_IMG.int" _make_test_img -b "$TEST_IMG.base" -F $IMGFMT
55 _make_test_img -b "$TEST_IMG.int" -F $IMGFMT
56
57 # Launch QEMU with these two drives:
58 # none0: base (read-only)
59 # none1: base <- int <- active
60 _launch_qemu -drive if=none,file="${TEST_IMG}.base",node-name=base,read-only=on \
61 -drive if=none,file="${TEST_IMG}",backing.node-name=int,backing.backing=base
62
63 _send_qemu_cmd $QEMU_HANDLE \
64 "{ 'execute': 'qmp_capabilities' }" \
65 'return'
66
67 echo
68 echo '=== Send a write command to a drive opened in read-only mode (1)'
69 echo
70 _send_qemu_cmd $QEMU_HANDLE \
71 "{ 'execute': 'human-monitor-command',
72 'arguments': {'command-line': 'qemu-io none0 \"aio_write 0 2k\"'}}" \
73 'return'
74
75 echo
76 echo '=== Run block-commit on base using an invalid filter node name'
77 echo
78 _send_qemu_cmd $QEMU_HANDLE \
79 "{ 'execute': 'block-commit',
80 'arguments': {'job-id': 'job0', 'device': 'none1', 'top-node': 'int',
81 'filter-node-name': '1234'}}" \
82 'error'
83
84 echo
85 echo '=== Send a write command to a drive opened in read-only mode (2)'
86 echo
87 _send_qemu_cmd $QEMU_HANDLE \
88 "{ 'execute': 'human-monitor-command',
89 'arguments': {'command-line': 'qemu-io none0 \"aio_write 0 2k\"'}}" \
90 'return'
91
92 echo
93 echo '=== Run block-commit on base using the default filter node name'
94 echo
95 _send_qemu_cmd $QEMU_HANDLE \
96 "{ 'execute': 'block-commit',
97 'arguments': {'job-id': 'job0', 'device': 'none1', 'top-node': 'int'}}" \
98 'return'
99
100 # Wait for block-commit to finish
101 _send_qemu_cmd $QEMU_HANDLE '' \
102 '"status": "null"'
103
104 echo
105 echo '=== Send a write command to a drive opened in read-only mode (3)'
106 echo
107 _send_qemu_cmd $QEMU_HANDLE \
108 "{ 'execute': 'human-monitor-command',
109 'arguments': {'command-line': 'qemu-io none0 \"aio_write 0 2k\"'}}" \
110 'return'
111
112 _cleanup_qemu
113
114 # success, all done
115 echo "*** done"
116 rm -f $seq.full
117 status=0