SUNRPC: Add XDR overflow trace event
This can help field troubleshooting without needing the overhead of a full network capture (ie, tcpdump). Signed-off-by: Chuck Lever <chuck.lever@oracle.com> Signed-off-by: Anna Schumaker <Anna.Schumaker@Netapp.com>
This commit is contained in:

committed by
Anna Schumaker

parent
0ccc61b1c7
commit
5582863f45
@@ -16,6 +16,7 @@
|
||||
#include <linux/sunrpc/xdr.h>
|
||||
#include <linux/sunrpc/msg_prot.h>
|
||||
#include <linux/bvec.h>
|
||||
#include <trace/events/sunrpc.h>
|
||||
|
||||
/*
|
||||
* XDR functions for basic NFS types
|
||||
@@ -554,9 +555,9 @@ static __be32 *xdr_get_next_encode_buffer(struct xdr_stream *xdr,
|
||||
int frag1bytes, frag2bytes;
|
||||
|
||||
if (nbytes > PAGE_SIZE)
|
||||
return NULL; /* Bigger buffers require special handling */
|
||||
goto out_overflow; /* Bigger buffers require special handling */
|
||||
if (xdr->buf->len + nbytes > xdr->buf->buflen)
|
||||
return NULL; /* Sorry, we're totally out of space */
|
||||
goto out_overflow; /* Sorry, we're totally out of space */
|
||||
frag1bytes = (xdr->end - xdr->p) << 2;
|
||||
frag2bytes = nbytes - frag1bytes;
|
||||
if (xdr->iov)
|
||||
@@ -585,6 +586,9 @@ static __be32 *xdr_get_next_encode_buffer(struct xdr_stream *xdr,
|
||||
xdr->buf->page_len += frag2bytes;
|
||||
xdr->buf->len += nbytes;
|
||||
return p;
|
||||
out_overflow:
|
||||
trace_rpc_xdr_overflow(xdr, nbytes);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -902,20 +906,23 @@ static __be32 *xdr_copy_to_scratch(struct xdr_stream *xdr, size_t nbytes)
|
||||
size_t cplen = (char *)xdr->end - (char *)xdr->p;
|
||||
|
||||
if (nbytes > xdr->scratch.iov_len)
|
||||
return NULL;
|
||||
goto out_overflow;
|
||||
p = __xdr_inline_decode(xdr, cplen);
|
||||
if (p == NULL)
|
||||
return NULL;
|
||||
memcpy(cpdest, p, cplen);
|
||||
if (!xdr_set_next_buffer(xdr))
|
||||
goto out_overflow;
|
||||
cpdest += cplen;
|
||||
nbytes -= cplen;
|
||||
if (!xdr_set_next_buffer(xdr))
|
||||
return NULL;
|
||||
p = __xdr_inline_decode(xdr, nbytes);
|
||||
if (p == NULL)
|
||||
return NULL;
|
||||
memcpy(cpdest, p, nbytes);
|
||||
return xdr->scratch.iov_base;
|
||||
out_overflow:
|
||||
trace_rpc_xdr_overflow(xdr, nbytes);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -932,14 +939,17 @@ __be32 * xdr_inline_decode(struct xdr_stream *xdr, size_t nbytes)
|
||||
{
|
||||
__be32 *p;
|
||||
|
||||
if (nbytes == 0)
|
||||
if (unlikely(nbytes == 0))
|
||||
return xdr->p;
|
||||
if (xdr->p == xdr->end && !xdr_set_next_buffer(xdr))
|
||||
return NULL;
|
||||
goto out_overflow;
|
||||
p = __xdr_inline_decode(xdr, nbytes);
|
||||
if (p != NULL)
|
||||
return p;
|
||||
return xdr_copy_to_scratch(xdr, nbytes);
|
||||
out_overflow:
|
||||
trace_rpc_xdr_overflow(xdr, nbytes);
|
||||
return NULL;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(xdr_inline_decode);
|
||||
|
||||
|
Reference in New Issue
Block a user