From 7e0f506241edfea82b7741fb1a78d40116a11e0b Mon Sep 17 00:00:00 2001 From: David Sterba Date: Tue, 11 Feb 2025 23:44:31 +0100 Subject: [PATCH] btrfs-progs: scrub status: fix rate units There's a special case when scrub rate is printed, the device sizes and rate use different units. The size can be in terabytes while the rate can be in hundreds of megabytes (contemporary 10-20T disks, 250MB/s). The sizes use what is set on command line (or human readable by default), while the rate is always human readable with exception to the option --raw to provide a way to print the exact numbers without any conversions. This got broken in commit ec3c8428590e90 ("btrfs-progs: scrub status: with --si, show rate in metric units") that forced the command line mode to the rate as well. Instead of that we need to detect the SI/IEC mode and set it to the human readable format of rate. Signed-off-by: David Sterba --- cmds/scrub.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/cmds/scrub.c b/cmds/scrub.c index 23af1628..b1d2f731 100644 --- a/cmds/scrub.c +++ b/cmds/scrub.c @@ -204,9 +204,10 @@ static void print_scrub_summary(struct btrfs_scrub_progress *p, struct scrub_sta pr_verbose(LOG_DEFAULT, "Total to scrub: %s\n", pretty_size_mode(bytes_total, unit_mode)); } + /* * Rate and size units are disproportionate so they are affected only - * by --raw, otherwise it's human readable + * by --raw, otherwise it's human readable (respecting the SI or IEC mode). */ if (unit_mode == UNITS_RAW) { pr_verbose(LOG_DEFAULT, "Rate: %s/s", @@ -218,11 +219,16 @@ static void print_scrub_summary(struct btrfs_scrub_progress *p, struct scrub_sta pr_verbose(LOG_DEFAULT, " (some device limits set)"); pr_verbose(LOG_DEFAULT, "\n"); } else { + unsigned int mode = UNITS_HUMAN_DECIMAL; + + if (unit_mode & UNITS_BINARY) + mode = UNITS_HUMAN_BINARY; + pr_verbose(LOG_DEFAULT, "Rate: %s/s", - pretty_size_mode(bytes_per_sec, unit_mode)); + pretty_size_mode(bytes_per_sec, mode)); if (limit > 1) pr_verbose(LOG_DEFAULT, " (limit %s/s)", - pretty_size_mode(limit, unit_mode)); + pretty_size_mode(limit, mode)); else if (limit == 1) pr_verbose(LOG_DEFAULT, " (some device limits set)"); pr_verbose(LOG_DEFAULT, "\n");