dlmcommon.h 27 KB

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