btrfs-progs: scrub: use device's used_bytes to print summary for running scrubs

[BUG]
For running scrubs, with v6.3 and newer btrfs-progs, it can report
incorrect "Total to scrub":

  Scrub resumed:    Mon Oct  9 11:28:33 2023
  Status:           running
  Duration:         0:44:36
  Time left:        0:00:00
  ETA:              Mon Oct  9 11:51:38 2023
  Total to scrub:   625.49GiB
  Bytes scrubbed:   625.49GiB  (100.00%)
  Rate:             239.35MiB/s
  Error summary:    no errors found

[CAUSE]
Commit c88ac0170b ("btrfs-progs: scrub: unify the output numbers for
"Total to scrub"") changed the output method for "Total to scrub", but
that value is only suitable for finished scrubs.

For running scrubs, if we use the currently scrubbed values, it would
lead to the above problem.

The real scrubbed bytes is only reliable for finished scrubs, not for
running/canceled/interrupted ones.

[FIX]
Change print_scrub_dev() to do extra checks, and only for finished
scrubs to use the scrubbed bytes.
Otherwise fall back to the device's bytes_used.

Issue: #690
Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
Qu Wenruo 2023-10-12 15:25:35 +10:30 committed by David Sterba
parent 4f5a455d1b
commit 660dd1ed71

View file

@ -321,11 +321,24 @@ static void print_scrub_dev(struct btrfs_ioctl_dev_info_args *di,
_print_scrub_ss(ss);
if (p) {
if (raw)
if (raw) {
print_scrub_full(p);
else
} else if (ss->finished) {
/*
* For finished scrub, we can use the total scrubbed
* bytes to report "Total to scrub", which is more
* accurate (e.g. mostly empty block groups).
*/
print_scrub_summary(p, ss, p->data_bytes_scrubbed +
p->tree_bytes_scrubbed);
} else {
/*
* For any canceled/interrupted/running scrub, we're
* not sure how many bytes we're really going to scrub,
* thus we use device's used bytes instead.
*/
print_scrub_summary(p, ss, di->bytes_used);
}
}
}