generic: test deadlock on O_DIRECT|O_DSYNC
[xfstests-dev.git] / tests / generic / 605
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2017 Red Hat Inc.  All Rights Reserved.
4 #
5 # FS QA Test 605
6 #
7 # Test per-inode DAX flag by mmap direct/buffered IO.
8 #
9 seq=`basename $0`
10 seqres=$RESULT_DIR/$seq
11 echo "QA output created by $seq"
12
13 here=`pwd`
14 tmp=/tmp/$$
15 status=1        # failure is the default!
16 trap "_cleanup; exit \$status" 0 1 2 3 15
17
18 _cleanup()
19 {
20         cd /
21         rm -f $tmp.*
22 }
23
24 # get standard environment, filters and checks
25 . ./common/rc
26 . ./common/filter
27
28 # remove previous $seqres.full before test
29 rm -f $seqres.full
30
31 _supported_fs generic
32 _supported_os Linux
33 _require_scratch_dax_mountopt "dax=always"
34 _require_test_program "feature"
35 _require_test_program "t_mmap_dio"
36 _require_dax_iflag
37 _require_xfs_io_command "falloc"
38
39 SRC_DIR=$SCRATCH_MNT/src
40 SRC_FILE=$SRC_DIR/tf_s
41 DST_DIR=$SCRATCH_MNT/dst
42 DST_FILE=$DST_DIR/tf_d
43
44 prep_directories()
45 {
46         mkdir -p $SRC_DIR $DST_DIR
47 }
48
49 prep_files()
50 {
51         rm -f $SRC_FILE $DST_FILE
52         $XFS_IO_PROG -f -c "falloc 0 $tsize" \
53                 $SRC_FILE $DST_FILE >> $seqres.full 2>&1
54 }
55
56 t_both_dax()
57 {
58         $XFS_IO_PROG -c "chattr +x" $SRC_DIR $DST_DIR
59         prep_files
60         # with O_DIRECT first
61         $here/src/t_mmap_dio $SRC_FILE $DST_FILE \
62                 $1 "dio both dax"
63
64         prep_files
65         # again with buffered IO
66         $here/src/t_mmap_dio -b $SRC_FILE $DST_FILE \
67                 $1 "buffered both dax"
68 }
69
70 t_nondax_to_dax()
71 {
72         $XFS_IO_PROG -c "chattr -x" $SRC_DIR
73         $XFS_IO_PROG -c "chattr +x" $DST_DIR
74         prep_files
75         $here/src/t_mmap_dio $SRC_FILE $DST_FILE \
76                 $1 "dio nondax to dax"
77
78         prep_files
79         $here/src/t_mmap_dio -b $SRC_FILE $DST_FILE \
80                 $1 "buffered nondax to dax"
81 }
82
83 t_dax_to_nondax()
84 {
85         $XFS_IO_PROG -c "chattr +x" $SRC_DIR
86         $XFS_IO_PROG -c "chattr -x" $DST_DIR
87         prep_files
88         $here/src/t_mmap_dio $SRC_FILE $DST_FILE \
89                 $1 "dio dax to nondax"
90
91         prep_files
92         $here/src/t_mmap_dio -b $SRC_FILE $DST_FILE \
93                 $1 "buffered dax to nondax"
94 }
95
96 t_both_nondax()
97 {
98         $XFS_IO_PROG -c "chattr -x" $SRC_DIR $DST_DIR
99         prep_files
100         $here/src/t_mmap_dio $SRC_FILE $DST_FILE \
101                 $1 "dio both nondax"
102
103         prep_files
104         $here/src/t_mmap_dio -b $SRC_FILE $DST_FILE \
105                 $1 "buffered both nondax"
106 }
107
108 # $1 mmap read/write size
109 t_dax_flag_mmap_dio()
110 {
111         t_both_dax $1
112         t_dax_to_nondax $1
113         t_nondax_to_dax $1
114         t_both_nondax $1
115 }
116
117 do_tests()
118 {
119         local mount_option=$1
120
121         _scratch_mount "$mount_option"
122
123         prep_directories
124         # less than page size
125         t_dax_flag_mmap_dio 1024
126         # page size
127         t_dax_flag_mmap_dio `$here/src/feature -s`
128         # bigger sizes, for PMD faults
129         t_dax_flag_mmap_dio $((16 * 1024 * 1024))
130         t_dax_flag_mmap_dio $((64 * 1024 * 1024))
131
132         _scratch_unmount
133 }
134
135 # make xfs aligned for PMD fault testing
136 _scratch_mkfs_geom $(_get_hugepagesize) 1 >> $seqres.full 2>&1
137
138 tsize=$((128 * 1024 * 1024))
139
140 # mount with dax=inode option
141 do_tests "-o dax=inode"
142
143 # mount without dax option
144 export MOUNT_OPTIONS=""
145 do_tests
146
147 # success, all done
148 echo "Silence is golden"
149 status=0
150 exit