Skip to content

Commit 4b1a29a

Browse files
mhiramatAlexei Starovoitov
authored andcommitted
error-injection: Support fault injection framework
Support in-kernel fault-injection framework via debugfs. This allows you to inject a conditional error to specified function using debugfs interfaces. Here is the result of test script described in Documentation/fault-injection/fault-injection.txt =========== # ./test_fail_function.sh 1+0 records in 1+0 records out 1048576 bytes (1.0 MB, 1.0 MiB) copied, 0.0227404 s, 46.1 MB/s btrfs-progs v4.4 See http://btrfs.wiki.kernel.org for more information. Label: (null) UUID: bfa96010-12e9-4360-aed0-42eec7af5798 Node size: 16384 Sector size: 4096 Filesystem size: 1001.00MiB Block group profiles: Data: single 8.00MiB Metadata: DUP 58.00MiB System: DUP 12.00MiB SSD detected: no Incompat features: extref, skinny-metadata Number of devices: 1 Devices: ID SIZE PATH 1 1001.00MiB /dev/loop2 mount: mount /dev/loop2 on /opt/tmpmnt failed: Cannot allocate memory SUCCESS! =========== Signed-off-by: Masami Hiramatsu <[email protected]> Reviewed-by: Josef Bacik <[email protected]> Signed-off-by: Alexei Starovoitov <[email protected]>
1 parent 663faf9 commit 4b1a29a

File tree

4 files changed

+428
-0
lines changed

4 files changed

+428
-0
lines changed

Documentation/fault-injection/fault-injection.txt

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ o fail_mmc_request
3030
injects MMC data errors on devices permitted by setting
3131
debugfs entries under /sys/kernel/debug/mmc0/fail_mmc_request
3232

33+
o fail_function
34+
35+
injects error return on specific functions, which are marked by
36+
ALLOW_ERROR_INJECTION() macro, by setting debugfs entries
37+
under /sys/kernel/debug/fail_function. No boot option supported.
38+
3339
Configure fault-injection capabilities behavior
3440
-----------------------------------------------
3541

@@ -123,6 +129,29 @@ configuration of fault-injection capabilities.
123129
default is 'N', setting it to 'Y' will disable failure injections
124130
when dealing with private (address space) futexes.
125131

132+
- /sys/kernel/debug/fail_function/inject:
133+
134+
Format: { 'function-name' | '!function-name' | '' }
135+
specifies the target function of error injection by name.
136+
If the function name leads '!' prefix, given function is
137+
removed from injection list. If nothing specified ('')
138+
injection list is cleared.
139+
140+
- /sys/kernel/debug/fail_function/injectable:
141+
142+
(read only) shows error injectable functions and what type of
143+
error values can be specified. The error type will be one of
144+
below;
145+
- NULL: retval must be 0.
146+
- ERRNO: retval must be -1 to -MAX_ERRNO (-4096).
147+
- ERR_NULL: retval must be 0 or -1 to -MAX_ERRNO (-4096).
148+
149+
- /sys/kernel/debug/fail_function/<functiuon-name>/retval:
150+
151+
specifies the "error" return value to inject to the given
152+
function for given function. This will be created when
153+
user specifies new injection entry.
154+
126155
o Boot option
127156

128157
In order to inject faults while debugfs is not available (early boot time),
@@ -268,6 +297,45 @@ trap "echo 0 > /sys/kernel/debug/$FAILTYPE/probability" SIGINT SIGTERM EXIT
268297
echo "Injecting errors into the module $module... (interrupt to stop)"
269298
sleep 1000000
270299

300+
------------------------------------------------------------------------------
301+
302+
o Inject open_ctree error while btrfs mount
303+
304+
#!/bin/bash
305+
306+
rm -f testfile.img
307+
dd if=/dev/zero of=testfile.img bs=1M seek=1000 count=1
308+
DEVICE=$(losetup --show -f testfile.img)
309+
mkfs.btrfs -f $DEVICE
310+
mkdir -p tmpmnt
311+
312+
FAILTYPE=fail_function
313+
FAILFUNC=open_ctree
314+
echo $FAILFUNC > /sys/kernel/debug/$FAILTYPE/inject
315+
echo -12 > /sys/kernel/debug/$FAILTYPE/$FAILFUNC/retval
316+
echo N > /sys/kernel/debug/$FAILTYPE/task-filter
317+
echo 100 > /sys/kernel/debug/$FAILTYPE/probability
318+
echo 0 > /sys/kernel/debug/$FAILTYPE/interval
319+
echo -1 > /sys/kernel/debug/$FAILTYPE/times
320+
echo 0 > /sys/kernel/debug/$FAILTYPE/space
321+
echo 1 > /sys/kernel/debug/$FAILTYPE/verbose
322+
323+
mount -t btrfs $DEVICE tmpmnt
324+
if [ $? -ne 0 ]
325+
then
326+
echo "SUCCESS!"
327+
else
328+
echo "FAILED!"
329+
umount tmpmnt
330+
fi
331+
332+
echo > /sys/kernel/debug/$FAILTYPE/inject
333+
334+
rmdir tmpmnt
335+
losetup -d $DEVICE
336+
rm testfile.img
337+
338+
271339
Tool to run command with failslab or fail_page_alloc
272340
----------------------------------------------------
273341
In order to make it easier to accomplish the tasks mentioned above, we can use

kernel/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ obj-$(CONFIG_AUDIT_TREE) += audit_tree.o
8181
obj-$(CONFIG_GCOV_KERNEL) += gcov/
8282
obj-$(CONFIG_KCOV) += kcov.o
8383
obj-$(CONFIG_KPROBES) += kprobes.o
84+
obj-$(CONFIG_FAIL_FUNCTION) += fail_function.o
8485
obj-$(CONFIG_KGDB) += debug/
8586
obj-$(CONFIG_DETECT_HUNG_TASK) += hung_task.o
8687
obj-$(CONFIG_LOCKUP_DETECTOR) += watchdog.o

0 commit comments

Comments
 (0)