blob: 999aed1425287aeb58cc2395ba8c3b6051f40f58 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
|
#! /bin/bash
# SPDX-License-Identifier: GPL-2.0
# Copyright (c) 2014, Oracle and/or its affiliates. All Rights Reserved.
#
# FS QA Test No. generic/003
#
# Tests the noatime, relatime, strictatime and nodiratime mount options.
# There is an extra check for Btrfs to ensure that the access time is
# never updated on read-only subvolumes. (Regression test for bug fixed
# with commit 93fd63c2f001ca6797c6b15b696a484b165b4800)
#
. ./common/preamble
_begin_fstest atime auto quick
# Import common functions.
. ./common/filter
# real QA test starts here
_supported_fs generic
_require_scratch
_require_atime
_require_relatime
if [ "$FSTYP" = "exfat" ]; then
# exfat's timestamp for access_time has double seconds granularity
access_delay=2.1
else
access_delay=1
fi
_stat() {
stat -c "%x;%y;%z" $1
}
_compare_stat_times() {
updated=$1 # 3 chars indicating if access, modify and
# change times should be updated (Y) or not (N)
IFS=';' read -a first_stat <<< "$2" # Convert first stat to array
IFS=';' read -a second_stat <<< "$3" # Convert second stat to array
test_step=$4 # Will be printed to output stream in case of an
# error, to make debugging easier
types=( access modify change )
for i in 0 1 2; do
if [ "${first_stat[$i]}" == "${second_stat[$i]}" ]; then
if [ "${updated:$i:1}" == "N" ]; then
continue;
fi
echo -n "ERROR: ${types[$i]} time has not been updated "
echo $test_step
elif [ "${updated:$i:1}" == "N" ]; then
echo -n "ERROR: ${types[$i]} time has changed "
echo $test_step
fi
done
}
_scratch_mkfs >> $seqres.full 2>&1 || _fail "mkfs failed"
_scratch_mount "-o relatime"
if [ "$FSTYP" = "btrfs" ]; then
TPATH=$SCRATCH_MNT/sub1
$BTRFS_UTIL_PROG subvolume create $TPATH > $seqres.full
else
TPATH=$SCRATCH_MNT
fi
mkdir $TPATH/dir1
echo "aaa" > $TPATH/dir1/file1
file1_stat_before_first_access=`_stat $TPATH/dir1/file1`
# Accessing file1 the first time
sleep $access_delay
cat $TPATH/dir1/file1 > /dev/null
file1_stat_after_first_access=`_stat $TPATH/dir1/file1`
_compare_stat_times YNN "$file1_stat_before_first_access" \
"$file1_stat_after_first_access" "after accessing file1 first time"
# Accessing file1 a second time
sleep $access_delay
cat $TPATH/dir1/file1 > /dev/null
file1_stat_after_second_access=`_stat $TPATH/dir1/file1`
_compare_stat_times NNN "$file1_stat_after_first_access" \
"$file1_stat_after_second_access" "after accessing file1 second time"
# Mounting with nodiratime option
_scratch_cycle_mount "nodiratime"
file1_stat_after_remount=`_stat $TPATH/dir1/file1`
_compare_stat_times NNN "$file1_stat_after_second_access" \
"$file1_stat_after_remount" "for file1 after remount"
# Creating dir2 and file2, checking directory stats
mkdir $TPATH/dir2
dir2_stat_before_file_creation=`_stat $TPATH/dir2`
sleep 1
echo "bbb" > $TPATH/dir2/file2
dir2_stat_after_file_creation=`_stat $TPATH/dir2`
_compare_stat_times NYY "$dir2_stat_before_file_creation" \
"$dir2_stat_after_file_creation" "for dir2 after file creation"
# Accessing file2
file2_stat_before_first_access=`_stat $TPATH/dir2/file2`
sleep $access_delay
cat $TPATH/dir2/file2 > /dev/null
file2_stat_after_first_access=`_stat $TPATH/dir2/file2`
_compare_stat_times YNN "$file2_stat_before_first_access" \
"$file2_stat_after_first_access" "after accessing file2"
dir2_stat_after_file_access=`_stat $TPATH/dir2`
_compare_stat_times NNN "$dir2_stat_after_file_creation" \
"$dir2_stat_after_file_access" "for dir2 after file access"
# Mounting with noatime option, creating a file and accessing it
_scratch_cycle_mount "noatime"
echo "ccc" > $TPATH/dir2/file3
file3_stat_before_first_access=`_stat $TPATH/dir2/file3`
sleep 1
cat $TPATH/dir2/file3 > /dev/null
file3_stat_after_first_access=`_stat $TPATH/dir2/file3`
_compare_stat_times NNN "$file3_stat_before_first_access" \
"$file3_stat_after_first_access" "after accessing file3 first time"
# Checking that the modify and change times are still updated
file1_stat_before_modify=`_stat $TPATH/dir1/file1`
sleep 1
echo "xyz" > $TPATH/dir1/file1
file1_stat_after_modify=`_stat $TPATH/dir1/file1`
_compare_stat_times NYY "$file1_stat_before_modify" \
"$file1_stat_after_modify" "after modifying file1"
# exfat does not support last metadata change timestamp
if [ "$FSTYP" != "exfat" ]; then
sleep 1
mv $TPATH/dir1/file1 $TPATH/dir1/file1_renamed
file1_stat_after_change=`_stat $TPATH/dir1/file1_renamed`
_compare_stat_times NNY "$file1_stat_after_modify" \
"$file1_stat_after_change" "after changing file1"
fi
# Mounting with strictatime option and
# accessing a previously created file twice
_scratch_cycle_mount "strictatime"
cat $TPATH/dir2/file3 > /dev/null
file3_stat_after_second_access=`_stat $TPATH/dir2/file3`
_compare_stat_times YNN "$file3_stat_after_first_access" \
"$file3_stat_after_second_access" "after accessing file3 second time"
sleep $access_delay
cat $TPATH/dir2/file3 > /dev/null
file3_stat_after_third_access=`_stat $TPATH/dir2/file3`
_compare_stat_times YNN "$file3_stat_after_second_access" \
"$file3_stat_after_third_access" "after accessing file3 third time"
# Btrfs only: Creating readonly snapshot. Access time should never
# be updated, even when the strictatime mount option is active
if [ "$FSTYP" = "btrfs" ]; then
SPATH=$SCRATCH_MNT/snap1
btrfs subvol snapshot -r $TPATH $SPATH >> $seqres.full
dir2_stat_readonly_before_access=`_stat $SPATH/dir2`
sleep 1
ls $SPATH/dir2 >> $seqres.full
cat $SPATH/dir2/file3 >> $seqres.full
dir2_stat_readonly_after_access=`_stat $SPATH/dir2`
_compare_stat_times NNN "$dir2_stat_readonly_before_access" \
"$dir2_stat_readonly_after_access" "for dir in readonly subvol"
file3_stat_readonly_after_access=`_stat $SPATH/dir2/file3`
_compare_stat_times NNN "$file3_stat_after_third_access" \
"$file3_stat_readonly_after_access" "for file in readonly subvol"
fi
# Mounting read-only. Access time should never be updated, despite the
# strictatime mount option.
sleep 1
dir2_stat_before_ro_mount=`_stat $TPATH/dir2`
file3_stat_before_ro_mount=`_stat $TPATH/dir2/file3`
_scratch_cycle_mount "ro,strictatime"
ls $TPATH/dir2 > /dev/null
cat $TPATH/dir2/file3 > /dev/null
dir2_stat_after_ro_mount=`_stat $TPATH/dir2`
_compare_stat_times NNN "$dir2_stat_before_ro_mount" \
"$dir2_stat_after_ro_mount" "for dir in read-only filesystem"
file3_stat_after_ro_mount=`_stat $TPATH/dir2/file3`
_compare_stat_times NNN "$file3_stat_before_ro_mount" \
"$file3_stat_after_ro_mount" "for file in read-only filesystem"
# success, all done
_scratch_unmount
echo "Silence is golden"
status=0
exit
|