dlmcommon.h 26 KB

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