Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

block: add a bio_submit_or_kill helper

Factor the common logic for the ioctl helpers to either submit a bio or
end if the process is being killed. As this is now the only user of
bio_await_chain, open code that.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Damien Le Moal <dlemoal@kernel.org>
Link: https://patch.msgid.link/20260407140538.633364-5-hch@lst.de
Signed-off-by: Jens Axboe <axboe@kernel.dk>

authored by

Christoph Hellwig and committed by
Jens Axboe
92c3737a 6fa74755

+19 -33
+14 -9
block/bio.c
··· 1520 1520 bio_endio(bio); 1521 1521 } 1522 1522 1523 + /* 1524 + * Submit @bio synchronously, or call bio_endio on it if the current process 1525 + * is being killed. 1526 + */ 1527 + int bio_submit_or_kill(struct bio *bio, unsigned int flags) 1528 + { 1529 + if ((flags & BLKDEV_ZERO_KILLABLE) && fatal_signal_pending(current)) { 1530 + bio_await(bio, NULL, bio_endio_cb); 1531 + return -EINTR; 1532 + } 1533 + 1534 + return submit_bio_wait(bio); 1535 + } 1536 + 1523 1537 /** 1524 1538 * bdev_rw_virt - synchronously read into / write from kernel mapping 1525 1539 * @bdev: block device to access ··· 1563 1549 return error; 1564 1550 } 1565 1551 EXPORT_SYMBOL_GPL(bdev_rw_virt); 1566 - 1567 - /* 1568 - * bio_await_chain - ends @bio and waits for every chained bio to complete 1569 - */ 1570 - void bio_await_chain(struct bio *bio) 1571 - { 1572 - bio_await(bio, NULL, bio_endio_cb); 1573 - bio_put(bio); 1574 - } 1575 1552 1576 1553 void __bio_advance(struct bio *bio, unsigned bytes) 1577 1554 {
+2 -14
block/blk-lib.c
··· 155 155 __blkdev_issue_write_zeroes(bdev, sector, nr_sects, gfp, &bio, 156 156 flags, limit); 157 157 if (bio) { 158 - if ((flags & BLKDEV_ZERO_KILLABLE) && 159 - fatal_signal_pending(current)) { 160 - bio_await_chain(bio); 161 - blk_finish_plug(&plug); 162 - return -EINTR; 163 - } 164 - ret = submit_bio_wait(bio); 158 + ret = bio_submit_or_kill(bio, flags); 165 159 bio_put(bio); 166 160 } 167 161 blk_finish_plug(&plug); ··· 230 236 blk_start_plug(&plug); 231 237 __blkdev_issue_zero_pages(bdev, sector, nr_sects, gfp, &bio, flags); 232 238 if (bio) { 233 - if ((flags & BLKDEV_ZERO_KILLABLE) && 234 - fatal_signal_pending(current)) { 235 - bio_await_chain(bio); 236 - blk_finish_plug(&plug); 237 - return -EINTR; 238 - } 239 - ret = submit_bio_wait(bio); 239 + ret = bio_submit_or_kill(bio, flags); 240 240 bio_put(bio); 241 241 } 242 242 blk_finish_plug(&plug);
+1 -1
block/blk.h
··· 55 55 struct task_struct *owner); 56 56 int __bio_queue_enter(struct request_queue *q, struct bio *bio); 57 57 void submit_bio_noacct_nocheck(struct bio *bio, bool split); 58 - void bio_await_chain(struct bio *bio); 58 + int bio_submit_or_kill(struct bio *bio, unsigned int flags); 59 59 60 60 static inline bool blk_try_enter_queue(struct request_queue *q, bool pm) 61 61 {
+2 -9
block/ioctl.c
··· 153 153 nr_sects = len >> SECTOR_SHIFT; 154 154 155 155 blk_start_plug(&plug); 156 - while (1) { 157 - if (fatal_signal_pending(current)) { 158 - if (prev) 159 - bio_await_chain(prev); 160 - err = -EINTR; 161 - goto out_unplug; 162 - } 156 + while (!fatal_signal_pending(current)) { 163 157 bio = blk_alloc_discard_bio(bdev, &sector, &nr_sects, 164 158 GFP_KERNEL); 165 159 if (!bio) ··· 161 167 prev = bio_chain_and_submit(prev, bio); 162 168 } 163 169 if (prev) { 164 - err = submit_bio_wait(prev); 170 + err = bio_submit_or_kill(prev, BLKDEV_ZERO_KILLABLE); 165 171 if (err == -EOPNOTSUPP) 166 172 err = 0; 167 173 bio_put(prev); 168 174 } 169 - out_unplug: 170 175 blk_finish_plug(&plug); 171 176 fail: 172 177 filemap_invalidate_unlock(bdev->bd_mapping);