From 6f7151f4992bc2a22a4fb84e7536a8b3c709a771 Mon Sep 17 00:00:00 2001 From: Wang Yugui Date: Wed, 14 Sep 2022 13:58:46 +0800 Subject: [PATCH] btrfs-progs: balance: fix some cases wrongly parsed as old syntax Some cases of 'btrfs balance' are wrongly parsed as old syntax. $ 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 Signed-off-by: David Sterba --- cmds/balance.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/cmds/balance.c b/cmds/balance.c index c2be7260..13b762a7 100644 --- a/cmds/balance.c +++ b/cmds/balance.c @@ -865,8 +865,24 @@ 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 ' syntax */ + bool old_syntax = true; + + /* + * Exclude all valid subcommands from being potentially confused as path + * for the obsolete syntax: btrfs balance + */ + if (argc >= 2) { + for (int 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));