common: add leading underscore to get_block_size
[xfstests-dev.git] / tests / generic / 297
1 #! /bin/bash
2 # FS QA Test No. 297
3 #
4 # See how well reflink handles ^C in the middle of a slow reflink.
5 #
6 #-----------------------------------------------------------------------
7 # Copyright (c) 2016, Oracle and/or its affiliates.  All Rights Reserved.
8 #
9 # This program is free software; you can redistribute it and/or
10 # modify it under the terms of the GNU General Public License as
11 # published by the Free Software Foundation.
12 #
13 # This program is distributed in the hope that it would be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 # GNU General Public License for more details.
17 #
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, write the Free Software Foundation,
20 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
21 #-----------------------------------------------------------------------
22
23 seq=`basename $0`
24 seqres=$RESULT_DIR/$seq
25 echo "QA output created by $seq"
26
27 here=`pwd`
28 tmp=/tmp/$$
29 status=1    # failure is the default!
30 trap "_cleanup; exit \$status" 0 1 2 3 15
31
32 _cleanup()
33 {
34     cd /
35     rm -rf $tmp.* $TEST_DIR/before $TEST_DIR/after
36 }
37
38 # get standard environment, filters and checks
39 . ./common/rc
40 . ./common/filter
41 . ./common/attr
42 . ./common/reflink
43
44 # real QA test starts here
45 _supported_os Linux
46 _require_scratch_reflink
47 _require_cp_reflink
48 _require_command "$(which timeout)" "timeout"
49
50 test $FSTYP == "nfs"  && _notrun "NFS can't interrupt clone operations"
51
52 rm -f $seqres.full
53
54 echo "Format and mount"
55 _scratch_mkfs > $seqres.full 2>&1
56 _scratch_mount >> $seqres.full 2>&1
57
58 testdir=$SCRATCH_MNT/test-$seq
59 mkdir $testdir
60
61 echo "Create a one block file"
62 blksz="$(_get_block_size $testdir)"
63 _pwrite_byte 0x61 0 $blksz $testdir/file1 >> $seqres.full
64
65 fnr=26          # 2^26 reflink extents should be enough to find a slow op?
66 timeout=8       # guarantee a good long run...
67 echo "Find a reflink size that takes a long time"
68 truncate -s $(( (2 ** i) * blksz)) $testdir/file1
69 for i in $(seq 0 $fnr); do
70         echo " ++ Reflink size $i, $((2 ** i)) blocks" >> $seqres.full
71         n=$(( (2 ** i) * blksz))
72         touch $TEST_DIR/before
73         $XFS_IO_PROG -f -c "reflink $testdir/file1 0 $n $n" $testdir/file1 >> $seqres.full 2>&1
74         touch $TEST_DIR/after
75         before=$(stat -c '%Y' $TEST_DIR/before)
76         after=$(stat -c '%Y' $TEST_DIR/after)
77         delta=$((after - before))
78         test $delta -gt $timeout && break
79 done
80
81 echo "Try to kill reflink after a shorter period of time"
82 kill_after=2    # give us a shorter time to die
83 n=$(stat -c '%s' $testdir/file1)
84 echo "performing kill test on $n bytes..." >> $seqres.full
85 touch $TEST_DIR/before
86 timeout -s INT ${kill_after}s $XFS_IO_PROG -f -c "reflink $testdir/file1 0 $n $n" $testdir/file1 >> $seqres.full 2>&1
87 touch $TEST_DIR/after
88 before=$(stat -c '%Y' $TEST_DIR/before)
89 after=$(stat -c '%Y' $TEST_DIR/after)
90 delta=$((after - before))
91 echo "reflink of $n bytes took $delta seconds" >> $seqres.full
92 test $delta -gt $timeout && _fail "reflink didn't stop in time, n=$n t=$delta"
93
94 echo "Check scratch fs"
95 sleep 2         # give it a few seconds to actually die...
96
97 # success, all done
98 status=0
99 exit