From patchwork Sat Apr 25 14:33:29 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akinobu Mita X-Patchwork-Id: 6274691 Return-Path: X-Original-To: patchwork-linux-scsi@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id B6DD49F313 for ; Sat, 25 Apr 2015 14:34:14 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id BB0452022A for ; Sat, 25 Apr 2015 14:34:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id BC9B0201CD for ; Sat, 25 Apr 2015 14:34:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S964911AbbDYOeL (ORCPT ); Sat, 25 Apr 2015 10:34:11 -0400 Received: from mail-pa0-f45.google.com ([209.85.220.45]:35663 "EHLO mail-pa0-f45.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932427AbbDYOeJ (ORCPT ); Sat, 25 Apr 2015 10:34:09 -0400 Received: by pabtp1 with SMTP id tp1so77783614pab.2; Sat, 25 Apr 2015 07:34:08 -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=102trMk7bkTF+02LeyMWPWBJVwMZrloPFAaPZedlIFs=; b=oYtFjukBvANR5v3GWnuyg2IAUiXQRrtBoy7MDWShjRpS1gBdh795ItjpTpxjRFP9AA 7RXONW+Apz7he1ftvJEIx9KyWdqbEc1b8daCs4HA9Vai7UrOiqIHG6fOdWVlel2n1K0t ANDjR4xHJuggkkZw+8fU7raWICotJaOxQZuBg6moM9uyVYQuKTdS53lfPJKqtbJ3ERHs fqrWGVzFYP6pkQERlUPTiV3BYP3qOLiQxOQLjGErl6036mpluBTvVwKBC8PC49s1nrsM 5MwuPgzHXq0YuNr+mkzNzRjzuI7+8voAehqh4jBY9i0YeoNB+Jk2IYxeSVKqh5Q3rOCA MrwA== X-Received: by 10.68.176.3 with SMTP id ce3mr6570964pbc.122.1429972448599; Sat, 25 Apr 2015 07:34:08 -0700 (PDT) Received: from localhost.localdomain (KD106168100169.ppp-bb.dion.ne.jp. [106.168.100.169]) by mx.google.com with ESMTPSA id ts4sm14156224pbc.41.2015.04.25.07.34.04 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 25 Apr 2015 07:34:07 -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 v3 4/5] target: Fix sbc_dif_generate() and sbc_dif_verify() for WRITE SAME Date: Sat, 25 Apr 2015 23:33:29 +0900 Message-Id: <1429972410-7146-5-git-send-email-akinobu.mita@gmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1429972410-7146-1-git-send-email-akinobu.mita@gmail.com> References: <1429972410-7146-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 v2: - Handle odd SG mapping correctly instead of giving up drivers/target/target_core_sbc.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/drivers/target/target_core_sbc.c b/drivers/target/target_core_sbc.c index 33d2426..10c7cb9 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; +} + void sbc_dif_generate(struct se_cmd *cmd) { @@ -1187,6 +1205,7 @@ sbc_dif_generate(struct se_cmd *cmd) void *daddr, *paddr; int i, j, offset = 0; unsigned int block_size = dev->dev_attrib.block_size; + bool is_write_same = sbc_is_write_same(cmd); for_each_sg(cmd->t_prot_sg, psg, cmd->t_prot_nents, i) { paddr = kmap_atomic(sg_page(psg)) + psg->offset; @@ -1201,6 +1220,8 @@ sbc_dif_generate(struct se_cmd *cmd) offset -= dsg->length; kunmap_atomic(daddr); dsg = sg_next(dsg); + if (!dsg && is_write_same) + dsg = cmd->t_data_sg; daddr = kmap_atomic(sg_page(dsg)) + dsg->offset; } @@ -1211,6 +1232,8 @@ sbc_dif_generate(struct se_cmd *cmd) if (avail < block_size) { kunmap_atomic(daddr); dsg = sg_next(dsg); + if (!dsg && is_write_same) + dsg = cmd->t_data_sg; daddr = kmap_atomic(sg_page(dsg)) + dsg->offset; offset = block_size - avail; crc = crc_t10dif_update(crc, daddr, offset); @@ -1336,6 +1359,7 @@ sbc_dif_verify(struct se_cmd *cmd, sector_t start, unsigned int sectors, sense_reason_t rc; int dsg_off = 0; unsigned int block_size = dev->dev_attrib.block_size; + bool is_write_same = sbc_is_write_same(cmd); for (; psg && sector < start + sectors; psg = sg_next(psg)) { paddr = kmap_atomic(sg_page(psg)) + psg->offset; @@ -1351,6 +1375,8 @@ sbc_dif_verify(struct se_cmd *cmd, sector_t start, unsigned int sectors, dsg_off -= dsg->length; kunmap_atomic(daddr); dsg = sg_next(dsg); + if (!dsg && is_write_same) + dsg = cmd->t_data_sg; daddr = kmap_atomic(sg_page(dsg)) + dsg->offset; } @@ -1372,6 +1398,8 @@ sbc_dif_verify(struct se_cmd *cmd, sector_t start, unsigned int sectors, if (avail < block_size) { kunmap_atomic(daddr); dsg = sg_next(dsg); + if (!dsg && is_write_same) + dsg = cmd->t_data_sg; daddr = kmap_atomic(sg_page(dsg)) + dsg->offset; dsg_off = block_size - avail; crc = crc_t10dif_update(crc, daddr, dsg_off);