Skip to content

Commit dae9a6c

Browse files
chuckleverJ. Bruce Fields
authored andcommitted
NFSD: Have legacy NFSD WRITE decoders use xdr_stream_subsegment()
Refactor. Now that the NFSv2 and NFSv3 XDR decoders have been converted to use xdr_streams, the WRITE decoder functions can use xdr_stream_subsegment() to extract the WRITE payload into its own xdr_buf, just as the NFSv4 WRITE XDR decoder currently does. That makes it possible to pass the first kvec, pages array + length, page_base, and total payload length via a single function parameter. The payload's page_base is not yet assigned or used, but will be in subsequent patches. Signed-off-by: Chuck Lever <[email protected]> Signed-off-by: J. Bruce Fields <[email protected]>
1 parent f49b68d commit dae9a6c

File tree

9 files changed

+15
-33
lines changed

9 files changed

+15
-33
lines changed

fs/nfsd/nfs3proc.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,7 @@ nfsd3_proc_write(struct svc_rqst *rqstp)
201201

202202
fh_copy(&resp->fh, &argp->fh);
203203
resp->committed = argp->stable;
204-
nvecs = svc_fill_write_vector(rqstp, rqstp->rq_arg.pages,
205-
&argp->first, cnt);
204+
nvecs = svc_fill_write_vector(rqstp, &argp->payload);
206205
if (!nvecs) {
207206
resp->status = nfserr_io;
208207
goto out;

fs/nfsd/nfs3xdr.c

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -621,9 +621,6 @@ nfs3svc_decode_writeargs(struct svc_rqst *rqstp, __be32 *p)
621621
struct xdr_stream *xdr = &rqstp->rq_arg_stream;
622622
struct nfsd3_writeargs *args = rqstp->rq_argp;
623623
u32 max_blocksize = svc_max_payload(rqstp);
624-
struct kvec *head = rqstp->rq_arg.head;
625-
struct kvec *tail = rqstp->rq_arg.tail;
626-
size_t remaining;
627624

628625
if (!svcxdr_decode_nfs_fh3(xdr, &args->fh))
629626
return 0;
@@ -641,17 +638,12 @@ nfs3svc_decode_writeargs(struct svc_rqst *rqstp, __be32 *p)
641638
/* request sanity */
642639
if (args->count != args->len)
643640
return 0;
644-
remaining = head->iov_len + rqstp->rq_arg.page_len + tail->iov_len;
645-
remaining -= xdr_stream_pos(xdr);
646-
if (remaining < xdr_align_size(args->len))
647-
return 0;
648641
if (args->count > max_blocksize) {
649642
args->count = max_blocksize;
650643
args->len = max_blocksize;
651644
}
652-
653-
args->first.iov_base = xdr->p;
654-
args->first.iov_len = head->iov_len - xdr_stream_pos(xdr);
645+
if (!xdr_stream_subsegment(xdr, &args->payload, args->count))
646+
return 0;
655647

656648
return 1;
657649
}

fs/nfsd/nfs4proc.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1033,8 +1033,7 @@ nfsd4_write(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
10331033

10341034
write->wr_how_written = write->wr_stable_how;
10351035

1036-
nvecs = svc_fill_write_vector(rqstp, write->wr_payload.pages,
1037-
write->wr_payload.head, write->wr_buflen);
1036+
nvecs = svc_fill_write_vector(rqstp, &write->wr_payload);
10381037
WARN_ON_ONCE(nvecs > ARRAY_SIZE(rqstp->rq_vec));
10391038

10401039
status = nfsd_vfs_write(rqstp, &cstate->current_fh, nf,

fs/nfsd/nfsproc.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,8 +234,7 @@ nfsd_proc_write(struct svc_rqst *rqstp)
234234
SVCFH_fmt(&argp->fh),
235235
argp->len, argp->offset);
236236

237-
nvecs = svc_fill_write_vector(rqstp, rqstp->rq_arg.pages,
238-
&argp->first, cnt);
237+
nvecs = svc_fill_write_vector(rqstp, &argp->payload);
239238
if (!nvecs) {
240239
resp->status = nfserr_io;
241240
goto out;

fs/nfsd/nfsxdr.c

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -325,10 +325,7 @@ nfssvc_decode_writeargs(struct svc_rqst *rqstp, __be32 *p)
325325
{
326326
struct xdr_stream *xdr = &rqstp->rq_arg_stream;
327327
struct nfsd_writeargs *args = rqstp->rq_argp;
328-
struct kvec *head = rqstp->rq_arg.head;
329-
struct kvec *tail = rqstp->rq_arg.tail;
330328
u32 beginoffset, totalcount;
331-
size_t remaining;
332329

333330
if (!svcxdr_decode_fhandle(xdr, &args->fh))
334331
return 0;
@@ -346,12 +343,8 @@ nfssvc_decode_writeargs(struct svc_rqst *rqstp, __be32 *p)
346343
return 0;
347344
if (args->len > NFSSVC_MAXBLKSIZE_V2)
348345
return 0;
349-
remaining = head->iov_len + rqstp->rq_arg.page_len + tail->iov_len;
350-
remaining -= xdr_stream_pos(xdr);
351-
if (remaining < xdr_align_size(args->len))
346+
if (!xdr_stream_subsegment(xdr, &args->payload, args->len))
352347
return 0;
353-
args->first.iov_base = xdr->p;
354-
args->first.iov_len = head->iov_len - xdr_stream_pos(xdr);
355348

356349
return 1;
357350
}

fs/nfsd/xdr.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ struct nfsd_writeargs {
3333
svc_fh fh;
3434
__u32 offset;
3535
int len;
36-
struct kvec first;
36+
struct xdr_buf payload;
3737
};
3838

3939
struct nfsd_createargs {

fs/nfsd/xdr3.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ struct nfsd3_writeargs {
4040
__u32 count;
4141
int stable;
4242
__u32 len;
43-
struct kvec first;
43+
struct xdr_buf payload;
4444
};
4545

4646
struct nfsd3_createargs {

include/linux/sunrpc/svc.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -532,8 +532,7 @@ int svc_encode_result_payload(struct svc_rqst *rqstp,
532532
unsigned int offset,
533533
unsigned int length);
534534
unsigned int svc_fill_write_vector(struct svc_rqst *rqstp,
535-
struct page **pages,
536-
struct kvec *first, size_t total);
535+
struct xdr_buf *payload);
537536
char *svc_fill_symlink_pathname(struct svc_rqst *rqstp,
538537
struct kvec *first, void *p,
539538
size_t total);

net/sunrpc/svc.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1676,16 +1676,17 @@ EXPORT_SYMBOL_GPL(svc_encode_result_payload);
16761676
/**
16771677
* svc_fill_write_vector - Construct data argument for VFS write call
16781678
* @rqstp: svc_rqst to operate on
1679-
* @pages: list of pages containing data payload
1680-
* @first: buffer containing first section of write payload
1681-
* @total: total number of bytes of write payload
1679+
* @payload: xdr_buf containing only the write data payload
16821680
*
16831681
* Fills in rqstp::rq_vec, and returns the number of elements.
16841682
*/
1685-
unsigned int svc_fill_write_vector(struct svc_rqst *rqstp, struct page **pages,
1686-
struct kvec *first, size_t total)
1683+
unsigned int svc_fill_write_vector(struct svc_rqst *rqstp,
1684+
struct xdr_buf *payload)
16871685
{
1686+
struct page **pages = payload->pages;
1687+
struct kvec *first = payload->head;
16881688
struct kvec *vec = rqstp->rq_vec;
1689+
size_t total = payload->len;
16891690
unsigned int i;
16901691

16911692
/* Some types of transport can present the write payload

0 commit comments

Comments
 (0)