generic: Verify how to change the S_DAX flag on an existing file
[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 # Change FS_XFLAG_DAX on an existing file and check if S_DAX on
7 # the file can take effect immediately by the following steps:
8 # 1) Stop all applications which are using the file.
9 # 2) Do drop_caches or umount & mount cycle.
10
11 seq=`basename $0`
12 seqres=$RESULT_DIR/$seq
13 echo "QA output created by $seq"
14
15 here=`pwd`
16 tmp=/tmp/$$
17 status=1        # failure is the default!
18 trap "_cleanup; exit \$status" 0 1 2 3 15
19
20 _cleanup()
21 {
22         cd /
23         rm -f $tmp.*
24 }
25
26 # get standard environment, filters and checks
27 . ./common/rc
28 . ./common/filter
29
30 # remove previous $seqres.full before test
31 rm -f $seqres.full
32
33 _supported_fs generic
34 _supported_os Linux
35 _require_scratch_dax_mountopt "dax=always"
36 _require_dax_iflag
37 _require_xfs_io_command "lsattr" "-v"
38 _require_xfs_io_command "statx" "-r"
39
40 test_drop_caches()
41 {
42         local t_file=$SCRATCH_MNT/testfile
43
44         rm -f $t_file
45         touch $t_file
46         _check_xflag $t_file 0
47         _check_s_dax $t_file 0
48
49         exec 3< $t_file
50
51         $XFS_IO_PROG -c 'chattr +x' $t_file
52         _check_xflag $t_file 1
53         _check_s_dax $t_file 0
54
55         # One application is using test file and check if S_DAX on
56         # the file doesn't take effect immediately by drop_caches
57         echo 2 > /proc/sys/vm/drop_caches
58         _check_s_dax $t_file 0
59
60         exec 3<&-
61
62         # No application is using test file and check if S_DAX on
63         # the file takes effect immediately by drop_caches
64         echo 2 > /proc/sys/vm/drop_caches
65         _check_s_dax $t_file 1
66 }
67
68 test_cycle_mount()
69 {
70         local option=$1
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         _check_s_dax $t_file 1
86
87         exec 3<&-
88
89         # No application is using test file and check if S_DAX on
90         # the file takes effect immediately by umount & mount
91         _scratch_cycle_mount "$option"
92         _check_s_dax $t_file 0
93 }
94
95 do_tests()
96 {
97         local mount_option=$1
98         local cycle_mount_option=$2
99
100         _scratch_mount "$mount_option"
101
102         test_drop_caches
103
104         test_cycle_mount "$cycle_mount_option"
105
106         _scratch_unmount
107 }
108
109 _scratch_mkfs >> $seqres.full 2>&1
110
111 # Mount with dax option
112 do_tests "-o dax=inode" "dax=inode"
113
114 # Mount without dax option
115 export MOUNT_OPTIONS=""
116 do_tests
117
118 # success, all done
119 echo "Silence is golden"
120 status=0
121 exit