4 # Tests to verify policy for filesystem timestamps for
6 # 1. Verify filesystem rw mount according to sysctl
8 # 2. Verify timestamp clamping for timestamps beyond max
11 # Exit status 1: either or both tests above fail.
12 # Exit status 0: both the above tests pass.
14 #-----------------------------------------------------------------------
15 # Copyright (c) 2016 Deepa Dinamani. All Rights Reserved.
17 # This program is free software; you can redistribute it and/or
18 # modify it under the terms of the GNU General Public License as
19 # published by the Free Software Foundation.
21 # This program is distributed in the hope that it would be useful,
22 # but WITHOUT ANY WARRANTY; without even the implied warranty of
23 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 # GNU General Public License for more details.
26 # You should have received a copy of the GNU General Public License
27 # along with this program; if not, write the Free Software Foundation,
28 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
29 #-----------------------------------------------------------------------
33 seqres=$RESULT_DIR/$seq
34 echo "QA output created by $seq"
38 status=1 # failure is the default!
39 trap "exit \$status" 0 1 2 3 15
41 # Get standard environment, filters and checks.
46 # remove previous $seqres.full before test
49 # Prerequisites for the test run.
53 _require_xfs_io_command utimes
55 # Compare file timestamps obtained from stat
56 # with a given timestamp.
62 stat_timestamp=`stat -c"%X;%Y" $file`
64 prev_timestamp="$timestamp;$timestamp"
65 if [ $prev_timestamp != $stat_timestamp ]; then
66 echo "$prev_timestamp != $stat_timestamp" | tee -a $seqres.full
76 # check if the time needs update
77 if [ $update_time -eq 1 ]; then
78 echo "Updating file: $file to timestamp `date -d @$timestamp`" >> $seqres.full
79 $XFS_IO_PROG -f -c "utimes $timestamp 0 $timestamp 0" $file
81 echo "Failed to update times on $file" | tee -a $seqres.full
85 tsclamp=$(($timestamp>$tsmax?$tsmax:$timestamp))
86 echo "Checking file: $file Updated timestamp is `date -d @$tsclamp`" >> $seqres.full
87 check_stat $file $tsclamp
96 for TIME in "${TIMESTAMPS[@]}"; do
97 run_test_individual ${SCRATCH_MNT}/test_$n $TIME $update_time
102 _scratch_mkfs &>> $seqres.full 2>&1 || _fail "mkfs failed"
103 _require_y2038 $SCRATCH_DEV
105 read tsmin tsmax <<<$(_filesystem_timestamp_range $SCRATCH_DEV)
106 echo min supported timestamp $tsmin $(date --date=@$tsmin) >> $seqres.full
107 echo max supported timestamp $tsmax $(date --date=@$tsmax) >> $seqres.full
109 # Test timestamps array
111 declare -a TIMESTAMPS=(
121 # Max timestamp is hardcoded to Mon Jan 18 19:14:07 PST 2038
123 echo "max timestamp that needs to be supported by fs for rw mount is" \
124 "$((sys_tsmax+1)) $(date --date=@$((sys_tsmax+1)))" >> $seqres.full
126 read ts_check <<<$(cat /proc/sys/fs/fs-timestamp-check-on)
131 if [ $ts_check -ne 0 ]; then
132 echo "sysctl filesystem timestamp check is on" >> $seqres.full
133 # check for mount failure if the minimum requirement for max timestamp
134 # supported is not met.
135 if [ $sys_tsmax -ge $tsmax ]; then
136 if [ $result -eq 0 ]; then
137 echo "mount test failed" | tee -a $seqres.full
141 if [ $result -ne 0 ]; then
142 echo "failed to mount $SCRATCH_DEV" | tee -a $seqres.full
147 # if sysctl switch is off then mount should succeed always.
148 echo "sysctl filesystem timestamp check is off" >> $seqres.full
149 if [ $result -ne 0 ]; then
150 echo "failed to mount $SCRATCH_DEV and timestamp check is off" >> $seqres.full
156 echo "In memory timestamps update test start" >> $seqres.full
158 # update time on the file
161 run_test $update_time
163 echo "In memory timestamps update complete" >> $seqres.full
165 echo "Unmounting and mounting scratch $SCRATCH_MNT" >> $seqres.full
167 # unmount and remount $SCRATCH_DEV
174 # Do not update time on the file this time, just read from disk
177 echo "On disk timestamps update test start" >> $seqres.full
180 run_test $update_time
182 echo "On disk timestamps update test complete" >> $seqres.full
184 echo "y2038 inode timestamp tests completed successfully"