Skip to content

Commit 8be70a8

Browse files
David Jefferymartinkpetersen
authored andcommitted
scsi: target: pscsi: Set SCF_TREAT_READ_AS_NORMAL flag only if there is valid data
With tape devices, the SCF_TREAT_READ_AS_NORMAL flag is used by the target subsystem to mark commands which have both data to return as well as sense data. But with pscsi, SCF_TREAT_READ_AS_NORMAL can be set even if there is no data to return. The SCF_TREAT_READ_AS_NORMAL flag causes the target core to call iscsit data-in callbacks even if there is no data, which iscsit does not support. This results in iscsit going into an error state requiring recovery and being unable to complete the command to the initiator. This issue can be resolved by fixing pscsi to only set SCF_TREAT_READ_AS_NORMAL if there is valid data to return alongside the sense data. Link: https://lore.kernel.org/r/20220427183250.291881-1-djeffery@redhat.com Fixes: bd81372 ("scsi: target: transport should handle st FM/EOM/ILI reads") Reported-by: Scott Hamilton <scott.hamilton@atos.net> Tested-by: Laurence Oberman <loberman@redhat.com> Reviewed-by: Laurence Oberman <loberman@redhat.com> Signed-off-by: David Jeffery <djeffery@redhat.com> Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
1 parent faad6ce commit 8be70a8

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

drivers/target/target_core_pscsi.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -588,7 +588,7 @@ static void pscsi_destroy_device(struct se_device *dev)
588588
}
589589

590590
static void pscsi_complete_cmd(struct se_cmd *cmd, u8 scsi_status,
591-
unsigned char *req_sense)
591+
unsigned char *req_sense, int valid_data)
592592
{
593593
struct pscsi_dev_virt *pdv = PSCSI_DEV(cmd->se_dev);
594594
struct scsi_device *sd = pdv->pdv_sd;
@@ -681,7 +681,7 @@ static void pscsi_complete_cmd(struct se_cmd *cmd, u8 scsi_status,
681681
* back despite framework assumption that a
682682
* check condition means there is no data
683683
*/
684-
if (sd->type == TYPE_TAPE &&
684+
if (sd->type == TYPE_TAPE && valid_data &&
685685
cmd->data_direction == DMA_FROM_DEVICE) {
686686
/*
687687
* is sense data valid, fixed format,
@@ -1032,19 +1032,19 @@ static void pscsi_req_done(struct request *req, blk_status_t status)
10321032
struct se_cmd *cmd = req->end_io_data;
10331033
struct scsi_cmnd *scmd = blk_mq_rq_to_pdu(req);
10341034
enum sam_status scsi_status = scmd->result & 0xff;
1035+
int valid_data = cmd->data_length - scmd->resid_len;
10351036
u8 *cdb = cmd->priv;
10361037

10371038
if (scsi_status != SAM_STAT_GOOD) {
10381039
pr_debug("PSCSI Status Byte exception at cmd: %p CDB:"
10391040
" 0x%02x Result: 0x%08x\n", cmd, cdb[0], scmd->result);
10401041
}
10411042

1042-
pscsi_complete_cmd(cmd, scsi_status, scmd->sense_buffer);
1043+
pscsi_complete_cmd(cmd, scsi_status, scmd->sense_buffer, valid_data);
10431044

10441045
switch (host_byte(scmd->result)) {
10451046
case DID_OK:
1046-
target_complete_cmd_with_length(cmd, scsi_status,
1047-
cmd->data_length - scmd->resid_len);
1047+
target_complete_cmd_with_length(cmd, scsi_status, valid_data);
10481048
break;
10491049
default:
10501050
pr_debug("PSCSI Host Byte exception at cmd: %p CDB:"

0 commit comments

Comments
 (0)