Skip to content

Commit e1bd876

Browse files
amschuma-ntapTrond Myklebust
authored andcommitted
SUNRPC: Add a function for zeroing out a portion of an xdr_stream
This will be used during READ_PLUS decoding for handling HOLE segments. Signed-off-by: Anna Schumaker <[email protected]> Signed-off-by: Trond Myklebust <[email protected]>
1 parent 7c4cd5f commit e1bd876

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

include/linux/sunrpc/xdr.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,8 @@ extern bool xdr_stream_subsegment(struct xdr_stream *xdr, struct xdr_buf *subbuf
265265
unsigned int len);
266266
extern unsigned int xdr_stream_move_subsegment(struct xdr_stream *xdr, unsigned int offset,
267267
unsigned int target, unsigned int length);
268+
extern unsigned int xdr_stream_zero(struct xdr_stream *xdr, unsigned int offset,
269+
unsigned int length);
268270

269271
/**
270272
* xdr_set_scratch_buffer - Attach a scratch buffer for decoding data.

net/sunrpc/xdr.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1769,6 +1769,29 @@ unsigned int xdr_stream_move_subsegment(struct xdr_stream *xdr, unsigned int off
17691769
}
17701770
EXPORT_SYMBOL_GPL(xdr_stream_move_subsegment);
17711771

1772+
/**
1773+
* xdr_stream_zero - zero out a portion of an xdr_stream
1774+
* @xdr: an xdr_stream to zero out
1775+
* @offset: the starting point in the stream
1776+
* @length: the number of bytes to zero
1777+
*/
1778+
unsigned int xdr_stream_zero(struct xdr_stream *xdr, unsigned int offset,
1779+
unsigned int length)
1780+
{
1781+
struct xdr_buf buf;
1782+
1783+
if (xdr_buf_subsegment(xdr->buf, &buf, offset, length) < 0)
1784+
return 0;
1785+
if (buf.head[0].iov_len)
1786+
xdr_buf_iov_zero(buf.head, 0, buf.head[0].iov_len);
1787+
if (buf.page_len > 0)
1788+
xdr_buf_pages_zero(&buf, 0, buf.page_len);
1789+
if (buf.tail[0].iov_len)
1790+
xdr_buf_iov_zero(buf.tail, 0, buf.tail[0].iov_len);
1791+
return length;
1792+
}
1793+
EXPORT_SYMBOL_GPL(xdr_stream_zero);
1794+
17721795
/**
17731796
* xdr_buf_trim - lop at most "len" bytes off the end of "buf"
17741797
* @buf: buf to be trimmed

0 commit comments

Comments
 (0)