btrfs/057: Fix false alerts due to orphan files
[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 _supported_os Linux
39 _require_test
40 _require_scratch
41 _require_fssum
42
43 send_files_dir=$TEST_DIR/btrfs-test-$seq
44
45 rm -f $seqres.full
46 rm -fr $send_files_dir
47 mkdir $send_files_dir
48
49 _scratch_mkfs "-O extref" >/dev/null 2>&1
50 _scratch_mount
51
52 # 2550 hard links is enough to cause creation of extended references
53 # even if the leaf/node size is 64Kb (largest possible).
54 NUM_LINKS=2550
55 TEST_PATH=$SCRATCH_MNT/home/john/files/series/qwerty
56
57 mkdir -p $TEST_PATH
58 touch $TEST_PATH/foobar
59
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`
64 done
65
66 # The only link we'll have alive at the end.
67 ln $TEST_PATH/foobar $TEST_PATH/final_foobar_name
68
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`
76 done
77
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
81
82 _scratch_unmount
83 _check_scratch_fs
84
85 _scratch_mkfs >/dev/null 2>&1
86 _scratch_mount
87
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
90
91 status=0
92 exit