btrfs: check qgroup doesn't crash when beyond limit
[xfstests-dev.git] / tests / btrfs / 084
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2015 SUSE Linux Products GmbH. All Rights Reserved.
4 #
5 # FS QA Test No. btrfs/084
6 #
7 # Test for incremental send where the difference between the parent and send
8 # snapshots is that for a subtree with the same path in both snapshots (p1/p2),
9 # the root directories were swapped.
10 #
11 # This issue was fixed by the following linux kernel btrfs patch:
12 #
13 #   Btrfs: incremental send, clear name from cache after orphanization
14 #
15 seq=`basename $0`
16 seqres=$RESULT_DIR/$seq
17 echo "QA output created by $seq"
18
19 tmp=/tmp/$$
20 status=1        # failure is the default!
21 trap "_cleanup; exit \$status" 0 1 2 3 15
22
23 _cleanup()
24 {
25         rm -fr $send_files_dir
26         rm -f $tmp.*
27 }
28
29 # get standard environment, filters and checks
30 . ./common/rc
31 . ./common/filter
32
33 # real QA test starts here
34 _supported_fs btrfs
35 _require_scratch
36 _require_fssum
37
38 send_files_dir=$TEST_DIR/btrfs-test-$seq
39
40 rm -f $seqres.full
41 rm -fr $send_files_dir
42 mkdir $send_files_dir
43
44 _scratch_mkfs >>$seqres.full 2>&1
45 _scratch_mount
46
47 mkdir -p $SCRATCH_MNT/data/n1/n2/p1/p2
48 mkdir $SCRATCH_MNT/data/n4
49 mkdir -p $SCRATCH_MNT/data/p1/p2
50
51 # Filesystem looks like:
52 #
53 # .                                       (ino 256)
54 # |---- data                              (ino 257)
55 #         |---- n1/                       (ino 258)
56 #         |     |---- n2/                 (ino 259)
57 #         |           |---- p1/           (ino 260)
58 #         |                 |---- p2/     (ino 261)
59 #         |
60 #         |---- n4/                       (ino 262)
61 #         |---- p1/                       (ino 263)
62 #               |---- p2/                 (ino 264)
63 #
64 _run_btrfs_util_prog subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/mysnap1
65
66 # Now move directories around such that for the subtrees with the path "p1/p2"
67 # we end up swapping the parents, that is, inode 263 becomes the parent of
68 # inode 261 and inode 260 becomes the parent of inode 264. This makes the send
69 # stream orphanize the inodes 263 and 264, and we want to verify the respective
70 # rename operations don't fail, that they don't use incorrect paths.
71 mv $SCRATCH_MNT/data/p1/p2 $SCRATCH_MNT/data
72 mv $SCRATCH_MNT/data/n1/n2/p1/p2 $SCRATCH_MNT/data/p1
73 mv $SCRATCH_MNT/data/p2 $SCRATCH_MNT/data/n1/n2/p1
74 mv $SCRATCH_MNT/data/n1/n2 $SCRATCH_MNT/data/p1
75 mv $SCRATCH_MNT/data/p1 $SCRATCH_MNT/data/n4
76 mv $SCRATCH_MNT/data/n4/p1/n2/p1 $SCRATCH_MNT/data
77
78 # Filesystem now looks like:
79 #
80 # .                                       (ino 256)
81 # |---- data                              (ino 257)
82 #         |---- n1/                       (ino 258)
83 #         |---- n4/                       (ino 262)
84 #         |     |---- p1/                 (ino 263)
85 #         |           |---- n2/           (ino 259)
86 #         |           |---- p2/           (ino 261)
87 #         |
88 #         |---- p1/                       (ino 260)
89 #               |---- p2/                 (ino 264)
90 #
91 _run_btrfs_util_prog subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/mysnap2
92
93 run_check $FSSUM_PROG -A -f -w $send_files_dir/1.fssum $SCRATCH_MNT/mysnap1
94 run_check $FSSUM_PROG -A -f -w $send_files_dir/2.fssum \
95         -x $SCRATCH_MNT/mysnap2/mysnap1 $SCRATCH_MNT/mysnap2
96
97 _run_btrfs_util_prog send -f $send_files_dir/1.snap $SCRATCH_MNT/mysnap1
98 _run_btrfs_util_prog send -p $SCRATCH_MNT/mysnap1 -f $send_files_dir/2.snap \
99         $SCRATCH_MNT/mysnap2
100
101 # Now recreate the filesystem by receiving both send streams and verify we get
102 # the same content that the original filesystem had.
103 _scratch_unmount
104 _scratch_mkfs >>$seqres.full 2>&1
105 _scratch_mount
106
107 _run_btrfs_util_prog receive -f $send_files_dir/1.snap $SCRATCH_MNT
108 run_check $FSSUM_PROG -r $send_files_dir/1.fssum $SCRATCH_MNT/mysnap1
109 _run_btrfs_util_prog receive -f $send_files_dir/2.snap $SCRATCH_MNT
110 run_check $FSSUM_PROG -r $send_files_dir/2.fssum $SCRATCH_MNT/mysnap2
111
112 echo "Silence is golden"
113 status=0
114 exit