aboutsummaryrefslogtreecommitdiffstats
path: root/fs/bio.c
diff options
context:
space:
mode:
authorKent Overstreet <koverstreet@google.com>2012-09-10 17:41:12 -0400
committerKent Overstreet <koverstreet@google.com>2013-03-23 17:15:32 -0400
commit9e882242c6193ae6f416f2d8d8db0d9126bd996b (patch)
tree388e4a9ef2ab3693eaee77a8bffabc62a9b86d7f /fs/bio.c
parent2f477877f8c4be18f054aeb7c4be8cc748cfe932 (diff)
block: Add submit_bio_wait(), remove from md
Random cleanup - this code was duplicated and it's not really specific to md. Also added the ability to return the actual error code. Signed-off-by: Kent Overstreet <koverstreet@google.com> CC: Jens Axboe <axboe@kernel.dk> CC: NeilBrown <neilb@suse.de> Acked-by: Tejun Heo <tj@kernel.org>
Diffstat (limited to 'fs/bio.c')
-rw-r--r--fs/bio.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/fs/bio.c b/fs/bio.c
index f1b4c1651089..4ce24ee5dcd0 100644
--- a/fs/bio.c
+++ b/fs/bio.c
@@ -752,6 +752,42 @@ int bio_add_page(struct bio *bio, struct page *page, unsigned int len,
752} 752}
753EXPORT_SYMBOL(bio_add_page); 753EXPORT_SYMBOL(bio_add_page);
754 754
755struct submit_bio_ret {
756 struct completion event;
757 int error;
758};
759
760static void submit_bio_wait_endio(struct bio *bio, int error)
761{
762 struct submit_bio_ret *ret = bio->bi_private;
763
764 ret->error = error;
765 complete(&ret->event);
766}
767
768/**
769 * submit_bio_wait - submit a bio, and wait until it completes
770 * @rw: whether to %READ or %WRITE, or maybe to %READA (read ahead)
771 * @bio: The &struct bio which describes the I/O
772 *
773 * Simple wrapper around submit_bio(). Returns 0 on success, or the error from
774 * bio_endio() on failure.
775 */
776int submit_bio_wait(int rw, struct bio *bio)
777{
778 struct submit_bio_ret ret;
779
780 rw |= REQ_SYNC;
781 init_completion(&ret.event);
782 bio->bi_private = &ret;
783 bio->bi_end_io = submit_bio_wait_endio;
784 submit_bio(rw, bio);
785 wait_for_completion(&ret.event);
786
787 return ret.error;
788}
789EXPORT_SYMBOL(submit_bio_wait);
790
755/** 791/**
756 * bio_advance - increment/complete a bio by some number of bytes 792 * bio_advance - increment/complete a bio by some number of bytes
757 * @bio: bio to advance 793 * @bio: bio to advance