Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * linux/fs/lockd/clnt4xdr.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * XDR functions to encode/decode NLM version 4 RPC arguments and results.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  * NLM client-side only.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  * Copyright (C) 2010, Oracle.  All rights reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/sunrpc/xdr.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/sunrpc/clnt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/sunrpc/stats.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/lockd/lockd.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <uapi/linux/nfs3.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #define NLMDBG_FACILITY		NLMDBG_XDR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #if (NLMCLNT_OHSIZE > XDR_MAX_NETOBJ)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #  error "NLM host name cannot be larger than XDR_MAX_NETOBJ!"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #if (NLMCLNT_OHSIZE > NLM_MAXSTRLEN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) #  error "NLM host name cannot be larger than NLM's maximum string length!"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31)  * Declare the space requirements for NLM arguments and replies as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32)  * number of 32bit-words
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) #define NLM4_void_sz		(0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) #define NLM4_cookie_sz		(1+(NLM_MAXCOOKIELEN>>2))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) #define NLM4_caller_sz		(1+(NLMCLNT_OHSIZE>>2))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) #define NLM4_owner_sz		(1+(NLMCLNT_OHSIZE>>2))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) #define NLM4_fhandle_sz		(1+(NFS3_FHSIZE>>2))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) #define NLM4_lock_sz		(5+NLM4_caller_sz+NLM4_owner_sz+NLM4_fhandle_sz)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) #define NLM4_holder_sz		(6+NLM4_owner_sz)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) #define NLM4_testargs_sz	(NLM4_cookie_sz+1+NLM4_lock_sz)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) #define NLM4_lockargs_sz	(NLM4_cookie_sz+4+NLM4_lock_sz)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) #define NLM4_cancargs_sz	(NLM4_cookie_sz+2+NLM4_lock_sz)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) #define NLM4_unlockargs_sz	(NLM4_cookie_sz+NLM4_lock_sz)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) #define NLM4_testres_sz		(NLM4_cookie_sz+1+NLM4_holder_sz)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) #define NLM4_res_sz		(NLM4_cookie_sz+1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) #define NLM4_norep_sz		(0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) static s64 loff_t_to_s64(loff_t offset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	s64 res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	if (offset >= NLM4_OFFSET_MAX)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 		res = NLM4_OFFSET_MAX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	else if (offset <= -NLM4_OFFSET_MAX)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 		res = -NLM4_OFFSET_MAX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 		res = offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	return res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) static void nlm4_compute_offsets(const struct nlm_lock *lock,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 				 u64 *l_offset, u64 *l_len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	const struct file_lock *fl = &lock->fl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	*l_offset = loff_t_to_s64(fl->fl_start);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	if (fl->fl_end == OFFSET_MAX)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 		*l_len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 		*l_len = loff_t_to_s64(fl->fl_end - fl->fl_start + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78)  * Encode/decode NLMv4 basic data types
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80)  * Basic NLMv4 data types are defined in Appendix II, section 6.1.4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81)  * of RFC 1813: "NFS Version 3 Protocol Specification" and in Chapter
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82)  * 10 of X/Open's "Protocols for Interworking: XNFS, Version 3W".
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84)  * Not all basic data types have their own encoding and decoding
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85)  * functions.  For run-time efficiency, some data types are encoded
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86)  * or decoded inline.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) static void encode_bool(struct xdr_stream *xdr, const int value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	__be32 *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	p = xdr_reserve_space(xdr, 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	*p = value ? xdr_one : xdr_zero;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) static void encode_int32(struct xdr_stream *xdr, const s32 value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	__be32 *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	p = xdr_reserve_space(xdr, 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	*p = cpu_to_be32(value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106)  *	typedef opaque netobj<MAXNETOBJ_SZ>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) static void encode_netobj(struct xdr_stream *xdr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 			  const u8 *data, const unsigned int length)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	__be32 *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	p = xdr_reserve_space(xdr, 4 + length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	xdr_encode_opaque(p, data, length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) static int decode_netobj(struct xdr_stream *xdr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 			 struct xdr_netobj *obj)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	ssize_t ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	ret = xdr_stream_decode_opaque_inline(xdr, (void *)&obj->data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 						XDR_MAX_NETOBJ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	if (unlikely(ret < 0))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	obj->len = ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131)  *	netobj cookie;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) static void encode_cookie(struct xdr_stream *xdr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 			  const struct nlm_cookie *cookie)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	encode_netobj(xdr, (u8 *)&cookie->data, cookie->len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) static int decode_cookie(struct xdr_stream *xdr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 			     struct nlm_cookie *cookie)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	u32 length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	__be32 *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	p = xdr_inline_decode(xdr, 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	if (unlikely(p == NULL))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 		goto out_overflow;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	length = be32_to_cpup(p++);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	/* apparently HPUX can return empty cookies */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	if (length == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 		goto out_hpux;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	if (length > NLM_MAXCOOKIELEN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 		goto out_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	p = xdr_inline_decode(xdr, length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	if (unlikely(p == NULL))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 		goto out_overflow;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	cookie->len = length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	memcpy(cookie->data, p, length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) out_hpux:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	cookie->len = 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	memset(cookie->data, 0, 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) out_size:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	dprintk("NFS: returned cookie was too long: %u\n", length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) out_overflow:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172)  *	netobj fh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) static void encode_fh(struct xdr_stream *xdr, const struct nfs_fh *fh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	encode_netobj(xdr, (u8 *)&fh->data, fh->size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180)  *	enum nlm4_stats {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181)  *		NLM4_GRANTED = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182)  *		NLM4_DENIED = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183)  *		NLM4_DENIED_NOLOCKS = 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184)  *		NLM4_BLOCKED = 3,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185)  *		NLM4_DENIED_GRACE_PERIOD = 4,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186)  *		NLM4_DEADLCK = 5,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187)  *		NLM4_ROFS = 6,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188)  *		NLM4_STALE_FH = 7,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189)  *		NLM4_FBIG = 8,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190)  *		NLM4_FAILED = 9
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191)  *	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193)  *	struct nlm4_stat {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194)  *		nlm4_stats stat;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195)  *	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197)  * NB: we don't swap bytes for the NLM status values.  The upper
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198)  * layers deal directly with the status value in network byte
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199)  * order.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) static void encode_nlm4_stat(struct xdr_stream *xdr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 			     const __be32 stat)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 	__be32 *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 	BUG_ON(be32_to_cpu(stat) > NLM_FAILED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	p = xdr_reserve_space(xdr, 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	*p = stat;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) static int decode_nlm4_stat(struct xdr_stream *xdr, __be32 *stat)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 	__be32 *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 	p = xdr_inline_decode(xdr, 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	if (unlikely(p == NULL))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 		goto out_overflow;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	if (unlikely(ntohl(*p) > ntohl(nlm4_failed)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 		goto out_bad_xdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	*stat = *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) out_bad_xdr:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	dprintk("%s: server returned invalid nlm4_stats value: %u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 			__func__, be32_to_cpup(p));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) out_overflow:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231)  *	struct nlm4_holder {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232)  *		bool	exclusive;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233)  *		int32	svid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234)  *		netobj	oh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235)  *		uint64	l_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236)  *		uint64	l_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237)  *	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) static void encode_nlm4_holder(struct xdr_stream *xdr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 			       const struct nlm_res *result)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	const struct nlm_lock *lock = &result->lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	u64 l_offset, l_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	__be32 *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	encode_bool(xdr, lock->fl.fl_type == F_RDLCK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 	encode_int32(xdr, lock->svid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	encode_netobj(xdr, lock->oh.data, lock->oh.len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 	p = xdr_reserve_space(xdr, 4 + 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	nlm4_compute_offsets(lock, &l_offset, &l_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 	p = xdr_encode_hyper(p, l_offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 	xdr_encode_hyper(p, l_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) static int decode_nlm4_holder(struct xdr_stream *xdr, struct nlm_res *result)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 	struct nlm_lock *lock = &result->lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	struct file_lock *fl = &lock->fl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 	u64 l_offset, l_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 	u32 exclusive;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 	int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 	__be32 *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 	s32 end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 	memset(lock, 0, sizeof(*lock));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 	locks_init_lock(fl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 	p = xdr_inline_decode(xdr, 4 + 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 	if (unlikely(p == NULL))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 		goto out_overflow;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 	exclusive = be32_to_cpup(p++);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 	lock->svid = be32_to_cpup(p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 	fl->fl_pid = (pid_t)lock->svid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 	error = decode_netobj(xdr, &lock->oh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 	if (unlikely(error))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 	p = xdr_inline_decode(xdr, 8 + 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 	if (unlikely(p == NULL))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 		goto out_overflow;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 	fl->fl_flags = FL_POSIX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 	fl->fl_type  = exclusive != 0 ? F_WRLCK : F_RDLCK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 	p = xdr_decode_hyper(p, &l_offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 	xdr_decode_hyper(p, &l_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 	end = l_offset + l_len - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 	fl->fl_start = (loff_t)l_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 	if (l_len == 0 || end < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 		fl->fl_end = OFFSET_MAX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 		fl->fl_end = (loff_t)end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 	error = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 	return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) out_overflow:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 	return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303)  *	string caller_name<LM_MAXSTRLEN>;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) static void encode_caller_name(struct xdr_stream *xdr, const char *name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 	/* NB: client-side does not set lock->len */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 	u32 length = strlen(name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 	__be32 *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 	p = xdr_reserve_space(xdr, 4 + length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 	xdr_encode_opaque(p, name, length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316)  *	struct nlm4_lock {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317)  *		string	caller_name<LM_MAXSTRLEN>;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318)  *		netobj	fh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319)  *		netobj	oh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320)  *		int32	svid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321)  *		uint64	l_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322)  *		uint64	l_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323)  *	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) static void encode_nlm4_lock(struct xdr_stream *xdr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 			     const struct nlm_lock *lock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 	u64 l_offset, l_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 	__be32 *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 	encode_caller_name(xdr, lock->caller);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 	encode_fh(xdr, &lock->fh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 	encode_netobj(xdr, lock->oh.data, lock->oh.len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 	p = xdr_reserve_space(xdr, 4 + 8 + 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 	*p++ = cpu_to_be32(lock->svid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 	nlm4_compute_offsets(lock, &l_offset, &l_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 	p = xdr_encode_hyper(p, l_offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 	xdr_encode_hyper(p, l_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345)  * NLMv4 XDR encode functions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347)  * NLMv4 argument types are defined in Appendix II of RFC 1813:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348)  * "NFS Version 3 Protocol Specification" and Chapter 10 of X/Open's
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349)  * "Protocols for Interworking: XNFS, Version 3W".
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353)  *	struct nlm4_testargs {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354)  *		netobj cookie;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355)  *		bool exclusive;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356)  *		struct nlm4_lock alock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357)  *	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) static void nlm4_xdr_enc_testargs(struct rpc_rqst *req,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 				  struct xdr_stream *xdr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 				  const void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 	const struct nlm_args *args = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 	const struct nlm_lock *lock = &args->lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 	encode_cookie(xdr, &args->cookie);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 	encode_bool(xdr, lock->fl.fl_type == F_WRLCK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 	encode_nlm4_lock(xdr, lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372)  *	struct nlm4_lockargs {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373)  *		netobj cookie;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374)  *		bool block;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375)  *		bool exclusive;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376)  *		struct nlm4_lock alock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377)  *		bool reclaim;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378)  *		int state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379)  *	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) static void nlm4_xdr_enc_lockargs(struct rpc_rqst *req,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 				  struct xdr_stream *xdr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 				  const void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 	const struct nlm_args *args = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 	const struct nlm_lock *lock = &args->lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 	encode_cookie(xdr, &args->cookie);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 	encode_bool(xdr, args->block);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 	encode_bool(xdr, lock->fl.fl_type == F_WRLCK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 	encode_nlm4_lock(xdr, lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 	encode_bool(xdr, args->reclaim);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 	encode_int32(xdr, args->state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397)  *	struct nlm4_cancargs {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398)  *		netobj cookie;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399)  *		bool block;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400)  *		bool exclusive;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401)  *		struct nlm4_lock alock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402)  *	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) static void nlm4_xdr_enc_cancargs(struct rpc_rqst *req,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 				  struct xdr_stream *xdr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 				  const void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 	const struct nlm_args *args = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 	const struct nlm_lock *lock = &args->lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 	encode_cookie(xdr, &args->cookie);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 	encode_bool(xdr, args->block);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 	encode_bool(xdr, lock->fl.fl_type == F_WRLCK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 	encode_nlm4_lock(xdr, lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418)  *	struct nlm4_unlockargs {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419)  *		netobj cookie;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420)  *		struct nlm4_lock alock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421)  *	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) static void nlm4_xdr_enc_unlockargs(struct rpc_rqst *req,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 				    struct xdr_stream *xdr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 				    const void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 	const struct nlm_args *args = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 	const struct nlm_lock *lock = &args->lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 	encode_cookie(xdr, &args->cookie);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 	encode_nlm4_lock(xdr, lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435)  *	struct nlm4_res {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436)  *		netobj cookie;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437)  *		nlm4_stat stat;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438)  *	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) static void nlm4_xdr_enc_res(struct rpc_rqst *req,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 			     struct xdr_stream *xdr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 			     const void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 	const struct nlm_res *result = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 	encode_cookie(xdr, &result->cookie);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) 	encode_nlm4_stat(xdr, result->status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451)  *	union nlm4_testrply switch (nlm4_stats stat) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452)  *	case NLM4_DENIED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453)  *		struct nlm4_holder holder;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454)  *	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455)  *		void;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456)  *	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458)  *	struct nlm4_testres {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459)  *		netobj cookie;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460)  *		nlm4_testrply test_stat;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461)  *	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) static void nlm4_xdr_enc_testres(struct rpc_rqst *req,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) 				 struct xdr_stream *xdr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) 				 const void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) 	const struct nlm_res *result = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) 	encode_cookie(xdr, &result->cookie);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) 	encode_nlm4_stat(xdr, result->status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) 	if (result->status == nlm_lck_denied)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) 		encode_nlm4_holder(xdr, result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477)  * NLMv4 XDR decode functions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479)  * NLMv4 argument types are defined in Appendix II of RFC 1813:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480)  * "NFS Version 3 Protocol Specification" and Chapter 10 of X/Open's
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481)  * "Protocols for Interworking: XNFS, Version 3W".
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485)  *	union nlm4_testrply switch (nlm4_stats stat) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486)  *	case NLM4_DENIED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487)  *		struct nlm4_holder holder;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488)  *	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489)  *		void;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490)  *	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492)  *	struct nlm4_testres {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493)  *		netobj cookie;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494)  *		nlm4_testrply test_stat;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495)  *	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) static int decode_nlm4_testrply(struct xdr_stream *xdr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) 				struct nlm_res *result)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) 	int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) 	error = decode_nlm4_stat(xdr, &result->status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) 	if (unlikely(error))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) 	if (result->status == nlm_lck_denied)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) 		error = decode_nlm4_holder(xdr, result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) 	return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) static int nlm4_xdr_dec_testres(struct rpc_rqst *req,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) 				struct xdr_stream *xdr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) 				void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) 	struct nlm_res *result = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) 	int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) 	error = decode_cookie(xdr, &result->cookie);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) 	if (unlikely(error))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) 	error = decode_nlm4_testrply(xdr, result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) 	return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527)  *	struct nlm4_res {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528)  *		netobj cookie;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529)  *		nlm4_stat stat;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530)  *	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) static int nlm4_xdr_dec_res(struct rpc_rqst *req,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) 			    struct xdr_stream *xdr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) 			    void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) 	struct nlm_res *result = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) 	int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) 	error = decode_cookie(xdr, &result->cookie);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) 	if (unlikely(error))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) 	error = decode_nlm4_stat(xdr, &result->status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) 	return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549)  * For NLM, a void procedure really returns nothing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) #define nlm4_xdr_dec_norep	NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) #define PROC(proc, argtype, restype)					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) [NLMPROC_##proc] = {							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) 	.p_proc      = NLMPROC_##proc,					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) 	.p_encode    = nlm4_xdr_enc_##argtype,				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) 	.p_decode    = nlm4_xdr_dec_##restype,				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) 	.p_arglen    = NLM4_##argtype##_sz,				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) 	.p_replen    = NLM4_##restype##_sz,				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) 	.p_statidx   = NLMPROC_##proc,					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) 	.p_name      = #proc,						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) static const struct rpc_procinfo nlm4_procedures[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) 	PROC(TEST,		testargs,	testres),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) 	PROC(LOCK,		lockargs,	res),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) 	PROC(CANCEL,		cancargs,	res),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) 	PROC(UNLOCK,		unlockargs,	res),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) 	PROC(GRANTED,		testargs,	res),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) 	PROC(TEST_MSG,		testargs,	norep),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) 	PROC(LOCK_MSG,		lockargs,	norep),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) 	PROC(CANCEL_MSG,	cancargs,	norep),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) 	PROC(UNLOCK_MSG,	unlockargs,	norep),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) 	PROC(GRANTED_MSG,	testargs,	norep),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) 	PROC(TEST_RES,		testres,	norep),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) 	PROC(LOCK_RES,		res,		norep),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) 	PROC(CANCEL_RES,	res,		norep),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) 	PROC(UNLOCK_RES,	res,		norep),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) 	PROC(GRANTED_RES,	res,		norep),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) static unsigned int nlm_version4_counts[ARRAY_SIZE(nlm4_procedures)];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) const struct rpc_version nlm_version4 = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) 	.number		= 4,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) 	.nrprocs	= ARRAY_SIZE(nlm4_procedures),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) 	.procs		= nlm4_procedures,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) 	.counts		= nlm_version4_counts,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) };