generic: convert tests to SPDX license tags
[xfstests-dev.git] / tests / generic / 297
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. 297
6 #
7 # See how well reflink handles ^C in the middle of a slow reflink.
8 #
9 seq=`basename $0`
10 seqres=$RESULT_DIR/$seq
11 echo "QA output created by $seq"
12
13 here=`pwd`
14 tmp=/tmp/$$
15 status=1    # failure is the default!
16 trap "_cleanup; exit \$status" 0 1 2 3 15
17
18 _cleanup()
19 {
20     cd /
21     rm -rf $tmp.* $TEST_DIR/before $TEST_DIR/after
22 }
23
24 # get standard environment, filters and checks
25 . ./common/rc
26 . ./common/filter
27 . ./common/attr
28 . ./common/reflink
29
30 # real QA test starts here
31 _supported_os Linux
32 _require_scratch_reflink
33 _require_cp_reflink
34 _require_command "$TIMEOUT_PROG" "timeout"
35
36 test $FSTYP == "nfs"  && _notrun "NFS can't interrupt clone operations"
37
38 rm -f $seqres.full
39
40 echo "Format and mount"
41 _scratch_mkfs > $seqres.full 2>&1
42 _scratch_mount >> $seqres.full 2>&1
43
44 testdir=$SCRATCH_MNT/test-$seq
45 mkdir $testdir
46
47 echo "Create a one block file"
48 blksz="$(_get_block_size $testdir)"
49 _pwrite_byte 0x61 0 $blksz $testdir/file1 >> $seqres.full
50
51 fnr=26          # 2^26 reflink extents should be enough to find a slow op?
52 timeout=8       # guarantee a good long run...
53 echo "Find a reflink size that takes a long time"
54 truncate -s $(( (2 ** i) * blksz)) $testdir/file1
55 for i in $(seq 0 $fnr); do
56         echo " ++ Reflink size $i, $((2 ** i)) blocks" >> $seqres.full
57         n=$(( (2 ** i) * blksz))
58         touch $TEST_DIR/before
59         $XFS_IO_PROG -f -c "reflink $testdir/file1 0 $n $n" $testdir/file1 >> $seqres.full 2>&1
60         touch $TEST_DIR/after
61         before=$(stat -c '%Y' $TEST_DIR/before)
62         after=$(stat -c '%Y' $TEST_DIR/after)
63         delta=$((after - before))
64         test $delta -gt $timeout && break
65 done
66
67 echo "Try to kill reflink after a shorter period of time"
68 kill_after=2    # give us a shorter time to die
69 n=$(stat -c '%s' $testdir/file1)
70 echo "performing kill test on $n bytes..." >> $seqres.full
71 touch $TEST_DIR/before
72 $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 touch $TEST_DIR/after
74 before=$(stat -c '%Y' $TEST_DIR/before)
75 after=$(stat -c '%Y' $TEST_DIR/after)
76 delta=$((after - before))
77 echo "reflink of $n bytes took $delta seconds" >> $seqres.full
78 test $delta -gt $timeout && _fail "reflink didn't stop in time, n=$n t=$delta"
79
80 echo "Check scratch fs"
81 sleep 2         # give it a few seconds to actually die...
82
83 # success, all done
84 status=0
85 exit