btrfs: fsync after hole punching with no-holes mode
[xfstests-dev.git] / tests / btrfs / 145
1 #! /bin/bash
2 # FS QA Test No. btrfs/145
3 #
4 # Test that an incremental send works if we rename some directory inode A and
5 # then rename some file inode B to the name inode A had, for the case where the
6 # directory inode A is an ancestor of inode B in the parent snapshot.
7 #
8 #-----------------------------------------------------------------------
9 #
10 # Copyright (C) 2017 SUSE Linux Products GmbH. All Rights Reserved.
11 # Author: Filipe Manana <fdmanana@suse.com>
12 #
13 # This program is free software; you can redistribute it and/or
14 # modify it under the terms of the GNU General Public License as
15 # published by the Free Software Foundation.
16 #
17 # This program is distributed in the hope that it would be useful,
18 # but WITHOUT ANY WARRANTY; without even the implied warranty of
19 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20 # GNU General Public License for more details.
21 #
22 # You should have received a copy of the GNU General Public License
23 # along with this program; if not, write the Free Software Foundation,
24 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
25 #-----------------------------------------------------------------------
26 #
27
28 seq=`basename $0`
29 seqres=$RESULT_DIR/$seq
30 echo "QA output created by $seq"
31
32 tmp=/tmp/$$
33 status=1        # failure is the default!
34 trap "_cleanup; exit \$status" 0 1 2 3 15
35
36 _cleanup()
37 {
38         cd /
39         rm -fr $send_files_dir
40         rm -f $tmp.*
41 }
42
43 # get standard environment, filters and checks
44 . ./common/rc
45 . ./common/filter
46
47 # real QA test starts here
48 _supported_fs btrfs
49 _supported_os Linux
50 _require_test
51 _require_scratch
52 _require_fssum
53
54 send_files_dir=$TEST_DIR/btrfs-test-$seq
55
56 rm -f $seqres.full
57 rm -fr $send_files_dir
58 mkdir $send_files_dir
59
60 _scratch_mkfs >>$seqres.full 2>&1
61 _scratch_mount
62
63 mkdir $SCRATCH_MNT/dir1
64 mkdir $SCRATCH_MNT/dir1/dir2
65 touch $SCRATCH_MNT/dir1/dir2/file1
66 touch $SCRATCH_MNT/dir1/dir2/file2
67 touch $SCRATCH_MNT/dir1/dir2/file3
68 mkdir $SCRATCH_MNT/dir1/dir3
69 mv $SCRATCH_MNT/dir1/dir2/file2 $SCRATCH_MNT/dir1/dir3/file22
70 mkdir $SCRATCH_MNT/dir1/dir3/dir4
71
72 # Filesystem looks like:
73 #
74 # .                                                      (ino 256)
75 # |
76 # |--- dir1/                                             (ino 257)
77 #       |--- dir2/                                       (ino 258)
78 #       |     |--- file1                                 (ino 259)
79 #       |     |--- file3                                 (ino 261)
80 #       |
81 #       |--- dir3/                                       (ino 262)
82 #             |--- file22                                (ino 260)
83 #             |--- dir4/                                 (ino 263)
84 #
85 $BTRFS_UTIL_PROG subvolume snapshot -r $SCRATCH_MNT \
86         $SCRATCH_MNT/mysnap1 > /dev/null
87
88 $BTRFS_UTIL_PROG send -f $send_files_dir/1.snap \
89         $SCRATCH_MNT/mysnap1 2>&1 1>/dev/null | _filter_scratch
90
91 mv $SCRATCH_MNT/dir1/dir2/file3 $SCRATCH_MNT/dir1/dir3/dir4/file33
92 mv $SCRATCH_MNT/dir1/dir2/file1 $SCRATCH_MNT/dir1/dir3/dir4/file11
93 mv $SCRATCH_MNT/dir1/dir3 $SCRATCH_MNT/dir1/file3
94 mv $SCRATCH_MNT/dir1/file3/file22 $SCRATCH_MNT/dir1/dir3
95
96 # Filesystem now looks like:
97 #
98 # .                                                      (ino 256)
99 # |
100 # |--- dir1/                                             (ino 257)
101 #       |--- dir2/                                       (ino 258)
102 #       |--- dir3                                        (ino 260)
103 #       |--- file3/                                      (ino 262)
104 #             |--- dir4/                                 (ino 263)
105 #                   |--- file11                          (ino 269)
106 #                   |--- file33                          (ino 261)
107 #
108 $BTRFS_UTIL_PROG subvolume snapshot -r $SCRATCH_MNT \
109                  $SCRATCH_MNT/mysnap2 > /dev/null
110
111 $BTRFS_UTIL_PROG send -p $SCRATCH_MNT/mysnap1 -f $send_files_dir/2.snap \
112                  $SCRATCH_MNT/mysnap2 2>&1 1>/dev/null | _filter_scratch
113
114 $FSSUM_PROG -A -f -w $send_files_dir/1.fssum $SCRATCH_MNT/mysnap1
115 $FSSUM_PROG -A -f -w $send_files_dir/2.fssum \
116         -x $SCRATCH_MNT/mysnap2/mysnap1 $SCRATCH_MNT/mysnap2
117
118 # Now recreate the filesystem by receiving both send streams and verify we get
119 # the same content that the original filesystem had.
120 _scratch_unmount
121 _scratch_mkfs >>$seqres.full 2>&1
122 _scratch_mount
123
124 $BTRFS_UTIL_PROG receive -f $send_files_dir/1.snap $SCRATCH_MNT > /dev/null
125 $BTRFS_UTIL_PROG receive -f $send_files_dir/2.snap $SCRATCH_MNT > /dev/null
126 $FSSUM_PROG -r $send_files_dir/1.fssum $SCRATCH_MNT/mysnap1
127 $FSSUM_PROG -r $send_files_dir/2.fssum $SCRATCH_MNT/mysnap2
128
129 status=0
130 exit