dlmdomain.c 49 KB

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