• Wenchao Hao's avatar
    scsi: scsi_debug: Set command result and sense data if error is injected · 33592274
    Wenchao Hao authored
    If a fail command error is injected, set the command's status and sense
    data then finish this SCSI command.
    
    Set SCSI command's status and sense data format:
    
      +--------+------+-------------------------------------------------------+
      | Column | Type | Description                                           |
      +--------+------+-------------------------------------------------------+
      |   1    |  u8  | Error type, fixed to 0x2                              |
      +--------+------+-------------------------------------------------------+
      |   2    |  s32 | Error Count                                           |
      |        |      |  0: the rule will be ignored                          |
      |        |      |  positive: the rule will always take effect           |
      |        |      |  negative: the rule takes effect n times where -n is  |
      |        |      |            the value given. Ignored after n times     |
      +--------+------+-------------------------------------------------------+
      |   3    |  x8  | SCSI command opcode, 0xff for all commands            |
      +--------+------+-------------------------------------------------------+
      |   4    |  x8  | Host byte in scsi_cmd::status                         |
      |        |      | [scsi_cmd::status has 32 bits holding these 3 bytes]  |
      +--------+------+-------------------------------------------------------+
      |   5    |  x8  | Driver byte in scsi_cmd::status                       |
      +--------+------+-------------------------------------------------------+
      |   6    |  x8  | SCSI Status byte in scsi_cmd::status                  |
      +--------+------+-------------------------------------------------------+
      |   7    |  x8  | SCSI Sense Key in scsi_cmnd                           |
      +--------+------+-------------------------------------------------------+
      |   8    |  x8  | SCSI ASC in scsi_cmnd                                 |
      +--------+------+-------------------------------------------------------+
      |   9    |  x8  | SCSI ASCQ in scsi_cmnd                                |
      +--------+------+-------------------------------------------------------+
    
    Examples:
        error=/sys/kernel/debug/scsi_debug/0:0:0:1/error
        echo "2 -10 0x88 0 0 0x2 0x3 0x11 0x0" >${error}
    
    will make device's read command return with media error with additional
    sense of "Unrecovered read error" (UNC):
    Acked-by: default avatarDouglas Gilbert <dgilbert@interlog.com>
    Signed-off-by: default avatarWenchao Hao <haowenchao2@huawei.com>
    Link: https://lore.kernel.org/r/20231010092051.608007-7-haowenchao2@huawei.comSigned-off-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
    33592274
scsi_debug.c 234 KB