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
43 send_files_dir=$TEST_DIR/btrfs-test-$seq
46 rm -fr $send_files_dir
49 _scratch_mkfs "-O extref" >/dev/null 2>&1
52 # 2550 hard links is enough to cause creation of extended references
53 # even if the leaf/node size is 64Kb (largest possible).
55 TEST_PATH=$SCRATCH_MNT/home/john/files/series/qwerty
58 touch $TEST_PATH/foobar
60 # Create a bunch of hard links for the file, such that at least one
61 # inode extended reference item is created.
62 for i in `seq 1 $NUM_LINKS`; do
63 ln $TEST_PATH/foobar $TEST_PATH/foobar_link_`printf "%04d" $i`
66 # The only link we'll have alive at the end.
67 ln $TEST_PATH/foobar $TEST_PATH/final_foobar_name
69 # Now delete all previous hard links (except the last one). This will
70 # remove the regular inode reference item from the b+tree, and will
71 # leave only an inode extended reference item, which is the condition
72 # necessary to trigger the bug.
73 rm -f $TEST_PATH/foobar
74 for i in `seq 1 $NUM_LINKS`; do
75 rm -f $TEST_PATH/foobar_link_`printf "%04d" $i`
78 _run_btrfs_util_prog subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/mysnap1
79 run_check $FSSUM_PROG -A -f -w $send_files_dir/1.fssum $SCRATCH_MNT/mysnap1
80 _run_btrfs_util_prog send -f $send_files_dir/1.snap $SCRATCH_MNT/mysnap1
85 _scratch_mkfs >/dev/null 2>&1
88 _run_btrfs_util_prog receive -f $send_files_dir/1.snap $SCRATCH_MNT
89 run_check $FSSUM_PROG -r $send_files_dir/1.fssum $SCRATCH_MNT/mysnap1