public inbox for linux-btrfs@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] btrfs-progs: balance: fix some cases wrongly parsed as old syntax
@ 2022-09-14  5:58 Wang Yugui
  2022-09-14  7:11 ` Qu Wenruo
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Wang Yugui @ 2022-09-14  5:58 UTC (permalink / raw)
  To: linux-btrfs; +Cc: Wang Yugui

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

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));
-- 
2.36.2


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

end of thread, other threads:[~2023-03-16 15:53 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-09-14  5:58 [PATCH] btrfs-progs: balance: fix some cases wrongly parsed as old syntax Wang Yugui
2022-09-14  7:11 ` Qu Wenruo
2022-09-21  8:24   ` David Sterba
2022-09-21 15:34 ` [PATCH] btrfs-progs: balance: deprecate " Wang Yugui
2022-09-21 21:54 ` [PATCH v2] " Wang Yugui
2023-03-16 15:47 ` [PATCH] btrfs-progs: balance: fix some cases wrongly parsed as " David Sterba

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox