btrfs: test incremental send after removing a directory and all its files
[xfstests-dev.git] / tests / btrfs / 039
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/039
6 #
7 # Regression test for a btrfs incremental send issue related to renaming of
8 # directories. If at the time of the initial send we have a directory that is
9 # a child of a directory with a higher inode number, and then later after the
10 # initial full send we rename both the child and parent directories, but
11 # without moving any of them, a subsequent incremental send would produce a
12 # rename instruction for the child directory that pointed to an invalid path.
13 # This made the btrfs receive operation fail.
14 #
15 # This issue is fixed by the following linux kernel btrfs patch:
16 #
17 #   Btrfs: incremental send, fix invalid path after dir rename
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
47 mkdir $SCRATCH_MNT/d
48 mkdir $SCRATCH_MNT/a/b/c
49 mv $SCRATCH_MNT/d $SCRATCH_MNT/a/b/c
50 mkdir $SCRATCH_MNT/e
51 mkdir -p $SCRATCH_MNT/a/b/f/g
52 mv $SCRATCH_MNT/e $SCRATCH_MNT/a/b/f/g
53
54 # Filesystem looks like:
55 #
56 # .                      (ino 256)
57 # |-- a                  (ino 257)
58 #     |-- b              (ino 258)
59 #         |-- c          (ino 260)
60 #         |   |-- d      (ino 259)
61 #         |
62 #         |-- f          (ino 262)
63 #             |-- g      (ino 263)
64 #                 |-- e  (ino 261)
65
66 _run_btrfs_util_prog subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/mysnap1
67
68 mv $SCRATCH_MNT/a/b/c $SCRATCH_MNT/a/b/x
69 mv $SCRATCH_MNT/a/b/x/d $SCRATCH_MNT/a/b/x/y
70 mv $SCRATCH_MNT/a/b/f $SCRATCH_MNT/a/b/w
71 mv $SCRATCH_MNT/a/b/w/g/e $SCRATCH_MNT/a/b/w/g/z
72
73 # Filesystem now looks like:
74 #
75 # .                      (ino 256)
76 # |-- a                  (ino 257)
77 #     |-- b              (ino 258)
78 #         |-- x          (ino 260)
79 #         |   |-- y      (ino 259)
80 #         |
81 #         |-- w          (ino 262)
82 #             |-- g      (ino 263)
83 #                 |-- z  (ino 261)
84
85 _run_btrfs_util_prog subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/mysnap2
86
87 run_check $FSSUM_PROG -A -f -w $tmp/1.fssum $SCRATCH_MNT/mysnap1
88 run_check $FSSUM_PROG -A -f -w $tmp/2.fssum -x $SCRATCH_MNT/mysnap2/mysnap1 \
89         $SCRATCH_MNT/mysnap2
90
91 _run_btrfs_util_prog send -f $tmp/1.snap $SCRATCH_MNT/mysnap1
92 _run_btrfs_util_prog send -p $SCRATCH_MNT/mysnap1 -f $tmp/2.snap \
93         $SCRATCH_MNT/mysnap2
94
95 _scratch_unmount
96 _check_btrfs_filesystem $SCRATCH_DEV
97
98 _scratch_mkfs >/dev/null 2>&1
99 _scratch_mount
100
101 _run_btrfs_util_prog receive -f $tmp/1.snap $SCRATCH_MNT
102 run_check $FSSUM_PROG -r $tmp/1.fssum $SCRATCH_MNT/mysnap1 2>> $seqres.full
103
104 _run_btrfs_util_prog receive -f $tmp/2.snap $SCRATCH_MNT
105 run_check $FSSUM_PROG -r $tmp/2.fssum $SCRATCH_MNT/mysnap2 2>> $seqres.full
106
107 _scratch_unmount
108 _check_btrfs_filesystem $SCRATCH_DEV
109
110 status=0
111 exit