From patchwork Tue Apr 21 23:46:16 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akinobu Mita X-Patchwork-Id: 6254351 Return-Path: X-Original-To: patchwork-linux-scsi@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 9043EBF4A6 for ; Tue, 21 Apr 2015 23:46:50 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 989C12035B for ; Tue, 21 Apr 2015 23:46:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A300820328 for ; Tue, 21 Apr 2015 23:46:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965283AbbDUXqr (ORCPT ); Tue, 21 Apr 2015 19:46:47 -0400 Received: from mail-pd0-f175.google.com ([209.85.192.175]:32856 "EHLO mail-pd0-f175.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965273AbbDUXqq (ORCPT ); Tue, 21 Apr 2015 19:46:46 -0400 Received: by pdbnk13 with SMTP id nk13so256377773pdb.0; Tue, 21 Apr 2015 16:46:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=YVIgP+c+TXtL86ArqtKcv88n4Qmh6gIjaidzIvU/6sQ=; b=yKUeffrb679jlIzRHN4Ojjm40CBMnRWSDRKz5oeJi7+7qKZ+133kkhmeflLNTPpCkc xvX3k081Pe2Zi1jZIDmaAYLJuTpCDWcE/I7GlSh5T2aDg0i3/9BYjrnhWt5zpET9vPx/ OH4ksRTV1HMJTjEBfmcm/7bqXAWKyYtfLzcivK6IXIx9klMTorbB6MMH9U+SpwiTTF6l 1NO8Vr3QulWOkwsRwRFzkGT6MbobKbrljTGGBSvbmD/IWnBc9kyjSkp1PgsOaCmpq1Fu l+1bk1qBSefv5sB9aZ0uUh9Sj9XQX90zmNxAEvmlIIdMf0DLMXgTIy+GMTcpZ1zw5ij+ E2gg== X-Received: by 10.66.150.196 with SMTP id uk4mr13203825pab.54.1429660005983; Tue, 21 Apr 2015 16:46:45 -0700 (PDT) Received: from localhost.localdomain (KD106168100169.ppp-bb.dion.ne.jp. [106.168.100.169]) by mx.google.com with ESMTPSA id wh6sm3060643pbc.96.2015.04.21.16.46.42 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 21 Apr 2015 16:46:45 -0700 (PDT) From: Akinobu Mita To: target-devel@vger.kernel.org Cc: Akinobu Mita , Nicholas Bellinger , Sagi Grimberg , "Martin K. Petersen" , Christoph Hellwig , "James E.J. Bottomley" , linux-scsi@vger.kernel.org Subject: [PATCH v2 3/4] target: Fix sbc_dif_generate() and sbc_dif_verify() for WRITE SAME Date: Wed, 22 Apr 2015 08:46:16 +0900 Message-Id: <1429659977-7156-4-git-send-email-akinobu.mita@gmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1429659977-7156-1-git-send-email-akinobu.mita@gmail.com> References: <1429659977-7156-1-git-send-email-akinobu.mita@gmail.com> Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP For WRITE SAME, data transfer memory only contains a single block but protection information is required for all blocks that are written by the command. This makes sbc_dif_generate() and sbc_dif_verify() work for WRITE_SAME. Signed-off-by: Akinobu Mita Cc: Nicholas Bellinger Cc: Sagi Grimberg Cc: "Martin K. Petersen" Cc: Christoph Hellwig Cc: "James E.J. Bottomley" Cc: target-devel@vger.kernel.org Cc: linux-scsi@vger.kernel.org --- * Changes from v1: - Fix sbc_dif_verify() for WRITE_SAME command drivers/target/target_core_sbc.c | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/drivers/target/target_core_sbc.c b/drivers/target/target_core_sbc.c index 982836b..5577829 100644 --- a/drivers/target/target_core_sbc.c +++ b/drivers/target/target_core_sbc.c @@ -1177,6 +1177,24 @@ err: } EXPORT_SYMBOL(sbc_execute_unmap); +static bool sbc_is_write_same(struct se_cmd *cmd) +{ + u16 service_action; + + switch (cmd->t_task_cdb[0]) { + case WRITE_SAME: + case WRITE_SAME_16: + return true; + case VARIABLE_LENGTH_CMD: + service_action = get_unaligned_be16(&cmd->t_task_cdb[8]); + if (service_action == WRITE_SAME_32) + return true; + break; + } + + return false; +} + sense_reason_t sbc_dif_generate(struct se_cmd *cmd) { @@ -1185,8 +1203,14 @@ sbc_dif_generate(struct se_cmd *cmd) struct scatterlist *dsg, *psg = cmd->t_prot_sg; sector_t sector = cmd->t_task_lba; void *daddr, *paddr; - int i, j, offset = 0; + int i, j, offset = 0, left = cmd->prot_length; + bool is_write_same = sbc_is_write_same(cmd); + if (is_write_same && (cmd->t_data_nents != 1 || + cmd->t_data_sg->length != dev->dev_attrib.block_size)) + return TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE; + +repeat: for_each_sg(cmd->t_data_sg, dsg, cmd->t_data_nents, i) { if (dsg->length % dev->dev_attrib.block_size) return TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE; @@ -1219,11 +1243,14 @@ sbc_dif_generate(struct se_cmd *cmd) sector++; offset += sizeof(struct se_dif_v1_tuple); + left -= sizeof(struct se_dif_v1_tuple); } kunmap_atomic(paddr); kunmap_atomic(daddr); } + if (is_write_same && left) + goto repeat; return 0; } @@ -1326,7 +1353,14 @@ sbc_dif_verify(struct se_cmd *cmd, sector_t start, unsigned int sectors, void *daddr, *paddr; int i, j; sense_reason_t rc; + int left = cmd->prot_length; + bool is_write_same = sbc_is_write_same(cmd); + + if (is_write_same && (cmd->t_data_nents != 1 || + cmd->t_data_sg->length != dev->dev_attrib.block_size)) + return TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE; +repeat: for_each_sg(cmd->t_data_sg, dsg, cmd->t_data_nents, i) { if (dsg->length % dev->dev_attrib.block_size) return TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE; @@ -1368,11 +1402,14 @@ sbc_dif_verify(struct se_cmd *cmd, sector_t start, unsigned int sectors, sector++; ei_lba++; psg_off += sizeof(struct se_dif_v1_tuple); + left -= sizeof(struct se_dif_v1_tuple); } kunmap_atomic(paddr - psg->offset); kunmap_atomic(daddr - dsg->offset); } + if (is_write_same && left) + goto repeat; return 0; }