xref: /openbmc/linux/fs/dlm/dlm_internal.h (revision 475f230c6072fb2186f48b23943afcd0ee3a8343)
1e7fd4179SDavid Teigland /******************************************************************************
2e7fd4179SDavid Teigland *******************************************************************************
3e7fd4179SDavid Teigland **
4e7fd4179SDavid Teigland **  Copyright (C) Sistina Software, Inc.  1997-2003  All rights reserved.
560f98d18SDavid Teigland **  Copyright (C) 2004-2011 Red Hat, Inc.  All rights reserved.
6e7fd4179SDavid Teigland **
7e7fd4179SDavid Teigland **  This copyrighted material is made available to anyone wishing to use,
8e7fd4179SDavid Teigland **  modify, copy, or redistribute it subject to the terms and conditions
9e7fd4179SDavid Teigland **  of the GNU General Public License v.2.
10e7fd4179SDavid Teigland **
11e7fd4179SDavid Teigland *******************************************************************************
12e7fd4179SDavid Teigland ******************************************************************************/
13e7fd4179SDavid Teigland 
14e7fd4179SDavid Teigland #ifndef __DLM_INTERNAL_DOT_H__
15e7fd4179SDavid Teigland #define __DLM_INTERNAL_DOT_H__
16e7fd4179SDavid Teigland 
17e7fd4179SDavid Teigland /*
18e7fd4179SDavid Teigland  * This is the main header file to be included in each DLM source file.
19e7fd4179SDavid Teigland  */
20e7fd4179SDavid Teigland 
21e7fd4179SDavid Teigland #include <linux/module.h>
22e7fd4179SDavid Teigland #include <linux/slab.h>
23e7fd4179SDavid Teigland #include <linux/sched.h>
24e7fd4179SDavid Teigland #include <linux/types.h>
25e7fd4179SDavid Teigland #include <linux/ctype.h>
26e7fd4179SDavid Teigland #include <linux/spinlock.h>
27e7fd4179SDavid Teigland #include <linux/vmalloc.h>
28e7fd4179SDavid Teigland #include <linux/list.h>
29e7fd4179SDavid Teigland #include <linux/errno.h>
30e7fd4179SDavid Teigland #include <linux/random.h>
31e7fd4179SDavid Teigland #include <linux/delay.h>
32e7fd4179SDavid Teigland #include <linux/socket.h>
33e7fd4179SDavid Teigland #include <linux/kthread.h>
34e7fd4179SDavid Teigland #include <linux/kobject.h>
35e7fd4179SDavid Teigland #include <linux/kref.h>
36e7fd4179SDavid Teigland #include <linux/kernel.h>
37e7fd4179SDavid Teigland #include <linux/jhash.h>
38597d0caeSDavid Teigland #include <linux/miscdevice.h>
3990135925SDavid Teigland #include <linux/mutex.h>
403d6aa675SDavid Teigland #include <linux/idr.h>
41d6e24788SDavid Teigland #include <linux/ratelimit.h>
42e7fd4179SDavid Teigland #include <asm/uaccess.h>
43e7fd4179SDavid Teigland 
44e7fd4179SDavid Teigland #include <linux/dlm.h>
4599fc6487SDavid Teigland #include "config.h"
46e7fd4179SDavid Teigland 
47e7fd4179SDavid Teigland /* Size of the temp buffer midcomms allocates on the stack.
48e7fd4179SDavid Teigland    We try to make this large enough so most messages fit.
49e7fd4179SDavid Teigland    FIXME: should sctp make this unnecessary? */
50e7fd4179SDavid Teigland 
51e7fd4179SDavid Teigland #define DLM_INBUF_LEN		148
52e7fd4179SDavid Teigland 
53e7fd4179SDavid Teigland struct dlm_ls;
54e7fd4179SDavid Teigland struct dlm_lkb;
55e7fd4179SDavid Teigland struct dlm_rsb;
56e7fd4179SDavid Teigland struct dlm_member;
57e7fd4179SDavid Teigland struct dlm_rsbtable;
58e7fd4179SDavid Teigland struct dlm_recover;
59e7fd4179SDavid Teigland struct dlm_header;
60e7fd4179SDavid Teigland struct dlm_message;
61e7fd4179SDavid Teigland struct dlm_rcom;
62e7fd4179SDavid Teigland struct dlm_mhandle;
63e7fd4179SDavid Teigland 
64e7fd4179SDavid Teigland #define log_print(fmt, args...) \
65e7fd4179SDavid Teigland 	printk(KERN_ERR "dlm: "fmt"\n" , ##args)
66e7fd4179SDavid Teigland #define log_error(ls, fmt, args...) \
67e7fd4179SDavid Teigland 	printk(KERN_ERR "dlm: %s: " fmt "\n", (ls)->ls_name , ##args)
68e7fd4179SDavid Teigland 
6999fc6487SDavid Teigland #define log_debug(ls, fmt, args...) \
7099fc6487SDavid Teigland do { \
7199fc6487SDavid Teigland 	if (dlm_config.ci_log_debug) \
7299fc6487SDavid Teigland 		printk(KERN_DEBUG "dlm: %s: " fmt "\n", \
7399fc6487SDavid Teigland 		       (ls)->ls_name , ##args); \
7499fc6487SDavid Teigland } while (0)
75e7fd4179SDavid Teigland 
76d6e24788SDavid Teigland #define log_limit(ls, fmt, args...) \
77d6e24788SDavid Teigland do { \
78d6e24788SDavid Teigland 	if (dlm_config.ci_log_debug) \
79d6e24788SDavid Teigland 		printk_ratelimited(KERN_DEBUG "dlm: %s: " fmt "\n", \
80d6e24788SDavid Teigland 			(ls)->ls_name , ##args); \
81d6e24788SDavid Teigland } while (0)
82d6e24788SDavid Teigland 
83e7fd4179SDavid Teigland #define DLM_ASSERT(x, do) \
84e7fd4179SDavid Teigland { \
85e7fd4179SDavid Teigland   if (!(x)) \
86e7fd4179SDavid Teigland   { \
87e7fd4179SDavid Teigland     printk(KERN_ERR "\nDLM:  Assertion failed on line %d of file %s\n" \
88e7fd4179SDavid Teigland                "DLM:  assertion:  \"%s\"\n" \
89e7fd4179SDavid Teigland                "DLM:  time = %lu\n", \
90e7fd4179SDavid Teigland                __LINE__, __FILE__, #x, jiffies); \
91e7fd4179SDavid Teigland     {do} \
92e7fd4179SDavid Teigland     printk("\n"); \
93e7fd4179SDavid Teigland     BUG(); \
94e7fd4179SDavid Teigland     panic("DLM:  Record message above and reboot.\n"); \
95e7fd4179SDavid Teigland   } \
96e7fd4179SDavid Teigland }
97e7fd4179SDavid Teigland 
98e7fd4179SDavid Teigland 
99e7fd4179SDavid Teigland struct dlm_rsbtable {
1009beb3bf5SBob Peterson 	struct rb_root		keep;
1019beb3bf5SBob Peterson 	struct rb_root		toss;
102c7be761aSDavid Teigland 	spinlock_t		lock;
103e7fd4179SDavid Teigland };
104e7fd4179SDavid Teigland 
105e7fd4179SDavid Teigland 
106e7fd4179SDavid Teigland /*
107e7fd4179SDavid Teigland  * Lockspace member (per node in a ls)
108e7fd4179SDavid Teigland  */
109e7fd4179SDavid Teigland 
110e7fd4179SDavid Teigland struct dlm_member {
111e7fd4179SDavid Teigland 	struct list_head	list;
112e7fd4179SDavid Teigland 	int			nodeid;
113e7fd4179SDavid Teigland 	int			weight;
114757a4271SDavid Teigland 	int			slot;
115757a4271SDavid Teigland 	int			slot_prev;
11660f98d18SDavid Teigland 	int			comm_seq;
117757a4271SDavid Teigland 	uint32_t		generation;
118757a4271SDavid Teigland };
119757a4271SDavid Teigland 
120757a4271SDavid Teigland /*
121e7fd4179SDavid Teigland  * Save and manage recovery state for a lockspace.
122e7fd4179SDavid Teigland  */
123e7fd4179SDavid Teigland 
124e7fd4179SDavid Teigland struct dlm_recover {
125e7fd4179SDavid Teigland 	struct list_head	list;
12660f98d18SDavid Teigland 	struct dlm_config_node	*nodes;
12760f98d18SDavid Teigland 	int			nodes_count;
128e7fd4179SDavid Teigland 	uint64_t		seq;
129e7fd4179SDavid Teigland };
130e7fd4179SDavid Teigland 
131e7fd4179SDavid Teigland /*
132e7fd4179SDavid Teigland  * Pass input args to second stage locking function.
133e7fd4179SDavid Teigland  */
134e7fd4179SDavid Teigland 
135e7fd4179SDavid Teigland struct dlm_args {
136e7fd4179SDavid Teigland 	uint32_t		flags;
137e5dae548SDavid Teigland 	void			(*astfn) (void *astparam);
138e5dae548SDavid Teigland 	void			*astparam;
139e5dae548SDavid Teigland 	void			(*bastfn) (void *astparam, int mode);
140e7fd4179SDavid Teigland 	int			mode;
141e7fd4179SDavid Teigland 	struct dlm_lksb		*lksb;
142d7db923eSDavid Teigland 	unsigned long		timeout;
143e7fd4179SDavid Teigland };
144e7fd4179SDavid Teigland 
145e7fd4179SDavid Teigland 
146e7fd4179SDavid Teigland /*
147e7fd4179SDavid Teigland  * Lock block
148e7fd4179SDavid Teigland  *
149e7fd4179SDavid Teigland  * A lock can be one of three types:
150e7fd4179SDavid Teigland  *
151e7fd4179SDavid Teigland  * local copy      lock is mastered locally
152e7fd4179SDavid Teigland  *                 (lkb_nodeid is zero and DLM_LKF_MSTCPY is not set)
153e7fd4179SDavid Teigland  * process copy    lock is mastered on a remote node
154e7fd4179SDavid Teigland  *                 (lkb_nodeid is non-zero and DLM_LKF_MSTCPY is not set)
155e7fd4179SDavid Teigland  * master copy     master node's copy of a lock owned by remote node
156e7fd4179SDavid Teigland  *                 (lkb_nodeid is non-zero and DLM_LKF_MSTCPY is set)
157e7fd4179SDavid Teigland  *
158e7fd4179SDavid Teigland  * lkb_exflags: a copy of the most recent flags arg provided to dlm_lock or
159e7fd4179SDavid Teigland  * dlm_unlock.  The dlm does not modify these or use any private flags in
160e7fd4179SDavid Teigland  * this field; it only contains DLM_LKF_ flags from dlm.h.  These flags
161e7fd4179SDavid Teigland  * are sent as-is to the remote master when the lock is remote.
162e7fd4179SDavid Teigland  *
163e7fd4179SDavid Teigland  * lkb_flags: internal dlm flags (DLM_IFL_ prefix) from dlm_internal.h.
164e7fd4179SDavid Teigland  * Some internal flags are shared between the master and process nodes;
165e7fd4179SDavid Teigland  * these shared flags are kept in the lower two bytes.  One of these
166e7fd4179SDavid Teigland  * flags set on the master copy will be propagated to the process copy
167e7fd4179SDavid Teigland  * and v.v.  Other internal flags are private to the master or process
168e7fd4179SDavid Teigland  * node (e.g. DLM_IFL_MSTCPY).  These are kept in the high two bytes.
169e7fd4179SDavid Teigland  *
170e7fd4179SDavid Teigland  * lkb_sbflags: status block flags.  These flags are copied directly into
171e7fd4179SDavid Teigland  * the caller's lksb.sb_flags prior to the dlm_lock/dlm_unlock completion
172e7fd4179SDavid Teigland  * ast.  All defined in dlm.h with DLM_SBF_ prefix.
173e7fd4179SDavid Teigland  *
174e7fd4179SDavid Teigland  * lkb_status: the lock status indicates which rsb queue the lock is
175e7fd4179SDavid Teigland  * on, grant, convert, or wait.  DLM_LKSTS_ WAITING/GRANTED/CONVERT
176e7fd4179SDavid Teigland  *
177e7fd4179SDavid Teigland  * lkb_wait_type: the dlm message type (DLM_MSG_ prefix) for which a
178e7fd4179SDavid Teigland  * reply is needed.  Only set when the lkb is on the lockspace waiters
179e7fd4179SDavid Teigland  * list awaiting a reply from a remote node.
180e7fd4179SDavid Teigland  *
181e7fd4179SDavid Teigland  * lkb_nodeid: when the lkb is a local copy, nodeid is 0; when the lkb
182e7fd4179SDavid Teigland  * is a master copy, nodeid specifies the remote lock holder, when the
183e7fd4179SDavid Teigland  * lkb is a process copy, the nodeid specifies the lock master.
184e7fd4179SDavid Teigland  */
185e7fd4179SDavid Teigland 
186e7fd4179SDavid Teigland /* lkb_status */
187e7fd4179SDavid Teigland 
188e7fd4179SDavid Teigland #define DLM_LKSTS_WAITING	1
189e7fd4179SDavid Teigland #define DLM_LKSTS_GRANTED	2
190e7fd4179SDavid Teigland #define DLM_LKSTS_CONVERT	3
191e7fd4179SDavid Teigland 
192e7fd4179SDavid Teigland /* lkb_flags */
193e7fd4179SDavid Teigland 
194e7fd4179SDavid Teigland #define DLM_IFL_MSTCPY		0x00010000
195e7fd4179SDavid Teigland #define DLM_IFL_RESEND		0x00020000
196597d0caeSDavid Teigland #define DLM_IFL_DEAD		0x00040000
197ef0c2bb0SDavid Teigland #define DLM_IFL_OVERLAP_UNLOCK  0x00080000
198ef0c2bb0SDavid Teigland #define DLM_IFL_OVERLAP_CANCEL  0x00100000
199ef0c2bb0SDavid Teigland #define DLM_IFL_ENDOFLIFE	0x00200000
2003ae1acf9SDavid Teigland #define DLM_IFL_WATCH_TIMEWARN	0x00400000
20184d8cd69SDavid Teigland #define DLM_IFL_TIMEOUT_CANCEL	0x00800000
2028b4021faSDavid Teigland #define DLM_IFL_DEADLOCK_CANCEL	0x01000000
2032a7ce0edSDavid Teigland #define DLM_IFL_STUB_MS		0x02000000 /* magic number for m_flags */
204597d0caeSDavid Teigland #define DLM_IFL_USER		0x00000001
205597d0caeSDavid Teigland #define DLM_IFL_ORPHAN		0x00000002
206e7fd4179SDavid Teigland 
2078304d6f2SDavid Teigland #define DLM_CALLBACKS_SIZE	6
2088304d6f2SDavid Teigland 
2098304d6f2SDavid Teigland #define DLM_CB_CAST		0x00000001
2108304d6f2SDavid Teigland #define DLM_CB_BAST		0x00000002
2118304d6f2SDavid Teigland #define DLM_CB_SKIP		0x00000004
2128304d6f2SDavid Teigland 
2138304d6f2SDavid Teigland struct dlm_callback {
2148304d6f2SDavid Teigland 	uint64_t		seq;
2158304d6f2SDavid Teigland 	uint32_t		flags;		/* DLM_CBF_ */
2168304d6f2SDavid Teigland 	int			sb_status;	/* copy to lksb status */
2178304d6f2SDavid Teigland 	uint8_t			sb_flags;	/* copy to lksb flags */
2188304d6f2SDavid Teigland 	int8_t			mode; /* rq mode of bast, gr mode of cast */
2198304d6f2SDavid Teigland };
2208304d6f2SDavid Teigland 
221e7fd4179SDavid Teigland struct dlm_lkb {
222e7fd4179SDavid Teigland 	struct dlm_rsb		*lkb_resource;	/* the rsb */
223e7fd4179SDavid Teigland 	struct kref		lkb_ref;
224e7fd4179SDavid Teigland 	int			lkb_nodeid;	/* copied from rsb */
225e7fd4179SDavid Teigland 	int			lkb_ownpid;	/* pid of lock owner */
226e7fd4179SDavid Teigland 	uint32_t		lkb_id;		/* our lock ID */
227e7fd4179SDavid Teigland 	uint32_t		lkb_remid;	/* lock ID on remote partner */
228e7fd4179SDavid Teigland 	uint32_t		lkb_exflags;	/* external flags from caller */
229e7fd4179SDavid Teigland 	uint32_t		lkb_sbflags;	/* lksb flags */
230e7fd4179SDavid Teigland 	uint32_t		lkb_flags;	/* internal flags */
231e7fd4179SDavid Teigland 	uint32_t		lkb_lvbseq;	/* lvb sequence number */
232e7fd4179SDavid Teigland 
233e7fd4179SDavid Teigland 	int8_t			lkb_status;     /* granted, waiting, convert */
234e7fd4179SDavid Teigland 	int8_t			lkb_rqmode;	/* requested lock mode */
235e7fd4179SDavid Teigland 	int8_t			lkb_grmode;	/* granted lock mode */
236e7fd4179SDavid Teigland 	int8_t			lkb_highbast;	/* highest mode bast sent for */
2377fe2b319SDavid Teigland 
238e7fd4179SDavid Teigland 	int8_t			lkb_wait_type;	/* type of reply waiting for */
239ef0c2bb0SDavid Teigland 	int8_t			lkb_wait_count;
240c6ff669bSDavid Teigland 	int			lkb_wait_nodeid; /* for debugging */
241e7fd4179SDavid Teigland 
242e7fd4179SDavid Teigland 	struct list_head	lkb_statequeue;	/* rsb g/c/w list */
243e7fd4179SDavid Teigland 	struct list_head	lkb_rsb_lookup;	/* waiting for rsb lookup */
244e7fd4179SDavid Teigland 	struct list_head	lkb_wait_reply;	/* waiting for remote reply */
245597d0caeSDavid Teigland 	struct list_head	lkb_ownqueue;	/* list of locks for a process */
2463ae1acf9SDavid Teigland 	struct list_head	lkb_time_list;
247eeda418dSDavid Teigland 	ktime_t			lkb_timestamp;
248c6ff669bSDavid Teigland 	ktime_t			lkb_wait_time;
2493ae1acf9SDavid Teigland 	unsigned long		lkb_timeout_cs;
250e7fd4179SDavid Teigland 
25123e8e1aaSDavid Teigland 	struct mutex		lkb_cb_mutex;
25223e8e1aaSDavid Teigland 	struct work_struct	lkb_cb_work;
25323e8e1aaSDavid Teigland 	struct list_head	lkb_cb_list; /* for ls_cb_delay or proc->asts */
2548304d6f2SDavid Teigland 	struct dlm_callback	lkb_callbacks[DLM_CALLBACKS_SIZE];
2558304d6f2SDavid Teigland 	struct dlm_callback	lkb_last_cast;
2568304d6f2SDavid Teigland 	struct dlm_callback	lkb_last_bast;
2578304d6f2SDavid Teigland 	ktime_t			lkb_last_cast_time;	/* for debugging */
2588304d6f2SDavid Teigland 	ktime_t			lkb_last_bast_time;	/* for debugging */
2598304d6f2SDavid Teigland 
2604875647aSDavid Teigland 	uint64_t		lkb_recover_seq; /* from ls_recover_seq */
2614875647aSDavid Teigland 
262e7fd4179SDavid Teigland 	char			*lkb_lvbptr;
263e7fd4179SDavid Teigland 	struct dlm_lksb		*lkb_lksb;      /* caller's status block */
264e5dae548SDavid Teigland 	void			(*lkb_astfn) (void *astparam);
265e5dae548SDavid Teigland 	void			(*lkb_bastfn) (void *astparam, int mode);
266d292c0ccSDavid Teigland 	union {
267e5dae548SDavid Teigland 		void			*lkb_astparam;	/* caller's ast arg */
268d292c0ccSDavid Teigland 		struct dlm_user_args	*lkb_ua;
269d292c0ccSDavid Teigland 	};
270e7fd4179SDavid Teigland };
271e7fd4179SDavid Teigland 
272c04fecb4SDavid Teigland /*
273c04fecb4SDavid Teigland  * res_master_nodeid is "normal": 0 is unset/invalid, non-zero is the real
274c04fecb4SDavid Teigland  * nodeid, even when nodeid is our_nodeid.
275c04fecb4SDavid Teigland  *
276c04fecb4SDavid Teigland  * res_nodeid is "odd": -1 is unset/invalid, zero means our_nodeid,
277c04fecb4SDavid Teigland  * greater than zero when another nodeid.
278c04fecb4SDavid Teigland  *
279c04fecb4SDavid Teigland  * (TODO: remove res_nodeid and only use res_master_nodeid)
280c04fecb4SDavid Teigland  */
281e7fd4179SDavid Teigland 
282e7fd4179SDavid Teigland struct dlm_rsb {
283e7fd4179SDavid Teigland 	struct dlm_ls		*res_ls;	/* the lockspace */
284e7fd4179SDavid Teigland 	struct kref		res_ref;
28590135925SDavid Teigland 	struct mutex		res_mutex;
286e7fd4179SDavid Teigland 	unsigned long		res_flags;
287e7fd4179SDavid Teigland 	int			res_length;	/* length of rsb name */
288e7fd4179SDavid Teigland 	int			res_nodeid;
289c04fecb4SDavid Teigland 	int			res_master_nodeid;
290c04fecb4SDavid Teigland 	int			res_dir_nodeid;
2911d7c484eSDavid Teigland 	int			res_id;		/* for ls_recover_idr */
292e7fd4179SDavid Teigland 	uint32_t                res_lvbseq;
293e7fd4179SDavid Teigland 	uint32_t		res_hash;
294e7fd4179SDavid Teigland 	uint32_t		res_bucket;	/* rsbtbl */
295e7fd4179SDavid Teigland 	unsigned long		res_toss_time;
296e7fd4179SDavid Teigland 	uint32_t		res_first_lkid;
297e7fd4179SDavid Teigland 	struct list_head	res_lookup;	/* lkbs waiting on first */
2989beb3bf5SBob Peterson 	union {
2999beb3bf5SBob Peterson 		struct list_head	res_hashchain;
3009beb3bf5SBob Peterson 		struct rb_node		res_hashnode;	/* rsbtbl */
3019beb3bf5SBob Peterson 	};
302e7fd4179SDavid Teigland 	struct list_head	res_grantqueue;
303e7fd4179SDavid Teigland 	struct list_head	res_convertqueue;
304e7fd4179SDavid Teigland 	struct list_head	res_waitqueue;
305e7fd4179SDavid Teigland 
306e7fd4179SDavid Teigland 	struct list_head	res_root_list;	    /* used for recovery */
307e7fd4179SDavid Teigland 	struct list_head	res_recover_list;   /* used for recovery */
308e7fd4179SDavid Teigland 	int			res_recover_locks_count;
309e7fd4179SDavid Teigland 
310e7fd4179SDavid Teigland 	char			*res_lvbptr;
3113881ac04SDavid Teigland 	char			res_name[DLM_RESNAME_MAXLEN+1];
312e7fd4179SDavid Teigland };
313e7fd4179SDavid Teigland 
314c04fecb4SDavid Teigland /* dlm_master_lookup() flags */
315c04fecb4SDavid Teigland 
316c04fecb4SDavid Teigland #define DLM_LU_RECOVER_DIR	1
317c04fecb4SDavid Teigland #define DLM_LU_RECOVER_MASTER	2
318c04fecb4SDavid Teigland 
319c04fecb4SDavid Teigland /* dlm_master_lookup() results */
320c04fecb4SDavid Teigland 
321c04fecb4SDavid Teigland #define DLM_LU_MATCH		1
322c04fecb4SDavid Teigland #define DLM_LU_ADD		2
323c04fecb4SDavid Teigland 
324e7fd4179SDavid Teigland /* find_rsb() flags */
325e7fd4179SDavid Teigland 
326c04fecb4SDavid Teigland #define R_REQUEST		0x00000001
327c04fecb4SDavid Teigland #define R_RECEIVE_REQUEST	0x00000002
328c04fecb4SDavid Teigland #define R_RECEIVE_RECOVER	0x00000004
329e7fd4179SDavid Teigland 
330e7fd4179SDavid Teigland /* rsb_flags */
331e7fd4179SDavid Teigland 
332e7fd4179SDavid Teigland enum rsb_flags {
333e7fd4179SDavid Teigland 	RSB_MASTER_UNCERTAIN,
334e7fd4179SDavid Teigland 	RSB_VALNOTVALID,
335e7fd4179SDavid Teigland 	RSB_VALNOTVALID_PREV,
336e7fd4179SDavid Teigland 	RSB_NEW_MASTER,
337e7fd4179SDavid Teigland 	RSB_NEW_MASTER2,
338e7fd4179SDavid Teigland 	RSB_RECOVER_CONVERT,
3394875647aSDavid Teigland 	RSB_RECOVER_GRANT,
340e7fd4179SDavid Teigland };
341e7fd4179SDavid Teigland 
342e7fd4179SDavid Teigland static inline void rsb_set_flag(struct dlm_rsb *r, enum rsb_flags flag)
343e7fd4179SDavid Teigland {
344e7fd4179SDavid Teigland 	__set_bit(flag, &r->res_flags);
345e7fd4179SDavid Teigland }
346e7fd4179SDavid Teigland 
347e7fd4179SDavid Teigland static inline void rsb_clear_flag(struct dlm_rsb *r, enum rsb_flags flag)
348e7fd4179SDavid Teigland {
349e7fd4179SDavid Teigland 	__clear_bit(flag, &r->res_flags);
350e7fd4179SDavid Teigland }
351e7fd4179SDavid Teigland 
352e7fd4179SDavid Teigland static inline int rsb_flag(struct dlm_rsb *r, enum rsb_flags flag)
353e7fd4179SDavid Teigland {
354e7fd4179SDavid Teigland 	return test_bit(flag, &r->res_flags);
355e7fd4179SDavid Teigland }
356e7fd4179SDavid Teigland 
357e7fd4179SDavid Teigland 
358e7fd4179SDavid Teigland /* dlm_header is first element of all structs sent between nodes */
359e7fd4179SDavid Teigland 
36038aa8b0cSDavid Teigland #define DLM_HEADER_MAJOR	0x00030000
361757a4271SDavid Teigland #define DLM_HEADER_MINOR	0x00000001
362757a4271SDavid Teigland 
363757a4271SDavid Teigland #define DLM_HEADER_SLOTS	0x00000001
364e7fd4179SDavid Teigland 
365e7fd4179SDavid Teigland #define DLM_MSG			1
366e7fd4179SDavid Teigland #define DLM_RCOM		2
367e7fd4179SDavid Teigland 
368e7fd4179SDavid Teigland struct dlm_header {
369e7fd4179SDavid Teigland 	uint32_t		h_version;
370e7fd4179SDavid Teigland 	uint32_t		h_lockspace;
371e7fd4179SDavid Teigland 	uint32_t		h_nodeid;	/* nodeid of sender */
372e7fd4179SDavid Teigland 	uint16_t		h_length;
373e7fd4179SDavid Teigland 	uint8_t			h_cmd;		/* DLM_MSG, DLM_RCOM */
374e7fd4179SDavid Teigland 	uint8_t			h_pad;
375e7fd4179SDavid Teigland };
376e7fd4179SDavid Teigland 
377e7fd4179SDavid Teigland 
378e7fd4179SDavid Teigland #define DLM_MSG_REQUEST		1
379e7fd4179SDavid Teigland #define DLM_MSG_CONVERT		2
380e7fd4179SDavid Teigland #define DLM_MSG_UNLOCK		3
381e7fd4179SDavid Teigland #define DLM_MSG_CANCEL		4
382e7fd4179SDavid Teigland #define DLM_MSG_REQUEST_REPLY	5
383e7fd4179SDavid Teigland #define DLM_MSG_CONVERT_REPLY	6
384e7fd4179SDavid Teigland #define DLM_MSG_UNLOCK_REPLY	7
385e7fd4179SDavid Teigland #define DLM_MSG_CANCEL_REPLY	8
386e7fd4179SDavid Teigland #define DLM_MSG_GRANT		9
387e7fd4179SDavid Teigland #define DLM_MSG_BAST		10
388e7fd4179SDavid Teigland #define DLM_MSG_LOOKUP		11
389e7fd4179SDavid Teigland #define DLM_MSG_REMOVE		12
390e7fd4179SDavid Teigland #define DLM_MSG_LOOKUP_REPLY	13
3918499137dSDavid Teigland #define DLM_MSG_PURGE		14
392e7fd4179SDavid Teigland 
393e7fd4179SDavid Teigland struct dlm_message {
394e7fd4179SDavid Teigland 	struct dlm_header	m_header;
395e7fd4179SDavid Teigland 	uint32_t		m_type;		/* DLM_MSG_ */
396e7fd4179SDavid Teigland 	uint32_t		m_nodeid;
397e7fd4179SDavid Teigland 	uint32_t		m_pid;
398e7fd4179SDavid Teigland 	uint32_t		m_lkid;		/* lkid on sender */
399e7fd4179SDavid Teigland 	uint32_t		m_remid;	/* lkid on receiver */
400e7fd4179SDavid Teigland 	uint32_t		m_parent_lkid;
401e7fd4179SDavid Teigland 	uint32_t		m_parent_remid;
402e7fd4179SDavid Teigland 	uint32_t		m_exflags;
403e7fd4179SDavid Teigland 	uint32_t		m_sbflags;
404e7fd4179SDavid Teigland 	uint32_t		m_flags;
405e7fd4179SDavid Teigland 	uint32_t		m_lvbseq;
406e7fd4179SDavid Teigland 	uint32_t		m_hash;
407e7fd4179SDavid Teigland 	int			m_status;
408e7fd4179SDavid Teigland 	int			m_grmode;
409e7fd4179SDavid Teigland 	int			m_rqmode;
410e7fd4179SDavid Teigland 	int			m_bastmode;
411e7fd4179SDavid Teigland 	int			m_asts;
412e7fd4179SDavid Teigland 	int			m_result;	/* 0 or -EXXX */
413e7fd4179SDavid Teigland 	char			m_extra[0];	/* name or lvb */
414e7fd4179SDavid Teigland };
415e7fd4179SDavid Teigland 
416e7fd4179SDavid Teigland 
417e7fd4179SDavid Teigland #define DLM_RS_NODES		0x00000001
418e7fd4179SDavid Teigland #define DLM_RS_NODES_ALL	0x00000002
419e7fd4179SDavid Teigland #define DLM_RS_DIR		0x00000004
420e7fd4179SDavid Teigland #define DLM_RS_DIR_ALL		0x00000008
421e7fd4179SDavid Teigland #define DLM_RS_LOCKS		0x00000010
422e7fd4179SDavid Teigland #define DLM_RS_LOCKS_ALL	0x00000020
423e7fd4179SDavid Teigland #define DLM_RS_DONE		0x00000040
424e7fd4179SDavid Teigland #define DLM_RS_DONE_ALL		0x00000080
425e7fd4179SDavid Teigland 
426e7fd4179SDavid Teigland #define DLM_RCOM_STATUS		1
427e7fd4179SDavid Teigland #define DLM_RCOM_NAMES		2
428e7fd4179SDavid Teigland #define DLM_RCOM_LOOKUP		3
429e7fd4179SDavid Teigland #define DLM_RCOM_LOCK		4
430e7fd4179SDavid Teigland #define DLM_RCOM_STATUS_REPLY	5
431e7fd4179SDavid Teigland #define DLM_RCOM_NAMES_REPLY	6
432e7fd4179SDavid Teigland #define DLM_RCOM_LOOKUP_REPLY	7
433e7fd4179SDavid Teigland #define DLM_RCOM_LOCK_REPLY	8
434e7fd4179SDavid Teigland 
435e7fd4179SDavid Teigland struct dlm_rcom {
436e7fd4179SDavid Teigland 	struct dlm_header	rc_header;
437e7fd4179SDavid Teigland 	uint32_t		rc_type;	/* DLM_RCOM_ */
438e7fd4179SDavid Teigland 	int			rc_result;	/* multi-purpose */
439e7fd4179SDavid Teigland 	uint64_t		rc_id;		/* match reply with request */
44038aa8b0cSDavid Teigland 	uint64_t		rc_seq;		/* sender's ls_recover_seq */
44138aa8b0cSDavid Teigland 	uint64_t		rc_seq_reply;	/* remote ls_recover_seq */
442e7fd4179SDavid Teigland 	char			rc_buf[0];
443e7fd4179SDavid Teigland };
444e7fd4179SDavid Teigland 
445eef7d739SAl Viro union dlm_packet {
446eef7d739SAl Viro 	struct dlm_header	header;		/* common to other two */
447eef7d739SAl Viro 	struct dlm_message	message;
448eef7d739SAl Viro 	struct dlm_rcom		rcom;
449eef7d739SAl Viro };
450eef7d739SAl Viro 
451757a4271SDavid Teigland #define DLM_RSF_NEED_SLOTS	0x00000001
452757a4271SDavid Teigland 
453757a4271SDavid Teigland /* RCOM_STATUS data */
454757a4271SDavid Teigland struct rcom_status {
455757a4271SDavid Teigland 	__le32			rs_flags;
456757a4271SDavid Teigland 	__le32			rs_unused1;
457757a4271SDavid Teigland 	__le64			rs_unused2;
458757a4271SDavid Teigland };
459757a4271SDavid Teigland 
460757a4271SDavid Teigland /* RCOM_STATUS_REPLY data */
461e7fd4179SDavid Teigland struct rcom_config {
46293ff2971SAl Viro 	__le32			rf_lvblen;
46393ff2971SAl Viro 	__le32			rf_lsflags;
464757a4271SDavid Teigland 
465757a4271SDavid Teigland 	/* DLM_HEADER_SLOTS adds: */
466757a4271SDavid Teigland 	__le32			rf_flags;
467757a4271SDavid Teigland 	__le16			rf_our_slot;
468757a4271SDavid Teigland 	__le16			rf_num_slots;
469757a4271SDavid Teigland 	__le32			rf_generation;
470757a4271SDavid Teigland 	__le32			rf_unused1;
471757a4271SDavid Teigland 	__le64			rf_unused2;
472757a4271SDavid Teigland };
473757a4271SDavid Teigland 
474757a4271SDavid Teigland struct rcom_slot {
475757a4271SDavid Teigland 	__le32			ro_nodeid;
476757a4271SDavid Teigland 	__le16			ro_slot;
477757a4271SDavid Teigland 	__le16			ro_unused1;
478757a4271SDavid Teigland 	__le64			ro_unused2;
479e7fd4179SDavid Teigland };
480e7fd4179SDavid Teigland 
481e7fd4179SDavid Teigland struct rcom_lock {
482163a1859SAl Viro 	__le32			rl_ownpid;
483163a1859SAl Viro 	__le32			rl_lkid;
484163a1859SAl Viro 	__le32			rl_remid;
485163a1859SAl Viro 	__le32			rl_parent_lkid;
486163a1859SAl Viro 	__le32			rl_parent_remid;
487163a1859SAl Viro 	__le32			rl_exflags;
488163a1859SAl Viro 	__le32			rl_flags;
489163a1859SAl Viro 	__le32			rl_lvbseq;
490163a1859SAl Viro 	__le32			rl_result;
491e7fd4179SDavid Teigland 	int8_t			rl_rqmode;
492e7fd4179SDavid Teigland 	int8_t			rl_grmode;
493e7fd4179SDavid Teigland 	int8_t			rl_status;
494e7fd4179SDavid Teigland 	int8_t			rl_asts;
495163a1859SAl Viro 	__le16			rl_wait_type;
496163a1859SAl Viro 	__le16			rl_namelen;
497e7fd4179SDavid Teigland 	char			rl_name[DLM_RESNAME_MAXLEN];
498e7fd4179SDavid Teigland 	char			rl_lvb[0];
499e7fd4179SDavid Teigland };
500e7fd4179SDavid Teigland 
50105c32f47SDavid Teigland /*
50205c32f47SDavid Teigland  * The max number of resources per rsbtbl bucket that shrink will attempt
50305c32f47SDavid Teigland  * to remove in each iteration.
50405c32f47SDavid Teigland  */
50505c32f47SDavid Teigland 
50605c32f47SDavid Teigland #define DLM_REMOVE_NAMES_MAX 8
50705c32f47SDavid Teigland 
508e7fd4179SDavid Teigland struct dlm_ls {
509e7fd4179SDavid Teigland 	struct list_head	ls_list;	/* list of lockspaces */
510597d0caeSDavid Teigland 	dlm_lockspace_t		*ls_local_handle;
511e7fd4179SDavid Teigland 	uint32_t		ls_global_id;	/* global unique lockspace ID */
512757a4271SDavid Teigland 	uint32_t		ls_generation;
513e7fd4179SDavid Teigland 	uint32_t		ls_exflags;
514e7fd4179SDavid Teigland 	int			ls_lvblen;
5150f8e0d9aSDavid Teigland 	int			ls_count;	/* refcount of processes in
5160f8e0d9aSDavid Teigland 						   the dlm using this ls */
5170f8e0d9aSDavid Teigland 	int			ls_create_count; /* create/release refcount */
518e7fd4179SDavid Teigland 	unsigned long		ls_flags;	/* LSFL_ */
519c1dcf65fSDavid Teigland 	unsigned long		ls_scan_time;
520e7fd4179SDavid Teigland 	struct kobject		ls_kobj;
521e7fd4179SDavid Teigland 
5223d6aa675SDavid Teigland 	struct idr		ls_lkbidr;
5233d6aa675SDavid Teigland 	spinlock_t		ls_lkbidr_spin;
5243d6aa675SDavid Teigland 
525e7fd4179SDavid Teigland 	struct dlm_rsbtable	*ls_rsbtbl;
526e7fd4179SDavid Teigland 	uint32_t		ls_rsbtbl_size;
527e7fd4179SDavid Teigland 
52890135925SDavid Teigland 	struct mutex		ls_waiters_mutex;
529e7fd4179SDavid Teigland 	struct list_head	ls_waiters;	/* lkbs needing a reply */
530e7fd4179SDavid Teigland 
531ef0c2bb0SDavid Teigland 	struct mutex		ls_orphans_mutex;
532ef0c2bb0SDavid Teigland 	struct list_head	ls_orphans;
533ef0c2bb0SDavid Teigland 
5343ae1acf9SDavid Teigland 	struct mutex		ls_timeout_mutex;
5353ae1acf9SDavid Teigland 	struct list_head	ls_timeout;
5363ae1acf9SDavid Teigland 
5373881ac04SDavid Teigland 	spinlock_t		ls_new_rsb_spin;
5383881ac04SDavid Teigland 	int			ls_new_rsb_count;
5393881ac04SDavid Teigland 	struct list_head	ls_new_rsb;	/* new rsb structs */
5403881ac04SDavid Teigland 
54105c32f47SDavid Teigland 	spinlock_t		ls_remove_spin;
54205c32f47SDavid Teigland 	char			ls_remove_name[DLM_RESNAME_MAXLEN+1];
54305c32f47SDavid Teigland 	char			*ls_remove_names[DLM_REMOVE_NAMES_MAX];
54405c32f47SDavid Teigland 	int			ls_remove_len;
54505c32f47SDavid Teigland 	int			ls_remove_lens[DLM_REMOVE_NAMES_MAX];
54605c32f47SDavid Teigland 
547e7fd4179SDavid Teigland 	struct list_head	ls_nodes;	/* current nodes in ls */
548e7fd4179SDavid Teigland 	struct list_head	ls_nodes_gone;	/* dead node list, recovery */
549e7fd4179SDavid Teigland 	int			ls_num_nodes;	/* number of nodes in ls */
550e7fd4179SDavid Teigland 	int			ls_low_nodeid;
551e7fd4179SDavid Teigland 	int			ls_total_weight;
552e7fd4179SDavid Teigland 	int			*ls_node_array;
553e7fd4179SDavid Teigland 
554757a4271SDavid Teigland 	int			ls_slot;
555757a4271SDavid Teigland 	int			ls_num_slots;
556757a4271SDavid Teigland 	int			ls_slots_size;
557757a4271SDavid Teigland 	struct dlm_slot		*ls_slots;
558757a4271SDavid Teigland 
559e7fd4179SDavid Teigland 	struct dlm_rsb		ls_stub_rsb;	/* for returning errors */
560e7fd4179SDavid Teigland 	struct dlm_lkb		ls_stub_lkb;	/* for returning errors */
561e7fd4179SDavid Teigland 	struct dlm_message	ls_stub_ms;	/* for faking a reply */
562e7fd4179SDavid Teigland 
5635de6319bSDavid Teigland 	struct dentry		*ls_debug_rsb_dentry; /* debugfs */
5645de6319bSDavid Teigland 	struct dentry		*ls_debug_waiters_dentry; /* debugfs */
565ac90a255SDavid Teigland 	struct dentry		*ls_debug_locks_dentry; /* debugfs */
566d022509dSDavid Teigland 	struct dentry		*ls_debug_all_dentry; /* debugfs */
567c04fecb4SDavid Teigland 	struct dentry		*ls_debug_toss_dentry; /* debugfs */
568e7fd4179SDavid Teigland 
569e7fd4179SDavid Teigland 	wait_queue_head_t	ls_uevent_wait;	/* user part of join/leave */
570e7fd4179SDavid Teigland 	int			ls_uevent_result;
5718b0e7b2cSDavid Teigland 	struct completion	ls_members_done;
5728b0e7b2cSDavid Teigland 	int			ls_members_result;
573e7fd4179SDavid Teigland 
574597d0caeSDavid Teigland 	struct miscdevice       ls_device;
575597d0caeSDavid Teigland 
57623e8e1aaSDavid Teigland 	struct workqueue_struct	*ls_callback_wq;
57723e8e1aaSDavid Teigland 
578e7fd4179SDavid Teigland 	/* recovery related */
579e7fd4179SDavid Teigland 
58023e8e1aaSDavid Teigland 	struct mutex		ls_cb_mutex;
58123e8e1aaSDavid Teigland 	struct list_head	ls_cb_delay; /* save for queue_work later */
582e7fd4179SDavid Teigland 	struct timer_list	ls_timer;
583e7fd4179SDavid Teigland 	struct task_struct	*ls_recoverd_task;
58490135925SDavid Teigland 	struct mutex		ls_recoverd_active;
585e7fd4179SDavid Teigland 	spinlock_t		ls_recover_lock;
5863ae1acf9SDavid Teigland 	unsigned long		ls_recover_begin; /* jiffies timestamp */
587e7fd4179SDavid Teigland 	uint32_t		ls_recover_status; /* DLM_RS_ */
588e7fd4179SDavid Teigland 	uint64_t		ls_recover_seq;
589e7fd4179SDavid Teigland 	struct dlm_recover	*ls_recover_args;
590e7fd4179SDavid Teigland 	struct rw_semaphore	ls_in_recovery;	/* block local requests */
591c36258b5SDavid Teigland 	struct rw_semaphore	ls_recv_active;	/* block dlm_recv */
592e7fd4179SDavid Teigland 	struct list_head	ls_requestqueue;/* queue remote requests */
59390135925SDavid Teigland 	struct mutex		ls_requestqueue_mutex;
5944007685cSAl Viro 	struct dlm_rcom		*ls_recover_buf;
595faa0f267SDavid Teigland 	int			ls_recover_nodeid; /* for debugging */
596c04fecb4SDavid Teigland 	unsigned int		ls_recover_dir_sent_res; /* for log info */
597c04fecb4SDavid Teigland 	unsigned int		ls_recover_dir_sent_msg; /* for log info */
5984875647aSDavid Teigland 	unsigned int		ls_recover_locks_in; /* for log info */
5994a99c3d9SDavid Teigland 	uint64_t		ls_rcom_seq;
60098f176fbSDavid Teigland 	spinlock_t		ls_rcom_spin;
601e7fd4179SDavid Teigland 	struct list_head	ls_recover_list;
602e7fd4179SDavid Teigland 	spinlock_t		ls_recover_list_lock;
603e7fd4179SDavid Teigland 	int			ls_recover_list_count;
6041d7c484eSDavid Teigland 	struct idr		ls_recover_idr;
6051d7c484eSDavid Teigland 	spinlock_t		ls_recover_idr_lock;
606e7fd4179SDavid Teigland 	wait_queue_head_t	ls_wait_general;
607*475f230cSDavid Teigland 	wait_queue_head_t	ls_recover_lock_wait;
608597d0caeSDavid Teigland 	struct mutex		ls_clear_proc_locks;
609e7fd4179SDavid Teigland 
610e7fd4179SDavid Teigland 	struct list_head	ls_root_list;	/* root resources */
611e7fd4179SDavid Teigland 	struct rw_semaphore	ls_root_sem;	/* protect root_list */
612e7fd4179SDavid Teigland 
61360f98d18SDavid Teigland 	const struct dlm_lockspace_ops *ls_ops;
61460f98d18SDavid Teigland 	void			*ls_ops_arg;
61560f98d18SDavid Teigland 
616e7fd4179SDavid Teigland 	int			ls_namelen;
617e7fd4179SDavid Teigland 	char			ls_name[1];
618e7fd4179SDavid Teigland };
619e7fd4179SDavid Teigland 
620*475f230cSDavid Teigland /*
621*475f230cSDavid Teigland  * LSFL_RECOVER_STOP - dlm_ls_stop() sets this to tell dlm recovery routines
622*475f230cSDavid Teigland  * that they should abort what they're doing so new recovery can be started.
623*475f230cSDavid Teigland  *
624*475f230cSDavid Teigland  * LSFL_RECOVER_DOWN - dlm_ls_stop() sets this to tell dlm_recoverd that it
625*475f230cSDavid Teigland  * should do down_write() on the in_recovery rw_semaphore. (doing down_write
626*475f230cSDavid Teigland  * within dlm_ls_stop causes complaints about the lock acquired/released
627*475f230cSDavid Teigland  * in different contexts.)
628*475f230cSDavid Teigland  *
629*475f230cSDavid Teigland  * LSFL_RECOVER_LOCK - dlm_recoverd holds the in_recovery rw_semaphore.
630*475f230cSDavid Teigland  * It sets this after it is done with down_write() on the in_recovery
631*475f230cSDavid Teigland  * rw_semaphore and clears it after it has released the rw_semaphore.
632*475f230cSDavid Teigland  *
633*475f230cSDavid Teigland  * LSFL_RECOVER_WORK - dlm_ls_start() sets this to tell dlm_recoverd that it
634*475f230cSDavid Teigland  * should begin recovery of the lockspace.
635*475f230cSDavid Teigland  *
636*475f230cSDavid Teigland  * LSFL_RUNNING - set when normal locking activity is enabled.
637*475f230cSDavid Teigland  * dlm_ls_stop() clears this to tell dlm locking routines that they should
638*475f230cSDavid Teigland  * quit what they are doing so recovery can run.  dlm_recoverd sets
639*475f230cSDavid Teigland  * this after recovery is finished.
640*475f230cSDavid Teigland  */
641*475f230cSDavid Teigland 
642*475f230cSDavid Teigland #define LSFL_RECOVER_STOP	0
643*475f230cSDavid Teigland #define LSFL_RECOVER_DOWN	1
644*475f230cSDavid Teigland #define LSFL_RECOVER_LOCK	2
645*475f230cSDavid Teigland #define LSFL_RECOVER_WORK	3
646*475f230cSDavid Teigland #define LSFL_RUNNING		4
647*475f230cSDavid Teigland 
648*475f230cSDavid Teigland #define LSFL_RCOM_READY		5
649*475f230cSDavid Teigland #define LSFL_RCOM_WAIT		6
650*475f230cSDavid Teigland #define LSFL_UEVENT_WAIT	7
651*475f230cSDavid Teigland #define LSFL_TIMEWARN		8
652*475f230cSDavid Teigland #define LSFL_CB_DELAY		9
653*475f230cSDavid Teigland #define LSFL_NODIR		10
654e7fd4179SDavid Teigland 
655597d0caeSDavid Teigland /* much of this is just saving user space pointers associated with the
656597d0caeSDavid Teigland    lock that we pass back to the user lib with an ast */
657597d0caeSDavid Teigland 
658597d0caeSDavid Teigland struct dlm_user_args {
659597d0caeSDavid Teigland 	struct dlm_user_proc	*proc; /* each process that opens the lockspace
660597d0caeSDavid Teigland 					  device has private data
661597d0caeSDavid Teigland 					  (dlm_user_proc) on the struct file,
662597d0caeSDavid Teigland 					  the process's locks point back to it*/
663597d0caeSDavid Teigland 	struct dlm_lksb		lksb;
664597d0caeSDavid Teigland 	struct dlm_lksb __user	*user_lksb;
665597d0caeSDavid Teigland 	void __user		*castparam;
666597d0caeSDavid Teigland 	void __user		*castaddr;
667597d0caeSDavid Teigland 	void __user		*bastparam;
668597d0caeSDavid Teigland 	void __user		*bastaddr;
669d7db923eSDavid Teigland 	uint64_t		xid;
670597d0caeSDavid Teigland };
671597d0caeSDavid Teigland 
672597d0caeSDavid Teigland #define DLM_PROC_FLAGS_CLOSING 1
673597d0caeSDavid Teigland #define DLM_PROC_FLAGS_COMPAT  2
674597d0caeSDavid Teigland 
675597d0caeSDavid Teigland /* locks list is kept so we can remove all a process's locks when it
676597d0caeSDavid Teigland    exits (or orphan those that are persistent) */
677597d0caeSDavid Teigland 
678597d0caeSDavid Teigland struct dlm_user_proc {
679597d0caeSDavid Teigland 	dlm_lockspace_t		*lockspace;
680597d0caeSDavid Teigland 	unsigned long		flags; /* DLM_PROC_FLAGS */
681597d0caeSDavid Teigland 	struct list_head	asts;
682597d0caeSDavid Teigland 	spinlock_t		asts_spin;
683597d0caeSDavid Teigland 	struct list_head	locks;
684597d0caeSDavid Teigland 	spinlock_t		locks_spin;
685a1bc86e6SDavid Teigland 	struct list_head	unlocking;
686597d0caeSDavid Teigland 	wait_queue_head_t	wait;
687597d0caeSDavid Teigland };
688597d0caeSDavid Teigland 
689e7fd4179SDavid Teigland static inline int dlm_locking_stopped(struct dlm_ls *ls)
690e7fd4179SDavid Teigland {
691e7fd4179SDavid Teigland 	return !test_bit(LSFL_RUNNING, &ls->ls_flags);
692e7fd4179SDavid Teigland }
693e7fd4179SDavid Teigland 
694e7fd4179SDavid Teigland static inline int dlm_recovery_stopped(struct dlm_ls *ls)
695e7fd4179SDavid Teigland {
696*475f230cSDavid Teigland 	return test_bit(LSFL_RECOVER_STOP, &ls->ls_flags);
697e7fd4179SDavid Teigland }
698e7fd4179SDavid Teigland 
699e7fd4179SDavid Teigland static inline int dlm_no_directory(struct dlm_ls *ls)
700e7fd4179SDavid Teigland {
7014875647aSDavid Teigland 	return test_bit(LSFL_NODIR, &ls->ls_flags);
702e7fd4179SDavid Teigland }
703e7fd4179SDavid Teigland 
704e028398dSAdrian Bunk int dlm_netlink_init(void);
705e028398dSAdrian Bunk void dlm_netlink_exit(void);
706e028398dSAdrian Bunk void dlm_timeout_warn(struct dlm_lkb *lkb);
7072402211aSDavid Teigland int dlm_plock_init(void);
7082402211aSDavid Teigland void dlm_plock_exit(void);
709e028398dSAdrian Bunk 
710e028398dSAdrian Bunk #ifdef CONFIG_DLM_DEBUG
711e028398dSAdrian Bunk int dlm_register_debugfs(void);
712e028398dSAdrian Bunk void dlm_unregister_debugfs(void);
713e028398dSAdrian Bunk int dlm_create_debug_file(struct dlm_ls *ls);
714e028398dSAdrian Bunk void dlm_delete_debug_file(struct dlm_ls *ls);
715e028398dSAdrian Bunk #else
716e028398dSAdrian Bunk static inline int dlm_register_debugfs(void) { return 0; }
717e028398dSAdrian Bunk static inline void dlm_unregister_debugfs(void) { }
718e028398dSAdrian Bunk static inline int dlm_create_debug_file(struct dlm_ls *ls) { return 0; }
719e028398dSAdrian Bunk static inline void dlm_delete_debug_file(struct dlm_ls *ls) { }
720e028398dSAdrian Bunk #endif
721e028398dSAdrian Bunk 
722e7fd4179SDavid Teigland #endif				/* __DLM_INTERNAL_DOT_H__ */
723e7fd4179SDavid Teigland 
724