All of lore.kernel.org
 help / color / mirror / Atom feed
From: Anna.Schumaker@Netapp.com
To: steved@redhat.com, linux-nfs@vger.kernel.org
Cc: Anna.Schumaker@Netapp.com
Subject: [PATCH v1 3/6] SUNRPC: Introduce xdr_buf_trim_head()
Date: Mon, 16 May 2022 16:35:46 -0400	[thread overview]
Message-ID: <20220516203549.2605575-4-Anna.Schumaker@Netapp.com> (raw)
In-Reply-To: <20220516203549.2605575-1-Anna.Schumaker@Netapp.com>

From: Anna Schumaker <Anna.Schumaker@Netapp.com>

The READ_PLUS operation uses a 32-bit length field for encoding a DATA
segment, but 64-bit length field for encoding a HOLE segment. When
setting up our reply buffer, we need to reserve enough space to encode
a HOLE before reading the file data and use this function if the first
segment turns out to be DATA.

Signed-off-by: Anna Schumaker <Anna.Schumaker@Netapp.com>
---
 include/linux/sunrpc/xdr.h |  1 +
 net/sunrpc/xdr.c           | 17 +++++++++++++++++
 2 files changed, 18 insertions(+)

diff --git a/include/linux/sunrpc/xdr.h b/include/linux/sunrpc/xdr.h
index e502fe576813..344c820484ba 100644
--- a/include/linux/sunrpc/xdr.h
+++ b/include/linux/sunrpc/xdr.h
@@ -191,6 +191,7 @@ xdr_adjust_iovec(struct kvec *iov, __be32 *p)
 extern void xdr_shift_buf(struct xdr_buf *, size_t);
 extern void xdr_buf_from_iov(const struct kvec *, struct xdr_buf *);
 extern int xdr_buf_subsegment(const struct xdr_buf *, struct xdr_buf *, unsigned int, unsigned int);
+extern void xdr_buf_trim_head(struct xdr_buf *, unsigned int);
 extern void xdr_buf_trim(struct xdr_buf *, unsigned int);
 extern int read_bytes_from_xdr_buf(const struct xdr_buf *, unsigned int, void *, unsigned int);
 extern int write_bytes_to_xdr_buf(const struct xdr_buf *, unsigned int, void *, unsigned int);
diff --git a/net/sunrpc/xdr.c b/net/sunrpc/xdr.c
index 87526bce9e15..3ecc444b27be 100644
--- a/net/sunrpc/xdr.c
+++ b/net/sunrpc/xdr.c
@@ -1730,6 +1730,23 @@ unsigned int xdr_stream_move_segment(struct xdr_stream *xdr, unsigned int offset
 }
 EXPORT_SYMBOL_GPL(xdr_stream_move_segment);
 
+/**
+ * xdr_buf_trim_head - lop at most "len" bytes off the end of "buf"->head
+ * @buf: buf to be trimmed
+ * @len: number of bytes to reduce "buf"->head by
+ *
+ * Trim an xdr_buf->head by the given number of bytes by fixing up the lengths.
+ * Note that it's possible that we'll trim less than that amount if the
+ *  xdr_buf->head is too small.
+ */
+void xdr_buf_trim_head(struct xdr_buf *buf, unsigned int len)
+{
+	size_t trim = min_t(size_t, buf->head[0].iov_len, len);
+	buf->head[0].iov_len -= trim;
+	buf->len -= trim;
+}
+EXPORT_SYMBOL_GPL(xdr_buf_trim_head);
+
 /**
  * xdr_buf_trim - lop at most "len" bytes off the end of "buf"
  * @buf: buf to be trimmed
-- 
2.36.1


  parent reply	other threads:[~2022-05-16 21:01 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-16 20:35 [PATCH v1 0/6] NFSD: Improvements for the NFSv4.2 READ_PLUS operation Anna.Schumaker
2022-05-16 20:35 ` [PATCH v1 1/6] SUNRPC: Introduce xdr_stream_move_segment() Anna.Schumaker
2022-05-16 20:35 ` [PATCH v1 2/6] SUNRPC: Introduce xdr_encode_double() Anna.Schumaker
2022-05-16 20:35 ` Anna.Schumaker [this message]
2022-05-16 20:35 ` [PATCH v1 4/6] SUNRPC: Introduce xdr_buf_nth_page_address() Anna.Schumaker
2022-05-16 20:35 ` [PATCH v1 5/6] SUNRPC: Export xdr_buf_pagecount() Anna.Schumaker
2022-05-16 20:35 ` [PATCH v1 6/6] NFSD: Repeal and replace the READ_PLUS implementation Anna.Schumaker
2022-05-16 21:37   ` Chuck Lever III
2022-05-17 13:39     ` Anna Schumaker
2022-05-17 13:53       ` Chuck Lever III
2022-05-17 14:55         ` Anna Schumaker

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=20220516203549.2605575-4-Anna.Schumaker@Netapp.com \
    --to=anna.schumaker@netapp.com \
    --cc=linux-nfs@vger.kernel.org \
    --cc=steved@redhat.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.