From: Nicholas Bellinger <nab@xxxxxxxxxxxxxxx> 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 inspect iscsi_cmd->iscsi_opcode types based on individual context in order 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(). Reported-by: Christoph Hellwig <hch@xxxxxx> Cc: Christoph Hellwig <hch@xxxxxx> Signed-off-by: Nicholas Bellinger <nab@xxxxxxxxxxxxxxx> --- drivers/target/iscsi/iscsi_target.c | 29 ++++++++--------------------- drivers/target/iscsi/iscsi_target_erl2.c | 16 ++++++++-------- 2 files changed, 16 insertions(+), 29 deletions(-) diff --git a/drivers/target/iscsi/iscsi_target.c b/drivers/target/iscsi/iscsi_target.c index 6751e59..d386143 100644 --- a/drivers/target/iscsi/iscsi_target.c +++ b/drivers/target/iscsi/iscsi_target.c @@ -3542,8 +3542,8 @@ get_immediate: * 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)) + if ((cmd->iscsi_opcode != ISCSI_OP_SCSI_CMD) && + (cmd->iscsi_opcode != ISCSI_OP_SCSI_TMFUNC)) iscsit_release_cmd(cmd); else transport_generic_free_cmd(&cmd->se_cmd, @@ -3947,30 +3947,17 @@ 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, 0); - 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); + + if ((cmd->iscsi_opcode != ISCSI_OP_SCSI_CMD) && + (cmd->iscsi_opcode != ISCSI_OP_SCSI_TMFUNC)) + iscsit_release_cmd(cmd); + else + transport_generic_free_cmd(&cmd->se_cmd, 1); spin_lock_bh(&conn->cmd_lock); } diff --git a/drivers/target/iscsi/iscsi_target_erl2.c b/drivers/target/iscsi/iscsi_target_erl2.c index 0af537a..c3561e5 100644 --- a/drivers/target/iscsi/iscsi_target_erl2.c +++ b/drivers/target/iscsi/iscsi_target_erl2.c @@ -143,7 +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)) + if (cmd->iscsi_opcode != ISCSI_OP_SCSI_CMD) iscsit_release_cmd(cmd); else transport_generic_free_cmd(&cmd->se_cmd, 1); @@ -168,7 +168,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)) + if (cmd->iscsi_opcode != ISCSI_OP_SCSI_CMD) iscsit_release_cmd(cmd); else transport_generic_free_cmd(&cmd->se_cmd, 1); @@ -256,7 +256,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)) + if (cmd->iscsi_opcode != ISCSI_OP_SCSI_CMD) iscsit_release_cmd(cmd); else transport_generic_free_cmd(&cmd->se_cmd, 1); @@ -313,7 +313,8 @@ 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)) + if ((cmd->iscsi_opcode != ISCSI_OP_SCSI_CMD) && + (cmd->iscsi_opcode != ISCSI_OP_SCSI_TMFUNC)) iscsit_release_cmd(cmd); else transport_generic_free_cmd(&cmd->se_cmd, 1); @@ -370,7 +371,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)) + if (cmd->iscsi_opcode != ISCSI_OP_SCSI_TMFUNC) iscsit_release_cmd(cmd); else transport_generic_free_cmd(&cmd->se_cmd, 1); @@ -394,7 +395,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)) + if (cmd->iscsi_opcode != ISCSI_OP_SCSI_CMD) iscsit_release_cmd(cmd); else transport_generic_free_cmd(&cmd->se_cmd, 1); @@ -422,8 +423,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_generic_wait_for_tasks(&cmd->se_cmd); + transport_generic_wait_for_tasks(&cmd->se_cmd); /* * Add the struct iscsi_cmd to the connection recovery cmd list */ -- 1.7.2.5 -- To unsubscribe from this list: send the line "unsubscribe target-devel" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html