block: change __blkdev_issue_discard() return type to void
Subsystems (7)
RFC PATCH 1/1 block: change __blkdev_issue_discard() return type to void
__blkdev_issue_discard() always returns 0, making all error checking at call sites dead code. The function simply stops allocating bios and returns 0.
Discard operations are advisory/optimization, not critical. Some callers have dead error checking code expecting wrong return codes such as -ENOTSUPP when 0 is only returned.
This patch changes __blkdev_issue_discard() return type to void and removes dead error checking code from all call sites:
* Block layer:
blk-lib.c: Remove return value, update blkdev_issue_discard() caller
* Device mapper:
dm-thin.c: Change issue_discard() to void, update both callers md.c: Simplify conditional to just check for NULL bio
* NVMe target:
io-cmd-bdev.c: Remove dead error handling and error_slba assignment
* Filesystems:
f2fs/segment.c: Preserve fault injection xfs/xfs_discard.c: Update both xfs_discard_extents() and xfs_discard_rtdev_extents() to remove dead error checks
---
Hi,
Due to involvement of all the subsystem making it as an RFC, ideally it shuoldn't be an RFC.
-ck
--- block/blk-lib.c | 7 +++---- drivers/md/dm-thin.c | 12 +++++------- drivers/md/md.c | 4 ++-- drivers/nvme/target/io-cmd-bdev.c | 7 +------ fs/f2fs/segment.c | 2 +- fs/xfs/xfs_discard.c | 17 +++-------------- include/linux/blkdev.h | 2 +- 7 files changed, 16 insertions(+), 35 deletions(-)
block/blk-lib.c +3 -4
@@ -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);
@@ -90,8 +89,8 @@ int blkdev_issue_discard(struct block_device *bdev, sector_t sector,int ret;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 ;
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 ); } }
drivers/md/md.c +2 -2
@@ -9041,8 +9041,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);
drivers/nvme/target/io-cmd-bdev.c +1 -6
@@ -366,16 +366,11 @@ 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, +__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 ; }
fs/f2fs/segment.c +1 -1
@@ -1346,7 +1346,7 @@ static int __submit_discard_cmd(struct f2fs_sb_info *sbi,if (time_to_inject (sbi,FAULT_DISCARD )) { err = -EIO ; }else { - err =__blkdev_issue_discard (bdev, +__blkdev_issue_discard (bdev,SECTOR_FROM_BLOCK (start),SECTOR_FROM_BLOCK (len),GFP_NOFS , &bio);
fs/xfs/xfs_discard.c +3 -14
@@ -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) {
@@ -149,7 +140,7 @@ xfs_discard_extents( }blk_finish_plug (&plug); -return error; +return 0 ; }/*
@@ -496,12 +487,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);
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
Christoph Hellwig
maintainerQuoted 2 lines · Chaitanya Kulkarni
Due to involvement of all the subsystem making it as an RFC, ideally it shuoldn't be an RFC.
I think best would be a series that drops error checking first, and then changes the return type. That way we can maybe get all the callers fixed up in this merge window and then drop the return value after -rc1.
block/blk-lib.c int blkdev_issue_discard(struct block_device *bdev, sector_t sector, · line 92
Quoted 13 lines
block/blk-lib.c +1
-3gfp_mask))) *biop =bio_chain_and_submit (*biop, bio); -return 0 ; }EXPORT_SYMBOL (__blkdev_issue_discard);@@ -90,8 +89,8 @@ int blkdev_issue_discard(struct block_device *bdev, sector_t sector,int ret;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);
ret now needs to be initialized to 0 above.
Quoted 9 lines
index
8d246b8ca604..f26010c46c33100644drivers/nvme/target/io-cmd-bdev.c +0
-1@@ -366,16 +366,11 @@ 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;
drivers/nvme/target/io-cmd-bdev.c static u16 nvmet_bdev_discard_range(struct nvmet_req *req, · line 374
Quoted 10 lines
drivers/nvme/target/io-cmd-bdev.c +1
-5- ret =__blkdev_issue_discard (ns->bdev, +__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 ;
nvmet_bdev_discard_range can return void now.
fs/f2fs/segment.c static int __submit_discard_cmd(struct f2fs_sb_info *sbi, · line 1352
Quoted 13 lines
fs/f2fs/segment.c +1
-1@@ -1346,7 +1346,7 @@ static int __submit_discard_cmd(struct f2fs_sb_info *sbi,if (time_to_inject (sbi,FAULT_DISCARD )) { err = -EIO ; }else { - err =__blkdev_issue_discard (bdev, +__blkdev_issue_discard (bdev,SECTOR_FROM_BLOCK (start),SECTOR_FROM_BLOCK (len),GFP_NOFS , &bio);
Please fold the following 'if (err)' block directly into the injection one, and either initialize err to 0, or use a direct return from that block to skip the last branch in the function checking err.
fs/f2fs/segment.c
Quoted 4 lines
fs/f2fs/segment.c +1
-1blk_finish_plug (&plug); -return error; +return 0 ;
Please drop the error return for xfs_discard_extents entirely.
Quoted 7 lines · Christoph Hellwig
Quoted 2 lines · Chaitanya Kulkarni
Due to involvement of all the subsystem making it as an RFC, ideally it shuoldn't be an RFC.
I think best would be a series that drops error checking first, and then changes the return type. That way we can maybe get all the callers fixed up in this merge window and then drop the return value after -rc1.
thanks for the suggestion
Quoted 6 lines
Quoted 6 lines
gfp_mask))) *biop = bio_chain_and_submit(*biop, bio);(quoted diff) +0
-1- return 0; } EXPORT_SYMBOL(__blkdev_issue_discard);
Quoted 8 lines
Review int blkdev_issue_discard(struct block_device *bdev, sector_t sector, · line 92
Quoted 7 lines
(quoted diff) +1
-2@@ -90,8 +89,8 @@ int blkdev_issue_discard(struct block_device *bdev, sector_t sector, int ret; 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);ret now needs to be initialized to 0 above.
done.
Quoted 10 lines
Quoted 10 lines
index
8d246b8ca604..f26010c46c33100644drivers/nvme/target/io-cmd-bdev.c +0
-1@@ -366,16 +366,11 @@ 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;
Quoted 11 lines
drivers/nvme/target/io-cmd-bdev.c static u16 nvmet_bdev_discard_range(struct nvmet_req *req, · line 374
Quoted 10 lines
drivers/nvme/target/io-cmd-bdev.c +1
-5- ret =__blkdev_issue_discard (ns->bdev, +__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 ;
nvmet_bdev_discard_rangecan return void now.
done.
Quoted 17 lines
Quoted 6 lines
fs/f2fs/segment.c +0
-0fs/f2fs/segment.c static int __submit_discard_cmd(struct f2fs_sb_info *sbi, · line 1352
Quoted 8 lines
fs/f2fs/segment.c +1
-1@@ -1346,7 +1346,7 @@ static int __submit_discard_cmd(struct f2fs_sb_info *sbi,if (time_to_inject (sbi,FAULT_DISCARD )) { err = -EIO ; }else { - err =__blkdev_issue_discard (bdev, +__blkdev_issue_discard (bdev,SECTOR_FROM_BLOCK (start),SECTOR_FROM_BLOCK (len),GFP_NOFS , &bio);Please fold the following 'if (err)' block directly into the injection one, and either initialize err to 0, or use a direct return from that block to skip the last branch in the function checking err.
done :-
fs/f2fs/segment.c +5 -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,10 @@ 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
Quoted 7 lines
fs/f2fs/segment.c
Quoted 5 lines
blk_finish_plug(&plug);fs/f2fs/segment.c +1
-1-return error; +return 0 ;Please drop the error return for
xfs_discard_extentsentirely.
done :-
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);
@@ -739,9 +724,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 · 8 lines
2.40.0 will run the basic xfstest and send out a series to just remove the dead-code. Thanks for the review comments. -ck
kernel test robot
build botkernel test robot noticed the following build warnings:
Hi Chaitanya,
[This is a private test report for your RFC patch.] kernel test robot noticed the following build warnings:
[auto build test WARNING on axboe/for-next]
[also build test WARNING on device-mapper-dm/for-next jaegeuk-f2fs/dev-test jaegeuk-f2fs/dev xfs-linux/for-next linus/master v6.18-rc6 next-20251118] [cannot apply to linux-nvme/for-next]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Chaitanya-Kulkarni/block-change-__blkdev_issue_discard-return-type-to-void/20251118-154435 base: https://git.kernel.org/pub/scm/linux/kernel/git/axboe/linux.git for-next patch link: https://lore.kernel.org/r/20251118074243.636812-1-ckulkarnilinux%40gmail.com patch subject: [RFC PATCH] block: change __blkdev_issue_discard() return type to void config: x86_64-allnoconfig (https://download.01.org/0day-ci/archive/20251118/[email protected]/config) compiler: clang version 20.1.8 (https://github.com/llvm/llvm-project 87f0227cb60147a26a1eeb4fb06e3b505e9c7261) reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20251118/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All warnings (new ones prefixed by >>):
>> block/blk-lib.c:93:6: warning: variable 'ret' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized]
93 | if (bio) {
| ^~~
block/blk-lib.c:101:9: note: uninitialized use occurs here
101 | return ret;
| ^~~
block/blk-lib.c:93:2: note: remove the 'if' if its condition is always true
93 | if (bio) {
| ^~~~~~~~
block/blk-lib.c:89:9: note: initialize the variable 'ret' to silence this warning
89 | int ret;
| ^
| = 01 warning generated.
vim +93 block/blk-lib.c
73
74 /**
75 * blkdev_issue_discard - queue a discard
76 * @bdev: blockdev to issue discard for
77 * @sector: start sector
78 * @nr_sects: number of sectors to discard
79 * @gfp_mask: memory allocation flags (for bio_alloc)
80 *
81 * Description:
82 * Issue a discard request for the sectors in question.
83 */
84 int blkdev_issue_discard(struct block_device *bdev, sector_t sector,
85 sector_t nr_sects, gfp_t gfp_mask)
86 {
87 struct bio *bio = NULL;
88 struct blk_plug plug;
89 int ret;
90
91 blk_start_plug(&plug);
92 __blkdev_issue_discard(bdev, sector, nr_sects, gfp_mask, &bio);
> 93 if (bio) {
94 ret = submit_bio_wait(bio);
95 if (ret == -EOPNOTSUPP)
96 ret = 0;
97 bio_put(bio);
98 }
99 blk_finish_plug(&plug); 100
101 return ret;
102 }
103 EXPORT_SYMBOL(blkdev_issue_discard);
104
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki