Commit f7da7a129d57bfe0f74573dc03531c63e1360fae
Committed by
Boaz Harrosh
1 parent
35c8bb543c
Exists in
master
and in
20 other branches
SUNRPC: introduce xdr_init_decode_pages
Initialize xdr_stream and xdr_buf using an array of page pointers and length of buffer. Signed-off-by: Benny Halevy <bhalevy@panasas.com>
Showing 5 changed files with 27 additions and 21 deletions Side-by-side Diff
fs/nfs/dir.c
... | ... | @@ -512,12 +512,7 @@ |
512 | 512 | struct page **xdr_pages, struct page *page, unsigned int buflen) |
513 | 513 | { |
514 | 514 | struct xdr_stream stream; |
515 | - struct xdr_buf buf = { | |
516 | - .pages = xdr_pages, | |
517 | - .page_len = buflen, | |
518 | - .buflen = buflen, | |
519 | - .len = buflen, | |
520 | - }; | |
515 | + struct xdr_buf buf; | |
521 | 516 | struct page *scratch; |
522 | 517 | struct nfs_cache_array *array; |
523 | 518 | unsigned int count = 0; |
... | ... | @@ -527,7 +522,7 @@ |
527 | 522 | if (scratch == NULL) |
528 | 523 | return -ENOMEM; |
529 | 524 | |
530 | - xdr_init_decode(&stream, &buf, NULL); | |
525 | + xdr_init_decode_pages(&stream, &buf, xdr_pages, buflen); | |
531 | 526 | xdr_set_scratch_buffer(&stream, page_address(scratch), PAGE_SIZE); |
532 | 527 | |
533 | 528 | do { |
fs/nfs/nfs4filelayout.c
... | ... | @@ -510,12 +510,7 @@ |
510 | 510 | gfp_t gfp_flags) |
511 | 511 | { |
512 | 512 | struct xdr_stream stream; |
513 | - struct xdr_buf buf = { | |
514 | - .pages = lgr->layoutp->pages, | |
515 | - .page_len = lgr->layoutp->len, | |
516 | - .buflen = lgr->layoutp->len, | |
517 | - .len = lgr->layoutp->len, | |
518 | - }; | |
513 | + struct xdr_buf buf; | |
519 | 514 | struct page *scratch; |
520 | 515 | __be32 *p; |
521 | 516 | uint32_t nfl_util; |
... | ... | @@ -527,7 +522,7 @@ |
527 | 522 | if (!scratch) |
528 | 523 | return -ENOMEM; |
529 | 524 | |
530 | - xdr_init_decode(&stream, &buf, NULL); | |
525 | + xdr_init_decode_pages(&stream, &buf, lgr->layoutp->pages, lgr->layoutp->len); | |
531 | 526 | xdr_set_scratch_buffer(&stream, page_address(scratch), PAGE_SIZE); |
532 | 527 | |
533 | 528 | /* 20 = ufl_util (4), first_stripe_index (4), pattern_offset (8), |
fs/nfs/nfs4filelayoutdev.c
... | ... | @@ -308,12 +308,7 @@ |
308 | 308 | u8 max_stripe_index; |
309 | 309 | struct nfs4_file_layout_dsaddr *dsaddr = NULL; |
310 | 310 | struct xdr_stream stream; |
311 | - struct xdr_buf buf = { | |
312 | - .pages = pdev->pages, | |
313 | - .page_len = pdev->pglen, | |
314 | - .buflen = pdev->pglen, | |
315 | - .len = pdev->pglen, | |
316 | - }; | |
311 | + struct xdr_buf buf; | |
317 | 312 | struct page *scratch; |
318 | 313 | |
319 | 314 | /* set up xdr stream */ |
... | ... | @@ -321,7 +316,7 @@ |
321 | 316 | if (!scratch) |
322 | 317 | goto out_err; |
323 | 318 | |
324 | - xdr_init_decode(&stream, &buf, NULL); | |
319 | + xdr_init_decode_pages(&stream, &buf, pdev->pages, pdev->pglen); | |
325 | 320 | xdr_set_scratch_buffer(&stream, page_address(scratch), PAGE_SIZE); |
326 | 321 | |
327 | 322 | /* Get the stripe count (number of stripe index) */ |
include/linux/sunrpc/xdr.h
... | ... | @@ -216,6 +216,8 @@ |
216 | 216 | extern void xdr_write_pages(struct xdr_stream *xdr, struct page **pages, |
217 | 217 | unsigned int base, unsigned int len); |
218 | 218 | extern void xdr_init_decode(struct xdr_stream *xdr, struct xdr_buf *buf, __be32 *p); |
219 | +extern void xdr_init_decode_pages(struct xdr_stream *xdr, struct xdr_buf *buf, | |
220 | + struct page **pages, unsigned int len); | |
219 | 221 | extern void xdr_set_scratch_buffer(struct xdr_stream *xdr, void *buf, size_t buflen); |
220 | 222 | extern __be32 *xdr_inline_decode(struct xdr_stream *xdr, size_t nbytes); |
221 | 223 | extern void xdr_read_pages(struct xdr_stream *xdr, unsigned int len); |
net/sunrpc/xdr.c
... | ... | @@ -638,6 +638,25 @@ |
638 | 638 | } |
639 | 639 | EXPORT_SYMBOL_GPL(xdr_init_decode); |
640 | 640 | |
641 | +/** | |
642 | + * xdr_init_decode - Initialize an xdr_stream for decoding data. | |
643 | + * @xdr: pointer to xdr_stream struct | |
644 | + * @buf: pointer to XDR buffer from which to decode data | |
645 | + * @pages: list of pages to decode into | |
646 | + * @len: length in bytes of buffer in pages | |
647 | + */ | |
648 | +void xdr_init_decode_pages(struct xdr_stream *xdr, struct xdr_buf *buf, | |
649 | + struct page **pages, unsigned int len) | |
650 | +{ | |
651 | + memset(buf, 0, sizeof(*buf)); | |
652 | + buf->pages = pages; | |
653 | + buf->page_len = len; | |
654 | + buf->buflen = len; | |
655 | + buf->len = len; | |
656 | + xdr_init_decode(xdr, buf, NULL); | |
657 | +} | |
658 | +EXPORT_SYMBOL_GPL(xdr_init_decode_pages); | |
659 | + | |
641 | 660 | static __be32 * __xdr_inline_decode(struct xdr_stream *xdr, size_t nbytes) |
642 | 661 | { |
643 | 662 | __be32 *p = xdr->p; |