dlm_internal.h 20 KB

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