linux-f2fs-devel.lists.sourceforge.net archive mirror
 help / color / mirror / Atom feed
* [f2fs-dev] [PATCH] f2fs: check zone type before sending async reset zone command
@ 2023-08-04  9:15 Shin'ichiro Kawasaki via Linux-f2fs-devel
  2023-08-07  2:34 ` Chao Yu
  0 siblings, 1 reply; 2+ messages in thread
From: Shin'ichiro Kawasaki via Linux-f2fs-devel @ 2023-08-04  9:15 UTC (permalink / raw)
  To: Jaegeuk Kim, Chao Yu, linux-f2fs-devel
  Cc: Shin'ichiro Kawasaki, Damien Le Moal

The commit 25f9080576b9 ("f2fs: add async reset zone command support")
introduced "async reset zone commands" by calling
__submit_zone_reset_cmd() in async discard operations. However,
__submit_zone_reset_cmd() is called regardless of zone type of discard
target zone. When devices have conventional zones, zone reset commands
are sent to the conventional zones and cause I/O errors.

Avoid the I/O errors by checking that the discard target zone type is
sequential write required. If not, handle the discard operation in same
manner as non-zoned, regular block devices. For that purpose, add a new
helper function f2fs_bdev_index() which gets index of the zone reset
target device.

Fixes: 25f9080576b9 ("f2fs: add async reset zone command support")
Signed-off-by: Shin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>
---
 fs/f2fs/f2fs.h    | 16 ++++++++++++++++
 fs/f2fs/segment.c | 35 +++++++++++++++++++++++++----------
 2 files changed, 41 insertions(+), 10 deletions(-)

diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
index c7cb2177b252..73fbc9c5f5b3 100644
--- a/fs/f2fs/f2fs.h
+++ b/fs/f2fs/f2fs.h
@@ -4423,6 +4423,22 @@ static inline bool f2fs_blkz_is_seq(struct f2fs_sb_info *sbi, int devi,
 }
 #endif
 
+static inline int f2fs_bdev_index(struct f2fs_sb_info *sbi,
+				  struct block_device *bdev)
+{
+	int i;
+
+	if (!f2fs_is_multi_device(sbi))
+		return 0;
+
+	for (i = 0; i < sbi->s_ndevs; i++)
+		if (FDEV(i).bdev == bdev)
+			return i;
+
+	WARN_ON(1);
+	return -1;
+}
+
 static inline bool f2fs_hw_should_discard(struct f2fs_sb_info *sbi)
 {
 	return f2fs_sb_has_blkzoned(sbi);
diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c
index 0457d620011f..668cf709927f 100644
--- a/fs/f2fs/segment.c
+++ b/fs/f2fs/segment.c
@@ -1257,7 +1257,13 @@ static int __submit_discard_cmd(struct f2fs_sb_info *sbi,
 		return 0;
 
 #ifdef CONFIG_BLK_DEV_ZONED
-	if (f2fs_sb_has_blkzoned(sbi) && bdev_is_zoned(bdev)) {
+	int devi = f2fs_bdev_index(sbi, bdev);
+
+	if (devi < 0)
+		return -EINVAL;
+
+	if (f2fs_sb_has_blkzoned(sbi) && bdev_is_zoned(bdev) &&
+		f2fs_blkz_is_seq(sbi, devi, dc->di.start)) {
 		__submit_zone_reset_cmd(sbi, dc, flag, wait_list, issued);
 		return 0;
 	}
@@ -1785,15 +1791,24 @@ static void f2fs_wait_discard_bio(struct f2fs_sb_info *sbi, block_t blkaddr)
 	dc = __lookup_discard_cmd(sbi, blkaddr);
 #ifdef CONFIG_BLK_DEV_ZONED
 	if (dc && f2fs_sb_has_blkzoned(sbi) && bdev_is_zoned(dc->bdev)) {
-		/* force submit zone reset */
-		if (dc->state == D_PREP)
-			__submit_zone_reset_cmd(sbi, dc, REQ_SYNC,
-						&dcc->wait_list, NULL);
-		dc->ref++;
-		mutex_unlock(&dcc->cmd_lock);
-		/* wait zone reset */
-		__wait_one_discard_bio(sbi, dc);
-		return;
+		int devi = f2fs_bdev_index(sbi, dc->bdev);
+
+		if (devi < 0) {
+			mutex_unlock(&dcc->cmd_lock);
+			return;
+		}
+
+		if (f2fs_blkz_is_seq(sbi, devi, dc->di.start)) {
+			/* force submit zone reset */
+			if (dc->state == D_PREP)
+				__submit_zone_reset_cmd(sbi, dc, REQ_SYNC,
+							&dcc->wait_list, NULL);
+			dc->ref++;
+			mutex_unlock(&dcc->cmd_lock);
+			/* wait zone reset */
+			__wait_one_discard_bio(sbi, dc);
+			return;
+		}
 	}
 #endif
 	if (dc) {
-- 
2.40.1



_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

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

* Re: [f2fs-dev] [PATCH] f2fs: check zone type before sending async reset zone command
  2023-08-04  9:15 [f2fs-dev] [PATCH] f2fs: check zone type before sending async reset zone command Shin'ichiro Kawasaki via Linux-f2fs-devel
@ 2023-08-07  2:34 ` Chao Yu
  0 siblings, 0 replies; 2+ messages in thread
From: Chao Yu @ 2023-08-07  2:34 UTC (permalink / raw)
  To: Shin'ichiro Kawasaki, Jaegeuk Kim, Chao Yu, linux-f2fs-devel
  Cc: Damien Le Moal

On 2023/8/4 17:15, Shin'ichiro Kawasaki via Linux-f2fs-devel wrote:
> The commit 25f9080576b9 ("f2fs: add async reset zone command support")
> introduced "async reset zone commands" by calling
> __submit_zone_reset_cmd() in async discard operations. However,
> __submit_zone_reset_cmd() is called regardless of zone type of discard
> target zone. When devices have conventional zones, zone reset commands
> are sent to the conventional zones and cause I/O errors.
> 
> Avoid the I/O errors by checking that the discard target zone type is
> sequential write required. If not, handle the discard operation in same
> manner as non-zoned, regular block devices. For that purpose, add a new
> helper function f2fs_bdev_index() which gets index of the zone reset
> target device.
> 
> Fixes: 25f9080576b9 ("f2fs: add async reset zone command support")
> Signed-off-by: Shin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>

Reviewed-by: Chao Yu <chao@kernel.org>

Thanks,



_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

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

end of thread, other threads:[~2023-08-07  2:34 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-08-04  9:15 [f2fs-dev] [PATCH] f2fs: check zone type before sending async reset zone command Shin'ichiro Kawasaki via Linux-f2fs-devel
2023-08-07  2:34 ` Chao Yu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).