btrfs: fsync after hole punching with no-holes mode
[xfstests-dev.git] / tests / btrfs / 054
1 #! /bin/bash
2 # FS QA Test No. btrfs/054
3 #
4 # Regression test for a btrfs incremental send issue where the difference
5 # between the snapshots used by the incremental send consists of one of
6 # these cases:
7 #
8 # 1) First snapshot has a directory with name X and in the second snapshot
9 #    that directory doesn't exist anymore but a subvolume/snapshot with
10 #    the same name (X) exists;
11 #
12 # 2) First snapshot has a subvolume/snapshot with name X and in the second
13 #    snapshot that subvolume/snapshot doesn't exist anymore (might have been
14 #    replaced by a directory with the same name or not).
15 #
16 # This issue is fixed by the following linux kernel btrfs patches:
17 #
18 #    Btrfs: send, don't error in the presence of subvols/snapshots
19 #    Btrfs: set dead flag on the right root when destroying snapshot
20 #
21 #-----------------------------------------------------------------------
22 # Copyright (c) 2014 Filipe Manana.  All Rights Reserved.
23 #
24 # This program is free software; you can redistribute it and/or
25 # modify it under the terms of the GNU General Public License as
26 # published by the Free Software Foundation.
27 #
28 # This program is distributed in the hope that it would be useful,
29 # but WITHOUT ANY WARRANTY; without even the implied warranty of
30 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
31 # GNU General Public License for more details.
32 #
33 # You should have received a copy of the GNU General Public License
34 # along with this program; if not, write the Free Software Foundation,
35 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
36 #-----------------------------------------------------------------------
37 #
38
39 seq=`basename $0`
40 seqres=$RESULT_DIR/$seq
41 echo "QA output created by $seq"
42
43 tmp=/tmp/$$
44 status=1        # failure is the default!
45 trap "_cleanup; exit \$status" 0 1 2 3 15
46
47 _cleanup()
48 {
49     rm -fr $send_files_dir
50     rm -fr $tmp
51 }
52
53 # get standard environment, filters and checks
54 . ./common/rc
55 . ./common/filter
56 . ./common/attr
57
58 # real QA test starts here
59 _supported_fs btrfs
60 _supported_os Linux
61 _require_test
62 _require_scratch
63
64 send_files_dir=$TEST_DIR/btrfs-test-$seq
65
66 rm -f $seqres.full
67 rm -fr $send_files_dir
68 mkdir $send_files_dir
69
70 _scratch_mkfs >/dev/null 2>&1
71 _scratch_mount
72
73 mkdir $SCRATCH_MNT/testdir
74 _run_btrfs_util_prog subvolume create $SCRATCH_MNT/first_subvol
75
76 _run_btrfs_util_prog subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/mysnap1
77
78 # Replace the directory testdir with a subvolume that has the same name.
79 rmdir $SCRATCH_MNT/testdir
80 _run_btrfs_util_prog subvolume create $SCRATCH_MNT/testdir
81
82 # Delete the subvolume first_subvol and create a directory with the same name.
83 _run_btrfs_util_prog subvolume delete $SCRATCH_MNT/first_subvol
84 mkdir $SCRATCH_MNT/first_subvol
85
86 _run_btrfs_util_prog subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/mysnap2
87
88 _run_btrfs_util_prog send -f $send_files_dir/1.snap $SCRATCH_MNT/mysnap1
89 _run_btrfs_util_prog send -p $SCRATCH_MNT/mysnap1 -f $send_files_dir/2.snap \
90         $SCRATCH_MNT/mysnap2
91
92 _scratch_unmount
93 _check_scratch_fs
94
95 _scratch_mkfs >/dev/null 2>&1
96 _scratch_mount
97
98 _run_btrfs_util_prog receive -f $send_files_dir/1.snap $SCRATCH_MNT
99 [ -e $SCRATCH_MNT/first_subvol ] && \
100         echo "Subvolume first_subvol was not supposed to be replicated by full send!"
101
102 _run_btrfs_util_prog receive -f $send_files_dir/2.snap $SCRATCH_MNT
103 [ -e $SCRATCH_MNT/testdir ] && \
104         echo "Directory testdir was supposed to be deleted after incremental send!"
105
106 status=0
107 exit