generic/60[78]: ensure the initial DAX file flag state before test
[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 _require_scratch_dax_mountopt "dax=always"
35 _require_dax_iflag
36 _require_xfs_io_command "lsattr" "-v"
37 _require_xfs_io_command "statx" "-r"
38
39 test_drop_caches()
40 {
41         local t_file=$SCRATCH_MNT/testfile
42
43         rm -f $t_file
44         touch $t_file
45         _check_xflag $t_file 0
46         _check_s_dax $t_file 0
47
48         exec 3< $t_file
49
50         $XFS_IO_PROG -c 'chattr +x' $t_file
51         _check_xflag $t_file 1
52         _check_s_dax $t_file 0
53
54         # One application is using test file and check if S_DAX on
55         # the file doesn't take effect immediately by drop_caches
56         echo 2 > /proc/sys/vm/drop_caches
57         _check_s_dax $t_file 0
58
59         exec 3<&-
60
61         # No application is using test file and check if S_DAX on
62         # the file takes effect immediately by drop_caches
63         echo 2 > /proc/sys/vm/drop_caches
64         _check_s_dax $t_file 1
65 }
66
67 test_cycle_mount()
68 {
69         local option=$1
70         local t_dir=$SCRATCH_MNT/testdir
71         local t_file=$t_dir/testfile
72
73         mkdir -p $t_dir
74         $XFS_IO_PROG -c 'chattr +x' $t_dir
75         rm -f $t_file
76         touch $t_file
77         _check_xflag $t_file 1
78         _check_s_dax $t_file 1
79
80         exec 3< $t_file
81
82         $XFS_IO_PROG -c 'chattr -x' $t_file
83         _check_xflag $t_file 0
84         _check_s_dax $t_file 1
85
86         exec 3<&-
87
88         # No application is using test file and check if S_DAX on
89         # the file takes effect immediately by umount & mount
90         _scratch_cycle_mount "$option"
91         _check_s_dax $t_file 0
92 }
93
94 do_tests()
95 {
96         local mount_option=$1
97         local cycle_mount_option=$2
98
99         _scratch_mount "$mount_option"
100
101         # Make sure the root dir doesn't have FS_XFLAG_DAX set before we start.
102         $XFS_IO_PROG -c "chattr -x" $SCRATCH_MNT &>> $seqres.full
103
104         test_drop_caches
105
106         test_cycle_mount "$cycle_mount_option"
107
108         _scratch_unmount
109 }
110
111 _scratch_mkfs >> $seqres.full 2>&1
112
113 # Mount with dax option
114 do_tests "-o dax=inode" "dax=inode"
115
116 # Mount without dax option
117 export MOUNT_OPTIONS=""
118 do_tests
119
120 # success, all done
121 echo "Silence is golden"
122 status=0
123 exit