Blame view

fs/lockd/clnt4xdr.c 12.9 KB
b24413180   Greg Kroah-Hartman   License cleanup: ...
1
  // SPDX-License-Identifier: GPL-2.0
3460f29a2   Chuck Lever   lockd: Introduce ...
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
  /*
   * linux/fs/lockd/clnt4xdr.c
   *
   * XDR functions to encode/decode NLM version 4 RPC arguments and results.
   *
   * NLM client-side only.
   *
   * Copyright (C) 2010, Oracle.  All rights reserved.
   */
  
  #include <linux/types.h>
  #include <linux/sunrpc/xdr.h>
  #include <linux/sunrpc/clnt.h>
  #include <linux/sunrpc/stats.h>
  #include <linux/lockd/lockd.h>
9c69de4c9   Christoph Hellwig   nfsd: remove <lin...
17
  #include <uapi/linux/nfs3.h>
3460f29a2   Chuck Lever   lockd: Introduce ...
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
  #define NLMDBG_FACILITY		NLMDBG_XDR
  
  #if (NLMCLNT_OHSIZE > XDR_MAX_NETOBJ)
  #  error "NLM host name cannot be larger than XDR_MAX_NETOBJ!"
  #endif
  
  #if (NLMCLNT_OHSIZE > NLM_MAXSTRLEN)
  #  error "NLM host name cannot be larger than NLM's maximum string length!"
  #endif
  
  /*
   * Declare the space requirements for NLM arguments and replies as
   * number of 32bit-words
   */
  #define NLM4_void_sz		(0)
  #define NLM4_cookie_sz		(1+(NLM_MAXCOOKIELEN>>2))
  #define NLM4_caller_sz		(1+(NLMCLNT_OHSIZE>>2))
  #define NLM4_owner_sz		(1+(NLMCLNT_OHSIZE>>2))
  #define NLM4_fhandle_sz		(1+(NFS3_FHSIZE>>2))
  #define NLM4_lock_sz		(5+NLM4_caller_sz+NLM4_owner_sz+NLM4_fhandle_sz)
  #define NLM4_holder_sz		(6+NLM4_owner_sz)
  
  #define NLM4_testargs_sz	(NLM4_cookie_sz+1+NLM4_lock_sz)
  #define NLM4_lockargs_sz	(NLM4_cookie_sz+4+NLM4_lock_sz)
  #define NLM4_cancargs_sz	(NLM4_cookie_sz+2+NLM4_lock_sz)
  #define NLM4_unlockargs_sz	(NLM4_cookie_sz+NLM4_lock_sz)
  
  #define NLM4_testres_sz		(NLM4_cookie_sz+1+NLM4_holder_sz)
  #define NLM4_res_sz		(NLM4_cookie_sz+1)
  #define NLM4_norep_sz		(0)
  
  
  static s64 loff_t_to_s64(loff_t offset)
  {
  	s64 res;
  
  	if (offset >= NLM4_OFFSET_MAX)
  		res = NLM4_OFFSET_MAX;
  	else if (offset <= -NLM4_OFFSET_MAX)
  		res = -NLM4_OFFSET_MAX;
  	else
  		res = offset;
  	return res;
  }
  
  static void nlm4_compute_offsets(const struct nlm_lock *lock,
  				 u64 *l_offset, u64 *l_len)
  {
  	const struct file_lock *fl = &lock->fl;
3460f29a2   Chuck Lever   lockd: Introduce ...
67
68
69
70
71
72
73
74
  	*l_offset = loff_t_to_s64(fl->fl_start);
  	if (fl->fl_end == OFFSET_MAX)
  		*l_len = 0;
  	else
  		*l_len = loff_t_to_s64(fl->fl_end - fl->fl_start + 1);
  }
  
  /*
3460f29a2   Chuck Lever   lockd: Introduce ...
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
   * Encode/decode NLMv4 basic data types
   *
   * Basic NLMv4 data types are defined in Appendix II, section 6.1.4
   * of RFC 1813: "NFS Version 3 Protocol Specification" and in Chapter
   * 10 of X/Open's "Protocols for Interworking: XNFS, Version 3W".
   *
   * Not all basic data types have their own encoding and decoding
   * functions.  For run-time efficiency, some data types are encoded
   * or decoded inline.
   */
  
  static void encode_bool(struct xdr_stream *xdr, const int value)
  {
  	__be32 *p;
  
  	p = xdr_reserve_space(xdr, 4);
  	*p = value ? xdr_one : xdr_zero;
  }
  
  static void encode_int32(struct xdr_stream *xdr, const s32 value)
  {
  	__be32 *p;
  
  	p = xdr_reserve_space(xdr, 4);
  	*p = cpu_to_be32(value);
  }
  
  /*
   *	typedef opaque netobj<MAXNETOBJ_SZ>
   */
  static void encode_netobj(struct xdr_stream *xdr,
  			  const u8 *data, const unsigned int length)
  {
  	__be32 *p;
3460f29a2   Chuck Lever   lockd: Introduce ...
109
110
111
112
113
114
115
  	p = xdr_reserve_space(xdr, 4 + length);
  	xdr_encode_opaque(p, data, length);
  }
  
  static int decode_netobj(struct xdr_stream *xdr,
  			 struct xdr_netobj *obj)
  {
b8db15923   J. Bruce Fields   lockd: fix decodi...
116
  	ssize_t ret;
3460f29a2   Chuck Lever   lockd: Introduce ...
117

b8db15923   J. Bruce Fields   lockd: fix decodi...
118
119
120
121
122
  	ret = xdr_stream_decode_opaque_inline(xdr, (void *)&obj->data,
  						XDR_MAX_NETOBJ);
  	if (unlikely(ret < 0))
  		return -EIO;
  	obj->len = ret;
3460f29a2   Chuck Lever   lockd: Introduce ...
123
  	return 0;
3460f29a2   Chuck Lever   lockd: Introduce ...
124
125
126
127
128
129
130
131
  }
  
  /*
   *	netobj cookie;
   */
  static void encode_cookie(struct xdr_stream *xdr,
  			  const struct nlm_cookie *cookie)
  {
3460f29a2   Chuck Lever   lockd: Introduce ...
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
  	encode_netobj(xdr, (u8 *)&cookie->data, cookie->len);
  }
  
  static int decode_cookie(struct xdr_stream *xdr,
  			     struct nlm_cookie *cookie)
  {
  	u32 length;
  	__be32 *p;
  
  	p = xdr_inline_decode(xdr, 4);
  	if (unlikely(p == NULL))
  		goto out_overflow;
  	length = be32_to_cpup(p++);
  	/* apparently HPUX can return empty cookies */
  	if (length == 0)
  		goto out_hpux;
  	if (length > NLM_MAXCOOKIELEN)
  		goto out_size;
  	p = xdr_inline_decode(xdr, length);
  	if (unlikely(p == NULL))
  		goto out_overflow;
  	cookie->len = length;
  	memcpy(cookie->data, p, length);
  	return 0;
  out_hpux:
  	cookie->len = 4;
  	memset(cookie->data, 0, 4);
  	return 0;
  out_size:
  	dprintk("NFS: returned cookie was too long: %u
  ", length);
  	return -EIO;
  out_overflow:
3460f29a2   Chuck Lever   lockd: Introduce ...
165
166
167
168
169
170
171
172
  	return -EIO;
  }
  
  /*
   *	netobj fh;
   */
  static void encode_fh(struct xdr_stream *xdr, const struct nfs_fh *fh)
  {
3460f29a2   Chuck Lever   lockd: Introduce ...
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
  	encode_netobj(xdr, (u8 *)&fh->data, fh->size);
  }
  
  /*
   *	enum nlm4_stats {
   *		NLM4_GRANTED = 0,
   *		NLM4_DENIED = 1,
   *		NLM4_DENIED_NOLOCKS = 2,
   *		NLM4_BLOCKED = 3,
   *		NLM4_DENIED_GRACE_PERIOD = 4,
   *		NLM4_DEADLCK = 5,
   *		NLM4_ROFS = 6,
   *		NLM4_STALE_FH = 7,
   *		NLM4_FBIG = 8,
   *		NLM4_FAILED = 9
   *	};
   *
   *	struct nlm4_stat {
   *		nlm4_stats stat;
   *	};
   *
   * NB: we don't swap bytes for the NLM status values.  The upper
   * layers deal directly with the status value in network byte
   * order.
   */
  static void encode_nlm4_stat(struct xdr_stream *xdr,
  			     const __be32 stat)
  {
  	__be32 *p;
  
  	BUG_ON(be32_to_cpu(stat) > NLM_FAILED);
  	p = xdr_reserve_space(xdr, 4);
  	*p = stat;
  }
  
  static int decode_nlm4_stat(struct xdr_stream *xdr, __be32 *stat)
  {
  	__be32 *p;
  
  	p = xdr_inline_decode(xdr, 4);
  	if (unlikely(p == NULL))
  		goto out_overflow;
e847469bf   Al Viro   lockd: fix the en...
215
  	if (unlikely(ntohl(*p) > ntohl(nlm4_failed)))
3460f29a2   Chuck Lever   lockd: Introduce ...
216
217
218
219
220
221
222
223
224
  		goto out_bad_xdr;
  	*stat = *p;
  	return 0;
  out_bad_xdr:
  	dprintk("%s: server returned invalid nlm4_stats value: %u
  ",
  			__func__, be32_to_cpup(p));
  	return -EIO;
  out_overflow:
3460f29a2   Chuck Lever   lockd: Introduce ...
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
  	return -EIO;
  }
  
  /*
   *	struct nlm4_holder {
   *		bool	exclusive;
   *		int32	svid;
   *		netobj	oh;
   *		uint64	l_offset;
   *		uint64	l_len;
   *	};
   */
  static void encode_nlm4_holder(struct xdr_stream *xdr,
  			       const struct nlm_res *result)
  {
  	const struct nlm_lock *lock = &result->lock;
  	u64 l_offset, l_len;
  	__be32 *p;
  
  	encode_bool(xdr, lock->fl.fl_type == F_RDLCK);
  	encode_int32(xdr, lock->svid);
  	encode_netobj(xdr, lock->oh.data, lock->oh.len);
  
  	p = xdr_reserve_space(xdr, 4 + 4);
  	nlm4_compute_offsets(lock, &l_offset, &l_len);
  	p = xdr_encode_hyper(p, l_offset);
  	xdr_encode_hyper(p, l_len);
  }
  
  static int decode_nlm4_holder(struct xdr_stream *xdr, struct nlm_res *result)
  {
  	struct nlm_lock *lock = &result->lock;
  	struct file_lock *fl = &lock->fl;
  	u64 l_offset, l_len;
  	u32 exclusive;
  	int error;
  	__be32 *p;
  	s32 end;
  
  	memset(lock, 0, sizeof(*lock));
  	locks_init_lock(fl);
  
  	p = xdr_inline_decode(xdr, 4 + 4);
  	if (unlikely(p == NULL))
  		goto out_overflow;
  	exclusive = be32_to_cpup(p++);
  	lock->svid = be32_to_cpup(p);
  	fl->fl_pid = (pid_t)lock->svid;
  
  	error = decode_netobj(xdr, &lock->oh);
  	if (unlikely(error))
  		goto out;
  
  	p = xdr_inline_decode(xdr, 8 + 8);
  	if (unlikely(p == NULL))
  		goto out_overflow;
  
  	fl->fl_flags = FL_POSIX;
  	fl->fl_type  = exclusive != 0 ? F_WRLCK : F_RDLCK;
  	p = xdr_decode_hyper(p, &l_offset);
  	xdr_decode_hyper(p, &l_len);
  	end = l_offset + l_len - 1;
  
  	fl->fl_start = (loff_t)l_offset;
  	if (l_len == 0 || end < 0)
  		fl->fl_end = OFFSET_MAX;
  	else
  		fl->fl_end = (loff_t)end;
  	error = 0;
  out:
  	return error;
  out_overflow:
3460f29a2   Chuck Lever   lockd: Introduce ...
297
298
299
300
301
302
303
304
305
306
307
  	return -EIO;
  }
  
  /*
   *	string caller_name<LM_MAXSTRLEN>;
   */
  static void encode_caller_name(struct xdr_stream *xdr, const char *name)
  {
  	/* NB: client-side does not set lock->len */
  	u32 length = strlen(name);
  	__be32 *p;
3460f29a2   Chuck Lever   lockd: Introduce ...
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
  	p = xdr_reserve_space(xdr, 4 + length);
  	xdr_encode_opaque(p, name, length);
  }
  
  /*
   *	struct nlm4_lock {
   *		string	caller_name<LM_MAXSTRLEN>;
   *		netobj	fh;
   *		netobj	oh;
   *		int32	svid;
   *		uint64	l_offset;
   *		uint64	l_len;
   *	};
   */
  static void encode_nlm4_lock(struct xdr_stream *xdr,
  			     const struct nlm_lock *lock)
  {
  	u64 l_offset, l_len;
  	__be32 *p;
  
  	encode_caller_name(xdr, lock->caller);
  	encode_fh(xdr, &lock->fh);
  	encode_netobj(xdr, lock->oh.data, lock->oh.len);
  
  	p = xdr_reserve_space(xdr, 4 + 8 + 8);
  	*p++ = cpu_to_be32(lock->svid);
  
  	nlm4_compute_offsets(lock, &l_offset, &l_len);
  	p = xdr_encode_hyper(p, l_offset);
  	xdr_encode_hyper(p, l_len);
  }
  
  
  /*
   * NLMv4 XDR encode functions
   *
   * NLMv4 argument types are defined in Appendix II of RFC 1813:
   * "NFS Version 3 Protocol Specification" and Chapter 10 of X/Open's
   * "Protocols for Interworking: XNFS, Version 3W".
   */
  
  /*
   *	struct nlm4_testargs {
   *		netobj cookie;
   *		bool exclusive;
   *		struct nlm4_lock alock;
   *	};
   */
9f06c719f   Chuck Lever   SUNRPC: New xdr_s...
356
357
  static void nlm4_xdr_enc_testargs(struct rpc_rqst *req,
  				  struct xdr_stream *xdr,
bf96391e7   Christoph Hellwig   lockd: fix encode...
358
  				  const void *data)
3460f29a2   Chuck Lever   lockd: Introduce ...
359
  {
bf96391e7   Christoph Hellwig   lockd: fix encode...
360
  	const struct nlm_args *args = data;
3460f29a2   Chuck Lever   lockd: Introduce ...
361
  	const struct nlm_lock *lock = &args->lock;
3460f29a2   Chuck Lever   lockd: Introduce ...
362

9f06c719f   Chuck Lever   SUNRPC: New xdr_s...
363
364
365
  	encode_cookie(xdr, &args->cookie);
  	encode_bool(xdr, lock->fl.fl_type == F_WRLCK);
  	encode_nlm4_lock(xdr, lock);
3460f29a2   Chuck Lever   lockd: Introduce ...
366
367
368
369
370
371
372
373
374
375
376
377
  }
  
  /*
   *	struct nlm4_lockargs {
   *		netobj cookie;
   *		bool block;
   *		bool exclusive;
   *		struct nlm4_lock alock;
   *		bool reclaim;
   *		int state;
   *	};
   */
9f06c719f   Chuck Lever   SUNRPC: New xdr_s...
378
379
  static void nlm4_xdr_enc_lockargs(struct rpc_rqst *req,
  				  struct xdr_stream *xdr,
bf96391e7   Christoph Hellwig   lockd: fix encode...
380
  				  const void *data)
3460f29a2   Chuck Lever   lockd: Introduce ...
381
  {
bf96391e7   Christoph Hellwig   lockd: fix encode...
382
  	const struct nlm_args *args = data;
3460f29a2   Chuck Lever   lockd: Introduce ...
383
  	const struct nlm_lock *lock = &args->lock;
3460f29a2   Chuck Lever   lockd: Introduce ...
384

9f06c719f   Chuck Lever   SUNRPC: New xdr_s...
385
386
387
388
389
390
  	encode_cookie(xdr, &args->cookie);
  	encode_bool(xdr, args->block);
  	encode_bool(xdr, lock->fl.fl_type == F_WRLCK);
  	encode_nlm4_lock(xdr, lock);
  	encode_bool(xdr, args->reclaim);
  	encode_int32(xdr, args->state);
3460f29a2   Chuck Lever   lockd: Introduce ...
391
392
393
394
395
396
397
398
399
400
  }
  
  /*
   *	struct nlm4_cancargs {
   *		netobj cookie;
   *		bool block;
   *		bool exclusive;
   *		struct nlm4_lock alock;
   *	};
   */
9f06c719f   Chuck Lever   SUNRPC: New xdr_s...
401
402
  static void nlm4_xdr_enc_cancargs(struct rpc_rqst *req,
  				  struct xdr_stream *xdr,
bf96391e7   Christoph Hellwig   lockd: fix encode...
403
  				  const void *data)
3460f29a2   Chuck Lever   lockd: Introduce ...
404
  {
bf96391e7   Christoph Hellwig   lockd: fix encode...
405
  	const struct nlm_args *args = data;
3460f29a2   Chuck Lever   lockd: Introduce ...
406
  	const struct nlm_lock *lock = &args->lock;
3460f29a2   Chuck Lever   lockd: Introduce ...
407

9f06c719f   Chuck Lever   SUNRPC: New xdr_s...
408
409
410
411
  	encode_cookie(xdr, &args->cookie);
  	encode_bool(xdr, args->block);
  	encode_bool(xdr, lock->fl.fl_type == F_WRLCK);
  	encode_nlm4_lock(xdr, lock);
3460f29a2   Chuck Lever   lockd: Introduce ...
412
413
414
415
416
417
418
419
  }
  
  /*
   *	struct nlm4_unlockargs {
   *		netobj cookie;
   *		struct nlm4_lock alock;
   *	};
   */
9f06c719f   Chuck Lever   SUNRPC: New xdr_s...
420
421
  static void nlm4_xdr_enc_unlockargs(struct rpc_rqst *req,
  				    struct xdr_stream *xdr,
bf96391e7   Christoph Hellwig   lockd: fix encode...
422
  				    const void *data)
3460f29a2   Chuck Lever   lockd: Introduce ...
423
  {
bf96391e7   Christoph Hellwig   lockd: fix encode...
424
  	const struct nlm_args *args = data;
3460f29a2   Chuck Lever   lockd: Introduce ...
425
  	const struct nlm_lock *lock = &args->lock;
3460f29a2   Chuck Lever   lockd: Introduce ...
426

9f06c719f   Chuck Lever   SUNRPC: New xdr_s...
427
428
  	encode_cookie(xdr, &args->cookie);
  	encode_nlm4_lock(xdr, lock);
3460f29a2   Chuck Lever   lockd: Introduce ...
429
430
431
432
433
434
435
436
  }
  
  /*
   *	struct nlm4_res {
   *		netobj cookie;
   *		nlm4_stat stat;
   *	};
   */
9f06c719f   Chuck Lever   SUNRPC: New xdr_s...
437
438
  static void nlm4_xdr_enc_res(struct rpc_rqst *req,
  			     struct xdr_stream *xdr,
bf96391e7   Christoph Hellwig   lockd: fix encode...
439
  			     const void *data)
3460f29a2   Chuck Lever   lockd: Introduce ...
440
  {
bf96391e7   Christoph Hellwig   lockd: fix encode...
441
  	const struct nlm_res *result = data;
9f06c719f   Chuck Lever   SUNRPC: New xdr_s...
442
443
  	encode_cookie(xdr, &result->cookie);
  	encode_nlm4_stat(xdr, result->status);
3460f29a2   Chuck Lever   lockd: Introduce ...
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
  }
  
  /*
   *	union nlm4_testrply switch (nlm4_stats stat) {
   *	case NLM4_DENIED:
   *		struct nlm4_holder holder;
   *	default:
   *		void;
   *	};
   *
   *	struct nlm4_testres {
   *		netobj cookie;
   *		nlm4_testrply test_stat;
   *	};
   */
9f06c719f   Chuck Lever   SUNRPC: New xdr_s...
459
460
  static void nlm4_xdr_enc_testres(struct rpc_rqst *req,
  				 struct xdr_stream *xdr,
bf96391e7   Christoph Hellwig   lockd: fix encode...
461
  				 const void *data)
3460f29a2   Chuck Lever   lockd: Introduce ...
462
  {
bf96391e7   Christoph Hellwig   lockd: fix encode...
463
  	const struct nlm_res *result = data;
9f06c719f   Chuck Lever   SUNRPC: New xdr_s...
464
465
  	encode_cookie(xdr, &result->cookie);
  	encode_nlm4_stat(xdr, result->status);
3460f29a2   Chuck Lever   lockd: Introduce ...
466
  	if (result->status == nlm_lck_denied)
9f06c719f   Chuck Lever   SUNRPC: New xdr_s...
467
  		encode_nlm4_holder(xdr, result);
3460f29a2   Chuck Lever   lockd: Introduce ...
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
  }
  
  
  /*
   * NLMv4 XDR decode functions
   *
   * NLMv4 argument types are defined in Appendix II of RFC 1813:
   * "NFS Version 3 Protocol Specification" and Chapter 10 of X/Open's
   * "Protocols for Interworking: XNFS, Version 3W".
   */
  
  /*
   *	union nlm4_testrply switch (nlm4_stats stat) {
   *	case NLM4_DENIED:
   *		struct nlm4_holder holder;
   *	default:
   *		void;
   *	};
   *
   *	struct nlm4_testres {
   *		netobj cookie;
   *		nlm4_testrply test_stat;
   *	};
   */
  static int decode_nlm4_testrply(struct xdr_stream *xdr,
  				struct nlm_res *result)
  {
  	int error;
  
  	error = decode_nlm4_stat(xdr, &result->status);
  	if (unlikely(error))
  		goto out;
  	if (result->status == nlm_lck_denied)
  		error = decode_nlm4_holder(xdr, result);
  out:
  	return error;
  }
bf2695516   Chuck Lever   SUNRPC: New xdr_s...
505
506
  static int nlm4_xdr_dec_testres(struct rpc_rqst *req,
  				struct xdr_stream *xdr,
1fa233912   Christoph Hellwig   lockd: fix decode...
507
  				void *data)
3460f29a2   Chuck Lever   lockd: Introduce ...
508
  {
1fa233912   Christoph Hellwig   lockd: fix decode...
509
  	struct nlm_res *result = data;
3460f29a2   Chuck Lever   lockd: Introduce ...
510
  	int error;
bf2695516   Chuck Lever   SUNRPC: New xdr_s...
511
  	error = decode_cookie(xdr, &result->cookie);
3460f29a2   Chuck Lever   lockd: Introduce ...
512
513
  	if (unlikely(error))
  		goto out;
bf2695516   Chuck Lever   SUNRPC: New xdr_s...
514
  	error = decode_nlm4_testrply(xdr, result);
3460f29a2   Chuck Lever   lockd: Introduce ...
515
516
517
518
519
520
521
522
523
524
  out:
  	return error;
  }
  
  /*
   *	struct nlm4_res {
   *		netobj cookie;
   *		nlm4_stat stat;
   *	};
   */
bf2695516   Chuck Lever   SUNRPC: New xdr_s...
525
526
  static int nlm4_xdr_dec_res(struct rpc_rqst *req,
  			    struct xdr_stream *xdr,
1fa233912   Christoph Hellwig   lockd: fix decode...
527
  			    void *data)
3460f29a2   Chuck Lever   lockd: Introduce ...
528
  {
1fa233912   Christoph Hellwig   lockd: fix decode...
529
  	struct nlm_res *result = data;
3460f29a2   Chuck Lever   lockd: Introduce ...
530
  	int error;
bf2695516   Chuck Lever   SUNRPC: New xdr_s...
531
  	error = decode_cookie(xdr, &result->cookie);
3460f29a2   Chuck Lever   lockd: Introduce ...
532
533
  	if (unlikely(error))
  		goto out;
bf2695516   Chuck Lever   SUNRPC: New xdr_s...
534
  	error = decode_nlm4_stat(xdr, &result->status);
3460f29a2   Chuck Lever   lockd: Introduce ...
535
536
537
538
539
540
541
542
543
544
545
546
547
  out:
  	return error;
  }
  
  
  /*
   * For NLM, a void procedure really returns nothing
   */
  #define nlm4_xdr_dec_norep	NULL
  
  #define PROC(proc, argtype, restype)					\
  [NLMPROC_##proc] = {							\
  	.p_proc      = NLMPROC_##proc,					\
bf96391e7   Christoph Hellwig   lockd: fix encode...
548
  	.p_encode    = nlm4_xdr_enc_##argtype,				\
1fa233912   Christoph Hellwig   lockd: fix decode...
549
  	.p_decode    = nlm4_xdr_dec_##restype,				\
3460f29a2   Chuck Lever   lockd: Introduce ...
550
551
552
553
554
  	.p_arglen    = NLM4_##argtype##_sz,				\
  	.p_replen    = NLM4_##restype##_sz,				\
  	.p_statidx   = NLMPROC_##proc,					\
  	.p_name      = #proc,						\
  	}
499b49881   Christoph Hellwig   sunrpc: mark all ...
555
  static const struct rpc_procinfo nlm4_procedures[] = {
3460f29a2   Chuck Lever   lockd: Introduce ...
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
  	PROC(TEST,		testargs,	testres),
  	PROC(LOCK,		lockargs,	res),
  	PROC(CANCEL,		cancargs,	res),
  	PROC(UNLOCK,		unlockargs,	res),
  	PROC(GRANTED,		testargs,	res),
  	PROC(TEST_MSG,		testargs,	norep),
  	PROC(LOCK_MSG,		lockargs,	norep),
  	PROC(CANCEL_MSG,	cancargs,	norep),
  	PROC(UNLOCK_MSG,	unlockargs,	norep),
  	PROC(GRANTED_MSG,	testargs,	norep),
  	PROC(TEST_RES,		testres,	norep),
  	PROC(LOCK_RES,		res,		norep),
  	PROC(CANCEL_RES,	res,		norep),
  	PROC(UNLOCK_RES,	res,		norep),
  	PROC(GRANTED_RES,	res,		norep),
  };
1c5876ddb   Christoph Hellwig   sunrpc: move p_co...
572
  static unsigned int nlm_version4_counts[ARRAY_SIZE(nlm4_procedures)];
a613fa168   Trond Myklebust   SUNRPC: constify ...
573
  const struct rpc_version nlm_version4 = {
3460f29a2   Chuck Lever   lockd: Introduce ...
574
575
576
  	.number		= 4,
  	.nrprocs	= ARRAY_SIZE(nlm4_procedures),
  	.procs		= nlm4_procedures,
1c5876ddb   Christoph Hellwig   sunrpc: move p_co...
577
  	.counts		= nlm_version4_counts,
3460f29a2   Chuck Lever   lockd: Introduce ...
578
  };