@@ -767,9 +767,8 @@ static int iscsit_handle_scsi_cmd(
767767 struct iscsi_conn * conn ,
768768 unsigned char * buf )
769769{
770- int data_direction , cmdsn_ret = 0 , immed_ret , ret , transport_ret ;
771- int dump_immediate_data = 0 , send_check_condition = 0 , payload_length ;
772- struct iscsi_cmd * cmd = NULL ;
770+ int data_direction , payload_length , cmdsn_ret = 0 , immed_ret ;
771+ struct iscsi_cmd * cmd = NULL ;
773772 struct iscsi_scsi_req * hdr ;
774773 int iscsi_task_attr ;
775774 int sam_task_attr ;
@@ -956,38 +955,26 @@ static int iscsit_handle_scsi_cmd(
956955 " ExpXferLen: %u, Length: %u, CID: %hu\n" , hdr -> itt ,
957956 hdr -> cmdsn , hdr -> data_length , payload_length , conn -> cid );
958957
959- /*
960- * The CDB is going to an se_device_t.
961- */
962- ret = transport_lookup_cmd_lun (& cmd -> se_cmd ,
963- scsilun_to_int (& hdr -> lun ));
964- if (ret < 0 ) {
965- if (cmd -> se_cmd .scsi_sense_reason == TCM_NON_EXISTENT_LUN ) {
966- pr_debug ("Responding to non-acl'ed,"
967- " non-existent or non-exported iSCSI LUN:"
968- " 0x%016Lx\n" , get_unaligned_le64 (& hdr -> lun ));
958+ cmd -> sense_reason = transport_lookup_cmd_lun (& cmd -> se_cmd ,
959+ scsilun_to_int (& hdr -> lun ));
960+ if (cmd -> sense_reason )
961+ goto attach_cmd ;
962+
963+ cmd -> sense_reason = target_setup_cmd_from_cdb (& cmd -> se_cmd , hdr -> cdb );
964+ if (cmd -> sense_reason ) {
965+ if (cmd -> sense_reason == TCM_OUT_OF_RESOURCES ) {
966+ return iscsit_add_reject_from_cmd (
967+ ISCSI_REASON_BOOKMARK_NO_RESOURCES ,
968+ 1 , 1 , buf , cmd );
969969 }
970- send_check_condition = 1 ;
970+
971971 goto attach_cmd ;
972972 }
973973
974- transport_ret = target_setup_cmd_from_cdb (& cmd -> se_cmd , hdr -> cdb );
975- if (transport_ret == - ENOMEM ) {
974+ if (iscsit_build_pdu_and_seq_lists (cmd , payload_length ) < 0 ) {
976975 return iscsit_add_reject_from_cmd (
977- ISCSI_REASON_BOOKMARK_NO_RESOURCES ,
978- 1 , 1 , buf , cmd );
979- } else if (transport_ret < 0 ) {
980- /*
981- * Unsupported SAM Opcode. CHECK_CONDITION will be sent
982- * in iscsit_execute_cmd() during the CmdSN OOO Execution
983- * Mechinism.
984- */
985- send_check_condition = 1 ;
986- } else {
987- if (iscsit_build_pdu_and_seq_lists (cmd , payload_length ) < 0 )
988- return iscsit_add_reject_from_cmd (
989- ISCSI_REASON_BOOKMARK_NO_RESOURCES ,
990- 1 , 1 , buf , cmd );
976+ ISCSI_REASON_BOOKMARK_NO_RESOURCES ,
977+ 1 , 1 , buf , cmd );
991978 }
992979
993980attach_cmd :
@@ -1000,11 +987,12 @@ static int iscsit_handle_scsi_cmd(
1000987 */
1001988 core_alua_check_nonop_delay (& cmd -> se_cmd );
1002989
1003- ret = iscsit_allocate_iovecs (cmd );
1004- if (ret < 0 )
990+ if (iscsit_allocate_iovecs (cmd ) < 0 ) {
1005991 return iscsit_add_reject_from_cmd (
1006992 ISCSI_REASON_BOOKMARK_NO_RESOURCES ,
1007993 1 , 0 , buf , cmd );
994+ }
995+
1008996 /*
1009997 * Check the CmdSN against ExpCmdSN/MaxCmdSN here if
1010998 * the Immediate Bit is not set, and no Immediate
@@ -1031,10 +1019,7 @@ static int iscsit_handle_scsi_cmd(
10311019 * If no Immediate Data is attached, it's OK to return now.
10321020 */
10331021 if (!cmd -> immediate_data ) {
1034- if (send_check_condition )
1035- return 0 ;
1036-
1037- if (cmd -> unsolicited_data ) {
1022+ if (!cmd -> sense_reason && cmd -> unsolicited_data ) {
10381023 iscsit_set_dataout_sequence_values (cmd );
10391024
10401025 spin_lock_bh (& cmd -> dataout_timeout_lock );
@@ -1050,19 +1035,17 @@ static int iscsit_handle_scsi_cmd(
10501035 * thread. They are processed in CmdSN order by
10511036 * iscsit_check_received_cmdsn() below.
10521037 */
1053- if (send_check_condition ) {
1038+ if (cmd -> sense_reason ) {
10541039 immed_ret = IMMEDIATE_DATA_NORMAL_OPERATION ;
1055- dump_immediate_data = 1 ;
10561040 goto after_immediate_data ;
10571041 }
10581042 /*
10591043 * Call directly into transport_generic_new_cmd() to perform
10601044 * the backend memory allocation.
10611045 */
1062- ret = transport_generic_new_cmd (& cmd -> se_cmd );
1063- if (ret < 0 ) {
1046+ cmd -> sense_reason = transport_generic_new_cmd (& cmd -> se_cmd );
1047+ if (cmd -> sense_reason ) {
10641048 immed_ret = IMMEDIATE_DATA_NORMAL_OPERATION ;
1065- dump_immediate_data = 1 ;
10661049 goto after_immediate_data ;
10671050 }
10681051
@@ -1079,7 +1062,7 @@ static int iscsit_handle_scsi_cmd(
10791062 * Special case for Unsupported SAM WRITE Opcodes
10801063 * and ImmediateData=Yes.
10811064 */
1082- if (dump_immediate_data ) {
1065+ if (cmd -> sense_reason ) {
10831066 if (iscsit_dump_data_payload (conn , payload_length , 1 ) < 0 )
10841067 return -1 ;
10851068 } else if (cmd -> unsolicited_data ) {
@@ -1272,8 +1255,7 @@ static int iscsit_handle_data_out(struct iscsi_conn *conn, unsigned char *buf)
12721255 spin_unlock_irqrestore (& se_cmd -> t_state_lock , flags );
12731256
12741257 spin_lock_irqsave (& se_cmd -> t_state_lock , flags );
1275- if (!(se_cmd -> se_cmd_flags & SCF_SUPPORTED_SAM_OPCODE ) ||
1276- (se_cmd -> se_cmd_flags & SCF_SCSI_CDB_EXCEPTION ))
1258+ if (!(se_cmd -> se_cmd_flags & SCF_SUPPORTED_SAM_OPCODE ))
12771259 dump_unsolicited_data = 1 ;
12781260 spin_unlock_irqrestore (& se_cmd -> t_state_lock , flags );
12791261
@@ -1742,7 +1724,6 @@ static int iscsit_handle_task_mgt_cmd(
17421724 ret = transport_lookup_tmr_lun (& cmd -> se_cmd ,
17431725 scsilun_to_int (& hdr -> lun ));
17441726 if (ret < 0 ) {
1745- cmd -> se_cmd .se_cmd_flags |= SCF_SCSI_CDB_EXCEPTION ;
17461727 se_tmr -> response = ISCSI_TMF_RSP_NO_LUN ;
17471728 goto attach ;
17481729 }
@@ -1751,10 +1732,8 @@ static int iscsit_handle_task_mgt_cmd(
17511732 switch (function ) {
17521733 case ISCSI_TM_FUNC_ABORT_TASK :
17531734 se_tmr -> response = iscsit_tmr_abort_task (cmd , buf );
1754- if (se_tmr -> response != ISCSI_TMF_RSP_COMPLETE ) {
1755- cmd -> se_cmd .se_cmd_flags |= SCF_SCSI_CDB_EXCEPTION ;
1735+ if (se_tmr -> response )
17561736 goto attach ;
1757- }
17581737 break ;
17591738 case ISCSI_TM_FUNC_ABORT_TASK_SET :
17601739 case ISCSI_TM_FUNC_CLEAR_ACA :
@@ -1763,14 +1742,12 @@ static int iscsit_handle_task_mgt_cmd(
17631742 break ;
17641743 case ISCSI_TM_FUNC_TARGET_WARM_RESET :
17651744 if (iscsit_tmr_task_warm_reset (conn , tmr_req , buf ) < 0 ) {
1766- cmd -> se_cmd .se_cmd_flags |= SCF_SCSI_CDB_EXCEPTION ;
17671745 se_tmr -> response = ISCSI_TMF_RSP_AUTH_FAILED ;
17681746 goto attach ;
17691747 }
17701748 break ;
17711749 case ISCSI_TM_FUNC_TARGET_COLD_RESET :
17721750 if (iscsit_tmr_task_cold_reset (conn , tmr_req , buf ) < 0 ) {
1773- cmd -> se_cmd .se_cmd_flags |= SCF_SCSI_CDB_EXCEPTION ;
17741751 se_tmr -> response = ISCSI_TMF_RSP_AUTH_FAILED ;
17751752 goto attach ;
17761753 }
@@ -1781,7 +1758,7 @@ static int iscsit_handle_task_mgt_cmd(
17811758 * Perform sanity checks on the ExpDataSN only if the
17821759 * TASK_REASSIGN was successful.
17831760 */
1784- if (se_tmr -> response != ISCSI_TMF_RSP_COMPLETE )
1761+ if (se_tmr -> response )
17851762 break ;
17861763
17871764 if (iscsit_check_task_reassign_expdatasn (tmr_req , conn ) < 0 )
@@ -1792,7 +1769,6 @@ static int iscsit_handle_task_mgt_cmd(
17921769 default :
17931770 pr_err ("Unknown TMR function: 0x%02x, protocol"
17941771 " error.\n" , function );
1795- cmd -> se_cmd .se_cmd_flags |= SCF_SCSI_CDB_EXCEPTION ;
17961772 se_tmr -> response = ISCSI_TMF_RSP_NOT_SUPPORTED ;
17971773 goto attach ;
17981774 }
0 commit comments