dlmdomain.c 48 KB

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