2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2020 Fujitsu. All Rights Reserved.
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")'
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()"'
18 seqres=$RESULT_DIR/$seq
19 echo "QA output created by $seq"
23 status=1 # failure is the default!
24 trap "_cleanup; exit \$status" 0 1 2 3 15
32 # get standard environment, filters and checks
36 # remove previous $seqres.full before test
40 _require_scratch_dax_mountopt "dax=always"
42 _require_xfs_io_command "lsattr" "-v"
43 _require_xfs_io_command "statx" "-r"
47 local t_file=$SCRATCH_MNT/testfile
51 _check_xflag $t_file 0
52 _check_s_dax $t_file 0
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
64 # No application is using test file and S_DAX
65 # on the file is changed immediately
66 _check_s_dax $t_file 1
71 local t_dir=$SCRATCH_MNT/testdir
72 local t_file=$t_dir/testfile
75 $XFS_IO_PROG -c 'chattr +x' $t_dir
78 _check_xflag $t_file 1
79 _check_s_dax $t_file 1
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
91 # No application is using test file and S_DAX
92 # on the file is changed immediately
93 _check_s_dax $t_file 0
96 test_buffered_data_lost()
98 local t_file=$SCRATCH_MNT/datafile
100 # Write data into a file
101 echo "Buffered data" > $t_file
103 # Then enable DAX on the file immediately
104 $XFS_IO_PROG -c 'chattr +x' $t_file
106 # Without commit 77573fa310d9, ensure inode can
107 # be evicted by drop_caches
108 echo 2 > /proc/sys/vm/drop_caches
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"
118 local mount_option=$1
120 _scratch_mount "$mount_option"
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
125 # Do test for commit 77573fa310d9
129 # Do test for commit 88149082bb8e
130 test_buffered_data_lost
135 _scratch_mkfs >> $seqres.full 2>&1
137 # Mount with dax option
138 do_tests "-o dax=inode"
140 # Mount without dax option
141 export MOUNT_OPTIONS=""
145 echo "Silence is golden"