btrfs/012: check free size of scratch device before copying files
[xfstests-dev.git] / tests / btrfs / 040
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/040
6 #
7 # Regression test for btrfs incremental send issue where an rmdir
8 # instruction was sent multiple times for the same target directory.
9 # The number of times depended on the number of hardlinks against
10 # the same inode inside the target directory. That inode must have
11 # had the highest number of all the inodes that were children of the
12 # directory. This made the btrfs receive command fail immediately once
13 # it received the second rmdir instruction.
14 #
15 # This issue is fixed by the following linux kernel btrfs patch:
16 #
17 #   Btrfs: send, don't send rmdir for same target multiple times
18 #
19 seq=`basename $0`
20 seqres=$RESULT_DIR/$seq
21 echo "QA output created by $seq"
22
23 tmp=`mktemp -d`
24 status=1        # failure is the default!
25 trap "_cleanup; exit \$status" 0 1 2 3 15
26
27 _cleanup()
28 {
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 _require_scratch
39 _require_fssum
40
41 rm -f $seqres.full
42
43 _scratch_mkfs >/dev/null 2>&1
44 _scratch_mount
45
46 mkdir -p $SCRATCH_MNT/a/b/c
47 echo 'hello world' > $SCRATCH_MNT/a/b/c/hel.txt
48 echo 'ola mundo' > $SCRATCH_MNT/a/b/c/foo.txt
49 ln $SCRATCH_MNT/a/b/c/foo.txt $SCRATCH_MNT/a/b/c/bar.txt
50 ln $SCRATCH_MNT/a/b/c/foo.txt $SCRATCH_MNT/a/b/baz.txt
51
52 # Filesystem looks like:
53 #
54 # .                        (ino 256)
55 # |-- a/                   (ino 257)
56 #     |-- b/               (ino 258)
57 #         |-- c/           (ino 259)
58 #         |   |-- hel.txt  (ino 260)
59 #         |   |-- foo.txt  (ino 261)
60 #         |   |-- bar.txt  (ino 261)
61 #         |
62 #         |-- baz.txt      (ino 261)
63
64 _run_btrfs_util_prog subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/mysnap1
65
66 rm -f $SCRATCH_MNT/a/b/c/foo.txt
67 rm -f $SCRATCH_MNT/a/b/c/bar.txt
68 rm -f $SCRATCH_MNT/a/b/c/hel.txt
69 rmdir $SCRATCH_MNT/a/b/c
70
71 # Filesystem now looks like:
72 #
73 # .                        (ino 256)
74 # |-- a/                   (ino 257)
75 #     |-- b/               (ino 258)
76 #         |-- baz.txt      (ino 261)
77
78 _run_btrfs_util_prog subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/mysnap2
79
80 run_check $FSSUM_PROG -A -f -w $tmp/1.fssum $SCRATCH_MNT/mysnap1
81 run_check $FSSUM_PROG -A -f -w $tmp/2.fssum -x $SCRATCH_MNT/mysnap2/mysnap1 \
82         $SCRATCH_MNT/mysnap2
83
84 _run_btrfs_util_prog send -f $tmp/1.snap $SCRATCH_MNT/mysnap1
85 _run_btrfs_util_prog send -p $SCRATCH_MNT/mysnap1 -f $tmp/2.snap \
86         $SCRATCH_MNT/mysnap2
87
88 _scratch_unmount
89 _check_btrfs_filesystem $SCRATCH_DEV
90
91 _scratch_mkfs >/dev/null 2>&1
92 _scratch_mount
93
94 _run_btrfs_util_prog receive -f $tmp/1.snap $SCRATCH_MNT
95 run_check $FSSUM_PROG -r $tmp/1.fssum $SCRATCH_MNT/mysnap1 2>> $seqres.full
96
97 _run_btrfs_util_prog receive -f $tmp/2.snap $SCRATCH_MNT
98 run_check $FSSUM_PROG -r $tmp/2.fssum $SCRATCH_MNT/mysnap2 2>> $seqres.full
99
100 _scratch_unmount
101 _check_btrfs_filesystem $SCRATCH_DEV
102
103 status=0
104 exit