Skip to content

Commit 32be8b6

Browse files
wenchao-haomartinkpetersen
authored andcommitted
scsi: scsi_debug: Time out command if the error is injected
If a timeout error is injected, return 0 from scsi_debug_queuecommand to make the command time out. Time out SCSI command format: +--------+------+-------------------------------------------------------+ | Column | Type | Description | +--------+------+-------------------------------------------------------+ | 1 | u8 | Error type, fixed to 0x0 | +--------+------+-------------------------------------------------------+ | 2 | s32 | Error count | | | | 0: this 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 | +--------+------+-------------------------------------------------------+ Examples: error=/sys/kernel/debug/scsi_debug/0:0:0:1/error echo "0 -10 0x12" > ${error} will make the device's inquiry command time out 10 times. echo "0 1 0x12" > ${error} will make the device's inquiry time out each time it is invoked on this device. Acked-by: Douglas Gilbert <[email protected]> Signed-off-by: Wenchao Hao <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Martin K. Petersen <[email protected]>
1 parent 962d77c commit 32be8b6

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

drivers/scsi/scsi_debug.c

+34
Original file line numberDiff line numberDiff line change
@@ -7741,6 +7741,34 @@ static int sdebug_blk_mq_poll(struct Scsi_Host *shost, unsigned int queue_num)
77417741
return num_entries;
77427742
}
77437743

7744+
static int sdebug_timeout_cmd(struct scsi_cmnd *cmnd)
7745+
{
7746+
struct scsi_device *sdp = cmnd->device;
7747+
struct sdebug_dev_info *devip = (struct sdebug_dev_info *)sdp->hostdata;
7748+
struct sdebug_err_inject *err;
7749+
unsigned char *cmd = cmnd->cmnd;
7750+
int ret = 0;
7751+
7752+
if (devip == NULL)
7753+
return 0;
7754+
7755+
rcu_read_lock();
7756+
list_for_each_entry_rcu(err, &devip->inject_err_list, list) {
7757+
if (err->type == ERR_TMOUT_CMD &&
7758+
(err->cmd == cmd[0] || err->cmd == 0xff)) {
7759+
ret = !!err->cnt;
7760+
if (err->cnt < 0)
7761+
err->cnt++;
7762+
7763+
rcu_read_unlock();
7764+
return ret;
7765+
}
7766+
}
7767+
rcu_read_unlock();
7768+
7769+
return 0;
7770+
}
7771+
77447772
static int scsi_debug_queuecommand(struct Scsi_Host *shost,
77457773
struct scsi_cmnd *scp)
77467774
{
@@ -7799,6 +7827,12 @@ static int scsi_debug_queuecommand(struct Scsi_Host *shost,
77997827
if (NULL == devip)
78007828
goto err_out;
78017829
}
7830+
7831+
if (sdebug_timeout_cmd(scp)) {
7832+
scmd_printk(KERN_INFO, scp, "timeout command 0x%x\n", opcode);
7833+
return 0;
7834+
}
7835+
78027836
if (unlikely(inject_now && !atomic_read(&sdeb_inject_pending)))
78037837
atomic_set(&sdeb_inject_pending, 1);
78047838

0 commit comments

Comments
 (0)