linux-block.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH V3 0/6] block: ignore __blkdev_issue_discard() ret value
@ 2025-11-24 23:48 Chaitanya Kulkarni
  2025-11-24 23:48 ` [PATCH V3 1/6] block: ignore discard return value Chaitanya Kulkarni
                   ` (9 more replies)
  0 siblings, 10 replies; 28+ messages in thread
From: Chaitanya Kulkarni @ 2025-11-24 23:48 UTC (permalink / raw)
  To: axboe, agk, snitzer, mpatocka, song, yukuai, hch, sagi, kch,
	jaegeuk, chao, cem
  Cc: linux-block, linux-kernel, dm-devel, linux-raid, linux-nvme,
	linux-f2fs-devel, linux-xfs, bpf, Chaitanya Kulkarni

Hi,

__blkdev_issue_discard() only returns value 0, that makes post call
error checking code dead. This patch series revmoes this dead code at
all the call sites and adjust the callers.

Please note that it doesn't change the return type of the function from
int to void in this series, it will be done once this series gets merged
smoothly.

For f2fs and xfs I've ran following test which includes discard
they produce same PASS and FAIL output with and without this patch
series.

  for-next (lblk-fnext)    discard-ret (lblk-discard)
  ---------------------    --------------------------
  FAIL f2fs/008            FAIL f2fs/008
  FAIL f2fs/014            FAIL f2fs/014
  FAIL f2fs/015            FAIL f2fs/015
  PASS f2fs/017            PASS f2fs/017
  PASS xfs/016             PASS xfs/016
  PASS xfs/288             PASS xfs/288
  PASS xfs/432             PASS xfs/432
  PASS xfs/449             PASS xfs/449
  PASS xfs/513             PASS xfs/513
  PASS generic/033         PASS generic/033
  PASS generic/038         PASS generic/038
  PASS generic/098         PASS generic/098
  PASS generic/224         PASS generic/224
  PASS generic/251         PASS generic/251
  PASS generic/260         PASS generic/260
  PASS generic/288         PASS generic/288
  PASS generic/351         PASS generic/351
  PASS generic/455         PASS generic/455
  PASS generic/457         PASS generic/457
  PASS generic/470         PASS generic/470
  PASS generic/482         PASS generic/482
  PASS generic/500         PASS generic/500
  PASS generic/537         PASS generic/537
  PASS generic/608         PASS generic/608
  PASS generic/619         PASS generic/619
  PASS generic/746         PASS generic/746
  PASS generic/757         PASS generic/757
 
For NVMeOF taret I've testing blktest with nvme_trtype=nvme_loop
and all the testcases are passing.

 -ck

Changes from V2:-

1. Add Reviewed-by: tags.
2. Split patch 2 into two separate patches dm and md.
3. Condense __blkdev_issue_discard() parameters for in nvmet patch.
4. Condense __blkdev_issue_discard() parameters for in f2fs patch.

Chaitanya Kulkarni (6):
  block: ignore discard return value
  md: ignore discard return value
  dm: ignore discard return value
  nvmet: ignore discard return value
  f2fs: ignore discard return value
  xfs: ignore discard return value

 block/blk-lib.c                   |  6 +++---
 drivers/md/dm-thin.c              | 12 +++++-------
 drivers/md/md.c                   |  4 ++--
 drivers/nvme/target/io-cmd-bdev.c | 28 +++++++---------------------
 fs/f2fs/segment.c                 | 10 +++-------
 fs/xfs/xfs_discard.c              | 27 +++++----------------------
 fs/xfs/xfs_discard.h              |  2 +-
 7 files changed, 26 insertions(+), 63 deletions(-)

-- 
2.40.0


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

* [PATCH V3 1/6] block: ignore discard return value
  2025-11-24 23:48 [PATCH V3 0/6] block: ignore __blkdev_issue_discard() ret value Chaitanya Kulkarni
@ 2025-11-24 23:48 ` Chaitanya Kulkarni
  2025-11-25 17:38   ` Jens Axboe
  2025-11-24 23:48 ` [PATCH V3 2/6] md: " Chaitanya Kulkarni
                   ` (8 subsequent siblings)
  9 siblings, 1 reply; 28+ messages in thread
From: Chaitanya Kulkarni @ 2025-11-24 23:48 UTC (permalink / raw)
  To: axboe, agk, snitzer, mpatocka, song, yukuai, hch, sagi, kch,
	jaegeuk, chao, cem
  Cc: linux-block, linux-kernel, dm-devel, linux-raid, linux-nvme,
	linux-f2fs-devel, linux-xfs, bpf, Chaitanya Kulkarni,
	Johannes Thumshirn, Martin K . Petersen

__blkdev_issue_discard() always returns 0, making the error check
in blkdev_issue_discard() dead code.

In function blkdev_issue_discard() initialize ret = 0, remove ret
assignment from __blkdev_issue_discard(), rely on bio == NULL check to
call submit_bio_wait(), preserve submit_bio_wait() error handling, and
preserve -EOPNOTSUPP to 0 mapping.

Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Reviewed-by: Martin K. Petersen <martin.petersen@oracle.com>
Signed-off-by: Chaitanya Kulkarni <ckulkarnilinux@gmail.com>
---
 block/blk-lib.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/block/blk-lib.c b/block/blk-lib.c
index 3030a772d3aa..19e0203cc18a 100644
--- a/block/blk-lib.c
+++ b/block/blk-lib.c
@@ -87,11 +87,11 @@ int blkdev_issue_discard(struct block_device *bdev, sector_t sector,
 {
 	struct bio *bio = NULL;
 	struct blk_plug plug;
-	int ret;
+	int ret = 0;
 
 	blk_start_plug(&plug);
-	ret = __blkdev_issue_discard(bdev, sector, nr_sects, gfp_mask, &bio);
-	if (!ret && bio) {
+	__blkdev_issue_discard(bdev, sector, nr_sects, gfp_mask, &bio);
+	if (bio) {
 		ret = submit_bio_wait(bio);
 		if (ret == -EOPNOTSUPP)
 			ret = 0;
-- 
2.40.0


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

* [PATCH V3 2/6] md: ignore discard return value
  2025-11-24 23:48 [PATCH V3 0/6] block: ignore __blkdev_issue_discard() ret value Chaitanya Kulkarni
  2025-11-24 23:48 ` [PATCH V3 1/6] block: ignore discard return value Chaitanya Kulkarni
@ 2025-11-24 23:48 ` Chaitanya Kulkarni
  2025-11-24 23:48 ` [PATCH V3 3/6] dm: " Chaitanya Kulkarni
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 28+ messages in thread
From: Chaitanya Kulkarni @ 2025-11-24 23:48 UTC (permalink / raw)
  To: axboe, agk, snitzer, mpatocka, song, yukuai, hch, sagi, kch,
	jaegeuk, chao, cem
  Cc: linux-block, linux-kernel, dm-devel, linux-raid, linux-nvme,
	linux-f2fs-devel, linux-xfs, bpf, Chaitanya Kulkarni,
	Martin K . Petersen, Johannes Thumshirn

__blkdev_issue_discard() always returns 0, making all error checking at
call sites dead code.

Simplify md to only check !discard_bio by ignoring the
__blkdev_issue_discard() value.

Reviewed-by: Martin K. Petersen <martin.petersen@oracle.com>
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Chaitanya Kulkarni <ckulkarnilinux@gmail.com>
---
 drivers/md/md.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/md/md.c b/drivers/md/md.c
index 7b5c5967568f..aeb62df39828 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -9132,8 +9132,8 @@ void md_submit_discard_bio(struct mddev *mddev, struct md_rdev *rdev,
 {
 	struct bio *discard_bio = NULL;
 
-	if (__blkdev_issue_discard(rdev->bdev, start, size, GFP_NOIO,
-			&discard_bio) || !discard_bio)
+	__blkdev_issue_discard(rdev->bdev, start, size, GFP_NOIO, &discard_bio);
+	if (!discard_bio)
 		return;
 
 	bio_chain(discard_bio, bio);
-- 
2.40.0


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

* [PATCH V3 3/6] dm: ignore discard return value
  2025-11-24 23:48 [PATCH V3 0/6] block: ignore __blkdev_issue_discard() ret value Chaitanya Kulkarni
  2025-11-24 23:48 ` [PATCH V3 1/6] block: ignore discard return value Chaitanya Kulkarni
  2025-11-24 23:48 ` [PATCH V3 2/6] md: " Chaitanya Kulkarni
@ 2025-11-24 23:48 ` Chaitanya Kulkarni
  2025-11-24 23:48 ` [PATCH V3 4/6] nvmet: " Chaitanya Kulkarni
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 28+ messages in thread
From: Chaitanya Kulkarni @ 2025-11-24 23:48 UTC (permalink / raw)
  To: axboe, agk, snitzer, mpatocka, song, yukuai, hch, sagi, kch,
	jaegeuk, chao, cem
  Cc: linux-block, linux-kernel, dm-devel, linux-raid, linux-nvme,
	linux-f2fs-devel, linux-xfs, bpf, Chaitanya Kulkarni,
	Martin K . Petersen, Johannes Thumshirn

__blkdev_issue_discard() always returns 0, making all error checking
at call sites dead code.

For dm-thin change issue_discard() return type to void, in
passdown_double_checking_shared_status() remove the r assignment from
return value of the issue_discard(), for end_discard() hardcode value of 
r to 0 that matches only value returned from __blkdev_issue_discard().

Reviewed-by: Martin K. Petersen <martin.petersen@oracle.com>
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Chaitanya Kulkarni <ckulkarnilinux@gmail.com>
---
 drivers/md/dm-thin.c | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/drivers/md/dm-thin.c b/drivers/md/dm-thin.c
index c84149ba4e38..77c76f75c85f 100644
--- a/drivers/md/dm-thin.c
+++ b/drivers/md/dm-thin.c
@@ -395,13 +395,13 @@ static void begin_discard(struct discard_op *op, struct thin_c *tc, struct bio *
 	op->bio = NULL;
 }
 
-static int issue_discard(struct discard_op *op, dm_block_t data_b, dm_block_t data_e)
+static void issue_discard(struct discard_op *op, dm_block_t data_b, dm_block_t data_e)
 {
 	struct thin_c *tc = op->tc;
 	sector_t s = block_to_sectors(tc->pool, data_b);
 	sector_t len = block_to_sectors(tc->pool, data_e - data_b);
 
-	return __blkdev_issue_discard(tc->pool_dev->bdev, s, len, GFP_NOIO, &op->bio);
+	__blkdev_issue_discard(tc->pool_dev->bdev, s, len, GFP_NOIO, &op->bio);
 }
 
 static void end_discard(struct discard_op *op, int r)
@@ -1113,9 +1113,7 @@ static void passdown_double_checking_shared_status(struct dm_thin_new_mapping *m
 				break;
 		}
 
-		r = issue_discard(&op, b, e);
-		if (r)
-			goto out;
+		issue_discard(&op, b, e);
 
 		b = e;
 	}
@@ -1188,8 +1186,8 @@ static void process_prepared_discard_passdown_pt1(struct dm_thin_new_mapping *m)
 		struct discard_op op;
 
 		begin_discard(&op, tc, discard_parent);
-		r = issue_discard(&op, m->data_block, data_end);
-		end_discard(&op, r);
+		issue_discard(&op, m->data_block, data_end);
+		end_discard(&op, 0);
 	}
 }
 
-- 
2.40.0


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

* [PATCH V3 4/6] nvmet: ignore discard return value
  2025-11-24 23:48 [PATCH V3 0/6] block: ignore __blkdev_issue_discard() ret value Chaitanya Kulkarni
                   ` (2 preceding siblings ...)
  2025-11-24 23:48 ` [PATCH V3 3/6] dm: " Chaitanya Kulkarni
@ 2025-11-24 23:48 ` Chaitanya Kulkarni
  2025-11-26 10:14   ` [f2fs-dev] " Yongpeng Yang
  2025-11-24 23:48 ` [PATCH V3 5/6] f2fs: " Chaitanya Kulkarni
                   ` (5 subsequent siblings)
  9 siblings, 1 reply; 28+ messages in thread
From: Chaitanya Kulkarni @ 2025-11-24 23:48 UTC (permalink / raw)
  To: axboe, agk, snitzer, mpatocka, song, yukuai, hch, sagi, kch,
	jaegeuk, chao, cem
  Cc: linux-block, linux-kernel, dm-devel, linux-raid, linux-nvme,
	linux-f2fs-devel, linux-xfs, bpf, Chaitanya Kulkarni,
	Martin K . Petersen, Johannes Thumshirn

__blkdev_issue_discard() always returns 0, making the error checking
in nvmet_bdev_discard_range() dead code.

Kill the function nvmet_bdev_discard_range() and call
__blkdev_issue_discard() directly from nvmet_bdev_execute_discard(),
since no error handling is needed anymore for __blkdev_issue_discard()
call.

Reviewed-by: Martin K. Petersen <martin.petersen@oracle.com>
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Chaitanya Kulkarni <ckulkarnilinux@gmail.com>
---
 drivers/nvme/target/io-cmd-bdev.c | 28 +++++++---------------------
 1 file changed, 7 insertions(+), 21 deletions(-)

diff --git a/drivers/nvme/target/io-cmd-bdev.c b/drivers/nvme/target/io-cmd-bdev.c
index 8d246b8ca604..ca7731048940 100644
--- a/drivers/nvme/target/io-cmd-bdev.c
+++ b/drivers/nvme/target/io-cmd-bdev.c
@@ -362,29 +362,14 @@ u16 nvmet_bdev_flush(struct nvmet_req *req)
 	return 0;
 }
 
-static u16 nvmet_bdev_discard_range(struct nvmet_req *req,
-		struct nvme_dsm_range *range, struct bio **bio)
-{
-	struct nvmet_ns *ns = req->ns;
-	int ret;
-
-	ret = __blkdev_issue_discard(ns->bdev,
-			nvmet_lba_to_sect(ns, range->slba),
-			le32_to_cpu(range->nlb) << (ns->blksize_shift - 9),
-			GFP_KERNEL, bio);
-	if (ret && ret != -EOPNOTSUPP) {
-		req->error_slba = le64_to_cpu(range->slba);
-		return errno_to_nvme_status(req, ret);
-	}
-	return NVME_SC_SUCCESS;
-}
-
 static void nvmet_bdev_execute_discard(struct nvmet_req *req)
 {
+	struct nvmet_ns *ns = req->ns;
 	struct nvme_dsm_range range;
 	struct bio *bio = NULL;
+	sector_t nr_sects;
 	int i;
-	u16 status;
+	u16 status = NVME_SC_SUCCESS;
 
 	for (i = 0; i <= le32_to_cpu(req->cmd->dsm.nr); i++) {
 		status = nvmet_copy_from_sgl(req, i * sizeof(range), &range,
@@ -392,9 +377,10 @@ static void nvmet_bdev_execute_discard(struct nvmet_req *req)
 		if (status)
 			break;
 
-		status = nvmet_bdev_discard_range(req, &range, &bio);
-		if (status)
-			break;
+		nr_sects = le32_to_cpu(range.nlb) << (ns->blksize_shift - 9);
+		__blkdev_issue_discard(ns->bdev,
+				nvmet_lba_to_sect(ns, range.slba), nr_sects,
+				GFP_KERNEL, &bio);
 	}
 
 	if (bio) {
-- 
2.40.0


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

* [PATCH V3 5/6] f2fs: ignore discard return value
  2025-11-24 23:48 [PATCH V3 0/6] block: ignore __blkdev_issue_discard() ret value Chaitanya Kulkarni
                   ` (3 preceding siblings ...)
  2025-11-24 23:48 ` [PATCH V3 4/6] nvmet: " Chaitanya Kulkarni
@ 2025-11-24 23:48 ` Chaitanya Kulkarni
  2025-11-25  1:10   ` Chao Yu
  2025-11-26  2:47   ` Chao Yu
  2025-11-24 23:48 ` [PATCH V3 6/6] xfs: " Chaitanya Kulkarni
                   ` (4 subsequent siblings)
  9 siblings, 2 replies; 28+ messages in thread
From: Chaitanya Kulkarni @ 2025-11-24 23:48 UTC (permalink / raw)
  To: axboe, agk, snitzer, mpatocka, song, yukuai, hch, sagi, kch,
	jaegeuk, chao, cem
  Cc: linux-block, linux-kernel, dm-devel, linux-raid, linux-nvme,
	linux-f2fs-devel, linux-xfs, bpf, Chaitanya Kulkarni,
	Martin K . Petersen, Johannes Thumshirn

__blkdev_issue_discard() always returns 0, making the error assignment
in __submit_discard_cmd() dead code.

Initialize err to 0 and remove the error assignment from the
__blkdev_issue_discard() call to err. Move fault injection code into
already present if branch where err is set to -EIO.

This preserves the fault injection behavior while removing dead error
handling.

Reviewed-by: Martin K. Petersen <martin.petersen@oracle.com>
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Chaitanya Kulkarni <ckulkarnilinux@gmail.com>
---
 fs/f2fs/segment.c | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)

diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c
index b45eace879d7..22b736ec9c51 100644
--- a/fs/f2fs/segment.c
+++ b/fs/f2fs/segment.c
@@ -1343,15 +1343,9 @@ static int __submit_discard_cmd(struct f2fs_sb_info *sbi,
 
 		dc->di.len += len;
 
+		err = 0;
 		if (time_to_inject(sbi, FAULT_DISCARD)) {
 			err = -EIO;
-		} else {
-			err = __blkdev_issue_discard(bdev,
-					SECTOR_FROM_BLOCK(start),
-					SECTOR_FROM_BLOCK(len),
-					GFP_NOFS, &bio);
-		}
-		if (err) {
 			spin_lock_irqsave(&dc->lock, flags);
 			if (dc->state == D_PARTIAL)
 				dc->state = D_SUBMIT;
@@ -1360,6 +1354,8 @@ static int __submit_discard_cmd(struct f2fs_sb_info *sbi,
 			break;
 		}
 
+		__blkdev_issue_discard(bdev, SECTOR_FROM_BLOCK(start),
+				SECTOR_FROM_BLOCK(len), GFP_NOFS, &bio);
 		f2fs_bug_on(sbi, !bio);
 
 		/*
-- 
2.40.0


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

* [PATCH V3 6/6] xfs: ignore discard return value
  2025-11-24 23:48 [PATCH V3 0/6] block: ignore __blkdev_issue_discard() ret value Chaitanya Kulkarni
                   ` (4 preceding siblings ...)
  2025-11-24 23:48 ` [PATCH V3 5/6] f2fs: " Chaitanya Kulkarni
@ 2025-11-24 23:48 ` Chaitanya Kulkarni
  2025-11-26  2:37   ` [f2fs-dev] " Yongpeng Yang
  2025-11-25 13:20 ` [PATCH V3 0/6] block: ignore __blkdev_issue_discard() ret value Anuj gupta
                   ` (3 subsequent siblings)
  9 siblings, 1 reply; 28+ messages in thread
From: Chaitanya Kulkarni @ 2025-11-24 23:48 UTC (permalink / raw)
  To: axboe, agk, snitzer, mpatocka, song, yukuai, hch, sagi, kch,
	jaegeuk, chao, cem
  Cc: linux-block, linux-kernel, dm-devel, linux-raid, linux-nvme,
	linux-f2fs-devel, linux-xfs, bpf, Chaitanya Kulkarni,
	Johannes Thumshirn

__blkdev_issue_discard() always returns 0, making all error checking
in XFS discard functions dead code.

Change xfs_discard_extents() return type to void, remove error variable,
error checking, and error logging for the __blkdev_issue_discard() call
in same function.

Update xfs_trim_perag_extents() and xfs_trim_rtgroup_extents() to
ignore the xfs_discard_extents() return value and error checking
code.

Update xfs_discard_rtdev_extents() to ignore __blkdev_issue_discard()
return value and error checking code.

Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Chaitanya Kulkarni <ckulkarnilinux@gmail.com>
---
 fs/xfs/xfs_discard.c | 27 +++++----------------------
 fs/xfs/xfs_discard.h |  2 +-
 2 files changed, 6 insertions(+), 23 deletions(-)

diff --git a/fs/xfs/xfs_discard.c b/fs/xfs/xfs_discard.c
index 6917de832191..b6ffe4807a11 100644
--- a/fs/xfs/xfs_discard.c
+++ b/fs/xfs/xfs_discard.c
@@ -108,7 +108,7 @@ xfs_discard_endio(
  * list. We plug and chain the bios so that we only need a single completion
  * call to clear all the busy extents once the discards are complete.
  */
-int
+void
 xfs_discard_extents(
 	struct xfs_mount	*mp,
 	struct xfs_busy_extents	*extents)
@@ -116,7 +116,6 @@ xfs_discard_extents(
 	struct xfs_extent_busy	*busyp;
 	struct bio		*bio = NULL;
 	struct blk_plug		plug;
-	int			error = 0;
 
 	blk_start_plug(&plug);
 	list_for_each_entry(busyp, &extents->extent_list, list) {
@@ -126,18 +125,10 @@ xfs_discard_extents(
 
 		trace_xfs_discard_extent(xg, busyp->bno, busyp->length);
 
-		error = __blkdev_issue_discard(btp->bt_bdev,
+		__blkdev_issue_discard(btp->bt_bdev,
 				xfs_gbno_to_daddr(xg, busyp->bno),
 				XFS_FSB_TO_BB(mp, busyp->length),
 				GFP_KERNEL, &bio);
-		if (error && error != -EOPNOTSUPP) {
-			xfs_info(mp,
-	 "discard failed for extent [0x%llx,%u], error %d",
-				 (unsigned long long)busyp->bno,
-				 busyp->length,
-				 error);
-			break;
-		}
 	}
 
 	if (bio) {
@@ -148,8 +139,6 @@ xfs_discard_extents(
 		xfs_discard_endio_work(&extents->endio_work);
 	}
 	blk_finish_plug(&plug);
-
-	return error;
 }
 
 /*
@@ -385,9 +374,7 @@ xfs_trim_perag_extents(
 		 * list  after this function call, as it may have been freed by
 		 * the time control returns to us.
 		 */
-		error = xfs_discard_extents(pag_mount(pag), extents);
-		if (error)
-			break;
+		xfs_discard_extents(pag_mount(pag), extents);
 
 		if (xfs_trim_should_stop())
 			break;
@@ -496,12 +483,10 @@ xfs_discard_rtdev_extents(
 
 		trace_xfs_discard_rtextent(mp, busyp->bno, busyp->length);
 
-		error = __blkdev_issue_discard(bdev,
+		__blkdev_issue_discard(bdev,
 				xfs_rtb_to_daddr(mp, busyp->bno),
 				XFS_FSB_TO_BB(mp, busyp->length),
 				GFP_NOFS, &bio);
-		if (error)
-			break;
 	}
 	xfs_discard_free_rtdev_extents(tr);
 
@@ -741,9 +726,7 @@ xfs_trim_rtgroup_extents(
 		 * list  after this function call, as it may have been freed by
 		 * the time control returns to us.
 		 */
-		error = xfs_discard_extents(rtg_mount(rtg), tr.extents);
-		if (error)
-			break;
+		xfs_discard_extents(rtg_mount(rtg), tr.extents);
 
 		low = tr.restart_rtx;
 	} while (!xfs_trim_should_stop() && low <= high);
diff --git a/fs/xfs/xfs_discard.h b/fs/xfs/xfs_discard.h
index 2b1a85223a56..8c5cc4af6a07 100644
--- a/fs/xfs/xfs_discard.h
+++ b/fs/xfs/xfs_discard.h
@@ -6,7 +6,7 @@ struct fstrim_range;
 struct xfs_mount;
 struct xfs_busy_extents;
 
-int xfs_discard_extents(struct xfs_mount *mp, struct xfs_busy_extents *busy);
+void xfs_discard_extents(struct xfs_mount *mp, struct xfs_busy_extents *busy);
 int xfs_ioc_trim(struct xfs_mount *mp, struct fstrim_range __user *fstrim);
 
 #endif /* XFS_DISCARD_H */
-- 
2.40.0


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

* Re: [PATCH V3 5/6] f2fs: ignore discard return value
  2025-11-24 23:48 ` [PATCH V3 5/6] f2fs: " Chaitanya Kulkarni
@ 2025-11-25  1:10   ` Chao Yu
  2025-11-25  6:33     ` Christoph Hellwig
  2025-11-26  2:47   ` Chao Yu
  1 sibling, 1 reply; 28+ messages in thread
From: Chao Yu @ 2025-11-25  1:10 UTC (permalink / raw)
  To: Chaitanya Kulkarni, axboe, agk, snitzer, mpatocka, song, yukuai,
	hch, sagi, kch, jaegeuk, cem
  Cc: chao, linux-block, linux-kernel, dm-devel, linux-raid, linux-nvme,
	linux-f2fs-devel, linux-xfs, bpf, Martin K . Petersen,
	Johannes Thumshirn

On 11/25/2025 7:48 AM, Chaitanya Kulkarni wrote:
> __blkdev_issue_discard() always returns 0, making the error assignment
> in __submit_discard_cmd() dead code.
> 
> Initialize err to 0 and remove the error assignment from the
> __blkdev_issue_discard() call to err. Move fault injection code into
> already present if branch where err is set to -EIO.
> 
> This preserves the fault injection behavior while removing dead error
> handling.
> 
> Reviewed-by: Martin K. Petersen <martin.petersen@oracle.com>
> Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
> Reviewed-by: Christoph Hellwig <hch@lst.de>
> Signed-off-by: Chaitanya Kulkarni <ckulkarnilinux@gmail.com>

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

Thanks,

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

* Re: [PATCH V3 5/6] f2fs: ignore discard return value
  2025-11-25  1:10   ` Chao Yu
@ 2025-11-25  6:33     ` Christoph Hellwig
  2025-11-25  7:11       ` Chao Yu
  0 siblings, 1 reply; 28+ messages in thread
From: Christoph Hellwig @ 2025-11-25  6:33 UTC (permalink / raw)
  To: Chao Yu
  Cc: Chaitanya Kulkarni, axboe, agk, snitzer, mpatocka, song, yukuai,
	hch, sagi, kch, jaegeuk, cem, linux-block, linux-kernel, dm-devel,
	linux-raid, linux-nvme, linux-f2fs-devel, linux-xfs, bpf,
	Martin K . Petersen, Johannes Thumshirn

On Tue, Nov 25, 2025 at 09:10:00AM +0800, Chao Yu wrote:
> Reviewed-by: Chao Yu <chao@kernel.org>

Sending these all as a series might be confusing - it would be good
if the individual patches get picked through the subsystem trees
so that the function signature can be cleaned up after -rc1.

Can we get this queued up in the f2fs tree?


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

* Re: [PATCH V3 5/6] f2fs: ignore discard return value
  2025-11-25  6:33     ` Christoph Hellwig
@ 2025-11-25  7:11       ` Chao Yu
  0 siblings, 0 replies; 28+ messages in thread
From: Chao Yu @ 2025-11-25  7:11 UTC (permalink / raw)
  To: Christoph Hellwig, jaegeuk
  Cc: chao, Chaitanya Kulkarni, axboe, agk, snitzer, mpatocka, song,
	yukuai, sagi, kch, cem, linux-block, linux-kernel, dm-devel,
	linux-raid, linux-nvme, linux-f2fs-devel, linux-xfs, bpf,
	Martin K . Petersen, Johannes Thumshirn

On 11/25/2025 2:33 PM, Christoph Hellwig wrote:
> On Tue, Nov 25, 2025 at 09:10:00AM +0800, Chao Yu wrote:
>> Reviewed-by: Chao Yu <chao@kernel.org>
> 
> Sending these all as a series might be confusing - it would be good
> if the individual patches get picked through the subsystem trees
> so that the function signature can be cleaned up after -rc1.
> 
> Can we get this queued up in the f2fs tree?

Yes, I think it's clean to queue this patch into f2fs tree.

Thanks,

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

* Re: [PATCH V3 0/6] block: ignore __blkdev_issue_discard() ret value
  2025-11-24 23:48 [PATCH V3 0/6] block: ignore __blkdev_issue_discard() ret value Chaitanya Kulkarni
                   ` (5 preceding siblings ...)
  2025-11-24 23:48 ` [PATCH V3 6/6] xfs: " Chaitanya Kulkarni
@ 2025-11-25 13:20 ` Anuj gupta
  2025-11-25 19:20 ` (subset) " Jens Axboe
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 28+ messages in thread
From: Anuj gupta @ 2025-11-25 13:20 UTC (permalink / raw)
  To: Chaitanya Kulkarni
  Cc: axboe, agk, snitzer, mpatocka, song, yukuai, hch, sagi, kch,
	jaegeuk, chao, cem, linux-block, linux-kernel, dm-devel,
	linux-raid, linux-nvme, linux-f2fs-devel, linux-xfs, bpf

Reviewed-by: Anuj Gupta <anuj20.g@samsung.com>

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

* Re: [PATCH V3 1/6] block: ignore discard return value
  2025-11-24 23:48 ` [PATCH V3 1/6] block: ignore discard return value Chaitanya Kulkarni
@ 2025-11-25 17:38   ` Jens Axboe
  2025-11-25 19:09     ` Chaitanya Kulkarni
  0 siblings, 1 reply; 28+ messages in thread
From: Jens Axboe @ 2025-11-25 17:38 UTC (permalink / raw)
  To: Chaitanya Kulkarni, agk, snitzer, mpatocka, song, yukuai, hch,
	sagi, kch, jaegeuk, chao, cem
  Cc: linux-block, linux-kernel, dm-devel, linux-raid, linux-nvme,
	linux-f2fs-devel, linux-xfs, bpf, Johannes Thumshirn,
	Martin K . Petersen

On 11/24/25 4:48 PM, Chaitanya Kulkarni wrote:
> __blkdev_issue_discard() always returns 0, making the error check
> in blkdev_issue_discard() dead code.

Shouldn't it be a void instead then?

-- 
Jens Axboe


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

* Re: [PATCH V3 1/6] block: ignore discard return value
  2025-11-25 17:38   ` Jens Axboe
@ 2025-11-25 19:09     ` Chaitanya Kulkarni
  2025-11-25 19:19       ` Jens Axboe
  0 siblings, 1 reply; 28+ messages in thread
From: Chaitanya Kulkarni @ 2025-11-25 19:09 UTC (permalink / raw)
  To: Jens Axboe, agk, snitzer, mpatocka, song, yukuai, hch, sagi, kch,
	jaegeuk, chao, cem
  Cc: linux-block, linux-kernel, dm-devel, linux-raid, linux-nvme,
	linux-f2fs-devel, linux-xfs, bpf, Johannes Thumshirn,
	Martin K . Petersen

On 11/25/25 09:38, Jens Axboe wrote:
> On 11/24/25 4:48 PM, Chaitanya Kulkarni wrote:
>> __blkdev_issue_discard() always returns 0, making the error check
>> in blkdev_issue_discard() dead code.
> Shouldn't it be a void instead then?
>
Yes, we have decided to clean up the callers first [1]. Once they are
merged safely, after rc1 I'll send a patch [2] to make it void since
it touches many different subsystems.

-ck

[1]
https://marc.info/?l=linux-block&m=176405170918235&w=2
https://marc.info/?l=dm-devel&m=176345232320530&w=2

[2]
 From abdf4d1863a02d4be816aaab9a789f44bfca568f Mon Sep 17 00:00:00 2001
From: Chaitanya Kulkarni <ckulkarnilinux@gmail.com>
Date: Tue, 18 Nov 2025 10:35:58 -0800
Subject: [PATCH 6/6] block: change discar return type to  void

Now that all callers have been updated to not check the return value
of __blkdev_issue_discard(), change its return type from int to void
and remove the return 0 statement.

This completes the cleanup of dead error checking code around
__blkdev_issue_discard().

Signed-off-by: Chaitanya Kulkarni <ckulkarnilinux@gmail.com>
---
  block/blk-lib.c        | 3 +--
  include/linux/blkdev.h | 2 +-
  2 files changed, 2 insertions(+), 3 deletions(-)

diff --git a/block/blk-lib.c b/block/blk-lib.c
index 19e0203cc18a..0a5f39325b2d 100644
--- a/block/blk-lib.c
+++ b/block/blk-lib.c
@@ -60,7 +60,7 @@ struct bio *blk_alloc_discard_bio(struct block_device *bdev,
  	return bio;
  }
  
-int __blkdev_issue_discard(struct block_device *bdev, sector_t sector,
+void __blkdev_issue_discard(struct block_device *bdev, sector_t sector,
  		sector_t nr_sects, gfp_t gfp_mask, struct bio **biop)
  {
  	struct bio *bio;
@@ -68,7 +68,6 @@ int __blkdev_issue_discard(struct block_device *bdev, sector_t sector,
  	while ((bio = blk_alloc_discard_bio(bdev, &sector, &nr_sects,
  			gfp_mask)))
  		*biop = bio_chain_and_submit(*biop, bio);
-	return 0;
  }
  EXPORT_SYMBOL(__blkdev_issue_discard);
  
diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
index f0ab02e0a673..b05c37d20b09 100644
--- a/include/linux/blkdev.h
+++ b/include/linux/blkdev.h
@@ -1258,7 +1258,7 @@ extern void blk_io_schedule(void);
  
  int blkdev_issue_discard(struct block_device *bdev, sector_t sector,
  		sector_t nr_sects, gfp_t gfp_mask);
-int __blkdev_issue_discard(struct block_device *bdev, sector_t sector,
+void __blkdev_issue_discard(struct block_device *bdev, sector_t sector,
  		sector_t nr_sects, gfp_t gfp_mask, struct bio **biop);
  int blkdev_issue_secure_erase(struct block_device *bdev, sector_t sector,
  		sector_t nr_sects, gfp_t gfp);
-- 
2.40.0


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

* Re: [PATCH V3 1/6] block: ignore discard return value
  2025-11-25 19:09     ` Chaitanya Kulkarni
@ 2025-11-25 19:19       ` Jens Axboe
  0 siblings, 0 replies; 28+ messages in thread
From: Jens Axboe @ 2025-11-25 19:19 UTC (permalink / raw)
  To: Chaitanya Kulkarni, agk, snitzer, mpatocka, song, yukuai, hch,
	sagi, kch, jaegeuk, chao, cem
  Cc: linux-block, linux-kernel, dm-devel, linux-raid, linux-nvme,
	linux-f2fs-devel, linux-xfs, bpf, Johannes Thumshirn,
	Martin K . Petersen

On 11/25/25 12:09 PM, Chaitanya Kulkarni wrote:
> On 11/25/25 09:38, Jens Axboe wrote:
>> On 11/24/25 4:48 PM, Chaitanya Kulkarni wrote:
>>> __blkdev_issue_discard() always returns 0, making the error check
>>> in blkdev_issue_discard() dead code.
>> Shouldn't it be a void instead then?
>>
> Yes, we have decided to clean up the callers first [1]. Once they are
> merged safely, after rc1 I'll send a patch [2] to make it void since
> it touches many different subsystems.

OK, that make sense. I'll queue patch 1.

-- 
Jens Axboe


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

* Re: (subset) [PATCH V3 0/6] block: ignore __blkdev_issue_discard() ret value
  2025-11-24 23:48 [PATCH V3 0/6] block: ignore __blkdev_issue_discard() ret value Chaitanya Kulkarni
                   ` (6 preceding siblings ...)
  2025-11-25 13:20 ` [PATCH V3 0/6] block: ignore __blkdev_issue_discard() ret value Anuj gupta
@ 2025-11-25 19:20 ` Jens Axboe
  2025-12-03 21:50 ` [f2fs-dev] " patchwork-bot+f2fs
  2025-12-09 17:18 ` patchwork-bot+f2fs
  9 siblings, 0 replies; 28+ messages in thread
From: Jens Axboe @ 2025-11-25 19:20 UTC (permalink / raw)
  To: agk, snitzer, mpatocka, song, yukuai, hch, sagi, kch, jaegeuk,
	chao, cem, Chaitanya Kulkarni
  Cc: linux-block, linux-kernel, dm-devel, linux-raid, linux-nvme,
	linux-f2fs-devel, linux-xfs, bpf


On Mon, 24 Nov 2025 15:48:00 -0800, Chaitanya Kulkarni wrote:
> __blkdev_issue_discard() only returns value 0, that makes post call
> error checking code dead. This patch series revmoes this dead code at
> all the call sites and adjust the callers.
> 
> Please note that it doesn't change the return type of the function from
> int to void in this series, it will be done once this series gets merged
> smoothly.
> 
> [...]

Applied, thanks!

[1/6] block: ignore discard return value
      (no commit info)

Best regards,
-- 
Jens Axboe




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

* Re: [f2fs-dev] [PATCH V3 6/6] xfs: ignore discard return value
  2025-11-24 23:48 ` [PATCH V3 6/6] xfs: " Chaitanya Kulkarni
@ 2025-11-26  2:37   ` Yongpeng Yang
  2025-11-26  8:07     ` Chaitanya Kulkarni
  2025-11-26 10:33     ` Christoph Hellwig
  0 siblings, 2 replies; 28+ messages in thread
From: Yongpeng Yang @ 2025-11-26  2:37 UTC (permalink / raw)
  To: Chaitanya Kulkarni, axboe, agk, snitzer, mpatocka, song, yukuai,
	hch, sagi, kch, jaegeuk, chao, cem
  Cc: dm-devel, linux-raid, Johannes Thumshirn, linux-kernel,
	linux-nvme, linux-f2fs-devel, linux-block, bpf, linux-xfs,
	Yongpeng Yang


On 11/25/25 07:48, Chaitanya Kulkarni wrote:
> __blkdev_issue_discard() always returns 0, making all error checking
> in XFS discard functions dead code.
> 
> Change xfs_discard_extents() return type to void, remove error variable,
> error checking, and error logging for the __blkdev_issue_discard() call
> in same function.
> 
> Update xfs_trim_perag_extents() and xfs_trim_rtgroup_extents() to
> ignore the xfs_discard_extents() return value and error checking
> code.
> 
> Update xfs_discard_rtdev_extents() to ignore __blkdev_issue_discard()
> return value and error checking code.
> 
> Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
> Reviewed-by: Christoph Hellwig <hch@lst.de>
> Signed-off-by: Chaitanya Kulkarni <ckulkarnilinux@gmail.com>
> ---
>   fs/xfs/xfs_discard.c | 27 +++++----------------------
>   fs/xfs/xfs_discard.h |  2 +-
>   2 files changed, 6 insertions(+), 23 deletions(-)
> 
> diff --git a/fs/xfs/xfs_discard.c b/fs/xfs/xfs_discard.c
> index 6917de832191..b6ffe4807a11 100644
> --- a/fs/xfs/xfs_discard.c
> +++ b/fs/xfs/xfs_discard.c
> @@ -108,7 +108,7 @@ xfs_discard_endio(
>    * list. We plug and chain the bios so that we only need a single completion
>    * call to clear all the busy extents once the discards are complete.
>    */
> -int
> +void
>   xfs_discard_extents(
>   	struct xfs_mount	*mp,
>   	struct xfs_busy_extents	*extents)
> @@ -116,7 +116,6 @@ xfs_discard_extents(
>   	struct xfs_extent_busy	*busyp;
>   	struct bio		*bio = NULL;
>   	struct blk_plug		plug;
> -	int			error = 0;
>   
>   	blk_start_plug(&plug);
>   	list_for_each_entry(busyp, &extents->extent_list, list) {
> @@ -126,18 +125,10 @@ xfs_discard_extents(
>   
>   		trace_xfs_discard_extent(xg, busyp->bno, busyp->length);
>   
> -		error = __blkdev_issue_discard(btp->bt_bdev,
> +		__blkdev_issue_discard(btp->bt_bdev,
>   				xfs_gbno_to_daddr(xg, busyp->bno),
>   				XFS_FSB_TO_BB(mp, busyp->length),
>   				GFP_KERNEL, &bio);

If blk_alloc_discard_bio() fails to allocate a bio inside
__blkdev_issue_discard(), this may lead to an invalid loop in
list_for_each_entry{}. Instead of using __blkdev_issue_discard(), how
about allocate and submit the discard bios explicitly in
list_for_each_entry{}?

Yongpeng,

> -		if (error && error != -EOPNOTSUPP) {
> -			xfs_info(mp,
> -	 "discard failed for extent [0x%llx,%u], error %d",
> -				 (unsigned long long)busyp->bno,
> -				 busyp->length,
> -				 error);
> -			break;
> -		}
>   	}
>   
>   	if (bio) {
> @@ -148,8 +139,6 @@ xfs_discard_extents(
>   		xfs_discard_endio_work(&extents->endio_work);
>   	}
>   	blk_finish_plug(&plug);
> -
> -	return error;
>   }
>   
>   /*
> @@ -385,9 +374,7 @@ xfs_trim_perag_extents(
>   		 * list  after this function call, as it may have been freed by
>   		 * the time control returns to us.
>   		 */
> -		error = xfs_discard_extents(pag_mount(pag), extents);
> -		if (error)
> -			break;
> +		xfs_discard_extents(pag_mount(pag), extents);
>   
>   		if (xfs_trim_should_stop())
>   			break;
> @@ -496,12 +483,10 @@ xfs_discard_rtdev_extents(
>   
>   		trace_xfs_discard_rtextent(mp, busyp->bno, busyp->length);
>   
> -		error = __blkdev_issue_discard(bdev,
> +		__blkdev_issue_discard(bdev,
>   				xfs_rtb_to_daddr(mp, busyp->bno),
>   				XFS_FSB_TO_BB(mp, busyp->length),
>   				GFP_NOFS, &bio);
> -		if (error)
> -			break;
>   	}
>   	xfs_discard_free_rtdev_extents(tr);
>   
> @@ -741,9 +726,7 @@ xfs_trim_rtgroup_extents(
>   		 * list  after this function call, as it may have been freed by
>   		 * the time control returns to us.
>   		 */
> -		error = xfs_discard_extents(rtg_mount(rtg), tr.extents);
> -		if (error)
> -			break;
> +		xfs_discard_extents(rtg_mount(rtg), tr.extents);
>   
>   		low = tr.restart_rtx;
>   	} while (!xfs_trim_should_stop() && low <= high);
> diff --git a/fs/xfs/xfs_discard.h b/fs/xfs/xfs_discard.h
> index 2b1a85223a56..8c5cc4af6a07 100644
> --- a/fs/xfs/xfs_discard.h
> +++ b/fs/xfs/xfs_discard.h
> @@ -6,7 +6,7 @@ struct fstrim_range;
>   struct xfs_mount;
>   struct xfs_busy_extents;
>   
> -int xfs_discard_extents(struct xfs_mount *mp, struct xfs_busy_extents *busy);
> +void xfs_discard_extents(struct xfs_mount *mp, struct xfs_busy_extents *busy);
>   int xfs_ioc_trim(struct xfs_mount *mp, struct fstrim_range __user *fstrim);
>   
>   #endif /* XFS_DISCARD_H */


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

* Re: [PATCH V3 5/6] f2fs: ignore discard return value
  2025-11-24 23:48 ` [PATCH V3 5/6] f2fs: " Chaitanya Kulkarni
  2025-11-25  1:10   ` Chao Yu
@ 2025-11-26  2:47   ` Chao Yu
  2025-11-26  3:37     ` Chaitanya Kulkarni
  1 sibling, 1 reply; 28+ messages in thread
From: Chao Yu @ 2025-11-26  2:47 UTC (permalink / raw)
  To: Chaitanya Kulkarni, axboe, agk, snitzer, mpatocka, song, yukuai,
	hch, sagi, kch, jaegeuk, cem
  Cc: chao, linux-block, linux-kernel, dm-devel, linux-raid, linux-nvme,
	linux-f2fs-devel, linux-xfs, bpf, Martin K . Petersen,
	Johannes Thumshirn

On 11/25/25 07:48, Chaitanya Kulkarni wrote:
> __blkdev_issue_discard() always returns 0, making the error assignment
> in __submit_discard_cmd() dead code.
> 
> Initialize err to 0 and remove the error assignment from the
> __blkdev_issue_discard() call to err. Move fault injection code into
> already present if branch where err is set to -EIO.
> 
> This preserves the fault injection behavior while removing dead error
> handling.
> 
> Reviewed-by: Martin K. Petersen <martin.petersen@oracle.com>
> Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
> Reviewed-by: Christoph Hellwig <hch@lst.de>
> Signed-off-by: Chaitanya Kulkarni <ckulkarnilinux@gmail.com>
> ---
>  fs/f2fs/segment.c | 10 +++-------
>  1 file changed, 3 insertions(+), 7 deletions(-)
> 
> diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c
> index b45eace879d7..22b736ec9c51 100644
> --- a/fs/f2fs/segment.c
> +++ b/fs/f2fs/segment.c
> @@ -1343,15 +1343,9 @@ static int __submit_discard_cmd(struct f2fs_sb_info *sbi,
>  
>  		dc->di.len += len;
>  
> +		err = 0;
>  		if (time_to_inject(sbi, FAULT_DISCARD)) {
>  			err = -EIO;
> -		} else {
> -			err = __blkdev_issue_discard(bdev,
> -					SECTOR_FROM_BLOCK(start),
> -					SECTOR_FROM_BLOCK(len),
> -					GFP_NOFS, &bio);
> -		}
> -		if (err) {
>  			spin_lock_irqsave(&dc->lock, flags);
>  			if (dc->state == D_PARTIAL)
>  				dc->state = D_SUBMIT;
> @@ -1360,6 +1354,8 @@ static int __submit_discard_cmd(struct f2fs_sb_info *sbi,
>  			break;
>  		}
>  
> +		__blkdev_issue_discard(bdev, SECTOR_FROM_BLOCK(start),
> +				SECTOR_FROM_BLOCK(len), GFP_NOFS, &bio);

Oh, wait, bio can be NULL? Then below f2fs_bug_on() will trigger panic or warning.

Thanks,

>  		f2fs_bug_on(sbi, !bio);
>  
>  		/*


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

* Re: [PATCH V3 5/6] f2fs: ignore discard return value
  2025-11-26  2:47   ` Chao Yu
@ 2025-11-26  3:37     ` Chaitanya Kulkarni
  2025-11-26  3:58       ` Chao Yu
  0 siblings, 1 reply; 28+ messages in thread
From: Chaitanya Kulkarni @ 2025-11-26  3:37 UTC (permalink / raw)
  To: Chao Yu
  Cc: linux-block@vger.kernel.org, jaegeuk@kernel.org,
	Chaitanya Kulkarni, hch@lst.de, song@kernel.org, axboe@kernel.dk,
	linux-kernel@vger.kernel.org, dm-devel@lists.linux.dev,
	linux-raid@vger.kernel.org, linux-nvme@lists.infradead.org,
	linux-f2fs-devel@lists.sourceforge.net, cem@kernel.org,
	linux-xfs@vger.kernel.org, sagi@grimberg.me, yukuai@fnnas.com,
	bpf@vger.kernel.org, mpatocka@redhat.com, Martin K . Petersen,
	agk@redhat.com, Johannes Thumshirn, Chaitanya Kulkarni,
	snitzer@kernel.org

On 11/25/25 18:47, Chao Yu wrote:
> On 11/25/25 07:48, Chaitanya Kulkarni wrote:
>> __blkdev_issue_discard() always returns 0, making the error assignment
>> in __submit_discard_cmd() dead code.
>>
>> Initialize err to 0 and remove the error assignment from the
>> __blkdev_issue_discard() call to err. Move fault injection code into
>> already present if branch where err is set to -EIO.
>>
>> This preserves the fault injection behavior while removing dead error
>> handling.
>>
>> Reviewed-by: Martin K. Petersen <martin.petersen@oracle.com>
>> Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
>> Reviewed-by: Christoph Hellwig <hch@lst.de>
>> Signed-off-by: Chaitanya Kulkarni <ckulkarnilinux@gmail.com>
>> ---
>>   fs/f2fs/segment.c | 10 +++-------
>>   1 file changed, 3 insertions(+), 7 deletions(-)
>>
>> diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c
>> index b45eace879d7..22b736ec9c51 100644
>> --- a/fs/f2fs/segment.c
>> +++ b/fs/f2fs/segment.c
>> @@ -1343,15 +1343,9 @@ static int __submit_discard_cmd(struct f2fs_sb_info *sbi,
>>   
>>   		dc->di.len += len;
>>   
>> +		err = 0;
>>   		if (time_to_inject(sbi, FAULT_DISCARD)) {
>>   			err = -EIO;
>> -		} else {
>> -			err = __blkdev_issue_discard(bdev,
>> -					SECTOR_FROM_BLOCK(start),
>> -					SECTOR_FROM_BLOCK(len),
>> -					GFP_NOFS, &bio);
>> -		}
>> -		if (err) {
>>   			spin_lock_irqsave(&dc->lock, flags);
>>   			if (dc->state == D_PARTIAL)
>>   				dc->state = D_SUBMIT;
>> @@ -1360,6 +1354,8 @@ static int __submit_discard_cmd(struct f2fs_sb_info *sbi,
>>   			break;
>>   		}
>>   
>> +		__blkdev_issue_discard(bdev, SECTOR_FROM_BLOCK(start),
>> +				SECTOR_FROM_BLOCK(len), GFP_NOFS, &bio);
> Oh, wait, bio can be NULL? Then below f2fs_bug_on() will trigger panic or warning.
>
> Thanks,

That will happen without this patch also or not ?

Since __blkdev_issue_discard() is always returning 0 irrespective of bio
is null or not.

The following condition in original code will only execute when err is set to
-EIO and that will only happen when time_to_inject() -> true.
Original call to __blkdev_issue_discard() without this patch will always
return 0 even for bio == NULL after __blkdev_issue_discard().

This is what we are trying to fix so caller should not rely on
__blkdev_issue_discard() return value  :-

354                 if (err) {
1355                         spin_lock_irqsave(&dc->lock, flags);
1356                         if (dc->state == D_PARTIAL)
1357                                 dc->state = D_SUBMIT;
1358                         spin_unlock_irqrestore(&dc->lock, flags);
1359
1360                         break;
1361                 }

which will lead f2fs_bug_on() for bio == NULL even without this patch.

This patch is not changing exiting behavior, correct me if I'm wrong.


>
>>   		f2fs_bug_on(sbi, !bio);
>>   
>>   		/*

-ck



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

* Re: [PATCH V3 5/6] f2fs: ignore discard return value
  2025-11-26  3:37     ` Chaitanya Kulkarni
@ 2025-11-26  3:58       ` Chao Yu
  0 siblings, 0 replies; 28+ messages in thread
From: Chao Yu @ 2025-11-26  3:58 UTC (permalink / raw)
  To: Chaitanya Kulkarni
  Cc: chao, linux-block@vger.kernel.org, jaegeuk@kernel.org, hch@lst.de,
	song@kernel.org, axboe@kernel.dk, linux-kernel@vger.kernel.org,
	dm-devel@lists.linux.dev, linux-raid@vger.kernel.org,
	linux-nvme@lists.infradead.org,
	linux-f2fs-devel@lists.sourceforge.net, cem@kernel.org,
	linux-xfs@vger.kernel.org, sagi@grimberg.me, yukuai@fnnas.com,
	bpf@vger.kernel.org, mpatocka@redhat.com, Martin K . Petersen,
	agk@redhat.com, Johannes Thumshirn, Chaitanya Kulkarni,
	snitzer@kernel.org

On 11/26/25 11:37, Chaitanya Kulkarni wrote:
> On 11/25/25 18:47, Chao Yu wrote:
>> On 11/25/25 07:48, Chaitanya Kulkarni wrote:
>>> __blkdev_issue_discard() always returns 0, making the error assignment
>>> in __submit_discard_cmd() dead code.
>>>
>>> Initialize err to 0 and remove the error assignment from the
>>> __blkdev_issue_discard() call to err. Move fault injection code into
>>> already present if branch where err is set to -EIO.
>>>
>>> This preserves the fault injection behavior while removing dead error
>>> handling.
>>>
>>> Reviewed-by: Martin K. Petersen <martin.petersen@oracle.com>
>>> Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
>>> Reviewed-by: Christoph Hellwig <hch@lst.de>
>>> Signed-off-by: Chaitanya Kulkarni <ckulkarnilinux@gmail.com>
>>> ---
>>>   fs/f2fs/segment.c | 10 +++-------
>>>   1 file changed, 3 insertions(+), 7 deletions(-)
>>>
>>> diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c
>>> index b45eace879d7..22b736ec9c51 100644
>>> --- a/fs/f2fs/segment.c
>>> +++ b/fs/f2fs/segment.c
>>> @@ -1343,15 +1343,9 @@ static int __submit_discard_cmd(struct f2fs_sb_info *sbi,
>>>   
>>>   		dc->di.len += len;
>>>   
>>> +		err = 0;
>>>   		if (time_to_inject(sbi, FAULT_DISCARD)) {
>>>   			err = -EIO;
>>> -		} else {
>>> -			err = __blkdev_issue_discard(bdev,
>>> -					SECTOR_FROM_BLOCK(start),
>>> -					SECTOR_FROM_BLOCK(len),
>>> -					GFP_NOFS, &bio);
>>> -		}
>>> -		if (err) {
>>>   			spin_lock_irqsave(&dc->lock, flags);
>>>   			if (dc->state == D_PARTIAL)
>>>   				dc->state = D_SUBMIT;
>>> @@ -1360,6 +1354,8 @@ static int __submit_discard_cmd(struct f2fs_sb_info *sbi,
>>>   			break;
>>>   		}
>>>   
>>> +		__blkdev_issue_discard(bdev, SECTOR_FROM_BLOCK(start),
>>> +				SECTOR_FROM_BLOCK(len), GFP_NOFS, &bio);
>> Oh, wait, bio can be NULL? Then below f2fs_bug_on() will trigger panic or warning.
>>
>> Thanks,
> 
> That will happen without this patch also or not ?
> 
> Since __blkdev_issue_discard() is always returning 0 irrespective of bio
> is null or not.
> 
> The following condition in original code will only execute when err is set to
> -EIO and that will only happen when time_to_inject() -> true.
> Original call to __blkdev_issue_discard() without this patch will always
> return 0 even for bio == NULL after __blkdev_issue_discard().
> 
> This is what we are trying to fix so caller should not rely on
> __blkdev_issue_discard() return value  :-
> 
> 354                 if (err) {
> 1355                         spin_lock_irqsave(&dc->lock, flags);
> 1356                         if (dc->state == D_PARTIAL)
> 1357                                 dc->state = D_SUBMIT;
> 1358                         spin_unlock_irqrestore(&dc->lock, flags);
> 1359
> 1360                         break;
> 1361                 }
> 
> which will lead f2fs_bug_on() for bio == NULL even without this patch.
> 
> This patch is not changing exiting behavior, correct me if I'm wrong.

Yes, I think you're right, thanks for the explanation.

So it's fine to leave this cleanup patch as it is, and let's fix this bug in
a separated patch.

Thanks,

> 
> 
>>
>>>   		f2fs_bug_on(sbi, !bio);
>>>   
>>>   		/*
> 
> -ck
> 
> 


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

* Re: [f2fs-dev] [PATCH V3 6/6] xfs: ignore discard return value
  2025-11-26  2:37   ` [f2fs-dev] " Yongpeng Yang
@ 2025-11-26  8:07     ` Chaitanya Kulkarni
  2025-11-26  9:14       ` Yongpeng Yang
  2025-11-26 10:34       ` hch
  2025-11-26 10:33     ` Christoph Hellwig
  1 sibling, 2 replies; 28+ messages in thread
From: Chaitanya Kulkarni @ 2025-11-26  8:07 UTC (permalink / raw)
  To: Yongpeng Yang, Chaitanya Kulkarni, axboe@kernel.dk,
	agk@redhat.com, snitzer@kernel.org, mpatocka@redhat.com,
	song@kernel.org, yukuai@fnnas.com, hch@lst.de, sagi@grimberg.me,
	Chaitanya Kulkarni, jaegeuk@kernel.org, chao@kernel.org,
	cem@kernel.org
  Cc: dm-devel@lists.linux.dev, linux-raid@vger.kernel.org,
	Johannes Thumshirn, linux-kernel@vger.kernel.org,
	linux-nvme@lists.infradead.org,
	linux-f2fs-devel@lists.sourceforge.net,
	linux-block@vger.kernel.org, bpf@vger.kernel.org,
	linux-xfs@vger.kernel.org, Yongpeng Yang

On 11/25/25 18:37, Yongpeng Yang wrote:
>> diff --git a/fs/xfs/xfs_discard.c b/fs/xfs/xfs_discard.c
>> index 6917de832191..b6ffe4807a11 100644
>> --- a/fs/xfs/xfs_discard.c
>> +++ b/fs/xfs/xfs_discard.c
>> @@ -108,7 +108,7 @@ xfs_discard_endio(
>>    * list. We plug and chain the bios so that we only need a single 
>> completion
>>    * call to clear all the busy extents once the discards are complete.
>>    */
>> -int
>> +void
>>   xfs_discard_extents(
>>       struct xfs_mount    *mp,
>>       struct xfs_busy_extents    *extents)
>> @@ -116,7 +116,6 @@ xfs_discard_extents(
>>       struct xfs_extent_busy    *busyp;
>>       struct bio        *bio = NULL;
>>       struct blk_plug        plug;
>> -    int            error = 0;
>>         blk_start_plug(&plug);
>>       list_for_each_entry(busyp, &extents->extent_list, list) {
>> @@ -126,18 +125,10 @@ xfs_discard_extents(
>>             trace_xfs_discard_extent(xg, busyp->bno, busyp->length);
>>   -        error = __blkdev_issue_discard(btp->bt_bdev,
>> +        __blkdev_issue_discard(btp->bt_bdev,
>>                   xfs_gbno_to_daddr(xg, busyp->bno),
>>                   XFS_FSB_TO_BB(mp, busyp->length),
>>                   GFP_KERNEL, &bio);
>
> If blk_alloc_discard_bio() fails to allocate a bio inside
> __blkdev_issue_discard(), this may lead to an invalid loop in
> list_for_each_entry{}. Instead of using __blkdev_issue_discard(), how
> about allocate and submit the discard bios explicitly in
> list_for_each_entry{}?
>
> Yongpeng,


Calling __blkdev_issue_discard() keeps managing all the bio with the
appropriate GFP mask, so the semantics stay the same. You are just
moving memory allocation to the caller and potentially looking at
implementing retry on bio allocation failure.

The retry for discard bio memory allocation is not desired I think,
since it's only a hint to the controller.

This patch is simply cleaning up dead error-handling branches at the
callers no behavioral changes intended.

What maybe useful is to stop iterating once we fail to allocate the
bio [1].

-ck

[1] Potential addition on the top of this to exit early in discard loop
     on bio allocation failure.

diff --git a/fs/xfs/xfs_discard.c b/fs/xfs/xfs_discard.c
index b6ffe4807a11..1519f708bb79 100644
--- a/fs/xfs/xfs_discard.c
+++ b/fs/xfs/xfs_discard.c
@@ -129,6 +129,13 @@ xfs_discard_extents(
                                 xfs_gbno_to_daddr(xg, busyp->bno),
                                 XFS_FSB_TO_BB(mp, busyp->length),
                                 GFP_KERNEL, &bio);
+               /*
+                * We failed to allocate bio instead of continuing the loop
+                * so it will lead to inconsistent discards to the disk
+                * exit early and jump into xfs_discard_busy_clear().
+                */
+               if (!bio)
+                       break;
         }
  
         if (bio) {

If we keep looping after the first bio == NULL, the rest of the range is
guaranteed to be inconsistent anyways, because every subsequent iteration
will fall into one of three cases:

- The allocator keeps returning NULL, so none of the remaining LBAs receive
   discard.
- Rest of the allocator succeeds, but we’ve already skipped a chunk, leaving
   a hole in the discard range.
- We get intermittent successes, which produces alternating chunks of
   discarded and undiscarded blocks.

In each of those scenarios, the disk ends up with a partially discarded
range, so the correct fix is to break out of the loop immediately and
proceed to xfs_discard_busy_clear() once the very first allocation fails.




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

* Re: [f2fs-dev] [PATCH V3 6/6] xfs: ignore discard return value
  2025-11-26  8:07     ` Chaitanya Kulkarni
@ 2025-11-26  9:14       ` Yongpeng Yang
  2025-11-26  9:48         ` Yongpeng Yang
  2025-11-26 10:34       ` hch
  1 sibling, 1 reply; 28+ messages in thread
From: Yongpeng Yang @ 2025-11-26  9:14 UTC (permalink / raw)
  To: Chaitanya Kulkarni, Yongpeng Yang, Chaitanya Kulkarni,
	axboe@kernel.dk, agk@redhat.com, snitzer@kernel.org,
	mpatocka@redhat.com, song@kernel.org, yukuai@fnnas.com,
	hch@lst.de, sagi@grimberg.me, jaegeuk@kernel.org, chao@kernel.org,
	cem@kernel.org
  Cc: dm-devel@lists.linux.dev, linux-block@vger.kernel.org,
	Johannes Thumshirn, Yongpeng Yang, linux-kernel@vger.kernel.org,
	linux-nvme@lists.infradead.org,
	linux-f2fs-devel@lists.sourceforge.net,
	linux-raid@vger.kernel.org, bpf@vger.kernel.org,
	linux-xfs@vger.kernel.org

On 11/26/25 16:07, Chaitanya Kulkarni via Linux-f2fs-devel wrote:
> On 11/25/25 18:37, Yongpeng Yang wrote:
>>> diff --git a/fs/xfs/xfs_discard.c b/fs/xfs/xfs_discard.c
>>> index 6917de832191..b6ffe4807a11 100644
>>> --- a/fs/xfs/xfs_discard.c
>>> +++ b/fs/xfs/xfs_discard.c
>>> @@ -108,7 +108,7 @@ xfs_discard_endio(
>>>     * list. We plug and chain the bios so that we only need a single
>>> completion
>>>     * call to clear all the busy extents once the discards are complete.
>>>     */
>>> -int
>>> +void
>>>    xfs_discard_extents(
>>>        struct xfs_mount    *mp,
>>>        struct xfs_busy_extents    *extents)
>>> @@ -116,7 +116,6 @@ xfs_discard_extents(
>>>        struct xfs_extent_busy    *busyp;
>>>        struct bio        *bio = NULL;
>>>        struct blk_plug        plug;
>>> -    int            error = 0;
>>>          blk_start_plug(&plug);
>>>        list_for_each_entry(busyp, &extents->extent_list, list) {
>>> @@ -126,18 +125,10 @@ xfs_discard_extents(
>>>              trace_xfs_discard_extent(xg, busyp->bno, busyp->length);
>>>    -        error = __blkdev_issue_discard(btp->bt_bdev,
>>> +        __blkdev_issue_discard(btp->bt_bdev,
>>>                    xfs_gbno_to_daddr(xg, busyp->bno),
>>>                    XFS_FSB_TO_BB(mp, busyp->length),
>>>                    GFP_KERNEL, &bio);
>>
>> If blk_alloc_discard_bio() fails to allocate a bio inside
>> __blkdev_issue_discard(), this may lead to an invalid loop in
>> list_for_each_entry{}. Instead of using __blkdev_issue_discard(), how
>> about allocate and submit the discard bios explicitly in
>> list_for_each_entry{}?
>>
>> Yongpeng,
> 
> 
> Calling __blkdev_issue_discard() keeps managing all the bio with the
> appropriate GFP mask, so the semantics stay the same. You are just
> moving memory allocation to the caller and potentially looking at
> implementing retry on bio allocation failure.
> 
> The retry for discard bio memory allocation is not desired I think,
> since it's only a hint to the controller.

Agreed. I'm not trying to retry bio allocation inside the
list_for_each_entry{} loop. Instead, since blk_alloc_discard_bio()
returning NULL cannot reliably indicate whether the failure is due to
bio allocation failure, it could also be caused by 'bio_sects == 0', I'd
like to allocate the bio explicitly.

> 
> This patch is simply cleaning up dead error-handling branches at the
> callers no behavioral changes intended.
> 
> What maybe useful is to stop iterating once we fail to allocate the
> bio [1].
> 
> -ck
> 
> [1] Potential addition on the top of this to exit early in discard loop
>       on bio allocation failure.
> 
> diff --git a/fs/xfs/xfs_discard.c b/fs/xfs/xfs_discard.c
> index b6ffe4807a11..1519f708bb79 100644
> --- a/fs/xfs/xfs_discard.c
> +++ b/fs/xfs/xfs_discard.c
> @@ -129,6 +129,13 @@ xfs_discard_extents(
>                                   xfs_gbno_to_daddr(xg, busyp->bno),
>                                   XFS_FSB_TO_BB(mp, busyp->length),
>                                   GFP_KERNEL, &bio);
> +               /*
> +                * We failed to allocate bio instead of continuing the loop
> +                * so it will lead to inconsistent discards to the disk
> +                * exit early and jump into xfs_discard_busy_clear().
> +                */
> +               if (!bio)
> +                       break;

I noticed that as long as XFS_FSB_TO_BB(mp, busyp->length) is greater
than 0 and there is no bio allocation failure, __blkdev_issue_discard()
will never return NULL. I'm not familiar with this part of the xfs, so
I'm not sure whether there are cases where 'XFS_FSB_TO_BB(mp,
busyp->length)' could be 0. If such cases do not exist, then
checking whether the bio is NULL should be sufficient.

Yongpeng,

>           }
>    
>           if (bio) {
> > If we keep looping after the first bio == NULL, the rest of the range is
> guaranteed to be inconsistent anyways, because every subsequent iteration
> will fall into one of three cases:
> 
> - The allocator keeps returning NULL, so none of the remaining LBAs receive
>     discard.
> - Rest of the allocator succeeds, but we’ve already skipped a chunk, leaving
>     a hole in the discard range.
> - We get intermittent successes, which produces alternating chunks of
>     discarded and undiscarded blocks.
> 
> In each of those scenarios, the disk ends up with a partially discarded
> range, so the correct fix is to break out of the loop immediately and
> proceed to xfs_discard_busy_clear() once the very first allocation fails.



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

* Re: [f2fs-dev] [PATCH V3 6/6] xfs: ignore discard return value
  2025-11-26  9:14       ` Yongpeng Yang
@ 2025-11-26  9:48         ` Yongpeng Yang
  0 siblings, 0 replies; 28+ messages in thread
From: Yongpeng Yang @ 2025-11-26  9:48 UTC (permalink / raw)
  To: Yongpeng Yang, Chaitanya Kulkarni, Chaitanya Kulkarni,
	axboe@kernel.dk, agk@redhat.com, snitzer@kernel.org,
	mpatocka@redhat.com, song@kernel.org, yukuai@fnnas.com,
	hch@lst.de, sagi@grimberg.me, jaegeuk@kernel.org, chao@kernel.org,
	cem@kernel.org
  Cc: dm-devel@lists.linux.dev, linux-raid@vger.kernel.org,
	Johannes Thumshirn, Yongpeng Yang, linux-kernel@vger.kernel.org,
	linux-nvme@lists.infradead.org,
	linux-f2fs-devel@lists.sourceforge.net,
	linux-block@vger.kernel.org, bpf@vger.kernel.org,
	linux-xfs@vger.kernel.org

On 11/26/25 17:14, Yongpeng Yang wrote:
> On 11/26/25 16:07, Chaitanya Kulkarni via Linux-f2fs-devel wrote:
>> On 11/25/25 18:37, Yongpeng Yang wrote:
>>>> diff --git a/fs/xfs/xfs_discard.c b/fs/xfs/xfs_discard.c
>>>> index 6917de832191..b6ffe4807a11 100644
>>>> --- a/fs/xfs/xfs_discard.c
>>>> +++ b/fs/xfs/xfs_discard.c
>>>> @@ -108,7 +108,7 @@ xfs_discard_endio(
>>>>     * list. We plug and chain the bios so that we only need a single
>>>> completion
>>>>     * call to clear all the busy extents once the discards are 
>>>> complete.
>>>>     */
>>>> -int
>>>> +void
>>>>    xfs_discard_extents(
>>>>        struct xfs_mount    *mp,
>>>>        struct xfs_busy_extents    *extents)
>>>> @@ -116,7 +116,6 @@ xfs_discard_extents(
>>>>        struct xfs_extent_busy    *busyp;
>>>>        struct bio        *bio = NULL;
>>>>        struct blk_plug        plug;
>>>> -    int            error = 0;
>>>>          blk_start_plug(&plug);
>>>>        list_for_each_entry(busyp, &extents->extent_list, list) {
>>>> @@ -126,18 +125,10 @@ xfs_discard_extents(
>>>>              trace_xfs_discard_extent(xg, busyp->bno, busyp->length);
>>>>    -        error = __blkdev_issue_discard(btp->bt_bdev,
>>>> +        __blkdev_issue_discard(btp->bt_bdev,
>>>>                    xfs_gbno_to_daddr(xg, busyp->bno),
>>>>                    XFS_FSB_TO_BB(mp, busyp->length),
>>>>                    GFP_KERNEL, &bio);
>>>
>>> If blk_alloc_discard_bio() fails to allocate a bio inside
>>> __blkdev_issue_discard(), this may lead to an invalid loop in
>>> list_for_each_entry{}. Instead of using __blkdev_issue_discard(), how
>>> about allocate and submit the discard bios explicitly in
>>> list_for_each_entry{}?
>>>
>>> Yongpeng,
>>
>>
>> Calling __blkdev_issue_discard() keeps managing all the bio with the
>> appropriate GFP mask, so the semantics stay the same. You are just
>> moving memory allocation to the caller and potentially looking at
>> implementing retry on bio allocation failure.
>>
>> The retry for discard bio memory allocation is not desired I think,
>> since it's only a hint to the controller.
> 
> Agreed. I'm not trying to retry bio allocation inside the
> list_for_each_entry{} loop. Instead, since blk_alloc_discard_bio()
> returning NULL cannot reliably indicate whether the failure is due to
> bio allocation failure, it could also be caused by 'bio_sects == 0', I'd
> like to allocate the bio explicitly.
> 
>>
>> This patch is simply cleaning up dead error-handling branches at the
>> callers no behavioral changes intended.
>>
>> What maybe useful is to stop iterating once we fail to allocate the
>> bio [1].
>>
>> -ck
>>
>> [1] Potential addition on the top of this to exit early in discard loop
>>       on bio allocation failure.
>>
>> diff --git a/fs/xfs/xfs_discard.c b/fs/xfs/xfs_discard.c
>> index b6ffe4807a11..1519f708bb79 100644
>> --- a/fs/xfs/xfs_discard.c
>> +++ b/fs/xfs/xfs_discard.c
>> @@ -129,6 +129,13 @@ xfs_discard_extents(
>>                                   xfs_gbno_to_daddr(xg, busyp->bno),
>>                                   XFS_FSB_TO_BB(mp, busyp->length),
>>                                   GFP_KERNEL, &bio);
>> +               /*
>> +                * We failed to allocate bio instead of continuing the 
>> loop
>> +                * so it will lead to inconsistent discards to the disk
>> +                * exit early and jump into xfs_discard_busy_clear().
>> +                */
>> +               if (!bio)
>> +                       break;
> 
> I noticed that as long as XFS_FSB_TO_BB(mp, busyp->length) is greater
> than 0 and there is no bio allocation failure, __blkdev_issue_discard()
> will never return NULL. I'm not familiar with this part of the xfs, so
> I'm not sure whether there are cases where 'XFS_FSB_TO_BB(mp,
> busyp->length)' could be 0. If such cases do not exist, then
> checking whether the bio is NULL should be sufficient.
> 
> Yongpeng,

If __blkdev_issue_discard() requires multiple calls to
blk_alloc_discard_bio(), once the first bio allocation succeeds, it will
never result in bio == NULL, meaning that any subsequent bio allocation
failures cannot be detected.

Yongpeng,

> 
>>           }
>>           if (bio) {
>> > If we keep looping after the first bio == NULL, the rest of the 
>> range is
>> guaranteed to be inconsistent anyways, because every subsequent iteration
>> will fall into one of three cases:
>>
>> - The allocator keeps returning NULL, so none of the remaining LBAs 
>> receive
>>     discard.
>> - Rest of the allocator succeeds, but we’ve already skipped a chunk, 
>> leaving
>>     a hole in the discard range.
>> - We get intermittent successes, which produces alternating chunks of
>>     discarded and undiscarded blocks.
>>
>> In each of those scenarios, the disk ends up with a partially discarded
>> range, so the correct fix is to break out of the loop immediately and
>> proceed to xfs_discard_busy_clear() once the very first allocation fails.

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

* Re: [f2fs-dev] [PATCH V3 4/6] nvmet: ignore discard return value
  2025-11-24 23:48 ` [PATCH V3 4/6] nvmet: " Chaitanya Kulkarni
@ 2025-11-26 10:14   ` Yongpeng Yang
  2025-11-26 10:37     ` Christoph Hellwig
  0 siblings, 1 reply; 28+ messages in thread
From: Yongpeng Yang @ 2025-11-26 10:14 UTC (permalink / raw)
  To: Chaitanya Kulkarni, axboe, agk, snitzer, mpatocka, song, yukuai,
	hch, sagi, kch, jaegeuk, chao, cem
  Cc: dm-devel, linux-raid, Martin K . Petersen, Johannes Thumshirn,
	linux-kernel, linux-nvme, linux-f2fs-devel, linux-block, bpf,
	linux-xfs


On 11/25/25 07:48, Chaitanya Kulkarni wrote:
> __blkdev_issue_discard() always returns 0, making the error checking
> in nvmet_bdev_discard_range() dead code.
> 
> Kill the function nvmet_bdev_discard_range() and call
> __blkdev_issue_discard() directly from nvmet_bdev_execute_discard(),
> since no error handling is needed anymore for __blkdev_issue_discard()
> call.
> 
> Reviewed-by: Martin K. Petersen <martin.petersen@oracle.com>
> Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
> Reviewed-by: Christoph Hellwig <hch@lst.de>
> Signed-off-by: Chaitanya Kulkarni <ckulkarnilinux@gmail.com>
> ---
>   drivers/nvme/target/io-cmd-bdev.c | 28 +++++++---------------------
>   1 file changed, 7 insertions(+), 21 deletions(-)
> 
> diff --git a/drivers/nvme/target/io-cmd-bdev.c b/drivers/nvme/target/io-cmd-bdev.c
> index 8d246b8ca604..ca7731048940 100644
> --- a/drivers/nvme/target/io-cmd-bdev.c
> +++ b/drivers/nvme/target/io-cmd-bdev.c
> @@ -362,29 +362,14 @@ u16 nvmet_bdev_flush(struct nvmet_req *req)
>   	return 0;
>   }
>   
> -static u16 nvmet_bdev_discard_range(struct nvmet_req *req,
> -		struct nvme_dsm_range *range, struct bio **bio)
> -{
> -	struct nvmet_ns *ns = req->ns;
> -	int ret;
> -
> -	ret = __blkdev_issue_discard(ns->bdev,
> -			nvmet_lba_to_sect(ns, range->slba),
> -			le32_to_cpu(range->nlb) << (ns->blksize_shift - 9),
> -			GFP_KERNEL, bio);
> -	if (ret && ret != -EOPNOTSUPP) {
> -		req->error_slba = le64_to_cpu(range->slba);
> -		return errno_to_nvme_status(req, ret);
> -	}
> -	return NVME_SC_SUCCESS;
> -}
> -
>   static void nvmet_bdev_execute_discard(struct nvmet_req *req)
>   {
> +	struct nvmet_ns *ns = req->ns;
>   	struct nvme_dsm_range range;
>   	struct bio *bio = NULL;
> +	sector_t nr_sects;
>   	int i;
> -	u16 status;
> +	u16 status = NVME_SC_SUCCESS;
>   
>   	for (i = 0; i <= le32_to_cpu(req->cmd->dsm.nr); i++) {
>   		status = nvmet_copy_from_sgl(req, i * sizeof(range), &range,
> @@ -392,9 +377,10 @@ static void nvmet_bdev_execute_discard(struct nvmet_req *req)
>   		if (status)
>   			break;
>   
> -		status = nvmet_bdev_discard_range(req, &range, &bio);
> -		if (status)
> -			break;
> +		nr_sects = le32_to_cpu(range.nlb) << (ns->blksize_shift - 9);
> +		__blkdev_issue_discard(ns->bdev,
> +				nvmet_lba_to_sect(ns, range.slba), nr_sects,
> +				GFP_KERNEL, &bio);

We also need to check for memory allocation errors in
__blkdev_issue_discard(). However, this cannot be done by simply
checking if bio is NULL. Similar to the issue with xfs_discard_extents,
once __blkdev_issue_discard()->blk_alloc_discard_bio() succeeds once,
any subsequent memory allocation failures cannot be detected by checking
if bio is NULL.

Yongpeng,

>   	}
>   
>   	if (bio) {


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

* Re: [f2fs-dev] [PATCH V3 6/6] xfs: ignore discard return value
  2025-11-26  2:37   ` [f2fs-dev] " Yongpeng Yang
  2025-11-26  8:07     ` Chaitanya Kulkarni
@ 2025-11-26 10:33     ` Christoph Hellwig
  1 sibling, 0 replies; 28+ messages in thread
From: Christoph Hellwig @ 2025-11-26 10:33 UTC (permalink / raw)
  To: Yongpeng Yang
  Cc: Chaitanya Kulkarni, axboe, agk, snitzer, mpatocka, song, yukuai,
	hch, sagi, kch, jaegeuk, chao, cem, dm-devel, linux-raid,
	Johannes Thumshirn, linux-kernel, linux-nvme, linux-f2fs-devel,
	linux-block, bpf, linux-xfs, Yongpeng Yang

On Wed, Nov 26, 2025 at 10:37:10AM +0800, Yongpeng Yang wrote:
>>   				xfs_gbno_to_daddr(xg, busyp->bno),
>>   				XFS_FSB_TO_BB(mp, busyp->length),
>>   				GFP_KERNEL, &bio);
>
> If blk_alloc_discard_bio() fails to allocate a bio inside
> __blkdev_issue_discard(),

It won't, because mempool allocations will not fail if they can
sleep as they can here.


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

* Re: [f2fs-dev] [PATCH V3 6/6] xfs: ignore discard return value
  2025-11-26  8:07     ` Chaitanya Kulkarni
  2025-11-26  9:14       ` Yongpeng Yang
@ 2025-11-26 10:34       ` hch
  1 sibling, 0 replies; 28+ messages in thread
From: hch @ 2025-11-26 10:34 UTC (permalink / raw)
  To: Chaitanya Kulkarni
  Cc: Yongpeng Yang, Chaitanya Kulkarni, axboe@kernel.dk,
	agk@redhat.com, snitzer@kernel.org, mpatocka@redhat.com,
	song@kernel.org, yukuai@fnnas.com, hch@lst.de, sagi@grimberg.me,
	jaegeuk@kernel.org, chao@kernel.org, cem@kernel.org,
	dm-devel@lists.linux.dev, linux-raid@vger.kernel.org,
	Johannes Thumshirn, linux-kernel@vger.kernel.org,
	linux-nvme@lists.infradead.org,
	linux-f2fs-devel@lists.sourceforge.net,
	linux-block@vger.kernel.org, bpf@vger.kernel.org,
	linux-xfs@vger.kernel.org, Yongpeng Yang

On Wed, Nov 26, 2025 at 08:07:21AM +0000, Chaitanya Kulkarni wrote:
> The retry for discard bio memory allocation is not desired I think,
> since it's only a hint to the controller.

Yes, it is.  The command is defined as a hint, but it's required for
a lot of workloads to work.  It's not just a speculative readahead.


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

* Re: [f2fs-dev] [PATCH V3 4/6] nvmet: ignore discard return value
  2025-11-26 10:14   ` [f2fs-dev] " Yongpeng Yang
@ 2025-11-26 10:37     ` Christoph Hellwig
  0 siblings, 0 replies; 28+ messages in thread
From: Christoph Hellwig @ 2025-11-26 10:37 UTC (permalink / raw)
  To: Yongpeng Yang
  Cc: Chaitanya Kulkarni, axboe, agk, snitzer, mpatocka, song, yukuai,
	hch, sagi, kch, jaegeuk, chao, cem, dm-devel, linux-raid,
	Martin K . Petersen, Johannes Thumshirn, linux-kernel, linux-nvme,
	linux-f2fs-devel, linux-block, bpf, linux-xfs

On Wed, Nov 26, 2025 at 06:14:32PM +0800, Yongpeng Yang wrote:
> We also need to check for memory allocation errors in
> __blkdev_issue_discard().

No, we still don't.  What is so hard to grasp about mempool allocations
even after repeated explanations?


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

* Re: [f2fs-dev] [PATCH V3 0/6] block: ignore __blkdev_issue_discard() ret value
  2025-11-24 23:48 [PATCH V3 0/6] block: ignore __blkdev_issue_discard() ret value Chaitanya Kulkarni
                   ` (7 preceding siblings ...)
  2025-11-25 19:20 ` (subset) " Jens Axboe
@ 2025-12-03 21:50 ` patchwork-bot+f2fs
  2025-12-09 17:18 ` patchwork-bot+f2fs
  9 siblings, 0 replies; 28+ messages in thread
From: patchwork-bot+f2fs @ 2025-12-03 21:50 UTC (permalink / raw)
  To: Chaitanya Kulkarni
  Cc: axboe, agk, snitzer, mpatocka, song, yukuai, hch, sagi, kch,
	jaegeuk, chao, cem, dm-devel, linux-raid, linux-kernel,
	linux-nvme, linux-f2fs-devel, linux-block, bpf, linux-xfs

Hello:

This series was applied to jaegeuk/f2fs.git (dev)
by Jaegeuk Kim <jaegeuk@kernel.org>:

On Mon, 24 Nov 2025 15:48:00 -0800 you wrote:
> Hi,
> 
> __blkdev_issue_discard() only returns value 0, that makes post call
> error checking code dead. This patch series revmoes this dead code at
> all the call sites and adjust the callers.
> 
> Please note that it doesn't change the return type of the function from
> int to void in this series, it will be done once this series gets merged
> smoothly.
> 
> [...]

Here is the summary with links:
  - [f2fs-dev,V3,1/6] block: ignore discard return value
    (no matching commit)
  - [f2fs-dev,V3,2/6] md: ignore discard return value
    (no matching commit)
  - [f2fs-dev,V3,3/6] dm: ignore discard return value
    (no matching commit)
  - [f2fs-dev,V3,4/6] nvmet: ignore discard return value
    (no matching commit)
  - [f2fs-dev,V3,5/6] f2fs: ignore discard return value
    https://git.kernel.org/jaegeuk/f2fs/c/807e755c468a
  - [f2fs-dev,V3,6/6] xfs: ignore discard return value
    (no matching commit)

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



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

* Re: [f2fs-dev] [PATCH V3 0/6] block: ignore __blkdev_issue_discard() ret value
  2025-11-24 23:48 [PATCH V3 0/6] block: ignore __blkdev_issue_discard() ret value Chaitanya Kulkarni
                   ` (8 preceding siblings ...)
  2025-12-03 21:50 ` [f2fs-dev] " patchwork-bot+f2fs
@ 2025-12-09 17:18 ` patchwork-bot+f2fs
  9 siblings, 0 replies; 28+ messages in thread
From: patchwork-bot+f2fs @ 2025-12-09 17:18 UTC (permalink / raw)
  To: Chaitanya Kulkarni
  Cc: axboe, agk, snitzer, mpatocka, song, yukuai, hch, sagi, kch,
	jaegeuk, chao, cem, dm-devel, linux-raid, linux-kernel,
	linux-nvme, linux-f2fs-devel, linux-block, bpf, linux-xfs

Hello:

This series was applied to jaegeuk/f2fs.git (dev)
by Jens Axboe <axboe@kernel.dk>:

On Mon, 24 Nov 2025 15:48:00 -0800 you wrote:
> Hi,
> 
> __blkdev_issue_discard() only returns value 0, that makes post call
> error checking code dead. This patch series revmoes this dead code at
> all the call sites and adjust the callers.
> 
> Please note that it doesn't change the return type of the function from
> int to void in this series, it will be done once this series gets merged
> smoothly.
> 
> [...]

Here is the summary with links:
  - [f2fs-dev,V3,1/6] block: ignore discard return value
    https://git.kernel.org/jaegeuk/f2fs/c/7d09a8e25121
  - [f2fs-dev,V3,2/6] md: ignore discard return value
    (no matching commit)
  - [f2fs-dev,V3,3/6] dm: ignore discard return value
    (no matching commit)
  - [f2fs-dev,V3,4/6] nvmet: ignore discard return value
    (no matching commit)
  - [f2fs-dev,V3,5/6] f2fs: ignore discard return value
    (no matching commit)
  - [f2fs-dev,V3,6/6] xfs: ignore discard return value
    (no matching commit)

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



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

end of thread, other threads:[~2025-12-09 17:21 UTC | newest]

Thread overview: 28+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-24 23:48 [PATCH V3 0/6] block: ignore __blkdev_issue_discard() ret value Chaitanya Kulkarni
2025-11-24 23:48 ` [PATCH V3 1/6] block: ignore discard return value Chaitanya Kulkarni
2025-11-25 17:38   ` Jens Axboe
2025-11-25 19:09     ` Chaitanya Kulkarni
2025-11-25 19:19       ` Jens Axboe
2025-11-24 23:48 ` [PATCH V3 2/6] md: " Chaitanya Kulkarni
2025-11-24 23:48 ` [PATCH V3 3/6] dm: " Chaitanya Kulkarni
2025-11-24 23:48 ` [PATCH V3 4/6] nvmet: " Chaitanya Kulkarni
2025-11-26 10:14   ` [f2fs-dev] " Yongpeng Yang
2025-11-26 10:37     ` Christoph Hellwig
2025-11-24 23:48 ` [PATCH V3 5/6] f2fs: " Chaitanya Kulkarni
2025-11-25  1:10   ` Chao Yu
2025-11-25  6:33     ` Christoph Hellwig
2025-11-25  7:11       ` Chao Yu
2025-11-26  2:47   ` Chao Yu
2025-11-26  3:37     ` Chaitanya Kulkarni
2025-11-26  3:58       ` Chao Yu
2025-11-24 23:48 ` [PATCH V3 6/6] xfs: " Chaitanya Kulkarni
2025-11-26  2:37   ` [f2fs-dev] " Yongpeng Yang
2025-11-26  8:07     ` Chaitanya Kulkarni
2025-11-26  9:14       ` Yongpeng Yang
2025-11-26  9:48         ` Yongpeng Yang
2025-11-26 10:34       ` hch
2025-11-26 10:33     ` Christoph Hellwig
2025-11-25 13:20 ` [PATCH V3 0/6] block: ignore __blkdev_issue_discard() ret value Anuj gupta
2025-11-25 19:20 ` (subset) " Jens Axboe
2025-12-03 21:50 ` [f2fs-dev] " patchwork-bot+f2fs
2025-12-09 17:18 ` patchwork-bot+f2fs

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).