Skip to content

Commit 92c3737

Browse files
Christoph Hellwigaxboe
authored andcommitted
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>
1 parent 6fa7475 commit 92c3737

4 files changed

Lines changed: 19 additions & 33 deletions

File tree

block/bio.c

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1520,6 +1520,20 @@ static void bio_endio_cb(struct bio *bio, void *priv)
15201520
bio_endio(bio);
15211521
}
15221522

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+
15231537
/**
15241538
* bdev_rw_virt - synchronously read into / write from kernel mapping
15251539
* @bdev: block device to access
@@ -1550,15 +1564,6 @@ int bdev_rw_virt(struct block_device *bdev, sector_t sector, void *data,
15501564
}
15511565
EXPORT_SYMBOL_GPL(bdev_rw_virt);
15521566

1553-
/*
1554-
* bio_await_chain - ends @bio and waits for every chained bio to complete
1555-
*/
1556-
void bio_await_chain(struct bio *bio)
1557-
{
1558-
bio_await(bio, NULL, bio_endio_cb);
1559-
bio_put(bio);
1560-
}
1561-
15621567
void __bio_advance(struct bio *bio, unsigned bytes)
15631568
{
15641569
if (bio_integrity(bio))

block/blk-lib.c

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -155,13 +155,7 @@ static int blkdev_issue_write_zeroes(struct block_device *bdev, sector_t sector,
155155
__blkdev_issue_write_zeroes(bdev, sector, nr_sects, gfp, &bio,
156156
flags, limit);
157157
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);
165159
bio_put(bio);
166160
}
167161
blk_finish_plug(&plug);
@@ -236,13 +230,7 @@ static int blkdev_issue_zero_pages(struct block_device *bdev, sector_t sector,
236230
blk_start_plug(&plug);
237231
__blkdev_issue_zero_pages(bdev, sector, nr_sects, gfp, &bio, flags);
238232
if (bio) {
239-
if ((flags & BLKDEV_ZERO_KILLABLE) &&
240-
fatal_signal_pending(current)) {
241-
bio_await_chain(bio);
242-
blk_finish_plug(&plug);
243-
return -EINTR;
244-
}
245-
ret = submit_bio_wait(bio);
233+
ret = bio_submit_or_kill(bio, flags);
246234
bio_put(bio);
247235
}
248236
blk_finish_plug(&plug);

block/blk.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ bool __blk_freeze_queue_start(struct request_queue *q,
5555
struct task_struct *owner);
5656
int __bio_queue_enter(struct request_queue *q, struct bio *bio);
5757
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);
5959

6060
static inline bool blk_try_enter_queue(struct request_queue *q, bool pm)
6161
{

block/ioctl.c

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -153,26 +153,19 @@ static int blk_ioctl_discard(struct block_device *bdev, blk_mode_t mode,
153153
nr_sects = len >> SECTOR_SHIFT;
154154

155155
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)) {
163157
bio = blk_alloc_discard_bio(bdev, &sector, &nr_sects,
164158
GFP_KERNEL);
165159
if (!bio)
166160
break;
167161
prev = bio_chain_and_submit(prev, bio);
168162
}
169163
if (prev) {
170-
err = submit_bio_wait(prev);
164+
err = bio_submit_or_kill(prev, BLKDEV_ZERO_KILLABLE);
171165
if (err == -EOPNOTSUPP)
172166
err = 0;
173167
bio_put(prev);
174168
}
175-
out_unplug:
176169
blk_finish_plug(&plug);
177170
fail:
178171
filemap_invalidate_unlock(bdev->bd_mapping);

0 commit comments

Comments
 (0)