From patchwork Fri Feb 10 01:28:35 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: 9565763 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 769D460573 for ; Fri, 10 Feb 2017 01:29:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 67F5E28532 for ; Fri, 10 Feb 2017 01:29:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5CD5B2853B; Fri, 10 Feb 2017 01:29:09 +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 C5ACD28532 for ; Fri, 10 Feb 2017 01:29:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751074AbdBJB3I (ORCPT ); Thu, 9 Feb 2017 20:29:08 -0500 Received: from esa1.hgst.iphmx.com ([68.232.141.245]:18628 "EHLO esa1.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751208AbdBJB3E (ORCPT ); Thu, 9 Feb 2017 20:29:04 -0500 X-IronPort-AV: E=Sophos;i="5.33,348,1477929600"; d="scan'208";a="82349458" Received: from unknown (HELO milsmgep14.sandisk.com) ([63.163.107.225]) by ob1.hgst.iphmx.com with ESMTP; 10 Feb 2017 09:28:59 +0800 Received: from MILHUBIP03.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 F0.64.18895.7571D985; Thu, 9 Feb 2017 17:28:58 -0800 (PST) Received: from milsmgip11.sandisk.com (10.177.9.6) by MILHUBIP03.sdcorp.global.sandisk.com (10.177.9.96) with Microsoft SMTP Server id 14.3.319.2; Thu, 9 Feb 2017 17:28:55 -0800 X-AuditID: 0ac94371-d73ff700000049cf-06-589d1757d3f8 Received: from exp-402881.sdcorp.global.sandisk.com ( [10.177.9.6]) by (Symantec Messaging Gateway) with SMTP id 03.9F.11415.7571D985; Thu, 9 Feb 2017 17:28:55 -0800 (PST) From: Bart Van Assche To: "Nicholas A . Bellinger" CC: , Bart Van Assche , Hannes Reinecke , Christoph Hellwig , Andy Grover , David Disseldorp Subject: [PATCH v5 05/22] target: Make transport_wait_for_tasks() show what it is waiting for Date: Thu, 9 Feb 2017 17:28:35 -0800 Message-ID: <20170210012852.15735-6-bart.vanassche@sandisk.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170210012852.15735-1-bart.vanassche@sandisk.com> References: <20170210012852.15735-1-bart.vanassche@sandisk.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrFLMWRmVeSWpSXmKPExsXCddJ5kW6U+NwIgx2nzSz2z3rGZPH1/3QW iwVv9rJZrFx9lMmibfUZRovWpW+ZHNg87m8/wuSx+2YDm8f7fVfZPNZvucrisfl0tcfnTXIB bFFcNimpOZllqUX6dglcGcdff2Qt+KtYsXDDL7YGxg8yXYycHBICJhIL53xn6mLk4hASWMok sfliL5SzlVHifesqZpiqU+tPMUMkNjJKzNjczwSSYBMwkvj2fiYLiC0CZK/uWQbWzSxwm1Fi zePVbCAJYYFYiSM7v4PZLAIqEhuP32MHsXkF7CUOvV3GArFBXmJX20VWEJtTwEHi1ezrQDYH 0DZ7iR27DEBmSggsYpX49v00VK+gxMmZT8B6mQUkJA6+eAF2qZCAusTJJfOZJjAKzUJSNgtJ 2QJGplWMYrmZOcW56akFhiZ6xYl5KZnF2XrJ+bmbGCExULiD8fVt70OMAhyMSjy8E6rmRAix JpYVV+YeYpTgYFYS4b3PNzdCiDclsbIqtSg/vqg0J7X4EKM0B4uSOG+W7NQIIYH0xJLU7NTU gtQimCwTB6dUA+Pq+I6mkp63bQu38LDMv+fyTJE3cHuqjX1rTLZHrN5PrQiW1z4iM1fl+Szc tfP1yr731eH6k2d/ajhb8GaJ1neRsLULP6dfWX8ybIb5JsvZsW2L8ie9s2ly59VI35AqZpF+ 8PeuCUd+fM31zd3wVyX8tFN787LNWVEsP066nZuzddXxLTvqT21TYinOSDTUYi4qTgQAxX40 0X0CAAA= X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrJJMWRmVeSWpSXmKPExsXCtZGTTTdcfG6Ewd12AYv9s54xWRz82cZo 8fX/dBaLBW/2slmsXH2UyaJt9RlGi9alb5kc2D3ubz/C5LH7ZgObx/t9V9k8pq05z+SxfstV Fo/Np6s9Pm+SC2CP4rJJSc3JLEst0rdL4Mo4/voja8FfxYqFG36xNTB+kOli5OSQEDCROLX+ FHMXIxeHkMB6RokrO+YygiTYBIwkvr2fyQJiiwDZq3uWMYEUMQvcZZQ40/2JDSQhLBArcWTn dzCbRUBV4uTB1WDNvAL2EvNfTWCB2CAvsavtIiuIzSngIPFq9nUgmwNom73Ejl0GExi5FzAy rGIUy83MKc5NzywwNNQrTsxLySzO1kvOz93ECAmcyB2MTyeaH2Jk4uCUamDU5Gp+PbNeWVxM bcpxq6T/E26nP1K3/HxbJ+nbPm6bG11rJ5SG6RUmmP5Ov3A1R2HeC58rK9zSXk3bmybzyFPI WPhzs126xJNtcRa/F0t1XHrTzq9laPtvqfNNbf6Jx6d9m+ezuV33+0T+XbxZTZMLojfv+ZQU d+pU1HYLW0Xtu9Inv6z2t7ytxFKckWioxVxUnAgAJP5/rcwBAAA= 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 If transport_wait_for_tasks() takes too long, make it show the state of the command it is waiting for. Signed-off-by: Bart Van Assche Cc: Hannes Reinecke Cc: Christoph Hellwig Cc: Andy Grover Cc: David Disseldorp --- drivers/target/target_core_internal.h | 1 + drivers/target/target_core_transport.c | 79 +++++++++++++++++++++++++++++++++- 2 files changed, 79 insertions(+), 1 deletion(-) diff --git a/drivers/target/target_core_internal.h b/drivers/target/target_core_internal.h index 48de996ad28d..86880c6d6c8e 100644 --- a/drivers/target/target_core_internal.h +++ b/drivers/target/target_core_internal.h @@ -148,6 +148,7 @@ 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 *ctxt, 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); bool target_check_wce(struct se_device *dev); diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c index 27a6df77c078..5e0aaae96817 100644 --- a/drivers/target/target_core_transport.c +++ b/drivers/target/target_core_transport.c @@ -2650,6 +2650,81 @@ int target_put_sess_cmd(struct se_cmd *se_cmd) } EXPORT_SYMBOL(target_put_sess_cmd); +static const char *data_dir_name(enum dma_data_direction d) +{ + switch (d) { + case DMA_BIDIRECTIONAL: return "BIDI"; + case DMA_TO_DEVICE: return "WRITE"; + case DMA_FROM_DEVICE: return "READ"; + case DMA_NONE: return "NONE"; + } + + return "(?)"; +} + +static const char *cmd_state_name(enum transport_state_table t) +{ + switch (t) { + case TRANSPORT_NO_STATE: return "NO_STATE"; + case TRANSPORT_NEW_CMD: return "NEW_CMD"; + case TRANSPORT_WRITE_PENDING: return "WRITE_PENDING"; + case TRANSPORT_PROCESSING: return "PROCESSING"; + case TRANSPORT_COMPLETE: return "COMPLETE"; + case TRANSPORT_ISTATE_PROCESSING: + return "ISTATE_PROCESSING"; + case TRANSPORT_COMPLETE_QF_WP: return "COMPLETE_QF_WP"; + case TRANSPORT_COMPLETE_QF_OK: return "COMPLETE_QF_OK"; + } + + return "(?)"; +} + +static void target_append_str(char **str, const char *txt) +{ + char *prev = *str; + + *str = *str ? kasprintf(GFP_ATOMIC, "%s,%s", *str, txt) : + kstrdup(txt, GFP_ATOMIC); + kfree(prev); +} + +/* + * Convert a transport state bitmask into a string. The caller is + * responsible for freeing the returned pointer. + */ +static char *target_ts_to_str(u32 ts) +{ + char *str = NULL; + + if (ts & CMD_T_ABORTED) + target_append_str(&str, "aborted"); + if (ts & CMD_T_ACTIVE) + target_append_str(&str, "active"); + if (ts & CMD_T_COMPLETE) + target_append_str(&str, "complete"); + if (ts & CMD_T_SENT) + target_append_str(&str, "sent"); + if (ts & CMD_T_STOP) + target_append_str(&str, "stop"); + if (ts & CMD_T_FABRIC_STOP) + target_append_str(&str, "fabric_stop"); + + return str; +} + +void target_show_cmd(const char *ctxt, struct se_cmd *cmd) +{ + char *ts_str = target_ts_to_str(cmd->transport_state); + + pr_debug("%s: still waiting for %s with tag %#llx; dir %s i_state %d t_state %s len %d tgt_ref %d refcnt %d transport_state %s\n", + ctxt, cmd->se_cmd_flags & SCF_SCSI_TMR_CDB ? "tmf" : "cmd", + cmd->tag, data_dir_name(cmd->data_direction), + cmd->se_tfo->get_cmd_state(cmd), cmd_state_name(cmd->t_state), + cmd->data_length, atomic_read(&cmd->tgt_ref.refcount), + atomic_read(&cmd->cmd_kref.refcount), ts_str); + kfree(ts_str); +} + /** * target_sess_cmd_list_set_waiting - prevent new commands to be queued * @se_sess: session to flag @@ -2771,7 +2846,9 @@ __transport_wait_for_tasks(struct se_cmd *cmd, bool fabric_stop, spin_unlock_irqrestore(&cmd->t_state_lock, *flags); - wait_for_completion(&cmd->t_transport_stop_comp); + while (!wait_for_completion_timeout(&cmd->t_transport_stop_comp, + 180 * HZ)) + target_show_cmd(__func__, cmd); spin_lock_irqsave(&cmd->t_state_lock, *flags); cmd->transport_state &= ~(CMD_T_ACTIVE | CMD_T_STOP);