generic: test MADV_POPULATE_READ with IO errors
[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 . ./common/preamble
10 _begin_fstest auto attr quick dax
11
12 # Import common functions.
13 . ./common/filter
14
15 _supported_fs generic
16 _require_scratch_dax_mountopt "dax=always"
17 _require_test_program "feature"
18 _require_test_program "t_mmap_dio"
19 _require_dax_iflag
20 _require_xfs_io_command "falloc"
21
22 SRC_DIR=$SCRATCH_MNT/src
23 SRC_FILE=$SRC_DIR/tf_s
24 DST_DIR=$SCRATCH_MNT/dst
25 DST_FILE=$DST_DIR/tf_d
26
27 prep_directories()
28 {
29         mkdir -p $SRC_DIR $DST_DIR
30 }
31
32 prep_files()
33 {
34         rm -f $SRC_FILE $DST_FILE
35         $XFS_IO_PROG -f -c "falloc 0 $tsize" \
36                 $SRC_FILE $DST_FILE >> $seqres.full 2>&1
37 }
38
39 t_both_dax()
40 {
41         $XFS_IO_PROG -c "chattr +x" $SRC_DIR $DST_DIR
42         prep_files
43         # with O_DIRECT first
44         $here/src/t_mmap_dio $SRC_FILE $DST_FILE \
45                 $1 "dio both dax"
46
47         prep_files
48         # again with buffered IO
49         $here/src/t_mmap_dio -b $SRC_FILE $DST_FILE \
50                 $1 "buffered both dax"
51 }
52
53 t_nondax_to_dax()
54 {
55         $XFS_IO_PROG -c "chattr -x" $SRC_DIR
56         $XFS_IO_PROG -c "chattr +x" $DST_DIR
57         prep_files
58         $here/src/t_mmap_dio $SRC_FILE $DST_FILE \
59                 $1 "dio nondax to dax"
60
61         prep_files
62         $here/src/t_mmap_dio -b $SRC_FILE $DST_FILE \
63                 $1 "buffered nondax to dax"
64 }
65
66 t_dax_to_nondax()
67 {
68         $XFS_IO_PROG -c "chattr +x" $SRC_DIR
69         $XFS_IO_PROG -c "chattr -x" $DST_DIR
70         prep_files
71         $here/src/t_mmap_dio $SRC_FILE $DST_FILE \
72                 $1 "dio dax to nondax"
73
74         prep_files
75         $here/src/t_mmap_dio -b $SRC_FILE $DST_FILE \
76                 $1 "buffered dax to nondax"
77 }
78
79 t_both_nondax()
80 {
81         $XFS_IO_PROG -c "chattr -x" $SRC_DIR $DST_DIR
82         prep_files
83         $here/src/t_mmap_dio $SRC_FILE $DST_FILE \
84                 $1 "dio both nondax"
85
86         prep_files
87         $here/src/t_mmap_dio -b $SRC_FILE $DST_FILE \
88                 $1 "buffered both nondax"
89 }
90
91 # $1 mmap read/write size
92 t_dax_flag_mmap_dio()
93 {
94         t_both_dax $1
95         t_dax_to_nondax $1
96         t_nondax_to_dax $1
97         t_both_nondax $1
98 }
99
100 do_tests()
101 {
102         local mount_option=$1
103
104         _scratch_mount "$mount_option"
105
106         prep_directories
107         # less than page size
108         t_dax_flag_mmap_dio 1024
109         # page size
110         t_dax_flag_mmap_dio `$here/src/feature -s`
111         # bigger sizes, for PMD faults
112         t_dax_flag_mmap_dio $((16 * 1024 * 1024))
113         t_dax_flag_mmap_dio $((64 * 1024 * 1024))
114
115         _scratch_unmount
116 }
117
118 # make xfs aligned for PMD fault testing
119 _scratch_mkfs_geom $(_get_hugepagesize) 1 >> $seqres.full 2>&1
120
121 tsize=$((128 * 1024 * 1024))
122
123 # mount with dax=inode option
124 do_tests "-o dax=inode"
125
126 # mount without dax option
127 export MOUNT_OPTIONS=""
128 do_tests
129
130 # success, all done
131 echo "Silence is golden"
132 status=0
133 exit