kdave / btrfs-progs

Development of userspace BTRFS tools
GNU General Public License v2.0
550 stars 241 forks source link

Scrub: wrong value `Total to scrub` in the final report #636

Closed ConsoleXXVII closed 1 year ago

ConsoleXXVII commented 1 year ago

The final report given by the command btrfs scrub start -B /mount_point does show a wrong value in the field Total to scrub:. Using btrfs scrub status /mount_point does report the correct value.

Exemple:

$ sudo btrfs scrub start -B /srv/backup-disk
Scrub started:    Sun Jun  4 18:00:50 2023
Status:           finished
Duration:         0:25:57
Total to scrub:   248.02GiB    # Wrong value
Rate:             92.91MiB/s
Error summary:    no errors found

$ sudo btrfs scrub status /srv/backup-disk
Scrub started:    Sun Jun  4 18:00:50 2023
Status:           finished
Duration:         0:25:57
Total to scrub:   141.27GiB  # Correct value
Rate:             92.91MiB/s
Error summary:    no errors found

System (RaspberryPi OS, arm64):

$ uname -a
Linux hostname 6.1.21-v8+ #1642 SMP PREEMPT Mon Apr  3 17:24:16 BST 2023 aarch64 GNU/Linux

$ btrfs version
btrfs-progs v6.2 

This bug also exist in the kernel 5.15 arm64, with btrfs-progs 5.10.

adam900710 commented 1 year ago

I can confirm the problem is hardware independent, and it looks more like a bug of how everything is interpreted.

For btrfs scrub start it reports the last physical location it scrubbed. This includes all the unused space. While for btrfs scrub status it reports the real sectors scrubbed, which excludes all the unused space.

This means for a filesystem like the following:

$ sudo btrfs fi df /mnt/btrfs/
Data, single: total=1.01GiB, used=9.06MiB
System, DUP: total=40.00MiB, used=64.00KiB
Metadata, DUP: total=256.00MiB, used=1.38MiB
GlobalReserve, single: total=22.00MiB, used=0.00B

The btrfs scrub start -B would report something like 1.01GiB + 40MiB * 2 + 256MiB * 2, which is around 1.5GiB:

$ sudo btrfs scrub start -B /mnt/btrfs/
scrub done for c107ef62-0a5d-4fd7-a119-b88f38b8e084
Scrub started:    Mon Jun  5 07:54:07 2023
Status:           finished
Duration:         0:00:00
Total to scrub:   1.52GiB
Rate:             0.00B/s
Error summary:    no errors found

But for btrfs scrub status it would only report 9.06MiB + 64KiB * 2 + 1.38MiB *2, which is just 10MiB strong:

$ sudo btrfs scrub status /mnt/btrfs/
UUID:             c107ef62-0a5d-4fd7-a119-b88f38b8e084
Scrub started:    Mon Jun  5 07:54:07 2023
Status:           finished
Duration:         0:00:00
Total to scrub:   12.00MiB
Rate:             0.00B/s
Error summary:    no errors found

I believe we need to update the progs to unify the output, mostly to follow the scrub status output.

kdave commented 1 year ago

Fix added to devel, thanks.

ConsoleXXVII commented 1 year ago

Thanks