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/clntxdr.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 3 RPC arguments and results.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  * NLM version 3 is backwards compatible with NLM versions 1 and 2.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  * NLM client-side only.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  * Copyright (C) 2010, Oracle.  All rights reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/sunrpc/xdr.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/sunrpc/clnt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/sunrpc/stats.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/lockd/lockd.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <uapi/linux/nfs2.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #define NLMDBG_FACILITY		NLMDBG_XDR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #if (NLMCLNT_OHSIZE > XDR_MAX_NETOBJ)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #  error "NLM host name cannot be larger than XDR_MAX_NETOBJ!"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28)  * Declare the space requirements for NLM arguments and replies as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29)  * number of 32bit-words
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) #define NLM_cookie_sz		(1+(NLM_MAXCOOKIELEN>>2))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) #define NLM_caller_sz		(1+(NLMCLNT_OHSIZE>>2))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) #define NLM_owner_sz		(1+(NLMCLNT_OHSIZE>>2))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) #define NLM_fhandle_sz		(1+(NFS2_FHSIZE>>2))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) #define NLM_lock_sz		(3+NLM_caller_sz+NLM_owner_sz+NLM_fhandle_sz)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) #define NLM_holder_sz		(4+NLM_owner_sz)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) #define NLM_testargs_sz		(NLM_cookie_sz+1+NLM_lock_sz)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) #define NLM_lockargs_sz		(NLM_cookie_sz+4+NLM_lock_sz)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) #define NLM_cancargs_sz		(NLM_cookie_sz+2+NLM_lock_sz)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) #define NLM_unlockargs_sz	(NLM_cookie_sz+NLM_lock_sz)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) #define NLM_testres_sz		(NLM_cookie_sz+1+NLM_holder_sz)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) #define NLM_res_sz		(NLM_cookie_sz+1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) #define NLM_norep_sz		(0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) static s32 loff_t_to_s32(loff_t offset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	s32 res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	if (offset >= NLM_OFFSET_MAX)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 		res = NLM_OFFSET_MAX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	else if (offset <= -NLM_OFFSET_MAX)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 		res = -NLM_OFFSET_MAX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 		res = offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	return res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) static void nlm_compute_offsets(const struct nlm_lock *lock,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 				u32 *l_offset, u32 *l_len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	const struct file_lock *fl = &lock->fl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	*l_offset = loff_t_to_s32(fl->fl_start);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	if (fl->fl_end == OFFSET_MAX)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 		*l_len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 		*l_len = loff_t_to_s32(fl->fl_end - fl->fl_start + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74)  * Encode/decode NLMv3 basic data types
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76)  * Basic NLMv3 data types are not defined in an IETF standards
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77)  * document.  X/Open has a description of these data types that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78)  * is useful.  See Chapter 10 of "Protocols for Interworking:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79)  * XNFS, Version 3W".
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81)  * Not all basic data types have their own encoding and decoding
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82)  * functions.  For run-time efficiency, some data types are encoded
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83)  * or decoded inline.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) static void encode_bool(struct xdr_stream *xdr, const int value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	__be32 *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	p = xdr_reserve_space(xdr, 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	*p = value ? xdr_one : xdr_zero;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) static void encode_int32(struct xdr_stream *xdr, const s32 value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	__be32 *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	p = xdr_reserve_space(xdr, 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	*p = cpu_to_be32(value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103)  *	typedef opaque netobj<MAXNETOBJ_SZ>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) static void encode_netobj(struct xdr_stream *xdr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 			  const u8 *data, const unsigned int length)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	__be32 *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	p = xdr_reserve_space(xdr, 4 + length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	xdr_encode_opaque(p, data, length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) static int decode_netobj(struct xdr_stream *xdr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 			 struct xdr_netobj *obj)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	ssize_t ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	ret = xdr_stream_decode_opaque_inline(xdr, (void *)&obj->data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 			XDR_MAX_NETOBJ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	if (unlikely(ret < 0))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	obj->len = ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128)  *	netobj cookie;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) static void encode_cookie(struct xdr_stream *xdr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 			  const struct nlm_cookie *cookie)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	encode_netobj(xdr, (u8 *)&cookie->data, cookie->len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) static int decode_cookie(struct xdr_stream *xdr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 			 struct nlm_cookie *cookie)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	u32 length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	__be32 *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	p = xdr_inline_decode(xdr, 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	if (unlikely(p == NULL))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 		goto out_overflow;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	length = be32_to_cpup(p++);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	/* apparently HPUX can return empty cookies */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	if (length == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 		goto out_hpux;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	if (length > NLM_MAXCOOKIELEN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 		goto out_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	p = xdr_inline_decode(xdr, length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	if (unlikely(p == NULL))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 		goto out_overflow;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	cookie->len = length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	memcpy(cookie->data, p, length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) out_hpux:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	cookie->len = 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	memset(cookie->data, 0, 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) out_size:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	dprintk("NFS: returned cookie was too long: %u\n", length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) out_overflow:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169)  *	netobj fh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) static void encode_fh(struct xdr_stream *xdr, const struct nfs_fh *fh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	encode_netobj(xdr, (u8 *)&fh->data, NFS2_FHSIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177)  *	enum nlm_stats {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178)  *		LCK_GRANTED = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179)  *		LCK_DENIED = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180)  *		LCK_DENIED_NOLOCKS = 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181)  *		LCK_BLOCKED = 3,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182)  *		LCK_DENIED_GRACE_PERIOD = 4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183)  *	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186)  *	struct nlm_stat {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187)  *		nlm_stats stat;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188)  *	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190)  * NB: we don't swap bytes for the NLM status values.  The upper
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191)  * layers deal directly with the status value in network byte
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192)  * order.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) static void encode_nlm_stat(struct xdr_stream *xdr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 			    const __be32 stat)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	__be32 *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	WARN_ON_ONCE(be32_to_cpu(stat) > NLM_LCK_DENIED_GRACE_PERIOD);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	p = xdr_reserve_space(xdr, 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	*p = stat;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) static int decode_nlm_stat(struct xdr_stream *xdr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 			   __be32 *stat)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	__be32 *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	p = xdr_inline_decode(xdr, 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 	if (unlikely(p == NULL))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 		goto out_overflow;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 	if (unlikely(ntohl(*p) > ntohl(nlm_lck_denied_grace_period)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 		goto out_enum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 	*stat = *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) out_enum:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	dprintk("%s: server returned invalid nlm_stats value: %u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 		__func__, be32_to_cpup(p));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) out_overflow:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226)  *	struct nlm_holder {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227)  *		bool exclusive;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228)  *		int uppid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229)  *		netobj oh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230)  *		unsigned l_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231)  *		unsigned l_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232)  *	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) static void encode_nlm_holder(struct xdr_stream *xdr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 			      const struct nlm_res *result)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 	const struct nlm_lock *lock = &result->lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	u32 l_offset, l_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 	__be32 *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	encode_bool(xdr, lock->fl.fl_type == F_RDLCK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	encode_int32(xdr, lock->svid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	encode_netobj(xdr, lock->oh.data, lock->oh.len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 	p = xdr_reserve_space(xdr, 4 + 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	nlm_compute_offsets(lock, &l_offset, &l_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 	*p++ = cpu_to_be32(l_offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	*p   = cpu_to_be32(l_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) static int decode_nlm_holder(struct xdr_stream *xdr, struct nlm_res *result)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 	struct nlm_lock *lock = &result->lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 	struct file_lock *fl = &lock->fl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 	u32 exclusive, l_offset, l_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 	__be32 *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 	s32 end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 	memset(lock, 0, sizeof(*lock));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 	locks_init_lock(fl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 	p = xdr_inline_decode(xdr, 4 + 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 	if (unlikely(p == NULL))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 		goto out_overflow;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 	exclusive = be32_to_cpup(p++);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 	lock->svid = be32_to_cpup(p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 	fl->fl_pid = (pid_t)lock->svid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 	error = decode_netobj(xdr, &lock->oh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 	if (unlikely(error))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 	p = xdr_inline_decode(xdr, 4 + 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 	if (unlikely(p == NULL))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 		goto out_overflow;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 	fl->fl_flags = FL_POSIX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 	fl->fl_type  = exclusive != 0 ? F_WRLCK : F_RDLCK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 	l_offset = be32_to_cpup(p++);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 	l_len = be32_to_cpup(p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 	end = l_offset + l_len - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 	fl->fl_start = (loff_t)l_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 	if (l_len == 0 || end < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 		fl->fl_end = OFFSET_MAX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 		fl->fl_end = (loff_t)end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 	error = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 	return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) out_overflow:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 	return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297)  *	string caller_name<LM_MAXSTRLEN>;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) static void encode_caller_name(struct xdr_stream *xdr, const char *name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 	/* NB: client-side does not set lock->len */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 	u32 length = strlen(name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 	__be32 *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 	p = xdr_reserve_space(xdr, 4 + length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 	xdr_encode_opaque(p, name, length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310)  *	struct nlm_lock {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311)  *		string caller_name<LM_MAXSTRLEN>;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312)  *		netobj fh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313)  *		netobj oh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314)  *		int uppid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315)  *		unsigned l_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316)  *		unsigned l_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317)  *	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) static void encode_nlm_lock(struct xdr_stream *xdr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 			    const struct nlm_lock *lock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 	u32 l_offset, l_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 	__be32 *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 	encode_caller_name(xdr, lock->caller);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 	encode_fh(xdr, &lock->fh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 	encode_netobj(xdr, lock->oh.data, lock->oh.len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 	p = xdr_reserve_space(xdr, 4 + 4 + 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 	*p++ = cpu_to_be32(lock->svid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 	nlm_compute_offsets(lock, &l_offset, &l_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 	*p++ = cpu_to_be32(l_offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 	*p   = cpu_to_be32(l_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339)  * NLMv3 XDR encode functions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341)  * NLMv3 argument types are defined in Chapter 10 of The Open Group's
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342)  * "Protocols for Interworking: XNFS, Version 3W".
^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) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346)  *	struct nlm_testargs {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347)  *		netobj cookie;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348)  *		bool exclusive;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349)  *		struct nlm_lock alock;
^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) static void nlm_xdr_enc_testargs(struct rpc_rqst *req,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 				 struct xdr_stream *xdr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 				 const void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 	const struct nlm_args *args = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 	const struct nlm_lock *lock = &args->lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 	encode_cookie(xdr, &args->cookie);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 	encode_bool(xdr, lock->fl.fl_type == F_WRLCK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 	encode_nlm_lock(xdr, lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365)  *	struct nlm_lockargs {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366)  *		netobj cookie;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367)  *		bool block;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368)  *		bool exclusive;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369)  *		struct nlm_lock alock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370)  *		bool reclaim;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371)  *		int state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372)  *	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) static void nlm_xdr_enc_lockargs(struct rpc_rqst *req,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 				 struct xdr_stream *xdr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 				 const void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 	const struct nlm_args *args = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 	const struct nlm_lock *lock = &args->lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 	encode_cookie(xdr, &args->cookie);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 	encode_bool(xdr, args->block);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 	encode_bool(xdr, lock->fl.fl_type == F_WRLCK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 	encode_nlm_lock(xdr, lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 	encode_bool(xdr, args->reclaim);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 	encode_int32(xdr, args->state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390)  *	struct nlm_cancargs {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391)  *		netobj cookie;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392)  *		bool block;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393)  *		bool exclusive;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394)  *		struct nlm_lock alock;
^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) static void nlm_xdr_enc_cancargs(struct rpc_rqst *req,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 				 struct xdr_stream *xdr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 				 const void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 	const struct nlm_args *args = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 	const struct nlm_lock *lock = &args->lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 	encode_cookie(xdr, &args->cookie);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 	encode_bool(xdr, args->block);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 	encode_bool(xdr, lock->fl.fl_type == F_WRLCK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 	encode_nlm_lock(xdr, lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411)  *	struct nlm_unlockargs {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412)  *		netobj cookie;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413)  *		struct nlm_lock alock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414)  *	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) static void nlm_xdr_enc_unlockargs(struct rpc_rqst *req,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 				   struct xdr_stream *xdr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 				   const void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 	const struct nlm_args *args = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 	const struct nlm_lock *lock = &args->lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 	encode_cookie(xdr, &args->cookie);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 	encode_nlm_lock(xdr, lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428)  *	struct nlm_res {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429)  *		netobj cookie;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430)  *		nlm_stat stat;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431)  *	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) static void nlm_xdr_enc_res(struct rpc_rqst *req,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 			    struct xdr_stream *xdr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 			    const void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) 	const struct nlm_res *result = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 	encode_cookie(xdr, &result->cookie);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 	encode_nlm_stat(xdr, result->status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444)  *	union nlm_testrply switch (nlm_stats stat) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445)  *	case LCK_DENIED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446)  *		struct nlm_holder holder;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447)  *	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448)  *		void;
^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)  *	struct nlm_testres {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452)  *		netobj cookie;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453)  *		nlm_testrply test_stat;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454)  *	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) static void encode_nlm_testrply(struct xdr_stream *xdr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) 				const struct nlm_res *result)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) 	if (result->status == nlm_lck_denied)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) 		encode_nlm_holder(xdr, result);
^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 nlm_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_nlm_stat(xdr, result->status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) 	encode_nlm_testrply(xdr, result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) }
^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)  * NLMv3 XDR decode functions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478)  * NLMv3 result types are defined in Chapter 10 of The Open Group's
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479)  * "Protocols for Interworking: XNFS, Version 3W".
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483)  *	union nlm_testrply switch (nlm_stats stat) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484)  *	case LCK_DENIED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485)  *		struct nlm_holder holder;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486)  *	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487)  *		void;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488)  *	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490)  *	struct nlm_testres {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491)  *		netobj cookie;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492)  *		nlm_testrply test_stat;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493)  *	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) static int decode_nlm_testrply(struct xdr_stream *xdr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) 			       struct nlm_res *result)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) 	int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) 	error = decode_nlm_stat(xdr, &result->status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) 	if (unlikely(error))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) 	if (result->status == nlm_lck_denied)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) 		error = decode_nlm_holder(xdr, result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) 	return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) static int nlm_xdr_dec_testres(struct rpc_rqst *req,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) 			       struct xdr_stream *xdr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) 			       void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) 	struct nlm_res *result = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) 	int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) 	error = decode_cookie(xdr, &result->cookie);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) 	if (unlikely(error))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) 	error = decode_nlm_testrply(xdr, result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) 	return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525)  *	struct nlm_res {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526)  *		netobj cookie;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527)  *		nlm_stat stat;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528)  *	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) static int nlm_xdr_dec_res(struct rpc_rqst *req,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) 			   struct xdr_stream *xdr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) 			   void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) 	struct nlm_res *result = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) 	int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) 	error = decode_cookie(xdr, &result->cookie);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) 	if (unlikely(error))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) 	error = decode_nlm_stat(xdr, &result->status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) 	return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) 
^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)  * For NLM, a void procedure really returns nothing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) #define nlm_xdr_dec_norep	NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) #define PROC(proc, argtype, restype)	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) [NLMPROC_##proc] = {							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) 	.p_proc      = NLMPROC_##proc,					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) 	.p_encode    = nlm_xdr_enc_##argtype,		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) 	.p_decode    = nlm_xdr_dec_##restype,				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) 	.p_arglen    = NLM_##argtype##_sz,				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) 	.p_replen    = NLM_##restype##_sz,				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) 	.p_statidx   = NLMPROC_##proc,					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) 	.p_name      = #proc,						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) static const struct rpc_procinfo nlm_procedures[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) 	PROC(TEST,		testargs,	testres),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) 	PROC(LOCK,		lockargs,	res),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) 	PROC(CANCEL,		cancargs,	res),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) 	PROC(UNLOCK,		unlockargs,	res),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) 	PROC(GRANTED,		testargs,	res),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) 	PROC(TEST_MSG,		testargs,	norep),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) 	PROC(LOCK_MSG,		lockargs,	norep),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) 	PROC(CANCEL_MSG,	cancargs,	norep),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) 	PROC(UNLOCK_MSG,	unlockargs,	norep),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) 	PROC(GRANTED_MSG,	testargs,	norep),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) 	PROC(TEST_RES,		testres,	norep),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) 	PROC(LOCK_RES,		res,		norep),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) 	PROC(CANCEL_RES,	res,		norep),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) 	PROC(UNLOCK_RES,	res,		norep),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) 	PROC(GRANTED_RES,	res,		norep),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) static unsigned int nlm_version1_counts[ARRAY_SIZE(nlm_procedures)];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) static const struct rpc_version	nlm_version1 = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) 	.number		= 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) 	.nrprocs	= ARRAY_SIZE(nlm_procedures),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) 	.procs		= nlm_procedures,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) 	.counts		= nlm_version1_counts,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) static unsigned int nlm_version3_counts[ARRAY_SIZE(nlm_procedures)];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) static const struct rpc_version	nlm_version3 = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) 	.number		= 3,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) 	.nrprocs	= ARRAY_SIZE(nlm_procedures),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) 	.procs		= nlm_procedures,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) 	.counts		= nlm_version3_counts,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) static const struct rpc_version	*nlm_versions[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) 	[1] = &nlm_version1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) 	[3] = &nlm_version3,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) #ifdef CONFIG_LOCKD_V4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) 	[4] = &nlm_version4,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) static struct rpc_stat		nlm_rpc_stats;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) const struct rpc_program	nlm_program = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) 	.name		= "lockd",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) 	.number		= NLM_PROGRAM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) 	.nrvers		= ARRAY_SIZE(nlm_versions),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) 	.version	= nlm_versions,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) 	.stats		= &nlm_rpc_stats,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) };