[PATCHv2,1/2] common: btrfs: Improve _require_btrfs_command
diff mbox series

Message ID 20200207131951.15859-2-marcos.souza.org@gmail.com
State New
Headers show
Series
  • btrfs: Test subvolume delete by id feature
Related show

Commit Message

Marcos Paulo de Souza Feb. 7, 2020, 1:19 p.m. UTC
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>
---

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(-)

Comments

Nikolay Borisov Feb. 7, 2020, 1:25 p.m. UTC | #1
On 7.02.20 г. 15:19 ч., Marcos Paulo de Souza wrote:
> 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>

Reviewed-by: Nikolay Borisov <nborisov@suse.com>

> ---
> 
> 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(-)
> 
> 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

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

> +
> +	# 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
>

Patch
diff mbox series

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