4956752cdb4e581940dc3095f96910fb77fcb53e
[xfstests-dev.git] / tests / xfs / 260
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 260
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 xfs
32 _supported_os Linux
33 _require_scratch_dax
34 _require_test_program "feature"
35 _require_test_program "t_mmap_dio"
36 _require_xfs_io_command "chattr" "x"
37 _require_xfs_io_command "falloc"
38
39 prep_files()
40 {
41         rm -f $SCRATCH_MNT/tf_{s,d}
42
43         $XFS_IO_PROG -f -c "falloc 0 $tsize" \
44                 $SCRATCH_MNT/tf_{s,d} >> $seqres.full 2>&1
45 }
46
47 t_both_dax()
48 {
49         prep_files
50         $XFS_IO_PROG -c "chattr +x" $SCRATCH_MNT/tf_{s,d}
51         # with O_DIRECT first
52         src/t_mmap_dio $SCRATCH_MNT/tf_{s,d} $1 "dio both dax"
53
54         prep_files
55         $XFS_IO_PROG -c "chattr +x" $SCRATCH_MNT/tf_{s,d}
56         # again with buffered IO
57         src/t_mmap_dio -b $SCRATCH_MNT/tf_{s,d} \
58                 $1 "buffered both dax"
59 }
60
61 t_nondax_to_dax()
62 {
63         prep_files
64         $XFS_IO_PROG -c "chattr -x" $SCRATCH_MNT/tf_s
65         $XFS_IO_PROG -c "chattr +x" $SCRATCH_MNT/tf_d
66         src/t_mmap_dio $SCRATCH_MNT/tf_{s,d} \
67                 $1 "dio nondax to dax"
68
69         prep_files
70         $XFS_IO_PROG -c "chattr -x" $SCRATCH_MNT/tf_s
71         $XFS_IO_PROG -c "chattr +x" $SCRATCH_MNT/tf_d
72         src/t_mmap_dio -b $SCRATCH_MNT/tf_{s,d} \
73                 $1 "buffered nondax to dax"
74 }
75
76 t_dax_to_nondax()
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 dax to nondax"
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 dax to nondax"
89 }
90
91 t_both_nondax()
92 {
93         prep_files
94         $XFS_IO_PROG -c "chattr -x" $SCRATCH_MNT/tf_{s,d}
95         src/t_mmap_dio $SCRATCH_MNT/tf_{s,d} \
96                 $1 "dio both nondax"
97
98         prep_files
99         $XFS_IO_PROG -c "chattr -x" $SCRATCH_MNT/tf_{s,d}
100         src/t_mmap_dio -b $SCRATCH_MNT/tf_{s,d} \
101                 $1 "buffered both nondax"
102 }
103
104 # $1 mmap read/write size
105 t_dax_flag_mmap_dio()
106 {
107         t_both_dax $1
108         t_dax_to_nondax $1
109         t_nondax_to_dax $1
110         t_both_nondax $1
111 }
112
113 do_tests()
114 {
115         # less than page size
116         t_dax_flag_mmap_dio 1024
117         # page size
118         t_dax_flag_mmap_dio `src/feature -s`
119         # bigger sizes, for PMD faults
120         t_dax_flag_mmap_dio $((16 * 1024 * 1024))
121         t_dax_flag_mmap_dio $((64 * 1024 * 1024))
122 }
123
124 # make xfs 2Mb aligned for PMD fault testing
125 _scratch_mkfs "-d su=2m,sw=1" > /dev/null 2>&1
126
127 # mount with dax option
128 _scratch_mount "-o dax"
129
130 tsize=$((128 * 1024 * 1024))
131
132 do_tests
133 _scratch_unmount
134
135 # mount again without dax option
136 export MOUNT_OPTIONS=""
137 _scratch_mount
138 do_tests
139
140 # success, all done
141 echo "Silence is golden"
142 status=0
143 exit