Currently bio-based drivers lack blktrace's completion notification
because the notification will be sent only in request completion path
(blk_update_request) and they never use requests.
This patch adds bio completion tracepoint in bio_endio() so that bio-
based drivers can be tracked. Also introduce __bio_endio() which keeps
original behavior (w/o trace) to be called from the request completion
path and error path of generic_make_request(). It should not affect
normal request-based drivers.
Signed-off-by: Namhyung Kim <[email protected]>
---
block/blk-core.c | 6 ++++--
fs/bio.c | 18 ++++++++++++++++++
2 files changed, 22 insertions(+), 2 deletions(-)
diff --git a/block/blk-core.c b/block/blk-core.c
index d2f8f4049abd..69d66ea6f083 100644
--- a/block/blk-core.c
+++ b/block/blk-core.c
@@ -147,6 +147,8 @@ void blk_rq_init(struct request_queue *q, struct request *rq)
}
EXPORT_SYMBOL(blk_rq_init);
+extern void __bio_endio(struct bio *bio, int error);
+
static void req_bio_endio(struct request *rq, struct bio *bio,
unsigned int nbytes, int error)
{
@@ -172,7 +174,7 @@ static void req_bio_endio(struct request *rq, struct bio *bio,
/* don't actually finish bio if it's part of flush sequence */
if (bio->bi_size == 0 && !(rq->cmd_flags & REQ_FLUSH_SEQ))
- bio_endio(bio, error);
+ __bio_endio(bio, error);
}
void blk_dump_rq_flags(struct request *rq, char *msg)
@@ -1545,7 +1547,7 @@ static inline void __generic_make_request(struct bio *bio)
return;
end_io:
- bio_endio(bio, err);
+ __bio_endio(bio, err);
}
/*
diff --git a/fs/bio.c b/fs/bio.c
index 9bfade8a609b..6a0346f8bd69 100644
--- a/fs/bio.c
+++ b/fs/bio.c
@@ -1426,6 +1426,20 @@ void bio_flush_dcache_pages(struct bio *bi)
EXPORT_SYMBOL(bio_flush_dcache_pages);
#endif
+/*
+ * Same as bio_endio() below but no trace.
+ */
+void __bio_endio(struct bio *bio, int error)
+{
+ if (error)
+ clear_bit(BIO_UPTODATE, &bio->bi_flags);
+ else if (!test_bit(BIO_UPTODATE, &bio->bi_flags))
+ error = -EIO;
+
+ if (bio->bi_end_io)
+ bio->bi_end_io(bio, error);
+}
+
/**
* bio_endio - end I/O on a bio
* @bio: bio
@@ -1442,11 +1456,15 @@ EXPORT_SYMBOL(bio_flush_dcache_pages);
**/
void bio_endio(struct bio *bio, int error)
{
+ struct request_queue *q = bdev_get_queue(bio->bi_bdev);
+
if (error)
clear_bit(BIO_UPTODATE, &bio->bi_flags);
else if (!test_bit(BIO_UPTODATE, &bio->bi_flags))
error = -EIO;
+ trace_block_bio_complete(q, bio, error);
+
if (bio->bi_end_io)
bio->bi_end_io(bio, error);
}
--
1.7.6