]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - queue-5.15/nfsd-refactor-common-code-out-of-dirlist-helpers.patch
Fixes for 5.15
[thirdparty/kernel/stable-queue.git] / queue-5.15 / nfsd-refactor-common-code-out-of-dirlist-helpers.patch
1 From e689093a85007cc0339585f20ab1141264a5439e Mon Sep 17 00:00:00 2001
2 From: Sasha Levin <sashal@kernel.org>
3 Date: Mon, 12 Sep 2022 17:22:56 -0400
4 Subject: NFSD: Refactor common code out of dirlist helpers
5
6 From: Chuck Lever <chuck.lever@oracle.com>
7
8 [ Upstream commit 98124f5bd6c76699d514fbe491dd95265369cc99 ]
9
10 The dust has settled a bit and it's become obvious what code is
11 totally common between nfsd_init_dirlist_pages() and
12 nfsd3_init_dirlist_pages(). Move that common code to SUNRPC.
13
14 The new helper brackets the existing xdr_init_decode_pages() API.
15
16 Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
17 ---
18 fs/nfsd/nfs3proc.c | 10 +---------
19 fs/nfsd/nfsproc.c | 10 +---------
20 include/linux/sunrpc/xdr.h | 2 ++
21 net/sunrpc/xdr.c | 22 ++++++++++++++++++++++
22 4 files changed, 26 insertions(+), 18 deletions(-)
23
24 diff --git a/fs/nfsd/nfs3proc.c b/fs/nfsd/nfs3proc.c
25 index 58695e4e18b46..923d9a80df92c 100644
26 --- a/fs/nfsd/nfs3proc.c
27 +++ b/fs/nfsd/nfs3proc.c
28 @@ -574,15 +574,7 @@ static void nfsd3_init_dirlist_pages(struct svc_rqst *rqstp,
29 buf->pages = rqstp->rq_next_page;
30 rqstp->rq_next_page += (buf->buflen + PAGE_SIZE - 1) >> PAGE_SHIFT;
31
32 - /* This is xdr_init_encode(), but it assumes that
33 - * the head kvec has already been consumed. */
34 - xdr_set_scratch_buffer(xdr, NULL, 0);
35 - xdr->buf = buf;
36 - xdr->page_ptr = buf->pages;
37 - xdr->iov = NULL;
38 - xdr->p = page_address(*buf->pages);
39 - xdr->end = (void *)xdr->p + min_t(u32, buf->buflen, PAGE_SIZE);
40 - xdr->rqst = NULL;
41 + xdr_init_encode_pages(xdr, buf, buf->pages, NULL);
42 }
43
44 /*
45 diff --git a/fs/nfsd/nfsproc.c b/fs/nfsd/nfsproc.c
46 index 49778ff410e32..82b3ddeacc338 100644
47 --- a/fs/nfsd/nfsproc.c
48 +++ b/fs/nfsd/nfsproc.c
49 @@ -575,15 +575,7 @@ static void nfsd_init_dirlist_pages(struct svc_rqst *rqstp,
50 buf->pages = rqstp->rq_next_page;
51 rqstp->rq_next_page++;
52
53 - /* This is xdr_init_encode(), but it assumes that
54 - * the head kvec has already been consumed. */
55 - xdr_set_scratch_buffer(xdr, NULL, 0);
56 - xdr->buf = buf;
57 - xdr->page_ptr = buf->pages;
58 - xdr->iov = NULL;
59 - xdr->p = page_address(*buf->pages);
60 - xdr->end = (void *)xdr->p + min_t(u32, buf->buflen, PAGE_SIZE);
61 - xdr->rqst = NULL;
62 + xdr_init_encode_pages(xdr, buf, buf->pages, NULL);
63 }
64
65 /*
66 diff --git a/include/linux/sunrpc/xdr.h b/include/linux/sunrpc/xdr.h
67 index 3a2c714d6b629..98e197376a0d9 100644
68 --- a/include/linux/sunrpc/xdr.h
69 +++ b/include/linux/sunrpc/xdr.h
70 @@ -240,6 +240,8 @@ typedef int (*kxdrdproc_t)(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
71
72 extern void xdr_init_encode(struct xdr_stream *xdr, struct xdr_buf *buf,
73 __be32 *p, struct rpc_rqst *rqst);
74 +extern void xdr_init_encode_pages(struct xdr_stream *xdr, struct xdr_buf *buf,
75 + struct page **pages, struct rpc_rqst *rqst);
76 extern __be32 *xdr_reserve_space(struct xdr_stream *xdr, size_t nbytes);
77 extern int xdr_reserve_space_vec(struct xdr_stream *xdr, struct kvec *vec,
78 size_t nbytes);
79 diff --git a/net/sunrpc/xdr.c b/net/sunrpc/xdr.c
80 index f0a0a4ad6d525..b227d0c8471ff 100644
81 --- a/net/sunrpc/xdr.c
82 +++ b/net/sunrpc/xdr.c
83 @@ -918,6 +918,28 @@ void xdr_init_encode(struct xdr_stream *xdr, struct xdr_buf *buf, __be32 *p,
84 }
85 EXPORT_SYMBOL_GPL(xdr_init_encode);
86
87 +/**
88 + * xdr_init_encode_pages - Initialize an xdr_stream for encoding into pages
89 + * @xdr: pointer to xdr_stream struct
90 + * @buf: pointer to XDR buffer into which to encode data
91 + * @pages: list of pages to decode into
92 + * @rqst: pointer to controlling rpc_rqst, for debugging
93 + *
94 + */
95 +void xdr_init_encode_pages(struct xdr_stream *xdr, struct xdr_buf *buf,
96 + struct page **pages, struct rpc_rqst *rqst)
97 +{
98 + xdr_reset_scratch_buffer(xdr);
99 +
100 + xdr->buf = buf;
101 + xdr->page_ptr = pages;
102 + xdr->iov = NULL;
103 + xdr->p = page_address(*pages);
104 + xdr->end = (void *)xdr->p + min_t(u32, buf->buflen, PAGE_SIZE);
105 + xdr->rqst = rqst;
106 +}
107 +EXPORT_SYMBOL_GPL(xdr_init_encode_pages);
108 +
109 /**
110 * xdr_commit_encode - Ensure all data is written to buffer
111 * @xdr: pointer to xdr_stream
112 --
113 2.43.0
114