From ed07de2ffb14c3533fd0d4cedc74f1b6c2532ec4 Mon Sep 17 00:00:00 2001 From: Vladislav Bolkhovitin Date: Mon, 6 Jun 2011 21:32:16 +0000 Subject: [PATCH] - Return no residual if expected values not set instead of BUG_ON(), because this is valid situation for some preliminary comleted commands. - Cleanup git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@3549 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- scst/src/scst_lib.c | 31 +++++++++++++++++++++++++++---- scst/src/scst_targ.c | 4 +--- 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/scst/src/scst_lib.c b/scst/src/scst_lib.c index a4b4bb46a..ec37ae943 100644 --- a/scst/src/scst_lib.c +++ b/scst/src/scst_lib.c @@ -2186,7 +2186,15 @@ void scst_cmd_set_write_not_received_data_len(struct scst_cmd *cmd, { TRACE_ENTRY(); - sBUG_ON(!cmd->expected_values_set); + if (!cmd->expected_values_set) { + /* + * No expected values set, so no residuals processing. + * It can happen if a command preliminary completed before + * target driver had a chance to set expected values. + */ + TRACE_MGMT_DBG("No expected values set, ignoring (cmd %p)", cmd); + goto out; + } cmd->resid_possible = 1; @@ -2226,13 +2234,25 @@ EXPORT_SYMBOL(scst_cmd_set_write_not_received_data_len); */ bool __scst_get_resid(struct scst_cmd *cmd, int *resid, int *bidi_out_resid) { + bool res; + TRACE_ENTRY(); *resid = 0; if (bidi_out_resid != NULL) *bidi_out_resid = 0; - sBUG_ON(!cmd->expected_values_set); + if (!cmd->expected_values_set) { + /* + * No expected values set, so no residuals processing. + * It can happen if a command preliminary completed before + * target driver had a chance to set expected values. + */ + TRACE_MGMT_DBG("No expected values set, returning no residual " + "(cmd %p)", cmd); + res = false; + goto out; + } if (cmd->expected_data_direction & SCST_DATA_READ) { *resid = cmd->expected_transfer_len - cmd->resp_data_len; @@ -2250,13 +2270,16 @@ bool __scst_get_resid(struct scst_cmd *cmd, int *resid, int *bidi_out_resid) *resid = cmd->write_len - cmd->bufflen; } + res = true; + TRACE_DBG("cmd %p, resid %d, bidi_out_resid %d (resp_data_len %d, " "expected_data_direction %d, write_len %d, bufflen %d)", cmd, *resid, bidi_out_resid ? *bidi_out_resid : 0, cmd->resp_data_len, cmd->expected_data_direction, cmd->write_len, cmd->bufflen); - TRACE_EXIT_RES(1); - return true; +out: + TRACE_EXIT_RES(res); + return res; } EXPORT_SYMBOL(__scst_get_resid); diff --git a/scst/src/scst_targ.c b/scst/src/scst_targ.c index 2fbe4144f..f5c37c5f4 100644 --- a/scst/src/scst_targ.c +++ b/scst/src/scst_targ.c @@ -213,11 +213,9 @@ struct scst_cmd *scst_rx_cmd(struct scst_session *sess, cmd->tgtt = sess->tgt->tgtt; cmd->lun = scst_unpack_lun(lun, lun_len); - if (unlikely(cmd->lun == NO_SUCH_LUN)) { - PRINT_ERROR("Wrong LUN %d, finishing cmd", -1); + if (unlikely(cmd->lun == NO_SUCH_LUN)) scst_set_cmd_error(cmd, SCST_LOAD_SENSE(scst_sense_lun_not_supported)); - } TRACE_DBG("cmd %p, sess %p", cmd, sess); scst_sess_get(sess);