common/rc: factor out _scratch_xfs_[get|set]_sb_field
[xfstests-dev.git] / tests / xfs / 260
1 #! /bin/bash
2 # FS QA Test 260
3 #
4 # Test per-inode DAX flag by mmap direct/buffered IO.
5 #
6 #-----------------------------------------------------------------------
7 # Copyright (c) 2017 Red Hat Inc.  All Rights Reserved.
8 #
9 # This program is free software; you can redistribute it and/or
10 # modify it under the terms of the GNU General Public License as
11 # published by the Free Software Foundation.
12 #
13 # This program is distributed in the hope that it would 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, write the Free Software Foundation,
20 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
21 #-----------------------------------------------------------------------
22 #
23
24 seq=`basename $0`
25 seqres=$RESULT_DIR/$seq
26 echo "QA output created by $seq"
27
28 here=`pwd`
29 tmp=/tmp/$$
30 status=1        # failure is the default!
31 trap "_cleanup; exit \$status" 0 1 2 3 15
32
33 _cleanup()
34 {
35         cd /
36         rm -f $tmp.*
37 }
38
39 # get standard environment, filters and checks
40 . ./common/rc
41 . ./common/filter
42
43 # remove previous $seqres.full before test
44 rm -f $seqres.full
45
46 _supported_fs xfs
47 _supported_os Linux
48 _require_scratch_dax
49 _require_test_program "feature"
50 _require_test_program "t_mmap_dio"
51 _require_xfs_io_command "chattr" "+/-x"
52 _require_xfs_io_command "falloc"
53
54 prep_files()
55 {
56         rm -f $SCRATCH_MNT/tf_{s,d}
57
58         $XFS_IO_PROG -f -c "falloc 0 $tsize" \
59                 $SCRATCH_MNT/tf_{s,d} >> $seqres.full 2>&1
60 }
61
62 t_both_dax()
63 {
64         prep_files
65         $XFS_IO_PROG -c "chattr +x" $SCRATCH_MNT/tf_{s,d}
66         # with O_DIRECT first
67         src/t_mmap_dio $SCRATCH_MNT/tf_{s,d} $1 "dio both dax"
68
69         prep_files
70         $XFS_IO_PROG -c "chattr +x" $SCRATCH_MNT/tf_{s,d}
71         # again with buffered IO
72         src/t_mmap_dio -b $SCRATCH_MNT/tf_{s,d} \
73                 $1 "buffered both dax"
74 }
75
76 t_nondax_to_dax()
77 {
78         prep_files
79         $XFS_IO_PROG -c "chattr -x" $SCRATCH_MNT/tf_s
80         $XFS_IO_PROG -c "chattr +x" $SCRATCH_MNT/tf_d
81         src/t_mmap_dio $SCRATCH_MNT/tf_{s,d} \
82                 $1 "dio nondax to dax"
83
84         prep_files
85         $XFS_IO_PROG -c "chattr -x" $SCRATCH_MNT/tf_s
86         $XFS_IO_PROG -c "chattr +x" $SCRATCH_MNT/tf_d
87         src/t_mmap_dio -b $SCRATCH_MNT/tf_{s,d} \
88                 $1 "buffered nondax to dax"
89 }
90
91 t_dax_to_nondax()
92 {
93         prep_files
94         $XFS_IO_PROG -c "chattr +x" $SCRATCH_MNT/tf_s
95         $XFS_IO_PROG -c "chattr -x" $SCRATCH_MNT/tf_d
96         src/t_mmap_dio $SCRATCH_MNT/tf_{s,d} \
97                 $1 "dio dax to nondax"
98
99         prep_files
100         $XFS_IO_PROG -c "chattr +x" $SCRATCH_MNT/tf_s
101         $XFS_IO_PROG -c "chattr -x" $SCRATCH_MNT/tf_d
102         src/t_mmap_dio -b $SCRATCH_MNT/tf_{s,d} \
103                 $1 "buffered dax to nondax"
104 }
105
106 t_both_nondax()
107 {
108         prep_files
109         $XFS_IO_PROG -c "chattr -x" $SCRATCH_MNT/tf_{s,d}
110         src/t_mmap_dio $SCRATCH_MNT/tf_{s,d} \
111                 $1 "dio both nondax"
112
113         prep_files
114         $XFS_IO_PROG -c "chattr -x" $SCRATCH_MNT/tf_{s,d}
115         src/t_mmap_dio -b $SCRATCH_MNT/tf_{s,d} \
116                 $1 "buffered both nondax"
117 }
118
119 # $1 mmap read/write size
120 t_dax_flag_mmap_dio()
121 {
122         t_both_dax $1
123         t_dax_to_nondax $1
124         t_nondax_to_dax $1
125         t_both_nondax $1
126 }
127
128 do_tests()
129 {
130         # less than page size
131         t_dax_flag_mmap_dio 1024
132         # page size
133         t_dax_flag_mmap_dio `src/feature -s`
134         # bigger sizes, for PMD faults
135         t_dax_flag_mmap_dio $((16 * 1024 * 1024))
136         t_dax_flag_mmap_dio $((64 * 1024 * 1024))
137 }
138
139 # make xfs 2Mb aligned for PMD fault testing
140 _scratch_mkfs "-d su=2m,sw=1" > /dev/null 2>&1
141
142 # mount with dax option
143 _scratch_mount "-o dax"
144
145 tsize=$((128 * 1024 * 1024))
146
147 do_tests
148 _scratch_unmount
149
150 # mount again without dax option
151 export MOUNT_OPTIONS=""
152 _scratch_mount
153 do_tests
154
155 # success, all done
156 echo "Silence is golden"
157 status=0
158 exit