Skip to content

Commit 4163ee7

Browse files
committed
NFSD: Insulate nfsd4_encode_fattr4() from page boundaries in the encode buffer
Commit ab04de6 ("NFSD: Optimize nfsd4_encode_fattr()") replaced the use of write_bytes_to_xdr_buf() because it's expensive and the data items to be encoded are already properly aligned. However, there's no guarantee that the pointer returned from xdr_reserve_space() will still point to the correct reserved space in the encode buffer after one or more intervening calls to xdr_reserve_space(). It just happens to work with the current implementation of xdr_reserve_space(). This commit effectively reverts the optimization. Reviewed-by: NeilBrown <[email protected]> Reviewed-by: Jeff Layton <[email protected]> Signed-off-by: Chuck Lever <[email protected]>
1 parent b786caa commit 4163ee7

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

fs/nfsd/nfs4xdr.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3507,8 +3507,8 @@ nfsd4_encode_fattr4(struct svc_rqst *rqstp, struct xdr_stream *xdr,
35073507
struct nfsd4_fattr_args args;
35083508
struct svc_fh *tempfh = NULL;
35093509
int starting_len = xdr->buf->len;
3510-
__be32 *attrlen_p, status;
3511-
int attrlen_offset;
3510+
unsigned int attrlen_offset;
3511+
__be32 attrlen, status;
35123512
u32 attrmask[3];
35133513
int err;
35143514
struct nfsd4_compoundres *resp = rqstp->rq_resp;
@@ -3629,8 +3629,7 @@ nfsd4_encode_fattr4(struct svc_rqst *rqstp, struct xdr_stream *xdr,
36293629

36303630
/* attr_vals */
36313631
attrlen_offset = xdr->buf->len;
3632-
attrlen_p = xdr_reserve_space(xdr, XDR_UNIT);
3633-
if (!attrlen_p)
3632+
if (unlikely(!xdr_reserve_space(xdr, XDR_UNIT)))
36343633
goto out_resource;
36353634
bitmap_from_arr32(attr_bitmap, attrmask,
36363635
ARRAY_SIZE(nfsd4_enc_fattr4_encode_ops));
@@ -3640,7 +3639,8 @@ nfsd4_encode_fattr4(struct svc_rqst *rqstp, struct xdr_stream *xdr,
36403639
if (status != nfs_ok)
36413640
goto out;
36423641
}
3643-
*attrlen_p = cpu_to_be32(xdr->buf->len - attrlen_offset - XDR_UNIT);
3642+
attrlen = cpu_to_be32(xdr->buf->len - attrlen_offset - XDR_UNIT);
3643+
write_bytes_to_xdr_buf(xdr->buf, attrlen_offset, &attrlen, XDR_UNIT);
36443644
status = nfs_ok;
36453645

36463646
out:

0 commit comments

Comments
 (0)