mirror of
https://github.com/SCST-project/scst.git
synced 2026-08-19 13:46:25 +00:00
Some cleanups to make the code more readable
git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@4365 d57e44dd-8a1f-0410-8b47-8ef2f437770f
This commit is contained in:
@@ -2935,30 +2935,6 @@ struct scst_cmd *scst_find_cmd(struct scst_session *sess, void *data,
|
||||
enum dma_data_direction scst_to_dma_dir(int scst_dir);
|
||||
enum dma_data_direction scst_to_tgt_dma_dir(int scst_dir);
|
||||
|
||||
/*
|
||||
* Returns true, if cmd's CDB is fully locally handled by SCST and false
|
||||
* otherwise. Dev handlers parse() and dev_done() not called for such commands.
|
||||
*/
|
||||
static inline bool scst_is_cmd_fully_local(struct scst_cmd *cmd)
|
||||
{
|
||||
return (cmd->op_flags & SCST_FULLY_LOCAL_CMD) != 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns true, if cmd's CDB is locally handled by SCST and
|
||||
* false otherwise.
|
||||
*/
|
||||
static inline bool scst_is_cmd_local(struct scst_cmd *cmd)
|
||||
{
|
||||
return (cmd->op_flags & SCST_LOCAL_CMD) != 0;
|
||||
}
|
||||
|
||||
/* Returns true, if cmd can deliver UA */
|
||||
static inline bool scst_is_ua_command(struct scst_cmd *cmd)
|
||||
{
|
||||
return (cmd->op_flags & SCST_SKIP_UA) == 0;
|
||||
}
|
||||
|
||||
int scst_register_virtual_device(struct scst_dev_type *dev_handler,
|
||||
const char *dev_name);
|
||||
void scst_unregister_virtual_device(int id);
|
||||
|
||||
@@ -190,7 +190,13 @@ enum scst_cdb_flags {
|
||||
SCST_SKIP_UA = 0x0080,
|
||||
SCST_WRITE_MEDIUM = 0x0100,
|
||||
SCST_LOCAL_CMD = 0x0200,
|
||||
|
||||
/*
|
||||
* Set if CDB is fully locally handled by SCST. Dev handlers
|
||||
* parse() and dev_done() not called for such commands
|
||||
*/
|
||||
SCST_FULLY_LOCAL_CMD = 0x0400,
|
||||
|
||||
SCST_REG_RESERVE_ALLOWED = 0x0800,
|
||||
SCST_WRITE_EXCL_ALLOWED = 0x1000,
|
||||
SCST_EXCL_ACCESS_ALLOWED = 0x2000,
|
||||
@@ -252,8 +258,7 @@ enum scst_cdb_flags {
|
||||
#define scst_sense_invalid_field_in_parm_list ILLEGAL_REQUEST, 0x26, 0
|
||||
#define scst_sense_parameter_value_invalid ILLEGAL_REQUEST, 0x26, 2
|
||||
#define scst_sense_invalid_release ILLEGAL_REQUEST, 0x26, 4
|
||||
#define scst_sense_parameter_list_length_invalid \
|
||||
ILLEGAL_REQUEST, 0x1A, 0
|
||||
#define scst_sense_parameter_list_length_invalid ILLEGAL_REQUEST, 0x1A, 0
|
||||
#define scst_sense_reset_UA UNIT_ATTENTION, 0x29, 0
|
||||
#define scst_sense_nexus_loss_UA UNIT_ATTENTION, 0x29, 0x7
|
||||
#define scst_sense_saving_params_unsup ILLEGAL_REQUEST, 0x39, 0
|
||||
|
||||
@@ -668,7 +668,7 @@ static int dev_user_alloc_space(struct scst_user_cmd *ucmd)
|
||||
}
|
||||
|
||||
if (!(cmd->data_direction & SCST_DATA_WRITE) &&
|
||||
!scst_is_cmd_local(cmd)) {
|
||||
((cmd->op_flags & SCST_LOCAL_CMD) == 0)) {
|
||||
TRACE_DBG("Delayed alloc, ucmd %p", ucmd);
|
||||
goto out;
|
||||
}
|
||||
|
||||
@@ -1832,7 +1832,7 @@ static int vcdrom_exec(struct scst_cmd *cmd)
|
||||
goto out_done;
|
||||
}
|
||||
|
||||
if (virt_dev->media_changed && scst_is_ua_command(cmd)) {
|
||||
if (virt_dev->media_changed && ((cmd->op_flags & SCST_SKIP_UA) == 0)) {
|
||||
spin_lock(&virt_dev->flags_lock);
|
||||
if (virt_dev->media_changed) {
|
||||
virt_dev->media_changed = 0;
|
||||
|
||||
+9
-16
@@ -4478,13 +4478,9 @@ static void scst_complete_request_sense(struct scst_cmd *req_cmd)
|
||||
return;
|
||||
}
|
||||
|
||||
struct scst_i_finish_t {
|
||||
void (*scst_i_finish_fn) (struct scst_cmd *cmd);
|
||||
};
|
||||
|
||||
struct scst_write_same_priv {
|
||||
/* Must be the first for scst_finish_internal_cmd()! */
|
||||
struct scst_i_finish_t ws_finish_fn;
|
||||
scst_i_finish_fn_t ws_finish_fn;
|
||||
|
||||
struct scst_cmd *ws_orig_cmd;
|
||||
|
||||
@@ -4508,7 +4504,7 @@ static int scst_ws_push_single_write(struct scst_write_same_priv *wsp,
|
||||
struct scatterlist *ws_sg = wsp->ws_sg;
|
||||
int ws_sg_cnt = wsp->ws_sg_cnt;
|
||||
int res, i;
|
||||
static uint8_t write16_cdb[16];
|
||||
uint8_t write16_cdb[16];
|
||||
struct scatterlist *sg;
|
||||
int sg_cnt, len = blocks << ws_cmd->dev->block_shift;
|
||||
struct sgv_pool_obj *sgv;
|
||||
@@ -4772,7 +4768,7 @@ void scst_write_same(struct scst_cmd *cmd)
|
||||
}
|
||||
|
||||
mutex_init(&wsp->ws_mutex);
|
||||
wsp->ws_finish_fn.scst_i_finish_fn = scst_ws_write_cmd_finished;
|
||||
wsp->ws_finish_fn = scst_ws_write_cmd_finished;
|
||||
wsp->ws_orig_cmd = cmd;
|
||||
|
||||
wsp->ws_cur_lba = cmd->lba;
|
||||
@@ -4828,8 +4824,8 @@ int scst_finish_internal_cmd(struct scst_cmd *cmd)
|
||||
if (cmd->cdb[0] == REQUEST_SENSE)
|
||||
scst_complete_request_sense(cmd);
|
||||
else {
|
||||
struct scst_i_finish_t *f = cmd->tgt_i_priv;
|
||||
f->scst_i_finish_fn(cmd);
|
||||
scst_i_finish_fn_t f = cmd->tgt_i_priv;
|
||||
f(cmd);
|
||||
}
|
||||
|
||||
__scst_cmd_put(cmd);
|
||||
@@ -7841,7 +7837,7 @@ bool __scst_check_blocked_dev(struct scst_cmd *cmd)
|
||||
(long long unsigned int)cmd->tag, cmd->cdb[0],
|
||||
dev->virt_name);
|
||||
goto out_block;
|
||||
} else if (scst_is_strictly_serialized_cmd(cmd)) {
|
||||
} else if ((cmd->op_flags & SCST_STRICTLY_SERIALIZED) == SCST_STRICTLY_SERIALIZED) {
|
||||
TRACE_MGMT_DBG("cmd %p (tag %llu, op %x): blocking further "
|
||||
"cmds on dev %s due to strict serialization", cmd,
|
||||
(long long unsigned int)cmd->tag, cmd->cdb[0],
|
||||
@@ -7856,7 +7852,8 @@ bool __scst_check_blocked_dev(struct scst_cmd *cmd)
|
||||
goto out_block;
|
||||
} else
|
||||
cmd->unblock_dev = 1;
|
||||
} else if ((dev->dev_double_ua_possible) || scst_is_serialized_cmd(cmd)) {
|
||||
} else if ((dev->dev_double_ua_possible) ||
|
||||
((cmd->op_flags & SCST_SERIALIZED) != 0)) {
|
||||
TRACE_MGMT_DBG("cmd %p (tag %llu, op %x): blocking further cmds "
|
||||
"on dev %s due to %s", cmd, (long long unsigned int)cmd->tag,
|
||||
cmd->cdb[0], dev->virt_name,
|
||||
@@ -7890,10 +7887,6 @@ void scst_unblock_dev(struct scst_device *dev)
|
||||
TRACE_MGMT_DBG("Device UNBLOCK(new %d), dev %s",
|
||||
dev->block_count-1, dev->virt_name);
|
||||
|
||||
#ifdef CONFIG_SMP
|
||||
EXTRACHECKS_BUG_ON(!spin_is_locked(&dev->dev_lock));
|
||||
#endif
|
||||
|
||||
if (--dev->block_count == 0) {
|
||||
struct scst_cmd *cmd, *tcmd;
|
||||
unsigned long flags;
|
||||
@@ -7912,7 +7905,7 @@ void scst_unblock_dev(struct scst_device *dev)
|
||||
else
|
||||
list_add_tail(&cmd->cmd_list_entry,
|
||||
&cmd->cmd_threads->active_cmd_list);
|
||||
strictly_serialized = scst_is_strictly_serialized_cmd(cmd);
|
||||
strictly_serialized = ((cmd->op_flags & SCST_STRICTLY_SERIALIZED) == SCST_STRICTLY_SERIALIZED);
|
||||
wake_up(&cmd->cmd_threads->cmd_list_waitQ);
|
||||
spin_unlock(&cmd->cmd_threads->cmd_list_lock);
|
||||
if (dev->strictly_serialized_cmd_waiting && strictly_serialized)
|
||||
|
||||
+2
-15
@@ -114,6 +114,8 @@ extern unsigned long scst_trace_flag;
|
||||
#define SCST_MAX_EACH_INTERNAL_IO_SIZE (128*1024)
|
||||
#define SCST_MAX_IN_FLIGHT_INTERNAL_COMMANDS 32
|
||||
|
||||
typedef void (*scst_i_finish_fn_t) (struct scst_cmd *cmd);
|
||||
|
||||
extern struct mutex scst_mutex2;
|
||||
|
||||
extern int scst_threads;
|
||||
@@ -594,21 +596,6 @@ void scst_free_aen(struct scst_aen *aen);
|
||||
void scst_gen_aen_or_ua(struct scst_tgt_dev *tgt_dev,
|
||||
int key, int asc, int ascq);
|
||||
|
||||
static inline bool scst_is_implicit_hq_cmd(struct scst_cmd *cmd)
|
||||
{
|
||||
return (cmd->op_flags & SCST_IMPLICIT_HQ) != 0;
|
||||
}
|
||||
|
||||
static inline bool scst_is_serialized_cmd(struct scst_cmd *cmd)
|
||||
{
|
||||
return (cmd->op_flags & SCST_SERIALIZED) != 0;
|
||||
}
|
||||
|
||||
static inline bool scst_is_strictly_serialized_cmd(struct scst_cmd *cmd)
|
||||
{
|
||||
return (cmd->op_flags & SCST_STRICTLY_SERIALIZED) == SCST_STRICTLY_SERIALIZED;
|
||||
}
|
||||
|
||||
/*
|
||||
* Some notes on devices "blocking". Blocking means that no
|
||||
* commands will go from SCST to underlying SCSI device until it
|
||||
|
||||
+10
-10
@@ -129,7 +129,7 @@ static bool scst_check_blocked_dev(struct scst_cmd *cmd)
|
||||
|
||||
if (unlikely(dev->block_count > 0) ||
|
||||
unlikely(dev->dev_double_ua_possible) ||
|
||||
unlikely(scst_is_serialized_cmd(cmd)))
|
||||
unlikely((cmd->op_flags & SCST_SERIALIZED) != 0))
|
||||
res = __scst_check_blocked_dev(cmd);
|
||||
else
|
||||
res = false;
|
||||
@@ -568,7 +568,7 @@ static int scst_parse_cmd(struct scst_cmd *cmd)
|
||||
|
||||
TRACE_ENTRY();
|
||||
|
||||
if (likely(!scst_is_cmd_fully_local(cmd))) {
|
||||
if (likely((cmd->op_flags & SCST_FULLY_LOCAL_CMD) == 0)) {
|
||||
if (unlikely(!devt->parse_atomic &&
|
||||
scst_cmd_atomic(cmd))) {
|
||||
/*
|
||||
@@ -967,7 +967,7 @@ static int scst_prepare_space(struct scst_cmd *cmd)
|
||||
if (cmd->data_direction == SCST_DATA_NONE)
|
||||
goto done;
|
||||
|
||||
if (likely(!scst_is_cmd_fully_local(cmd)) &&
|
||||
if (likely((cmd->op_flags & SCST_FULLY_LOCAL_CMD) == 0) &&
|
||||
(devt->alloc_data_buf != NULL)) {
|
||||
int state;
|
||||
|
||||
@@ -2426,7 +2426,7 @@ int __scst_check_local_events(struct scst_cmd *cmd, bool preempt_tests_only)
|
||||
/* If we had internal bus reset, set the command error unit attention */
|
||||
if ((dev->scsi_dev != NULL) &&
|
||||
unlikely(dev->scsi_dev->was_reset)) {
|
||||
if (scst_is_ua_command(cmd)) {
|
||||
if ((cmd->op_flags & SCST_SKIP_UA) == 0) {
|
||||
int done = 0;
|
||||
/*
|
||||
* Prevent more than 1 cmd to be triggered by was_reset
|
||||
@@ -2452,7 +2452,7 @@ int __scst_check_local_events(struct scst_cmd *cmd, bool preempt_tests_only)
|
||||
|
||||
if (unlikely(test_bit(SCST_TGT_DEV_UA_PENDING,
|
||||
&cmd->tgt_dev->tgt_dev_flags))) {
|
||||
if (scst_is_ua_command(cmd)) {
|
||||
if ((cmd->op_flags & SCST_SKIP_UA) == 0) {
|
||||
rc = scst_set_pending_UA(cmd, NULL, NULL);
|
||||
if (rc == 0)
|
||||
goto out_complete;
|
||||
@@ -2699,7 +2699,7 @@ static int scst_do_local_exec(struct scst_cmd *cmd)
|
||||
goto out_done;
|
||||
}
|
||||
|
||||
if (!scst_is_cmd_local(cmd)) {
|
||||
if ((cmd->op_flags & SCST_LOCAL_CMD) == 0) {
|
||||
res = SCST_EXEC_NOT_COMPLETED;
|
||||
goto out;
|
||||
}
|
||||
@@ -2979,7 +2979,7 @@ static int scst_check_sense(struct scst_cmd *cmd)
|
||||
/* If we had internal bus reset behind us, set the command error UA */
|
||||
if ((dev->scsi_dev != NULL) &&
|
||||
unlikely(cmd->host_status == DID_RESET) &&
|
||||
scst_is_ua_command(cmd)) {
|
||||
((cmd->op_flags & SCST_SKIP_UA) == 0)) {
|
||||
TRACE(TRACE_MGMT, "DID_RESET: was_reset=%d host_status=%x",
|
||||
dev->scsi_dev->was_reset, cmd->host_status);
|
||||
scst_set_cmd_error(cmd, SCST_LOAD_SENSE(scst_sense_reset_UA));
|
||||
@@ -3034,7 +3034,7 @@ static int scst_check_sense(struct scst_cmd *cmd)
|
||||
}
|
||||
|
||||
if (unlikely(cmd->double_ua_possible)) {
|
||||
if (scst_is_ua_command(cmd)) {
|
||||
if ((cmd->op_flags & SCST_SKIP_UA) == 0) {
|
||||
TRACE_MGMT_DBG("Clearing dbl_ua_possible flag (dev %p, "
|
||||
"cmd %p)", dev, cmd);
|
||||
/*
|
||||
@@ -3348,7 +3348,7 @@ static int scst_dev_done(struct scst_cmd *cmd)
|
||||
|
||||
state = SCST_CMD_STATE_PRE_XMIT_RESP;
|
||||
|
||||
if (likely(!scst_is_cmd_fully_local(cmd)) &&
|
||||
if (likely((cmd->op_flags & SCST_FULLY_LOCAL_CMD) == 0) &&
|
||||
likely(devt->dev_done != NULL)) {
|
||||
int rc;
|
||||
|
||||
@@ -3804,7 +3804,7 @@ static void scst_cmd_set_sn(struct scst_cmd *cmd)
|
||||
|
||||
TRACE_ENTRY();
|
||||
|
||||
if (scst_is_implicit_hq_cmd(cmd) &&
|
||||
if (((cmd->op_flags & SCST_IMPLICIT_HQ) != 0) &&
|
||||
likely(cmd->queue_type == SCST_CMD_QUEUE_SIMPLE)) {
|
||||
TRACE_SN("Implicit HQ cmd %p", cmd);
|
||||
cmd->queue_type = SCST_CMD_QUEUE_HEAD_OF_QUEUE;
|
||||
|
||||
Reference in New Issue
Block a user