Skip to content

Commit 0f8e9ec

Browse files
keithbuschaxboe
authored andcommitted
block: add a bio_await_chain helper
Add a helper to wait for an entire chain of bios to complete. [hch: split from a larger patch, moved and changed the name now that it is non-static] Signed-off-by: Keith Busch <kbusch@kernel.org> Signed-off-by: Christoph Hellwig <hch@lst.de> Link: https://lore.kernel.org/r/20240506042027.2289826-6-hch@lst.de Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent e8b4869 commit 0f8e9ec

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

block/bio.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1395,6 +1395,26 @@ int submit_bio_wait(struct bio *bio)
13951395
}
13961396
EXPORT_SYMBOL(submit_bio_wait);
13971397

1398+
static void bio_wait_end_io(struct bio *bio)
1399+
{
1400+
complete(bio->bi_private);
1401+
bio_put(bio);
1402+
}
1403+
1404+
/*
1405+
* bio_await_chain - ends @bio and waits for every chained bio to complete
1406+
*/
1407+
void bio_await_chain(struct bio *bio)
1408+
{
1409+
DECLARE_COMPLETION_ONSTACK_MAP(done,
1410+
bio->bi_bdev->bd_disk->lockdep_map);
1411+
1412+
bio->bi_private = &done;
1413+
bio->bi_end_io = bio_wait_end_io;
1414+
bio_endio(bio);
1415+
blk_wait_io(&done);
1416+
}
1417+
13981418
void __bio_advance(struct bio *bio, unsigned bytes)
13991419
{
14001420
if (bio_integrity(bio))

block/blk.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ void __blk_mq_unfreeze_queue(struct request_queue *q, bool force_atomic);
3838
void blk_queue_start_drain(struct request_queue *q);
3939
int __bio_queue_enter(struct request_queue *q, struct bio *bio);
4040
void submit_bio_noacct_nocheck(struct bio *bio);
41+
void bio_await_chain(struct bio *bio);
4142

4243
static inline bool blk_try_enter_queue(struct request_queue *q, bool pm)
4344
{

0 commit comments

Comments
 (0)