Skip to content

Commit

Permalink
NFSD: Add helper to set up the pages where the dirlist is encoded
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
chucklever committed Jan 25, 2021
1 parent 0a8f37f commit 40116eb
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 31 deletions.
29 changes: 19 additions & 10 deletions fs/nfsd/nfs3proc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand All @@ -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;

Expand Down Expand Up @@ -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;

Expand Down
20 changes: 0 additions & 20 deletions fs/nfsd/nfs3xdr.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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);
}
Expand All @@ -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)
Expand All @@ -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);
}

Expand Down
1 change: 0 additions & 1 deletion fs/nfsd/xdr3.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ struct nfsd3_readdirargs {
__u32 dircount;
__u32 count;
__be32 * verf;
__be32 * buffer;
};

struct nfsd3_commitargs {
Expand Down

0 comments on commit 40116eb

Please sign in to comment.