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)
committerChuck Lever <chuck.lever@oracle.com>
Mon, 25 Jan 2021 14:36:24 +0000 (09:36 -0500)
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>
fs/nfsd/nfs3proc.c
fs/nfsd/nfs3xdr.c
fs/nfsd/xdr3.h

index 7ea2fb127f6f2accf13fe395bfe4572c40053961..8675851199f8dde167394d3f3d524b8f13244acf 100644 (file)
@@ -435,6 +435,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.
  */
@@ -452,16 +469,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;
 
@@ -513,16 +526,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 {