Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp4053885pxk; Tue, 8 Sep 2020 09:29:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxzRQCZamukNM3UB9db1CrFyyCcbNjaTmUXzAYqJJAPQVVfBj23KP+qToxvs0LEUinviqgZ X-Received: by 2002:a17:906:3091:: with SMTP id 17mr28187906ejv.515.1599582563058; Tue, 08 Sep 2020 09:29:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599582563; cv=none; d=google.com; s=arc-20160816; b=KqR7pNb9TZ03IoL42NjIRmsMO+sZcYYC/zRXYh3ZrzzqUN3QqcLLXCTNTgAc0/UVB4 M15cSgE5BjUolaDGXSpE+bl2fIBfJ1yIkPq2FgKlQVPb041wnF9+mlY2ybYR9LFe5VDP 87hDGiPRgAFawNisYQxaxXDD65B1CgyHeosZngNElFMCe/KcQRApQz+NFOxmzooPIT2K Viq74f8/4L/Ox+K4QeCcRqPzFmYhxB/XyHkWqoYODGwe9nUAM7aY2zoWFFvCbtYlFmCg WGk6ILVKdFINQLDCRNVr0w/z4fuXRz2Az3bjajHWBnnt8fqauPi17n5KenvbPvLrK5sY EfbA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=igtPl6C6Gfbp4gxTezXs9k9ZWoIUbuf9BiavER35twk=; b=km0tKVB5pKN80a42jOWjlFLiBkaPKog+rh3bTWdIqFAeYUfeh3XGqPCemTckGPsM6x cZC2gN1Q8JTSpR5gSJsh0tLkuYOHV9C9mS019oRfY37rDzbJRZWlUbH90NvYxd4cBPnb +53FbZNAo/x1kGNkj9J5Hp5GL0x4gqadABXBSE6EVvgLiTJPEuqaEKKJioXLzi9h6KjF 8zH5+6ZdwHBncv9hWU3LqUN8BYI9r+1Z1iAGy5UyDCaaQD39YCRa+pSFqaJ06U7x7w0Q faIGn+UoZLKp8EuT1tTG4sIVoO9lllPApkpxuGCNijX438vCBz/cRXr72BJ7dxELyjwc slxA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=lDitmVQQ; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i10si12462647edu.323.2020.09.08.09.28.59; Tue, 08 Sep 2020 09:29:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=lDitmVQQ; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731502AbgIHQ0U (ORCPT + 99 others); Tue, 8 Sep 2020 12:26:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58746 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731648AbgIHQZj (ORCPT ); Tue, 8 Sep 2020 12:25:39 -0400 Received: from mail-io1-xd42.google.com (mail-io1-xd42.google.com [IPv6:2607:f8b0:4864:20::d42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A8A5FC061795 for ; Tue, 8 Sep 2020 09:25:21 -0700 (PDT) Received: by mail-io1-xd42.google.com with SMTP id g128so17667178iof.11 for ; Tue, 08 Sep 2020 09:25:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=igtPl6C6Gfbp4gxTezXs9k9ZWoIUbuf9BiavER35twk=; b=lDitmVQQUIZFMIff8iQvtOMv1mypPvgkLpB+V6uxR6jxk3UpH0MEFXmPssQGLOQ9qy vkaiaHW3f5EE5CV2D5ztvxtwDYpWFdIKpX8zt/9N2jdv9R/vKTTE1Rfhjxwcny61/GeO Wrhq8CMyGJEWo54MXeaMC+q9W7fqZ3gCoc3OQ3JAr/hMZcsMA+QPjyG4ku+6pocrbu1d 6IpeSFUoI/GF2M+Yx+C8cYev0pevfCGm33SSS3kLY4N+Z5jSpe7Gl6SNl7iGwbuLEBUb 2Kf7iZMySh8rFvgVzJDUhwo1Tm9AkPPUzCebwYHVwy9W78qMcirwQ091/2kZBSnzO+Rc xFfg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=igtPl6C6Gfbp4gxTezXs9k9ZWoIUbuf9BiavER35twk=; b=FGWF8OT1dsyG8ZFRo+ij9axp43R5Jakhy2+F5EPMAe3ayUomv9mcPxPYy+XVWoBYAm YpW9at+M9mmcsjqWX7bfPVkRVze+wcxwnkAteN2C/A6M/Mn7hOTrsjgjAtL9jEvVrPCS s00sCaZwTfEmSb6zxxVACH1NrC2ms8NSlxCqL/zPZZMaEMlEwAlLNVi1BZWlqFjAzT6B zwfjIY5SAR8LWey6VlrjeFcjrh6PjVqrWqZkh5O4tKLnYas5D8/x3LtE9KlkYTIrtKQ9 53xMOzx8vB1wo41E9DusPPbmqxg0VE6kfU+hKQF7oAS8Vyuy7WOior5hcu0/+idnjqF5 ts2g== X-Gm-Message-State: AOAM531YB0KM9JJPgDXV68JF4Jja81+k4OTcWbzKd1xus3F9U///M6qx yL5XLFpurE4tklPjuaaCjfmw7Kw8Gn0= X-Received: by 2002:a6b:f801:: with SMTP id o1mr21526403ioh.43.1599582320665; Tue, 08 Sep 2020 09:25:20 -0700 (PDT) Received: from gouda.nowheycreamery.com (c-68-32-74-190.hsd1.mi.comcast.net. [68.32.74.190]) by smtp.gmail.com with ESMTPSA id 2sm10291375ilj.24.2020.09.08.09.25.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Sep 2020 09:25:20 -0700 (PDT) From: schumaker.anna@gmail.com X-Google-Original-From: Anna.Schumaker@Netapp.com To: linux-nfs@vger.kernel.org Cc: Anna.Schumaker@Netapp.com Subject: [PATCH v5 06/10] SUNRPC: Split out _shift_data_right_tail() Date: Tue, 8 Sep 2020 12:25:09 -0400 Message-Id: <20200908162513.508991-7-Anna.Schumaker@Netapp.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200908162513.508991-1-Anna.Schumaker@Netapp.com> References: <20200908162513.508991-1-Anna.Schumaker@Netapp.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org From: Anna Schumaker xdr_shrink_pagelen() is very similar to what we need for hole expansion, so split out the common code into its own function that can be used by both functions. Signed-off-by: Anna Schumaker --- net/sunrpc/xdr.c | 68 +++++++++++++++++++++++++++++------------------- 1 file changed, 41 insertions(+), 27 deletions(-) diff --git a/net/sunrpc/xdr.c b/net/sunrpc/xdr.c index 70efb35c119e..d8c9555c6f2b 100644 --- a/net/sunrpc/xdr.c +++ b/net/sunrpc/xdr.c @@ -266,6 +266,46 @@ _shift_data_right_pages(struct page **pages, size_t pgto_base, } while ((len -= copy) != 0); } +static unsigned int +_shift_data_right_tail(struct xdr_buf *buf, unsigned int pgfrom, size_t len) +{ + struct kvec *tail = buf->tail; + unsigned int tailbuf_len; + unsigned int result = 0; + size_t copy; + + tailbuf_len = buf->buflen - buf->head->iov_len - buf->page_len; + + /* Shift the tail first */ + if (tailbuf_len != 0) { + unsigned int free_space = tailbuf_len - tail->iov_len; + + if (len < free_space) + free_space = len; + if (len > free_space) + len = free_space; + + tail->iov_len += free_space; + copy = len; + + if (tail->iov_len > len) { + char *p = (char *)tail->iov_base + len; + memmove(p, tail->iov_base, tail->iov_len - free_space); + result += tail->iov_len - free_space; + } else + copy = tail->iov_len; + + /* Copy from the inlined pages into the tail */ + _copy_from_pages((char *)tail->iov_base, + buf->pages, + buf->page_base + pgfrom, + copy); + result += copy; + } + + return result; +} + /** * _copy_to_pages * @pages: array of pages @@ -446,39 +486,13 @@ xdr_shrink_bufhead(struct xdr_buf *buf, size_t len) static unsigned int xdr_shrink_pagelen(struct xdr_buf *buf, size_t len) { - struct kvec *tail; - size_t copy; unsigned int pglen = buf->page_len; - unsigned int tailbuf_len; unsigned int result; - result = 0; - tail = buf->tail; if (len > buf->page_len) len = buf-> page_len; - tailbuf_len = buf->buflen - buf->head->iov_len - buf->page_len; - /* Shift the tail first */ - if (tailbuf_len != 0) { - unsigned int free_space = tailbuf_len - tail->iov_len; - - if (len < free_space) - free_space = len; - tail->iov_len += free_space; - - copy = len; - if (tail->iov_len > len) { - char *p = (char *)tail->iov_base + len; - memmove(p, tail->iov_base, tail->iov_len - len); - result += tail->iov_len - len; - } else - copy = tail->iov_len; - /* Copy from the inlined pages into the tail */ - _copy_from_pages((char *)tail->iov_base, - buf->pages, buf->page_base + pglen - len, - copy); - result += copy; - } + result = _shift_data_right_tail(buf, pglen - len, len); buf->page_len -= len; buf->buflen -= len; /* Have we truncated the message? */ -- 2.28.0