dlmcommon.h 28 KB

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