btrfs: Test subvolume delete --subvolid feature
authorMarcos Paulo de Souza <mpdesouza@suse.com>
Mon, 9 Mar 2020 10:39:56 +0000 (07:39 -0300)
committerEryu Guan <guaneryu@gmail.com>
Sun, 22 Mar 2020 14:16:03 +0000 (22:16 +0800)
Now btrfs can delete subvolumes based in ther subvolume id. This
makes easy for the user willing to delete a subvolume that cannot be
accessed by the mount point, since btrfs allows to mount a specific
subvolume and hiding the other from the mount point.

Signed-off-by: Marcos Paulo de Souza <mpdesouza@suse.com>
Reviewed-by: Josef Bacik <josef@toxicpanda.com>
Signed-off-by: Eryu Guan <guaneryu@gmail.com>
tests/btrfs/208 [new file with mode: 0755]
tests/btrfs/208.out [new file with mode: 0644]
tests/btrfs/group

diff --git a/tests/btrfs/208 b/tests/btrfs/208
new file mode 100755 (executable)
index 0000000..4ffc871
--- /dev/null
@@ -0,0 +1,68 @@
+#! /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.
+#
+seq=`basename $0`
+seqres=$RESULT_DIR/$seq
+echo "QA output created by $seq"
+tmp=/tmp/$$
+status=1       # failure is the default!
+
+# get standard environment, filters and checks
+. ./common/rc
+. ./common/filter
+. ./common/filter.btrfs
+
+# real QA test starts here
+_supported_fs btrfs
+_supported_os Linux
+_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
diff --git a/tests/btrfs/208.out b/tests/btrfs/208.out
new file mode 100644 (file)
index 0000000..9b66069
--- /dev/null
@@ -0,0 +1,17 @@
+QA output created by 208
+Create subvolume 'SCRATCH_MNT/subvol1'
+Create subvolume 'SCRATCH_MNT/subvol2'
+Create subvolume 'SCRATCH_MNT/subvol3'
+Current subvolume ids:
+subvol1
+subvol2
+subvol3
+Delete subvolume (no-commit): 'SCRATCH_MNT/subvol1'
+After deleting one subvolume:
+subvol2
+subvol3
+Delete subvolume (no-commit): 'SCRATCH_MNT/subvol3'
+Last remaining subvolume:
+subvol2
+Delete subvolume (no-commit): 'SCRATCH_MNT/subvol2'
+All subvolumes removed.
index 94090758a912427a00e98f138a5aedbdcada2dfa..4dfed8db7463c8f76ac0d8ec8137de45fb9a0169 100644 (file)
 205 auto quick clone compress
 206 auto quick log replay
 207 auto rw raid
+208 auto quick subvol