Skip to content

Commit aaa00cc

Browse files
bvanasschemartinkpetersen
authored andcommitted
scsi: target/core: Fix TAS handling for aborted commands
The TASK ABORTED STATUS (TAS) bit is defined as follows in SAM: "TASK_ABORTED: this status shall be returned if a command is aborted by a command or task management function on another I_T nexus and the control mode page TAS bit is set to one". TAS handling is spread over the target core and the iSCSI target driver. If a LUN RESET is received, the target core will send the TASK_ABORTED response for all commands for which such a response has to be sent. If an ABORT TASK is received, only the iSCSI target driver will send the TASK_ABORTED response for the commands for which that response has to be sent. That is a bug since all target drivers have to honor the TAS bit. Fix this by moving the code that handles TAS from the iSCSI target driver into the target core. Additionally, if a command has been aborted, instead of sending the TASK_ABORTED status from the context that processes the SCSI command send it from the context of the ABORT TMF. The core_tmr_abort_task() change in this patch causes the CMD_T_TAS flag to be set if a TASK_ABORTED status has to be sent back to the initiator that submitted the command. If that flag has been set transport_cmd_finish_abort() will send the TASK_ABORTED response. Cc: Nicholas Bellinger <nab@linux-iscsi.org> Cc: Mike Christie <mchristi@redhat.com> Cc: Christoph Hellwig <hch@lst.de> Cc: David Disseldorp <ddiss@suse.de> Cc: Hannes Reinecke <hare@suse.de> Signed-off-by: Bart Van Assche <bvanassche@acm.org> Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
1 parent fbbd492 commit aaa00cc

6 files changed

Lines changed: 10 additions & 89 deletions

File tree

‎drivers/target/iscsi/iscsi_target.c‎

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1493,8 +1493,6 @@ __iscsit_check_dataout_hdr(struct iscsi_conn *conn, void *buf,
14931493
if (hdr->flags & ISCSI_FLAG_CMD_FINAL)
14941494
iscsit_stop_dataout_timer(cmd);
14951495

1496-
transport_check_aborted_status(se_cmd,
1497-
(hdr->flags & ISCSI_FLAG_CMD_FINAL));
14981496
return iscsit_dump_data_payload(conn, payload_length, 1);
14991497
}
15001498
} else {
@@ -1509,12 +1507,9 @@ __iscsit_check_dataout_hdr(struct iscsi_conn *conn, void *buf,
15091507
* TASK_ABORTED status.
15101508
*/
15111509
if (se_cmd->transport_state & CMD_T_ABORTED) {
1512-
if (hdr->flags & ISCSI_FLAG_CMD_FINAL)
1513-
if (--cmd->outstanding_r2ts < 1) {
1514-
iscsit_stop_dataout_timer(cmd);
1515-
transport_check_aborted_status(
1516-
se_cmd, 1);
1517-
}
1510+
if (hdr->flags & ISCSI_FLAG_CMD_FINAL &&
1511+
--cmd->outstanding_r2ts < 1)
1512+
iscsit_stop_dataout_timer(cmd);
15181513

15191514
return iscsit_dump_data_payload(conn, payload_length, 1);
15201515
}

‎drivers/target/iscsi/iscsi_target_erl1.c‎

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -943,20 +943,8 @@ int iscsit_execute_cmd(struct iscsi_cmd *cmd, int ooo)
943943
return 0;
944944
}
945945
spin_unlock_bh(&cmd->istate_lock);
946-
/*
947-
* Determine if delayed TASK_ABORTED status for WRITEs
948-
* should be sent now if no unsolicited data out
949-
* payloads are expected, or if the delayed status
950-
* should be sent after unsolicited data out with
951-
* ISCSI_FLAG_CMD_FINAL set in iscsi_handle_data_out()
952-
*/
953-
if (transport_check_aborted_status(se_cmd,
954-
(cmd->unsolicited_data == 0)) != 0)
946+
if (cmd->se_cmd.transport_state & CMD_T_ABORTED)
955947
return 0;
956-
/*
957-
* Otherwise send CHECK_CONDITION and sense for
958-
* exception
959-
*/
960948
return transport_send_check_condition_and_sense(se_cmd,
961949
cmd->sense_reason, 0);
962950
}
@@ -974,13 +962,7 @@ int iscsit_execute_cmd(struct iscsi_cmd *cmd, int ooo)
974962

975963
if (!(cmd->cmd_flags &
976964
ICF_NON_IMMEDIATE_UNSOLICITED_DATA)) {
977-
/*
978-
* Send the delayed TASK_ABORTED status for
979-
* WRITEs if no more unsolicitied data is
980-
* expected.
981-
*/
982-
if (transport_check_aborted_status(se_cmd, 1)
983-
!= 0)
965+
if (cmd->se_cmd.transport_state & CMD_T_ABORTED)
984966
return 0;
985967

986968
iscsit_set_dataout_sequence_values(cmd);
@@ -995,11 +977,7 @@ int iscsit_execute_cmd(struct iscsi_cmd *cmd, int ooo)
995977

996978
if ((cmd->data_direction == DMA_TO_DEVICE) &&
997979
!(cmd->cmd_flags & ICF_NON_IMMEDIATE_UNSOLICITED_DATA)) {
998-
/*
999-
* Send the delayed TASK_ABORTED status for WRITEs if
1000-
* no more nsolicitied data is expected.
1001-
*/
1002-
if (transport_check_aborted_status(se_cmd, 1) != 0)
980+
if (cmd->se_cmd.transport_state & CMD_T_ABORTED)
1003981
return 0;
1004982

1005983
iscsit_set_unsoliticed_dataout(cmd);

‎drivers/target/target_core_tmr.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,8 @@ void core_tmr_abort_task(
165165
printk("ABORT_TASK: Found referenced %s task_tag: %llu\n",
166166
se_cmd->se_tfo->fabric_name, ref_tag);
167167

168-
if (!__target_check_io_state(se_cmd, se_sess, 0))
168+
if (!__target_check_io_state(se_cmd, se_sess,
169+
dev->dev_attrib.emulate_tas))
169170
continue;
170171

171172
spin_unlock_irqrestore(&se_sess->sess_cmd_lock, flags);

‎drivers/target/target_core_transport.c‎

Lines changed: 2 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1805,7 +1805,7 @@ void transport_generic_request_failure(struct se_cmd *cmd,
18051805
if (cmd->transport_complete_callback)
18061806
cmd->transport_complete_callback(cmd, false, NULL);
18071807

1808-
if (transport_check_aborted_status(cmd, 1))
1808+
if (cmd->transport_state & CMD_T_ABORTED)
18091809
return;
18101810

18111811
switch (sense_reason) {
@@ -2012,8 +2012,6 @@ static bool target_handle_task_attr(struct se_cmd *cmd)
20122012
return true;
20132013
}
20142014

2015-
static int __transport_check_aborted_status(struct se_cmd *, int);
2016-
20172015
void target_execute_cmd(struct se_cmd *cmd)
20182016
{
20192017
/*
@@ -2023,7 +2021,7 @@ void target_execute_cmd(struct se_cmd *cmd)
20232021
* If the received CDB has already been aborted stop processing it here.
20242022
*/
20252023
spin_lock_irq(&cmd->t_state_lock);
2026-
if (__transport_check_aborted_status(cmd, 1)) {
2024+
if (cmd->transport_state & CMD_T_ABORTED) {
20272025
spin_unlock_irq(&cmd->t_state_lock);
20282026
return;
20292027
}
@@ -3237,55 +3235,6 @@ transport_send_check_condition_and_sense(struct se_cmd *cmd,
32373235
}
32383236
EXPORT_SYMBOL(transport_send_check_condition_and_sense);
32393237

3240-
static int __transport_check_aborted_status(struct se_cmd *cmd, int send_status)
3241-
__releases(&cmd->t_state_lock)
3242-
__acquires(&cmd->t_state_lock)
3243-
{
3244-
int ret;
3245-
3246-
assert_spin_locked(&cmd->t_state_lock);
3247-
WARN_ON_ONCE(!irqs_disabled());
3248-
3249-
if (!(cmd->transport_state & CMD_T_ABORTED))
3250-
return 0;
3251-
/*
3252-
* If cmd has been aborted but either no status is to be sent or it has
3253-
* already been sent, just return
3254-
*/
3255-
if (!send_status || !(cmd->se_cmd_flags & SCF_SEND_DELAYED_TAS)) {
3256-
if (send_status)
3257-
cmd->se_cmd_flags |= SCF_SEND_DELAYED_TAS;
3258-
return 1;
3259-
}
3260-
3261-
pr_debug("Sending delayed SAM_STAT_TASK_ABORTED status for CDB:"
3262-
" 0x%02x ITT: 0x%08llx\n", cmd->t_task_cdb[0], cmd->tag);
3263-
3264-
cmd->se_cmd_flags &= ~SCF_SEND_DELAYED_TAS;
3265-
cmd->scsi_status = SAM_STAT_TASK_ABORTED;
3266-
trace_target_cmd_complete(cmd);
3267-
3268-
spin_unlock_irq(&cmd->t_state_lock);
3269-
ret = cmd->se_tfo->queue_status(cmd);
3270-
if (ret)
3271-
transport_handle_queue_full(cmd, cmd->se_dev, ret, false);
3272-
spin_lock_irq(&cmd->t_state_lock);
3273-
3274-
return 1;
3275-
}
3276-
3277-
int transport_check_aborted_status(struct se_cmd *cmd, int send_status)
3278-
{
3279-
int ret;
3280-
3281-
spin_lock_irq(&cmd->t_state_lock);
3282-
ret = __transport_check_aborted_status(cmd, send_status);
3283-
spin_unlock_irq(&cmd->t_state_lock);
3284-
3285-
return ret;
3286-
}
3287-
EXPORT_SYMBOL(transport_check_aborted_status);
3288-
32893238
void transport_send_task_abort(struct se_cmd *cmd)
32903239
{
32913240
unsigned long flags;

‎include/target/target_core_base.h‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,6 @@ enum se_cmd_flags_table {
136136
SCF_SENT_CHECK_CONDITION = 0x00000800,
137137
SCF_OVERFLOW_BIT = 0x00001000,
138138
SCF_UNDERFLOW_BIT = 0x00002000,
139-
SCF_SEND_DELAYED_TAS = 0x00004000,
140139
SCF_ALUA_NON_OPTIMIZED = 0x00008000,
141140
SCF_PASSTHROUGH_SG_TO_MEM_NOALLOC = 0x00020000,
142141
SCF_COMPARE_AND_WRITE = 0x00080000,

‎include/target/target_core_fabric.h‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,6 @@ void target_execute_cmd(struct se_cmd *cmd);
171171
int transport_generic_free_cmd(struct se_cmd *, int);
172172

173173
bool transport_wait_for_tasks(struct se_cmd *);
174-
int transport_check_aborted_status(struct se_cmd *, int);
175174
int transport_send_check_condition_and_sense(struct se_cmd *,
176175
sense_reason_t, int);
177176
int target_get_sess_cmd(struct se_cmd *, bool);

0 commit comments

Comments
 (0)