Skip to content

Commit 6372e2e

Browse files
committed
NFSD: da_addr_body field missing in some GETDEVICEINFO replies
The XDR specification in RFC 8881 looks like this: struct device_addr4 { layouttype4 da_layout_type; opaque da_addr_body<>; }; struct GETDEVICEINFO4resok { device_addr4 gdir_device_addr; bitmap4 gdir_notification; }; union GETDEVICEINFO4res switch (nfsstat4 gdir_status) { case NFS4_OK: GETDEVICEINFO4resok gdir_resok4; case NFS4ERR_TOOSMALL: count4 gdir_mincount; default: void; }; Looking at nfsd4_encode_getdeviceinfo() .... When the client provides a zero gd_maxcount, then the Linux NFS server implementation encodes the da_layout_type field and then skips the da_addr_body field completely, proceeding directly to encode gdir_notification field. There does not appear to be an option in the specification to skip encoding da_addr_body. Moreover, Section 18.40.3 says: > If the client wants to just update or turn off notifications, it > MAY send a GETDEVICEINFO operation with gdia_maxcount set to zero. > In that event, if the device ID is valid, the reply's da_addr_body > field of the gdir_device_addr field will be of zero length. Since the layout drivers are responsible for encoding the da_addr_body field, put this fix inside the ->encode_getdeviceinfo methods. Fixes: 9cf514c ("nfsd: implement pNFS operations") Reviewed-by: Christoph Hellwig <hch@lst.de> Cc: Tom Haynes <loghyr@gmail.com> Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
1 parent 2a45574 commit 6372e2e

File tree

3 files changed

+29
-14
lines changed

3 files changed

+29
-14
lines changed

fs/nfsd/blocklayoutxdr.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,15 @@ nfsd4_block_encode_getdeviceinfo(struct xdr_stream *xdr,
8383
int len = sizeof(__be32), ret, i;
8484
__be32 *p;
8585

86+
/*
87+
* See paragraph 5 of RFC 8881 S18.40.3.
88+
*/
89+
if (!gdp->gd_maxcount) {
90+
if (xdr_stream_encode_u32(xdr, 0) != XDR_UNIT)
91+
return nfserr_resource;
92+
return nfs_ok;
93+
}
94+
8695
p = xdr_reserve_space(xdr, len + sizeof(__be32));
8796
if (!p)
8897
return nfserr_resource;

fs/nfsd/flexfilelayoutxdr.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,15 @@ nfsd4_ff_encode_getdeviceinfo(struct xdr_stream *xdr,
8585
int addr_len;
8686
__be32 *p;
8787

88+
/*
89+
* See paragraph 5 of RFC 8881 S18.40.3.
90+
*/
91+
if (!gdp->gd_maxcount) {
92+
if (xdr_stream_encode_u32(xdr, 0) != XDR_UNIT)
93+
return nfserr_resource;
94+
return nfs_ok;
95+
}
96+
8897
/* len + padding for two strings */
8998
addr_len = 16 + da->netaddr.netid_len + da->netaddr.addr_len;
9099
ver_len = 20;

fs/nfsd/nfs4xdr.c

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4686,20 +4686,17 @@ nfsd4_encode_getdeviceinfo(struct nfsd4_compoundres *resp, __be32 nfserr,
46864686

46874687
*p++ = cpu_to_be32(gdev->gd_layout_type);
46884688

4689-
/* If maxcount is 0 then just update notifications */
4690-
if (gdev->gd_maxcount != 0) {
4691-
ops = nfsd4_layout_ops[gdev->gd_layout_type];
4692-
nfserr = ops->encode_getdeviceinfo(xdr, gdev);
4693-
if (nfserr) {
4694-
/*
4695-
* We don't bother to burden the layout drivers with
4696-
* enforcing gd_maxcount, just tell the client to
4697-
* come back with a bigger buffer if it's not enough.
4698-
*/
4699-
if (xdr->buf->len + 4 > gdev->gd_maxcount)
4700-
goto toosmall;
4701-
return nfserr;
4702-
}
4689+
ops = nfsd4_layout_ops[gdev->gd_layout_type];
4690+
nfserr = ops->encode_getdeviceinfo(xdr, gdev);
4691+
if (nfserr) {
4692+
/*
4693+
* We don't bother to burden the layout drivers with
4694+
* enforcing gd_maxcount, just tell the client to
4695+
* come back with a bigger buffer if it's not enough.
4696+
*/
4697+
if (xdr->buf->len + 4 > gdev->gd_maxcount)
4698+
goto toosmall;
4699+
return nfserr;
47034700
}
47044701

47054702
if (gdev->gd_notify_types) {

0 commit comments

Comments
 (0)