Skip to content

Commit de103c9

Browse files
Christoph HellwigNicholas Bellinger
authored andcommitted
target: pass sense_reason as a return value
Pass the sense reason as an explicit return value from the I/O submission path instead of storing it in struct se_cmd and using negative return values. This cleans up a lot of the code pathes, and with the sparse annotations for the new sense_reason_t type allows for much better error checking. (nab: Convert spc_emulate_modesense + spc_emulate_modeselect to use sense_reason_t with Roland's MODE SELECT changes) Signed-off-by: Christoph Hellwig <hch@lst.de> Cc: Roland Dreier <roland@purestorage.com> Signed-off-by: Nicholas Bellinger <nab@linux-iscsi.org>
1 parent fecae40 commit de103c9

24 files changed

Lines changed: 841 additions & 1059 deletions

‎drivers/infiniband/ulp/srpt/ib_srpt.c‎

Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1730,7 +1730,7 @@ static int srpt_handle_cmd(struct srpt_rdma_ch *ch,
17301730
uint64_t unpacked_lun;
17311731
u64 data_len;
17321732
enum dma_data_direction dir;
1733-
int ret;
1733+
sense_reason_t ret;
17341734

17351735
BUG_ON(!send_ioctx);
17361736

@@ -1755,12 +1755,10 @@ static int srpt_handle_cmd(struct srpt_rdma_ch *ch,
17551755
break;
17561756
}
17571757

1758-
ret = srpt_get_desc_tbl(send_ioctx, srp_cmd, &dir, &data_len);
1759-
if (ret) {
1758+
if (srpt_get_desc_tbl(send_ioctx, srp_cmd, &dir, &data_len)) {
17601759
printk(KERN_ERR "0x%llx: parsing SRP descriptor table failed.\n",
17611760
srp_cmd->tag);
1762-
cmd->se_cmd_flags |= SCF_SCSI_CDB_EXCEPTION;
1763-
cmd->scsi_sense_reason = TCM_INVALID_CDB_FIELD;
1761+
ret = TCM_INVALID_CDB_FIELD;
17641762
kref_put(&send_ioctx->kref, srpt_put_send_ioctx_kref);
17651763
goto send_sense;
17661764
}
@@ -1769,26 +1767,26 @@ static int srpt_handle_cmd(struct srpt_rdma_ch *ch,
17691767
cmd->data_direction = dir;
17701768
unpacked_lun = srpt_unpack_lun((uint8_t *)&srp_cmd->lun,
17711769
sizeof(srp_cmd->lun));
1772-
if (transport_lookup_cmd_lun(cmd, unpacked_lun) < 0) {
1770+
ret = transport_lookup_cmd_lun(cmd, unpacked_lun);
1771+
if (ret) {
17731772
kref_put(&send_ioctx->kref, srpt_put_send_ioctx_kref);
17741773
goto send_sense;
17751774
}
17761775
ret = target_setup_cmd_from_cdb(cmd, srp_cmd->cdb);
1777-
if (ret < 0) {
1776+
if (ret) {
17781777
kref_put(&send_ioctx->kref, srpt_put_send_ioctx_kref);
1779-
if (cmd->se_cmd_flags & SCF_SCSI_RESERVATION_CONFLICT) {
1778+
if (ret == TCM_RESERVATION_CONFLICT) {
17801779
srpt_queue_status(cmd);
17811780
return 0;
1782-
} else
1783-
goto send_sense;
1781+
}
1782+
goto send_sense;
17841783
}
17851784

17861785
transport_handle_cdb_direct(cmd);
17871786
return 0;
17881787

17891788
send_sense:
1790-
transport_send_check_condition_and_sense(cmd, cmd->scsi_sense_reason,
1791-
0);
1789+
transport_send_check_condition_and_sense(cmd, ret, 0);
17921790
return -1;
17931791
}
17941792

@@ -1882,39 +1880,34 @@ static void srpt_handle_tsk_mgmt(struct srpt_rdma_ch *ch,
18821880
send_ioctx->tag = srp_tsk->tag;
18831881
tcm_tmr = srp_tmr_to_tcm(srp_tsk->tsk_mgmt_func);
18841882
if (tcm_tmr < 0) {
1885-
send_ioctx->cmd.se_cmd_flags |= SCF_SCSI_CDB_EXCEPTION;
18861883
send_ioctx->cmd.se_tmr_req->response =
18871884
TMR_TASK_MGMT_FUNCTION_NOT_SUPPORTED;
1888-
goto process_tmr;
1885+
goto fail;
18891886
}
18901887
res = core_tmr_alloc_req(cmd, NULL, tcm_tmr, GFP_KERNEL);
18911888
if (res < 0) {
1892-
send_ioctx->cmd.se_cmd_flags |= SCF_SCSI_CDB_EXCEPTION;
18931889
send_ioctx->cmd.se_tmr_req->response = TMR_FUNCTION_REJECTED;
1894-
goto process_tmr;
1890+
goto fail;
18951891
}
18961892

18971893
unpacked_lun = srpt_unpack_lun((uint8_t *)&srp_tsk->lun,
18981894
sizeof(srp_tsk->lun));
18991895
res = transport_lookup_tmr_lun(&send_ioctx->cmd, unpacked_lun);
19001896
if (res) {
19011897
pr_debug("rejecting TMR for LUN %lld\n", unpacked_lun);
1902-
send_ioctx->cmd.se_cmd_flags |= SCF_SCSI_CDB_EXCEPTION;
19031898
send_ioctx->cmd.se_tmr_req->response = TMR_LUN_DOES_NOT_EXIST;
1904-
goto process_tmr;
1899+
goto fail;
19051900
}
19061901

19071902
if (srp_tsk->tsk_mgmt_func == SRP_TSK_ABORT_TASK)
19081903
srpt_rx_mgmt_fn_tag(send_ioctx, srp_tsk->task_tag);
19091904

1910-
process_tmr:
19111905
kref_get(&send_ioctx->kref);
1912-
if (!(send_ioctx->cmd.se_cmd_flags & SCF_SCSI_CDB_EXCEPTION))
1913-
transport_generic_handle_tmr(&send_ioctx->cmd);
1914-
else
1915-
transport_send_check_condition_and_sense(cmd,
1916-
cmd->scsi_sense_reason, 0);
1917-
1906+
transport_generic_handle_tmr(&send_ioctx->cmd);
1907+
return;
1908+
fail:
1909+
kref_get(&send_ioctx->kref);
1910+
transport_send_check_condition_and_sense(cmd, 0, 0); // XXX:
19181911
}
19191912

19201913
/**

‎drivers/scsi/qla2xxx/tcm_qla2xxx.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -620,8 +620,8 @@ static void tcm_qla2xxx_handle_data_work(struct work_struct *work)
620620
return;
621621
}
622622

623-
cmd->se_cmd.scsi_sense_reason = TCM_CHECK_CONDITION_ABORT_CMD;
624-
transport_generic_request_failure(&cmd->se_cmd);
623+
transport_generic_request_failure(&cmd->se_cmd,
624+
TCM_CHECK_CONDITION_ABORT_CMD);
625625
return;
626626
}
627627

‎drivers/target/iscsi/iscsi_target.c‎

Lines changed: 28 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -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

993980
attach_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
}

‎drivers/target/iscsi/iscsi_target_core.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ struct iscsi_cmd {
474474
struct scatterlist *first_data_sg;
475475
u32 first_data_sg_off;
476476
u32 kmapped_nents;
477-
477+
sense_reason_t sense_reason;
478478
} ____cacheline_aligned;
479479

480480
struct iscsi_tmr_req {

‎drivers/target/iscsi/iscsi_target_erl1.c‎

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -929,11 +929,10 @@ int iscsit_execute_cmd(struct iscsi_cmd *cmd, int ooo)
929929
case ISCSI_OP_SCSI_CMD:
930930
/*
931931
* Go ahead and send the CHECK_CONDITION status for
932-
* any SCSI CDB exceptions that may have occurred, also
933-
* handle the SCF_SCSI_RESERVATION_CONFLICT case here as well.
932+
* any SCSI CDB exceptions that may have occurred.
934933
*/
935-
if (se_cmd->se_cmd_flags & SCF_SCSI_CDB_EXCEPTION) {
936-
if (se_cmd->scsi_sense_reason == TCM_RESERVATION_CONFLICT) {
934+
if (cmd->sense_reason) {
935+
if (cmd->sense_reason == TCM_RESERVATION_CONFLICT) {
937936
cmd->i_state = ISTATE_SEND_STATUS;
938937
spin_unlock_bh(&cmd->istate_lock);
939938
iscsit_add_cmd_to_response_queue(cmd, cmd->conn,
@@ -956,7 +955,7 @@ int iscsit_execute_cmd(struct iscsi_cmd *cmd, int ooo)
956955
* exception
957956
*/
958957
return transport_send_check_condition_and_sense(se_cmd,
959-
se_cmd->scsi_sense_reason, 0);
958+
cmd->sense_reason, 0);
960959
}
961960
/*
962961
* Special case for delayed CmdSN with Immediate
@@ -1013,7 +1012,7 @@ int iscsit_execute_cmd(struct iscsi_cmd *cmd, int ooo)
10131012
iscsit_add_cmd_to_response_queue(cmd, cmd->conn, cmd->i_state);
10141013
break;
10151014
case ISCSI_OP_SCSI_TMFUNC:
1016-
if (se_cmd->se_cmd_flags & SCF_SCSI_CDB_EXCEPTION) {
1015+
if (cmd->se_cmd.se_tmr_req->response) {
10171016
spin_unlock_bh(&cmd->istate_lock);
10181017
iscsit_add_cmd_to_response_queue(cmd, cmd->conn,
10191018
cmd->i_state);

0 commit comments

Comments
 (0)