diff --git a/scst/src/dev_handlers/scst_vdisk.c b/scst/src/dev_handlers/scst_vdisk.c index 83087cbf9..d05eb024f 100644 --- a/scst/src/dev_handlers/scst_vdisk.c +++ b/scst/src/dev_handlers/scst_vdisk.c @@ -1058,7 +1058,7 @@ static enum compl_status_e vdisk_exec_send_diagnostic(struct vdisk_cmd_params *p static enum compl_status_e vdisk_invalid_opcode(struct vdisk_cmd_params *p) { - TRACE_DBG_SPECIAL("Invalid opcode %d", p->cmd->cdb[0]); + TRACE_DBG("Invalid opcode %d", p->cmd->cdb[0]); return INVALID_OPCODE; } diff --git a/scst/src/scst_lib.c b/scst/src/scst_lib.c index a954c5e02..7215ece23 100644 --- a/scst/src/scst_lib.c +++ b/scst/src/scst_lib.c @@ -4750,7 +4750,8 @@ struct scst_cmd *scst_alloc_cmd(const uint8_t *cdb, cmd->queue_type = SCST_CMD_QUEUE_SIMPLE; cmd->timeout = SCST_DEFAULT_TIMEOUT; cmd->retries = 0; - cmd->data_len = SCST_DEF_DATA_LEN; + cmd->lba = SCST_DEF_LBA_DATA_LEN; + cmd->data_len = SCST_DEF_LBA_DATA_LEN; cmd->is_send_status = 1; cmd->resp_data_len = -1; cmd->write_sg = &cmd->sg; @@ -5565,6 +5566,7 @@ static int get_cdb_info_len_10(struct scst_cmd *cmd, const struct scst_sdbops *sdbops) { cmd->cdb_len = 10; + cmd->lba = 0; /* It supposed to be already zeroed */ EXTRACHECKS_BUG_ON(cmd->bufflen != 0); cmd->data_len = cmd->bufflen; @@ -5574,6 +5576,7 @@ static int get_cdb_info_len_10(struct scst_cmd *cmd, static int get_cdb_info_block_limit(struct scst_cmd *cmd, const struct scst_sdbops *sdbops) { + cmd->lba = 0; cmd->bufflen = 6; cmd->data_len = cmd->bufflen; return 0; @@ -5582,6 +5585,7 @@ static int get_cdb_info_block_limit(struct scst_cmd *cmd, static int get_cdb_info_read_capacity(struct scst_cmd *cmd, const struct scst_sdbops *sdbops) { + cmd->lba = 0; cmd->bufflen = 8; cmd->data_len = cmd->bufflen; return 0; @@ -5594,6 +5598,8 @@ static int get_cdb_info_serv_act_in(struct scst_cmd *cmd, TRACE_ENTRY(); + cmd->lba = 0; + if ((cmd->cdb[1] & 0x1f) == SAI_READ_CAPACITY_16) { cmd->op_name = "READ CAPACITY(16)"; cmd->bufflen = get_unaligned_be32(&cmd->cdb[10]); @@ -5613,6 +5619,7 @@ static int get_cdb_info_serv_act_in(struct scst_cmd *cmd, static int get_cdb_info_single(struct scst_cmd *cmd, const struct scst_sdbops *sdbops) { + cmd->lba = 0; cmd->bufflen = 1; cmd->data_len = cmd->bufflen; return 0; @@ -5623,6 +5630,7 @@ static int get_cdb_info_read_pos(struct scst_cmd *cmd, { int res = 0; + cmd->lba = 0; cmd->bufflen = get_unaligned_be16(cmd->cdb + sdbops->info_len_off); switch (cmd->cdb[1] & 0x1f) { @@ -5670,6 +5678,10 @@ out_inval: static int get_cdb_info_prevent_allow_medium_removal(struct scst_cmd *cmd, const struct scst_sdbops *sdbops) { + cmd->lba = 0; + cmd->data_len = 0; + /* It supposed to be already zeroed */ + EXTRACHECKS_BUG_ON(cmd->bufflen != 0); if ((cmd->cdb[4] & 3) == 0) cmd->op_flags |= SCST_REG_RESERVE_ALLOWED | SCST_WRITE_EXCL_ALLOWED | SCST_EXCL_ACCESS_ALLOWED; @@ -5679,6 +5691,10 @@ static int get_cdb_info_prevent_allow_medium_removal(struct scst_cmd *cmd, static int get_cdb_info_start_stop(struct scst_cmd *cmd, const struct scst_sdbops *sdbops) { + cmd->lba = 0; + cmd->data_len = 0; + /* It supposed to be already zeroed */ + EXTRACHECKS_BUG_ON(cmd->bufflen != 0); if ((cmd->cdb[4] & 0xF1) == 0x1) cmd->op_flags |= SCST_REG_RESERVE_ALLOWED | SCST_WRITE_EXCL_ALLOWED | SCST_EXCL_ACCESS_ALLOWED; @@ -5688,6 +5704,7 @@ static int get_cdb_info_start_stop(struct scst_cmd *cmd, static int get_cdb_info_len_3_read_elem_stat(struct scst_cmd *cmd, const struct scst_sdbops *sdbops) { + cmd->lba = 0; cmd->bufflen = get_unaligned_be24(cmd->cdb + sdbops->info_len_off); cmd->data_len = cmd->bufflen; @@ -5710,6 +5727,7 @@ static int get_cdb_info_bidi_lba_4_len_2(struct scst_cmd *cmd, static int get_cdb_info_fmt(struct scst_cmd *cmd, const struct scst_sdbops *sdbops) { + cmd->lba = 0; if (cmd->cdb[1] & 0x10/*FMTDATA*/) { cmd->data_direction = SCST_DATA_WRITE; cmd->op_flags |= SCST_UNKNOWN_LENGTH; @@ -5736,6 +5754,7 @@ static int get_cdb_info_verify10(struct scst_cmd *cmd, static int get_cdb_info_verify6(struct scst_cmd *cmd, const struct scst_sdbops *sdbops) { + cmd->lba = 0; if (cmd->cdb[1] & BYTCHK) { cmd->bufflen = get_unaligned_be24(cmd->cdb + sdbops->info_len_off); cmd->data_len = cmd->bufflen; @@ -5783,6 +5802,7 @@ static int get_cdb_info_verify16(struct scst_cmd *cmd, static int get_cdb_info_len_1(struct scst_cmd *cmd, const struct scst_sdbops *sdbops) { + cmd->lba = 0; cmd->bufflen = (u32)cmd->cdb[sdbops->info_len_off]; cmd->data_len = cmd->bufflen; return 0; @@ -5811,6 +5831,7 @@ static int get_cdb_info_lba_2_len_1_256(struct scst_cmd *cmd, static int get_cdb_info_len_2(struct scst_cmd *cmd, const struct scst_sdbops *sdbops) { + cmd->lba = 0; cmd->bufflen = get_unaligned_be16(cmd->cdb + sdbops->info_len_off); cmd->data_len = cmd->bufflen; return 0; @@ -5819,6 +5840,7 @@ static int get_cdb_info_len_2(struct scst_cmd *cmd, static int get_cdb_info_len_3(struct scst_cmd *cmd, const struct scst_sdbops *sdbops) { + cmd->lba = 0; cmd->bufflen = get_unaligned_be24(cmd->cdb + sdbops->info_len_off); cmd->data_len = cmd->bufflen; return 0; @@ -5827,6 +5849,7 @@ static int get_cdb_info_len_3(struct scst_cmd *cmd, static int get_cdb_info_len_4(struct scst_cmd *cmd, const struct scst_sdbops *sdbops) { + cmd->lba = 0; cmd->bufflen = get_unaligned_be32(cmd->cdb + sdbops->info_len_off); cmd->data_len = cmd->bufflen; return 0; @@ -5835,8 +5858,8 @@ static int get_cdb_info_len_4(struct scst_cmd *cmd, static int get_cdb_info_none(struct scst_cmd *cmd, const struct scst_sdbops *sdbops) { - /* All supposed to be already zeroed, except data_len, which is -1 */ - EXTRACHECKS_BUG_ON(cmd->lba != 0); + cmd->lba = 0; + /* It supposed to be already zeroed */ EXTRACHECKS_BUG_ON(cmd->bufflen != 0); cmd->data_len = cmd->bufflen; return 0; diff --git a/scst/src/scst_priv.h b/scst/src/scst_priv.h index a554c20c1..a4ce96537 100644 --- a/scst/src/scst_priv.h +++ b/scst/src/scst_priv.h @@ -109,7 +109,7 @@ extern unsigned long scst_trace_flag; #define SCST_TGT_RETRY_TIMEOUT (3/2*HZ) -#define SCST_DEF_DATA_LEN -1 +#define SCST_DEF_LBA_DATA_LEN -1 extern struct mutex scst_mutex2; diff --git a/scst/src/scst_targ.c b/scst/src/scst_targ.c index 13e2bd2be..433c57451 100644 --- a/scst/src/scst_targ.c +++ b/scst/src/scst_targ.c @@ -881,14 +881,16 @@ set_res: out: #ifdef CONFIG_SCST_EXTRACHECKS /* - * At this point either data_len must be initialized, or cmd - * completed (with an error) and correct state set. + * At this point either both lba and data_len must be initialized to + * at least 0 for not data transfer commands, or cmd must be + * completed (with an error) and have correct state set. */ - if (unlikely((cmd->data_len == SCST_DEF_DATA_LEN)) && - (!cmd->completed || - (((cmd->state < SCST_CMD_STATE_PRE_XMIT_RESP) || - (cmd->state >= SCST_CMD_STATE_LAST_ACTIVE)) && - (cmd->state != SCST_CMD_STATE_PREPROCESSING_DONE)))) { + if (unlikely(((cmd->lba == SCST_DEF_LBA_DATA_LEN) || + (cmd->data_len == SCST_DEF_LBA_DATA_LEN)) && + (!cmd->completed || + (((cmd->state < SCST_CMD_STATE_PRE_XMIT_RESP) || + (cmd->state >= SCST_CMD_STATE_LAST_ACTIVE)) && + (cmd->state != SCST_CMD_STATE_PREPROCESSING_DONE))))) { PRINT_CRIT_ERROR("Not initialized data_len for going to " "execute command or bad state (cmd %p, data_len %d, " "completed %d, state %d)", cmd, cmd->data_len, @@ -2727,7 +2729,8 @@ static int scst_pre_exec_checks(struct scst_cmd *cmd) TRACE_ENTRY(); - EXTRACHECKS_BUG_ON(cmd->data_len == SCST_DEF_DATA_LEN); + EXTRACHECKS_BUG_ON(cmd->lba == SCST_DEF_LBA_DATA_LEN); + EXTRACHECKS_BUG_ON(cmd->data_len == SCST_DEF_LBA_DATA_LEN); rc = __scst_check_local_events(cmd, false); if (unlikely(rc != 0))