iscsi-target: Introduce session_get_next_ttt
authorSagi Grimberg <sagig@mellanox.com>
Mon, 26 Jan 2015 10:49:05 +0000 (12:49 +0200)
committerNicholas Bellinger <nab@linux-iscsi.org>
Wed, 4 Feb 2015 18:55:33 +0000 (10:55 -0800)
Reduce code duplication.

Signed-off-by: Sagi Grimberg <sagig@mellanox.com>
Signed-off-by: Nicholas Bellinger <nab@linux-iscsi.org>
drivers/target/iscsi/iscsi_target.c
drivers/target/iscsi/iscsi_target_util.c
include/target/iscsi/iscsi_target_core.h

index dd646c43d16d5d03bf46eeac9694c9449313a91a..5b25faa43c646a557efdbbacff67f32caf6ffbfc 100644 (file)
@@ -968,11 +968,7 @@ int iscsit_setup_scsi_cmd(struct iscsi_conn *conn, struct iscsi_cmd *cmd,
 
        conn->sess->init_task_tag = cmd->init_task_tag = hdr->itt;
        if (hdr->flags & ISCSI_FLAG_CMD_READ) {
-               spin_lock_bh(&conn->sess->ttt_lock);
-               cmd->targ_xfer_tag = conn->sess->targ_xfer_tag++;
-               if (cmd->targ_xfer_tag == 0xFFFFFFFF)
-                       cmd->targ_xfer_tag = conn->sess->targ_xfer_tag++;
-               spin_unlock_bh(&conn->sess->ttt_lock);
+               cmd->targ_xfer_tag = session_get_next_ttt(conn->sess);
        } else if (hdr->flags & ISCSI_FLAG_CMD_WRITE)
                cmd->targ_xfer_tag = 0xFFFFFFFF;
        cmd->cmd_sn             = be32_to_cpu(hdr->cmdsn);
@@ -3047,11 +3043,7 @@ static int iscsit_send_r2t(
        int_to_scsilun(cmd->se_cmd.orig_fe_lun,
                        (struct scsi_lun *)&hdr->lun);
        hdr->itt                = cmd->init_task_tag;
-       spin_lock_bh(&conn->sess->ttt_lock);
-       r2t->targ_xfer_tag      = conn->sess->targ_xfer_tag++;
-       if (r2t->targ_xfer_tag == 0xFFFFFFFF)
-               r2t->targ_xfer_tag = conn->sess->targ_xfer_tag++;
-       spin_unlock_bh(&conn->sess->ttt_lock);
+       r2t->targ_xfer_tag      = session_get_next_ttt(conn->sess);
        hdr->ttt                = cpu_to_be32(r2t->targ_xfer_tag);
        hdr->statsn             = cpu_to_be32(conn->stat_sn);
        hdr->exp_cmdsn          = cpu_to_be32(conn->sess->exp_cmd_sn);
index 70f57c1924158f776a5322645d6064aa3261f31c..c211d3f2726c7216215a1d1aea1ae9c972bd3d3e 100644 (file)
@@ -939,13 +939,8 @@ static int iscsit_add_nopin(struct iscsi_conn *conn, int want_response)
        state = (want_response) ? ISTATE_SEND_NOPIN_WANT_RESPONSE :
                                ISTATE_SEND_NOPIN_NO_RESPONSE;
        cmd->init_task_tag = RESERVED_ITT;
-       spin_lock_bh(&conn->sess->ttt_lock);
-       cmd->targ_xfer_tag = (want_response) ? conn->sess->targ_xfer_tag++ :
-                       0xFFFFFFFF;
-       if (want_response && (cmd->targ_xfer_tag == 0xFFFFFFFF))
-               cmd->targ_xfer_tag = conn->sess->targ_xfer_tag++;
-       spin_unlock_bh(&conn->sess->ttt_lock);
-
+       cmd->targ_xfer_tag = (want_response) ?
+                            session_get_next_ttt(conn->sess) : 0xFFFFFFFF;
        spin_lock_bh(&conn->cmd_lock);
        list_add_tail(&cmd->i_conn_node, &conn->conn_cmd_list);
        spin_unlock_bh(&conn->cmd_lock);
index 09a522bae222d190ec92e157a42f13d2e361da4a..5f41a17bdafdf0cc29064140df9da2c015cd3628 100644 (file)
@@ -880,4 +880,17 @@ struct iscsit_global {
        struct iscsi_portal_group       *discovery_tpg;
 };
 
+static inline u32 session_get_next_ttt(struct iscsi_session *session)
+{
+       u32 ttt;
+
+       spin_lock_bh(&session->ttt_lock);
+       ttt = session->targ_xfer_tag++;
+       if (ttt == 0xFFFFFFFF)
+               ttt = session->targ_xfer_tag++;
+       spin_unlock_bh(&session->ttt_lock);
+
+       return ttt;
+}
+
 #endif /* ISCSI_TARGET_CORE_H */