generic: test for file loss after mix of rename, fsync and inode eviction
[xfstests-dev.git] / tests / generic / 402
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2016 Deepa Dinamani.  All Rights Reserved.
4 #
5 # FS QA Test 402
6 #
7 # Test to verify filesystem timestamps for supported ranges.
8 #
9 # Exit status 1: test failed.
10 # Exit status 0: test passed.
11 #
12 . ./common/preamble
13 _begin_fstest auto quick rw bigtime
14
15 # Get standard environment, filters and checks.
16 . ./common/filter
17 . ./common/attr
18
19 # Prerequisites for the test run.
20 _supported_fs generic
21 _require_scratch
22 _require_check_dmesg
23 _require_xfs_io_command utimes
24
25 # Compare file timestamps obtained from stat
26 # with a given timestamp.
27 check_stat()
28 {
29         file=$1
30         timestamp=$2
31
32         stat_timestamp=`stat -c"%X;%Y" $file`
33
34         prev_timestamp="$timestamp;$timestamp"
35         if [ $prev_timestamp != $stat_timestamp ]; then
36                 echo "$prev_timestamp != $stat_timestamp" | tee -a $seqres.full
37         fi
38 }
39
40 run_test_individual()
41 {
42         file=$1
43         timestamp=$2
44         update_time=$3
45
46         # check if the time needs update
47         if [ $update_time -eq 1 ]; then
48                 echo "Updating file: $file to timestamp $timestamp"  >> $seqres.full
49                 rm -f $tmp.utimes
50                 $XFS_IO_PROG -f -c "utimes $timestamp 0 $timestamp 0" $file > $tmp.utimes 2>&1
51                 local res=$?
52
53                 cat $tmp.utimes >> $seqres.full
54                 if [ "$timestamp" -ne 0 ] && grep -q "Bad value" "$tmp.utimes"; then
55                         echo "xfs_io could not interpret time value \"$timestamp\", skipping \"$file\" test." >> $seqres.full
56                         rm -f $file $tmp.utimes
57                         return
58                 fi
59                 cat $tmp.utimes
60                 rm -f $tmp.utimes
61                 if [ $res -ne 0 ]; then
62                         echo "Failed to update times on $file" | tee -a $seqres.full
63                 fi
64         else
65                 if [ ! -f "$file" ]; then
66                         echo "xfs_io did not create file for time value \"$timestamp\", skipping test." >> $seqres.full
67                         return
68                 fi
69         fi
70
71         tsclamp=$((timestamp<tsmin?tsmin:timestamp>tsmax?tsmax:timestamp))
72         echo "Checking file: $file Updated timestamp is $tsclamp"  >> $seqres.full
73         check_stat $file $tsclamp
74 }
75
76 run_test()
77 {
78         update_time=$1
79
80         n=1
81
82         for TIME in "${TIMESTAMPS[@]}"; do
83                 run_test_individual ${SCRATCH_MNT}/test_$n $TIME $update_time
84                 ((n++))
85         done
86 }
87
88 _scratch_mkfs &>> $seqres.full 2>&1 || _fail "mkfs failed"
89 _scratch_mount
90
91 _require_timestamp_range $SCRATCH_DEV
92
93 read tsmin tsmax <<<$(_filesystem_timestamp_range $SCRATCH_DEV)
94 echo min supported timestamp $tsmin >> $seqres.full
95 echo max supported timestamp $tsmax >> $seqres.full
96
97 # Test timestamps array
98
99 declare -a TIMESTAMPS=(
100         $tsmin
101         0
102         $tsmax
103         $((tsmax/2))
104         $((tsmax+1))
105 )
106
107 status=0
108
109 # Begin test case 1
110 echo "In memory timestamps update test start" >> $seqres.full
111
112 # update time on the file
113 update_time=1
114
115 run_test $update_time
116
117 echo "In memory timestamps update complete" >> $seqres.full
118
119 echo "Unmounting and mounting scratch $SCRATCH_MNT" >> $seqres.full
120
121 # unmount and remount $SCRATCH_DEV
122 _scratch_cycle_mount
123
124 # Begin test case 2
125
126 n=1
127
128 # Do not update time on the file this time, just read from disk
129 update_time=0
130
131 echo "On disk timestamps update test start" >> $seqres.full
132
133 # Re-run test
134 run_test $update_time
135
136 echo "On disk timestamps update test complete" >> $seqres.full
137
138 echo Silence is golden
139 exit