Skip to content

Commit e560e3b

Browse files
chuckleverJ. Bruce Fields
authored andcommitted
svcrdma: Add zero padding if the client doesn't send it
See RFC 5666 section 3.7: clients don't have to send zero XDR padding. BugLink: https://bugzilla.linux-nfs.org/show_bug.cgi?id=246 Signed-off-by: Chuck Lever <[email protected]> Signed-off-by: J. Bruce Fields <[email protected]>
1 parent d55a166 commit e560e3b

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

net/sunrpc/xprtrdma/svc_rdma_recvfrom.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
#include <linux/sunrpc/debug.h>
4444
#include <linux/sunrpc/rpc_rdma.h>
4545
#include <linux/spinlock.h>
46+
#include <linux/highmem.h>
4647
#include <asm/unaligned.h>
4748
#include <rdma/ib_verbs.h>
4849
#include <rdma/rdma_cm.h>
@@ -435,6 +436,32 @@ static int rdma_read_chunks(struct svcxprt_rdma *xprt,
435436
return ret;
436437
}
437438

439+
/*
440+
* To avoid a separate RDMA READ just for a handful of zero bytes,
441+
* RFC 5666 section 3.7 allows the client to omit the XDR zero pad
442+
* in chunk lists.
443+
*/
444+
static void
445+
rdma_fix_xdr_pad(struct xdr_buf *buf)
446+
{
447+
unsigned int page_len = buf->page_len;
448+
unsigned int size = (XDR_QUADLEN(page_len) << 2) - page_len;
449+
unsigned int offset, pg_no;
450+
char *p;
451+
452+
if (size == 0)
453+
return;
454+
455+
pg_no = page_len >> PAGE_SHIFT;
456+
offset = page_len & ~PAGE_MASK;
457+
p = page_address(buf->pages[pg_no]);
458+
memset(p + offset, 0, size);
459+
460+
buf->page_len += size;
461+
buf->buflen += size;
462+
buf->len += size;
463+
}
464+
438465
static int rdma_read_complete(struct svc_rqst *rqstp,
439466
struct svc_rdma_op_ctxt *head)
440467
{
@@ -449,6 +476,7 @@ static int rdma_read_complete(struct svc_rqst *rqstp,
449476
rqstp->rq_pages[page_no] = head->pages[page_no];
450477
}
451478
/* Point rq_arg.pages past header */
479+
rdma_fix_xdr_pad(&head->arg);
452480
rqstp->rq_arg.pages = &rqstp->rq_pages[head->hdr_count];
453481
rqstp->rq_arg.page_len = head->arg.page_len;
454482
rqstp->rq_arg.page_base = head->arg.page_base;

0 commit comments

Comments
 (0)