Merge tag 'v9.0.0-rc3'
[qemu/ar7.git] / tests / qemu-iotests / tests / file-io-error
blobfb8db73b31b8755dae25ffcaaec2d081af5c8d73
1 #!/usr/bin/env bash
2 # group: rw
4 # Produce an I/O error in file-posix, and hope that it is not catastrophic.
5 # Regression test for: https://bugzilla.redhat.com/show_bug.cgi?id=2234374
7 # Copyright (C) 2023 Red Hat, Inc.
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.
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.
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/>.
23 seq=$(basename "$0")
24 echo "QA output created by $seq"
26 status=1 # failure is the default!
28 _cleanup()
30 _cleanup_qemu
31 rm -f "$TEST_DIR/fuse-export"
33 trap "_cleanup; exit \$status" 0 1 2 3 15
35 # get standard environment, filters and checks
36 . ../common.rc
37 . ../common.filter
38 . ../common.qemu
40 # Format-agnostic (we do not use any), but we do test the file protocol
41 _supported_proto file
42 _require_drivers blkdebug null-co
44 if [ "$IMGOPTSSYNTAX" = "true" ]; then
45 # We need `$QEMU_IO -f file` to work; IMGOPTSSYNTAX uses --image-opts,
46 # breaking -f.
47 _unsupported_fmt $IMGFMT
50 # This is a regression test of a bug in which flie-posix would access zone
51 # information in case of an I/O error even when there is no zone information,
52 # resulting in a division by zero.
53 # To reproduce the problem, we need to trigger an I/O error inside of
54 # file-posix, which can be done (rootless) by providing a FUSE export that
55 # presents only errors when accessed.
57 _launch_qemu
58 _send_qemu_cmd $QEMU_HANDLE \
59 "{'execute': 'qmp_capabilities'}" \
60 'return'
62 _send_qemu_cmd $QEMU_HANDLE \
63 "{'execute': 'blockdev-add',
64 'arguments': {
65 'driver': 'blkdebug',
66 'node-name': 'node0',
67 'inject-error': [{'event': 'none'}],
68 'image': {
69 'driver': 'null-co'
71 }}" \
72 'return'
74 # FUSE mountpoint must exist and be a regular file
75 touch "$TEST_DIR/fuse-export"
77 # The grep -v to filter fusermount's (benign) error when /etc/fuse.conf does
78 # not contain user_allow_other and the subsequent check for missing FUSE support
79 # have both been taken from iotest 308.
80 output=$(_send_qemu_cmd $QEMU_HANDLE \
81 "{'execute': 'block-export-add',
82 'arguments': {
83 'id': 'exp0',
84 'type': 'fuse',
85 'node-name': 'node0',
86 'mountpoint': '$TEST_DIR/fuse-export',
87 'writable': true
88 }}" \
89 'return' \
90 | grep -v 'option allow_other only allowed if')
92 if echo "$output" | grep -q "Parameter 'type' does not accept value 'fuse'"; then
93 _notrun 'No FUSE support'
95 echo "$output"
97 echo
98 # This should fail, but gracefully, i.e. just print an I/O error, not crash.
99 $QEMU_IO -f file -c 'write 0 64M' "$TEST_DIR/fuse-export" | _filter_qemu_io
100 echo
102 capture_events=BLOCK_EXPORT_DELETED _send_qemu_cmd $QEMU_HANDLE \
103 "{'execute': 'block-export-del',
104 'arguments': {'id': 'exp0'}}" \
105 'return'
107 _wait_event $QEMU_HANDLE \
108 'BLOCK_EXPORT_DELETED'
110 _send_qemu_cmd $QEMU_HANDLE \
111 "{'execute': 'blockdev-del',
112 'arguments': {'node-name': 'node0'}}" \
113 'return'
115 # success, all done
116 echo "*** done"
117 rm -f $seq.full
118 status=0