Skip to contentSkip to conversation

btrfs: Test subvolume delete by id feature

PATCH Superseded Marcos Paulo de Souza 3 participants 9 messages Feb 24, 2020 – Mar 8, 2020 Btrfs file system

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v3 cover btrfs: Test subvolume delete by id feature

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

Changes from v2:
* Added Reviewed-by from Nikolay to patch 0001
* Changed awk to $AWK_PROG, suggested by Eryu
* Changed _run_btrfs_util_prog to $BTRFS_UTIL_PROG, suggested by Eryu
* Use _scratch_unmount instead of executing umount by hand, sugested by Eryu
* Created a local function to delete and list subvolumes, suggested by Eryu

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.25.0
#1 lore raw

PATCH v3 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 v2:
* Added Reviewed-by from Nikolay to patch 0001

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.25.0
#3 lore raw

Re: [ fstests PATCHv3 1/2] common: btrfs: Improve _require_btrfs_command

In reply to Marcos Paulo de Souza
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".

Ah, this patch has already been applied in previous updates. Please see

2f9b4039253d common/btrfs: Improve _require_btrfs_command

Thanks,
Eryu

Quoted 49 lines

---
Changes from v2:
* Added Reviewed-by from Nikolay to patch 0001

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.25.0
#4 lore raw

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

In reply to Marcos Paulo de Souza

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

---
Changes from v2:
* Added 'Created subvolume...' into 203.out to match the subvolume creating command
* Changed awk to $AWK_PROG, suggested by Eryu
* Changed _run_btrfs_util_prog to $BTRFS_UTIL_PROG, suggested by Eryu
* Use _scratch_unmount instead of executing umount by hand, sugested by Eryu
* Created a local function to delete and list subvolumes, suggested by Eryu

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     | 68 +++++++++++++++++++++++++++++++++++++++++++++
 tests/btrfs/203.out | 17 ++++++++++++
 tests/btrfs/group   |  1 +
 3 files changed, 86 insertions(+)
 create mode 100755 tests/btrfs/203
 create mode 100644 tests/btrfs/203.out
tests/btrfs/203 new file +68 -0
new file mode 100755
index 00000000..0f662db1
@@ -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. 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
+
+_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
tests/btrfs/203.out new file +17 -0
new file mode 100644
index 00000000..3301852b
@@ -0,0 +1,17 @@
+QA output created by 203
+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.
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.25.0
#5 lore raw

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

Quoted 3 lines · Marcos Paulo de Souza

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

Looks fine to me overall, but it'd be better to have commit message to describe the test.

Also, it'd be great if btrfs folks could help review it.

Thanks,
Eryu

Quoted 130 lines

---
Changes from v2:
* Added 'Created subvolume...' into 203.out to match the subvolume creating command
* Changed awk to $AWK_PROG, suggested by Eryu
* Changed _run_btrfs_util_prog to $BTRFS_UTIL_PROG, suggested by Eryu
* Use _scratch_unmount instead of executing umount by hand, sugested by Eryu
* Created a local function to delete and list subvolumes, suggested by Eryu

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     | 68 +++++++++++++++++++++++++++++++++++++++++++++
 tests/btrfs/203.out | 17 ++++++++++++
 tests/btrfs/group   |  1 +
 3 files changed, 86 insertions(+)
 create mode 100755 tests/btrfs/203
 create mode 100644 tests/btrfs/203.out
tests/btrfs/203 new file +68 -0
new file mode 100755
index 00000000..0f662db1
@@ -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. 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
+
+_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
tests/btrfs/203.out new file +17 -0
new file mode 100644
index 00000000..3301852b
@@ -0,0 +1,17 @@
+QA output created by 203
+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.
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.25.0
#6 lore raw

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

Quoted 9 lines · Eryu Guan
Quoted 3 lines · Marcos Paulo de Souza

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

Looks fine to me overall, but it'd be better to have commit message to describe the test.

Also, it'd be great if btrfs folks could help review it.

Indeed, a commit message makes things better. I'm attaching here a new version of the patch containing a commit message. This new version also bumps the test number from 203 -> 207, since other messages were merged after I sent my patch.

While adding the commit message I found in Josef's commit that he added a new btrfs test 206, but groups contained test 204[1]. Is it a typo?

[1]: https://git.kernel.org/pub/scm/fs/xfs/xfstests-dev.git/commit/?id=1d6d14db1165db1ffc87fbddcf97eb70fdf84607

Quoted 126 lines

Thanks,
Eryu

Quoted 122 lines

---
Changes from v2:
* Added 'Created subvolume...' into 203.out to match the subvolume creating command
* Changed awk to $AWK_PROG, suggested by Eryu
* Changed _run_btrfs_util_prog to $BTRFS_UTIL_PROG, suggested by Eryu
* Use _scratch_unmount instead of executing umount by hand, sugested by Eryu
* Created a local function to delete and list subvolumes, suggested by Eryu

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     | 68 +++++++++++++++++++++++++++++++++++++++++++++
 tests/btrfs/203.out | 17 ++++++++++++
 tests/btrfs/group   |  1 +
 3 files changed, 86 insertions(+)
 create mode 100755 tests/btrfs/203
 create mode 100644 tests/btrfs/203.out
tests/btrfs/203 new file +68 -0
new file mode 100755
index 00000000..0f662db1
@@ -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. 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
+
+_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
tests/btrfs/203.out new file +17 -0
new file mode 100644
index 00000000..3301852b
@@ -0,0 +1,17 @@
+QA output created by 203
+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.
tests/btrfs/group +0 -0
index 79f85e97..e7744217 100644
Quoted 8 lines
Quoted 8 lines
tests/btrfs/group +1 -0
@@ -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.25.0

From 2541e8ef08d45030f97073ef1e5bc9196ef22e4d Mon Sep 17 00:00:00 2001
From: Marcos Paulo de Souza <[email protected]>
Date: Sun, 26 Jan 2020 23:44:22 -0300
Subject: [PATCHv4] btrfs: Test subvolume delete --subvolid feature

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.

---
Changes from v3:
* Changes test 203 -> 207, since other tests were merged
* The first patch was merged, so remove it from sending again
[https://git.kernel.org/pub/scm/fs/xfs/xfstests-dev.git/commit/?id=2f9b4039253d3a6f91cb2a22639a243b5a27e110]

Changes from v2:
* Added Reviewed-by from Nikolay to patch 0001
* Changed awk to $AWK_PROG, suggested by Eryu
* Changed _run_btrfs_util_prog to $BTRFS_UTIL_PROG, suggested by Eryu
* Use _scratch_unmount instead of executing umount by hand, sugested by Eryu
* Created a local function to delete and list subvolumes, suggested by Eryu

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

 tests/btrfs/207     | 68 +++++++++++++++++++++++++++++++++++++++++++++
 tests/btrfs/207.out | 17 ++++++++++++
 tests/btrfs/group   |  1 +
 3 files changed, 86 insertions(+)
 create mode 100755 tests/btrfs/207
 create mode 100644 tests/btrfs/207.out
tests/btrfs/207 new file +68 -0
new file mode 100755
index 00000000..bec5baea
@@ -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. 207
+#
+# 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
tests/btrfs/207.out new file +17 -0
new file mode 100644
index 00000000..e3f7daa4
@@ -0,0 +1,17 @@
+QA output created by 207
+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.
tests/btrfs/group +1 -0
index e3ad347b..1acf6af7 100644
@@ -209,3 +209,4 @@
 204 auto quick punch
 205 auto quick clone compress
 204 auto quick log replay
+207 auto quick subvol
Signature · 1 line
2.25.0
#7 lore raw

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

Quoted 6 lines · Marcos Paulo de Souza
Quoted 5 lines · Eryu Guan
Quoted 3 lines · Marcos Paulo de Souza

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

Quoted 8 lines
Quoted 4 lines

Looks fine to me overall, but it'd be better to have commit message to describe the test.

Also, it'd be great if btrfs folks could help review it.

Indeed, a commit message makes things better. I'm attaching here a new version of the patch containing a commit message. This new version also bumps the test number from 203 -> 207, since other messages were merged after I sent my patch.

Thanks! Would you please send a formal patch to the list?

Quoted 3 lines

While adding the commit message I found in Josef's commit that he added a new btrfs test 206, but groups contained test 204[1]. Is it a typo?

Ah, it is, my bad. This is a merge error and easy enough to fix, I've fixed it in my local tree. Thanks for pointing it out!

Thanks,
Eryu

Quoted 285 lines

[1]: https://git.kernel.org/pub/scm/fs/xfs/xfstests-dev.git/commit/?id=1d6d14db1165db1ffc87fbddcf97eb70fdf84607

Quoted 126 lines

Thanks,
Eryu

Quoted 122 lines

---
Changes from v2:
* Added 'Created subvolume...' into 203.out to match the subvolume creating command
* Changed awk to $AWK_PROG, suggested by Eryu
* Changed _run_btrfs_util_prog to $BTRFS_UTIL_PROG, suggested by Eryu
* Use _scratch_unmount instead of executing umount by hand, sugested by Eryu
* Created a local function to delete and list subvolumes, suggested by Eryu

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     | 68 +++++++++++++++++++++++++++++++++++++++++++++
 tests/btrfs/203.out | 17 ++++++++++++
 tests/btrfs/group   |  1 +
 3 files changed, 86 insertions(+)
 create mode 100755 tests/btrfs/203
 create mode 100644 tests/btrfs/203.out
tests/btrfs/203 new file +68 -0
new file mode 100755
index 00000000..0f662db1
@@ -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. 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
+
+_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
tests/btrfs/203.out new file +17 -0
new file mode 100644
index 00000000..3301852b
@@ -0,0 +1,17 @@
+QA output created by 203
+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.
tests/btrfs/group +0 -0
index 79f85e97..e7744217 100644
Quoted 8 lines
Quoted 8 lines
tests/btrfs/group +1 -0
@@ -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.25.0

From 2541e8ef08d45030f97073ef1e5bc9196ef22e4d Mon Sep 17 00:00:00 2001
From: Marcos Paulo de Souza <[email protected]>
Date: Sun, 26 Jan 2020 23:44:22 -0300
Subject: [PATCHv4] btrfs: Test subvolume delete --subvolid feature

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.

---
Changes from v3:
* Changes test 203 -> 207, since other tests were merged
* The first patch was merged, so remove it from sending again
[https://git.kernel.org/pub/scm/fs/xfs/xfstests-dev.git/commit/?id=2f9b4039253d3a6f91cb2a22639a243b5a27e110]

Changes from v2:
* Added Reviewed-by from Nikolay to patch 0001
* Changed awk to $AWK_PROG, suggested by Eryu
* Changed _run_btrfs_util_prog to $BTRFS_UTIL_PROG, suggested by Eryu
* Use _scratch_unmount instead of executing umount by hand, sugested by Eryu
* Created a local function to delete and list subvolumes, suggested by Eryu

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

 tests/btrfs/207     | 68 +++++++++++++++++++++++++++++++++++++++++++++
 tests/btrfs/207.out | 17 ++++++++++++
 tests/btrfs/group   |  1 +
 3 files changed, 86 insertions(+)
 create mode 100755 tests/btrfs/207
 create mode 100644 tests/btrfs/207.out
tests/btrfs/207 new file +68 -0
new file mode 100755
index 00000000..bec5baea
@@ -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. 207
+#
+# 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
tests/btrfs/207.out new file +17 -0
new file mode 100644
index 00000000..e3f7daa4
@@ -0,0 +1,17 @@
+QA output created by 207
+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.
tests/btrfs/group +1 -0
index e3ad347b..1acf6af7 100644
@@ -209,3 +209,4 @@
 204 auto quick punch
 205 auto quick clone compress
 204 auto quick log replay
+207 auto quick subvol
Signature · 1 line
2.25.0
#8 lore raw

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

Quoted 16 lines · Eryu Guan
Quoted 6 lines · Marcos Paulo de Souza
Quoted 5 lines · Eryu Guan
Quoted 3 lines · Marcos Paulo de Souza

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

Quoted 8 lines
Quoted 4 lines

Looks fine to me overall, but it'd be better to have commit message to describe the test.

Also, it'd be great if btrfs folks could help review it.

Indeed, a commit message makes things better. I'm attaching here a new version of the patch containing a commit message. This new version also bumps the test number from 203 -> 207, since other messages were merged after I sent my patch.

Quoted 8 lines

Thanks! Would you please send a formal patch to the list?

Quoted 3 lines

While adding the commit message I found in Josef's commit that he added a new btrfs test 206, but groups contained test 204[1]. Is it a typo?

Ah, it is, my bad. This is a merge error and easy enough to fix, I've fixed it in my local tree. Thanks for pointing it out!

Then I noticed that Omar has fixed it in his new test.. Will drop my local fix.

Eryu