dlmcommon.h 26 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028
  1. /* -*- mode: c; c-basic-offset: 8; -*-
  2. * vim: noexpandtab sw=8 ts=8 sts=0:
  3. *
  4. * dlmcommon.h
  5. *
  6. * Copyright (C) 2004 Oracle. All rights reserved.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public
  10. * License as published by the Free Software Foundation; either
  11. * version 2 of the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public
  19. * License along with this program; if not, write to the
  20. * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  21. * Boston, MA 021110-1307, USA.
  22. *
  23. */
  24. #ifndef DLMCOMMON_H
  25. #define DLMCOMMON_H
  26. #include <linux/kref.h>
  27. #define DLM_HB_NODE_DOWN_PRI (0xf000000)
  28. #define DLM_HB_NODE_UP_PRI (0x8000000)
  29. #define DLM_LOCKID_NAME_MAX 32
  30. #define DLM_DOMAIN_NAME_MAX_LEN 255
  31. #define DLM_LOCK_RES_OWNER_UNKNOWN O2NM_MAX_NODES
  32. #define DLM_THREAD_SHUFFLE_INTERVAL 5 // flush everything every 5 passes
  33. #define DLM_THREAD_MS 200 // flush at least every 200 ms
  34. #define DLM_HASH_SIZE_DEFAULT (1 << 14)
  35. #if DLM_HASH_SIZE_DEFAULT < PAGE_SIZE
  36. # define DLM_HASH_PAGES 1
  37. #else
  38. # define DLM_HASH_PAGES (DLM_HASH_SIZE_DEFAULT / PAGE_SIZE)
  39. #endif
  40. #define DLM_BUCKETS_PER_PAGE (PAGE_SIZE / sizeof(struct hlist_head))
  41. #define DLM_HASH_BUCKETS (DLM_HASH_PAGES * DLM_BUCKETS_PER_PAGE)
  42. /* Intended to make it easier for us to switch out hash functions */
  43. #define dlm_lockid_hash(_n, _l) full_name_hash(_n, _l)
  44. enum dlm_ast_type {
  45. DLM_AST = 0,
  46. DLM_BAST,
  47. DLM_ASTUNLOCK
  48. };
  49. #define LKM_VALID_FLAGS (LKM_VALBLK | LKM_CONVERT | LKM_UNLOCK | \
  50. LKM_CANCEL | LKM_INVVALBLK | LKM_FORCE | \
  51. LKM_RECOVERY | LKM_LOCAL | LKM_NOQUEUE)
  52. #define DLM_RECOVERY_LOCK_NAME "$RECOVERY"
  53. #define DLM_RECOVERY_LOCK_NAME_LEN 9
  54. static inline int dlm_is_recovery_lock(const char *lock_name, int name_len)
  55. {
  56. if (name_len == DLM_RECOVERY_LOCK_NAME_LEN &&
  57. memcmp(lock_name, DLM_RECOVERY_LOCK_NAME, name_len)==0)
  58. return 1;
  59. return 0;
  60. }
  61. #define DLM_RECO_STATE_ACTIVE 0x0001
  62. #define DLM_RECO_STATE_FINALIZE 0x0002
  63. struct dlm_recovery_ctxt
  64. {
  65. struct list_head resources;
  66. struct list_head received;
  67. struct list_head node_data;
  68. u8 new_master;
  69. u8 dead_node;
  70. u16 state;
  71. unsigned long node_map[BITS_TO_LONGS(O2NM_MAX_NODES)];
  72. wait_queue_head_t event;
  73. };
  74. enum dlm_ctxt_state {
  75. DLM_CTXT_NEW = 0,
  76. DLM_CTXT_JOINED,
  77. DLM_CTXT_IN_SHUTDOWN,
  78. DLM_CTXT_LEAVING,
  79. };
  80. struct dlm_ctxt
  81. {
  82. struct list_head list;
  83. struct hlist_head **lockres_hash;
  84. struct list_head dirty_list;
  85. struct list_head purge_list;
  86. struct list_head pending_asts;
  87. struct list_head pending_basts;
  88. unsigned int purge_count;
  89. spinlock_t spinlock;
  90. spinlock_t ast_lock;
  91. char *name;
  92. u8 node_num;
  93. u32 key;
  94. u8 joining_node;
  95. wait_queue_head_t dlm_join_events;
  96. unsigned long live_nodes_map[BITS_TO_LONGS(O2NM_MAX_NODES)];
  97. unsigned long domain_map[BITS_TO_LONGS(O2NM_MAX_NODES)];
  98. unsigned long recovery_map[BITS_TO_LONGS(O2NM_MAX_NODES)];
  99. struct dlm_recovery_ctxt reco;
  100. spinlock_t master_lock;
  101. struct list_head master_list;
  102. struct list_head mle_hb_events;
  103. /* these give a really vague idea of the system load */
  104. atomic_t local_resources;
  105. atomic_t remote_resources;
  106. atomic_t unknown_resources;
  107. /* NOTE: Next three are protected by dlm_domain_lock */
  108. struct kref dlm_refs;
  109. enum dlm_ctxt_state dlm_state;
  110. unsigned int num_joins;
  111. struct o2hb_callback_func dlm_hb_up;
  112. struct o2hb_callback_func dlm_hb_down;
  113. struct task_struct *dlm_thread_task;
  114. struct task_struct *dlm_reco_thread_task;
  115. struct workqueue_struct *dlm_worker;
  116. wait_queue_head_t dlm_thread_wq;
  117. wait_queue_head_t dlm_reco_thread_wq;
  118. wait_queue_head_t ast_wq;
  119. wait_queue_head_t migration_wq;
  120. struct work_struct dispatched_work;
  121. struct list_head work_list;
  122. spinlock_t work_lock;
  123. struct list_head dlm_domain_handlers;
  124. struct list_head dlm_eviction_callbacks;
  125. };
  126. static inline struct hlist_head *dlm_lockres_hash(struct dlm_ctxt *dlm, unsigned i)
  127. {
  128. return dlm->lockres_hash[(i / DLM_BUCKETS_PER_PAGE) % DLM_HASH_PAGES] + (i % DLM_BUCKETS_PER_PAGE);
  129. }
  130. /* these keventd work queue items are for less-frequently
  131. * called functions that cannot be directly called from the
  132. * net message handlers for some reason, usually because
  133. * they need to send net messages of their own. */
  134. void dlm_dispatch_work(struct work_struct *work);
  135. struct dlm_lock_resource;
  136. struct dlm_work_item;
  137. typedef void (dlm_workfunc_t)(struct dlm_work_item *, void *);
  138. struct dlm_request_all_locks_priv
  139. {
  140. u8 reco_master;
  141. u8 dead_node;
  142. };
  143. struct dlm_mig_lockres_priv
  144. {
  145. struct dlm_lock_resource *lockres;
  146. u8 real_master;
  147. };
  148. struct dlm_assert_master_priv
  149. {
  150. struct dlm_lock_resource *lockres;
  151. u8 request_from;
  152. u32 flags;
  153. unsigned ignore_higher:1;
  154. };
  155. struct dlm_work_item
  156. {
  157. struct list_head list;
  158. dlm_workfunc_t *func;
  159. struct dlm_ctxt *dlm;
  160. void *data;
  161. union {
  162. struct dlm_request_all_locks_priv ral;
  163. struct dlm_mig_lockres_priv ml;
  164. struct dlm_assert_master_priv am;
  165. } u;
  166. };
  167. static inline void dlm_init_work_item(struct dlm_ctxt *dlm,
  168. struct dlm_work_item *i,
  169. dlm_workfunc_t *f, void *data)
  170. {
  171. memset(i, 0, sizeof(*i));
  172. i->func = f;
  173. INIT_LIST_HEAD(&i->list);
  174. i->data = data;
  175. i->dlm = dlm; /* must have already done a dlm_grab on this! */
  176. }
  177. static inline void __dlm_set_joining_node(struct dlm_ctxt *dlm,
  178. u8 node)
  179. {
  180. assert_spin_locked(&dlm->spinlock);
  181. dlm->joining_node = node;
  182. wake_up(&dlm->dlm_join_events);
  183. }
  184. #define DLM_LOCK_RES_UNINITED 0x00000001
  185. #define DLM_LOCK_RES_RECOVERING 0x00000002
  186. #define DLM_LOCK_RES_READY 0x00000004
  187. #define DLM_LOCK_RES_DIRTY 0x00000008
  188. #define DLM_LOCK_RES_IN_PROGRESS 0x00000010
  189. #define DLM_LOCK_RES_MIGRATING 0x00000020
  190. #define DLM_LOCK_RES_DROPPING_REF 0x00000040
  191. #define DLM_LOCK_RES_BLOCK_DIRTY 0x00001000
  192. #define DLM_LOCK_RES_SETREF_INPROG 0x00002000
  193. /* max milliseconds to wait to sync up a network failure with a node death */
  194. #define DLM_NODE_DEATH_WAIT_MAX (5 * 1000)
  195. #define DLM_PURGE_INTERVAL_MS (8 * 1000)
  196. struct dlm_lock_resource
  197. {
  198. /* WARNING: Please see the comment in dlm_init_lockres before
  199. * adding fields here. */
  200. struct hlist_node hash_node;
  201. struct qstr lockname;
  202. struct kref refs;
  203. /*
  204. * Please keep granted, converting, and blocked in this order,
  205. * as some funcs want to iterate over all lists.
  206. *
  207. * All four lists are protected by the hash's reference.
  208. */
  209. struct list_head granted;
  210. struct list_head converting;
  211. struct list_head blocked;
  212. struct list_head purge;
  213. /*
  214. * These two lists require you to hold an additional reference
  215. * while they are on the list.
  216. */
  217. struct list_head dirty;
  218. struct list_head recovering; // dlm_recovery_ctxt.resources list
  219. /* unused lock resources have their last_used stamped and are
  220. * put on a list for the dlm thread to run. */
  221. unsigned long last_used;
  222. unsigned migration_pending:1;
  223. atomic_t asts_reserved;
  224. spinlock_t spinlock;
  225. wait_queue_head_t wq;
  226. u8 owner; //node which owns the lock resource, or unknown
  227. u16 state;
  228. char lvb[DLM_LVB_LEN];
  229. unsigned int inflight_locks;
  230. unsigned long refmap[BITS_TO_LONGS(O2NM_MAX_NODES)];
  231. };
  232. struct dlm_migratable_lock
  233. {
  234. __be64 cookie;
  235. /* these 3 are just padding for the in-memory structure, but
  236. * list and flags are actually used when sent over the wire */
  237. __be16 pad1;
  238. u8 list; // 0=granted, 1=converting, 2=blocked
  239. u8 flags;
  240. s8 type;
  241. s8 convert_type;
  242. s8 highest_blocked;
  243. u8 node;
  244. }; // 16 bytes
  245. struct dlm_lock
  246. {
  247. struct dlm_migratable_lock ml;
  248. struct list_head list;
  249. struct list_head ast_list;
  250. struct list_head bast_list;
  251. struct dlm_lock_resource *lockres;
  252. spinlock_t spinlock;
  253. struct kref lock_refs;
  254. // ast and bast must be callable while holding a spinlock!
  255. dlm_astlockfunc_t *ast;
  256. dlm_bastlockfunc_t *bast;
  257. void *astdata;
  258. struct dlm_lockstatus *lksb;
  259. unsigned ast_pending:1,
  260. bast_pending:1,
  261. convert_pending:1,
  262. lock_pending:1,
  263. cancel_pending:1,
  264. unlock_pending:1,
  265. lksb_kernel_allocated:1;
  266. };
  267. #define DLM_LKSB_UNUSED1 0x01
  268. #define DLM_LKSB_PUT_LVB 0x02
  269. #define DLM_LKSB_GET_LVB 0x04
  270. #define DLM_LKSB_UNUSED2 0x08
  271. #define DLM_LKSB_UNUSED3 0x10
  272. #define DLM_LKSB_UNUSED4 0x20
  273. #define DLM_LKSB_UNUSED5 0x40
  274. #define DLM_LKSB_UNUSED6 0x80
  275. enum dlm_lockres_list {
  276. DLM_GRANTED_LIST = 0,
  277. DLM_CONVERTING_LIST,
  278. DLM_BLOCKED_LIST
  279. };
  280. static inline int dlm_lvb_is_empty(char *lvb)
  281. {
  282. int i;
  283. for (i=0; i<DLM_LVB_LEN; i++)
  284. if (lvb[i])
  285. return 0;
  286. return 1;
  287. }
  288. static inline struct list_head *
  289. dlm_list_idx_to_ptr(struct dlm_lock_resource *res, enum dlm_lockres_list idx)
  290. {
  291. struct list_head *ret = NULL;
  292. if (idx == DLM_GRANTED_LIST)
  293. ret = &res->granted;
  294. else if (idx == DLM_CONVERTING_LIST)
  295. ret = &res->converting;
  296. else if (idx == DLM_BLOCKED_LIST)
  297. ret = &res->blocked;
  298. else
  299. BUG();
  300. return ret;
  301. }
  302. struct dlm_node_iter
  303. {
  304. unsigned long node_map[BITS_TO_LONGS(O2NM_MAX_NODES)];
  305. int curnode;
  306. };
  307. enum {
  308. DLM_MASTER_REQUEST_MSG = 500,
  309. DLM_UNUSED_MSG1, /* 501 */
  310. DLM_ASSERT_MASTER_MSG, /* 502 */
  311. DLM_CREATE_LOCK_MSG, /* 503 */
  312. DLM_CONVERT_LOCK_MSG, /* 504 */
  313. DLM_PROXY_AST_MSG, /* 505 */
  314. DLM_UNLOCK_LOCK_MSG, /* 506 */
  315. DLM_DEREF_LOCKRES_MSG, /* 507 */
  316. DLM_MIGRATE_REQUEST_MSG, /* 508 */
  317. DLM_MIG_LOCKRES_MSG, /* 509 */
  318. DLM_QUERY_JOIN_MSG, /* 510 */
  319. DLM_ASSERT_JOINED_MSG, /* 511 */
  320. DLM_CANCEL_JOIN_MSG, /* 512 */
  321. DLM_EXIT_DOMAIN_MSG, /* 513 */
  322. DLM_MASTER_REQUERY_MSG, /* 514 */
  323. DLM_LOCK_REQUEST_MSG, /* 515 */
  324. DLM_RECO_DATA_DONE_MSG, /* 516 */
  325. DLM_BEGIN_RECO_MSG, /* 517 */
  326. DLM_FINALIZE_RECO_MSG /* 518 */
  327. };
  328. struct dlm_reco_node_data
  329. {
  330. int state;
  331. u8 node_num;
  332. struct list_head list;
  333. };
  334. enum {
  335. DLM_RECO_NODE_DATA_DEAD = -1,
  336. DLM_RECO_NODE_DATA_INIT = 0,
  337. DLM_RECO_NODE_DATA_REQUESTING,
  338. DLM_RECO_NODE_DATA_REQUESTED,
  339. DLM_RECO_NODE_DATA_RECEIVING,
  340. DLM_RECO_NODE_DATA_DONE,
  341. DLM_RECO_NODE_DATA_FINALIZE_SENT,
  342. };
  343. enum {
  344. DLM_MASTER_RESP_NO = 0,
  345. DLM_MASTER_RESP_YES,
  346. DLM_MASTER_RESP_MAYBE,
  347. DLM_MASTER_RESP_ERROR
  348. };
  349. struct dlm_master_request
  350. {
  351. u8 node_idx;
  352. u8 namelen;
  353. __be16 pad1;
  354. __be32 flags;
  355. u8 name[O2NM_MAX_NAME_LEN];
  356. };
  357. #define DLM_ASSERT_RESPONSE_REASSERT 0x00000001
  358. #define DLM_ASSERT_RESPONSE_MASTERY_REF 0x00000002
  359. #define DLM_ASSERT_MASTER_MLE_CLEANUP 0x00000001
  360. #define DLM_ASSERT_MASTER_REQUERY 0x00000002
  361. #define DLM_ASSERT_MASTER_FINISH_MIGRATION 0x00000004
  362. struct dlm_assert_master
  363. {
  364. u8 node_idx;
  365. u8 namelen;
  366. __be16 pad1;
  367. __be32 flags;
  368. u8 name[O2NM_MAX_NAME_LEN];
  369. };
  370. #define DLM_MIGRATE_RESPONSE_MASTERY_REF 0x00000001
  371. struct dlm_migrate_request
  372. {
  373. u8 master;
  374. u8 new_master;
  375. u8 namelen;
  376. u8 pad1;
  377. __be32 pad2;
  378. u8 name[O2NM_MAX_NAME_LEN];
  379. };
  380. struct dlm_master_requery
  381. {
  382. u8 pad1;
  383. u8 pad2;
  384. u8 node_idx;
  385. u8 namelen;
  386. __be32 pad3;
  387. u8 name[O2NM_MAX_NAME_LEN];
  388. };
  389. #define DLM_MRES_RECOVERY 0x01
  390. #define DLM_MRES_MIGRATION 0x02
  391. #define DLM_MRES_ALL_DONE 0x04
  392. /*
  393. * We would like to get one whole lockres into a single network
  394. * message whenever possible. Generally speaking, there will be
  395. * at most one dlm_lock on a lockres for each node in the cluster,
  396. * plus (infrequently) any additional locks coming in from userdlm.
  397. *
  398. * struct _dlm_lockres_page
  399. * {
  400. * dlm_migratable_lockres mres;
  401. * dlm_migratable_lock ml[DLM_MAX_MIGRATABLE_LOCKS];
  402. * u8 pad[DLM_MIG_LOCKRES_RESERVED];
  403. * };
  404. *
  405. * from ../cluster/tcp.h
  406. * NET_MAX_PAYLOAD_BYTES (4096 - sizeof(net_msg))
  407. * (roughly 4080 bytes)
  408. * and sizeof(dlm_migratable_lockres) = 112 bytes
  409. * and sizeof(dlm_migratable_lock) = 16 bytes
  410. *
  411. * Choosing DLM_MAX_MIGRATABLE_LOCKS=240 and
  412. * DLM_MIG_LOCKRES_RESERVED=128 means we have this:
  413. *
  414. * (DLM_MAX_MIGRATABLE_LOCKS * sizeof(dlm_migratable_lock)) +
  415. * sizeof(dlm_migratable_lockres) + DLM_MIG_LOCKRES_RESERVED =
  416. * NET_MAX_PAYLOAD_BYTES
  417. * (240 * 16) + 112 + 128 = 4080
  418. *
  419. * So a lockres would need more than 240 locks before it would
  420. * use more than one network packet to recover. Not too bad.
  421. */
  422. #define DLM_MAX_MIGRATABLE_LOCKS 240
  423. struct dlm_migratable_lockres
  424. {
  425. u8 master;
  426. u8 lockname_len;
  427. u8 num_locks; // locks sent in this structure
  428. u8 flags;
  429. __be32 total_locks; // locks to be sent for this migration cookie
  430. __be64 mig_cookie; // cookie for this lockres migration
  431. // or zero if not needed
  432. // 16 bytes
  433. u8 lockname[DLM_LOCKID_NAME_MAX];
  434. // 48 bytes
  435. u8 lvb[DLM_LVB_LEN];
  436. // 112 bytes
  437. struct dlm_migratable_lock ml[0]; // 16 bytes each, begins at byte 112
  438. };
  439. #define DLM_MIG_LOCKRES_MAX_LEN \
  440. (sizeof(struct dlm_migratable_lockres) + \
  441. (sizeof(struct dlm_migratable_lock) * \
  442. DLM_MAX_MIGRATABLE_LOCKS) )
  443. /* from above, 128 bytes
  444. * for some undetermined future use */
  445. #define DLM_MIG_LOCKRES_RESERVED (NET_MAX_PAYLOAD_BYTES - \
  446. DLM_MIG_LOCKRES_MAX_LEN)
  447. struct dlm_create_lock
  448. {
  449. __be64 cookie;
  450. __be32 flags;
  451. u8 pad1;
  452. u8 node_idx;
  453. s8 requested_type;
  454. u8 namelen;
  455. u8 name[O2NM_MAX_NAME_LEN];
  456. };
  457. struct dlm_convert_lock
  458. {
  459. __be64 cookie;
  460. __be32 flags;
  461. u8 pad1;
  462. u8 node_idx;
  463. s8 requested_type;
  464. u8 namelen;
  465. u8 name[O2NM_MAX_NAME_LEN];
  466. s8 lvb[0];
  467. };
  468. #define DLM_CONVERT_LOCK_MAX_LEN (sizeof(struct dlm_convert_lock)+DLM_LVB_LEN)
  469. struct dlm_unlock_lock
  470. {
  471. __be64 cookie;
  472. __be32 flags;
  473. __be16 pad1;
  474. u8 node_idx;
  475. u8 namelen;
  476. u8 name[O2NM_MAX_NAME_LEN];
  477. s8 lvb[0];
  478. };
  479. #define DLM_UNLOCK_LOCK_MAX_LEN (sizeof(struct dlm_unlock_lock)+DLM_LVB_LEN)
  480. struct dlm_proxy_ast
  481. {
  482. __be64 cookie;
  483. __be32 flags;
  484. u8 node_idx;
  485. u8 type;
  486. u8 blocked_type;
  487. u8 namelen;
  488. u8 name[O2NM_MAX_NAME_LEN];
  489. s8 lvb[0];
  490. };
  491. #define DLM_PROXY_AST_MAX_LEN (sizeof(struct dlm_proxy_ast)+DLM_LVB_LEN)
  492. #define DLM_MOD_KEY (0x666c6172)
  493. enum dlm_query_join_response {
  494. JOIN_DISALLOW = 0,
  495. JOIN_OK,
  496. JOIN_OK_NO_MAP,
  497. };
  498. struct dlm_lock_request
  499. {
  500. u8 node_idx;
  501. u8 dead_node;
  502. __be16 pad1;
  503. __be32 pad2;
  504. };
  505. struct dlm_reco_data_done
  506. {
  507. u8 node_idx;
  508. u8 dead_node;
  509. __be16 pad1;
  510. __be32 pad2;
  511. /* unused for now */
  512. /* eventually we can use this to attempt
  513. * lvb recovery based on each node's info */
  514. u8 reco_lvb[DLM_LVB_LEN];
  515. };
  516. struct dlm_begin_reco
  517. {
  518. u8 node_idx;
  519. u8 dead_node;
  520. __be16 pad1;
  521. __be32 pad2;
  522. };
  523. struct dlm_query_join_request
  524. {
  525. u8 node_idx;
  526. u8 pad1[2];
  527. u8 name_len;
  528. u8 domain[O2NM_MAX_NAME_LEN];
  529. };
  530. struct dlm_assert_joined
  531. {
  532. u8 node_idx;
  533. u8 pad1[2];
  534. u8 name_len;
  535. u8 domain[O2NM_MAX_NAME_LEN];
  536. };
  537. struct dlm_cancel_join
  538. {
  539. u8 node_idx;
  540. u8 pad1[2];
  541. u8 name_len;
  542. u8 domain[O2NM_MAX_NAME_LEN];
  543. };
  544. struct dlm_exit_domain
  545. {
  546. u8 node_idx;
  547. u8 pad1[3];
  548. };
  549. struct dlm_finalize_reco
  550. {
  551. u8 node_idx;
  552. u8 dead_node;
  553. u8 flags;
  554. u8 pad1;
  555. __be32 pad2;
  556. };
  557. struct dlm_deref_lockres
  558. {
  559. u32 pad1;
  560. u16 pad2;
  561. u8 node_idx;
  562. u8 namelen;
  563. u8 name[O2NM_MAX_NAME_LEN];
  564. };
  565. static inline enum dlm_status
  566. __dlm_lockres_state_to_status(struct dlm_lock_resource *res)
  567. {
  568. enum dlm_status status = DLM_NORMAL;
  569. assert_spin_locked(&res->spinlock);
  570. if (res->state & DLM_LOCK_RES_RECOVERING)
  571. status = DLM_RECOVERING;
  572. else if (res->state & DLM_LOCK_RES_MIGRATING)
  573. status = DLM_MIGRATING;
  574. else if (res->state & DLM_LOCK_RES_IN_PROGRESS)
  575. status = DLM_FORWARD;
  576. return status;
  577. }
  578. static inline u8 dlm_get_lock_cookie_node(u64 cookie)
  579. {
  580. u8 ret;
  581. cookie >>= 56;
  582. ret = (u8)(cookie & 0xffULL);
  583. return ret;
  584. }
  585. static inline unsigned long long dlm_get_lock_cookie_seq(u64 cookie)
  586. {
  587. unsigned long long ret;
  588. ret = ((unsigned long long)cookie) & 0x00ffffffffffffffULL;
  589. return ret;
  590. }
  591. struct dlm_lock * dlm_new_lock(int type, u8 node, u64 cookie,
  592. struct dlm_lockstatus *lksb);
  593. void dlm_lock_get(struct dlm_lock *lock);
  594. void dlm_lock_put(struct dlm_lock *lock);
  595. void dlm_lock_attach_lockres(struct dlm_lock *lock,
  596. struct dlm_lock_resource *res);
  597. int dlm_create_lock_handler(struct o2net_msg *msg, u32 len, void *data,
  598. void **ret_data);
  599. int dlm_convert_lock_handler(struct o2net_msg *msg, u32 len, void *data,
  600. void **ret_data);
  601. int dlm_proxy_ast_handler(struct o2net_msg *msg, u32 len, void *data,
  602. void **ret_data);
  603. void dlm_revert_pending_convert(struct dlm_lock_resource *res,
  604. struct dlm_lock *lock);
  605. void dlm_revert_pending_lock(struct dlm_lock_resource *res,
  606. struct dlm_lock *lock);
  607. int dlm_unlock_lock_handler(struct o2net_msg *msg, u32 len, void *data,
  608. void **ret_data);
  609. void dlm_commit_pending_cancel(struct dlm_lock_resource *res,
  610. struct dlm_lock *lock);
  611. void dlm_commit_pending_unlock(struct dlm_lock_resource *res,
  612. struct dlm_lock *lock);
  613. int dlm_launch_thread(struct dlm_ctxt *dlm);
  614. void dlm_complete_thread(struct dlm_ctxt *dlm);
  615. int dlm_launch_recovery_thread(struct dlm_ctxt *dlm);
  616. void dlm_complete_recovery_thread(struct dlm_ctxt *dlm);
  617. void dlm_wait_for_recovery(struct dlm_ctxt *dlm);
  618. void dlm_kick_recovery_thread(struct dlm_ctxt *dlm);
  619. int dlm_is_node_dead(struct dlm_ctxt *dlm, u8 node);
  620. int dlm_wait_for_node_death(struct dlm_ctxt *dlm, u8 node, int timeout);
  621. int dlm_wait_for_node_recovery(struct dlm_ctxt *dlm, u8 node, int timeout);
  622. void dlm_put(struct dlm_ctxt *dlm);
  623. struct dlm_ctxt *dlm_grab(struct dlm_ctxt *dlm);
  624. int dlm_domain_fully_joined(struct dlm_ctxt *dlm);
  625. void __dlm_lockres_calc_usage(struct dlm_ctxt *dlm,
  626. struct dlm_lock_resource *res);
  627. void dlm_lockres_calc_usage(struct dlm_ctxt *dlm,
  628. struct dlm_lock_resource *res);
  629. static inline void dlm_lockres_get(struct dlm_lock_resource *res)
  630. {
  631. /* This is called on every lookup, so it might be worth
  632. * inlining. */
  633. kref_get(&res->refs);
  634. }
  635. void dlm_lockres_put(struct dlm_lock_resource *res);
  636. void __dlm_unhash_lockres(struct dlm_lock_resource *res);
  637. void __dlm_insert_lockres(struct dlm_ctxt *dlm,
  638. struct dlm_lock_resource *res);
  639. struct dlm_lock_resource * __dlm_lookup_lockres_full(struct dlm_ctxt *dlm,
  640. const char *name,
  641. unsigned int len,
  642. unsigned int hash);
  643. struct dlm_lock_resource * __dlm_lookup_lockres(struct dlm_ctxt *dlm,
  644. const char *name,
  645. unsigned int len,
  646. unsigned int hash);
  647. struct dlm_lock_resource * dlm_lookup_lockres(struct dlm_ctxt *dlm,
  648. const char *name,
  649. unsigned int len);
  650. int dlm_is_host_down(int errno);
  651. void dlm_change_lockres_owner(struct dlm_ctxt *dlm,
  652. struct dlm_lock_resource *res,
  653. u8 owner);
  654. struct dlm_lock_resource * dlm_get_lock_resource(struct dlm_ctxt *dlm,
  655. const char *lockid,
  656. int namelen,
  657. int flags);
  658. struct dlm_lock_resource *dlm_new_lockres(struct dlm_ctxt *dlm,
  659. const char *name,
  660. unsigned int namelen);
  661. #define dlm_lockres_set_refmap_bit(bit,res) \
  662. __dlm_lockres_set_refmap_bit(bit,res,__FILE__,__LINE__)
  663. #define dlm_lockres_clear_refmap_bit(bit,res) \
  664. __dlm_lockres_clear_refmap_bit(bit,res,__FILE__,__LINE__)
  665. static inline void __dlm_lockres_set_refmap_bit(int bit,
  666. struct dlm_lock_resource *res,
  667. const char *file,
  668. int line)
  669. {
  670. //printk("%s:%d:%.*s: setting bit %d\n", file, line,
  671. // res->lockname.len, res->lockname.name, bit);
  672. set_bit(bit, res->refmap);
  673. }
  674. static inline void __dlm_lockres_clear_refmap_bit(int bit,
  675. struct dlm_lock_resource *res,
  676. const char *file,
  677. int line)
  678. {
  679. //printk("%s:%d:%.*s: clearing bit %d\n", file, line,
  680. // res->lockname.len, res->lockname.name, bit);
  681. clear_bit(bit, res->refmap);
  682. }
  683. void __dlm_lockres_drop_inflight_ref(struct dlm_ctxt *dlm,
  684. struct dlm_lock_resource *res,
  685. const char *file,
  686. int line);
  687. void __dlm_lockres_grab_inflight_ref(struct dlm_ctxt *dlm,
  688. struct dlm_lock_resource *res,
  689. int new_lockres,
  690. const char *file,
  691. int line);
  692. #define dlm_lockres_drop_inflight_ref(d,r) \
  693. __dlm_lockres_drop_inflight_ref(d,r,__FILE__,__LINE__)
  694. #define dlm_lockres_grab_inflight_ref(d,r) \
  695. __dlm_lockres_grab_inflight_ref(d,r,0,__FILE__,__LINE__)
  696. #define dlm_lockres_grab_inflight_ref_new(d,r) \
  697. __dlm_lockres_grab_inflight_ref(d,r,1,__FILE__,__LINE__)
  698. void dlm_queue_ast(struct dlm_ctxt *dlm, struct dlm_lock *lock);
  699. void dlm_queue_bast(struct dlm_ctxt *dlm, struct dlm_lock *lock);
  700. void dlm_do_local_ast(struct dlm_ctxt *dlm,
  701. struct dlm_lock_resource *res,
  702. struct dlm_lock *lock);
  703. int dlm_do_remote_ast(struct dlm_ctxt *dlm,
  704. struct dlm_lock_resource *res,
  705. struct dlm_lock *lock);
  706. void dlm_do_local_bast(struct dlm_ctxt *dlm,
  707. struct dlm_lock_resource *res,
  708. struct dlm_lock *lock,
  709. int blocked_type);
  710. int dlm_send_proxy_ast_msg(struct dlm_ctxt *dlm,
  711. struct dlm_lock_resource *res,
  712. struct dlm_lock *lock,
  713. int msg_type,
  714. int blocked_type, int flags);
  715. static inline int dlm_send_proxy_bast(struct dlm_ctxt *dlm,
  716. struct dlm_lock_resource *res,
  717. struct dlm_lock *lock,
  718. int blocked_type)
  719. {
  720. return dlm_send_proxy_ast_msg(dlm, res, lock, DLM_BAST,
  721. blocked_type, 0);
  722. }
  723. static inline int dlm_send_proxy_ast(struct dlm_ctxt *dlm,
  724. struct dlm_lock_resource *res,
  725. struct dlm_lock *lock,
  726. int flags)
  727. {
  728. return dlm_send_proxy_ast_msg(dlm, res, lock, DLM_AST,
  729. 0, flags);
  730. }
  731. void dlm_print_one_lock_resource(struct dlm_lock_resource *res);
  732. void __dlm_print_one_lock_resource(struct dlm_lock_resource *res);
  733. u8 dlm_nm_this_node(struct dlm_ctxt *dlm);
  734. void dlm_kick_thread(struct dlm_ctxt *dlm, struct dlm_lock_resource *res);
  735. void __dlm_dirty_lockres(struct dlm_ctxt *dlm, struct dlm_lock_resource *res);
  736. int dlm_nm_init(struct dlm_ctxt *dlm);
  737. int dlm_heartbeat_init(struct dlm_ctxt *dlm);
  738. void dlm_hb_node_down_cb(struct o2nm_node *node, int idx, void *data);
  739. void dlm_hb_node_up_cb(struct o2nm_node *node, int idx, void *data);
  740. int dlm_empty_lockres(struct dlm_ctxt *dlm, struct dlm_lock_resource *res);
  741. int dlm_finish_migration(struct dlm_ctxt *dlm,
  742. struct dlm_lock_resource *res,
  743. u8 old_master);
  744. void dlm_lockres_release_ast(struct dlm_ctxt *dlm,
  745. struct dlm_lock_resource *res);
  746. void __dlm_lockres_reserve_ast(struct dlm_lock_resource *res);
  747. int dlm_master_request_handler(struct o2net_msg *msg, u32 len, void *data,
  748. void **ret_data);
  749. int dlm_assert_master_handler(struct o2net_msg *msg, u32 len, void *data,
  750. void **ret_data);
  751. void dlm_assert_master_post_handler(int status, void *data, void *ret_data);
  752. int dlm_deref_lockres_handler(struct o2net_msg *msg, u32 len, void *data,
  753. void **ret_data);
  754. int dlm_migrate_request_handler(struct o2net_msg *msg, u32 len, void *data,
  755. void **ret_data);
  756. int dlm_mig_lockres_handler(struct o2net_msg *msg, u32 len, void *data,
  757. void **ret_data);
  758. int dlm_master_requery_handler(struct o2net_msg *msg, u32 len, void *data,
  759. void **ret_data);
  760. int dlm_request_all_locks_handler(struct o2net_msg *msg, u32 len, void *data,
  761. void **ret_data);
  762. int dlm_reco_data_done_handler(struct o2net_msg *msg, u32 len, void *data,
  763. void **ret_data);
  764. int dlm_begin_reco_handler(struct o2net_msg *msg, u32 len, void *data,
  765. void **ret_data);
  766. int dlm_finalize_reco_handler(struct o2net_msg *msg, u32 len, void *data,
  767. void **ret_data);
  768. int dlm_do_master_requery(struct dlm_ctxt *dlm, struct dlm_lock_resource *res,
  769. u8 nodenum, u8 *real_master);
  770. int dlm_dispatch_assert_master(struct dlm_ctxt *dlm,
  771. struct dlm_lock_resource *res,
  772. int ignore_higher,
  773. u8 request_from,
  774. u32 flags);
  775. int dlm_send_one_lockres(struct dlm_ctxt *dlm,
  776. struct dlm_lock_resource *res,
  777. struct dlm_migratable_lockres *mres,
  778. u8 send_to,
  779. u8 flags);
  780. void dlm_move_lockres_to_recovery_list(struct dlm_ctxt *dlm,
  781. struct dlm_lock_resource *res);
  782. /* will exit holding res->spinlock, but may drop in function */
  783. void __dlm_wait_on_lockres_flags(struct dlm_lock_resource *res, int flags);
  784. void __dlm_wait_on_lockres_flags_set(struct dlm_lock_resource *res, int flags);
  785. /* will exit holding res->spinlock, but may drop in function */
  786. static inline void __dlm_wait_on_lockres(struct dlm_lock_resource *res)
  787. {
  788. __dlm_wait_on_lockres_flags(res, (DLM_LOCK_RES_IN_PROGRESS|
  789. DLM_LOCK_RES_RECOVERING|
  790. DLM_LOCK_RES_MIGRATING));
  791. }
  792. int dlm_init_mle_cache(void);
  793. void dlm_destroy_mle_cache(void);
  794. void dlm_hb_event_notify_attached(struct dlm_ctxt *dlm, int idx, int node_up);
  795. int dlm_drop_lockres_ref(struct dlm_ctxt *dlm,
  796. struct dlm_lock_resource *res);
  797. void dlm_clean_master_list(struct dlm_ctxt *dlm,
  798. u8 dead_node);
  799. int dlm_lock_basts_flushed(struct dlm_ctxt *dlm, struct dlm_lock *lock);
  800. int __dlm_lockres_has_locks(struct dlm_lock_resource *res);
  801. int __dlm_lockres_unused(struct dlm_lock_resource *res);
  802. static inline const char * dlm_lock_mode_name(int mode)
  803. {
  804. switch (mode) {
  805. case LKM_EXMODE:
  806. return "EX";
  807. case LKM_PRMODE:
  808. return "PR";
  809. case LKM_NLMODE:
  810. return "NL";
  811. }
  812. return "UNKNOWN";
  813. }
  814. static inline int dlm_lock_compatible(int existing, int request)
  815. {
  816. /* NO_LOCK compatible with all */
  817. if (request == LKM_NLMODE ||
  818. existing == LKM_NLMODE)
  819. return 1;
  820. /* EX incompatible with all non-NO_LOCK */
  821. if (request == LKM_EXMODE)
  822. return 0;
  823. /* request must be PR, which is compatible with PR */
  824. if (existing == LKM_PRMODE)
  825. return 1;
  826. return 0;
  827. }
  828. static inline int dlm_lock_on_list(struct list_head *head,
  829. struct dlm_lock *lock)
  830. {
  831. struct list_head *iter;
  832. struct dlm_lock *tmplock;
  833. list_for_each(iter, head) {
  834. tmplock = list_entry(iter, struct dlm_lock, list);
  835. if (tmplock == lock)
  836. return 1;
  837. }
  838. return 0;
  839. }
  840. static inline enum dlm_status dlm_err_to_dlm_status(int err)
  841. {
  842. enum dlm_status ret;
  843. if (err == -ENOMEM)
  844. ret = DLM_SYSERR;
  845. else if (err == -ETIMEDOUT || o2net_link_down(err, NULL))
  846. ret = DLM_NOLOCKMGR;
  847. else if (err == -EINVAL)
  848. ret = DLM_BADPARAM;
  849. else if (err == -ENAMETOOLONG)
  850. ret = DLM_IVBUFLEN;
  851. else
  852. ret = DLM_BADARGS;
  853. return ret;
  854. }
  855. static inline void dlm_node_iter_init(unsigned long *map,
  856. struct dlm_node_iter *iter)
  857. {
  858. memcpy(iter->node_map, map, sizeof(iter->node_map));
  859. iter->curnode = -1;
  860. }
  861. static inline int dlm_node_iter_next(struct dlm_node_iter *iter)
  862. {
  863. int bit;
  864. bit = find_next_bit(iter->node_map, O2NM_MAX_NODES, iter->curnode+1);
  865. if (bit >= O2NM_MAX_NODES) {
  866. iter->curnode = O2NM_MAX_NODES;
  867. return -ENOENT;
  868. }
  869. iter->curnode = bit;
  870. return bit;
  871. }
  872. #endif /* DLMCOMMON_H */