xref: /openbmc/linux/fs/dlm/dlm_internal.h (revision 164d88abd7608e869b7617d5ff8893344fdda759)
12522fe45SThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-only */
2e7fd4179SDavid Teigland /******************************************************************************
3e7fd4179SDavid Teigland *******************************************************************************
4e7fd4179SDavid Teigland **
5e7fd4179SDavid Teigland **  Copyright (C) Sistina Software, Inc.  1997-2003  All rights reserved.
660f98d18SDavid Teigland **  Copyright (C) 2004-2011 Red Hat, Inc.  All rights reserved.
7e7fd4179SDavid Teigland **
8e7fd4179SDavid Teigland **
9e7fd4179SDavid Teigland *******************************************************************************
10e7fd4179SDavid Teigland ******************************************************************************/
11e7fd4179SDavid Teigland 
12e7fd4179SDavid Teigland #ifndef __DLM_INTERNAL_DOT_H__
13e7fd4179SDavid Teigland #define __DLM_INTERNAL_DOT_H__
14e7fd4179SDavid Teigland 
15e7fd4179SDavid Teigland /*
16e7fd4179SDavid Teigland  * This is the main header file to be included in each DLM source file.
17e7fd4179SDavid Teigland  */
18e7fd4179SDavid Teigland 
19e7fd4179SDavid Teigland #include <linux/slab.h>
20e7fd4179SDavid Teigland #include <linux/sched.h>
21e7fd4179SDavid Teigland #include <linux/types.h>
22e7fd4179SDavid Teigland #include <linux/ctype.h>
23e7fd4179SDavid Teigland #include <linux/spinlock.h>
24e7fd4179SDavid Teigland #include <linux/vmalloc.h>
25e7fd4179SDavid Teigland #include <linux/list.h>
26e7fd4179SDavid Teigland #include <linux/errno.h>
27e7fd4179SDavid Teigland #include <linux/random.h>
28e7fd4179SDavid Teigland #include <linux/delay.h>
29e7fd4179SDavid Teigland #include <linux/socket.h>
30e7fd4179SDavid Teigland #include <linux/kthread.h>
31e7fd4179SDavid Teigland #include <linux/kobject.h>
32e7fd4179SDavid Teigland #include <linux/kref.h>
33e7fd4179SDavid Teigland #include <linux/kernel.h>
34e7fd4179SDavid Teigland #include <linux/jhash.h>
35597d0caeSDavid Teigland #include <linux/miscdevice.h>
3690135925SDavid Teigland #include <linux/mutex.h>
373d6aa675SDavid Teigland #include <linux/idr.h>
38d6e24788SDavid Teigland #include <linux/ratelimit.h>
397c0f6ba6SLinus Torvalds #include <linux/uaccess.h>
40e7fd4179SDavid Teigland 
41e7fd4179SDavid Teigland #include <linux/dlm.h>
4299fc6487SDavid Teigland #include "config.h"
43e7fd4179SDavid Teigland 
44e7fd4179SDavid Teigland struct dlm_ls;
45e7fd4179SDavid Teigland struct dlm_lkb;
46e7fd4179SDavid Teigland struct dlm_rsb;
47e7fd4179SDavid Teigland struct dlm_member;
48e7fd4179SDavid Teigland struct dlm_rsbtable;
49e7fd4179SDavid Teigland struct dlm_recover;
50e7fd4179SDavid Teigland struct dlm_header;
51e7fd4179SDavid Teigland struct dlm_message;
52e7fd4179SDavid Teigland struct dlm_rcom;
53e7fd4179SDavid Teigland struct dlm_mhandle;
548f2dc78dSAlexander Aring struct dlm_msg;
55e7fd4179SDavid Teigland 
56e7fd4179SDavid Teigland #define log_print(fmt, args...) \
57e7fd4179SDavid Teigland 	printk(KERN_ERR "dlm: "fmt"\n" , ##args)
582df6b762SAlexander Aring #define log_print_ratelimited(fmt, args...) \
592df6b762SAlexander Aring 	printk_ratelimited(KERN_ERR "dlm: "fmt"\n", ##args)
60e7fd4179SDavid Teigland #define log_error(ls, fmt, args...) \
61e7fd4179SDavid Teigland 	printk(KERN_ERR "dlm: %s: " fmt "\n", (ls)->ls_name , ##args)
62505ee528SZhilong Liu 
63075f0177SDavid Teigland #define log_rinfo(ls, fmt, args...) \
64505ee528SZhilong Liu do { \
65505ee528SZhilong Liu 	if (dlm_config.ci_log_info) \
66505ee528SZhilong Liu 		printk(KERN_INFO "dlm: %s: " fmt "\n", \
67505ee528SZhilong Liu 			(ls)->ls_name, ##args); \
68505ee528SZhilong Liu 	else if (dlm_config.ci_log_debug) \
69505ee528SZhilong Liu 		printk(KERN_DEBUG "dlm: %s: " fmt "\n", \
70505ee528SZhilong Liu 		       (ls)->ls_name , ##args); \
71505ee528SZhilong Liu } while (0)
72e7fd4179SDavid Teigland 
7399fc6487SDavid Teigland #define log_debug(ls, fmt, args...) \
7499fc6487SDavid Teigland do { \
7599fc6487SDavid Teigland 	if (dlm_config.ci_log_debug) \
7699fc6487SDavid Teigland 		printk(KERN_DEBUG "dlm: %s: " fmt "\n", \
7799fc6487SDavid Teigland 		       (ls)->ls_name , ##args); \
7899fc6487SDavid Teigland } while (0)
79e7fd4179SDavid Teigland 
80d6e24788SDavid Teigland #define log_limit(ls, fmt, args...) \
81d6e24788SDavid Teigland do { \
82d6e24788SDavid Teigland 	if (dlm_config.ci_log_debug) \
83d6e24788SDavid Teigland 		printk_ratelimited(KERN_DEBUG "dlm: %s: " fmt "\n", \
84d6e24788SDavid Teigland 			(ls)->ls_name , ##args); \
85d6e24788SDavid Teigland } while (0)
86d6e24788SDavid Teigland 
87e7fd4179SDavid Teigland #define DLM_ASSERT(x, do) \
88e7fd4179SDavid Teigland { \
89e7fd4179SDavid Teigland   if (!(x)) \
90e7fd4179SDavid Teigland   { \
91e7fd4179SDavid Teigland     printk(KERN_ERR "\nDLM:  Assertion failed on line %d of file %s\n" \
92e7fd4179SDavid Teigland                "DLM:  assertion:  \"%s\"\n" \
93e7fd4179SDavid Teigland                "DLM:  time = %lu\n", \
94e7fd4179SDavid Teigland                __LINE__, __FILE__, #x, jiffies); \
95e7fd4179SDavid Teigland     {do} \
96e7fd4179SDavid Teigland     printk("\n"); \
97e7fd4179SDavid Teigland     panic("DLM:  Record message above and reboot.\n"); \
98e7fd4179SDavid Teigland   } \
99e7fd4179SDavid Teigland }
100e7fd4179SDavid Teigland 
101e7fd4179SDavid Teigland 
102f1172283SDavid Teigland #define DLM_RTF_SHRINK		0x00000001
103f1172283SDavid Teigland 
104e7fd4179SDavid Teigland struct dlm_rsbtable {
1059beb3bf5SBob Peterson 	struct rb_root		keep;
1069beb3bf5SBob Peterson 	struct rb_root		toss;
107c7be761aSDavid Teigland 	spinlock_t		lock;
108f1172283SDavid Teigland 	uint32_t		flags;
109e7fd4179SDavid Teigland };
110e7fd4179SDavid Teigland 
111e7fd4179SDavid Teigland 
112e7fd4179SDavid Teigland /*
113e7fd4179SDavid Teigland  * Lockspace member (per node in a ls)
114e7fd4179SDavid Teigland  */
115e7fd4179SDavid Teigland 
116e7fd4179SDavid Teigland struct dlm_member {
117e7fd4179SDavid Teigland 	struct list_head	list;
118e7fd4179SDavid Teigland 	int			nodeid;
119e7fd4179SDavid Teigland 	int			weight;
120757a4271SDavid Teigland 	int			slot;
121757a4271SDavid Teigland 	int			slot_prev;
12260f98d18SDavid Teigland 	int			comm_seq;
123757a4271SDavid Teigland 	uint32_t		generation;
124757a4271SDavid Teigland };
125757a4271SDavid Teigland 
126757a4271SDavid Teigland /*
127e7fd4179SDavid Teigland  * Save and manage recovery state for a lockspace.
128e7fd4179SDavid Teigland  */
129e7fd4179SDavid Teigland 
130e7fd4179SDavid Teigland struct dlm_recover {
131e7fd4179SDavid Teigland 	struct list_head	list;
13260f98d18SDavid Teigland 	struct dlm_config_node	*nodes;
13360f98d18SDavid Teigland 	int			nodes_count;
134e7fd4179SDavid Teigland 	uint64_t		seq;
135e7fd4179SDavid Teigland };
136e7fd4179SDavid Teigland 
137e7fd4179SDavid Teigland /*
138e7fd4179SDavid Teigland  * Pass input args to second stage locking function.
139e7fd4179SDavid Teigland  */
140e7fd4179SDavid Teigland 
141e7fd4179SDavid Teigland struct dlm_args {
142e7fd4179SDavid Teigland 	uint32_t		flags;
143e5dae548SDavid Teigland 	void			(*astfn) (void *astparam);
144e5dae548SDavid Teigland 	void			*astparam;
145e5dae548SDavid Teigland 	void			(*bastfn) (void *astparam, int mode);
146e7fd4179SDavid Teigland 	int			mode;
147e7fd4179SDavid Teigland 	struct dlm_lksb		*lksb;
148d7db923eSDavid Teigland 	unsigned long		timeout;
149e7fd4179SDavid Teigland };
150e7fd4179SDavid Teigland 
151e7fd4179SDavid Teigland 
152e7fd4179SDavid Teigland /*
153e7fd4179SDavid Teigland  * Lock block
154e7fd4179SDavid Teigland  *
155e7fd4179SDavid Teigland  * A lock can be one of three types:
156e7fd4179SDavid Teigland  *
157e7fd4179SDavid Teigland  * local copy      lock is mastered locally
158e7fd4179SDavid Teigland  *                 (lkb_nodeid is zero and DLM_LKF_MSTCPY is not set)
159e7fd4179SDavid Teigland  * process copy    lock is mastered on a remote node
160e7fd4179SDavid Teigland  *                 (lkb_nodeid is non-zero and DLM_LKF_MSTCPY is not set)
161e7fd4179SDavid Teigland  * master copy     master node's copy of a lock owned by remote node
162e7fd4179SDavid Teigland  *                 (lkb_nodeid is non-zero and DLM_LKF_MSTCPY is set)
163e7fd4179SDavid Teigland  *
164e7fd4179SDavid Teigland  * lkb_exflags: a copy of the most recent flags arg provided to dlm_lock or
165e7fd4179SDavid Teigland  * dlm_unlock.  The dlm does not modify these or use any private flags in
166e7fd4179SDavid Teigland  * this field; it only contains DLM_LKF_ flags from dlm.h.  These flags
167e7fd4179SDavid Teigland  * are sent as-is to the remote master when the lock is remote.
168e7fd4179SDavid Teigland  *
169e7fd4179SDavid Teigland  * lkb_flags: internal dlm flags (DLM_IFL_ prefix) from dlm_internal.h.
170e7fd4179SDavid Teigland  * Some internal flags are shared between the master and process nodes;
171e7fd4179SDavid Teigland  * these shared flags are kept in the lower two bytes.  One of these
172e7fd4179SDavid Teigland  * flags set on the master copy will be propagated to the process copy
173e7fd4179SDavid Teigland  * and v.v.  Other internal flags are private to the master or process
174e7fd4179SDavid Teigland  * node (e.g. DLM_IFL_MSTCPY).  These are kept in the high two bytes.
175e7fd4179SDavid Teigland  *
176e7fd4179SDavid Teigland  * lkb_sbflags: status block flags.  These flags are copied directly into
177e7fd4179SDavid Teigland  * the caller's lksb.sb_flags prior to the dlm_lock/dlm_unlock completion
178e7fd4179SDavid Teigland  * ast.  All defined in dlm.h with DLM_SBF_ prefix.
179e7fd4179SDavid Teigland  *
180e7fd4179SDavid Teigland  * lkb_status: the lock status indicates which rsb queue the lock is
181e7fd4179SDavid Teigland  * on, grant, convert, or wait.  DLM_LKSTS_ WAITING/GRANTED/CONVERT
182e7fd4179SDavid Teigland  *
183e7fd4179SDavid Teigland  * lkb_wait_type: the dlm message type (DLM_MSG_ prefix) for which a
184e7fd4179SDavid Teigland  * reply is needed.  Only set when the lkb is on the lockspace waiters
185e7fd4179SDavid Teigland  * list awaiting a reply from a remote node.
186e7fd4179SDavid Teigland  *
187e7fd4179SDavid Teigland  * lkb_nodeid: when the lkb is a local copy, nodeid is 0; when the lkb
188e7fd4179SDavid Teigland  * is a master copy, nodeid specifies the remote lock holder, when the
189e7fd4179SDavid Teigland  * lkb is a process copy, the nodeid specifies the lock master.
190e7fd4179SDavid Teigland  */
191e7fd4179SDavid Teigland 
192e7fd4179SDavid Teigland /* lkb_status */
193e7fd4179SDavid Teigland 
194e7fd4179SDavid Teigland #define DLM_LKSTS_WAITING	1
195e7fd4179SDavid Teigland #define DLM_LKSTS_GRANTED	2
196e7fd4179SDavid Teigland #define DLM_LKSTS_CONVERT	3
197e7fd4179SDavid Teigland 
198e7fd4179SDavid Teigland /* lkb_flags */
199e7fd4179SDavid Teigland 
200e7fd4179SDavid Teigland #define DLM_IFL_MSTCPY		0x00010000
201e7fd4179SDavid Teigland #define DLM_IFL_RESEND		0x00020000
202597d0caeSDavid Teigland #define DLM_IFL_DEAD		0x00040000
203ef0c2bb0SDavid Teigland #define DLM_IFL_OVERLAP_UNLOCK  0x00080000
204ef0c2bb0SDavid Teigland #define DLM_IFL_OVERLAP_CANCEL  0x00100000
205ef0c2bb0SDavid Teigland #define DLM_IFL_ENDOFLIFE	0x00200000
2063ae1acf9SDavid Teigland #define DLM_IFL_WATCH_TIMEWARN	0x00400000
20784d8cd69SDavid Teigland #define DLM_IFL_TIMEOUT_CANCEL	0x00800000
2088b4021faSDavid Teigland #define DLM_IFL_DEADLOCK_CANCEL	0x01000000
2092a7ce0edSDavid Teigland #define DLM_IFL_STUB_MS		0x02000000 /* magic number for m_flags */
210597d0caeSDavid Teigland #define DLM_IFL_USER		0x00000001
211597d0caeSDavid Teigland #define DLM_IFL_ORPHAN		0x00000002
212e7fd4179SDavid Teigland 
2138304d6f2SDavid Teigland #define DLM_CALLBACKS_SIZE	6
2148304d6f2SDavid Teigland 
2158304d6f2SDavid Teigland #define DLM_CB_CAST		0x00000001
2168304d6f2SDavid Teigland #define DLM_CB_BAST		0x00000002
2178304d6f2SDavid Teigland #define DLM_CB_SKIP		0x00000004
2188304d6f2SDavid Teigland 
2198304d6f2SDavid Teigland struct dlm_callback {
2208304d6f2SDavid Teigland 	uint64_t		seq;
2218304d6f2SDavid Teigland 	uint32_t		flags;		/* DLM_CBF_ */
2228304d6f2SDavid Teigland 	int			sb_status;	/* copy to lksb status */
2238304d6f2SDavid Teigland 	uint8_t			sb_flags;	/* copy to lksb flags */
2248304d6f2SDavid Teigland 	int8_t			mode; /* rq mode of bast, gr mode of cast */
2258304d6f2SDavid Teigland };
2268304d6f2SDavid Teigland 
227e7fd4179SDavid Teigland struct dlm_lkb {
228e7fd4179SDavid Teigland 	struct dlm_rsb		*lkb_resource;	/* the rsb */
229e7fd4179SDavid Teigland 	struct kref		lkb_ref;
230e7fd4179SDavid Teigland 	int			lkb_nodeid;	/* copied from rsb */
231e7fd4179SDavid Teigland 	int			lkb_ownpid;	/* pid of lock owner */
232e7fd4179SDavid Teigland 	uint32_t		lkb_id;		/* our lock ID */
233e7fd4179SDavid Teigland 	uint32_t		lkb_remid;	/* lock ID on remote partner */
234e7fd4179SDavid Teigland 	uint32_t		lkb_exflags;	/* external flags from caller */
235e7fd4179SDavid Teigland 	uint32_t		lkb_sbflags;	/* lksb flags */
236e7fd4179SDavid Teigland 	uint32_t		lkb_flags;	/* internal flags */
237e7fd4179SDavid Teigland 	uint32_t		lkb_lvbseq;	/* lvb sequence number */
238e7fd4179SDavid Teigland 
239e7fd4179SDavid Teigland 	int8_t			lkb_status;     /* granted, waiting, convert */
240e7fd4179SDavid Teigland 	int8_t			lkb_rqmode;	/* requested lock mode */
241e7fd4179SDavid Teigland 	int8_t			lkb_grmode;	/* granted lock mode */
242e7fd4179SDavid Teigland 	int8_t			lkb_highbast;	/* highest mode bast sent for */
2437fe2b319SDavid Teigland 
244e7fd4179SDavid Teigland 	int8_t			lkb_wait_type;	/* type of reply waiting for */
245ef0c2bb0SDavid Teigland 	int8_t			lkb_wait_count;
246c6ff669bSDavid Teigland 	int			lkb_wait_nodeid; /* for debugging */
247e7fd4179SDavid Teigland 
248e7fd4179SDavid Teigland 	struct list_head	lkb_statequeue;	/* rsb g/c/w list */
249e7fd4179SDavid Teigland 	struct list_head	lkb_rsb_lookup;	/* waiting for rsb lookup */
250e7fd4179SDavid Teigland 	struct list_head	lkb_wait_reply;	/* waiting for remote reply */
251597d0caeSDavid Teigland 	struct list_head	lkb_ownqueue;	/* list of locks for a process */
2523ae1acf9SDavid Teigland 	struct list_head	lkb_time_list;
253eeda418dSDavid Teigland 	ktime_t			lkb_timestamp;
254c6ff669bSDavid Teigland 	ktime_t			lkb_wait_time;
2553ae1acf9SDavid Teigland 	unsigned long		lkb_timeout_cs;
256e7fd4179SDavid Teigland 
25723e8e1aaSDavid Teigland 	struct mutex		lkb_cb_mutex;
25823e8e1aaSDavid Teigland 	struct work_struct	lkb_cb_work;
25923e8e1aaSDavid Teigland 	struct list_head	lkb_cb_list; /* for ls_cb_delay or proc->asts */
2608304d6f2SDavid Teigland 	struct dlm_callback	lkb_callbacks[DLM_CALLBACKS_SIZE];
2618304d6f2SDavid Teigland 	struct dlm_callback	lkb_last_cast;
2628304d6f2SDavid Teigland 	struct dlm_callback	lkb_last_bast;
2638304d6f2SDavid Teigland 	ktime_t			lkb_last_cast_time;	/* for debugging */
2648304d6f2SDavid Teigland 	ktime_t			lkb_last_bast_time;	/* for debugging */
2658304d6f2SDavid Teigland 
2664875647aSDavid Teigland 	uint64_t		lkb_recover_seq; /* from ls_recover_seq */
2674875647aSDavid Teigland 
268e7fd4179SDavid Teigland 	char			*lkb_lvbptr;
269e7fd4179SDavid Teigland 	struct dlm_lksb		*lkb_lksb;      /* caller's status block */
270e5dae548SDavid Teigland 	void			(*lkb_astfn) (void *astparam);
271e5dae548SDavid Teigland 	void			(*lkb_bastfn) (void *astparam, int mode);
272d292c0ccSDavid Teigland 	union {
273e5dae548SDavid Teigland 		void			*lkb_astparam;	/* caller's ast arg */
274d292c0ccSDavid Teigland 		struct dlm_user_args	*lkb_ua;
275d292c0ccSDavid Teigland 	};
276e7fd4179SDavid Teigland };
277e7fd4179SDavid Teigland 
278c04fecb4SDavid Teigland /*
279c04fecb4SDavid Teigland  * res_master_nodeid is "normal": 0 is unset/invalid, non-zero is the real
280c04fecb4SDavid Teigland  * nodeid, even when nodeid is our_nodeid.
281c04fecb4SDavid Teigland  *
282c04fecb4SDavid Teigland  * res_nodeid is "odd": -1 is unset/invalid, zero means our_nodeid,
283c04fecb4SDavid Teigland  * greater than zero when another nodeid.
284c04fecb4SDavid Teigland  *
285c04fecb4SDavid Teigland  * (TODO: remove res_nodeid and only use res_master_nodeid)
286c04fecb4SDavid Teigland  */
287e7fd4179SDavid Teigland 
288e7fd4179SDavid Teigland struct dlm_rsb {
289e7fd4179SDavid Teigland 	struct dlm_ls		*res_ls;	/* the lockspace */
290e7fd4179SDavid Teigland 	struct kref		res_ref;
29190135925SDavid Teigland 	struct mutex		res_mutex;
292e7fd4179SDavid Teigland 	unsigned long		res_flags;
293e7fd4179SDavid Teigland 	int			res_length;	/* length of rsb name */
294e7fd4179SDavid Teigland 	int			res_nodeid;
295c04fecb4SDavid Teigland 	int			res_master_nodeid;
296c04fecb4SDavid Teigland 	int			res_dir_nodeid;
2971d7c484eSDavid Teigland 	int			res_id;		/* for ls_recover_idr */
298e7fd4179SDavid Teigland 	uint32_t                res_lvbseq;
299e7fd4179SDavid Teigland 	uint32_t		res_hash;
300e7fd4179SDavid Teigland 	uint32_t		res_bucket;	/* rsbtbl */
301e7fd4179SDavid Teigland 	unsigned long		res_toss_time;
302e7fd4179SDavid Teigland 	uint32_t		res_first_lkid;
303e7fd4179SDavid Teigland 	struct list_head	res_lookup;	/* lkbs waiting on first */
3049beb3bf5SBob Peterson 	union {
3059beb3bf5SBob Peterson 		struct list_head	res_hashchain;
3069beb3bf5SBob Peterson 		struct rb_node		res_hashnode;	/* rsbtbl */
3079beb3bf5SBob Peterson 	};
308e7fd4179SDavid Teigland 	struct list_head	res_grantqueue;
309e7fd4179SDavid Teigland 	struct list_head	res_convertqueue;
310e7fd4179SDavid Teigland 	struct list_head	res_waitqueue;
311e7fd4179SDavid Teigland 
312e7fd4179SDavid Teigland 	struct list_head	res_root_list;	    /* used for recovery */
313e7fd4179SDavid Teigland 	struct list_head	res_recover_list;   /* used for recovery */
314e7fd4179SDavid Teigland 	int			res_recover_locks_count;
315e7fd4179SDavid Teigland 
316e7fd4179SDavid Teigland 	char			*res_lvbptr;
3173881ac04SDavid Teigland 	char			res_name[DLM_RESNAME_MAXLEN+1];
318e7fd4179SDavid Teigland };
319e7fd4179SDavid Teigland 
320c04fecb4SDavid Teigland /* dlm_master_lookup() flags */
321c04fecb4SDavid Teigland 
322c04fecb4SDavid Teigland #define DLM_LU_RECOVER_DIR	1
323c04fecb4SDavid Teigland #define DLM_LU_RECOVER_MASTER	2
324c04fecb4SDavid Teigland 
325c04fecb4SDavid Teigland /* dlm_master_lookup() results */
326c04fecb4SDavid Teigland 
327c04fecb4SDavid Teigland #define DLM_LU_MATCH		1
328c04fecb4SDavid Teigland #define DLM_LU_ADD		2
329c04fecb4SDavid Teigland 
330e7fd4179SDavid Teigland /* find_rsb() flags */
331e7fd4179SDavid Teigland 
332c04fecb4SDavid Teigland #define R_REQUEST		0x00000001
333c04fecb4SDavid Teigland #define R_RECEIVE_REQUEST	0x00000002
334c04fecb4SDavid Teigland #define R_RECEIVE_RECOVER	0x00000004
335e7fd4179SDavid Teigland 
336e7fd4179SDavid Teigland /* rsb_flags */
337e7fd4179SDavid Teigland 
338e7fd4179SDavid Teigland enum rsb_flags {
339e7fd4179SDavid Teigland 	RSB_MASTER_UNCERTAIN,
340e7fd4179SDavid Teigland 	RSB_VALNOTVALID,
341e7fd4179SDavid Teigland 	RSB_VALNOTVALID_PREV,
342e7fd4179SDavid Teigland 	RSB_NEW_MASTER,
343e7fd4179SDavid Teigland 	RSB_NEW_MASTER2,
344e7fd4179SDavid Teigland 	RSB_RECOVER_CONVERT,
3454875647aSDavid Teigland 	RSB_RECOVER_GRANT,
346da8c6663SDavid Teigland 	RSB_RECOVER_LVB_INVAL,
347e7fd4179SDavid Teigland };
348e7fd4179SDavid Teigland 
349e7fd4179SDavid Teigland static inline void rsb_set_flag(struct dlm_rsb *r, enum rsb_flags flag)
350e7fd4179SDavid Teigland {
351e7fd4179SDavid Teigland 	__set_bit(flag, &r->res_flags);
352e7fd4179SDavid Teigland }
353e7fd4179SDavid Teigland 
354e7fd4179SDavid Teigland static inline void rsb_clear_flag(struct dlm_rsb *r, enum rsb_flags flag)
355e7fd4179SDavid Teigland {
356e7fd4179SDavid Teigland 	__clear_bit(flag, &r->res_flags);
357e7fd4179SDavid Teigland }
358e7fd4179SDavid Teigland 
359e7fd4179SDavid Teigland static inline int rsb_flag(struct dlm_rsb *r, enum rsb_flags flag)
360e7fd4179SDavid Teigland {
361e7fd4179SDavid Teigland 	return test_bit(flag, &r->res_flags);
362e7fd4179SDavid Teigland }
363e7fd4179SDavid Teigland 
364e7fd4179SDavid Teigland 
365e7fd4179SDavid Teigland /* dlm_header is first element of all structs sent between nodes */
366e7fd4179SDavid Teigland 
36738aa8b0cSDavid Teigland #define DLM_HEADER_MAJOR	0x00030000
368489d8e55SAlexander Aring #define DLM_HEADER_MINOR	0x00000002
369489d8e55SAlexander Aring 
370489d8e55SAlexander Aring #define DLM_VERSION_3_1		0x00030001
371489d8e55SAlexander Aring #define DLM_VERSION_3_2		0x00030002
372757a4271SDavid Teigland 
373757a4271SDavid Teigland #define DLM_HEADER_SLOTS	0x00000001
374e7fd4179SDavid Teigland 
375e7fd4179SDavid Teigland #define DLM_MSG			1
376e7fd4179SDavid Teigland #define DLM_RCOM		2
377489d8e55SAlexander Aring #define DLM_OPTS		3
378489d8e55SAlexander Aring #define DLM_ACK			4
379489d8e55SAlexander Aring #define DLM_FIN			5
380e7fd4179SDavid Teigland 
381e7fd4179SDavid Teigland struct dlm_header {
382e7fd4179SDavid Teigland 	uint32_t		h_version;
3838e2e4086SAlexander Aring 	union {
3848e2e4086SAlexander Aring 		/* for DLM_MSG and DLM_RCOM */
385e7fd4179SDavid Teigland 		uint32_t	h_lockspace;
386489d8e55SAlexander Aring 		/* for DLM_ACK and DLM_OPTS */
387489d8e55SAlexander Aring 		uint32_t	h_seq;
3888e2e4086SAlexander Aring 	} u;
389e7fd4179SDavid Teigland 	uint32_t		h_nodeid;	/* nodeid of sender */
390e7fd4179SDavid Teigland 	uint16_t		h_length;
391e7fd4179SDavid Teigland 	uint8_t			h_cmd;		/* DLM_MSG, DLM_RCOM */
392e7fd4179SDavid Teigland 	uint8_t			h_pad;
393e7fd4179SDavid Teigland };
394e7fd4179SDavid Teigland 
395e7fd4179SDavid Teigland #define DLM_MSG_REQUEST		1
396e7fd4179SDavid Teigland #define DLM_MSG_CONVERT		2
397e7fd4179SDavid Teigland #define DLM_MSG_UNLOCK		3
398e7fd4179SDavid Teigland #define DLM_MSG_CANCEL		4
399e7fd4179SDavid Teigland #define DLM_MSG_REQUEST_REPLY	5
400e7fd4179SDavid Teigland #define DLM_MSG_CONVERT_REPLY	6
401e7fd4179SDavid Teigland #define DLM_MSG_UNLOCK_REPLY	7
402e7fd4179SDavid Teigland #define DLM_MSG_CANCEL_REPLY	8
403e7fd4179SDavid Teigland #define DLM_MSG_GRANT		9
404e7fd4179SDavid Teigland #define DLM_MSG_BAST		10
405e7fd4179SDavid Teigland #define DLM_MSG_LOOKUP		11
406e7fd4179SDavid Teigland #define DLM_MSG_REMOVE		12
407e7fd4179SDavid Teigland #define DLM_MSG_LOOKUP_REPLY	13
4088499137dSDavid Teigland #define DLM_MSG_PURGE		14
409e7fd4179SDavid Teigland 
410e7fd4179SDavid Teigland struct dlm_message {
411e7fd4179SDavid Teigland 	struct dlm_header	m_header;
412e7fd4179SDavid Teigland 	uint32_t		m_type;		/* DLM_MSG_ */
413e7fd4179SDavid Teigland 	uint32_t		m_nodeid;
414e7fd4179SDavid Teigland 	uint32_t		m_pid;
415e7fd4179SDavid Teigland 	uint32_t		m_lkid;		/* lkid on sender */
416e7fd4179SDavid Teigland 	uint32_t		m_remid;	/* lkid on receiver */
417e7fd4179SDavid Teigland 	uint32_t		m_parent_lkid;
418e7fd4179SDavid Teigland 	uint32_t		m_parent_remid;
419e7fd4179SDavid Teigland 	uint32_t		m_exflags;
420e7fd4179SDavid Teigland 	uint32_t		m_sbflags;
421e7fd4179SDavid Teigland 	uint32_t		m_flags;
422e7fd4179SDavid Teigland 	uint32_t		m_lvbseq;
423e7fd4179SDavid Teigland 	uint32_t		m_hash;
424e7fd4179SDavid Teigland 	int			m_status;
425e7fd4179SDavid Teigland 	int			m_grmode;
426e7fd4179SDavid Teigland 	int			m_rqmode;
427e7fd4179SDavid Teigland 	int			m_bastmode;
428e7fd4179SDavid Teigland 	int			m_asts;
429e7fd4179SDavid Teigland 	int			m_result;	/* 0 or -EXXX */
430a4e439a6SGustavo A. R. Silva 	char			m_extra[];	/* name or lvb */
431e7fd4179SDavid Teigland };
432e7fd4179SDavid Teigland 
433e7fd4179SDavid Teigland 
434e7fd4179SDavid Teigland #define DLM_RS_NODES		0x00000001
435e7fd4179SDavid Teigland #define DLM_RS_NODES_ALL	0x00000002
436e7fd4179SDavid Teigland #define DLM_RS_DIR		0x00000004
437e7fd4179SDavid Teigland #define DLM_RS_DIR_ALL		0x00000008
438e7fd4179SDavid Teigland #define DLM_RS_LOCKS		0x00000010
439e7fd4179SDavid Teigland #define DLM_RS_LOCKS_ALL	0x00000020
440e7fd4179SDavid Teigland #define DLM_RS_DONE		0x00000040
441e7fd4179SDavid Teigland #define DLM_RS_DONE_ALL		0x00000080
442e7fd4179SDavid Teigland 
443e7fd4179SDavid Teigland #define DLM_RCOM_STATUS		1
444e7fd4179SDavid Teigland #define DLM_RCOM_NAMES		2
445e7fd4179SDavid Teigland #define DLM_RCOM_LOOKUP		3
446e7fd4179SDavid Teigland #define DLM_RCOM_LOCK		4
447e7fd4179SDavid Teigland #define DLM_RCOM_STATUS_REPLY	5
448e7fd4179SDavid Teigland #define DLM_RCOM_NAMES_REPLY	6
449e7fd4179SDavid Teigland #define DLM_RCOM_LOOKUP_REPLY	7
450e7fd4179SDavid Teigland #define DLM_RCOM_LOCK_REPLY	8
451e7fd4179SDavid Teigland 
452e7fd4179SDavid Teigland struct dlm_rcom {
453e7fd4179SDavid Teigland 	struct dlm_header	rc_header;
454e7fd4179SDavid Teigland 	uint32_t		rc_type;	/* DLM_RCOM_ */
455e7fd4179SDavid Teigland 	int			rc_result;	/* multi-purpose */
456e7fd4179SDavid Teigland 	uint64_t		rc_id;		/* match reply with request */
45738aa8b0cSDavid Teigland 	uint64_t		rc_seq;		/* sender's ls_recover_seq */
45838aa8b0cSDavid Teigland 	uint64_t		rc_seq_reply;	/* remote ls_recover_seq */
459a4e439a6SGustavo A. R. Silva 	char			rc_buf[];
460e7fd4179SDavid Teigland };
461e7fd4179SDavid Teigland 
462489d8e55SAlexander Aring struct dlm_opt_header {
463489d8e55SAlexander Aring 	uint16_t	t_type;
464489d8e55SAlexander Aring 	uint16_t	t_length;
465b892e479SAlexander Aring 	uint32_t	t_pad;
466489d8e55SAlexander Aring 	/* need to be 8 byte aligned */
467489d8e55SAlexander Aring 	char		t_value[];
468489d8e55SAlexander Aring };
469489d8e55SAlexander Aring 
470489d8e55SAlexander Aring /* encapsulation header */
471489d8e55SAlexander Aring struct dlm_opts {
472489d8e55SAlexander Aring 	struct dlm_header	o_header;
473489d8e55SAlexander Aring 	uint8_t			o_nextcmd;
474489d8e55SAlexander Aring 	uint8_t			o_pad;
475489d8e55SAlexander Aring 	uint16_t		o_optlen;
476489d8e55SAlexander Aring 	uint32_t		o_pad2;
477489d8e55SAlexander Aring 	char			o_opts[];
478489d8e55SAlexander Aring };
479489d8e55SAlexander Aring 
480eef7d739SAl Viro union dlm_packet {
481eef7d739SAl Viro 	struct dlm_header	header;		/* common to other two */
482eef7d739SAl Viro 	struct dlm_message	message;
483eef7d739SAl Viro 	struct dlm_rcom		rcom;
484489d8e55SAlexander Aring 	struct dlm_opts		opts;
485eef7d739SAl Viro };
486eef7d739SAl Viro 
487757a4271SDavid Teigland #define DLM_RSF_NEED_SLOTS	0x00000001
488757a4271SDavid Teigland 
489757a4271SDavid Teigland /* RCOM_STATUS data */
490757a4271SDavid Teigland struct rcom_status {
491757a4271SDavid Teigland 	__le32			rs_flags;
492757a4271SDavid Teigland 	__le32			rs_unused1;
493757a4271SDavid Teigland 	__le64			rs_unused2;
494757a4271SDavid Teigland };
495757a4271SDavid Teigland 
496757a4271SDavid Teigland /* RCOM_STATUS_REPLY data */
497e7fd4179SDavid Teigland struct rcom_config {
49893ff2971SAl Viro 	__le32			rf_lvblen;
49993ff2971SAl Viro 	__le32			rf_lsflags;
500757a4271SDavid Teigland 
501757a4271SDavid Teigland 	/* DLM_HEADER_SLOTS adds: */
502757a4271SDavid Teigland 	__le32			rf_flags;
503757a4271SDavid Teigland 	__le16			rf_our_slot;
504757a4271SDavid Teigland 	__le16			rf_num_slots;
505757a4271SDavid Teigland 	__le32			rf_generation;
506757a4271SDavid Teigland 	__le32			rf_unused1;
507757a4271SDavid Teigland 	__le64			rf_unused2;
508757a4271SDavid Teigland };
509757a4271SDavid Teigland 
510757a4271SDavid Teigland struct rcom_slot {
511757a4271SDavid Teigland 	__le32			ro_nodeid;
512757a4271SDavid Teigland 	__le16			ro_slot;
513757a4271SDavid Teigland 	__le16			ro_unused1;
514757a4271SDavid Teigland 	__le64			ro_unused2;
515e7fd4179SDavid Teigland };
516e7fd4179SDavid Teigland 
517e7fd4179SDavid Teigland struct rcom_lock {
518163a1859SAl Viro 	__le32			rl_ownpid;
519163a1859SAl Viro 	__le32			rl_lkid;
520163a1859SAl Viro 	__le32			rl_remid;
521163a1859SAl Viro 	__le32			rl_parent_lkid;
522163a1859SAl Viro 	__le32			rl_parent_remid;
523163a1859SAl Viro 	__le32			rl_exflags;
524163a1859SAl Viro 	__le32			rl_flags;
525163a1859SAl Viro 	__le32			rl_lvbseq;
526163a1859SAl Viro 	__le32			rl_result;
527e7fd4179SDavid Teigland 	int8_t			rl_rqmode;
528e7fd4179SDavid Teigland 	int8_t			rl_grmode;
529e7fd4179SDavid Teigland 	int8_t			rl_status;
530e7fd4179SDavid Teigland 	int8_t			rl_asts;
531163a1859SAl Viro 	__le16			rl_wait_type;
532163a1859SAl Viro 	__le16			rl_namelen;
533e7fd4179SDavid Teigland 	char			rl_name[DLM_RESNAME_MAXLEN];
534a4e439a6SGustavo A. R. Silva 	char			rl_lvb[];
535e7fd4179SDavid Teigland };
536e7fd4179SDavid Teigland 
53705c32f47SDavid Teigland /*
53805c32f47SDavid Teigland  * The max number of resources per rsbtbl bucket that shrink will attempt
53905c32f47SDavid Teigland  * to remove in each iteration.
54005c32f47SDavid Teigland  */
54105c32f47SDavid Teigland 
54205c32f47SDavid Teigland #define DLM_REMOVE_NAMES_MAX 8
54305c32f47SDavid Teigland 
544e7fd4179SDavid Teigland struct dlm_ls {
545e7fd4179SDavid Teigland 	struct list_head	ls_list;	/* list of lockspaces */
546597d0caeSDavid Teigland 	dlm_lockspace_t		*ls_local_handle;
547e7fd4179SDavid Teigland 	uint32_t		ls_global_id;	/* global unique lockspace ID */
548757a4271SDavid Teigland 	uint32_t		ls_generation;
549e7fd4179SDavid Teigland 	uint32_t		ls_exflags;
550e7fd4179SDavid Teigland 	int			ls_lvblen;
5510f8e0d9aSDavid Teigland 	int			ls_count;	/* refcount of processes in
5520f8e0d9aSDavid Teigland 						   the dlm using this ls */
5530f8e0d9aSDavid Teigland 	int			ls_create_count; /* create/release refcount */
554e7fd4179SDavid Teigland 	unsigned long		ls_flags;	/* LSFL_ */
555c1dcf65fSDavid Teigland 	unsigned long		ls_scan_time;
556e7fd4179SDavid Teigland 	struct kobject		ls_kobj;
557e7fd4179SDavid Teigland 
5583d6aa675SDavid Teigland 	struct idr		ls_lkbidr;
5593d6aa675SDavid Teigland 	spinlock_t		ls_lkbidr_spin;
5603d6aa675SDavid Teigland 
561e7fd4179SDavid Teigland 	struct dlm_rsbtable	*ls_rsbtbl;
562e7fd4179SDavid Teigland 	uint32_t		ls_rsbtbl_size;
563e7fd4179SDavid Teigland 
56490135925SDavid Teigland 	struct mutex		ls_waiters_mutex;
565e7fd4179SDavid Teigland 	struct list_head	ls_waiters;	/* lkbs needing a reply */
566e7fd4179SDavid Teigland 
567ef0c2bb0SDavid Teigland 	struct mutex		ls_orphans_mutex;
568ef0c2bb0SDavid Teigland 	struct list_head	ls_orphans;
569ef0c2bb0SDavid Teigland 
5703ae1acf9SDavid Teigland 	struct mutex		ls_timeout_mutex;
5713ae1acf9SDavid Teigland 	struct list_head	ls_timeout;
5723ae1acf9SDavid Teigland 
5733881ac04SDavid Teigland 	spinlock_t		ls_new_rsb_spin;
5743881ac04SDavid Teigland 	int			ls_new_rsb_count;
5753881ac04SDavid Teigland 	struct list_head	ls_new_rsb;	/* new rsb structs */
5763881ac04SDavid Teigland 
57705c32f47SDavid Teigland 	spinlock_t		ls_remove_spin;
57805c32f47SDavid Teigland 	char			ls_remove_name[DLM_RESNAME_MAXLEN+1];
57905c32f47SDavid Teigland 	char			*ls_remove_names[DLM_REMOVE_NAMES_MAX];
58005c32f47SDavid Teigland 	int			ls_remove_len;
58105c32f47SDavid Teigland 	int			ls_remove_lens[DLM_REMOVE_NAMES_MAX];
58205c32f47SDavid Teigland 
583e7fd4179SDavid Teigland 	struct list_head	ls_nodes;	/* current nodes in ls */
584e7fd4179SDavid Teigland 	struct list_head	ls_nodes_gone;	/* dead node list, recovery */
585e7fd4179SDavid Teigland 	int			ls_num_nodes;	/* number of nodes in ls */
586e7fd4179SDavid Teigland 	int			ls_low_nodeid;
587e7fd4179SDavid Teigland 	int			ls_total_weight;
588e7fd4179SDavid Teigland 	int			*ls_node_array;
589e7fd4179SDavid Teigland 
590757a4271SDavid Teigland 	int			ls_slot;
591757a4271SDavid Teigland 	int			ls_num_slots;
592757a4271SDavid Teigland 	int			ls_slots_size;
593757a4271SDavid Teigland 	struct dlm_slot		*ls_slots;
594757a4271SDavid Teigland 
595e7fd4179SDavid Teigland 	struct dlm_rsb		ls_stub_rsb;	/* for returning errors */
596e7fd4179SDavid Teigland 	struct dlm_lkb		ls_stub_lkb;	/* for returning errors */
597e7fd4179SDavid Teigland 	struct dlm_message	ls_stub_ms;	/* for faking a reply */
598e7fd4179SDavid Teigland 
5995de6319bSDavid Teigland 	struct dentry		*ls_debug_rsb_dentry; /* debugfs */
6005de6319bSDavid Teigland 	struct dentry		*ls_debug_waiters_dentry; /* debugfs */
601ac90a255SDavid Teigland 	struct dentry		*ls_debug_locks_dentry; /* debugfs */
602d022509dSDavid Teigland 	struct dentry		*ls_debug_all_dentry; /* debugfs */
603c04fecb4SDavid Teigland 	struct dentry		*ls_debug_toss_dentry; /* debugfs */
604e7fd4179SDavid Teigland 
605e7fd4179SDavid Teigland 	wait_queue_head_t	ls_uevent_wait;	/* user part of join/leave */
606e7fd4179SDavid Teigland 	int			ls_uevent_result;
6078b0e7b2cSDavid Teigland 	struct completion	ls_members_done;
6088b0e7b2cSDavid Teigland 	int			ls_members_result;
609e7fd4179SDavid Teigland 
610597d0caeSDavid Teigland 	struct miscdevice       ls_device;
611597d0caeSDavid Teigland 
61223e8e1aaSDavid Teigland 	struct workqueue_struct	*ls_callback_wq;
61323e8e1aaSDavid Teigland 
614e7fd4179SDavid Teigland 	/* recovery related */
615e7fd4179SDavid Teigland 
61623e8e1aaSDavid Teigland 	struct mutex		ls_cb_mutex;
61723e8e1aaSDavid Teigland 	struct list_head	ls_cb_delay; /* save for queue_work later */
618e7fd4179SDavid Teigland 	struct timer_list	ls_timer;
619e7fd4179SDavid Teigland 	struct task_struct	*ls_recoverd_task;
62090135925SDavid Teigland 	struct mutex		ls_recoverd_active;
621e7fd4179SDavid Teigland 	spinlock_t		ls_recover_lock;
6223ae1acf9SDavid Teigland 	unsigned long		ls_recover_begin; /* jiffies timestamp */
623e7fd4179SDavid Teigland 	uint32_t		ls_recover_status; /* DLM_RS_ */
624e7fd4179SDavid Teigland 	uint64_t		ls_recover_seq;
625e7fd4179SDavid Teigland 	struct dlm_recover	*ls_recover_args;
626e7fd4179SDavid Teigland 	struct rw_semaphore	ls_in_recovery;	/* block local requests */
627c36258b5SDavid Teigland 	struct rw_semaphore	ls_recv_active;	/* block dlm_recv */
628e7fd4179SDavid Teigland 	struct list_head	ls_requestqueue;/* queue remote requests */
629*164d88abSAlexander Aring 	atomic_t		ls_requestqueue_cnt;
630*164d88abSAlexander Aring 	wait_queue_head_t	ls_requestqueue_wait;
63190135925SDavid Teigland 	struct mutex		ls_requestqueue_mutex;
6324007685cSAl Viro 	struct dlm_rcom		*ls_recover_buf;
633faa0f267SDavid Teigland 	int			ls_recover_nodeid; /* for debugging */
634c04fecb4SDavid Teigland 	unsigned int		ls_recover_dir_sent_res; /* for log info */
635c04fecb4SDavid Teigland 	unsigned int		ls_recover_dir_sent_msg; /* for log info */
6364875647aSDavid Teigland 	unsigned int		ls_recover_locks_in; /* for log info */
6374a99c3d9SDavid Teigland 	uint64_t		ls_rcom_seq;
63898f176fbSDavid Teigland 	spinlock_t		ls_rcom_spin;
639e7fd4179SDavid Teigland 	struct list_head	ls_recover_list;
640e7fd4179SDavid Teigland 	spinlock_t		ls_recover_list_lock;
641e7fd4179SDavid Teigland 	int			ls_recover_list_count;
6421d7c484eSDavid Teigland 	struct idr		ls_recover_idr;
6431d7c484eSDavid Teigland 	spinlock_t		ls_recover_idr_lock;
644e7fd4179SDavid Teigland 	wait_queue_head_t	ls_wait_general;
645475f230cSDavid Teigland 	wait_queue_head_t	ls_recover_lock_wait;
646597d0caeSDavid Teigland 	struct mutex		ls_clear_proc_locks;
647e7fd4179SDavid Teigland 
648e7fd4179SDavid Teigland 	struct list_head	ls_root_list;	/* root resources */
649e7fd4179SDavid Teigland 	struct rw_semaphore	ls_root_sem;	/* protect root_list */
650e7fd4179SDavid Teigland 
65160f98d18SDavid Teigland 	const struct dlm_lockspace_ops *ls_ops;
65260f98d18SDavid Teigland 	void			*ls_ops_arg;
65360f98d18SDavid Teigland 
654e7fd4179SDavid Teigland 	int			ls_namelen;
655e7fd4179SDavid Teigland 	char			ls_name[1];
656e7fd4179SDavid Teigland };
657e7fd4179SDavid Teigland 
658475f230cSDavid Teigland /*
659475f230cSDavid Teigland  * LSFL_RECOVER_STOP - dlm_ls_stop() sets this to tell dlm recovery routines
660475f230cSDavid Teigland  * that they should abort what they're doing so new recovery can be started.
661475f230cSDavid Teigland  *
662475f230cSDavid Teigland  * LSFL_RECOVER_DOWN - dlm_ls_stop() sets this to tell dlm_recoverd that it
663475f230cSDavid Teigland  * should do down_write() on the in_recovery rw_semaphore. (doing down_write
664475f230cSDavid Teigland  * within dlm_ls_stop causes complaints about the lock acquired/released
665475f230cSDavid Teigland  * in different contexts.)
666475f230cSDavid Teigland  *
667475f230cSDavid Teigland  * LSFL_RECOVER_LOCK - dlm_recoverd holds the in_recovery rw_semaphore.
668475f230cSDavid Teigland  * It sets this after it is done with down_write() on the in_recovery
669475f230cSDavid Teigland  * rw_semaphore and clears it after it has released the rw_semaphore.
670475f230cSDavid Teigland  *
671475f230cSDavid Teigland  * LSFL_RECOVER_WORK - dlm_ls_start() sets this to tell dlm_recoverd that it
672475f230cSDavid Teigland  * should begin recovery of the lockspace.
673475f230cSDavid Teigland  *
674475f230cSDavid Teigland  * LSFL_RUNNING - set when normal locking activity is enabled.
675475f230cSDavid Teigland  * dlm_ls_stop() clears this to tell dlm locking routines that they should
676475f230cSDavid Teigland  * quit what they are doing so recovery can run.  dlm_recoverd sets
677475f230cSDavid Teigland  * this after recovery is finished.
678475f230cSDavid Teigland  */
679475f230cSDavid Teigland 
680475f230cSDavid Teigland #define LSFL_RECOVER_STOP	0
681475f230cSDavid Teigland #define LSFL_RECOVER_DOWN	1
682475f230cSDavid Teigland #define LSFL_RECOVER_LOCK	2
683475f230cSDavid Teigland #define LSFL_RECOVER_WORK	3
684475f230cSDavid Teigland #define LSFL_RUNNING		4
685475f230cSDavid Teigland 
686475f230cSDavid Teigland #define LSFL_RCOM_READY		5
687475f230cSDavid Teigland #define LSFL_RCOM_WAIT		6
688475f230cSDavid Teigland #define LSFL_UEVENT_WAIT	7
689475f230cSDavid Teigland #define LSFL_TIMEWARN		8
690475f230cSDavid Teigland #define LSFL_CB_DELAY		9
691475f230cSDavid Teigland #define LSFL_NODIR		10
692e7fd4179SDavid Teigland 
693597d0caeSDavid Teigland /* much of this is just saving user space pointers associated with the
694597d0caeSDavid Teigland    lock that we pass back to the user lib with an ast */
695597d0caeSDavid Teigland 
696597d0caeSDavid Teigland struct dlm_user_args {
697597d0caeSDavid Teigland 	struct dlm_user_proc	*proc; /* each process that opens the lockspace
698597d0caeSDavid Teigland 					  device has private data
699597d0caeSDavid Teigland 					  (dlm_user_proc) on the struct file,
700597d0caeSDavid Teigland 					  the process's locks point back to it*/
701597d0caeSDavid Teigland 	struct dlm_lksb		lksb;
702597d0caeSDavid Teigland 	struct dlm_lksb __user	*user_lksb;
703597d0caeSDavid Teigland 	void __user		*castparam;
704597d0caeSDavid Teigland 	void __user		*castaddr;
705597d0caeSDavid Teigland 	void __user		*bastparam;
706597d0caeSDavid Teigland 	void __user		*bastaddr;
707d7db923eSDavid Teigland 	uint64_t		xid;
708597d0caeSDavid Teigland };
709597d0caeSDavid Teigland 
710597d0caeSDavid Teigland #define DLM_PROC_FLAGS_CLOSING 1
711597d0caeSDavid Teigland #define DLM_PROC_FLAGS_COMPAT  2
712597d0caeSDavid Teigland 
713597d0caeSDavid Teigland /* locks list is kept so we can remove all a process's locks when it
714597d0caeSDavid Teigland    exits (or orphan those that are persistent) */
715597d0caeSDavid Teigland 
716597d0caeSDavid Teigland struct dlm_user_proc {
717597d0caeSDavid Teigland 	dlm_lockspace_t		*lockspace;
718597d0caeSDavid Teigland 	unsigned long		flags; /* DLM_PROC_FLAGS */
719597d0caeSDavid Teigland 	struct list_head	asts;
720597d0caeSDavid Teigland 	spinlock_t		asts_spin;
721597d0caeSDavid Teigland 	struct list_head	locks;
722597d0caeSDavid Teigland 	spinlock_t		locks_spin;
723a1bc86e6SDavid Teigland 	struct list_head	unlocking;
724597d0caeSDavid Teigland 	wait_queue_head_t	wait;
725597d0caeSDavid Teigland };
726597d0caeSDavid Teigland 
727e7fd4179SDavid Teigland static inline int dlm_locking_stopped(struct dlm_ls *ls)
728e7fd4179SDavid Teigland {
729e7fd4179SDavid Teigland 	return !test_bit(LSFL_RUNNING, &ls->ls_flags);
730e7fd4179SDavid Teigland }
731e7fd4179SDavid Teigland 
732e7fd4179SDavid Teigland static inline int dlm_recovery_stopped(struct dlm_ls *ls)
733e7fd4179SDavid Teigland {
734475f230cSDavid Teigland 	return test_bit(LSFL_RECOVER_STOP, &ls->ls_flags);
735e7fd4179SDavid Teigland }
736e7fd4179SDavid Teigland 
737e7fd4179SDavid Teigland static inline int dlm_no_directory(struct dlm_ls *ls)
738e7fd4179SDavid Teigland {
7394875647aSDavid Teigland 	return test_bit(LSFL_NODIR, &ls->ls_flags);
740e7fd4179SDavid Teigland }
741e7fd4179SDavid Teigland 
742e028398dSAdrian Bunk int dlm_netlink_init(void);
743e028398dSAdrian Bunk void dlm_netlink_exit(void);
744e028398dSAdrian Bunk void dlm_timeout_warn(struct dlm_lkb *lkb);
7452402211aSDavid Teigland int dlm_plock_init(void);
7462402211aSDavid Teigland void dlm_plock_exit(void);
747e028398dSAdrian Bunk 
748e028398dSAdrian Bunk #ifdef CONFIG_DLM_DEBUG
749a48f9721SGreg Kroah-Hartman void dlm_register_debugfs(void);
750e028398dSAdrian Bunk void dlm_unregister_debugfs(void);
751a48f9721SGreg Kroah-Hartman void dlm_create_debug_file(struct dlm_ls *ls);
752e028398dSAdrian Bunk void dlm_delete_debug_file(struct dlm_ls *ls);
7535b2f981fSAlexander Aring void *dlm_create_debug_comms_file(int nodeid, void *data);
7545b2f981fSAlexander Aring void dlm_delete_debug_comms_file(void *ctx);
755e028398dSAdrian Bunk #else
756a48f9721SGreg Kroah-Hartman static inline void dlm_register_debugfs(void) { }
757e028398dSAdrian Bunk static inline void dlm_unregister_debugfs(void) { }
758a48f9721SGreg Kroah-Hartman static inline void dlm_create_debug_file(struct dlm_ls *ls) { }
759e028398dSAdrian Bunk static inline void dlm_delete_debug_file(struct dlm_ls *ls) { }
7605b2f981fSAlexander Aring static inline void *dlm_create_debug_comms_file(int nodeid, void *data) { return NULL; }
7615b2f981fSAlexander Aring static inline void dlm_delete_debug_comms_file(void *ctx) { }
762e028398dSAdrian Bunk #endif
763e028398dSAdrian Bunk 
764e7fd4179SDavid Teigland #endif				/* __DLM_INTERNAL_DOT_H__ */
765e7fd4179SDavid Teigland 
766