2 # SPDX-License-Identifier: GPL-2.0-or-later
3 # Copyright (c) 2021 Oracle. All Rights Reserved.
7 # Make sure we can store and retrieve timestamps on the extremes of the
8 # date ranges supported by userspace, and the common places where overflows
9 # can happen. This test also ensures that the timestamps are persisted
10 # correctly after a shutdown.
12 # This differs from generic/402 in that we don't constrain ourselves to the
13 # range that the filesystem claims to support; we attempt various things that
14 # /userspace/ can parse, and then check that the vfs clamps and persists the
17 # NOTE: Old kernels (pre 5.4) allow filesystems to truncate timestamps silently
18 # when writing timestamps to disk! This test detects this silent truncation
19 # and fails. If you see a failure on such a kernel, contact your distributor
23 _begin_fstest auto quick atime bigtime shutdown
25 # Import common functions.
27 # real QA test starts here
30 _require_scratch_shutdown
32 _scratch_mkfs > $seqres.full
35 # Does our userspace even support large dates?
37 touch -d 'May 30 01:53:03 UTC 2514' $SCRATCH_MNT 2>/dev/null || test_bigdates=0
39 # And can we do statx?
41 ($XFS_IO_PROG -c 'help statx' | grep -q 'Print raw statx' && \
42 $XFS_IO_PROG -c 'statx -r' $SCRATCH_MNT 2>/dev/null | grep -q 'stat.mtime') || \
45 echo "Userspace support of large timestamps: $test_bigdates" >> $seqres.full
46 echo "xfs_io support of statx: $test_statx" >> $seqres.full
52 echo "$arg" > $SCRATCH_MNT/t_$name
53 touch -d "$arg" $SCRATCH_MNT/t_$name
57 local files=($SCRATCH_MNT/t_*)
58 for file in "${files[@]}"; do
59 echo "${file}: $(cat "${file}")"
60 TZ=UTC stat -c '%y %Y %n' "${file}"
61 test $test_statx -gt 0 && \
62 $XFS_IO_PROG -c 'statx -r' "${file}" | grep 'stat.mtime'
66 # -2147483648 (S32_MIN, or classic unix min)
67 touchme 'Dec 13 20:45:52 UTC 1901' s32_min
69 # 2147483647 (S32_MAX, or classic unix max)
70 touchme 'Jan 19 03:14:07 UTC 2038' s32_max
72 # 7956915742, all twos
73 touchme 'Feb 22 22:22:22 UTC 2222' all_twos
75 if [ $test_bigdates -gt 0 ]; then
76 # 16299260424 (u64 nsec counter from s32_min, like xfs does)
77 touchme 'Tue Jul 2 20:20:24 UTC 2486' u64ns_from_s32_min
79 # 15032385535 (u34 time if you start from s32_min, like ext4 does)
80 touchme 'May 10 22:38:55 UTC 2446' u34_from_s32_min
82 # 17179869183 (u34 time if you start from the unix epoch)
83 touchme 'May 30 01:53:03 UTC 2514' u34_max
85 # Latest date we can synthesize(?)
86 touchme 'Dec 31 23:59:59 UTC 2147483647' abs_max_time
88 # Earliest date we can synthesize(?)
89 touchme 'Jan 1 00:00:00 UTC 0' abs_min_time
92 # Query timestamps from incore
93 echo before >> $seqres.full
94 report > $tmp.before_crash
95 cat $tmp.before_crash >> $seqres.full
100 # Query timestamps from disk
101 echo after >> $seqres.full
102 report > $tmp.after_crash
103 cat $tmp.after_crash >> $seqres.full
106 cmp -s $tmp.before_crash $tmp.after_crash