Small cleanup: there's no need to have SN's long + test on SNs overflow added
authorvlnb <vlnb@d57e44dd-8a1f-0410-8b47-8ef2f437770f>
Thu, 17 Dec 2009 12:57:24 +0000 (12:57 +0000)
committervlnb <vlnb@d57e44dd-8a1f-0410-8b47-8ef2f437770f>
Thu, 17 Dec 2009 12:57:24 +0000 (12:57 +0000)
git-svn-id: https://scst.svn.sourceforge.net/svnroot/scst/trunk@1406 d57e44dd-8a1f-0410-8b47-8ef2f437770f

scst/include/scst.h
scst/src/scst_lib.c
scst/src/scst_targ.c

index 6c41af0..5cbe33b 100644 (file)
@@ -1479,7 +1479,7 @@ struct scst_cmd {
        struct list_head sn_cmd_list_entry;
 
        /* Cmd's serial number, used to execute cmd's in order of arrival */
-       unsigned long sn;
+       unsigned int sn;
 
        /* The corresponding sn_slot in tgt_dev->sn_slots */
        atomic_t *sn_slot;
@@ -1865,8 +1865,8 @@ struct scst_tgt_dev {
         */
        int def_cmd_count;
        spinlock_t sn_lock;
-       unsigned long expected_sn;
-       unsigned long curr_sn;
+       unsigned int expected_sn;
+       unsigned int curr_sn;
        int hq_cmd_count;
        struct list_head deferred_cmd_list;
        struct list_head skipped_sn_list;
index 33425ed..de30092 100644 (file)
@@ -1567,7 +1567,8 @@ static struct scst_tgt_dev *scst_alloc_add_tgt_dev(struct scst_session *sess,
        spin_lock_init(&tgt_dev->sn_lock);
        INIT_LIST_HEAD(&tgt_dev->deferred_cmd_list);
        INIT_LIST_HEAD(&tgt_dev->skipped_sn_list);
-       tgt_dev->expected_sn = 1;
+       tgt_dev->curr_sn = (typeof(tgt_dev->curr_sn)) -300;
+       tgt_dev->expected_sn = tgt_dev->curr_sn + 1;
        tgt_dev->num_free_sn_slots = ARRAY_SIZE(tgt_dev->sn_slots)-1;
        tgt_dev->cur_sn_slot = &tgt_dev->sn_slots[0];
        for (i = 0; i < (int)ARRAY_SIZE(tgt_dev->sn_slots); i++)
@@ -2576,7 +2577,7 @@ void scst_free_cmd(struct scst_cmd *cmd)
 #ifdef CONFIG_SCST_EXTRACHECKS
                if (unlikely(!cmd->sent_for_exec) && !cmd->internal) {
                        PRINT_ERROR("Finishing not executed cmd %p (opcode "
-                           "%d, target %s, LUN %lld, sn %ld, expected_sn %ld)",
+                           "%d, target %s, LUN %lld, sn %d, expected_sn %d)",
                            cmd, cmd->cdb[0], cmd->tgtt->name,
                            (long long unsigned int)cmd->lun,
                            cmd->sn, cmd->tgt_dev->expected_sn);
@@ -2585,7 +2586,7 @@ void scst_free_cmd(struct scst_cmd *cmd)
 #endif
 
                if (unlikely(cmd->out_of_sn)) {
-                       TRACE_SN("Out of SN cmd %p (tag %llu, sn %ld), "
+                       TRACE_SN("Out of SN cmd %p (tag %llu, sn %d), "
                                "destroy=%d", cmd,
                                (long long unsigned int)cmd->tag,
                                cmd->sn, destroy);
@@ -4481,7 +4482,7 @@ restart:
                EXTRACHECKS_BUG_ON(cmd->queue_type ==
                        SCST_CMD_QUEUE_HEAD_OF_QUEUE);
                if (cmd->sn == expected_sn) {
-                       TRACE_SN("Deferred command %p (sn %ld, set %d) found",
+                       TRACE_SN("Deferred command %p (sn %d, set %d) found",
                                cmd, cmd->sn, cmd->sn_set);
                        tgt_dev->def_cmd_count--;
                        list_del(&cmd->sn_cmd_list_entry);
@@ -4512,7 +4513,7 @@ restart:
                         * !! sn_slot and sn_cmd_list_entry, could be   !!
                         * !! already destroyed                         !!
                         */
-                       TRACE_SN("cmd %p (tag %llu) with skipped sn %ld found",
+                       TRACE_SN("cmd %p (tag %llu) with skipped sn %d found",
                                 cmd,
                                 (long long unsigned int)cmd->tag,
                                 cmd->sn);
@@ -4837,8 +4838,8 @@ static void __scst_unblock_deferred(struct scst_tgt_dev *tgt_dev,
                tgt_dev->def_cmd_count++;
                list_add_tail(&out_of_sn_cmd->sn_cmd_list_entry,
                              &tgt_dev->skipped_sn_list);
-               TRACE_SN("out_of_sn_cmd %p with sn %ld added to skipped_sn_list"
-                       " (expected_sn %ld)", out_of_sn_cmd, out_of_sn_cmd->sn,
+               TRACE_SN("out_of_sn_cmd %p with sn %d added to skipped_sn_list"
+                       " (expected_sn %d)", out_of_sn_cmd, out_of_sn_cmd->sn,
                        tgt_dev->expected_sn);
                spin_unlock_irq(&tgt_dev->sn_lock);
        }
index 47037c2..610f20f 100644 (file)
@@ -1917,7 +1917,7 @@ inc:
         * scst_post_exec_sn(). See comment in scst_send_for_exec().
         */
        smp_mb();
-       TRACE_SN("Next expected_sn: %ld", tgt_dev->expected_sn);
+       TRACE_SN("Next expected_sn: %d", tgt_dev->expected_sn);
 
 out:
        return;
@@ -2344,14 +2344,14 @@ static int scst_send_for_exec(struct scst_cmd **active_cmd)
                                              &cmd->cmd_flags))) {
                                /* Necessary to allow aborting out of sn cmds */
                                TRACE_MGMT_DBG("Aborting out of sn cmd %p "
-                                       "(tag %llu, sn %lu)", cmd,
+                                       "(tag %llu, sn %u)", cmd,
                                        (long long unsigned)cmd->tag, cmd->sn);
                                tgt_dev->def_cmd_count--;
                                scst_set_cmd_abnormal_done_state(cmd);
                                res = SCST_CMD_STATE_RES_CONT_SAME;
                        } else {
-                               TRACE_SN("Deferring cmd %p (sn=%ld, set %d, "
-                                       "expected_sn=%ld)", cmd, cmd->sn,
+                               TRACE_SN("Deferring cmd %p (sn=%d, set %d, "
+                                       "expected_sn=%d)", cmd, cmd->sn,
                                        cmd->sn_set, expected_sn);
                                list_add_tail(&cmd->sn_cmd_list_entry,
                                              &tgt_dev->deferred_cmd_list);
@@ -2360,7 +2360,7 @@ static int scst_send_for_exec(struct scst_cmd **active_cmd)
                        spin_unlock_irq(&tgt_dev->sn_lock);
                        goto out;
                } else {
-                       TRACE_SN("Somebody incremented expected_sn %ld, "
+                       TRACE_SN("Somebody incremented expected_sn %d, "
                                "continuing", expected_sn);
                        tgt_dev->def_cmd_count--;
                        spin_unlock_irq(&tgt_dev->sn_lock);
@@ -2872,7 +2872,7 @@ static int scst_pre_xmit_response(struct scst_cmd *cmd)
 
                if (unlikely(!cmd->sent_for_exec)) {
                        TRACE_SN("cmd %p was not sent to mid-lev"
-                               " (sn %ld, set %d)",
+                               " (sn %d, set %d)",
                                cmd, cmd->sn, cmd->sn_set);
                        scst_unblock_deferred(cmd->tgt_dev, cmd);
                        cmd->sent_for_exec = 1;
@@ -3159,7 +3159,7 @@ static void scst_cmd_set_sn(struct scst_cmd *cmd)
                         */
                        if (atomic_inc_return(tgt_dev->cur_sn_slot) == 1) {
                                tgt_dev->curr_sn++;
-                               TRACE_SN("Incremented curr_sn %ld",
+                               TRACE_SN("Incremented curr_sn %d",
                                        tgt_dev->curr_sn);
                        }
                        cmd->sn_slot = tgt_dev->cur_sn_slot;
@@ -3221,7 +3221,7 @@ ordered:
                sBUG();
        }
 
-       TRACE_SN("cmd(%p)->sn: %ld (tgt_dev %p, *cur_sn_slot %d, "
+       TRACE_SN("cmd(%p)->sn: %d (tgt_dev %p, *cur_sn_slot %d, "
                "num_free_sn_slots %d, prev_cmd_ordered %ld, "
                "cur_sn_slot %zd)", cmd, cmd->sn, tgt_dev,
                atomic_read(tgt_dev->cur_sn_slot),
@@ -4113,7 +4113,7 @@ void scst_abort_cmd(struct scst_cmd *cmd, struct scst_mgmt_cmd *mcmd,
                 * command actually gets executed *after* new commands sent
                 * after this TM command completed.
                 */
-               TRACE_MGMT_DBG("cmd %p (tag %llu, sn %lu) being "
+               TRACE_MGMT_DBG("cmd %p (tag %llu, sn %u) being "
                        "executed/xmitted (state %d, op %x, proc time %ld "
                        "sec., timeout %d sec.), deferring ABORT...", cmd,
                        (long long unsigned int)cmd->tag, cmd->sn, cmd->state,
@@ -4223,7 +4223,7 @@ static void scst_unblock_aborted_cmds(int scst_mutex_held)
                                if (__scst_check_unblock_aborted_cmd(cmd,
                                                &cmd->sn_cmd_list_entry)) {
                                        TRACE_MGMT_DBG("Unblocked aborted SN "
-                                               "cmd %p (sn %lu)",
+                                               "cmd %p (sn %u)",
                                                cmd, cmd->sn);
                                        tgt_dev->def_cmd_count--;
                                }
@@ -4433,7 +4433,7 @@ static int scst_mgmt_cmd_init(struct scst_mgmt_cmd *mcmd)
                }
                __scst_cmd_get(cmd);
                spin_unlock_irq(&sess->sess_list_lock);
-               TRACE_MGMT_DBG("Cmd %p for tag %llu (sn %ld, set %d, "
+               TRACE_MGMT_DBG("Cmd %p for tag %llu (sn %d, set %d, "
                        "queue_type %x) found, aborting it",
                        cmd, (long long unsigned int)mcmd->tag,
                        cmd->sn, cmd->sn_set, cmd->queue_type);