Minor fixes and cleanups
authorvlnb <vlnb@d57e44dd-8a1f-0410-8b47-8ef2f437770f>
Tue, 19 May 2009 17:56:25 +0000 (17:56 +0000)
committervlnb <vlnb@d57e44dd-8a1f-0410-8b47-8ef2f437770f>
Tue, 19 May 2009 17:56:25 +0000 (17:56 +0000)
git-svn-id: https://scst.svn.sourceforge.net/svnroot/scst/trunk@862 d57e44dd-8a1f-0410-8b47-8ef2f437770f

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

index effca1b..e517c07 100644 (file)
@@ -1224,6 +1224,7 @@ void scst_nexus_loss(struct scst_tgt_dev *tgt_dev, bool queue_UA)
        /* With activity suspended the lock isn't needed, but let's be safe */
        spin_lock_bh(&tgt_dev->tgt_dev_lock);
        scst_free_all_UA(tgt_dev);
+       memset(tgt_dev->tgt_dev_sense, 0, sizeof(tgt_dev->tgt_dev_sense));
        spin_unlock_bh(&tgt_dev->tgt_dev_lock);
 
        if (queue_UA) {
@@ -3426,7 +3427,12 @@ void scst_process_reset(struct scst_device *dev,
                struct scst_session *sess = tgt_dev->sess;
 
                spin_lock_bh(&tgt_dev->tgt_dev_lock);
+
                scst_free_all_UA(tgt_dev);
+
+               memset(tgt_dev->tgt_dev_sense, 0,
+                       sizeof(tgt_dev->tgt_dev_sense));
+
                spin_unlock_bh(&tgt_dev->tgt_dev_lock);
 
                spin_lock_irq(&sess->sess_list_lock);
@@ -4158,6 +4164,37 @@ out:
        return;
 }
 
+void scst_store_sense(struct scst_cmd *cmd)
+{
+       TRACE_ENTRY();
+
+       if (SCST_SENSE_VALID(cmd->sense) &&
+           !test_bit(SCST_CMD_NO_RESP, &cmd->cmd_flags) &&
+           (cmd->tgt_dev != NULL)) {
+               struct scst_tgt_dev *tgt_dev = cmd->tgt_dev;
+
+               TRACE_DBG("Storing sense (cmd %p)", cmd);
+
+               spin_lock_bh(&tgt_dev->tgt_dev_lock);
+
+               if (cmd->sense_bufflen <= sizeof(tgt_dev->tgt_dev_sense))
+                       tgt_dev->tgt_dev_valid_sense_len = cmd->sense_bufflen;
+               else {
+                       tgt_dev->tgt_dev_valid_sense_len = sizeof(tgt_dev->tgt_dev_sense);
+                       PRINT_ERROR("Stored sense truncated to size %d "
+                               "(needed %d)", tgt_dev->tgt_dev_valid_sense_len,
+                               cmd->sense_bufflen);
+               }
+               memcpy(tgt_dev->tgt_dev_sense, cmd->sense,
+                       tgt_dev->tgt_dev_valid_sense_len);
+
+               spin_unlock_bh(&tgt_dev->tgt_dev_lock);
+       }
+
+       TRACE_EXIT();
+       return;
+}
+
 void scst_xmit_process_aborted_cmd(struct scst_cmd *cmd)
 {
        TRACE_ENTRY();
index 224e20e..aa2cee5 100644 (file)
@@ -303,6 +303,8 @@ int scst_acg_remove_name(struct scst_acg *acg, const char *name);
 int scst_prepare_request_sense(struct scst_cmd *orig_cmd);
 int scst_finish_internal_cmd(struct scst_cmd *cmd);
 
+void scst_store_sense(struct scst_cmd *cmd);
+
 int scst_assign_dev_handler(struct scst_device *dev,
        struct scst_dev_type *handler);
 
index 167e5a5..cdb7feb 100644 (file)
@@ -2922,29 +2922,8 @@ static int scst_pre_xmit_response(struct scst_cmd *cmd)
 
        if (unlikely(test_bit(SCST_CMD_ABORTED, &cmd->cmd_flags)))
                scst_xmit_process_aborted_cmd(cmd);
-       else if (unlikely(cmd->status == SAM_STAT_CHECK_CONDITION) &&
-                SCST_SENSE_VALID(cmd->sense) &&
-                !test_bit(SCST_CMD_NO_RESP, &cmd->cmd_flags) &&
-                (cmd->tgt_dev != NULL)) {
-               struct scst_tgt_dev *tgt_dev = cmd->tgt_dev;
-
-               TRACE_DBG("Storing sense (cmd %p)", cmd);
-
-               spin_lock_bh(&tgt_dev->tgt_dev_lock);
-
-               if (cmd->sense_bufflen <= sizeof(tgt_dev->tgt_dev_sense))
-                       tgt_dev->tgt_dev_valid_sense_len = cmd->sense_bufflen;
-               else {
-                       tgt_dev->tgt_dev_valid_sense_len = sizeof(tgt_dev->tgt_dev_sense);
-                       PRINT_ERROR("Stored sense truncated to size %d "
-                               "(needed %d)", tgt_dev->tgt_dev_valid_sense_len,
-                               cmd->sense_bufflen);
-               }
-               memcpy(tgt_dev->tgt_dev_sense, cmd->sense,
-                       tgt_dev->tgt_dev_valid_sense_len);
-
-               spin_unlock_bh(&tgt_dev->tgt_dev_lock);
-       }
+       else if (unlikely(cmd->status == SAM_STAT_CHECK_CONDITION))
+               scst_store_sense(cmd);
 
        if (unlikely(test_bit(SCST_CMD_NO_RESP, &cmd->cmd_flags))) {
                TRACE_MGMT_DBG("Flag NO_RESP set for cmd %p (tag %llu),"