scsi: core: Fix block I/O error of USB card reader during resume
PATCH 1/1 scsi: core: Fix block I/O error of USB card reader during resume
When accessing storage device via an USB card reader, a block I/O error occurs during resume:
PM: suspend exit
sd 0: 0:0:0: [sda] tag#0 UNKNOWN(0x2003) Result: hostbyte=0x00 driverbyte =0x08
sd 0: 0:0:0: [sda] tag#0 Sense Key : 0x6 [current]
sd 0: 0:0:0: [sda] tag#0 ASC=0x28 ASCQ=0x0
sd 0: 0:0:0: [sda] tag#0 CDB: opcode=0x28 28 00 00 17 ce e1 00 00 f0 00blk_update_request: I/O error, dev sda, sector 1560289 op 0x0:(READ) flags 0x84700 phys_seg 19 prio class 0
sd 0: 0:0:0: [sda] tag#0 device offline or changed
Fix it by changing the action in scsi_io_completion_action() from ACTION_FAIL to ACTION_RETRY by adding the condition cmd->device-> lockable.
--- drivers/scsi/scsi_lib.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/scsi/scsi_lib.c +2 -1
@@ -704,7 +704,8 @@ static void scsi_io_completion_action(struct scsi_cmnd *cmd, int result) }else if (sense_valid && sense_current) {switch (sshdr.sense_key) {case UNIT_ATTENTION : -if (cmd->device->removable) { +if (cmd->device->removable && + cmd->device->lockable) {/* Detected disc change. Set a bit * and quietly refuse further access. */
Signature · 1 line
2.29.0
Quoted 27 lines · Michael Wu
When accessing storage device via an USB card reader, a block I/O error occurs during resume:
PM: suspend exit
sd 0: 0:0:0: [sda] tag#0 UNKNOWN(0x2003) Result: hostbyte=0x00 driverbyte =0x08
sd 0: 0:0:0: [sda] tag#0 Sense Key :0x6[current]
sd 0: 0:0:0: [sda] tag#0 ASC=0x28 ASCQ=0x0
sd 0: 0:0:0: [sda] tag#0 CDB: opcode=0x28 28 00 00 17 ce e1 00 00 f0 00blk_update_request: I/O error, dev sda, sector 1560289 op 0x0:(READ) flags0x84700phys_seg19 prio class 0
sd 0: 0:0:0: [sda] tag#0 device offline or changedFix it by changing the action in
scsi_io_completion_action()fromACTION_FAILtoACTION_RETRYby adding the conditioncmd->device-> lockable.Signed-off-by Michael Wu <[email protected]>--- drivers/scsi/scsi_lib.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)drivers/scsi/scsi_lib.c +0
-0
drivers/scsi/scsi_lib.c static void scsi_io_completion_action(struct scsi_cmnd *cmd, int result) · line 711
Quoted 9 lines
drivers/scsi/scsi_lib.c +2
-1@@ -704,7 +704,8 @@ static void scsi_io_completion_action(struct scsi_cmnd *cmd, int result) }else if (sense_valid && sense_current) {switch (sshdr.sense_key) {case UNIT_ATTENTION : -if (cmd->device->removable) { +if (cmd->device->removable && + cmd->device->lockable) {/* Detected disc change. Set a bit * and quietly refuse further access. */
To me the above doesn't look like a good way to address this. I don't see why a device being lockable should control whether or not a unit attention results in a retry? Shouldn't the decision taken by scsi_io_completion_action() depend on the ASC and ASCQ codes rather than on whether a device is removable and/or lockable?
BTW, the code modified by the above patch is old. This is what I found in the 2002 version of scsi_lib.c:
if ((SCpnt->sense_buffer[0] & 0x7f) == 0x70
&& (SCpnt->sense_buffer[2] & 0xf) == UNIT_ATTENTION) {
if (SCpnt->device->removable) {
/* detected disc change. set a bit and quietly refuse
* further access.
*/
SCpnt->device->changed = 1;
SCpnt = scsi_end_request(SCpnt, 0, this_count);
return;
} else {
/*
* Must have been a power glitch, or a
* bus reset. Could not have been a
* media change, so we just retry the
* request and see what happens.
*/
scsi_queue_next_request(q, SCpnt);
return;
}Bart.
Thanks,
Bart.
Quoted 32 lines · Bart Van Assche
Quoted 31 lines · Michael Wu
When accessing storage device via an USB card reader, a block I/O error occurs during resume:
PM: suspend exit
sd 0: 0:0:0: [sda] tag#0 UNKNOWN(0x2003) Result: hostbyte=0x00 driverbyte =0x08
sd 0: 0:0:0: [sda] tag#0 Sense Key :0x6[current]
sd 0: 0:0:0: [sda] tag#0 ASC=0x28 ASCQ=0x0
sd 0: 0:0:0: [sda] tag#0 CDB: opcode=0x28 28 00 00 17 ce e1 00 00 f0 00blk_update_request: I/O error, dev sda, sector 1560289 op 0x0:(READ) flags0x84700phys_seg19 prio class 0
sd 0: 0:0:0: [sda] tag#0 device offline or changedFix it by changing the action in
scsi_io_completion_action()fromACTION_FAILtoACTION_RETRYby adding the conditioncmd->device-> lockable.Signed-off-by Michael Wu <[email protected]>---
drivers/scsi/scsi_lib.c| 3 ++-1 file changed, 2 insertions(+), 1 deletion(-)drivers/scsi/scsi_lib.c +0
-0@@ -704,7 +704,8 @@ static void scsi_io_completion_action(struct scsi_cmnd *cmd, int result) } else if (sense_valid && sense_current) { switch (sshdr.sense_key) {case
UNIT_ATTENTION:
Quoted 9 lines
Quoted 6 lines
- if (
cmd->device->removable) {
+ if (cmd->device->removable&&
+cmd->device->lockable) {
/* Detected disc change. Set a bit
* and quietly refuse further access. */To me the above doesn't look like a good way to address this. I don't see why a device being lockable should control whether or not a unit attention results in a retry? Shouldn't the decision taken by
scsi_io_completion_action()depend on the ASC and ASCQ codes rather than on whether a device is removable and/or lockable?
Dear Bart,
Yes... My patch did seem suspicious. Here's the scene about the block I/O error: Some card reader does not respond the command 'MEDIUM REMOVAL PREVENT' correctly, as a result, the host does not send subsequent cmd 'MEDIUM REMOVAL ALLOW'/'MEDIUM REMOVAL PREVENT' before/after sleep, which leads to a enumeration failure after system resume. I wonder, without changing the behavior of the device, is there's a better way to solve this? -- Modifying the scsi core should not be a good idea though :(
Quoted 22 lines
BTW, the code modified by the above patch is old. This is what I found in the 2002 version of
scsi_lib.c:if ((SCpnt->sense_buffer[0] &
0x7f) ==0x70
&& (SCpnt->sense_buffer[2] &0xf) ==UNIT_ATTENTION) { if (SCpnt->device->removable) {
/* detected disc change. set a bit and quietly refuse
* further access.
*/
SCpnt->device->changed= 1;
SCpnt =scsi_end_request(SCpnt, 0, this_count); return;
} else {
/*
* Must have been a power glitch, or a
* bus reset. Could not have been a
* media change, so we just retry the
* request and see what happens.
*/
scsi_queue_next_request(q, SCpnt);
return;
}
Quoted 3 lines
Bart.
Thanks,
Thanks for your kindly notice. I looked around in the latest linux mainline repo, but could not find this code. Where can I get this 2002 version of scsi_lib.c? Thank you.
Signature · 2 lines
Regards, Michael Wu
Quoted 2 lines · Michael Wu
Yes... My patch did seem suspicious. Here's the scene about the block I/O error: Some card reader does not respond the command 'MEDIUM REMOVAL PREVENT' correctly, as a result, the host does not send subsequent cmd 'MEDIUM REMOVAL ALLOW'/'MEDIUM REMOVAL PREVENT' before/after sleep, which leads to a enumeration failure after system resume. I wonder, without changing the behavior of the device, is there's a better way to solve this? -- Modifying the scsi core should not be a good idea though :(
The above is not clear to me. My understanding is that "MEDIUM REMOVAL PREVENT" is a sense code instead of a SCSI command?
Quoted 1 line
Thanks for your kindly notice. I looked around in the latest linux mainline repo, but could not find this code. Where can I get this 2002 version of
scsi_lib.c? Thank you.
Please take a look at https://stackoverflow.com/questions/3264283/linux-kernel-historical-git-repository-with-full-history. That web page has instructions for how to configure a git repository such that history goes back before the time when Linus started using git.
Bart.
Quoted 4 lines · Bart Van Assche
Quoted 2 lines · Michael Wu
Yes... My patch did seem suspicious. Here's the scene about the block I/O error: Some card reader does not respond the command 'MEDIUM REMOVAL PREVENT' correctly, as a result, the host does not send subsequent cmd 'MEDIUM REMOVAL ALLOW'/'MEDIUM REMOVAL PREVENT' before/after sleep, which leads to a enumeration failure after system resume. I wonder, without changing the behavior of the device, is there's a better way to solve this? -- Modifying the scsi core should not be a good idea though :(
Quoted 8 lines
The above is not clear to me. My understanding is that "MEDIUM REMOVAL PREVENT" is a sense code instead of a SCSI command?
Quoted 1 line
Thanks for your kindly notice. I looked around in the latest linux mainline repo, but could not find this code. Where can I get this 2002 version of
scsi_lib.c? Thank you.Please take a look at https://stackoverflow.com/questions/3264283/linux-kernel-historical-git-repository-with-full-history. That web page has instructions for how to configure a git repository such that history goes back before the time when Linus started using git.
Bart.
Dear Bart,
Thank you. I'll try to figure it out and sync to you later.
Signature · 2 lines
Regards, Michael Wu