Message ID | 55061b90dd4fe3193ca9992ada5c6c79e8e9c32f.1710906371.git.wqu@suse.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | btrfs: scrub: refine the error messages output frequency | expand |
On Wed, Mar 20, 2024 at 3:55 AM Qu Wenruo <wqu@suse.com> wrote: > > The @stripe passed into scrub_stripe_report_errors() either has > stripe->dev and stripe->physical properly populated (regular data > stripes) or stripe->flags would have SCRUB_STRIPE_FLAG_NO_REPORT > (RAID56 P/Q stripes). > > Thus there is no need to go with btrfs_map_block() to get the > dev/physical. > > Just add an extra ASSERT() to make sure we get stripe->dev populated > correctly. > > Signed-off-by: Qu Wenruo <wqu@suse.com> Reviewed-by: Filipe Manana <fdmanana@suse.com> Looks good now, thanks. > --- > fs/btrfs/scrub.c | 54 +++++++----------------------------------------- > 1 file changed, 7 insertions(+), 47 deletions(-) > > diff --git a/fs/btrfs/scrub.c b/fs/btrfs/scrub.c > index a5a9fef2bdb2..ff952dd2b510 100644 > --- a/fs/btrfs/scrub.c > +++ b/fs/btrfs/scrub.c > @@ -863,7 +863,7 @@ static void scrub_stripe_report_errors(struct scrub_ctx *sctx, > static DEFINE_RATELIMIT_STATE(rs, DEFAULT_RATELIMIT_INTERVAL, > DEFAULT_RATELIMIT_BURST); > struct btrfs_fs_info *fs_info = sctx->fs_info; > - struct btrfs_device *dev = NULL; > + struct btrfs_device *dev = stripe->dev; > u64 stripe_physical = stripe->physical; > int nr_data_sectors = 0; > int nr_meta_sectors = 0; > @@ -874,35 +874,7 @@ static void scrub_stripe_report_errors(struct scrub_ctx *sctx, > if (test_bit(SCRUB_STRIPE_FLAG_NO_REPORT, &stripe->state)) > return; > > - /* > - * Init needed infos for error reporting. > - * > - * Although our scrub_stripe infrastructure is mostly based on btrfs_submit_bio() > - * thus no need for dev/physical, error reporting still needs dev and physical. > - */ > - if (!bitmap_empty(&stripe->init_error_bitmap, stripe->nr_sectors)) { > - u64 mapped_len = fs_info->sectorsize; > - struct btrfs_io_context *bioc = NULL; > - int stripe_index = stripe->mirror_num - 1; > - int ret; > - > - /* For scrub, our mirror_num should always start at 1. */ > - ASSERT(stripe->mirror_num >= 1); > - ret = btrfs_map_block(fs_info, BTRFS_MAP_GET_READ_MIRRORS, > - stripe->logical, &mapped_len, &bioc, > - NULL, NULL); > - /* > - * If we failed, dev will be NULL, and later detailed reports > - * will just be skipped. > - */ > - if (ret < 0) > - goto skip; > - stripe_physical = bioc->stripes[stripe_index].physical; > - dev = bioc->stripes[stripe_index].dev; > - btrfs_put_bioc(bioc); > - } > - > -skip: > + ASSERT(dev); > for_each_set_bit(sector_nr, &stripe->extent_sector_bitmap, stripe->nr_sectors) { > const u64 logical = stripe->logical + > (sector_nr << fs_info->sectorsize_bits); > @@ -933,41 +905,29 @@ static void scrub_stripe_report_errors(struct scrub_ctx *sctx, > * output the message of repaired message. > */ > if (repaired) { > - if (dev) { > - btrfs_err_rl_in_rcu(fs_info, > + btrfs_err_rl_in_rcu(fs_info, > "fixed up error at logical %llu on dev %s physical %llu", > logical, btrfs_dev_name(dev), > physical); > - } else { > - btrfs_err_rl_in_rcu(fs_info, > - "fixed up error at logical %llu on mirror %u", > - logical, stripe->mirror_num); > - } > continue; > } > > /* The remaining are all for unrepaired. */ > - if (dev) { > - btrfs_err_rl_in_rcu(fs_info, > + btrfs_err_rl_in_rcu(fs_info, > "unable to fixup (regular) error at logical %llu on dev %s physical %llu", > logical, btrfs_dev_name(dev), > physical); > - } else { > - btrfs_err_rl_in_rcu(fs_info, > - "unable to fixup (regular) error at logical %llu on mirror %u", > - logical, stripe->mirror_num); > - } > > if (test_bit(sector_nr, &stripe->io_error_bitmap)) > - if (__ratelimit(&rs) && dev) > + if (__ratelimit(&rs)) > scrub_print_common_warning("i/o error", dev, > logical, physical); > if (test_bit(sector_nr, &stripe->csum_error_bitmap)) > - if (__ratelimit(&rs) && dev) > + if (__ratelimit(&rs)) > scrub_print_common_warning("checksum error", dev, > logical, physical); > if (test_bit(sector_nr, &stripe->meta_error_bitmap)) > - if (__ratelimit(&rs) && dev) > + if (__ratelimit(&rs)) > scrub_print_common_warning("header error", dev, > logical, physical); > } > -- > 2.44.0 > >
diff --git a/fs/btrfs/scrub.c b/fs/btrfs/scrub.c index a5a9fef2bdb2..ff952dd2b510 100644 --- a/fs/btrfs/scrub.c +++ b/fs/btrfs/scrub.c @@ -863,7 +863,7 @@ static void scrub_stripe_report_errors(struct scrub_ctx *sctx, static DEFINE_RATELIMIT_STATE(rs, DEFAULT_RATELIMIT_INTERVAL, DEFAULT_RATELIMIT_BURST); struct btrfs_fs_info *fs_info = sctx->fs_info; - struct btrfs_device *dev = NULL; + struct btrfs_device *dev = stripe->dev; u64 stripe_physical = stripe->physical; int nr_data_sectors = 0; int nr_meta_sectors = 0; @@ -874,35 +874,7 @@ static void scrub_stripe_report_errors(struct scrub_ctx *sctx, if (test_bit(SCRUB_STRIPE_FLAG_NO_REPORT, &stripe->state)) return; - /* - * Init needed infos for error reporting. - * - * Although our scrub_stripe infrastructure is mostly based on btrfs_submit_bio() - * thus no need for dev/physical, error reporting still needs dev and physical. - */ - if (!bitmap_empty(&stripe->init_error_bitmap, stripe->nr_sectors)) { - u64 mapped_len = fs_info->sectorsize; - struct btrfs_io_context *bioc = NULL; - int stripe_index = stripe->mirror_num - 1; - int ret; - - /* For scrub, our mirror_num should always start at 1. */ - ASSERT(stripe->mirror_num >= 1); - ret = btrfs_map_block(fs_info, BTRFS_MAP_GET_READ_MIRRORS, - stripe->logical, &mapped_len, &bioc, - NULL, NULL); - /* - * If we failed, dev will be NULL, and later detailed reports - * will just be skipped. - */ - if (ret < 0) - goto skip; - stripe_physical = bioc->stripes[stripe_index].physical; - dev = bioc->stripes[stripe_index].dev; - btrfs_put_bioc(bioc); - } - -skip: + ASSERT(dev); for_each_set_bit(sector_nr, &stripe->extent_sector_bitmap, stripe->nr_sectors) { const u64 logical = stripe->logical + (sector_nr << fs_info->sectorsize_bits); @@ -933,41 +905,29 @@ static void scrub_stripe_report_errors(struct scrub_ctx *sctx, * output the message of repaired message. */ if (repaired) { - if (dev) { - btrfs_err_rl_in_rcu(fs_info, + btrfs_err_rl_in_rcu(fs_info, "fixed up error at logical %llu on dev %s physical %llu", logical, btrfs_dev_name(dev), physical); - } else { - btrfs_err_rl_in_rcu(fs_info, - "fixed up error at logical %llu on mirror %u", - logical, stripe->mirror_num); - } continue; } /* The remaining are all for unrepaired. */ - if (dev) { - btrfs_err_rl_in_rcu(fs_info, + btrfs_err_rl_in_rcu(fs_info, "unable to fixup (regular) error at logical %llu on dev %s physical %llu", logical, btrfs_dev_name(dev), physical); - } else { - btrfs_err_rl_in_rcu(fs_info, - "unable to fixup (regular) error at logical %llu on mirror %u", - logical, stripe->mirror_num); - } if (test_bit(sector_nr, &stripe->io_error_bitmap)) - if (__ratelimit(&rs) && dev) + if (__ratelimit(&rs)) scrub_print_common_warning("i/o error", dev, logical, physical); if (test_bit(sector_nr, &stripe->csum_error_bitmap)) - if (__ratelimit(&rs) && dev) + if (__ratelimit(&rs)) scrub_print_common_warning("checksum error", dev, logical, physical); if (test_bit(sector_nr, &stripe->meta_error_bitmap)) - if (__ratelimit(&rs) && dev) + if (__ratelimit(&rs)) scrub_print_common_warning("header error", dev, logical, physical); }
The @stripe passed into scrub_stripe_report_errors() either has stripe->dev and stripe->physical properly populated (regular data stripes) or stripe->flags would have SCRUB_STRIPE_FLAG_NO_REPORT (RAID56 P/Q stripes). Thus there is no need to go with btrfs_map_block() to get the dev/physical. Just add an extra ASSERT() to make sure we get stripe->dev populated correctly. Signed-off-by: Qu Wenruo <wqu@suse.com> --- fs/btrfs/scrub.c | 54 +++++++----------------------------------------- 1 file changed, 7 insertions(+), 47 deletions(-)