dlmcommon.h 22 KB

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