generic: test for file loss after mix of rename, fsync and inode eviction
[xfstests-dev.git] / tests / generic / 298
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2016, Oracle and/or its affiliates.  All Rights Reserved.
4 #
5 # FS QA Test No. 298
6 #
7 # See how well reflink handles SIGKILL in the middle of a slow reflink.
8 #
9 . ./common/preamble
10 _begin_fstest auto clone
11
12 # Override the default cleanup function.
13 _cleanup()
14 {
15     cd /
16     rm -rf $tmp.* $TEST_DIR/before $TEST_DIR/after
17 }
18
19 # Import common functions.
20 . ./common/filter
21 . ./common/attr
22 . ./common/reflink
23
24 # real QA test starts here
25 _require_scratch_reflink
26 _require_cp_reflink
27 _require_command "$TIMEOUT_PROG" "timeout"
28
29 test $FSTYP == "nfs"  && _notrun "NFS can't interrupt clone operations"
30
31 echo "Format and mount"
32 _scratch_mkfs > $seqres.full 2>&1
33 _scratch_mount >> $seqres.full 2>&1
34
35 testdir=$SCRATCH_MNT/test-$seq
36 mkdir $testdir
37
38 echo "Create a one block file"
39 blksz="$(_get_block_size $testdir)"
40 _pwrite_byte 0x61 0 $blksz $testdir/file1 >> $seqres.full
41
42 fnr=26          # 2^26 reflink extents should be enough to find a slow op?
43 timeout=8       # guarantee a good long run...
44 echo "Find a reflink size that takes a long time"
45 truncate -s $(( (2 ** i) * blksz)) $testdir/file1
46 for i in $(seq 0 $fnr); do
47         echo " ++ Reflink size $i, $((2 ** i)) blocks" >> $seqres.full
48         n=$(( (2 ** i) * blksz))
49         touch $TEST_DIR/before
50         $XFS_IO_PROG -f -c "reflink $testdir/file1 0 $n $n" $testdir/file1 >> $seqres.full 2>&1
51         touch $TEST_DIR/after
52         before=$(stat -c '%Y' $TEST_DIR/before)
53         after=$(stat -c '%Y' $TEST_DIR/after)
54         delta=$((after - before))
55         test $delta -gt $timeout && break
56 done
57
58 echo "Try to kill reflink after a shorter period of time"
59 kill_after=2    # give us a shorter time to die
60 n=$(_get_filesize $testdir/file1)
61 echo "performing kill test on $n bytes..." >> $seqres.full
62 touch $TEST_DIR/before
63 urk=$($TIMEOUT_PROG -s KILL ${kill_after}s $XFS_IO_PROG -f -c "reflink $testdir/file1 0 $n $n" $testdir/file1 >> $seqres.full 2>&1)
64 touch $TEST_DIR/after
65 before=$(stat -c '%Y' $TEST_DIR/before)
66 after=$(stat -c '%Y' $TEST_DIR/after)
67 delta=$((after - before))
68 echo "reflink of $n bytes took $delta seconds" >> $seqres.full
69 test $delta -gt $timeout && _fail "reflink didn't stop in time, n=$n t=$delta"
70
71 echo "Check scratch fs"
72 sleep 2         # give it a few seconds to actually die...
73
74 # success, all done
75 status=0
76 exit