From: Anna Schumaker <anna@kernel.org>
To: linux-nfs@vger.kernel.org, chuck.lever@oracle.com
Cc: anna@kernel.org
Subject: [PATCH v3 3/6] SUNRPC: Introduce xdr_buf_trim_head()
Date: Fri, 15 Jul 2022 14:44:30 -0400 [thread overview]
Message-ID: <20220715184433.838521-4-anna@kernel.org> (raw)
In-Reply-To: <20220715184433.838521-1-anna@kernel.org>
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 e26047d474b2..bdaf048edde0 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 63d9cdc989da..37956a274f81 100644
--- a/net/sunrpc/xdr.c
+++ b/net/sunrpc/xdr.c
@@ -1739,6 +1739,23 @@ unsigned int xdr_stream_move_subsegment(struct xdr_stream *xdr, unsigned int off
}
EXPORT_SYMBOL_GPL(xdr_stream_move_subsegment);
+/**
+ * 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.37.1
next prev parent reply other threads:[~2022-07-15 18:44 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-15 18:44 [PATCH v3 0/6] NFSD: Improvements for the NFSv4.2 READ_PLUS operation Anna Schumaker
2022-07-15 18:44 ` [PATCH v3 1/6] SUNRPC: Introduce xdr_stream_move_subsegment() Anna Schumaker
2022-07-15 18:44 ` [PATCH v3 2/6] SUNRPC: Introduce xdr_encode_double() Anna Schumaker
2022-07-15 18:44 ` Anna Schumaker [this message]
2022-07-15 18:44 ` [PATCH v3 4/6] SUNRPC: Introduce xdr_buf_nth_page_address() Anna Schumaker
2022-07-15 18:44 ` [PATCH v3 5/6] SUNRPC: Export xdr_buf_pagecount() Anna Schumaker
2022-07-15 18:44 ` [PATCH v3 6/6] NFSD: Repeal and replace the READ_PLUS implementation Anna Schumaker
2022-07-15 19:08 ` Chuck Lever III
2022-07-18 1:15 ` Dave Chinner
2022-07-19 17:21 ` Chuck Lever III
2022-07-19 20:24 ` Anna Schumaker
2022-07-19 20:47 ` Chuck Lever III
2022-07-19 21:10 ` Matthew Wilcox
2022-07-19 23:18 ` Dave Chinner
2022-07-19 20:46 ` Anna Schumaker
2022-07-19 22:44 ` Dave Chinner
2022-07-20 1:26 ` Chuck Lever III
2022-07-20 2:36 ` Dave Chinner
2022-07-20 4:18 ` Chuck Lever III
2022-07-22 0:44 ` Dave Chinner
2022-07-22 15:09 ` Chuck Lever III
2022-08-18 18:31 ` Anna Schumaker
2022-08-19 15:18 ` Chuck Lever III
2022-07-20 12:55 ` Jeff Layton
2022-07-21 23:12 ` Dave Chinner
2022-07-21 20:47 ` Josef Bacik
2022-07-22 12:45 ` Anna Schumaker
2022-07-22 13:32 ` Josef Bacik
2022-07-22 13:43 ` 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=20220715184433.838521-4-anna@kernel.org \
--to=anna@kernel.org \
--cc=chuck.lever@oracle.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