dlmcommon.h 30 KB

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