btrfs/012: check free size of scratch device before copying files
[xfstests-dev.git] / tests / btrfs / 122
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2016 SUSE Linux Products GmbH. All Rights Reserved.
4 #
5 # FS QA Test No. btrfs/122
6 #
7 # Test that qgroup counts are valid after snapshot creation. This has
8 # been broken in btrfs since Linux v4.1
9 #
10 seq=`basename $0`
11 seqres=$RESULT_DIR/$seq
12 echo "QA output created by $seq"
13
14 here=`pwd`
15 tmp=/tmp/$$
16 status=1        # failure is the default!
17 trap "_cleanup; exit \$status" 0 1 2 3 15
18
19 _cleanup()
20 {
21         cd /
22         rm -f $tmp.*
23 }
24
25 # get standard environment, filters and checks
26 . ./common/rc
27 . ./common/filter
28
29 # remove previous $seqres.full before test
30 rm -f $seqres.full
31
32 # real QA test starts here
33 _supported_fs btrfs
34 _require_scratch
35 _require_btrfs_qgroup_report
36
37 rm -f $seqres.full
38
39 # Force a small leaf size to make it easier to blow out our root
40 # subvolume tree
41 _scratch_mkfs "--nodesize 16384" >/dev/null
42 _scratch_mount
43 _run_btrfs_util_prog quota enable $SCRATCH_MNT
44
45 mkdir "$SCRATCH_MNT/snaps"
46
47 # First make some simple snapshots - the bug was initially reproduced like this
48 _run_btrfs_util_prog subvolume snapshot $SCRATCH_MNT "$SCRATCH_MNT/snaps/empty1"
49 _run_btrfs_util_prog subvolume snapshot $SCRATCH_MNT "$SCRATCH_MNT/snaps/empty2"
50
51 # This forces the fs tree out past level 0, adding at least one tree
52 # block which must be properly accounted for when we make our next
53 # snapshots.
54 mkdir "$SCRATCH_MNT/data"
55 for i in `seq 0 640`; do
56         $XFS_IO_PROG -f -c "pwrite 0 1M" "$SCRATCH_MNT/data/file$i" > /dev/null 2>&1
57 done
58
59 # Snapshot twice.
60 _run_btrfs_util_prog subvolume snapshot $SCRATCH_MNT "$SCRATCH_MNT/snaps/snap1"
61 _run_btrfs_util_prog subvolume snapshot $SCRATCH_MNT "$SCRATCH_MNT/snaps/snap2"
62
63 _scratch_unmount
64
65
66 # qgroup will be checked by fstest at _check_scratch_fs()
67 status=0
68 exit