btrfs: convert tests to SPDX license tags
[xfstests-dev.git] / tests / btrfs / 130
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2016 Fujitsu. All Rights Reserved.
4 #
5 # FS QA Test 130
6 #
7 # Check if btrfs send can handle large deduped file, whose file extents
8 # are all pointing to one extent.
9 # Such file structure will cause quite large pressure to any operation which
10 # iterates all backref of one extent.
11 # And unfortunately, btrfs send is one of these operations, and will cause
12 # softlock or OOM on systems with small memory(<4G).
13 #
14 seq=`basename $0`
15 seqres=$RESULT_DIR/$seq
16 echo "QA output created by $seq"
17
18 here=`pwd`
19 tmp=/tmp/$$
20 status=1        # failure is the default!
21 trap "_cleanup; exit \$status" 0 1 2 3 15
22
23 _cleanup()
24 {
25         cd /
26         rm -f $tmp.*
27 }
28
29 # get standard environment, filters and checks
30 . ./common/rc
31 . ./common/filter
32 . ./common/reflink
33
34 # remove previous $seqres.full before test
35 rm -f $seqres.full
36
37 # real QA test starts here
38
39 # Modify as appropriate.
40 _supported_fs btrfs
41 _supported_os Linux
42 _require_scratch
43 _require_scratch_reflink
44
45 _scratch_mkfs > /dev/null 2>&1
46 _scratch_mount
47
48 nr_extents=$((256 * $LOAD_FACTOR))
49
50 # Use 128K blocksize, the default value of both deduperemove or
51 # inband dedupe
52 blocksize=$((128 * 1024))
53 file=$SCRATCH_MNT/foobar
54
55 echo LOAD_FACTOR=$LOAD_FACTOR nr_extents=$nr_extents blocksize=$blocksize >> $seqres.full
56
57 # create the initial file, whose file extents are all point to one extent
58 _pwrite_byte 0xcdcdcdcd 0 $blocksize  $file | _filter_xfs_io
59
60 for i in $(seq 1 $(($nr_extents - 1))); do
61         _reflink_range $file 0 $file $(($i * $blocksize)) $blocksize \
62                 >> $seqres.full 2>&1
63 done
64
65 # create a RO snapshot, so we can send out the snapshot
66 _run_btrfs_util_prog subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/ro_snap
67
68 # send out the subvolume, and it will either:
69 # 1) OOM since memory is allocated inside a O(n^3) loop
70 # 2) Softlock since time consuming backref walk is called without scheduling.
71 # the send destination is not important, just send will cause the problem
72 echo "# $BTRFS_UTIL_PROG send $SCRATCH_MNT/ro_snap > /dev/null" >> $seqres.full
73 $BTRFS_UTIL_PROG send $SCRATCH_MNT/ro_snap > /dev/null 2>>$seqres.full
74
75 # success, all done
76 status=0
77 exit