public inbox for linux-btrfs@vger.kernel.org
 help / color / mirror / Atom feed
From: David Sterba <dsterba@suse.cz>
To: Racz Zoltan <racz.zoli@gmail.com>
Cc: linux-btrfs@vger.kernel.org
Subject: Re: [PATCH 1/2] Removed redundant if/else statement
Date: Tue, 11 Feb 2025 20:14:57 +0100	[thread overview]
Message-ID: <20250211191457.GU5777@suse.cz> (raw)
In-Reply-To: <20250207023302.311829-2-racz.zoli@gmail.com>

On Fri, Feb 07, 2025 at 04:33:01AM +0200, Racz Zoltan wrote:
> Removed unnecesary if/else statement in the print_scrub_summary
> function. If unit_mode == UNITS_RAW, bytes_per_sec and limit get converted to
> UNITS_RAW, otherwise to unit_mode, but in both cases the exact same message is 
> written to the output
> 
>  cmds/scrub.c | 28 +++++++++-------------------
>  1 file changed, 9 insertions(+), 19 deletions(-)
> 
> diff --git a/cmds/scrub.c b/cmds/scrub.c
> index b2cdc924..3507c9d8 100644
> --- a/cmds/scrub.c
> +++ b/cmds/scrub.c
> @@ -207,25 +207,15 @@ static void print_scrub_summary(struct btrfs_scrub_progress *p, struct scrub_sta
>  	 * Rate and size units are disproportionate so they are affected only
>  	 * by --raw, otherwise it's human readable
>  	 */
> -	if (unit_mode == UNITS_RAW) {
> -		pr_verbose(LOG_DEFAULT, "Rate:             %s/s",
> -			pretty_size_mode(bytes_per_sec, UNITS_RAW));
> -		if (limit > 1)
> -			pr_verbose(LOG_DEFAULT, " (limit %s/s)",
> -				   pretty_size_mode(limit, UNITS_RAW));
> -		else if (limit == 1)
> -			pr_verbose(LOG_DEFAULT, " (some device limits set)");
> -		pr_verbose(LOG_DEFAULT, "\n");
> -	} else {
> -		pr_verbose(LOG_DEFAULT, "Rate:             %s/s",
> -			pretty_size_mode(bytes_per_sec, unit_mode));
> -		if (limit > 1)
> -			pr_verbose(LOG_DEFAULT, " (limit %s/s)",
> -				   pretty_size_mode(limit, unit_mode));
> -		else if (limit == 1)
> -			pr_verbose(LOG_DEFAULT, " (some device limits set)");
> -		pr_verbose(LOG_DEFAULT, "\n");
> -	}
> +	
> +	pr_verbose(LOG_DEFAULT, "Rate:             %s/s",
> +		pretty_size_mode(bytes_per_sec, unit_mode));
> +	if (limit > 1)
> +		pr_verbose(LOG_DEFAULT, " (limit %s/s)",
> +			pretty_size_mode(limit, unit_mode));
> +	else if (limit == 1)
> +		pr_verbose(LOG_DEFAULT, " (some device limits set)");
> +	pr_verbose(LOG_DEFAULT, "\n");

It's true that the branch is redundant and it's been like since the
first commit d60d48fce5d32a ("btrfs-progs: scrub status: add unit mode
options") where I added. The idea is to separate the other size options
from the rate, e.g. a 20TB sized device may not give more than 200MB/s
of rate and selecting --tbytes as size option will print number like
0.000MB/s

How it works now:

$ sudo btrfs scrub status /data
...
Total to scrub:   5.14TiB
Bytes scrubbed:   7.08GiB  (0.13%)
Rate:             207.07MiB/s
...


$ sudo btrfs scrub status --tbytes /data
...
Total to scrub:   5.14TiB
Bytes scrubbed:   0.00TiB  (0.09%)
Rate:             0.00TiB/s
...

but scrub is still running so the Rate is really not 0. The point is to
print sensible numbers for Rate regardless of the other options but with
the exception of --raw that will always print the raw numbers.

Digging in the log it seems it got broken in ec3c8428590e90
("btrfs-progs: scrub status: with --si, show rate in metric units"), the
fix should have been to add the SI modifier to the units, not forcing
the unit_mode from the command line.

  reply	other threads:[~2025-02-11 19:15 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-07  2:33 [PATCH 0/2] btrfs-progs: scrub status: add json output format Racz Zoltan
2025-02-07  2:33 ` [PATCH 1/2] Removed redundant if/else statement Racz Zoltan
2025-02-11 19:14   ` David Sterba [this message]
2025-02-11 19:31     ` Racz Zoli
2025-02-11 23:42       ` David Sterba
2025-02-13 19:49         ` Racz Zoli
2025-02-07  2:33 ` [PATCH 2/2] scrub status: add json output format Racz Zoltan
2025-02-11 19:41   ` David Sterba
2025-02-11 23:37     ` Racz Zoli

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250211191457.GU5777@suse.cz \
    --to=dsterba@suse.cz \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=racz.zoli@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox