xfs: convert tests to SPDX license tags
[xfstests-dev.git] / tests / xfs / 265
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. 265
6 #
7 # Ensure that we can create enough distinct reflink entries to force creation
8 # of a multi-level refcount btree by reflinking a file a number of times and
9 # truncating the copies at successively lower sizes.  Delete and recreate a few
10 # times to exercise the refcount btree grow/shrink functions.
11 #
12 seq=`basename $0`
13 seqres=$RESULT_DIR/$seq
14 echo "QA output created by $seq"
15
16 here=`pwd`
17 tmp=/tmp/$$
18 status=1    # failure is the default!
19 trap "_cleanup; exit \$status" 0 1 2 3 15
20
21 _cleanup()
22 {
23     cd /
24     umount $SCRATCH_MNT > /dev/null 2>&1
25     rm -rf $tmp.*
26 }
27
28 # get standard environment, filters and checks
29 . ./common/rc
30 . ./common/filter
31 . ./common/reflink
32
33 # real QA test starts here
34 _supported_os Linux
35 _supported_fs xfs
36 _require_scratch_reflink
37 _require_cp_reflink
38
39 rm -f $seqres.full
40
41 _scratch_mkfs >/dev/null 2>&1
42 _scratch_mount
43
44 testdir=$SCRATCH_MNT/test-$seq
45 mkdir $testdir
46
47 echo "Create the original file blocks"
48 blksz="$(_get_block_size $testdir)"
49 nr_blks=$((2 * blksz / 12))
50
51 for i in 1 2 x; do
52         _pwrite_byte 0x61 0 $((blksz * nr_blks)) $testdir/file1 >> $seqres.full
53
54         echo "$i: Reflink a bunch of times"
55         seq 1 $nr_blks | while read nr; do
56                 _cp_reflink $testdir/file1 $testdir/file1.$nr >> $seqres.full
57         done
58         sync
59
60         echo "$i: Truncate files"
61         seq 1 $nr_blks | while read nr; do
62                 truncate -s $((blksz * (nr_blks - nr))) $testdir/file1.$nr >> $seqres.full
63         done
64
65         umount $SCRATCH_MNT
66         _check_scratch_fs
67         _scratch_mount
68
69         test $i = "x" && break
70
71         echo "$i: Delete both files"
72         rm -rf $testdir
73         mkdir -p $testdir
74         umount $SCRATCH_MNT
75         _check_scratch_fs
76         _scratch_mount
77 done
78
79 # success, all done
80 status=0
81 exit