generic: test MADV_POPULATE_READ with IO errors
[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 . ./common/preamble
14 _begin_fstest auto quick qgroup
15
16 # Import common functions.
17 . ./common/filter
18 . ./common/filter.btrfs
19
20 # real QA test starts here
21 _supported_fs btrfs
22 _require_scratch
23
24 _scratch_mkfs > /dev/null 2>&1
25 _scratch_mount
26
27 # Populate the fs
28 $BTRFS_UTIL_PROG subvolume create "$SCRATCH_MNT/subvol" > /dev/null
29 _pwrite_byte 0xcdcd 0 1M "$SCRATCH_MNT/subvol/file1" > /dev/null
30
31 # Ensure that buffered file data is persisted, so we won't have an
32 # empty file in the snapshot.
33 sync
34 $BTRFS_UTIL_PROG subvolume snapshot "$SCRATCH_MNT/subvol" \
35         "$SCRATCH_MNT/snapshot" > /dev/null
36
37 $BTRFS_UTIL_PROG quota enable "$SCRATCH_MNT" > /dev/null
38 $BTRFS_UTIL_PROG quota rescan -w "$SCRATCH_MNT" > /dev/null
39
40 # Create high level qgroup
41 $BTRFS_UTIL_PROG qgroup create 1/0 "$SCRATCH_MNT"
42
43 $BTRFS_UTIL_PROG qgroup assign "$SCRATCH_MNT/snapshot" 1/0 "$SCRATCH_MNT" \
44         2>&1 | _filter_btrfs_qgroup_assign_warnings
45
46 # Above assignment will mark qgroup inconsistent due to the shared extents
47 # between subvol/snapshot/high level qgroup, do rescan here.
48 $BTRFS_UTIL_PROG quota rescan -w "$SCRATCH_MNT" > /dev/null
49
50 # Now remove the qgroup relationship and make 1/0 childless
51 # Due to the shared extent outside of 1/0, we will mark qgroup inconsistent
52 # and keep the number of qgroup 1/0.
53 $BTRFS_UTIL_PROG qgroup remove "$SCRATCH_MNT/snapshot" 1/0 "$SCRATCH_MNT" \
54         2>&1 | _filter_btrfs_qgroup_assign_warnings
55
56 # Above removal also marks qgroup inconsistent, rescan again
57 $BTRFS_UTIL_PROG quota rescan -w "$SCRATCH_MNT" > /dev/null
58
59 # After the test, btrfs check will verify qgroup numbers to catch any
60 # corruption.
61
62 echo "Silence is golden"
63
64 # success, all done
65 status=0
66 exit