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 SIGKILL in the middle of a slow reflink.
10 _begin_fstest auto clone
12 # Override the default cleanup function.
16 rm -rf $tmp.* $TEST_DIR/before $TEST_DIR/after
19 # Import common functions.
24 # real QA test starts here
25 _require_scratch_reflink
27 _require_command "$TIMEOUT_PROG" "timeout"
29 test $FSTYP == "nfs" && _notrun "NFS can't interrupt clone operations"
31 echo "Format and mount"
32 _scratch_mkfs > $seqres.full 2>&1
33 _scratch_mount >> $seqres.full 2>&1
35 testdir=$SCRATCH_MNT/test-$seq
38 echo "Create a one block file"
39 blksz="$(_get_block_size $testdir)"
40 _pwrite_byte 0x61 0 $blksz $testdir/file1 >> $seqres.full
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
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
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)
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"
71 echo "Check scratch fs"
72 sleep 2 # give it a few seconds to actually die...