dlmcommon.h 27 KB

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