Skip to contentSkip to conversation

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

PATCH In review Wang Yugui 3 participants 6 messages Sep 14, 2022 – Mar 16, 2023 Btrfs file system

lore
Share & tools
lore

Wang Yugui

author
#0 lore raw

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

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.

---
 cmds/balance.c | 19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)
cmds/balance.c +17 -2
index c5e10f92..bafd1714 100644
@@ -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));
Signature · 1 line
2.36.2
#1 lore raw
Quoted 10 lines · 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.

The old code is over 10 years.

Can we just remove it completely?

Thanks,
Qu

Quoted 34 lines
---
  cmds/balance.c | 19 +++++++++++++++++--
  1 file changed, 17 insertions(+), 2 deletions(-)
cmds/balance.c +17 -2
index c5e10f92..bafd1714 100644
@@ -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 lore raw
Quoted 9 lines · Qu Wenruo
Quoted 6 lines · 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
Quoted 8 lines
Quoted 4 lines

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

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.

author
#3 lore raw

PATCH 1/1 btrfs-progs: balance: deprecate old syntax

In reply to Wang Yugui

deprecate btrfs blanace old syntax since new syntax is already introduced in 2012.

we will remove the old syntax completely in a few releases.

---
 cmds/balance.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
cmds/balance.c +3 -1
index d1e66d42..3cb6334a 100644
@@ -37,7 +37,7 @@
 
 static const char * const balance_cmd_group_usage[] = {
 	"btrfs balance <command> [options] <path>",
-	"btrfs balance <path>",
+	"btrfs balance <path>        deprecated by 'btrfs balance replace'",
 	NULL
 };
 
@@ -882,6 +882,8 @@ static int cmd_balance(const struct cmd_struct *cmd, int argc, char **argv)
 		/* old 'btrfs filesystem balance <path>' syntax */
 		struct btrfs_ioctl_balance_args args;
 
+		warning("deprecated by 'btrfs balance replace'");
+
 		memset(&args, 0, sizeof(args));
 		args.flags |= BTRFS_BALANCE_TYPE_MASK;
 
Signature · 1 line
2.36.2
author
#4 lore raw

PATCH v2 1/1 btrfs-progs: balance: deprecate old syntax

In reply to Wang Yugui

deprecate btrfs blanace old syntax since new syntax is already introduced in 2012.

we will remove the old syntax completely in a few releases.

---
changes since v1:

	fix typo(btrfs balance replace -> btrfs balance start)
 cmds/balance.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
cmds/balance.c +3 -1
index d1e66d42..3cb6334a 100644
@@ -37,7 +37,7 @@
 
 static const char * const balance_cmd_group_usage[] = {
 	"btrfs balance <command> [options] <path>",
-	"btrfs balance <path>",
+	"btrfs balance <path>        deprecated by 'btrfs balance start'",
 	NULL
 };
 
@@ -882,6 +882,8 @@ static int cmd_balance(const struct cmd_struct *cmd, int argc, char **argv)
 		/* old 'btrfs filesystem balance <path>' syntax */
 		struct btrfs_ioctl_balance_args args;
 
+		warning("deprecated by 'btrfs balance start'");
+
 		memset(&args, 0, sizeof(args));
 		args.flags |= BTRFS_BALANCE_TYPE_MASK;
 
Signature · 1 line
2.36.2
#5 lore raw
In reply to Wang Yugui
Quoted 10 lines · 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.

Added to devel with some minor updates, thanks.