From: Howard McLauchlan <hmclauchlan@fb.com>
To: <linux-block@vger.kernel.org>
Cc: Jens Axboe <axboe@fb.com>, <kernel-team@fb.com>,
Omar Sandoval <osandov@osandov.com>, Josef Bacik <jbacik@fb.com>,
Howard McLauchlan <hmclauchlan@fb.com>
Subject: [PATCH v2] block: Add should_fail_bio() for bpf error injection
Date: Tue, 6 Feb 2018 13:11:08 -0800 [thread overview]
Message-ID: <20180206211108.3236-1-hmclauchlan@fb.com> (raw)
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.
Reviewed-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: Howard McLauchlan <hmclauchlan@fb.com>
---
V2: rebased on master for 4.15
block/blk-core.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/block/blk-core.c b/block/blk-core.c
index d0d104268f1a..560a0260a8dc 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,12 @@ static inline bool bio_check_ro(struct bio *bio, struct hd_struct *part)
return false;
}
+static noinline bool should_fail_bio(struct bio *bio)
+{
+ return should_fail_request(&bio->bi_disk->part0, bio->bi_iter.bi_size);
+}
+BPF_ALLOW_ERROR_INJECTION(should_fail_bio);
+
/*
* Remap block n of partition p to block n+start(p) of the disk.
*/
@@ -2174,7 +2181,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) {
--
2.14.1
next reply other threads:[~2018-02-06 21:11 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-02-06 21:11 Howard McLauchlan [this message]
2018-02-06 21:15 ` [PATCH v2] block: Add should_fail_bio() for bpf error injection Jens Axboe
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180206211108.3236-1-hmclauchlan@fb.com \
--to=hmclauchlan@fb.com \
--cc=axboe@fb.com \
--cc=jbacik@fb.com \
--cc=kernel-team@fb.com \
--cc=linux-block@vger.kernel.org \
--cc=osandov@osandov.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox