NFSD: Refactor common code out of dirlist helpers
authorChuck Lever <chuck.lever@oracle.com>
Mon, 12 Sep 2022 21:22:56 +0000 (17:22 -0400)
committerChuck Lever <chuck.lever@oracle.com>
Mon, 26 Sep 2022 18:02:47 +0000 (14:02 -0400)
The dust has settled a bit and it's become obvious what code is
totally common between nfsd_init_dirlist_pages() and
nfsd3_init_dirlist_pages(). Move that common code to SUNRPC.

The new helper brackets the existing xdr_init_decode_pages() API.

Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
fs/nfsd/nfs3proc.c
fs/nfsd/nfsproc.c
include/linux/sunrpc/xdr.h
net/sunrpc/xdr.c

index 58695e4..923d9a8 100644 (file)
@@ -574,15 +574,7 @@ static void nfsd3_init_dirlist_pages(struct svc_rqst *rqstp,
        buf->pages = rqstp->rq_next_page;
        rqstp->rq_next_page += (buf->buflen + PAGE_SIZE - 1) >> PAGE_SHIFT;
 
-       /* This is xdr_init_encode(), but it assumes that
-        * the head kvec has already been consumed. */
-       xdr_set_scratch_buffer(xdr, NULL, 0);
-       xdr->buf = buf;
-       xdr->page_ptr = buf->pages;
-       xdr->iov = NULL;
-       xdr->p = page_address(*buf->pages);
-       xdr->end = (void *)xdr->p + min_t(u32, buf->buflen, PAGE_SIZE);
-       xdr->rqst = NULL;
+       xdr_init_encode_pages(xdr, buf, buf->pages,  NULL);
 }
 
 /*
index 49778ff..82b3dde 100644 (file)
@@ -575,15 +575,7 @@ static void nfsd_init_dirlist_pages(struct svc_rqst *rqstp,
        buf->pages = rqstp->rq_next_page;
        rqstp->rq_next_page++;
 
-       /* This is xdr_init_encode(), but it assumes that
-        * the head kvec has already been consumed. */
-       xdr_set_scratch_buffer(xdr, NULL, 0);
-       xdr->buf = buf;
-       xdr->page_ptr = buf->pages;
-       xdr->iov = NULL;
-       xdr->p = page_address(*buf->pages);
-       xdr->end = (void *)xdr->p + min_t(u32, buf->buflen, PAGE_SIZE);
-       xdr->rqst = NULL;
+       xdr_init_encode_pages(xdr, buf, buf->pages,  NULL);
 }
 
 /*
index 6917502..f84e2a1 100644 (file)
@@ -240,6 +240,8 @@ typedef int (*kxdrdproc_t)(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
 
 extern void xdr_init_encode(struct xdr_stream *xdr, struct xdr_buf *buf,
                            __be32 *p, struct rpc_rqst *rqst);
+extern void xdr_init_encode_pages(struct xdr_stream *xdr, struct xdr_buf *buf,
+                          struct page **pages, struct rpc_rqst *rqst);
 extern __be32 *xdr_reserve_space(struct xdr_stream *xdr, size_t nbytes);
 extern int xdr_reserve_space_vec(struct xdr_stream *xdr, struct kvec *vec,
                size_t nbytes);
index 482586c..b7a7e14 100644 (file)
@@ -947,6 +947,28 @@ void xdr_init_encode(struct xdr_stream *xdr, struct xdr_buf *buf, __be32 *p,
 EXPORT_SYMBOL_GPL(xdr_init_encode);
 
 /**
+ * xdr_init_encode_pages - Initialize an xdr_stream for encoding into pages
+ * @xdr: pointer to xdr_stream struct
+ * @buf: pointer to XDR buffer into which to encode data
+ * @pages: list of pages to decode into
+ * @rqst: pointer to controlling rpc_rqst, for debugging
+ *
+ */
+void xdr_init_encode_pages(struct xdr_stream *xdr, struct xdr_buf *buf,
+                          struct page **pages, struct rpc_rqst *rqst)
+{
+       xdr_reset_scratch_buffer(xdr);
+
+       xdr->buf = buf;
+       xdr->page_ptr = pages;
+       xdr->iov = NULL;
+       xdr->p = page_address(*pages);
+       xdr->end = (void *)xdr->p + min_t(u32, buf->buflen, PAGE_SIZE);
+       xdr->rqst = rqst;
+}
+EXPORT_SYMBOL_GPL(xdr_init_encode_pages);
+
+/**
  * __xdr_commit_encode - Ensure all data is written to buffer
  * @xdr: pointer to xdr_stream
  *