aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHoward McLauchlan <hmclauchlan@fb.com>2018-02-06 17:05:39 -0500
committerJens Axboe <axboe@kernel.dk>2018-02-06 17:09:51 -0500
commit30abb3a67f4b2aa160feeb3c0b771f730cbcca67 (patch)
tree14c7784a2e69497b38cbb35b3554a4482261fab9
parent5235553d821433e1f4fa720fd025d2c4b7ee9994 (diff)
block: Add should_fail_bio() for bpf error injection
The classic error injection mechanism, should_fail_request() does not support use cases where more information is required (from the entire struct bio, for example). To that end, this patch introduces should_fail_bio(), which calls should_fail_request() under the hood but provides a convenient place for kprobes to hook into if they require the entire struct bio. This patch also replaces some existing calls to should_fail_request() with should_fail_bio() with no degradation in performance. Signed-off-by: Howard McLauchlan <hmclauchlan@fb.com> Signed-off-by: Jens Axboe <axboe@kernel.dk>
-rw-r--r--block/blk-core.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/block/blk-core.c b/block/blk-core.c
index d0d104268f1a..2d1a7bbe0634 100644
--- a/block/blk-core.c
+++ b/block/blk-core.c
@@ -34,6 +34,7 @@
34#include <linux/pm_runtime.h> 34#include <linux/pm_runtime.h>
35#include <linux/blk-cgroup.h> 35#include <linux/blk-cgroup.h>
36#include <linux/debugfs.h> 36#include <linux/debugfs.h>
37#include <linux/bpf.h>
37 38
38#define CREATE_TRACE_POINTS 39#define CREATE_TRACE_POINTS
39#include <trace/events/block.h> 40#include <trace/events/block.h>
@@ -2083,6 +2084,14 @@ static inline bool bio_check_ro(struct bio *bio, struct hd_struct *part)
2083 return false; 2084 return false;
2084} 2085}
2085 2086
2087static noinline int should_fail_bio(struct bio *bio)
2088{
2089 if (should_fail_request(&bio->bi_disk->part0, bio->bi_iter.bi_size))
2090 return -EIO;
2091 return 0;
2092}
2093ALLOW_ERROR_INJECTION(should_fail_bio, ERRNO);
2094
2086/* 2095/*
2087 * Remap block n of partition p to block n+start(p) of the disk. 2096 * Remap block n of partition p to block n+start(p) of the disk.
2088 */ 2097 */
@@ -2174,7 +2183,7 @@ generic_make_request_checks(struct bio *bio)
2174 if ((bio->bi_opf & REQ_NOWAIT) && !queue_is_rq_based(q)) 2183 if ((bio->bi_opf & REQ_NOWAIT) && !queue_is_rq_based(q))
2175 goto not_supported; 2184 goto not_supported;
2176 2185
2177 if (should_fail_request(&bio->bi_disk->part0, bio->bi_iter.bi_size)) 2186 if (should_fail_bio(bio))
2178 goto end_io; 2187 goto end_io;
2179 2188
2180 if (!bio->bi_partno) { 2189 if (!bio->bi_partno) {