All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] btrfs: zoned: fix full zone SB reading on ZNS
@ 2023-05-09 18:29 Naohiro Aota
  2023-05-09 21:10 ` Johannes Thumshirn
  2023-05-09 22:27 ` David Sterba
  0 siblings, 2 replies; 3+ messages in thread
From: Naohiro Aota @ 2023-05-09 18:29 UTC (permalink / raw)
  To: linux-btrfs; +Cc: Naohiro Aota

When both of the superblock zones are full, we need to check which
superblock is newer. The calculation of last superblock position is wrong
as it does not consider zone_capacity. Fix it.

Fixes: 9658b72ef300 ("btrfs: zoned: locate superblock position using zone capacity")
CC: stable@vger.kernel.org # 6.1+
Signed-off-by: Naohiro Aota <naohiro.aota@wdc.com>
---
 fs/btrfs/zoned.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/fs/btrfs/zoned.c b/fs/btrfs/zoned.c
index e3fe02aae641..cd1fee22998c 100644
--- a/fs/btrfs/zoned.c
+++ b/fs/btrfs/zoned.c
@@ -122,10 +122,9 @@ static int sb_write_pointer(struct block_device *bdev, struct blk_zone *zones,
 		int i;
 
 		for (i = 0; i < BTRFS_NR_SB_LOG_ZONES; i++) {
-			u64 bytenr;
-
-			bytenr = ((zones[i].start + zones[i].len)
-				   << SECTOR_SHIFT) - BTRFS_SUPER_INFO_SIZE;
+			u64 zone_end = (zones[i].start + zones[i].capacity) << SECTOR_SHIFT;
+			u64 bytenr = ALIGN_DOWN(zone_end, BTRFS_SUPER_INFO_SIZE) -
+				BTRFS_SUPER_INFO_SIZE;
 
 			page[i] = read_cache_page_gfp(mapping,
 					bytenr >> PAGE_SHIFT, GFP_NOFS);
-- 
2.40.1

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] btrfs: zoned: fix full zone SB reading on ZNS
  2023-05-09 18:29 [PATCH] btrfs: zoned: fix full zone SB reading on ZNS Naohiro Aota
@ 2023-05-09 21:10 ` Johannes Thumshirn
  2023-05-09 22:27 ` David Sterba
  1 sibling, 0 replies; 3+ messages in thread
From: Johannes Thumshirn @ 2023-05-09 21:10 UTC (permalink / raw)
  To: Naohiro Aota, linux-btrfs

Looks good,
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] btrfs: zoned: fix full zone SB reading on ZNS
  2023-05-09 18:29 [PATCH] btrfs: zoned: fix full zone SB reading on ZNS Naohiro Aota
  2023-05-09 21:10 ` Johannes Thumshirn
@ 2023-05-09 22:27 ` David Sterba
  1 sibling, 0 replies; 3+ messages in thread
From: David Sterba @ 2023-05-09 22:27 UTC (permalink / raw)
  To: Naohiro Aota; +Cc: linux-btrfs

On Tue, May 09, 2023 at 06:29:15PM +0000, Naohiro Aota wrote:
> When both of the superblock zones are full, we need to check which
> superblock is newer. The calculation of last superblock position is wrong
> as it does not consider zone_capacity. Fix it.
> 
> Fixes: 9658b72ef300 ("btrfs: zoned: locate superblock position using zone capacity")
> CC: stable@vger.kernel.org # 6.1+
> Signed-off-by: Naohiro Aota <naohiro.aota@wdc.com>

Added to misc-next, thanks.

> ---
>  fs/btrfs/zoned.c | 7 +++----
>  1 file changed, 3 insertions(+), 4 deletions(-)
> 
> diff --git a/fs/btrfs/zoned.c b/fs/btrfs/zoned.c
> index e3fe02aae641..cd1fee22998c 100644
> --- a/fs/btrfs/zoned.c
> +++ b/fs/btrfs/zoned.c
> @@ -122,10 +122,9 @@ static int sb_write_pointer(struct block_device *bdev, struct blk_zone *zones,
>  		int i;
>  
>  		for (i = 0; i < BTRFS_NR_SB_LOG_ZONES; i++) {
> -			u64 bytenr;
> -
> -			bytenr = ((zones[i].start + zones[i].len)
> -				   << SECTOR_SHIFT) - BTRFS_SUPER_INFO_SIZE;
> +			u64 zone_end = (zones[i].start + zones[i].capacity) << SECTOR_SHIFT;
> +			u64 bytenr = ALIGN_DOWN(zone_end, BTRFS_SUPER_INFO_SIZE) -
> +				BTRFS_SUPER_INFO_SIZE;

I did a quick grep for 'zone.*len' as a wide search for potential
candidates of the same pattern but haven't spotted anything obvious.
With the ZNS support it may be useful to have a helper to read the zone
end in case the real blocks need to be considered, like here.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-05-09 22:33 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-09 18:29 [PATCH] btrfs: zoned: fix full zone SB reading on ZNS Naohiro Aota
2023-05-09 21:10 ` Johannes Thumshirn
2023-05-09 22:27 ` David Sterba

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.