xfs: Check for extent overflow when trivally adding a new extent
[xfstests-dev.git] / tests / btrfs / 181
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2019 SUSE Linux Products GmbH. All Rights Reserved.
4 #
5 # FS QA Test 181
6 #
7 # Test if btrfs will commit too many transactions for nothing and cause
8 # performance regression during balance.
9 #
10 # This bug is going to be fixed by a patch for kernel title
11 # "btrfs: don't end the transaction for delayed refs in throttle"
12 #
13 seq=`basename $0`
14 seqres=$RESULT_DIR/$seq
15 echo "QA output created by $seq"
16
17 here=`pwd`
18 tmp=/tmp/$$
19 status=1        # failure is the default!
20 trap "_cleanup; exit \$status" 0 1 2 3 15
21
22 _cleanup()
23 {
24         cd /
25         rm -f $tmp.*
26 }
27
28 # get standard environment, filters and checks
29 . ./common/rc
30 . ./common/filter
31
32 # remove previous $seqres.full before test
33 rm -f $seqres.full
34
35 # real QA test starts here
36
37 # Modify as appropriate.
38 _supported_fs btrfs
39 _require_scratch
40 _require_btrfs_command inspect-internal dump-super
41
42 _scratch_mkfs > /dev/null
43
44 _scratch_mount
45
46 nr_files=1024
47
48 get_super_gen()
49 {
50         local ret=$($BTRFS_UTIL_PROG inspect dump-super "$SCRATCH_DEV" |\
51                 grep ^generation | awk '{print $2}')
52         if [ -z $ret ]; then
53                 _fail "failed to get super block generation"
54         fi
55         echo "$ret"
56 }
57
58 $BTRFS_UTIL_PROG subvolume create "$SCRATCH_MNT/subvol" > /dev/null
59
60 # Create some small files to take up enough metadata reserved space
61 for ((i = 0; i < $nr_files; i++)) do
62         _pwrite_byte 0xcd 0 1K "$SCRATCH_MNT/subvol/file_$i" > /dev/null
63 done
64
65 # Commit the fs so we can get a stable super generation
66 sync
67
68 before_gen=$(get_super_gen)
69
70 _run_btrfs_balance_start -m $SCRATCH_MNT >> $seqres.full
71
72 after_gen=$(get_super_gen)
73
74 # Since the fs is pretty small, we should have only 1 small metadata chunk and
75 # one tiny system chunk.
76 # Relocating such small chunks only needs 6 commits for each, thus 12 commits for
77 # 2 chunks.
78 # Here we use 10x the theoretic value as threshold.
79 theoretic_gen=$(( 6 * 2 ))
80 threshold_gen=$(( 10 * $theoretic_gen ))
81 if [ $(( $after_gen - $before_gen )) -gt 120 ]; then
82         echo "balance committed too many transactions"
83         echo "super generation before balance: ${before_gen}"
84         echo "super generation after balance:  ${after_gen}"
85         echo "super generation difference:     $((after_gen - before_gen))"
86         echo "theoretic generation difference: ${theoretic_gen}"
87         echo "threshold generation difference: ${threshold_gen}"
88 fi
89
90 echo "super generation before balance: ${before_gen}" >> $seqres.full
91 echo "super generation after balance:  ${after_gen}" >> $seqres.full
92 echo "super generation difference:     $((after_gen - before_gen))" >> $seqres.full
93 echo "theoretic generation difference: ${theoretic_gen}" >> $seqres.full
94 echo "threshold generation difference: ${threshold_gen}" >> $seqres.full
95
96 # success, all done
97 echo "Silence is golden"
98
99 status=0
100 exit