btrfs: fsync after hole punching with no-holes mode
[xfstests-dev.git] / tests / btrfs / 039
1 #! /bin/bash
2 # FS QA Test No. btrfs/039
3 #
4 # Regression test for a btrfs incremental send issue related to renaming of
5 # directories. If at the time of the initial send we have a directory that is
6 # a child of a directory with a higher inode number, and then later after the
7 # initial full send we rename both the child and parent directories, but
8 # without moving any of them, a subsequent incremental send would produce a
9 # rename instruction for the child directory that pointed to an invalid path.
10 # This made the btrfs receive operation fail.
11 #
12 # This issue is fixed by the following linux kernel btrfs patch:
13 #
14 #   Btrfs: incremental send, fix invalid path after dir rename
15 #
16 #-----------------------------------------------------------------------
17 # Copyright (c) 2014 Filipe Manana.  All Rights Reserved.
18 #
19 # This program is free software; you can redistribute it and/or
20 # modify it under the terms of the GNU General Public License as
21 # published by the Free Software Foundation.
22 #
23 # This program is distributed in the hope that it would be useful,
24 # but WITHOUT ANY WARRANTY; without even the implied warranty of
25 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
26 # GNU General Public License for more details.
27 #
28 # You should have received a copy of the GNU General Public License
29 # along with this program; if not, write the Free Software Foundation,
30 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
31 #-----------------------------------------------------------------------
32 #
33
34 seq=`basename $0`
35 seqres=$RESULT_DIR/$seq
36 echo "QA output created by $seq"
37
38 tmp=`mktemp -d`
39 status=1        # failure is the default!
40 trap "_cleanup; exit \$status" 0 1 2 3 15
41
42 _cleanup()
43 {
44     rm -fr $tmp
45 }
46
47 # get standard environment, filters and checks
48 . ./common/rc
49 . ./common/filter
50
51 # real QA test starts here
52 _supported_fs btrfs
53 _supported_os Linux
54 _require_scratch
55 _require_fssum
56
57 rm -f $seqres.full
58
59 _scratch_mkfs >/dev/null 2>&1
60 _scratch_mount
61
62 mkdir -p $SCRATCH_MNT/a/b
63 mkdir $SCRATCH_MNT/d
64 mkdir $SCRATCH_MNT/a/b/c
65 mv $SCRATCH_MNT/d $SCRATCH_MNT/a/b/c
66 mkdir $SCRATCH_MNT/e
67 mkdir -p $SCRATCH_MNT/a/b/f/g
68 mv $SCRATCH_MNT/e $SCRATCH_MNT/a/b/f/g
69
70 # Filesystem looks like:
71 #
72 # .                      (ino 256)
73 # |-- a                  (ino 257)
74 #     |-- b              (ino 258)
75 #         |-- c          (ino 260)
76 #         |   |-- d      (ino 259)
77 #         |
78 #         |-- f          (ino 262)
79 #             |-- g      (ino 263)
80 #                 |-- e  (ino 261)
81
82 _run_btrfs_util_prog subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/mysnap1
83
84 mv $SCRATCH_MNT/a/b/c $SCRATCH_MNT/a/b/x
85 mv $SCRATCH_MNT/a/b/x/d $SCRATCH_MNT/a/b/x/y
86 mv $SCRATCH_MNT/a/b/f $SCRATCH_MNT/a/b/w
87 mv $SCRATCH_MNT/a/b/w/g/e $SCRATCH_MNT/a/b/w/g/z
88
89 # Filesystem now looks like:
90 #
91 # .                      (ino 256)
92 # |-- a                  (ino 257)
93 #     |-- b              (ino 258)
94 #         |-- x          (ino 260)
95 #         |   |-- y      (ino 259)
96 #         |
97 #         |-- w          (ino 262)
98 #             |-- g      (ino 263)
99 #                 |-- z  (ino 261)
100
101 _run_btrfs_util_prog subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/mysnap2
102
103 run_check $FSSUM_PROG -A -f -w $tmp/1.fssum $SCRATCH_MNT/mysnap1
104 run_check $FSSUM_PROG -A -f -w $tmp/2.fssum -x $SCRATCH_MNT/mysnap2/mysnap1 \
105         $SCRATCH_MNT/mysnap2
106
107 _run_btrfs_util_prog send -f $tmp/1.snap $SCRATCH_MNT/mysnap1
108 _run_btrfs_util_prog send -p $SCRATCH_MNT/mysnap1 -f $tmp/2.snap \
109         $SCRATCH_MNT/mysnap2
110
111 _scratch_unmount
112 _check_btrfs_filesystem $SCRATCH_DEV
113
114 _scratch_mkfs >/dev/null 2>&1
115 _scratch_mount
116
117 _run_btrfs_util_prog receive -f $tmp/1.snap $SCRATCH_MNT
118 run_check $FSSUM_PROG -r $tmp/1.fssum $SCRATCH_MNT/mysnap1 2>> $seqres.full
119
120 _run_btrfs_util_prog receive -f $tmp/2.snap $SCRATCH_MNT
121 run_check $FSSUM_PROG -r $tmp/2.fssum $SCRATCH_MNT/mysnap2 2>> $seqres.full
122
123 _scratch_unmount
124 _check_btrfs_filesystem $SCRATCH_DEV
125
126 status=0
127 exit