From 476900e0fe83cbb5eb266e96c541793a677a98ca Mon Sep 17 00:00:00 2001 From: Vladislav Bolkhovitin Date: Fri, 24 Aug 2007 16:54:19 +0000 Subject: [PATCH] - Calling pre_exec() moved to the separate state - Minor cleanups git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@170 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- scst/include/scsi_tgt.h | 15 +++++++----- scst/src/scst_lib.c | 1 - scst/src/scst_targ.c | 53 +++++++++++++++++++++++++---------------- 3 files changed, 42 insertions(+), 27 deletions(-) diff --git a/scst/include/scsi_tgt.h b/scst/include/scsi_tgt.h index 7bbbb2be9..6a0dfc2e1 100644 --- a/scst/include/scsi_tgt.h +++ b/scst/include/scsi_tgt.h @@ -66,23 +66,26 @@ /* Waiting for data from the initiator (until scst_rx_data() called) */ #define SCST_CMD_STATE_DATA_WAIT 8 +/* Target driver's pre_exec() is going to be called */ +#define SCST_CMD_STATE_PRE_EXEC 9 + /* CDB is going to be sent to SCSI mid-level for execution */ -#define SCST_CMD_STATE_SEND_TO_MIDLEV 9 +#define SCST_CMD_STATE_SEND_TO_MIDLEV 10 /* Waiting for CDB's execution finish */ -#define SCST_CMD_STATE_EXECUTING 10 +#define SCST_CMD_STATE_EXECUTING 11 /* Dev handler's dev_done() is going to be called */ -#define SCST_CMD_STATE_DEV_DONE 11 +#define SCST_CMD_STATE_DEV_DONE 12 /* Target driver's xmit_response() is going to be called */ -#define SCST_CMD_STATE_XMIT_RESP 12 +#define SCST_CMD_STATE_XMIT_RESP 13 /* Waiting for response's transmission finish */ -#define SCST_CMD_STATE_XMIT_WAIT 13 +#define SCST_CMD_STATE_XMIT_WAIT 14 /* The cmd finished */ -#define SCST_CMD_STATE_FINISHED 14 +#define SCST_CMD_STATE_FINISHED 15 /************************************************************* ** Can be retuned instead of cmd's state by dev handlers' diff --git a/scst/src/scst_lib.c b/scst/src/scst_lib.c index 16a8c247d..9396a83e6 100644 --- a/scst/src/scst_lib.c +++ b/scst/src/scst_lib.c @@ -2636,7 +2636,6 @@ struct scst_thr_data_hdr *scst_find_thr_data(struct scst_tgt_dev *tgt_dev) void __scst_block_dev(struct scst_device *dev) { dev->block_count++; - smp_mb(); TRACE_MGMT_DBG("Device BLOCK(new %d), dev %p", dev->block_count, dev); } diff --git a/scst/src/scst_targ.c b/scst/src/scst_targ.c index 07d8397a9..da97b9fb9 100644 --- a/scst/src/scst_targ.c +++ b/scst/src/scst_targ.c @@ -452,6 +452,7 @@ call_parse: case SCST_CMD_STATE_PREPARE_SPACE: case SCST_CMD_STATE_DEV_PARSE: case SCST_CMD_STATE_RDY_TO_XFER: + case SCST_CMD_STATE_PRE_EXEC: case SCST_CMD_STATE_SEND_TO_MIDLEV: case SCST_CMD_STATE_DEV_DONE: case SCST_CMD_STATE_XMIT_RESP: @@ -677,7 +678,7 @@ prep_done: break; default: - cmd->state = SCST_CMD_STATE_SEND_TO_MIDLEV; + cmd->state = SCST_CMD_STATE_PRE_EXEC; break; } @@ -726,7 +727,7 @@ void scst_restart_cmd(struct scst_cmd *cmd, int status, int pref_context) cmd->state = SCST_CMD_STATE_RDY_TO_XFER; break; default: - cmd->state = SCST_CMD_STATE_SEND_TO_MIDLEV; + cmd->state = SCST_CMD_STATE_PRE_EXEC; break; } if (cmd->no_sn) @@ -826,7 +827,7 @@ static int scst_rdy_to_xfer(struct scst_cmd *cmd) } if (cmd->tgtt->rdy_to_xfer == NULL) { - cmd->state = SCST_CMD_STATE_SEND_TO_MIDLEV; + cmd->state = SCST_CMD_STATE_PRE_EXEC; res = SCST_CMD_STATE_RES_CONT_SAME; goto out; } @@ -971,7 +972,7 @@ void scst_rx_data(struct scst_cmd *cmd, int status, int pref_context) switch (status) { case SCST_RX_STATUS_SUCCESS: - cmd->state = SCST_CMD_STATE_SEND_TO_MIDLEV; + cmd->state = SCST_CMD_STATE_PRE_EXEC; /* Small context optimization */ if ((pref_context == SCST_CONTEXT_TASKLET) || (pref_context == SCST_CONTEXT_DIRECT_ATOMIC)) { @@ -1007,12 +1008,17 @@ void scst_rx_data(struct scst_cmd *cmd, int status, int pref_context) return; } -static int scst_tgt_pre_exec(struct scst_cmd *cmd, int *action) +static int scst_tgt_pre_exec(struct scst_cmd *cmd) { - int res = 0, rc; + int rc; TRACE_ENTRY(); + cmd->state = SCST_CMD_STATE_SEND_TO_MIDLEV; + + if (cmd->tgtt->pre_exec == NULL) + goto out; + TRACE_DBG("Calling pre_exec(%p)", cmd); rc = cmd->tgtt->pre_exec(cmd); TRACE_DBG("pre_exec() returned %d", rc); @@ -1021,8 +1027,6 @@ static int scst_tgt_pre_exec(struct scst_cmd *cmd, int *action) switch(rc) { case SCST_PREPROCESS_STATUS_ERROR_SENSE_SET: cmd->state = SCST_CMD_STATE_DEV_DONE; - *action = SCST_CMD_STATE_RES_CONT_SAME; - res = -1; break; case SCST_PREPROCESS_STATUS_ERROR_FATAL: set_bit(SCST_CMD_NO_RESP, &cmd->cmd_flags); @@ -1031,8 +1035,6 @@ static int scst_tgt_pre_exec(struct scst_cmd *cmd, int *action) scst_set_cmd_error(cmd, SCST_LOAD_SENSE(scst_sense_hardw_error)); cmd->state = SCST_CMD_STATE_DEV_DONE; - *action = SCST_CMD_STATE_RES_CONT_SAME; - res = -1; break; default: sBUG(); @@ -1040,8 +1042,9 @@ static int scst_tgt_pre_exec(struct scst_cmd *cmd, int *action) } } - TRACE_EXIT_RES(res); - return res; +out: + TRACE_EXIT(); + return SCST_CMD_STATE_RES_CONT_SAME; } static void scst_inc_check_expected_sn(struct scst_cmd *cmd) @@ -1892,12 +1895,6 @@ static int scst_send_to_midlev(struct scst_cmd *cmd) res = SCST_CMD_STATE_RES_CONT_NEXT; - if (cmd->tgtt->pre_exec != NULL) { - rc = scst_tgt_pre_exec(cmd, &res); - if (unlikely(rc != 0)) - goto out; - } - if (unlikely(scst_inc_on_dev_cmd(cmd) != 0)) goto out; @@ -2339,12 +2336,13 @@ static int scst_dev_done(struct scst_cmd *cmd) } switch (state) { + case SCST_CMD_STATE_XMIT_RESP: case SCST_CMD_STATE_DEV_PARSE: case SCST_CMD_STATE_PREPARE_SPACE: case SCST_CMD_STATE_RDY_TO_XFER: + case SCST_CMD_STATE_PRE_EXEC: case SCST_CMD_STATE_SEND_TO_MIDLEV: case SCST_CMD_STATE_DEV_DONE: - case SCST_CMD_STATE_XMIT_RESP: case SCST_CMD_STATE_FINISHED: cmd->state = state; res = SCST_CMD_STATE_RES_CONT_SAME; @@ -2908,7 +2906,10 @@ void scst_process_active_cmd(struct scst_cmd *cmd, int context) switch (cmd->state) { case SCST_CMD_STATE_DEV_PARSE: res = scst_parse_cmd(cmd); - break; + if ((res != SCST_CMD_STATE_RES_CONT_SAME) || + (cmd->state != SCST_CMD_STATE_PREPARE_SPACE)) + break; + /* else go through */ case SCST_CMD_STATE_PREPARE_SPACE: res = scst_prepare_space(cmd); @@ -2918,6 +2919,13 @@ void scst_process_active_cmd(struct scst_cmd *cmd, int context) res = scst_rdy_to_xfer(cmd); break; + case SCST_CMD_STATE_PRE_EXEC: + res = scst_tgt_pre_exec(cmd); + if ((res != SCST_CMD_STATE_RES_CONT_SAME) || + (cmd->state != SCST_CMD_STATE_SEND_TO_MIDLEV)) + break; + /* else go through */ + case SCST_CMD_STATE_SEND_TO_MIDLEV: if (tm_dbg_check_cmd(cmd) != 0) { res = SCST_CMD_STATE_RES_CONT_NEXT; @@ -2932,6 +2940,10 @@ void scst_process_active_cmd(struct scst_cmd *cmd, int context) case SCST_CMD_STATE_DEV_DONE: res = scst_dev_done(cmd); + if ((res != SCST_CMD_STATE_RES_CONT_SAME) || + (cmd->state != SCST_CMD_STATE_XMIT_RESP)) + break; + /* else go through */ break; case SCST_CMD_STATE_XMIT_RESP: @@ -2959,6 +2971,7 @@ void scst_process_active_cmd(struct scst_cmd *cmd, int context) case SCST_CMD_STATE_DEV_PARSE: case SCST_CMD_STATE_PREPARE_SPACE: case SCST_CMD_STATE_RDY_TO_XFER: + case SCST_CMD_STATE_PRE_EXEC: case SCST_CMD_STATE_SEND_TO_MIDLEV: case SCST_CMD_STATE_DEV_DONE: case SCST_CMD_STATE_XMIT_RESP: