diff --git a/scst/include/scst.h b/scst/include/scst.h index 1443f3fc1..42ad4abe3 100644 --- a/scst/include/scst.h +++ b/scst/include/scst.h @@ -114,53 +114,50 @@ static inline int list_is_last(const struct list_head *list, ** "switch" statements. *************************************************************/ -/* Internal parsing */ -#define SCST_CMD_STATE_PRE_PARSE 0 - /* Dev handler's parse() is going to be called */ -#define SCST_CMD_STATE_DEV_PARSE 1 +#define SCST_CMD_STATE_PARSE 0 /* Allocation of the cmd's data buffer */ -#define SCST_CMD_STATE_PREPARE_SPACE 2 +#define SCST_CMD_STATE_PREPARE_SPACE 1 /* Calling preprocessing_done() */ -#define SCST_CMD_STATE_PREPROCESSING_DONE 3 +#define SCST_CMD_STATE_PREPROCESSING_DONE 2 /* Target driver's rdy_to_xfer() is going to be called */ -#define SCST_CMD_STATE_RDY_TO_XFER 4 +#define SCST_CMD_STATE_RDY_TO_XFER 3 /* Target driver's pre_exec() is going to be called */ -#define SCST_CMD_STATE_TGT_PRE_EXEC 5 +#define SCST_CMD_STATE_TGT_PRE_EXEC 4 /* Cmd is going to be sent for execution */ -#define SCST_CMD_STATE_SEND_FOR_EXEC 6 +#define SCST_CMD_STATE_SEND_FOR_EXEC 5 /* Cmd is being checked if it should be executed locally */ -#define SCST_CMD_STATE_LOCAL_EXEC 7 +#define SCST_CMD_STATE_LOCAL_EXEC 6 /* Cmd is ready for execution */ -#define SCST_CMD_STATE_REAL_EXEC 8 +#define SCST_CMD_STATE_REAL_EXEC 7 /* Internal post-exec checks */ -#define SCST_CMD_STATE_PRE_DEV_DONE 9 +#define SCST_CMD_STATE_PRE_DEV_DONE 8 /* Internal MODE SELECT pages related checks */ -#define SCST_CMD_STATE_MODE_SELECT_CHECKS 10 +#define SCST_CMD_STATE_MODE_SELECT_CHECKS 9 /* Dev handler's dev_done() is going to be called */ -#define SCST_CMD_STATE_DEV_DONE 11 +#define SCST_CMD_STATE_DEV_DONE 10 /* Target driver's xmit_response() is going to be called */ -#define SCST_CMD_STATE_PRE_XMIT_RESP 12 +#define SCST_CMD_STATE_PRE_XMIT_RESP 11 /* Target driver's xmit_response() is going to be called */ -#define SCST_CMD_STATE_XMIT_RESP 13 +#define SCST_CMD_STATE_XMIT_RESP 12 /* Cmd finished */ -#define SCST_CMD_STATE_FINISHED 14 +#define SCST_CMD_STATE_FINISHED 13 /* Internal cmd finished */ -#define SCST_CMD_STATE_FINISHED_INTERNAL 15 +#define SCST_CMD_STATE_FINISHED_INTERNAL 14 #define SCST_CMD_STATE_LAST_ACTIVE (SCST_CMD_STATE_FINISHED_INTERNAL+100) diff --git a/scst/src/scst_lib.c b/scst/src/scst_lib.c index 9c9dc4999..837833f1f 100644 --- a/scst/src/scst_lib.c +++ b/scst/src/scst_lib.c @@ -1866,8 +1866,7 @@ static int scst_get_cmd_abnormal_done_state(const struct scst_cmd *cmd) switch (cmd->state) { case SCST_CMD_STATE_INIT_WAIT: case SCST_CMD_STATE_INIT: - case SCST_CMD_STATE_PRE_PARSE: - case SCST_CMD_STATE_DEV_PARSE: + case SCST_CMD_STATE_PARSE: if (cmd->preprocessing_only) { res = SCST_CMD_STATE_PREPROCESSING_DONE; break; @@ -1952,7 +1951,7 @@ int scst_set_cmd_abnormal_done_state(struct scst_cmd *cmd) switch (cmd->state) { case SCST_CMD_STATE_INIT_WAIT: case SCST_CMD_STATE_INIT: - case SCST_CMD_STATE_PRE_PARSE: + case SCST_CMD_STATE_PARSE: case SCST_CMD_STATE_PREPROCESSING_DONE: case SCST_CMD_STATE_PREPROCESSING_DONE_CALLED: case SCST_CMD_STATE_PREPARE_SPACE: @@ -1966,7 +1965,6 @@ int scst_set_cmd_abnormal_done_state(struct scst_cmd *cmd) case SCST_CMD_STATE_LOCAL_EXEC: case SCST_CMD_STATE_REAL_EXEC: case SCST_CMD_STATE_REAL_EXECUTING: - case SCST_CMD_STATE_DEV_PARSE: case SCST_CMD_STATE_DEV_DONE: case SCST_CMD_STATE_PRE_DEV_DONE: case SCST_CMD_STATE_MODE_SELECT_CHECKS: @@ -3708,7 +3706,7 @@ static struct scst_cmd *scst_create_prepare_internal_cmd( if (res->tgt_dev != NULL) __scst_get(0); - res->state = SCST_CMD_STATE_PRE_PARSE; + res->state = SCST_CMD_STATE_PARSE; out: TRACE_EXIT_HRES((unsigned long)res); diff --git a/scst/src/scst_targ.c b/scst/src/scst_targ.c index e276ac2ec..e9702cf11 100644 --- a/scst/src/scst_targ.c +++ b/scst/src/scst_targ.c @@ -404,22 +404,12 @@ EXPORT_SYMBOL(scst_cmd_init_done); static int scst_pre_parse(struct scst_cmd *cmd) { - int res = SCST_CMD_STATE_RES_CONT_SAME; + int res; struct scst_device *dev = cmd->dev; int rc; TRACE_ENTRY(); -#ifdef CONFIG_SCST_STRICT_SERIALIZING - cmd->inc_expected_sn_on_done = 1; -#else - cmd->inc_expected_sn_on_done = dev->handler->exec_sync || - scst_is_implicit_ordered(cmd) || - (!dev->has_own_order_mgmt && - (dev->queue_alg == SCST_CONTR_MODE_QUEUE_ALG_RESTRICTED_REORDER || - cmd->queue_type == SCST_CMD_QUEUE_ORDERED)); -#endif - /* * Expected transfer data supplied by the SCSI transport via the * target driver are untrusted, so we prefer to fetch them from CDB. @@ -441,11 +431,19 @@ static int scst_pre_parse(struct scst_cmd *cmd) cmd->cdb[0], dev->handler->name); PRINT_BUFF_FLAG(TRACE_MINOR, "Failed CDB", cmd->cdb, cmd->cdb_len); - } else { + } else EXTRACHECKS_BUG_ON(!(cmd->op_flags & SCST_INFO_VALID)); - } - cmd->state = SCST_CMD_STATE_DEV_PARSE; +#ifdef CONFIG_SCST_STRICT_SERIALIZING + cmd->inc_expected_sn_on_done = 1; +#else + cmd->inc_expected_sn_on_done = dev->handler->exec_sync || + scst_is_implicit_ordered(cmd) || + (!dev->has_own_order_mgmt && + (dev->queue_alg == SCST_CONTR_MODE_QUEUE_ALG_RESTRICTED_REORDER || + cmd->queue_type == SCST_CMD_QUEUE_ORDERED)); +#endif + TRACE_DBG("op_name <%s> (cmd %p), direction=%d " "(expected %d, set %s), bufflen=%d, out_bufflen=%d (expected " @@ -455,6 +453,8 @@ static int scst_pre_parse(struct scst_cmd *cmd) cmd->bufflen, cmd->out_bufflen, cmd->expected_transfer_len, cmd->expected_out_transfer_len, cmd->op_flags); + res = 0; + out: TRACE_EXIT_RES(res); return res; @@ -462,7 +462,7 @@ out: out_err: scst_set_cmd_error(cmd, SCST_LOAD_SENSE(scst_sense_invalid_field_in_cdb)); scst_set_cmd_abnormal_done_state(cmd); - res = SCST_CMD_STATE_RES_CONT_SAME; + res = -1; goto out; } @@ -767,8 +767,7 @@ set_res: #ifdef CONFIG_SCST_EXTRACHECKS switch (state) { case SCST_CMD_STATE_PREPARE_SPACE: - case SCST_CMD_STATE_PRE_PARSE: - case SCST_CMD_STATE_DEV_PARSE: + case SCST_CMD_STATE_PARSE: case SCST_CMD_STATE_RDY_TO_XFER: case SCST_CMD_STATE_TGT_PRE_EXEC: case SCST_CMD_STATE_SEND_FOR_EXEC: @@ -3293,8 +3292,7 @@ static int scst_dev_done(struct scst_cmd *cmd) switch (state) { #ifdef CONFIG_SCST_EXTRACHECKS case SCST_CMD_STATE_PRE_XMIT_RESP: - case SCST_CMD_STATE_DEV_PARSE: - case SCST_CMD_STATE_PRE_PARSE: + case SCST_CMD_STATE_PARSE: case SCST_CMD_STATE_PREPARE_SPACE: case SCST_CMD_STATE_RDY_TO_XFER: case SCST_CMD_STATE_TGT_PRE_EXEC: @@ -3845,7 +3843,7 @@ static int __scst_init_cmd(struct scst_cmd *cmd) int cnt; bool failure = false; - cmd->state = SCST_CMD_STATE_PRE_PARSE; + cmd->state = SCST_CMD_STATE_PARSE; cnt = atomic_inc_return(&cmd->tgt_dev->tgt_dev_cmd_count); if (unlikely(cnt > SCST_MAX_TGT_DEV_COMMANDS)) { @@ -3882,6 +3880,9 @@ static int __scst_init_cmd(struct scst_cmd *cmd) if (unlikely(failure)) goto out_busy; + if (unlikely(scst_pre_parse(cmd) != 0)) + goto out; + if (!cmd->set_sn_on_restart_cmd) scst_cmd_set_sn(cmd); } else if (res < 0) { @@ -4066,13 +4067,7 @@ void scst_process_active_cmd(struct scst_cmd *cmd, bool atomic) do { switch (cmd->state) { - case SCST_CMD_STATE_PRE_PARSE: - res = scst_pre_parse(cmd); - EXTRACHECKS_BUG_ON(res == - SCST_CMD_STATE_RES_NEED_THREAD); - break; - - case SCST_CMD_STATE_DEV_PARSE: + case SCST_CMD_STATE_PARSE: res = scst_parse_cmd(cmd); break; @@ -4172,7 +4167,7 @@ void scst_process_active_cmd(struct scst_cmd *cmd, bool atomic) spin_lock_irq(&cmd->cmd_threads->cmd_list_lock); #ifdef CONFIG_SCST_EXTRACHECKS switch (cmd->state) { - case SCST_CMD_STATE_DEV_PARSE: + case SCST_CMD_STATE_PARSE: case SCST_CMD_STATE_PREPARE_SPACE: case SCST_CMD_STATE_RDY_TO_XFER: case SCST_CMD_STATE_TGT_PRE_EXEC: