diff mbox series

btrfs-progs: balance: fix some cases wrongly parsed as old syntax

Message ID 20220914055846.52008-1-wangyugui@e16-tech.com (mailing list archive)
State New, archived
Headers show
Series btrfs-progs: balance: fix some cases wrongly parsed as old syntax | expand

Commit Message

Wang Yugui Sept. 14, 2022, 5:58 a.m. UTC
Some cases of 'btrfs balance' are wrongly parsed as old syntax.

an example:
$ btrfs balance status
ERROR: cannot access 'status': No such file or directory

currently, only 'start' is successfully excluded in the check of old syntax.
fix it by adding others in the check of old syntax.

Signed-off-by: Wang Yugui <wangyugui@e16-tech.com>
---
 cmds/balance.c | 19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)

Comments

Qu Wenruo Sept. 14, 2022, 7:11 a.m. UTC | #1
On 2022/9/14 13:58, Wang Yugui wrote:
> Some cases of 'btrfs balance' are wrongly parsed as old syntax.
> 
> an example:
> $ btrfs balance status
> ERROR: cannot access 'status': No such file or directory
> 
> currently, only 'start' is successfully excluded in the check of old syntax.
> fix it by adding others in the check of old syntax.
> 
> Signed-off-by: Wang Yugui <wangyugui@e16-tech.com>

The old code is over 10 years.

Can we just remove it completely?

Thanks,
Qu
> ---
>   cmds/balance.c | 19 +++++++++++++++++--
>   1 file changed, 17 insertions(+), 2 deletions(-)
> 
> diff --git a/cmds/balance.c b/cmds/balance.c
> index c5e10f92..bafd1714 100644
> --- a/cmds/balance.c
> +++ b/cmds/balance.c
> @@ -852,8 +852,23 @@ static const struct cmd_group balance_cmd_group = {
>   
>   static int cmd_balance(const struct cmd_struct *cmd, int argc, char **argv)
>   {
> -	if (argc == 2 && strcmp("start", argv[1]) != 0) {
> -		/* old 'btrfs filesystem balance <path>' syntax */
> +	bool old_syntax = true; /* old 'btrfs balance <path>' syntax */
> +	if (argc >= 2)
> +	{
> +		int i;
> +		for (i = 0; balance_cmd_group.commands[i] != NULL; i++)
> +		{
> +			if (strcmp(argv[1], balance_cmd_group.commands[i]->token) == 0)
> +			{
> +				old_syntax = false;
> +				break;
> +			}
> +		}
> +	} else {
> +		old_syntax = false;
> +	}
> +	if (old_syntax)
> +	{
>   		struct btrfs_ioctl_balance_args args;
>   
>   		memset(&args, 0, sizeof(args));
David Sterba Sept. 21, 2022, 8:24 a.m. UTC | #2
On Wed, Sep 14, 2022 at 03:11:04PM +0800, Qu Wenruo wrote:
> 
> 
> On 2022/9/14 13:58, Wang Yugui wrote:
> > Some cases of 'btrfs balance' are wrongly parsed as old syntax.
> > 
> > an example:
> > $ btrfs balance status
> > ERROR: cannot access 'status': No such file or directory
> > 
> > currently, only 'start' is successfully excluded in the check of old syntax.
> > fix it by adding others in the check of old syntax.
> > 
> > Signed-off-by: Wang Yugui <wangyugui@e16-tech.com>
> 
> The old code is over 10 years.
> 
> Can we just remove it completely?

I hope everybody uses the new syntax so it's time to remove support for
the old one, but we should still leave some warning in place suggesting
what's the preferred way and then remove it completely in a few
releases.
David Sterba March 16, 2023, 3:47 p.m. UTC | #3
On Wed, Sep 14, 2022 at 01:58:46PM +0800, Wang Yugui wrote:
> Some cases of 'btrfs balance' are wrongly parsed as old syntax.
> 
> an example:
> $ btrfs balance status
> ERROR: cannot access 'status': No such file or directory
> 
> currently, only 'start' is successfully excluded in the check of old syntax.
> fix it by adding others in the check of old syntax.
> 
> Signed-off-by: Wang Yugui <wangyugui@e16-tech.com>

Added to devel with some minor updates, thanks.
diff mbox series

Patch

diff --git a/cmds/balance.c b/cmds/balance.c
index c5e10f92..bafd1714 100644
--- a/cmds/balance.c
+++ b/cmds/balance.c
@@ -852,8 +852,23 @@  static const struct cmd_group balance_cmd_group = {
 
 static int cmd_balance(const struct cmd_struct *cmd, int argc, char **argv)
 {
-	if (argc == 2 && strcmp("start", argv[1]) != 0) {
-		/* old 'btrfs filesystem balance <path>' syntax */
+	bool old_syntax = true; /* old 'btrfs balance <path>' syntax */
+	if (argc >= 2)
+	{
+		int i;
+		for (i = 0; balance_cmd_group.commands[i] != NULL; i++)
+		{
+			if (strcmp(argv[1], balance_cmd_group.commands[i]->token) == 0)
+			{
+				old_syntax = false;
+				break;
+			}
+		}
+	} else {
+		old_syntax = false;
+	}
+	if (old_syntax)
+	{
 		struct btrfs_ioctl_balance_args args;
 
 		memset(&args, 0, sizeof(args));