From patchwork Tue Jan 22 18:57:23 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 10776127 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5EF22139A for ; Tue, 22 Jan 2019 18:58:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4DEAD2B885 for ; Tue, 22 Jan 2019 18:58:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 422E42B948; Tue, 22 Jan 2019 18:58:20 +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=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,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 C364F2B885 for ; Tue, 22 Jan 2019 18:58:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726143AbfAVS6S (ORCPT ); Tue, 22 Jan 2019 13:58:18 -0500 Received: from com-out001.mailprotect.be ([83.217.72.83]:39991 "EHLO com-out001.mailprotect.be" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726125AbfAVS6S (ORCPT ); Tue, 22 Jan 2019 13:58:18 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mailprotect.be; s=mail; h=Content-Transfer-Encoding:MIME-Version:References :In-Reply-To:Message-Id:Date:Subject:Cc:To:From:reply-to:sender:bcc: content-type; bh=LYG3fEq6CRjAFQucH6Dvzcckp8brakJ66kK0yb6Cp3k=; b=YIvxoS9QlFa1 eQHQGWUtiRkl953986vRvaGZOkkh2iHPgHt4OCFDXETK9y36ZAzaePbVubyQV/eaxxcY1gb5L9fPo lzRC7/CQxzSclpbO4UMFDNynCpShJo51+RU/3xLM+mEHaBQcc15Bc+25KYK3mn8EDkzqCThjoGNxX ndQcbaGt3vcWrHFURTCOEKFR3zJmvcJqqMz9ZlYZ3xyZ6hKxoMc1lgFVMohq5Ic9rEalqeD9ijWJL XnKqKUOwECffxWFKfAsPraEBdpGtnigRH9YKAvHqWXCvawldcZPW+/Kn3uhliB2CepsUDaxPwOeJM luIxMftH/7BqrtiLbvV/Lg==; Received: from smtp-auth.mailprotect.be ([178.208.39.159]) by com-mpt-out001.mailprotect.be with esmtp (Exim 4.89) (envelope-from ) id 1gm1F6-00039L-LS; Tue, 22 Jan 2019 19:57:48 +0100 Received: from desktop-bart.svl.corp.google.com (unknown [104.133.8.89]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp-auth.mailprotect.be (Postfix) with ESMTPSA id 2C29FC0AED; Tue, 22 Jan 2019 19:57:44 +0100 (CET) From: Bart Van Assche To: "Martin K . Petersen" , "James E . J . Bottomley" Cc: linux-scsi@vger.kernel.org, Bart Van Assche , Douglas Gilbert , Hannes Reinecke , Christoph Hellwig , Lee Duncan , Chris Leech , Paolo Bonzini Subject: [PATCH 6/7] Introduce scsi_in_[sg]et_resid() and scsi_out_[sg]et_resid() Date: Tue, 22 Jan 2019 10:57:23 -0800 Message-Id: <20190122185724.71598-7-bvanassche@acm.org> X-Mailer: git-send-email 2.20.1.321.g9e740568ce-goog In-Reply-To: <20190122185724.71598-1-bvanassche@acm.org> References: <20190122185724.71598-1-bvanassche@acm.org> MIME-Version: 1.0 X-Originating-IP: 178.208.39.159 X-SpamExperts-Domain: mailprotect.be X-SpamExperts-Username: 178.208.39.128/27 Authentication-Results: mailprotect.be; auth=pass smtp.auth=178.208.39.128/27@mailprotect.be X-SpamExperts-Outgoing-Class: ham X-SpamExperts-Outgoing-Evidence: SB/global_tokens (0.00682732845345) X-Recommended-Action: accept X-Filter-ID: EX5BVjFpneJeBchSMxfU5lTU/ZTpJvbiUZIgNPv3kIx602E9L7XzfQH6nu9C/Fh9KJzpNe6xgvOx q3u0UDjvO1tLifGj39bI0bcPyaJsYTZnx3upumnqWBHj0/Vmi/pASQQA8gPlICyOXF4VQA3r681n IyHanrMzYl1QUFnGrJlGZdzQSLJYSD89hpteF8v30ykPg8qyrdUV98WGlbOjhJdwZpOImhB57vlA Ovnv7bTFlefH5GZB2zKlxrpPWIK2tjx4n/PrYhB5hmGmQxMVYVAKkEeH4f3QNjnZQsMBDjH4MJg9 YHIdz0Dl6O7ob5t7s0JmTITK6nc3QbOK5CoO7BGsr2YkQf6GHRtGGbpACH6VAhni5ocedxUSQD9R GuQEjZ892PEyNw69vEzsu606q67x2Ua3T1Mc1WaTf4bbLVYEybI1sOftHmSKUCHCvcq0UIIqcWW4 ifKaEwthyP1VxRXFlYuWrE0vLapFlbaWqJjuyf/9FwsQjCZ/G16ONVA9bTkFsvCGkPVV+auVjHwB H0RhAta0pIzMTTnbIXymD5ebG0Xni7XCo6ehBw6KaJm7DIXqP5P5X1d0cf7YNeX80Mi/IFb8H9P2 UweQHsd5pwaJ7YxW+jLD3ZDBACJzg6v8ChIMUBexuGo66F0oVT5ebO9n9zqkM12Y+COJLnC0ol3n sXEBAaJKYpjfiKWbEgl3w5gS4D3X4kVivwz4Sz4qStezYqxGMqsKjARq8PBC4qj1z+8KP1/w7Nvd xY9bKBxJzbBZVuMc79ykmmxiW8WEz0sosrzI3EdRChAJhsbcCJAeMzveq5eJrexBvOsP5AjXM0S3 Ej9wK9U6T08uj1LhgQEiRQv+PVjjwa+Z5RFCOMRJIinr7MdK9bPW4qgtLAMsxeALkH8Xtdz0W8sw tWz8lpn1AtJbOzlWxsgX2Vgf2jSExp8sAqOQvlCFhGLiUy48iLgMlCvTtx4+HGatF9xp2t6YDkhi 6kKHWGhsE+ciTYPnC9kU8EzzPWXPJewIpRuRtgZkcRkCnoMzps1w8ZlyWoBR0RG0hPasLKXprlc7 I3hAA1Te9AzAvsB5ebmx67gSNSuEgaravxjr32HVMX+LlVFfEoXm0/FPF8PR0w363lmbp5/Z9/y8 d6CkJRuULLE0yNHTe7SA/QklbN9cnl0KNGB1eQxePet6exctZLANANtQvy23SZXSfMZ7RzHGH1l2 3yp/yWvJqZN6SAs+Uz/r0K7dceGa8Ws4pCIiEvrIES7uyf/9FwsQjCZ/G16ONVA9xvkcs7W/3UH1 4Wz64pf2HuQC6llR+qFCQs6UaJKpbflnrkIDSWXgqeBI79lSWqTU X-Report-Abuse-To: spam@com-mpt-mgt001.mailprotect.be Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This patch does not change any functionality. Cc: Douglas Gilbert Cc: Hannes Reinecke Cc: Christoph Hellwig Cc: Lee Duncan Cc: Chris Leech Cc: Paolo Bonzini Signed-off-by: Bart Van Assche --- drivers/scsi/libiscsi.c | 12 ++++++------ drivers/scsi/scsi_debug.c | 9 +++++---- drivers/scsi/sd.c | 4 ++-- drivers/scsi/virtio_scsi.c | 4 ++-- include/scsi/scsi_cmnd.h | 24 ++++++++++++++++++++++-- 5 files changed, 37 insertions(+), 16 deletions(-) diff --git a/drivers/scsi/libiscsi.c b/drivers/scsi/libiscsi.c index b8d325ce8754..fe5b3371553c 100644 --- a/drivers/scsi/libiscsi.c +++ b/drivers/scsi/libiscsi.c @@ -650,8 +650,8 @@ static void fail_scsi_task(struct iscsi_task *task, int err) if (!scsi_bidi_cmnd(sc)) scsi_set_resid(sc, scsi_bufflen(sc)); else { - scsi_out(sc)->resid = scsi_out(sc)->length; - scsi_in(sc)->resid = scsi_in(sc)->length; + scsi_out_set_resid(sc, scsi_out(sc)->length); + scsi_in_set_resid(sc, scsi_in(sc)->length); } /* regular RX path uses back_lock */ @@ -912,7 +912,7 @@ static void iscsi_scsi_cmd_rsp(struct iscsi_conn *conn, struct iscsi_hdr *hdr, if (scsi_bidi_cmnd(sc) && res_count > 0 && (rhdr->flags & ISCSI_FLAG_CMD_BIDI_OVERFLOW || res_count <= scsi_in(sc)->length)) - scsi_in(sc)->resid = res_count; + scsi_in_set_resid(sc, res_count); else sc->result = (DID_BAD_TARGET << 16) | rhdr->cmd_status; } @@ -962,7 +962,7 @@ iscsi_data_in_rsp(struct iscsi_conn *conn, struct iscsi_hdr *hdr, if (res_count > 0 && (rhdr->flags & ISCSI_FLAG_CMD_OVERFLOW || res_count <= scsi_in(sc)->length)) - scsi_in(sc)->resid = res_count; + scsi_in_set_resid(sc, res_count); else sc->result = (DID_BAD_TARGET << 16) | rhdr->cmd_status; } @@ -1807,8 +1807,8 @@ int iscsi_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *sc) if (!scsi_bidi_cmnd(sc)) scsi_set_resid(sc, scsi_bufflen(sc)); else { - scsi_out(sc)->resid = scsi_out(sc)->length; - scsi_in(sc)->resid = scsi_in(sc)->length; + scsi_out_set_resid(sc, scsi_out(sc)->length); + scsi_in_set_resid(sc, scsi_in(sc)->length); } sc->scsi_done(sc); return 0; diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c index e253c0129b40..822aed12ca31 100644 --- a/drivers/scsi/scsi_debug.c +++ b/drivers/scsi/scsi_debug.c @@ -1019,7 +1019,7 @@ static int fill_from_dev_buffer(struct scsi_cmnd *scp, unsigned char *arr, act_len = sg_copy_from_buffer(sdb->table.sgl, sdb->table.nents, arr, arr_len); - sdb->resid = scsi_bufflen(scp) - act_len; + scsi_in_set_resid(scp, scsi_bufflen(scp) - act_len); return 0; } @@ -1044,9 +1044,10 @@ static int p_fill_from_dev_buffer(struct scsi_cmnd *scp, const void *arr, act_len = sg_pcopy_from_buffer(sdb->table.sgl, sdb->table.nents, arr, arr_len, skip); pr_debug("%s: off_dst=%u, scsi_bufflen=%u, act_len=%u, resid=%d\n", - __func__, off_dst, scsi_bufflen(scp), act_len, sdb->resid); + __func__, off_dst, scsi_bufflen(scp), act_len, + scsi_in_get_resid(scp)); n = (int)scsi_bufflen(scp) - ((int)off_dst + act_len); - sdb->resid = min(sdb->resid, n); + scsi_in_set_resid(scp, min(scsi_in_get_resid(scp), n)); return 0; } @@ -2774,7 +2775,7 @@ static int resp_read_dt0(struct scsi_cmnd *scp, struct sdebug_dev_info *devip) if (unlikely(ret == -1)) return DID_ERROR << 16; - scsi_in(scp)->resid = scsi_bufflen(scp) - ret; + scsi_in_set_resid(scp, scsi_bufflen(scp) - ret); if (unlikely(sqcp)) { if (sqcp->inj_recovered) { diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c index b0eb83526c54..2219ba81f0b3 100644 --- a/drivers/scsi/sd.c +++ b/drivers/scsi/sd.c @@ -844,7 +844,7 @@ static blk_status_t sd_setup_unmap_cmnd(struct scsi_cmnd *cmd) cmd->allowed = SD_MAX_RETRIES; cmd->transfersize = data_len; rq->timeout = SD_TIMEOUT; - scsi_req(rq)->resid_len = data_len; + scsi_set_resid(cmd, data_len); return scsi_init_io(cmd); } @@ -908,7 +908,7 @@ static blk_status_t sd_setup_write_same10_cmnd(struct scsi_cmnd *cmd, cmd->allowed = SD_MAX_RETRIES; cmd->transfersize = data_len; rq->timeout = unmap ? SD_TIMEOUT : SD_WRITE_SAME_TIMEOUT; - scsi_req(rq)->resid_len = data_len; + scsi_set_resid(cmd, data_len); return scsi_init_io(cmd); } diff --git a/drivers/scsi/virtio_scsi.c b/drivers/scsi/virtio_scsi.c index 772b976e4ee4..47888649f6b8 100644 --- a/drivers/scsi/virtio_scsi.c +++ b/drivers/scsi/virtio_scsi.c @@ -108,8 +108,8 @@ static void virtscsi_compute_resid(struct scsi_cmnd *sc, u32 resid) return; } - scsi_in(sc)->resid = min(resid, scsi_in(sc)->length); - scsi_out(sc)->resid = resid - scsi_in(sc)->resid; + scsi_in_set_resid(sc, min(resid, scsi_in(sc)->length)); + scsi_out_set_resid(sc, resid - scsi_in_get_resid(sc)); } /** diff --git a/include/scsi/scsi_cmnd.h b/include/scsi/scsi_cmnd.h index 673980ed7db6..8f3ed55a5ee5 100644 --- a/include/scsi/scsi_cmnd.h +++ b/include/scsi/scsi_cmnd.h @@ -227,16 +227,36 @@ static inline unsigned scsi_bufflen(struct scsi_cmnd *cmd) return cmd->sdb.length; } -static inline void scsi_set_resid(struct scsi_cmnd *cmd, int resid) +static inline void scsi_in_set_resid(struct scsi_cmnd *cmd, int resid) +{ + scsi_in_cmd(cmd)->sdb.resid = resid; +} + +static inline int scsi_in_get_resid(struct scsi_cmnd *cmd) +{ + return scsi_in_cmd(cmd)->sdb.resid; +} + +static inline void scsi_out_set_resid(struct scsi_cmnd *cmd, int resid) { cmd->sdb.resid = resid; } -static inline int scsi_get_resid(struct scsi_cmnd *cmd) +static inline int scsi_out_get_resid(struct scsi_cmnd *cmd) { return cmd->sdb.resid; } +static inline void scsi_set_resid(struct scsi_cmnd *cmd, int resid) +{ + return scsi_out_set_resid(cmd, resid); +} + +static inline int scsi_get_resid(struct scsi_cmnd *cmd) +{ + return scsi_out_get_resid(cmd); +} + #define scsi_for_each_sg(cmd, sg, nseg, __i) \ for_each_sg(scsi_sglist(cmd), sg, nseg, __i)