Skip to content

Commit 962d77c

Browse files
wenchao-haomartinkpetersen
authored andcommitted
scsi: scsi_debug: Define grammar to remove added error injection
The grammar to remove error injection is a line with fixed 3 columns separated by spaces. First column is fixed to "-". It tells this is a removal operation. Second column is the error code to match. Third column is the scsi command to match. For example the following command would remove timeout injection of inquiry command: echo "- 0 0x12" > /sys/kernel/debug/scsi_debug/0:0:0:1/error 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 a9996d7 commit 962d77c

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

drivers/scsi/scsi_debug.c

+31
Original file line numberDiff line numberDiff line change
@@ -930,6 +930,34 @@ static void sdebug_err_add(struct scsi_device *sdev, struct sdebug_err_inject *n
930930
spin_unlock(&devip->list_lock);
931931
}
932932

933+
static int sdebug_err_remove(struct scsi_device *sdev, const char *buf, size_t count)
934+
{
935+
struct sdebug_dev_info *devip = (struct sdebug_dev_info *)sdev->hostdata;
936+
struct sdebug_err_inject *err;
937+
int type;
938+
unsigned char cmd;
939+
940+
if (sscanf(buf, "- %d %hhx", &type, &cmd) != 2) {
941+
kfree(buf);
942+
return -EINVAL;
943+
}
944+
945+
spin_lock(&devip->list_lock);
946+
list_for_each_entry_rcu(err, &devip->inject_err_list, list) {
947+
if (err->type == type && err->cmd == cmd) {
948+
list_del_rcu(&err->list);
949+
call_rcu(&err->rcu, sdebug_err_free);
950+
spin_unlock(&devip->list_lock);
951+
kfree(buf);
952+
return count;
953+
}
954+
}
955+
spin_unlock(&devip->list_lock);
956+
957+
kfree(buf);
958+
return -EINVAL;
959+
}
960+
933961
static int sdebug_error_show(struct seq_file *m, void *p)
934962
{
935963
struct scsi_device *sdev = (struct scsi_device *)m->private;
@@ -987,6 +1015,9 @@ static ssize_t sdebug_error_write(struct file *file, const char __user *ubuf,
9871015
return -EFAULT;
9881016
}
9891017

1018+
if (buf[0] == '-')
1019+
return sdebug_err_remove(sdev, buf, count);
1020+
9901021
if (sscanf(buf, "%d", &inject_type) != 1) {
9911022
kfree(buf);
9921023
return -EINVAL;

0 commit comments

Comments
 (0)