dlmcommon.h 23 KB

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