fstests: move test group info to test files
[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 . ./common/preamble
18 _begin_fstest auto attr quick dax
19
20 # Import common functions.
21 . ./common/filter
22
23 _supported_fs generic
24 _require_scratch_dax_mountopt "dax=always"
25 _require_dax_iflag
26 _require_xfs_io_command "lsattr" "-v"
27 _require_xfs_io_command "statx" "-r"
28
29 test_enable_dax()
30 {
31         local t_file=$SCRATCH_MNT/testfile
32
33         rm -f $t_file
34         touch $t_file
35         _check_xflag $t_file 0
36         _check_s_dax $t_file 0
37
38         exec 3< $t_file
39
40         $XFS_IO_PROG -c 'chattr +x' $t_file
41         _check_xflag $t_file 1
42         # One application is using test file and S_DAX
43         # on the file is not changed immediately
44         _check_s_dax $t_file 0
45
46         exec 3<&-
47
48         # No application is using test file and S_DAX
49         # on the file is changed immediately
50         _check_s_dax $t_file 1
51 }
52
53 test_disable_dax()
54 {
55         local t_dir=$SCRATCH_MNT/testdir
56         local t_file=$t_dir/testfile
57
58         mkdir -p $t_dir
59         $XFS_IO_PROG -c 'chattr +x' $t_dir
60         rm -f $t_file
61         touch $t_file
62         _check_xflag $t_file 1
63         _check_s_dax $t_file 1
64
65         exec 3< $t_file
66
67         $XFS_IO_PROG -c 'chattr -x' $t_file
68         _check_xflag $t_file 0
69         # One application is using test file and S_DAX
70         # on the file is not changed immediately
71         _check_s_dax $t_file 1
72
73         exec 3<&-
74
75         # No application is using test file and S_DAX
76         # on the file is changed immediately
77         _check_s_dax $t_file 0
78 }
79
80 test_buffered_data_lost()
81 {
82         local t_file=$SCRATCH_MNT/datafile
83
84         # Write data into a file
85         echo "Buffered data" > $t_file
86
87         # Then enable DAX on the file immediately
88         $XFS_IO_PROG -c 'chattr +x' $t_file
89
90         # Without commit 77573fa310d9, ensure inode can
91         # be evicted by drop_caches
92         echo 2 > /proc/sys/vm/drop_caches
93
94         # The written data which is still in the buffer should not be lost
95         grep -q "Buffered data" $t_file || echo "Buffered data is lost"
96
97         rm -f $t_file
98 }
99
100 do_tests()
101 {
102         local mount_option=$1
103
104         _scratch_mount "$mount_option"
105
106         # Make sure the root dir doesn't have FS_XFLAG_DAX set before we start.
107         $XFS_IO_PROG -c "chattr -x" $SCRATCH_MNT &>> $seqres.full
108
109         # Do test for commit 77573fa310d9
110         test_enable_dax
111         test_disable_dax
112
113         # Do test for commit 88149082bb8e
114         test_buffered_data_lost
115
116         _scratch_unmount
117 }
118
119 _scratch_mkfs >> $seqres.full 2>&1
120
121 # Mount with dax option
122 do_tests "-o dax=inode"
123
124 # Mount without dax option
125 export MOUNT_OPTIONS=""
126 do_tests
127
128 # success, all done
129 echo "Silence is golden"
130 status=0
131 exit