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