2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2016, Oracle and/or its affiliates. All Rights Reserved.
7 # See how well reflink handles ^C in the middle of a slow reflink.
10 seqres=$RESULT_DIR/$seq
11 echo "QA output created by $seq"
15 status=1 # failure is the default!
16 trap "_cleanup; exit \$status" 0 1 2 3 15
21 rm -rf $tmp.* $TEST_DIR/before $TEST_DIR/after
24 # get standard environment, filters and checks
30 # real QA test starts here
31 _require_scratch_reflink
33 _require_command "$TIMEOUT_PROG" "timeout"
35 test $FSTYP == "nfs" && _notrun "NFS can't interrupt clone operations"
39 echo "Format and mount"
40 _scratch_mkfs > $seqres.full 2>&1
41 _scratch_mount >> $seqres.full 2>&1
43 testdir=$SCRATCH_MNT/test-$seq
46 echo "Create a one block file"
47 blksz="$(_get_block_size $testdir)"
48 _pwrite_byte 0x61 0 $blksz $testdir/file1 >> $seqres.full
50 fnr=26 # 2^26 reflink extents should be enough to find a slow op?
51 timeout=8 # guarantee a good long run...
52 echo "Find a reflink size that takes a long time"
53 truncate -s $(( (2 ** i) * blksz)) $testdir/file1
54 for i in $(seq 0 $fnr); do
55 echo " ++ Reflink size $i, $((2 ** i)) blocks" >> $seqres.full
56 n=$(( (2 ** i) * blksz))
57 touch $TEST_DIR/before
58 $XFS_IO_PROG -f -c "reflink $testdir/file1 0 $n $n" $testdir/file1 >> $seqres.full 2>&1
60 before=$(stat -c '%Y' $TEST_DIR/before)
61 after=$(stat -c '%Y' $TEST_DIR/after)
62 delta=$((after - before))
63 test $delta -gt $timeout && break
66 echo "Try to kill reflink after a shorter period of time"
67 kill_after=2 # give us a shorter time to die
68 n=$(_get_filesize $testdir/file1)
69 echo "performing kill test on $n bytes..." >> $seqres.full
70 touch $TEST_DIR/before
71 $TIMEOUT_PROG -s INT ${kill_after}s $XFS_IO_PROG -f -c "reflink $testdir/file1 0 $n $n" $testdir/file1 >> $seqres.full 2>&1
73 before=$(stat -c '%Y' $TEST_DIR/before)
74 after=$(stat -c '%Y' $TEST_DIR/after)
75 delta=$((after - before))
76 echo "reflink of $n bytes took $delta seconds" >> $seqres.full
77 test $delta -gt $timeout && _fail "reflink didn't stop in time, n=$n t=$delta"
79 echo "Check scratch fs"
80 sleep 2 # give it a few seconds to actually die...