dlmdomain.c 49 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929
  1. /* -*- mode: c; c-basic-offset: 8; -*-
  2. * vim: noexpandtab sw=8 ts=8 sts=0:
  3. *
  4. * dlmdomain.c
  5. *
  6. * defines domain join / leave apis
  7. *
  8. * Copyright (C) 2004 Oracle. All rights reserved.
  9. *
  10. * This program is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU General Public
  12. * License as published by the Free Software Foundation; either
  13. * version 2 of the License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18. * General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public
  21. * License along with this program; if not, write to the
  22. * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  23. * Boston, MA 021110-1307, USA.
  24. *
  25. */
  26. #include <linux/module.h>
  27. #include <linux/types.h>
  28. #include <linux/slab.h>
  29. #include <linux/highmem.h>
  30. #include <linux/init.h>
  31. #include <linux/spinlock.h>
  32. #include <linux/delay.h>
  33. #include <linux/err.h>
  34. #include <linux/debugfs.h>
  35. #include "cluster/heartbeat.h"
  36. #include "cluster/nodemanager.h"
  37. #include "cluster/tcp.h"
  38. #include "dlmapi.h"
  39. #include "dlmcommon.h"
  40. #include "dlmdomain.h"
  41. #include "dlmdebug.h"
  42. #include "dlmver.h"
  43. #define MLOG_MASK_PREFIX (ML_DLM|ML_DLM_DOMAIN)
  44. #include "cluster/masklog.h"
  45. /*
  46. * ocfs2 node maps are array of long int, which limits to send them freely
  47. * across the wire due to endianness issues. To workaround this, we convert
  48. * long ints to byte arrays. Following 3 routines are helper functions to
  49. * set/test/copy bits within those array of bytes
  50. */
  51. static inline void byte_set_bit(u8 nr, u8 map[])
  52. {
  53. map[nr >> 3] |= (1UL << (nr & 7));
  54. }
  55. static inline int byte_test_bit(u8 nr, u8 map[])
  56. {
  57. return ((1UL << (nr & 7)) & (map[nr >> 3])) != 0;
  58. }
  59. static inline void byte_copymap(u8 dmap[], unsigned long smap[],
  60. unsigned int sz)
  61. {
  62. unsigned int nn;
  63. if (!sz)
  64. return;
  65. memset(dmap, 0, ((sz + 7) >> 3));
  66. for (nn = 0 ; nn < sz; nn++)
  67. if (test_bit(nn, smap))
  68. byte_set_bit(nn, dmap);
  69. }
  70. static void dlm_free_pagevec(void **vec, int pages)
  71. {
  72. while (pages--)
  73. free_page((unsigned long)vec[pages]);
  74. kfree(vec);
  75. }
  76. static void **dlm_alloc_pagevec(int pages)
  77. {
  78. void **vec = kmalloc(pages * sizeof(void *), GFP_KERNEL);
  79. int i;
  80. if (!vec)
  81. return NULL;
  82. for (i = 0; i < pages; i++)
  83. if (!(vec[i] = (void *)__get_free_page(GFP_KERNEL)))
  84. goto out_free;
  85. mlog(0, "Allocated DLM hash pagevec; %d pages (%lu expected), %lu buckets per page\n",
  86. pages, (unsigned long)DLM_HASH_PAGES,
  87. (unsigned long)DLM_BUCKETS_PER_PAGE);
  88. return vec;
  89. out_free:
  90. dlm_free_pagevec(vec, i);
  91. return NULL;
  92. }
  93. /*
  94. *
  95. * spinlock lock ordering: if multiple locks are needed, obey this ordering:
  96. * dlm_domain_lock
  97. * struct dlm_ctxt->spinlock
  98. * struct dlm_lock_resource->spinlock
  99. * struct dlm_ctxt->master_lock
  100. * struct dlm_ctxt->ast_lock
  101. * dlm_master_list_entry->spinlock
  102. * dlm_lock->spinlock
  103. *
  104. */
  105. DEFINE_SPINLOCK(dlm_domain_lock);
  106. LIST_HEAD(dlm_domains);
  107. static DECLARE_WAIT_QUEUE_HEAD(dlm_domain_events);
  108. /*
  109. * The supported protocol version for DLM communication. Running domains
  110. * will have a negotiated version with the same major number and a minor
  111. * number equal or smaller. The dlm_ctxt->dlm_locking_proto field should
  112. * be used to determine what a running domain is actually using.
  113. */
  114. static const struct dlm_protocol_version dlm_protocol = {
  115. .pv_major = 1,
  116. .pv_minor = 0,
  117. };
  118. #define DLM_DOMAIN_BACKOFF_MS 200
  119. static int dlm_query_join_handler(struct o2net_msg *msg, u32 len, void *data,
  120. void **ret_data);
  121. static int dlm_assert_joined_handler(struct o2net_msg *msg, u32 len, void *data,
  122. void **ret_data);
  123. static int dlm_cancel_join_handler(struct o2net_msg *msg, u32 len, void *data,
  124. void **ret_data);
  125. static int dlm_exit_domain_handler(struct o2net_msg *msg, u32 len, void *data,
  126. void **ret_data);
  127. static int dlm_protocol_compare(struct dlm_protocol_version *existing,
  128. struct dlm_protocol_version *request);
  129. static void dlm_unregister_domain_handlers(struct dlm_ctxt *dlm);
  130. void __dlm_unhash_lockres(struct dlm_lock_resource *lockres)
  131. {
  132. if (!hlist_unhashed(&lockres->hash_node)) {
  133. hlist_del_init(&lockres->hash_node);
  134. dlm_lockres_put(lockres);
  135. }
  136. }
  137. void __dlm_insert_lockres(struct dlm_ctxt *dlm,
  138. struct dlm_lock_resource *res)
  139. {
  140. struct hlist_head *bucket;
  141. struct qstr *q;
  142. assert_spin_locked(&dlm->spinlock);
  143. q = &res->lockname;
  144. bucket = dlm_lockres_hash(dlm, q->hash);
  145. /* get a reference for our hashtable */
  146. dlm_lockres_get(res);
  147. hlist_add_head(&res->hash_node, bucket);
  148. }
  149. struct dlm_lock_resource * __dlm_lookup_lockres_full(struct dlm_ctxt *dlm,
  150. const char *name,
  151. unsigned int len,
  152. unsigned int hash)
  153. {
  154. struct hlist_head *bucket;
  155. struct hlist_node *list;
  156. mlog_entry("%.*s\n", len, name);
  157. assert_spin_locked(&dlm->spinlock);
  158. bucket = dlm_lockres_hash(dlm, hash);
  159. hlist_for_each(list, bucket) {
  160. struct dlm_lock_resource *res = hlist_entry(list,
  161. struct dlm_lock_resource, hash_node);
  162. if (res->lockname.name[0] != name[0])
  163. continue;
  164. if (unlikely(res->lockname.len != len))
  165. continue;
  166. if (memcmp(res->lockname.name + 1, name + 1, len - 1))
  167. continue;
  168. dlm_lockres_get(res);
  169. return res;
  170. }
  171. return NULL;
  172. }
  173. /* intended to be called by functions which do not care about lock
  174. * resources which are being purged (most net _handler functions).
  175. * this will return NULL for any lock resource which is found but
  176. * currently in the process of dropping its mastery reference.
  177. * use __dlm_lookup_lockres_full when you need the lock resource
  178. * regardless (e.g. dlm_get_lock_resource) */
  179. struct dlm_lock_resource * __dlm_lookup_lockres(struct dlm_ctxt *dlm,
  180. const char *name,
  181. unsigned int len,
  182. unsigned int hash)
  183. {
  184. struct dlm_lock_resource *res = NULL;
  185. mlog_entry("%.*s\n", len, name);
  186. assert_spin_locked(&dlm->spinlock);
  187. res = __dlm_lookup_lockres_full(dlm, name, len, hash);
  188. if (res) {
  189. spin_lock(&res->spinlock);
  190. if (res->state & DLM_LOCK_RES_DROPPING_REF) {
  191. spin_unlock(&res->spinlock);
  192. dlm_lockres_put(res);
  193. return NULL;
  194. }
  195. spin_unlock(&res->spinlock);
  196. }
  197. return res;
  198. }
  199. struct dlm_lock_resource * dlm_lookup_lockres(struct dlm_ctxt *dlm,
  200. const char *name,
  201. unsigned int len)
  202. {
  203. struct dlm_lock_resource *res;
  204. unsigned int hash = dlm_lockid_hash(name, len);
  205. spin_lock(&dlm->spinlock);
  206. res = __dlm_lookup_lockres(dlm, name, len, hash);
  207. spin_unlock(&dlm->spinlock);
  208. return res;
  209. }
  210. static struct dlm_ctxt * __dlm_lookup_domain_full(const char *domain, int len)
  211. {
  212. struct dlm_ctxt *tmp = NULL;
  213. struct list_head *iter;
  214. assert_spin_locked(&dlm_domain_lock);
  215. /* tmp->name here is always NULL terminated,
  216. * but domain may not be! */
  217. list_for_each(iter, &dlm_domains) {
  218. tmp = list_entry (iter, struct dlm_ctxt, list);
  219. if (strlen(tmp->name) == len &&
  220. memcmp(tmp->name, domain, len)==0)
  221. break;
  222. tmp = NULL;
  223. }
  224. return tmp;
  225. }
  226. /* For null terminated domain strings ONLY */
  227. static struct dlm_ctxt * __dlm_lookup_domain(const char *domain)
  228. {
  229. assert_spin_locked(&dlm_domain_lock);
  230. return __dlm_lookup_domain_full(domain, strlen(domain));
  231. }
  232. /* returns true on one of two conditions:
  233. * 1) the domain does not exist
  234. * 2) the domain exists and it's state is "joined" */
  235. static int dlm_wait_on_domain_helper(const char *domain)
  236. {
  237. int ret = 0;
  238. struct dlm_ctxt *tmp = NULL;
  239. spin_lock(&dlm_domain_lock);
  240. tmp = __dlm_lookup_domain(domain);
  241. if (!tmp)
  242. ret = 1;
  243. else if (tmp->dlm_state == DLM_CTXT_JOINED)
  244. ret = 1;
  245. spin_unlock(&dlm_domain_lock);
  246. return ret;
  247. }
  248. static void dlm_free_ctxt_mem(struct dlm_ctxt *dlm)
  249. {
  250. dlm_destroy_debugfs_subroot(dlm);
  251. if (dlm->lockres_hash)
  252. dlm_free_pagevec((void **)dlm->lockres_hash, DLM_HASH_PAGES);
  253. if (dlm->master_hash)
  254. dlm_free_pagevec((void **)dlm->master_hash, DLM_HASH_PAGES);
  255. if (dlm->name)
  256. kfree(dlm->name);
  257. kfree(dlm);
  258. }
  259. /* A little strange - this function will be called while holding
  260. * dlm_domain_lock and is expected to be holding it on the way out. We
  261. * will however drop and reacquire it multiple times */
  262. static void dlm_ctxt_release(struct kref *kref)
  263. {
  264. struct dlm_ctxt *dlm;
  265. dlm = container_of(kref, struct dlm_ctxt, dlm_refs);
  266. BUG_ON(dlm->num_joins);
  267. BUG_ON(dlm->dlm_state == DLM_CTXT_JOINED);
  268. /* we may still be in the list if we hit an error during join. */
  269. list_del_init(&dlm->list);
  270. spin_unlock(&dlm_domain_lock);
  271. mlog(0, "freeing memory from domain %s\n", dlm->name);
  272. wake_up(&dlm_domain_events);
  273. dlm_free_ctxt_mem(dlm);
  274. spin_lock(&dlm_domain_lock);
  275. }
  276. void dlm_put(struct dlm_ctxt *dlm)
  277. {
  278. spin_lock(&dlm_domain_lock);
  279. kref_put(&dlm->dlm_refs, dlm_ctxt_release);
  280. spin_unlock(&dlm_domain_lock);
  281. }
  282. static void __dlm_get(struct dlm_ctxt *dlm)
  283. {
  284. kref_get(&dlm->dlm_refs);
  285. }
  286. /* given a questionable reference to a dlm object, gets a reference if
  287. * it can find it in the list, otherwise returns NULL in which case
  288. * you shouldn't trust your pointer. */
  289. struct dlm_ctxt *dlm_grab(struct dlm_ctxt *dlm)
  290. {
  291. struct list_head *iter;
  292. struct dlm_ctxt *target = NULL;
  293. spin_lock(&dlm_domain_lock);
  294. list_for_each(iter, &dlm_domains) {
  295. target = list_entry (iter, struct dlm_ctxt, list);
  296. if (target == dlm) {
  297. __dlm_get(target);
  298. break;
  299. }
  300. target = NULL;
  301. }
  302. spin_unlock(&dlm_domain_lock);
  303. return target;
  304. }
  305. int dlm_domain_fully_joined(struct dlm_ctxt *dlm)
  306. {
  307. int ret;
  308. spin_lock(&dlm_domain_lock);
  309. ret = (dlm->dlm_state == DLM_CTXT_JOINED) ||
  310. (dlm->dlm_state == DLM_CTXT_IN_SHUTDOWN);
  311. spin_unlock(&dlm_domain_lock);
  312. return ret;
  313. }
  314. static void dlm_destroy_dlm_worker(struct dlm_ctxt *dlm)
  315. {
  316. if (dlm->dlm_worker) {
  317. flush_workqueue(dlm->dlm_worker);
  318. destroy_workqueue(dlm->dlm_worker);
  319. dlm->dlm_worker = NULL;
  320. }
  321. }
  322. static void dlm_complete_dlm_shutdown(struct dlm_ctxt *dlm)
  323. {
  324. dlm_unregister_domain_handlers(dlm);
  325. dlm_debug_shutdown(dlm);
  326. dlm_complete_thread(dlm);
  327. dlm_complete_recovery_thread(dlm);
  328. dlm_destroy_dlm_worker(dlm);
  329. /* We've left the domain. Now we can take ourselves out of the
  330. * list and allow the kref stuff to help us free the
  331. * memory. */
  332. spin_lock(&dlm_domain_lock);
  333. list_del_init(&dlm->list);
  334. spin_unlock(&dlm_domain_lock);
  335. /* Wake up anyone waiting for us to remove this domain */
  336. wake_up(&dlm_domain_events);
  337. }
  338. static int dlm_migrate_all_locks(struct dlm_ctxt *dlm)
  339. {
  340. int i, num, n, ret = 0;
  341. struct dlm_lock_resource *res;
  342. struct hlist_node *iter;
  343. struct hlist_head *bucket;
  344. int dropped;
  345. mlog(0, "Migrating locks from domain %s\n", dlm->name);
  346. num = 0;
  347. spin_lock(&dlm->spinlock);
  348. for (i = 0; i < DLM_HASH_BUCKETS; i++) {
  349. redo_bucket:
  350. n = 0;
  351. bucket = dlm_lockres_hash(dlm, i);
  352. iter = bucket->first;
  353. while (iter) {
  354. n++;
  355. res = hlist_entry(iter, struct dlm_lock_resource,
  356. hash_node);
  357. dlm_lockres_get(res);
  358. /* migrate, if necessary. this will drop the dlm
  359. * spinlock and retake it if it does migration. */
  360. dropped = dlm_empty_lockres(dlm, res);
  361. spin_lock(&res->spinlock);
  362. __dlm_lockres_calc_usage(dlm, res);
  363. iter = res->hash_node.next;
  364. spin_unlock(&res->spinlock);
  365. dlm_lockres_put(res);
  366. if (dropped)
  367. goto redo_bucket;
  368. }
  369. cond_resched_lock(&dlm->spinlock);
  370. num += n;
  371. mlog(0, "%s: touched %d lockreses in bucket %d "
  372. "(tot=%d)\n", dlm->name, n, i, num);
  373. }
  374. spin_unlock(&dlm->spinlock);
  375. wake_up(&dlm->dlm_thread_wq);
  376. /* let the dlm thread take care of purging, keep scanning until
  377. * nothing remains in the hash */
  378. if (num) {
  379. mlog(0, "%s: %d lock resources in hash last pass\n",
  380. dlm->name, num);
  381. ret = -EAGAIN;
  382. }
  383. mlog(0, "DONE Migrating locks from domain %s\n", dlm->name);
  384. return ret;
  385. }
  386. static int dlm_no_joining_node(struct dlm_ctxt *dlm)
  387. {
  388. int ret;
  389. spin_lock(&dlm->spinlock);
  390. ret = dlm->joining_node == DLM_LOCK_RES_OWNER_UNKNOWN;
  391. spin_unlock(&dlm->spinlock);
  392. return ret;
  393. }
  394. static void dlm_mark_domain_leaving(struct dlm_ctxt *dlm)
  395. {
  396. /* Yikes, a double spinlock! I need domain_lock for the dlm
  397. * state and the dlm spinlock for join state... Sorry! */
  398. again:
  399. spin_lock(&dlm_domain_lock);
  400. spin_lock(&dlm->spinlock);
  401. if (dlm->joining_node != DLM_LOCK_RES_OWNER_UNKNOWN) {
  402. mlog(0, "Node %d is joining, we wait on it.\n",
  403. dlm->joining_node);
  404. spin_unlock(&dlm->spinlock);
  405. spin_unlock(&dlm_domain_lock);
  406. wait_event(dlm->dlm_join_events, dlm_no_joining_node(dlm));
  407. goto again;
  408. }
  409. dlm->dlm_state = DLM_CTXT_LEAVING;
  410. spin_unlock(&dlm->spinlock);
  411. spin_unlock(&dlm_domain_lock);
  412. }
  413. static void __dlm_print_nodes(struct dlm_ctxt *dlm)
  414. {
  415. int node = -1;
  416. assert_spin_locked(&dlm->spinlock);
  417. printk(KERN_NOTICE "o2dlm: Nodes in domain %s: ", dlm->name);
  418. while ((node = find_next_bit(dlm->domain_map, O2NM_MAX_NODES,
  419. node + 1)) < O2NM_MAX_NODES) {
  420. printk("%d ", node);
  421. }
  422. printk("\n");
  423. }
  424. static int dlm_exit_domain_handler(struct o2net_msg *msg, u32 len, void *data,
  425. void **ret_data)
  426. {
  427. struct dlm_ctxt *dlm = data;
  428. unsigned int node;
  429. struct dlm_exit_domain *exit_msg = (struct dlm_exit_domain *) msg->buf;
  430. mlog_entry("%p %u %p", msg, len, data);
  431. if (!dlm_grab(dlm))
  432. return 0;
  433. node = exit_msg->node_idx;
  434. printk(KERN_NOTICE "o2dlm: Node %u leaves domain %s\n", node, dlm->name);
  435. spin_lock(&dlm->spinlock);
  436. clear_bit(node, dlm->domain_map);
  437. __dlm_print_nodes(dlm);
  438. /* notify anything attached to the heartbeat events */
  439. dlm_hb_event_notify_attached(dlm, node, 0);
  440. spin_unlock(&dlm->spinlock);
  441. dlm_put(dlm);
  442. return 0;
  443. }
  444. static int dlm_send_one_domain_exit(struct dlm_ctxt *dlm,
  445. unsigned int node)
  446. {
  447. int status;
  448. struct dlm_exit_domain leave_msg;
  449. mlog(0, "Asking node %u if we can leave the domain %s me = %u\n",
  450. node, dlm->name, dlm->node_num);
  451. memset(&leave_msg, 0, sizeof(leave_msg));
  452. leave_msg.node_idx = dlm->node_num;
  453. status = o2net_send_message(DLM_EXIT_DOMAIN_MSG, dlm->key,
  454. &leave_msg, sizeof(leave_msg), node,
  455. NULL);
  456. if (status < 0)
  457. mlog(ML_ERROR, "Error %d when sending message %u (key 0x%x) to "
  458. "node %u\n", status, DLM_EXIT_DOMAIN_MSG, dlm->key, node);
  459. mlog(0, "status return %d from o2net_send_message\n", status);
  460. return status;
  461. }
  462. static void dlm_leave_domain(struct dlm_ctxt *dlm)
  463. {
  464. int node, clear_node, status;
  465. /* At this point we've migrated away all our locks and won't
  466. * accept mastership of new ones. The dlm is responsible for
  467. * almost nothing now. We make sure not to confuse any joining
  468. * nodes and then commence shutdown procedure. */
  469. spin_lock(&dlm->spinlock);
  470. /* Clear ourselves from the domain map */
  471. clear_bit(dlm->node_num, dlm->domain_map);
  472. while ((node = find_next_bit(dlm->domain_map, O2NM_MAX_NODES,
  473. 0)) < O2NM_MAX_NODES) {
  474. /* Drop the dlm spinlock. This is safe wrt the domain_map.
  475. * -nodes cannot be added now as the
  476. * query_join_handlers knows to respond with OK_NO_MAP
  477. * -we catch the right network errors if a node is
  478. * removed from the map while we're sending him the
  479. * exit message. */
  480. spin_unlock(&dlm->spinlock);
  481. clear_node = 1;
  482. status = dlm_send_one_domain_exit(dlm, node);
  483. if (status < 0 &&
  484. status != -ENOPROTOOPT &&
  485. status != -ENOTCONN) {
  486. mlog(ML_NOTICE, "Error %d sending domain exit message "
  487. "to node %d\n", status, node);
  488. /* Not sure what to do here but lets sleep for
  489. * a bit in case this was a transient
  490. * error... */
  491. msleep(DLM_DOMAIN_BACKOFF_MS);
  492. clear_node = 0;
  493. }
  494. spin_lock(&dlm->spinlock);
  495. /* If we're not clearing the node bit then we intend
  496. * to loop back around to try again. */
  497. if (clear_node)
  498. clear_bit(node, dlm->domain_map);
  499. }
  500. spin_unlock(&dlm->spinlock);
  501. }
  502. int dlm_joined(struct dlm_ctxt *dlm)
  503. {
  504. int ret = 0;
  505. spin_lock(&dlm_domain_lock);
  506. if (dlm->dlm_state == DLM_CTXT_JOINED)
  507. ret = 1;
  508. spin_unlock(&dlm_domain_lock);
  509. return ret;
  510. }
  511. int dlm_shutting_down(struct dlm_ctxt *dlm)
  512. {
  513. int ret = 0;
  514. spin_lock(&dlm_domain_lock);
  515. if (dlm->dlm_state == DLM_CTXT_IN_SHUTDOWN)
  516. ret = 1;
  517. spin_unlock(&dlm_domain_lock);
  518. return ret;
  519. }
  520. void dlm_unregister_domain(struct dlm_ctxt *dlm)
  521. {
  522. int leave = 0;
  523. struct dlm_lock_resource *res;
  524. spin_lock(&dlm_domain_lock);
  525. BUG_ON(dlm->dlm_state != DLM_CTXT_JOINED);
  526. BUG_ON(!dlm->num_joins);
  527. dlm->num_joins--;
  528. if (!dlm->num_joins) {
  529. /* We mark it "in shutdown" now so new register
  530. * requests wait until we've completely left the
  531. * domain. Don't use DLM_CTXT_LEAVING yet as we still
  532. * want new domain joins to communicate with us at
  533. * least until we've completed migration of our
  534. * resources. */
  535. dlm->dlm_state = DLM_CTXT_IN_SHUTDOWN;
  536. leave = 1;
  537. }
  538. spin_unlock(&dlm_domain_lock);
  539. if (leave) {
  540. mlog(0, "shutting down domain %s\n", dlm->name);
  541. /* We changed dlm state, notify the thread */
  542. dlm_kick_thread(dlm, NULL);
  543. while (dlm_migrate_all_locks(dlm)) {
  544. /* Give dlm_thread time to purge the lockres' */
  545. msleep(500);
  546. mlog(0, "%s: more migration to do\n", dlm->name);
  547. }
  548. /* This list should be empty. If not, print remaining lockres */
  549. if (!list_empty(&dlm->tracking_list)) {
  550. mlog(ML_ERROR, "Following lockres' are still on the "
  551. "tracking list:\n");
  552. list_for_each_entry(res, &dlm->tracking_list, tracking)
  553. dlm_print_one_lock_resource(res);
  554. }
  555. dlm_mark_domain_leaving(dlm);
  556. dlm_leave_domain(dlm);
  557. dlm_complete_dlm_shutdown(dlm);
  558. }
  559. dlm_put(dlm);
  560. }
  561. EXPORT_SYMBOL_GPL(dlm_unregister_domain);
  562. static int dlm_query_join_proto_check(char *proto_type, int node,
  563. struct dlm_protocol_version *ours,
  564. struct dlm_protocol_version *request)
  565. {
  566. int rc;
  567. struct dlm_protocol_version proto = *request;
  568. if (!dlm_protocol_compare(ours, &proto)) {
  569. mlog(0,
  570. "node %u wanted to join with %s locking protocol "
  571. "%u.%u, we respond with %u.%u\n",
  572. node, proto_type,
  573. request->pv_major,
  574. request->pv_minor,
  575. proto.pv_major, proto.pv_minor);
  576. request->pv_minor = proto.pv_minor;
  577. rc = 0;
  578. } else {
  579. mlog(ML_NOTICE,
  580. "Node %u wanted to join with %s locking "
  581. "protocol %u.%u, but we have %u.%u, disallowing\n",
  582. node, proto_type,
  583. request->pv_major,
  584. request->pv_minor,
  585. ours->pv_major,
  586. ours->pv_minor);
  587. rc = 1;
  588. }
  589. return rc;
  590. }
  591. /*
  592. * struct dlm_query_join_packet is made up of four one-byte fields. They
  593. * are effectively in big-endian order already. However, little-endian
  594. * machines swap them before putting the packet on the wire (because
  595. * query_join's response is a status, and that status is treated as a u32
  596. * on the wire). Thus, a big-endian and little-endian machines will treat
  597. * this structure differently.
  598. *
  599. * The solution is to have little-endian machines swap the structure when
  600. * converting from the structure to the u32 representation. This will
  601. * result in the structure having the correct format on the wire no matter
  602. * the host endian format.
  603. */
  604. static void dlm_query_join_packet_to_wire(struct dlm_query_join_packet *packet,
  605. u32 *wire)
  606. {
  607. union dlm_query_join_response response;
  608. response.packet = *packet;
  609. *wire = cpu_to_be32(response.intval);
  610. }
  611. static void dlm_query_join_wire_to_packet(u32 wire,
  612. struct dlm_query_join_packet *packet)
  613. {
  614. union dlm_query_join_response response;
  615. response.intval = cpu_to_be32(wire);
  616. *packet = response.packet;
  617. }
  618. static int dlm_query_join_handler(struct o2net_msg *msg, u32 len, void *data,
  619. void **ret_data)
  620. {
  621. struct dlm_query_join_request *query;
  622. struct dlm_query_join_packet packet = {
  623. .code = JOIN_DISALLOW,
  624. };
  625. struct dlm_ctxt *dlm = NULL;
  626. u32 response;
  627. u8 nodenum;
  628. query = (struct dlm_query_join_request *) msg->buf;
  629. mlog(0, "node %u wants to join domain %s\n", query->node_idx,
  630. query->domain);
  631. /*
  632. * If heartbeat doesn't consider the node live, tell it
  633. * to back off and try again. This gives heartbeat a chance
  634. * to catch up.
  635. */
  636. if (!o2hb_check_node_heartbeating(query->node_idx)) {
  637. mlog(0, "node %u is not in our live map yet\n",
  638. query->node_idx);
  639. packet.code = JOIN_DISALLOW;
  640. goto respond;
  641. }
  642. packet.code = JOIN_OK_NO_MAP;
  643. spin_lock(&dlm_domain_lock);
  644. dlm = __dlm_lookup_domain_full(query->domain, query->name_len);
  645. if (!dlm)
  646. goto unlock_respond;
  647. /*
  648. * There is a small window where the joining node may not see the
  649. * node(s) that just left but still part of the cluster. DISALLOW
  650. * join request if joining node has different node map.
  651. */
  652. nodenum=0;
  653. while (nodenum < O2NM_MAX_NODES) {
  654. if (test_bit(nodenum, dlm->domain_map)) {
  655. if (!byte_test_bit(nodenum, query->node_map)) {
  656. mlog(0, "disallow join as node %u does not "
  657. "have node %u in its nodemap\n",
  658. query->node_idx, nodenum);
  659. packet.code = JOIN_DISALLOW;
  660. goto unlock_respond;
  661. }
  662. }
  663. nodenum++;
  664. }
  665. /* Once the dlm ctxt is marked as leaving then we don't want
  666. * to be put in someone's domain map.
  667. * Also, explicitly disallow joining at certain troublesome
  668. * times (ie. during recovery). */
  669. if (dlm && dlm->dlm_state != DLM_CTXT_LEAVING) {
  670. int bit = query->node_idx;
  671. spin_lock(&dlm->spinlock);
  672. if (dlm->dlm_state == DLM_CTXT_NEW &&
  673. dlm->joining_node == DLM_LOCK_RES_OWNER_UNKNOWN) {
  674. /*If this is a brand new context and we
  675. * haven't started our join process yet, then
  676. * the other node won the race. */
  677. packet.code = JOIN_OK_NO_MAP;
  678. } else if (dlm->joining_node != DLM_LOCK_RES_OWNER_UNKNOWN) {
  679. /* Disallow parallel joins. */
  680. packet.code = JOIN_DISALLOW;
  681. } else if (dlm->reco.state & DLM_RECO_STATE_ACTIVE) {
  682. mlog(0, "node %u trying to join, but recovery "
  683. "is ongoing.\n", bit);
  684. packet.code = JOIN_DISALLOW;
  685. } else if (test_bit(bit, dlm->recovery_map)) {
  686. mlog(0, "node %u trying to join, but it "
  687. "still needs recovery.\n", bit);
  688. packet.code = JOIN_DISALLOW;
  689. } else if (test_bit(bit, dlm->domain_map)) {
  690. mlog(0, "node %u trying to join, but it "
  691. "is still in the domain! needs recovery?\n",
  692. bit);
  693. packet.code = JOIN_DISALLOW;
  694. } else {
  695. /* Alright we're fully a part of this domain
  696. * so we keep some state as to who's joining
  697. * and indicate to him that needs to be fixed
  698. * up. */
  699. /* Make sure we speak compatible locking protocols. */
  700. if (dlm_query_join_proto_check("DLM", bit,
  701. &dlm->dlm_locking_proto,
  702. &query->dlm_proto)) {
  703. packet.code = JOIN_PROTOCOL_MISMATCH;
  704. } else if (dlm_query_join_proto_check("fs", bit,
  705. &dlm->fs_locking_proto,
  706. &query->fs_proto)) {
  707. packet.code = JOIN_PROTOCOL_MISMATCH;
  708. } else {
  709. packet.dlm_minor = query->dlm_proto.pv_minor;
  710. packet.fs_minor = query->fs_proto.pv_minor;
  711. packet.code = JOIN_OK;
  712. __dlm_set_joining_node(dlm, query->node_idx);
  713. }
  714. }
  715. spin_unlock(&dlm->spinlock);
  716. }
  717. unlock_respond:
  718. spin_unlock(&dlm_domain_lock);
  719. respond:
  720. mlog(0, "We respond with %u\n", packet.code);
  721. dlm_query_join_packet_to_wire(&packet, &response);
  722. return response;
  723. }
  724. static int dlm_assert_joined_handler(struct o2net_msg *msg, u32 len, void *data,
  725. void **ret_data)
  726. {
  727. struct dlm_assert_joined *assert;
  728. struct dlm_ctxt *dlm = NULL;
  729. assert = (struct dlm_assert_joined *) msg->buf;
  730. mlog(0, "node %u asserts join on domain %s\n", assert->node_idx,
  731. assert->domain);
  732. spin_lock(&dlm_domain_lock);
  733. dlm = __dlm_lookup_domain_full(assert->domain, assert->name_len);
  734. /* XXX should we consider no dlm ctxt an error? */
  735. if (dlm) {
  736. spin_lock(&dlm->spinlock);
  737. /* Alright, this node has officially joined our
  738. * domain. Set him in the map and clean up our
  739. * leftover join state. */
  740. BUG_ON(dlm->joining_node != assert->node_idx);
  741. set_bit(assert->node_idx, dlm->domain_map);
  742. __dlm_set_joining_node(dlm, DLM_LOCK_RES_OWNER_UNKNOWN);
  743. printk(KERN_NOTICE "o2dlm: Node %u joins domain %s\n",
  744. assert->node_idx, dlm->name);
  745. __dlm_print_nodes(dlm);
  746. /* notify anything attached to the heartbeat events */
  747. dlm_hb_event_notify_attached(dlm, assert->node_idx, 1);
  748. spin_unlock(&dlm->spinlock);
  749. }
  750. spin_unlock(&dlm_domain_lock);
  751. return 0;
  752. }
  753. static int dlm_cancel_join_handler(struct o2net_msg *msg, u32 len, void *data,
  754. void **ret_data)
  755. {
  756. struct dlm_cancel_join *cancel;
  757. struct dlm_ctxt *dlm = NULL;
  758. cancel = (struct dlm_cancel_join *) msg->buf;
  759. mlog(0, "node %u cancels join on domain %s\n", cancel->node_idx,
  760. cancel->domain);
  761. spin_lock(&dlm_domain_lock);
  762. dlm = __dlm_lookup_domain_full(cancel->domain, cancel->name_len);
  763. if (dlm) {
  764. spin_lock(&dlm->spinlock);
  765. /* Yikes, this guy wants to cancel his join. No
  766. * problem, we simply cleanup our join state. */
  767. BUG_ON(dlm->joining_node != cancel->node_idx);
  768. __dlm_set_joining_node(dlm, DLM_LOCK_RES_OWNER_UNKNOWN);
  769. spin_unlock(&dlm->spinlock);
  770. }
  771. spin_unlock(&dlm_domain_lock);
  772. return 0;
  773. }
  774. static int dlm_send_one_join_cancel(struct dlm_ctxt *dlm,
  775. unsigned int node)
  776. {
  777. int status;
  778. struct dlm_cancel_join cancel_msg;
  779. memset(&cancel_msg, 0, sizeof(cancel_msg));
  780. cancel_msg.node_idx = dlm->node_num;
  781. cancel_msg.name_len = strlen(dlm->name);
  782. memcpy(cancel_msg.domain, dlm->name, cancel_msg.name_len);
  783. status = o2net_send_message(DLM_CANCEL_JOIN_MSG, DLM_MOD_KEY,
  784. &cancel_msg, sizeof(cancel_msg), node,
  785. NULL);
  786. if (status < 0) {
  787. mlog(ML_ERROR, "Error %d when sending message %u (key 0x%x) to "
  788. "node %u\n", status, DLM_CANCEL_JOIN_MSG, DLM_MOD_KEY,
  789. node);
  790. goto bail;
  791. }
  792. bail:
  793. return status;
  794. }
  795. /* map_size should be in bytes. */
  796. static int dlm_send_join_cancels(struct dlm_ctxt *dlm,
  797. unsigned long *node_map,
  798. unsigned int map_size)
  799. {
  800. int status, tmpstat;
  801. unsigned int node;
  802. if (map_size != (BITS_TO_LONGS(O2NM_MAX_NODES) *
  803. sizeof(unsigned long))) {
  804. mlog(ML_ERROR,
  805. "map_size %u != BITS_TO_LONGS(O2NM_MAX_NODES) %u\n",
  806. map_size, (unsigned)BITS_TO_LONGS(O2NM_MAX_NODES));
  807. return -EINVAL;
  808. }
  809. status = 0;
  810. node = -1;
  811. while ((node = find_next_bit(node_map, O2NM_MAX_NODES,
  812. node + 1)) < O2NM_MAX_NODES) {
  813. if (node == dlm->node_num)
  814. continue;
  815. tmpstat = dlm_send_one_join_cancel(dlm, node);
  816. if (tmpstat) {
  817. mlog(ML_ERROR, "Error return %d cancelling join on "
  818. "node %d\n", tmpstat, node);
  819. if (!status)
  820. status = tmpstat;
  821. }
  822. }
  823. if (status)
  824. mlog_errno(status);
  825. return status;
  826. }
  827. static int dlm_request_join(struct dlm_ctxt *dlm,
  828. int node,
  829. enum dlm_query_join_response_code *response)
  830. {
  831. int status;
  832. struct dlm_query_join_request join_msg;
  833. struct dlm_query_join_packet packet;
  834. u32 join_resp;
  835. mlog(0, "querying node %d\n", node);
  836. memset(&join_msg, 0, sizeof(join_msg));
  837. join_msg.node_idx = dlm->node_num;
  838. join_msg.name_len = strlen(dlm->name);
  839. memcpy(join_msg.domain, dlm->name, join_msg.name_len);
  840. join_msg.dlm_proto = dlm->dlm_locking_proto;
  841. join_msg.fs_proto = dlm->fs_locking_proto;
  842. /* copy live node map to join message */
  843. byte_copymap(join_msg.node_map, dlm->live_nodes_map, O2NM_MAX_NODES);
  844. status = o2net_send_message(DLM_QUERY_JOIN_MSG, DLM_MOD_KEY, &join_msg,
  845. sizeof(join_msg), node, &join_resp);
  846. if (status < 0 && status != -ENOPROTOOPT) {
  847. mlog(ML_ERROR, "Error %d when sending message %u (key 0x%x) to "
  848. "node %u\n", status, DLM_QUERY_JOIN_MSG, DLM_MOD_KEY,
  849. node);
  850. goto bail;
  851. }
  852. dlm_query_join_wire_to_packet(join_resp, &packet);
  853. /* -ENOPROTOOPT from the net code means the other side isn't
  854. listening for our message type -- that's fine, it means
  855. his dlm isn't up, so we can consider him a 'yes' but not
  856. joined into the domain. */
  857. if (status == -ENOPROTOOPT) {
  858. status = 0;
  859. *response = JOIN_OK_NO_MAP;
  860. } else if (packet.code == JOIN_DISALLOW ||
  861. packet.code == JOIN_OK_NO_MAP) {
  862. *response = packet.code;
  863. } else if (packet.code == JOIN_PROTOCOL_MISMATCH) {
  864. mlog(ML_NOTICE,
  865. "This node requested DLM locking protocol %u.%u and "
  866. "filesystem locking protocol %u.%u. At least one of "
  867. "the protocol versions on node %d is not compatible, "
  868. "disconnecting\n",
  869. dlm->dlm_locking_proto.pv_major,
  870. dlm->dlm_locking_proto.pv_minor,
  871. dlm->fs_locking_proto.pv_major,
  872. dlm->fs_locking_proto.pv_minor,
  873. node);
  874. status = -EPROTO;
  875. *response = packet.code;
  876. } else if (packet.code == JOIN_OK) {
  877. *response = packet.code;
  878. /* Use the same locking protocol as the remote node */
  879. dlm->dlm_locking_proto.pv_minor = packet.dlm_minor;
  880. dlm->fs_locking_proto.pv_minor = packet.fs_minor;
  881. mlog(0,
  882. "Node %d responds JOIN_OK with DLM locking protocol "
  883. "%u.%u and fs locking protocol %u.%u\n",
  884. node,
  885. dlm->dlm_locking_proto.pv_major,
  886. dlm->dlm_locking_proto.pv_minor,
  887. dlm->fs_locking_proto.pv_major,
  888. dlm->fs_locking_proto.pv_minor);
  889. } else {
  890. status = -EINVAL;
  891. mlog(ML_ERROR, "invalid response %d from node %u\n",
  892. packet.code, node);
  893. }
  894. mlog(0, "status %d, node %d response is %d\n", status, node,
  895. *response);
  896. bail:
  897. return status;
  898. }
  899. static int dlm_send_one_join_assert(struct dlm_ctxt *dlm,
  900. unsigned int node)
  901. {
  902. int status;
  903. struct dlm_assert_joined assert_msg;
  904. mlog(0, "Sending join assert to node %u\n", node);
  905. memset(&assert_msg, 0, sizeof(assert_msg));
  906. assert_msg.node_idx = dlm->node_num;
  907. assert_msg.name_len = strlen(dlm->name);
  908. memcpy(assert_msg.domain, dlm->name, assert_msg.name_len);
  909. status = o2net_send_message(DLM_ASSERT_JOINED_MSG, DLM_MOD_KEY,
  910. &assert_msg, sizeof(assert_msg), node,
  911. NULL);
  912. if (status < 0)
  913. mlog(ML_ERROR, "Error %d when sending message %u (key 0x%x) to "
  914. "node %u\n", status, DLM_ASSERT_JOINED_MSG, DLM_MOD_KEY,
  915. node);
  916. return status;
  917. }
  918. static void dlm_send_join_asserts(struct dlm_ctxt *dlm,
  919. unsigned long *node_map)
  920. {
  921. int status, node, live;
  922. status = 0;
  923. node = -1;
  924. while ((node = find_next_bit(node_map, O2NM_MAX_NODES,
  925. node + 1)) < O2NM_MAX_NODES) {
  926. if (node == dlm->node_num)
  927. continue;
  928. do {
  929. /* It is very important that this message be
  930. * received so we spin until either the node
  931. * has died or it gets the message. */
  932. status = dlm_send_one_join_assert(dlm, node);
  933. spin_lock(&dlm->spinlock);
  934. live = test_bit(node, dlm->live_nodes_map);
  935. spin_unlock(&dlm->spinlock);
  936. if (status) {
  937. mlog(ML_ERROR, "Error return %d asserting "
  938. "join on node %d\n", status, node);
  939. /* give us some time between errors... */
  940. if (live)
  941. msleep(DLM_DOMAIN_BACKOFF_MS);
  942. }
  943. } while (status && live);
  944. }
  945. }
  946. struct domain_join_ctxt {
  947. unsigned long live_map[BITS_TO_LONGS(O2NM_MAX_NODES)];
  948. unsigned long yes_resp_map[BITS_TO_LONGS(O2NM_MAX_NODES)];
  949. };
  950. static int dlm_should_restart_join(struct dlm_ctxt *dlm,
  951. struct domain_join_ctxt *ctxt,
  952. enum dlm_query_join_response_code response)
  953. {
  954. int ret;
  955. if (response == JOIN_DISALLOW) {
  956. mlog(0, "Latest response of disallow -- should restart\n");
  957. return 1;
  958. }
  959. spin_lock(&dlm->spinlock);
  960. /* For now, we restart the process if the node maps have
  961. * changed at all */
  962. ret = memcmp(ctxt->live_map, dlm->live_nodes_map,
  963. sizeof(dlm->live_nodes_map));
  964. spin_unlock(&dlm->spinlock);
  965. if (ret)
  966. mlog(0, "Node maps changed -- should restart\n");
  967. return ret;
  968. }
  969. static int dlm_try_to_join_domain(struct dlm_ctxt *dlm)
  970. {
  971. int status = 0, tmpstat, node;
  972. struct domain_join_ctxt *ctxt;
  973. enum dlm_query_join_response_code response = JOIN_DISALLOW;
  974. mlog_entry("%p", dlm);
  975. ctxt = kzalloc(sizeof(*ctxt), GFP_KERNEL);
  976. if (!ctxt) {
  977. status = -ENOMEM;
  978. mlog_errno(status);
  979. goto bail;
  980. }
  981. /* group sem locking should work for us here -- we're already
  982. * registered for heartbeat events so filling this should be
  983. * atomic wrt getting those handlers called. */
  984. o2hb_fill_node_map(dlm->live_nodes_map, sizeof(dlm->live_nodes_map));
  985. spin_lock(&dlm->spinlock);
  986. memcpy(ctxt->live_map, dlm->live_nodes_map, sizeof(ctxt->live_map));
  987. __dlm_set_joining_node(dlm, dlm->node_num);
  988. spin_unlock(&dlm->spinlock);
  989. node = -1;
  990. while ((node = find_next_bit(ctxt->live_map, O2NM_MAX_NODES,
  991. node + 1)) < O2NM_MAX_NODES) {
  992. if (node == dlm->node_num)
  993. continue;
  994. status = dlm_request_join(dlm, node, &response);
  995. if (status < 0) {
  996. mlog_errno(status);
  997. goto bail;
  998. }
  999. /* Ok, either we got a response or the node doesn't have a
  1000. * dlm up. */
  1001. if (response == JOIN_OK)
  1002. set_bit(node, ctxt->yes_resp_map);
  1003. if (dlm_should_restart_join(dlm, ctxt, response)) {
  1004. status = -EAGAIN;
  1005. goto bail;
  1006. }
  1007. }
  1008. mlog(0, "Yay, done querying nodes!\n");
  1009. /* Yay, everyone agree's we can join the domain. My domain is
  1010. * comprised of all nodes who were put in the
  1011. * yes_resp_map. Copy that into our domain map and send a join
  1012. * assert message to clean up everyone elses state. */
  1013. spin_lock(&dlm->spinlock);
  1014. memcpy(dlm->domain_map, ctxt->yes_resp_map,
  1015. sizeof(ctxt->yes_resp_map));
  1016. set_bit(dlm->node_num, dlm->domain_map);
  1017. spin_unlock(&dlm->spinlock);
  1018. dlm_send_join_asserts(dlm, ctxt->yes_resp_map);
  1019. /* Joined state *must* be set before the joining node
  1020. * information, otherwise the query_join handler may read no
  1021. * current joiner but a state of NEW and tell joining nodes
  1022. * we're not in the domain. */
  1023. spin_lock(&dlm_domain_lock);
  1024. dlm->dlm_state = DLM_CTXT_JOINED;
  1025. dlm->num_joins++;
  1026. spin_unlock(&dlm_domain_lock);
  1027. bail:
  1028. spin_lock(&dlm->spinlock);
  1029. __dlm_set_joining_node(dlm, DLM_LOCK_RES_OWNER_UNKNOWN);
  1030. if (!status)
  1031. __dlm_print_nodes(dlm);
  1032. spin_unlock(&dlm->spinlock);
  1033. if (ctxt) {
  1034. /* Do we need to send a cancel message to any nodes? */
  1035. if (status < 0) {
  1036. tmpstat = dlm_send_join_cancels(dlm,
  1037. ctxt->yes_resp_map,
  1038. sizeof(ctxt->yes_resp_map));
  1039. if (tmpstat < 0)
  1040. mlog_errno(tmpstat);
  1041. }
  1042. kfree(ctxt);
  1043. }
  1044. mlog(0, "returning %d\n", status);
  1045. return status;
  1046. }
  1047. static void dlm_unregister_domain_handlers(struct dlm_ctxt *dlm)
  1048. {
  1049. o2hb_unregister_callback(NULL, &dlm->dlm_hb_up);
  1050. o2hb_unregister_callback(NULL, &dlm->dlm_hb_down);
  1051. o2net_unregister_handler_list(&dlm->dlm_domain_handlers);
  1052. }
  1053. static int dlm_register_domain_handlers(struct dlm_ctxt *dlm)
  1054. {
  1055. int status;
  1056. mlog(0, "registering handlers.\n");
  1057. o2hb_setup_callback(&dlm->dlm_hb_down, O2HB_NODE_DOWN_CB,
  1058. dlm_hb_node_down_cb, dlm, DLM_HB_NODE_DOWN_PRI);
  1059. status = o2hb_register_callback(NULL, &dlm->dlm_hb_down);
  1060. if (status)
  1061. goto bail;
  1062. o2hb_setup_callback(&dlm->dlm_hb_up, O2HB_NODE_UP_CB,
  1063. dlm_hb_node_up_cb, dlm, DLM_HB_NODE_UP_PRI);
  1064. status = o2hb_register_callback(NULL, &dlm->dlm_hb_up);
  1065. if (status)
  1066. goto bail;
  1067. status = o2net_register_handler(DLM_MASTER_REQUEST_MSG, dlm->key,
  1068. sizeof(struct dlm_master_request),
  1069. dlm_master_request_handler,
  1070. dlm, NULL, &dlm->dlm_domain_handlers);
  1071. if (status)
  1072. goto bail;
  1073. status = o2net_register_handler(DLM_ASSERT_MASTER_MSG, dlm->key,
  1074. sizeof(struct dlm_assert_master),
  1075. dlm_assert_master_handler,
  1076. dlm, dlm_assert_master_post_handler,
  1077. &dlm->dlm_domain_handlers);
  1078. if (status)
  1079. goto bail;
  1080. status = o2net_register_handler(DLM_CREATE_LOCK_MSG, dlm->key,
  1081. sizeof(struct dlm_create_lock),
  1082. dlm_create_lock_handler,
  1083. dlm, NULL, &dlm->dlm_domain_handlers);
  1084. if (status)
  1085. goto bail;
  1086. status = o2net_register_handler(DLM_CONVERT_LOCK_MSG, dlm->key,
  1087. DLM_CONVERT_LOCK_MAX_LEN,
  1088. dlm_convert_lock_handler,
  1089. dlm, NULL, &dlm->dlm_domain_handlers);
  1090. if (status)
  1091. goto bail;
  1092. status = o2net_register_handler(DLM_UNLOCK_LOCK_MSG, dlm->key,
  1093. DLM_UNLOCK_LOCK_MAX_LEN,
  1094. dlm_unlock_lock_handler,
  1095. dlm, NULL, &dlm->dlm_domain_handlers);
  1096. if (status)
  1097. goto bail;
  1098. status = o2net_register_handler(DLM_PROXY_AST_MSG, dlm->key,
  1099. DLM_PROXY_AST_MAX_LEN,
  1100. dlm_proxy_ast_handler,
  1101. dlm, NULL, &dlm->dlm_domain_handlers);
  1102. if (status)
  1103. goto bail;
  1104. status = o2net_register_handler(DLM_EXIT_DOMAIN_MSG, dlm->key,
  1105. sizeof(struct dlm_exit_domain),
  1106. dlm_exit_domain_handler,
  1107. dlm, NULL, &dlm->dlm_domain_handlers);
  1108. if (status)
  1109. goto bail;
  1110. status = o2net_register_handler(DLM_DEREF_LOCKRES_MSG, dlm->key,
  1111. sizeof(struct dlm_deref_lockres),
  1112. dlm_deref_lockres_handler,
  1113. dlm, NULL, &dlm->dlm_domain_handlers);
  1114. if (status)
  1115. goto bail;
  1116. status = o2net_register_handler(DLM_MIGRATE_REQUEST_MSG, dlm->key,
  1117. sizeof(struct dlm_migrate_request),
  1118. dlm_migrate_request_handler,
  1119. dlm, NULL, &dlm->dlm_domain_handlers);
  1120. if (status)
  1121. goto bail;
  1122. status = o2net_register_handler(DLM_MIG_LOCKRES_MSG, dlm->key,
  1123. DLM_MIG_LOCKRES_MAX_LEN,
  1124. dlm_mig_lockres_handler,
  1125. dlm, NULL, &dlm->dlm_domain_handlers);
  1126. if (status)
  1127. goto bail;
  1128. status = o2net_register_handler(DLM_MASTER_REQUERY_MSG, dlm->key,
  1129. sizeof(struct dlm_master_requery),
  1130. dlm_master_requery_handler,
  1131. dlm, NULL, &dlm->dlm_domain_handlers);
  1132. if (status)
  1133. goto bail;
  1134. status = o2net_register_handler(DLM_LOCK_REQUEST_MSG, dlm->key,
  1135. sizeof(struct dlm_lock_request),
  1136. dlm_request_all_locks_handler,
  1137. dlm, NULL, &dlm->dlm_domain_handlers);
  1138. if (status)
  1139. goto bail;
  1140. status = o2net_register_handler(DLM_RECO_DATA_DONE_MSG, dlm->key,
  1141. sizeof(struct dlm_reco_data_done),
  1142. dlm_reco_data_done_handler,
  1143. dlm, NULL, &dlm->dlm_domain_handlers);
  1144. if (status)
  1145. goto bail;
  1146. status = o2net_register_handler(DLM_BEGIN_RECO_MSG, dlm->key,
  1147. sizeof(struct dlm_begin_reco),
  1148. dlm_begin_reco_handler,
  1149. dlm, NULL, &dlm->dlm_domain_handlers);
  1150. if (status)
  1151. goto bail;
  1152. status = o2net_register_handler(DLM_FINALIZE_RECO_MSG, dlm->key,
  1153. sizeof(struct dlm_finalize_reco),
  1154. dlm_finalize_reco_handler,
  1155. dlm, NULL, &dlm->dlm_domain_handlers);
  1156. if (status)
  1157. goto bail;
  1158. bail:
  1159. if (status)
  1160. dlm_unregister_domain_handlers(dlm);
  1161. return status;
  1162. }
  1163. static int dlm_join_domain(struct dlm_ctxt *dlm)
  1164. {
  1165. int status;
  1166. unsigned int backoff;
  1167. unsigned int total_backoff = 0;
  1168. BUG_ON(!dlm);
  1169. mlog(0, "Join domain %s\n", dlm->name);
  1170. status = dlm_register_domain_handlers(dlm);
  1171. if (status) {
  1172. mlog_errno(status);
  1173. goto bail;
  1174. }
  1175. status = dlm_debug_init(dlm);
  1176. if (status < 0) {
  1177. mlog_errno(status);
  1178. goto bail;
  1179. }
  1180. status = dlm_launch_thread(dlm);
  1181. if (status < 0) {
  1182. mlog_errno(status);
  1183. goto bail;
  1184. }
  1185. status = dlm_launch_recovery_thread(dlm);
  1186. if (status < 0) {
  1187. mlog_errno(status);
  1188. goto bail;
  1189. }
  1190. dlm->dlm_worker = create_singlethread_workqueue("dlm_wq");
  1191. if (!dlm->dlm_worker) {
  1192. status = -ENOMEM;
  1193. mlog_errno(status);
  1194. goto bail;
  1195. }
  1196. do {
  1197. status = dlm_try_to_join_domain(dlm);
  1198. /* If we're racing another node to the join, then we
  1199. * need to back off temporarily and let them
  1200. * complete. */
  1201. #define DLM_JOIN_TIMEOUT_MSECS 90000
  1202. if (status == -EAGAIN) {
  1203. if (signal_pending(current)) {
  1204. status = -ERESTARTSYS;
  1205. goto bail;
  1206. }
  1207. if (total_backoff >
  1208. msecs_to_jiffies(DLM_JOIN_TIMEOUT_MSECS)) {
  1209. status = -ERESTARTSYS;
  1210. mlog(ML_NOTICE, "Timed out joining dlm domain "
  1211. "%s after %u msecs\n", dlm->name,
  1212. jiffies_to_msecs(total_backoff));
  1213. goto bail;
  1214. }
  1215. /*
  1216. * <chip> After you!
  1217. * <dale> No, after you!
  1218. * <chip> I insist!
  1219. * <dale> But you first!
  1220. * ...
  1221. */
  1222. backoff = (unsigned int)(jiffies & 0x3);
  1223. backoff *= DLM_DOMAIN_BACKOFF_MS;
  1224. total_backoff += backoff;
  1225. mlog(0, "backoff %d\n", backoff);
  1226. msleep(backoff);
  1227. }
  1228. } while (status == -EAGAIN);
  1229. if (status < 0) {
  1230. mlog_errno(status);
  1231. goto bail;
  1232. }
  1233. status = 0;
  1234. bail:
  1235. wake_up(&dlm_domain_events);
  1236. if (status) {
  1237. dlm_unregister_domain_handlers(dlm);
  1238. dlm_debug_shutdown(dlm);
  1239. dlm_complete_thread(dlm);
  1240. dlm_complete_recovery_thread(dlm);
  1241. dlm_destroy_dlm_worker(dlm);
  1242. }
  1243. return status;
  1244. }
  1245. static struct dlm_ctxt *dlm_alloc_ctxt(const char *domain,
  1246. u32 key)
  1247. {
  1248. int i;
  1249. int ret;
  1250. struct dlm_ctxt *dlm = NULL;
  1251. dlm = kzalloc(sizeof(*dlm), GFP_KERNEL);
  1252. if (!dlm) {
  1253. mlog_errno(-ENOMEM);
  1254. goto leave;
  1255. }
  1256. dlm->name = kstrdup(domain, GFP_KERNEL);
  1257. if (dlm->name == NULL) {
  1258. mlog_errno(-ENOMEM);
  1259. kfree(dlm);
  1260. dlm = NULL;
  1261. goto leave;
  1262. }
  1263. dlm->lockres_hash = (struct hlist_head **)dlm_alloc_pagevec(DLM_HASH_PAGES);
  1264. if (!dlm->lockres_hash) {
  1265. mlog_errno(-ENOMEM);
  1266. kfree(dlm->name);
  1267. kfree(dlm);
  1268. dlm = NULL;
  1269. goto leave;
  1270. }
  1271. for (i = 0; i < DLM_HASH_BUCKETS; i++)
  1272. INIT_HLIST_HEAD(dlm_lockres_hash(dlm, i));
  1273. dlm->master_hash = (struct hlist_head **)
  1274. dlm_alloc_pagevec(DLM_HASH_PAGES);
  1275. if (!dlm->master_hash) {
  1276. mlog_errno(-ENOMEM);
  1277. dlm_free_pagevec((void **)dlm->lockres_hash, DLM_HASH_PAGES);
  1278. kfree(dlm->name);
  1279. kfree(dlm);
  1280. dlm = NULL;
  1281. goto leave;
  1282. }
  1283. for (i = 0; i < DLM_HASH_BUCKETS; i++)
  1284. INIT_HLIST_HEAD(dlm_master_hash(dlm, i));
  1285. dlm->key = key;
  1286. dlm->node_num = o2nm_this_node();
  1287. ret = dlm_create_debugfs_subroot(dlm);
  1288. if (ret < 0) {
  1289. dlm_free_pagevec((void **)dlm->master_hash, DLM_HASH_PAGES);
  1290. dlm_free_pagevec((void **)dlm->lockres_hash, DLM_HASH_PAGES);
  1291. kfree(dlm->name);
  1292. kfree(dlm);
  1293. dlm = NULL;
  1294. goto leave;
  1295. }
  1296. spin_lock_init(&dlm->spinlock);
  1297. spin_lock_init(&dlm->master_lock);
  1298. spin_lock_init(&dlm->ast_lock);
  1299. spin_lock_init(&dlm->track_lock);
  1300. INIT_LIST_HEAD(&dlm->list);
  1301. INIT_LIST_HEAD(&dlm->dirty_list);
  1302. INIT_LIST_HEAD(&dlm->reco.resources);
  1303. INIT_LIST_HEAD(&dlm->reco.received);
  1304. INIT_LIST_HEAD(&dlm->reco.node_data);
  1305. INIT_LIST_HEAD(&dlm->purge_list);
  1306. INIT_LIST_HEAD(&dlm->dlm_domain_handlers);
  1307. INIT_LIST_HEAD(&dlm->tracking_list);
  1308. dlm->reco.state = 0;
  1309. INIT_LIST_HEAD(&dlm->pending_asts);
  1310. INIT_LIST_HEAD(&dlm->pending_basts);
  1311. mlog(0, "dlm->recovery_map=%p, &(dlm->recovery_map[0])=%p\n",
  1312. dlm->recovery_map, &(dlm->recovery_map[0]));
  1313. memset(dlm->recovery_map, 0, sizeof(dlm->recovery_map));
  1314. memset(dlm->live_nodes_map, 0, sizeof(dlm->live_nodes_map));
  1315. memset(dlm->domain_map, 0, sizeof(dlm->domain_map));
  1316. dlm->dlm_thread_task = NULL;
  1317. dlm->dlm_reco_thread_task = NULL;
  1318. dlm->dlm_worker = NULL;
  1319. init_waitqueue_head(&dlm->dlm_thread_wq);
  1320. init_waitqueue_head(&dlm->dlm_reco_thread_wq);
  1321. init_waitqueue_head(&dlm->reco.event);
  1322. init_waitqueue_head(&dlm->ast_wq);
  1323. init_waitqueue_head(&dlm->migration_wq);
  1324. INIT_LIST_HEAD(&dlm->mle_hb_events);
  1325. dlm->joining_node = DLM_LOCK_RES_OWNER_UNKNOWN;
  1326. init_waitqueue_head(&dlm->dlm_join_events);
  1327. dlm->reco.new_master = O2NM_INVALID_NODE_NUM;
  1328. dlm->reco.dead_node = O2NM_INVALID_NODE_NUM;
  1329. atomic_set(&dlm->res_tot_count, 0);
  1330. atomic_set(&dlm->res_cur_count, 0);
  1331. for (i = 0; i < DLM_MLE_NUM_TYPES; ++i) {
  1332. atomic_set(&dlm->mle_tot_count[i], 0);
  1333. atomic_set(&dlm->mle_cur_count[i], 0);
  1334. }
  1335. spin_lock_init(&dlm->work_lock);
  1336. INIT_LIST_HEAD(&dlm->work_list);
  1337. INIT_WORK(&dlm->dispatched_work, dlm_dispatch_work);
  1338. kref_init(&dlm->dlm_refs);
  1339. dlm->dlm_state = DLM_CTXT_NEW;
  1340. INIT_LIST_HEAD(&dlm->dlm_eviction_callbacks);
  1341. mlog(0, "context init: refcount %u\n",
  1342. atomic_read(&dlm->dlm_refs.refcount));
  1343. leave:
  1344. return dlm;
  1345. }
  1346. /*
  1347. * Compare a requested locking protocol version against the current one.
  1348. *
  1349. * If the major numbers are different, they are incompatible.
  1350. * If the current minor is greater than the request, they are incompatible.
  1351. * If the current minor is less than or equal to the request, they are
  1352. * compatible, and the requester should run at the current minor version.
  1353. */
  1354. static int dlm_protocol_compare(struct dlm_protocol_version *existing,
  1355. struct dlm_protocol_version *request)
  1356. {
  1357. if (existing->pv_major != request->pv_major)
  1358. return 1;
  1359. if (existing->pv_minor > request->pv_minor)
  1360. return 1;
  1361. if (existing->pv_minor < request->pv_minor)
  1362. request->pv_minor = existing->pv_minor;
  1363. return 0;
  1364. }
  1365. /*
  1366. * dlm_register_domain: one-time setup per "domain".
  1367. *
  1368. * The filesystem passes in the requested locking version via proto.
  1369. * If registration was successful, proto will contain the negotiated
  1370. * locking protocol.
  1371. */
  1372. struct dlm_ctxt * dlm_register_domain(const char *domain,
  1373. u32 key,
  1374. struct dlm_protocol_version *fs_proto)
  1375. {
  1376. int ret;
  1377. struct dlm_ctxt *dlm = NULL;
  1378. struct dlm_ctxt *new_ctxt = NULL;
  1379. if (strlen(domain) >= O2NM_MAX_NAME_LEN) {
  1380. ret = -ENAMETOOLONG;
  1381. mlog(ML_ERROR, "domain name length too long\n");
  1382. goto leave;
  1383. }
  1384. if (!o2hb_check_local_node_heartbeating()) {
  1385. mlog(ML_ERROR, "the local node has not been configured, or is "
  1386. "not heartbeating\n");
  1387. ret = -EPROTO;
  1388. goto leave;
  1389. }
  1390. mlog(0, "register called for domain \"%s\"\n", domain);
  1391. retry:
  1392. dlm = NULL;
  1393. if (signal_pending(current)) {
  1394. ret = -ERESTARTSYS;
  1395. mlog_errno(ret);
  1396. goto leave;
  1397. }
  1398. spin_lock(&dlm_domain_lock);
  1399. dlm = __dlm_lookup_domain(domain);
  1400. if (dlm) {
  1401. if (dlm->dlm_state != DLM_CTXT_JOINED) {
  1402. spin_unlock(&dlm_domain_lock);
  1403. mlog(0, "This ctxt is not joined yet!\n");
  1404. wait_event_interruptible(dlm_domain_events,
  1405. dlm_wait_on_domain_helper(
  1406. domain));
  1407. goto retry;
  1408. }
  1409. if (dlm_protocol_compare(&dlm->fs_locking_proto, fs_proto)) {
  1410. spin_unlock(&dlm_domain_lock);
  1411. mlog(ML_ERROR,
  1412. "Requested locking protocol version is not "
  1413. "compatible with already registered domain "
  1414. "\"%s\"\n", domain);
  1415. ret = -EPROTO;
  1416. goto leave;
  1417. }
  1418. __dlm_get(dlm);
  1419. dlm->num_joins++;
  1420. spin_unlock(&dlm_domain_lock);
  1421. ret = 0;
  1422. goto leave;
  1423. }
  1424. /* doesn't exist */
  1425. if (!new_ctxt) {
  1426. spin_unlock(&dlm_domain_lock);
  1427. new_ctxt = dlm_alloc_ctxt(domain, key);
  1428. if (new_ctxt)
  1429. goto retry;
  1430. ret = -ENOMEM;
  1431. mlog_errno(ret);
  1432. goto leave;
  1433. }
  1434. /* a little variable switch-a-roo here... */
  1435. dlm = new_ctxt;
  1436. new_ctxt = NULL;
  1437. /* add the new domain */
  1438. list_add_tail(&dlm->list, &dlm_domains);
  1439. spin_unlock(&dlm_domain_lock);
  1440. /*
  1441. * Pass the locking protocol version into the join. If the join
  1442. * succeeds, it will have the negotiated protocol set.
  1443. */
  1444. dlm->dlm_locking_proto = dlm_protocol;
  1445. dlm->fs_locking_proto = *fs_proto;
  1446. ret = dlm_join_domain(dlm);
  1447. if (ret) {
  1448. mlog_errno(ret);
  1449. dlm_put(dlm);
  1450. goto leave;
  1451. }
  1452. /* Tell the caller what locking protocol we negotiated */
  1453. *fs_proto = dlm->fs_locking_proto;
  1454. ret = 0;
  1455. leave:
  1456. if (new_ctxt)
  1457. dlm_free_ctxt_mem(new_ctxt);
  1458. if (ret < 0)
  1459. dlm = ERR_PTR(ret);
  1460. return dlm;
  1461. }
  1462. EXPORT_SYMBOL_GPL(dlm_register_domain);
  1463. static LIST_HEAD(dlm_join_handlers);
  1464. static void dlm_unregister_net_handlers(void)
  1465. {
  1466. o2net_unregister_handler_list(&dlm_join_handlers);
  1467. }
  1468. static int dlm_register_net_handlers(void)
  1469. {
  1470. int status = 0;
  1471. status = o2net_register_handler(DLM_QUERY_JOIN_MSG, DLM_MOD_KEY,
  1472. sizeof(struct dlm_query_join_request),
  1473. dlm_query_join_handler,
  1474. NULL, NULL, &dlm_join_handlers);
  1475. if (status)
  1476. goto bail;
  1477. status = o2net_register_handler(DLM_ASSERT_JOINED_MSG, DLM_MOD_KEY,
  1478. sizeof(struct dlm_assert_joined),
  1479. dlm_assert_joined_handler,
  1480. NULL, NULL, &dlm_join_handlers);
  1481. if (status)
  1482. goto bail;
  1483. status = o2net_register_handler(DLM_CANCEL_JOIN_MSG, DLM_MOD_KEY,
  1484. sizeof(struct dlm_cancel_join),
  1485. dlm_cancel_join_handler,
  1486. NULL, NULL, &dlm_join_handlers);
  1487. bail:
  1488. if (status < 0)
  1489. dlm_unregister_net_handlers();
  1490. return status;
  1491. }
  1492. /* Domain eviction callback handling.
  1493. *
  1494. * The file system requires notification of node death *before* the
  1495. * dlm completes it's recovery work, otherwise it may be able to
  1496. * acquire locks on resources requiring recovery. Since the dlm can
  1497. * evict a node from it's domain *before* heartbeat fires, a similar
  1498. * mechanism is required. */
  1499. /* Eviction is not expected to happen often, so a per-domain lock is
  1500. * not necessary. Eviction callbacks are allowed to sleep for short
  1501. * periods of time. */
  1502. static DECLARE_RWSEM(dlm_callback_sem);
  1503. void dlm_fire_domain_eviction_callbacks(struct dlm_ctxt *dlm,
  1504. int node_num)
  1505. {
  1506. struct list_head *iter;
  1507. struct dlm_eviction_cb *cb;
  1508. down_read(&dlm_callback_sem);
  1509. list_for_each(iter, &dlm->dlm_eviction_callbacks) {
  1510. cb = list_entry(iter, struct dlm_eviction_cb, ec_item);
  1511. cb->ec_func(node_num, cb->ec_data);
  1512. }
  1513. up_read(&dlm_callback_sem);
  1514. }
  1515. void dlm_setup_eviction_cb(struct dlm_eviction_cb *cb,
  1516. dlm_eviction_func *f,
  1517. void *data)
  1518. {
  1519. INIT_LIST_HEAD(&cb->ec_item);
  1520. cb->ec_func = f;
  1521. cb->ec_data = data;
  1522. }
  1523. EXPORT_SYMBOL_GPL(dlm_setup_eviction_cb);
  1524. void dlm_register_eviction_cb(struct dlm_ctxt *dlm,
  1525. struct dlm_eviction_cb *cb)
  1526. {
  1527. down_write(&dlm_callback_sem);
  1528. list_add_tail(&cb->ec_item, &dlm->dlm_eviction_callbacks);
  1529. up_write(&dlm_callback_sem);
  1530. }
  1531. EXPORT_SYMBOL_GPL(dlm_register_eviction_cb);
  1532. void dlm_unregister_eviction_cb(struct dlm_eviction_cb *cb)
  1533. {
  1534. down_write(&dlm_callback_sem);
  1535. list_del_init(&cb->ec_item);
  1536. up_write(&dlm_callback_sem);
  1537. }
  1538. EXPORT_SYMBOL_GPL(dlm_unregister_eviction_cb);
  1539. static int __init dlm_init(void)
  1540. {
  1541. int status;
  1542. dlm_print_version();
  1543. status = dlm_init_mle_cache();
  1544. if (status) {
  1545. mlog(ML_ERROR, "Could not create o2dlm_mle slabcache\n");
  1546. goto error;
  1547. }
  1548. status = dlm_init_master_caches();
  1549. if (status) {
  1550. mlog(ML_ERROR, "Could not create o2dlm_lockres and "
  1551. "o2dlm_lockname slabcaches\n");
  1552. goto error;
  1553. }
  1554. status = dlm_init_lock_cache();
  1555. if (status) {
  1556. mlog(ML_ERROR, "Count not create o2dlm_lock slabcache\n");
  1557. goto error;
  1558. }
  1559. status = dlm_register_net_handlers();
  1560. if (status) {
  1561. mlog(ML_ERROR, "Unable to register network handlers\n");
  1562. goto error;
  1563. }
  1564. status = dlm_create_debugfs_root();
  1565. if (status)
  1566. goto error;
  1567. return 0;
  1568. error:
  1569. dlm_unregister_net_handlers();
  1570. dlm_destroy_lock_cache();
  1571. dlm_destroy_master_caches();
  1572. dlm_destroy_mle_cache();
  1573. return -1;
  1574. }
  1575. static void __exit dlm_exit (void)
  1576. {
  1577. dlm_destroy_debugfs_root();
  1578. dlm_unregister_net_handlers();
  1579. dlm_destroy_lock_cache();
  1580. dlm_destroy_master_caches();
  1581. dlm_destroy_mle_cache();
  1582. }
  1583. MODULE_AUTHOR("Oracle");
  1584. MODULE_LICENSE("GPL");
  1585. module_init(dlm_init);
  1586. module_exit(dlm_exit);