* [PATCH] btrfs-progs: balance: print warn mesg in old command
@ 2021-10-31 2:21 Sidong Yang
2021-10-31 11:28 ` Qu Wenruo
0 siblings, 1 reply; 3+ messages in thread
From: Sidong Yang @ 2021-10-31 2:21 UTC (permalink / raw)
To: linux-btrfs; +Cc: 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 <realwakka@gmail.com>
---
cmds/balance.c | 37 ++++++++++++++++++++++---------------
1 file changed, 22 insertions(+), 15 deletions(-)
diff --git a/cmds/balance.c b/cmds/balance.c
index 7abc69d9..8d8db8a2 100644
--- a/cmds/balance.c
+++ b/cmds/balance.c
@@ -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);
}
--
2.25.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] btrfs-progs: balance: print warn mesg in old command
2021-10-31 2:21 [PATCH] btrfs-progs: balance: print warn mesg in old command Sidong Yang
@ 2021-10-31 11:28 ` Qu Wenruo
2021-10-31 12:55 ` Sidong Yang
0 siblings, 1 reply; 3+ messages in thread
From: Qu Wenruo @ 2021-10-31 11:28 UTC (permalink / raw)
To: Sidong Yang, linux-btrfs
On 2021/10/31 10:21, Sidong Yang wrote:
> 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 <realwakka@gmail.com>
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 | 37 ++++++++++++++++++++++---------------
> 1 file changed, 22 insertions(+), 15 deletions(-)
>
> diff --git a/cmds/balance.c b/cmds/balance.c
> index 7abc69d9..8d8db8a2 100644
> --- a/cmds/balance.c
> +++ b/cmds/balance.c
> @@ -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
> };
>
> +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);
> }
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] btrfs-progs: balance: print warn mesg in old command
2021-10-31 11:28 ` Qu Wenruo
@ 2021-10-31 12:55 ` Sidong Yang
0 siblings, 0 replies; 3+ messages in thread
From: Sidong Yang @ 2021-10-31 12:55 UTC (permalink / raw)
To: Qu Wenruo; +Cc: linux-btrfs
On Sun, Oct 31, 2021 at 07:28:17PM +0800, Qu Wenruo wrote:
>
>
> On 2021/10/31 10:21, Sidong Yang wrote:
> > 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 <realwakka@gmail.com>
Hi, Qu.
Thanks for review!
>
> 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 | 37 ++++++++++++++++++++++---------------
> > 1 file changed, 22 insertions(+), 15 deletions(-)
> >
> > diff --git a/cmds/balance.c b/cmds/balance.c
> > index 7abc69d9..8d8db8a2 100644
> > --- a/cmds/balance.c
> > +++ b/cmds/balance.c
> > @@ -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.
Yes. I've checked do_balance() that it doesn't check START_NOWARN.
>
> So can we handle it better for the warning in do_balance() other than
> cmd_balance_full() or cmd_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.
>
> And fully utilize the START_NOWARN flags?
I'll send you v2 soon.
Thanks,
Sidong
>
> Thanks,
> Qu
>
> > };
> >
> > +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);
> > }
> >
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-10-31 13:01 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-31 2:21 [PATCH] btrfs-progs: balance: print warn mesg in old command Sidong Yang
2021-10-31 11:28 ` Qu Wenruo
2021-10-31 12:55 ` Sidong Yang
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.