diff mbox series

btrfs-progs: cmds/scrub: using device's used_bytes to print summary for running scrubs

Message ID be6f1470add5193fcb435e7bbba875dc60a2a2ba.1697086519.git.wqu@suse.com (mailing list archive)
State New, archived
Headers show
Series btrfs-progs: cmds/scrub: using device's used_bytes to print summary for running scrubs | expand

Commit Message

Qu Wenruo Oct. 12, 2023, 4:55 a.m. UTC
[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 c88ac0170b35 ("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>
---
 cmds/scrub.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

Comments

David Sterba Oct. 12, 2023, 4:40 p.m. UTC | #1
On Thu, Oct 12, 2023 at 03:25:35PM +1030, Qu Wenruo wrote:
> [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 c88ac0170b35 ("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>

Added to devel, thanks.

> ---
>  cmds/scrub.c | 15 ++++++++++++++-
>  1 file changed, 14 insertions(+), 1 deletion(-)
> 
> diff --git a/cmds/scrub.c b/cmds/scrub.c
> index c45ab3dd2a31..247e056ac70d 100644
> --- a/cmds/scrub.c
> +++ b/cmds/scrub.c
> @@ -323,9 +323,22 @@ static void print_scrub_dev(struct btrfs_ioctl_dev_info_args *di,
>  	if (p) {
>  		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);

Please also use { } around single statement blocks but with a long
comment.

> +		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);
>  	}
>  }
>  
> -- 
> 2.42.0
diff mbox series

Patch

diff --git a/cmds/scrub.c b/cmds/scrub.c
index c45ab3dd2a31..247e056ac70d 100644
--- a/cmds/scrub.c
+++ b/cmds/scrub.c
@@ -323,9 +323,22 @@  static void print_scrub_dev(struct btrfs_ioctl_dev_info_args *di,
 	if (p) {
 		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);
 	}
 }