dlm_internal.h 23 KB

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