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
44 _compare_stat_times() {
45 updated=$1 # 3 chars indicating if access, modify and
46 # change times should be updated (Y) or not (N)
47 IFS=';' read -a first_stat <<< "$2" # Convert first stat to array
48 IFS=';' read -a second_stat <<< "$3" # Convert second stat to array
49 test_step=$4 # Will be printed to output stream in case of an
50 # error, to make debugging easier
51 types=( access modify change )
54 if [ "${first_stat[$i]}" == "${second_stat[$i]}" ]; then
55 if [ "${updated:$i:1}" == "N" ]; then
58 echo -n "ERROR: ${types[$i]} time has not been updated "
60 elif [ "${updated:$i:1}" == "N" ]; then
61 echo -n "ERROR: ${types[$i]} time has changed "
67 _scratch_mkfs >> $seqres.full 2>&1 || _fail "mkfs failed"
68 _scratch_mount "-o relatime"
70 if [ "$FSTYP" = "btrfs" ]; then
71 TPATH=$SCRATCH_MNT/sub1
72 $BTRFS_UTIL_PROG subvolume create $TPATH > $seqres.full
78 echo "aaa" > $TPATH/dir1/file1
79 file1_stat_before_first_access=`_stat $TPATH/dir1/file1`
81 # Accessing file1 the first time
83 cat $TPATH/dir1/file1 > /dev/null
84 file1_stat_after_first_access=`_stat $TPATH/dir1/file1`
85 _compare_stat_times YNN "$file1_stat_before_first_access" \
86 "$file1_stat_after_first_access" "after accessing file1 first time"
88 # Accessing file1 a second time
90 cat $TPATH/dir1/file1 > /dev/null
91 file1_stat_after_second_access=`_stat $TPATH/dir1/file1`
92 _compare_stat_times NNN "$file1_stat_after_first_access" \
93 "$file1_stat_after_second_access" "after accessing file1 second time"
95 # Mounting with nodiratime option
96 _scratch_cycle_mount "nodiratime"
97 file1_stat_after_remount=`_stat $TPATH/dir1/file1`
98 _compare_stat_times NNN "$file1_stat_after_second_access" \
99 "$file1_stat_after_remount" "for file1 after remount"
101 # Creating dir2 and file2, checking directory stats
103 dir2_stat_before_file_creation=`_stat $TPATH/dir2`
105 echo "bbb" > $TPATH/dir2/file2
106 dir2_stat_after_file_creation=`_stat $TPATH/dir2`
107 _compare_stat_times NYY "$dir2_stat_before_file_creation" \
108 "$dir2_stat_after_file_creation" "for dir2 after file creation"
111 file2_stat_before_first_access=`_stat $TPATH/dir2/file2`
113 cat $TPATH/dir2/file2 > /dev/null
114 file2_stat_after_first_access=`_stat $TPATH/dir2/file2`
115 _compare_stat_times YNN "$file2_stat_before_first_access" \
116 "$file2_stat_after_first_access" "after accessing file2"
117 dir2_stat_after_file_access=`_stat $TPATH/dir2`
118 _compare_stat_times NNN "$dir2_stat_after_file_creation" \
119 "$dir2_stat_after_file_access" "for dir2 after file access"
121 # Mounting with noatime option, creating a file and accessing it
122 _scratch_cycle_mount "noatime"
123 echo "ccc" > $TPATH/dir2/file3
124 file3_stat_before_first_access=`_stat $TPATH/dir2/file3`
126 cat $TPATH/dir2/file3 > /dev/null
127 file3_stat_after_first_access=`_stat $TPATH/dir2/file3`
128 _compare_stat_times NNN "$file3_stat_before_first_access" \
129 "$file3_stat_after_first_access" "after accessing file3 first time"
131 # Checking that the modify and change times are still updated
132 file1_stat_before_modify=`_stat $TPATH/dir1/file1`
134 echo "xyz" > $TPATH/dir1/file1
135 file1_stat_after_modify=`_stat $TPATH/dir1/file1`
136 _compare_stat_times NYY "$file1_stat_before_modify" \
137 "$file1_stat_after_modify" "after modifying file1"
139 mv $TPATH/dir1/file1 $TPATH/dir1/file1_renamed
140 file1_stat_after_change=`_stat $TPATH/dir1/file1_renamed`
141 _compare_stat_times NNY "$file1_stat_after_modify" \
142 "$file1_stat_after_change" "after changing file1"
144 # Mounting with strictatime option and
145 # accessing a previously created file twice
146 _scratch_cycle_mount "strictatime"
147 cat $TPATH/dir2/file3 > /dev/null
148 file3_stat_after_second_access=`_stat $TPATH/dir2/file3`
149 _compare_stat_times YNN "$file3_stat_after_first_access" \
150 "$file3_stat_after_second_access" "after accessing file3 second time"
152 cat $TPATH/dir2/file3 > /dev/null
153 file3_stat_after_third_access=`_stat $TPATH/dir2/file3`
154 _compare_stat_times YNN "$file3_stat_after_second_access" \
155 "$file3_stat_after_third_access" "after accessing file3 third time"
157 # Btrfs only: Creating readonly snapshot. Access time should never
158 # be updated, even when the strictatime mount option is active
159 if [ "$FSTYP" = "btrfs" ]; then
160 SPATH=$SCRATCH_MNT/snap1
161 btrfs subvol snapshot -r $TPATH $SPATH >> $seqres.full
162 dir2_stat_readonly_before_access=`_stat $SPATH/dir2`
164 ls $SPATH/dir2 >> $seqres.full
165 cat $SPATH/dir2/file3 >> $seqres.full
166 dir2_stat_readonly_after_access=`_stat $SPATH/dir2`
167 _compare_stat_times NNN "$dir2_stat_readonly_before_access" \
168 "$dir2_stat_readonly_after_access" "for dir in readonly subvol"
169 file3_stat_readonly_after_access=`_stat $SPATH/dir2/file3`
170 _compare_stat_times NNN "$file3_stat_after_third_access" \
171 "$file3_stat_readonly_after_access" "for file in readonly subvol"
174 # Mounting read-only. Access time should never be updated, despite the
175 # strictatime mount option.
177 dir2_stat_before_ro_mount=`_stat $TPATH/dir2`
178 file3_stat_before_ro_mount=`_stat $TPATH/dir2/file3`
179 _scratch_cycle_mount "ro,strictatime"
180 ls $TPATH/dir2 > /dev/null
181 cat $TPATH/dir2/file3 > /dev/null
182 dir2_stat_after_ro_mount=`_stat $TPATH/dir2`
183 _compare_stat_times NNN "$dir2_stat_before_ro_mount" \
184 "$dir2_stat_after_ro_mount" "for dir in read-only filesystem"
185 file3_stat_after_ro_mount=`_stat $TPATH/dir2/file3`
186 _compare_stat_times NNN "$file3_stat_before_ro_mount" \
187 "$file3_stat_after_ro_mount" "for file in read-only filesystem"
191 echo "Silence is golden"