Skip to content

Commit ded04a5

Browse files
committed
NFSD: Update the NFSv3 PATHCONF3res encoder to use struct xdr_stream
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
1 parent 0a139d1 commit ded04a5

File tree

2 files changed

+49
-13
lines changed

2 files changed

+49
-13
lines changed

fs/nfsd/nfs3xdr.c

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1501,25 +1501,47 @@ nfs3svc_encode_fsinfores(struct svc_rqst *rqstp, __be32 *p)
15011501
return 1;
15021502
}
15031503

1504+
static bool
1505+
svcxdr_encode_pathconf3resok(struct xdr_stream *xdr,
1506+
const struct nfsd3_pathconfres *resp)
1507+
{
1508+
__be32 *p;
1509+
1510+
p = xdr_reserve_space(xdr, XDR_UNIT * 6);
1511+
if (!p)
1512+
return false;
1513+
*p++ = cpu_to_be32(resp->p_link_max);
1514+
*p++ = cpu_to_be32(resp->p_name_max);
1515+
p = xdr_encode_bool(p, resp->p_no_trunc);
1516+
p = xdr_encode_bool(p, resp->p_chown_restricted);
1517+
p = xdr_encode_bool(p, resp->p_case_insensitive);
1518+
xdr_encode_bool(p, resp->p_case_preserving);
1519+
1520+
return true;
1521+
}
1522+
15041523
/* PATHCONF */
15051524
int
15061525
nfs3svc_encode_pathconfres(struct svc_rqst *rqstp, __be32 *p)
15071526
{
1527+
struct xdr_stream *xdr = &rqstp->rq_res_stream;
15081528
struct nfsd3_pathconfres *resp = rqstp->rq_resp;
15091529

1510-
*p++ = resp->status;
1511-
*p++ = xdr_zero; /* no post_op_attr */
1512-
1513-
if (resp->status == 0) {
1514-
*p++ = htonl(resp->p_link_max);
1515-
*p++ = htonl(resp->p_name_max);
1516-
*p++ = htonl(resp->p_no_trunc);
1517-
*p++ = htonl(resp->p_chown_restricted);
1518-
*p++ = htonl(resp->p_case_insensitive);
1519-
*p++ = htonl(resp->p_case_preserving);
1530+
if (!svcxdr_encode_nfsstat3(xdr, resp->status))
1531+
return 0;
1532+
switch (resp->status) {
1533+
case nfs_ok:
1534+
if (!svcxdr_encode_post_op_attr(rqstp, xdr, &nfs3svc_null_fh))
1535+
return 0;
1536+
if (!svcxdr_encode_pathconf3resok(xdr, resp))
1537+
return 0;
1538+
break;
1539+
default:
1540+
if (!svcxdr_encode_post_op_attr(rqstp, xdr, &nfs3svc_null_fh))
1541+
return 0;
15201542
}
15211543

1522-
return xdr_ressize_check(rqstp, p);
1544+
return 1;
15231545
}
15241546

15251547
/* COMMIT */

include/linux/sunrpc/xdr.h

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,21 @@ static inline int xdr_stream_encode_item_absent(struct xdr_stream *xdr)
395395
}
396396

397397
/**
398-
* xdr_stream_encode_bool - Encode a "not present" list item
398+
* xdr_encode_bool - Encode a boolean item
399+
* @p: address in a buffer into which to encode
400+
* @n: boolean value to encode
401+
*
402+
* Return value:
403+
* Address of item following the encoded boolean
404+
*/
405+
static inline __be32 *xdr_encode_bool(__be32 *p, u32 n)
406+
{
407+
*p = n ? xdr_one : xdr_zero;
408+
return p++;
409+
}
410+
411+
/**
412+
* xdr_stream_encode_bool - Encode a boolean item
399413
* @xdr: pointer to xdr_stream
400414
* @n: boolean value to encode
401415
*
@@ -410,7 +424,7 @@ static inline int xdr_stream_encode_bool(struct xdr_stream *xdr, __u32 n)
410424

411425
if (unlikely(!p))
412426
return -EMSGSIZE;
413-
*p = n ? xdr_one : xdr_zero;
427+
xdr_encode_bool(p, n);
414428
return len;
415429
}
416430

0 commit comments

Comments
 (0)