btrfs: check qgroup doesn't crash when beyond limit
[xfstests-dev.git] / tests / btrfs / 083
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/083
6 #
7 # Test for incremental send where the difference between the parent and child
8 # snapshots is that a directory A was renamed and a directory B was renamed to
9 # the name directory A had before (in the parent snapshot), but directory A's
10 # rename must happen before some other directory C is renamed.
11 #
12 # This issue was fixed by the following linux kernel btrfs patch:
13 #
14 #   Btrfs: incremental send, don't rename a directory too soon
15 #
16 seq=`basename $0`
17 seqres=$RESULT_DIR/$seq
18 echo "QA output created by $seq"
19
20 tmp=/tmp/$$
21 status=1        # failure is the default!
22 trap "_cleanup; exit \$status" 0 1 2 3 15
23
24 _cleanup()
25 {
26         rm -fr $send_files_dir
27         rm -f $tmp.*
28 }
29
30 # get standard environment, filters and checks
31 . ./common/rc
32 . ./common/filter
33
34 # real QA test starts here
35 _supported_fs btrfs
36 _require_scratch
37 _require_fssum
38
39 send_files_dir=$TEST_DIR/btrfs-test-$seq
40
41 rm -f $seqres.full
42 rm -fr $send_files_dir
43 mkdir $send_files_dir
44
45 _scratch_mkfs >>$seqres.full 2>&1
46 _scratch_mount
47
48 mkdir $SCRATCH_MNT/a
49 mkdir $SCRATCH_MNT/b
50 mkdir $SCRATCH_MNT/c
51 touch $SCRATCH_MNT/a/file
52
53 mkdir $SCRATCH_MNT/d
54 mkdir $SCRATCH_MNT/e
55 touch $SCRATCH_MNT/e/file2
56 mkdir $SCRATCH_MNT/f
57
58 # Filesystem looks like:
59 #
60 # .                                       (ino 256)
61 # |---- a/                                (ino 257)
62 # |     |---- file                        (ino 260)
63 # |
64 # |---- b/                                (ino 258)
65 # |---- c/                                (ino 259)
66 # |---- d/                                (ino 261)
67 # |---- e/                                (ino 262)
68 # |     |--- file2                        (ino 263)
69 # |
70 # |---- f/                                (ino 264)
71 #
72 _run_btrfs_util_prog subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/mysnap1
73
74 # Now make inode 257 a child of inode 259 and rename inode 258 to the name that
75 # inode 257 had before. When the incremental send processes inode 257, it can't
76 # do the rename immediately because inode 259 must be renamed first, so inode's
77 # 257 rename is delayed and happens after the rename for inode 259 is done.
78 # Since send processes inodes by ascending order of their number, inode 258
79 # can't be renamed before inode 257 is renamed and therefore must be delayed
80 # as well. So the send stream must issue rename commands in the following order:
81 #
82 # 1 - rename inode 259 ('c' -> 'x')
83 # 2 - rename inode 257 ('a' -> 'x/y')
84 # 3 - rename inode 258 ('b' -> 'a')
85 #
86 # Before the fix mentioned above, the send stream attempted to rename inode 258
87 # before inode 257 was renamed, resulting in a client error mentioning
88 # 'directory not empty'.
89 #
90 # Same logic applies to 'd', 'e' and 'f', but the difference is that in the
91 # second snapshot 'e' is associated to an inode with a lower inode number than
92 # in the first snapshot.
93 #
94 mv $SCRATCH_MNT/c $SCRATCH_MNT/x
95 mv $SCRATCH_MNT/a $SCRATCH_MNT/x/y
96 mv $SCRATCH_MNT/b $SCRATCH_MNT/a
97
98 mv $SCRATCH_MNT/f $SCRATCH_MNT/f2
99 mv $SCRATCH_MNT/e $SCRATCH_MNT/f2/e2
100 mv $SCRATCH_MNT/d $SCRATCH_MNT/e
101
102 # Filesystem now looks like:
103 #
104 #
105 # .                                       (ino 256)
106 # |---- a/                                (ino 258)
107 # |---- x/                                (ino 259)
108 # |     |---- y/                          (ino 257)
109 # |           |----- file                 (ino 260)
110 # |
111 # |---- e/                                (ino 261)
112 # |---- f2/                               (ino 264)
113 # |     |----- e2/                        (ino 262)
114 #              |---- file2                (ino 263)
115
116 _run_btrfs_util_prog subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/mysnap2
117
118 run_check $FSSUM_PROG -A -f -w $send_files_dir/1.fssum $SCRATCH_MNT/mysnap1
119 run_check $FSSUM_PROG -A -f -w $send_files_dir/2.fssum \
120         -x $SCRATCH_MNT/mysnap2/mysnap1 $SCRATCH_MNT/mysnap2
121
122 _run_btrfs_util_prog send -f $send_files_dir/1.snap $SCRATCH_MNT/mysnap1
123 _run_btrfs_util_prog send -p $SCRATCH_MNT/mysnap1 -f $send_files_dir/2.snap \
124         $SCRATCH_MNT/mysnap2
125
126 # Now recreate the filesystem by receiving both send streams and verify we get
127 # the same content that the original filesystem had.
128 _scratch_unmount
129 _scratch_mkfs >>$seqres.full 2>&1
130 _scratch_mount
131
132 _run_btrfs_util_prog receive -f $send_files_dir/1.snap $SCRATCH_MNT
133 run_check $FSSUM_PROG -r $send_files_dir/1.fssum $SCRATCH_MNT/mysnap1
134
135 _run_btrfs_util_prog receive -f $send_files_dir/2.snap $SCRATCH_MNT
136 run_check $FSSUM_PROG -r $send_files_dir/2.fssum $SCRATCH_MNT/mysnap2
137
138 echo "Silence is golden"
139
140 status=0
141 exit