dlm_internal.h 22 KB

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