btrfs: check qgroup doesn't crash when beyond limit
[xfstests-dev.git] / tests / btrfs / 208
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2020 SUSE Linux Products GmbH. All Rights Reserved.
4 #
5 # FSQA Test No. 208
6 #
7 # Test subvolume deletion using the subvolume id, even when the subvolume in
8 # question is in a different mount space.
9 #
10 seq=`basename $0`
11 seqres=$RESULT_DIR/$seq
12 echo "QA output created by $seq"
13 tmp=/tmp/$$
14 status=1        # failure is the default!
15
16 # get standard environment, filters and checks
17 . ./common/rc
18 . ./common/filter
19 . ./common/filter.btrfs
20
21 # real QA test starts here
22 _supported_fs btrfs
23 _require_scratch
24 _require_btrfs_command subvolume delete --subvolid
25
26 _scratch_mkfs > /dev/null 2>&1
27 _scratch_mount
28
29 _delete_and_list()
30 {
31         local subvol_name="$1"
32         local msg="$2"
33
34         SUBVOLID=$(_btrfs_get_subvolid $SCRATCH_MNT "$subvol_name")
35         $BTRFS_UTIL_PROG subvolume delete --subvolid $SUBVOLID $SCRATCH_MNT | _filter_scratch
36
37         echo "$msg"
38         $BTRFS_UTIL_PROG subvolume list $SCRATCH_MNT | $AWK_PROG '{ print $NF }'
39 }
40
41 # Test creating a normal subvolumes
42 $BTRFS_UTIL_PROG subvolume create $SCRATCH_MNT/subvol1 | _filter_scratch
43 $BTRFS_UTIL_PROG subvolume create $SCRATCH_MNT/subvol2 | _filter_scratch
44 $BTRFS_UTIL_PROG subvolume create $SCRATCH_MNT/subvol3 | _filter_scratch
45
46 echo "Current subvolume ids:"
47 $BTRFS_UTIL_PROG subvolume list $SCRATCH_MNT | $AWK_PROG '{ print $NF }'
48
49 # Delete the subvolume subvol1, and list the remaining two subvolumes
50 _delete_and_list subvol1 "After deleting one subvolume:"
51 _scratch_unmount
52
53 # Now we mount the subvol2, which makes subvol3 not accessible for this mount
54 # point, but we should be able to delete it using it's subvolume id
55 $MOUNT_PROG -o subvol=subvol2 $SCRATCH_DEV $SCRATCH_MNT
56 _delete_and_list subvol3 "Last remaining subvolume:"
57 _scratch_unmount
58
59 # now mount the rootfs
60 _scratch_mount
61 # Delete the subvol2
62 _delete_and_list subvol2 "All subvolumes removed."
63 _scratch_unmount
64
65 # success, all done
66 status=0
67 exit