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 _begin_fstest atime auto quick
15 # Import common functions.
18 # real QA test starts here
25 if [ "$FSTYP" = "exfat" ]; then
26 # exfat's timestamp for access_time has double seconds granularity
36 _compare_stat_times() {
37 updated=$1 # 3 chars indicating if access, modify and
38 # change times should be updated (Y) or not (N)
39 IFS=';' read -a first_stat <<< "$2" # Convert first stat to array
40 IFS=';' read -a second_stat <<< "$3" # Convert second stat to array
41 test_step=$4 # Will be printed to output stream in case of an
42 # error, to make debugging easier
43 types=( access modify change )
46 if [ "${first_stat[$i]}" == "${second_stat[$i]}" ]; then
47 if [ "${updated:$i:1}" == "N" ]; then
50 echo -n "ERROR: ${types[$i]} time has not been updated "
52 elif [ "${updated:$i:1}" == "N" ]; then
53 echo -n "ERROR: ${types[$i]} time has changed "
59 _scratch_mkfs >> $seqres.full 2>&1 || _fail "mkfs failed"
60 _scratch_mount "-o relatime"
62 if [ "$FSTYP" = "btrfs" ]; then
63 TPATH=$SCRATCH_MNT/sub1
64 $BTRFS_UTIL_PROG subvolume create $TPATH > $seqres.full
70 echo "aaa" > $TPATH/dir1/file1
71 file1_stat_before_first_access=`_stat $TPATH/dir1/file1`
73 # Accessing file1 the first time
75 cat $TPATH/dir1/file1 > /dev/null
76 file1_stat_after_first_access=`_stat $TPATH/dir1/file1`
77 _compare_stat_times YNN "$file1_stat_before_first_access" \
78 "$file1_stat_after_first_access" "after accessing file1 first time"
80 # Accessing file1 a second time
82 cat $TPATH/dir1/file1 > /dev/null
83 file1_stat_after_second_access=`_stat $TPATH/dir1/file1`
84 _compare_stat_times NNN "$file1_stat_after_first_access" \
85 "$file1_stat_after_second_access" "after accessing file1 second time"
87 # Mounting with nodiratime option
88 _scratch_cycle_mount "nodiratime"
89 file1_stat_after_remount=`_stat $TPATH/dir1/file1`
90 _compare_stat_times NNN "$file1_stat_after_second_access" \
91 "$file1_stat_after_remount" "for file1 after remount"
93 # Creating dir2 and file2, checking directory stats
95 dir2_stat_before_file_creation=`_stat $TPATH/dir2`
97 echo "bbb" > $TPATH/dir2/file2
98 dir2_stat_after_file_creation=`_stat $TPATH/dir2`
99 _compare_stat_times NYY "$dir2_stat_before_file_creation" \
100 "$dir2_stat_after_file_creation" "for dir2 after file creation"
103 file2_stat_before_first_access=`_stat $TPATH/dir2/file2`
105 cat $TPATH/dir2/file2 > /dev/null
106 file2_stat_after_first_access=`_stat $TPATH/dir2/file2`
107 _compare_stat_times YNN "$file2_stat_before_first_access" \
108 "$file2_stat_after_first_access" "after accessing file2"
109 dir2_stat_after_file_access=`_stat $TPATH/dir2`
110 _compare_stat_times NNN "$dir2_stat_after_file_creation" \
111 "$dir2_stat_after_file_access" "for dir2 after file access"
113 # Mounting with noatime option, creating a file and accessing it
114 _scratch_cycle_mount "noatime"
115 echo "ccc" > $TPATH/dir2/file3
116 file3_stat_before_first_access=`_stat $TPATH/dir2/file3`
118 cat $TPATH/dir2/file3 > /dev/null
119 file3_stat_after_first_access=`_stat $TPATH/dir2/file3`
120 _compare_stat_times NNN "$file3_stat_before_first_access" \
121 "$file3_stat_after_first_access" "after accessing file3 first time"
123 # Checking that the modify and change times are still updated
124 file1_stat_before_modify=`_stat $TPATH/dir1/file1`
126 echo "xyz" > $TPATH/dir1/file1
127 file1_stat_after_modify=`_stat $TPATH/dir1/file1`
128 _compare_stat_times NYY "$file1_stat_before_modify" \
129 "$file1_stat_after_modify" "after modifying file1"
131 # exfat does not support last metadata change timestamp
132 if [ "$FSTYP" != "exfat" ]; then
134 mv $TPATH/dir1/file1 $TPATH/dir1/file1_renamed
135 file1_stat_after_change=`_stat $TPATH/dir1/file1_renamed`
136 _compare_stat_times NNY "$file1_stat_after_modify" \
137 "$file1_stat_after_change" "after changing file1"
140 # Mounting with strictatime option and
141 # accessing a previously created file twice
142 _scratch_cycle_mount "strictatime"
143 cat $TPATH/dir2/file3 > /dev/null
144 file3_stat_after_second_access=`_stat $TPATH/dir2/file3`
145 _compare_stat_times YNN "$file3_stat_after_first_access" \
146 "$file3_stat_after_second_access" "after accessing file3 second time"
148 cat $TPATH/dir2/file3 > /dev/null
149 file3_stat_after_third_access=`_stat $TPATH/dir2/file3`
150 _compare_stat_times YNN "$file3_stat_after_second_access" \
151 "$file3_stat_after_third_access" "after accessing file3 third time"
153 # Btrfs only: Creating readonly snapshot. Access time should never
154 # be updated, even when the strictatime mount option is active
155 if [ "$FSTYP" = "btrfs" ]; then
156 SPATH=$SCRATCH_MNT/snap1
157 btrfs subvol snapshot -r $TPATH $SPATH >> $seqres.full
158 dir2_stat_readonly_before_access=`_stat $SPATH/dir2`
160 ls $SPATH/dir2 >> $seqres.full
161 cat $SPATH/dir2/file3 >> $seqres.full
162 dir2_stat_readonly_after_access=`_stat $SPATH/dir2`
163 _compare_stat_times NNN "$dir2_stat_readonly_before_access" \
164 "$dir2_stat_readonly_after_access" "for dir in readonly subvol"
165 file3_stat_readonly_after_access=`_stat $SPATH/dir2/file3`
166 _compare_stat_times NNN "$file3_stat_after_third_access" \
167 "$file3_stat_readonly_after_access" "for file in readonly subvol"
170 # Mounting read-only. Access time should never be updated, despite the
171 # strictatime mount option.
173 dir2_stat_before_ro_mount=`_stat $TPATH/dir2`
174 file3_stat_before_ro_mount=`_stat $TPATH/dir2/file3`
175 _scratch_cycle_mount "ro,strictatime"
176 ls $TPATH/dir2 > /dev/null
177 cat $TPATH/dir2/file3 > /dev/null
178 dir2_stat_after_ro_mount=`_stat $TPATH/dir2`
179 _compare_stat_times NNN "$dir2_stat_before_ro_mount" \
180 "$dir2_stat_after_ro_mount" "for dir in read-only filesystem"
181 file3_stat_after_ro_mount=`_stat $TPATH/dir2/file3`
182 _compare_stat_times NNN "$file3_stat_before_ro_mount" \
183 "$file3_stat_after_ro_mount" "for file in read-only filesystem"
187 echo "Silence is golden"