iscsi-target: Remove SCF_SE_LUN_CMD flag abuses
authorNicholas Bellinger <nab@linux-iscsi.org>
Sun, 9 Oct 2011 08:48:14 +0000 (01:48 -0700)
committerNicholas Bellinger <nab@linux-iscsi.org>
Mon, 24 Oct 2011 03:20:56 +0000 (03:20 +0000)
This patch removes a number of SCF_SE_LUN_CMD flag abuses within iscsi-target
code to determine when iscsit_release_cmd() or transport_generic_free_cmd()
should be called while releasing an individual iscsi_cmd descriptor.

In the place of SCF_SE_LUN_CMD checks, this patch converts existing code to
use a new iscsit_free_cmd() that inspects iscsi_cmd->iscsi_opcode types to
determine which of the above functions should be invoked.  It also removes the
now unnecessary special case checking in iscsit_release_commands_from_conn().

(hch: Use iscsit_free_cmd instead of open-coded alternative)

Reported-by: Christoph Hellwig <hch@lst.de>
Cc: Christoph Hellwig <hch@lst.de>
Signed-off-by: Nicholas Bellinger <nab@linux-iscsi.org>
drivers/target/iscsi/iscsi_target.c
drivers/target/iscsi/iscsi_target_erl2.c
drivers/target/iscsi/iscsi_target_util.c
drivers/target/iscsi/iscsi_target_util.h

index e4b9ba296dcfc0f8673ea8323fcb2e92e5075112..d86e18dc163a663b035181539d51c96dd03d9cea 100644 (file)
@@ -3538,16 +3538,8 @@ get_immediate:
                                spin_lock_bh(&conn->cmd_lock);
                                list_del(&cmd->i_list);
                                spin_unlock_bh(&conn->cmd_lock);
-                               /*
-                                * Determine if a struct se_cmd is assoicated with
-                                * this struct iscsi_cmd.
-                                */
-                               if (!(cmd->se_cmd.se_cmd_flags & SCF_SE_LUN_CMD) &&
-                                   !(cmd->tmr_req))
-                                       iscsit_release_cmd(cmd);
-                               else
-                                       transport_generic_free_cmd(&cmd->se_cmd,
-                                                               1);
+
+                               iscsit_free_cmd(cmd);
                                goto get_immediate;
                        case ISTATE_SEND_NOPIN_WANT_RESPONSE:
                                spin_unlock_bh(&cmd->istate_lock);
@@ -3947,30 +3939,13 @@ static void iscsit_release_commands_from_conn(struct iscsi_conn *conn)
         */
        spin_lock_bh(&conn->cmd_lock);
        list_for_each_entry_safe(cmd, cmd_tmp, &conn->conn_cmd_list, i_list) {
-               if (!(cmd->se_cmd.se_cmd_flags & SCF_SE_LUN_CMD)) {
-
-                       list_del(&cmd->i_list);
-                       spin_unlock_bh(&conn->cmd_lock);
-                       iscsit_increment_maxcmdsn(cmd, sess);
-                       /*
-                        * Special cases for active iSCSI TMR, and
-                        * transport_lookup_cmd_lun() failing from
-                        * iscsit_get_lun_for_cmd() in iscsit_handle_scsi_cmd().
-                        */
-                       if (cmd->tmr_req)
-                               transport_generic_free_cmd(&cmd->se_cmd, 1);
-                       else
-                               iscsit_release_cmd(cmd);
 
-                       spin_lock_bh(&conn->cmd_lock);
-                       continue;
-               }
                list_del(&cmd->i_list);
                spin_unlock_bh(&conn->cmd_lock);
 
                iscsit_increment_maxcmdsn(cmd, sess);
 
-               transport_generic_free_cmd(&cmd->se_cmd, 1);
+               iscsit_free_cmd(cmd);
 
                spin_lock_bh(&conn->cmd_lock);
        }
index c3803b2fdd6544708643fb3c6d04a9e0a0d0b5f1..0b8404c30125256a99bff82082516c324ff16364 100644 (file)
@@ -143,10 +143,7 @@ void iscsit_free_connection_recovery_entires(struct iscsi_session *sess)
                        list_del(&cmd->i_list);
                        cmd->conn = NULL;
                        spin_unlock(&cr->conn_recovery_cmd_lock);
-                       if (!(cmd->se_cmd.se_cmd_flags & SCF_SE_LUN_CMD))
-                               iscsit_release_cmd(cmd);
-                       else
-                               transport_generic_free_cmd(&cmd->se_cmd, 1);
+                       iscsit_free_cmd(cmd);
                        spin_lock(&cr->conn_recovery_cmd_lock);
                }
                spin_unlock(&cr->conn_recovery_cmd_lock);
@@ -168,10 +165,7 @@ void iscsit_free_connection_recovery_entires(struct iscsi_session *sess)
                        list_del(&cmd->i_list);
                        cmd->conn = NULL;
                        spin_unlock(&cr->conn_recovery_cmd_lock);
-                       if (!(cmd->se_cmd.se_cmd_flags & SCF_SE_LUN_CMD))
-                               iscsit_release_cmd(cmd);
-                       else
-                               transport_generic_free_cmd(&cmd->se_cmd, 1);
+                       iscsit_free_cmd(cmd);
                        spin_lock(&cr->conn_recovery_cmd_lock);
                }
                spin_unlock(&cr->conn_recovery_cmd_lock);
@@ -256,10 +250,7 @@ void iscsit_discard_cr_cmds_by_expstatsn(
                iscsit_remove_cmd_from_connection_recovery(cmd, sess);
 
                spin_unlock(&cr->conn_recovery_cmd_lock);
-               if (!(cmd->se_cmd.se_cmd_flags & SCF_SE_LUN_CMD))
-                       iscsit_release_cmd(cmd);
-               else
-                       transport_generic_free_cmd(&cmd->se_cmd, 1);
+               iscsit_free_cmd(cmd);
                spin_lock(&cr->conn_recovery_cmd_lock);
        }
        spin_unlock(&cr->conn_recovery_cmd_lock);
@@ -313,10 +304,7 @@ int iscsit_discard_unacknowledged_ooo_cmdsns_for_conn(struct iscsi_conn *conn)
                list_del(&cmd->i_list);
 
                spin_unlock_bh(&conn->cmd_lock);
-               if (!(cmd->se_cmd.se_cmd_flags & SCF_SE_LUN_CMD))
-                       iscsit_release_cmd(cmd);
-               else
-                       transport_generic_free_cmd(&cmd->se_cmd, 1);
+               iscsit_free_cmd(cmd);
                spin_lock_bh(&conn->cmd_lock);
        }
        spin_unlock_bh(&conn->cmd_lock);
@@ -369,11 +357,7 @@ int iscsit_prepare_cmds_for_realligance(struct iscsi_conn *conn)
 
                        list_del(&cmd->i_list);
                        spin_unlock_bh(&conn->cmd_lock);
-
-                       if (!(cmd->se_cmd.se_cmd_flags & SCF_SE_LUN_CMD))
-                               iscsit_release_cmd(cmd);
-                       else
-                               transport_generic_free_cmd(&cmd->se_cmd, 1);
+                       iscsit_free_cmd(cmd);
                        spin_lock_bh(&conn->cmd_lock);
                        continue;
                }
@@ -393,11 +377,7 @@ int iscsit_prepare_cmds_for_realligance(struct iscsi_conn *conn)
                     (cmd->cmd_sn >= conn->sess->exp_cmd_sn)) {
                        list_del(&cmd->i_list);
                        spin_unlock_bh(&conn->cmd_lock);
-
-                       if (!(cmd->se_cmd.se_cmd_flags & SCF_SE_LUN_CMD))
-                               iscsit_release_cmd(cmd);
-                       else
-                               transport_generic_free_cmd(&cmd->se_cmd, 1);
+                       iscsit_free_cmd(cmd);
                        spin_lock_bh(&conn->cmd_lock);
                        continue;
                }
@@ -422,8 +402,7 @@ int iscsit_prepare_cmds_for_realligance(struct iscsi_conn *conn)
 
                iscsit_free_all_datain_reqs(cmd);
 
-               if (cmd->se_cmd.se_cmd_flags & SCF_SE_LUN_CMD)
-                       transport_wait_for_tasks(&cmd->se_cmd);
+               transport_wait_for_tasks(&cmd->se_cmd);
                /*
                 * Add the struct iscsi_cmd to the connection recovery cmd list
                 */
index c4be6223b9ccade0fc937aae0da95081d01960c5..02348f727bd4ddaaa4ef4b70e3499fc135001dad 100644 (file)
@@ -840,6 +840,23 @@ void iscsit_release_cmd(struct iscsi_cmd *cmd)
        kmem_cache_free(lio_cmd_cache, cmd);
 }
 
+void iscsit_free_cmd(struct iscsi_cmd *cmd)
+{
+       /*
+        * Determine if a struct se_cmd is assoicated with
+        * this struct iscsi_cmd.
+        */
+       switch (cmd->iscsi_opcode) {
+       case ISCSI_OP_SCSI_CMD:
+       case ISCSI_OP_SCSI_TMFUNC:
+               transport_generic_free_cmd(&cmd->se_cmd, 1);
+               break;
+       default:
+               iscsit_release_cmd(cmd);
+               break;
+       }
+}
+
 int iscsit_check_session_usage_count(struct iscsi_session *sess)
 {
        spin_lock_bh(&sess->session_usage_lock);
index 2cd49d607bda4e0bf9afdaba1e7edba2d50c93f2..835bf7de02815d272476edd071be2b9e4aebe6d3 100644 (file)
@@ -30,6 +30,7 @@ extern struct iscsi_queue_req *iscsit_get_cmd_from_response_queue(struct iscsi_c
 extern void iscsit_remove_cmd_from_tx_queues(struct iscsi_cmd *, struct iscsi_conn *);
 extern void iscsit_free_queue_reqs_for_conn(struct iscsi_conn *);
 extern void iscsit_release_cmd(struct iscsi_cmd *);
+extern void iscsit_free_cmd(struct iscsi_cmd *);
 extern int iscsit_check_session_usage_count(struct iscsi_session *);
 extern void iscsit_dec_session_usage_count(struct iscsi_session *);
 extern void iscsit_inc_session_usage_count(struct iscsi_session *);