Skip to content

Commit c88ac01

Browse files
adam900710kdave
authored andcommitted
btrfs-progs: scrub: unify the output numbers for "Total to scrub"
[BUG] Command `btrfs scrub start -B` and `btrfs scrub status` are reporting very different results for "Total to scrub": $ 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 $ 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 This can be very confusing for end users. [CAUSE] It's the function print_fs_stat() handling the "Total to scrub" output. For `btrfs scrub start` command, we use the used bytes (aka, the total used dev extents of a device) for output. This is not really accurate, as the chunks may be mostly empty just like the following: $ 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 Thus we're reporting 1.5GiB to scrub (1.01GiB + 40MiB * 2 + 256MiB * 2). But in reality, we only scrubbed 12MiB (9.06MiB + 64KiB * 2 + 1.38MiB * 2). [FIX] Instead of using the used dev-extent bytes of a device, go with proper scrubbed bytes for each device. This involves print_fs_stat() and print_scrub_dev() called inside scrub_start(). Now the output should match each other. Issue: #636 Signed-off-by: Qu Wenruo <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent af6f301 commit c88ac01

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

cmds/scrub.c

+11-7
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,8 @@ static void print_scrub_dev(struct btrfs_ioctl_dev_info_args *di,
326326
if (raw)
327327
print_scrub_full(p);
328328
else
329-
print_scrub_summary(p, ss, di->bytes_used);
329+
print_scrub_summary(p, ss, p->data_bytes_scrubbed +
330+
p->tree_bytes_scrubbed);
330331
}
331332
}
332333

@@ -1540,28 +1541,31 @@ static int scrub_start(const struct cmd_struct *cmd, int argc, char **argv,
15401541

15411542
if (do_print) {
15421543
const char *append = "done";
1543-
u64 total_bytes_used = 0;
1544+
u64 total_bytes_scrubbed = 0;
15441545

15451546
if (!do_stats_per_dev)
15461547
init_fs_stat(&fs_stat);
15471548
for (i = 0; i < fi_args.num_devices; ++i) {
1549+
struct btrfs_scrub_progress *cur_progress =
1550+
&sp[i].scrub_args.progress;
1551+
15481552
if (do_stats_per_dev) {
15491553
print_scrub_dev(&di_args[i],
1550-
&sp[i].scrub_args.progress,
1554+
cur_progress,
15511555
print_raw,
15521556
sp[i].ret ? "canceled" : "done",
15531557
&sp[i].stats);
15541558
} else {
15551559
if (sp[i].ret)
15561560
append = "canceled";
1557-
add_to_fs_stat(&sp[i].scrub_args.progress,
1558-
&sp[i].stats, &fs_stat);
1561+
add_to_fs_stat(cur_progress, &sp[i].stats, &fs_stat);
15591562
}
1560-
total_bytes_used += di_args[i].bytes_used;
1563+
total_bytes_scrubbed += cur_progress->data_bytes_scrubbed +
1564+
cur_progress->tree_bytes_scrubbed;
15611565
}
15621566
if (!do_stats_per_dev) {
15631567
pr_verbose(LOG_DEFAULT, "scrub %s for %s\n", append, fsid);
1564-
print_fs_stat(&fs_stat, print_raw, total_bytes_used);
1568+
print_fs_stat(&fs_stat, print_raw, total_bytes_scrubbed);
15651569
}
15661570
}
15671571

0 commit comments

Comments
 (0)