From patchwork Wed May 31 20:52:46 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Christie X-Patchwork-Id: 9758107 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 8D6A260390 for ; Wed, 31 May 2017 20:53:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 80712284AF for ; Wed, 31 May 2017 20:53:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 75542284C7; Wed, 31 May 2017 20:53:01 +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 08CB1284AF for ; Wed, 31 May 2017 20:53:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751193AbdEaUxA (ORCPT ); Wed, 31 May 2017 16:53:00 -0400 Received: from mx1.redhat.com ([209.132.183.28]:46882 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751159AbdEaUw7 (ORCPT ); Wed, 31 May 2017 16:52:59 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 55799149; Wed, 31 May 2017 20:52:59 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 55799149 Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=mchristi@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 55799149 Received: from rh2.redhat.com (ovpn-126-11.rdu2.redhat.com [10.10.126.11]) by smtp.corp.redhat.com (Postfix) with ESMTP id B78FF94D94; Wed, 31 May 2017 20:52:58 +0000 (UTC) From: Mike Christie To: target-devel@vger.kernel.org, nab@linux-iscsi.org Cc: Mike Christie Subject: [RFC PATCH 09/13] usb f_tcm: remove transport_send_check_condition_and_sense use Date: Wed, 31 May 2017 15:52:46 -0500 Message-Id: <1496263970-7632-10-git-send-email-mchristi@redhat.com> In-Reply-To: <1496263970-7632-1-git-send-email-mchristi@redhat.com> References: <1496263970-7632-1-git-send-email-mchristi@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Wed, 31 May 2017 20:52:59 +0000 (UTC) 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 The usb submission failure path seems like it is broken because: 1. transport_send_check_condition_and_sense is called with from_transport=1 so the scsi sense value passed to it is not set. We just call queue_status and it looks like we will return a successful status. 2. It looks like if the cmd is not supported in get_cmd_dir we wanted to return a unsupported opcode error, but that error does not make sense for target_submit_cmd failures. To try and fail/cleanup the failed command, it relies on target_submit_cmd calling at least transport_init_se_cmd which seems like too much info for a fabric driver to have. This syncs f_tcm's submission failure handling with other fabric drivers. Instead of faking setup or assuming it is partially setup on failure, this patch just has f_tcm setup the sense, send it and release what it has allocated. It also fixes the sense code used for targe t_submit_cmd failures since the TCM_UNSUPPORTED_SCSI_OPCODE was only supposed to be for when when get_cmd_dir failed. Signed-off-by: Mike Christie --- drivers/usb/gadget/function/f_tcm.c | 38 +++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/drivers/usb/gadget/function/f_tcm.c b/drivers/usb/gadget/function/f_tcm.c index a82e2bd..b3dc7e8 100644 --- a/drivers/usb/gadget/function/f_tcm.c +++ b/drivers/usb/gadget/function/f_tcm.c @@ -1033,10 +1033,13 @@ static int usbg_send_read_response(struct se_cmd *se_cmd) return uasp_send_read_response(cmd); } +static void usbg_release_cmd(struct se_cmd *); + static void usbg_cmd_work(struct work_struct *work) { struct usbg_cmd *cmd = container_of(work, struct usbg_cmd, work); struct se_cmd *se_cmd; + sense_reason_t failure_reason; struct tcm_usbg_nexus *tv_nexus; struct usbg_tpg *tpg; int dir, flags = (TARGET_SCF_UNKNOWN_SIZE | TARGET_SCF_ACK_KREF); @@ -1046,24 +1049,24 @@ static void usbg_cmd_work(struct work_struct *work) tv_nexus = tpg->tpg_nexus; dir = get_cmd_dir(cmd->cmd_buf); if (dir < 0) { - transport_init_se_cmd(se_cmd, - tv_nexus->tvn_se_sess->se_tpg->se_tpg_tfo, - tv_nexus->tvn_se_sess, cmd->data_len, DMA_NONE, - cmd->prio_attr, cmd->sense_iu.sense); + failure_reason = TCM_UNSUPPORTED_SCSI_OPCODE; goto out; } if (target_submit_cmd(se_cmd, tv_nexus->tvn_se_sess, cmd->cmd_buf, cmd->sense_iu.sense, cmd->unpacked_lun, 0, - cmd->prio_attr, dir, flags) < 0) + cmd->prio_attr, dir, flags) < 0) { + failure_reason = TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE; goto out; + } return; out: - transport_send_check_condition_and_sense(se_cmd, - TCM_UNSUPPORTED_SCSI_OPCODE, 1); - transport_generic_free_cmd(&cmd->se_cmd, 0); + se_cmd->sense_buffer = cmd->sense_iu.sense; + transport_setup_sense(se_cmd, failure_reason); + usbg_send_status_response(&cmd->se_cmd); + usbg_release_cmd(&cmd->se_cmd); } static struct usbg_cmd *usbg_get_cmd(struct f_uas *fu, @@ -1086,8 +1089,6 @@ static struct usbg_cmd *usbg_get_cmd(struct f_uas *fu, return cmd; } -static void usbg_release_cmd(struct se_cmd *); - static int usbg_submit_command(struct f_uas *fu, void *cmdbuf, unsigned int len) { @@ -1165,6 +1166,7 @@ static void bot_cmd_work(struct work_struct *work) { struct usbg_cmd *cmd = container_of(work, struct usbg_cmd, work); struct se_cmd *se_cmd; + sense_reason_t failure_reason; struct tcm_usbg_nexus *tv_nexus; struct usbg_tpg *tpg; int dir; @@ -1174,24 +1176,24 @@ static void bot_cmd_work(struct work_struct *work) tv_nexus = tpg->tpg_nexus; dir = get_cmd_dir(cmd->cmd_buf); if (dir < 0) { - transport_init_se_cmd(se_cmd, - tv_nexus->tvn_se_sess->se_tpg->se_tpg_tfo, - tv_nexus->tvn_se_sess, cmd->data_len, DMA_NONE, - cmd->prio_attr, cmd->sense_iu.sense); + failure_reason = TCM_UNSUPPORTED_SCSI_OPCODE; goto out; } if (target_submit_cmd(se_cmd, tv_nexus->tvn_se_sess, cmd->cmd_buf, cmd->sense_iu.sense, cmd->unpacked_lun, - cmd->data_len, cmd->prio_attr, dir, 0) < 0) + cmd->data_len, cmd->prio_attr, dir, 0) < 0) { + failure_reason = TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE; goto out; + } return; out: - transport_send_check_condition_and_sense(se_cmd, - TCM_UNSUPPORTED_SCSI_OPCODE, 1); - transport_generic_free_cmd(&cmd->se_cmd, 0); + se_cmd->sense_buffer = cmd->sense_iu.sense; + transport_setup_sense(se_cmd, failure_reason); + usbg_send_status_response(&cmd->se_cmd); + usbg_release_cmd(&cmd->se_cmd); } static int bot_submit_command(struct f_uas *fu,