Skip to contentSkip to conversation

btrfs: Test subvolume delete by id feature

PATCH In review Marcos Paulo de Souza 3 participants 5 messages Feb 7, 2020 – Feb 17, 2020 Btrfs file system

lore
Share & tools
lore
#0 lore raw

v2 cover btrfs: Test subvolume delete by id feature

From: Marcos Paulo de Souza <[email protected]>

Changes from v1:
* Added some prints printing what is being tested
* The test now uses the _btrfs_get_subvolid to get subvolumeids instead of using plain integers
* New patch expanding the funtionality of _require_btrfs_command, which now check for argument of subcommands

Marcos Paulo de Souza (2):
common: btrfs: Improve _require_btrfs_command
btrfs: Test subvolume delete --subvolid feature

 common/btrfs        | 13 ++++++--
 tests/btrfs/203     | 73 +++++++++++++++++++++++++++++++++++++++++++++
 tests/btrfs/203.out | 14 +++++++++
 tests/btrfs/group   |  1 +
 4 files changed, 99 insertions(+), 2 deletions(-)
 create mode 100755 tests/btrfs/203
 create mode 100644 tests/btrfs/203.out
Signature · 1 line
2.24.0
#1 lore raw

PATCH v2 1/2 common: btrfs: Improve _require_btrfs_command

From: Marcos Paulo de Souza <[email protected]>

Now _require_btrfs_command can also check for subfuntion options, like "subvolume delete --subvolid".

---

Changes from v1:
* New patch expanding the funtionality of _require_btrfs_command, which now check for argument of subcommands

 common/btrfs | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)
common/btrfs +11 -2
index 19ac7cc4..ae3142b6 100644
@@ -12,12 +12,14 @@ _btrfs_get_subvolid()
 
 # _require_btrfs_command <command> [<subcommand>|<option>]
 # We check for btrfs and (optionally) features of the btrfs command
-# It can both subfunction like "inspect-internal dump-tree" and
-# options like "check --qgroup-report"
+# This function support both subfunction like "inspect-internal dump-tree" and
+# options like "check --qgroup-report", and also subfunction options like
+# "subvolume delete --subvolid"
 _require_btrfs_command()
 {
 	local cmd=$1
 	local param=$2
+	local param_arg=$3
 	local safe_param
 
 	_require_command "$BTRFS_UTIL_PROG" btrfs
@@ -39,6 +41,13 @@ _require_btrfs_command()
 
 	$BTRFS_UTIL_PROG $cmd $param --help &> /dev/null
 	[ $? -eq 0 ] || _notrun "$BTRFS_UTIL_PROG too old (must support $cmd $param)"
+
+	test -z "$param_arg" && return
+
+	# replace leading "-"s for grep
+	safe_param=$(echo $param_arg | sed 's/^-*//')
+	$BTRFS_UTIL_PROG $cmd $param --help | grep -wq $safe_param || \
+		_notrun "$BTRFS_UTIL_PROG too old (must support $cmd $param $param_arg)"
 }
 
 # Require extra check on btrfs qgroup numbers
Signature · 1 line
2.24.0
Reviewed-by on v2 1/2
#2 lore raw

Re: [PATCHv2 1/2] common: btrfs: Improve _require_btrfs_command

Quoted 6 lines · Marcos Paulo de Souza

From: Marcos Paulo de Souza <[email protected]>

Now _require_btrfs_command can also check for subfuntion options, like "subvolume delete --subvolid".

Quoted 31 lines

---

Changes from v1:
* New patch expanding the funtionality of _require_btrfs_command, which now check for argument of subcommands

 common/btrfs | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)
common/btrfs +4 -2
index 19ac7cc4..ae3142b6 100644
@@ -12,12 +12,14 @@ _btrfs_get_subvolid()
 
 # _require_btrfs_command <command> [<subcommand>|<option>]
 # We check for btrfs and (optionally) features of the btrfs command
-# It can both subfunction like "inspect-internal dump-tree" and
-# options like "check --qgroup-report"
+# This function support both subfunction like "inspect-internal dump-tree" and
+# options like "check --qgroup-report", and also subfunction options like
+# "subvolume delete --subvolid"
 _require_btrfs_command()
 {
 	local cmd=$1
 	local param=$2
+	local param_arg=$3
 	local safe_param
 
 	_require_command "$BTRFS_UTIL_PROG" btrfs

common/btrfs _require_btrfs_command() · line 45

Quoted 5 lines
common/btrfs +2 -0
@@ -39,6 +41,13 @@ _require_btrfs_command()
 
 	$BTRFS_UTIL_PROG $cmd $param --help &> /dev/null
 	[ $? -eq 0 ] || _notrun "$BTRFS_UTIL_PROG too old (must support $cmd $param)"
+
+	test -z "$param_arg" && return

nit: That could be [ -z "$param_arg" ] && return so the code is uniform with the rest of the tests in this function

Quoted 9 lines
common/btrfs +5 -0
+
+	# replace leading "-"s for grep
+	safe_param=$(echo $param_arg | sed 's/^-*//')
+	$BTRFS_UTIL_PROG $cmd $param --help | grep -wq $safe_param || \
+		_notrun "$BTRFS_UTIL_PROG too old (must support $cmd $param $param_arg)"
 }
 
 # Require extra check on btrfs qgroup numbers
#3 lore raw

PATCH v2 2/2 btrfs: Test subvolume delete --subvolid feature

In reply to Marcos Paulo de Souza

From: Marcos Paulo de Souza <[email protected]>

---
Changes from v1:
* Added some prints printing what is being tested
* The test now uses the _btrfs_get_subvolid to get subvolumeids instead of using plain integers

 tests/btrfs/203     | 73 +++++++++++++++++++++++++++++++++++++++++++++
 tests/btrfs/203.out | 14 +++++++++
 tests/btrfs/group   |  1 +
 3 files changed, 88 insertions(+)
 create mode 100755 tests/btrfs/203
 create mode 100644 tests/btrfs/203.out
tests/btrfs/203 new file +73 -0
new file mode 100755
index 00000000..b9f1391f
@@ -0,0 +1,73 @@
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (C) 2020 SUSE Linux Products GmbH. All Rights Reserved.
+#
+# FSQA Test No. 203
+#
+# 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
+
+# Test creating a normal subvolumes
+_run_btrfs_util_prog subvolume create $SCRATCH_MNT/subvol1 | _filter_scratch
+_run_btrfs_util_prog subvolume create $SCRATCH_MNT/subvol2 | _filter_scratch
+_run_btrfs_util_prog subvolume create $SCRATCH_MNT/subvol3 | _filter_scratch
+
+echo "Current subvolume ids:"
+$BTRFS_UTIL_PROG subvolume list $SCRATCH_MNT | awk '{ print $NF }'
+
+# Delete the subvolume subvol1 using it's subvolume id
+SUBVOLID=$(_btrfs_get_subvolid $SCRATCH_MNT subvol1)
+$BTRFS_UTIL_PROG subvolume delete --subvolid $SUBVOLID  $SCRATCH_MNT | _filter_scratch
+
+echo "After deleting one subvolume:"
+# should present only two subvolumes
+$BTRFS_UTIL_PROG subvolume list $SCRATCH_MNT | awk '{ print $NF }'
+
+umount $SCRATCH_MNT
+
+# 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
+SUBVOLID=$(_btrfs_get_subvolid $SCRATCH_MNT subvol3)
+$BTRFS_UTIL_PROG subvolume delete --subvolid $SUBVOLID $SCRATCH_MNT | _filter_scratch
+
+echo "Last remaining subvolume:"
+$BTRFS_UTIL_PROG subvolume list $SCRATCH_MNT | awk '{ print $NF }'
+
+umount $SCRATCH_MNT
+
+# now mount the rootfs
+_scratch_mount
+
+# Delete the subvol2
+SUBVOLID=$(_btrfs_get_subvolid $SCRATCH_MNT subvol2)
+$BTRFS_UTIL_PROG subvolume delete --subvolid $SUBVOLID  $SCRATCH_MNT | _filter_scratch
+
+echo "All subvolumes removed."
+$BTRFS_UTIL_PROG subvolume list $SCRATCH_MNT | awk '{ print $NF }'
+
+umount $SCRATCH_MNT
+
+# success, all done
+status=0
+exit
tests/btrfs/203.out new file +14 -0
new file mode 100644
index 00000000..bca18c32
@@ -0,0 +1,14 @@
+QA output created by 203
+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.
tests/btrfs/group +1 -0
index 79f85e97..e7744217 100644
@@ -204,3 +204,4 @@
 200 auto quick send clone
 201 auto quick punch log
 202 auto quick subvol snapshot
+203 auto quick subvol
Signature · 1 line
2.24.0
#4 lore raw

Re: [PATCHv2 2/2] btrfs: Test subvolume delete --subvolid feature

Quoted 45 lines · Marcos Paulo de Souza

From: Marcos Paulo de Souza <[email protected]>

---
Changes from v1:
* Added some prints printing what is being tested
* The test now uses the _btrfs_get_subvolid to get subvolumeids instead of using plain integers

 tests/btrfs/203     | 73 +++++++++++++++++++++++++++++++++++++++++++++
 tests/btrfs/203.out | 14 +++++++++
 tests/btrfs/group   |  1 +
 3 files changed, 88 insertions(+)
 create mode 100755 tests/btrfs/203
 create mode 100644 tests/btrfs/203.out
tests/btrfs/203 new file +23 -0
new file mode 100755
index 00000000..b9f1391f
@@ -0,0 +1,73 @@
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (C) 2020 SUSE Linux Products GmbH. All Rights Reserved.
+#
+# FSQA Test No. 203
+#
+# 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

tests/btrfs/203 line 33

Quoted 10 lines
tests/btrfs/203 new file +10 -0
+_require_scratch
+_require_btrfs_command subvolume delete --subvolid
+
+_scratch_mkfs > /dev/null 2>&1
+_scratch_mount
+
+# Test creating a normal subvolumes
+_run_btrfs_util_prog subvolume create $SCRATCH_MNT/subvol1 | _filter_scratch
+_run_btrfs_util_prog subvolume create $SCRATCH_MNT/subvol2 | _filter_scratch
+_run_btrfs_util_prog subvolume create $SCRATCH_MNT/subvol3 | _filter_scratch

The usa of _run_btrfs_util_prog is deprecated, please use bare $BTRFS_UTIL_PROG commands, and do filter as needed.

tests/btrfs/203 line 36

Quoted 3 lines
tests/btrfs/203 new file +3 -0
+
+echo "Current subvolume ids:"
+$BTRFS_UTIL_PROG subvolume list $SCRATCH_MNT | awk '{ print $NF }'

Use $AWK_PROG instead of bare awk. And I noticed this pattern repeated for several times, make it a local helper function?

tests/btrfs/203 line 46

Quoted 10 lines
tests/btrfs/203 new file +10 -0
+
+# Delete the subvolume subvol1 using it's subvolume id
+SUBVOLID=$(_btrfs_get_subvolid $SCRATCH_MNT subvol1)
+$BTRFS_UTIL_PROG subvolume delete --subvolid $SUBVOLID  $SCRATCH_MNT | _filter_scratch
+
+echo "After deleting one subvolume:"
+# should present only two subvolumes
+$BTRFS_UTIL_PROG subvolume list $SCRATCH_MNT | awk '{ print $NF }'
+
+umount $SCRATCH_MNT

Does _scratch_unmount work here?

tests/btrfs/203 line 57

Quoted 11 lines
tests/btrfs/203 new file +11 -0
+
+# 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
+SUBVOLID=$(_btrfs_get_subvolid $SCRATCH_MNT subvol3)
+$BTRFS_UTIL_PROG subvolume delete --subvolid $SUBVOLID $SCRATCH_MNT | _filter_scratch
+
+echo "Last remaining subvolume:"
+$BTRFS_UTIL_PROG subvolume list $SCRATCH_MNT | awk '{ print $NF }'
+
+umount $SCRATCH_MNT

_scratch_unmount

tests/btrfs/203 line 69

Quoted 12 lines
tests/btrfs/203 new file +12 -0
+
+# now mount the rootfs
+_scratch_mount
+
+# Delete the subvol2
+SUBVOLID=$(_btrfs_get_subvolid $SCRATCH_MNT subvol2)
+$BTRFS_UTIL_PROG subvolume delete --subvolid $SUBVOLID  $SCRATCH_MNT | _filter_scratch
+
+echo "All subvolumes removed."
+$BTRFS_UTIL_PROG subvolume list $SCRATCH_MNT | awk '{ print $NF }'
+
+umount $SCRATCH_MNT

_scratch_unmount

Thanks,
Eryu

Quoted 36 lines
tests/btrfs/203 new file +4 -0
+
+# success, all done
+status=0
+exit
tests/btrfs/203.out new file +14 -0
new file mode 100644
index 00000000..bca18c32
@@ -0,0 +1,14 @@
+QA output created by 203
+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.
tests/btrfs/group +1 -0
index 79f85e97..e7744217 100644
@@ -204,3 +204,4 @@
 200 auto quick send clone
 201 auto quick punch log
 202 auto quick subvol snapshot
+203 auto quick subvol
Signature · 1 line
2.24.0