block: add a bio_await_chain helper
[linux-block.git] / block / bio.c
index d82ef4fd545cb2860476f1dff0af15d2201a5d5f..dce12a0efdead26c8bf3eebc54cdce6d5e50421d 100644 (file)
@@ -1395,6 +1395,26 @@ int submit_bio_wait(struct bio *bio)
 }
 EXPORT_SYMBOL(submit_bio_wait);
 
+static void bio_wait_end_io(struct bio *bio)
+{
+       complete(bio->bi_private);
+       bio_put(bio);
+}
+
+/*
+ * bio_await_chain - ends @bio and waits for every chained bio to complete
+ */
+void bio_await_chain(struct bio *bio)
+{
+       DECLARE_COMPLETION_ONSTACK_MAP(done,
+                       bio->bi_bdev->bd_disk->lockdep_map);
+
+       bio->bi_private = &done;
+       bio->bi_end_io = bio_wait_end_io;
+       bio_endio(bio);
+       blk_wait_io(&done);
+}
+
 void __bio_advance(struct bio *bio, unsigned bytes)
 {
        if (bio_integrity(bio))