2022-11-09 02:59:51

by Wenchao Hao

[permalink] [raw]
Subject: [RFC PATCH 0/5] scsi:scsi_debug:Add error injection for single lun

The original error injection mechanism was based on scsi_host which
could not inject fault for a single SCSI device.

This patchset provides the ability to inject errors for a single
SCSI device. Now we supports inject timeout errors, queuecommand
errors, and hostbyte, driverbyte, statusbyte, and sense data for
specific SCSI Command

The first patch add an sysfs interface to add and inquiry single
device's error injection info; the second patch defined how to remove
an injection which has been added. The following 3 patches use the
injection info and generate the related error type.

Wenchao Hao (5):
scsi:scsi_debug: Add sysfs interface to manager single devices' error inject
scsi:scsi_debug: Add interface to remove injection which has been added
scsi:scsi_debug: make command timeout if timeout error is injected
scsi:scsi_debug: Return failed value for specific command's queuecommand
scsi:scsi_debug: fail specific scsi command with result and sense data

drivers/scsi/scsi_debug.c | 295 ++++++++++++++++++++++++++++++++++++++
1 file changed, 295 insertions(+)

--
2.35.3



2022-11-09 03:39:01

by Wenchao Hao

[permalink] [raw]
Subject: [RFC PATCH 2/5] scsi:scsi_debug: Add interface to remove injection which has been added

The removal interface is still "/sys/block/sdX/device/error_inect/error".
The format is still line-by-line integer separated by spaces with fixed 3
column.
first column is "-", which tells this is a removal operation;
second column is error code;
third column is the scsi command.

For example the following command would remove timeout injection of
inquiry command.

echo "- 0 0x12" > /sys/block/sdb/device/error_inect/error

Signed-off-by: Wenchao Hao <[email protected]>
---
drivers/scsi/scsi_debug.c | 27 +++++++++++++++++++++++++++
1 file changed, 27 insertions(+)

diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c
index 0cdc9599b628..06e3150812fa 100644
--- a/drivers/scsi/scsi_debug.c
+++ b/drivers/scsi/scsi_debug.c
@@ -7653,6 +7653,30 @@ static void sdebug_err_add(struct device *dev, struct sdebug_err_inject *new)
list_add_tail(&new->list, &devip->inject_err_list);
}

+static int sdebug_err_remove(struct device *dev, const char *buf, size_t count)
+{
+ struct scsi_device *sdev = to_scsi_device(dev);
+ struct sdebug_dev_info *devip = (struct sdebug_dev_info *)sdev->hostdata;
+ struct sdebug_err_inject *tmp, *err;
+ int type;
+ unsigned char cmd;
+
+ if (sscanf(buf, "- %d %hhx", &type, &cmd) != 2)
+ return -EINVAL;
+
+ list_for_each_entry_safe(err, tmp, &devip->inject_err_list, list) {
+ if (err->type == type && err->cmd == cmd) {
+ sdev_printk(KERN_INFO, sdev, "Remove %d 0x%x\n",
+ err->type, err->cmd);
+ list_del(&err->list);
+ kfree(err);
+ return count;
+ }
+ }
+
+ return -EINVAL;
+}
+
static ssize_t error_show(struct device *dev, struct device_attribute *attr,
char *buf)
{
@@ -7698,6 +7722,9 @@ static ssize_t error_store(struct device *dev, struct device_attribute *attr,
unsigned int inject_type;
struct sdebug_err_inject *inject;

+ if (buf[0] == '-')
+ return sdebug_err_remove(dev, buf, count);
+
if (sscanf(buf, "%d", &inject_type) != 1)
return -EINVAL;

--
2.35.3


2022-11-13 22:27:05

by Douglas Gilbert

[permalink] [raw]
Subject: Re: [RFC PATCH 0/5] scsi:scsi_debug:Add error injection for single lun

On 2022-11-09 10:59, Wenchao Hao wrote:
> The original error injection mechanism was based on scsi_host which
> could not inject fault for a single SCSI device.
>
> This patchset provides the ability to inject errors for a single
> SCSI device. Now we supports inject timeout errors, queuecommand
> errors, and hostbyte, driverbyte, statusbyte, and sense data for
> specific SCSI Command
>
> The first patch add an sysfs interface to add and inquiry single
> device's error injection info; the second patch defined how to remove
> an injection which has been added. The following 3 patches use the
> injection info and generate the related error type.
>
> Wenchao Hao (5):
> scsi:scsi_debug: Add sysfs interface to manager single devices' error inject
> scsi:scsi_debug: Add interface to remove injection which has been added
> scsi:scsi_debug: make command timeout if timeout error is injected
> scsi:scsi_debug: Return failed value for specific command's queuecommand
> scsi:scsi_debug: fail specific scsi command with result and sense data
>
> drivers/scsi/scsi_debug.c | 295 ++++++++++++++++++++++++++++++++++++++
> 1 file changed, 295 insertions(+)

Hi,
This patchset seems to assume all scsi_debug devices will be disk (-like) SCSI
devices. That leaves out other device types: tapes, enclosures, WLUNs, etc.

Have you considered putting these device specific additions under:
/sys/class/scsi_device/<hctl>/device/error_inject/
instead of
/sys/block/sdb/device/error_inject/

?

Doug Gilbert




2022-11-14 01:24:45

by Damien Le Moal

[permalink] [raw]
Subject: Re: [RFC PATCH 0/5] scsi:scsi_debug:Add error injection for single lun

On 11/14/22 06:48, Douglas Gilbert wrote:
> On 2022-11-09 10:59, Wenchao Hao wrote:
>> The original error injection mechanism was based on scsi_host which
>> could not inject fault for a single SCSI device.
>>
>> This patchset provides the ability to inject errors for a single
>> SCSI device. Now we supports inject timeout errors, queuecommand
>> errors, and hostbyte, driverbyte, statusbyte, and sense data for
>> specific SCSI Command
>>
>> The first patch add an sysfs interface to add and inquiry single
>> device's error injection info; the second patch defined how to remove
>> an injection which has been added. The following 3 patches use the
>> injection info and generate the related error type.
>>
>> Wenchao Hao (5):
>> scsi:scsi_debug: Add sysfs interface to manager single devices' error inject
>> scsi:scsi_debug: Add interface to remove injection which has been added
>> scsi:scsi_debug: make command timeout if timeout error is injected
>> scsi:scsi_debug: Return failed value for specific command's queuecommand
>> scsi:scsi_debug: fail specific scsi command with result and sense data
>>
>> drivers/scsi/scsi_debug.c | 295 ++++++++++++++++++++++++++++++++++++++
>> 1 file changed, 295 insertions(+)
>
> Hi,
> This patchset seems to assume all scsi_debug devices will be disk (-like) SCSI
> devices. That leaves out other device types: tapes, enclosures, WLUNs, etc.
>
> Have you considered putting these device specific additions under:
> /sys/class/scsi_device/<hctl>/device/error_inject/
> instead of
> /sys/block/sdb/device/error_inject/

But these are the same, no ?
At least on my Fedora box, I see:

/sys/block/sdp/device/ being
/sys/devices/pseudo_0/adapter0/host19/target19:0:0/19:0:0:0

and /sys/class/scsi_device/19:0:0:0/device being
/sys/devices/pseudo_0/adapter0/host19/target19:0:0/19:0:0:0

>
> ?
>
> Doug Gilbert
>
>
>

--
Damien Le Moal
Western Digital Research


2022-11-14 03:05:39

by Douglas Gilbert

[permalink] [raw]
Subject: Re: [RFC PATCH 0/5] scsi:scsi_debug:Add error injection for single lun

On 2022-11-13 19:30, Damien Le Moal wrote:
> On 11/14/22 06:48, Douglas Gilbert wrote:
>> On 2022-11-09 10:59, Wenchao Hao wrote:
>>> The original error injection mechanism was based on scsi_host which
>>> could not inject fault for a single SCSI device.
>>>
>>> This patchset provides the ability to inject errors for a single
>>> SCSI device. Now we supports inject timeout errors, queuecommand
>>> errors, and hostbyte, driverbyte, statusbyte, and sense data for
>>> specific SCSI Command
>>>
>>> The first patch add an sysfs interface to add and inquiry single
>>> device's error injection info; the second patch defined how to remove
>>> an injection which has been added. The following 3 patches use the
>>> injection info and generate the related error type.
>>>
>>> Wenchao Hao (5):
>>> scsi:scsi_debug: Add sysfs interface to manager single devices' error inject
>>> scsi:scsi_debug: Add interface to remove injection which has been added
>>> scsi:scsi_debug: make command timeout if timeout error is injected
>>> scsi:scsi_debug: Return failed value for specific command's queuecommand
>>> scsi:scsi_debug: fail specific scsi command with result and sense data
>>>
>>> drivers/scsi/scsi_debug.c | 295 ++++++++++++++++++++++++++++++++++++++
>>> 1 file changed, 295 insertions(+)
>>
>> Hi,
>> This patchset seems to assume all scsi_debug devices will be disk (-like) SCSI
>> devices. That leaves out other device types: tapes, enclosures, WLUNs, etc.
>>
>> Have you considered putting these device specific additions under:
>> /sys/class/scsi_device/<hctl>/device/error_inject/
>> instead of
>> /sys/block/sdb/device/error_inject/
>
> But these are the same, no ?
> At least on my Fedora box, I see:
>
> /sys/block/sdp/device/ being
> /sys/devices/pseudo_0/adapter0/host19/target19:0:0/19:0:0:0
>
> and /sys/class/scsi_device/19:0:0:0/device being
> /sys/devices/pseudo_0/adapter0/host19/target19:0:0/19:0:0:0

Well the patch descriptions are all in terms of /sys/block/sd<letter>/
which will not exist if scsi_debug is called like this:
$ modprobe scsi_debug ptype=1

That creates a pseudo host with an attached (virtual) tape drive. If
the patchset works for other peripheral device types (i.e. that don't
use the sd driver) then the description should at least mention the
more general case (i.e. /sys/class/scsi_device/<hctl>/device ) IMO.

Doug Gilbert


2022-11-14 03:35:08

by Damien Le Moal

[permalink] [raw]
Subject: Re: [RFC PATCH 0/5] scsi:scsi_debug:Add error injection for single lun

On 11/14/22 11:54, Douglas Gilbert wrote:
> On 2022-11-13 19:30, Damien Le Moal wrote:
>> On 11/14/22 06:48, Douglas Gilbert wrote:
>>> On 2022-11-09 10:59, Wenchao Hao wrote:
>>>> The original error injection mechanism was based on scsi_host which
>>>> could not inject fault for a single SCSI device.
>>>>
>>>> This patchset provides the ability to inject errors for a single
>>>> SCSI device. Now we supports inject timeout errors, queuecommand
>>>> errors, and hostbyte, driverbyte, statusbyte, and sense data for
>>>> specific SCSI Command
>>>>
>>>> The first patch add an sysfs interface to add and inquiry single
>>>> device's error injection info; the second patch defined how to remove
>>>> an injection which has been added. The following 3 patches use the
>>>> injection info and generate the related error type.
>>>>
>>>> Wenchao Hao (5):
>>>> scsi:scsi_debug: Add sysfs interface to manager single devices' error inject
>>>> scsi:scsi_debug: Add interface to remove injection which has been added
>>>> scsi:scsi_debug: make command timeout if timeout error is injected
>>>> scsi:scsi_debug: Return failed value for specific command's queuecommand
>>>> scsi:scsi_debug: fail specific scsi command with result and sense data
>>>>
>>>> drivers/scsi/scsi_debug.c | 295 ++++++++++++++++++++++++++++++++++++++
>>>> 1 file changed, 295 insertions(+)
>>>
>>> Hi,
>>> This patchset seems to assume all scsi_debug devices will be disk (-like) SCSI
>>> devices. That leaves out other device types: tapes, enclosures, WLUNs, etc.
>>>
>>> Have you considered putting these device specific additions under:
>>> /sys/class/scsi_device/<hctl>/device/error_inject/
>>> instead of
>>> /sys/block/sdb/device/error_inject/
>>
>> But these are the same, no ?
>> At least on my Fedora box, I see:
>>
>> /sys/block/sdp/device/ being
>> /sys/devices/pseudo_0/adapter0/host19/target19:0:0/19:0:0:0
>>
>> and /sys/class/scsi_device/19:0:0:0/device being
>> /sys/devices/pseudo_0/adapter0/host19/target19:0:0/19:0:0:0
>
> Well the patch descriptions are all in terms of /sys/block/sd<letter>/
> which will not exist if scsi_debug is called like this:
> $ modprobe scsi_debug ptype=1
>
> That creates a pseudo host with an attached (virtual) tape drive. If
> the patchset works for other peripheral device types (i.e. that don't
> use the sd driver) then the description should at least mention the
> more general case (i.e. /sys/class/scsi_device/<hctl>/device ) IMO.

Got it.

>
> Doug Gilbert
>

--
Damien Le Moal
Western Digital Research


2022-11-21 15:45:55

by Wenchao Hao

[permalink] [raw]
Subject: Re: [RFC PATCH 0/5] scsi:scsi_debug:Add error injection for single lun

On 2022/11/14 5:48, Douglas Gilbert wrote:
> On 2022-11-09 10:59, Wenchao Hao wrote:
>> The original error injection mechanism was based on scsi_host which
>> could not inject fault for a single SCSI device.
>>
>> This patchset provides the ability to inject errors for a single
>> SCSI device. Now we supports inject timeout errors, queuecommand
>> errors, and hostbyte, driverbyte, statusbyte, and sense data for
>> specific SCSI Command
>>
>> The first patch add an sysfs interface to add and inquiry single
>> device's error injection info; the second patch defined how to remove
>> an injection which has been added. The following 3 patches use the
>> injection info and generate the related error type.
>>
>> Wenchao Hao (5):
>>    scsi:scsi_debug: Add sysfs interface to manager single devices' error inject
>>    scsi:scsi_debug: Add interface to remove injection which has been added
>>    scsi:scsi_debug: make command timeout if timeout error is injected
>>    scsi:scsi_debug: Return failed value for specific command's queuecommand
>>    scsi:scsi_debug: fail specific scsi command with result and sense data
>>
>>   drivers/scsi/scsi_debug.c | 295 ++++++++++++++++++++++++++++++++++++++
>>   1 file changed, 295 insertions(+)
>
> Hi,
> This patchset seems to assume all scsi_debug devices will be disk (-like) SCSI
> devices. That leaves out other device types: tapes, enclosures, WLUNs, etc.
>
> Have you considered putting these device specific additions under:
>    /sys/class/scsi_device/<hctl>/device/error_inject/
> instead of
>    /sys/block/sdb/device/error_inject/
>
> ?
>
> Doug Gilbert
>

Thanks for your reply. I did not notice other device types, but the error_inject interface is
added for scsi_device, so it is available for all types. I would update the path in patch description.

Do you have other suggestions?