xref: /linux/fs/lockd/xdr.h (revision 5ea5880764cbb164afb17a62e76ca75dc371409d)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * XDR types for the NLM protocol
4  *
5  * Copyright (C) 1996 Olaf Kirch <okir@monad.swb.de>
6  */
7 
8 #ifndef _LOCKD_XDR_H
9 #define _LOCKD_XDR_H
10 
11 #include <linux/fs.h>
12 #include <linux/filelock.h>
13 #include <linux/nfs.h>
14 #include <linux/sunrpc/xdr.h>
15 
16 #define SM_MAXSTRLEN		1024
17 #define SM_PRIV_SIZE		16
18 
19 struct nsm_private {
20 	unsigned char		data[SM_PRIV_SIZE];
21 };
22 
23 struct svc_rqst;
24 
25 #define NLM_MAXCOOKIELEN    	32
26 #define NLM_MAXSTRLEN		1024
27 
28 #define	nlm_granted		cpu_to_be32(NLM_LCK_GRANTED)
29 #define	nlm_lck_denied		cpu_to_be32(NLM_LCK_DENIED)
30 #define	nlm_lck_denied_nolocks	cpu_to_be32(NLM_LCK_DENIED_NOLOCKS)
31 #define	nlm_lck_blocked		cpu_to_be32(NLM_LCK_BLOCKED)
32 #define	nlm_lck_denied_grace_period	cpu_to_be32(NLM_LCK_DENIED_GRACE_PERIOD)
33 
34 /* Lock info passed via NLM */
35 struct nlm_lock {
36 	char *			caller;
37 	unsigned int		len; 	/* length of "caller" */
38 	struct nfs_fh		fh;
39 	struct xdr_netobj	oh;
40 	u32			svid;
41 	u64			lock_start;
42 	u64			lock_len;
43 	struct file_lock	fl;
44 };
45 
46 /*
47  *	NLM cookies. Technically they can be 1K, but Linux only uses 8 bytes.
48  *	FreeBSD uses 16, Apple Mac OS X 10.3 uses 20. Therefore we set it to
49  *	32 bytes.
50  */
51 
52 struct nlm_cookie
53 {
54 	unsigned char data[NLM_MAXCOOKIELEN];
55 	unsigned int len;
56 };
57 
58 /*
59  * Generic lockd arguments for all but sm_notify
60  */
61 struct nlm_args {
62 	struct nlm_cookie	cookie;
63 	struct nlm_lock		lock;
64 	u32			block;
65 	u32			reclaim;
66 	u32			state;
67 	u32			monitor;
68 	u32			fsm_access;
69 	u32			fsm_mode;
70 };
71 
72 /*
73  * Generic lockd result
74  */
75 struct nlm_res {
76 	struct nlm_cookie	cookie;
77 	__be32			status;
78 	struct nlm_lock		lock;
79 };
80 
81 /*
82  * statd callback when client has rebooted
83  */
84 struct nlm_reboot {
85 	char			*mon;
86 	unsigned int		len;
87 	u32			state;
88 	struct nsm_private	priv;
89 };
90 
91 bool	nlmsvc_decode_void(struct svc_rqst *rqstp, struct xdr_stream *xdr);
92 bool	nlmsvc_decode_testargs(struct svc_rqst *rqstp, struct xdr_stream *xdr);
93 bool	nlmsvc_decode_lockargs(struct svc_rqst *rqstp, struct xdr_stream *xdr);
94 bool	nlmsvc_decode_cancargs(struct svc_rqst *rqstp, struct xdr_stream *xdr);
95 bool	nlmsvc_decode_unlockargs(struct svc_rqst *rqstp, struct xdr_stream *xdr);
96 bool	nlmsvc_decode_res(struct svc_rqst *rqstp, struct xdr_stream *xdr);
97 bool	nlmsvc_decode_reboot(struct svc_rqst *rqstp, struct xdr_stream *xdr);
98 bool	nlmsvc_decode_shareargs(struct svc_rqst *rqstp, struct xdr_stream *xdr);
99 bool	nlmsvc_decode_notify(struct svc_rqst *rqstp, struct xdr_stream *xdr);
100 
101 bool	nlmsvc_encode_testres(struct svc_rqst *rqstp, struct xdr_stream *xdr);
102 bool	nlmsvc_encode_res(struct svc_rqst *rqstp, struct xdr_stream *xdr);
103 bool	nlmsvc_encode_void(struct svc_rqst *rqstp, struct xdr_stream *xdr);
104 bool	nlmsvc_encode_shareres(struct svc_rqst *rqstp, struct xdr_stream *xdr);
105 
106 #endif /* _LOCKD_XDR_H */
107