]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
SUNRPC: Add xdr_set_scratch_page() and xdr_reset_scratch_buffer()
authorChuck Lever <chuck.lever@oracle.com>
Wed, 11 Nov 2020 20:52:47 +0000 (15:52 -0500)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 21 Jun 2024 12:52:33 +0000 (14:52 +0200)
[ Upstream commit 0ae4c3e8a64ace1b8d7de033b0751afe43024416 ]

Clean up: De-duplicate some frequently-used code.

Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
13 files changed:
fs/nfs/blocklayout/blocklayout.c
fs/nfs/blocklayout/dev.c
fs/nfs/dir.c
fs/nfs/filelayout/filelayout.c
fs/nfs/filelayout/filelayoutdev.c
fs/nfs/flexfilelayout/flexfilelayout.c
fs/nfs/flexfilelayout/flexfilelayoutdev.c
fs/nfs/nfs42xdr.c
fs/nfs/nfs4xdr.c
fs/nfsd/nfs4proc.c
include/linux/sunrpc/xdr.h
net/sunrpc/auth_gss/gss_rpc_xdr.c
net/sunrpc/xdr.c

index 73000aa2d220b72bfd6b73422d1045fc48d0a9bb..a9e563145e0c28f0ec7404908265868f06b868c4 100644 (file)
@@ -699,7 +699,7 @@ bl_alloc_lseg(struct pnfs_layout_hdr *lo, struct nfs4_layoutget_res *lgr,
 
        xdr_init_decode_pages(&xdr, &buf,
                        lgr->layoutp->pages, lgr->layoutp->len);
-       xdr_set_scratch_buffer(&xdr, page_address(scratch), PAGE_SIZE);
+       xdr_set_scratch_page(&xdr, scratch);
 
        status = -EIO;
        p = xdr_inline_decode(&xdr, 4);
index 6e3a14fdff9c8841b0d1af30a88926081ef725ef..16412d6636e8603083db35bbfd95837f4d3e1e77 100644 (file)
@@ -510,7 +510,7 @@ bl_alloc_deviceid_node(struct nfs_server *server, struct pnfs_device *pdev,
                goto out;
 
        xdr_init_decode_pages(&xdr, &buf, pdev->pages, pdev->pglen);
-       xdr_set_scratch_buffer(&xdr, page_address(scratch), PAGE_SIZE);
+       xdr_set_scratch_page(&xdr, scratch);
 
        p = xdr_inline_decode(&xdr, sizeof(__be32));
        if (!p)
index 9f88ca7b2001567447aa47c79d6b91aba12b3246..935029632d5f6e09c91135ccb8a95e212b1ba619 100644 (file)
@@ -576,7 +576,7 @@ int nfs_readdir_page_filler(nfs_readdir_descriptor_t *desc, struct nfs_entry *en
                goto out_nopages;
 
        xdr_init_decode_pages(&stream, &buf, xdr_pages, buflen);
-       xdr_set_scratch_buffer(&stream, page_address(scratch), PAGE_SIZE);
+       xdr_set_scratch_page(&stream, scratch);
 
        do {
                if (entry->label)
index deecfb50dd7e3d6eb452eef2adef05cf3bfa4295..45eec08ec904f0f323a7a0b1a7c41ee12621d478 100644 (file)
@@ -666,7 +666,7 @@ filelayout_decode_layout(struct pnfs_layout_hdr *flo,
                return -ENOMEM;
 
        xdr_init_decode_pages(&stream, &buf, lgr->layoutp->pages, lgr->layoutp->len);
-       xdr_set_scratch_buffer(&stream, page_address(scratch), PAGE_SIZE);
+       xdr_set_scratch_page(&stream, scratch);
 
        /* 20 = ufl_util (4), first_stripe_index (4), pattern_offset (8),
         * num_fh (4) */
index d913e818858f3fee8d7d5c199714d2d79b1bef39..86c3f7e69ec423d4f13952ee2eea8622b7e8b2a0 100644 (file)
@@ -82,7 +82,7 @@ nfs4_fl_alloc_deviceid_node(struct nfs_server *server, struct pnfs_device *pdev,
                goto out_err;
 
        xdr_init_decode_pages(&stream, &buf, pdev->pages, pdev->pglen);
-       xdr_set_scratch_buffer(&stream, page_address(scratch), PAGE_SIZE);
+       xdr_set_scratch_page(&stream, scratch);
 
        /* Get the stripe count (number of stripe index) */
        p = xdr_inline_decode(&stream, 4);
index e4f2820ba5a596eb81f09770a965f5770ddd7e9a..f2ae271fe7ec7c075c30a1c28f2eb02bf8202223 100644 (file)
@@ -378,7 +378,7 @@ ff_layout_alloc_lseg(struct pnfs_layout_hdr *lh,
 
        xdr_init_decode_pages(&stream, &buf, lgr->layoutp->pages,
                              lgr->layoutp->len);
-       xdr_set_scratch_buffer(&stream, page_address(scratch), PAGE_SIZE);
+       xdr_set_scratch_page(&stream, scratch);
 
        /* stripe unit and mirror_array_cnt */
        rc = -EIO;
index 1f12297109b4186d46f54031606da22e10470527..bfa7202ca7be14f1b6728c62a04341430074bfec 100644 (file)
@@ -69,7 +69,7 @@ nfs4_ff_alloc_deviceid_node(struct nfs_server *server, struct pnfs_device *pdev,
        INIT_LIST_HEAD(&dsaddrs);
 
        xdr_init_decode_pages(&stream, &buf, pdev->pages, pdev->pglen);
-       xdr_set_scratch_buffer(&stream, page_address(scratch), PAGE_SIZE);
+       xdr_set_scratch_page(&stream, scratch);
 
        /* multipath count */
        p = xdr_inline_decode(&stream, 4);
index f2248d9d4db51a86e196526c69516332623a240a..df5bee2f505c4bc4c3ca113e5111da1227948d1c 100644 (file)
@@ -1536,7 +1536,7 @@ static int nfs4_xdr_dec_listxattrs(struct rpc_rqst *rqstp,
        struct compound_hdr hdr;
        int status;
 
-       xdr_set_scratch_buffer(xdr, page_address(res->scratch), PAGE_SIZE);
+       xdr_set_scratch_page(xdr, res->scratch);
 
        status = decode_compound_hdr(xdr, &hdr);
        if (status)
index f1e599553f2bee98c2c131012b919327c649e3a0..4e5c6cb770ad56ce3f5569fb70e22c70fbec3990 100644 (file)
@@ -6404,10 +6404,8 @@ nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
        struct compound_hdr hdr;
        int status;
 
-       if (res->acl_scratch != NULL) {
-               void *p = page_address(res->acl_scratch);
-               xdr_set_scratch_buffer(xdr, p, PAGE_SIZE);
-       }
+       if (res->acl_scratch != NULL)
+               xdr_set_scratch_page(xdr, res->acl_scratch);
        status = decode_compound_hdr(xdr, &hdr);
        if (status)
                goto out;
index e84996c3867c7adc92b71580adf36173da113a43..c01b6f7462fcbbb93276dd34c9eac29f176cc33b 100644 (file)
@@ -2266,7 +2266,7 @@ static void svcxdr_init_encode(struct svc_rqst *rqstp,
        xdr->end = head->iov_base + PAGE_SIZE - rqstp->rq_auth_slack;
        /* Tail and page_len should be zero at this point: */
        buf->len = buf->head[0].iov_len;
-       xdr->scratch.iov_len = 0;
+       xdr_reset_scratch_buffer(xdr);
        xdr->page_ptr = buf->pages - 1;
        buf->buflen = PAGE_SIZE * (1 + rqstp->rq_page_end - buf->pages)
                - rqstp->rq_auth_slack;
index 6d9d1520612b87e07dedff9875c49f302aa70075..0c8cab6210b3bfab72b6241bed8d1492e4488113 100644 (file)
@@ -246,7 +246,6 @@ extern void xdr_init_decode(struct xdr_stream *xdr, struct xdr_buf *buf,
                            __be32 *p, struct rpc_rqst *rqst);
 extern void xdr_init_decode_pages(struct xdr_stream *xdr, struct xdr_buf *buf,
                struct page **pages, unsigned int len);
-extern void xdr_set_scratch_buffer(struct xdr_stream *xdr, void *buf, size_t buflen);
 extern __be32 *xdr_inline_decode(struct xdr_stream *xdr, size_t nbytes);
 extern unsigned int xdr_read_pages(struct xdr_stream *xdr, unsigned int len);
 extern void xdr_enter_page(struct xdr_stream *xdr, unsigned int len);
@@ -254,6 +253,49 @@ extern int xdr_process_buf(struct xdr_buf *buf, unsigned int offset, unsigned in
 extern uint64_t xdr_align_data(struct xdr_stream *, uint64_t, uint32_t);
 extern uint64_t xdr_expand_hole(struct xdr_stream *, uint64_t, uint64_t);
 
+/**
+ * xdr_set_scratch_buffer - Attach a scratch buffer for decoding data.
+ * @xdr: pointer to xdr_stream struct
+ * @buf: pointer to an empty buffer
+ * @buflen: size of 'buf'
+ *
+ * The scratch buffer is used when decoding from an array of pages.
+ * If an xdr_inline_decode() call spans across page boundaries, then
+ * we copy the data into the scratch buffer in order to allow linear
+ * access.
+ */
+static inline void
+xdr_set_scratch_buffer(struct xdr_stream *xdr, void *buf, size_t buflen)
+{
+       xdr->scratch.iov_base = buf;
+       xdr->scratch.iov_len = buflen;
+}
+
+/**
+ * xdr_set_scratch_page - Attach a scratch buffer for decoding data
+ * @xdr: pointer to xdr_stream struct
+ * @page: an anonymous page
+ *
+ * See xdr_set_scratch_buffer().
+ */
+static inline void
+xdr_set_scratch_page(struct xdr_stream *xdr, struct page *page)
+{
+       xdr_set_scratch_buffer(xdr, page_address(page), PAGE_SIZE);
+}
+
+/**
+ * xdr_reset_scratch_buffer - Clear scratch buffer information
+ * @xdr: pointer to xdr_stream struct
+ *
+ * See xdr_set_scratch_buffer().
+ */
+static inline void
+xdr_reset_scratch_buffer(struct xdr_stream *xdr)
+{
+       xdr_set_scratch_buffer(xdr, NULL, 0);
+}
+
 /**
  * xdr_stream_remaining - Return the number of bytes remaining in the stream
  * @xdr: pointer to struct xdr_stream
index e265b8d38aa14db3f7c89e5a050e7d45b890e586..a857fc99431ce5fddff19cb6dff6a3d21ca96b75 100644 (file)
@@ -800,7 +800,7 @@ int gssx_dec_accept_sec_context(struct rpc_rqst *rqstp,
        scratch = alloc_page(GFP_KERNEL);
        if (!scratch)
                return -ENOMEM;
-       xdr_set_scratch_buffer(xdr, page_address(scratch), PAGE_SIZE);
+       xdr_set_scratch_page(xdr, scratch);
 
        /* res->status */
        err = gssx_dec_status(xdr, &res->status);
index d84bb5037bb5b244320baed525c110665096ef3f..02adc5c7f034d2671c36fbaa2ebe1b2a314fbf48 100644 (file)
@@ -669,7 +669,7 @@ void xdr_init_encode(struct xdr_stream *xdr, struct xdr_buf *buf, __be32 *p,
        struct kvec *iov = buf->head;
        int scratch_len = buf->buflen - buf->page_len - buf->tail[0].iov_len;
 
-       xdr_set_scratch_buffer(xdr, NULL, 0);
+       xdr_reset_scratch_buffer(xdr);
        BUG_ON(scratch_len < 0);
        xdr->buf = buf;
        xdr->iov = iov;
@@ -713,7 +713,7 @@ inline void xdr_commit_encode(struct xdr_stream *xdr)
        page = page_address(*xdr->page_ptr);
        memcpy(xdr->scratch.iov_base, page, shift);
        memmove(page, page + shift, (void *)xdr->p - page);
-       xdr->scratch.iov_len = 0;
+       xdr_reset_scratch_buffer(xdr);
 }
 EXPORT_SYMBOL_GPL(xdr_commit_encode);
 
@@ -743,8 +743,7 @@ static __be32 *xdr_get_next_encode_buffer(struct xdr_stream *xdr,
         * the "scratch" iov to track any temporarily unused fragment of
         * space at the end of the previous buffer:
         */
-       xdr->scratch.iov_base = xdr->p;
-       xdr->scratch.iov_len = frag1bytes;
+       xdr_set_scratch_buffer(xdr, xdr->p, frag1bytes);
        p = page_address(*xdr->page_ptr);
        /*
         * Note this is where the next encode will start after we've
@@ -1056,8 +1055,7 @@ void xdr_init_decode(struct xdr_stream *xdr, struct xdr_buf *buf, __be32 *p,
                     struct rpc_rqst *rqst)
 {
        xdr->buf = buf;
-       xdr->scratch.iov_base = NULL;
-       xdr->scratch.iov_len = 0;
+       xdr_reset_scratch_buffer(xdr);
        xdr->nwords = XDR_QUADLEN(buf->len);
        if (buf->head[0].iov_len != 0)
                xdr_set_iov(xdr, buf->head, buf->len);
@@ -1105,24 +1103,6 @@ static __be32 * __xdr_inline_decode(struct xdr_stream *xdr, size_t nbytes)
        return p;
 }
 
-/**
- * xdr_set_scratch_buffer - Attach a scratch buffer for decoding data.
- * @xdr: pointer to xdr_stream struct
- * @buf: pointer to an empty buffer
- * @buflen: size of 'buf'
- *
- * The scratch buffer is used when decoding from an array of pages.
- * If an xdr_inline_decode() call spans across page boundaries, then
- * we copy the data into the scratch buffer in order to allow linear
- * access.
- */
-void xdr_set_scratch_buffer(struct xdr_stream *xdr, void *buf, size_t buflen)
-{
-       xdr->scratch.iov_base = buf;
-       xdr->scratch.iov_len = buflen;
-}
-EXPORT_SYMBOL_GPL(xdr_set_scratch_buffer);
-
 static __be32 *xdr_copy_to_scratch(struct xdr_stream *xdr, size_t nbytes)
 {
        __be32 *p;