master
text 96 lines 2.11 KB
Raw
1 #!/usr/bin/env bash
2 # group: rw quick
3 #
4 # Test that opening O_DIRECT succeeds when image file I/O produces EIO
5 #
6 # Copyright (C) 2015 Red Hat, Inc.
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
23 owner=stefanha@redhat.com
24
25 seq=`basename $0`
26 echo "QA output created by $seq"
27
28 status=1 # failure is the default!
29
30 devname="eiodev$$"
31 sudo=""
32
33 _sudo_qemu_io_wrapper()
34 {
35 (exec $sudo "$QEMU_IO_PROG" $QEMU_IO_OPTIONS "$@")
36 }
37
38 _setup_eiodev()
39 {
40 # This test should either be run as root or with passwordless sudo
41 for cmd in "" "sudo -n"; do
42 echo "0 $((1024 * 1024 * 1024 / 512)) error" | \
43 $cmd dmsetup create "$devname" 2>/dev/null
44 if [ "$?" -eq 0 ]; then
45 DEV="/dev/mapper/$devname"
46 if ! -e $DEV
47 then
48 _notrun "Device $DEV not appearing"
49 fi
50
51 sudo="$cmd"
52 return
53 fi
54 done
55 _notrun "root privileges required to run dmsetup"
56 }
57
58 _cleanup_eiodev()
59 {
60 for cmd in "" "sudo -n"; do
61 $cmd dmsetup remove "$devname" 2>/dev/null
62 if [ "$?" -eq 0 ]; then
63 return
64 fi
65 done
66 }
67
68 _cleanup()
69 {
70 _cleanup_eiodev
71 }
72 trap "_cleanup; exit \$status" 0 1 2 3 15
73
74 # get standard environment, filters and checks
75 . ./common.rc
76 . ./common.filter
77
78 _supported_fmt raw
79 _supported_proto file
80 _supported_os Linux
81
82 _setup_eiodev
83
84 TEST_IMG="/dev/mapper/$devname"
85
86 echo
87 echo "== reading from error device =="
88 # Opening image should succeed but the read operation should fail
89 _sudo_qemu_io_wrapper --format "$IMGFMT" --nocache \
90 -c "read 0 65536" "$TEST_IMG" \
91 | _filter_qemu_io
92
93 # success, all done
94 echo "*** done"
95 rm -f $seq.full
96 status=0