From: schumaker.anna@gmail.com
To: linux-nfs@vger.kernel.org
Cc: Anna.Schumaker@Netapp.com
Subject: [PATCH v4 06/10] SUNRPC: Split out _shift_data_right_tail()
Date: Mon, 17 Aug 2020 12:53:23 -0400 [thread overview]
Message-ID: <20200817165327.354181-7-Anna.Schumaker@Netapp.com> (raw)
In-Reply-To: <20200817165327.354181-1-Anna.Schumaker@Netapp.com>
From: Anna Schumaker <Anna.Schumaker@Netapp.com>
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 <Anna.Schumaker@Netapp.com>
---
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
next prev parent reply other threads:[~2020-08-17 17:33 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-08-17 16:53 [PATCH v4 00/10] NFS: Add support for the v4.2 READ_PLUS operation schumaker.anna
2020-08-17 16:53 ` [PATCH v4 01/10] SUNRPC: Split out a function for setting current page schumaker.anna
2020-08-17 16:53 ` [PATCH v4 02/10] SUNRPC: Implement a xdr_page_pos() function schumaker.anna
2020-08-17 16:53 ` [PATCH v4 03/10] NFS: Use xdr_page_pos() in NFSv4 decode_getacl() schumaker.anna
2020-08-17 16:53 ` [PATCH v4 04/10] NFS: Add READ_PLUS data segment support schumaker.anna
2020-08-17 16:53 ` [PATCH v4 05/10] SUNRPC: Split out xdr_realign_pages() from xdr_align_pages() schumaker.anna
2020-08-17 16:53 ` schumaker.anna [this message]
2020-08-17 16:53 ` [PATCH v4 07/10] SUNRPC: Add the ability to expand holes in data pages schumaker.anna
2020-08-17 16:53 ` [PATCH v4 08/10] NFS: Add READ_PLUS hole segment decoding schumaker.anna
2020-08-17 16:53 ` [PATCH v4 09/10] SUNRPC: Add an xdr_align_data() function schumaker.anna
2020-08-17 16:53 ` [PATCH v4 10/10] NFS: Decode a full READ_PLUS reply schumaker.anna
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200817165327.354181-7-Anna.Schumaker@Netapp.com \
--to=schumaker.anna@gmail.com \
--cc=Anna.Schumaker@Netapp.com \
--cc=linux-nfs@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox