btrfs: fsync after hole punching with no-holes mode
[xfstests-dev.git] / tests / btrfs / 122
1 #! /bin/bash
2 # FS QA Test No. btrfs/122
3 #
4 # Test that qgroup counts are valid after snapshot creation. This has
5 # been broken in btrfs since Linux v4.1
6 #
7 #-----------------------------------------------------------------------
8 # Copyright (C) 2016 SUSE Linux Products GmbH. All Rights Reserved.
9 #
10 # This program is free software; you can redistribute it and/or
11 # modify it under the terms of the GNU General Public License as
12 # published by the Free Software Foundation.
13 #
14 # This program is distributed in the hope that it would be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 # GNU General Public License for more details.
18 #
19 # You should have received a copy of the GNU General Public License
20 # along with this program; if not, write the Free Software Foundation,
21 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
22 #
23 #-----------------------------------------------------------------------
24 #
25
26 seq=`basename $0`
27 seqres=$RESULT_DIR/$seq
28 echo "QA output created by $seq"
29
30 here=`pwd`
31 tmp=/tmp/$$
32 status=1        # failure is the default!
33 trap "_cleanup; exit \$status" 0 1 2 3 15
34
35 _cleanup()
36 {
37         cd /
38         rm -f $tmp.*
39 }
40
41 # get standard environment, filters and checks
42 . ./common/rc
43 . ./common/filter
44
45 # remove previous $seqres.full before test
46 rm -f $seqres.full
47
48 # real QA test starts here
49 _supported_fs btrfs
50 _supported_os Linux
51 _require_scratch
52 _require_btrfs_qgroup_report
53
54 rm -f $seqres.full
55
56 # Force a small leaf size to make it easier to blow out our root
57 # subvolume tree
58 _scratch_mkfs "--nodesize 16384" >/dev/null
59 _scratch_mount
60 _run_btrfs_util_prog quota enable $SCRATCH_MNT
61
62 mkdir "$SCRATCH_MNT/snaps"
63
64 # First make some simple snapshots - the bug was initially reproduced like this
65 _run_btrfs_util_prog subvolume snapshot $SCRATCH_MNT "$SCRATCH_MNT/snaps/empty1"
66 _run_btrfs_util_prog subvolume snapshot $SCRATCH_MNT "$SCRATCH_MNT/snaps/empty2"
67
68 # This forces the fs tree out past level 0, adding at least one tree
69 # block which must be properly accounted for when we make our next
70 # snapshots.
71 mkdir "$SCRATCH_MNT/data"
72 for i in `seq 0 640`; do
73         $XFS_IO_PROG -f -c "pwrite 0 1M" "$SCRATCH_MNT/data/file$i" > /dev/null 2>&1
74 done
75
76 # Snapshot twice.
77 _run_btrfs_util_prog subvolume snapshot $SCRATCH_MNT "$SCRATCH_MNT/snaps/snap1"
78 _run_btrfs_util_prog subvolume snapshot $SCRATCH_MNT "$SCRATCH_MNT/snaps/snap2"
79
80 _scratch_unmount
81
82
83 # qgroup will be checked by fstest at _check_scratch_fs()
84 status=0
85 exit