dlm_internal.h 20 KB

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