c8fb527c4de64fd5fcd3bd902d9baefbc0f3ed60
[xfstests-dev.git] / tests / xfs / 265
1 #! /bin/bash
2 # FS QA Test No. 265
3 #
4 # Ensure that we can create enough distinct reflink entries to force creation
5 # of a multi-level refcount btree by reflinking a file a number of times and
6 # truncating the copies at successively lower sizes.  Delete and recreate a few
7 # times to exercise the refcount btree grow/shrink functions.
8 #
9 #-----------------------------------------------------------------------
10 # Copyright (c) 2016, Oracle and/or its affiliates.  All Rights Reserved.
11 #
12 # This program is free software; you can redistribute it and/or
13 # modify it under the terms of the GNU General Public License as
14 # published by the Free Software Foundation.
15 #
16 # This program is distributed in the hope that it would be useful,
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 # GNU General Public License for more details.
20 #
21 # You should have received a copy of the GNU General Public License
22 # along with this program; if not, write the Free Software Foundation,
23 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
24 #-----------------------------------------------------------------------
25
26 seq=`basename $0`
27 seqres=$RESULT_DIR/$seq
28 echo "QA output created by $seq"
29
30 here=`pwd`
31 tmp=/tmp/$$
32 status=1    # failure is the default!
33 trap "_cleanup; exit \$status" 0 1 2 3 15
34
35 _cleanup()
36 {
37     cd /
38     umount $SCRATCH_MNT > /dev/null 2>&1
39     rm -rf $tmp.*
40 }
41
42 # get standard environment, filters and checks
43 . ./common/rc
44 . ./common/filter
45 . ./common/reflink
46
47 # real QA test starts here
48 _supported_os Linux
49 _supported_fs xfs
50 _require_scratch_reflink
51 _require_cp_reflink
52
53 rm -f $seqres.full
54
55 _scratch_mkfs >/dev/null 2>&1
56 _scratch_mount
57
58 testdir=$SCRATCH_MNT/test-$seq
59 mkdir $testdir
60
61 echo "Create the original file blocks"
62 blksz="$(get_block_size $testdir)"
63 nr_blks=$((2 * blksz / 12))
64
65 for i in 1 2 x; do
66         _pwrite_byte 0x61 0 $((blksz * nr_blks)) $testdir/file1 >> $seqres.full
67
68         echo "$i: Reflink a bunch of times"
69         seq 1 $nr_blks | while read nr; do
70                 _cp_reflink $testdir/file1 $testdir/file1.$nr >> $seqres.full
71         done
72         sync
73
74         echo "$i: Truncate files"
75         seq 1 $nr_blks | while read nr; do
76                 truncate -s $((blksz * (nr_blks - nr))) $testdir/file1.$nr >> $seqres.full
77         done
78
79         umount $SCRATCH_MNT
80         _check_scratch_fs
81         _scratch_mount
82
83         test $i = "x" && break
84
85         echo "$i: Delete both files"
86         rm -rf $testdir
87         mkdir -p $testdir
88         umount $SCRATCH_MNT
89         _check_scratch_fs
90         _scratch_mount
91 done
92
93 # success, all done
94 status=0
95 exit