Skip to content

Commit 0267811

Browse files
wenchao-haomartinkpetersen
authored andcommitted
scsi: scsi_debug: Add new error injection type: Reset LUN failed
Add error injection type 4 to make scsi_debug_device_reset() return FAILED. Fail abort command format: +--------+------+-------------------------------------------------------+ | Column | Type | Description | +--------+------+-------------------------------------------------------+ | 1 | u8 | Error type, fixed to 0x4 | +--------+------+-------------------------------------------------------+ | 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 "4 -10 0x12" > ${error} will make the device return FAILED when trying to reset LUN with inquiry command 10 times. error=/sys/kernel/debug/scsi_debug/0:0:0:1/error echo "4 -10 0xff" > ${error} will make the device return FAILED when trying to reset LUN 10 times. Usually we do not care about what command it is when trying to perform reset LUN, so 0xff could be applied. 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 5551ce9 commit 0267811

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

Diff for: drivers/scsi/scsi_debug.c

+39
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,8 @@ enum sdebug_err_type {
295295
/* with errors set in scsi_cmnd */
296296
ERR_ABORT_CMD_FAILED = 3, /* control return FAILED from */
297297
/* scsi_debug_abort() */
298+
ERR_LUN_RESET_FAILED = 4, /* control return FAILED from */
299+
/* scsi_debug_device_reseLUN_RESET_FAILEDt() */
298300
};
299301

300302
struct sdebug_err_inject {
@@ -973,6 +975,7 @@ static int sdebug_error_show(struct seq_file *m, void *p)
973975
switch (err->type) {
974976
case ERR_TMOUT_CMD:
975977
case ERR_ABORT_CMD_FAILED:
978+
case ERR_LUN_RESET_FAILED:
976979
seq_printf(m, "%d\t%d\t0x%x\n", err->type, err->cnt,
977980
err->cmd);
978981
break;
@@ -1035,6 +1038,7 @@ static ssize_t sdebug_error_write(struct file *file, const char __user *ubuf,
10351038
switch (inject_type) {
10361039
case ERR_TMOUT_CMD:
10371040
case ERR_ABORT_CMD_FAILED:
1041+
case ERR_LUN_RESET_FAILED:
10381042
if (sscanf(buf, "%d %d %hhx", &inject->type, &inject->cnt,
10391043
&inject->cmd) != 3)
10401044
goto out_error;
@@ -5586,10 +5590,40 @@ static void scsi_debug_stop_all_queued(struct scsi_device *sdp)
55865590
scsi_debug_stop_all_queued_iter, sdp);
55875591
}
55885592

5593+
static int sdebug_fail_lun_reset(struct scsi_cmnd *cmnd)
5594+
{
5595+
struct scsi_device *sdp = cmnd->device;
5596+
struct sdebug_dev_info *devip = (struct sdebug_dev_info *)sdp->hostdata;
5597+
struct sdebug_err_inject *err;
5598+
unsigned char *cmd = cmnd->cmnd;
5599+
int ret = 0;
5600+
5601+
if (devip == NULL)
5602+
return 0;
5603+
5604+
rcu_read_lock();
5605+
list_for_each_entry_rcu(err, &devip->inject_err_list, list) {
5606+
if (err->type == ERR_LUN_RESET_FAILED &&
5607+
(err->cmd == cmd[0] || err->cmd == 0xff)) {
5608+
ret = !!err->cnt;
5609+
if (err->cnt < 0)
5610+
err->cnt++;
5611+
5612+
rcu_read_unlock();
5613+
return ret;
5614+
}
5615+
}
5616+
rcu_read_unlock();
5617+
5618+
return 0;
5619+
}
5620+
55895621
static int scsi_debug_device_reset(struct scsi_cmnd *SCpnt)
55905622
{
55915623
struct scsi_device *sdp = SCpnt->device;
55925624
struct sdebug_dev_info *devip = sdp->hostdata;
5625+
u8 *cmd = SCpnt->cmnd;
5626+
u8 opcode = cmd[0];
55935627

55945628
++num_dev_resets;
55955629

@@ -5600,6 +5634,11 @@ static int scsi_debug_device_reset(struct scsi_cmnd *SCpnt)
56005634
if (devip)
56015635
set_bit(SDEBUG_UA_POR, devip->uas_bm);
56025636

5637+
if (sdebug_fail_lun_reset(SCpnt)) {
5638+
scmd_printk(KERN_INFO, SCpnt, "fail lun reset 0x%x\n", opcode);
5639+
return FAILED;
5640+
}
5641+
56035642
return SUCCESS;
56045643
}
56055644

0 commit comments

Comments
 (0)