From patchwork Wed Feb 15 00:25:59 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 9573087 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 2913E600F6 for ; Wed, 15 Feb 2017 00:26:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1B498283F4 for ; Wed, 15 Feb 2017 00:26:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 103EC2842B; Wed, 15 Feb 2017 00:26:51 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F07B2283F4 for ; Wed, 15 Feb 2017 00:26:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751392AbdBOA0t (ORCPT ); Tue, 14 Feb 2017 19:26:49 -0500 Received: from esa1.hgst.iphmx.com ([68.232.141.245]:61609 "EHLO esa1.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751289AbdBOA0r (ORCPT ); Tue, 14 Feb 2017 19:26:47 -0500 X-IronPort-AV: E=Sophos;i="5.33,348,1477929600"; d="scan'208";a="86867856" Received: from unknown (HELO milsmgep15.sandisk.com) ([63.163.107.21]) by ob1.hgst.iphmx.com with ESMTP; 15 Feb 2017 08:26:21 +0800 Received: from MILHUBIP04.sdcorp.global.sandisk.com (Unknown_Domain [10.201.67.162]) (using TLS with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by (Symantec Messaging Gateway) with SMTP id 2C.E4.57638.C20A3A85; Tue, 14 Feb 2017 16:26:21 -0800 (PST) Received: from milsmgip11.sandisk.com (10.177.8.100) by MILHUBIP04.sdcorp.global.sandisk.com (10.177.9.97) with Microsoft SMTP Server id 14.3.319.2; Tue, 14 Feb 2017 16:26:16 -0800 X-AuditID: 0ac94369-26dee9800001e126-76-58a3a02cc762 Received: from exp-402881.sdcorp.global.sandisk.com ( [10.177.9.6]) by (Symantec Messaging Gateway) with SMTP id 2F.7D.11415.720A3A85; Tue, 14 Feb 2017 16:26:15 -0800 (PST) From: Bart Van Assche To: "Nicholas A . Bellinger" CC: , Bart Van Assche , Hannes Reinecke , Christoph Hellwig , Andy Grover , David Disseldorp Subject: [PATCH v6 20/33] target: Make ABORT and LUN RESET handling synchronous Date: Tue, 14 Feb 2017 16:25:59 -0800 Message-ID: <20170215002612.14566-21-bart.vanassche@sandisk.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170215002612.14566-1-bart.vanassche@sandisk.com> References: <20170215002612.14566-1-bart.vanassche@sandisk.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrJLMWRmVeSWpSXmKPExsXCddJ5ka7ugsURBq8WsFrsn/WMyeLr/+ks Fgve7GWzWLn6KJNF2+ozjBatS98yObB53N9+hMlj980GNo/3+66yeazfcpXFY/Ppao/Pm+QC 2KK4bFJSczLLUov07RK4MnYv+cBecKqXsaJ/+3fmBsYDJV2MnBwSAiYSuyccYexi5OIQEljK JDFhwxw2CGcHo0Trud9sMFV3FzQyg9hCAhsZJV6udAex2QSMJL69n8kCYosA2at7ljGBNDML 3GaUWPN4NVizsIC/xIbLaxhBbBYBVYmem3vAbF4BB4lrn+czQiyQl9jVdpEVxOYEis/YcRJo KAfQMnuJR2esIUoWsUocfuAG0SoocXLmE7C9zAISEgdfvIC6TV3i5JL5TBMYhWYhKZuFpGwB I9MqRrHczJzi3PTUAkNTveLEvJTM4my95PzcTYyQCMjcwXj3ifchRgEORiUe3hOyiyOEWBPL iitzDzFKcDArifCy1QOFeFMSK6tSi/Lji0pzUosPMUpzsCiJ856TmRohJJCeWJKanZpakFoE k2Xi4JRqYExve9EaJfasX/fp1mzRj4lLrZlfhXKE6TNM6EjSqTu6YqncLu4rKbW/FRefjCj9 72JTN+XRFsbWDsM5+hKzt+U88//+64gax/rTd1UjTCY9a2Q8k3WUgWfrs6Nm5kuObtDo+CJe rjstTF79Rvhu0UnlrHUfX2pUc3x0e9w0/8vX22K7btxKc1NiKc5INNRiLipOBACX4AJgfAIA AA== X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrJJMWRmVeSWpSXmKPExsXCtZGTTVd9weIIg+cL1Cz2z3rGZHHwZxuj xdf/01ksFrzZy2axcvVRJou21WcYLVqXvmVyYPe4v/0Ik8fumw1sHu/3XWXzmLbmPJPH+i1X WTw2n672+LxJLoA9issmJTUnsyy1SN8ugStj95IP7AWnehkr+rd/Z25gPFDSxcjJISFgInF3 QSNzFyMXh5DAekaJN/OvsoEk2ASMJL69n8kCYosA2at7ljGBFDEL3GWUONP9CaxIWMBfYsPl NYwgNouAqkTPzT1ANgcHr4CDRPfVAogF8hK72i6ygticQOEZO06ygJQICdhLPDpjPYGRewEj wypGsdzMnOLc9MwCQ0O94sS8lMzibL3k/NxNjJDAidzB+HSi+SFGJg5OqQbGpuXRVxUUn02e ZGXfJe1sKnXoQllXqAZDgoUeV8yFH+t2vDB+eOhXrLjxEsYTR5IFAlR4bDwZVadzbfPJWnJH f/fv3oYMBnHBq/n3D76ZFhkfZOWvLJ5fNNOv9tLJtB3NTIlOaXOfitfsefRr/valmvrdIk2m k1VCVyp9fS4eftjy5c5H+oZKLMUZiYZazEXFiQARPyI0zAEAAA== MIME-Version: 1.0 Sender: target-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: target-devel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Instead of invoking target driver callback functions from the context that handles an abort or LUN RESET task management function, only set the abort flag from that context and perform the actual abort handling from the context of the regular command processing flow. This approach has the following advantages: - The task management function code becomes much easier to read and to verify since the number of potential race conditions against the command processing flow is strongly reduced. - It is no longer needed to store the command state into the command itself since that information is no longer needed from the context where a task management function is processed. Notes: - With this patch applied for SCSI commands the CMD_T_ABORTED flag is checked at two stages by the target core during command execution: just before local execution of a command starts (see also target_execute_cmd()) and also just before the response is sent (see also target_complete_cmd()). Signed-off-by: Bart Van Assche Cc: Hannes Reinecke Cc: Christoph Hellwig Cc: Andy Grover Cc: David Disseldorp --- drivers/target/target_core_internal.h | 2 - drivers/target/target_core_tmr.c | 66 +++++------ drivers/target/target_core_transport.c | 208 +++++++++++++-------------------- include/target/target_core_base.h | 1 + 4 files changed, 108 insertions(+), 169 deletions(-) diff --git a/drivers/target/target_core_internal.h b/drivers/target/target_core_internal.h index b91cb1aca235..1f31bc4137a9 100644 --- a/drivers/target/target_core_internal.h +++ b/drivers/target/target_core_internal.h @@ -138,7 +138,6 @@ int init_se_kmem_caches(void); void release_se_kmem_caches(void); u32 scsi_get_new_index(scsi_index_t); void transport_subsystem_check_init(void); -void transport_cmd_finish_abort(struct se_cmd *, int); unsigned char *transport_dump_cmd_direction(struct se_cmd *); void transport_dump_dev_state(struct se_device *, char *, int *); void transport_dump_dev_info(struct se_device *, struct se_lun *, @@ -149,7 +148,6 @@ int transport_dump_vpd_ident_type(struct t10_vpd *, unsigned char *, int); int transport_dump_vpd_ident(struct t10_vpd *, unsigned char *, int); void transport_clear_lun_ref(struct se_lun *); int __target_put_sess_cmd(struct se_cmd *se_cmd); -void transport_send_task_abort(struct se_cmd *); void target_show_cmd(const char *pfx, struct se_cmd *cmd); sense_reason_t target_cmd_size_check(struct se_cmd *cmd, unsigned int size); void target_qf_do_work(struct work_struct *work); diff --git a/drivers/target/target_core_tmr.c b/drivers/target/target_core_tmr.c index 16e748eb32d2..eddc3fa649f1 100644 --- a/drivers/target/target_core_tmr.c +++ b/drivers/target/target_core_tmr.c @@ -75,25 +75,6 @@ void core_tmr_release_req(struct se_tmr_req *tmr) kfree(tmr); } -static void core_tmr_handle_tas_abort(struct se_cmd *cmd, int tas) -{ - unsigned long flags; - bool remove = true, send_tas; - /* - * TASK ABORTED status (TAS) bit support - */ - spin_lock_irqsave(&cmd->t_state_lock, flags); - send_tas = (cmd->transport_state & CMD_T_TAS); - spin_unlock_irqrestore(&cmd->t_state_lock, flags); - - if (send_tas) { - remove = false; - transport_send_task_abort(cmd); - } - - transport_cmd_finish_abort(cmd, remove); -} - static int target_check_cdb_and_preempt(struct list_head *list, struct se_cmd *cmd) { @@ -186,6 +167,7 @@ void core_tmr_abort_task( 0)) continue; + se_cmd->send_abort_response = false; list_del_init(&se_cmd->se_cmd_list); spin_unlock_irqrestore(&se_sess->sess_cmd_lock, flags); @@ -197,10 +179,9 @@ void core_tmr_abort_task( WARN_ON_ONCE(transport_lookup_tmr_lun(tmr->task_cmd, se_cmd->orig_fe_lun) < 0); - cancel_work_sync(&se_cmd->work); - transport_wait_for_tasks(se_cmd); + while (!wait_for_completion_timeout(&se_cmd->complete, 180 * HZ)) + target_show_cmd("abort: still waiting for ", se_cmd); - transport_cmd_finish_abort(se_cmd, true); __target_put_sess_cmd(se_cmd); printk("ABORT_TASK: Sending TMR_FUNCTION_COMPLETE for" @@ -292,14 +273,31 @@ static void core_tmr_drain_tmr_list( (preempt_and_abort_list) ? "Preempt" : "", tmr_p, tmr_p->function, tmr_p->response, cmd->t_state); - cancel_work_sync(&cmd->work); - transport_wait_for_tasks(cmd); - - transport_cmd_finish_abort(cmd, 1); + while (!wait_for_completion_timeout(&cmd->complete, 180 * HZ)) + target_show_cmd("drain tmr list: still waiting for ", + cmd); __target_put_sess_cmd(cmd); } } +/** + * core_tmr_drain_state_list() - abort SCSI commands associated with a device + * + * @dev: Device for which to abort outstanding SCSI commands. + * @prout_cmd: Pointer to the SCSI PREEMPT AND ABORT if this function is called + * to realize the PREEMPT AND ABORT functionality. + * @tmr_sess: Session through which the LUN RESET has been received. + * @tas: Task Aborted Status (TAS) bit from the SCSI control mode page. + * A quote from SPC-4, paragraph "7.5.10 Control mode page": + * "A task aborted status (TAS) bit set to zero specifies that + * aborted commands shall be terminated by the device server + * without any response to the application client. A TAS bit set + * to one specifies that commands aborted by the actions of an I_T + * nexus other than the I_T nexus on which the command was + * received shall be completed with TASK ABORTED status." + * @preempt_and_abort_list: For the PREEMPT AND ABORT functionality, a list + * with registrations that will be preempted. + */ static void core_tmr_drain_state_list( struct se_device *dev, struct se_cmd *prout_cmd, @@ -308,6 +306,7 @@ static void core_tmr_drain_state_list( struct list_head *preempt_and_abort_list) { LIST_HEAD(drain_task_list); + struct se_node_acl *tmr_nacl = tmr_sess ? tmr_sess->se_node_acl : NULL; struct se_session *sess; struct se_cmd *cmd, *next; unsigned long flags; @@ -362,6 +361,8 @@ static void core_tmr_drain_state_list( list_move_tail(&cmd->state_list, &drain_task_list); cmd->state_active = false; + if (tmr_nacl && tmr_nacl != cmd->se_sess->se_node_acl && tas) + cmd->send_abort_response = true; } spin_unlock_irqrestore(&dev->execute_task_lock, flags); @@ -374,17 +375,8 @@ static void core_tmr_drain_state_list( cmd->tag, (preempt_and_abort_list) ? "preempt" : "", cmd->pr_res_key); - /* - * If the command may be queued onto a workqueue cancel it now. - * - * This is equivalent to removal from the execute queue in the - * loop above, but we do it down here given that - * cancel_work_sync may block. - */ - cancel_work_sync(&cmd->work); - transport_wait_for_tasks(cmd); - - core_tmr_handle_tas_abort(cmd, tas); + while (!wait_for_completion_timeout(&cmd->complete, 180 * HZ)) + target_show_cmd("LUN RESET: still waiting for ", cmd); __target_put_sess_cmd(cmd); } } diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c index d03d4a6d20e6..41e40cebcd98 100644 --- a/drivers/target/target_core_transport.c +++ b/drivers/target/target_core_transport.c @@ -651,25 +651,6 @@ static void transport_lun_remove_cmd(struct se_cmd *cmd) percpu_ref_put(&lun->lun_ref); } -void transport_cmd_finish_abort(struct se_cmd *cmd, int remove) -{ - bool ack_kref = (cmd->se_cmd_flags & SCF_ACK_KREF); - - if (cmd->se_cmd_flags & SCF_SE_LUN_CMD) - transport_lun_remove_cmd(cmd); - /* - * Allow the fabric driver to unmap any resources before - * releasing the descriptor via TFO->release_cmd() - */ - if (remove) - cmd->se_tfo->aborted_task(cmd); - - if (transport_cmd_check_stop_to_fabric(cmd)) - return; - if (remove && ack_kref) - transport_put_cmd(cmd); -} - static void target_complete_failure_work(struct work_struct *work) { struct se_cmd *cmd = container_of(work, struct se_cmd, work); @@ -701,14 +682,64 @@ static unsigned char *transport_get_sense_buffer(struct se_cmd *cmd) return cmd->sense_buffer; } +static void target_handle_abort(struct se_cmd *cmd) +{ + pr_debug("tag %#llx: send_abort_response = %d\n", cmd->tag, + cmd->send_abort_response); + + transport_lun_remove_cmd(cmd); + + if (cmd->send_abort_response) { + if (!(cmd->se_cmd_flags & SCF_SCSI_TMR_CDB)) { + cmd->scsi_status = SAM_STAT_TASK_ABORTED; + pr_debug("Setting SAM_STAT_TASK_ABORTED status for CDB: 0x%02x, ITT: 0x%08llx\n", + cmd->t_task_cdb[0], cmd->tag); + trace_target_cmd_complete(cmd); + cmd->se_tfo->queue_status(cmd); + } else { + cmd->se_tmr_req->response = TMR_FUNCTION_REJECTED; + cmd->se_tfo->queue_tm_rsp(cmd); + } + } else { + /* + * Allow the fabric driver to unmap any resources before + * releasing the descriptor via TFO->release_cmd() + */ + cmd->se_tfo->aborted_task(cmd); + /* + * To do: establish a unit attention condition on the I_T + * nexus associated with cmd. See also the paragraph "Aborting + * commands" in SAM. + */ + if (cmd->se_cmd_flags & SCF_ACK_KREF) + target_put_sess_cmd(cmd); + } + transport_cmd_check_stop_to_fabric(cmd); +} + +static void target_abort_work(struct work_struct *work) +{ + struct se_cmd *cmd = container_of(work, struct se_cmd, work); + + target_handle_abort(cmd); +} + +/* May be called from interrupt context so must not sleep. */ void target_complete_cmd(struct se_cmd *cmd, u8 scsi_status) { struct se_device *dev = cmd->se_dev; int success = scsi_status == GOOD; unsigned long flags; - cmd->scsi_status = scsi_status; + if (cmd->transport_state & CMD_T_ABORTED) { + INIT_WORK(&cmd->work, target_abort_work); + goto queue_work; + } else if (cmd->transport_state & CMD_T_STOP) { + complete_all(&cmd->t_transport_stop_comp); + return; + } + cmd->scsi_status = scsi_status; spin_lock_irqsave(&cmd->t_state_lock, flags); @@ -720,16 +751,7 @@ void target_complete_cmd(struct se_cmd *cmd, u8 scsi_status) success = 1; } - /* - * Check for case where an explicit ABORT_TASK has been received - * and transport_wait_for_tasks() will be waiting for completion.. - */ - if (cmd->transport_state & CMD_T_ABORTED || - cmd->transport_state & CMD_T_STOP) { - spin_unlock_irqrestore(&cmd->t_state_lock, flags); - complete_all(&cmd->t_transport_stop_comp); - return; - } else if (!success) { + if (!success) { INIT_WORK(&cmd->work, target_complete_failure_work); } else { INIT_WORK(&cmd->work, target_complete_ok_work); @@ -739,6 +761,7 @@ void target_complete_cmd(struct se_cmd *cmd, u8 scsi_status) cmd->transport_state |= (CMD_T_COMPLETE | CMD_T_ACTIVE); spin_unlock_irqrestore(&cmd->t_state_lock, flags); +queue_work: if (cmd->se_cmd_flags & SCF_USE_CPUID) queue_work_on(cmd->cpuid, target_completion_wq, &cmd->work); else @@ -1656,8 +1679,10 @@ void transport_generic_request_failure(struct se_cmd *cmd, { int ret = 0, post_ret = 0; - if (transport_check_aborted_status(cmd, 1)) + if (transport_check_aborted_status(cmd, 1)) { + target_handle_abort(cmd); return; + } pr_debug("-----[ Storage Engine Exception; sense_reason %d\n", sense_reason); @@ -1888,6 +1913,7 @@ void target_execute_cmd(struct se_cmd *cmd) spin_lock_irq(&cmd->t_state_lock); if (__transport_check_aborted_status(cmd, 1)) { spin_unlock_irq(&cmd->t_state_lock); + target_handle_abort(cmd); return; } if (cmd->transport_state & CMD_T_STOP) { @@ -2496,16 +2522,12 @@ static void target_wait_free_cmd(struct se_cmd *cmd, bool *aborted, bool *tas) int transport_generic_free_cmd(struct se_cmd *cmd, int wait_for_tasks) { - int ret = 0; bool aborted = false, tas = false; if (wait_for_tasks) target_wait_free_cmd(cmd, &aborted, &tas); - if (!(cmd->se_cmd_flags & SCF_SE_LUN_CMD)) { - if (!aborted || tas) - ret = transport_put_cmd(cmd); - } else { + if (cmd->se_cmd_flags & SCF_SE_LUN_CMD) { /* * Handle WRITE failure case where transport_generic_new_cmd() * has already added se_cmd to state_list, but fabric has @@ -2516,22 +2538,8 @@ int transport_generic_free_cmd(struct se_cmd *cmd, int wait_for_tasks) if (cmd->se_lun) transport_lun_remove_cmd(cmd); - - if (!aborted || tas) - ret = transport_put_cmd(cmd); } - /* - * If the task has been internally aborted due to TMR ABORT_TASK - * or LUN_RESET, target_core_tmr.c is responsible for performing - * the remaining calls to target_put_sess_cmd(), and not the - * callers of this function. - */ - if (aborted) { - pr_debug("Detected CMD_T_ABORTED for ITT: %llu\n", cmd->tag); - transport_put_cmd(cmd); - ret = 1; - } - return ret; + return transport_put_cmd(cmd); } EXPORT_SYMBOL(transport_generic_free_cmd); @@ -3119,16 +3127,7 @@ static int __transport_check_aborted_status(struct se_cmd *cmd, int send_status) return 1; } - pr_debug("Sending delayed SAM_STAT_TASK_ABORTED status for CDB:" - " 0x%02x ITT: 0x%08llx\n", cmd->t_task_cdb[0], cmd->tag); - cmd->se_cmd_flags &= ~SCF_SEND_DELAYED_TAS; - cmd->scsi_status = SAM_STAT_TASK_ABORTED; - trace_target_cmd_complete(cmd); - - spin_unlock_irq(&cmd->t_state_lock); - cmd->se_tfo->queue_status(cmd); - spin_lock_irq(&cmd->t_state_lock); return 1; } @@ -3145,62 +3144,15 @@ int transport_check_aborted_status(struct se_cmd *cmd, int send_status) } EXPORT_SYMBOL(transport_check_aborted_status); -void transport_send_task_abort(struct se_cmd *cmd) -{ - unsigned long flags; - - spin_lock_irqsave(&cmd->t_state_lock, flags); - if (cmd->se_cmd_flags & (SCF_SENT_CHECK_CONDITION)) { - spin_unlock_irqrestore(&cmd->t_state_lock, flags); - return; - } - spin_unlock_irqrestore(&cmd->t_state_lock, flags); - - /* - * If there are still expected incoming fabric WRITEs, we wait - * until until they have completed before sending a TASK_ABORTED - * response. This response with TASK_ABORTED status will be - * queued back to fabric module by transport_check_aborted_status(). - */ - if (cmd->data_direction == DMA_TO_DEVICE) { - if (cmd->se_tfo->write_pending_status(cmd) != 0) { - spin_lock_irqsave(&cmd->t_state_lock, flags); - if (cmd->se_cmd_flags & SCF_SEND_DELAYED_TAS) { - spin_unlock_irqrestore(&cmd->t_state_lock, flags); - goto send_abort; - } - cmd->se_cmd_flags |= SCF_SEND_DELAYED_TAS; - spin_unlock_irqrestore(&cmd->t_state_lock, flags); - return; - } - } -send_abort: - cmd->scsi_status = SAM_STAT_TASK_ABORTED; - - transport_lun_remove_cmd(cmd); - - pr_debug("Setting SAM_STAT_TASK_ABORTED status for CDB: 0x%02x, ITT: 0x%08llx\n", - cmd->t_task_cdb[0], cmd->tag); - - trace_target_cmd_complete(cmd); - cmd->se_tfo->queue_status(cmd); -} - static void target_tmr_work(struct work_struct *work) { struct se_cmd *cmd = container_of(work, struct se_cmd, work); struct se_device *dev = cmd->se_dev; struct se_tmr_req *tmr = cmd->se_tmr_req; - unsigned long flags; int ret; - spin_lock_irqsave(&cmd->t_state_lock, flags); - if (cmd->transport_state & CMD_T_ABORTED) { - tmr->response = TMR_FUNCTION_REJECTED; - spin_unlock_irqrestore(&cmd->t_state_lock, flags); - goto check_stop; - } - spin_unlock_irqrestore(&cmd->t_state_lock, flags); + if (cmd->transport_state & CMD_T_ABORTED) + goto aborted; switch (tmr->function) { case TMR_ABORT_TASK: @@ -3234,42 +3186,38 @@ static void target_tmr_work(struct work_struct *work) break; } - spin_lock_irqsave(&cmd->t_state_lock, flags); - if (cmd->transport_state & CMD_T_ABORTED) { - spin_unlock_irqrestore(&cmd->t_state_lock, flags); - goto check_stop; - } - spin_unlock_irqrestore(&cmd->t_state_lock, flags); + if (cmd->transport_state & CMD_T_ABORTED) + goto aborted; cmd->se_tfo->queue_tm_rsp(cmd); -check_stop: transport_cmd_check_stop_to_fabric(cmd); + return; + +aborted: + cmd->send_abort_response = true; + target_handle_abort(cmd); } int transport_generic_handle_tmr( struct se_cmd *cmd) { unsigned long flags; - bool aborted = false; - spin_lock_irqsave(&cmd->t_state_lock, flags); if (cmd->transport_state & CMD_T_ABORTED) { - aborted = true; - } else { - cmd->t_state = TRANSPORT_ISTATE_PROCESSING; - cmd->transport_state |= CMD_T_ACTIVE; - } - spin_unlock_irqrestore(&cmd->t_state_lock, flags); - - if (aborted) { - pr_warn_ratelimited("handle_tmr caught CMD_T_ABORTED TMR %d" - "ref_tag: %llu tag: %llu\n", cmd->se_tmr_req->function, - cmd->se_tmr_req->ref_task_tag, cmd->tag); - transport_cmd_check_stop_to_fabric(cmd); + pr_warn_ratelimited("handle_tmr caught CMD_T_ABORTED TMR %d ref_tag: %llu tag: %llu\n", + cmd->se_tmr_req->function, + cmd->se_tmr_req->ref_task_tag, cmd->tag); + cmd->send_abort_response = true; + target_handle_abort(cmd); return 0; } + spin_lock_irqsave(&cmd->t_state_lock, flags); + cmd->t_state = TRANSPORT_ISTATE_PROCESSING; + cmd->transport_state |= CMD_T_ACTIVE; + spin_unlock_irqrestore(&cmd->t_state_lock, flags); + INIT_WORK(&cmd->work, target_tmr_work); schedule_work(&cmd->work); return 0; diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h index 6cd207fa1dc8..d06f2678f988 100644 --- a/include/target/target_core_base.h +++ b/include/target/target_core_base.h @@ -444,6 +444,7 @@ struct se_cmd { unsigned cmd_wait_set:1; unsigned unknown_data_length:1; bool state_active:1; + bool send_abort_response:1; u64 tag; /* SAM command identifier aka task tag */ /* Delay for ALUA Active/NonOptimized state access in milliseconds */ int alua_nonop_delay;