btrfs/057: Fix false alerts due to orphan files
[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 _supported_os Linux
39 _require_scratch
40
41 _scratch_mkfs > /dev/null 2>&1
42 _scratch_mount
43
44
45 # Populate the fs
46 $BTRFS_UTIL_PROG subvolume create "$SCRATCH_MNT/subvol" > /dev/null
47 _pwrite_byte 0xcdcd 0 1M "$SCRATCH_MNT/subvol/file1" > /dev/null
48
49 # Ensure that buffered file data is persisted, so we won't have an
50 # empty file in the snapshot.
51 sync
52 $BTRFS_UTIL_PROG subvolume snapshot "$SCRATCH_MNT/subvol" \
53         "$SCRATCH_MNT/snapshot" > /dev/null
54
55
56 $BTRFS_UTIL_PROG quota enable "$SCRATCH_MNT" > /dev/null
57 $BTRFS_UTIL_PROG quota rescan -w "$SCRATCH_MNT" > /dev/null
58
59 # Create high level qgroup
60 $BTRFS_UTIL_PROG qgroup create 1/0 "$SCRATCH_MNT"
61
62 $BTRFS_UTIL_PROG qgroup assign "$SCRATCH_MNT/snapshot" 1/0 "$SCRATCH_MNT" \
63         2>&1 | _filter_btrfs_qgroup_assign_warnings
64
65 # Above assignment will mark qgroup inconsistent due to the shared extents
66 # between subvol/snapshot/high level qgroup, do rescan here.
67 $BTRFS_UTIL_PROG quota rescan -w "$SCRATCH_MNT" > /dev/null
68
69 # Now remove the qgroup relationship and make 1/0 childless
70 # Due to the shared extent outside of 1/0, we will mark qgroup inconsistent
71 # and keep the number of qgroup 1/0.
72 $BTRFS_UTIL_PROG qgroup remove "$SCRATCH_MNT/snapshot" 1/0 "$SCRATCH_MNT" \
73         2>&1 | _filter_btrfs_qgroup_assign_warnings
74
75 # Above removal also marks qgroup inconsistent, rescan again
76 $BTRFS_UTIL_PROG quota rescan -w "$SCRATCH_MNT" > /dev/null
77
78 # After the test, btrfs check will verify qgroup numbers to catch any
79 # corruption.
80
81 echo "Silence is golden"
82
83 # success, all done
84 status=0
85 exit