From patchwork Mon Apr 20 23:36:21 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akinobu Mita X-Patchwork-Id: 6244991 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 AB525BF4A6 for ; Mon, 20 Apr 2015 23:36:54 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 90BDA20435 for ; Mon, 20 Apr 2015 23:36:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A131D2026D for ; Mon, 20 Apr 2015 23:36:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753327AbbDTXgv (ORCPT ); Mon, 20 Apr 2015 19:36:51 -0400 Received: from mail-pd0-f179.google.com ([209.85.192.179]:36811 "EHLO mail-pd0-f179.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752914AbbDTXgu (ORCPT ); Mon, 20 Apr 2015 19:36:50 -0400 Received: by pdea3 with SMTP id a3so222840842pde.3; Mon, 20 Apr 2015 16:36:50 -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=fF3KpZcsbRYkX3RZ2gWg7vYlbfI5ykKy13Vsja87xX0=; b=VXAYEwhLi+ZEZXd4R8dfEBvZF7nsOUVF00aE6/RLl+ozs505J0bY34MDAxYs1iJyLa 7tZX7S2ZBRdOkUt2ByLEgUKcqvgdL/9IveZpoZ3AOYboXfK/YzDlD9i/QicXkmssN+S5 AJvq4v91Tuf3tb/MHC4Wh+1My1zvmSJmOEAL5AoDhe11t+3s+ZJRobmmf2snLkxEuwmV LgopfmWyDhZ2YCCEZKA4AiwS/D6wnOdXLcAT5naRBb23H7ilPA3/DjC+6YxrflCk+wd9 9/2npi7wr26ZqW2n3c07DBf6AnKNXFk3840TO5OB9I786cOY3nczXbVhGZ0LtJXxrw+V 3T6Q== X-Received: by 10.68.57.144 with SMTP id i16mr32512461pbq.162.1429573010330; Mon, 20 Apr 2015 16:36:50 -0700 (PDT) Received: from localhost.localdomain (KD106168100169.ppp-bb.dion.ne.jp. [106.168.100.169]) by mx.google.com with ESMTPSA id f4sm22995pdc.95.2015.04.20.16.36.46 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 20 Apr 2015 16:36:49 -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 3/4] target: Fix sbc_dif_generate() for WRITE SAME Date: Tue, 21 Apr 2015 08:36:21 +0900 Message-Id: <1429572982-6809-4-git-send-email-akinobu.mita@gmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1429572982-6809-1-git-send-email-akinobu.mita@gmail.com> References: <1429572982-6809-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() 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 --- drivers/target/target_core_sbc.c | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/drivers/target/target_core_sbc.c b/drivers/target/target_core_sbc.c index 982836b..9815c1b 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,15 @@ 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_sg->length != dev->dev_attrib.block_size || + cmd->t_data_nents != 1)) + 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 +1244,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; }