dlmdomain.c 48 KB

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