dlmdomain.c 47 KB

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