btrfs: check qgroup doesn't crash when beyond limit
[xfstests-dev.git] / tests / btrfs / 050
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2014 Filipe Manana.  All Rights Reserved.
4 #
5 # FS QA Test No. btrfs/050
6 #
7 # Regression for btrfs send when an inode only has extended references
8 # associated to it (no regular references present). This used to cause
9 # incorrect access to a b+tree leaf, where an extended reference item
10 # was accessed as if it were a regular reference item, causing unexpected
11 # and unpredictable behaviour such as producing a random/weird path string
12 # or a crash.
13 #
14 # This issue is fixed by the following linux kernel btrfs patch:
15 #
16 #   Btrfs: send, fix incorrect ref access when using extrefs
17 #
18 seq=`basename $0`
19 seqres=$RESULT_DIR/$seq
20 echo "QA output created by $seq"
21
22 tmp=/tmp/$$
23 status=1        # failure is the default!
24 trap "_cleanup; exit \$status" 0 1 2 3 15
25
26 _cleanup()
27 {
28     rm -fr $send_files_dir
29     rm -fr $tmp
30 }
31
32 # get standard environment, filters and checks
33 . ./common/rc
34 . ./common/filter
35
36 # real QA test starts here
37 _supported_fs btrfs
38 _require_test
39 _require_scratch
40 _require_fssum
41
42 send_files_dir=$TEST_DIR/btrfs-test-$seq
43
44 rm -f $seqres.full
45 rm -fr $send_files_dir
46 mkdir $send_files_dir
47
48 _scratch_mkfs "-O extref" >/dev/null 2>&1
49 _scratch_mount
50
51 # 2550 hard links is enough to cause creation of extended references
52 # even if the leaf/node size is 64Kb (largest possible).
53 NUM_LINKS=2550
54 TEST_PATH=$SCRATCH_MNT/home/john/files/series/qwerty
55
56 mkdir -p $TEST_PATH
57 touch $TEST_PATH/foobar
58
59 # Create a bunch of hard links for the file, such that at least one
60 # inode extended reference item is created.
61 for i in `seq 1 $NUM_LINKS`; do
62         ln $TEST_PATH/foobar $TEST_PATH/foobar_link_`printf "%04d" $i`
63 done
64
65 # The only link we'll have alive at the end.
66 ln $TEST_PATH/foobar $TEST_PATH/final_foobar_name
67
68 # Now delete all previous hard links (except the last one). This will
69 # remove the regular inode reference item from the b+tree, and will
70 # leave only an inode extended reference item, which is the condition
71 # necessary to trigger the bug.
72 rm -f $TEST_PATH/foobar
73 for i in `seq 1 $NUM_LINKS`; do
74         rm -f $TEST_PATH/foobar_link_`printf "%04d" $i`
75 done
76
77 _run_btrfs_util_prog subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/mysnap1
78 run_check $FSSUM_PROG -A -f -w $send_files_dir/1.fssum $SCRATCH_MNT/mysnap1
79 _run_btrfs_util_prog send -f $send_files_dir/1.snap $SCRATCH_MNT/mysnap1
80
81 _scratch_unmount
82 _check_scratch_fs
83
84 _scratch_mkfs >/dev/null 2>&1
85 _scratch_mount
86
87 _run_btrfs_util_prog receive -f $send_files_dir/1.snap $SCRATCH_MNT
88 run_check $FSSUM_PROG -r $send_files_dir/1.fssum $SCRATCH_MNT/mysnap1
89
90 status=0
91 exit