block: add add_disk() failure injection support
For a long time we have lived without any error handling
on the add_disk() error path. Now that we have some initial
error handling, add error injection support for its path so
that we can test it and ensure we don't regress this path
moving forward.
This only adds runtime code *iff* the new bool CONFIG_FAIL_ADD_DISK is
enabled in your kernel. If you don't have this enabled this provides
no new functional. When CONFIG_FAIL_ADD_DISK is disabled the new routine
blk_should_fail_add_disk() ends up being transformed to if (false), and
so the compiler should optimize these out as dead code producing no
new effective binary changes.
Failure injection lets us configure at boot how often we want a failure
to take place by specifying the interval, the probability, and when needed
a size constraint. We don't need to test for size constraints for
add_disk() and so ignore that part of error injection. Although testing
early boot failures with add_disk() failures might be useful we don't
to make add_disk() fail every time as otherwise we wouldn't be able to
boot. So enabling add_disk() error injection requires a second post
boot step where you specify where in the add_disk() code path you want
to enable failure injection for. This lets us verify correctness of
the different error handling parts of add_disk(), while also allowing
a respective blktests test to grow dynamically in case the add_disk()
paths grows.
We currently enable 11 code paths on add_disk() which can fail
and we can test for:
# ls -1 /sys/kernel/debug/block/config_fail_add_disk/
alloc_ext_minor
alloc_events
bdi_register
device_add
get_queue
integrity_add
register_disk
register_queue
sysfs_bdi_link
sysfs_depr_link
To enable you can boot by addig to your kernel comand line something
such as:
fail_blk_add_disk=1,100,0,-1
The values are <interval,probability,size,times>, we don't care for
size, so for now we ignore it. The above ensures interval is 1, so
it will fail each time one. But since we set time to -1 it means it
"no limit" and so will always fail.
If you want to modify the configuration of fail_add_disk dynamically
at boot, you can enable CONFIG_FAULT_INJECTION_DEBUG_FS. If you've
enabled CONFIG_FAIL_ADD_DISK you will see these knobs:
# ls -1 /sys/kernel/debug/block/fail_add_disk/
interval
probability
space
task-filter
times
verbose
verbose_ratelimit_burst
verbose_ratelimit_interval_ms
Suggested-by: Bart Van Assche <bvanassche@acm.org>
Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>
7 files changed