From patchwork Tue Jun 24 16:27:46 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sagi Grimberg X-Patchwork-Id: 4411301 Return-Path: X-Original-To: patchwork-linux-rdma@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 11A92BEEAA for ; Tue, 24 Jun 2014 16:27:59 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 3F80D2034B for ; Tue, 24 Jun 2014 16:27:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 37B252035C for ; Tue, 24 Jun 2014 16:27:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S964865AbaFXQ1z (ORCPT ); Tue, 24 Jun 2014 12:27:55 -0400 Received: from mail-we0-f180.google.com ([74.125.82.180]:52413 "EHLO mail-we0-f180.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S964886AbaFXQ1y (ORCPT ); Tue, 24 Jun 2014 12:27:54 -0400 Received: by mail-we0-f180.google.com with SMTP id x48so622610wes.25 for ; Tue, 24 Jun 2014 09:27:51 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:message-id:date:from:user-agent:mime-version:to :cc:subject:references:in-reply-to:content-type :content-transfer-encoding; bh=u53f12tu7KF4hS4NQHVOiAxPI1fiLM19oH4C+6ZzPy0=; b=iCaZIvIDeQf9kHY9Xdo8NAZw/2o3t0928kat0GEd8H0unFNaEH1ebsDEnTQDDYWs3D tqKLvalwjCUIlIRu2+Xa2uQ/g8svehgBo8nJ4PxJG7kNlvbd12FCU3RVX02jJ/0FGrTg qXO+ob5WbwMoR++GQeh/NfsqwMffVujutPjSqaanUEqzr2ZHKFpzZ+/9tRb7+Jtdh6Hg +B5ydhJAk3urPb+M2wlG4IK/AlBBvdMzLCvQb7bA3H37gplKO/9sNknvsGgDtrs+CTNl YsAwcUdtNDVwWaEA/OYWB33R4uppORjD2DP2sR8hFdzpLYed1oy/oFYqg+vx/xJFln/Z mwwg== X-Gm-Message-State: ALoCoQntlO58vY/hS6xI+98ZT9Y+mTPj216xAdBB2bUMrkiljkJITXSQWko39KXVVpFMRjECKZfq X-Received: by 10.194.243.104 with SMTP id wx8mr2827852wjc.32.1403627270235; Tue, 24 Jun 2014 09:27:50 -0700 (PDT) Received: from [172.25.5.3] (out.voltaire.com. [193.47.165.251]) by mx.google.com with ESMTPSA id oy4sm1499205wjb.41.2014.06.24.09.27.48 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 24 Jun 2014 09:27:49 -0700 (PDT) Message-ID: <53A9A702.8050503@dev.mellanox.co.il> Date: Tue, 24 Jun 2014 19:27:46 +0300 From: Sagi Grimberg User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.6.0 MIME-Version: 1.0 To: Michael Christie , "Martin K. Petersen" CC: Sagi Grimberg , nab@linux-iscsi.org, roland@kernel.org, linux-scsi@vger.kernel.org, target-devel@vger.kernel.org, linux-rdma@vger.kernel.org, Christoph Hellwig Subject: Re: [PATCH v2 1/3] scsi_cmnd: Introduce scsi_transfer_length helper References: <1402477799-24610-1-git-send-email-sagig@mellanox.com> <1402477799-24610-2-git-send-email-sagig@mellanox.com> <53A920B2.9060503@cs.wisc.edu> <28678EBD-1AE9-48F9-B9E2-E6A61B042BB1@cs.wisc.edu> In-Reply-To: <28678EBD-1AE9-48F9-B9E2-E6A61B042BB1@cs.wisc.edu> Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable 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 On 6/24/2014 7:08 PM, Michael Christie wrote: > On Jun 24, 2014, at 7:53 AM, Martin K. Petersen wrote: > >>>>>>> "Mike" == Mike Christie writes: >> Mike> The problem is WRITE_SAME requests are setup so that >> Mike> req->__data_len is the value of the entire request when the setup >> Mike> is completed but during the setup process it's value changes >> >> Oh, I see. So things break because iSCSI uses scsi_transfer_length() >> where the scatterlist length was used in the past. >> >> How about this? >> >> >> SCSI: Use SCSI data buffer length to extract transfer size >> >> Commit 8846bab180fa introduced a helper that can be used to query the >> wire transfer size for a SCSI command taking protection information into >> account. >> >> However, some commands do not have a 1:1 mapping between the block range >> they work on and the payload size (discard, write same). After the >> scatterlist has been set up these requests use __data_len to store the >> number of bytes to report completion on. This means that callers of >> scsi_transfer_length() would get the wrong byte count for these types of >> requests. >> >> To overcome this we make scsi_transfer_length() use the scatterlist >> length in the scsi_data_buffer as basis for the wire transfer >> calculation instead of __data_len. >> >> Reported-by: Christoph Hellwig >> Debugged-by: Mike Christie >> Signed-off-by: Martin K. Petersen >> >> diff --git a/include/scsi/scsi_cmnd.h b/include/scsi/scsi_cmnd.h >> index 42ed789ebafc..e0ae71098144 100644 >> --- a/include/scsi/scsi_cmnd.h >> +++ b/include/scsi/scsi_cmnd.h >> @@ -318,7 +318,7 @@ static inline void set_driver_byte(struct scsi_cmnd *cmd, char status) >> >> static inline unsigned scsi_transfer_length(struct scsi_cmnd *scmd) >> { >> - unsigned int xfer_len = blk_rq_bytes(scmd->request); >> + unsigned int xfer_len = scsi_out(scmd)->length; >> unsigned int prot_op = scsi_get_prot_op(scmd); >> unsigned int sector_size = scmd->device->sector_size; > > Do we need to check for the data direction. Something like > > if (scmd->sc_data_direction == DMA_TO_DEVICE) > xfer_len = scsi_out(scmnd)->length; > else > xfer_len = scsi_in(scmnd)->length; This condition only matters in the bidi case, which is not relevant for the PI case. I suggested to condition that in libiscsi (posted in the second thread, copy-paste below). Although I do agree that scsi_transfer_length() helper is not really just for PI and not more. I think Mike's way is cleaner. struct iscsi_r2t_info *r2t = &task->unsol_r2t; Sagi. Acked-by: Mike Christie --- To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/scsi/libiscsi.c b/drivers/scsi/libiscsi.c index 3f46234..abf0c3e 100644 --- a/drivers/scsi/libiscsi.c +++ b/drivers/scsi/libiscsi.c @@ -386,12 +386,14 @@ static int iscsi_prep_scsi_cmd_pdu(struct iscsi_task *task) rc = iscsi_prep_bidi_ahs(task); if (rc) return rc; + transfer_length = scsi_in(sc)->length; + } else { + transfer_length = scsi_transfer_length(sc); } if (scsi_get_prot_op(sc) != SCSI_PROT_NORMAL) task->protected = true; - transfer_length = scsi_transfer_length(sc); hdr->data_length = cpu_to_be32(transfer_length); if (sc->sc_data_direction == DMA_TO_DEVICE) {