]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
NFSD: Add helper to set up the pages where the dirlist is encoded
authorChuck Lever <chuck.lever@oracle.com>
Tue, 17 Nov 2020 14:50:23 +0000 (09:50 -0500)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 21 Jun 2024 12:52:51 +0000 (14:52 +0200)
[ Upstream commit 40116ebd0934cca7e46423bdb3397d3d27eb9fb9 ]

De-duplicate some code that is used by both READDIR and READDIRPLUS
to build the dirlist in the Reply. Because this code is not related
to decoding READ arguments, it is moved to a more appropriate spot.

Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
fs/nfsd/nfs3proc.c
fs/nfsd/nfs3xdr.c
fs/nfsd/xdr3.h

index 8cffd9852ef043dc38f169d6bd8483d5faa6675d..25f31a03c4f1b36ec58cb3e3cd85c002b1f578c1 100644 (file)
@@ -440,6 +440,23 @@ nfsd3_proc_link(struct svc_rqst *rqstp)
        return rpc_success;
 }
 
+static void nfsd3_init_dirlist_pages(struct svc_rqst *rqstp,
+                                    struct nfsd3_readdirres *resp,
+                                    int count)
+{
+       count = min_t(u32, count, svc_max_payload(rqstp));
+
+       /* Convert byte count to number of words (i.e. >> 2),
+        * and reserve room for the NULL ptr & eof flag (-2 words) */
+       resp->buflen = (count >> 2) - 2;
+
+       resp->buffer = page_address(*rqstp->rq_next_page);
+       while (count > 0) {
+               rqstp->rq_next_page++;
+               count -= PAGE_SIZE;
+       }
+}
+
 /*
  * Read a portion of a directory.
  */
@@ -457,16 +474,12 @@ nfsd3_proc_readdir(struct svc_rqst *rqstp)
                                SVCFH_fmt(&argp->fh),
                                argp->count, (u32) argp->cookie);
 
-       /* Make sure we've room for the NULL ptr & eof flag, and shrink to
-        * client read size */
-       count = (argp->count >> 2) - 2;
+       nfsd3_init_dirlist_pages(rqstp, resp, argp->count);
 
        /* Read directory and encode entries on the fly */
        fh_copy(&resp->fh, &argp->fh);
 
-       resp->buflen = count;
        resp->common.err = nfs_ok;
-       resp->buffer = argp->buffer;
        resp->rqstp = rqstp;
        offset = argp->cookie;
 
@@ -518,16 +531,12 @@ nfsd3_proc_readdirplus(struct svc_rqst *rqstp)
                                SVCFH_fmt(&argp->fh),
                                argp->count, (u32) argp->cookie);
 
-       /* Convert byte count to number of words (i.e. >> 2),
-        * and reserve room for the NULL ptr & eof flag (-2 words) */
-       resp->count = (argp->count >> 2) - 2;
+       nfsd3_init_dirlist_pages(rqstp, resp, argp->count);
 
        /* Read directory and encode entries on the fly */
        fh_copy(&resp->fh, &argp->fh);
 
        resp->common.err = nfs_ok;
-       resp->buffer = argp->buffer;
-       resp->buflen = resp->count;
        resp->rqstp = rqstp;
        offset = argp->cookie;
 
index 6b6a839c1fc8cc75a113a33c12bb1a361be2d8bf..8394aeb8381e606a448ca6b56624ed15eb133ab4 100644 (file)
@@ -560,8 +560,6 @@ int
 nfs3svc_decode_readdirargs(struct svc_rqst *rqstp, __be32 *p)
 {
        struct nfsd3_readdirargs *args = rqstp->rq_argp;
-       int len;
-       u32 max_blocksize = svc_max_payload(rqstp);
 
        p = decode_fh(p, &args->fh);
        if (!p)
@@ -570,14 +568,6 @@ nfs3svc_decode_readdirargs(struct svc_rqst *rqstp, __be32 *p)
        args->verf   = p; p += 2;
        args->dircount = ~0;
        args->count  = ntohl(*p++);
-       len = args->count  = min_t(u32, args->count, max_blocksize);
-
-       while (len > 0) {
-               struct page *p = *(rqstp->rq_next_page++);
-               if (!args->buffer)
-                       args->buffer = page_address(p);
-               len -= PAGE_SIZE;
-       }
 
        return xdr_argsize_check(rqstp, p);
 }
@@ -586,8 +576,6 @@ int
 nfs3svc_decode_readdirplusargs(struct svc_rqst *rqstp, __be32 *p)
 {
        struct nfsd3_readdirargs *args = rqstp->rq_argp;
-       int len;
-       u32 max_blocksize = svc_max_payload(rqstp);
 
        p = decode_fh(p, &args->fh);
        if (!p)
@@ -597,14 +585,6 @@ nfs3svc_decode_readdirplusargs(struct svc_rqst *rqstp, __be32 *p)
        args->dircount = ntohl(*p++);
        args->count    = ntohl(*p++);
 
-       len = args->count = min(args->count, max_blocksize);
-       while (len > 0) {
-               struct page *p = *(rqstp->rq_next_page++);
-               if (!args->buffer)
-                       args->buffer = page_address(p);
-               len -= PAGE_SIZE;
-       }
-
        return xdr_argsize_check(rqstp, p);
 }
 
index 08f909142ddf71785bd22586651a07c42040cc86..789a364d5e69d40d0cd987bd827bd216dc00d6f7 100644 (file)
@@ -93,7 +93,6 @@ struct nfsd3_readdirargs {
        __u32                   dircount;
        __u32                   count;
        __be32 *                verf;
-       __be32 *                buffer;
 };
 
 struct nfsd3_commitargs {