86a7d28faea833cfea7978757352a1bf4a357113
[xfstests-dev.git] / tests / overlay / 016
1 #! /bin/bash
2 # FSQA Test No. 016
3 #
4 # Test ro/rw fd data inconsistecies
5 #
6 # This simple test demonstrates a known issue with overlayfs:
7 # - process A opens file F for read
8 # - process B writes new data to file F
9 # - process A reads old data from file F
10 #
11 #-----------------------------------------------------------------------
12 #
13 # Copyright (C) 2016 CTERA Networks. All Rights Reserved.
14 # Author: Amir Goldstein <amir73il@gmail.com>
15 #
16 # This program is free software; you can redistribute it and/or
17 # modify it under the terms of the GNU General Public License as
18 # published by the Free Software Foundation.
19 #
20 # This program is distributed in the hope that it would be useful,
21 # but WITHOUT ANY WARRANTY; without even the implied warranty of
22 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23 # GNU General Public License for more details.
24 #
25 # You should have received a copy of the GNU General Public License
26 # along with this program; if not, write the Free Software Foundation,
27 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
28 #-----------------------------------------------------------------------
29 #
30
31 seq=`basename $0`
32 seqres=$RESULT_DIR/$seq
33 echo "QA output created by $seq"
34
35 tmp=/tmp/$$
36 status=1        # failure is the default!
37 trap "_cleanup; exit \$status" 0 1 2 3 15
38
39 _cleanup()
40 {
41         cd /
42         rm -f $tmp.*
43 }
44
45 # get standard environment, filters and checks
46 . ./common/rc
47 . ./common/filter
48
49 # real QA test starts here
50 _supported_fs overlay
51 _supported_os Linux
52 _require_scratch
53 _require_xfs_io_command "open"
54
55 rm -f $seqres.full
56
57 _scratch_mkfs >>$seqres.full 2>&1
58
59 # Create our test files.
60 lowerdir=$OVL_BASE_SCRATCH_MNT/$OVL_LOWER
61 mkdir -p $lowerdir
62 echo "This is old news" > $lowerdir/foo
63 echo "This is old news" > $lowerdir/bar
64
65 _scratch_mount
66
67
68 #
69 # case #1:
70 # open file for read (rofd)
71 # open file for write (rwfd)
72 # write to rwfd
73 # read from rofd
74 #
75 $XFS_IO_PROG -r $SCRATCH_MNT/foo \
76         -C "open $SCRATCH_MNT/foo" \
77         -C "pwrite -S 0x61 0 16" \
78         -C "file 0" \
79         -C "pread -v 0 16" \
80 | _filter_xfs_io | _filter_scratch
81
82 #
83 # case #2:
84 # mmap MAP_SHARED|PROT_READ of rofd
85 # write to rwfd
86 # read from mapped memory
87 #
88 $XFS_IO_PROG -r $SCRATCH_MNT/bar \
89         -C "mmap -r 0 16" \
90         -C "open $SCRATCH_MNT/bar" \
91         -C "pwrite -S 0x61 0 16" \
92         -C "mread -v 0 16" \
93 | _filter_xfs_io | _filter_scratch
94
95 status=0
96 exit