1b2441318SGreg Kroah-Hartman // SPDX-License-Identifier: GPL-2.0
23460f29aSChuck Lever /*
33460f29aSChuck Lever * linux/fs/lockd/clnt4xdr.c
43460f29aSChuck Lever *
53460f29aSChuck Lever * XDR functions to encode/decode NLM version 4 RPC arguments and results.
63460f29aSChuck Lever *
73460f29aSChuck Lever * NLM client-side only.
83460f29aSChuck Lever *
93460f29aSChuck Lever * Copyright (C) 2010, Oracle. All rights reserved.
103460f29aSChuck Lever */
113460f29aSChuck Lever
123460f29aSChuck Lever #include <linux/types.h>
133460f29aSChuck Lever #include <linux/sunrpc/xdr.h>
143460f29aSChuck Lever #include <linux/sunrpc/clnt.h>
153460f29aSChuck Lever #include <linux/sunrpc/stats.h>
163460f29aSChuck Lever #include <linux/lockd/lockd.h>
173460f29aSChuck Lever
189c69de4cSChristoph Hellwig #include <uapi/linux/nfs3.h>
199c69de4cSChristoph Hellwig
203460f29aSChuck Lever #define NLMDBG_FACILITY NLMDBG_XDR
213460f29aSChuck Lever
223460f29aSChuck Lever #if (NLMCLNT_OHSIZE > XDR_MAX_NETOBJ)
233460f29aSChuck Lever # error "NLM host name cannot be larger than XDR_MAX_NETOBJ!"
243460f29aSChuck Lever #endif
253460f29aSChuck Lever
263460f29aSChuck Lever #if (NLMCLNT_OHSIZE > NLM_MAXSTRLEN)
273460f29aSChuck Lever # error "NLM host name cannot be larger than NLM's maximum string length!"
283460f29aSChuck Lever #endif
293460f29aSChuck Lever
303460f29aSChuck Lever /*
313460f29aSChuck Lever * Declare the space requirements for NLM arguments and replies as
323460f29aSChuck Lever * number of 32bit-words
333460f29aSChuck Lever */
343460f29aSChuck Lever #define NLM4_void_sz (0)
353460f29aSChuck Lever #define NLM4_cookie_sz (1+(NLM_MAXCOOKIELEN>>2))
363460f29aSChuck Lever #define NLM4_caller_sz (1+(NLMCLNT_OHSIZE>>2))
373460f29aSChuck Lever #define NLM4_owner_sz (1+(NLMCLNT_OHSIZE>>2))
383460f29aSChuck Lever #define NLM4_fhandle_sz (1+(NFS3_FHSIZE>>2))
393460f29aSChuck Lever #define NLM4_lock_sz (5+NLM4_caller_sz+NLM4_owner_sz+NLM4_fhandle_sz)
403460f29aSChuck Lever #define NLM4_holder_sz (6+NLM4_owner_sz)
413460f29aSChuck Lever
423460f29aSChuck Lever #define NLM4_testargs_sz (NLM4_cookie_sz+1+NLM4_lock_sz)
433460f29aSChuck Lever #define NLM4_lockargs_sz (NLM4_cookie_sz+4+NLM4_lock_sz)
443460f29aSChuck Lever #define NLM4_cancargs_sz (NLM4_cookie_sz+2+NLM4_lock_sz)
453460f29aSChuck Lever #define NLM4_unlockargs_sz (NLM4_cookie_sz+NLM4_lock_sz)
463460f29aSChuck Lever
473460f29aSChuck Lever #define NLM4_testres_sz (NLM4_cookie_sz+1+NLM4_holder_sz)
483460f29aSChuck Lever #define NLM4_res_sz (NLM4_cookie_sz+1)
493460f29aSChuck Lever #define NLM4_norep_sz (0)
503460f29aSChuck Lever
513460f29aSChuck Lever
loff_t_to_s64(loff_t offset)523460f29aSChuck Lever static s64 loff_t_to_s64(loff_t offset)
533460f29aSChuck Lever {
543460f29aSChuck Lever s64 res;
553460f29aSChuck Lever
563460f29aSChuck Lever if (offset >= NLM4_OFFSET_MAX)
573460f29aSChuck Lever res = NLM4_OFFSET_MAX;
583460f29aSChuck Lever else if (offset <= -NLM4_OFFSET_MAX)
593460f29aSChuck Lever res = -NLM4_OFFSET_MAX;
603460f29aSChuck Lever else
613460f29aSChuck Lever res = offset;
623460f29aSChuck Lever return res;
633460f29aSChuck Lever }
643460f29aSChuck Lever
nlm4_compute_offsets(const struct nlm_lock * lock,u64 * l_offset,u64 * l_len)653460f29aSChuck Lever static void nlm4_compute_offsets(const struct nlm_lock *lock,
663460f29aSChuck Lever u64 *l_offset, u64 *l_len)
673460f29aSChuck Lever {
683460f29aSChuck Lever const struct file_lock *fl = &lock->fl;
693460f29aSChuck Lever
703460f29aSChuck Lever *l_offset = loff_t_to_s64(fl->fl_start);
713460f29aSChuck Lever if (fl->fl_end == OFFSET_MAX)
723460f29aSChuck Lever *l_len = 0;
733460f29aSChuck Lever else
743460f29aSChuck Lever *l_len = loff_t_to_s64(fl->fl_end - fl->fl_start + 1);
753460f29aSChuck Lever }
763460f29aSChuck Lever
773460f29aSChuck Lever /*
783460f29aSChuck Lever * Encode/decode NLMv4 basic data types
793460f29aSChuck Lever *
803460f29aSChuck Lever * Basic NLMv4 data types are defined in Appendix II, section 6.1.4
813460f29aSChuck Lever * of RFC 1813: "NFS Version 3 Protocol Specification" and in Chapter
823460f29aSChuck Lever * 10 of X/Open's "Protocols for Interworking: XNFS, Version 3W".
833460f29aSChuck Lever *
843460f29aSChuck Lever * Not all basic data types have their own encoding and decoding
853460f29aSChuck Lever * functions. For run-time efficiency, some data types are encoded
863460f29aSChuck Lever * or decoded inline.
873460f29aSChuck Lever */
883460f29aSChuck Lever
encode_bool(struct xdr_stream * xdr,const int value)893460f29aSChuck Lever static void encode_bool(struct xdr_stream *xdr, const int value)
903460f29aSChuck Lever {
913460f29aSChuck Lever __be32 *p;
923460f29aSChuck Lever
933460f29aSChuck Lever p = xdr_reserve_space(xdr, 4);
943460f29aSChuck Lever *p = value ? xdr_one : xdr_zero;
953460f29aSChuck Lever }
963460f29aSChuck Lever
encode_int32(struct xdr_stream * xdr,const s32 value)973460f29aSChuck Lever static void encode_int32(struct xdr_stream *xdr, const s32 value)
983460f29aSChuck Lever {
993460f29aSChuck Lever __be32 *p;
1003460f29aSChuck Lever
1013460f29aSChuck Lever p = xdr_reserve_space(xdr, 4);
1023460f29aSChuck Lever *p = cpu_to_be32(value);
1033460f29aSChuck Lever }
1043460f29aSChuck Lever
1053460f29aSChuck Lever /*
1063460f29aSChuck Lever * typedef opaque netobj<MAXNETOBJ_SZ>
1073460f29aSChuck Lever */
encode_netobj(struct xdr_stream * xdr,const u8 * data,const unsigned int length)1083460f29aSChuck Lever static void encode_netobj(struct xdr_stream *xdr,
1093460f29aSChuck Lever const u8 *data, const unsigned int length)
1103460f29aSChuck Lever {
1113460f29aSChuck Lever __be32 *p;
1123460f29aSChuck Lever
1133460f29aSChuck Lever p = xdr_reserve_space(xdr, 4 + length);
1143460f29aSChuck Lever xdr_encode_opaque(p, data, length);
1153460f29aSChuck Lever }
1163460f29aSChuck Lever
decode_netobj(struct xdr_stream * xdr,struct xdr_netobj * obj)1173460f29aSChuck Lever static int decode_netobj(struct xdr_stream *xdr,
1183460f29aSChuck Lever struct xdr_netobj *obj)
1193460f29aSChuck Lever {
120b8db1592SJ. Bruce Fields ssize_t ret;
1213460f29aSChuck Lever
122b8db1592SJ. Bruce Fields ret = xdr_stream_decode_opaque_inline(xdr, (void *)&obj->data,
123b8db1592SJ. Bruce Fields XDR_MAX_NETOBJ);
124b8db1592SJ. Bruce Fields if (unlikely(ret < 0))
125b8db1592SJ. Bruce Fields return -EIO;
126b8db1592SJ. Bruce Fields obj->len = ret;
1273460f29aSChuck Lever return 0;
1283460f29aSChuck Lever }
1293460f29aSChuck Lever
1303460f29aSChuck Lever /*
1313460f29aSChuck Lever * netobj cookie;
1323460f29aSChuck Lever */
encode_cookie(struct xdr_stream * xdr,const struct nlm_cookie * cookie)1333460f29aSChuck Lever static void encode_cookie(struct xdr_stream *xdr,
1343460f29aSChuck Lever const struct nlm_cookie *cookie)
1353460f29aSChuck Lever {
1363460f29aSChuck Lever encode_netobj(xdr, (u8 *)&cookie->data, cookie->len);
1373460f29aSChuck Lever }
1383460f29aSChuck Lever
decode_cookie(struct xdr_stream * xdr,struct nlm_cookie * cookie)1393460f29aSChuck Lever static int decode_cookie(struct xdr_stream *xdr,
1403460f29aSChuck Lever struct nlm_cookie *cookie)
1413460f29aSChuck Lever {
1423460f29aSChuck Lever u32 length;
1433460f29aSChuck Lever __be32 *p;
1443460f29aSChuck Lever
1453460f29aSChuck Lever p = xdr_inline_decode(xdr, 4);
1463460f29aSChuck Lever if (unlikely(p == NULL))
1473460f29aSChuck Lever goto out_overflow;
1483460f29aSChuck Lever length = be32_to_cpup(p++);
1493460f29aSChuck Lever /* apparently HPUX can return empty cookies */
1503460f29aSChuck Lever if (length == 0)
1513460f29aSChuck Lever goto out_hpux;
1523460f29aSChuck Lever if (length > NLM_MAXCOOKIELEN)
1533460f29aSChuck Lever goto out_size;
1543460f29aSChuck Lever p = xdr_inline_decode(xdr, length);
1553460f29aSChuck Lever if (unlikely(p == NULL))
1563460f29aSChuck Lever goto out_overflow;
1573460f29aSChuck Lever cookie->len = length;
1583460f29aSChuck Lever memcpy(cookie->data, p, length);
1593460f29aSChuck Lever return 0;
1603460f29aSChuck Lever out_hpux:
1613460f29aSChuck Lever cookie->len = 4;
1623460f29aSChuck Lever memset(cookie->data, 0, 4);
1633460f29aSChuck Lever return 0;
1643460f29aSChuck Lever out_size:
1653460f29aSChuck Lever dprintk("NFS: returned cookie was too long: %u\n", length);
1663460f29aSChuck Lever return -EIO;
1673460f29aSChuck Lever out_overflow:
1683460f29aSChuck Lever return -EIO;
1693460f29aSChuck Lever }
1703460f29aSChuck Lever
1713460f29aSChuck Lever /*
1723460f29aSChuck Lever * netobj fh;
1733460f29aSChuck Lever */
encode_fh(struct xdr_stream * xdr,const struct nfs_fh * fh)1743460f29aSChuck Lever static void encode_fh(struct xdr_stream *xdr, const struct nfs_fh *fh)
1753460f29aSChuck Lever {
1763460f29aSChuck Lever encode_netobj(xdr, (u8 *)&fh->data, fh->size);
1773460f29aSChuck Lever }
1783460f29aSChuck Lever
1793460f29aSChuck Lever /*
1803460f29aSChuck Lever * enum nlm4_stats {
1813460f29aSChuck Lever * NLM4_GRANTED = 0,
1823460f29aSChuck Lever * NLM4_DENIED = 1,
1833460f29aSChuck Lever * NLM4_DENIED_NOLOCKS = 2,
1843460f29aSChuck Lever * NLM4_BLOCKED = 3,
1853460f29aSChuck Lever * NLM4_DENIED_GRACE_PERIOD = 4,
1863460f29aSChuck Lever * NLM4_DEADLCK = 5,
1873460f29aSChuck Lever * NLM4_ROFS = 6,
1883460f29aSChuck Lever * NLM4_STALE_FH = 7,
1893460f29aSChuck Lever * NLM4_FBIG = 8,
1903460f29aSChuck Lever * NLM4_FAILED = 9
1913460f29aSChuck Lever * };
1923460f29aSChuck Lever *
1933460f29aSChuck Lever * struct nlm4_stat {
1943460f29aSChuck Lever * nlm4_stats stat;
1953460f29aSChuck Lever * };
1963460f29aSChuck Lever *
1973460f29aSChuck Lever * NB: we don't swap bytes for the NLM status values. The upper
1983460f29aSChuck Lever * layers deal directly with the status value in network byte
1993460f29aSChuck Lever * order.
2003460f29aSChuck Lever */
encode_nlm4_stat(struct xdr_stream * xdr,const __be32 stat)2013460f29aSChuck Lever static void encode_nlm4_stat(struct xdr_stream *xdr,
2023460f29aSChuck Lever const __be32 stat)
2033460f29aSChuck Lever {
2043460f29aSChuck Lever __be32 *p;
2053460f29aSChuck Lever
2063460f29aSChuck Lever BUG_ON(be32_to_cpu(stat) > NLM_FAILED);
2073460f29aSChuck Lever p = xdr_reserve_space(xdr, 4);
2083460f29aSChuck Lever *p = stat;
2093460f29aSChuck Lever }
2103460f29aSChuck Lever
decode_nlm4_stat(struct xdr_stream * xdr,__be32 * stat)2113460f29aSChuck Lever static int decode_nlm4_stat(struct xdr_stream *xdr, __be32 *stat)
2123460f29aSChuck Lever {
2133460f29aSChuck Lever __be32 *p;
2143460f29aSChuck Lever
2153460f29aSChuck Lever p = xdr_inline_decode(xdr, 4);
2163460f29aSChuck Lever if (unlikely(p == NULL))
2173460f29aSChuck Lever goto out_overflow;
218e847469bSAl Viro if (unlikely(ntohl(*p) > ntohl(nlm4_failed)))
2193460f29aSChuck Lever goto out_bad_xdr;
2203460f29aSChuck Lever *stat = *p;
2213460f29aSChuck Lever return 0;
2223460f29aSChuck Lever out_bad_xdr:
2233460f29aSChuck Lever dprintk("%s: server returned invalid nlm4_stats value: %u\n",
2243460f29aSChuck Lever __func__, be32_to_cpup(p));
2253460f29aSChuck Lever return -EIO;
2263460f29aSChuck Lever out_overflow:
2273460f29aSChuck Lever return -EIO;
2283460f29aSChuck Lever }
2293460f29aSChuck Lever
2303460f29aSChuck Lever /*
2313460f29aSChuck Lever * struct nlm4_holder {
2323460f29aSChuck Lever * bool exclusive;
2333460f29aSChuck Lever * int32 svid;
2343460f29aSChuck Lever * netobj oh;
2353460f29aSChuck Lever * uint64 l_offset;
2363460f29aSChuck Lever * uint64 l_len;
2373460f29aSChuck Lever * };
2383460f29aSChuck Lever */
encode_nlm4_holder(struct xdr_stream * xdr,const struct nlm_res * result)2393460f29aSChuck Lever static void encode_nlm4_holder(struct xdr_stream *xdr,
2403460f29aSChuck Lever const struct nlm_res *result)
2413460f29aSChuck Lever {
2423460f29aSChuck Lever const struct nlm_lock *lock = &result->lock;
2433460f29aSChuck Lever u64 l_offset, l_len;
2443460f29aSChuck Lever __be32 *p;
2453460f29aSChuck Lever
246*eb8ed7c6SJeff Layton encode_bool(xdr, lock->fl.c.flc_type == F_RDLCK);
2473460f29aSChuck Lever encode_int32(xdr, lock->svid);
2483460f29aSChuck Lever encode_netobj(xdr, lock->oh.data, lock->oh.len);
2493460f29aSChuck Lever
2503460f29aSChuck Lever p = xdr_reserve_space(xdr, 4 + 4);
2513460f29aSChuck Lever nlm4_compute_offsets(lock, &l_offset, &l_len);
2523460f29aSChuck Lever p = xdr_encode_hyper(p, l_offset);
2533460f29aSChuck Lever xdr_encode_hyper(p, l_len);
2543460f29aSChuck Lever }
2553460f29aSChuck Lever
decode_nlm4_holder(struct xdr_stream * xdr,struct nlm_res * result)2563460f29aSChuck Lever static int decode_nlm4_holder(struct xdr_stream *xdr, struct nlm_res *result)
2573460f29aSChuck Lever {
2583460f29aSChuck Lever struct nlm_lock *lock = &result->lock;
2593460f29aSChuck Lever struct file_lock *fl = &lock->fl;
2603460f29aSChuck Lever u64 l_offset, l_len;
2613460f29aSChuck Lever u32 exclusive;
2623460f29aSChuck Lever int error;
2633460f29aSChuck Lever __be32 *p;
2643460f29aSChuck Lever
2653460f29aSChuck Lever memset(lock, 0, sizeof(*lock));
2663460f29aSChuck Lever locks_init_lock(fl);
2673460f29aSChuck Lever
2683460f29aSChuck Lever p = xdr_inline_decode(xdr, 4 + 4);
2693460f29aSChuck Lever if (unlikely(p == NULL))
2703460f29aSChuck Lever goto out_overflow;
2713460f29aSChuck Lever exclusive = be32_to_cpup(p++);
2723460f29aSChuck Lever lock->svid = be32_to_cpup(p);
273*eb8ed7c6SJeff Layton fl->c.flc_pid = (pid_t)lock->svid;
2743460f29aSChuck Lever
2753460f29aSChuck Lever error = decode_netobj(xdr, &lock->oh);
2763460f29aSChuck Lever if (unlikely(error))
2773460f29aSChuck Lever goto out;
2783460f29aSChuck Lever
2793460f29aSChuck Lever p = xdr_inline_decode(xdr, 8 + 8);
2803460f29aSChuck Lever if (unlikely(p == NULL))
2813460f29aSChuck Lever goto out_overflow;
2823460f29aSChuck Lever
283*eb8ed7c6SJeff Layton fl->c.flc_flags = FL_POSIX;
284*eb8ed7c6SJeff Layton fl->c.flc_type = exclusive != 0 ? F_WRLCK : F_RDLCK;
2853460f29aSChuck Lever p = xdr_decode_hyper(p, &l_offset);
2863460f29aSChuck Lever xdr_decode_hyper(p, &l_len);
2877ff84910SJeff Layton nlm4svc_set_file_lock_range(fl, l_offset, l_len);
2883460f29aSChuck Lever error = 0;
2893460f29aSChuck Lever out:
2903460f29aSChuck Lever return error;
2913460f29aSChuck Lever out_overflow:
2923460f29aSChuck Lever return -EIO;
2933460f29aSChuck Lever }
2943460f29aSChuck Lever
2953460f29aSChuck Lever /*
2963460f29aSChuck Lever * string caller_name<LM_MAXSTRLEN>;
2973460f29aSChuck Lever */
encode_caller_name(struct xdr_stream * xdr,const char * name)2983460f29aSChuck Lever static void encode_caller_name(struct xdr_stream *xdr, const char *name)
2993460f29aSChuck Lever {
3003460f29aSChuck Lever /* NB: client-side does not set lock->len */
3013460f29aSChuck Lever u32 length = strlen(name);
3023460f29aSChuck Lever __be32 *p;
3033460f29aSChuck Lever
3043460f29aSChuck Lever p = xdr_reserve_space(xdr, 4 + length);
3053460f29aSChuck Lever xdr_encode_opaque(p, name, length);
3063460f29aSChuck Lever }
3073460f29aSChuck Lever
3083460f29aSChuck Lever /*
3093460f29aSChuck Lever * struct nlm4_lock {
3103460f29aSChuck Lever * string caller_name<LM_MAXSTRLEN>;
3113460f29aSChuck Lever * netobj fh;
3123460f29aSChuck Lever * netobj oh;
3133460f29aSChuck Lever * int32 svid;
3143460f29aSChuck Lever * uint64 l_offset;
3153460f29aSChuck Lever * uint64 l_len;
3163460f29aSChuck Lever * };
3173460f29aSChuck Lever */
encode_nlm4_lock(struct xdr_stream * xdr,const struct nlm_lock * lock)3183460f29aSChuck Lever static void encode_nlm4_lock(struct xdr_stream *xdr,
3193460f29aSChuck Lever const struct nlm_lock *lock)
3203460f29aSChuck Lever {
3213460f29aSChuck Lever u64 l_offset, l_len;
3223460f29aSChuck Lever __be32 *p;
3233460f29aSChuck Lever
3243460f29aSChuck Lever encode_caller_name(xdr, lock->caller);
3253460f29aSChuck Lever encode_fh(xdr, &lock->fh);
3263460f29aSChuck Lever encode_netobj(xdr, lock->oh.data, lock->oh.len);
3273460f29aSChuck Lever
3283460f29aSChuck Lever p = xdr_reserve_space(xdr, 4 + 8 + 8);
3293460f29aSChuck Lever *p++ = cpu_to_be32(lock->svid);
3303460f29aSChuck Lever
3313460f29aSChuck Lever nlm4_compute_offsets(lock, &l_offset, &l_len);
3323460f29aSChuck Lever p = xdr_encode_hyper(p, l_offset);
3333460f29aSChuck Lever xdr_encode_hyper(p, l_len);
3343460f29aSChuck Lever }
3353460f29aSChuck Lever
3363460f29aSChuck Lever
3373460f29aSChuck Lever /*
3383460f29aSChuck Lever * NLMv4 XDR encode functions
3393460f29aSChuck Lever *
3403460f29aSChuck Lever * NLMv4 argument types are defined in Appendix II of RFC 1813:
3413460f29aSChuck Lever * "NFS Version 3 Protocol Specification" and Chapter 10 of X/Open's
3423460f29aSChuck Lever * "Protocols for Interworking: XNFS, Version 3W".
3433460f29aSChuck Lever */
3443460f29aSChuck Lever
3453460f29aSChuck Lever /*
3463460f29aSChuck Lever * struct nlm4_testargs {
3473460f29aSChuck Lever * netobj cookie;
3483460f29aSChuck Lever * bool exclusive;
3493460f29aSChuck Lever * struct nlm4_lock alock;
3503460f29aSChuck Lever * };
3513460f29aSChuck Lever */
nlm4_xdr_enc_testargs(struct rpc_rqst * req,struct xdr_stream * xdr,const void * data)3529f06c719SChuck Lever static void nlm4_xdr_enc_testargs(struct rpc_rqst *req,
3539f06c719SChuck Lever struct xdr_stream *xdr,
354bf96391eSChristoph Hellwig const void *data)
3553460f29aSChuck Lever {
356bf96391eSChristoph Hellwig const struct nlm_args *args = data;
3573460f29aSChuck Lever const struct nlm_lock *lock = &args->lock;
3583460f29aSChuck Lever
3599f06c719SChuck Lever encode_cookie(xdr, &args->cookie);
360*eb8ed7c6SJeff Layton encode_bool(xdr, lock->fl.c.flc_type == F_WRLCK);
3619f06c719SChuck Lever encode_nlm4_lock(xdr, lock);
3623460f29aSChuck Lever }
3633460f29aSChuck Lever
3643460f29aSChuck Lever /*
3653460f29aSChuck Lever * struct nlm4_lockargs {
3663460f29aSChuck Lever * netobj cookie;
3673460f29aSChuck Lever * bool block;
3683460f29aSChuck Lever * bool exclusive;
3693460f29aSChuck Lever * struct nlm4_lock alock;
3703460f29aSChuck Lever * bool reclaim;
3713460f29aSChuck Lever * int state;
3723460f29aSChuck Lever * };
3733460f29aSChuck Lever */
nlm4_xdr_enc_lockargs(struct rpc_rqst * req,struct xdr_stream * xdr,const void * data)3749f06c719SChuck Lever static void nlm4_xdr_enc_lockargs(struct rpc_rqst *req,
3759f06c719SChuck Lever struct xdr_stream *xdr,
376bf96391eSChristoph Hellwig const void *data)
3773460f29aSChuck Lever {
378bf96391eSChristoph Hellwig const struct nlm_args *args = data;
3793460f29aSChuck Lever const struct nlm_lock *lock = &args->lock;
3803460f29aSChuck Lever
3819f06c719SChuck Lever encode_cookie(xdr, &args->cookie);
3829f06c719SChuck Lever encode_bool(xdr, args->block);
383*eb8ed7c6SJeff Layton encode_bool(xdr, lock->fl.c.flc_type == F_WRLCK);
3849f06c719SChuck Lever encode_nlm4_lock(xdr, lock);
3859f06c719SChuck Lever encode_bool(xdr, args->reclaim);
3869f06c719SChuck Lever encode_int32(xdr, args->state);
3873460f29aSChuck Lever }
3883460f29aSChuck Lever
3893460f29aSChuck Lever /*
3903460f29aSChuck Lever * struct nlm4_cancargs {
3913460f29aSChuck Lever * netobj cookie;
3923460f29aSChuck Lever * bool block;
3933460f29aSChuck Lever * bool exclusive;
3943460f29aSChuck Lever * struct nlm4_lock alock;
3953460f29aSChuck Lever * };
3963460f29aSChuck Lever */
nlm4_xdr_enc_cancargs(struct rpc_rqst * req,struct xdr_stream * xdr,const void * data)3979f06c719SChuck Lever static void nlm4_xdr_enc_cancargs(struct rpc_rqst *req,
3989f06c719SChuck Lever struct xdr_stream *xdr,
399bf96391eSChristoph Hellwig const void *data)
4003460f29aSChuck Lever {
401bf96391eSChristoph Hellwig const struct nlm_args *args = data;
4023460f29aSChuck Lever const struct nlm_lock *lock = &args->lock;
4033460f29aSChuck Lever
4049f06c719SChuck Lever encode_cookie(xdr, &args->cookie);
4059f06c719SChuck Lever encode_bool(xdr, args->block);
406*eb8ed7c6SJeff Layton encode_bool(xdr, lock->fl.c.flc_type == F_WRLCK);
4079f06c719SChuck Lever encode_nlm4_lock(xdr, lock);
4083460f29aSChuck Lever }
4093460f29aSChuck Lever
4103460f29aSChuck Lever /*
4113460f29aSChuck Lever * struct nlm4_unlockargs {
4123460f29aSChuck Lever * netobj cookie;
4133460f29aSChuck Lever * struct nlm4_lock alock;
4143460f29aSChuck Lever * };
4153460f29aSChuck Lever */
nlm4_xdr_enc_unlockargs(struct rpc_rqst * req,struct xdr_stream * xdr,const void * data)4169f06c719SChuck Lever static void nlm4_xdr_enc_unlockargs(struct rpc_rqst *req,
4179f06c719SChuck Lever struct xdr_stream *xdr,
418bf96391eSChristoph Hellwig const void *data)
4193460f29aSChuck Lever {
420bf96391eSChristoph Hellwig const struct nlm_args *args = data;
4213460f29aSChuck Lever const struct nlm_lock *lock = &args->lock;
4223460f29aSChuck Lever
4239f06c719SChuck Lever encode_cookie(xdr, &args->cookie);
4249f06c719SChuck Lever encode_nlm4_lock(xdr, lock);
4253460f29aSChuck Lever }
4263460f29aSChuck Lever
4273460f29aSChuck Lever /*
4283460f29aSChuck Lever * struct nlm4_res {
4293460f29aSChuck Lever * netobj cookie;
4303460f29aSChuck Lever * nlm4_stat stat;
4313460f29aSChuck Lever * };
4323460f29aSChuck Lever */
nlm4_xdr_enc_res(struct rpc_rqst * req,struct xdr_stream * xdr,const void * data)4339f06c719SChuck Lever static void nlm4_xdr_enc_res(struct rpc_rqst *req,
4349f06c719SChuck Lever struct xdr_stream *xdr,
435bf96391eSChristoph Hellwig const void *data)
4363460f29aSChuck Lever {
437bf96391eSChristoph Hellwig const struct nlm_res *result = data;
438bf96391eSChristoph Hellwig
4399f06c719SChuck Lever encode_cookie(xdr, &result->cookie);
4409f06c719SChuck Lever encode_nlm4_stat(xdr, result->status);
4413460f29aSChuck Lever }
4423460f29aSChuck Lever
4433460f29aSChuck Lever /*
4443460f29aSChuck Lever * union nlm4_testrply switch (nlm4_stats stat) {
4453460f29aSChuck Lever * case NLM4_DENIED:
4463460f29aSChuck Lever * struct nlm4_holder holder;
4473460f29aSChuck Lever * default:
4483460f29aSChuck Lever * void;
4493460f29aSChuck Lever * };
4503460f29aSChuck Lever *
4513460f29aSChuck Lever * struct nlm4_testres {
4523460f29aSChuck Lever * netobj cookie;
4533460f29aSChuck Lever * nlm4_testrply test_stat;
4543460f29aSChuck Lever * };
4553460f29aSChuck Lever */
nlm4_xdr_enc_testres(struct rpc_rqst * req,struct xdr_stream * xdr,const void * data)4569f06c719SChuck Lever static void nlm4_xdr_enc_testres(struct rpc_rqst *req,
4579f06c719SChuck Lever struct xdr_stream *xdr,
458bf96391eSChristoph Hellwig const void *data)
4593460f29aSChuck Lever {
460bf96391eSChristoph Hellwig const struct nlm_res *result = data;
461bf96391eSChristoph Hellwig
4629f06c719SChuck Lever encode_cookie(xdr, &result->cookie);
4639f06c719SChuck Lever encode_nlm4_stat(xdr, result->status);
4643460f29aSChuck Lever if (result->status == nlm_lck_denied)
4659f06c719SChuck Lever encode_nlm4_holder(xdr, result);
4663460f29aSChuck Lever }
4673460f29aSChuck Lever
4683460f29aSChuck Lever
4693460f29aSChuck Lever /*
4703460f29aSChuck Lever * NLMv4 XDR decode functions
4713460f29aSChuck Lever *
4723460f29aSChuck Lever * NLMv4 argument types are defined in Appendix II of RFC 1813:
4733460f29aSChuck Lever * "NFS Version 3 Protocol Specification" and Chapter 10 of X/Open's
4743460f29aSChuck Lever * "Protocols for Interworking: XNFS, Version 3W".
4753460f29aSChuck Lever */
4763460f29aSChuck Lever
4773460f29aSChuck Lever /*
4783460f29aSChuck Lever * union nlm4_testrply switch (nlm4_stats stat) {
4793460f29aSChuck Lever * case NLM4_DENIED:
4803460f29aSChuck Lever * struct nlm4_holder holder;
4813460f29aSChuck Lever * default:
4823460f29aSChuck Lever * void;
4833460f29aSChuck Lever * };
4843460f29aSChuck Lever *
4853460f29aSChuck Lever * struct nlm4_testres {
4863460f29aSChuck Lever * netobj cookie;
4873460f29aSChuck Lever * nlm4_testrply test_stat;
4883460f29aSChuck Lever * };
4893460f29aSChuck Lever */
decode_nlm4_testrply(struct xdr_stream * xdr,struct nlm_res * result)4903460f29aSChuck Lever static int decode_nlm4_testrply(struct xdr_stream *xdr,
4913460f29aSChuck Lever struct nlm_res *result)
4923460f29aSChuck Lever {
4933460f29aSChuck Lever int error;
4943460f29aSChuck Lever
4953460f29aSChuck Lever error = decode_nlm4_stat(xdr, &result->status);
4963460f29aSChuck Lever if (unlikely(error))
4973460f29aSChuck Lever goto out;
4983460f29aSChuck Lever if (result->status == nlm_lck_denied)
4993460f29aSChuck Lever error = decode_nlm4_holder(xdr, result);
5003460f29aSChuck Lever out:
5013460f29aSChuck Lever return error;
5023460f29aSChuck Lever }
5033460f29aSChuck Lever
nlm4_xdr_dec_testres(struct rpc_rqst * req,struct xdr_stream * xdr,void * data)504bf269551SChuck Lever static int nlm4_xdr_dec_testres(struct rpc_rqst *req,
505bf269551SChuck Lever struct xdr_stream *xdr,
5061fa23391SChristoph Hellwig void *data)
5073460f29aSChuck Lever {
5081fa23391SChristoph Hellwig struct nlm_res *result = data;
5093460f29aSChuck Lever int error;
5103460f29aSChuck Lever
511bf269551SChuck Lever error = decode_cookie(xdr, &result->cookie);
5123460f29aSChuck Lever if (unlikely(error))
5133460f29aSChuck Lever goto out;
514bf269551SChuck Lever error = decode_nlm4_testrply(xdr, result);
5153460f29aSChuck Lever out:
5163460f29aSChuck Lever return error;
5173460f29aSChuck Lever }
5183460f29aSChuck Lever
5193460f29aSChuck Lever /*
5203460f29aSChuck Lever * struct nlm4_res {
5213460f29aSChuck Lever * netobj cookie;
5223460f29aSChuck Lever * nlm4_stat stat;
5233460f29aSChuck Lever * };
5243460f29aSChuck Lever */
nlm4_xdr_dec_res(struct rpc_rqst * req,struct xdr_stream * xdr,void * data)525bf269551SChuck Lever static int nlm4_xdr_dec_res(struct rpc_rqst *req,
526bf269551SChuck Lever struct xdr_stream *xdr,
5271fa23391SChristoph Hellwig void *data)
5283460f29aSChuck Lever {
5291fa23391SChristoph Hellwig struct nlm_res *result = data;
5303460f29aSChuck Lever int error;
5313460f29aSChuck Lever
532bf269551SChuck Lever error = decode_cookie(xdr, &result->cookie);
5333460f29aSChuck Lever if (unlikely(error))
5343460f29aSChuck Lever goto out;
535bf269551SChuck Lever error = decode_nlm4_stat(xdr, &result->status);
5363460f29aSChuck Lever out:
5373460f29aSChuck Lever return error;
5383460f29aSChuck Lever }
5393460f29aSChuck Lever
5403460f29aSChuck Lever
5413460f29aSChuck Lever /*
5423460f29aSChuck Lever * For NLM, a void procedure really returns nothing
5433460f29aSChuck Lever */
5443460f29aSChuck Lever #define nlm4_xdr_dec_norep NULL
5453460f29aSChuck Lever
5463460f29aSChuck Lever #define PROC(proc, argtype, restype) \
5473460f29aSChuck Lever [NLMPROC_##proc] = { \
5483460f29aSChuck Lever .p_proc = NLMPROC_##proc, \
549bf96391eSChristoph Hellwig .p_encode = nlm4_xdr_enc_##argtype, \
5501fa23391SChristoph Hellwig .p_decode = nlm4_xdr_dec_##restype, \
5513460f29aSChuck Lever .p_arglen = NLM4_##argtype##_sz, \
5523460f29aSChuck Lever .p_replen = NLM4_##restype##_sz, \
5533460f29aSChuck Lever .p_statidx = NLMPROC_##proc, \
5543460f29aSChuck Lever .p_name = #proc, \
5553460f29aSChuck Lever }
5563460f29aSChuck Lever
557499b4988SChristoph Hellwig static const struct rpc_procinfo nlm4_procedures[] = {
5583460f29aSChuck Lever PROC(TEST, testargs, testres),
5593460f29aSChuck Lever PROC(LOCK, lockargs, res),
5603460f29aSChuck Lever PROC(CANCEL, cancargs, res),
5613460f29aSChuck Lever PROC(UNLOCK, unlockargs, res),
5623460f29aSChuck Lever PROC(GRANTED, testargs, res),
5633460f29aSChuck Lever PROC(TEST_MSG, testargs, norep),
5643460f29aSChuck Lever PROC(LOCK_MSG, lockargs, norep),
5653460f29aSChuck Lever PROC(CANCEL_MSG, cancargs, norep),
5663460f29aSChuck Lever PROC(UNLOCK_MSG, unlockargs, norep),
5673460f29aSChuck Lever PROC(GRANTED_MSG, testargs, norep),
5683460f29aSChuck Lever PROC(TEST_RES, testres, norep),
5693460f29aSChuck Lever PROC(LOCK_RES, res, norep),
5703460f29aSChuck Lever PROC(CANCEL_RES, res, norep),
5713460f29aSChuck Lever PROC(UNLOCK_RES, res, norep),
5723460f29aSChuck Lever PROC(GRANTED_RES, res, norep),
5733460f29aSChuck Lever };
5743460f29aSChuck Lever
5751c5876ddSChristoph Hellwig static unsigned int nlm_version4_counts[ARRAY_SIZE(nlm4_procedures)];
576a613fa16STrond Myklebust const struct rpc_version nlm_version4 = {
5773460f29aSChuck Lever .number = 4,
5783460f29aSChuck Lever .nrprocs = ARRAY_SIZE(nlm4_procedures),
5793460f29aSChuck Lever .procs = nlm4_procedures,
5801c5876ddSChristoph Hellwig .counts = nlm_version4_counts,
5813460f29aSChuck Lever };
582