generic: test for non-zero used blocks while writing into a file
[xfstests-dev.git] / tests / btrfs / 171
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2018 SUSE Linux Products GmbH.  All Rights Reserved.
4 #
5 # FS QA Test 171
6 #
7 # Test if btrfs can clear high level childless qgroup's accounting numbers
8 # during rescan.
9 #
10 # Fixed by the following kernel patch:
11 # "btrfs: qgroup: Dirty all qgroups before rescan"
12 #
13 seq=`basename $0`
14 seqres=$RESULT_DIR/$seq
15 echo "QA output created by $seq"
16
17 here=`pwd`
18 tmp=/tmp/$$
19 status=1        # failure is the default!
20 trap "_cleanup; exit \$status" 0 1 2 3 15
21
22 _cleanup()
23 {
24         cd /
25         rm -f $tmp.*
26 }
27
28 # get standard environment, filters and checks
29 . ./common/rc
30 . ./common/filter
31 . ./common/filter.btrfs
32
33 # remove previous $seqres.full before test
34 rm -f $seqres.full
35
36 # real QA test starts here
37 _supported_fs btrfs
38 _require_scratch
39
40 _scratch_mkfs > /dev/null 2>&1
41 _scratch_mount
42
43
44 # Populate the fs
45 $BTRFS_UTIL_PROG subvolume create "$SCRATCH_MNT/subvol" > /dev/null
46 _pwrite_byte 0xcdcd 0 1M "$SCRATCH_MNT/subvol/file1" > /dev/null
47
48 # Ensure that buffered file data is persisted, so we won't have an
49 # empty file in the snapshot.
50 sync
51 $BTRFS_UTIL_PROG subvolume snapshot "$SCRATCH_MNT/subvol" \
52         "$SCRATCH_MNT/snapshot" > /dev/null
53
54
55 $BTRFS_UTIL_PROG quota enable "$SCRATCH_MNT" > /dev/null
56 $BTRFS_UTIL_PROG quota rescan -w "$SCRATCH_MNT" > /dev/null
57
58 # Create high level qgroup
59 $BTRFS_UTIL_PROG qgroup create 1/0 "$SCRATCH_MNT"
60
61 $BTRFS_UTIL_PROG qgroup assign "$SCRATCH_MNT/snapshot" 1/0 "$SCRATCH_MNT" \
62         2>&1 | _filter_btrfs_qgroup_assign_warnings
63
64 # Above assignment will mark qgroup inconsistent due to the shared extents
65 # between subvol/snapshot/high level qgroup, do rescan here.
66 $BTRFS_UTIL_PROG quota rescan -w "$SCRATCH_MNT" > /dev/null
67
68 # Now remove the qgroup relationship and make 1/0 childless
69 # Due to the shared extent outside of 1/0, we will mark qgroup inconsistent
70 # and keep the number of qgroup 1/0.
71 $BTRFS_UTIL_PROG qgroup remove "$SCRATCH_MNT/snapshot" 1/0 "$SCRATCH_MNT" \
72         2>&1 | _filter_btrfs_qgroup_assign_warnings
73
74 # Above removal also marks qgroup inconsistent, rescan again
75 $BTRFS_UTIL_PROG quota rescan -w "$SCRATCH_MNT" > /dev/null
76
77 # After the test, btrfs check will verify qgroup numbers to catch any
78 # corruption.
79
80 echo "Silence is golden"
81
82 # success, all done
83 status=0
84 exit