Skip to contentSkip to conversation

f2fs: wrap all unusable_blocks_per_sec code in CONFIG_BLK_DEV_ZONED

PATCH In review Yongpeng Yang 2 participants 14 messages Nov 10, 2025 – Nov 24, 2025 F2FS file system

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/3 f2fs: wrap all unusable_blocks_per_sec code in CONFIG_BLK_DEV_ZONED

From: Yongpeng Yang <[email protected]>

The usage of unusable_blocks_per_sec is already wrapped by CONFIG_BLK_DEV_ZONED, except for its declaration and the definitions of CAP_BLKS_PER_SEC and CAP_SEGS_PER_SEC. This patch ensures that all code related to unusable_blocks_per_sec is properly wrapped under the CONFIG_BLK_DEV_ZONED option.

---
v2:
- Revert the renaming of unusable_blocks_per_sec.
- Separate the sysfs node addition for max_open_zones into a separate patch.
- Add more explanation for the case that zoned block device's max_open_zones == 0.

---
 fs/f2fs/f2fs.h    | 2 +-
 fs/f2fs/segment.h | 5 +++++
 2 files changed, 6 insertions(+), 1 deletion(-)
fs/f2fs/f2fs.h +1 -1
index 5b4e9548a231..238ef4bcab6d 100644
@@ -1661,6 +1661,7 @@ struct f2fs_sb_info {
 
 #ifdef CONFIG_BLK_DEV_ZONED
 	unsigned int blocks_per_blkz;		/* F2FS blocks per zone */
+	unsigned int unusable_blocks_per_sec;   /* unusable blocks per section */
 	unsigned int max_open_zones;		/* max open zone resources of the zoned device */
 	/* For adjust the priority writing position of data in zone UFS */
 	unsigned int blkzone_alloc_policy;
@@ -1732,7 +1733,6 @@ struct f2fs_sb_info {
 	unsigned int meta_ino_num;		/* meta inode number*/
 	unsigned int log_blocks_per_seg;	/* log2 blocks per segment */
 	unsigned int blocks_per_seg;		/* blocks per segment */
-	unsigned int unusable_blocks_per_sec;	/* unusable blocks per section */
 	unsigned int segs_per_sec;		/* segments per section */
 	unsigned int secs_per_zone;		/* sections per zone */
 	unsigned int total_sections;		/* total section count */
fs/f2fs/segment.h +5 -0
index 1ce2c8abaf48..e9134f66ab1f 100644
@@ -69,11 +69,16 @@ static inline void sanity_check_seg_type(struct f2fs_sb_info *sbi,
 	((!__is_valid_data_blkaddr(blk_addr)) ?			\
 	NULL_SEGNO : GET_L2R_SEGNO(FREE_I(sbi),			\
 		GET_SEGNO_FROM_SEG0(sbi, blk_addr)))
+#ifdef CONFIG_BLK_DEV_ZONED
 #define CAP_BLKS_PER_SEC(sbi)					\
 	(BLKS_PER_SEC(sbi) - (sbi)->unusable_blocks_per_sec)
 #define CAP_SEGS_PER_SEC(sbi)					\
 	(SEGS_PER_SEC(sbi) -					\
 	BLKS_TO_SEGS(sbi, (sbi)->unusable_blocks_per_sec))
+#else
+#define CAP_BLKS_PER_SEC(sbi) BLKS_PER_SEC(sbi)
+#define CAP_SEGS_PER_SEC(sbi) SEGS_PER_SEC(sbi)
+#endif
 #define GET_START_SEG_FROM_SEC(sbi, segno)			\
 	(rounddown(segno, SEGS_PER_SEC(sbi)))
 #define GET_SEC_FROM_SEG(sbi, segno)				\
Signature · 8 lines
2.43.0



_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
#1 lore raw

PATCH v2 2/3 f2fs: add a sysfs entry to show max open zones

From: Yongpeng Yang <[email protected]>

This patch adds a sysfs entry showing the max zones that F2FS can write concurrently.

---
 Documentation/ABI/testing/sysfs-fs-f2fs | 6 ++++++
 fs/f2fs/sysfs.c                         | 2 ++
 2 files changed, 8 insertions(+)
Documentation/ABI/testing/sysfs-fs-f2fs +6 -0
index b590809869ca..770470e0598b 100644
@@ -643,6 +643,12 @@ Contact:	"Jaegeuk Kim" <[email protected]>
 Description:	Shows the number of unusable blocks in a section which was defined by
 		the zone capacity reported by underlying zoned device.
 
+What:		/sys/fs/f2fs/<disk>/max_open_zones
+Date:		November 2025
+Contact:	"Yongpeng Yang" <[email protected]>
+Description:	Shows the max number of zones that F2FS can write concurrently when a zoned
+		device is mounted.
+
 What:		/sys/fs/f2fs/<disk>/current_atomic_write
 Date:		July 2022
 Contact:	"Daeho Jeong" <[email protected]>
fs/f2fs/sysfs.c +2 -0
index 6d2a4fba68a2..1072cfdaeb69 100644
@@ -1210,6 +1210,7 @@ F2FS_SBI_GENERAL_RW_ATTR(last_age_weight);
 F2FS_SBI_GENERAL_RW_ATTR(max_read_extent_count);
 #ifdef CONFIG_BLK_DEV_ZONED
 F2FS_SBI_GENERAL_RO_ATTR(unusable_blocks_per_sec);
+F2FS_SBI_GENERAL_RO_ATTR(max_open_zones);
 F2FS_SBI_GENERAL_RW_ATTR(blkzone_alloc_policy);
 #endif
 F2FS_SBI_GENERAL_RW_ATTR(carve_out);
@@ -1384,6 +1385,7 @@ static struct attribute *f2fs_attrs[] = {
 #endif
 #ifdef CONFIG_BLK_DEV_ZONED
 	ATTR_LIST(unusable_blocks_per_sec),
+	ATTR_LIST(max_open_zones),
 	ATTR_LIST(blkzone_alloc_policy),
 #endif
 #ifdef CONFIG_F2FS_FS_COMPRESSION
Signature · 8 lines
2.43.0



_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
Reviewed-by Chao Yu on v2 2/3
#2 lore raw

Re: [f2fs-dev] [PATCH v2 2/3] f2fs: add a sysfs entry to show max open zones

Quoted 6 lines · Yongpeng Yang

From: Yongpeng Yang <[email protected]>

This patch adds a sysfs entry showing the max zones that F2FS can write concurrently.

Thanks,

_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

#3 lore raw

PATCH v2 3/3 f2fs: fix handling of zoned block devices with max_open_zones == 0

In reply to Yongpeng Yang

From: Yongpeng Yang <[email protected]>

When emulating a ZNS SSD on qemu with zoned.max_open set to 0, the F2FS can still be mounted successfully. The sysfs entry shows sbi->max_open_zones as UINT_MAX.

root@fedora-vm:~# cat /sys/block/nvme0n1/queue/zoned
host-managed
root@fedora-vm:~# cat /sys/block/nvme0n1/queue/max_open_zones
0
root@fedora-vm:~# mkfs.f2fs -m -c /dev/nvme0n1 /dev/vda
root@fedora-vm:~# mount /dev/vda /mnt/f2fs/
root@fedora-vm:~# cat /sys/fs/f2fs/vda/max_open_zones
4294967295

The root cause is that sbi->max_open_zones is initialized to UINT_MAX and only updated when the device’s max_open_zones is greater than 0. However, both the scsi driver (sd_zbc_read_zones may assigns 0 to device's max_open_zones) and the nvme driver (nvme_query_zone_info don't check max_open_zones) allow max_open_zones to be 0.

This patch fixes the issue by preventing mounting on zoned SSDs when max_open_zones is 0, while still allowing SMR HDDs to be mounted. init_blkz_info() is only called by f2fs_scan_devices(), and the blkzoned feature has already been checked there. So, this patch also remove redundant zoned device checks.

---
 fs/f2fs/super.c | 36 +++++++++++++++++++++---------------
 1 file changed, 21 insertions(+), 15 deletions(-)
fs/f2fs/super.c +21 -15
index db7afb806411..6dc8945e24af 100644
@@ -4353,21 +4353,6 @@ static int init_blkz_info(struct f2fs_sb_info *sbi, int devi)
 	unsigned int max_open_zones;
 	int ret;
 
-	if (!f2fs_sb_has_blkzoned(sbi))
-		return 0;
-
-	if (bdev_is_zoned(FDEV(devi).bdev)) {
-		max_open_zones = bdev_max_open_zones(bdev);
-		if (max_open_zones && (max_open_zones < sbi->max_open_zones))
-			sbi->max_open_zones = max_open_zones;
-		if (sbi->max_open_zones < F2FS_OPTION(sbi).active_logs) {
-			f2fs_err(sbi,
-				"zoned: max open zones %u is too small, need at least %u open zones",
-				sbi->max_open_zones, F2FS_OPTION(sbi).active_logs);
-			return -EINVAL;
-		}
-	}
-
 	zone_sectors = bdev_zone_sectors(bdev);
 	if (sbi->blocks_per_blkz && sbi->blocks_per_blkz !=
 				SECTOR_TO_BLOCK(zone_sectors))
@@ -4378,6 +4363,27 @@ static int init_blkz_info(struct f2fs_sb_info *sbi, int devi)
 	if (nr_sectors & (zone_sectors - 1))
 		FDEV(devi).nr_blkz++;
 
+	max_open_zones = bdev_max_open_zones(bdev);
+	if (!max_open_zones) {
+		/*
+		 * SSDs require max_open_zones > 0 to be mountable.
+		 * For HDDs, if max_open_zones is reported as 0, it doesn't matter,
+		 * set it to FDEV(devi).nr_blkz.
+		 */
+		if (bdev_nonrot(bdev)) {
+			f2fs_err(sbi, "zoned: SSD device %s without open zones", FDEV(devi).path);
+			return -EINVAL;
+		}
+		max_open_zones = FDEV(devi).nr_blkz;
+	}
+	sbi->max_open_zones = min_t(unsigned int, max_open_zones, sbi->max_open_zones);
+	if (sbi->max_open_zones < F2FS_OPTION(sbi).active_logs) {
+		f2fs_err(sbi,
+			"zoned: max open zones %u is too small, need at least %u open zones",
+			sbi->max_open_zones, F2FS_OPTION(sbi).active_logs);
+		return -EINVAL;
+	}
+
 	FDEV(devi).blkz_seq = f2fs_kvzalloc(sbi,
 					BITS_TO_LONGS(FDEV(devi).nr_blkz)
 					* sizeof(unsigned long),
Signature · 8 lines
2.43.0



_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
Reviewed-by Chao Yu on v2 3/3
#4 lore raw

Re: [f2fs-dev] [PATCH v2 3/3] f2fs: fix handling of zoned block devices with max_open_zones == 0

Quoted 21 lines · Yongpeng Yang

From: Yongpeng Yang <[email protected]>

When emulating a ZNS SSD on qemu with zoned.max_open set to 0, the F2FS can still be mounted successfully. The sysfs entry shows sbi->max_open_zones as UINT_MAX.

root@fedora-vm:~# cat /sys/block/nvme0n1/queue/zoned
host-managed
root@fedora-vm:~# cat /sys/block/nvme0n1/queue/max_open_zones
0
root@fedora-vm:~# mkfs.f2fs -m -c /dev/nvme0n1 /dev/vda
root@fedora-vm:~# mount /dev/vda /mnt/f2fs/
root@fedora-vm:~# cat /sys/fs/f2fs/vda/max_open_zones
4294967295

The root cause is that sbi->max_open_zones is initialized to UINT_MAX and only updated when the device’s max_open_zones is greater than 0. However, both the scsi driver (sd_zbc_read_zones may assigns 0 to device's max_open_zones) and the nvme driver (nvme_query_zone_info don't check max_open_zones) allow max_open_zones to be 0.

Quoted 7 lines

This patch fixes the issue by preventing mounting on zoned SSDs when max_open_zones is 0, while still allowing SMR HDDs to be mounted. init_blkz_info() is only called by f2fs_scan_devices(), and the blkzoned feature has already been checked there. So, this patch also remove redundant zoned device checks.

Thanks,

_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

#5 lore raw

Re: [f2fs-dev] [PATCH v2 3/3] f2fs: fix handling of zoned block devices with max_open_zones == 0

In reply to Yongpeng Yang

This breaks the device giving 0 open zone which was working. Hence, I dropped the change.

Quoted 88 lines · Yongpeng Yang

From: Yongpeng Yang <[email protected]>

When emulating a ZNS SSD on qemu with zoned.max_open set to 0, the F2FS can still be mounted successfully. The sysfs entry shows sbi->max_open_zones as UINT_MAX.

root@fedora-vm:~# cat /sys/block/nvme0n1/queue/zoned
host-managed
root@fedora-vm:~# cat /sys/block/nvme0n1/queue/max_open_zones
0
root@fedora-vm:~# mkfs.f2fs -m -c /dev/nvme0n1 /dev/vda
root@fedora-vm:~# mount /dev/vda /mnt/f2fs/
root@fedora-vm:~# cat /sys/fs/f2fs/vda/max_open_zones
4294967295

The root cause is that sbi->max_open_zones is initialized to UINT_MAX and only updated when the device’s max_open_zones is greater than 0. However, both the scsi driver (sd_zbc_read_zones may assigns 0 to device's max_open_zones) and the nvme driver (nvme_query_zone_info don't check max_open_zones) allow max_open_zones to be 0.

This patch fixes the issue by preventing mounting on zoned SSDs when max_open_zones is 0, while still allowing SMR HDDs to be mounted. init_blkz_info() is only called by f2fs_scan_devices(), and the blkzoned feature has already been checked there. So, this patch also remove redundant zoned device checks.

---
 fs/f2fs/super.c | 36 +++++++++++++++++++++---------------
 1 file changed, 21 insertions(+), 15 deletions(-)
fs/f2fs/super.c +21 -15
index db7afb806411..6dc8945e24af 100644
@@ -4353,21 +4353,6 @@ static int init_blkz_info(struct f2fs_sb_info *sbi, int devi)
 	unsigned int max_open_zones;
 	int ret;
 
-	if (!f2fs_sb_has_blkzoned(sbi))
-		return 0;
-
-	if (bdev_is_zoned(FDEV(devi).bdev)) {
-		max_open_zones = bdev_max_open_zones(bdev);
-		if (max_open_zones && (max_open_zones < sbi->max_open_zones))
-			sbi->max_open_zones = max_open_zones;
-		if (sbi->max_open_zones < F2FS_OPTION(sbi).active_logs) {
-			f2fs_err(sbi,
-				"zoned: max open zones %u is too small, need at least %u open zones",
-				sbi->max_open_zones, F2FS_OPTION(sbi).active_logs);
-			return -EINVAL;
-		}
-	}
-
 	zone_sectors = bdev_zone_sectors(bdev);
 	if (sbi->blocks_per_blkz && sbi->blocks_per_blkz !=
 				SECTOR_TO_BLOCK(zone_sectors))
@@ -4378,6 +4363,27 @@ static int init_blkz_info(struct f2fs_sb_info *sbi, int devi)
 	if (nr_sectors & (zone_sectors - 1))
 		FDEV(devi).nr_blkz++;
 
+	max_open_zones = bdev_max_open_zones(bdev);
+	if (!max_open_zones) {
+		/*
+		 * SSDs require max_open_zones > 0 to be mountable.
+		 * For HDDs, if max_open_zones is reported as 0, it doesn't matter,
+		 * set it to FDEV(devi).nr_blkz.
+		 */
+		if (bdev_nonrot(bdev)) {
+			f2fs_err(sbi, "zoned: SSD device %s without open zones", FDEV(devi).path);
+			return -EINVAL;
+		}
+		max_open_zones = FDEV(devi).nr_blkz;
+	}
+	sbi->max_open_zones = min_t(unsigned int, max_open_zones, sbi->max_open_zones);
+	if (sbi->max_open_zones < F2FS_OPTION(sbi).active_logs) {
+		f2fs_err(sbi,
+			"zoned: max open zones %u is too small, need at least %u open zones",
+			sbi->max_open_zones, F2FS_OPTION(sbi).active_logs);
+		return -EINVAL;
+	}
+
 	FDEV(devi).blkz_seq = f2fs_kvzalloc(sbi,
 					BITS_TO_LONGS(FDEV(devi).nr_blkz)
 					* sizeof(unsigned long),
Signature · 1 line
2.43.0

_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

#6 lore raw

Re: [f2fs-dev] [PATCH v2 3/3] f2fs: fix handling of zoned block devices with max_open_zones == 0

Quoted 66 lines · Jaegeuk Kim

This breaks the device giving 0 open zone which was working. Hence, I dropped the change.

Quoted 62 lines · Yongpeng Yang

From: Yongpeng Yang <[email protected]>

When emulating a ZNS SSD on qemu with zoned.max_open set to 0, the F2FS can still be mounted successfully. The sysfs entry shows sbi->max_open_zones as UINT_MAX.

root@fedora-vm:~# cat /sys/block/nvme0n1/queue/zoned
host-managed
root@fedora-vm:~# cat /sys/block/nvme0n1/queue/max_open_zones
0
root@fedora-vm:~# mkfs.f2fs -m -c /dev/nvme0n1 /dev/vda
root@fedora-vm:~# mount /dev/vda /mnt/f2fs/
root@fedora-vm:~# cat /sys/fs/f2fs/vda/max_open_zones
4294967295

The root cause is that sbi->max_open_zones is initialized to UINT_MAX and only updated when the device’s max_open_zones is greater than 0. However, both the scsi driver (sd_zbc_read_zones may assigns 0 to device's max_open_zones) and the nvme driver (nvme_query_zone_info don't check max_open_zones) allow max_open_zones to be 0.

This patch fixes the issue by preventing mounting on zoned SSDs when max_open_zones is 0, while still allowing SMR HDDs to be mounted. init_blkz_info() is only called by f2fs_scan_devices(), and the blkzoned feature has already been checked there. So, this patch also remove redundant zoned device checks.

---
  fs/f2fs/super.c | 36 +++++++++++++++++++++---------------
  1 file changed, 21 insertions(+), 15 deletions(-)
fs/f2fs/super.c +0 -15
index db7afb806411..6dc8945e24af 100644
@@ -4353,21 +4353,6 @@ static int init_blkz_info(struct f2fs_sb_info *sbi, int devi)
  	unsigned int max_open_zones;
  	int ret;
 
-	if (!f2fs_sb_has_blkzoned(sbi))
-		return 0;
-
-	if (bdev_is_zoned(FDEV(devi).bdev)) {
-		max_open_zones = bdev_max_open_zones(bdev);
-		if (max_open_zones && (max_open_zones < sbi->max_open_zones))
-			sbi->max_open_zones = max_open_zones;
-		if (sbi->max_open_zones < F2FS_OPTION(sbi).active_logs) {
-			f2fs_err(sbi,
-				"zoned: max open zones %u is too small, need at least %u open zones",
-				sbi->max_open_zones, F2FS_OPTION(sbi).active_logs);
-			return -EINVAL;
-		}
-	}
-
  	zone_sectors = bdev_zone_sectors(bdev);
  	if (sbi->blocks_per_blkz && sbi->blocks_per_blkz !=
  				SECTOR_TO_BLOCK(zone_sectors))
@@ -4378,6 +4363,27 @@ static int init_blkz_info(struct f2fs_sb_info *sbi, int devi)
  	if (nr_sectors & (zone_sectors - 1))
  		FDEV(devi).nr_blkz++;
 
Quoted 10 lines

fs/f2fs/super.c static int init_blkz_info(struct f2fs_sb_info *sbi, int devi) · line 4375

Quoted 10 lines
fs/f2fs/super.c +10 -0
+	max_open_zones = bdev_max_open_zones(bdev);
+	if (!max_open_zones) {
+		/*
+		 * SSDs require max_open_zones > 0 to be mountable.
+		 * For HDDs, if max_open_zones is reported as 0, it doesn't matter,
+		 * set it to FDEV(devi).nr_blkz.
+		 */
+		if (bdev_nonrot(bdev)) {
+			f2fs_err(sbi, "zoned: SSD device %s without open zones", FDEV(devi).path);
+			return -EINVAL;

Oh, so, for conventional UFS, it will go into this path as SSD w/ zero open zone?

Any way to distinguish that?

Thanks,

Quoted 8 lines
Quoted 8 lines
fs/f2fs/super.c +8 -0
+		}
+		max_open_zones = FDEV(devi).nr_blkz;
+	}
+	sbi->max_open_zones = min_t(unsigned int, max_open_zones, sbi->max_open_zones);
+	if (sbi->max_open_zones < F2FS_OPTION(sbi).active_logs) {
+		f2fs_err(sbi,
+			"zoned: max open zones %u is too small, need at least %u open zones",
+			sbi->max_open_zones, F2FS_OPTION(sbi).active_logs);
Quoted 8 lines
Quoted 8 lines
fs/f2fs/super.c +3 -0
+		return -EINVAL;
+	}
+
  	FDEV(devi).blkz_seq = f2fs_kvzalloc(sbi,
  					BITS_TO_LONGS(FDEV(devi).nr_blkz)
  					* sizeof(unsigned long),
Signature · 1 line
2.43.0

_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

#7 lore raw

Re: [f2fs-dev] [PATCH v2 3/3] f2fs: fix handling of zoned block devices with max_open_zones == 0

Quoted 83 lines · On 11/14/25 08:51, Chao Yu via Linux-f2fs-devel wrote:
Quoted 71 lines · Jaegeuk Kim

This breaks the device giving 0 open zone which was working. Hence, I dropped the change.

Quoted 67 lines · Yongpeng Yang

From: Yongpeng Yang <[email protected]>

When emulating a ZNS SSD on qemu with zoned.max_open set to 0, the F2FS can still be mounted successfully. The sysfs entry shows sbi->max_open_zones as UINT_MAX.

root@fedora-vm:~# cat /sys/block/nvme0n1/queue/zoned
host-managed
root@fedora-vm:~# cat /sys/block/nvme0n1/queue/max_open_zones
0
root@fedora-vm:~# mkfs.f2fs -m -c /dev/nvme0n1 /dev/vda
root@fedora-vm:~# mount /dev/vda /mnt/f2fs/
root@fedora-vm:~# cat /sys/fs/f2fs/vda/max_open_zones
4294967295

The root cause is that sbi->max_open_zones is initialized to UINT_MAX and only updated when the device’s max_open_zones is greater than 0. However, both the scsi driver (sd_zbc_read_zones may assigns 0 to device's max_open_zones) and the nvme driver (nvme_query_zone_info don't check max_open_zones) allow max_open_zones to be 0.

This patch fixes the issue by preventing mounting on zoned SSDs when max_open_zones is 0, while still allowing SMR HDDs to be mounted. init_blkz_info() is only called by f2fs_scan_devices(), and the blkzoned feature has already been checked there. So, this patch also remove redundant zoned device checks.

---
  fs/f2fs/super.c | 36 +++++++++++++++++++++---------------

  1 file changed, 21 insertions(+), 15 deletions(-)
fs/f2fs/super.c +0 -15
index db7afb806411..6dc8945e24af 100644
@@ -4353,21 +4353,6 @@ static int init_blkz_info(struct f2fs_sb_info 
 *sbi, int devi)
       unsigned int max_open_zones;
       int ret;
-    if (!f2fs_sb_has_blkzoned(sbi))
-        return 0;
-
-    if (bdev_is_zoned(FDEV(devi).bdev)) {
-        max_open_zones = bdev_max_open_zones(bdev);
-        if (max_open_zones && (max_open_zones < sbi->max_open_zones))
-            sbi->max_open_zones = max_open_zones;
-        if (sbi->max_open_zones < F2FS_OPTION(sbi).active_logs) {
-            f2fs_err(sbi,
-                "zoned: max open zones %u is too small, need at 
 least %u open zones",
-                sbi->max_open_zones, F2FS_OPTION(sbi).active_logs);
-            return -EINVAL;
-        }
-    }
-
       zone_sectors = bdev_zone_sectors(bdev);

      if (sbi->blocks_per_blkz && sbi->blocks_per_blkz != SECTOR_TO_BLOCK(zone_sectors))

fs/f2fs/super.c +4 -0
@@ -4378,6 +4363,27 @@ static int init_blkz_info(struct f2fs_sb_info 
 *sbi, int devi)
       if (nr_sectors & (zone_sectors - 1))
           FDEV(devi).nr_blkz++;
+    max_open_zones = bdev_max_open_zones(bdev);
+    if (!max_open_zones) {
+        /*
+         * SSDs require max_open_zones > 0 to be mountable.
Quoted 8 lines

fs/f2fs/super.c static int init_blkz_info(struct f2fs_sb_info *sbi, int devi) · line 4375

Quoted 8 lines
fs/f2fs/super.c +6 -0
+         * For HDDs, if max_open_zones is reported as 0, it doesn't 
 matter,
+         * set it to FDEV(devi).nr_blkz.
+         */
+        if (bdev_nonrot(bdev)) {
+            f2fs_err(sbi, "zoned: SSD device %s without open zones", 
 FDEV(devi).path);
+            return -EINVAL;

Oh, so, for conventional UFS, it will go into this path as SSD w/ zero open zone?

Quoted 4 lines

Any way to distinguish that?

Thanks,

sbi->max_open_zones might be classified into 4 cases:

1. For non rotational devices that have both conventional zones and sequential zones, we should still ensure that max_open_zones > 0. If the

# of sequential zones exceeds max_open_zones, we still need to guarantee
that max_open_zones >= F2FS_OPTION(sbi).active_logs.

I tested this with null_blk by emulating a device that has 10 conventional zones and 4 sequential zones, and the filesystem can be formatted successfully. In this case, the filesystem should also be mountable, and sbi->max_open_zones should be 14. However, if zone_max_open is set to 3, the filesystem cannot be mounted.

#modprobe null_blk nr_devices=1 zoned=1 zone_nr_conv=10 zone_size=1024 gb=14 bs=4096 rotational=0 zone_max_open=4
#mkfs.f2fs -m -c /dev/nullb0 /dev/vda -f

So, sbi->max_open_zones might be # of max_open_zones or '# of sequential zones' + '# of conventional zones'.

2. For non rotational devices which only have conventional zones, I'm not sure whether there are zoned flash devices that provide only conventional zones. If such devices do exist, then returning -EINVAL is indeed not appropriate. sbi->max_open_zones should be # of conventional zones.

3. For non rotational devices which only have sequential zones, sbi-

Quoted 1 line

max_open_zones should be # max_open_zones.

4. For rotational devices, sbi->max_open_zones should be # zones or max_open_zones.

Am I missing any other cases?

Yongpeng,

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
fs/f2fs/super.c +4 -0
+        }
+        max_open_zones = FDEV(devi).nr_blkz;
+    }
+    sbi->max_open_zones = min_t(unsigned int, max_open_zones, sbi- 
 >max_open_zones);
Quoted 13 lines
Quoted 5 lines
Quoted 5 lines
fs/f2fs/super.c +3 -0
+    if (sbi->max_open_zones < F2FS_OPTION(sbi).active_logs) {
+        f2fs_err(sbi,
+            "zoned: max open zones %u is too small, need at least %u 

open zones",
+            sbi->max_open_zones, F2FS_OPTION(sbi).active_logs);

Quoted 8 lines
Quoted 8 lines

+        return -EINVAL;
+    }
+
      FDEV(devi).blkz_seq = f2fs_kvzalloc(sbi, BITS_TO_LONGS(FDEV(devi).nr_blkz)
                      * sizeof(unsigned long),

Signature · 1 line
2.43.0

_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

#8 lore raw

Re: [f2fs-dev] [PATCH v2 3/3] f2fs: fix handling of zoned block devices with max_open_zones == 0

Quoted 108 lines · Yongpeng Yang
Quoted 85 lines · On 11/14/25 08:51, Chao Yu via Linux-f2fs-devel wrote:
Quoted 72 lines · Jaegeuk Kim

This breaks the device giving 0 open zone which was working. Hence, I dropped
the change.

Quoted 67 lines · Yongpeng Yang

From: Yongpeng Yang <[email protected]>

When emulating a ZNS SSD on qemu with zoned.max_open set to 0, the F2FS can still be mounted successfully. The sysfs entry shows sbi->max_open_zones as UINT_MAX.

root@fedora-vm:~# cat /sys/block/nvme0n1/queue/zoned
host-managed
root@fedora-vm:~# cat /sys/block/nvme0n1/queue/max_open_zones
0
root@fedora-vm:~# mkfs.f2fs -m -c /dev/nvme0n1 /dev/vda
root@fedora-vm:~# mount /dev/vda /mnt/f2fs/
root@fedora-vm:~# cat /sys/fs/f2fs/vda/max_open_zones
4294967295

The root cause is that sbi->max_open_zones is initialized to UINT_MAX and only updated when the device’s max_open_zones is greater than 0. However, both the scsi driver (sd_zbc_read_zones may assigns 0 to device's max_open_zones) and the nvme driver (nvme_query_zone_info don't check max_open_zones) allow max_open_zones to be 0.

This patch fixes the issue by preventing mounting on zoned SSDs when max_open_zones is 0, while still allowing SMR HDDs to be mounted. init_blkz_info() is only called by f2fs_scan_devices(), and the blkzoned feature has already been checked there. So, this patch also remove redundant zoned device checks.

---
   fs/f2fs/super.c | 36 +++++++++++++++++++++---------------
   1 file changed, 21 insertions(+), 15 deletions(-)
fs/f2fs/super.c +0 -15
index db7afb806411..6dc8945e24af 100644
@@ -4353,21 +4353,6 @@ static int init_blkz_info(struct f2fs_sb_info
 *sbi, int devi)
       unsigned int max_open_zones;
       int ret;
-    if (!f2fs_sb_has_blkzoned(sbi))
-        return 0;
-
-    if (bdev_is_zoned(FDEV(devi).bdev)) {
-        max_open_zones = bdev_max_open_zones(bdev);
-        if (max_open_zones && (max_open_zones < sbi->max_open_zones))
-            sbi->max_open_zones = max_open_zones;
-        if (sbi->max_open_zones < F2FS_OPTION(sbi).active_logs) {
-            f2fs_err(sbi,
-                "zoned: max open zones %u is too small, need at
 least %u open zones",
-                sbi->max_open_zones, F2FS_OPTION(sbi).active_logs);
-            return -EINVAL;
-        }
-    }
-
       zone_sectors = bdev_zone_sectors(bdev);
       if (sbi->blocks_per_blkz && sbi->blocks_per_blkz !=

                  SECTOR_TO_BLOCK(zone_sectors))

fs/f2fs/super.c +4 -0
@@ -4378,6 +4363,27 @@ static int init_blkz_info(struct f2fs_sb_info
 *sbi, int devi)
       if (nr_sectors & (zone_sectors - 1))
           FDEV(devi).nr_blkz++;
+    max_open_zones = bdev_max_open_zones(bdev);
+    if (!max_open_zones) {
+        /*
+         * SSDs require max_open_zones > 0 to be mountable.
Quoted 8 lines

fs/f2fs/super.c static int init_blkz_info(struct f2fs_sb_info *sbi, int devi) · line 4375

Quoted 8 lines
fs/f2fs/super.c +6 -0
+         * For HDDs, if max_open_zones is reported as 0, it doesn't
 matter,
+         * set it to FDEV(devi).nr_blkz.
+         */
+        if (bdev_nonrot(bdev)) {
+            f2fs_err(sbi, "zoned: SSD device %s without open zones",
 FDEV(devi).path);
+            return -EINVAL;

Oh, so, for conventional UFS, it will go into this path as SSD w/ zero open zone?

Quoted 4 lines

Any way to distinguish that?

Thanks,

sbi->max_open_zones might be classified into 4 cases:

1. For non rotational devices that have both conventional zones and sequential zones, we should still ensure that max_open_zones > 0. If the

# of sequential zones exceeds max_open_zones, we still need to guarantee
that max_open_zones >= F2FS_OPTION(sbi).active_logs.

I tested this with null_blk by emulating a device that has 10 conventional zones and 4 sequential zones, and the filesystem can be formatted successfully. In this case, the filesystem should also be mountable, and sbi->max_open_zones should be 14. However, if zone_max_open is set to 3, the filesystem cannot be mounted.

#modprobe null_blk nr_devices=1 zoned=1 zone_nr_conv=10 zone_size=1024 gb=14 bs=4096 rotational=0 zone_max_open=4
#mkfs.f2fs -m -c /dev/nullb0 /dev/vda -f

Quoted 5 lines

So, sbi->max_open_zones might be # of max_open_zones or '# of sequential zones' + '# of conventional zones'.

2. For non rotational devices which only have conventional zones, I'm not sure whether there are zoned flash devices that provide only

I guess this is a similar case, we should not let mount() fail for such case, right?

- modprobe null_blk nr_devices=1 zoned=1 zone_nr_conv=512 zone_size=2 \
gb=1 bs=4096 rotational=0 zone_max_open=6
- mkfs.f2fs -m /dev/nullb0
- mount /dev/nullb0 /mnt/f2fs

Thanks,

Quoted 5 lines

conventional zones. If such devices do exist, then returning -EINVAL is indeed not appropriate. sbi->max_open_zones should be # of conventional zones.

3. For non rotational devices which only have sequential zones, sbi-

Quoted 29 lines
Quoted 1 line

max_open_zones should be # max_open_zones.

4. For rotational devices, sbi->max_open_zones should be # zones or max_open_zones.

Am I missing any other cases?

Yongpeng,

Quoted 18 lines
Quoted 18 lines
Quoted 18 lines
fs/f2fs/super.c +7 -0
+        }
+        max_open_zones = FDEV(devi).nr_blkz;
+    }
+    sbi->max_open_zones = min_t(unsigned int, max_open_zones, sbi-
 > max_open_zones);
+    if (sbi->max_open_zones < F2FS_OPTION(sbi).active_logs) {
+        f2fs_err(sbi,
+            "zoned: max open zones %u is too small, need at least %u

open zones",
+            sbi->max_open_zones, F2FS_OPTION(sbi).active_logs); +        return -EINVAL;
+    }
+
      FDEV(devi).blkz_seq = f2fs_kvzalloc(sbi, BITS_TO_LONGS(FDEV(devi).nr_blkz)
                      * sizeof(unsigned long),

Signature · 1 line
2.43.0

_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

#9 lore raw

Re: [f2fs-dev] [PATCH v2 3/3] f2fs: fix handling of zoned block devices with max_open_zones == 0

Quoted 109 lines · On 11/15/2025 7:36 PM, Chao Yu via Linux-f2fs-devel wrote:
Quoted 108 lines · Yongpeng Yang
Quoted 85 lines · On 11/14/25 08:51, Chao Yu via Linux-f2fs-devel wrote:
Quoted 72 lines · Jaegeuk Kim

This breaks the device giving 0 open zone which was working. Hence, I dropped
the change.

Quoted 67 lines · Yongpeng Yang

From: Yongpeng Yang <[email protected]>

When emulating a ZNS SSD on qemu with zoned.max_open set to 0, the F2FS can still be mounted successfully. The sysfs entry shows sbi->max_open_zones as UINT_MAX.

root@fedora-vm:~# cat /sys/block/nvme0n1/queue/zoned
host-managed
root@fedora-vm:~# cat /sys/block/nvme0n1/queue/max_open_zones
0
root@fedora-vm:~# mkfs.f2fs -m -c /dev/nvme0n1 /dev/vda
root@fedora-vm:~# mount /dev/vda /mnt/f2fs/
root@fedora-vm:~# cat /sys/fs/f2fs/vda/max_open_zones
4294967295

The root cause is that sbi->max_open_zones is initialized to UINT_MAX and only updated when the device’s max_open_zones is greater than 0. However, both the scsi driver (sd_zbc_read_zones may assigns 0 to device's max_open_zones) and the nvme driver (nvme_query_zone_info don't check max_open_zones) allow max_open_zones to be 0.

This patch fixes the issue by preventing mounting on zoned SSDs when max_open_zones is 0, while still allowing SMR HDDs to be mounted. init_blkz_info() is only called by f2fs_scan_devices(), and the blkzoned feature has already been checked there. So, this patch also remove redundant zoned device checks.

---
   fs/f2fs/super.c | 36 +++++++++++++++++++++---------------

   1 file changed, 21 insertions(+), 15 deletions(-)
fs/f2fs/super.c +0 -15
index db7afb806411..6dc8945e24af 100644
@@ -4353,21 +4353,6 @@ static int init_blkz_info(struct f2fs_sb_info
 *sbi, int devi)
        unsigned int max_open_zones;
        int ret;
-    if (!f2fs_sb_has_blkzoned(sbi))
-        return 0;
-
-    if (bdev_is_zoned(FDEV(devi).bdev)) {
-        max_open_zones = bdev_max_open_zones(bdev);
-        if (max_open_zones && (max_open_zones < sbi->max_open_zones))
-            sbi->max_open_zones = max_open_zones;
-        if (sbi->max_open_zones < F2FS_OPTION(sbi).active_logs) {
-            f2fs_err(sbi,
-                "zoned: max open zones %u is too small, need at
 least %u open zones",
-                sbi->max_open_zones, F2FS_OPTION(sbi).active_logs);
-            return -EINVAL;
-        }
-    }
-
        zone_sectors = bdev_zone_sectors(bdev);

       if (sbi->blocks_per_blkz && sbi->blocks_per_blkz != SECTOR_TO_BLOCK(zone_sectors))

fs/f2fs/super.c +4 -0
@@ -4378,6 +4363,27 @@ static int init_blkz_info(struct f2fs_sb_info
 *sbi, int devi)
        if (nr_sectors & (zone_sectors - 1))
            FDEV(devi).nr_blkz++;
+    max_open_zones = bdev_max_open_zones(bdev);
+    if (!max_open_zones) {
+        /*
+         * SSDs require max_open_zones > 0 to be mountable.
Quoted 8 lines

fs/f2fs/super.c static int init_blkz_info(struct f2fs_sb_info *sbi, int devi) · line 4375

Quoted 8 lines
fs/f2fs/super.c +6 -0
+         * For HDDs, if max_open_zones is reported as 0, it doesn't
 matter,
+         * set it to FDEV(devi).nr_blkz.
+         */
+        if (bdev_nonrot(bdev)) {
+            f2fs_err(sbi, "zoned: SSD device %s without open zones",
 FDEV(devi).path);
+            return -EINVAL;

Oh, so, for conventional UFS, it will go into this path as SSD w/ zero open zone?

Quoted 4 lines

Any way to distinguish that?

Thanks,

sbi->max_open_zones might be classified into 4 cases:

1. For non rotational devices that have both conventional zones and sequential zones, we should still ensure that max_open_zones > 0. If the

# of sequential zones exceeds max_open_zones, we still need to guarantee
that max_open_zones >= F2FS_OPTION(sbi).active_logs.

I tested this with null_blk by emulating a device that has 10 conventional zones and 4 sequential zones, and the filesystem can be formatted successfully. In this case, the filesystem should also be mountable, and sbi->max_open_zones should be 14. However, if zone_max_open is set to 3, the filesystem cannot be mounted.

#modprobe null_blk nr_devices=1 zoned=1  zone_nr_conv=10  zone_size=1024 gb=14 bs=4096 rotational=0 zone_max_open=4
#mkfs.f2fs -m -c /dev/nullb0 /dev/vda -f

Quoted 8 lines
Quoted 5 lines

So, sbi->max_open_zones might be # of max_open_zones or '# of sequential zones' + '# of conventional zones'.

2. For non rotational devices which only have conventional zones, I'm not sure whether there are zoned flash devices that provide only

I guess this is a similar case, we should not let mount() fail for such case, right?

Yes, it should be moutable. I'll take all these cases into account in the v3 patch.

Quoted 3 lines

- modprobe null_blk nr_devices=1 zoned=1 zone_nr_conv=512 zone_size=2 \
gb=1 bs=4096 rotational=0 zone_max_open=6

This scenario cannot be emulated with null_blk. There must be at least 1 sequential zone, and zone_max_open is greater than # of sequential zones, whereas in reality max_open_zones is 0.

Yongpeng,

Quoted 42 lines

- mkfs.f2fs -m /dev/nullb0
- mount /dev/nullb0 /mnt/f2fs

Thanks,

Quoted 5 lines

conventional zones. If such devices do exist, then returning -EINVAL is indeed not appropriate. sbi->max_open_zones should be # of conventional zones.

3. For non rotational devices which only have sequential zones, sbi-

Quoted 29 lines
Quoted 1 line

max_open_zones should be # max_open_zones.

4. For rotational devices, sbi->max_open_zones should be # zones or max_open_zones.

Am I missing any other cases?

Yongpeng,

Quoted 18 lines
Quoted 18 lines
Quoted 18 lines
fs/f2fs/super.c +7 -0
+        }
+        max_open_zones = FDEV(devi).nr_blkz;
+    }
+    sbi->max_open_zones = min_t(unsigned int, max_open_zones, sbi-
 > max_open_zones);
+    if (sbi->max_open_zones < F2FS_OPTION(sbi).active_logs) {
+        f2fs_err(sbi,
+            "zoned: max open zones %u is too small, need at least %u

open zones",
+            sbi->max_open_zones, F2FS_OPTION(sbi).active_logs); +        return -EINVAL;
+    }
+
       FDEV(devi).blkz_seq = f2fs_kvzalloc(sbi, BITS_TO_LONGS(FDEV(devi).nr_blkz)
                       * sizeof(unsigned long),

Signature · 1 line
2.43.0
Quoted 4 lines

_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

#10 lore raw

Re: [f2fs-dev] [PATCH v2 3/3] f2fs: fix handling of zoned block devices with max_open_zones == 0

Quoted 108 lines · Yongpeng Yang
Quoted 106 lines · On 11/15/2025 7:36 PM, Chao Yu via Linux-f2fs-devel wrote:
Quoted 105 lines · Yongpeng Yang
Quoted 86 lines · On 11/14/25 08:51, Chao Yu via Linux-f2fs-devel wrote:
Quoted 73 lines · Jaegeuk Kim

This breaks the device giving 0 open zone which was working. Hence, I dropped
the change.

Quoted 68 lines · Yongpeng Yang

From: Yongpeng Yang <[email protected]>

When emulating a ZNS SSD on qemu with zoned.max_open set to 0, the F2FS can still be mounted successfully. The sysfs entry shows sbi->max_open_zones as UINT_MAX.

root@fedora-vm:~# cat /sys/block/nvme0n1/queue/zoned
host-managed
root@fedora-vm:~# cat /sys/block/nvme0n1/queue/max_open_zones
0
root@fedora-vm:~# mkfs.f2fs -m -c /dev/nvme0n1 /dev/vda
root@fedora-vm:~# mount /dev/vda /mnt/f2fs/
root@fedora-vm:~# cat /sys/fs/f2fs/vda/max_open_zones
4294967295

The root cause is that sbi->max_open_zones is initialized to UINT_MAX and only updated when the device’s max_open_zones is greater than 0. However, both the scsi driver (sd_zbc_read_zones may assigns 0 to device's max_open_zones) and the nvme driver (nvme_query_zone_info don't check max_open_zones) allow max_open_zones to be 0.

This patch fixes the issue by preventing mounting on zoned SSDs when max_open_zones is 0, while still allowing SMR HDDs to be mounted. init_blkz_info() is only called by f2fs_scan_devices(), and the blkzoned feature has already been checked there. So, this patch also remove redundant zoned device checks.

---
   fs/f2fs/super.c | 36 +++++++++++++++++++++---------------

   1 file changed, 21 insertions(+), 15 deletions(-)
fs/f2fs/super.c +0 -15
index db7afb806411..6dc8945e24af 100644
@@ -4353,21 +4353,6 @@ static int init_blkz_info(struct f2fs_sb_info
 *sbi, int devi)
        unsigned int max_open_zones;
        int ret;
-    if (!f2fs_sb_has_blkzoned(sbi))
-        return 0;
-
-    if (bdev_is_zoned(FDEV(devi).bdev)) {
-        max_open_zones = bdev_max_open_zones(bdev);
-        if (max_open_zones && (max_open_zones < sbi- 
 >max_open_zones))
-            sbi->max_open_zones = max_open_zones;
-        if (sbi->max_open_zones < F2FS_OPTION(sbi).active_logs) {
-            f2fs_err(sbi,
-                "zoned: max open zones %u is too small, need at
 least %u open zones",
-                sbi->max_open_zones, F2FS_OPTION(sbi).active_logs);
-            return -EINVAL;
-        }
-    }
-
        zone_sectors = bdev_zone_sectors(bdev);

       if (sbi->blocks_per_blkz && sbi->blocks_per_blkz != SECTOR_TO_BLOCK(zone_sectors))

fs/f2fs/super.c +4 -0
@@ -4378,6 +4363,27 @@ static int init_blkz_info(struct f2fs_sb_info
 *sbi, int devi)
        if (nr_sectors & (zone_sectors - 1))
            FDEV(devi).nr_blkz++;
+    max_open_zones = bdev_max_open_zones(bdev);
+    if (!max_open_zones) {
+        /*
+         * SSDs require max_open_zones > 0 to be mountable.
Quoted 8 lines

fs/f2fs/super.c static int init_blkz_info(struct f2fs_sb_info *sbi, int devi) · line 4375

Quoted 8 lines
fs/f2fs/super.c +6 -0
+         * For HDDs, if max_open_zones is reported as 0, it doesn't
 matter,
+         * set it to FDEV(devi).nr_blkz.
+         */
+        if (bdev_nonrot(bdev)) {
+            f2fs_err(sbi, "zoned: SSD device %s without open zones",
 FDEV(devi).path);
+            return -EINVAL;

Oh, so, for conventional UFS, it will go into this path as SSD w/ zero open zone?

Quoted 4 lines

Any way to distinguish that?

Thanks,

sbi->max_open_zones might be classified into 4 cases:

1. For non rotational devices that have both conventional zones and sequential zones, we should still ensure that max_open_zones > 0. If the

# of sequential zones exceeds max_open_zones, we still need to guarantee
that max_open_zones >= F2FS_OPTION(sbi).active_logs.

I tested this with null_blk by emulating a device that has 10 conventional zones and 4 sequential zones, and the filesystem can be formatted successfully. In this case, the filesystem should also be mountable, and sbi->max_open_zones should be 14. However, if zone_max_open is set to 3, the filesystem cannot be mounted.

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

#modprobe null_blk nr_devices=1 zoned=1  zone_nr_conv=10  zone_size=1024 gb=14 bs=4096 rotational=0 zone_max_open=4
#mkfs.f2fs -m -c /dev/nullb0 /dev/vda -f

So, sbi->max_open_zones might be # of max_open_zones or '# of sequential zones' + '# of conventional zones'.

This scenario has already accounted for in disk_update_zone_resources(). My earlier understanding was incorrect. lim.max_open_zones == 0 indicates no open zones limitted. Sorry for bothering.

/*
* Some devices can advertise zone resource limits that are larger than

* the number of sequential zones of the zoned block device, e.g. a

* small ZNS namespace. For such case, assume that the zoned device has

* no zone resource limits.
*/
nr_seq_zones = disk->nr_zones - args->nr_conv_zones;

if (lim.max_open_zones >= nr_seq_zones)

	lim.max_open_zones = 0;

Yongpeng,

Quoted 9 lines
Quoted 5 lines
Quoted 2 lines

2. For non rotational devices which only have conventional zones, I'm not sure whether there are zoned flash devices that provide only

I guess this is a similar case, we should not let mount() fail for such case, right?

Yes, it should be moutable. I'll take all these cases into account in the v3 patch.

No changes required.

Quoted 59 lines
Quoted 3 lines

- modprobe null_blk nr_devices=1 zoned=1 zone_nr_conv=512 zone_size=2 \
gb=1 bs=4096 rotational=0 zone_max_open=6

This scenario cannot be emulated with null_blk. There must be at least 1 sequential zone, and zone_max_open is greater than # of sequential zones, whereas in reality max_open_zones is 0.

Yongpeng,

Quoted 42 lines

- mkfs.f2fs -m /dev/nullb0
- mount /dev/nullb0 /mnt/f2fs

Thanks,

Quoted 5 lines

conventional zones. If such devices do exist, then returning -EINVAL is indeed not appropriate. sbi->max_open_zones should be # of conventional zones.

3. For non rotational devices which only have sequential zones, sbi-

Quoted 29 lines
Quoted 1 line

max_open_zones should be # max_open_zones.

4. For rotational devices, sbi->max_open_zones should be # zones or max_open_zones.

Am I missing any other cases?

Yongpeng,

Quoted 18 lines
Quoted 18 lines
Quoted 18 lines
fs/f2fs/super.c +7 -0
+        }
+        max_open_zones = FDEV(devi).nr_blkz;
+    }
+    sbi->max_open_zones = min_t(unsigned int, max_open_zones, sbi-
 > max_open_zones);
+    if (sbi->max_open_zones < F2FS_OPTION(sbi).active_logs) {
+        f2fs_err(sbi,
+            "zoned: max open zones %u is too small, need at least %u

open zones",
+            sbi->max_open_zones, F2FS_OPTION(sbi).active_logs); +        return -EINVAL;
+    }
+
       FDEV(devi).blkz_seq = f2fs_kvzalloc(sbi, BITS_TO_LONGS(FDEV(devi).nr_blkz)
                       * sizeof(unsigned long),

Signature · 1 line
2.43.0
Quoted 4 lines

_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

Quoted 4 lines

_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

#11 lore raw

Re: [f2fs-dev] [PATCH v2 3/3] f2fs: fix handling of zoned block devices with max_open_zones == 0

In reply to Yongpeng Yang
Quoted 124 lines · Yongpeng Yang
Quoted 109 lines · On 11/15/2025 7:36 PM, Chao Yu via Linux-f2fs-devel wrote:
Quoted 108 lines · Yongpeng Yang
Quoted 85 lines · On 11/14/25 08:51, Chao Yu via Linux-f2fs-devel wrote:
Quoted 72 lines · Jaegeuk Kim

This breaks the device giving 0 open zone which was working. Hence, I dropped
the change.

Quoted 67 lines · Yongpeng Yang

From: Yongpeng Yang <[email protected]>

When emulating a ZNS SSD on qemu with zoned.max_open set to 0, the F2FS can still be mounted successfully. The sysfs entry shows sbi->max_open_zones as UINT_MAX.

root@fedora-vm:~# cat /sys/block/nvme0n1/queue/zoned
host-managed
root@fedora-vm:~# cat /sys/block/nvme0n1/queue/max_open_zones
0
root@fedora-vm:~# mkfs.f2fs -m -c /dev/nvme0n1 /dev/vda
root@fedora-vm:~# mount /dev/vda /mnt/f2fs/
root@fedora-vm:~# cat /sys/fs/f2fs/vda/max_open_zones
4294967295

The root cause is that sbi->max_open_zones is initialized to UINT_MAX and only updated when the device’s max_open_zones is greater than 0. However, both the scsi driver (sd_zbc_read_zones may assigns 0 to device's max_open_zones) and the nvme driver (nvme_query_zone_info don't check max_open_zones) allow max_open_zones to be 0.

This patch fixes the issue by preventing mounting on zoned SSDs when max_open_zones is 0, while still allowing SMR HDDs to be mounted. init_blkz_info() is only called by f2fs_scan_devices(), and the blkzoned feature has already been checked there. So, this patch also remove redundant zoned device checks.

---
   fs/f2fs/super.c | 36 +++++++++++++++++++++---------------

   1 file changed, 21 insertions(+), 15 deletions(-)
fs/f2fs/super.c +0 -15
index db7afb806411..6dc8945e24af 100644
@@ -4353,21 +4353,6 @@ static int init_blkz_info(struct f2fs_sb_info
 *sbi, int devi)
        unsigned int max_open_zones;
        int ret;
-    if (!f2fs_sb_has_blkzoned(sbi))
-        return 0;
-
-    if (bdev_is_zoned(FDEV(devi).bdev)) {
-        max_open_zones = bdev_max_open_zones(bdev);
-        if (max_open_zones && (max_open_zones < sbi->max_open_zones))
-            sbi->max_open_zones = max_open_zones;
-        if (sbi->max_open_zones < F2FS_OPTION(sbi).active_logs) {
-            f2fs_err(sbi,
-                "zoned: max open zones %u is too small, need at
 least %u open zones",
-                sbi->max_open_zones, F2FS_OPTION(sbi).active_logs);
-            return -EINVAL;
-        }
-    }
-
        zone_sectors = bdev_zone_sectors(bdev);

       if (sbi->blocks_per_blkz && sbi->blocks_per_blkz != SECTOR_TO_BLOCK(zone_sectors))

fs/f2fs/super.c +4 -0
@@ -4378,6 +4363,27 @@ static int init_blkz_info(struct f2fs_sb_info
 *sbi, int devi)
        if (nr_sectors & (zone_sectors - 1))
            FDEV(devi).nr_blkz++;
+    max_open_zones = bdev_max_open_zones(bdev);
+    if (!max_open_zones) {
+        /*
+         * SSDs require max_open_zones > 0 to be mountable.
Quoted 8 lines

fs/f2fs/super.c static int init_blkz_info(struct f2fs_sb_info *sbi, int devi) · line 4375

Quoted 8 lines
fs/f2fs/super.c +6 -0
+         * For HDDs, if max_open_zones is reported as 0, it doesn't
 matter,
+         * set it to FDEV(devi).nr_blkz.
+         */
+        if (bdev_nonrot(bdev)) {
+            f2fs_err(sbi, "zoned: SSD device %s without open zones",
 FDEV(devi).path);
+            return -EINVAL;

Oh, so, for conventional UFS, it will go into this path as SSD w/ zero open zone?

Quoted 4 lines

Any way to distinguish that?

Thanks,

sbi->max_open_zones might be classified into 4 cases:

1. For non rotational devices that have both conventional zones and sequential zones, we should still ensure that max_open_zones > 0. If the

# of sequential zones exceeds max_open_zones, we still need to guarantee
that max_open_zones >= F2FS_OPTION(sbi).active_logs.

I tested this with null_blk by emulating a device that has 10 conventional zones and 4 sequential zones, and the filesystem can be formatted successfully. In this case, the filesystem should also be mountable, and sbi->max_open_zones should be 14. However, if zone_max_open is set to 3, the filesystem cannot be mounted.

#modprobe null_blk nr_devices=1 zoned=1  zone_nr_conv=10  zone_size=1024 gb=14 bs=4096 rotational=0 zone_max_open=4
#mkfs.f2fs -m -c /dev/nullb0 /dev/vda -f

Quoted 8 lines
Quoted 5 lines

So, sbi->max_open_zones might be # of max_open_zones or '# of sequential zones' + '# of conventional zones'.

2. For non rotational devices which only have conventional zones, I'm not sure whether there are zoned flash devices that provide only

I guess this is a similar case, we should not let mount() fail for such case, right?

Yes, it should be moutable. I'll take all these cases into account in the v3 patch.

Quoted 1 line
Quoted 5 lines
Quoted 2 lines

- modprobe null_blk nr_devices=1 zoned=1 zone_nr_conv=512 zone_size=2 \
gb=1 bs=4096 rotational=0 zone_max_open=6

This scenario cannot be emulated with null_blk. There must be at least 1 sequential zone, and zone_max_open is greater than # of sequential

Oh, I see.

root@localhost:~# dump.f2fs -d 3 /dev/nullb0
Info: Debug level = 3
[f2fs_check_zones: 355] Zone 00000: Conventional, cond 0x0 (Not-write-pointer), sector 0, 4096 sectors
...
[f2fs_check_zones: 355] Zone 00510: Conventional, cond 0x0 (Not-write-pointer), sector 2088960, 4096 sectors
[f2fs_check_zones: 366] Zone 00511: type 0x2 (Sequential-write-required), cond 0x1 (Empty), need_reset 0, non_seq 0, sector 2093056, 4096 sectors, capacity 4096, wp sector 2093056

I may suffer different failure during mounting a successfully formatted nullblk device.

[  346.143520] F2FS-fs (nullb0): Magic Mismatch, valid(0xf2f52010) - read(0x0)
[  346.143526] F2FS-fs (nullb0): Can't find valid F2FS filesystem in 1th superblock
[  346.146159] F2FS-fs (nullb0): Magic Mismatch, valid(0xf2f52010) - read(0x0)
[  346.146162] F2FS-fs (nullb0): Can't find valid F2FS filesystem in 2th superblock

Thanks,

Quoted 51 lines

zones, whereas in reality max_open_zones is 0.

Yongpeng,

Quoted 46 lines

- mkfs.f2fs -m /dev/nullb0
- mount /dev/nullb0 /mnt/f2fs

Thanks,

Quoted 5 lines

conventional zones. If such devices do exist, then returning -EINVAL is indeed not appropriate. sbi->max_open_zones should be # of conventional zones.

3. For non rotational devices which only have sequential zones, sbi-

Quoted 29 lines
Quoted 1 line

max_open_zones should be # max_open_zones.

4. For rotational devices, sbi->max_open_zones should be # zones or max_open_zones.

Am I missing any other cases?

Yongpeng,

Quoted 18 lines
Quoted 18 lines
Quoted 18 lines
fs/f2fs/super.c +7 -0
+        }
+        max_open_zones = FDEV(devi).nr_blkz;
+    }
+    sbi->max_open_zones = min_t(unsigned int, max_open_zones, sbi-
 > max_open_zones);
+    if (sbi->max_open_zones < F2FS_OPTION(sbi).active_logs) {
+        f2fs_err(sbi,
+            "zoned: max open zones %u is too small, need at least %u

open zones",
+            sbi->max_open_zones, F2FS_OPTION(sbi).active_logs); +        return -EINVAL;
+    }
+
       FDEV(devi).blkz_seq = f2fs_kvzalloc(sbi, BITS_TO_LONGS(FDEV(devi).nr_blkz)
                       * sizeof(unsigned long),
--
2.43.0

_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

Reviewed-by Chao Yu on v2 1/3
#12 lore raw
In reply to Yongpeng Yang
Quoted 9 lines · Yongpeng Yang

From: Yongpeng Yang <[email protected]>

The usage of unusable_blocks_per_sec is already wrapped by CONFIG_BLK_DEV_ZONED, except for its declaration and the definitions of CAP_BLKS_PER_SEC and CAP_SEGS_PER_SEC. This patch ensures that all code related to unusable_blocks_per_sec is properly wrapped under the CONFIG_BLK_DEV_ZONED option.

Thanks,

_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

#13 lore raw
In reply to Yongpeng Yang

Hello:

This series was applied to jaegeuk/f2fs.git (dev)
by Jaegeuk Kim <[email protected]>:

Quoted 9 lines · On Mon, 10 Nov 2025 16:22:21 +0800 you wrote:

From: Yongpeng Yang <[email protected]>

The usage of unusable_blocks_per_sec is already wrapped by CONFIG_BLK_DEV_ZONED, except for its declaration and the definitions of CAP_BLKS_PER_SEC and CAP_SEGS_PER_SEC. This patch ensures that all code related to unusable_blocks_per_sec is properly wrapped under the CONFIG_BLK_DEV_ZONED option.

[...]

Here is the summary with links:
- [f2fs-dev,v2,1/3] f2fs: wrap all unusable_blocks_per_sec code in CONFIG_BLK_DEV_ZONED

    https://git.kernel.org/jaegeuk/f2fs/c/9e1244d45e7d
  - [f2fs-dev,v2,2/3] f2fs: add a sysfs entry to show max open zones
    https://git.kernel.org/jaegeuk/f2fs/c/823190ca76b0

- [f2fs-dev,v2,3/3] f2fs: fix handling of zoned block devices with max_open_zones == 0 (no matching commit)

You are awesome, thank you!

Signature · 10 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html




_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel