2 # FS QA Test No. generic/003
4 # Tests the noatime, relatime, strictatime and nodiratime mount options.
5 # There is an extra check for Btrfs to ensure that the access time is
6 # never updated on read-only subvolumes. (Regression test for bug fixed
7 # with commit 93fd63c2f001ca6797c6b15b696a484b165b4800)
9 #-----------------------------------------------------------------------
10 # Copyright (c) 2014, Oracle and/or its affiliates. All Rights Reserved.
12 # This program is free software; you can redistribute it and/or
13 # modify it under the terms of the GNU General Public License as
14 # published by the Free Software Foundation.
16 # This program is distributed in the hope that it would be useful,
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 # GNU General Public License for more details.
21 # You should have received a copy of the GNU General Public License
22 # along with this program; if not, write the Free Software Foundation,
23 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24 #-----------------------------------------------------------------------
27 seqres=$RESULT_DIR/$seq
28 echo "QA output created by $seq"
32 status=1 # failure is the default!
33 trap "_cleanup; exit \$status" 0 1 2 3 15
41 # get standard environment, filters and checks
45 # real QA test starts here
55 stat --printf="%x;%y;%z" $1
58 _compare_stat_times() {
59 updated=$1 # 3 chars indicating if access, modify and
60 # change times should be updated (Y) or not (N)
61 IFS=';' read -a first_stat <<< "$2" # Convert first stat to array
62 IFS=';' read -a second_stat <<< "$3" # Convert second stat to array
63 test_step=$4 # Will be printed to output stream in case of an
64 # error, to make debugging easier
65 types=( access modify change )
68 if [ "${first_stat[$i]}" == "${second_stat[$i]}" ]; then
69 if [ "${updated:$i:1}" == "N" ]; then
72 echo -n "ERROR: ${types[$i]} time has not been updated "
74 elif [ "${updated:$i:1}" == "N" ]; then
75 echo -n "ERROR: ${types[$i]} time has changed "
81 _scratch_mkfs >> $seqres.full 2>&1 || _fail "mkfs failed"
82 _scratch_mount "-o relatime"
84 if [ "$FSTYP" = "btrfs" ]; then
85 TPATH=$SCRATCH_MNT/sub1
86 $BTRFS_UTIL_PROG subvolume create $TPATH > $seqres.full
92 echo "aaa" > $TPATH/dir1/file1
93 file1_stat_before_first_access=`_stat $TPATH/dir1/file1`
95 # Accessing file1 the first time
97 cat $TPATH/dir1/file1 > /dev/null
98 file1_stat_after_first_access=`_stat $TPATH/dir1/file1`
99 _compare_stat_times YNN "$file1_stat_before_first_access" \
100 "$file1_stat_after_first_access" "after accessing file1 first time"
102 # Accessing file1 a second time
104 cat $TPATH/dir1/file1 > /dev/null
105 file1_stat_after_second_access=`_stat $TPATH/dir1/file1`
106 _compare_stat_times NNN "$file1_stat_after_first_access" \
107 "$file1_stat_after_second_access" "after accessing file1 second time"
109 # Remounting with nodiratime option
111 _scratch_mount "-o nodiratime"
112 file1_stat_after_remount=`_stat $TPATH/dir1/file1`
113 _compare_stat_times NNN "$file1_stat_after_second_access" \
114 "$file1_stat_after_remount" "for file1 after remount"
116 # Creating dir2 and file2, checking directory stats
118 dir2_stat_before_file_creation=`_stat $TPATH/dir2`
120 echo "bbb" > $TPATH/dir2/file2
121 dir2_stat_after_file_creation=`_stat $TPATH/dir2`
122 _compare_stat_times NYY "$dir2_stat_before_file_creation" \
123 "$dir2_stat_after_file_creation" "for dir2 after file creation"
126 file2_stat_before_first_access=`_stat $TPATH/dir2/file2`
128 cat $TPATH/dir2/file2 > /dev/null
129 file2_stat_after_first_access=`_stat $TPATH/dir2/file2`
130 _compare_stat_times YNN "$file2_stat_before_first_access" \
131 "$file2_stat_after_first_access" "after accessing file2"
132 dir2_stat_after_file_access=`_stat $TPATH/dir2`
133 _compare_stat_times NNN "$dir2_stat_after_file_creation" \
134 "$dir2_stat_after_file_access" "for dir2 after file access"
136 # Remounting with noatime option, creating a file and accessing it
138 _scratch_mount "-o noatime"
139 echo "ccc" > $TPATH/dir2/file3
140 file3_stat_before_first_access=`_stat $TPATH/dir2/file3`
142 cat $TPATH/dir2/file3 > /dev/null
143 file3_stat_after_first_access=`_stat $TPATH/dir2/file3`
144 _compare_stat_times NNN "$file3_stat_before_first_access" \
145 "$file3_stat_after_first_access" "after accessing file3 first time"
147 # Checking that the modify and change times are still updated
148 file1_stat_before_modify=`_stat $TPATH/dir1/file1`
150 echo "xyz" > $TPATH/dir1/file1
151 file1_stat_after_modify=`_stat $TPATH/dir1/file1`
152 _compare_stat_times NYY "$file1_stat_before_modify" \
153 "$file1_stat_after_modify" "after modifying file1"
155 mv $TPATH/dir1/file1 $TPATH/dir1/file1_renamed
156 file1_stat_after_change=`_stat $TPATH/dir1/file1_renamed`
157 _compare_stat_times NNY "$file1_stat_after_modify" \
158 "$file1_stat_after_change" "after changing file1"
160 # Remounting with strictatime option and
161 # accessing a previously created file twice
163 _scratch_mount "-o strictatime"
164 cat $TPATH/dir2/file3 > /dev/null
165 file3_stat_after_second_access=`_stat $TPATH/dir2/file3`
166 _compare_stat_times YNN "$file3_stat_after_first_access" \
167 "$file3_stat_after_second_access" "after accessing file3 second time"
169 cat $TPATH/dir2/file3 > /dev/null
170 file3_stat_after_third_access=`_stat $TPATH/dir2/file3`
171 _compare_stat_times YNN "$file3_stat_after_second_access" \
172 "$file3_stat_after_third_access" "after accessing file3 third time"
174 # Btrfs only: Creating readonly snapshot. Access time should never
175 # be updated, even when the strictatime mount option is active
176 if [ "$FSTYP" = "btrfs" ]; then
177 SPATH=$SCRATCH_MNT/snap1
178 btrfs subvol snapshot -r $TPATH $SPATH >> $seqres.full
179 dir2_stat_readonly_before_access=`_stat $SPATH/dir2`
181 ls $SPATH/dir2 >> $seqres.full
182 cat $SPATH/dir2/file3 >> $seqres.full
183 dir2_stat_readonly_after_access=`_stat $SPATH/dir2`
184 _compare_stat_times NNN "$dir2_stat_readonly_before_access" \
185 "$dir2_stat_readonly_after_access" "for dir in readonly subvol"
186 file3_stat_readonly_after_access=`_stat $SPATH/dir2/file3`
187 _compare_stat_times NNN "$file3_stat_after_third_access" \
188 "$file3_stat_readonly_after_access" "for file in readonly subvol"
191 # Remounting read-only. Access time should never be updated, despite the
192 # strictatime mount option.
194 dir2_stat_before_ro_mount=`_stat $TPATH/dir2`
195 file3_stat_before_ro_mount=`_stat $TPATH/dir2/file3`
197 _scratch_mount "-o ro,strictatime"
198 ls $TPATH/dir2 > /dev/null
199 cat $TPATH/dir2/file3 > /dev/null
200 dir2_stat_after_ro_mount=`_stat $TPATH/dir2`
201 _compare_stat_times NNN "$dir2_stat_before_ro_mount" \
202 "$dir2_stat_after_ro_mount" "for dir in read-only filesystem"
203 file3_stat_after_ro_mount=`_stat $TPATH/dir2/file3`
204 _compare_stat_times NNN "$file3_stat_before_ro_mount" \
205 "$file3_stat_after_ro_mount" "for file in read-only filesystem"
209 echo "Silence is golden"