btrfs-progs: balance: print warn mesg in old command
PATCH 1/1 btrfs-progs: balance: print warn mesg in old command
This patch makes old balance command to print warn mesg same as in start command. It makes a function that print warn mesg and commands use that function.
Issue: #411
--- cmds/balance.c | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-)
cmds/balance.c +22 -15
@@ -303,6 +303,25 @@ enum {BALANCE_START_NOWARN =1 <<1 }; +static void print_start_warn_mesg () +{ +int delay =10 ; + +printf ("WARNING:\n\n" ); +printf ("\tFull balance without filters requested. This operation is very\n" ); +printf ("\tintense and takes potentially very long. It is recommended to\n" ); +printf ("\tuse the balance filters to narrow down the scope of balance.\n" ); +printf ("\tUse 'btrfs balance start --full-balance' option to skip this\n" ); +printf ("\twarning. The operation will start in %d seconds.\n" , delay); +printf ("\tUse Ctrl-C to stop it.\n" ); +while (delay) { +printf ("%2d" , delay--); +fflush (stdout); +sleep (1 ); + } +printf ("\nStarting balance without any filters.\n" ); +} +static int do_balance (const char *path,struct btrfs_ioctl_balance_args *args,unsigned flags,bool enqueue) {
@@ -548,21 +567,7 @@ static int cmd_balance_start(const struct cmd_struct *cmd, }if (!(start_flags &BALANCE_START_FILTERS ) && !(start_flags &BALANCE_START_NOWARN )) { -int delay =10 ; - -printf ("WARNING:\n\n" ); -printf ("\tFull balance without filters requested. This operation is very\n" ); -printf ("\tintense and takes potentially very long. It is recommended to\n" ); -printf ("\tuse the balance filters to narrow down the scope of balance.\n" ); -printf ("\tUse 'btrfs balance start --full-balance' option to skip this\n" ); -printf ("\twarning. The operation will start in %d seconds.\n" , delay); -printf ("\tUse Ctrl-C to stop it.\n" ); -while (delay) { -printf ("%2d" , delay--); -fflush (stdout); -sleep (1 ); - } -printf ("\nStarting balance without any filters.\n" ); +print_start_warn_mesg (); }if (force)
@@ -886,6 +891,8 @@ static int cmd_balance(const struct cmd_struct *cmd, int argc, char **argv)memset (&args,0 ,sizeof (args)); args.flags |=BTRFS_BALANCE_TYPE_MASK ; +print_start_warn_mesg (); +/* No enqueueing supported for the obsolete syntax */ return do_balance (argv[1 ], &args,0 , false); }
Signature · 1 line
2.25.1
Quoted 7 lines · Sidong Yang
This patch makes old balance command to print warn mesg same as in start command. It makes a function that print warn mesg and commands use that function.
Issue: #411
Signed-off-by Sidong Yang <[email protected]>
The patch is indeed solving a problem, so good job.
But I found something weird which may worth some refactor before the fix.
cmds/balance.c enum { · line 303
Quoted 10 lines
--- cmds/balance.c | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-)cmds/balance.c +0
-0@@ -303,6 +303,25 @@ enum {BALANCE_START_NOWARN =1 <<1
We have such flag for do_balance(), but it only checks START_FILTERS, no check for START_NOWARN.
So can we handle it better for the warning in do_balance() other than cmd_balance_full() or cmd_balance_start()?
And fully utilize the START_NOWARN flags?
Thanks,
Qu
Quoted 57 lines
cmds/balance.c +22
-15}; +static void print_start_warn_mesg () +{ +int delay =10 ; + +printf ("WARNING:\n\n" ); +printf ("\tFull balance without filters requested. This operation is very\n" ); +printf ("\tintense and takes potentially very long. It is recommended to\n" ); +printf ("\tuse the balance filters to narrow down the scope of balance.\n" ); +printf ("\tUse 'btrfs balance start --full-balance' option to skip this\n" ); +printf ("\twarning. The operation will start in %d seconds.\n" , delay); +printf ("\tUse Ctrl-C to stop it.\n" ); +while (delay) { +printf ("%2d" , delay--); +fflush (stdout); +sleep (1 ); + } +printf ("\nStarting balance without any filters.\n" ); +} +static int do_balance (const char *path,struct btrfs_ioctl_balance_args *args,unsigned flags,bool enqueue) {@@ -548,21 +567,7 @@ static int cmd_balance_start(const struct cmd_struct *cmd, }if (!(start_flags &BALANCE_START_FILTERS ) && !(start_flags &BALANCE_START_NOWARN )) { -int delay =10 ; - -printf ("WARNING:\n\n" ); -printf ("\tFull balance without filters requested. This operation is very\n" ); -printf ("\tintense and takes potentially very long. It is recommended to\n" ); -printf ("\tuse the balance filters to narrow down the scope of balance.\n" ); -printf ("\tUse 'btrfs balance start --full-balance' option to skip this\n" ); -printf ("\twarning. The operation will start in %d seconds.\n" , delay); -printf ("\tUse Ctrl-C to stop it.\n" ); -while (delay) { -printf ("%2d" , delay--); -fflush (stdout); -sleep (1 ); - } -printf ("\nStarting balance without any filters.\n" ); +print_start_warn_mesg (); }if (force)@@ -886,6 +891,8 @@ static int cmd_balance(const struct cmd_struct *cmd, int argc, char **argv)memset (&args,0 ,sizeof (args)); args.flags |=BTRFS_BALANCE_TYPE_MASK ; +print_start_warn_mesg (); +/* No enqueueing supported for the obsolete syntax */ return do_balance (argv[1 ], &args,0 , false); }
Quoted 10 lines · Qu Wenruo
Quoted 7 lines · Sidong Yang
This patch makes old balance command to print warn mesg same as in start command. It makes a function that print warn mesg and commands use that function.
Issue: #411
Signed-off-by Sidong Yang <[email protected]>
Hi, Qu.
Thanks for review!
Quoted 9 lines
The patch is indeed solving a problem, so good job.
But I found something weird which may worth some refactor before the fix.
Quoted 4 lines
--- cmds/balance.c | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-)
Quoted 9 lines
cmds/balance.c enum { · line 303
Quoted 6 lines
cmds/balance.c +0
-0@@ -303,6 +303,25 @@ enum {BALANCE_START_NOWARN =1 <<1 We have such flag for
do_balance(), but it only checksSTART_FILTERS, no check forSTART_NOWARN.
Yes. I've checked do_balance() that it doesn't check START_NOWARN.
Quoted 3 lines
So can we handle it better for the warning in
do_balance()other thancmd_balance_full()orcmd_balance_start()?
Totally agree. It would be better that it prints warning message in do_balance(). Also it's a way to simplify the logic.
Quoted 2 lines
And fully utilize the
START_NOWARNflags?
I'll send you v2 soon.
Thanks,
Sidong
Quoted 61 lines
Thanks,
QuQuoted 57 lines
cmds/balance.c +22
-15}; +static void print_start_warn_mesg () +{ +int delay =10 ; + +printf ("WARNING:\n\n" ); +printf ("\tFull balance without filters requested. This operation is very\n" ); +printf ("\tintense and takes potentially very long. It is recommended to\n" ); +printf ("\tuse the balance filters to narrow down the scope of balance.\n" ); +printf ("\tUse 'btrfs balance start --full-balance' option to skip this\n" ); +printf ("\twarning. The operation will start in %d seconds.\n" , delay); +printf ("\tUse Ctrl-C to stop it.\n" ); +while (delay) { +printf ("%2d" , delay--); +fflush (stdout); +sleep (1 ); + } +printf ("\nStarting balance without any filters.\n" ); +} +static int do_balance (const char *path,struct btrfs_ioctl_balance_args *args,unsigned flags,bool enqueue) {@@ -548,21 +567,7 @@ static int cmd_balance_start(const struct cmd_struct *cmd, }if (!(start_flags &BALANCE_START_FILTERS ) && !(start_flags &BALANCE_START_NOWARN )) { -int delay =10 ; - -printf ("WARNING:\n\n" ); -printf ("\tFull balance without filters requested. This operation is very\n" ); -printf ("\tintense and takes potentially very long. It is recommended to\n" ); -printf ("\tuse the balance filters to narrow down the scope of balance.\n" ); -printf ("\tUse 'btrfs balance start --full-balance' option to skip this\n" ); -printf ("\twarning. The operation will start in %d seconds.\n" , delay); -printf ("\tUse Ctrl-C to stop it.\n" ); -while (delay) { -printf ("%2d" , delay--); -fflush (stdout); -sleep (1 ); - } -printf ("\nStarting balance without any filters.\n" ); +print_start_warn_mesg (); }if (force)@@ -886,6 +891,8 @@ static int cmd_balance(const struct cmd_struct *cmd, int argc, char **argv)memset (&args,0 ,sizeof (args)); args.flags |=BTRFS_BALANCE_TYPE_MASK ; +print_start_warn_mesg (); +/* No enqueueing supported for the obsolete syntax */ return do_balance (argv[1 ], &args,0 , false); }