2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2014 Filipe Manana. All Rights Reserved.
5 # FS QA Test No. btrfs/050
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
14 # This issue is fixed by the following linux kernel btrfs patch:
16 # Btrfs: send, fix incorrect ref access when using extrefs
19 seqres=$RESULT_DIR/$seq
20 echo "QA output created by $seq"
23 status=1 # failure is the default!
24 trap "_cleanup; exit \$status" 0 1 2 3 15
28 rm -fr $send_files_dir
32 # get standard environment, filters and checks
36 # real QA test starts here
42 send_files_dir=$TEST_DIR/btrfs-test-$seq
45 rm -fr $send_files_dir
48 _scratch_mkfs "-O extref" >/dev/null 2>&1
51 # 2550 hard links is enough to cause creation of extended references
52 # even if the leaf/node size is 64Kb (largest possible).
54 TEST_PATH=$SCRATCH_MNT/home/john/files/series/qwerty
57 touch $TEST_PATH/foobar
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`
65 # The only link we'll have alive at the end.
66 ln $TEST_PATH/foobar $TEST_PATH/final_foobar_name
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`
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
84 _scratch_mkfs >/dev/null 2>&1
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