1.. SPDX-License-Identifier: GPL-2.0 2 3============================ 4Configurable Error Injection 5============================ 6 7Overview 8-------- 9 10Configurable error injection allows injecting specific block layer status codes 11for sector ranges of a block device. Errors can be injected unconditionally, or 12with a given probability. 13 14To use configurable error injection, CONFIG_BLK_ERROR_INJECTION must be enabled. 15 16The only interface is the error_injection debugfs file, which is created for 17each registered gendisk. Writes to this file are used to create or delete rules 18and reads return a list of the current error injection sites. 19 20Options 21------- 22 23The following options specify the operations: 24 25=================== ======================================================= 26add add a new rule 27removeall remove all existing rules 28=================== ======================================================= 29 30The following options specify the details of the rule for the add operation: 31 32=================== ======================================================= 33op=<string> block layer operation this rule applies to. This uses 34 the XYZ for each REQ_OP_XYZ operation, e.g. READ, WRITE 35 or DISCARD. Mandatory. 36status=<string> Status to return. This uses XYZ for each BLK_STS_XYZ 37 code, e.g. IOERR or MEDIUM. Mandatory. 38start=<number> First block layer sector the rule applies to. 39 Optional, defaults to 0. 40nr_sectors=<number> Number of sectors this rule applies. 41 Optional, defaults to the remainder of the device. 42chance=<number> Only return a failure with a likelihood of 1/chance. 43 Optional, defaults to 1 (always). 44=================== ======================================================= 45 46Example 47------- 48 49Return BLK_STS_IOERR for one in 10 reads of sector 0 of /dev/nvme0n1: 50 51 $ echo 'add,op=READ,start=0,status=IOERR,chance=10' > /sys/kernel/debug/block/nvme0n1/error_injection 52 53Return BLK_STS_MEDIUM for every write to /dev/nvme0n1: 54 55 $ echo 'add,op=WRITE,start=0,status=MEDIUM' > /sys/kernel/debug/block/nvme0n1/error_injection 56 57Remove all rules for /dev/nvme0n1: 58 59 $ echo 'removeall' > /sys/kernel/debug/block/nvme0n1/error_injection 60