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: factor out a bio_await helper

Add a new helper to wait for a bio and anything chained off it to
complete synchronously after submitting it. This factors common code out
of submit_bio_wait and bio_await_chain and will also be useful for
file system code and thus is exported.

Note that this will now set REQ_SYNC also for the bio_await case for
consistency. Nothing should look at the flag in the end_io handler,
but if something does having the flag set makes more sense.

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

authored by

Christoph Hellwig and committed by
Jens Axboe
6fa74755 65565ca5

+39 -16
+37 -16
block/bio.c
··· 1468 1468 } 1469 1469 1470 1470 /** 1471 + * bio_await - call a function on a bio, and wait until it completes 1472 + * @bio: the bio which describes the I/O 1473 + * @submit: function called to submit the bio 1474 + * @priv: private data passed to @submit 1475 + * 1476 + * Wait for the bio as well as any bio chained off it after executing the 1477 + * passed in callback @submit. The wait for the bio is set up before calling 1478 + * @submit to ensure that the completion is captured. If @submit is %NULL, 1479 + * submit_bio() is used instead to submit the bio. 1480 + * 1481 + * Note: this overrides the bi_private and bi_end_io fields in the bio. 1482 + */ 1483 + void bio_await(struct bio *bio, void *priv, 1484 + void (*submit)(struct bio *bio, void *priv)) 1485 + { 1486 + DECLARE_COMPLETION_ONSTACK_MAP(done, 1487 + bio->bi_bdev->bd_disk->lockdep_map); 1488 + 1489 + bio->bi_private = &done; 1490 + bio->bi_end_io = bio_wait_end_io; 1491 + bio->bi_opf |= REQ_SYNC; 1492 + if (submit) 1493 + submit(bio, priv); 1494 + else 1495 + submit_bio(bio); 1496 + blk_wait_io(&done); 1497 + } 1498 + EXPORT_SYMBOL_GPL(bio_await); 1499 + 1500 + /** 1471 1501 * submit_bio_wait - submit a bio, and wait until it completes 1472 1502 * @bio: The &struct bio which describes the I/O 1473 1503 * ··· 1510 1480 */ 1511 1481 int submit_bio_wait(struct bio *bio) 1512 1482 { 1513 - DECLARE_COMPLETION_ONSTACK_MAP(done, 1514 - bio->bi_bdev->bd_disk->lockdep_map); 1515 - 1516 - bio->bi_private = &done; 1517 - bio->bi_end_io = bio_wait_end_io; 1518 - bio->bi_opf |= REQ_SYNC; 1519 - submit_bio(bio); 1520 - blk_wait_io(&done); 1521 - 1483 + bio_await(bio, NULL, NULL); 1522 1484 return blk_status_to_errno(bio->bi_status); 1523 1485 } 1524 1486 EXPORT_SYMBOL(submit_bio_wait); 1487 + 1488 + static void bio_endio_cb(struct bio *bio, void *priv) 1489 + { 1490 + bio_endio(bio); 1491 + } 1525 1492 1526 1493 /** 1527 1494 * bdev_rw_virt - synchronously read into / write from kernel mapping ··· 1555 1528 */ 1556 1529 void bio_await_chain(struct bio *bio) 1557 1530 { 1558 - DECLARE_COMPLETION_ONSTACK_MAP(done, 1559 - bio->bi_bdev->bd_disk->lockdep_map); 1560 - 1561 - bio->bi_private = &done; 1562 - bio->bi_end_io = bio_wait_end_io; 1563 - bio_endio(bio); 1564 - blk_wait_io(&done); 1531 + bio_await(bio, NULL, bio_endio_cb); 1565 1532 bio_put(bio); 1566 1533 } 1567 1534
+2
include/linux/bio.h
··· 432 432 void bio_reset(struct bio *bio, struct block_device *bdev, blk_opf_t opf); 433 433 void bio_reuse(struct bio *bio, blk_opf_t opf); 434 434 void bio_chain(struct bio *, struct bio *); 435 + void bio_await(struct bio *bio, void *priv, 436 + void (*submit)(struct bio *bio, void *priv)); 435 437 436 438 int __must_check bio_add_page(struct bio *bio, struct page *page, unsigned len, 437 439 unsigned off);