Skip to content

Commit 21d316a

Browse files
committed
NFSD: Clean up nfsd4_encode_copy_notify()
Replace open-coded encoding logic with the use of conventional XDR utility functions. Note that if we replace the cpn_sec and cpn_nsec fields with a single struct timespec64 field, the encoder can use nfsd4_encode_nfstime4(), as that is the data type specified by the XDR spec. NFS4ERR_INVAL seems inappropriate if the encoder doesn't support encoding the response. Instead use NFS4ERR_SERVERFAULT, since this condition is a software bug on the server. Reviewed-by: Jeff Layton <[email protected]> Signed-off-by: Chuck Lever <[email protected]>
1 parent 02e0297 commit 21d316a

File tree

3 files changed

+44
-69
lines changed

3 files changed

+44
-69
lines changed

fs/nfsd/nfs4proc.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1939,8 +1939,8 @@ nfsd4_copy_notify(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
19391939
if (status)
19401940
return status;
19411941

1942-
cn->cpn_sec = nn->nfsd4_lease;
1943-
cn->cpn_nsec = 0;
1942+
cn->cpn_lease_time.tv_sec = nn->nfsd4_lease;
1943+
cn->cpn_lease_time.tv_nsec = 0;
19441944

19451945
status = nfserrno(-ENOMEM);
19461946
cps = nfs4_alloc_init_cpntf_state(nn, stid);

fs/nfsd/nfs4xdr.c

Lines changed: 41 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -2575,6 +2575,19 @@ nfsd4_encode_change_info4(struct xdr_stream *xdr, const struct nfsd4_change_info
25752575
return nfsd4_encode_changeid4(xdr, c->after_change);
25762576
}
25772577

2578+
static __be32 nfsd4_encode_netaddr4(struct xdr_stream *xdr,
2579+
const struct nfs42_netaddr *addr)
2580+
{
2581+
__be32 status;
2582+
2583+
/* na_r_netid */
2584+
status = nfsd4_encode_opaque(xdr, addr->netid, addr->netid_len);
2585+
if (status != nfs_ok)
2586+
return status;
2587+
/* na_r_addr */
2588+
return nfsd4_encode_opaque(xdr, addr->addr, addr->addr_len);
2589+
}
2590+
25782591
/* Encode as an array of strings the string given with components
25792592
* separated @sep, escaped with esc_enter and esc_exit.
25802593
*/
@@ -5132,43 +5145,42 @@ nfsd4_encode_copy(struct nfsd4_compoundres *resp, __be32 nfserr,
51325145
}
51335146

51345147
static __be32
5135-
nfsd42_encode_nl4_server(struct nfsd4_compoundres *resp, struct nl4_server *ns)
5148+
nfsd4_encode_netloc4(struct xdr_stream *xdr, const struct nl4_server *ns)
51365149
{
5137-
struct xdr_stream *xdr = resp->xdr;
5138-
struct nfs42_netaddr *addr;
5139-
__be32 *p;
5140-
5141-
p = xdr_reserve_space(xdr, 4);
5142-
*p++ = cpu_to_be32(ns->nl4_type);
5150+
__be32 status;
51435151

5152+
if (xdr_stream_encode_u32(xdr, ns->nl4_type) != XDR_UNIT)
5153+
return nfserr_resource;
51445154
switch (ns->nl4_type) {
51455155
case NL4_NETADDR:
5146-
addr = &ns->u.nl4_addr;
5147-
5148-
/* netid_len, netid, uaddr_len, uaddr (port included
5149-
* in RPCBIND_MAXUADDRLEN)
5150-
*/
5151-
p = xdr_reserve_space(xdr,
5152-
4 /* netid len */ +
5153-
(XDR_QUADLEN(addr->netid_len) * 4) +
5154-
4 /* uaddr len */ +
5155-
(XDR_QUADLEN(addr->addr_len) * 4));
5156-
if (!p)
5157-
return nfserr_resource;
5158-
5159-
*p++ = cpu_to_be32(addr->netid_len);
5160-
p = xdr_encode_opaque_fixed(p, addr->netid,
5161-
addr->netid_len);
5162-
*p++ = cpu_to_be32(addr->addr_len);
5163-
p = xdr_encode_opaque_fixed(p, addr->addr,
5164-
addr->addr_len);
5156+
/* nl_addr */
5157+
status = nfsd4_encode_netaddr4(xdr, &ns->u.nl4_addr);
51655158
break;
51665159
default:
5167-
WARN_ON_ONCE(ns->nl4_type != NL4_NETADDR);
5168-
return nfserr_inval;
5160+
status = nfserr_serverfault;
51695161
}
5162+
return status;
5163+
}
51705164

5171-
return 0;
5165+
static __be32
5166+
nfsd4_encode_copy_notify(struct nfsd4_compoundres *resp, __be32 nfserr,
5167+
union nfsd4_op_u *u)
5168+
{
5169+
struct nfsd4_copy_notify *cn = &u->copy_notify;
5170+
struct xdr_stream *xdr = resp->xdr;
5171+
5172+
/* cnr_lease_time */
5173+
nfserr = nfsd4_encode_nfstime4(xdr, &cn->cpn_lease_time);
5174+
if (nfserr)
5175+
return nfserr;
5176+
/* cnr_stateid */
5177+
nfserr = nfsd4_encode_stateid4(xdr, &cn->cpn_cnr_stateid);
5178+
if (nfserr)
5179+
return nfserr;
5180+
/* cnr_source_server<> */
5181+
if (xdr_stream_encode_u32(xdr, 1) != XDR_UNIT)
5182+
return nfserr_resource;
5183+
return nfsd4_encode_netloc4(xdr, cn->cpn_src);
51725184
}
51735185

51745186
static __be32
@@ -5261,42 +5273,6 @@ nfsd4_encode_read_plus(struct nfsd4_compoundres *resp, __be32 nfserr,
52615273
return nfserr;
52625274
}
52635275

5264-
static __be32
5265-
nfsd4_encode_copy_notify(struct nfsd4_compoundres *resp, __be32 nfserr,
5266-
union nfsd4_op_u *u)
5267-
{
5268-
struct nfsd4_copy_notify *cn = &u->copy_notify;
5269-
struct xdr_stream *xdr = resp->xdr;
5270-
__be32 *p;
5271-
5272-
if (nfserr)
5273-
return nfserr;
5274-
5275-
/* 8 sec, 4 nsec */
5276-
p = xdr_reserve_space(xdr, 12);
5277-
if (!p)
5278-
return nfserr_resource;
5279-
5280-
/* cnr_lease_time */
5281-
p = xdr_encode_hyper(p, cn->cpn_sec);
5282-
*p++ = cpu_to_be32(cn->cpn_nsec);
5283-
5284-
/* cnr_stateid */
5285-
nfserr = nfsd4_encode_stateid4(xdr, &cn->cpn_cnr_stateid);
5286-
if (nfserr)
5287-
return nfserr;
5288-
5289-
/* cnr_src.nl_nsvr */
5290-
p = xdr_reserve_space(xdr, 4);
5291-
if (!p)
5292-
return nfserr_resource;
5293-
5294-
*p++ = cpu_to_be32(1);
5295-
5296-
nfserr = nfsd42_encode_nl4_server(resp, cn->cpn_src);
5297-
return nfserr;
5298-
}
5299-
53005276
static __be32
53015277
nfsd4_encode_seek(struct nfsd4_compoundres *resp, __be32 nfserr,
53025278
union nfsd4_op_u *u)

fs/nfsd/xdr4.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -745,8 +745,7 @@ struct nfsd4_copy_notify {
745745

746746
/* response */
747747
stateid_t cpn_cnr_stateid;
748-
u64 cpn_sec;
749-
u32 cpn_nsec;
748+
struct timespec64 cpn_lease_time;
750749
struct nl4_server *cpn_src;
751750
};
752751

0 commit comments

Comments
 (0)