xfs: Check for extent overflow when trivally adding a new extent
[xfstests-dev.git] / tests / btrfs / 233
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2021 SUSE Linux Products GmbH. All Rights Reserved.
4 #
5 # FSQA Test No. 233
6 #
7 # Test that subvolume deletion is resumed on RW mounts, that it is not performed
8 # on RO mounts and that after remounting a filesystem from RO to RW mode, it is
9 # performed.
10 #
11 seq=`basename $0`
12 seqres=$RESULT_DIR/$seq
13 echo "QA output created by $seq"
14 tmp=/tmp/$$
15 status=1        # failure is the default!
16 trap "_cleanup; exit \$status" 0 1 2 3 15
17
18 _cleanup()
19 {
20         _cleanup_flakey
21         cd /
22         rm -f $tmp.*
23 }
24
25 # get standard environment, filters and checks
26 . ./common/rc
27 . ./common/filter
28 . ./common/dmflakey
29
30 # real QA test starts here
31 _supported_fs btrfs
32 _require_scratch
33 _require_dm_target flakey
34 _require_btrfs_command inspect-internal dump-tree
35
36 rm -f $seqres.full
37
38 _scratch_mkfs >>$seqres.full 2>&1
39 _require_metadata_journaling $SCRATCH_DEV
40 _init_flakey
41 _mount_flakey
42
43 check_subvol_orphan_item_exists()
44 {
45         # Check that the orphan item for our subvolume exists in the root tree.
46         $BTRFS_UTIL_PROG inspect-internal dump-tree -t 1 $SCRATCH_DEV | \
47                 grep -q 'ORPHAN ORPHAN_ITEM 256'
48         [ $? -ne 0 ] && echo "subvolume orphan item is missing"
49 }
50
51 check_subvol_orphan_item_not_exists()
52 {
53         # Check that the orphan item for our subvolume does not exists in the
54         # root tree.
55         $BTRFS_UTIL_PROG inspect-internal dump-tree -t 1 $SCRATCH_DEV | \
56                 grep -q 'ORPHAN ORPHAN_ITEM 256'
57         [ $? -eq 0 ] && echo "subvolume orphan item still exists"
58 }
59
60 check_subvol_btree_exists()
61 {
62         $BTRFS_UTIL_PROG inspect-internal dump-tree $SCRATCH_DEV | \
63                 grep -q 'file tree key (256 ROOT_ITEM 0)'
64         [ $? -ne 0 ] && echo "subvolume btree is missing"
65 }
66
67 check_subvol_btree_not_exists()
68 {
69         $BTRFS_UTIL_PROG inspect-internal dump-tree $SCRATCH_DEV | \
70                 grep -q 'file tree key (256 ROOT_ITEM 0)'
71         [ $? -eq 0 ] && echo "subvolume btree still exists"
72 }
73
74 create_subvol_with_orphan()
75 {
76         $BTRFS_UTIL_PROG subvolume create $SCRATCH_MNT/testsv | _filter_scratch
77
78         # Create a file in our subvolume and make it durably persisted.
79         touch $SCRATCH_MNT/testsv/foobar
80         sync
81
82         # Now open a file descriptor on the file and, while holding the file
83         # open, delete the subvolume, then 'sync' to durably persist the orphan
84         # item for the subvolume.
85         exec 73< $SCRATCH_MNT/testsv/foobar
86         $BTRFS_UTIL_PROG subvolume delete $SCRATCH_MNT/testsv | _filter_scratch
87         sync
88
89         # Now silently drop writes on the device, close the file descriptor and
90         # unmount the filesystem. After this we should have an orphan item in
91         # root tree for the subvolume, so that its tree is deleted on the next
92         # RW mount.
93         _load_flakey_table $FLAKEY_DROP_WRITES
94         exec 73>&-
95         _unmount_flakey
96
97         check_subvol_orphan_item_exists
98         check_subvol_btree_exists
99
100         _load_flakey_table $FLAKEY_ALLOW_WRITES
101 }
102
103 create_subvol_with_orphan
104
105 # Mount the filesystem in RW mode and unmount it. After that, the subvolume
106 # and its orphan item should not exist anymore.
107 # Use a commit interval lower than the default (30 seconds) so that the test
108 # is faster and we spend less time waiting for transaction commits.
109 MOUNT_OPTIONS="-o commit=1"
110 _mount_flakey
111 $BTRFS_UTIL_PROG subvolume sync $SCRATCH_MNT >>$seqres.full
112 _unmount_flakey
113
114 check_subvol_orphan_item_not_exists
115 check_subvol_btree_not_exists
116
117 # Now lets check a RO mount does not trigger subvolume deletion.
118 _cleanup_flakey
119 _scratch_mkfs >>$seqres.full 2>&1
120 _init_flakey
121 _mount_flakey
122
123 create_subvol_with_orphan
124 MOUNT_OPTIONS="-o ro,commit=1"
125 _mount_flakey
126 # The subvolume path should not be accessible anymore, even if deletion of the
127 # subvolume btree did not happen yet.
128 [ -e $SCRATCH_MNT/testsv ] && echo "subvolume path still exists"
129 _unmount_flakey
130
131 # The subvolume btree should still exist, even though the path is not accessible.
132 check_subvol_btree_exists
133 # The orphan item for the subvolume should still exist, as the subvolume btree
134 # was not yet deleted.
135 check_subvol_orphan_item_exists
136
137 # Mount the filesystem RO again.
138 _mount_flakey
139
140 # Now remount RW, then unmount and then check the subvolume's orphan item, btree
141 # and path don't exist anymore.
142 MOUNT_OPTIONS="-o remount,rw"
143 _mount_flakey
144 $BTRFS_UTIL_PROG subvolume sync $SCRATCH_MNT >>$seqres.full
145 [ -e $SCRATCH_MNT/testsv ] && echo "subvolume path still exists"
146 _unmount_flakey
147
148 check_subvol_orphan_item_not_exists
149 check_subvol_btree_not_exists
150
151 status=0
152 exit