dlmcommon.h 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889
  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_BITS 7
  35. #define DLM_HASH_SIZE (1 << DLM_HASH_BITS)
  36. #define DLM_HASH_MASK (DLM_HASH_SIZE - 1)
  37. enum dlm_ast_type {
  38. DLM_AST = 0,
  39. DLM_BAST,
  40. DLM_ASTUNLOCK
  41. };
  42. #define LKM_VALID_FLAGS (LKM_VALBLK | LKM_CONVERT | LKM_UNLOCK | \
  43. LKM_CANCEL | LKM_INVVALBLK | LKM_FORCE | \
  44. LKM_RECOVERY | LKM_LOCAL | LKM_NOQUEUE)
  45. #define DLM_RECOVERY_LOCK_NAME "$RECOVERY"
  46. #define DLM_RECOVERY_LOCK_NAME_LEN 9
  47. static inline int dlm_is_recovery_lock(const char *lock_name, int name_len)
  48. {
  49. if (name_len == DLM_RECOVERY_LOCK_NAME_LEN &&
  50. memcmp(lock_name, DLM_RECOVERY_LOCK_NAME, name_len)==0)
  51. return 1;
  52. return 0;
  53. }
  54. #define DLM_RECO_STATE_ACTIVE 0x0001
  55. struct dlm_recovery_ctxt
  56. {
  57. struct list_head resources;
  58. struct list_head received;
  59. struct list_head node_data;
  60. u8 new_master;
  61. u8 dead_node;
  62. u16 state;
  63. unsigned long node_map[BITS_TO_LONGS(O2NM_MAX_NODES)];
  64. wait_queue_head_t event;
  65. };
  66. enum dlm_ctxt_state {
  67. DLM_CTXT_NEW = 0,
  68. DLM_CTXT_JOINED,
  69. DLM_CTXT_IN_SHUTDOWN,
  70. DLM_CTXT_LEAVING,
  71. };
  72. struct dlm_ctxt
  73. {
  74. struct list_head list;
  75. struct list_head *resources;
  76. struct list_head dirty_list;
  77. struct list_head purge_list;
  78. struct list_head pending_asts;
  79. struct list_head pending_basts;
  80. unsigned int purge_count;
  81. spinlock_t spinlock;
  82. spinlock_t ast_lock;
  83. char *name;
  84. u8 node_num;
  85. u32 key;
  86. u8 joining_node;
  87. wait_queue_head_t dlm_join_events;
  88. unsigned long live_nodes_map[BITS_TO_LONGS(O2NM_MAX_NODES)];
  89. unsigned long domain_map[BITS_TO_LONGS(O2NM_MAX_NODES)];
  90. unsigned long recovery_map[BITS_TO_LONGS(O2NM_MAX_NODES)];
  91. struct dlm_recovery_ctxt reco;
  92. spinlock_t master_lock;
  93. struct list_head master_list;
  94. struct list_head mle_hb_events;
  95. /* these give a really vague idea of the system load */
  96. atomic_t local_resources;
  97. atomic_t remote_resources;
  98. atomic_t unknown_resources;
  99. /* NOTE: Next three are protected by dlm_domain_lock */
  100. struct kref dlm_refs;
  101. enum dlm_ctxt_state dlm_state;
  102. unsigned int num_joins;
  103. struct o2hb_callback_func dlm_hb_up;
  104. struct o2hb_callback_func dlm_hb_down;
  105. struct task_struct *dlm_thread_task;
  106. struct task_struct *dlm_reco_thread_task;
  107. wait_queue_head_t dlm_thread_wq;
  108. wait_queue_head_t dlm_reco_thread_wq;
  109. wait_queue_head_t ast_wq;
  110. wait_queue_head_t migration_wq;
  111. struct work_struct dispatched_work;
  112. struct list_head work_list;
  113. spinlock_t work_lock;
  114. struct list_head dlm_domain_handlers;
  115. struct list_head dlm_eviction_callbacks;
  116. };
  117. /* these keventd work queue items are for less-frequently
  118. * called functions that cannot be directly called from the
  119. * net message handlers for some reason, usually because
  120. * they need to send net messages of their own. */
  121. void dlm_dispatch_work(void *data);
  122. struct dlm_lock_resource;
  123. struct dlm_work_item;
  124. typedef void (dlm_workfunc_t)(struct dlm_work_item *, void *);
  125. struct dlm_request_all_locks_priv
  126. {
  127. u8 reco_master;
  128. u8 dead_node;
  129. };
  130. struct dlm_mig_lockres_priv
  131. {
  132. struct dlm_lock_resource *lockres;
  133. u8 real_master;
  134. };
  135. struct dlm_assert_master_priv
  136. {
  137. struct dlm_lock_resource *lockres;
  138. u8 request_from;
  139. u32 flags;
  140. unsigned ignore_higher:1;
  141. };
  142. struct dlm_work_item
  143. {
  144. struct list_head list;
  145. dlm_workfunc_t *func;
  146. struct dlm_ctxt *dlm;
  147. void *data;
  148. union {
  149. struct dlm_request_all_locks_priv ral;
  150. struct dlm_mig_lockres_priv ml;
  151. struct dlm_assert_master_priv am;
  152. } u;
  153. };
  154. static inline void dlm_init_work_item(struct dlm_ctxt *dlm,
  155. struct dlm_work_item *i,
  156. dlm_workfunc_t *f, void *data)
  157. {
  158. memset(i, 0, sizeof(*i));
  159. i->func = f;
  160. INIT_LIST_HEAD(&i->list);
  161. i->data = data;
  162. i->dlm = dlm; /* must have already done a dlm_grab on this! */
  163. }
  164. static inline void __dlm_set_joining_node(struct dlm_ctxt *dlm,
  165. u8 node)
  166. {
  167. assert_spin_locked(&dlm->spinlock);
  168. dlm->joining_node = node;
  169. wake_up(&dlm->dlm_join_events);
  170. }
  171. #define DLM_LOCK_RES_UNINITED 0x00000001
  172. #define DLM_LOCK_RES_RECOVERING 0x00000002
  173. #define DLM_LOCK_RES_READY 0x00000004
  174. #define DLM_LOCK_RES_DIRTY 0x00000008
  175. #define DLM_LOCK_RES_IN_PROGRESS 0x00000010
  176. #define DLM_LOCK_RES_MIGRATING 0x00000020
  177. /* max milliseconds to wait to sync up a network failure with a node death */
  178. #define DLM_NODE_DEATH_WAIT_MAX (5 * 1000)
  179. #define DLM_PURGE_INTERVAL_MS (8 * 1000)
  180. struct dlm_lock_resource
  181. {
  182. /* WARNING: Please see the comment in dlm_init_lockres before
  183. * adding fields here. */
  184. struct list_head list;
  185. struct kref refs;
  186. /* please keep these next 3 in this order
  187. * some funcs want to iterate over all lists */
  188. struct list_head granted;
  189. struct list_head converting;
  190. struct list_head blocked;
  191. struct list_head dirty;
  192. struct list_head recovering; // dlm_recovery_ctxt.resources list
  193. /* unused lock resources have their last_used stamped and are
  194. * put on a list for the dlm thread to run. */
  195. struct list_head purge;
  196. unsigned long last_used;
  197. unsigned migration_pending:1;
  198. atomic_t asts_reserved;
  199. spinlock_t spinlock;
  200. wait_queue_head_t wq;
  201. u8 owner; //node which owns the lock resource, or unknown
  202. u16 state;
  203. struct qstr lockname;
  204. char lvb[DLM_LVB_LEN];
  205. };
  206. struct dlm_migratable_lock
  207. {
  208. __be64 cookie;
  209. /* these 3 are just padding for the in-memory structure, but
  210. * list and flags are actually used when sent over the wire */
  211. __be16 pad1;
  212. u8 list; // 0=granted, 1=converting, 2=blocked
  213. u8 flags;
  214. s8 type;
  215. s8 convert_type;
  216. s8 highest_blocked;
  217. u8 node;
  218. }; // 16 bytes
  219. struct dlm_lock
  220. {
  221. struct dlm_migratable_lock ml;
  222. struct list_head list;
  223. struct list_head ast_list;
  224. struct list_head bast_list;
  225. struct dlm_lock_resource *lockres;
  226. spinlock_t spinlock;
  227. struct kref lock_refs;
  228. // ast and bast must be callable while holding a spinlock!
  229. dlm_astlockfunc_t *ast;
  230. dlm_bastlockfunc_t *bast;
  231. void *astdata;
  232. struct dlm_lockstatus *lksb;
  233. unsigned ast_pending:1,
  234. bast_pending:1,
  235. convert_pending:1,
  236. lock_pending:1,
  237. cancel_pending:1,
  238. unlock_pending:1,
  239. lksb_kernel_allocated:1;
  240. };
  241. #define DLM_LKSB_UNUSED1 0x01
  242. #define DLM_LKSB_PUT_LVB 0x02
  243. #define DLM_LKSB_GET_LVB 0x04
  244. #define DLM_LKSB_UNUSED2 0x08
  245. #define DLM_LKSB_UNUSED3 0x10
  246. #define DLM_LKSB_UNUSED4 0x20
  247. #define DLM_LKSB_UNUSED5 0x40
  248. #define DLM_LKSB_UNUSED6 0x80
  249. enum dlm_lockres_list {
  250. DLM_GRANTED_LIST = 0,
  251. DLM_CONVERTING_LIST,
  252. DLM_BLOCKED_LIST
  253. };
  254. static inline struct list_head *
  255. dlm_list_idx_to_ptr(struct dlm_lock_resource *res, enum dlm_lockres_list idx)
  256. {
  257. struct list_head *ret = NULL;
  258. if (idx == DLM_GRANTED_LIST)
  259. ret = &res->granted;
  260. else if (idx == DLM_CONVERTING_LIST)
  261. ret = &res->converting;
  262. else if (idx == DLM_BLOCKED_LIST)
  263. ret = &res->blocked;
  264. else
  265. BUG();
  266. return ret;
  267. }
  268. struct dlm_node_iter
  269. {
  270. unsigned long node_map[BITS_TO_LONGS(O2NM_MAX_NODES)];
  271. int curnode;
  272. };
  273. enum {
  274. DLM_MASTER_REQUEST_MSG = 500,
  275. DLM_UNUSED_MSG1, /* 501 */
  276. DLM_ASSERT_MASTER_MSG, /* 502 */
  277. DLM_CREATE_LOCK_MSG, /* 503 */
  278. DLM_CONVERT_LOCK_MSG, /* 504 */
  279. DLM_PROXY_AST_MSG, /* 505 */
  280. DLM_UNLOCK_LOCK_MSG, /* 506 */
  281. DLM_UNUSED_MSG2, /* 507 */
  282. DLM_MIGRATE_REQUEST_MSG, /* 508 */
  283. DLM_MIG_LOCKRES_MSG, /* 509 */
  284. DLM_QUERY_JOIN_MSG, /* 510 */
  285. DLM_ASSERT_JOINED_MSG, /* 511 */
  286. DLM_CANCEL_JOIN_MSG, /* 512 */
  287. DLM_EXIT_DOMAIN_MSG, /* 513 */
  288. DLM_MASTER_REQUERY_MSG, /* 514 */
  289. DLM_LOCK_REQUEST_MSG, /* 515 */
  290. DLM_RECO_DATA_DONE_MSG, /* 516 */
  291. DLM_BEGIN_RECO_MSG, /* 517 */
  292. DLM_FINALIZE_RECO_MSG /* 518 */
  293. };
  294. struct dlm_reco_node_data
  295. {
  296. int state;
  297. u8 node_num;
  298. struct list_head list;
  299. };
  300. enum {
  301. DLM_RECO_NODE_DATA_DEAD = -1,
  302. DLM_RECO_NODE_DATA_INIT = 0,
  303. DLM_RECO_NODE_DATA_REQUESTING,
  304. DLM_RECO_NODE_DATA_REQUESTED,
  305. DLM_RECO_NODE_DATA_RECEIVING,
  306. DLM_RECO_NODE_DATA_DONE,
  307. DLM_RECO_NODE_DATA_FINALIZE_SENT,
  308. };
  309. enum {
  310. DLM_MASTER_RESP_NO = 0,
  311. DLM_MASTER_RESP_YES,
  312. DLM_MASTER_RESP_MAYBE,
  313. DLM_MASTER_RESP_ERROR
  314. };
  315. struct dlm_master_request
  316. {
  317. u8 node_idx;
  318. u8 namelen;
  319. __be16 pad1;
  320. __be32 flags;
  321. u8 name[O2NM_MAX_NAME_LEN];
  322. };
  323. #define DLM_ASSERT_MASTER_MLE_CLEANUP 0x00000001
  324. #define DLM_ASSERT_MASTER_REQUERY 0x00000002
  325. #define DLM_ASSERT_MASTER_FINISH_MIGRATION 0x00000004
  326. struct dlm_assert_master
  327. {
  328. u8 node_idx;
  329. u8 namelen;
  330. __be16 pad1;
  331. __be32 flags;
  332. u8 name[O2NM_MAX_NAME_LEN];
  333. };
  334. struct dlm_migrate_request
  335. {
  336. u8 master;
  337. u8 new_master;
  338. u8 namelen;
  339. u8 pad1;
  340. __be32 pad2;
  341. u8 name[O2NM_MAX_NAME_LEN];
  342. };
  343. struct dlm_master_requery
  344. {
  345. u8 pad1;
  346. u8 pad2;
  347. u8 node_idx;
  348. u8 namelen;
  349. __be32 pad3;
  350. u8 name[O2NM_MAX_NAME_LEN];
  351. };
  352. #define DLM_MRES_RECOVERY 0x01
  353. #define DLM_MRES_MIGRATION 0x02
  354. #define DLM_MRES_ALL_DONE 0x04
  355. /*
  356. * We would like to get one whole lockres into a single network
  357. * message whenever possible. Generally speaking, there will be
  358. * at most one dlm_lock on a lockres for each node in the cluster,
  359. * plus (infrequently) any additional locks coming in from userdlm.
  360. *
  361. * struct _dlm_lockres_page
  362. * {
  363. * dlm_migratable_lockres mres;
  364. * dlm_migratable_lock ml[DLM_MAX_MIGRATABLE_LOCKS];
  365. * u8 pad[DLM_MIG_LOCKRES_RESERVED];
  366. * };
  367. *
  368. * from ../cluster/tcp.h
  369. * NET_MAX_PAYLOAD_BYTES (4096 - sizeof(net_msg))
  370. * (roughly 4080 bytes)
  371. * and sizeof(dlm_migratable_lockres) = 112 bytes
  372. * and sizeof(dlm_migratable_lock) = 16 bytes
  373. *
  374. * Choosing DLM_MAX_MIGRATABLE_LOCKS=240 and
  375. * DLM_MIG_LOCKRES_RESERVED=128 means we have this:
  376. *
  377. * (DLM_MAX_MIGRATABLE_LOCKS * sizeof(dlm_migratable_lock)) +
  378. * sizeof(dlm_migratable_lockres) + DLM_MIG_LOCKRES_RESERVED =
  379. * NET_MAX_PAYLOAD_BYTES
  380. * (240 * 16) + 112 + 128 = 4080
  381. *
  382. * So a lockres would need more than 240 locks before it would
  383. * use more than one network packet to recover. Not too bad.
  384. */
  385. #define DLM_MAX_MIGRATABLE_LOCKS 240
  386. struct dlm_migratable_lockres
  387. {
  388. u8 master;
  389. u8 lockname_len;
  390. u8 num_locks; // locks sent in this structure
  391. u8 flags;
  392. __be32 total_locks; // locks to be sent for this migration cookie
  393. __be64 mig_cookie; // cookie for this lockres migration
  394. // or zero if not needed
  395. // 16 bytes
  396. u8 lockname[DLM_LOCKID_NAME_MAX];
  397. // 48 bytes
  398. u8 lvb[DLM_LVB_LEN];
  399. // 112 bytes
  400. struct dlm_migratable_lock ml[0]; // 16 bytes each, begins at byte 112
  401. };
  402. #define DLM_MIG_LOCKRES_MAX_LEN \
  403. (sizeof(struct dlm_migratable_lockres) + \
  404. (sizeof(struct dlm_migratable_lock) * \
  405. DLM_MAX_MIGRATABLE_LOCKS) )
  406. /* from above, 128 bytes
  407. * for some undetermined future use */
  408. #define DLM_MIG_LOCKRES_RESERVED (NET_MAX_PAYLOAD_BYTES - \
  409. DLM_MIG_LOCKRES_MAX_LEN)
  410. struct dlm_create_lock
  411. {
  412. __be64 cookie;
  413. __be32 flags;
  414. u8 pad1;
  415. u8 node_idx;
  416. s8 requested_type;
  417. u8 namelen;
  418. u8 name[O2NM_MAX_NAME_LEN];
  419. };
  420. struct dlm_convert_lock
  421. {
  422. __be64 cookie;
  423. __be32 flags;
  424. u8 pad1;
  425. u8 node_idx;
  426. s8 requested_type;
  427. u8 namelen;
  428. u8 name[O2NM_MAX_NAME_LEN];
  429. s8 lvb[0];
  430. };
  431. #define DLM_CONVERT_LOCK_MAX_LEN (sizeof(struct dlm_convert_lock)+DLM_LVB_LEN)
  432. struct dlm_unlock_lock
  433. {
  434. __be64 cookie;
  435. __be32 flags;
  436. __be16 pad1;
  437. u8 node_idx;
  438. u8 namelen;
  439. u8 name[O2NM_MAX_NAME_LEN];
  440. s8 lvb[0];
  441. };
  442. #define DLM_UNLOCK_LOCK_MAX_LEN (sizeof(struct dlm_unlock_lock)+DLM_LVB_LEN)
  443. struct dlm_proxy_ast
  444. {
  445. __be64 cookie;
  446. __be32 flags;
  447. u8 node_idx;
  448. u8 type;
  449. u8 blocked_type;
  450. u8 namelen;
  451. u8 name[O2NM_MAX_NAME_LEN];
  452. s8 lvb[0];
  453. };
  454. #define DLM_PROXY_AST_MAX_LEN (sizeof(struct dlm_proxy_ast)+DLM_LVB_LEN)
  455. #define DLM_MOD_KEY (0x666c6172)
  456. enum dlm_query_join_response {
  457. JOIN_DISALLOW = 0,
  458. JOIN_OK,
  459. JOIN_OK_NO_MAP,
  460. };
  461. struct dlm_lock_request
  462. {
  463. u8 node_idx;
  464. u8 dead_node;
  465. __be16 pad1;
  466. __be32 pad2;
  467. };
  468. struct dlm_reco_data_done
  469. {
  470. u8 node_idx;
  471. u8 dead_node;
  472. __be16 pad1;
  473. __be32 pad2;
  474. /* unused for now */
  475. /* eventually we can use this to attempt
  476. * lvb recovery based on each node's info */
  477. u8 reco_lvb[DLM_LVB_LEN];
  478. };
  479. struct dlm_begin_reco
  480. {
  481. u8 node_idx;
  482. u8 dead_node;
  483. __be16 pad1;
  484. __be32 pad2;
  485. };
  486. struct dlm_query_join_request
  487. {
  488. u8 node_idx;
  489. u8 pad1[2];
  490. u8 name_len;
  491. u8 domain[O2NM_MAX_NAME_LEN];
  492. };
  493. struct dlm_assert_joined
  494. {
  495. u8 node_idx;
  496. u8 pad1[2];
  497. u8 name_len;
  498. u8 domain[O2NM_MAX_NAME_LEN];
  499. };
  500. struct dlm_cancel_join
  501. {
  502. u8 node_idx;
  503. u8 pad1[2];
  504. u8 name_len;
  505. u8 domain[O2NM_MAX_NAME_LEN];
  506. };
  507. struct dlm_exit_domain
  508. {
  509. u8 node_idx;
  510. u8 pad1[3];
  511. };
  512. struct dlm_finalize_reco
  513. {
  514. u8 node_idx;
  515. u8 dead_node;
  516. __be16 pad1;
  517. __be32 pad2;
  518. };
  519. static inline enum dlm_status
  520. __dlm_lockres_state_to_status(struct dlm_lock_resource *res)
  521. {
  522. enum dlm_status status = DLM_NORMAL;
  523. assert_spin_locked(&res->spinlock);
  524. if (res->state & DLM_LOCK_RES_RECOVERING)
  525. status = DLM_RECOVERING;
  526. else if (res->state & DLM_LOCK_RES_MIGRATING)
  527. status = DLM_MIGRATING;
  528. else if (res->state & DLM_LOCK_RES_IN_PROGRESS)
  529. status = DLM_FORWARD;
  530. return status;
  531. }
  532. struct dlm_lock * dlm_new_lock(int type, u8 node, u64 cookie,
  533. struct dlm_lockstatus *lksb);
  534. void dlm_lock_get(struct dlm_lock *lock);
  535. void dlm_lock_put(struct dlm_lock *lock);
  536. void dlm_lock_attach_lockres(struct dlm_lock *lock,
  537. struct dlm_lock_resource *res);
  538. int dlm_create_lock_handler(struct o2net_msg *msg, u32 len, void *data);
  539. int dlm_convert_lock_handler(struct o2net_msg *msg, u32 len, void *data);
  540. int dlm_proxy_ast_handler(struct o2net_msg *msg, u32 len, void *data);
  541. void dlm_revert_pending_convert(struct dlm_lock_resource *res,
  542. struct dlm_lock *lock);
  543. void dlm_revert_pending_lock(struct dlm_lock_resource *res,
  544. struct dlm_lock *lock);
  545. int dlm_unlock_lock_handler(struct o2net_msg *msg, u32 len, void *data);
  546. void dlm_commit_pending_cancel(struct dlm_lock_resource *res,
  547. struct dlm_lock *lock);
  548. void dlm_commit_pending_unlock(struct dlm_lock_resource *res,
  549. struct dlm_lock *lock);
  550. int dlm_launch_thread(struct dlm_ctxt *dlm);
  551. void dlm_complete_thread(struct dlm_ctxt *dlm);
  552. int dlm_launch_recovery_thread(struct dlm_ctxt *dlm);
  553. void dlm_complete_recovery_thread(struct dlm_ctxt *dlm);
  554. void dlm_wait_for_recovery(struct dlm_ctxt *dlm);
  555. int dlm_is_node_dead(struct dlm_ctxt *dlm, u8 node);
  556. int dlm_wait_for_node_death(struct dlm_ctxt *dlm, u8 node, int timeout);
  557. void dlm_put(struct dlm_ctxt *dlm);
  558. struct dlm_ctxt *dlm_grab(struct dlm_ctxt *dlm);
  559. int dlm_domain_fully_joined(struct dlm_ctxt *dlm);
  560. void __dlm_lockres_calc_usage(struct dlm_ctxt *dlm,
  561. struct dlm_lock_resource *res);
  562. void dlm_lockres_calc_usage(struct dlm_ctxt *dlm,
  563. struct dlm_lock_resource *res);
  564. void dlm_purge_lockres(struct dlm_ctxt *dlm,
  565. struct dlm_lock_resource *lockres);
  566. void dlm_lockres_get(struct dlm_lock_resource *res);
  567. void dlm_lockres_put(struct dlm_lock_resource *res);
  568. void __dlm_unhash_lockres(struct dlm_lock_resource *res);
  569. void __dlm_insert_lockres(struct dlm_ctxt *dlm,
  570. struct dlm_lock_resource *res);
  571. struct dlm_lock_resource * __dlm_lookup_lockres(struct dlm_ctxt *dlm,
  572. const char *name,
  573. unsigned int len);
  574. struct dlm_lock_resource * dlm_lookup_lockres(struct dlm_ctxt *dlm,
  575. const char *name,
  576. unsigned int len);
  577. int dlm_is_host_down(int errno);
  578. void dlm_change_lockres_owner(struct dlm_ctxt *dlm,
  579. struct dlm_lock_resource *res,
  580. u8 owner);
  581. struct dlm_lock_resource * dlm_get_lock_resource(struct dlm_ctxt *dlm,
  582. const char *lockid,
  583. int flags);
  584. struct dlm_lock_resource *dlm_new_lockres(struct dlm_ctxt *dlm,
  585. const char *name,
  586. unsigned int namelen);
  587. void dlm_queue_ast(struct dlm_ctxt *dlm, struct dlm_lock *lock);
  588. void dlm_queue_bast(struct dlm_ctxt *dlm, struct dlm_lock *lock);
  589. void dlm_do_local_ast(struct dlm_ctxt *dlm,
  590. struct dlm_lock_resource *res,
  591. struct dlm_lock *lock);
  592. int dlm_do_remote_ast(struct dlm_ctxt *dlm,
  593. struct dlm_lock_resource *res,
  594. struct dlm_lock *lock);
  595. void dlm_do_local_bast(struct dlm_ctxt *dlm,
  596. struct dlm_lock_resource *res,
  597. struct dlm_lock *lock,
  598. int blocked_type);
  599. int dlm_send_proxy_ast_msg(struct dlm_ctxt *dlm,
  600. struct dlm_lock_resource *res,
  601. struct dlm_lock *lock,
  602. int msg_type,
  603. int blocked_type, int flags);
  604. static inline int dlm_send_proxy_bast(struct dlm_ctxt *dlm,
  605. struct dlm_lock_resource *res,
  606. struct dlm_lock *lock,
  607. int blocked_type)
  608. {
  609. return dlm_send_proxy_ast_msg(dlm, res, lock, DLM_BAST,
  610. blocked_type, 0);
  611. }
  612. static inline int dlm_send_proxy_ast(struct dlm_ctxt *dlm,
  613. struct dlm_lock_resource *res,
  614. struct dlm_lock *lock,
  615. int flags)
  616. {
  617. return dlm_send_proxy_ast_msg(dlm, res, lock, DLM_AST,
  618. 0, flags);
  619. }
  620. void dlm_print_one_lock_resource(struct dlm_lock_resource *res);
  621. void __dlm_print_one_lock_resource(struct dlm_lock_resource *res);
  622. u8 dlm_nm_this_node(struct dlm_ctxt *dlm);
  623. void dlm_kick_thread(struct dlm_ctxt *dlm, struct dlm_lock_resource *res);
  624. void __dlm_dirty_lockres(struct dlm_ctxt *dlm, struct dlm_lock_resource *res);
  625. int dlm_nm_init(struct dlm_ctxt *dlm);
  626. int dlm_heartbeat_init(struct dlm_ctxt *dlm);
  627. void dlm_hb_node_down_cb(struct o2nm_node *node, int idx, void *data);
  628. void dlm_hb_node_up_cb(struct o2nm_node *node, int idx, void *data);
  629. int dlm_lockres_is_dirty(struct dlm_ctxt *dlm, struct dlm_lock_resource *res);
  630. int dlm_migrate_lockres(struct dlm_ctxt *dlm,
  631. struct dlm_lock_resource *res,
  632. u8 target);
  633. int dlm_finish_migration(struct dlm_ctxt *dlm,
  634. struct dlm_lock_resource *res,
  635. u8 old_master);
  636. void dlm_lockres_release_ast(struct dlm_ctxt *dlm,
  637. struct dlm_lock_resource *res);
  638. void __dlm_lockres_reserve_ast(struct dlm_lock_resource *res);
  639. int dlm_master_request_handler(struct o2net_msg *msg, u32 len, void *data);
  640. int dlm_assert_master_handler(struct o2net_msg *msg, u32 len, void *data);
  641. int dlm_migrate_request_handler(struct o2net_msg *msg, u32 len, void *data);
  642. int dlm_mig_lockres_handler(struct o2net_msg *msg, u32 len, void *data);
  643. int dlm_master_requery_handler(struct o2net_msg *msg, u32 len, void *data);
  644. int dlm_request_all_locks_handler(struct o2net_msg *msg, u32 len, void *data);
  645. int dlm_reco_data_done_handler(struct o2net_msg *msg, u32 len, void *data);
  646. int dlm_begin_reco_handler(struct o2net_msg *msg, u32 len, void *data);
  647. int dlm_finalize_reco_handler(struct o2net_msg *msg, u32 len, void *data);
  648. int dlm_dispatch_assert_master(struct dlm_ctxt *dlm,
  649. struct dlm_lock_resource *res,
  650. int ignore_higher,
  651. u8 request_from,
  652. u32 flags);
  653. int dlm_send_one_lockres(struct dlm_ctxt *dlm,
  654. struct dlm_lock_resource *res,
  655. struct dlm_migratable_lockres *mres,
  656. u8 send_to,
  657. u8 flags);
  658. void dlm_move_lockres_to_recovery_list(struct dlm_ctxt *dlm,
  659. struct dlm_lock_resource *res);
  660. /* will exit holding res->spinlock, but may drop in function */
  661. void __dlm_wait_on_lockres_flags(struct dlm_lock_resource *res, int flags);
  662. void __dlm_wait_on_lockres_flags_set(struct dlm_lock_resource *res, int flags);
  663. /* will exit holding res->spinlock, but may drop in function */
  664. static inline void __dlm_wait_on_lockres(struct dlm_lock_resource *res)
  665. {
  666. __dlm_wait_on_lockres_flags(res, (DLM_LOCK_RES_IN_PROGRESS|
  667. DLM_LOCK_RES_RECOVERING|
  668. DLM_LOCK_RES_MIGRATING));
  669. }
  670. int dlm_init_mle_cache(void);
  671. void dlm_destroy_mle_cache(void);
  672. void dlm_hb_event_notify_attached(struct dlm_ctxt *dlm, int idx, int node_up);
  673. void dlm_clean_master_list(struct dlm_ctxt *dlm,
  674. u8 dead_node);
  675. int dlm_lock_basts_flushed(struct dlm_ctxt *dlm, struct dlm_lock *lock);
  676. static inline const char * dlm_lock_mode_name(int mode)
  677. {
  678. switch (mode) {
  679. case LKM_EXMODE:
  680. return "EX";
  681. case LKM_PRMODE:
  682. return "PR";
  683. case LKM_NLMODE:
  684. return "NL";
  685. }
  686. return "UNKNOWN";
  687. }
  688. static inline int dlm_lock_compatible(int existing, int request)
  689. {
  690. /* NO_LOCK compatible with all */
  691. if (request == LKM_NLMODE ||
  692. existing == LKM_NLMODE)
  693. return 1;
  694. /* EX incompatible with all non-NO_LOCK */
  695. if (request == LKM_EXMODE)
  696. return 0;
  697. /* request must be PR, which is compatible with PR */
  698. if (existing == LKM_PRMODE)
  699. return 1;
  700. return 0;
  701. }
  702. static inline int dlm_lock_on_list(struct list_head *head,
  703. struct dlm_lock *lock)
  704. {
  705. struct list_head *iter;
  706. struct dlm_lock *tmplock;
  707. list_for_each(iter, head) {
  708. tmplock = list_entry(iter, struct dlm_lock, list);
  709. if (tmplock == lock)
  710. return 1;
  711. }
  712. return 0;
  713. }
  714. static inline enum dlm_status dlm_err_to_dlm_status(int err)
  715. {
  716. enum dlm_status ret;
  717. if (err == -ENOMEM)
  718. ret = DLM_SYSERR;
  719. else if (err == -ETIMEDOUT || o2net_link_down(err, NULL))
  720. ret = DLM_NOLOCKMGR;
  721. else if (err == -EINVAL)
  722. ret = DLM_BADPARAM;
  723. else if (err == -ENAMETOOLONG)
  724. ret = DLM_IVBUFLEN;
  725. else
  726. ret = DLM_BADARGS;
  727. return ret;
  728. }
  729. static inline void dlm_node_iter_init(unsigned long *map,
  730. struct dlm_node_iter *iter)
  731. {
  732. memcpy(iter->node_map, map, sizeof(iter->node_map));
  733. iter->curnode = -1;
  734. }
  735. static inline int dlm_node_iter_next(struct dlm_node_iter *iter)
  736. {
  737. int bit;
  738. bit = find_next_bit(iter->node_map, O2NM_MAX_NODES, iter->curnode+1);
  739. if (bit >= O2NM_MAX_NODES) {
  740. iter->curnode = O2NM_MAX_NODES;
  741. return -ENOENT;
  742. }
  743. iter->curnode = bit;
  744. return bit;
  745. }
  746. #endif /* DLMCOMMON_H */