dlm_internal.h 20 KB

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