11 #include <linux/types.h>
17 #define NLMDBG_FACILITY NLMDBG_XDR
19 #if (NLMCLNT_OHSIZE > XDR_MAX_NETOBJ)
20 # error "NLM host name cannot be larger than XDR_MAX_NETOBJ!"
23 #if (NLMCLNT_OHSIZE > NLM_MAXSTRLEN)
24 # error "NLM host name cannot be larger than NLM's maximum string length!"
31 #define NLM4_void_sz (0)
32 #define NLM4_cookie_sz (1+(NLM_MAXCOOKIELEN>>2))
33 #define NLM4_caller_sz (1+(NLMCLNT_OHSIZE>>2))
34 #define NLM4_owner_sz (1+(NLMCLNT_OHSIZE>>2))
35 #define NLM4_fhandle_sz (1+(NFS3_FHSIZE>>2))
36 #define NLM4_lock_sz (5+NLM4_caller_sz+NLM4_owner_sz+NLM4_fhandle_sz)
37 #define NLM4_holder_sz (6+NLM4_owner_sz)
39 #define NLM4_testargs_sz (NLM4_cookie_sz+1+NLM4_lock_sz)
40 #define NLM4_lockargs_sz (NLM4_cookie_sz+4+NLM4_lock_sz)
41 #define NLM4_cancargs_sz (NLM4_cookie_sz+2+NLM4_lock_sz)
42 #define NLM4_unlockargs_sz (NLM4_cookie_sz+NLM4_lock_sz)
44 #define NLM4_testres_sz (NLM4_cookie_sz+1+NLM4_holder_sz)
45 #define NLM4_res_sz (NLM4_cookie_sz+1)
46 #define NLM4_norep_sz (0)
62 static void nlm4_compute_offsets(
const struct nlm_lock *lock,
71 *l_offset = loff_t_to_s64(fl->
fl_start);
81 static void print_overflow_msg(
const char *
func,
const struct xdr_stream *xdr)
83 dprintk(
"lockd: %s prematurely hit the end of our receive buffer. "
84 "Remaining buffer length is %tu words.\n",
85 func, xdr->end - xdr->p);
101 static void encode_bool(
struct xdr_stream *xdr,
const int value)
106 *p = value ? xdr_one : xdr_zero;
109 static void encode_int32(
struct xdr_stream *xdr,
const s32 value)
120 static void encode_netobj(
struct xdr_stream *xdr,
125 BUG_ON(length > XDR_MAX_NETOBJ);
130 static int decode_netobj(
struct xdr_stream *xdr,
131 struct xdr_netobj *obj)
140 if (
unlikely(length > XDR_MAX_NETOBJ))
146 dprintk(
"NFS: returned netobj was too long: %u\n", length);
149 print_overflow_msg(__func__, xdr);
156 static void encode_cookie(
struct xdr_stream *xdr,
160 encode_netobj(xdr, (
u8 *)&cookie->
data, cookie->
len);
163 static int decode_cookie(
struct xdr_stream *xdr,
189 dprintk(
"NFS: returned cookie was too long: %u\n", length);
192 print_overflow_msg(__func__, xdr);
199 static void encode_fh(
struct xdr_stream *xdr,
const struct nfs_fh *fh)
202 encode_netobj(xdr, (
u8 *)&fh->
data, fh->
size);
227 static void encode_nlm4_stat(
struct xdr_stream *xdr,
237 static int decode_nlm4_stat(
struct xdr_stream *xdr,
__be32 *stat)
249 dprintk(
"%s: server returned invalid nlm4_stats value: %u\n",
253 print_overflow_msg(__func__, xdr);
266 static void encode_nlm4_holder(
struct xdr_stream *xdr,
273 encode_bool(xdr, lock->
fl.fl_type ==
F_RDLCK);
274 encode_int32(xdr, lock->
svid);
275 encode_netobj(xdr, lock->
oh.data, lock->
oh.len);
278 nlm4_compute_offsets(lock, &l_offset, &l_len);
279 p = xdr_encode_hyper(p, l_offset);
280 xdr_encode_hyper(p, l_len);
283 static int decode_nlm4_holder(
struct xdr_stream *xdr,
struct nlm_res *
result)
293 memset(lock, 0,
sizeof(*lock));
303 error = decode_netobj(xdr, &lock->
oh);
313 p = xdr_decode_hyper(p, &l_offset);
314 xdr_decode_hyper(p, &l_len);
315 end = l_offset + l_len - 1;
318 if (l_len == 0 || end < 0)
326 print_overflow_msg(__func__, xdr);
333 static void encode_caller_name(
struct xdr_stream *xdr,
const char *
name)
354 static void encode_nlm4_lock(
struct xdr_stream *xdr,
360 encode_caller_name(xdr, lock->
caller);
361 encode_fh(xdr, &lock->
fh);
362 encode_netobj(xdr, lock->
oh.data, lock->
oh.len);
367 nlm4_compute_offsets(lock, &l_offset, &l_len);
368 p = xdr_encode_hyper(p, l_offset);
369 xdr_encode_hyper(p, l_len);
388 static void nlm4_xdr_enc_testargs(
struct rpc_rqst *
req,
389 struct xdr_stream *xdr,
394 encode_cookie(xdr, &args->
cookie);
395 encode_bool(xdr, lock->
fl.fl_type ==
F_WRLCK);
396 encode_nlm4_lock(xdr, lock);
409 static void nlm4_xdr_enc_lockargs(
struct rpc_rqst *
req,
410 struct xdr_stream *xdr,
415 encode_cookie(xdr, &args->
cookie);
416 encode_bool(xdr, args->
block);
417 encode_bool(xdr, lock->
fl.fl_type ==
F_WRLCK);
418 encode_nlm4_lock(xdr, lock);
419 encode_bool(xdr, args->
reclaim);
420 encode_int32(xdr, args->
state);
431 static void nlm4_xdr_enc_cancargs(
struct rpc_rqst *
req,
432 struct xdr_stream *xdr,
437 encode_cookie(xdr, &args->
cookie);
438 encode_bool(xdr, args->
block);
439 encode_bool(xdr, lock->
fl.fl_type ==
F_WRLCK);
440 encode_nlm4_lock(xdr, lock);
449 static void nlm4_xdr_enc_unlockargs(
struct rpc_rqst *
req,
450 struct xdr_stream *xdr,
455 encode_cookie(xdr, &args->
cookie);
456 encode_nlm4_lock(xdr, lock);
465 static void nlm4_xdr_enc_res(
struct rpc_rqst *
req,
466 struct xdr_stream *xdr,
469 encode_cookie(xdr, &result->
cookie);
470 encode_nlm4_stat(xdr, result->
status);
486 static void nlm4_xdr_enc_testres(
struct rpc_rqst *
req,
487 struct xdr_stream *xdr,
490 encode_cookie(xdr, &result->
cookie);
491 encode_nlm4_stat(xdr, result->
status);
493 encode_nlm4_holder(xdr, result);
518 static int decode_nlm4_testrply(
struct xdr_stream *xdr,
523 error = decode_nlm4_stat(xdr, &result->
status);
527 error = decode_nlm4_holder(xdr, result);
532 static int nlm4_xdr_dec_testres(
struct rpc_rqst *req,
533 struct xdr_stream *xdr,
538 error = decode_cookie(xdr, &result->
cookie);
541 error = decode_nlm4_testrply(xdr, result);
552 static int nlm4_xdr_dec_res(
struct rpc_rqst *req,
553 struct xdr_stream *xdr,
558 error = decode_cookie(xdr, &result->
cookie);
561 error = decode_nlm4_stat(xdr, &result->
status);
570 #define nlm4_xdr_dec_norep NULL
572 #define PROC(proc, argtype, restype) \
573 [NLMPROC_##proc] = { \
574 .p_proc = NLMPROC_##proc, \
575 .p_encode = (kxdreproc_t)nlm4_xdr_enc_##argtype, \
576 .p_decode = (kxdrdproc_t)nlm4_xdr_dec_##restype, \
577 .p_arglen = NLM4_##argtype##_sz, \
578 .p_replen = NLM4_##restype##_sz, \
579 .p_statidx = NLMPROC_##proc, \
589 PROC(TEST_MSG, testargs, norep),
590 PROC(LOCK_MSG, lockargs, norep),
591 PROC(CANCEL_MSG, cancargs, norep),
592 PROC(UNLOCK_MSG, unlockargs, norep),
593 PROC(GRANTED_MSG, testargs, norep),
594 PROC(TEST_RES, testres, norep),
604 .procs = nlm4_procedures,