2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2016 Deepa Dinamani. All Rights Reserved.
7 # Tests to verify policy for filesystem timestamps for
9 # 1. Verify filesystem rw mount according to sysctl
10 # timestamp_supported.
11 # 2. Verify timestamp clamping for timestamps beyond max
12 # timestamp supported.
14 # Exit status 1: either or both tests above fail.
15 # Exit status 0: both the above tests pass.
18 seqres=$RESULT_DIR/$seq
19 echo "QA output created by $seq"
23 status=1 # failure is the default!
24 trap "exit \$status" 0 1 2 3 15
26 # Get standard environment, filters and checks.
31 # remove previous $seqres.full before test
34 # Prerequisites for the test run.
38 _require_xfs_io_command utimes
40 # Compare file timestamps obtained from stat
41 # with a given timestamp.
47 stat_timestamp=`stat -c"%X;%Y" $file`
49 prev_timestamp="$timestamp;$timestamp"
50 if [ $prev_timestamp != $stat_timestamp ]; then
51 echo "$prev_timestamp != $stat_timestamp" | tee -a $seqres.full
61 # check if the time needs update
62 if [ $update_time -eq 1 ]; then
63 echo "Updating file: $file to timestamp `date -d @$timestamp`" >> $seqres.full
64 $XFS_IO_PROG -f -c "utimes $timestamp 0 $timestamp 0" $file
66 echo "Failed to update times on $file" | tee -a $seqres.full
70 tsclamp=$(($timestamp>$tsmax?$tsmax:$timestamp))
71 echo "Checking file: $file Updated timestamp is `date -d @$tsclamp`" >> $seqres.full
72 check_stat $file $tsclamp
81 for TIME in "${TIMESTAMPS[@]}"; do
82 run_test_individual ${SCRATCH_MNT}/test_$n $TIME $update_time
87 _scratch_mkfs &>> $seqres.full 2>&1 || _fail "mkfs failed"
88 _require_y2038 $SCRATCH_DEV
90 read tsmin tsmax <<<$(_filesystem_timestamp_range $SCRATCH_DEV)
91 echo min supported timestamp $tsmin $(date --date=@$tsmin) >> $seqres.full
92 echo max supported timestamp $tsmax $(date --date=@$tsmax) >> $seqres.full
94 # Test timestamps array
96 declare -a TIMESTAMPS=(
106 # Max timestamp is hardcoded to Mon Jan 18 19:14:07 PST 2038
108 echo "max timestamp that needs to be supported by fs for rw mount is" \
109 "$((sys_tsmax+1)) $(date --date=@$((sys_tsmax+1)))" >> $seqres.full
111 read ts_check <<<$(cat /proc/sys/fs/fs-timestamp-check-on)
116 if [ $ts_check -ne 0 ]; then
117 echo "sysctl filesystem timestamp check is on" >> $seqres.full
118 # check for mount failure if the minimum requirement for max timestamp
119 # supported is not met.
120 if [ $sys_tsmax -ge $tsmax ]; then
121 if [ $result -eq 0 ]; then
122 echo "mount test failed" | tee -a $seqres.full
126 if [ $result -ne 0 ]; then
127 echo "failed to mount $SCRATCH_DEV" | tee -a $seqres.full
132 # if sysctl switch is off then mount should succeed always.
133 echo "sysctl filesystem timestamp check is off" >> $seqres.full
134 if [ $result -ne 0 ]; then
135 echo "failed to mount $SCRATCH_DEV and timestamp check is off" >> $seqres.full
141 echo "In memory timestamps update test start" >> $seqres.full
143 # update time on the file
146 run_test $update_time
148 echo "In memory timestamps update complete" >> $seqres.full
150 echo "Unmounting and mounting scratch $SCRATCH_MNT" >> $seqres.full
152 # unmount and remount $SCRATCH_DEV
159 # Do not update time on the file this time, just read from disk
162 echo "On disk timestamps update test start" >> $seqres.full
165 run_test $update_time
167 echo "On disk timestamps update test complete" >> $seqres.full
169 echo "y2038 inode timestamp tests completed successfully"