From 45e50e12b0cdeca13aedf68c18d5429ab992b12e Mon Sep 17 00:00:00 2001 From: Vladislav Bolkhovitin Date: Fri, 20 Jul 2012 21:58:45 +0000 Subject: [PATCH] Zero size descriptor are possible, so we have to add cmd_data_descriptors_cnt to track their count. + small cleanup git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@4412 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- scst/include/scst.h | 4 ++-- scst/src/dev_handlers/scst_vdisk.c | 4 ++-- scst/src/scst_lib.c | 7 +++++-- scst/src/scst_priv.h | 2 ++ scst/src/scst_targ.c | 4 ++-- 5 files changed, 13 insertions(+), 8 deletions(-) diff --git a/scst/include/scst.h b/scst/include/scst.h index 49a8e9667..716f6c768 100644 --- a/scst/include/scst.h +++ b/scst/include/scst.h @@ -2122,10 +2122,10 @@ struct scst_cmd { /* * List of parsed data descriptors for commands operating with - * several lba and data_len pairs, like UNMAP, finished with zero - * length entry. + * several lba and data_len pairs, like UNMAP, and its size in elements. */ void *cmd_data_descriptors; + int cmd_data_descriptors_cnt; #ifdef CONFIG_SCST_MEASURE_LATENCY /* diff --git a/scst/src/dev_handlers/scst_vdisk.c b/scst/src/dev_handlers/scst_vdisk.c index d38f93a70..20d953af8 100644 --- a/scst/src/dev_handlers/scst_vdisk.c +++ b/scst/src/dev_handlers/scst_vdisk.c @@ -2019,7 +2019,7 @@ static enum compl_status_e vdisk_exec_unmap(struct vdisk_cmd_params *p) struct scst_cmd *cmd = p->cmd; struct scst_vdisk_dev *virt_dev = cmd->dev->dh_priv; struct scst_data_descriptor *pd = cmd->cmd_data_descriptors; - int i; + int i, cnt = cmd->cmd_data_descriptors_cnt; TRACE_ENTRY(); @@ -2040,7 +2040,7 @@ static enum compl_status_e vdisk_exec_unmap(struct vdisk_cmd_params *p) if (pd == NULL) goto out; - for (i = 0; pd[i].sdd_len != 0; i++) { + for (i = 0; i < cnt; i++) { int rc; if (unlikely(test_bit(SCST_CMD_ABORTED, &cmd->cmd_flags))) { diff --git a/scst/src/scst_lib.c b/scst/src/scst_lib.c index 6a613b6e5..4e954e187 100644 --- a/scst/src/scst_lib.c +++ b/scst/src/scst_lib.c @@ -1971,7 +1971,7 @@ out: } EXPORT_SYMBOL(scst_check_convert_sense); -static int scst_set_cmd_error_sense(struct scst_cmd *cmd, uint8_t *sense, +int scst_set_cmd_error_sense(struct scst_cmd *cmd, uint8_t *sense, unsigned int len) { int res; @@ -8564,6 +8564,7 @@ static bool scst_parse_unmap_descriptors(struct scst_cmd *cmd) TRACE_ENTRY(); EXTRACHECKS_BUG_ON(cmd->cmd_data_descriptors != NULL); + EXTRACHECKS_BUG_ON(cmd->cmd_data_descriptors_cnt != 0); length = scst_get_buf_full_sense(cmd, &address); if (unlikely(length <= 0)) { @@ -8596,7 +8597,7 @@ static bool scst_parse_unmap_descriptors(struct scst_cmd *cmd) if (cnt == 0) goto out_put; - pd = kzalloc(sizeof(*pd) * (cnt+1), GFP_KERNEL); + pd = kzalloc(sizeof(*pd) * cnt, GFP_KERNEL); if (pd == NULL) { PRINT_ERROR("Unable to kmalloc UNMAP %d descriptors", cnt+1); scst_set_busy(cmd); @@ -8618,6 +8619,7 @@ static bool scst_parse_unmap_descriptors(struct scst_cmd *cmd) } cmd->cmd_data_descriptors = pd; + cmd->cmd_data_descriptors_cnt = cnt; out_put: scst_put_buf_full(cmd, address); @@ -8640,6 +8642,7 @@ static void scst_free_unmap_descriptors(struct scst_cmd *cmd) TRACE_ENTRY(); kfree(cmd->cmd_data_descriptors); + cmd->cmd_data_descriptors = NULL; TRACE_EXIT(); return; diff --git a/scst/src/scst_priv.h b/scst/src/scst_priv.h index a02ea7de9..15ef072c9 100644 --- a/scst/src/scst_priv.h +++ b/scst/src/scst_priv.h @@ -340,6 +340,8 @@ static inline bool scst_acg_sess_is_empty(struct scst_acg *acg) int scst_prepare_request_sense(struct scst_cmd *orig_cmd); int scst_finish_internal_cmd(struct scst_cmd *cmd); +int scst_set_cmd_error_sense(struct scst_cmd *cmd, uint8_t *sense, + unsigned int len); void scst_store_sense(struct scst_cmd *cmd); int scst_assign_dev_handler(struct scst_device *dev, diff --git a/scst/src/scst_targ.c b/scst/src/scst_targ.c index 3bb04497b..f0630b30f 100644 --- a/scst/src/scst_targ.c +++ b/scst/src/scst_targ.c @@ -628,7 +628,7 @@ static int scst_parse_cmd(struct scst_cmd *cmd) cmd->data_len = cmd->bufflen; cmd->out_bufflen = cmd->expected_out_transfer_len; } else { - PRINT_ERROR("Unknown opcode 0x%02x for %s and " + PRINT_WARNING("Unknown opcode 0x%02x for %s and " "target %s not supplied expected values", cmd->cdb[0], devt->name, cmd->tgtt->name); scst_set_cmd_error(cmd, @@ -636,7 +636,7 @@ static int scst_parse_cmd(struct scst_cmd *cmd) goto out_done; } #else - PRINT_ERROR("Refusing unknown opcode %x", cmd->cdb[0]); + PRINT_WARNING("Refusing unknown opcode %x", cmd->cdb[0]); scst_set_cmd_error(cmd, SCST_LOAD_SENSE(scst_sense_invalid_opcode)); goto out_done;