From 7c4b3c0d0c1b6bf24007530402e50026f617de05 Mon Sep 17 00:00:00 2001 From: Vladislav Bolkhovitin Date: Mon, 28 Apr 2014 21:38:22 +0000 Subject: [PATCH] Returned sense cleanups git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@5488 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- scst/src/dev_handlers/scst_vdisk.c | 29 ++++++++++++++--------------- scst/src/scst_lib.c | 3 +-- scst/src/scst_pres.c | 12 +++++------- scst/src/scst_targ.c | 23 +++++++++++------------ 4 files changed, 31 insertions(+), 36 deletions(-) diff --git a/scst/src/dev_handlers/scst_vdisk.c b/scst/src/dev_handlers/scst_vdisk.c index c83ded7f7..09b108811 100644 --- a/scst/src/dev_handlers/scst_vdisk.c +++ b/scst/src/dev_handlers/scst_vdisk.c @@ -1549,7 +1549,7 @@ static enum compl_status_e vdisk_exec_format_unit(struct vdisk_cmd_params *p) PRINT_ERROR("FORMAT UNIT: too small parameters list " "header %d (dev %s)", length, dev->virt_name); scst_set_cmd_error(cmd, - SCST_LOAD_SENSE(scst_sense_invalid_field_in_cdb)); + SCST_LOAD_SENSE(scst_sense_parameter_list_length_invalid)); goto out_put; } @@ -1569,8 +1569,8 @@ static enum compl_status_e vdisk_exec_format_unit(struct vdisk_cmd_params *p) PRINT_ERROR("FORMAT UNIT: too small long " "parameters list header %d (dev %s)", length, dev->virt_name); - scst_set_cmd_error(cmd, - SCST_LOAD_SENSE(scst_sense_invalid_field_in_cdb)); + scst_set_invalid_field_in_cdb(cmd, 1, + SCST_INVAL_FIELD_BIT_OFFS_VALID | 5); goto out_put; } if ((buf[3] & 0xF0) != 0) { @@ -3990,8 +3990,8 @@ static void vdisk_ctrl_m_pg_select(unsigned char *p, if (save && !vdev_saved_mode_pages_enabled) { TRACE(TRACE_MINOR|TRACE_SCSI, "MODE SELECT: saved control page " "not supported"); - scst_set_cmd_error(cmd, - SCST_LOAD_SENSE(scst_sense_invalid_field_in_cdb)); + scst_set_invalid_field_in_cdb(cmd, 2, + SCST_INVAL_FIELD_BIT_OFFS_VALID | 1); goto out; } @@ -4001,13 +4001,14 @@ static void vdisk_ctrl_m_pg_select(unsigned char *p, */ #if 0 /* Not implemented yet, see comment in struct scst_device */ - dev->tst = (p[2] >> 5) & 1; + dev->tst = (p[2] >> 5) & 7; + /* ToDo: check validity of the new value */ #else - if (dev->tst != ((p[2] >> 5) & 1)) { + if (dev->tst != ((p[2] >> 5) & 7)) { TRACE(TRACE_MINOR|TRACE_SCSI, "%s", "MODE SELECT: Changing of " "TST not supported"); - scst_set_cmd_error(cmd, - SCST_LOAD_SENSE(scst_sense_invalid_field_in_cdb)); + scst_set_invalid_field_in_parm_list(cmd, param_offset + 2, + SCST_INVAL_FIELD_BIT_OFFS_VALID | 5); goto out; } #endif @@ -4133,8 +4134,8 @@ static void vdisk_caching_m_pg_select(unsigned char *p, if (save && (!vdev_saved_mode_pages_enabled || virt_dev->nv_cache)) { TRACE(TRACE_MINOR|TRACE_SCSI, "MODE SELECT: saved cache page " "not supported"); - scst_set_cmd_error(cmd, - SCST_LOAD_SENSE(scst_sense_invalid_field_in_cdb)); + scst_set_invalid_field_in_cdb(cmd, 1, + SCST_INVAL_FIELD_BIT_OFFS_VALID | 0); goto out; } @@ -4287,8 +4288,7 @@ static enum compl_status_e vdisk_exec_read_capacity(struct vdisk_cmd_params *p) uint32_t lba = get_unaligned_be32(&cmd->cdb[2]); if (lba != 0) { TRACE_DBG("PMI zero and LBA not zero (cmd %p)", cmd); - scst_set_cmd_error(cmd, - SCST_LOAD_SENSE(scst_sense_invalid_field_in_cdb)); + scst_set_invalid_field_in_cdb(cmd, 2, 0); goto out; } } @@ -4348,8 +4348,7 @@ static enum compl_status_e vdisk_exec_read_capacity16(struct vdisk_cmd_params *p uint32_t lba = get_unaligned_be32(&cmd->cdb[2]); if (lba != 0) { TRACE_DBG("PMI zero and LBA not zero (cmd %p)", cmd); - scst_set_cmd_error(cmd, - SCST_LOAD_SENSE(scst_sense_invalid_field_in_cdb)); + scst_set_invalid_field_in_cdb(cmd, 2, 0); goto out; } } diff --git a/scst/src/scst_lib.c b/scst/src/scst_lib.c index fcc3a978b..6ddf71540 100644 --- a/scst/src/scst_lib.c +++ b/scst/src/scst_lib.c @@ -9326,8 +9326,7 @@ static int scst_parse_unmap_descriptors(struct scst_cmd *cmd) ((descriptor_len % 16) != 0))) { PRINT_ERROR("Bad descriptor length: %d < %d - 8", descriptor_len, total_len); - scst_set_cmd_error(cmd, - SCST_LOAD_SENSE(scst_sense_invalid_field_in_parm_list)); + scst_set_invalid_field_in_parm_list(cmd, 2, 0); goto out_abn_put; } diff --git a/scst/src/scst_pres.c b/scst/src/scst_pres.c index ee0727184..c4cc61fa7 100644 --- a/scst/src/scst_pres.c +++ b/scst/src/scst_pres.c @@ -1580,8 +1580,8 @@ void scst_pr_register(struct scst_cmd *cmd, uint8_t *buffer, int buffer_size) } if (spec_i_pt) { TRACE_PR("%s", "spec_i_pt must be zero in this case"); - scst_set_cmd_error(cmd, SCST_LOAD_SENSE( - scst_sense_invalid_field_in_cdb)); + scst_set_invalid_field_in_parm_list(cmd, 20, + SCST_INVAL_FIELD_BIT_OFFS_VALID | 3); goto out; } if (action_key == 0) { @@ -1721,8 +1721,7 @@ void scst_pr_register_and_move(struct scst_cmd *cmd, uint8_t *buffer, if (tid_buffer_size < 24) { TRACE_PR("%s", "Transport id buffer too small"); - scst_set_cmd_error(cmd, - SCST_LOAD_SENSE(scst_sense_invalid_field_in_parm_list)); + scst_set_invalid_field_in_parm_list(cmd, 20, 0); goto out; } @@ -1751,9 +1750,8 @@ void scst_pr_register_and_move(struct scst_cmd *cmd, uint8_t *buffer, */ if (!scst_pr_is_holder(dev, reg)) { TRACE_PR("Registrant %s/%d (%p) is not a holder (tgt_dev %p)", - debug_transport_id_to_initiator_name( - reg->transport_id), reg->rel_tgt_id, - reg, tgt_dev); + debug_transport_id_to_initiator_name(reg->transport_id), + reg->rel_tgt_id, reg, tgt_dev); scst_set_cmd_error_status(cmd, SAM_STAT_RESERVATION_CONFLICT); goto out; } diff --git a/scst/src/scst_targ.c b/scst/src/scst_targ.c index 402a9de3d..3011e43eb 100644 --- a/scst/src/scst_targ.c +++ b/scst/src/scst_targ.c @@ -1853,15 +1853,18 @@ static int scst_report_luns_local(struct scst_cmd *cmd) if ((cmd->cdb[2] != 0) && (cmd->cdb[2] != 2)) { PRINT_ERROR("Unsupported SELECT REPORT value %x in REPORT " "LUNS command", cmd->cdb[2]); - goto out_err; + scst_set_invalid_field_in_cdb(cmd, 2, 0); + goto out_compl; } buffer_size = scst_get_buf_full_sense(cmd, &buffer); if (unlikely(buffer_size <= 0)) goto out_compl; - if (buffer_size < 16) + if (buffer_size < 16) { + scst_set_invalid_field_in_cdb(cmd, 6, 0); goto out_put_err; + } memset(buffer, 0, buffer_size); offs = 8; @@ -1939,10 +1942,6 @@ out_compl: out_put_err: scst_put_buf_full(cmd, buffer); - -out_err: - scst_set_cmd_error(cmd, - SCST_LOAD_SENSE(scst_sense_invalid_field_in_cdb)); goto out_compl; } @@ -2642,8 +2641,8 @@ static int scst_persistent_reserve_out_local(struct scst_cmd *cmd) if ((action != PR_REGISTER) && (action != PR_REGISTER_AND_IGNORE) && (action != PR_CLEAR) && (cmd->cdb[2] >> 4) != SCOPE_LU) { TRACE_PR("Scope must be SCOPE_LU for action %x", action); - scst_set_cmd_error(cmd, - SCST_LOAD_SENSE(scst_sense_invalid_field_in_cdb)); + scst_set_invalid_field_in_cdb(cmd, 2, + SCST_INVAL_FIELD_BIT_OFFS_VALID | 4); goto out_unlock; } @@ -2651,8 +2650,8 @@ static int scst_persistent_reserve_out_local(struct scst_cmd *cmd) if ((action != PR_REGISTER) && (action != PR_REGISTER_AND_MOVE) && ((buffer[20] >> 3) & 0x01)) { TRACE_PR("SPEC_I_PT must be zero for action %x", action); - scst_set_cmd_error(cmd, SCST_LOAD_SENSE( - scst_sense_invalid_field_in_cdb)); + scst_set_invalid_field_in_parm_list(cmd, 20, + SCST_INVAL_FIELD_BIT_OFFS_VALID | 3); goto out_unlock; } @@ -2660,8 +2659,8 @@ static int scst_persistent_reserve_out_local(struct scst_cmd *cmd) if ((action != PR_REGISTER) && (action != PR_REGISTER_AND_IGNORE) && (action != PR_REGISTER_AND_MOVE) && ((buffer[20] >> 2) & 0x01)) { TRACE_PR("ALL_TG_PT must be zero for action %x", action); - scst_set_cmd_error(cmd, - SCST_LOAD_SENSE(scst_sense_invalid_field_in_cdb)); + scst_set_invalid_field_in_parm_list(cmd, 20, + SCST_INVAL_FIELD_BIT_OFFS_VALID | 2); goto out_unlock; }