From patchwork Wed Jun 28 05:58:59 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Le Moal X-Patchwork-Id: 9813531 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 8F4B96020A for ; Wed, 28 Jun 2017 05:59:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 84601280CF for ; Wed, 28 Jun 2017 05:59:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 79128283FB; Wed, 28 Jun 2017 05:59: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 2B6632818E for ; Wed, 28 Jun 2017 05:59:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751696AbdF1F7t (ORCPT ); Wed, 28 Jun 2017 01:59:49 -0400 Received: from esa4.hgst.iphmx.com ([216.71.154.42]:26441 "EHLO esa4.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751685AbdF1F7t (ORCPT ); Wed, 28 Jun 2017 01:59:49 -0400 X-IronPort-AV: E=Sophos;i="5.40,274,1496073600"; d="scan'208";a="29784213" Received: from sjappemgw12.hgst.com (HELO sjappemgw11.hgst.com) ([199.255.44.66]) by ob1.hgst.iphmx.com with ESMTP; 28 Jun 2017 13:59:44 +0800 Received: from washi.fujisawa.hgst.com ([10.80.170.19]) by sjappemgw11.hgst.com with ESMTP; 27 Jun 2017 22:59:05 -0700 From: Damien Le Moal To: target-devel@vger.kernel.org, linux-scsi@vger.kernel.org, "Nicholas A . Bellinger" Cc: "Martin K . Petersen" , Hannes Reinecke , Bart Van Assche Subject: [PATCH 4/5] target: user: Fix sense data handling Date: Wed, 28 Jun 2017 14:58:59 +0900 Message-Id: <20170628055900.22889-5-damien.lemoal@wdc.com> X-Mailer: git-send-email 2.9.4 In-Reply-To: <20170628055900.22889-1-damien.lemoal@wdc.com> References: <20170628055900.22889-1-damien.lemoal@wdc.com> 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 the user request handler completed the request with a CHECK CONDITION status, tcmu_handle_completion() copies the command entry sense data into the session request structure sense data. However, the sense data length indicated by the field scsi_sense_length is not set and equal to 0, resulting in the copy being a no-op and failure to propagate the sense data back to the initiator. To fix this, properly set the session command sense data length and also set the session command SCF_TRANSPORT_TASK_SENSE flag to indicate that the command has valid sense data. Signed-off-by: Damien Le Moal Reviewed-by: Mike Christie --- drivers/target/target_core_user.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/target/target_core_user.c b/drivers/target/target_core_user.c index beb5f09..7426b4c 100644 --- a/drivers/target/target_core_user.c +++ b/drivers/target/target_core_user.c @@ -831,7 +831,9 @@ static void tcmu_handle_completion(struct tcmu_cmd *cmd, struct tcmu_cmd_entry * entry->rsp.scsi_status = SAM_STAT_CHECK_CONDITION; } else if (entry->rsp.scsi_status == SAM_STAT_CHECK_CONDITION) { memcpy(se_cmd->sense_buffer, entry->rsp.sense_buffer, - se_cmd->scsi_sense_length); + TRANSPORT_SENSE_BUFFER); + se_cmd->scsi_sense_length = TRANSPORT_SENSE_BUFFER; + se_cmd->se_cmd_flags |= SCF_TRANSPORT_TASK_SENSE; } else if (se_cmd->se_cmd_flags & SCF_BIDI) { /* Get Data-In buffer before clean up */ gather_data_area(udev, cmd, true);