2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2014, Oracle and/or its affiliates. All Rights Reserved.
5 # FS QA Test No. generic/003
7 # Tests the noatime, relatime, strictatime and nodiratime mount options.
8 # There is an extra check for Btrfs to ensure that the access time is
9 # never updated on read-only subvolumes. (Regression test for bug fixed
10 # with commit 93fd63c2f001ca6797c6b15b696a484b165b4800)
13 seqres=$RESULT_DIR/$seq
14 echo "QA output created by $seq"
18 status=1 # failure is the default!
19 trap "_cleanup; exit \$status" 0 1 2 3 15
27 # get standard environment, filters and checks
31 # real QA test starts here
40 if [ "$FSTYP" = "exfat" ]; then
41 # exfat's timestamp for access_time has double seconds granularity
51 _compare_stat_times() {
52 updated=$1 # 3 chars indicating if access, modify and
53 # change times should be updated (Y) or not (N)
54 IFS=';' read -a first_stat <<< "$2" # Convert first stat to array
55 IFS=';' read -a second_stat <<< "$3" # Convert second stat to array
56 test_step=$4 # Will be printed to output stream in case of an
57 # error, to make debugging easier
58 types=( access modify change )
61 if [ "${first_stat[$i]}" == "${second_stat[$i]}" ]; then
62 if [ "${updated:$i:1}" == "N" ]; then
65 echo -n "ERROR: ${types[$i]} time has not been updated "
67 elif [ "${updated:$i:1}" == "N" ]; then
68 echo -n "ERROR: ${types[$i]} time has changed "
74 _scratch_mkfs >> $seqres.full 2>&1 || _fail "mkfs failed"
75 _scratch_mount "-o relatime"
77 if [ "$FSTYP" = "btrfs" ]; then
78 TPATH=$SCRATCH_MNT/sub1
79 $BTRFS_UTIL_PROG subvolume create $TPATH > $seqres.full
85 echo "aaa" > $TPATH/dir1/file1
86 file1_stat_before_first_access=`_stat $TPATH/dir1/file1`
88 # Accessing file1 the first time
90 cat $TPATH/dir1/file1 > /dev/null
91 file1_stat_after_first_access=`_stat $TPATH/dir1/file1`
92 _compare_stat_times YNN "$file1_stat_before_first_access" \
93 "$file1_stat_after_first_access" "after accessing file1 first time"
95 # Accessing file1 a second time
97 cat $TPATH/dir1/file1 > /dev/null
98 file1_stat_after_second_access=`_stat $TPATH/dir1/file1`
99 _compare_stat_times NNN "$file1_stat_after_first_access" \
100 "$file1_stat_after_second_access" "after accessing file1 second time"
102 # Mounting with nodiratime option
103 _scratch_cycle_mount "nodiratime"
104 file1_stat_after_remount=`_stat $TPATH/dir1/file1`
105 _compare_stat_times NNN "$file1_stat_after_second_access" \
106 "$file1_stat_after_remount" "for file1 after remount"
108 # Creating dir2 and file2, checking directory stats
110 dir2_stat_before_file_creation=`_stat $TPATH/dir2`
112 echo "bbb" > $TPATH/dir2/file2
113 dir2_stat_after_file_creation=`_stat $TPATH/dir2`
114 _compare_stat_times NYY "$dir2_stat_before_file_creation" \
115 "$dir2_stat_after_file_creation" "for dir2 after file creation"
118 file2_stat_before_first_access=`_stat $TPATH/dir2/file2`
120 cat $TPATH/dir2/file2 > /dev/null
121 file2_stat_after_first_access=`_stat $TPATH/dir2/file2`
122 _compare_stat_times YNN "$file2_stat_before_first_access" \
123 "$file2_stat_after_first_access" "after accessing file2"
124 dir2_stat_after_file_access=`_stat $TPATH/dir2`
125 _compare_stat_times NNN "$dir2_stat_after_file_creation" \
126 "$dir2_stat_after_file_access" "for dir2 after file access"
128 # Mounting with noatime option, creating a file and accessing it
129 _scratch_cycle_mount "noatime"
130 echo "ccc" > $TPATH/dir2/file3
131 file3_stat_before_first_access=`_stat $TPATH/dir2/file3`
133 cat $TPATH/dir2/file3 > /dev/null
134 file3_stat_after_first_access=`_stat $TPATH/dir2/file3`
135 _compare_stat_times NNN "$file3_stat_before_first_access" \
136 "$file3_stat_after_first_access" "after accessing file3 first time"
138 # Checking that the modify and change times are still updated
139 file1_stat_before_modify=`_stat $TPATH/dir1/file1`
141 echo "xyz" > $TPATH/dir1/file1
142 file1_stat_after_modify=`_stat $TPATH/dir1/file1`
143 _compare_stat_times NYY "$file1_stat_before_modify" \
144 "$file1_stat_after_modify" "after modifying file1"
146 # exfat does not support last metadata change timestamp
147 if [ "$FSTYP" != "exfat" ]; then
149 mv $TPATH/dir1/file1 $TPATH/dir1/file1_renamed
150 file1_stat_after_change=`_stat $TPATH/dir1/file1_renamed`
151 _compare_stat_times NNY "$file1_stat_after_modify" \
152 "$file1_stat_after_change" "after changing file1"
155 # Mounting with strictatime option and
156 # accessing a previously created file twice
157 _scratch_cycle_mount "strictatime"
158 cat $TPATH/dir2/file3 > /dev/null
159 file3_stat_after_second_access=`_stat $TPATH/dir2/file3`
160 _compare_stat_times YNN "$file3_stat_after_first_access" \
161 "$file3_stat_after_second_access" "after accessing file3 second time"
163 cat $TPATH/dir2/file3 > /dev/null
164 file3_stat_after_third_access=`_stat $TPATH/dir2/file3`
165 _compare_stat_times YNN "$file3_stat_after_second_access" \
166 "$file3_stat_after_third_access" "after accessing file3 third time"
168 # Btrfs only: Creating readonly snapshot. Access time should never
169 # be updated, even when the strictatime mount option is active
170 if [ "$FSTYP" = "btrfs" ]; then
171 SPATH=$SCRATCH_MNT/snap1
172 btrfs subvol snapshot -r $TPATH $SPATH >> $seqres.full
173 dir2_stat_readonly_before_access=`_stat $SPATH/dir2`
175 ls $SPATH/dir2 >> $seqres.full
176 cat $SPATH/dir2/file3 >> $seqres.full
177 dir2_stat_readonly_after_access=`_stat $SPATH/dir2`
178 _compare_stat_times NNN "$dir2_stat_readonly_before_access" \
179 "$dir2_stat_readonly_after_access" "for dir in readonly subvol"
180 file3_stat_readonly_after_access=`_stat $SPATH/dir2/file3`
181 _compare_stat_times NNN "$file3_stat_after_third_access" \
182 "$file3_stat_readonly_after_access" "for file in readonly subvol"
185 # Mounting read-only. Access time should never be updated, despite the
186 # strictatime mount option.
188 dir2_stat_before_ro_mount=`_stat $TPATH/dir2`
189 file3_stat_before_ro_mount=`_stat $TPATH/dir2/file3`
190 _scratch_cycle_mount "ro,strictatime"
191 ls $TPATH/dir2 > /dev/null
192 cat $TPATH/dir2/file3 > /dev/null
193 dir2_stat_after_ro_mount=`_stat $TPATH/dir2`
194 _compare_stat_times NNN "$dir2_stat_before_ro_mount" \
195 "$dir2_stat_after_ro_mount" "for dir in read-only filesystem"
196 file3_stat_after_ro_mount=`_stat $TPATH/dir2/file3`
197 _compare_stat_times NNN "$file3_stat_before_ro_mount" \
198 "$file3_stat_after_ro_mount" "for file in read-only filesystem"
202 echo "Silence is golden"