dlmdomain.c 48 KB

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