block: Add should_fail_bio() for bpf error injection
"Linux Kernel Mailing List" <[email protected]> Sat, 10 Feb 2018 22:21:28 +0000 (UTC)
| Newsgroups | gmane.linux.kernel.commits.head |
|---|---|
| Message-ID | <[email protected]> |
Web: https://git.kernel.org/torvalds/c/30abb3a67f4b2aa160feeb3c0b771f730cbcca67 Commit: 30abb3a67f4b2aa160feeb3c0b771f730cbcca67 Parent: 5235553d821433e1f4fa720fd025d2c4b7ee9994 Refname: refs/heads/master Author: Howard McLauchlan <[email protected]> AuthorDate: Tue Feb 6 14:05:39 2018 -0800 Committer: Jens Axboe <[email protected]> CommitDate: Tue Feb 6 15:09:51 2018 -0700 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 <[email protected]> Signed-off-by: Jens Axboe <[email protected]> --- block/blk-core.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) 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 @@ #include <linux/pm_runtime.h> #include <linux/blk-cgroup.h> #include <linux/debugfs.h> +#include <linux/bpf.h> #define CREATE_TRACE_POINTS #include <trace/events/block.h> @@ -2083,6 +2084,14 @@ static inline bool bio_check_ro(struct bio *bio, struct hd_struct *part) return false; } +static noinline int should_fail_bio(struct bio *bio) +{ + if (should_fail_request(&bio->bi_disk->part0, bio->bi_iter.bi_size)) + return -EIO; + return 0; +} +ALLOW_ERROR_INJECTION(should_fail_bio, ERRNO); + /* * Remap block n of partition p to block n+start(p) of the disk. */ @@ -2174,7 +2183,7 @@ generic_make_request_checks(struct bio *bio) if ((bio->bi_opf & REQ_NOWAIT) && !queue_is_rq_based(q)) goto not_supported; - if (should_fail_request(&bio->bi_disk->part0, bio->bi_iter.bi_size)) + if (should_fail_bio(bio)) goto end_io; if (!bio->bi_partno) { -- To unsubscribe from this list: send the line "unsubscribe git-commits-head" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html