diff --git a/scst/include/scst.h b/scst/include/scst.h index f1146b83a..9982b7bf6 100644 --- a/scst/include/scst.h +++ b/scst/include/scst.h @@ -1199,6 +1199,10 @@ struct scst_cmd { */ int resp_data_len; + /* + * The status fields in case of errors must be set using + * scst_set_cmd_error_status()! + */ uint8_t status; /* status byte from target device */ uint8_t msg_status; /* return status from host adapter itself */ uint8_t host_status; /* set by low-level driver to indicate status */ diff --git a/scst/src/scst_lib.c b/scst/src/scst_lib.c index a1da67ac9..2b9154b2e 100644 --- a/scst/src/scst_lib.c +++ b/scst/src/scst_lib.c @@ -1383,8 +1383,9 @@ struct scst_cmd *scst_alloc_cmd(int gfp_mask) cmd->data_len = -1; cmd->is_send_status = 1; cmd->resp_data_len = -1; - cmd->dbl_ua_orig_resp_data_len = -1; + cmd->dbl_ua_orig_data_direction = SCST_DATA_UNKNOWN; + cmd->dbl_ua_orig_resp_data_len = -1; out: TRACE_EXIT(); diff --git a/scst/src/scst_targ.c b/scst/src/scst_targ.c index 3818851f1..d956324f2 100644 --- a/scst/src/scst_targ.c +++ b/scst/src/scst_targ.c @@ -1104,9 +1104,14 @@ static void scst_do_cmd_done(struct scst_cmd *cmd, int result, scst_set_resp_data_len(cmd, cmd->resp_data_len - resid); } - if (cmd->status == SAM_STAT_CHECK_CONDITION) + if (unlikely(cmd->status == SAM_STAT_CHECK_CONDITION)) { + /* We might have double reset UA here */ + cmd->dbl_ua_orig_resp_data_len = cmd->resp_data_len; + cmd->dbl_ua_orig_data_direction = cmd->data_direction; + scst_alloc_set_sense(cmd, scst_is_context_gfp_atomic(), rq_sense, rq_sense_len); + } TRACE(TRACE_SCSI, "result=%x, cmd->status=%x, resid=%d, " "cmd->msg_status=%x, cmd->host_status=%x, "