Skip to content

Commit 90c9ce8

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 84519cd commit 90c9ce8

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
@@ -870,7 +870,7 @@ static void scrub_stripe_report_errors(struct scrub_ctx *sctx,
870870
DEFAULT_RATELIMIT_BURST);
871871
struct btrfs_fs_info *fs_info = sctx->fs_info;
872872
struct btrfs_device *dev = NULL;
873-
u64 physical = 0;
873+
u64 stripe_physical = stripe->physical;
874874
int nr_data_sectors = 0;
875875
int nr_meta_sectors = 0;
876876
int nr_nodatacsum_sectors = 0;
@@ -903,13 +903,17 @@ static void scrub_stripe_report_errors(struct scrub_ctx *sctx,
903903
*/
904904
if (ret < 0)
905905
goto skip;
906-
physical = bioc->stripes[stripe_index].physical;
906+
stripe_physical = bioc->stripes[stripe_index].physical;
907907
dev = bioc->stripes[stripe_index].dev;
908908
btrfs_put_bioc(bioc);
909909
}
910910

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

915919
if (stripe->sectors[sector_nr].is_metadata) {
@@ -938,12 +942,12 @@ static void scrub_stripe_report_errors(struct scrub_ctx *sctx,
938942
if (dev) {
939943
btrfs_err_rl_in_rcu(fs_info,
940944
"fixed up error at logical %llu on dev %s physical %llu",
941-
stripe->logical, btrfs_dev_name(dev),
945+
logical, btrfs_dev_name(dev),
942946
physical);
943947
} else {
944948
btrfs_err_rl_in_rcu(fs_info,
945949
"fixed up error at logical %llu on mirror %u",
946-
stripe->logical, stripe->mirror_num);
950+
logical, stripe->mirror_num);
947951
}
948952
continue;
949953
}
@@ -952,26 +956,26 @@ static void scrub_stripe_report_errors(struct scrub_ctx *sctx,
952956
if (dev) {
953957
btrfs_err_rl_in_rcu(fs_info,
954958
"unable to fixup (regular) error at logical %llu on dev %s physical %llu",
955-
stripe->logical, btrfs_dev_name(dev),
959+
logical, btrfs_dev_name(dev),
956960
physical);
957961
} else {
958962
btrfs_err_rl_in_rcu(fs_info,
959963
"unable to fixup (regular) error at logical %llu on mirror %u",
960-
stripe->logical, stripe->mirror_num);
964+
logical, stripe->mirror_num);
961965
}
962966

963967
if (test_bit(sector_nr, &stripe->io_error_bitmap))
964968
if (__ratelimit(&rs) && dev)
965969
scrub_print_common_warning("i/o error", dev, false,
966-
stripe->logical, physical);
970+
logical, physical);
967971
if (test_bit(sector_nr, &stripe->csum_error_bitmap))
968972
if (__ratelimit(&rs) && dev)
969973
scrub_print_common_warning("checksum error", dev, false,
970-
stripe->logical, physical);
974+
logical, physical);
971975
if (test_bit(sector_nr, &stripe->meta_error_bitmap))
972976
if (__ratelimit(&rs) && dev)
973977
scrub_print_common_warning("header error", dev, false,
974-
stripe->logical, physical);
978+
logical, physical);
975979
}
976980

977981
spin_lock(&sctx->stat_lock);

0 commit comments

Comments
 (0)