Skip to contentSkip to conversation

f2fs: fix zoned block device information initialization

PATCH Superseded Chao Yu 2 participants 3 messages Mar 28, 2024 – Apr 7, 2024 F2FS file system

v6 of 7 Superseded Latest is v7 →

lore
Share & tools
lore

Chao Yu

author maintainer
#0 lore raw

PATCH v6 1/1 f2fs: fix zoned block device information initialization

From: Wenjie Qi <[email protected]>

If the max open zones of zoned devices are less than the active logs of F2FS, the device may error due to insufficient zone resources when multiple active logs are being written at the same time.

---
v6:
- add check condition to avoid remount failure.

 fs/f2fs/f2fs.h  |  1 +
 fs/f2fs/super.c | 27 +++++++++++++++++++++++++++
 2 files changed, 28 insertions(+)
fs/f2fs/f2fs.h +1 -0
index 0550929dc6e5..694f8a52cb84 100644
@@ -1559,6 +1559,7 @@ struct f2fs_sb_info {
 
 #ifdef CONFIG_BLK_DEV_ZONED
 	unsigned int blocks_per_blkz;		/* F2FS blocks per zone */
+	unsigned int max_open_zones;		/* max open zone resources of the zoned device */
 #endif
 
 	/* for node-related operations */
fs/f2fs/super.c +27 -0
index 7c45929671ad..642540782471 100644
@@ -2326,6 +2326,17 @@ static int f2fs_remount(struct super_block *sb, int *flags, char *data)
 	if (err)
 		goto restore_opts;
 
+#ifdef CONFIG_BLK_DEV_ZONED
+	if (f2fs_is_multi_device(sbi) &&
+		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);
+		err = -EINVAL;
+		goto restore_opts;
+	}
+#endif
+
 	/* flush outstanding errors before changing fs state */
 	flush_work(&sbi->s_error_work);
 
@@ -3868,11 +3879,24 @@ static int init_blkz_info(struct f2fs_sb_info *sbi, int devi)
 	sector_t nr_sectors = bdev_nr_sectors(bdev);
 	struct f2fs_report_zones_args rep_zone_arg;
 	u64 zone_sectors;
+	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))
@@ -4186,6 +4210,9 @@ static int f2fs_scan_devices(struct f2fs_sb_info *sbi)
 
 	logical_blksize = bdev_logical_block_size(sbi->sb->s_bdev);
 	sbi->aligned_blksize = true;
+#ifdef CONFIG_BLK_DEV_ZONED
+	sbi->max_open_zones = UINT_MAX;
+#endif
 
 	for (i = 0; i < max_devices; i++) {
 		if (i == 0)
Signature · 1 line
2.40.1
#1 lore raw
Quoted 34 lines · Chao Yu

From: Wenjie Qi <[email protected]>

If the max open zones of zoned devices are less than the active logs of F2FS, the device may error due to insufficient zone resources when multiple active logs are being written at the same time.

---
v6:
- add check condition to avoid remount failure.

 fs/f2fs/f2fs.h  |  1 +
 fs/f2fs/super.c | 27 +++++++++++++++++++++++++++
 2 files changed, 28 insertions(+)
fs/f2fs/f2fs.h +1 -0
index 0550929dc6e5..694f8a52cb84 100644
@@ -1559,6 +1559,7 @@ struct f2fs_sb_info {
 
 #ifdef CONFIG_BLK_DEV_ZONED
        unsigned int blocks_per_blkz;           /* F2FS blocks per zone */
+       unsigned int max_open_zones;            /* max open zone resources of the zoned device */
 #endif
 
        /* for node-related operations */
fs/f2fs/super.c +0 -0
index 7c45929671ad..642540782471 100644

fs/f2fs/super.c static int f2fs_remount(struct super_block *sb, int *flags, char *data) · line 2330

Quoted 5 lines
fs/f2fs/super.c +2 -0
@@ -2326,6 +2326,17 @@ static int f2fs_remount(struct super_block *sb, int *flags, char *data)
        if (err)
                goto restore_opts;
 
+#ifdef CONFIG_BLK_DEV_ZONED
+       if (f2fs_is_multi_device(sbi) &&

Why do we check multiple devices' condition here?

Thanks,

Quoted 56 lines
fs/f2fs/super.c +25 -1
+               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);
+               err = -EINVAL;
+               goto restore_opts;
+       }
+#endif
+
        /* flush outstanding errors before changing fs state */
        flush_work(&sbi->s_error_work);
 
@@ -3868,11 +3879,24 @@ static int init_blkz_info(struct f2fs_sb_info *sbi, int devi)
        sector_t nr_sectors = bdev_nr_sectors(bdev);
        struct f2fs_report_zones_args rep_zone_arg;
        u64 zone_sectors;
+       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))
@@ -4186,6 +4210,9 @@ static int f2fs_scan_devices(struct f2fs_sb_info *sbi)
 
        logical_blksize = bdev_logical_block_size(sbi->sb->s_bdev);
        sbi->aligned_blksize = true;
+#ifdef CONFIG_BLK_DEV_ZONED
+       sbi->max_open_zones = UINT_MAX;
+#endif
 
        for (i = 0; i < max_devices; i++) {
                if (i == 0)
--

2.40.1

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

author maintainer
#2 lore raw
Quoted 38 lines · Daeho Jeong
Quoted 37 lines · Chao Yu

From: Wenjie Qi <[email protected]>

If the max open zones of zoned devices are less than the active logs of F2FS, the device may error due to insufficient zone resources when multiple active logs are being written at the same time.

---
v6:
- add check condition to avoid remount failure.

  fs/f2fs/f2fs.h  |  1 +
  fs/f2fs/super.c | 27 +++++++++++++++++++++++++++
  2 files changed, 28 insertions(+)
fs/f2fs/f2fs.h +1 -0
index 0550929dc6e5..694f8a52cb84 100644
@@ -1559,6 +1559,7 @@ struct f2fs_sb_info {
 
  #ifdef CONFIG_BLK_DEV_ZONED
         unsigned int blocks_per_blkz;           /* F2FS blocks per zone */
+       unsigned int max_open_zones;            /* max open zone resources of the zoned device */
  #endif
 
         /* for node-related operations */
fs/f2fs/super.c +0 -0
index 7c45929671ad..642540782471 100644
@@ -2326,6 +2326,17 @@ static int f2fs_remount(struct super_block *sb, int *flags, char *data)
         if (err)
                 goto restore_opts;
 
Quoted 4 lines

fs/f2fs/super.c static int f2fs_remount(struct super_block *sb, int *flags, char *data) · line 2330

Quoted 2 lines
fs/f2fs/super.c +2 -0
+#ifdef CONFIG_BLK_DEV_ZONED
+       if (f2fs_is_multi_device(sbi) &&

Why do we check multiple devices' condition here?

Oh, it needs to check f2fs_sb_has_blkzoned(), right?

Thanks,

Quoted 59 lines

Thanks,

Quoted 56 lines
fs/f2fs/super.c +25 -1
+               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);
+               err = -EINVAL;
+               goto restore_opts;
+       }
+#endif
+
         /* flush outstanding errors before changing fs state */
         flush_work(&sbi->s_error_work);
 
@@ -3868,11 +3879,24 @@ static int init_blkz_info(struct f2fs_sb_info *sbi, int devi)
         sector_t nr_sectors = bdev_nr_sectors(bdev);
         struct f2fs_report_zones_args rep_zone_arg;
         u64 zone_sectors;
+       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))
@@ -4186,6 +4210,9 @@ static int f2fs_scan_devices(struct f2fs_sb_info *sbi)
 
         logical_blksize = bdev_logical_block_size(sbi->sb->s_bdev);
         sbi->aligned_blksize = true;
+#ifdef CONFIG_BLK_DEV_ZONED
+       sbi->max_open_zones = UINT_MAX;
+#endif
 
         for (i = 0; i < max_devices; i++) {
                 if (i == 0)
--

2.40.1

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