Skip to content

Commit 02ef04e

Browse files
chuckleveramschuma-ntap
authored andcommitted
NFS: Account for XDR pad of buf->pages
Certain NFS results (eg. READLINK) might expect a data payload that is not an exact multiple of 4 bytes. In this case, XDR encoding is required to pad that payload so its length on the wire is a multiple of 4 bytes. The constants that define the maximum size of each NFS result do not appear to account for this extra word. In each case where the data payload is to be received into pages: - 1 word is added to the size of the receive buffer allocated by call_allocate - rpc_inline_rcv_pages subtracts 1 word from @hdrsize so that the extra buffer space falls into the rcv_buf's tail iovec - If buf->pagelen is word-aligned, an XDR pad is not needed and is thus removed from the tail Signed-off-by: Chuck Lever <[email protected]> Signed-off-by: Anna Schumaker <[email protected]>
1 parent cf500ba commit 02ef04e

File tree

5 files changed

+23
-16
lines changed

5 files changed

+23
-16
lines changed

fs/nfs/nfs2xdr.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,11 @@
5656

5757
#define NFS_attrstat_sz (1+NFS_fattr_sz)
5858
#define NFS_diropres_sz (1+NFS_fhandle_sz+NFS_fattr_sz)
59-
#define NFS_readlinkres_sz (2)
60-
#define NFS_readres_sz (1+NFS_fattr_sz+1)
59+
#define NFS_readlinkres_sz (2+1)
60+
#define NFS_readres_sz (1+NFS_fattr_sz+1+1)
6161
#define NFS_writeres_sz (NFS_attrstat_sz)
6262
#define NFS_stat_sz (1)
63-
#define NFS_readdirres_sz (1)
63+
#define NFS_readdirres_sz (1+1)
6464
#define NFS_statfsres_sz (1+NFS_info_sz)
6565

6666
static int nfs_stat_to_errno(enum nfs_stat);

fs/nfs/nfs3xdr.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,13 @@
6969
#define NFS3_removeres_sz (NFS3_setattrres_sz)
7070
#define NFS3_lookupres_sz (1+NFS3_fh_sz+(2 * NFS3_post_op_attr_sz))
7171
#define NFS3_accessres_sz (1+NFS3_post_op_attr_sz+1)
72-
#define NFS3_readlinkres_sz (1+NFS3_post_op_attr_sz+1)
73-
#define NFS3_readres_sz (1+NFS3_post_op_attr_sz+3)
72+
#define NFS3_readlinkres_sz (1+NFS3_post_op_attr_sz+1+1)
73+
#define NFS3_readres_sz (1+NFS3_post_op_attr_sz+3+1)
7474
#define NFS3_writeres_sz (1+NFS3_wcc_data_sz+4)
7575
#define NFS3_createres_sz (1+NFS3_fh_sz+NFS3_post_op_attr_sz+NFS3_wcc_data_sz)
7676
#define NFS3_renameres_sz (1+(2 * NFS3_wcc_data_sz))
7777
#define NFS3_linkres_sz (1+NFS3_post_op_attr_sz+NFS3_wcc_data_sz)
78-
#define NFS3_readdirres_sz (1+NFS3_post_op_attr_sz+2)
78+
#define NFS3_readdirres_sz (1+NFS3_post_op_attr_sz+2+1)
7979
#define NFS3_fsstatres_sz (1+NFS3_post_op_attr_sz+13)
8080
#define NFS3_fsinfores_sz (1+NFS3_post_op_attr_sz+12)
8181
#define NFS3_pathconfres_sz (1+NFS3_post_op_attr_sz+6)
@@ -85,7 +85,7 @@
8585
#define ACL3_setaclargs_sz (NFS3_fh_sz+1+ \
8686
XDR_QUADLEN(NFS_ACL_INLINE_BUFSIZE))
8787
#define ACL3_getaclres_sz (1+NFS3_post_op_attr_sz+1+ \
88-
XDR_QUADLEN(NFS_ACL_INLINE_BUFSIZE))
88+
XDR_QUADLEN(NFS_ACL_INLINE_BUFSIZE)+1)
8989
#define ACL3_setaclres_sz (1+NFS3_post_op_attr_sz)
9090

9191
static int nfs3_stat_to_errno(enum nfs_stat);
@@ -1629,7 +1629,7 @@ static int nfs3_xdr_dec_read3res(struct rpc_rqst *req, struct xdr_stream *xdr,
16291629
result->op_status = status;
16301630
if (status != NFS3_OK)
16311631
goto out_status;
1632-
result->replen = 3 + ((xdr_stream_pos(xdr) - pos) >> 2);
1632+
result->replen = 4 + ((xdr_stream_pos(xdr) - pos) >> 2);
16331633
error = decode_read3resok(xdr, result);
16341634
out:
16351635
return error;

fs/nfs/nfs4xdr.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -215,14 +215,14 @@ static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
215215
nfs4_fattr_bitmap_maxsz)
216216
#define encode_read_maxsz (op_encode_hdr_maxsz + \
217217
encode_stateid_maxsz + 3)
218-
#define decode_read_maxsz (op_decode_hdr_maxsz + 2)
218+
#define decode_read_maxsz (op_decode_hdr_maxsz + 2 + 1)
219219
#define encode_readdir_maxsz (op_encode_hdr_maxsz + \
220220
2 + encode_verifier_maxsz + 5 + \
221221
nfs4_label_maxsz)
222222
#define decode_readdir_maxsz (op_decode_hdr_maxsz + \
223-
decode_verifier_maxsz)
223+
decode_verifier_maxsz + 1)
224224
#define encode_readlink_maxsz (op_encode_hdr_maxsz)
225-
#define decode_readlink_maxsz (op_decode_hdr_maxsz + 1)
225+
#define decode_readlink_maxsz (op_decode_hdr_maxsz + 1 + 1)
226226
#define encode_write_maxsz (op_encode_hdr_maxsz + \
227227
encode_stateid_maxsz + 4)
228228
#define decode_write_maxsz (op_decode_hdr_maxsz + \
@@ -284,14 +284,14 @@ static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
284284
#define decode_delegreturn_maxsz (op_decode_hdr_maxsz)
285285
#define encode_getacl_maxsz (encode_getattr_maxsz)
286286
#define decode_getacl_maxsz (op_decode_hdr_maxsz + \
287-
nfs4_fattr_bitmap_maxsz + 1)
287+
nfs4_fattr_bitmap_maxsz + 1 + 1)
288288
#define encode_setacl_maxsz (op_encode_hdr_maxsz + \
289289
encode_stateid_maxsz + 3)
290290
#define decode_setacl_maxsz (decode_setattr_maxsz)
291291
#define encode_fs_locations_maxsz \
292292
(encode_getattr_maxsz)
293293
#define decode_fs_locations_maxsz \
294-
(0)
294+
(1)
295295
#define encode_secinfo_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz)
296296
#define decode_secinfo_maxsz (op_decode_hdr_maxsz + 1 + ((NFS_MAX_SECFLAVORS * (16 + GSS_OID_MAX_LEN)) / 4))
297297

@@ -392,12 +392,13 @@ static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
392392
1 /* opaque devaddr4 length */ + \
393393
/* devaddr4 payload is read into page */ \
394394
1 /* notification bitmap length */ + \
395-
1 /* notification bitmap, word 0 */)
395+
1 /* notification bitmap, word 0 */ + \
396+
1 /* possible XDR padding */)
396397
#define encode_layoutget_maxsz (op_encode_hdr_maxsz + 10 + \
397398
encode_stateid_maxsz)
398399
#define decode_layoutget_maxsz (op_decode_hdr_maxsz + 8 + \
399400
decode_stateid_maxsz + \
400-
XDR_QUADLEN(PNFS_LAYOUT_MAXSIZE))
401+
XDR_QUADLEN(PNFS_LAYOUT_MAXSIZE) + 1)
401402
#define encode_layoutcommit_maxsz (op_encode_hdr_maxsz + \
402403
2 /* offset */ + \
403404
2 /* length */ + \

net/sunrpc/clnt.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1177,7 +1177,11 @@ void rpc_prepare_reply_pages(struct rpc_rqst *req, struct page **pages,
11771177
unsigned int base, unsigned int len,
11781178
unsigned int hdrsize)
11791179
{
1180-
hdrsize += RPC_REPHDRSIZE + req->rq_cred->cr_auth->au_rslack;
1180+
/* Subtract one to force an extra word of buffer space for the
1181+
* payload's XDR pad to fall into the rcv_buf's tail iovec.
1182+
*/
1183+
hdrsize += RPC_REPHDRSIZE + req->rq_cred->cr_auth->au_rslack - 1;
1184+
11811185
xdr_inline_pages(&req->rq_rcv_buf, hdrsize << 2, pages, base, len);
11821186
trace_rpc_reply_pages(req);
11831187
}

net/sunrpc/xdr.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,8 @@ xdr_inline_pages(struct xdr_buf *xdr, unsigned int offset,
189189

190190
tail->iov_base = buf + offset;
191191
tail->iov_len = buflen - offset;
192+
if ((xdr->page_len & 3) == 0)
193+
tail->iov_len -= sizeof(__be32);
192194

193195
xdr->buflen += len;
194196
}

0 commit comments

Comments
 (0)