Skip to content

Commit 5551ce9

Browse files
wenchao-haomartinkpetersen
authored andcommitted
scsi: scsi_debug: Add new error injection type: Abort Failed
Add error injection type 3 to make scsi_debug_abort() return FAILED. Fail abort command format: +--------+------+-------------------------------------------------------+ | Column | Type | Description | +--------+------+-------------------------------------------------------+ | 1 | u8 | Error type, fixed to 0x3 | +--------+------+-------------------------------------------------------+ | 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 "3 -10 0x12" > ${error} will make the device return FAILED when aborting inquiry command 10 times. Signed-off-by: Wenchao Hao <[email protected]> Link: https://lore.kernel.org/r/[email protected] Tested-by: Douglas Gilbert <[email protected]> Signed-off-by: Martin K. Petersen <[email protected]>
1 parent 3359227 commit 5551ce9

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

drivers/scsi/scsi_debug.c

+40
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,8 @@ enum sdebug_err_type {
293293
ERR_FAIL_CMD = 2, /* make specific scsi command's */
294294
/* queuecmd return succeed but */
295295
/* with errors set in scsi_cmnd */
296+
ERR_ABORT_CMD_FAILED = 3, /* control return FAILED from */
297+
/* scsi_debug_abort() */
296298
};
297299

298300
struct sdebug_err_inject {
@@ -970,6 +972,7 @@ static int sdebug_error_show(struct seq_file *m, void *p)
970972
list_for_each_entry_rcu(err, &devip->inject_err_list, list) {
971973
switch (err->type) {
972974
case ERR_TMOUT_CMD:
975+
case ERR_ABORT_CMD_FAILED:
973976
seq_printf(m, "%d\t%d\t0x%x\n", err->type, err->cnt,
974977
err->cmd);
975978
break;
@@ -1031,6 +1034,7 @@ static ssize_t sdebug_error_write(struct file *file, const char __user *ubuf,
10311034

10321035
switch (inject_type) {
10331036
case ERR_TMOUT_CMD:
1037+
case ERR_ABORT_CMD_FAILED:
10341038
if (sscanf(buf, "%d %d %hhx", &inject->type, &inject->cnt,
10351039
&inject->cmd) != 3)
10361040
goto out_error;
@@ -5512,9 +5516,39 @@ static void stop_all_queued(void)
55125516
mutex_unlock(&sdebug_host_list_mutex);
55135517
}
55145518

5519+
static int sdebug_fail_abort(struct scsi_cmnd *cmnd)
5520+
{
5521+
struct scsi_device *sdp = cmnd->device;
5522+
struct sdebug_dev_info *devip = (struct sdebug_dev_info *)sdp->hostdata;
5523+
struct sdebug_err_inject *err;
5524+
unsigned char *cmd = cmnd->cmnd;
5525+
int ret = 0;
5526+
5527+
if (devip == NULL)
5528+
return 0;
5529+
5530+
rcu_read_lock();
5531+
list_for_each_entry_rcu(err, &devip->inject_err_list, list) {
5532+
if (err->type == ERR_ABORT_CMD_FAILED &&
5533+
(err->cmd == cmd[0] || err->cmd == 0xff)) {
5534+
ret = !!err->cnt;
5535+
if (err->cnt < 0)
5536+
err->cnt++;
5537+
5538+
rcu_read_unlock();
5539+
return ret;
5540+
}
5541+
}
5542+
rcu_read_unlock();
5543+
5544+
return 0;
5545+
}
5546+
55155547
static int scsi_debug_abort(struct scsi_cmnd *SCpnt)
55165548
{
55175549
bool ok = scsi_debug_abort_cmnd(SCpnt);
5550+
u8 *cmd = SCpnt->cmnd;
5551+
u8 opcode = cmd[0];
55185552

55195553
++num_aborts;
55205554

@@ -5523,6 +5557,12 @@ static int scsi_debug_abort(struct scsi_cmnd *SCpnt)
55235557
"%s: command%s found\n", __func__,
55245558
ok ? "" : " not");
55255559

5560+
if (sdebug_fail_abort(SCpnt)) {
5561+
scmd_printk(KERN_INFO, SCpnt, "fail abort command 0x%x\n",
5562+
opcode);
5563+
return FAILED;
5564+
}
5565+
55265566
return SUCCESS;
55275567
}
55285568

0 commit comments

Comments
 (0)