@@ -1462,11 +1462,41 @@ void bio_iov_iter_unbounce(struct bio *bio, bool is_error, bool mark_dirty)
14621462 bio_iov_iter_unbounce_read (bio , is_error , mark_dirty );
14631463}
14641464
1465- static void submit_bio_wait_endio (struct bio * bio )
1465+ static void bio_wait_end_io (struct bio * bio )
14661466{
14671467 complete (bio -> bi_private );
14681468}
14691469
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+
14701500/**
14711501 * submit_bio_wait - submit a bio, and wait until it completes
14721502 * @bio: The &struct bio which describes the I/O
@@ -1480,19 +1510,30 @@ static void submit_bio_wait_endio(struct bio *bio)
14801510 */
14811511int submit_bio_wait (struct bio * bio )
14821512{
1483- DECLARE_COMPLETION_ONSTACK_MAP (done ,
1484- bio -> bi_bdev -> bd_disk -> lockdep_map );
1485-
1486- bio -> bi_private = & done ;
1487- bio -> bi_end_io = submit_bio_wait_endio ;
1488- bio -> bi_opf |= REQ_SYNC ;
1489- submit_bio (bio );
1490- blk_wait_io (& done );
1491-
1513+ bio_await (bio , NULL , NULL );
14921514 return blk_status_to_errno (bio -> bi_status );
14931515}
14941516EXPORT_SYMBOL (submit_bio_wait );
14951517
1518+ static void bio_endio_cb (struct bio * bio , void * priv )
1519+ {
1520+ bio_endio (bio );
1521+ }
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+
14961537/**
14971538 * bdev_rw_virt - synchronously read into / write from kernel mapping
14981539 * @bdev: block device to access
@@ -1523,26 +1564,6 @@ int bdev_rw_virt(struct block_device *bdev, sector_t sector, void *data,
15231564}
15241565EXPORT_SYMBOL_GPL (bdev_rw_virt );
15251566
1526- static void bio_wait_end_io (struct bio * bio )
1527- {
1528- complete (bio -> bi_private );
1529- bio_put (bio );
1530- }
1531-
1532- /*
1533- * bio_await_chain - ends @bio and waits for every chained bio to complete
1534- */
1535- void bio_await_chain (struct bio * bio )
1536- {
1537- DECLARE_COMPLETION_ONSTACK_MAP (done ,
1538- bio -> bi_bdev -> bd_disk -> lockdep_map );
1539-
1540- bio -> bi_private = & done ;
1541- bio -> bi_end_io = bio_wait_end_io ;
1542- bio_endio (bio );
1543- blk_wait_io (& done );
1544- }
1545-
15461567void __bio_advance (struct bio * bio , unsigned bytes )
15471568{
15481569 if (bio_integrity (bio ))
0 commit comments