generic: test MADV_POPULATE_READ with IO errors
[xfstests-dev.git] / tests / generic / 635
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0-or-later
3 # Copyright (c) 2021 Oracle.  All Rights Reserved.
4 #
5 # FS QA Test No. 635
6 #
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.
11 #
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
15 # values correctly.
16 #
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
20 # for an update.
21
22 . ./common/preamble
23 _begin_fstest auto quick atime bigtime shutdown
24
25 # Import common functions.
26
27 # real QA test starts here
28 _supported_fs generic
29 _require_scratch
30 _require_scratch_shutdown
31
32 _scratch_mkfs > $seqres.full
33 _scratch_mount
34
35 # Does our userspace even support large dates?
36 test_bigdates=1
37 touch -d 'May 30 01:53:03 UTC 2514' $SCRATCH_MNT 2>/dev/null || test_bigdates=0
38
39 # And can we do statx?
40 test_statx=1
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') || \
43         test_statx=0
44
45 echo "Userspace support of large timestamps: $test_bigdates" >> $seqres.full
46 echo "xfs_io support of statx: $test_statx" >> $seqres.full
47
48 touchme() {
49         local arg="$1"
50         local name="$2"
51
52         echo "$arg" > $SCRATCH_MNT/t_$name
53         touch -d "$arg" $SCRATCH_MNT/t_$name
54 }
55
56 report() {
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'
63         done
64 }
65
66 # -2147483648 (S32_MIN, or classic unix min)
67 touchme 'Dec 13 20:45:52 UTC 1901' s32_min
68
69 # 2147483647 (S32_MAX, or classic unix max)
70 touchme 'Jan 19 03:14:07 UTC 2038' s32_max
71
72 # 7956915742, all twos
73 touchme 'Feb 22 22:22:22 UTC 2222' all_twos
74
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
78
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
81
82         # 17179869183 (u34 time if you start from the unix epoch)
83         touchme 'May 30 01:53:03 UTC 2514' u34_max
84
85         # Latest date we can synthesize(?)
86         touchme 'Dec 31 23:59:59 UTC 2147483647' abs_max_time
87
88         # Earliest date we can synthesize(?)
89         touchme 'Jan 1 00:00:00 UTC 0' abs_min_time
90 fi
91
92 # Query timestamps from incore
93 echo before >> $seqres.full
94 report > $tmp.before_crash
95 cat $tmp.before_crash >> $seqres.full
96
97 _scratch_shutdown -f
98 _scratch_cycle_mount
99
100 # Query timestamps from disk
101 echo after >> $seqres.full
102 report > $tmp.after_crash
103 cat $tmp.after_crash >> $seqres.full
104
105 # Did they match?
106 cmp -s $tmp.before_crash $tmp.after_crash
107
108 # success, all done
109 status=0
110 exit