btrfs: fsync after hole punching with no-holes mode
[xfstests-dev.git] / tests / btrfs / 152
1 #! /bin/bash
2 # FS QA Test No. btrfs/152
3 #
4 # Test that incremental send/receive operations don't corrupt metadata when
5 # qgroups are enabled.
6 #
7 #-----------------------------------------------------------------------
8 #
9 # Copyright (c) 2017 NETGEAR, Inc.  All Rights Reserved.
10 #
11 # This program is free software; you can redistribute it and/or
12 # modify it under the terms of the GNU General Public License as
13 # published by the Free Software Foundation.
14 #
15 # This program is distributed in the hope that it would be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 # GNU General Public License for more details.
19 #
20 # You should have received a copy of the GNU General Public License
21 # along with this program; if not, write the Free Software Foundation,
22 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
23 #-----------------------------------------------------------------------
24 #
25
26 seq=`basename $0`
27 seqres=$RESULT_DIR/$seq
28 echo "QA output created by $seq"
29
30 tmp=/tmp/$$
31 status=1        # failure is the default!
32 trap "_cleanup; exit \$status" 0 1 2 3 15
33
34 _cleanup()
35 {
36         cd /
37         rm -f $tmp.*
38 }
39
40 # get standard environment, filters and checks
41 . ./common/rc
42 . ./common/filter
43
44 # real QA test starts here
45 _supported_fs btrfs
46 _supported_os Linux
47 _require_scratch
48
49 rm -f $seqres.full
50
51 _scratch_mkfs >>$seqres.full 2>&1
52 _scratch_mount
53
54 # Enable quotas
55 $BTRFS_UTIL_PROG quota enable $SCRATCH_MNT
56
57 # Create 2 source and 4 destination subvolumes
58 for subvol in subvol1 subvol2 recv1_1 recv1_2 recv2_1 recv2_2; do
59         $BTRFS_UTIL_PROG subvolume create $SCRATCH_MNT/$subvol | _filter_scratch
60 done
61 mkdir $SCRATCH_MNT/subvol{1,2}/.snapshots
62 touch $SCRATCH_MNT/subvol{1,2}/foo
63
64 # Create base snapshots and send them
65 $BTRFS_UTIL_PROG subvolume snapshot -r $SCRATCH_MNT/subvol1 \
66         $SCRATCH_MNT/subvol1/.snapshots/1 | _filter_scratch
67 $BTRFS_UTIL_PROG subvolume snapshot -r $SCRATCH_MNT/subvol2 \
68         $SCRATCH_MNT/subvol2/.snapshots/1 | _filter_scratch
69 for recv in recv1_1 recv1_2 recv2_1 recv2_2; do
70         $BTRFS_UTIL_PROG send $SCRATCH_MNT/subvol1/.snapshots/1 2> /dev/null | \
71                 $BTRFS_UTIL_PROG receive $SCRATCH_MNT/${recv} | _filter_scratch
72 done
73
74 # Now do 10 loops of concurrent incremental send/receives
75 for i in `seq 1 10`; do
76         prev=$i
77         curr=$((i+1))
78
79         $BTRFS_UTIL_PROG subvolume snapshot -r $SCRATCH_MNT/subvol1 \
80                 $SCRATCH_MNT/subvol1/.snapshots/${curr} > /dev/null
81         ($BTRFS_UTIL_PROG send -p $SCRATCH_MNT/subvol1/.snapshots/${prev} \
82                 $SCRATCH_MNT/subvol1/.snapshots/${curr} 2> /dev/null | \
83                 $BTRFS_UTIL_PROG receive $SCRATCH_MNT/recv1_1) > /dev/null &
84         ($BTRFS_UTIL_PROG send -p $SCRATCH_MNT/subvol1/.snapshots/${prev} \
85                 $SCRATCH_MNT/subvol1/.snapshots/${curr} 2> /dev/null | \
86                 $BTRFS_UTIL_PROG receive $SCRATCH_MNT/recv1_2) > /dev/null &
87
88         $BTRFS_UTIL_PROG subvolume snapshot -r $SCRATCH_MNT/subvol2 \
89                 $SCRATCH_MNT/subvol2/.snapshots/${curr} > /dev/null
90         ($BTRFS_UTIL_PROG send -p $SCRATCH_MNT/subvol2/.snapshots/${prev} \
91                 $SCRATCH_MNT/subvol2/.snapshots/${curr} 2> /dev/null | \
92                 $BTRFS_UTIL_PROG receive $SCRATCH_MNT/recv2_1) > /dev/null &
93         ($BTRFS_UTIL_PROG send -p $SCRATCH_MNT/subvol2/.snapshots/${prev} \
94                 $SCRATCH_MNT/subvol2/.snapshots/${curr} 2> /dev/null | \
95                 $BTRFS_UTIL_PROG receive $SCRATCH_MNT/recv2_2) > /dev/null &
96         wait
97 done
98
99 _scratch_unmount
100
101 status=0
102 exit