btrfs: Verify falloc on multiple holes won't leak qgroup reserved data space
[xfstests-dev.git] / tests / btrfs / 129
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2016 SUSE Linux Products GmbH. All Rights Reserved.
4 #
5 # FS QA Test No. btrfs/129
6 #
7 # Test that an incremental send operation does not prematurely issues rmdir
8 # operations under a particular scenario (the rmdir operation is sent before
9 # the target directory is empty).
10 #
11 seq=`basename $0`
12 seqres=$RESULT_DIR/$seq
13 echo "QA output created by $seq"
14
15 tmp=/tmp/$$
16 status=1        # failure is the default!
17 trap "_cleanup; exit \$status" 0 1 2 3 15
18
19 _cleanup()
20 {
21         cd /
22         rm -fr $send_files_dir
23         rm -f $tmp.*
24 }
25
26 # get standard environment, filters and checks
27 . ./common/rc
28 . ./common/filter
29
30 # real QA test starts here
31 _supported_fs btrfs
32 _supported_os Linux
33 _require_test
34 _require_scratch
35 _require_fssum
36
37 send_files_dir=$TEST_DIR/btrfs-test-$seq
38
39 rm -f $seqres.full
40 rm -fr $send_files_dir
41 mkdir $send_files_dir
42
43 _scratch_mkfs >>$seqres.full 2>&1
44 _scratch_mount
45
46 mkdir $SCRATCH_MNT/a
47 mkdir $SCRATCH_MNT/tmp
48 mkdir $SCRATCH_MNT/del
49 mv $SCRATCH_MNT/tmp $SCRATCH_MNT/del
50 mkdir $SCRATCH_MNT/a/c
51 mkdir $SCRATCH_MNT/del/x
52
53 # Filesystem looks like:
54 #
55 # .                                                             (ino 256)
56 # |--- a/                                                       (ino 257)
57 # |    |--- c/                                                  (ino 260)
58 # |
59 # |--- del/                                                     (ino 259)
60 #       |--- tmp/                                               (ino 258)
61 #       |--- x/                                                 (ino 261)
62 #
63 _run_btrfs_util_prog subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/mysnap1
64
65 # When inode 260 was processed, rename operations for it and for inode 258 were
66 # issued (the rename for inode 260 must happen before the rename for inode 258).
67 # Then immediately after issuing the rename operation for inode 258, and before
68 # inode 261 was processed, the send stream issued a rmdir operation for inode
69 # 260, which would make the receiver fail with the error ENOTEMPTY because inode
70 # 261 was not yet renamed, it was still a child of inode 260 at that time.
71 #
72 mv $SCRATCH_MNT/a/c $SCRATCH_MNT
73 mv $SCRATCH_MNT/del/x $SCRATCH_MNT/a
74 mv $SCRATCH_MNT/del/tmp $SCRATCH_MNT/c
75 rmdir $SCRATCH_MNT/del
76
77 # Filesystem now looks like:
78 #
79 # .                                                             (ino 256)
80 # |--- a/                                                       (ino 257)
81 # |    |--- x/                                                  (ino 261)
82 # |
83 # |--- c/                                                       (ino 260)
84 #      |--- tmp/                                                (ino 258)
85 #
86 _run_btrfs_util_prog subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/mysnap2
87
88 run_check $FSSUM_PROG -A -f -w $send_files_dir/1.fssum $SCRATCH_MNT/mysnap1
89 run_check $FSSUM_PROG -A -f -w $send_files_dir/2.fssum \
90         -x $SCRATCH_MNT/mysnap2/mysnap1 $SCRATCH_MNT/mysnap2
91
92 _run_btrfs_util_prog send -f $send_files_dir/1.snap $SCRATCH_MNT/mysnap1
93 _run_btrfs_util_prog send -p $SCRATCH_MNT/mysnap1 -f $send_files_dir/2.snap \
94         $SCRATCH_MNT/mysnap2
95
96 # Now recreate the filesystem by receiving both send streams and verify we get
97 # the same content that the original filesystem had.
98 _scratch_unmount
99 _scratch_mkfs >>$seqres.full 2>&1
100 _scratch_mount
101
102 _run_btrfs_util_prog receive -f $send_files_dir/1.snap $SCRATCH_MNT
103 run_check $FSSUM_PROG -r $send_files_dir/1.fssum $SCRATCH_MNT/mysnap1
104 _run_btrfs_util_prog receive -f $send_files_dir/2.snap $SCRATCH_MNT
105 run_check $FSSUM_PROG -r $send_files_dir/2.fssum $SCRATCH_MNT/mysnap2
106
107 echo "Silence is golden"
108 status=0
109 exit