diff mbox series

[v3] btrfs: zoned: use zone aware sb location for scrub

Message ID 4d3e8c5cd6ba3e178a1e820c318d96317ac12845.1709890038.git.jth@kernel.org (mailing list archive)
State New, archived
Headers show
Series [v3] btrfs: zoned: use zone aware sb location for scrub | expand

Commit Message

Johannes Thumshirn March 8, 2024, 9:28 a.m. UTC
At the moment scrub_supers() doesn't grab the super block's location via
the zoned device aware btrfs_sb_log_location() but via btrfs_sb_offset().

This leads to checksum errors on 'scrub' as we're not accessing the
correct location of the super block.

So use btrfs_sb_log_location() for getting the super blocks location on
scrub.

Reported-by: WA AM <waautomata@gmail.com>
Cc: Qu Wenru <wqu@suse.com>
Link: http://lore.kernel.org/linux-btrfs/CANU2Z0EvUzfYxczLgGUiREoMndE9WdQnbaawV5Fv5gNXptPUKw@mail.gmail.com
Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
---
Changes to v2:
- Handle -ENOENT return from btrfs_sb_log_location
Link to v2:
- https://lore.kernel.org/linux-btrfs/75f3da872a8c1094ef0f6ed93aac9bf774ef895b.1709554485.git.jth@kernel.org
Changes to v1:
- Increase super_errors
- Don't break out after 1st error
Link to v1:
- https://lore.kernel.org/linux-btrfs/933562c5bf37ad3e03f1a6b2ab5a9eb741ee0192.1709206779.git.johannes.thumshirn@wdc.com
---
 fs/btrfs/scrub.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

Comments

Qu Wenruo March 8, 2024, 9:30 a.m. UTC | #1
在 2024/3/8 19:58, Johannes Thumshirn 写道:
> At the moment scrub_supers() doesn't grab the super block's location via
> the zoned device aware btrfs_sb_log_location() but via btrfs_sb_offset().
>
> This leads to checksum errors on 'scrub' as we're not accessing the
> correct location of the super block.
>
> So use btrfs_sb_log_location() for getting the super blocks location on
> scrub.
>
> Reported-by: WA AM <waautomata@gmail.com>
> Cc: Qu Wenru <wqu@suse.com>
> Link: http://lore.kernel.org/linux-btrfs/CANU2Z0EvUzfYxczLgGUiREoMndE9WdQnbaawV5Fv5gNXptPUKw@mail.gmail.com
> Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>

Reviewed-by: Qu Wenruo <wqu@suse.com>

Thanks,
Qu
> ---
> Changes to v2:
> - Handle -ENOENT return from btrfs_sb_log_location
> Link to v2:
> - https://lore.kernel.org/linux-btrfs/75f3da872a8c1094ef0f6ed93aac9bf774ef895b.1709554485.git.jth@kernel.org
> Changes to v1:
> - Increase super_errors
> - Don't break out after 1st error
> Link to v1:
> - https://lore.kernel.org/linux-btrfs/933562c5bf37ad3e03f1a6b2ab5a9eb741ee0192.1709206779.git.johannes.thumshirn@wdc.com
> ---
>   fs/btrfs/scrub.c | 12 +++++++++++-
>   1 file changed, 11 insertions(+), 1 deletion(-)
>
> diff --git a/fs/btrfs/scrub.c b/fs/btrfs/scrub.c
> index c4bd0e60db59..fa25004ab04e 100644
> --- a/fs/btrfs/scrub.c
> +++ b/fs/btrfs/scrub.c
> @@ -2812,7 +2812,17 @@ static noinline_for_stack int scrub_supers(struct scrub_ctx *sctx,
>   		gen = btrfs_get_last_trans_committed(fs_info);
>
>   	for (i = 0; i < BTRFS_SUPER_MIRROR_MAX; i++) {
> -		bytenr = btrfs_sb_offset(i);
> +		ret = btrfs_sb_log_location(scrub_dev, i, 0, &bytenr);
> +		if (ret == -ENOENT)
> +			break;
> +
> +		if (ret) {
> +			spin_lock(&sctx->stat_lock);
> +			sctx->stat.super_errors++;
> +			spin_unlock(&sctx->stat_lock);
> +			continue;
> +		}
> +
>   		if (bytenr + BTRFS_SUPER_INFO_SIZE >
>   		    scrub_dev->commit_total_bytes)
>   			break;
David Sterba March 11, 2024, 6:41 p.m. UTC | #2
On Fri, Mar 08, 2024 at 10:28:44AM +0100, Johannes Thumshirn wrote:
> At the moment scrub_supers() doesn't grab the super block's location via
> the zoned device aware btrfs_sb_log_location() but via btrfs_sb_offset().
> 
> This leads to checksum errors on 'scrub' as we're not accessing the
> correct location of the super block.
> 
> So use btrfs_sb_log_location() for getting the super blocks location on
> scrub.
> 
> Reported-by: WA AM <waautomata@gmail.com>
> Cc: Qu Wenru <wqu@suse.com>
> Link: http://lore.kernel.org/linux-btrfs/CANU2Z0EvUzfYxczLgGUiREoMndE9WdQnbaawV5Fv5gNXptPUKw@mail.gmail.com
> Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>

Reviewed-by: David Sterba <dsterba@suse.com>
Naohiro Aota March 12, 2024, 1:22 a.m. UTC | #3
On Fri, Mar 08, 2024 at 10:28:44AM +0100, Johannes Thumshirn wrote:
> At the moment scrub_supers() doesn't grab the super block's location via
> the zoned device aware btrfs_sb_log_location() but via btrfs_sb_offset().
> 
> This leads to checksum errors on 'scrub' as we're not accessing the
> correct location of the super block.
> 
> So use btrfs_sb_log_location() for getting the super blocks location on
> scrub.
> 
> Reported-by: WA AM <waautomata@gmail.com>
> Cc: Qu Wenru <wqu@suse.com>
> Link: http://lore.kernel.org/linux-btrfs/CANU2Z0EvUzfYxczLgGUiREoMndE9WdQnbaawV5Fv5gNXptPUKw@mail.gmail.com
> Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
> ---
> Changes to v2:
> - Handle -ENOENT return from btrfs_sb_log_location
> Link to v2:
> - https://lore.kernel.org/linux-btrfs/75f3da872a8c1094ef0f6ed93aac9bf774ef895b.1709554485.git.jth@kernel.org
> Changes to v1:
> - Increase super_errors
> - Don't break out after 1st error
> Link to v1:
> - https://lore.kernel.org/linux-btrfs/933562c5bf37ad3e03f1a6b2ab5a9eb741ee0192.1709206779.git.johannes.thumshirn@wdc.com
> ---
>  fs/btrfs/scrub.c | 12 +++++++++++-
>  1 file changed, 11 insertions(+), 1 deletion(-)

Looks good,

Reviewed-by: Naohiro Aota <naohiro.aota@wdc.com>
diff mbox series

Patch

diff --git a/fs/btrfs/scrub.c b/fs/btrfs/scrub.c
index c4bd0e60db59..fa25004ab04e 100644
--- a/fs/btrfs/scrub.c
+++ b/fs/btrfs/scrub.c
@@ -2812,7 +2812,17 @@  static noinline_for_stack int scrub_supers(struct scrub_ctx *sctx,
 		gen = btrfs_get_last_trans_committed(fs_info);
 
 	for (i = 0; i < BTRFS_SUPER_MIRROR_MAX; i++) {
-		bytenr = btrfs_sb_offset(i);
+		ret = btrfs_sb_log_location(scrub_dev, i, 0, &bytenr);
+		if (ret == -ENOENT)
+			break;
+
+		if (ret) {
+			spin_lock(&sctx->stat_lock);
+			sctx->stat.super_errors++;
+			spin_unlock(&sctx->stat_lock);
+			continue;
+		}
+
 		if (bytenr + BTRFS_SUPER_INFO_SIZE >
 		    scrub_dev->commit_total_bytes)
 			break;