dlmcommon.h 24 KB

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