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 seqres=$RESULT_DIR/$seq
24 echo "QA output created by $seq"
28 status=1 # failure is the default!
29 trap "_cleanup; exit \$status" 0 1 2 3 15
37 # get standard environment, filters and checks
40 # real QA test starts here
43 _require_scratch_shutdown
47 _scratch_mkfs > $seqres.full
50 # Does our userspace even support large dates?
52 touch -d 'May 30 01:53:03 UTC 2514' $SCRATCH_MNT 2>/dev/null || test_bigdates=0
54 # And can we do statx?
56 ($XFS_IO_PROG -c 'help statx' | grep -q 'Print raw statx' && \
57 $XFS_IO_PROG -c 'statx -r' $SCRATCH_MNT 2>/dev/null | grep -q 'stat.mtime') || \
60 echo "Userspace support of large timestamps: $test_bigdates" >> $seqres.full
61 echo "xfs_io support of statx: $test_statx" >> $seqres.full
67 echo "$arg" > $SCRATCH_MNT/t_$name
68 touch -d "$arg" $SCRATCH_MNT/t_$name
72 local files=($SCRATCH_MNT/t_*)
73 for file in "${files[@]}"; do
74 echo "${file}: $(cat "${file}")"
75 TZ=UTC stat -c '%y %Y %n' "${file}"
76 test $test_statx -gt 0 && \
77 $XFS_IO_PROG -c 'statx -r' "${file}" | grep 'stat.mtime'
81 # -2147483648 (S32_MIN, or classic unix min)
82 touchme 'Dec 13 20:45:52 UTC 1901' s32_min
84 # 2147483647 (S32_MAX, or classic unix max)
85 touchme 'Jan 19 03:14:07 UTC 2038' s32_max
87 # 7956915742, all twos
88 touchme 'Feb 22 22:22:22 UTC 2222' all_twos
90 if [ $test_bigdates -gt 0 ]; then
91 # 16299260424 (u64 nsec counter from s32_min, like xfs does)
92 touchme 'Tue Jul 2 20:20:24 UTC 2486' u64ns_from_s32_min
94 # 15032385535 (u34 time if you start from s32_min, like ext4 does)
95 touchme 'May 10 22:38:55 UTC 2446' u34_from_s32_min
97 # 17179869183 (u34 time if you start from the unix epoch)
98 touchme 'May 30 01:53:03 UTC 2514' u34_max
100 # Latest date we can synthesize(?)
101 touchme 'Dec 31 23:59:59 UTC 2147483647' abs_max_time
103 # Earliest date we can synthesize(?)
104 touchme 'Jan 1 00:00:00 UTC 0' abs_min_time
107 # Query timestamps from incore
108 echo before >> $seqres.full
109 report > $tmp.before_crash
110 cat $tmp.before_crash >> $seqres.full
115 # Query timestamps from disk
116 echo after >> $seqres.full
117 report > $tmp.after_crash
118 cat $tmp.after_crash >> $seqres.full
121 cmp -s $tmp.before_crash $tmp.after_crash