btrfs-progs: scrub status: improve Rate reporting for sub-second durations

Scrubs which complete in under one second may carry a duration rounded
down to zero. This subsequently results in a bytes_per_sec value of
zero, which corresponds to the Rate metric output, causing intermittent
tests/btrfs/282 failures.

This change ensures that Rate reflects any sub-second bytes processed.
Time left and ETA metrics are also affected by this change, in that they
increase to account for (sub-second) bytes_per_sec.

Reviewed-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Disseldorp <ddiss@suse.de>
Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
David Disseldorp 2023-12-08 00:56:47 +11:00 committed by David Sterba
parent 7f869161b7
commit b3b38751e9

View File

@ -159,7 +159,14 @@ static void print_scrub_summary(struct btrfs_scrub_progress *p, struct scrub_sta
time_t sec_eta;
bytes_scrubbed = p->data_bytes_scrubbed + p->tree_bytes_scrubbed;
if (s->duration > 0)
/*
* If duration is zero seconds (rounded down), then the Rate metric
* should still reflect the amount of bytes that have been processed
* in under a second.
*/
if (s->duration == 0)
bytes_per_sec = bytes_scrubbed;
else
bytes_per_sec = bytes_scrubbed / s->duration;
if (bytes_per_sec > 0)
sec_left = (bytes_total - bytes_scrubbed) / bytes_per_sec;