dlmdomain.c 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902
  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. spin_lock_init(&dlm->track_lock);
  1279. INIT_LIST_HEAD(&dlm->list);
  1280. INIT_LIST_HEAD(&dlm->dirty_list);
  1281. INIT_LIST_HEAD(&dlm->reco.resources);
  1282. INIT_LIST_HEAD(&dlm->reco.received);
  1283. INIT_LIST_HEAD(&dlm->reco.node_data);
  1284. INIT_LIST_HEAD(&dlm->purge_list);
  1285. INIT_LIST_HEAD(&dlm->dlm_domain_handlers);
  1286. INIT_LIST_HEAD(&dlm->tracking_list);
  1287. dlm->reco.state = 0;
  1288. INIT_LIST_HEAD(&dlm->pending_asts);
  1289. INIT_LIST_HEAD(&dlm->pending_basts);
  1290. mlog(0, "dlm->recovery_map=%p, &(dlm->recovery_map[0])=%p\n",
  1291. dlm->recovery_map, &(dlm->recovery_map[0]));
  1292. memset(dlm->recovery_map, 0, sizeof(dlm->recovery_map));
  1293. memset(dlm->live_nodes_map, 0, sizeof(dlm->live_nodes_map));
  1294. memset(dlm->domain_map, 0, sizeof(dlm->domain_map));
  1295. dlm->dlm_thread_task = NULL;
  1296. dlm->dlm_reco_thread_task = NULL;
  1297. dlm->dlm_worker = NULL;
  1298. init_waitqueue_head(&dlm->dlm_thread_wq);
  1299. init_waitqueue_head(&dlm->dlm_reco_thread_wq);
  1300. init_waitqueue_head(&dlm->reco.event);
  1301. init_waitqueue_head(&dlm->ast_wq);
  1302. init_waitqueue_head(&dlm->migration_wq);
  1303. INIT_LIST_HEAD(&dlm->master_list);
  1304. INIT_LIST_HEAD(&dlm->mle_hb_events);
  1305. dlm->joining_node = DLM_LOCK_RES_OWNER_UNKNOWN;
  1306. init_waitqueue_head(&dlm->dlm_join_events);
  1307. dlm->reco.new_master = O2NM_INVALID_NODE_NUM;
  1308. dlm->reco.dead_node = O2NM_INVALID_NODE_NUM;
  1309. atomic_set(&dlm->local_resources, 0);
  1310. atomic_set(&dlm->remote_resources, 0);
  1311. atomic_set(&dlm->unknown_resources, 0);
  1312. spin_lock_init(&dlm->work_lock);
  1313. INIT_LIST_HEAD(&dlm->work_list);
  1314. INIT_WORK(&dlm->dispatched_work, dlm_dispatch_work);
  1315. kref_init(&dlm->dlm_refs);
  1316. dlm->dlm_state = DLM_CTXT_NEW;
  1317. INIT_LIST_HEAD(&dlm->dlm_eviction_callbacks);
  1318. mlog(0, "context init: refcount %u\n",
  1319. atomic_read(&dlm->dlm_refs.refcount));
  1320. leave:
  1321. return dlm;
  1322. }
  1323. /*
  1324. * Compare a requested locking protocol version against the current one.
  1325. *
  1326. * If the major numbers are different, they are incompatible.
  1327. * If the current minor is greater than the request, they are incompatible.
  1328. * If the current minor is less than or equal to the request, they are
  1329. * compatible, and the requester should run at the current minor version.
  1330. */
  1331. static int dlm_protocol_compare(struct dlm_protocol_version *existing,
  1332. struct dlm_protocol_version *request)
  1333. {
  1334. if (existing->pv_major != request->pv_major)
  1335. return 1;
  1336. if (existing->pv_minor > request->pv_minor)
  1337. return 1;
  1338. if (existing->pv_minor < request->pv_minor)
  1339. request->pv_minor = existing->pv_minor;
  1340. return 0;
  1341. }
  1342. /*
  1343. * dlm_register_domain: one-time setup per "domain".
  1344. *
  1345. * The filesystem passes in the requested locking version via proto.
  1346. * If registration was successful, proto will contain the negotiated
  1347. * locking protocol.
  1348. */
  1349. struct dlm_ctxt * dlm_register_domain(const char *domain,
  1350. u32 key,
  1351. struct dlm_protocol_version *fs_proto)
  1352. {
  1353. int ret;
  1354. struct dlm_ctxt *dlm = NULL;
  1355. struct dlm_ctxt *new_ctxt = NULL;
  1356. if (strlen(domain) > O2NM_MAX_NAME_LEN) {
  1357. ret = -ENAMETOOLONG;
  1358. mlog(ML_ERROR, "domain name length too long\n");
  1359. goto leave;
  1360. }
  1361. if (!o2hb_check_local_node_heartbeating()) {
  1362. mlog(ML_ERROR, "the local node has not been configured, or is "
  1363. "not heartbeating\n");
  1364. ret = -EPROTO;
  1365. goto leave;
  1366. }
  1367. mlog(0, "register called for domain \"%s\"\n", domain);
  1368. retry:
  1369. dlm = NULL;
  1370. if (signal_pending(current)) {
  1371. ret = -ERESTARTSYS;
  1372. mlog_errno(ret);
  1373. goto leave;
  1374. }
  1375. spin_lock(&dlm_domain_lock);
  1376. dlm = __dlm_lookup_domain(domain);
  1377. if (dlm) {
  1378. if (dlm->dlm_state != DLM_CTXT_JOINED) {
  1379. spin_unlock(&dlm_domain_lock);
  1380. mlog(0, "This ctxt is not joined yet!\n");
  1381. wait_event_interruptible(dlm_domain_events,
  1382. dlm_wait_on_domain_helper(
  1383. domain));
  1384. goto retry;
  1385. }
  1386. if (dlm_protocol_compare(&dlm->fs_locking_proto, fs_proto)) {
  1387. mlog(ML_ERROR,
  1388. "Requested locking protocol version is not "
  1389. "compatible with already registered domain "
  1390. "\"%s\"\n", domain);
  1391. ret = -EPROTO;
  1392. goto leave;
  1393. }
  1394. __dlm_get(dlm);
  1395. dlm->num_joins++;
  1396. spin_unlock(&dlm_domain_lock);
  1397. ret = 0;
  1398. goto leave;
  1399. }
  1400. /* doesn't exist */
  1401. if (!new_ctxt) {
  1402. spin_unlock(&dlm_domain_lock);
  1403. new_ctxt = dlm_alloc_ctxt(domain, key);
  1404. if (new_ctxt)
  1405. goto retry;
  1406. ret = -ENOMEM;
  1407. mlog_errno(ret);
  1408. goto leave;
  1409. }
  1410. /* a little variable switch-a-roo here... */
  1411. dlm = new_ctxt;
  1412. new_ctxt = NULL;
  1413. /* add the new domain */
  1414. list_add_tail(&dlm->list, &dlm_domains);
  1415. spin_unlock(&dlm_domain_lock);
  1416. /*
  1417. * Pass the locking protocol version into the join. If the join
  1418. * succeeds, it will have the negotiated protocol set.
  1419. */
  1420. dlm->dlm_locking_proto = dlm_protocol;
  1421. dlm->fs_locking_proto = *fs_proto;
  1422. ret = dlm_join_domain(dlm);
  1423. if (ret) {
  1424. mlog_errno(ret);
  1425. dlm_put(dlm);
  1426. goto leave;
  1427. }
  1428. /* Tell the caller what locking protocol we negotiated */
  1429. *fs_proto = dlm->fs_locking_proto;
  1430. ret = 0;
  1431. leave:
  1432. if (new_ctxt)
  1433. dlm_free_ctxt_mem(new_ctxt);
  1434. if (ret < 0)
  1435. dlm = ERR_PTR(ret);
  1436. return dlm;
  1437. }
  1438. EXPORT_SYMBOL_GPL(dlm_register_domain);
  1439. static LIST_HEAD(dlm_join_handlers);
  1440. static void dlm_unregister_net_handlers(void)
  1441. {
  1442. o2net_unregister_handler_list(&dlm_join_handlers);
  1443. }
  1444. static int dlm_register_net_handlers(void)
  1445. {
  1446. int status = 0;
  1447. status = o2net_register_handler(DLM_QUERY_JOIN_MSG, DLM_MOD_KEY,
  1448. sizeof(struct dlm_query_join_request),
  1449. dlm_query_join_handler,
  1450. NULL, NULL, &dlm_join_handlers);
  1451. if (status)
  1452. goto bail;
  1453. status = o2net_register_handler(DLM_ASSERT_JOINED_MSG, DLM_MOD_KEY,
  1454. sizeof(struct dlm_assert_joined),
  1455. dlm_assert_joined_handler,
  1456. NULL, NULL, &dlm_join_handlers);
  1457. if (status)
  1458. goto bail;
  1459. status = o2net_register_handler(DLM_CANCEL_JOIN_MSG, DLM_MOD_KEY,
  1460. sizeof(struct dlm_cancel_join),
  1461. dlm_cancel_join_handler,
  1462. NULL, NULL, &dlm_join_handlers);
  1463. bail:
  1464. if (status < 0)
  1465. dlm_unregister_net_handlers();
  1466. return status;
  1467. }
  1468. /* Domain eviction callback handling.
  1469. *
  1470. * The file system requires notification of node death *before* the
  1471. * dlm completes it's recovery work, otherwise it may be able to
  1472. * acquire locks on resources requiring recovery. Since the dlm can
  1473. * evict a node from it's domain *before* heartbeat fires, a similar
  1474. * mechanism is required. */
  1475. /* Eviction is not expected to happen often, so a per-domain lock is
  1476. * not necessary. Eviction callbacks are allowed to sleep for short
  1477. * periods of time. */
  1478. static DECLARE_RWSEM(dlm_callback_sem);
  1479. void dlm_fire_domain_eviction_callbacks(struct dlm_ctxt *dlm,
  1480. int node_num)
  1481. {
  1482. struct list_head *iter;
  1483. struct dlm_eviction_cb *cb;
  1484. down_read(&dlm_callback_sem);
  1485. list_for_each(iter, &dlm->dlm_eviction_callbacks) {
  1486. cb = list_entry(iter, struct dlm_eviction_cb, ec_item);
  1487. cb->ec_func(node_num, cb->ec_data);
  1488. }
  1489. up_read(&dlm_callback_sem);
  1490. }
  1491. void dlm_setup_eviction_cb(struct dlm_eviction_cb *cb,
  1492. dlm_eviction_func *f,
  1493. void *data)
  1494. {
  1495. INIT_LIST_HEAD(&cb->ec_item);
  1496. cb->ec_func = f;
  1497. cb->ec_data = data;
  1498. }
  1499. EXPORT_SYMBOL_GPL(dlm_setup_eviction_cb);
  1500. void dlm_register_eviction_cb(struct dlm_ctxt *dlm,
  1501. struct dlm_eviction_cb *cb)
  1502. {
  1503. down_write(&dlm_callback_sem);
  1504. list_add_tail(&cb->ec_item, &dlm->dlm_eviction_callbacks);
  1505. up_write(&dlm_callback_sem);
  1506. }
  1507. EXPORT_SYMBOL_GPL(dlm_register_eviction_cb);
  1508. void dlm_unregister_eviction_cb(struct dlm_eviction_cb *cb)
  1509. {
  1510. down_write(&dlm_callback_sem);
  1511. list_del_init(&cb->ec_item);
  1512. up_write(&dlm_callback_sem);
  1513. }
  1514. EXPORT_SYMBOL_GPL(dlm_unregister_eviction_cb);
  1515. static int __init dlm_init(void)
  1516. {
  1517. int status;
  1518. dlm_print_version();
  1519. status = dlm_init_mle_cache();
  1520. if (status) {
  1521. mlog(ML_ERROR, "Could not create o2dlm_mle slabcache\n");
  1522. goto error;
  1523. }
  1524. status = dlm_init_master_caches();
  1525. if (status) {
  1526. mlog(ML_ERROR, "Could not create o2dlm_lockres and "
  1527. "o2dlm_lockname slabcaches\n");
  1528. goto error;
  1529. }
  1530. status = dlm_init_lock_cache();
  1531. if (status) {
  1532. mlog(ML_ERROR, "Count not create o2dlm_lock slabcache\n");
  1533. goto error;
  1534. }
  1535. status = dlm_register_net_handlers();
  1536. if (status) {
  1537. mlog(ML_ERROR, "Unable to register network handlers\n");
  1538. goto error;
  1539. }
  1540. status = dlm_create_debugfs_root();
  1541. if (status)
  1542. goto error;
  1543. return 0;
  1544. error:
  1545. dlm_unregister_net_handlers();
  1546. dlm_destroy_lock_cache();
  1547. dlm_destroy_master_caches();
  1548. dlm_destroy_mle_cache();
  1549. return -1;
  1550. }
  1551. static void __exit dlm_exit (void)
  1552. {
  1553. dlm_destroy_debugfs_root();
  1554. dlm_unregister_net_handlers();
  1555. dlm_destroy_lock_cache();
  1556. dlm_destroy_master_caches();
  1557. dlm_destroy_mle_cache();
  1558. }
  1559. MODULE_AUTHOR("Oracle");
  1560. MODULE_LICENSE("GPL");
  1561. module_init(dlm_init);
  1562. module_exit(dlm_exit);