generic/223: make sure all files get created on the data device
[xfstests-dev.git] / tests / generic / 608
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2020 Fujitsu.  All Rights Reserved.
4 #
5 # FS QA Test 608
6 # Toggling FS_XFLAG_DAX on an existing file can make S_DAX on the
7 # file change immediately when all applications close the file.
8 # It's a regression test for:
9 # 'commit 77573fa310d9 ("fs: Kill DCACHE_DONTCACHE dentry even if DCACHE_REFERENCED is set")'
10 #
11 # Write data into a file and then enable DAX on the file immediately,
12 # the written data which is still in the buffer should be synchronized
13 # to disk instead of discarded when the corresponding inode is evicted.
14 # It's a regression test for:
15 # 'commit 88149082bb8e ("fs: Handle I_DONTCACHE in iput_final() instead of generic_drop_inode()"'
16
17 seq=`basename $0`
18 seqres=$RESULT_DIR/$seq
19 echo "QA output created by $seq"
20
21 here=`pwd`
22 tmp=/tmp/$$
23 status=1        # failure is the default!
24 trap "_cleanup; exit \$status" 0 1 2 3 15
25
26 _cleanup()
27 {
28         cd /
29         rm -f $tmp.*
30 }
31
32 # get standard environment, filters and checks
33 . ./common/rc
34 . ./common/filter
35
36 # remove previous $seqres.full before test
37 rm -f $seqres.full
38
39 _supported_fs generic
40 _require_scratch_dax_mountopt "dax=always"
41 _require_dax_iflag
42 _require_xfs_io_command "lsattr" "-v"
43 _require_xfs_io_command "statx" "-r"
44
45 test_enable_dax()
46 {
47         local t_file=$SCRATCH_MNT/testfile
48
49         rm -f $t_file
50         touch $t_file
51         _check_xflag $t_file 0
52         _check_s_dax $t_file 0
53
54         exec 3< $t_file
55
56         $XFS_IO_PROG -c 'chattr +x' $t_file
57         _check_xflag $t_file 1
58         # One application is using test file and S_DAX
59         # on the file is not changed immediately
60         _check_s_dax $t_file 0
61
62         exec 3<&-
63
64         # No application is using test file and S_DAX
65         # on the file is changed immediately
66         _check_s_dax $t_file 1
67 }
68
69 test_disable_dax()
70 {
71         local t_dir=$SCRATCH_MNT/testdir
72         local t_file=$t_dir/testfile
73
74         mkdir -p $t_dir
75         $XFS_IO_PROG -c 'chattr +x' $t_dir
76         rm -f $t_file
77         touch $t_file
78         _check_xflag $t_file 1
79         _check_s_dax $t_file 1
80
81         exec 3< $t_file
82
83         $XFS_IO_PROG -c 'chattr -x' $t_file
84         _check_xflag $t_file 0
85         # One application is using test file and S_DAX
86         # on the file is not changed immediately
87         _check_s_dax $t_file 1
88
89         exec 3<&-
90
91         # No application is using test file and S_DAX
92         # on the file is changed immediately
93         _check_s_dax $t_file 0
94 }
95
96 test_buffered_data_lost()
97 {
98         local t_file=$SCRATCH_MNT/datafile
99
100         # Write data into a file
101         echo "Buffered data" > $t_file
102
103         # Then enable DAX on the file immediately
104         $XFS_IO_PROG -c 'chattr +x' $t_file
105
106         # Without commit 77573fa310d9, ensure inode can
107         # be evicted by drop_caches
108         echo 2 > /proc/sys/vm/drop_caches
109
110         # The written data which is still in the buffer should not be lost
111         grep -q "Buffered data" $t_file || echo "Buffered data is lost"
112
113         rm -f $t_file
114 }
115
116 do_tests()
117 {
118         local mount_option=$1
119
120         _scratch_mount "$mount_option"
121
122         # Make sure the root dir doesn't have FS_XFLAG_DAX set before we start.
123         $XFS_IO_PROG -c "chattr -x" $SCRATCH_MNT &>> $seqres.full
124
125         # Do test for commit 77573fa310d9
126         test_enable_dax
127         test_disable_dax
128
129         # Do test for commit 88149082bb8e
130         test_buffered_data_lost
131
132         _scratch_unmount
133 }
134
135 _scratch_mkfs >> $seqres.full 2>&1
136
137 # Mount with dax option
138 do_tests "-o dax=inode"
139
140 # Mount without dax option
141 export MOUNT_OPTIONS=""
142 do_tests
143
144 # success, all done
145 echo "Silence is golden"
146 status=0
147 exit