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 _begin_fstest auto attr quick dax
20 # Import common functions.
24 _require_scratch_dax_mountopt "dax=always"
26 _require_xfs_io_command "lsattr" "-v"
27 _require_xfs_io_command "statx" "-r"
31 local t_file=$SCRATCH_MNT/testfile
35 _check_xflag $t_file 0
36 _check_s_dax $t_file 0
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
48 # No application is using test file and S_DAX
49 # on the file is changed immediately
50 _check_s_dax $t_file 1
55 local t_dir=$SCRATCH_MNT/testdir
56 local t_file=$t_dir/testfile
59 $XFS_IO_PROG -c 'chattr +x' $t_dir
62 _check_xflag $t_file 1
63 _check_s_dax $t_file 1
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
75 # No application is using test file and S_DAX
76 # on the file is changed immediately
77 _check_s_dax $t_file 0
80 test_buffered_data_lost()
82 local t_file=$SCRATCH_MNT/datafile
84 # Write data into a file
85 echo "Buffered data" > $t_file
87 # Then enable DAX on the file immediately
88 $XFS_IO_PROG -c 'chattr +x' $t_file
90 # Without commit 77573fa310d9, ensure inode can
91 # be evicted by drop_caches
92 echo 2 > /proc/sys/vm/drop_caches
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"
102 local mount_option=$1
104 _scratch_mount "$mount_option"
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
109 # Do test for commit 77573fa310d9
113 # Do test for commit 88149082bb8e
114 test_buffered_data_lost
119 _scratch_mkfs >> $seqres.full 2>&1
121 # Mount with dax option
122 do_tests "-o dax=inode"
124 # Mount without dax option
125 export MOUNT_OPTIONS=""
129 echo "Silence is golden"