Patch from Terry Greeniaus:
authorvlnb <vlnb@d57e44dd-8a1f-0410-8b47-8ef2f437770f>
Wed, 18 Jul 2007 08:41:44 +0000 (08:41 +0000)
committervlnb <vlnb@d57e44dd-8a1f-0410-8b47-8ef2f437770f>
Wed, 18 Jul 2007 08:41:44 +0000 (08:41 +0000)
We use the 64-bit tag field in the SRP commands to store information allowing us to track each command.  However, SCST only saves/uses 32-bits out of this 64-bit field.  This causes our code to fail when we get a response SRP command that doesn't match any tags we used.

I have updated SCST to work with our product by changing it to save all 64-bits of the tag.

git-svn-id: https://scst.svn.sourceforge.net/svnroot/scst/trunk@150 d57e44dd-8a1f-0410-8b47-8ef2f437770f

scst/README
scst/include/scsi_tgt.h
scst/src/dev_handlers/scst_vdisk.c
scst/src/scst_lib.c
scst/src/scst_priv.h
scst/src/scst_targ.c

index 9917ca1..e60bd8f 100644 (file)
@@ -637,4 +637,6 @@ Thanks to:
 
  * Nathan Bullock <nbullock@yottayotta.com> for fixes.
 
+ * Terry Greeniaus <tgreeniaus@yottayotta.com> for fixes.
+
 Vladislav Bolkhovitin <vst@vlnb.net>, http://scst.sourceforge.net
index 53aa7cb..b52c176 100644 (file)
@@ -1049,7 +1049,7 @@ struct scst_cmd
         * Used to found the cmd by scst_find_cmd_by_tag(). Set by the
         * target driver on the cmd's initialization time
         */
-       uint32_t tag;
+       uint64_t tag;
 
        /* CDB and its len */
        uint8_t cdb[SCST_MAX_CDB_SIZE];
@@ -1149,7 +1149,7 @@ struct scst_mgmt_cmd
 
        lun_t lun;      /* LUN for this mgmt cmd */
        /* or */
-       uint32_t tag;   /* tag of the corresponding cmd */
+       uint64_t tag;   /* tag of the corresponding cmd */
 
        /* corresponding cmd (to be aborted, found by tag) */
        struct scst_cmd *cmd_to_abort;
@@ -1623,7 +1623,7 @@ void scst_tgt_cmd_done(struct scst_cmd *cmd);
  * Must not been called in parallel with scst_unregister_session() for the 
  * same sess. Returns 0 for success, error code otherwise.
  */
-int scst_rx_mgmt_fn_tag(struct scst_session *sess, int fn, uint32_t tag,
+int scst_rx_mgmt_fn_tag(struct scst_session *sess, int fn, uint64_t tag,
                       int atomic, void *tgt_priv);
 
 /* 
@@ -1667,7 +1667,7 @@ void scst_set_busy(struct scst_cmd *cmd);
  * that previously set by scst_cmd_set_tag(). 
  * Returns the command on success or NULL otherwise
  */
-struct scst_cmd *scst_find_cmd_by_tag(struct scst_session *sess, uint32_t tag);
+struct scst_cmd *scst_find_cmd_by_tag(struct scst_session *sess, uint64_t tag);
 
 /* 
  * Finds a command based on user supplied data and comparision
@@ -1879,12 +1879,12 @@ static inline int scst_cmd_get_sense_buffer_len(struct scst_cmd *cmd)
 /*
  * Get/Set functions for cmd's target SN
  */
-static inline uint32_t scst_cmd_get_tag(struct scst_cmd *cmd)
+static inline uint64_t scst_cmd_get_tag(struct scst_cmd *cmd)
 {
        return cmd->tag;
 }
 
-static inline void scst_cmd_set_tag(struct scst_cmd *cmd, uint32_t tag)
+static inline void scst_cmd_set_tag(struct scst_cmd *cmd, uint64_t tag)
 {
        cmd->tag = tag;
 }
index 81d5940..168237b 100644 (file)
@@ -657,7 +657,7 @@ static int vdisk_do_job(struct scst_cmd *cmd)
 
        if (unlikely(test_bit(SCST_CMD_ABORTED, &cmd->cmd_flags))) {
                TRACE_MGMT_DBG("Flag ABORTED set for "
-                     "cmd %p (tag %d), skipping", cmd, cmd->tag);
+                     "cmd %p (tag %lld), skipping", cmd, cmd->tag);
                goto done_uncompl;
        }
 
index c6ab178..df6c319 100644 (file)
@@ -126,7 +126,7 @@ void scst_set_resp_data_len(struct scst_cmd *cmd, int resp_data_len)
                l += cmd->sg[i].length;
                if (l >= resp_data_len) {
                        int left = resp_data_len - (l - cmd->sg[i].length);
-                       TRACE(TRACE_SG|TRACE_MEMORY, "cmd %p (tag %d), "
+                       TRACE(TRACE_SG|TRACE_MEMORY, "cmd %p (tag %lld), "
                                "resp_data_len %d, i %d, cmd->sg[i].length %d, "
                                "left %d", cmd, cmd->tag, resp_data_len, i,
                                cmd->sg[i].length, left);
@@ -1267,7 +1267,7 @@ void scst_free_cmd(struct scst_cmd *cmd)
 #endif
 
                if (unlikely(cmd->out_of_sn)) {
-                       TRACE_SN("Out of SN cmd %p (tag %d, sn %ld), "
+                       TRACE_SN("Out of SN cmd %p (tag %lld, sn %ld), "
                                "destroy=%d", cmd, cmd->tag, cmd->sn, destroy);
                        destroy = test_and_set_bit(SCST_CMD_CAN_BE_DESTROYED,
                                        &cmd->cmd_flags);
@@ -2536,7 +2536,7 @@ restart:
                         * !! sn_slot and sn_cmd_list_entry, could be   !!
                         * !! already destroyed                         !!
                         */
-                       TRACE_SN("cmd %p (tag %d) with skipped sn %ld found",
+                       TRACE_SN("cmd %p (tag %lld) with skipped sn %ld found",
                                cmd, cmd->tag, cmd->sn);
                        tgt_dev->def_cmd_count--;
                        list_del(&cmd->sn_cmd_list_entry);
@@ -2647,7 +2647,7 @@ int scst_inc_on_dev_cmd(struct scst_cmd *cmd)
        if (dev->block_count > 0) {
                scst_dec_on_dev_cmd(cmd, 0);
                TRACE_MGMT_DBG("Delaying cmd %p due to blocking or serializing"
-                     "(tag %d, dev %p)", cmd, cmd->tag, dev);
+                     "(tag %lld, dev %p)", cmd, cmd->tag, dev);
                list_add_tail(&cmd->blocked_cmd_list_entry,
                              &dev->blocked_cmd_list);
                res = 1;
@@ -2667,7 +2667,7 @@ repeat:
                if (dev->block_count > 0) {
                        scst_dec_on_dev_cmd(cmd, 0);
                        TRACE_MGMT_DBG("Delaying cmd %p due to blocking or "
-                               "serializing (tag %d, dev %p)", cmd,
+                               "serializing (tag %lld, dev %p)", cmd,
                                cmd->tag, dev);
                        list_add_tail(&cmd->blocked_cmd_list_entry,
                                      &dev->blocked_cmd_list);
@@ -2684,7 +2684,7 @@ repeat:
                spin_lock_bh(&dev->dev_lock);
                barrier(); /* to reread block_count */
                if (dev->block_count == 0) {
-                       TRACE_MGMT_DBG("cmd %p (tag %d), blocking further "
+                       TRACE_MGMT_DBG("cmd %p (tag %lld), blocking further "
                                "cmds due to serializing (dev %p)", cmd,
                                cmd->tag, dev);
                        __scst_block_dev(dev);
@@ -2960,7 +2960,7 @@ static void tm_dbg_delay_cmd(struct scst_cmd *cmd)
        case TM_DBG_STATE_ABORT:
                if (tm_dbg_delayed_cmds_count == 0) {
                        unsigned long d = 58*HZ + (scst_random() % (4*HZ));
-                       TRACE_MGMT_DBG("STATE ABORT: delaying cmd %p (tag %d) "
+                       TRACE_MGMT_DBG("STATE ABORT: delaying cmd %p (tag %lld) "
                                "for %ld.%ld seconds (%ld HZ), "
                                "tm_dbg_on_state_passes=%d", cmd, cmd->tag,
                                d/HZ, (d%HZ)*100/HZ, d, tm_dbg_on_state_passes);
@@ -2970,7 +2970,7 @@ static void tm_dbg_delay_cmd(struct scst_cmd *cmd)
 #endif
                } else {
                        TRACE_MGMT_DBG("Delaying another timed cmd %p "
-                               "(tag %d), delayed_cmds_count=%d, "
+                               "(tag %lld), delayed_cmds_count=%d, "
                                "tm_dbg_on_state_passes=%d", cmd, cmd->tag,
                                tm_dbg_delayed_cmds_count,
                                tm_dbg_on_state_passes);
@@ -2982,7 +2982,7 @@ static void tm_dbg_delay_cmd(struct scst_cmd *cmd)
        case TM_DBG_STATE_RESET:
        case TM_DBG_STATE_OFFLINE:
                TRACE_MGMT_DBG("STATE RESET/OFFLINE: delaying cmd %p "
-                       "(tag %d), delayed_cmds_count=%d, "
+                       "(tag %lld), delayed_cmds_count=%d, "
                        "tm_dbg_on_state_passes=%d", cmd, cmd->tag,
                        tm_dbg_delayed_cmds_count, tm_dbg_on_state_passes);
                tm_dbg_flags.tm_dbg_blocked = 1;
@@ -3008,7 +3008,7 @@ void tm_dbg_check_released_cmds(void)
                spin_lock_irq(&scst_tm_dbg_lock);
                list_for_each_entry_safe_reverse(cmd, tc, 
                                &tm_dbg_delayed_cmd_list, cmd_list_entry) {
-                       TRACE_MGMT_DBG("Releasing timed cmd %p (tag %d), "
+                       TRACE_MGMT_DBG("Releasing timed cmd %p (tag %lld), "
                                "delayed_cmds_count=%d", cmd, cmd->tag,
                                tm_dbg_delayed_cmds_count);
                        spin_lock(&cmd->cmd_lists->cmd_list_lock);
@@ -3070,7 +3070,7 @@ int tm_dbg_check_cmd(struct scst_cmd *cmd)
 
        if (cmd->tm_dbg_delayed) {
                spin_lock_irqsave(&scst_tm_dbg_lock, flags);
-               TRACE_MGMT_DBG("Processing delayed cmd %p (tag %d), "
+               TRACE_MGMT_DBG("Processing delayed cmd %p (tag %lld), "
                        "delayed_cmds_count=%d", cmd, cmd->tag,
                        tm_dbg_delayed_cmds_count);
 
@@ -3108,7 +3108,7 @@ void tm_dbg_release_cmd(struct scst_cmd *cmd)
                                cmd_list_entry) {
                if (c == cmd) {
                        TRACE_MGMT_DBG("Abort request for "
-                               "delayed cmd %p (tag=%d), moving it to "
+                               "delayed cmd %p (tag=%lld), moving it to "
                                "active cmd list (delayed_cmds_count=%d)",
                                c, c->tag, tm_dbg_delayed_cmds_count);
                        spin_lock(&cmd->cmd_lists->cmd_list_lock);
index 6491890..a049d27 100644 (file)
@@ -345,7 +345,7 @@ void scst_scsi_op_list_init(void);
 lun_t scst_unpack_lun(const uint8_t *lun, int len);
 
 struct scst_cmd *__scst_find_cmd_by_tag(struct scst_session *sess, 
-       uint32_t tag);
+       uint64_t tag);
 
 struct scst_mgmt_cmd *scst_alloc_mgmt_cmd(int gfp_mask);
 void scst_free_mgmt_cmd(struct scst_mgmt_cmd *mcmd);
@@ -460,7 +460,7 @@ static inline int scst_dec_on_dev_cmd(struct scst_cmd *cmd, int defer)
 {
        int cmd_blocking = cmd->blocking;
        if (cmd_blocking) {
-               TRACE_MGMT_DBG("cmd %p (tag %d): unblocking dev %p", cmd,
+               TRACE_MGMT_DBG("cmd %p (tag %lld): unblocking dev %p", cmd,
                        cmd->tag, cmd->dev);
                cmd->blocking = 0;
        }
index d17b841..7e2524f 100644 (file)
@@ -165,7 +165,7 @@ void scst_cmd_init_done(struct scst_cmd *cmd, int pref_context)
        TRACE_ENTRY();
 
        TRACE_DBG("Preferred context: %d (cmd %p)", pref_context, cmd);
-       TRACE(TRACE_SCSI, "tag=%d, lun=%Ld, CDB len=%d", cmd->tag, 
+       TRACE(TRACE_SCSI, "tag=%lld, lun=%Ld, CDB len=%d", cmd->tag, 
                (uint64_t)cmd->lun, cmd->cdb_len);
        TRACE_BUFF_FLAG(TRACE_SCSI|TRACE_RECV_BOT, "Recieving CDB",
                cmd->cdb, cmd->cdb_len);
@@ -700,7 +700,7 @@ void scst_restart_cmd(struct scst_cmd *cmd, int status, int pref_context)
        TRACE_ENTRY();
 
        TRACE_DBG("Preferred context: %d", pref_context);
-       TRACE_DBG("tag=%d, status=%#x", scst_cmd_get_tag(cmd), status);
+       TRACE_DBG("tag=%lld, status=%#x", scst_cmd_get_tag(cmd), status);
 
 #ifdef EXTRACHECKS
        if (in_irq() && ((pref_context == SCST_CONTEXT_DIRECT) ||
@@ -950,7 +950,7 @@ void scst_rx_data(struct scst_cmd *cmd, int status, int pref_context)
        TRACE_ENTRY();
 
        TRACE_DBG("Preferred context: %d", pref_context);
-       TRACE(TRACE_SCSI, "tag=%d status=%#x", scst_cmd_get_tag(cmd), status);
+       TRACE(TRACE_SCSI, "tag=%lld status=%#x", scst_cmd_get_tag(cmd), status);
 
 #ifdef EXTRACHECKS
        if (in_irq() && ((pref_context == SCST_CONTEXT_DIRECT) ||
@@ -1443,7 +1443,7 @@ static int scst_release_local(struct scst_cmd *cmd)
 
        scst_block_dev(dev, 1);
        cmd->blocking = 1;
-       TRACE_MGMT_DBG("Blocking cmd %p (tag %d)", cmd, cmd->tag);
+       TRACE_MGMT_DBG("Blocking cmd %p (tag %lld)", cmd, cmd->tag);
 
        spin_lock_bh(&dev->dev_lock);
 
@@ -1865,7 +1865,7 @@ static int scst_send_to_midlev(struct scst_cmd *cmd)
                        int cmd_blocking = scst_dec_on_dev_cmd(cmd, 1);
                        if (unlikely(test_bit(SCST_CMD_ABORTED, &cmd->cmd_flags))) {
                                /* Necessary to allow aborting out of sn cmds */
-                               TRACE_MGMT_DBG("Aborting out of sn cmd %p (tag %d)",
+                               TRACE_MGMT_DBG("Aborting out of sn cmd %p (tag %lld)",
                                        cmd, cmd->tag);
                                tgt_dev->def_cmd_count--;
                                cmd->state = SCST_CMD_STATE_DEV_DONE;
@@ -1995,7 +1995,7 @@ static int scst_check_sense(struct scst_cmd *cmd)
                                                        "Double UA detected");
                                                /* Do retry */
                                                TRACE(TRACE_MGMT, "Retrying cmd %p "
-                                                       "(tag %d)", cmd, cmd->tag);
+                                                       "(tag %lld)", cmd, cmd->tag);
                                                cmd->status = 0;
                                                cmd->msg_status = 0;
                                                cmd->host_status = DID_OK;
@@ -2330,13 +2330,13 @@ static int scst_xmit_response(struct scst_cmd *cmd)
        if (unlikely(test_bit(SCST_CMD_ABORTED, &cmd->cmd_flags))) {
                if (test_bit(SCST_CMD_ABORTED_OTHER, &cmd->cmd_flags)) {
                        TRACE_MGMT_DBG("Flag ABORTED OTHER set for cmd %p "
-                               "(tag %d), returning TASK ABORTED", cmd, cmd->tag);
+                               "(tag %lld), returning TASK ABORTED", cmd, cmd->tag);
                        scst_set_cmd_error_status(cmd, SAM_STAT_TASK_ABORTED);
                }
        }
 
        if (unlikely(test_bit(SCST_CMD_NO_RESP, &cmd->cmd_flags))) {
-               TRACE_MGMT_DBG("Flag NO_RESP set for cmd %p (tag %d), skipping",
+               TRACE_MGMT_DBG("Flag NO_RESP set for cmd %p (tag %lld), skipping",
                        cmd, cmd->tag);
                cmd->state = SCST_CMD_STATE_FINISHED;
                res = SCST_CMD_STATE_RES_CONT_SAME;
@@ -2350,7 +2350,7 @@ static int scst_xmit_response(struct scst_cmd *cmd)
                        res = SCST_CMD_STATE_RES_NEED_THREAD;
                        goto out;
                }
-               TRACE_MGMT_DBG("Delaying cmd %p (tag %d) for 1 second",
+               TRACE_MGMT_DBG("Delaying cmd %p (tag %lld) for 1 second",
                        cmd, cmd->tag);
                schedule_timeout_uninterruptible(HZ);
        }
@@ -2703,7 +2703,7 @@ restart:
                                goto restart;
                        }
                } else {
-                       TRACE_MGMT_DBG("Aborting not inited cmd %p (tag %d)",
+                       TRACE_MGMT_DBG("Aborting not inited cmd %p (tag %lld)",
                                cmd, cmd->tag);
                        cmd->state = SCST_CMD_STATE_XMIT_RESP;
                }
@@ -2823,7 +2823,7 @@ void scst_process_active_cmd(struct scst_cmd *cmd, int context)
                case SCST_CMD_STATE_SEND_TO_MIDLEV:
                        if (tm_dbg_check_cmd(cmd) != 0) {
                                res = SCST_CMD_STATE_RES_CONT_NEXT;
-                               TRACE_MGMT_DBG("Skipping cmd %p (tag %d), "
+                               TRACE_MGMT_DBG("Skipping cmd %p (tag %lld), "
                                        "because of TM DBG delay", cmd,
                                        cmd->tag);
                                break;
@@ -3051,7 +3051,7 @@ void scst_complete_cmd_mgmt(struct scst_cmd *cmd, struct scst_mgmt_cmd *mcmd)
 
        spin_lock_irq(&scst_mcmd_lock);
 
-       TRACE_MGMT_DBG("cmd %p completed (tag %d, mcmd %p, "
+       TRACE_MGMT_DBG("cmd %p completed (tag %lld, mcmd %p, "
                "mcmd->cmd_wait_count %d)", cmd, cmd->tag, mcmd,
                mcmd->cmd_wait_count);
 
@@ -3129,7 +3129,7 @@ void scst_abort_cmd(struct scst_cmd *cmd, struct scst_mgmt_cmd *mcmd,
 {
        TRACE_ENTRY();
 
-       TRACE(TRACE_MGMT, "Aborting cmd %p (tag %d)", cmd, cmd->tag);
+       TRACE(TRACE_MGMT, "Aborting cmd %p (tag %lld)", cmd, cmd->tag);
 
        if (other_ini) {
                set_bit(SCST_CMD_ABORTED_OTHER, &cmd->cmd_flags);
@@ -3161,12 +3161,12 @@ void scst_abort_cmd(struct scst_cmd *cmd, struct scst_mgmt_cmd *mcmd,
                 * we must wait here to be sure that we won't receive
                 * double commands with the same tag.
                 */
-               TRACE(TRACE_MGMT, "cmd %p (tag %d) being executed/"
+               TRACE(TRACE_MGMT, "cmd %p (tag %lld) being executed/"
                        "xmitted (state %d), deferring ABORT...", cmd,
                        cmd->tag, cmd->state);
 #ifdef EXTRACHECKS
                if (cmd->mgmt_cmnd) {
-                       printk(KERN_ALERT "cmd %p (tag %d, state %d) "
+                       printk(KERN_ALERT "cmd %p (tag %lld, state %d) "
                                "has non-NULL mgmt_cmnd %p!!! Current "
                                "mcmd %p\n", cmd, cmd->tag, cmd->state,
                                cmd->mgmt_cmnd, mcmd);
@@ -3357,7 +3357,7 @@ static int scst_mgmt_cmd_init(struct scst_mgmt_cmd *mcmd)
                cmd = __scst_find_cmd_by_tag(sess, mcmd->tag);
                if (cmd == NULL) {
                        TRACE(TRACE_MGMT, "ABORT TASK failed: command for "
-                               "tag %d not found", mcmd->tag);
+                               "tag %lld not found", mcmd->tag);
                        mcmd->status = SCST_MGMT_STATUS_TASK_NOT_EXIST;
                        mcmd->state = SCST_MGMT_CMD_STATE_DONE;
                        spin_unlock_irq(&sess->sess_list_lock);
@@ -3365,7 +3365,7 @@ static int scst_mgmt_cmd_init(struct scst_mgmt_cmd *mcmd)
                }
                scst_cmd_get(cmd);
                spin_unlock_irq(&sess->sess_list_lock);
-               TRACE(TRACE_MGMT, "Cmd %p for tag %d (sn %ld) found, "
+               TRACE(TRACE_MGMT, "Cmd %p for tag %lld (sn %ld) found, "
                        "aborting it", cmd, mcmd->tag, cmd->sn);
                mcmd->cmd_to_abort = cmd;
                scst_abort_cmd(cmd, mcmd, 0, 1);
@@ -4021,7 +4021,7 @@ out_free:
  * Must not been called in parallel with scst_unregister_session() for the 
  * same sess
  */
-int scst_rx_mgmt_fn_tag(struct scst_session *sess, int fn, uint32_t tag,
+int scst_rx_mgmt_fn_tag(struct scst_session *sess, int fn, uint64_t tag,
                       int atomic, void *tgt_priv)
 {
        int res = -EFAULT;
@@ -4041,7 +4041,7 @@ int scst_rx_mgmt_fn_tag(struct scst_session *sess, int fn, uint32_t tag,
 
        mcmd->tag = tag;
 
-       TRACE(TRACE_MGMT, "sess=%p, tag=%d", sess, mcmd->tag);
+       TRACE(TRACE_MGMT, "sess=%p, tag=%lld", sess, mcmd->tag);
 
        if (scst_post_rx_mgmt_cmd(sess, mcmd) != 0)
                goto out_free;
@@ -4411,7 +4411,7 @@ restart:
 }
 
 /* Called under sess->sess_list_lock */
-struct scst_cmd *__scst_find_cmd_by_tag(struct scst_session *sess, uint32_t tag)
+struct scst_cmd *__scst_find_cmd_by_tag(struct scst_session *sess, uint64_t tag)
 {
        struct scst_cmd *cmd = NULL;
 
@@ -4419,7 +4419,7 @@ struct scst_cmd *__scst_find_cmd_by_tag(struct scst_session *sess, uint32_t tag)
 
        /* ToDo: hash list */
 
-       TRACE_DBG("%s (sess=%p, tag=%d)", "Searching in search cmd list",
+       TRACE_DBG("%s (sess=%p, tag=%lld)", "Searching in search cmd list",
                sess, tag);
        list_for_each_entry(cmd, &sess->search_cmd_list, 
                        search_cmd_list_entry) {
@@ -4464,7 +4464,7 @@ out:
 }
 
 struct scst_cmd *scst_find_cmd_by_tag(struct scst_session *sess,
-       uint32_t tag)
+       uint64_t tag)
 {
        unsigned long flags;
        struct scst_cmd *cmd;