dlmcommon.h 29 KB

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