block: ignore __blkdev_issue_discard() ret value
Subsystems (8)
v3 cover block: ignore __blkdev_issue_discard() ret value
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(-)
Signature · 1 line
2.40.0
PATCH v3 1/6 block: ignore discard return value
__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.
--- block/blk-lib.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
block/blk-lib.c +3 -3
@@ -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 ;
Signature · 1 line
2.40.0
Jens Axboe
maintainerRe: [PATCH V3 1/6] block: ignore discard return value
Quoted 2 lines · Chaitanya Kulkarni
__blkdev_issue_discard()always returns 0, making the error check inblkdev_issue_discard()dead code.
Shouldn't it be a void instead then?
Signature · 1 line
Jens Axboe
Re: [PATCH V3 1/6] block: ignore discard return value
Quoted 5 lines · Jens Axboe
Quoted 2 lines · Chaitanya Kulkarni
__blkdev_issue_discard()always returns 0, making the error check inblkdev_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 <[email protected]>
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().
--- block/blk-lib.c | 3 +-- include/linux/blkdev.h | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-)
block/blk-lib.c +1 -2
@@ -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, §or, &nr_sects, gfp_mask))) *biop =bio_chain_and_submit (*biop, bio); -return 0 ; }EXPORT_SYMBOL (__blkdev_issue_discard);
include/linux/blkdev.h +1 -1
@@ -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);
Signature · 1 line
2.40.0
Jens Axboe
maintainerRe: [PATCH V3 1/6] block: ignore discard return value
Quoted 9 lines · Chaitanya Kulkarni
Quoted 5 lines · Jens Axboe
Quoted 2 lines · Chaitanya Kulkarni
__blkdev_issue_discard()always returns 0, making the error check inblkdev_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.
Signature · 1 line
Jens Axboe
PATCH v3 2/6 md: ignore discard return value
In reply to Chaitanya Kulkarni__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.
--- drivers/md/md.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/md/md.c +2 -2
@@ -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);
Signature · 1 line
2.40.0
Re: [PATCH V3 2/6] md: ignore discard return value
Hi Song Liu and Yu Kuai,
Quoted 19 lines · Chaitanya Kulkarni
__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 <[email protected]>Reviewed-by Johannes Thumshirn <[email protected]>Reviewed-by Christoph Hellwig <[email protected]>Signed-off-by Chaitanya Kulkarni <[email protected]>--- drivers/md/md.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/md/md.c +0
-0
drivers/md/md.c void md_submit_discard_bio(struct mddev *mddev, struct md_rdev *rdev, · line 9139
Quoted 10 lines
drivers/md/md.c +2
-2@@ -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);
Gentle ping on this.
-ck
Re: [PATCH V3 2/6] md: ignore discard return value
Quoted 36 lines · Chaitanya Kulkarni
Hi Song Liu and Yu Kuai,
Quoted 28 lines · Chaitanya Kulkarni
__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 <[email protected]>Reviewed-by Johannes Thumshirn <[email protected]>Reviewed-by Christoph Hellwig <[email protected]>Signed-off-by Chaitanya Kulkarni <[email protected]>---
drivers/md/md.c| 4 ++--1 file changed, 2 insertions(+), 2 deletions(-)drivers/md/md.c +2
-1@@ -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;Quoted 1 line
bio_chain(discard_bio, bio);Gentle ping on this.
Quoted 3 lines
-ck
Hi Song Liu and Yu Kuai,
Just pulled latest changes I don't see this patch been applied [1]. Unless my git repo is messed up.
Can you please provide review comments and let me know the blocker ?
-ck
9169 /* This is used by raid0 and raid10 */
9170 void md_submit_discard_bio(struct mddev *mddev, struct md_rdev *rdev,
9171 struct bio *bio, sector_t start, sector_t size)
9172 {
9173 struct bio *discard_bio = NULL;
9174
9175 if (__blkdev_issue_discard(rdev->bdev, start, size, GFP_NOIO,
9176 &discard_bio) || !discard_bio)
9177 return;
9178
9179 bio_chain(discard_bio, bio);
9180 bio_clone_blkg_association(discard_bio, bio);
9181 mddev_trace_remap(mddev, discard_bio, bio->bi_iter.bi_sector);
9182 submit_bio_noacct(discard_bio);
9183 }
9184 EXPORT_SYMBOL_GPL(md_submit_discard_bio);PATCH v3 3/6 dm: ignore discard return value
In reply to Chaitanya Kulkarni__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().
--- drivers/md/dm-thin.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-)
drivers/md/dm-thin.c +5 -7
@@ -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 *mbreak ; } - 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 ); } }
Signature · 1 line
2.40.0
Re: [PATCH V3 3/6] dm: ignore discard return value
Hi Mike and Mikulas,
Quoted 8 lines · Chaitanya Kulkarni
__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, inpassdown_double_checking_shared_status()remove the r assignment from return value of theissue_discard(), forend_discard()hardcode value of r to 0 that matches only value returned from__blkdev_issue_discard().
Quoted 5 lines
Reviewed-by Martin K. Petersen<[email protected]>Reviewed-by Johannes Thumshirn<[email protected]>Reviewed-by Christoph Hellwig<[email protected]>Signed-off-by Chaitanya Kulkarni<[email protected]>---
Gentle ping on this.
-ck
Mikulas Patocka
maintainerRe: [PATCH V3 3/6] dm: ignore discard return value
Quoted 18 lines · Chaitanya Kulkarni
Hi Mike and Mikulas,
Quoted 8 lines · Chaitanya Kulkarni
__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, inpassdown_double_checking_shared_status()remove the r assignment from return value of theissue_discard(), forend_discard()hardcode value of r to 0 that matches only value returned from__blkdev_issue_discard().Quoted 5 lines
Reviewed-by Martin K. Petersen<[email protected]>Reviewed-by Johannes Thumshirn<[email protected]>Reviewed-by Christoph Hellwig<[email protected]>Signed-off-by Chaitanya Kulkarni<[email protected]>---
Quoted 3 lines
Gentle ping on this.
-ck
Hi
I thought that this patch would go with the other patches that do the same change in other subsystems - but if you want me to make it go through the device mapper tree, I can do it.
I staged the patch for this merge window.
Mikulas
PATCH v3 4/6 nvmet: ignore discard return value
In reply to Chaitanya Kulkarni__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.
--- drivers/nvme/target/io-cmd-bdev.c | 28 +++++++--------------------- 1 file changed, 7 insertions(+), 21 deletions(-)
drivers/nvme/target/io-cmd-bdev.c +7 -21
@@ -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) {
Signature · 1 line
2.40.0
Re: [f2fs-dev] [PATCH V3 4/6] nvmet: ignore discard return value
Quoted 54 lines · Chaitanya Kulkarni
__blkdev_issue_discard()always returns 0, making the error checking innvmet_bdev_discard_range()dead code.Kill the function
nvmet_bdev_discard_range()and call__blkdev_issue_discard()directly fromnvmet_bdev_execute_discard(), since no error handling is needed anymore for__blkdev_issue_discard()call.Reviewed-by Martin K. Petersen <[email protected]>Reviewed-by Johannes Thumshirn <[email protected]>Reviewed-by Christoph Hellwig <[email protected]>Signed-off-by Chaitanya Kulkarni <[email protected]>--- drivers/nvme/target/io-cmd-bdev.c | 28 +++++++--------------------- 1 file changed, 7 insertions(+), 21 deletions(-)drivers/nvme/target/io-cmd-bdev.c +3
-18@@ -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,
drivers/nvme/target/io-cmd-bdev.c static void nvmet_bdev_execute_discard(struct nvmet_req *req) · line 383
Quoted 10 lines
drivers/nvme/target/io-cmd-bdev.c +4
-3@@ -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,
Quoted 3 lines
drivers/nvme/target/io-cmd-bdev.c +0
-0}if (bio) {
Christoph Hellwig
maintainerRe: [f2fs-dev] [PATCH V3 4/6] nvmet: ignore discard return value
Quoted 2 lines · Yongpeng Yang
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?
Re: [PATCH V3 4/6] nvmet: ignore discard return value
In reply to Chaitanya KulkarniQuoted 8 lines · Chaitanya Kulkarni
__blkdev_issue_discard()always returns 0, making the error checking innvmet_bdev_discard_range()dead code.Kill the function
nvmet_bdev_discard_range()and call__blkdev_issue_discard()directly fromnvmet_bdev_execute_discard(), since no error handling is needed anymore for__blkdev_issue_discard()call.
Quoted 5 lines
Reviewed-by Martin K. Petersen <[email protected]>Reviewed-by Johannes Thumshirn <[email protected]>Reviewed-by Christoph Hellwig <[email protected]>Signed-off-by Chaitanya Kulkarni <[email protected]>---
Gentle ping on this, can we apply this patch ?
-ck
[email protected]
maintainerRe: [PATCH V3 4/6] nvmet: ignore discard return value
Quoted 9 lines · Chaitanya Kulkarni
Quoted 8 lines · Chaitanya Kulkarni
__blkdev_issue_discard()always returns 0, making the error checking innvmet_bdev_discard_range()dead code.Kill the function
nvmet_bdev_discard_range()and call__blkdev_issue_discard()directly fromnvmet_bdev_execute_discard(), since no error handling is needed anymore for__blkdev_issue_discard()call.
Quoted 7 lines
Quoted 5 lines
Reviewed-by Martin K. Petersen <[email protected]>Reviewed-by Johannes Thumshirn <[email protected]>Reviewed-by Christoph Hellwig <[email protected]>Signed-off-by Chaitanya Kulkarni <[email protected]>---
Gentle ping on this, can we apply this patch ?
Are we down to three patches now? Maybe resend the whole series and get ACKs to merge everything through the block layer?
Re: [PATCH V3 4/6] nvmet: ignore discard return value
Quoted 10 lines · On 1/25/26 20:57, [email protected] wrote:
Quoted 9 lines · Chaitanya Kulkarni
Quoted 8 lines · Chaitanya Kulkarni
__blkdev_issue_discard()always returns 0, making the error checking innvmet_bdev_discard_range()dead code.Kill the function
nvmet_bdev_discard_range()and call__blkdev_issue_discard()directly fromnvmet_bdev_execute_discard(), since no error handling is needed anymore for__blkdev_issue_discard()call.
Quoted 9 lines
Quoted 6 lines
Quoted 5 lines
Reviewed-by Martin K. Petersen <[email protected]>Reviewed-by Johannes Thumshirn <[email protected]>Reviewed-by Christoph Hellwig <[email protected]>Signed-off-by Chaitanya Kulkarni <[email protected]>---
Gentle ping on this, can we apply this patch ?
Are we down to three patches now? Maybe resend the whole series and get ACKs to merge everything through the block layer?
sounds good, will re-spin the remaining patches on linux-block/for-next.
-ck
PATCH v3 5/6 f2fs: ignore discard return value
In reply to Chaitanya Kulkarni__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.
--- fs/f2fs/segment.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-)
fs/f2fs/segment.c +3 -7
@@ -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);/*
Signature · 1 line
2.40.0
Re: [PATCH V3 5/6] f2fs: ignore discard return value
Quoted 7 lines · Chaitanya Kulkarni
__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.
Quoted 7 lines
This preserves the fault injection behavior while removing dead error handling.
Reviewed-by Martin K. Petersen <[email protected]>Reviewed-by Johannes Thumshirn <[email protected]>Reviewed-by Christoph Hellwig <[email protected]>Signed-off-by Chaitanya Kulkarni <[email protected]>
Thanks,
Christoph Hellwig
maintainerRe: [PATCH V3 5/6] f2fs: ignore discard return value
Quoted 1 line · Chao Yu
Reviewed-by Chao Yu <[email protected]>
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?
Chao Yu
maintainerRe: [PATCH V3 5/6] f2fs: ignore discard return value
Quoted 8 lines · Christoph Hellwig
Quoted 1 line · Chao Yu
Reviewed-by Chao Yu <[email protected]>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,
Re: [f2fs-dev] [PATCH V3 5/6] f2fs: ignore discard return value
Hi Jaegeuk Kim and Chao Yu,
Quoted 8 lines · Chao Yu
Quoted 7 lines · Christoph Hellwig
Quoted 1 line · Chao Yu
Reviewed-by Chao Yu <[email protected]>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.
Quoted 5 lines
Quoted 1 line
Can we get this queued up in the f2fs tree?
Yes, I think it's clean to queue this patch into f2fs tree.
Thanks,
Gentle ping on this, if it's not already queued up, otherwise please ignore this email.
-ck
_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
Chao Yu
maintainerRe: [PATCH V3 5/6] f2fs: ignore discard return value
In reply to Chaitanya KulkarniQuoted 40 lines · Chaitanya Kulkarni
__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 <[email protected]>Reviewed-by Johannes Thumshirn <[email protected]>Reviewed-by Christoph Hellwig <[email protected]>Signed-off-by Chaitanya Kulkarni <[email protected]>--- fs/f2fs/segment.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-)fs/f2fs/segment.c +1
-7@@ -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 ;
fs/f2fs/segment.c static int __submit_discard_cmd(struct f2fs_sb_info *sbi, · line 1358
Quoted 5 lines
fs/f2fs/segment.c +2
-0@@ -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,
Quoted 3 lines
fs/f2fs/segment.c +0
-0f2fs_bug_on (sbi, !bio);/*
Re: [PATCH V3 5/6] f2fs: ignore discard return value
Quoted 44 lines · Chao Yu
Quoted 43 lines · Chaitanya Kulkarni
__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 <[email protected]>Reviewed-by Johannes Thumshirn <[email protected]>Reviewed-by Christoph Hellwig <[email protected]>Signed-off-by Chaitanya Kulkarni <[email protected]>--- fs/f2fs/segment.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-)fs/f2fs/segment.c +1
-7@@ -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 ; }
Quoted 5 lines
fs/f2fs/segment.c static int __submit_discard_cmd(struct f2fs_sb_info *sbi, · line 1358
Quoted 2 lines
fs/f2fs/segment.c +2
-0+__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.
Quoted 4 lines
fs/f2fs/segment.c static int __submit_discard_cmd(struct f2fs_sb_info *sbi, · line 1361
Quoted 4 lines
fs/f2fs/segment.c +0
-0f2fs_bug_on (sbi, !bio);/*
-ck
Chao Yu
maintainerRe: [PATCH V3 5/6] f2fs: ignore discard return value
Quoted 73 lines · Chaitanya Kulkarni
Quoted 44 lines · Chao Yu
Quoted 43 lines · Chaitanya Kulkarni
__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 <[email protected]>Reviewed-by Johannes Thumshirn <[email protected]>Reviewed-by Christoph Hellwig <[email protected]>Signed-off-by Chaitanya Kulkarni <[email protected]>--- fs/f2fs/segment.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-)fs/f2fs/segment.c +1
-7@@ -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 ; }Quoted 5 lines
fs/f2fs/segment.c static int __submit_discard_cmd(struct f2fs_sb_info *sbi, · line 1358
Quoted 2 lines
fs/f2fs/segment.c +2
-0+__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
-EIOand that will only happen whentime_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) {
1355spin_lock_irqsave(&dc->lock, flags);
1356 if (dc->state==D_PARTIAL)
1357dc->state=D_SUBMIT;
1358spin_unlock_irqrestore(&dc->lock, flags);
1359
1360 break;
1361 }
Quoted 3 lines
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,
Quoted 10 lines
Quoted 6 lines
fs/f2fs/segment.c static int __submit_discard_cmd(struct f2fs_sb_info *sbi, · line 1361
Quoted 6 lines
fs/f2fs/segment.c +0
-0f2fs_bug_on (sbi, !bio);/* -ck
PATCH v3 6/6 xfs: ignore discard return value
In reply to Chaitanya Kulkarni__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.
--- fs/xfs/xfs_discard.c | 27 +++++---------------------- fs/xfs/xfs_discard.h | 2 +- 2 files changed, 6 insertions(+), 23 deletions(-)
fs/xfs/xfs_discard.c +5 -22
@@ -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);
fs/xfs/xfs_discard.h +1 -1
@@ -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 */
Signature · 1 line
2.40.0
Re: [f2fs-dev] [PATCH V3 6/6] xfs: ignore discard return value
Quoted 44 lines · Chaitanya Kulkarni
__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()andxfs_trim_rtgroup_extents()to ignore thexfs_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 <[email protected]>Reviewed-by Christoph Hellwig <[email protected]>Signed-off-by Chaitanya Kulkarni <[email protected]>--- fs/xfs/xfs_discard.c | 27 +++++---------------------- fs/xfs/xfs_discard.h | 2 +- 2 files changed, 6 insertions(+), 23 deletions(-)fs/xfs/xfs_discard.c +1
-2@@ -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) {
fs/xfs/xfs_discard.c xfs_discard_extents( · line 131
Quoted 8 lines
fs/xfs/xfs_discard.c +1
-1@@ -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,
Quoted 69 lines
fs/xfs/xfs_discard.c +3
-19-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);fs/xfs/xfs_discard.h +1
-1@@ -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 */
Re: [f2fs-dev] [PATCH V3 6/6] xfs: ignore discard return value
Quoted 35 lines · Yongpeng Yang
Quoted 22 lines
fs/xfs/xfs_discard.c +0
-0@@ -108,7 +108,7 @@ xfs_discard_endio( * list. We plug and chain the bios so that we only need a singlecompletion
* call to clear all the busy extents once the discards are complete. */fs/xfs/xfs_discard.c +1
-1-int +void xfs_discard_extents(
struct xfs_mount *mp,
struct xfs_busy_extents *extents)fs/xfs/xfs_discard.c +0
-1@@ -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) {fs/xfs/xfs_discard.c xfs_discard_extents( · line 130
Quoted 6 lines
fs/xfs/xfs_discard.c +1
-0@@ -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{}?
Quoted 1 line
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.
fs/xfs/xfs_discard.c +7 -0
@@ -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.
Re: [f2fs-dev] [PATCH V3 6/6] xfs: ignore discard return value
Quoted 39 lines · On 11/26/25 16:07, Chaitanya Kulkarni via Linux-f2fs-devel wrote:
Quoted 35 lines · Yongpeng Yang
Quoted 22 lines
fs/xfs/xfs_discard.c +0
-0@@ -108,7 +108,7 @@ xfs_discard_endio( * list. We plug and chain the bios so that we only need a singlecompletion
* call to clear all the busy extents once the discards are complete. */fs/xfs/xfs_discard.c +1
-2-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) {fs/xfs/xfs_discard.c xfs_discard_extents( · line 130
Quoted 6 lines
fs/xfs/xfs_discard.c +1
-0@@ -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{}?Quoted 1 line
Yongpeng,
Quoted 7 lines
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.
Quoted 17 lines
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.
fs/xfs/xfs_discard.c +0
-0
fs/xfs/xfs_discard.c xfs_discard_extents( · line 138
Quoted 10 lines
fs/xfs/xfs_discard.c +7
-0@@ -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,
Quoted 17 lines
fs/xfs/xfs_discard.c +0
-0}if (bio) {Quoted 1 line
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.
Re: [f2fs-dev] [PATCH V3 6/6] xfs: ignore discard return value
Quoted 90 lines · Yongpeng Yang
Quoted 39 lines · On 11/26/25 16:07, Chaitanya Kulkarni via Linux-f2fs-devel wrote:
Quoted 35 lines · Yongpeng Yang
Quoted 22 lines
fs/xfs/xfs_discard.c +0
-0@@ -108,7 +108,7 @@ xfs_discard_endio( * list. We plug and chain the bios so that we only need a singlecompletion
* call to clear all the busy extents once the discards are complete. */fs/xfs/xfs_discard.c +1
-1-int +void xfs_discard_extents(
struct xfs_mount *mp,
struct xfs_busy_extents *extents)fs/xfs/xfs_discard.c +0
-1@@ -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) {fs/xfs/xfs_discard.c xfs_discard_extents( · line 130
Quoted 6 lines
fs/xfs/xfs_discard.c +1
-0@@ -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{}?Quoted 1 line
Yongpeng,
Quoted 7 lines
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.Quoted 22 lines
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.
fs/xfs/xfs_discard.c +2
-0@@ -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 Quoted 6 lines
loop
+ * so it will lead to inconsistent discards to the disk + * exit early and jump intoxfs_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.
Quoted 1 line
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,
Quoted 20 lines
Quoted 20 lines
}
if (bio) {Quoted 1 line
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.
[email protected]
maintainerRe: [f2fs-dev] [PATCH V3 6/6] xfs: ignore discard return value
In reply to Chaitanya KulkarniQuoted 2 lines · Chaitanya Kulkarni
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.
Christoph Hellwig
maintainerRe: [f2fs-dev] [PATCH V3 6/6] xfs: ignore discard return value
In reply to Yongpeng YangQuoted 6 lines · Yongpeng Yang
Quoted 3 lines
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.
Re: [PATCH V3 6/6] xfs: ignore discard return value
In reply to Chaitanya KulkarniHi Carlos Maiolino,
Quoted 11 lines · Chaitanya Kulkarni
__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()andxfs_trim_rtgroup_extents()to ignore thexfs_discard_extents()return value and error checking code.
Quoted 7 lines
Update
xfs_discard_rtdev_extents()to ignore__blkdev_issue_discard()return value and error checking code.Reviewed-by Johannes Thumshirn <[email protected]>Reviewed-by Christoph Hellwig <[email protected]>Signed-off-by Chaitanya Kulkarni <[email protected]>---
Gentle ping on this.
-ck
Carlos Maiolino
maintainerRe: [PATCH V3 6/6] xfs: ignore discard return value
Quoted 17 lines · Chaitanya Kulkarni
Hi Carlos Maiolino,
Quoted 14 lines · Chaitanya Kulkarni
__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()andxfs_trim_rtgroup_extents()to ignore thexfs_discard_extents()return value and error checking code.Update
xfs_discard_rtdev_extents()to ignore__blkdev_issue_discard()return value and error checking code.
Quoted 6 lines
Quoted 4 lines
Reviewed-by Johannes Thumshirn <[email protected]>Reviewed-by Christoph Hellwig <[email protected]>Signed-off-by Chaitanya Kulkarni <[email protected]>---
Gentle ping on this.
Thanks for the heads up, I'll queue it for the next batch
Quoted 4 lines
-ck
Re: (subset) [PATCH V3 0/6] block: ignore __blkdev_issue_discard() ret value
In reply to Chaitanya KulkarniQuoted 9 lines · Chaitanya Kulkarni
__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,
Signature · 1 line
Jens Axboe
This series was applied to jaegeuk/f2fs.git (dev) by Jaegeuk Kim <[email protected]>:
Hello:
This series was applied to jaegeuk/f2fs.git (dev)
by Jaegeuk Kim <[email protected]>:
Quoted 11 lines · 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!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html
This series was applied to jaegeuk/f2fs.git (dev) by Jens Axboe <[email protected]>:
Hello:
This series was applied to jaegeuk/f2fs.git (dev)
by Jens Axboe <[email protected]>:
Quoted 11 lines · 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!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html
This series was applied to jaegeuk/f2fs.git (dev) by Mikulas Patocka <[email protected]>:
Hello:
This series was applied to jaegeuk/f2fs.git (dev)
by Mikulas Patocka <[email protected]>:
Quoted 11 lines · 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
https://git.kernel.org/jaegeuk/f2fs/c/f4412c7d5a5a
- [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!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html
This series was applied to jaegeuk/f2fs.git (dev) by Carlos Maiolino <[email protected]>:
Hello:
This series was applied to jaegeuk/f2fs.git (dev)
by Carlos Maiolino <[email protected]>:
Quoted 11 lines · 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
https://git.kernel.org/jaegeuk/f2fs/c/699fcfb6cb80 - [f2fs-dev,V3,3/6] dm: ignore discard return value (no matching commit) - [f2fs-dev,V3,4/6] nvmet: ignore discard return value https://git.kernel.org/jaegeuk/f2fs/c/38d12f15c477 - [f2fs-dev,V3,5/6] f2fs: ignore discard return value (no matching commit) - [f2fs-dev,V3,6/6] xfs: ignore discard return value https://git.kernel.org/jaegeuk/f2fs/c/2145f447b79a
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html