From 6bd856cc99963b786cb530141745ef733de76cc3 Mon Sep 17 00:00:00 2001 From: Md Haris Iqbal Date: Wed, 11 Nov 2026 22:58:37 +0100 Subject: block: allow error injection rules to delay bios Error injection can only fail a bio today. Add a delay_us option so that a rule can hold a bio back first, to model a slow device. If a matching rule has delay_us set, the bio is held for that long. It is then failed if the rule also has a status, or resubmitted otherwise. The resubmission is done through submit_bio_noacct_nocheck(), which is where the injection hook sits. To avoid the same delay rule being applied to it again, mark the bio with the BIO_ERROR_INJECTED flag as soon as a rule matches. This also prevents bios that are split later and resubmitted from being evaluated for delay (or error injection) again. __bio_clone() does not propagate the flag, so a clone a stacking driver aims at a lower device is still evaluated. The bio is submitted from a workqueue rather than from the timer, because submitting a bio can sleep. A REQ_NOWAIT bio is failed with BLK_STS_AGAIN instead of being delayed. Values above 600 seconds are rejected. Cc: Christoph Hellwig Signed-off-by: Md Haris Iqbal Link: https://patch.msgid.link/20261111215838.103356-3-haris.iqbal@linux.dev Signed-off-by: Jens Axboe --- include/linux/blk_types.h | 1 + 1 file changed, 1 insertion(+) (limited to 'include/linux') diff --git a/include/linux/blk_types.h b/include/linux/blk_types.h index 0cc09b975d8f..1a5812fa4052 100644 --- a/include/linux/blk_types.h +++ b/include/linux/blk_types.h @@ -328,6 +328,7 @@ enum { BIO_ZONE_WRITE_PLUGGING, /* bio handled through zone write plugging */ BIO_EMULATES_ZONE_APPEND, /* bio emulates a zone append operation */ BIO_COMPLETE_IN_TASK, /* complete bi_end_io() in task context */ + BIO_ERROR_INJECTED, /* error injection rules already applied */ BIO_FLAG_LAST }; -- cgit v1.2.3