Skip to content

Commit

Permalink
svcrpc: track rpc data length separately from sk_tcplen
Browse files Browse the repository at this point in the history
Keep a separate field, sk_datalen, that tracks only the data contained
in a fragment, not including the fragment header.

For now, this is always just max(0, sk_tcplen - 4), but after we allow
multiple fragments sk_datalen will accumulate the total rpc data size
while sk_tcplen only tracks progress receiving the current fragment.

Signed-off-by: J. Bruce Fields <bfields@redhat.com>
  • Loading branch information
J. Bruce Fields committed Dec 4, 2012
1 parent 6a72ae2 commit 8af345f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
11 changes: 9 additions & 2 deletions include/linux/sunrpc/svcsock.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,15 @@ struct svc_sock {
void (*sk_owspace)(struct sock *);

/* private TCP part */
__be32 sk_reclen; /* length of record */
u32 sk_tcplen; /* current read length */
/* On-the-wire fragment header: */
__be32 sk_reclen;
/* As we receive a record, this includes the length received so
* far (including the fragment header): */
u32 sk_tcplen;
/* Total length of the data (not including fragment headers)
* received so far in the fragments making up this rpc: */
u32 sk_datalen;

struct page * sk_pages[RPCSVC_MAXPAGES]; /* received data */
};

Expand Down
19 changes: 12 additions & 7 deletions net/sunrpc/svcsock.c
Original file line number Diff line number Diff line change
Expand Up @@ -874,9 +874,9 @@ static unsigned int svc_tcp_restore_pages(struct svc_sock *svsk, struct svc_rqst
{
unsigned int i, len, npages;

if (svsk->sk_tcplen <= sizeof(rpc_fraghdr))
if (svsk->sk_datalen == 0)
return 0;
len = svsk->sk_tcplen - sizeof(rpc_fraghdr);
len = svsk->sk_datalen;
npages = (len + PAGE_SIZE - 1) >> PAGE_SHIFT;
for (i = 0; i < npages; i++) {
if (rqstp->rq_pages[i] != NULL)
Expand All @@ -893,9 +893,9 @@ static void svc_tcp_save_pages(struct svc_sock *svsk, struct svc_rqst *rqstp)
{
unsigned int i, len, npages;

if (svsk->sk_tcplen <= sizeof(rpc_fraghdr))
if (svsk->sk_datalen == 0)
return;
len = svsk->sk_tcplen - sizeof(rpc_fraghdr);
len = svsk->sk_datalen;
npages = (len + PAGE_SIZE - 1) >> PAGE_SHIFT;
for (i = 0; i < npages; i++) {
svsk->sk_pages[i] = rqstp->rq_pages[i];
Expand All @@ -907,9 +907,9 @@ static void svc_tcp_clear_pages(struct svc_sock *svsk)
{
unsigned int i, len, npages;

if (svsk->sk_tcplen <= sizeof(rpc_fraghdr))
if (svsk->sk_datalen == 0)
goto out;
len = svsk->sk_tcplen - sizeof(rpc_fraghdr);
len = svsk->sk_datalen;
npages = (len + PAGE_SIZE - 1) >> PAGE_SHIFT;
for (i = 0; i < npages; i++) {
BUG_ON(svsk->sk_pages[i] == NULL);
Expand All @@ -918,6 +918,7 @@ static void svc_tcp_clear_pages(struct svc_sock *svsk)
}
out:
svsk->sk_tcplen = 0;
svsk->sk_datalen = 0;
}

/*
Expand Down Expand Up @@ -1066,8 +1067,10 @@ static int svc_tcp_recvfrom(struct svc_rqst *rqstp)

/* Now receive data */
len = svc_partial_recvfrom(rqstp, vec, pnum, want, base);
if (len >= 0)
if (len >= 0) {
svsk->sk_tcplen += len;
svsk->sk_datalen += len;
}
if (len != want) {
svc_tcp_save_pages(svsk, rqstp);
if (len < 0 && len != -EAGAIN)
Expand Down Expand Up @@ -1100,6 +1103,7 @@ static int svc_tcp_recvfrom(struct svc_rqst *rqstp)
/* Reset TCP read info */
svsk->sk_reclen = 0;
svsk->sk_tcplen = 0;
svsk->sk_datalen = 0;
/* If we have more data, signal svc_xprt_enqueue() to try again */
if (svc_recv_available(svsk) > sizeof(rpc_fraghdr))
set_bit(XPT_DATA, &svsk->sk_xprt.xpt_flags);
Expand Down Expand Up @@ -1296,6 +1300,7 @@ static void svc_tcp_init(struct svc_sock *svsk, struct svc_serv *serv)

svsk->sk_reclen = 0;
svsk->sk_tcplen = 0;
svsk->sk_datalen = 0;
memset(&svsk->sk_pages[0], 0, sizeof(svsk->sk_pages));

tcp_sk(sk)->nonagle |= TCP_NAGLE_OFF;
Expand Down

0 comments on commit 8af345f

Please sign in to comment.