dlmcommon.h 26 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012
  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. /* max milliseconds to wait to sync up a network failure with a node death */
  193. #define DLM_NODE_DEATH_WAIT_MAX (5 * 1000)
  194. #define DLM_PURGE_INTERVAL_MS (8 * 1000)
  195. struct dlm_lock_resource
  196. {
  197. /* WARNING: Please see the comment in dlm_init_lockres before
  198. * adding fields here. */
  199. struct hlist_node hash_node;
  200. struct qstr lockname;
  201. struct kref refs;
  202. /*
  203. * Please keep granted, converting, and blocked in this order,
  204. * as some funcs want to iterate over all lists.
  205. *
  206. * All four lists are protected by the hash's reference.
  207. */
  208. struct list_head granted;
  209. struct list_head converting;
  210. struct list_head blocked;
  211. struct list_head purge;
  212. /*
  213. * These two lists require you to hold an additional reference
  214. * while they are on the list.
  215. */
  216. struct list_head dirty;
  217. struct list_head recovering; // dlm_recovery_ctxt.resources list
  218. /* unused lock resources have their last_used stamped and are
  219. * put on a list for the dlm thread to run. */
  220. unsigned long last_used;
  221. unsigned migration_pending:1;
  222. atomic_t asts_reserved;
  223. spinlock_t spinlock;
  224. wait_queue_head_t wq;
  225. u8 owner; //node which owns the lock resource, or unknown
  226. u16 state;
  227. char lvb[DLM_LVB_LEN];
  228. unsigned int inflight_locks;
  229. unsigned long refmap[BITS_TO_LONGS(O2NM_MAX_NODES)];
  230. };
  231. struct dlm_migratable_lock
  232. {
  233. __be64 cookie;
  234. /* these 3 are just padding for the in-memory structure, but
  235. * list and flags are actually used when sent over the wire */
  236. __be16 pad1;
  237. u8 list; // 0=granted, 1=converting, 2=blocked
  238. u8 flags;
  239. s8 type;
  240. s8 convert_type;
  241. s8 highest_blocked;
  242. u8 node;
  243. }; // 16 bytes
  244. struct dlm_lock
  245. {
  246. struct dlm_migratable_lock ml;
  247. struct list_head list;
  248. struct list_head ast_list;
  249. struct list_head bast_list;
  250. struct dlm_lock_resource *lockres;
  251. spinlock_t spinlock;
  252. struct kref lock_refs;
  253. // ast and bast must be callable while holding a spinlock!
  254. dlm_astlockfunc_t *ast;
  255. dlm_bastlockfunc_t *bast;
  256. void *astdata;
  257. struct dlm_lockstatus *lksb;
  258. unsigned ast_pending:1,
  259. bast_pending:1,
  260. convert_pending:1,
  261. lock_pending:1,
  262. cancel_pending:1,
  263. unlock_pending:1,
  264. lksb_kernel_allocated:1;
  265. };
  266. #define DLM_LKSB_UNUSED1 0x01
  267. #define DLM_LKSB_PUT_LVB 0x02
  268. #define DLM_LKSB_GET_LVB 0x04
  269. #define DLM_LKSB_UNUSED2 0x08
  270. #define DLM_LKSB_UNUSED3 0x10
  271. #define DLM_LKSB_UNUSED4 0x20
  272. #define DLM_LKSB_UNUSED5 0x40
  273. #define DLM_LKSB_UNUSED6 0x80
  274. enum dlm_lockres_list {
  275. DLM_GRANTED_LIST = 0,
  276. DLM_CONVERTING_LIST,
  277. DLM_BLOCKED_LIST
  278. };
  279. static inline int dlm_lvb_is_empty(char *lvb)
  280. {
  281. int i;
  282. for (i=0; i<DLM_LVB_LEN; i++)
  283. if (lvb[i])
  284. return 0;
  285. return 1;
  286. }
  287. static inline struct list_head *
  288. dlm_list_idx_to_ptr(struct dlm_lock_resource *res, enum dlm_lockres_list idx)
  289. {
  290. struct list_head *ret = NULL;
  291. if (idx == DLM_GRANTED_LIST)
  292. ret = &res->granted;
  293. else if (idx == DLM_CONVERTING_LIST)
  294. ret = &res->converting;
  295. else if (idx == DLM_BLOCKED_LIST)
  296. ret = &res->blocked;
  297. else
  298. BUG();
  299. return ret;
  300. }
  301. struct dlm_node_iter
  302. {
  303. unsigned long node_map[BITS_TO_LONGS(O2NM_MAX_NODES)];
  304. int curnode;
  305. };
  306. enum {
  307. DLM_MASTER_REQUEST_MSG = 500,
  308. DLM_UNUSED_MSG1, /* 501 */
  309. DLM_ASSERT_MASTER_MSG, /* 502 */
  310. DLM_CREATE_LOCK_MSG, /* 503 */
  311. DLM_CONVERT_LOCK_MSG, /* 504 */
  312. DLM_PROXY_AST_MSG, /* 505 */
  313. DLM_UNLOCK_LOCK_MSG, /* 506 */
  314. DLM_DEREF_LOCKRES_MSG, /* 507 */
  315. DLM_MIGRATE_REQUEST_MSG, /* 508 */
  316. DLM_MIG_LOCKRES_MSG, /* 509 */
  317. DLM_QUERY_JOIN_MSG, /* 510 */
  318. DLM_ASSERT_JOINED_MSG, /* 511 */
  319. DLM_CANCEL_JOIN_MSG, /* 512 */
  320. DLM_EXIT_DOMAIN_MSG, /* 513 */
  321. DLM_MASTER_REQUERY_MSG, /* 514 */
  322. DLM_LOCK_REQUEST_MSG, /* 515 */
  323. DLM_RECO_DATA_DONE_MSG, /* 516 */
  324. DLM_BEGIN_RECO_MSG, /* 517 */
  325. DLM_FINALIZE_RECO_MSG /* 518 */
  326. };
  327. struct dlm_reco_node_data
  328. {
  329. int state;
  330. u8 node_num;
  331. struct list_head list;
  332. };
  333. enum {
  334. DLM_RECO_NODE_DATA_DEAD = -1,
  335. DLM_RECO_NODE_DATA_INIT = 0,
  336. DLM_RECO_NODE_DATA_REQUESTING,
  337. DLM_RECO_NODE_DATA_REQUESTED,
  338. DLM_RECO_NODE_DATA_RECEIVING,
  339. DLM_RECO_NODE_DATA_DONE,
  340. DLM_RECO_NODE_DATA_FINALIZE_SENT,
  341. };
  342. enum {
  343. DLM_MASTER_RESP_NO = 0,
  344. DLM_MASTER_RESP_YES,
  345. DLM_MASTER_RESP_MAYBE,
  346. DLM_MASTER_RESP_ERROR
  347. };
  348. struct dlm_master_request
  349. {
  350. u8 node_idx;
  351. u8 namelen;
  352. __be16 pad1;
  353. __be32 flags;
  354. u8 name[O2NM_MAX_NAME_LEN];
  355. };
  356. #define DLM_ASSERT_RESPONSE_REASSERT 0x00000001
  357. #define DLM_ASSERT_RESPONSE_MASTERY_REF 0x00000002
  358. #define DLM_ASSERT_MASTER_MLE_CLEANUP 0x00000001
  359. #define DLM_ASSERT_MASTER_REQUERY 0x00000002
  360. #define DLM_ASSERT_MASTER_FINISH_MIGRATION 0x00000004
  361. struct dlm_assert_master
  362. {
  363. u8 node_idx;
  364. u8 namelen;
  365. __be16 pad1;
  366. __be32 flags;
  367. u8 name[O2NM_MAX_NAME_LEN];
  368. };
  369. #define DLM_MIGRATE_RESPONSE_MASTERY_REF 0x00000001
  370. struct dlm_migrate_request
  371. {
  372. u8 master;
  373. u8 new_master;
  374. u8 namelen;
  375. u8 pad1;
  376. __be32 pad2;
  377. u8 name[O2NM_MAX_NAME_LEN];
  378. };
  379. struct dlm_master_requery
  380. {
  381. u8 pad1;
  382. u8 pad2;
  383. u8 node_idx;
  384. u8 namelen;
  385. __be32 pad3;
  386. u8 name[O2NM_MAX_NAME_LEN];
  387. };
  388. #define DLM_MRES_RECOVERY 0x01
  389. #define DLM_MRES_MIGRATION 0x02
  390. #define DLM_MRES_ALL_DONE 0x04
  391. /*
  392. * We would like to get one whole lockres into a single network
  393. * message whenever possible. Generally speaking, there will be
  394. * at most one dlm_lock on a lockres for each node in the cluster,
  395. * plus (infrequently) any additional locks coming in from userdlm.
  396. *
  397. * struct _dlm_lockres_page
  398. * {
  399. * dlm_migratable_lockres mres;
  400. * dlm_migratable_lock ml[DLM_MAX_MIGRATABLE_LOCKS];
  401. * u8 pad[DLM_MIG_LOCKRES_RESERVED];
  402. * };
  403. *
  404. * from ../cluster/tcp.h
  405. * NET_MAX_PAYLOAD_BYTES (4096 - sizeof(net_msg))
  406. * (roughly 4080 bytes)
  407. * and sizeof(dlm_migratable_lockres) = 112 bytes
  408. * and sizeof(dlm_migratable_lock) = 16 bytes
  409. *
  410. * Choosing DLM_MAX_MIGRATABLE_LOCKS=240 and
  411. * DLM_MIG_LOCKRES_RESERVED=128 means we have this:
  412. *
  413. * (DLM_MAX_MIGRATABLE_LOCKS * sizeof(dlm_migratable_lock)) +
  414. * sizeof(dlm_migratable_lockres) + DLM_MIG_LOCKRES_RESERVED =
  415. * NET_MAX_PAYLOAD_BYTES
  416. * (240 * 16) + 112 + 128 = 4080
  417. *
  418. * So a lockres would need more than 240 locks before it would
  419. * use more than one network packet to recover. Not too bad.
  420. */
  421. #define DLM_MAX_MIGRATABLE_LOCKS 240
  422. struct dlm_migratable_lockres
  423. {
  424. u8 master;
  425. u8 lockname_len;
  426. u8 num_locks; // locks sent in this structure
  427. u8 flags;
  428. __be32 total_locks; // locks to be sent for this migration cookie
  429. __be64 mig_cookie; // cookie for this lockres migration
  430. // or zero if not needed
  431. // 16 bytes
  432. u8 lockname[DLM_LOCKID_NAME_MAX];
  433. // 48 bytes
  434. u8 lvb[DLM_LVB_LEN];
  435. // 112 bytes
  436. struct dlm_migratable_lock ml[0]; // 16 bytes each, begins at byte 112
  437. };
  438. #define DLM_MIG_LOCKRES_MAX_LEN \
  439. (sizeof(struct dlm_migratable_lockres) + \
  440. (sizeof(struct dlm_migratable_lock) * \
  441. DLM_MAX_MIGRATABLE_LOCKS) )
  442. /* from above, 128 bytes
  443. * for some undetermined future use */
  444. #define DLM_MIG_LOCKRES_RESERVED (NET_MAX_PAYLOAD_BYTES - \
  445. DLM_MIG_LOCKRES_MAX_LEN)
  446. struct dlm_create_lock
  447. {
  448. __be64 cookie;
  449. __be32 flags;
  450. u8 pad1;
  451. u8 node_idx;
  452. s8 requested_type;
  453. u8 namelen;
  454. u8 name[O2NM_MAX_NAME_LEN];
  455. };
  456. struct dlm_convert_lock
  457. {
  458. __be64 cookie;
  459. __be32 flags;
  460. u8 pad1;
  461. u8 node_idx;
  462. s8 requested_type;
  463. u8 namelen;
  464. u8 name[O2NM_MAX_NAME_LEN];
  465. s8 lvb[0];
  466. };
  467. #define DLM_CONVERT_LOCK_MAX_LEN (sizeof(struct dlm_convert_lock)+DLM_LVB_LEN)
  468. struct dlm_unlock_lock
  469. {
  470. __be64 cookie;
  471. __be32 flags;
  472. __be16 pad1;
  473. u8 node_idx;
  474. u8 namelen;
  475. u8 name[O2NM_MAX_NAME_LEN];
  476. s8 lvb[0];
  477. };
  478. #define DLM_UNLOCK_LOCK_MAX_LEN (sizeof(struct dlm_unlock_lock)+DLM_LVB_LEN)
  479. struct dlm_proxy_ast
  480. {
  481. __be64 cookie;
  482. __be32 flags;
  483. u8 node_idx;
  484. u8 type;
  485. u8 blocked_type;
  486. u8 namelen;
  487. u8 name[O2NM_MAX_NAME_LEN];
  488. s8 lvb[0];
  489. };
  490. #define DLM_PROXY_AST_MAX_LEN (sizeof(struct dlm_proxy_ast)+DLM_LVB_LEN)
  491. #define DLM_MOD_KEY (0x666c6172)
  492. enum dlm_query_join_response {
  493. JOIN_DISALLOW = 0,
  494. JOIN_OK,
  495. JOIN_OK_NO_MAP,
  496. };
  497. struct dlm_lock_request
  498. {
  499. u8 node_idx;
  500. u8 dead_node;
  501. __be16 pad1;
  502. __be32 pad2;
  503. };
  504. struct dlm_reco_data_done
  505. {
  506. u8 node_idx;
  507. u8 dead_node;
  508. __be16 pad1;
  509. __be32 pad2;
  510. /* unused for now */
  511. /* eventually we can use this to attempt
  512. * lvb recovery based on each node's info */
  513. u8 reco_lvb[DLM_LVB_LEN];
  514. };
  515. struct dlm_begin_reco
  516. {
  517. u8 node_idx;
  518. u8 dead_node;
  519. __be16 pad1;
  520. __be32 pad2;
  521. };
  522. struct dlm_query_join_request
  523. {
  524. u8 node_idx;
  525. u8 pad1[2];
  526. u8 name_len;
  527. u8 domain[O2NM_MAX_NAME_LEN];
  528. };
  529. struct dlm_assert_joined
  530. {
  531. u8 node_idx;
  532. u8 pad1[2];
  533. u8 name_len;
  534. u8 domain[O2NM_MAX_NAME_LEN];
  535. };
  536. struct dlm_cancel_join
  537. {
  538. u8 node_idx;
  539. u8 pad1[2];
  540. u8 name_len;
  541. u8 domain[O2NM_MAX_NAME_LEN];
  542. };
  543. struct dlm_exit_domain
  544. {
  545. u8 node_idx;
  546. u8 pad1[3];
  547. };
  548. struct dlm_finalize_reco
  549. {
  550. u8 node_idx;
  551. u8 dead_node;
  552. u8 flags;
  553. u8 pad1;
  554. __be32 pad2;
  555. };
  556. struct dlm_deref_lockres
  557. {
  558. u32 pad1;
  559. u16 pad2;
  560. u8 node_idx;
  561. u8 namelen;
  562. u8 name[O2NM_MAX_NAME_LEN];
  563. };
  564. static inline enum dlm_status
  565. __dlm_lockres_state_to_status(struct dlm_lock_resource *res)
  566. {
  567. enum dlm_status status = DLM_NORMAL;
  568. assert_spin_locked(&res->spinlock);
  569. if (res->state & DLM_LOCK_RES_RECOVERING)
  570. status = DLM_RECOVERING;
  571. else if (res->state & DLM_LOCK_RES_MIGRATING)
  572. status = DLM_MIGRATING;
  573. else if (res->state & DLM_LOCK_RES_IN_PROGRESS)
  574. status = DLM_FORWARD;
  575. return status;
  576. }
  577. static inline u8 dlm_get_lock_cookie_node(u64 cookie)
  578. {
  579. u8 ret;
  580. cookie >>= 56;
  581. ret = (u8)(cookie & 0xffULL);
  582. return ret;
  583. }
  584. static inline unsigned long long dlm_get_lock_cookie_seq(u64 cookie)
  585. {
  586. unsigned long long ret;
  587. ret = ((unsigned long long)cookie) & 0x00ffffffffffffffULL;
  588. return ret;
  589. }
  590. struct dlm_lock * dlm_new_lock(int type, u8 node, u64 cookie,
  591. struct dlm_lockstatus *lksb);
  592. void dlm_lock_get(struct dlm_lock *lock);
  593. void dlm_lock_put(struct dlm_lock *lock);
  594. void dlm_lock_attach_lockres(struct dlm_lock *lock,
  595. struct dlm_lock_resource *res);
  596. int dlm_create_lock_handler(struct o2net_msg *msg, u32 len, void *data);
  597. int dlm_convert_lock_handler(struct o2net_msg *msg, u32 len, void *data);
  598. int dlm_proxy_ast_handler(struct o2net_msg *msg, u32 len, void *data);
  599. void dlm_revert_pending_convert(struct dlm_lock_resource *res,
  600. struct dlm_lock *lock);
  601. void dlm_revert_pending_lock(struct dlm_lock_resource *res,
  602. struct dlm_lock *lock);
  603. int dlm_unlock_lock_handler(struct o2net_msg *msg, u32 len, void *data);
  604. void dlm_commit_pending_cancel(struct dlm_lock_resource *res,
  605. struct dlm_lock *lock);
  606. void dlm_commit_pending_unlock(struct dlm_lock_resource *res,
  607. struct dlm_lock *lock);
  608. int dlm_launch_thread(struct dlm_ctxt *dlm);
  609. void dlm_complete_thread(struct dlm_ctxt *dlm);
  610. int dlm_launch_recovery_thread(struct dlm_ctxt *dlm);
  611. void dlm_complete_recovery_thread(struct dlm_ctxt *dlm);
  612. void dlm_wait_for_recovery(struct dlm_ctxt *dlm);
  613. void dlm_kick_recovery_thread(struct dlm_ctxt *dlm);
  614. int dlm_is_node_dead(struct dlm_ctxt *dlm, u8 node);
  615. int dlm_wait_for_node_death(struct dlm_ctxt *dlm, u8 node, int timeout);
  616. int dlm_wait_for_node_recovery(struct dlm_ctxt *dlm, u8 node, int timeout);
  617. void dlm_put(struct dlm_ctxt *dlm);
  618. struct dlm_ctxt *dlm_grab(struct dlm_ctxt *dlm);
  619. int dlm_domain_fully_joined(struct dlm_ctxt *dlm);
  620. void __dlm_lockres_calc_usage(struct dlm_ctxt *dlm,
  621. struct dlm_lock_resource *res);
  622. void dlm_lockres_calc_usage(struct dlm_ctxt *dlm,
  623. struct dlm_lock_resource *res);
  624. static inline void dlm_lockres_get(struct dlm_lock_resource *res)
  625. {
  626. /* This is called on every lookup, so it might be worth
  627. * inlining. */
  628. kref_get(&res->refs);
  629. }
  630. void dlm_lockres_put(struct dlm_lock_resource *res);
  631. void __dlm_unhash_lockres(struct dlm_lock_resource *res);
  632. void __dlm_insert_lockres(struct dlm_ctxt *dlm,
  633. struct dlm_lock_resource *res);
  634. struct dlm_lock_resource * __dlm_lookup_lockres_full(struct dlm_ctxt *dlm,
  635. const char *name,
  636. unsigned int len,
  637. unsigned int hash);
  638. struct dlm_lock_resource * __dlm_lookup_lockres(struct dlm_ctxt *dlm,
  639. const char *name,
  640. unsigned int len,
  641. unsigned int hash);
  642. struct dlm_lock_resource * dlm_lookup_lockres(struct dlm_ctxt *dlm,
  643. const char *name,
  644. unsigned int len);
  645. int dlm_is_host_down(int errno);
  646. void dlm_change_lockres_owner(struct dlm_ctxt *dlm,
  647. struct dlm_lock_resource *res,
  648. u8 owner);
  649. struct dlm_lock_resource * dlm_get_lock_resource(struct dlm_ctxt *dlm,
  650. const char *lockid,
  651. int namelen,
  652. int flags);
  653. struct dlm_lock_resource *dlm_new_lockres(struct dlm_ctxt *dlm,
  654. const char *name,
  655. unsigned int namelen);
  656. #define dlm_lockres_set_refmap_bit(bit,res) \
  657. __dlm_lockres_set_refmap_bit(bit,res,__FILE__,__LINE__)
  658. #define dlm_lockres_clear_refmap_bit(bit,res) \
  659. __dlm_lockres_clear_refmap_bit(bit,res,__FILE__,__LINE__)
  660. static inline void __dlm_lockres_set_refmap_bit(int bit,
  661. struct dlm_lock_resource *res,
  662. const char *file,
  663. int line)
  664. {
  665. //printk("%s:%d:%.*s: setting bit %d\n", file, line,
  666. // res->lockname.len, res->lockname.name, bit);
  667. set_bit(bit, res->refmap);
  668. }
  669. static inline void __dlm_lockres_clear_refmap_bit(int bit,
  670. struct dlm_lock_resource *res,
  671. const char *file,
  672. int line)
  673. {
  674. //printk("%s:%d:%.*s: clearing bit %d\n", file, line,
  675. // res->lockname.len, res->lockname.name, bit);
  676. clear_bit(bit, res->refmap);
  677. }
  678. void __dlm_lockres_drop_inflight_ref(struct dlm_ctxt *dlm,
  679. struct dlm_lock_resource *res,
  680. const char *file,
  681. int line);
  682. void __dlm_lockres_grab_inflight_ref(struct dlm_ctxt *dlm,
  683. struct dlm_lock_resource *res,
  684. int new_lockres,
  685. const char *file,
  686. int line);
  687. #define dlm_lockres_drop_inflight_ref(d,r) \
  688. __dlm_lockres_drop_inflight_ref(d,r,__FILE__,__LINE__)
  689. #define dlm_lockres_grab_inflight_ref(d,r) \
  690. __dlm_lockres_grab_inflight_ref(d,r,0,__FILE__,__LINE__)
  691. #define dlm_lockres_grab_inflight_ref_new(d,r) \
  692. __dlm_lockres_grab_inflight_ref(d,r,1,__FILE__,__LINE__)
  693. void dlm_queue_ast(struct dlm_ctxt *dlm, struct dlm_lock *lock);
  694. void dlm_queue_bast(struct dlm_ctxt *dlm, struct dlm_lock *lock);
  695. void dlm_do_local_ast(struct dlm_ctxt *dlm,
  696. struct dlm_lock_resource *res,
  697. struct dlm_lock *lock);
  698. int dlm_do_remote_ast(struct dlm_ctxt *dlm,
  699. struct dlm_lock_resource *res,
  700. struct dlm_lock *lock);
  701. void dlm_do_local_bast(struct dlm_ctxt *dlm,
  702. struct dlm_lock_resource *res,
  703. struct dlm_lock *lock,
  704. int blocked_type);
  705. int dlm_send_proxy_ast_msg(struct dlm_ctxt *dlm,
  706. struct dlm_lock_resource *res,
  707. struct dlm_lock *lock,
  708. int msg_type,
  709. int blocked_type, int flags);
  710. static inline int dlm_send_proxy_bast(struct dlm_ctxt *dlm,
  711. struct dlm_lock_resource *res,
  712. struct dlm_lock *lock,
  713. int blocked_type)
  714. {
  715. return dlm_send_proxy_ast_msg(dlm, res, lock, DLM_BAST,
  716. blocked_type, 0);
  717. }
  718. static inline int dlm_send_proxy_ast(struct dlm_ctxt *dlm,
  719. struct dlm_lock_resource *res,
  720. struct dlm_lock *lock,
  721. int flags)
  722. {
  723. return dlm_send_proxy_ast_msg(dlm, res, lock, DLM_AST,
  724. 0, flags);
  725. }
  726. void dlm_print_one_lock_resource(struct dlm_lock_resource *res);
  727. void __dlm_print_one_lock_resource(struct dlm_lock_resource *res);
  728. u8 dlm_nm_this_node(struct dlm_ctxt *dlm);
  729. void dlm_kick_thread(struct dlm_ctxt *dlm, struct dlm_lock_resource *res);
  730. void __dlm_dirty_lockres(struct dlm_ctxt *dlm, struct dlm_lock_resource *res);
  731. int dlm_nm_init(struct dlm_ctxt *dlm);
  732. int dlm_heartbeat_init(struct dlm_ctxt *dlm);
  733. void dlm_hb_node_down_cb(struct o2nm_node *node, int idx, void *data);
  734. void dlm_hb_node_up_cb(struct o2nm_node *node, int idx, void *data);
  735. int dlm_empty_lockres(struct dlm_ctxt *dlm, struct dlm_lock_resource *res);
  736. int dlm_finish_migration(struct dlm_ctxt *dlm,
  737. struct dlm_lock_resource *res,
  738. u8 old_master);
  739. void dlm_lockres_release_ast(struct dlm_ctxt *dlm,
  740. struct dlm_lock_resource *res);
  741. void __dlm_lockres_reserve_ast(struct dlm_lock_resource *res);
  742. int dlm_master_request_handler(struct o2net_msg *msg, u32 len, void *data);
  743. int dlm_assert_master_handler(struct o2net_msg *msg, u32 len, void *data);
  744. int dlm_deref_lockres_handler(struct o2net_msg *msg, u32 len, void *data);
  745. int dlm_migrate_request_handler(struct o2net_msg *msg, u32 len, void *data);
  746. int dlm_mig_lockres_handler(struct o2net_msg *msg, u32 len, void *data);
  747. int dlm_master_requery_handler(struct o2net_msg *msg, u32 len, void *data);
  748. int dlm_request_all_locks_handler(struct o2net_msg *msg, u32 len, void *data);
  749. int dlm_reco_data_done_handler(struct o2net_msg *msg, u32 len, void *data);
  750. int dlm_begin_reco_handler(struct o2net_msg *msg, u32 len, void *data);
  751. int dlm_finalize_reco_handler(struct o2net_msg *msg, u32 len, void *data);
  752. int dlm_do_master_requery(struct dlm_ctxt *dlm, struct dlm_lock_resource *res,
  753. u8 nodenum, u8 *real_master);
  754. int dlm_dispatch_assert_master(struct dlm_ctxt *dlm,
  755. struct dlm_lock_resource *res,
  756. int ignore_higher,
  757. u8 request_from,
  758. u32 flags);
  759. int dlm_send_one_lockres(struct dlm_ctxt *dlm,
  760. struct dlm_lock_resource *res,
  761. struct dlm_migratable_lockres *mres,
  762. u8 send_to,
  763. u8 flags);
  764. void dlm_move_lockres_to_recovery_list(struct dlm_ctxt *dlm,
  765. struct dlm_lock_resource *res);
  766. /* will exit holding res->spinlock, but may drop in function */
  767. void __dlm_wait_on_lockres_flags(struct dlm_lock_resource *res, int flags);
  768. void __dlm_wait_on_lockres_flags_set(struct dlm_lock_resource *res, int flags);
  769. /* will exit holding res->spinlock, but may drop in function */
  770. static inline void __dlm_wait_on_lockres(struct dlm_lock_resource *res)
  771. {
  772. __dlm_wait_on_lockres_flags(res, (DLM_LOCK_RES_IN_PROGRESS|
  773. DLM_LOCK_RES_RECOVERING|
  774. DLM_LOCK_RES_MIGRATING));
  775. }
  776. int dlm_init_mle_cache(void);
  777. void dlm_destroy_mle_cache(void);
  778. void dlm_hb_event_notify_attached(struct dlm_ctxt *dlm, int idx, int node_up);
  779. int dlm_drop_lockres_ref(struct dlm_ctxt *dlm,
  780. struct dlm_lock_resource *res);
  781. void dlm_clean_master_list(struct dlm_ctxt *dlm,
  782. u8 dead_node);
  783. int dlm_lock_basts_flushed(struct dlm_ctxt *dlm, struct dlm_lock *lock);
  784. int __dlm_lockres_has_locks(struct dlm_lock_resource *res);
  785. int __dlm_lockres_unused(struct dlm_lock_resource *res);
  786. static inline const char * dlm_lock_mode_name(int mode)
  787. {
  788. switch (mode) {
  789. case LKM_EXMODE:
  790. return "EX";
  791. case LKM_PRMODE:
  792. return "PR";
  793. case LKM_NLMODE:
  794. return "NL";
  795. }
  796. return "UNKNOWN";
  797. }
  798. static inline int dlm_lock_compatible(int existing, int request)
  799. {
  800. /* NO_LOCK compatible with all */
  801. if (request == LKM_NLMODE ||
  802. existing == LKM_NLMODE)
  803. return 1;
  804. /* EX incompatible with all non-NO_LOCK */
  805. if (request == LKM_EXMODE)
  806. return 0;
  807. /* request must be PR, which is compatible with PR */
  808. if (existing == LKM_PRMODE)
  809. return 1;
  810. return 0;
  811. }
  812. static inline int dlm_lock_on_list(struct list_head *head,
  813. struct dlm_lock *lock)
  814. {
  815. struct list_head *iter;
  816. struct dlm_lock *tmplock;
  817. list_for_each(iter, head) {
  818. tmplock = list_entry(iter, struct dlm_lock, list);
  819. if (tmplock == lock)
  820. return 1;
  821. }
  822. return 0;
  823. }
  824. static inline enum dlm_status dlm_err_to_dlm_status(int err)
  825. {
  826. enum dlm_status ret;
  827. if (err == -ENOMEM)
  828. ret = DLM_SYSERR;
  829. else if (err == -ETIMEDOUT || o2net_link_down(err, NULL))
  830. ret = DLM_NOLOCKMGR;
  831. else if (err == -EINVAL)
  832. ret = DLM_BADPARAM;
  833. else if (err == -ENAMETOOLONG)
  834. ret = DLM_IVBUFLEN;
  835. else
  836. ret = DLM_BADARGS;
  837. return ret;
  838. }
  839. static inline void dlm_node_iter_init(unsigned long *map,
  840. struct dlm_node_iter *iter)
  841. {
  842. memcpy(iter->node_map, map, sizeof(iter->node_map));
  843. iter->curnode = -1;
  844. }
  845. static inline int dlm_node_iter_next(struct dlm_node_iter *iter)
  846. {
  847. int bit;
  848. bit = find_next_bit(iter->node_map, O2NM_MAX_NODES, iter->curnode+1);
  849. if (bit >= O2NM_MAX_NODES) {
  850. iter->curnode = O2NM_MAX_NODES;
  851. return -ENOENT;
  852. }
  853. iter->curnode = bit;
  854. return bit;
  855. }
  856. #endif /* DLMCOMMON_H */