All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] common: btrfs: Improve _require_btrfs_command
@ 2020-01-27  2:50 Marcos Paulo de Souza
  2020-01-27  2:50 ` [PATCH 2/2] btrfs: Test subvolume delete --subvolid feature Marcos Paulo de Souza
  0 siblings, 1 reply; 2+ messages in thread
From: Marcos Paulo de Souza @ 2020-01-27  2:50 UTC (permalink / raw)
  Cc: dsterba, josef, linux-btrfs, Marcos Paulo de Souza

From: Marcos Paulo de Souza <mpdesouza@suse.com>

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

Signed-off-by: Marcos Paulo de Souza <mpdesouza@suse.com>
---
 common/btrfs | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/common/btrfs b/common/btrfs
index 19ac7cc4..ae3142b6 100644
--- a/common/btrfs
+++ b/common/btrfs
@@ -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
-- 
2.24.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* [PATCH 2/2]  btrfs: Test subvolume delete --subvolid feature
  2020-01-27  2:50 [PATCH 1/2] common: btrfs: Improve _require_btrfs_command Marcos Paulo de Souza
@ 2020-01-27  2:50 ` Marcos Paulo de Souza
  0 siblings, 0 replies; 2+ messages in thread
From: Marcos Paulo de Souza @ 2020-01-27  2:50 UTC (permalink / raw)
  Cc: dsterba, josef, linux-btrfs, Marcos Paulo de Souza

From: Marcos Paulo de Souza <mpdesouza@suse.com>

Signed-off-by: Marcos Paulo de Souza <mpdesouza@suse.com>
---
 tests/btrfs/203     | 70 +++++++++++++++++++++++++++++++++++++++++++++
 tests/btrfs/203.out | 14 +++++++++
 tests/btrfs/group   |  1 +
 3 files changed, 85 insertions(+)
 create mode 100755 tests/btrfs/203
 create mode 100644 tests/btrfs/203.out

diff --git a/tests/btrfs/203 b/tests/btrfs/203
new file mode 100755
index 00000000..1765a963
--- /dev/null
+++ b/tests/btrfs/203
@@ -0,0 +1,70 @@
+#! /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 $2}'
+
+# Delete the subvolume subvol1 using it's subvolume id
+$BTRFS_UTIL_PROG subvolume delete --subvolid 256  $SCRATCH_MNT | _filter_scratch
+
+echo "After deleting one subvolume:"
+# should present only two subvolumes
+$BTRFS_UTIL_PROG subvolume list $SCRATCH_MNT | awk '{print $2}'
+
+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
+$BTRFS_UTIL_PROG subvolume delete --subvolid 259 $SCRATCH_MNT | _filter_scratch
+
+echo "Last remaining subvolume:"
+$BTRFS_UTIL_PROG subvolume list $SCRATCH_MNT | awk '{print $2}'
+
+umount $SCRATCH_MNT
+
+# now mount the rootfs
+_scratch_mount
+
+# Delete the subvol2
+$BTRFS_UTIL_PROG subvolume delete --subvolid 258  $SCRATCH_MNT | _filter_scratch
+
+echo "All subvolumes removed."
+$BTRFS_UTIL_PROG subvolume list $SCRATCH_MNT | awk '{print $2}'
+
+umount $SCRATCH_MNT
+
+# success, all done
+status=0
+exit
diff --git a/tests/btrfs/203.out b/tests/btrfs/203.out
new file mode 100644
index 00000000..d014a4ad
--- /dev/null
+++ b/tests/btrfs/203.out
@@ -0,0 +1,14 @@
+QA output created by 203
+Current subvolume ids:
+256
+258
+259
+Delete subvolume (no-commit): 'SCRATCH_MNT/subvol1'
+After deleting one subvolume:
+258
+259
+Delete subvolume (no-commit): 'SCRATCH_MNT/subvol3'
+Last remaining subvolume:
+258
+Delete subvolume (no-commit): 'SCRATCH_MNT/subvol2'
+All subvolumes removed.
diff --git a/tests/btrfs/group b/tests/btrfs/group
index 4b64bf8b..6b48b0c7 100644
--- a/tests/btrfs/group
+++ b/tests/btrfs/group
@@ -204,3 +204,4 @@
 200 auto quick send clone
 201 auto quick punch log
 202 auto quick subvol snapshot
+203 auto quick subvol
-- 
2.24.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-01-27  2:47 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-27  2:50 [PATCH 1/2] common: btrfs: Improve _require_btrfs_command Marcos Paulo de Souza
2020-01-27  2:50 ` [PATCH 2/2] btrfs: Test subvolume delete --subvolid feature Marcos Paulo de Souza

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.