• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /******************************************************************************
2 *******************************************************************************
3 **
4 **  Copyright (C) Sistina Software, Inc.  1997-2003  All rights reserved.
5 **  Copyright (C) 2004-2011 Red Hat, Inc.  All rights reserved.
6 **
7 **  This copyrighted material is made available to anyone wishing to use,
8 **  modify, copy, or redistribute it subject to the terms and conditions
9 **  of the GNU General Public License v.2.
10 **
11 *******************************************************************************
12 ******************************************************************************/
13 
14 #ifndef __DLM_INTERNAL_DOT_H__
15 #define __DLM_INTERNAL_DOT_H__
16 
17 /*
18  * This is the main header file to be included in each DLM source file.
19  */
20 
21 #include <linux/module.h>
22 #include <linux/slab.h>
23 #include <linux/sched.h>
24 #include <linux/types.h>
25 #include <linux/ctype.h>
26 #include <linux/spinlock.h>
27 #include <linux/vmalloc.h>
28 #include <linux/list.h>
29 #include <linux/errno.h>
30 #include <linux/random.h>
31 #include <linux/delay.h>
32 #include <linux/socket.h>
33 #include <linux/kthread.h>
34 #include <linux/kobject.h>
35 #include <linux/kref.h>
36 #include <linux/kernel.h>
37 #include <linux/jhash.h>
38 #include <linux/miscdevice.h>
39 #include <linux/mutex.h>
40 #include <linux/idr.h>
41 #include <linux/ratelimit.h>
42 #include <asm/uaccess.h>
43 
44 #include <linux/dlm.h>
45 #include "config.h"
46 
47 /* Size of the temp buffer midcomms allocates on the stack.
48    We try to make this large enough so most messages fit.
49    FIXME: should sctp make this unnecessary? */
50 
51 #define DLM_INBUF_LEN		148
52 
53 struct dlm_ls;
54 struct dlm_lkb;
55 struct dlm_rsb;
56 struct dlm_member;
57 struct dlm_rsbtable;
58 struct dlm_recover;
59 struct dlm_header;
60 struct dlm_message;
61 struct dlm_rcom;
62 struct dlm_mhandle;
63 
64 #define log_print(fmt, args...) \
65 	printk(KERN_ERR "dlm: "fmt"\n" , ##args)
66 #define log_error(ls, fmt, args...) \
67 	printk(KERN_ERR "dlm: %s: " fmt "\n", (ls)->ls_name , ##args)
68 #define log_rinfo(ls, fmt, args...) \
69 	printk(KERN_INFO "dlm: %s: " fmt "\n", (ls)->ls_name , ##args);
70 
71 #define log_debug(ls, fmt, args...) \
72 do { \
73 	if (dlm_config.ci_log_debug) \
74 		printk(KERN_DEBUG "dlm: %s: " fmt "\n", \
75 		       (ls)->ls_name , ##args); \
76 } while (0)
77 
78 #define log_limit(ls, fmt, args...) \
79 do { \
80 	if (dlm_config.ci_log_debug) \
81 		printk_ratelimited(KERN_DEBUG "dlm: %s: " fmt "\n", \
82 			(ls)->ls_name , ##args); \
83 } while (0)
84 
85 #define DLM_ASSERT(x, do) \
86 { \
87   if (!(x)) \
88   { \
89     printk(KERN_ERR "\nDLM:  Assertion failed on line %d of file %s\n" \
90                "DLM:  assertion:  \"%s\"\n" \
91                "DLM:  time = %lu\n", \
92                __LINE__, __FILE__, #x, jiffies); \
93     {do} \
94     printk("\n"); \
95     panic("DLM:  Record message above and reboot.\n"); \
96   } \
97 }
98 
99 
100 #define DLM_RTF_SHRINK		0x00000001
101 
102 struct dlm_rsbtable {
103 	struct rb_root		keep;
104 	struct rb_root		toss;
105 	spinlock_t		lock;
106 	uint32_t		flags;
107 };
108 
109 
110 /*
111  * Lockspace member (per node in a ls)
112  */
113 
114 struct dlm_member {
115 	struct list_head	list;
116 	int			nodeid;
117 	int			weight;
118 	int			slot;
119 	int			slot_prev;
120 	int			comm_seq;
121 	uint32_t		generation;
122 };
123 
124 /*
125  * Save and manage recovery state for a lockspace.
126  */
127 
128 struct dlm_recover {
129 	struct list_head	list;
130 	struct dlm_config_node	*nodes;
131 	int			nodes_count;
132 	uint64_t		seq;
133 };
134 
135 /*
136  * Pass input args to second stage locking function.
137  */
138 
139 struct dlm_args {
140 	uint32_t		flags;
141 	void			(*astfn) (void *astparam);
142 	void			*astparam;
143 	void			(*bastfn) (void *astparam, int mode);
144 	int			mode;
145 	struct dlm_lksb		*lksb;
146 	unsigned long		timeout;
147 };
148 
149 
150 /*
151  * Lock block
152  *
153  * A lock can be one of three types:
154  *
155  * local copy      lock is mastered locally
156  *                 (lkb_nodeid is zero and DLM_LKF_MSTCPY is not set)
157  * process copy    lock is mastered on a remote node
158  *                 (lkb_nodeid is non-zero and DLM_LKF_MSTCPY is not set)
159  * master copy     master node's copy of a lock owned by remote node
160  *                 (lkb_nodeid is non-zero and DLM_LKF_MSTCPY is set)
161  *
162  * lkb_exflags: a copy of the most recent flags arg provided to dlm_lock or
163  * dlm_unlock.  The dlm does not modify these or use any private flags in
164  * this field; it only contains DLM_LKF_ flags from dlm.h.  These flags
165  * are sent as-is to the remote master when the lock is remote.
166  *
167  * lkb_flags: internal dlm flags (DLM_IFL_ prefix) from dlm_internal.h.
168  * Some internal flags are shared between the master and process nodes;
169  * these shared flags are kept in the lower two bytes.  One of these
170  * flags set on the master copy will be propagated to the process copy
171  * and v.v.  Other internal flags are private to the master or process
172  * node (e.g. DLM_IFL_MSTCPY).  These are kept in the high two bytes.
173  *
174  * lkb_sbflags: status block flags.  These flags are copied directly into
175  * the caller's lksb.sb_flags prior to the dlm_lock/dlm_unlock completion
176  * ast.  All defined in dlm.h with DLM_SBF_ prefix.
177  *
178  * lkb_status: the lock status indicates which rsb queue the lock is
179  * on, grant, convert, or wait.  DLM_LKSTS_ WAITING/GRANTED/CONVERT
180  *
181  * lkb_wait_type: the dlm message type (DLM_MSG_ prefix) for which a
182  * reply is needed.  Only set when the lkb is on the lockspace waiters
183  * list awaiting a reply from a remote node.
184  *
185  * lkb_nodeid: when the lkb is a local copy, nodeid is 0; when the lkb
186  * is a master copy, nodeid specifies the remote lock holder, when the
187  * lkb is a process copy, the nodeid specifies the lock master.
188  */
189 
190 /* lkb_status */
191 
192 #define DLM_LKSTS_WAITING	1
193 #define DLM_LKSTS_GRANTED	2
194 #define DLM_LKSTS_CONVERT	3
195 
196 /* lkb_flags */
197 
198 #define DLM_IFL_MSTCPY		0x00010000
199 #define DLM_IFL_RESEND		0x00020000
200 #define DLM_IFL_DEAD		0x00040000
201 #define DLM_IFL_OVERLAP_UNLOCK  0x00080000
202 #define DLM_IFL_OVERLAP_CANCEL  0x00100000
203 #define DLM_IFL_ENDOFLIFE	0x00200000
204 #define DLM_IFL_WATCH_TIMEWARN	0x00400000
205 #define DLM_IFL_TIMEOUT_CANCEL	0x00800000
206 #define DLM_IFL_DEADLOCK_CANCEL	0x01000000
207 #define DLM_IFL_STUB_MS		0x02000000 /* magic number for m_flags */
208 #define DLM_IFL_USER		0x00000001
209 #define DLM_IFL_ORPHAN		0x00000002
210 
211 #define DLM_CALLBACKS_SIZE	6
212 
213 #define DLM_CB_CAST		0x00000001
214 #define DLM_CB_BAST		0x00000002
215 #define DLM_CB_SKIP		0x00000004
216 
217 struct dlm_callback {
218 	uint64_t		seq;
219 	uint32_t		flags;		/* DLM_CBF_ */
220 	int			sb_status;	/* copy to lksb status */
221 	uint8_t			sb_flags;	/* copy to lksb flags */
222 	int8_t			mode; /* rq mode of bast, gr mode of cast */
223 };
224 
225 struct dlm_lkb {
226 	struct dlm_rsb		*lkb_resource;	/* the rsb */
227 	struct kref		lkb_ref;
228 	int			lkb_nodeid;	/* copied from rsb */
229 	int			lkb_ownpid;	/* pid of lock owner */
230 	uint32_t		lkb_id;		/* our lock ID */
231 	uint32_t		lkb_remid;	/* lock ID on remote partner */
232 	uint32_t		lkb_exflags;	/* external flags from caller */
233 	uint32_t		lkb_sbflags;	/* lksb flags */
234 	uint32_t		lkb_flags;	/* internal flags */
235 	uint32_t		lkb_lvbseq;	/* lvb sequence number */
236 
237 	int8_t			lkb_status;     /* granted, waiting, convert */
238 	int8_t			lkb_rqmode;	/* requested lock mode */
239 	int8_t			lkb_grmode;	/* granted lock mode */
240 	int8_t			lkb_highbast;	/* highest mode bast sent for */
241 
242 	int8_t			lkb_wait_type;	/* type of reply waiting for */
243 	int8_t			lkb_wait_count;
244 	int			lkb_wait_nodeid; /* for debugging */
245 
246 	struct list_head	lkb_statequeue;	/* rsb g/c/w list */
247 	struct list_head	lkb_rsb_lookup;	/* waiting for rsb lookup */
248 	struct list_head	lkb_wait_reply;	/* waiting for remote reply */
249 	struct list_head	lkb_ownqueue;	/* list of locks for a process */
250 	struct list_head	lkb_time_list;
251 	ktime_t			lkb_timestamp;
252 	ktime_t			lkb_wait_time;
253 	unsigned long		lkb_timeout_cs;
254 
255 	struct mutex		lkb_cb_mutex;
256 	struct work_struct	lkb_cb_work;
257 	struct list_head	lkb_cb_list; /* for ls_cb_delay or proc->asts */
258 	struct dlm_callback	lkb_callbacks[DLM_CALLBACKS_SIZE];
259 	struct dlm_callback	lkb_last_cast;
260 	struct dlm_callback	lkb_last_bast;
261 	ktime_t			lkb_last_cast_time;	/* for debugging */
262 	ktime_t			lkb_last_bast_time;	/* for debugging */
263 
264 	uint64_t		lkb_recover_seq; /* from ls_recover_seq */
265 
266 	char			*lkb_lvbptr;
267 	struct dlm_lksb		*lkb_lksb;      /* caller's status block */
268 	void			(*lkb_astfn) (void *astparam);
269 	void			(*lkb_bastfn) (void *astparam, int mode);
270 	union {
271 		void			*lkb_astparam;	/* caller's ast arg */
272 		struct dlm_user_args	*lkb_ua;
273 	};
274 };
275 
276 /*
277  * res_master_nodeid is "normal": 0 is unset/invalid, non-zero is the real
278  * nodeid, even when nodeid is our_nodeid.
279  *
280  * res_nodeid is "odd": -1 is unset/invalid, zero means our_nodeid,
281  * greater than zero when another nodeid.
282  *
283  * (TODO: remove res_nodeid and only use res_master_nodeid)
284  */
285 
286 struct dlm_rsb {
287 	struct dlm_ls		*res_ls;	/* the lockspace */
288 	struct kref		res_ref;
289 	struct mutex		res_mutex;
290 	unsigned long		res_flags;
291 	int			res_length;	/* length of rsb name */
292 	int			res_nodeid;
293 	int			res_master_nodeid;
294 	int			res_dir_nodeid;
295 	int			res_id;		/* for ls_recover_idr */
296 	uint32_t                res_lvbseq;
297 	uint32_t		res_hash;
298 	uint32_t		res_bucket;	/* rsbtbl */
299 	unsigned long		res_toss_time;
300 	uint32_t		res_first_lkid;
301 	struct list_head	res_lookup;	/* lkbs waiting on first */
302 	union {
303 		struct list_head	res_hashchain;
304 		struct rb_node		res_hashnode;	/* rsbtbl */
305 	};
306 	struct list_head	res_grantqueue;
307 	struct list_head	res_convertqueue;
308 	struct list_head	res_waitqueue;
309 
310 	struct list_head	res_root_list;	    /* used for recovery */
311 	struct list_head	res_recover_list;   /* used for recovery */
312 	int			res_recover_locks_count;
313 
314 	char			*res_lvbptr;
315 	char			res_name[DLM_RESNAME_MAXLEN+1];
316 };
317 
318 /* dlm_master_lookup() flags */
319 
320 #define DLM_LU_RECOVER_DIR	1
321 #define DLM_LU_RECOVER_MASTER	2
322 
323 /* dlm_master_lookup() results */
324 
325 #define DLM_LU_MATCH		1
326 #define DLM_LU_ADD		2
327 
328 /* find_rsb() flags */
329 
330 #define R_REQUEST		0x00000001
331 #define R_RECEIVE_REQUEST	0x00000002
332 #define R_RECEIVE_RECOVER	0x00000004
333 
334 /* rsb_flags */
335 
336 enum rsb_flags {
337 	RSB_MASTER_UNCERTAIN,
338 	RSB_VALNOTVALID,
339 	RSB_VALNOTVALID_PREV,
340 	RSB_NEW_MASTER,
341 	RSB_NEW_MASTER2,
342 	RSB_RECOVER_CONVERT,
343 	RSB_RECOVER_GRANT,
344 	RSB_RECOVER_LVB_INVAL,
345 };
346 
rsb_set_flag(struct dlm_rsb * r,enum rsb_flags flag)347 static inline void rsb_set_flag(struct dlm_rsb *r, enum rsb_flags flag)
348 {
349 	__set_bit(flag, &r->res_flags);
350 }
351 
rsb_clear_flag(struct dlm_rsb * r,enum rsb_flags flag)352 static inline void rsb_clear_flag(struct dlm_rsb *r, enum rsb_flags flag)
353 {
354 	__clear_bit(flag, &r->res_flags);
355 }
356 
rsb_flag(struct dlm_rsb * r,enum rsb_flags flag)357 static inline int rsb_flag(struct dlm_rsb *r, enum rsb_flags flag)
358 {
359 	return test_bit(flag, &r->res_flags);
360 }
361 
362 
363 /* dlm_header is first element of all structs sent between nodes */
364 
365 #define DLM_HEADER_MAJOR	0x00030000
366 #define DLM_HEADER_MINOR	0x00000001
367 
368 #define DLM_HEADER_SLOTS	0x00000001
369 
370 #define DLM_MSG			1
371 #define DLM_RCOM		2
372 
373 struct dlm_header {
374 	uint32_t		h_version;
375 	uint32_t		h_lockspace;
376 	uint32_t		h_nodeid;	/* nodeid of sender */
377 	uint16_t		h_length;
378 	uint8_t			h_cmd;		/* DLM_MSG, DLM_RCOM */
379 	uint8_t			h_pad;
380 };
381 
382 
383 #define DLM_MSG_REQUEST		1
384 #define DLM_MSG_CONVERT		2
385 #define DLM_MSG_UNLOCK		3
386 #define DLM_MSG_CANCEL		4
387 #define DLM_MSG_REQUEST_REPLY	5
388 #define DLM_MSG_CONVERT_REPLY	6
389 #define DLM_MSG_UNLOCK_REPLY	7
390 #define DLM_MSG_CANCEL_REPLY	8
391 #define DLM_MSG_GRANT		9
392 #define DLM_MSG_BAST		10
393 #define DLM_MSG_LOOKUP		11
394 #define DLM_MSG_REMOVE		12
395 #define DLM_MSG_LOOKUP_REPLY	13
396 #define DLM_MSG_PURGE		14
397 
398 struct dlm_message {
399 	struct dlm_header	m_header;
400 	uint32_t		m_type;		/* DLM_MSG_ */
401 	uint32_t		m_nodeid;
402 	uint32_t		m_pid;
403 	uint32_t		m_lkid;		/* lkid on sender */
404 	uint32_t		m_remid;	/* lkid on receiver */
405 	uint32_t		m_parent_lkid;
406 	uint32_t		m_parent_remid;
407 	uint32_t		m_exflags;
408 	uint32_t		m_sbflags;
409 	uint32_t		m_flags;
410 	uint32_t		m_lvbseq;
411 	uint32_t		m_hash;
412 	int			m_status;
413 	int			m_grmode;
414 	int			m_rqmode;
415 	int			m_bastmode;
416 	int			m_asts;
417 	int			m_result;	/* 0 or -EXXX */
418 	char			m_extra[0];	/* name or lvb */
419 };
420 
421 
422 #define DLM_RS_NODES		0x00000001
423 #define DLM_RS_NODES_ALL	0x00000002
424 #define DLM_RS_DIR		0x00000004
425 #define DLM_RS_DIR_ALL		0x00000008
426 #define DLM_RS_LOCKS		0x00000010
427 #define DLM_RS_LOCKS_ALL	0x00000020
428 #define DLM_RS_DONE		0x00000040
429 #define DLM_RS_DONE_ALL		0x00000080
430 
431 #define DLM_RCOM_STATUS		1
432 #define DLM_RCOM_NAMES		2
433 #define DLM_RCOM_LOOKUP		3
434 #define DLM_RCOM_LOCK		4
435 #define DLM_RCOM_STATUS_REPLY	5
436 #define DLM_RCOM_NAMES_REPLY	6
437 #define DLM_RCOM_LOOKUP_REPLY	7
438 #define DLM_RCOM_LOCK_REPLY	8
439 
440 struct dlm_rcom {
441 	struct dlm_header	rc_header;
442 	uint32_t		rc_type;	/* DLM_RCOM_ */
443 	int			rc_result;	/* multi-purpose */
444 	uint64_t		rc_id;		/* match reply with request */
445 	uint64_t		rc_seq;		/* sender's ls_recover_seq */
446 	uint64_t		rc_seq_reply;	/* remote ls_recover_seq */
447 	char			rc_buf[0];
448 };
449 
450 union dlm_packet {
451 	struct dlm_header	header;		/* common to other two */
452 	struct dlm_message	message;
453 	struct dlm_rcom		rcom;
454 };
455 
456 #define DLM_RSF_NEED_SLOTS	0x00000001
457 
458 /* RCOM_STATUS data */
459 struct rcom_status {
460 	__le32			rs_flags;
461 	__le32			rs_unused1;
462 	__le64			rs_unused2;
463 };
464 
465 /* RCOM_STATUS_REPLY data */
466 struct rcom_config {
467 	__le32			rf_lvblen;
468 	__le32			rf_lsflags;
469 
470 	/* DLM_HEADER_SLOTS adds: */
471 	__le32			rf_flags;
472 	__le16			rf_our_slot;
473 	__le16			rf_num_slots;
474 	__le32			rf_generation;
475 	__le32			rf_unused1;
476 	__le64			rf_unused2;
477 };
478 
479 struct rcom_slot {
480 	__le32			ro_nodeid;
481 	__le16			ro_slot;
482 	__le16			ro_unused1;
483 	__le64			ro_unused2;
484 };
485 
486 struct rcom_lock {
487 	__le32			rl_ownpid;
488 	__le32			rl_lkid;
489 	__le32			rl_remid;
490 	__le32			rl_parent_lkid;
491 	__le32			rl_parent_remid;
492 	__le32			rl_exflags;
493 	__le32			rl_flags;
494 	__le32			rl_lvbseq;
495 	__le32			rl_result;
496 	int8_t			rl_rqmode;
497 	int8_t			rl_grmode;
498 	int8_t			rl_status;
499 	int8_t			rl_asts;
500 	__le16			rl_wait_type;
501 	__le16			rl_namelen;
502 	char			rl_name[DLM_RESNAME_MAXLEN];
503 	char			rl_lvb[0];
504 };
505 
506 /*
507  * The max number of resources per rsbtbl bucket that shrink will attempt
508  * to remove in each iteration.
509  */
510 
511 #define DLM_REMOVE_NAMES_MAX 8
512 
513 struct dlm_ls {
514 	struct list_head	ls_list;	/* list of lockspaces */
515 	dlm_lockspace_t		*ls_local_handle;
516 	uint32_t		ls_global_id;	/* global unique lockspace ID */
517 	uint32_t		ls_generation;
518 	uint32_t		ls_exflags;
519 	int			ls_lvblen;
520 	int			ls_count;	/* refcount of processes in
521 						   the dlm using this ls */
522 	int			ls_create_count; /* create/release refcount */
523 	unsigned long		ls_flags;	/* LSFL_ */
524 	unsigned long		ls_scan_time;
525 	struct kobject		ls_kobj;
526 
527 	struct idr		ls_lkbidr;
528 	spinlock_t		ls_lkbidr_spin;
529 
530 	struct dlm_rsbtable	*ls_rsbtbl;
531 	uint32_t		ls_rsbtbl_size;
532 
533 	struct mutex		ls_waiters_mutex;
534 	struct list_head	ls_waiters;	/* lkbs needing a reply */
535 
536 	struct mutex		ls_orphans_mutex;
537 	struct list_head	ls_orphans;
538 
539 	struct mutex		ls_timeout_mutex;
540 	struct list_head	ls_timeout;
541 
542 	spinlock_t		ls_new_rsb_spin;
543 	int			ls_new_rsb_count;
544 	struct list_head	ls_new_rsb;	/* new rsb structs */
545 
546 	spinlock_t		ls_remove_spin;
547 	char			ls_remove_name[DLM_RESNAME_MAXLEN+1];
548 	char			*ls_remove_names[DLM_REMOVE_NAMES_MAX];
549 	int			ls_remove_len;
550 	int			ls_remove_lens[DLM_REMOVE_NAMES_MAX];
551 
552 	struct list_head	ls_nodes;	/* current nodes in ls */
553 	struct list_head	ls_nodes_gone;	/* dead node list, recovery */
554 	int			ls_num_nodes;	/* number of nodes in ls */
555 	int			ls_low_nodeid;
556 	int			ls_total_weight;
557 	int			*ls_node_array;
558 
559 	int			ls_slot;
560 	int			ls_num_slots;
561 	int			ls_slots_size;
562 	struct dlm_slot		*ls_slots;
563 
564 	struct dlm_rsb		ls_stub_rsb;	/* for returning errors */
565 	struct dlm_lkb		ls_stub_lkb;	/* for returning errors */
566 	struct dlm_message	ls_stub_ms;	/* for faking a reply */
567 
568 	struct dentry		*ls_debug_rsb_dentry; /* debugfs */
569 	struct dentry		*ls_debug_waiters_dentry; /* debugfs */
570 	struct dentry		*ls_debug_locks_dentry; /* debugfs */
571 	struct dentry		*ls_debug_all_dentry; /* debugfs */
572 	struct dentry		*ls_debug_toss_dentry; /* debugfs */
573 
574 	wait_queue_head_t	ls_uevent_wait;	/* user part of join/leave */
575 	int			ls_uevent_result;
576 	struct completion	ls_members_done;
577 	int			ls_members_result;
578 
579 	struct miscdevice       ls_device;
580 
581 	struct workqueue_struct	*ls_callback_wq;
582 
583 	/* recovery related */
584 
585 	struct mutex		ls_cb_mutex;
586 	struct list_head	ls_cb_delay; /* save for queue_work later */
587 	struct timer_list	ls_timer;
588 	struct task_struct	*ls_recoverd_task;
589 	struct mutex		ls_recoverd_active;
590 	spinlock_t		ls_recover_lock;
591 	unsigned long		ls_recover_begin; /* jiffies timestamp */
592 	uint32_t		ls_recover_status; /* DLM_RS_ */
593 	uint64_t		ls_recover_seq;
594 	struct dlm_recover	*ls_recover_args;
595 	struct rw_semaphore	ls_in_recovery;	/* block local requests */
596 	struct rw_semaphore	ls_recv_active;	/* block dlm_recv */
597 	struct list_head	ls_requestqueue;/* queue remote requests */
598 	struct mutex		ls_requestqueue_mutex;
599 	struct dlm_rcom		*ls_recover_buf;
600 	int			ls_recover_nodeid; /* for debugging */
601 	unsigned int		ls_recover_dir_sent_res; /* for log info */
602 	unsigned int		ls_recover_dir_sent_msg; /* for log info */
603 	unsigned int		ls_recover_locks_in; /* for log info */
604 	uint64_t		ls_rcom_seq;
605 	spinlock_t		ls_rcom_spin;
606 	struct list_head	ls_recover_list;
607 	spinlock_t		ls_recover_list_lock;
608 	int			ls_recover_list_count;
609 	struct idr		ls_recover_idr;
610 	spinlock_t		ls_recover_idr_lock;
611 	wait_queue_head_t	ls_wait_general;
612 	wait_queue_head_t	ls_recover_lock_wait;
613 	struct mutex		ls_clear_proc_locks;
614 
615 	struct list_head	ls_root_list;	/* root resources */
616 	struct rw_semaphore	ls_root_sem;	/* protect root_list */
617 
618 	const struct dlm_lockspace_ops *ls_ops;
619 	void			*ls_ops_arg;
620 
621 	int			ls_namelen;
622 	char			ls_name[1];
623 };
624 
625 /*
626  * LSFL_RECOVER_STOP - dlm_ls_stop() sets this to tell dlm recovery routines
627  * that they should abort what they're doing so new recovery can be started.
628  *
629  * LSFL_RECOVER_DOWN - dlm_ls_stop() sets this to tell dlm_recoverd that it
630  * should do down_write() on the in_recovery rw_semaphore. (doing down_write
631  * within dlm_ls_stop causes complaints about the lock acquired/released
632  * in different contexts.)
633  *
634  * LSFL_RECOVER_LOCK - dlm_recoverd holds the in_recovery rw_semaphore.
635  * It sets this after it is done with down_write() on the in_recovery
636  * rw_semaphore and clears it after it has released the rw_semaphore.
637  *
638  * LSFL_RECOVER_WORK - dlm_ls_start() sets this to tell dlm_recoverd that it
639  * should begin recovery of the lockspace.
640  *
641  * LSFL_RUNNING - set when normal locking activity is enabled.
642  * dlm_ls_stop() clears this to tell dlm locking routines that they should
643  * quit what they are doing so recovery can run.  dlm_recoverd sets
644  * this after recovery is finished.
645  */
646 
647 #define LSFL_RECOVER_STOP	0
648 #define LSFL_RECOVER_DOWN	1
649 #define LSFL_RECOVER_LOCK	2
650 #define LSFL_RECOVER_WORK	3
651 #define LSFL_RUNNING		4
652 
653 #define LSFL_RCOM_READY		5
654 #define LSFL_RCOM_WAIT		6
655 #define LSFL_UEVENT_WAIT	7
656 #define LSFL_TIMEWARN		8
657 #define LSFL_CB_DELAY		9
658 #define LSFL_NODIR		10
659 
660 /* much of this is just saving user space pointers associated with the
661    lock that we pass back to the user lib with an ast */
662 
663 struct dlm_user_args {
664 	struct dlm_user_proc	*proc; /* each process that opens the lockspace
665 					  device has private data
666 					  (dlm_user_proc) on the struct file,
667 					  the process's locks point back to it*/
668 	struct dlm_lksb		lksb;
669 	struct dlm_lksb __user	*user_lksb;
670 	void __user		*castparam;
671 	void __user		*castaddr;
672 	void __user		*bastparam;
673 	void __user		*bastaddr;
674 	uint64_t		xid;
675 };
676 
677 #define DLM_PROC_FLAGS_CLOSING 1
678 #define DLM_PROC_FLAGS_COMPAT  2
679 
680 /* locks list is kept so we can remove all a process's locks when it
681    exits (or orphan those that are persistent) */
682 
683 struct dlm_user_proc {
684 	dlm_lockspace_t		*lockspace;
685 	unsigned long		flags; /* DLM_PROC_FLAGS */
686 	struct list_head	asts;
687 	spinlock_t		asts_spin;
688 	struct list_head	locks;
689 	spinlock_t		locks_spin;
690 	struct list_head	unlocking;
691 	wait_queue_head_t	wait;
692 };
693 
dlm_locking_stopped(struct dlm_ls * ls)694 static inline int dlm_locking_stopped(struct dlm_ls *ls)
695 {
696 	return !test_bit(LSFL_RUNNING, &ls->ls_flags);
697 }
698 
dlm_recovery_stopped(struct dlm_ls * ls)699 static inline int dlm_recovery_stopped(struct dlm_ls *ls)
700 {
701 	return test_bit(LSFL_RECOVER_STOP, &ls->ls_flags);
702 }
703 
dlm_no_directory(struct dlm_ls * ls)704 static inline int dlm_no_directory(struct dlm_ls *ls)
705 {
706 	return test_bit(LSFL_NODIR, &ls->ls_flags);
707 }
708 
709 int dlm_netlink_init(void);
710 void dlm_netlink_exit(void);
711 void dlm_timeout_warn(struct dlm_lkb *lkb);
712 int dlm_plock_init(void);
713 void dlm_plock_exit(void);
714 
715 #ifdef CONFIG_DLM_DEBUG
716 int dlm_register_debugfs(void);
717 void dlm_unregister_debugfs(void);
718 int dlm_create_debug_file(struct dlm_ls *ls);
719 void dlm_delete_debug_file(struct dlm_ls *ls);
720 #else
dlm_register_debugfs(void)721 static inline int dlm_register_debugfs(void) { return 0; }
dlm_unregister_debugfs(void)722 static inline void dlm_unregister_debugfs(void) { }
dlm_create_debug_file(struct dlm_ls * ls)723 static inline int dlm_create_debug_file(struct dlm_ls *ls) { return 0; }
dlm_delete_debug_file(struct dlm_ls * ls)724 static inline void dlm_delete_debug_file(struct dlm_ls *ls) { }
725 #endif
726 
727 #endif				/* __DLM_INTERNAL_DOT_H__ */
728 
729