summaryrefslogtreecommitdiff
path: root/tests/btrfs/208
blob: 909f9fa40803e6c089f6059bd51d3f8d45b4ff55 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#! /bin/bash
# SPDX-License-Identifier: GPL-2.0
# Copyright (C) 2020 SUSE Linux Products GmbH. All Rights Reserved.
#
# FSQA Test No. 208
#
# Test subvolume deletion using the subvolume id, even when the subvolume in
# question is in a different mount space.
#
. ./common/preamble
_begin_fstest auto quick subvol

# Import common functions.
. ./common/filter
. ./common/filter.btrfs

# real QA test starts here
_supported_fs btrfs
_require_scratch
_require_btrfs_command subvolume delete --subvolid

_scratch_mkfs > /dev/null 2>&1
_scratch_mount

_delete_and_list()
{
	local subvol_name="$1"
	local msg="$2"

	SUBVOLID=$(_btrfs_get_subvolid $SCRATCH_MNT "$subvol_name")
	$BTRFS_UTIL_PROG subvolume delete --subvolid $SUBVOLID $SCRATCH_MNT | _filter_scratch

	echo "$msg"
	$BTRFS_UTIL_PROG subvolume list $SCRATCH_MNT | $AWK_PROG '{ print $NF }'
}

# Test creating a normal subvolumes
$BTRFS_UTIL_PROG subvolume create $SCRATCH_MNT/subvol1 | _filter_scratch
$BTRFS_UTIL_PROG subvolume create $SCRATCH_MNT/subvol2 | _filter_scratch
$BTRFS_UTIL_PROG subvolume create $SCRATCH_MNT/subvol3 | _filter_scratch

echo "Current subvolume ids:"
$BTRFS_UTIL_PROG subvolume list $SCRATCH_MNT | $AWK_PROG '{ print $NF }'

# Delete the subvolume subvol1, and list the remaining two subvolumes
_delete_and_list subvol1 "After deleting one subvolume:"
_scratch_unmount

# Now we mount the subvol2, which makes subvol3 not accessible for this mount
# point, but we should be able to delete it using it's subvolume id
$MOUNT_PROG -o subvol=subvol2 $SCRATCH_DEV $SCRATCH_MNT
_delete_and_list subvol3 "Last remaining subvolume:"
_scratch_unmount

# now mount the rootfs
_scratch_mount
# Delete the subvol2
_delete_and_list subvol2 "All subvolumes removed."
_scratch_unmount

# success, all done
status=0
exit