12 #include <linux/types.h>
18 #define NLMDBG_FACILITY NLMDBG_XDR
20 #if (NLMCLNT_OHSIZE > XDR_MAX_NETOBJ)
21 # error "NLM host name cannot be larger than XDR_MAX_NETOBJ!"
28 #define NLM_cookie_sz (1+(NLM_MAXCOOKIELEN>>2))
29 #define NLM_caller_sz (1+(NLMCLNT_OHSIZE>>2))
30 #define NLM_owner_sz (1+(NLMCLNT_OHSIZE>>2))
31 #define NLM_fhandle_sz (1+(NFS2_FHSIZE>>2))
32 #define NLM_lock_sz (3+NLM_caller_sz+NLM_owner_sz+NLM_fhandle_sz)
33 #define NLM_holder_sz (4+NLM_owner_sz)
35 #define NLM_testargs_sz (NLM_cookie_sz+1+NLM_lock_sz)
36 #define NLM_lockargs_sz (NLM_cookie_sz+4+NLM_lock_sz)
37 #define NLM_cancargs_sz (NLM_cookie_sz+2+NLM_lock_sz)
38 #define NLM_unlockargs_sz (NLM_cookie_sz+NLM_lock_sz)
40 #define NLM_testres_sz (NLM_cookie_sz+1+NLM_holder_sz)
41 #define NLM_res_sz (NLM_cookie_sz+1)
42 #define NLM_norep_sz (0)
58 static void nlm_compute_offsets(
const struct nlm_lock *lock,
67 *l_offset = loff_t_to_s32(fl->
fl_start);
77 static void print_overflow_msg(
const char *
func,
const struct xdr_stream *xdr)
79 dprintk(
"lockd: %s prematurely hit the end of our receive buffer. "
80 "Remaining buffer length is %tu words.\n",
81 func, xdr->end - xdr->p);
98 static void encode_bool(
struct xdr_stream *xdr,
const int value)
103 *p = value ? xdr_one : xdr_zero;
106 static void encode_int32(
struct xdr_stream *xdr,
const s32 value)
117 static void encode_netobj(
struct xdr_stream *xdr,
122 BUG_ON(length > XDR_MAX_NETOBJ);
127 static int decode_netobj(
struct xdr_stream *xdr,
128 struct xdr_netobj *obj)
137 if (
unlikely(length > XDR_MAX_NETOBJ))
143 dprintk(
"NFS: returned netobj was too long: %u\n", length);
146 print_overflow_msg(__func__, xdr);
153 static void encode_cookie(
struct xdr_stream *xdr,
157 encode_netobj(xdr, (
u8 *)&cookie->
data, cookie->
len);
160 static int decode_cookie(
struct xdr_stream *xdr,
186 dprintk(
"NFS: returned cookie was too long: %u\n", length);
189 print_overflow_msg(__func__, xdr);
196 static void encode_fh(
struct xdr_stream *xdr,
const struct nfs_fh *fh)
221 static void encode_nlm_stat(
struct xdr_stream *xdr,
231 static int decode_nlm_stat(
struct xdr_stream *xdr,
244 dprintk(
"%s: server returned invalid nlm_stats value: %u\n",
248 print_overflow_msg(__func__, xdr);
261 static void encode_nlm_holder(
struct xdr_stream *xdr,
268 encode_bool(xdr, lock->
fl.fl_type ==
F_RDLCK);
269 encode_int32(xdr, lock->
svid);
270 encode_netobj(xdr, lock->
oh.data, lock->
oh.len);
273 nlm_compute_offsets(lock, &l_offset, &l_len);
278 static int decode_nlm_holder(
struct xdr_stream *xdr,
struct nlm_res *
result)
287 memset(lock, 0,
sizeof(*lock));
297 error = decode_netobj(xdr, &lock->
oh);
309 end = l_offset + l_len - 1;
312 if (l_len == 0 || end < 0)
320 print_overflow_msg(__func__, xdr);
327 static void encode_caller_name(
struct xdr_stream *xdr,
const char *
name)
348 static void encode_nlm_lock(
struct xdr_stream *xdr,
354 encode_caller_name(xdr, lock->
caller);
355 encode_fh(xdr, &lock->
fh);
356 encode_netobj(xdr, lock->
oh.data, lock->
oh.len);
361 nlm_compute_offsets(lock, &l_offset, &l_len);
381 static void nlm_xdr_enc_testargs(
struct rpc_rqst *
req,
382 struct xdr_stream *xdr,
387 encode_cookie(xdr, &args->
cookie);
388 encode_bool(xdr, lock->
fl.fl_type ==
F_WRLCK);
389 encode_nlm_lock(xdr, lock);
402 static void nlm_xdr_enc_lockargs(
struct rpc_rqst *
req,
403 struct xdr_stream *xdr,
408 encode_cookie(xdr, &args->
cookie);
409 encode_bool(xdr, args->
block);
410 encode_bool(xdr, lock->
fl.fl_type ==
F_WRLCK);
411 encode_nlm_lock(xdr, lock);
412 encode_bool(xdr, args->
reclaim);
413 encode_int32(xdr, args->
state);
424 static void nlm_xdr_enc_cancargs(
struct rpc_rqst *
req,
425 struct xdr_stream *xdr,
430 encode_cookie(xdr, &args->
cookie);
431 encode_bool(xdr, args->
block);
432 encode_bool(xdr, lock->
fl.fl_type ==
F_WRLCK);
433 encode_nlm_lock(xdr, lock);
442 static void nlm_xdr_enc_unlockargs(
struct rpc_rqst *
req,
443 struct xdr_stream *xdr,
448 encode_cookie(xdr, &args->
cookie);
449 encode_nlm_lock(xdr, lock);
458 static void nlm_xdr_enc_res(
struct rpc_rqst *
req,
459 struct xdr_stream *xdr,
462 encode_cookie(xdr, &result->
cookie);
463 encode_nlm_stat(xdr, result->
status);
479 static void encode_nlm_testrply(
struct xdr_stream *xdr,
483 encode_nlm_holder(xdr, result);
486 static void nlm_xdr_enc_testres(
struct rpc_rqst *
req,
487 struct xdr_stream *xdr,
490 encode_cookie(xdr, &result->
cookie);
491 encode_nlm_stat(xdr, result->
status);
492 encode_nlm_testrply(xdr, result);
516 static int decode_nlm_testrply(
struct xdr_stream *xdr,
521 error = decode_nlm_stat(xdr, &result->
status);
525 error = decode_nlm_holder(xdr, result);
530 static int nlm_xdr_dec_testres(
struct rpc_rqst *
req,
531 struct xdr_stream *xdr,
536 error = decode_cookie(xdr, &result->
cookie);
539 error = decode_nlm_testrply(xdr, result);
550 static int nlm_xdr_dec_res(
struct rpc_rqst *req,
551 struct xdr_stream *xdr,
556 error = decode_cookie(xdr, &result->
cookie);
559 error = decode_nlm_stat(xdr, &result->
status);
568 #define nlm_xdr_dec_norep NULL
570 #define PROC(proc, argtype, restype) \
571 [NLMPROC_##proc] = { \
572 .p_proc = NLMPROC_##proc, \
573 .p_encode = (kxdreproc_t)nlm_xdr_enc_##argtype, \
574 .p_decode = (kxdrdproc_t)nlm_xdr_dec_##restype, \
575 .p_arglen = NLM_##argtype##_sz, \
576 .p_replen = NLM_##restype##_sz, \
577 .p_statidx = NLMPROC_##proc, \
587 PROC(TEST_MSG, testargs, norep),
588 PROC(LOCK_MSG, lockargs, norep),
589 PROC(CANCEL_MSG, cancargs, norep),
590 PROC(UNLOCK_MSG, unlockargs, norep),
591 PROC(GRANTED_MSG, testargs, norep),
592 PROC(TEST_RES, testres, norep),
602 .procs = nlm_procedures,
608 .procs = nlm_procedures,
611 static const struct rpc_version *nlm_versions[] = {
614 #ifdef CONFIG_LOCKD_V4
619 static struct rpc_stat nlm_rpc_stats;
625 .version = nlm_versions,
626 .stats = &nlm_rpc_stats,