1f0dbba67eea121bf2fe5916b2772e3a1dcfab87
[xfstests-dev.git] / tests / generic / 413
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 413
6 #
7 # mmap direct/buffered io between DAX and non-DAX mountpoints.
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_test
34 _require_scratch_dax
35 _require_test_program "feature"
36 _require_test_program "t_mmap_dio"
37 _require_xfs_io_command "falloc"
38
39 prep_files()
40 {
41         rm -f $SCRATCH_MNT/tf_{s,d}
42         rm -f $TEST_DIR/tf_{s,d}
43
44         $XFS_IO_PROG -f -c "falloc 0 $tsize" \
45                 $SCRATCH_MNT/tf_{s,d} >> $seqres.full 2>&1
46         $XFS_IO_PROG -f -c "falloc 0 $tsize" \
47                 $TEST_DIR/tf_{s,d} >> $seqres.full 2>&1
48 }
49
50 t_both_dax()
51 {
52         prep_files
53         # with O_DIRECT first
54         src/t_mmap_dio $SCRATCH_MNT/tf_{s,d} $1 "dio both dax"
55
56         prep_files
57         # again with buffered IO
58         src/t_mmap_dio -b $SCRATCH_MNT/tf_{s,d} \
59                 $1 "buffered both dax"
60 }
61
62 t_nondax_to_dax()
63 {
64         prep_files
65         src/t_mmap_dio $TEST_DIR/tf_s \
66                 $SCRATCH_MNT/tf_d $1 "dio nondax to dax"
67
68         prep_files
69         src/t_mmap_dio -b $TEST_DIR/tf_s \
70                 $SCRATCH_MNT/tf_d $1 "buffered nondax to dax"
71 }
72
73 t_dax_to_nondax()
74 {
75         prep_files
76         src/t_mmap_dio $SCRATCH_MNT/tf_s \
77                 $TEST_DIR/tf_d $1 "dio dax to nondax"
78
79         prep_files
80         src/t_mmap_dio -b $SCRATCH_MNT/tf_s \
81                 $TEST_DIR/tf_d $1 "buffered dax to nondax"
82 }
83
84 t_both_nondax()
85 {
86         prep_files
87         src/t_mmap_dio $TEST_DIR/tf_{s,d} $1 "dio both nondax"
88
89         prep_files
90         src/t_mmap_dio -b $TEST_DIR/tf_{s,d} \
91                 $1 "buffered both nondax"
92 }
93
94 # $1 mmap read/write size
95 t_mmap_dio_dax()
96 {
97         t_both_dax $1
98         t_dax_to_nondax $1
99         t_nondax_to_dax $1
100         t_both_nondax $1
101 }
102
103 do_tests()
104 {
105         # less than page size
106         t_mmap_dio_dax 1024
107         # page size
108         t_mmap_dio_dax `src/feature -s`
109         # bigger sizes, for PMD faults
110         t_mmap_dio_dax $((16 * 1024 * 1024))
111         t_mmap_dio_dax $((64 * 1024 * 1024))
112 }
113
114 # make fs 2Mb aligned for PMD fault testing
115 mkfs_opts=""
116 if [ "$FSTYP" == "ext4" ]; then
117         mkfs_opts="-E stride=512,stripe_width=1"
118 elif [ "$FSTYP" == "xfs" ]; then
119         mkfs_opts="-d su=2m,sw=1"
120 fi
121 _scratch_mkfs "$mkfs_opts" > /dev/null 2>&1
122
123 # mount SCRATCH_DEV with dax option, TEST_DEV not
124 export MOUNT_OPTIONS=""
125 export TEST_FS_MOUNT_OPTS=""
126 _test_cycle_mount
127 _fs_options $TEST_DEV | grep -qw "dax" && \
128         _notrun "we need $TEST_DEV mount without dax"
129 _scratch_mount "-o dax"
130
131 tsize=$((128 * 1024 * 1024))
132
133 do_tests
134
135 # success, all done
136 echo "Silence is golden"
137 status=0
138 exit