Skip to content

Commit 165a339

Browse files
adam900710kdave
authored andcommitted
btrfs: scrub: fix incorrectly reported logical/physical address
[BUG] Scrub is not reporting the correct logical/physical address, it can be verified by the following script: # mkfs.btrfs -f $dev1 # mount $dev1 $mnt # xfs_io -f -c "pwrite -S 0xaa 0 128k" $mnt/file1 # umount $mnt # xfs_io -f -c "pwrite -S 0xff 13647872 4k" $dev1 # mount $dev1 $mnt # btrfs scrub start -fB $mnt # umount $mnt Note above 13647872 is the physical address for logical 13631488 + 4K. Scrub would report the following error: BTRFS error (device dm-2): unable to fixup (regular) error at logical 13631488 on dev /dev/mapper/test-scratch1 physical 13631488 BTRFS warning (device dm-2): checksum error at logical 13631488 on dev /dev/mapper/test-scratch1, physical 13631488, root 5, inode 257, offset 0, length 4096, links 1 (path: file1) On the other hand, "btrfs check --check-data-csum" is reporting the correct logical/physical address: Checking filesystem on /dev/test/scratch1 UUID: db2eb621-b09d-4f24-8199-da17dc7b3201 [5/7] checking csums against data mirror 1 bytenr 13647872 csum 0x13fec125 expected csum 0x656bd64e ERROR: errors found in csum tree [CAUSE] In the function scrub_stripe_report_errors(), we always use the stripe->logical and its physical address to print the error message, not taking the sector number into consideration at all. [FIX] Fix the error reporting function by calculating logical/physical with the sector number. Now the scrub report is correct: BTRFS error (device dm-2): unable to fixup (regular) error at logical 13647872 on dev /dev/mapper/test-scratch1 physical 13647872 BTRFS warning (device dm-2): checksum error at logical 13647872 on dev /dev/mapper/test-scratch1, physical 13647872, root 5, inode 257, offset 16384, length 4096, links 1 (path: file1) Fixes: 0096580 ("btrfs: scrub: introduce error reporting functionality for scrub_stripe") CC: stable@vger.kernel.org torvalds#6.4+ Reviewed-by: Anand Jain <anand.jain@oracle.com> Reviewed-by: Filipe Manana <fdmanana@suse.com> Signed-off-by: Qu Wenruo <wqu@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
1 parent f253a24 commit 165a339

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

fs/btrfs/scrub.c

+13-9
Original file line numberDiff line numberDiff line change
@@ -869,7 +869,7 @@ static void scrub_stripe_report_errors(struct scrub_ctx *sctx,
869869
DEFAULT_RATELIMIT_BURST);
870870
struct btrfs_fs_info *fs_info = sctx->fs_info;
871871
struct btrfs_device *dev = NULL;
872-
u64 physical = 0;
872+
u64 stripe_physical = stripe->physical;
873873
int nr_data_sectors = 0;
874874
int nr_meta_sectors = 0;
875875
int nr_nodatacsum_sectors = 0;
@@ -902,13 +902,17 @@ static void scrub_stripe_report_errors(struct scrub_ctx *sctx,
902902
*/
903903
if (ret < 0)
904904
goto skip;
905-
physical = bioc->stripes[stripe_index].physical;
905+
stripe_physical = bioc->stripes[stripe_index].physical;
906906
dev = bioc->stripes[stripe_index].dev;
907907
btrfs_put_bioc(bioc);
908908
}
909909

910910
skip:
911911
for_each_set_bit(sector_nr, &stripe->extent_sector_bitmap, stripe->nr_sectors) {
912+
const u64 logical = stripe->logical +
913+
(sector_nr << fs_info->sectorsize_bits);
914+
const u64 physical = stripe_physical +
915+
(sector_nr << fs_info->sectorsize_bits);
912916
bool repaired = false;
913917

914918
if (stripe->sectors[sector_nr].is_metadata) {
@@ -937,12 +941,12 @@ static void scrub_stripe_report_errors(struct scrub_ctx *sctx,
937941
if (dev) {
938942
btrfs_err_rl_in_rcu(fs_info,
939943
"fixed up error at logical %llu on dev %s physical %llu",
940-
stripe->logical, btrfs_dev_name(dev),
944+
logical, btrfs_dev_name(dev),
941945
physical);
942946
} else {
943947
btrfs_err_rl_in_rcu(fs_info,
944948
"fixed up error at logical %llu on mirror %u",
945-
stripe->logical, stripe->mirror_num);
949+
logical, stripe->mirror_num);
946950
}
947951
continue;
948952
}
@@ -951,26 +955,26 @@ static void scrub_stripe_report_errors(struct scrub_ctx *sctx,
951955
if (dev) {
952956
btrfs_err_rl_in_rcu(fs_info,
953957
"unable to fixup (regular) error at logical %llu on dev %s physical %llu",
954-
stripe->logical, btrfs_dev_name(dev),
958+
logical, btrfs_dev_name(dev),
955959
physical);
956960
} else {
957961
btrfs_err_rl_in_rcu(fs_info,
958962
"unable to fixup (regular) error at logical %llu on mirror %u",
959-
stripe->logical, stripe->mirror_num);
963+
logical, stripe->mirror_num);
960964
}
961965

962966
if (test_bit(sector_nr, &stripe->io_error_bitmap))
963967
if (__ratelimit(&rs) && dev)
964968
scrub_print_common_warning("i/o error", dev, false,
965-
stripe->logical, physical);
969+
logical, physical);
966970
if (test_bit(sector_nr, &stripe->csum_error_bitmap))
967971
if (__ratelimit(&rs) && dev)
968972
scrub_print_common_warning("checksum error", dev, false,
969-
stripe->logical, physical);
973+
logical, physical);
970974
if (test_bit(sector_nr, &stripe->meta_error_bitmap))
971975
if (__ratelimit(&rs) && dev)
972976
scrub_print_common_warning("header error", dev, false,
973-
stripe->logical, physical);
977+
logical, physical);
974978
}
975979

976980
spin_lock(&sctx->stat_lock);

0 commit comments

Comments
 (0)