dlmmaster.c 81 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979
  1. /* -*- mode: c; c-basic-offset: 8; -*-
  2. * vim: noexpandtab sw=8 ts=8 sts=0:
  3. *
  4. * dlmmod.c
  5. *
  6. * standalone DLM module
  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/fs.h>
  28. #include <linux/types.h>
  29. #include <linux/slab.h>
  30. #include <linux/highmem.h>
  31. #include <linux/utsname.h>
  32. #include <linux/init.h>
  33. #include <linux/sysctl.h>
  34. #include <linux/random.h>
  35. #include <linux/blkdev.h>
  36. #include <linux/socket.h>
  37. #include <linux/inet.h>
  38. #include <linux/spinlock.h>
  39. #include <linux/delay.h>
  40. #include "cluster/heartbeat.h"
  41. #include "cluster/nodemanager.h"
  42. #include "cluster/tcp.h"
  43. #include "dlmapi.h"
  44. #include "dlmcommon.h"
  45. #include "dlmdebug.h"
  46. #include "dlmdomain.h"
  47. #define MLOG_MASK_PREFIX (ML_DLM|ML_DLM_MASTER)
  48. #include "cluster/masklog.h"
  49. enum dlm_mle_type {
  50. DLM_MLE_BLOCK,
  51. DLM_MLE_MASTER,
  52. DLM_MLE_MIGRATION
  53. };
  54. struct dlm_lock_name
  55. {
  56. u8 len;
  57. u8 name[DLM_LOCKID_NAME_MAX];
  58. };
  59. struct dlm_master_list_entry
  60. {
  61. struct list_head list;
  62. struct list_head hb_events;
  63. struct dlm_ctxt *dlm;
  64. spinlock_t spinlock;
  65. wait_queue_head_t wq;
  66. atomic_t woken;
  67. struct kref mle_refs;
  68. int inuse;
  69. unsigned long maybe_map[BITS_TO_LONGS(O2NM_MAX_NODES)];
  70. unsigned long vote_map[BITS_TO_LONGS(O2NM_MAX_NODES)];
  71. unsigned long response_map[BITS_TO_LONGS(O2NM_MAX_NODES)];
  72. unsigned long node_map[BITS_TO_LONGS(O2NM_MAX_NODES)];
  73. u8 master;
  74. u8 new_master;
  75. enum dlm_mle_type type;
  76. struct o2hb_callback_func mle_hb_up;
  77. struct o2hb_callback_func mle_hb_down;
  78. union {
  79. struct dlm_lock_resource *res;
  80. struct dlm_lock_name name;
  81. } u;
  82. };
  83. static void dlm_mle_node_down(struct dlm_ctxt *dlm,
  84. struct dlm_master_list_entry *mle,
  85. struct o2nm_node *node,
  86. int idx);
  87. static void dlm_mle_node_up(struct dlm_ctxt *dlm,
  88. struct dlm_master_list_entry *mle,
  89. struct o2nm_node *node,
  90. int idx);
  91. static void dlm_assert_master_worker(struct dlm_work_item *item, void *data);
  92. static int dlm_do_assert_master(struct dlm_ctxt *dlm, const char *lockname,
  93. unsigned int namelen, void *nodemap,
  94. u32 flags);
  95. static inline int dlm_mle_equal(struct dlm_ctxt *dlm,
  96. struct dlm_master_list_entry *mle,
  97. const char *name,
  98. unsigned int namelen)
  99. {
  100. struct dlm_lock_resource *res;
  101. if (dlm != mle->dlm)
  102. return 0;
  103. if (mle->type == DLM_MLE_BLOCK ||
  104. mle->type == DLM_MLE_MIGRATION) {
  105. if (namelen != mle->u.name.len ||
  106. memcmp(name, mle->u.name.name, namelen)!=0)
  107. return 0;
  108. } else {
  109. res = mle->u.res;
  110. if (namelen != res->lockname.len ||
  111. memcmp(res->lockname.name, name, namelen) != 0)
  112. return 0;
  113. }
  114. return 1;
  115. }
  116. #if 0
  117. /* Code here is included but defined out as it aids debugging */
  118. #define dlm_print_nodemap(m) _dlm_print_nodemap(m,#m)
  119. void _dlm_print_nodemap(unsigned long *map, const char *mapname)
  120. {
  121. int i;
  122. printk("%s=[ ", mapname);
  123. for (i=0; i<O2NM_MAX_NODES; i++)
  124. if (test_bit(i, map))
  125. printk("%d ", i);
  126. printk("]");
  127. }
  128. void dlm_print_one_mle(struct dlm_master_list_entry *mle)
  129. {
  130. int refs;
  131. char *type;
  132. char attached;
  133. u8 master;
  134. unsigned int namelen;
  135. const char *name;
  136. struct kref *k;
  137. unsigned long *maybe = mle->maybe_map,
  138. *vote = mle->vote_map,
  139. *resp = mle->response_map,
  140. *node = mle->node_map;
  141. k = &mle->mle_refs;
  142. if (mle->type == DLM_MLE_BLOCK)
  143. type = "BLK";
  144. else if (mle->type == DLM_MLE_MASTER)
  145. type = "MAS";
  146. else
  147. type = "MIG";
  148. refs = atomic_read(&k->refcount);
  149. master = mle->master;
  150. attached = (list_empty(&mle->hb_events) ? 'N' : 'Y');
  151. if (mle->type != DLM_MLE_MASTER) {
  152. namelen = mle->u.name.len;
  153. name = mle->u.name.name;
  154. } else {
  155. namelen = mle->u.res->lockname.len;
  156. name = mle->u.res->lockname.name;
  157. }
  158. mlog(ML_NOTICE, "%.*s: %3s refs=%3d mas=%3u new=%3u evt=%c inuse=%d ",
  159. namelen, name, type, refs, master, mle->new_master, attached,
  160. mle->inuse);
  161. dlm_print_nodemap(maybe);
  162. printk(", ");
  163. dlm_print_nodemap(vote);
  164. printk(", ");
  165. dlm_print_nodemap(resp);
  166. printk(", ");
  167. dlm_print_nodemap(node);
  168. printk(", ");
  169. printk("\n");
  170. }
  171. static void dlm_dump_mles(struct dlm_ctxt *dlm)
  172. {
  173. struct dlm_master_list_entry *mle;
  174. struct list_head *iter;
  175. mlog(ML_NOTICE, "dumping all mles for domain %s:\n", dlm->name);
  176. spin_lock(&dlm->master_lock);
  177. list_for_each(iter, &dlm->master_list) {
  178. mle = list_entry(iter, struct dlm_master_list_entry, list);
  179. dlm_print_one_mle(mle);
  180. }
  181. spin_unlock(&dlm->master_lock);
  182. }
  183. int dlm_dump_all_mles(const char __user *data, unsigned int len)
  184. {
  185. struct list_head *iter;
  186. struct dlm_ctxt *dlm;
  187. spin_lock(&dlm_domain_lock);
  188. list_for_each(iter, &dlm_domains) {
  189. dlm = list_entry (iter, struct dlm_ctxt, list);
  190. mlog(ML_NOTICE, "found dlm: %p, name=%s\n", dlm, dlm->name);
  191. dlm_dump_mles(dlm);
  192. }
  193. spin_unlock(&dlm_domain_lock);
  194. return len;
  195. }
  196. EXPORT_SYMBOL_GPL(dlm_dump_all_mles);
  197. #endif /* 0 */
  198. static kmem_cache_t *dlm_mle_cache = NULL;
  199. static void dlm_mle_release(struct kref *kref);
  200. static void dlm_init_mle(struct dlm_master_list_entry *mle,
  201. enum dlm_mle_type type,
  202. struct dlm_ctxt *dlm,
  203. struct dlm_lock_resource *res,
  204. const char *name,
  205. unsigned int namelen);
  206. static void dlm_put_mle(struct dlm_master_list_entry *mle);
  207. static void __dlm_put_mle(struct dlm_master_list_entry *mle);
  208. static int dlm_find_mle(struct dlm_ctxt *dlm,
  209. struct dlm_master_list_entry **mle,
  210. char *name, unsigned int namelen);
  211. static int dlm_do_master_request(struct dlm_master_list_entry *mle, int to);
  212. static int dlm_wait_for_lock_mastery(struct dlm_ctxt *dlm,
  213. struct dlm_lock_resource *res,
  214. struct dlm_master_list_entry *mle,
  215. int *blocked);
  216. static int dlm_restart_lock_mastery(struct dlm_ctxt *dlm,
  217. struct dlm_lock_resource *res,
  218. struct dlm_master_list_entry *mle,
  219. int blocked);
  220. static int dlm_add_migration_mle(struct dlm_ctxt *dlm,
  221. struct dlm_lock_resource *res,
  222. struct dlm_master_list_entry *mle,
  223. struct dlm_master_list_entry **oldmle,
  224. const char *name, unsigned int namelen,
  225. u8 new_master, u8 master);
  226. static u8 dlm_pick_migration_target(struct dlm_ctxt *dlm,
  227. struct dlm_lock_resource *res);
  228. static void dlm_remove_nonlocal_locks(struct dlm_ctxt *dlm,
  229. struct dlm_lock_resource *res);
  230. static int dlm_mark_lockres_migrating(struct dlm_ctxt *dlm,
  231. struct dlm_lock_resource *res,
  232. u8 target);
  233. static int dlm_pre_master_reco_lockres(struct dlm_ctxt *dlm,
  234. struct dlm_lock_resource *res);
  235. int dlm_is_host_down(int errno)
  236. {
  237. switch (errno) {
  238. case -EBADF:
  239. case -ECONNREFUSED:
  240. case -ENOTCONN:
  241. case -ECONNRESET:
  242. case -EPIPE:
  243. case -EHOSTDOWN:
  244. case -EHOSTUNREACH:
  245. case -ETIMEDOUT:
  246. case -ECONNABORTED:
  247. case -ENETDOWN:
  248. case -ENETUNREACH:
  249. case -ENETRESET:
  250. case -ESHUTDOWN:
  251. case -ENOPROTOOPT:
  252. case -EINVAL: /* if returned from our tcp code,
  253. this means there is no socket */
  254. return 1;
  255. }
  256. return 0;
  257. }
  258. /*
  259. * MASTER LIST FUNCTIONS
  260. */
  261. /*
  262. * regarding master list entries and heartbeat callbacks:
  263. *
  264. * in order to avoid sleeping and allocation that occurs in
  265. * heartbeat, master list entries are simply attached to the
  266. * dlm's established heartbeat callbacks. the mle is attached
  267. * when it is created, and since the dlm->spinlock is held at
  268. * that time, any heartbeat event will be properly discovered
  269. * by the mle. the mle needs to be detached from the
  270. * dlm->mle_hb_events list as soon as heartbeat events are no
  271. * longer useful to the mle, and before the mle is freed.
  272. *
  273. * as a general rule, heartbeat events are no longer needed by
  274. * the mle once an "answer" regarding the lock master has been
  275. * received.
  276. */
  277. static inline void __dlm_mle_attach_hb_events(struct dlm_ctxt *dlm,
  278. struct dlm_master_list_entry *mle)
  279. {
  280. assert_spin_locked(&dlm->spinlock);
  281. list_add_tail(&mle->hb_events, &dlm->mle_hb_events);
  282. }
  283. static inline void __dlm_mle_detach_hb_events(struct dlm_ctxt *dlm,
  284. struct dlm_master_list_entry *mle)
  285. {
  286. if (!list_empty(&mle->hb_events))
  287. list_del_init(&mle->hb_events);
  288. }
  289. static inline void dlm_mle_detach_hb_events(struct dlm_ctxt *dlm,
  290. struct dlm_master_list_entry *mle)
  291. {
  292. spin_lock(&dlm->spinlock);
  293. __dlm_mle_detach_hb_events(dlm, mle);
  294. spin_unlock(&dlm->spinlock);
  295. }
  296. static void dlm_get_mle_inuse(struct dlm_master_list_entry *mle)
  297. {
  298. struct dlm_ctxt *dlm;
  299. dlm = mle->dlm;
  300. assert_spin_locked(&dlm->spinlock);
  301. assert_spin_locked(&dlm->master_lock);
  302. mle->inuse++;
  303. kref_get(&mle->mle_refs);
  304. }
  305. static void dlm_put_mle_inuse(struct dlm_master_list_entry *mle)
  306. {
  307. struct dlm_ctxt *dlm;
  308. dlm = mle->dlm;
  309. spin_lock(&dlm->spinlock);
  310. spin_lock(&dlm->master_lock);
  311. mle->inuse--;
  312. __dlm_put_mle(mle);
  313. spin_unlock(&dlm->master_lock);
  314. spin_unlock(&dlm->spinlock);
  315. }
  316. /* remove from list and free */
  317. static void __dlm_put_mle(struct dlm_master_list_entry *mle)
  318. {
  319. struct dlm_ctxt *dlm;
  320. dlm = mle->dlm;
  321. assert_spin_locked(&dlm->spinlock);
  322. assert_spin_locked(&dlm->master_lock);
  323. if (!atomic_read(&mle->mle_refs.refcount)) {
  324. /* this may or may not crash, but who cares.
  325. * it's a BUG. */
  326. mlog(ML_ERROR, "bad mle: %p\n", mle);
  327. dlm_print_one_mle(mle);
  328. BUG();
  329. } else
  330. kref_put(&mle->mle_refs, dlm_mle_release);
  331. }
  332. /* must not have any spinlocks coming in */
  333. static void dlm_put_mle(struct dlm_master_list_entry *mle)
  334. {
  335. struct dlm_ctxt *dlm;
  336. dlm = mle->dlm;
  337. spin_lock(&dlm->spinlock);
  338. spin_lock(&dlm->master_lock);
  339. __dlm_put_mle(mle);
  340. spin_unlock(&dlm->master_lock);
  341. spin_unlock(&dlm->spinlock);
  342. }
  343. static inline void dlm_get_mle(struct dlm_master_list_entry *mle)
  344. {
  345. kref_get(&mle->mle_refs);
  346. }
  347. static void dlm_init_mle(struct dlm_master_list_entry *mle,
  348. enum dlm_mle_type type,
  349. struct dlm_ctxt *dlm,
  350. struct dlm_lock_resource *res,
  351. const char *name,
  352. unsigned int namelen)
  353. {
  354. assert_spin_locked(&dlm->spinlock);
  355. mle->dlm = dlm;
  356. mle->type = type;
  357. INIT_LIST_HEAD(&mle->list);
  358. INIT_LIST_HEAD(&mle->hb_events);
  359. memset(mle->maybe_map, 0, sizeof(mle->maybe_map));
  360. spin_lock_init(&mle->spinlock);
  361. init_waitqueue_head(&mle->wq);
  362. atomic_set(&mle->woken, 0);
  363. kref_init(&mle->mle_refs);
  364. memset(mle->response_map, 0, sizeof(mle->response_map));
  365. mle->master = O2NM_MAX_NODES;
  366. mle->new_master = O2NM_MAX_NODES;
  367. mle->inuse = 0;
  368. if (mle->type == DLM_MLE_MASTER) {
  369. BUG_ON(!res);
  370. mle->u.res = res;
  371. } else if (mle->type == DLM_MLE_BLOCK) {
  372. BUG_ON(!name);
  373. memcpy(mle->u.name.name, name, namelen);
  374. mle->u.name.len = namelen;
  375. } else /* DLM_MLE_MIGRATION */ {
  376. BUG_ON(!name);
  377. memcpy(mle->u.name.name, name, namelen);
  378. mle->u.name.len = namelen;
  379. }
  380. /* copy off the node_map and register hb callbacks on our copy */
  381. memcpy(mle->node_map, dlm->domain_map, sizeof(mle->node_map));
  382. memcpy(mle->vote_map, dlm->domain_map, sizeof(mle->vote_map));
  383. clear_bit(dlm->node_num, mle->vote_map);
  384. clear_bit(dlm->node_num, mle->node_map);
  385. /* attach the mle to the domain node up/down events */
  386. __dlm_mle_attach_hb_events(dlm, mle);
  387. }
  388. /* returns 1 if found, 0 if not */
  389. static int dlm_find_mle(struct dlm_ctxt *dlm,
  390. struct dlm_master_list_entry **mle,
  391. char *name, unsigned int namelen)
  392. {
  393. struct dlm_master_list_entry *tmpmle;
  394. struct list_head *iter;
  395. assert_spin_locked(&dlm->master_lock);
  396. list_for_each(iter, &dlm->master_list) {
  397. tmpmle = list_entry(iter, struct dlm_master_list_entry, list);
  398. if (!dlm_mle_equal(dlm, tmpmle, name, namelen))
  399. continue;
  400. dlm_get_mle(tmpmle);
  401. *mle = tmpmle;
  402. return 1;
  403. }
  404. return 0;
  405. }
  406. void dlm_hb_event_notify_attached(struct dlm_ctxt *dlm, int idx, int node_up)
  407. {
  408. struct dlm_master_list_entry *mle;
  409. struct list_head *iter;
  410. assert_spin_locked(&dlm->spinlock);
  411. list_for_each(iter, &dlm->mle_hb_events) {
  412. mle = list_entry(iter, struct dlm_master_list_entry,
  413. hb_events);
  414. if (node_up)
  415. dlm_mle_node_up(dlm, mle, NULL, idx);
  416. else
  417. dlm_mle_node_down(dlm, mle, NULL, idx);
  418. }
  419. }
  420. static void dlm_mle_node_down(struct dlm_ctxt *dlm,
  421. struct dlm_master_list_entry *mle,
  422. struct o2nm_node *node, int idx)
  423. {
  424. spin_lock(&mle->spinlock);
  425. if (!test_bit(idx, mle->node_map))
  426. mlog(0, "node %u already removed from nodemap!\n", idx);
  427. else
  428. clear_bit(idx, mle->node_map);
  429. spin_unlock(&mle->spinlock);
  430. }
  431. static void dlm_mle_node_up(struct dlm_ctxt *dlm,
  432. struct dlm_master_list_entry *mle,
  433. struct o2nm_node *node, int idx)
  434. {
  435. spin_lock(&mle->spinlock);
  436. if (test_bit(idx, mle->node_map))
  437. mlog(0, "node %u already in node map!\n", idx);
  438. else
  439. set_bit(idx, mle->node_map);
  440. spin_unlock(&mle->spinlock);
  441. }
  442. int dlm_init_mle_cache(void)
  443. {
  444. dlm_mle_cache = kmem_cache_create("dlm_mle_cache",
  445. sizeof(struct dlm_master_list_entry),
  446. 0, SLAB_HWCACHE_ALIGN,
  447. NULL, NULL);
  448. if (dlm_mle_cache == NULL)
  449. return -ENOMEM;
  450. return 0;
  451. }
  452. void dlm_destroy_mle_cache(void)
  453. {
  454. if (dlm_mle_cache)
  455. kmem_cache_destroy(dlm_mle_cache);
  456. }
  457. static void dlm_mle_release(struct kref *kref)
  458. {
  459. struct dlm_master_list_entry *mle;
  460. struct dlm_ctxt *dlm;
  461. mlog_entry_void();
  462. mle = container_of(kref, struct dlm_master_list_entry, mle_refs);
  463. dlm = mle->dlm;
  464. if (mle->type != DLM_MLE_MASTER) {
  465. mlog(0, "calling mle_release for %.*s, type %d\n",
  466. mle->u.name.len, mle->u.name.name, mle->type);
  467. } else {
  468. mlog(0, "calling mle_release for %.*s, type %d\n",
  469. mle->u.res->lockname.len,
  470. mle->u.res->lockname.name, mle->type);
  471. }
  472. assert_spin_locked(&dlm->spinlock);
  473. assert_spin_locked(&dlm->master_lock);
  474. /* remove from list if not already */
  475. if (!list_empty(&mle->list))
  476. list_del_init(&mle->list);
  477. /* detach the mle from the domain node up/down events */
  478. __dlm_mle_detach_hb_events(dlm, mle);
  479. /* NOTE: kfree under spinlock here.
  480. * if this is bad, we can move this to a freelist. */
  481. kmem_cache_free(dlm_mle_cache, mle);
  482. }
  483. /*
  484. * LOCK RESOURCE FUNCTIONS
  485. */
  486. static void dlm_set_lockres_owner(struct dlm_ctxt *dlm,
  487. struct dlm_lock_resource *res,
  488. u8 owner)
  489. {
  490. assert_spin_locked(&res->spinlock);
  491. mlog_entry("%.*s, %u\n", res->lockname.len, res->lockname.name, owner);
  492. if (owner == dlm->node_num)
  493. atomic_inc(&dlm->local_resources);
  494. else if (owner == DLM_LOCK_RES_OWNER_UNKNOWN)
  495. atomic_inc(&dlm->unknown_resources);
  496. else
  497. atomic_inc(&dlm->remote_resources);
  498. res->owner = owner;
  499. }
  500. void dlm_change_lockres_owner(struct dlm_ctxt *dlm,
  501. struct dlm_lock_resource *res, u8 owner)
  502. {
  503. assert_spin_locked(&res->spinlock);
  504. if (owner == res->owner)
  505. return;
  506. if (res->owner == dlm->node_num)
  507. atomic_dec(&dlm->local_resources);
  508. else if (res->owner == DLM_LOCK_RES_OWNER_UNKNOWN)
  509. atomic_dec(&dlm->unknown_resources);
  510. else
  511. atomic_dec(&dlm->remote_resources);
  512. dlm_set_lockres_owner(dlm, res, owner);
  513. }
  514. static void dlm_lockres_release(struct kref *kref)
  515. {
  516. struct dlm_lock_resource *res;
  517. res = container_of(kref, struct dlm_lock_resource, refs);
  518. /* This should not happen -- all lockres' have a name
  519. * associated with them at init time. */
  520. BUG_ON(!res->lockname.name);
  521. mlog(0, "destroying lockres %.*s\n", res->lockname.len,
  522. res->lockname.name);
  523. if (!hlist_unhashed(&res->hash_node) ||
  524. !list_empty(&res->granted) ||
  525. !list_empty(&res->converting) ||
  526. !list_empty(&res->blocked) ||
  527. !list_empty(&res->dirty) ||
  528. !list_empty(&res->recovering) ||
  529. !list_empty(&res->purge)) {
  530. mlog(ML_ERROR,
  531. "Going to BUG for resource %.*s."
  532. " We're on a list! [%c%c%c%c%c%c%c]\n",
  533. res->lockname.len, res->lockname.name,
  534. !hlist_unhashed(&res->hash_node) ? 'H' : ' ',
  535. !list_empty(&res->granted) ? 'G' : ' ',
  536. !list_empty(&res->converting) ? 'C' : ' ',
  537. !list_empty(&res->blocked) ? 'B' : ' ',
  538. !list_empty(&res->dirty) ? 'D' : ' ',
  539. !list_empty(&res->recovering) ? 'R' : ' ',
  540. !list_empty(&res->purge) ? 'P' : ' ');
  541. dlm_print_one_lock_resource(res);
  542. }
  543. /* By the time we're ready to blow this guy away, we shouldn't
  544. * be on any lists. */
  545. BUG_ON(!hlist_unhashed(&res->hash_node));
  546. BUG_ON(!list_empty(&res->granted));
  547. BUG_ON(!list_empty(&res->converting));
  548. BUG_ON(!list_empty(&res->blocked));
  549. BUG_ON(!list_empty(&res->dirty));
  550. BUG_ON(!list_empty(&res->recovering));
  551. BUG_ON(!list_empty(&res->purge));
  552. kfree(res->lockname.name);
  553. kfree(res);
  554. }
  555. void dlm_lockres_put(struct dlm_lock_resource *res)
  556. {
  557. kref_put(&res->refs, dlm_lockres_release);
  558. }
  559. static void dlm_init_lockres(struct dlm_ctxt *dlm,
  560. struct dlm_lock_resource *res,
  561. const char *name, unsigned int namelen)
  562. {
  563. char *qname;
  564. /* If we memset here, we lose our reference to the kmalloc'd
  565. * res->lockname.name, so be sure to init every field
  566. * correctly! */
  567. qname = (char *) res->lockname.name;
  568. memcpy(qname, name, namelen);
  569. res->lockname.len = namelen;
  570. res->lockname.hash = dlm_lockid_hash(name, namelen);
  571. init_waitqueue_head(&res->wq);
  572. spin_lock_init(&res->spinlock);
  573. INIT_HLIST_NODE(&res->hash_node);
  574. INIT_LIST_HEAD(&res->granted);
  575. INIT_LIST_HEAD(&res->converting);
  576. INIT_LIST_HEAD(&res->blocked);
  577. INIT_LIST_HEAD(&res->dirty);
  578. INIT_LIST_HEAD(&res->recovering);
  579. INIT_LIST_HEAD(&res->purge);
  580. atomic_set(&res->asts_reserved, 0);
  581. res->migration_pending = 0;
  582. kref_init(&res->refs);
  583. /* just for consistency */
  584. spin_lock(&res->spinlock);
  585. dlm_set_lockres_owner(dlm, res, DLM_LOCK_RES_OWNER_UNKNOWN);
  586. spin_unlock(&res->spinlock);
  587. res->state = DLM_LOCK_RES_IN_PROGRESS;
  588. res->last_used = 0;
  589. memset(res->lvb, 0, DLM_LVB_LEN);
  590. }
  591. struct dlm_lock_resource *dlm_new_lockres(struct dlm_ctxt *dlm,
  592. const char *name,
  593. unsigned int namelen)
  594. {
  595. struct dlm_lock_resource *res;
  596. res = kmalloc(sizeof(struct dlm_lock_resource), GFP_KERNEL);
  597. if (!res)
  598. return NULL;
  599. res->lockname.name = kmalloc(namelen, GFP_KERNEL);
  600. if (!res->lockname.name) {
  601. kfree(res);
  602. return NULL;
  603. }
  604. dlm_init_lockres(dlm, res, name, namelen);
  605. return res;
  606. }
  607. /*
  608. * lookup a lock resource by name.
  609. * may already exist in the hashtable.
  610. * lockid is null terminated
  611. *
  612. * if not, allocate enough for the lockres and for
  613. * the temporary structure used in doing the mastering.
  614. *
  615. * also, do a lookup in the dlm->master_list to see
  616. * if another node has begun mastering the same lock.
  617. * if so, there should be a block entry in there
  618. * for this name, and we should *not* attempt to master
  619. * the lock here. need to wait around for that node
  620. * to assert_master (or die).
  621. *
  622. */
  623. struct dlm_lock_resource * dlm_get_lock_resource(struct dlm_ctxt *dlm,
  624. const char *lockid,
  625. int flags)
  626. {
  627. struct dlm_lock_resource *tmpres=NULL, *res=NULL;
  628. struct dlm_master_list_entry *mle = NULL;
  629. struct dlm_master_list_entry *alloc_mle = NULL;
  630. int blocked = 0;
  631. int ret, nodenum;
  632. struct dlm_node_iter iter;
  633. unsigned int namelen, hash;
  634. int tries = 0;
  635. int bit, wait_on_recovery = 0;
  636. BUG_ON(!lockid);
  637. namelen = strlen(lockid);
  638. hash = dlm_lockid_hash(lockid, namelen);
  639. mlog(0, "get lockres %s (len %d)\n", lockid, namelen);
  640. lookup:
  641. spin_lock(&dlm->spinlock);
  642. tmpres = __dlm_lookup_lockres(dlm, lockid, namelen, hash);
  643. if (tmpres) {
  644. spin_unlock(&dlm->spinlock);
  645. mlog(0, "found in hash!\n");
  646. if (res)
  647. dlm_lockres_put(res);
  648. res = tmpres;
  649. goto leave;
  650. }
  651. if (!res) {
  652. spin_unlock(&dlm->spinlock);
  653. mlog(0, "allocating a new resource\n");
  654. /* nothing found and we need to allocate one. */
  655. alloc_mle = (struct dlm_master_list_entry *)
  656. kmem_cache_alloc(dlm_mle_cache, GFP_KERNEL);
  657. if (!alloc_mle)
  658. goto leave;
  659. res = dlm_new_lockres(dlm, lockid, namelen);
  660. if (!res)
  661. goto leave;
  662. goto lookup;
  663. }
  664. mlog(0, "no lockres found, allocated our own: %p\n", res);
  665. if (flags & LKM_LOCAL) {
  666. /* caller knows it's safe to assume it's not mastered elsewhere
  667. * DONE! return right away */
  668. spin_lock(&res->spinlock);
  669. dlm_change_lockres_owner(dlm, res, dlm->node_num);
  670. __dlm_insert_lockres(dlm, res);
  671. spin_unlock(&res->spinlock);
  672. spin_unlock(&dlm->spinlock);
  673. /* lockres still marked IN_PROGRESS */
  674. goto wake_waiters;
  675. }
  676. /* check master list to see if another node has started mastering it */
  677. spin_lock(&dlm->master_lock);
  678. /* if we found a block, wait for lock to be mastered by another node */
  679. blocked = dlm_find_mle(dlm, &mle, (char *)lockid, namelen);
  680. if (blocked) {
  681. if (mle->type == DLM_MLE_MASTER) {
  682. mlog(ML_ERROR, "master entry for nonexistent lock!\n");
  683. BUG();
  684. } else if (mle->type == DLM_MLE_MIGRATION) {
  685. /* migration is in progress! */
  686. /* the good news is that we now know the
  687. * "current" master (mle->master). */
  688. spin_unlock(&dlm->master_lock);
  689. assert_spin_locked(&dlm->spinlock);
  690. /* set the lockres owner and hash it */
  691. spin_lock(&res->spinlock);
  692. dlm_set_lockres_owner(dlm, res, mle->master);
  693. __dlm_insert_lockres(dlm, res);
  694. spin_unlock(&res->spinlock);
  695. spin_unlock(&dlm->spinlock);
  696. /* master is known, detach */
  697. dlm_mle_detach_hb_events(dlm, mle);
  698. dlm_put_mle(mle);
  699. mle = NULL;
  700. goto wake_waiters;
  701. }
  702. } else {
  703. /* go ahead and try to master lock on this node */
  704. mle = alloc_mle;
  705. /* make sure this does not get freed below */
  706. alloc_mle = NULL;
  707. dlm_init_mle(mle, DLM_MLE_MASTER, dlm, res, NULL, 0);
  708. set_bit(dlm->node_num, mle->maybe_map);
  709. list_add(&mle->list, &dlm->master_list);
  710. /* still holding the dlm spinlock, check the recovery map
  711. * to see if there are any nodes that still need to be
  712. * considered. these will not appear in the mle nodemap
  713. * but they might own this lockres. wait on them. */
  714. bit = find_next_bit(dlm->recovery_map, O2NM_MAX_NODES, 0);
  715. if (bit < O2NM_MAX_NODES) {
  716. mlog(ML_NOTICE, "%s:%.*s: at least one node (%d) to"
  717. "recover before lock mastery can begin\n",
  718. dlm->name, namelen, (char *)lockid, bit);
  719. wait_on_recovery = 1;
  720. }
  721. }
  722. /* at this point there is either a DLM_MLE_BLOCK or a
  723. * DLM_MLE_MASTER on the master list, so it's safe to add the
  724. * lockres to the hashtable. anyone who finds the lock will
  725. * still have to wait on the IN_PROGRESS. */
  726. /* finally add the lockres to its hash bucket */
  727. __dlm_insert_lockres(dlm, res);
  728. /* get an extra ref on the mle in case this is a BLOCK
  729. * if so, the creator of the BLOCK may try to put the last
  730. * ref at this time in the assert master handler, so we
  731. * need an extra one to keep from a bad ptr deref. */
  732. dlm_get_mle_inuse(mle);
  733. spin_unlock(&dlm->master_lock);
  734. spin_unlock(&dlm->spinlock);
  735. while (wait_on_recovery) {
  736. /* any cluster changes that occurred after dropping the
  737. * dlm spinlock would be detectable be a change on the mle,
  738. * so we only need to clear out the recovery map once. */
  739. if (dlm_is_recovery_lock(lockid, namelen)) {
  740. mlog(ML_NOTICE, "%s: recovery map is not empty, but "
  741. "must master $RECOVERY lock now\n", dlm->name);
  742. if (!dlm_pre_master_reco_lockres(dlm, res))
  743. wait_on_recovery = 0;
  744. else {
  745. mlog(0, "%s: waiting 500ms for heartbeat state "
  746. "change\n", dlm->name);
  747. msleep(500);
  748. }
  749. continue;
  750. }
  751. dlm_kick_recovery_thread(dlm);
  752. msleep(100);
  753. dlm_wait_for_recovery(dlm);
  754. spin_lock(&dlm->spinlock);
  755. bit = find_next_bit(dlm->recovery_map, O2NM_MAX_NODES, 0);
  756. if (bit < O2NM_MAX_NODES) {
  757. mlog(ML_NOTICE, "%s:%.*s: at least one node (%d) to"
  758. "recover before lock mastery can begin\n",
  759. dlm->name, namelen, (char *)lockid, bit);
  760. wait_on_recovery = 1;
  761. } else
  762. wait_on_recovery = 0;
  763. spin_unlock(&dlm->spinlock);
  764. }
  765. /* must wait for lock to be mastered elsewhere */
  766. if (blocked)
  767. goto wait;
  768. redo_request:
  769. ret = -EINVAL;
  770. dlm_node_iter_init(mle->vote_map, &iter);
  771. while ((nodenum = dlm_node_iter_next(&iter)) >= 0) {
  772. ret = dlm_do_master_request(mle, nodenum);
  773. if (ret < 0)
  774. mlog_errno(ret);
  775. if (mle->master != O2NM_MAX_NODES) {
  776. /* found a master ! */
  777. if (mle->master <= nodenum)
  778. break;
  779. /* if our master request has not reached the master
  780. * yet, keep going until it does. this is how the
  781. * master will know that asserts are needed back to
  782. * the lower nodes. */
  783. mlog(0, "%s:%.*s: requests only up to %u but master "
  784. "is %u, keep going\n", dlm->name, namelen,
  785. lockid, nodenum, mle->master);
  786. }
  787. }
  788. wait:
  789. /* keep going until the response map includes all nodes */
  790. ret = dlm_wait_for_lock_mastery(dlm, res, mle, &blocked);
  791. if (ret < 0) {
  792. mlog(0, "%s:%.*s: node map changed, redo the "
  793. "master request now, blocked=%d\n",
  794. dlm->name, res->lockname.len,
  795. res->lockname.name, blocked);
  796. if (++tries > 20) {
  797. mlog(ML_ERROR, "%s:%.*s: spinning on "
  798. "dlm_wait_for_lock_mastery, blocked=%d\n",
  799. dlm->name, res->lockname.len,
  800. res->lockname.name, blocked);
  801. dlm_print_one_lock_resource(res);
  802. /* dlm_print_one_mle(mle); */
  803. tries = 0;
  804. }
  805. goto redo_request;
  806. }
  807. mlog(0, "lockres mastered by %u\n", res->owner);
  808. /* make sure we never continue without this */
  809. BUG_ON(res->owner == O2NM_MAX_NODES);
  810. /* master is known, detach if not already detached */
  811. dlm_mle_detach_hb_events(dlm, mle);
  812. dlm_put_mle(mle);
  813. /* put the extra ref */
  814. dlm_put_mle_inuse(mle);
  815. wake_waiters:
  816. spin_lock(&res->spinlock);
  817. res->state &= ~DLM_LOCK_RES_IN_PROGRESS;
  818. spin_unlock(&res->spinlock);
  819. wake_up(&res->wq);
  820. leave:
  821. /* need to free the unused mle */
  822. if (alloc_mle)
  823. kmem_cache_free(dlm_mle_cache, alloc_mle);
  824. return res;
  825. }
  826. #define DLM_MASTERY_TIMEOUT_MS 5000
  827. static int dlm_wait_for_lock_mastery(struct dlm_ctxt *dlm,
  828. struct dlm_lock_resource *res,
  829. struct dlm_master_list_entry *mle,
  830. int *blocked)
  831. {
  832. u8 m;
  833. int ret, bit;
  834. int map_changed, voting_done;
  835. int assert, sleep;
  836. recheck:
  837. ret = 0;
  838. assert = 0;
  839. /* check if another node has already become the owner */
  840. spin_lock(&res->spinlock);
  841. if (res->owner != DLM_LOCK_RES_OWNER_UNKNOWN) {
  842. mlog(0, "%s:%.*s: owner is suddenly %u\n", dlm->name,
  843. res->lockname.len, res->lockname.name, res->owner);
  844. spin_unlock(&res->spinlock);
  845. /* this will cause the master to re-assert across
  846. * the whole cluster, freeing up mles */
  847. ret = dlm_do_master_request(mle, res->owner);
  848. if (ret < 0) {
  849. /* give recovery a chance to run */
  850. mlog(ML_ERROR, "link to %u went down?: %d\n", res->owner, ret);
  851. msleep(500);
  852. goto recheck;
  853. }
  854. ret = 0;
  855. goto leave;
  856. }
  857. spin_unlock(&res->spinlock);
  858. spin_lock(&mle->spinlock);
  859. m = mle->master;
  860. map_changed = (memcmp(mle->vote_map, mle->node_map,
  861. sizeof(mle->vote_map)) != 0);
  862. voting_done = (memcmp(mle->vote_map, mle->response_map,
  863. sizeof(mle->vote_map)) == 0);
  864. /* restart if we hit any errors */
  865. if (map_changed) {
  866. int b;
  867. mlog(0, "%s: %.*s: node map changed, restarting\n",
  868. dlm->name, res->lockname.len, res->lockname.name);
  869. ret = dlm_restart_lock_mastery(dlm, res, mle, *blocked);
  870. b = (mle->type == DLM_MLE_BLOCK);
  871. if ((*blocked && !b) || (!*blocked && b)) {
  872. mlog(0, "%s:%.*s: status change: old=%d new=%d\n",
  873. dlm->name, res->lockname.len, res->lockname.name,
  874. *blocked, b);
  875. *blocked = b;
  876. }
  877. spin_unlock(&mle->spinlock);
  878. if (ret < 0) {
  879. mlog_errno(ret);
  880. goto leave;
  881. }
  882. mlog(0, "%s:%.*s: restart lock mastery succeeded, "
  883. "rechecking now\n", dlm->name, res->lockname.len,
  884. res->lockname.name);
  885. goto recheck;
  886. } else {
  887. if (!voting_done) {
  888. mlog(0, "map not changed and voting not done "
  889. "for %s:%.*s\n", dlm->name, res->lockname.len,
  890. res->lockname.name);
  891. }
  892. }
  893. if (m != O2NM_MAX_NODES) {
  894. /* another node has done an assert!
  895. * all done! */
  896. sleep = 0;
  897. } else {
  898. sleep = 1;
  899. /* have all nodes responded? */
  900. if (voting_done && !*blocked) {
  901. bit = find_next_bit(mle->maybe_map, O2NM_MAX_NODES, 0);
  902. if (dlm->node_num <= bit) {
  903. /* my node number is lowest.
  904. * now tell other nodes that I am
  905. * mastering this. */
  906. mle->master = dlm->node_num;
  907. assert = 1;
  908. sleep = 0;
  909. }
  910. /* if voting is done, but we have not received
  911. * an assert master yet, we must sleep */
  912. }
  913. }
  914. spin_unlock(&mle->spinlock);
  915. /* sleep if we haven't finished voting yet */
  916. if (sleep) {
  917. unsigned long timeo = msecs_to_jiffies(DLM_MASTERY_TIMEOUT_MS);
  918. /*
  919. if (atomic_read(&mle->mle_refs.refcount) < 2)
  920. mlog(ML_ERROR, "mle (%p) refs=%d, name=%.*s\n", mle,
  921. atomic_read(&mle->mle_refs.refcount),
  922. res->lockname.len, res->lockname.name);
  923. */
  924. atomic_set(&mle->woken, 0);
  925. (void)wait_event_timeout(mle->wq,
  926. (atomic_read(&mle->woken) == 1),
  927. timeo);
  928. if (res->owner == O2NM_MAX_NODES) {
  929. mlog(0, "waiting again\n");
  930. goto recheck;
  931. }
  932. mlog(0, "done waiting, master is %u\n", res->owner);
  933. ret = 0;
  934. goto leave;
  935. }
  936. ret = 0; /* done */
  937. if (assert) {
  938. m = dlm->node_num;
  939. mlog(0, "about to master %.*s here, this=%u\n",
  940. res->lockname.len, res->lockname.name, m);
  941. ret = dlm_do_assert_master(dlm, res->lockname.name,
  942. res->lockname.len, mle->vote_map, 0);
  943. if (ret) {
  944. /* This is a failure in the network path,
  945. * not in the response to the assert_master
  946. * (any nonzero response is a BUG on this node).
  947. * Most likely a socket just got disconnected
  948. * due to node death. */
  949. mlog_errno(ret);
  950. }
  951. /* no longer need to restart lock mastery.
  952. * all living nodes have been contacted. */
  953. ret = 0;
  954. }
  955. /* set the lockres owner */
  956. spin_lock(&res->spinlock);
  957. dlm_change_lockres_owner(dlm, res, m);
  958. spin_unlock(&res->spinlock);
  959. leave:
  960. return ret;
  961. }
  962. struct dlm_bitmap_diff_iter
  963. {
  964. int curnode;
  965. unsigned long *orig_bm;
  966. unsigned long *cur_bm;
  967. unsigned long diff_bm[BITS_TO_LONGS(O2NM_MAX_NODES)];
  968. };
  969. enum dlm_node_state_change
  970. {
  971. NODE_DOWN = -1,
  972. NODE_NO_CHANGE = 0,
  973. NODE_UP
  974. };
  975. static void dlm_bitmap_diff_iter_init(struct dlm_bitmap_diff_iter *iter,
  976. unsigned long *orig_bm,
  977. unsigned long *cur_bm)
  978. {
  979. unsigned long p1, p2;
  980. int i;
  981. iter->curnode = -1;
  982. iter->orig_bm = orig_bm;
  983. iter->cur_bm = cur_bm;
  984. for (i = 0; i < BITS_TO_LONGS(O2NM_MAX_NODES); i++) {
  985. p1 = *(iter->orig_bm + i);
  986. p2 = *(iter->cur_bm + i);
  987. iter->diff_bm[i] = (p1 & ~p2) | (p2 & ~p1);
  988. }
  989. }
  990. static int dlm_bitmap_diff_iter_next(struct dlm_bitmap_diff_iter *iter,
  991. enum dlm_node_state_change *state)
  992. {
  993. int bit;
  994. if (iter->curnode >= O2NM_MAX_NODES)
  995. return -ENOENT;
  996. bit = find_next_bit(iter->diff_bm, O2NM_MAX_NODES,
  997. iter->curnode+1);
  998. if (bit >= O2NM_MAX_NODES) {
  999. iter->curnode = O2NM_MAX_NODES;
  1000. return -ENOENT;
  1001. }
  1002. /* if it was there in the original then this node died */
  1003. if (test_bit(bit, iter->orig_bm))
  1004. *state = NODE_DOWN;
  1005. else
  1006. *state = NODE_UP;
  1007. iter->curnode = bit;
  1008. return bit;
  1009. }
  1010. static int dlm_restart_lock_mastery(struct dlm_ctxt *dlm,
  1011. struct dlm_lock_resource *res,
  1012. struct dlm_master_list_entry *mle,
  1013. int blocked)
  1014. {
  1015. struct dlm_bitmap_diff_iter bdi;
  1016. enum dlm_node_state_change sc;
  1017. int node;
  1018. int ret = 0;
  1019. mlog(0, "something happened such that the "
  1020. "master process may need to be restarted!\n");
  1021. assert_spin_locked(&mle->spinlock);
  1022. dlm_bitmap_diff_iter_init(&bdi, mle->vote_map, mle->node_map);
  1023. node = dlm_bitmap_diff_iter_next(&bdi, &sc);
  1024. while (node >= 0) {
  1025. if (sc == NODE_UP) {
  1026. /* a node came up. clear any old vote from
  1027. * the response map and set it in the vote map
  1028. * then restart the mastery. */
  1029. mlog(ML_NOTICE, "node %d up while restarting\n", node);
  1030. /* redo the master request, but only for the new node */
  1031. mlog(0, "sending request to new node\n");
  1032. clear_bit(node, mle->response_map);
  1033. set_bit(node, mle->vote_map);
  1034. } else {
  1035. mlog(ML_ERROR, "node down! %d\n", node);
  1036. /* if the node wasn't involved in mastery skip it,
  1037. * but clear it out from the maps so that it will
  1038. * not affect mastery of this lockres */
  1039. clear_bit(node, mle->response_map);
  1040. clear_bit(node, mle->vote_map);
  1041. if (!test_bit(node, mle->maybe_map))
  1042. goto next;
  1043. /* if we're already blocked on lock mastery, and the
  1044. * dead node wasn't the expected master, or there is
  1045. * another node in the maybe_map, keep waiting */
  1046. if (blocked) {
  1047. int lowest = find_next_bit(mle->maybe_map,
  1048. O2NM_MAX_NODES, 0);
  1049. /* act like it was never there */
  1050. clear_bit(node, mle->maybe_map);
  1051. if (node != lowest)
  1052. goto next;
  1053. mlog(ML_ERROR, "expected master %u died while "
  1054. "this node was blocked waiting on it!\n",
  1055. node);
  1056. lowest = find_next_bit(mle->maybe_map,
  1057. O2NM_MAX_NODES,
  1058. lowest+1);
  1059. if (lowest < O2NM_MAX_NODES) {
  1060. mlog(0, "still blocked. waiting "
  1061. "on %u now\n", lowest);
  1062. goto next;
  1063. }
  1064. /* mle is an MLE_BLOCK, but there is now
  1065. * nothing left to block on. we need to return
  1066. * all the way back out and try again with
  1067. * an MLE_MASTER. dlm_do_local_recovery_cleanup
  1068. * has already run, so the mle refcount is ok */
  1069. mlog(0, "no longer blocking. we can "
  1070. "try to master this here\n");
  1071. mle->type = DLM_MLE_MASTER;
  1072. memset(mle->maybe_map, 0,
  1073. sizeof(mle->maybe_map));
  1074. memset(mle->response_map, 0,
  1075. sizeof(mle->maybe_map));
  1076. memcpy(mle->vote_map, mle->node_map,
  1077. sizeof(mle->node_map));
  1078. mle->u.res = res;
  1079. set_bit(dlm->node_num, mle->maybe_map);
  1080. ret = -EAGAIN;
  1081. goto next;
  1082. }
  1083. clear_bit(node, mle->maybe_map);
  1084. if (node > dlm->node_num)
  1085. goto next;
  1086. mlog(0, "dead node in map!\n");
  1087. /* yuck. go back and re-contact all nodes
  1088. * in the vote_map, removing this node. */
  1089. memset(mle->response_map, 0,
  1090. sizeof(mle->response_map));
  1091. }
  1092. ret = -EAGAIN;
  1093. next:
  1094. node = dlm_bitmap_diff_iter_next(&bdi, &sc);
  1095. }
  1096. return ret;
  1097. }
  1098. /*
  1099. * DLM_MASTER_REQUEST_MSG
  1100. *
  1101. * returns: 0 on success,
  1102. * -errno on a network error
  1103. *
  1104. * on error, the caller should assume the target node is "dead"
  1105. *
  1106. */
  1107. static int dlm_do_master_request(struct dlm_master_list_entry *mle, int to)
  1108. {
  1109. struct dlm_ctxt *dlm = mle->dlm;
  1110. struct dlm_master_request request;
  1111. int ret, response=0, resend;
  1112. memset(&request, 0, sizeof(request));
  1113. request.node_idx = dlm->node_num;
  1114. BUG_ON(mle->type == DLM_MLE_MIGRATION);
  1115. if (mle->type != DLM_MLE_MASTER) {
  1116. request.namelen = mle->u.name.len;
  1117. memcpy(request.name, mle->u.name.name, request.namelen);
  1118. } else {
  1119. request.namelen = mle->u.res->lockname.len;
  1120. memcpy(request.name, mle->u.res->lockname.name,
  1121. request.namelen);
  1122. }
  1123. again:
  1124. ret = o2net_send_message(DLM_MASTER_REQUEST_MSG, dlm->key, &request,
  1125. sizeof(request), to, &response);
  1126. if (ret < 0) {
  1127. if (ret == -ESRCH) {
  1128. /* should never happen */
  1129. mlog(ML_ERROR, "TCP stack not ready!\n");
  1130. BUG();
  1131. } else if (ret == -EINVAL) {
  1132. mlog(ML_ERROR, "bad args passed to o2net!\n");
  1133. BUG();
  1134. } else if (ret == -ENOMEM) {
  1135. mlog(ML_ERROR, "out of memory while trying to send "
  1136. "network message! retrying\n");
  1137. /* this is totally crude */
  1138. msleep(50);
  1139. goto again;
  1140. } else if (!dlm_is_host_down(ret)) {
  1141. /* not a network error. bad. */
  1142. mlog_errno(ret);
  1143. mlog(ML_ERROR, "unhandled error!");
  1144. BUG();
  1145. }
  1146. /* all other errors should be network errors,
  1147. * and likely indicate node death */
  1148. mlog(ML_ERROR, "link to %d went down!\n", to);
  1149. goto out;
  1150. }
  1151. ret = 0;
  1152. resend = 0;
  1153. spin_lock(&mle->spinlock);
  1154. switch (response) {
  1155. case DLM_MASTER_RESP_YES:
  1156. set_bit(to, mle->response_map);
  1157. mlog(0, "node %u is the master, response=YES\n", to);
  1158. mle->master = to;
  1159. break;
  1160. case DLM_MASTER_RESP_NO:
  1161. mlog(0, "node %u not master, response=NO\n", to);
  1162. set_bit(to, mle->response_map);
  1163. break;
  1164. case DLM_MASTER_RESP_MAYBE:
  1165. mlog(0, "node %u not master, response=MAYBE\n", to);
  1166. set_bit(to, mle->response_map);
  1167. set_bit(to, mle->maybe_map);
  1168. break;
  1169. case DLM_MASTER_RESP_ERROR:
  1170. mlog(0, "node %u hit an error, resending\n", to);
  1171. resend = 1;
  1172. response = 0;
  1173. break;
  1174. default:
  1175. mlog(ML_ERROR, "bad response! %u\n", response);
  1176. BUG();
  1177. }
  1178. spin_unlock(&mle->spinlock);
  1179. if (resend) {
  1180. /* this is also totally crude */
  1181. msleep(50);
  1182. goto again;
  1183. }
  1184. out:
  1185. return ret;
  1186. }
  1187. /*
  1188. * locks that can be taken here:
  1189. * dlm->spinlock
  1190. * res->spinlock
  1191. * mle->spinlock
  1192. * dlm->master_list
  1193. *
  1194. * if possible, TRIM THIS DOWN!!!
  1195. */
  1196. int dlm_master_request_handler(struct o2net_msg *msg, u32 len, void *data)
  1197. {
  1198. u8 response = DLM_MASTER_RESP_MAYBE;
  1199. struct dlm_ctxt *dlm = data;
  1200. struct dlm_lock_resource *res = NULL;
  1201. struct dlm_master_request *request = (struct dlm_master_request *) msg->buf;
  1202. struct dlm_master_list_entry *mle = NULL, *tmpmle = NULL;
  1203. char *name;
  1204. unsigned int namelen, hash;
  1205. int found, ret;
  1206. int set_maybe;
  1207. int dispatch_assert = 0;
  1208. if (!dlm_grab(dlm))
  1209. return DLM_MASTER_RESP_NO;
  1210. if (!dlm_domain_fully_joined(dlm)) {
  1211. response = DLM_MASTER_RESP_NO;
  1212. goto send_response;
  1213. }
  1214. name = request->name;
  1215. namelen = request->namelen;
  1216. hash = dlm_lockid_hash(name, namelen);
  1217. if (namelen > DLM_LOCKID_NAME_MAX) {
  1218. response = DLM_IVBUFLEN;
  1219. goto send_response;
  1220. }
  1221. way_up_top:
  1222. spin_lock(&dlm->spinlock);
  1223. res = __dlm_lookup_lockres(dlm, name, namelen, hash);
  1224. if (res) {
  1225. spin_unlock(&dlm->spinlock);
  1226. /* take care of the easy cases up front */
  1227. spin_lock(&res->spinlock);
  1228. if (res->state & DLM_LOCK_RES_RECOVERING) {
  1229. spin_unlock(&res->spinlock);
  1230. mlog(0, "returning DLM_MASTER_RESP_ERROR since res is "
  1231. "being recovered\n");
  1232. response = DLM_MASTER_RESP_ERROR;
  1233. if (mle)
  1234. kmem_cache_free(dlm_mle_cache, mle);
  1235. goto send_response;
  1236. }
  1237. if (res->owner == dlm->node_num) {
  1238. spin_unlock(&res->spinlock);
  1239. // mlog(0, "this node is the master\n");
  1240. response = DLM_MASTER_RESP_YES;
  1241. if (mle)
  1242. kmem_cache_free(dlm_mle_cache, mle);
  1243. /* this node is the owner.
  1244. * there is some extra work that needs to
  1245. * happen now. the requesting node has
  1246. * caused all nodes up to this one to
  1247. * create mles. this node now needs to
  1248. * go back and clean those up. */
  1249. dispatch_assert = 1;
  1250. goto send_response;
  1251. } else if (res->owner != DLM_LOCK_RES_OWNER_UNKNOWN) {
  1252. spin_unlock(&res->spinlock);
  1253. // mlog(0, "node %u is the master\n", res->owner);
  1254. response = DLM_MASTER_RESP_NO;
  1255. if (mle)
  1256. kmem_cache_free(dlm_mle_cache, mle);
  1257. goto send_response;
  1258. }
  1259. /* ok, there is no owner. either this node is
  1260. * being blocked, or it is actively trying to
  1261. * master this lock. */
  1262. if (!(res->state & DLM_LOCK_RES_IN_PROGRESS)) {
  1263. mlog(ML_ERROR, "lock with no owner should be "
  1264. "in-progress!\n");
  1265. BUG();
  1266. }
  1267. // mlog(0, "lockres is in progress...\n");
  1268. spin_lock(&dlm->master_lock);
  1269. found = dlm_find_mle(dlm, &tmpmle, name, namelen);
  1270. if (!found) {
  1271. mlog(ML_ERROR, "no mle found for this lock!\n");
  1272. BUG();
  1273. }
  1274. set_maybe = 1;
  1275. spin_lock(&tmpmle->spinlock);
  1276. if (tmpmle->type == DLM_MLE_BLOCK) {
  1277. // mlog(0, "this node is waiting for "
  1278. // "lockres to be mastered\n");
  1279. response = DLM_MASTER_RESP_NO;
  1280. } else if (tmpmle->type == DLM_MLE_MIGRATION) {
  1281. mlog(0, "node %u is master, but trying to migrate to "
  1282. "node %u.\n", tmpmle->master, tmpmle->new_master);
  1283. if (tmpmle->master == dlm->node_num) {
  1284. response = DLM_MASTER_RESP_YES;
  1285. mlog(ML_ERROR, "no owner on lockres, but this "
  1286. "node is trying to migrate it to %u?!\n",
  1287. tmpmle->new_master);
  1288. BUG();
  1289. } else {
  1290. /* the real master can respond on its own */
  1291. response = DLM_MASTER_RESP_NO;
  1292. }
  1293. } else if (tmpmle->master != DLM_LOCK_RES_OWNER_UNKNOWN) {
  1294. set_maybe = 0;
  1295. if (tmpmle->master == dlm->node_num) {
  1296. response = DLM_MASTER_RESP_YES;
  1297. /* this node will be the owner.
  1298. * go back and clean the mles on any
  1299. * other nodes */
  1300. dispatch_assert = 1;
  1301. } else
  1302. response = DLM_MASTER_RESP_NO;
  1303. } else {
  1304. // mlog(0, "this node is attempting to "
  1305. // "master lockres\n");
  1306. response = DLM_MASTER_RESP_MAYBE;
  1307. }
  1308. if (set_maybe)
  1309. set_bit(request->node_idx, tmpmle->maybe_map);
  1310. spin_unlock(&tmpmle->spinlock);
  1311. spin_unlock(&dlm->master_lock);
  1312. spin_unlock(&res->spinlock);
  1313. /* keep the mle attached to heartbeat events */
  1314. dlm_put_mle(tmpmle);
  1315. if (mle)
  1316. kmem_cache_free(dlm_mle_cache, mle);
  1317. goto send_response;
  1318. }
  1319. /*
  1320. * lockres doesn't exist on this node
  1321. * if there is an MLE_BLOCK, return NO
  1322. * if there is an MLE_MASTER, return MAYBE
  1323. * otherwise, add an MLE_BLOCK, return NO
  1324. */
  1325. spin_lock(&dlm->master_lock);
  1326. found = dlm_find_mle(dlm, &tmpmle, name, namelen);
  1327. if (!found) {
  1328. /* this lockid has never been seen on this node yet */
  1329. // mlog(0, "no mle found\n");
  1330. if (!mle) {
  1331. spin_unlock(&dlm->master_lock);
  1332. spin_unlock(&dlm->spinlock);
  1333. mle = (struct dlm_master_list_entry *)
  1334. kmem_cache_alloc(dlm_mle_cache, GFP_KERNEL);
  1335. if (!mle) {
  1336. response = DLM_MASTER_RESP_ERROR;
  1337. mlog_errno(-ENOMEM);
  1338. goto send_response;
  1339. }
  1340. goto way_up_top;
  1341. }
  1342. // mlog(0, "this is second time thru, already allocated, "
  1343. // "add the block.\n");
  1344. dlm_init_mle(mle, DLM_MLE_BLOCK, dlm, NULL, name, namelen);
  1345. set_bit(request->node_idx, mle->maybe_map);
  1346. list_add(&mle->list, &dlm->master_list);
  1347. response = DLM_MASTER_RESP_NO;
  1348. } else {
  1349. // mlog(0, "mle was found\n");
  1350. set_maybe = 1;
  1351. spin_lock(&tmpmle->spinlock);
  1352. if (tmpmle->master == dlm->node_num) {
  1353. mlog(ML_ERROR, "no lockres, but an mle with this node as master!\n");
  1354. BUG();
  1355. }
  1356. if (tmpmle->type == DLM_MLE_BLOCK)
  1357. response = DLM_MASTER_RESP_NO;
  1358. else if (tmpmle->type == DLM_MLE_MIGRATION) {
  1359. mlog(0, "migration mle was found (%u->%u)\n",
  1360. tmpmle->master, tmpmle->new_master);
  1361. /* real master can respond on its own */
  1362. response = DLM_MASTER_RESP_NO;
  1363. } else
  1364. response = DLM_MASTER_RESP_MAYBE;
  1365. if (set_maybe)
  1366. set_bit(request->node_idx, tmpmle->maybe_map);
  1367. spin_unlock(&tmpmle->spinlock);
  1368. }
  1369. spin_unlock(&dlm->master_lock);
  1370. spin_unlock(&dlm->spinlock);
  1371. if (found) {
  1372. /* keep the mle attached to heartbeat events */
  1373. dlm_put_mle(tmpmle);
  1374. }
  1375. send_response:
  1376. if (dispatch_assert) {
  1377. if (response != DLM_MASTER_RESP_YES)
  1378. mlog(ML_ERROR, "invalid response %d\n", response);
  1379. if (!res) {
  1380. mlog(ML_ERROR, "bad lockres while trying to assert!\n");
  1381. BUG();
  1382. }
  1383. mlog(0, "%u is the owner of %.*s, cleaning everyone else\n",
  1384. dlm->node_num, res->lockname.len, res->lockname.name);
  1385. ret = dlm_dispatch_assert_master(dlm, res, 0, request->node_idx,
  1386. DLM_ASSERT_MASTER_MLE_CLEANUP);
  1387. if (ret < 0) {
  1388. mlog(ML_ERROR, "failed to dispatch assert master work\n");
  1389. response = DLM_MASTER_RESP_ERROR;
  1390. }
  1391. }
  1392. dlm_put(dlm);
  1393. return response;
  1394. }
  1395. /*
  1396. * DLM_ASSERT_MASTER_MSG
  1397. */
  1398. /*
  1399. * NOTE: this can be used for debugging
  1400. * can periodically run all locks owned by this node
  1401. * and re-assert across the cluster...
  1402. */
  1403. static int dlm_do_assert_master(struct dlm_ctxt *dlm, const char *lockname,
  1404. unsigned int namelen, void *nodemap,
  1405. u32 flags)
  1406. {
  1407. struct dlm_assert_master assert;
  1408. int to, tmpret;
  1409. struct dlm_node_iter iter;
  1410. int ret = 0;
  1411. int reassert;
  1412. BUG_ON(namelen > O2NM_MAX_NAME_LEN);
  1413. again:
  1414. reassert = 0;
  1415. /* note that if this nodemap is empty, it returns 0 */
  1416. dlm_node_iter_init(nodemap, &iter);
  1417. while ((to = dlm_node_iter_next(&iter)) >= 0) {
  1418. int r = 0;
  1419. mlog(0, "sending assert master to %d (%.*s)\n", to,
  1420. namelen, lockname);
  1421. memset(&assert, 0, sizeof(assert));
  1422. assert.node_idx = dlm->node_num;
  1423. assert.namelen = namelen;
  1424. memcpy(assert.name, lockname, namelen);
  1425. assert.flags = cpu_to_be32(flags);
  1426. tmpret = o2net_send_message(DLM_ASSERT_MASTER_MSG, dlm->key,
  1427. &assert, sizeof(assert), to, &r);
  1428. if (tmpret < 0) {
  1429. mlog(ML_ERROR, "assert_master returned %d!\n", tmpret);
  1430. if (!dlm_is_host_down(tmpret)) {
  1431. mlog(ML_ERROR, "unhandled error!\n");
  1432. BUG();
  1433. }
  1434. /* a node died. finish out the rest of the nodes. */
  1435. mlog(ML_ERROR, "link to %d went down!\n", to);
  1436. /* any nonzero status return will do */
  1437. ret = tmpret;
  1438. } else if (r < 0) {
  1439. /* ok, something horribly messed. kill thyself. */
  1440. mlog(ML_ERROR,"during assert master of %.*s to %u, "
  1441. "got %d.\n", namelen, lockname, to, r);
  1442. dlm_dump_lock_resources(dlm);
  1443. BUG();
  1444. } else if (r == EAGAIN) {
  1445. mlog(0, "%.*s: node %u create mles on other "
  1446. "nodes and requests a re-assert\n",
  1447. namelen, lockname, to);
  1448. reassert = 1;
  1449. }
  1450. }
  1451. if (reassert)
  1452. goto again;
  1453. return ret;
  1454. }
  1455. /*
  1456. * locks that can be taken here:
  1457. * dlm->spinlock
  1458. * res->spinlock
  1459. * mle->spinlock
  1460. * dlm->master_list
  1461. *
  1462. * if possible, TRIM THIS DOWN!!!
  1463. */
  1464. int dlm_assert_master_handler(struct o2net_msg *msg, u32 len, void *data)
  1465. {
  1466. struct dlm_ctxt *dlm = data;
  1467. struct dlm_master_list_entry *mle = NULL;
  1468. struct dlm_assert_master *assert = (struct dlm_assert_master *)msg->buf;
  1469. struct dlm_lock_resource *res = NULL;
  1470. char *name;
  1471. unsigned int namelen, hash;
  1472. u32 flags;
  1473. int master_request = 0;
  1474. int ret = 0;
  1475. if (!dlm_grab(dlm))
  1476. return 0;
  1477. name = assert->name;
  1478. namelen = assert->namelen;
  1479. hash = dlm_lockid_hash(name, namelen);
  1480. flags = be32_to_cpu(assert->flags);
  1481. if (namelen > DLM_LOCKID_NAME_MAX) {
  1482. mlog(ML_ERROR, "Invalid name length!");
  1483. goto done;
  1484. }
  1485. spin_lock(&dlm->spinlock);
  1486. if (flags)
  1487. mlog(0, "assert_master with flags: %u\n", flags);
  1488. /* find the MLE */
  1489. spin_lock(&dlm->master_lock);
  1490. if (!dlm_find_mle(dlm, &mle, name, namelen)) {
  1491. /* not an error, could be master just re-asserting */
  1492. mlog(0, "just got an assert_master from %u, but no "
  1493. "MLE for it! (%.*s)\n", assert->node_idx,
  1494. namelen, name);
  1495. } else {
  1496. int bit = find_next_bit (mle->maybe_map, O2NM_MAX_NODES, 0);
  1497. if (bit >= O2NM_MAX_NODES) {
  1498. /* not necessarily an error, though less likely.
  1499. * could be master just re-asserting. */
  1500. mlog(0, "no bits set in the maybe_map, but %u "
  1501. "is asserting! (%.*s)\n", assert->node_idx,
  1502. namelen, name);
  1503. } else if (bit != assert->node_idx) {
  1504. if (flags & DLM_ASSERT_MASTER_MLE_CLEANUP) {
  1505. mlog(0, "master %u was found, %u should "
  1506. "back off\n", assert->node_idx, bit);
  1507. } else {
  1508. /* with the fix for bug 569, a higher node
  1509. * number winning the mastery will respond
  1510. * YES to mastery requests, but this node
  1511. * had no way of knowing. let it pass. */
  1512. mlog(0, "%u is the lowest node, "
  1513. "%u is asserting. (%.*s) %u must "
  1514. "have begun after %u won.\n", bit,
  1515. assert->node_idx, namelen, name, bit,
  1516. assert->node_idx);
  1517. }
  1518. }
  1519. if (mle->type == DLM_MLE_MIGRATION) {
  1520. if (flags & DLM_ASSERT_MASTER_MLE_CLEANUP) {
  1521. mlog(0, "%s:%.*s: got cleanup assert"
  1522. " from %u for migration\n",
  1523. dlm->name, namelen, name,
  1524. assert->node_idx);
  1525. } else if (!(flags & DLM_ASSERT_MASTER_FINISH_MIGRATION)) {
  1526. mlog(0, "%s:%.*s: got unrelated assert"
  1527. " from %u for migration, ignoring\n",
  1528. dlm->name, namelen, name,
  1529. assert->node_idx);
  1530. __dlm_put_mle(mle);
  1531. spin_unlock(&dlm->master_lock);
  1532. spin_unlock(&dlm->spinlock);
  1533. goto done;
  1534. }
  1535. }
  1536. }
  1537. spin_unlock(&dlm->master_lock);
  1538. /* ok everything checks out with the MLE
  1539. * now check to see if there is a lockres */
  1540. res = __dlm_lookup_lockres(dlm, name, namelen, hash);
  1541. if (res) {
  1542. spin_lock(&res->spinlock);
  1543. if (res->state & DLM_LOCK_RES_RECOVERING) {
  1544. mlog(ML_ERROR, "%u asserting but %.*s is "
  1545. "RECOVERING!\n", assert->node_idx, namelen, name);
  1546. goto kill;
  1547. }
  1548. if (!mle) {
  1549. if (res->owner != DLM_LOCK_RES_OWNER_UNKNOWN &&
  1550. res->owner != assert->node_idx) {
  1551. mlog(ML_ERROR, "assert_master from "
  1552. "%u, but current owner is "
  1553. "%u! (%.*s)\n",
  1554. assert->node_idx, res->owner,
  1555. namelen, name);
  1556. goto kill;
  1557. }
  1558. } else if (mle->type != DLM_MLE_MIGRATION) {
  1559. if (res->owner != DLM_LOCK_RES_OWNER_UNKNOWN) {
  1560. /* owner is just re-asserting */
  1561. if (res->owner == assert->node_idx) {
  1562. mlog(0, "owner %u re-asserting on "
  1563. "lock %.*s\n", assert->node_idx,
  1564. namelen, name);
  1565. goto ok;
  1566. }
  1567. mlog(ML_ERROR, "got assert_master from "
  1568. "node %u, but %u is the owner! "
  1569. "(%.*s)\n", assert->node_idx,
  1570. res->owner, namelen, name);
  1571. goto kill;
  1572. }
  1573. if (!(res->state & DLM_LOCK_RES_IN_PROGRESS)) {
  1574. mlog(ML_ERROR, "got assert from %u, but lock "
  1575. "with no owner should be "
  1576. "in-progress! (%.*s)\n",
  1577. assert->node_idx,
  1578. namelen, name);
  1579. goto kill;
  1580. }
  1581. } else /* mle->type == DLM_MLE_MIGRATION */ {
  1582. /* should only be getting an assert from new master */
  1583. if (assert->node_idx != mle->new_master) {
  1584. mlog(ML_ERROR, "got assert from %u, but "
  1585. "new master is %u, and old master "
  1586. "was %u (%.*s)\n",
  1587. assert->node_idx, mle->new_master,
  1588. mle->master, namelen, name);
  1589. goto kill;
  1590. }
  1591. }
  1592. ok:
  1593. spin_unlock(&res->spinlock);
  1594. }
  1595. spin_unlock(&dlm->spinlock);
  1596. // mlog(0, "woo! got an assert_master from node %u!\n",
  1597. // assert->node_idx);
  1598. if (mle) {
  1599. int extra_ref = 0;
  1600. int nn = -1;
  1601. int rr, err = 0;
  1602. spin_lock(&mle->spinlock);
  1603. if (mle->type == DLM_MLE_BLOCK || mle->type == DLM_MLE_MIGRATION)
  1604. extra_ref = 1;
  1605. else {
  1606. /* MASTER mle: if any bits set in the response map
  1607. * then the calling node needs to re-assert to clear
  1608. * up nodes that this node contacted */
  1609. while ((nn = find_next_bit (mle->response_map, O2NM_MAX_NODES,
  1610. nn+1)) < O2NM_MAX_NODES) {
  1611. if (nn != dlm->node_num && nn != assert->node_idx)
  1612. master_request = 1;
  1613. }
  1614. }
  1615. mle->master = assert->node_idx;
  1616. atomic_set(&mle->woken, 1);
  1617. wake_up(&mle->wq);
  1618. spin_unlock(&mle->spinlock);
  1619. if (res) {
  1620. spin_lock(&res->spinlock);
  1621. if (mle->type == DLM_MLE_MIGRATION) {
  1622. mlog(0, "finishing off migration of lockres %.*s, "
  1623. "from %u to %u\n",
  1624. res->lockname.len, res->lockname.name,
  1625. dlm->node_num, mle->new_master);
  1626. res->state &= ~DLM_LOCK_RES_MIGRATING;
  1627. dlm_change_lockres_owner(dlm, res, mle->new_master);
  1628. BUG_ON(res->state & DLM_LOCK_RES_DIRTY);
  1629. } else {
  1630. dlm_change_lockres_owner(dlm, res, mle->master);
  1631. }
  1632. spin_unlock(&res->spinlock);
  1633. }
  1634. /* master is known, detach if not already detached.
  1635. * ensures that only one assert_master call will happen
  1636. * on this mle. */
  1637. spin_lock(&dlm->spinlock);
  1638. spin_lock(&dlm->master_lock);
  1639. rr = atomic_read(&mle->mle_refs.refcount);
  1640. if (mle->inuse > 0) {
  1641. if (extra_ref && rr < 3)
  1642. err = 1;
  1643. else if (!extra_ref && rr < 2)
  1644. err = 1;
  1645. } else {
  1646. if (extra_ref && rr < 2)
  1647. err = 1;
  1648. else if (!extra_ref && rr < 1)
  1649. err = 1;
  1650. }
  1651. if (err) {
  1652. mlog(ML_ERROR, "%s:%.*s: got assert master from %u "
  1653. "that will mess up this node, refs=%d, extra=%d, "
  1654. "inuse=%d\n", dlm->name, namelen, name,
  1655. assert->node_idx, rr, extra_ref, mle->inuse);
  1656. dlm_print_one_mle(mle);
  1657. }
  1658. list_del_init(&mle->list);
  1659. __dlm_mle_detach_hb_events(dlm, mle);
  1660. __dlm_put_mle(mle);
  1661. if (extra_ref) {
  1662. /* the assert master message now balances the extra
  1663. * ref given by the master / migration request message.
  1664. * if this is the last put, it will be removed
  1665. * from the list. */
  1666. __dlm_put_mle(mle);
  1667. }
  1668. spin_unlock(&dlm->master_lock);
  1669. spin_unlock(&dlm->spinlock);
  1670. } else if (res) {
  1671. if (res->owner != assert->node_idx) {
  1672. mlog(0, "assert_master from %u, but current "
  1673. "owner is %u (%.*s), no mle\n", assert->node_idx,
  1674. res->owner, namelen, name);
  1675. }
  1676. }
  1677. done:
  1678. ret = 0;
  1679. if (res)
  1680. dlm_lockres_put(res);
  1681. dlm_put(dlm);
  1682. if (master_request) {
  1683. mlog(0, "need to tell master to reassert\n");
  1684. ret = EAGAIN; // positive. negative would shoot down the node.
  1685. }
  1686. return ret;
  1687. kill:
  1688. /* kill the caller! */
  1689. spin_unlock(&res->spinlock);
  1690. spin_unlock(&dlm->spinlock);
  1691. dlm_lockres_put(res);
  1692. mlog(ML_ERROR, "Bad message received from another node. Dumping state "
  1693. "and killing the other node now! This node is OK and can continue.\n");
  1694. dlm_dump_lock_resources(dlm);
  1695. dlm_put(dlm);
  1696. return -EINVAL;
  1697. }
  1698. int dlm_dispatch_assert_master(struct dlm_ctxt *dlm,
  1699. struct dlm_lock_resource *res,
  1700. int ignore_higher, u8 request_from, u32 flags)
  1701. {
  1702. struct dlm_work_item *item;
  1703. item = kcalloc(1, sizeof(*item), GFP_KERNEL);
  1704. if (!item)
  1705. return -ENOMEM;
  1706. /* queue up work for dlm_assert_master_worker */
  1707. dlm_grab(dlm); /* get an extra ref for the work item */
  1708. dlm_init_work_item(dlm, item, dlm_assert_master_worker, NULL);
  1709. item->u.am.lockres = res; /* already have a ref */
  1710. /* can optionally ignore node numbers higher than this node */
  1711. item->u.am.ignore_higher = ignore_higher;
  1712. item->u.am.request_from = request_from;
  1713. item->u.am.flags = flags;
  1714. if (ignore_higher)
  1715. mlog(0, "IGNORE HIGHER: %.*s\n", res->lockname.len,
  1716. res->lockname.name);
  1717. spin_lock(&dlm->work_lock);
  1718. list_add_tail(&item->list, &dlm->work_list);
  1719. spin_unlock(&dlm->work_lock);
  1720. schedule_work(&dlm->dispatched_work);
  1721. return 0;
  1722. }
  1723. static void dlm_assert_master_worker(struct dlm_work_item *item, void *data)
  1724. {
  1725. struct dlm_ctxt *dlm = data;
  1726. int ret = 0;
  1727. struct dlm_lock_resource *res;
  1728. unsigned long nodemap[BITS_TO_LONGS(O2NM_MAX_NODES)];
  1729. int ignore_higher;
  1730. int bit;
  1731. u8 request_from;
  1732. u32 flags;
  1733. dlm = item->dlm;
  1734. res = item->u.am.lockres;
  1735. ignore_higher = item->u.am.ignore_higher;
  1736. request_from = item->u.am.request_from;
  1737. flags = item->u.am.flags;
  1738. spin_lock(&dlm->spinlock);
  1739. memcpy(nodemap, dlm->domain_map, sizeof(nodemap));
  1740. spin_unlock(&dlm->spinlock);
  1741. clear_bit(dlm->node_num, nodemap);
  1742. if (ignore_higher) {
  1743. /* if is this just to clear up mles for nodes below
  1744. * this node, do not send the message to the original
  1745. * caller or any node number higher than this */
  1746. clear_bit(request_from, nodemap);
  1747. bit = dlm->node_num;
  1748. while (1) {
  1749. bit = find_next_bit(nodemap, O2NM_MAX_NODES,
  1750. bit+1);
  1751. if (bit >= O2NM_MAX_NODES)
  1752. break;
  1753. clear_bit(bit, nodemap);
  1754. }
  1755. }
  1756. /* this call now finishes out the nodemap
  1757. * even if one or more nodes die */
  1758. mlog(0, "worker about to master %.*s here, this=%u\n",
  1759. res->lockname.len, res->lockname.name, dlm->node_num);
  1760. ret = dlm_do_assert_master(dlm, res->lockname.name,
  1761. res->lockname.len,
  1762. nodemap, flags);
  1763. if (ret < 0) {
  1764. /* no need to restart, we are done */
  1765. mlog_errno(ret);
  1766. }
  1767. dlm_lockres_put(res);
  1768. mlog(0, "finished with dlm_assert_master_worker\n");
  1769. }
  1770. /* SPECIAL CASE for the $RECOVERY lock used by the recovery thread.
  1771. * We cannot wait for node recovery to complete to begin mastering this
  1772. * lockres because this lockres is used to kick off recovery! ;-)
  1773. * So, do a pre-check on all living nodes to see if any of those nodes
  1774. * think that $RECOVERY is currently mastered by a dead node. If so,
  1775. * we wait a short time to allow that node to get notified by its own
  1776. * heartbeat stack, then check again. All $RECOVERY lock resources
  1777. * mastered by dead nodes are purged when the hearbeat callback is
  1778. * fired, so we can know for sure that it is safe to continue once
  1779. * the node returns a live node or no node. */
  1780. static int dlm_pre_master_reco_lockres(struct dlm_ctxt *dlm,
  1781. struct dlm_lock_resource *res)
  1782. {
  1783. struct dlm_node_iter iter;
  1784. int nodenum;
  1785. int ret = 0;
  1786. u8 master = DLM_LOCK_RES_OWNER_UNKNOWN;
  1787. spin_lock(&dlm->spinlock);
  1788. dlm_node_iter_init(dlm->domain_map, &iter);
  1789. spin_unlock(&dlm->spinlock);
  1790. while ((nodenum = dlm_node_iter_next(&iter)) >= 0) {
  1791. /* do not send to self */
  1792. if (nodenum == dlm->node_num)
  1793. continue;
  1794. ret = dlm_do_master_requery(dlm, res, nodenum, &master);
  1795. if (ret < 0) {
  1796. mlog_errno(ret);
  1797. if (!dlm_is_host_down(ret))
  1798. BUG();
  1799. /* host is down, so answer for that node would be
  1800. * DLM_LOCK_RES_OWNER_UNKNOWN. continue. */
  1801. }
  1802. if (master != DLM_LOCK_RES_OWNER_UNKNOWN) {
  1803. /* check to see if this master is in the recovery map */
  1804. spin_lock(&dlm->spinlock);
  1805. if (test_bit(master, dlm->recovery_map)) {
  1806. mlog(ML_NOTICE, "%s: node %u has not seen "
  1807. "node %u go down yet, and thinks the "
  1808. "dead node is mastering the recovery "
  1809. "lock. must wait.\n", dlm->name,
  1810. nodenum, master);
  1811. ret = -EAGAIN;
  1812. }
  1813. spin_unlock(&dlm->spinlock);
  1814. mlog(0, "%s: reco lock master is %u\n", dlm->name,
  1815. master);
  1816. break;
  1817. }
  1818. }
  1819. return ret;
  1820. }
  1821. /*
  1822. * DLM_MIGRATE_LOCKRES
  1823. */
  1824. int dlm_migrate_lockres(struct dlm_ctxt *dlm, struct dlm_lock_resource *res,
  1825. u8 target)
  1826. {
  1827. struct dlm_master_list_entry *mle = NULL;
  1828. struct dlm_master_list_entry *oldmle = NULL;
  1829. struct dlm_migratable_lockres *mres = NULL;
  1830. int ret = -EINVAL;
  1831. const char *name;
  1832. unsigned int namelen;
  1833. int mle_added = 0;
  1834. struct list_head *queue, *iter;
  1835. int i;
  1836. struct dlm_lock *lock;
  1837. int empty = 1;
  1838. if (!dlm_grab(dlm))
  1839. return -EINVAL;
  1840. name = res->lockname.name;
  1841. namelen = res->lockname.len;
  1842. mlog(0, "migrating %.*s to %u\n", namelen, name, target);
  1843. /*
  1844. * ensure this lockres is a proper candidate for migration
  1845. */
  1846. spin_lock(&res->spinlock);
  1847. if (res->owner == DLM_LOCK_RES_OWNER_UNKNOWN) {
  1848. mlog(0, "cannot migrate lockres with unknown owner!\n");
  1849. spin_unlock(&res->spinlock);
  1850. goto leave;
  1851. }
  1852. if (res->owner != dlm->node_num) {
  1853. mlog(0, "cannot migrate lockres this node doesn't own!\n");
  1854. spin_unlock(&res->spinlock);
  1855. goto leave;
  1856. }
  1857. mlog(0, "checking queues...\n");
  1858. queue = &res->granted;
  1859. for (i=0; i<3; i++) {
  1860. list_for_each(iter, queue) {
  1861. lock = list_entry (iter, struct dlm_lock, list);
  1862. empty = 0;
  1863. if (lock->ml.node == dlm->node_num) {
  1864. mlog(0, "found a lock owned by this node "
  1865. "still on the %s queue! will not "
  1866. "migrate this lockres\n",
  1867. i==0 ? "granted" :
  1868. (i==1 ? "converting" : "blocked"));
  1869. spin_unlock(&res->spinlock);
  1870. ret = -ENOTEMPTY;
  1871. goto leave;
  1872. }
  1873. }
  1874. queue++;
  1875. }
  1876. mlog(0, "all locks on this lockres are nonlocal. continuing\n");
  1877. spin_unlock(&res->spinlock);
  1878. /* no work to do */
  1879. if (empty) {
  1880. mlog(0, "no locks were found on this lockres! done!\n");
  1881. ret = 0;
  1882. goto leave;
  1883. }
  1884. /*
  1885. * preallocate up front
  1886. * if this fails, abort
  1887. */
  1888. ret = -ENOMEM;
  1889. mres = (struct dlm_migratable_lockres *) __get_free_page(GFP_KERNEL);
  1890. if (!mres) {
  1891. mlog_errno(ret);
  1892. goto leave;
  1893. }
  1894. mle = (struct dlm_master_list_entry *) kmem_cache_alloc(dlm_mle_cache,
  1895. GFP_KERNEL);
  1896. if (!mle) {
  1897. mlog_errno(ret);
  1898. goto leave;
  1899. }
  1900. ret = 0;
  1901. /*
  1902. * find a node to migrate the lockres to
  1903. */
  1904. mlog(0, "picking a migration node\n");
  1905. spin_lock(&dlm->spinlock);
  1906. /* pick a new node */
  1907. if (!test_bit(target, dlm->domain_map) ||
  1908. target >= O2NM_MAX_NODES) {
  1909. target = dlm_pick_migration_target(dlm, res);
  1910. }
  1911. mlog(0, "node %u chosen for migration\n", target);
  1912. if (target >= O2NM_MAX_NODES ||
  1913. !test_bit(target, dlm->domain_map)) {
  1914. /* target chosen is not alive */
  1915. ret = -EINVAL;
  1916. }
  1917. if (ret) {
  1918. spin_unlock(&dlm->spinlock);
  1919. goto fail;
  1920. }
  1921. mlog(0, "continuing with target = %u\n", target);
  1922. /*
  1923. * clear any existing master requests and
  1924. * add the migration mle to the list
  1925. */
  1926. spin_lock(&dlm->master_lock);
  1927. ret = dlm_add_migration_mle(dlm, res, mle, &oldmle, name,
  1928. namelen, target, dlm->node_num);
  1929. spin_unlock(&dlm->master_lock);
  1930. spin_unlock(&dlm->spinlock);
  1931. if (ret == -EEXIST) {
  1932. mlog(0, "another process is already migrating it\n");
  1933. goto fail;
  1934. }
  1935. mle_added = 1;
  1936. /*
  1937. * set the MIGRATING flag and flush asts
  1938. * if we fail after this we need to re-dirty the lockres
  1939. */
  1940. if (dlm_mark_lockres_migrating(dlm, res, target) < 0) {
  1941. mlog(ML_ERROR, "tried to migrate %.*s to %u, but "
  1942. "the target went down.\n", res->lockname.len,
  1943. res->lockname.name, target);
  1944. spin_lock(&res->spinlock);
  1945. res->state &= ~DLM_LOCK_RES_MIGRATING;
  1946. spin_unlock(&res->spinlock);
  1947. ret = -EINVAL;
  1948. }
  1949. fail:
  1950. if (oldmle) {
  1951. /* master is known, detach if not already detached */
  1952. dlm_mle_detach_hb_events(dlm, oldmle);
  1953. dlm_put_mle(oldmle);
  1954. }
  1955. if (ret < 0) {
  1956. if (mle_added) {
  1957. dlm_mle_detach_hb_events(dlm, mle);
  1958. dlm_put_mle(mle);
  1959. } else if (mle) {
  1960. kmem_cache_free(dlm_mle_cache, mle);
  1961. }
  1962. goto leave;
  1963. }
  1964. /*
  1965. * at this point, we have a migration target, an mle
  1966. * in the master list, and the MIGRATING flag set on
  1967. * the lockres
  1968. */
  1969. /* get an extra reference on the mle.
  1970. * otherwise the assert_master from the new
  1971. * master will destroy this.
  1972. * also, make sure that all callers of dlm_get_mle
  1973. * take both dlm->spinlock and dlm->master_lock */
  1974. spin_lock(&dlm->spinlock);
  1975. spin_lock(&dlm->master_lock);
  1976. dlm_get_mle_inuse(mle);
  1977. spin_unlock(&dlm->master_lock);
  1978. spin_unlock(&dlm->spinlock);
  1979. /* notify new node and send all lock state */
  1980. /* call send_one_lockres with migration flag.
  1981. * this serves as notice to the target node that a
  1982. * migration is starting. */
  1983. ret = dlm_send_one_lockres(dlm, res, mres, target,
  1984. DLM_MRES_MIGRATION);
  1985. if (ret < 0) {
  1986. mlog(0, "migration to node %u failed with %d\n",
  1987. target, ret);
  1988. /* migration failed, detach and clean up mle */
  1989. dlm_mle_detach_hb_events(dlm, mle);
  1990. dlm_put_mle(mle);
  1991. dlm_put_mle_inuse(mle);
  1992. spin_lock(&res->spinlock);
  1993. res->state &= ~DLM_LOCK_RES_MIGRATING;
  1994. spin_unlock(&res->spinlock);
  1995. goto leave;
  1996. }
  1997. /* at this point, the target sends a message to all nodes,
  1998. * (using dlm_do_migrate_request). this node is skipped since
  1999. * we had to put an mle in the list to begin the process. this
  2000. * node now waits for target to do an assert master. this node
  2001. * will be the last one notified, ensuring that the migration
  2002. * is complete everywhere. if the target dies while this is
  2003. * going on, some nodes could potentially see the target as the
  2004. * master, so it is important that my recovery finds the migration
  2005. * mle and sets the master to UNKNONWN. */
  2006. /* wait for new node to assert master */
  2007. while (1) {
  2008. ret = wait_event_interruptible_timeout(mle->wq,
  2009. (atomic_read(&mle->woken) == 1),
  2010. msecs_to_jiffies(5000));
  2011. if (ret >= 0) {
  2012. if (atomic_read(&mle->woken) == 1 ||
  2013. res->owner == target)
  2014. break;
  2015. mlog(0, "timed out during migration\n");
  2016. /* avoid hang during shutdown when migrating lockres
  2017. * to a node which also goes down */
  2018. if (dlm_is_node_dead(dlm, target)) {
  2019. mlog(0, "%s:%.*s: expected migration "
  2020. "target %u is no longer up, restarting\n",
  2021. dlm->name, res->lockname.len,
  2022. res->lockname.name, target);
  2023. ret = -ERESTARTSYS;
  2024. }
  2025. }
  2026. if (ret == -ERESTARTSYS) {
  2027. /* migration failed, detach and clean up mle */
  2028. dlm_mle_detach_hb_events(dlm, mle);
  2029. dlm_put_mle(mle);
  2030. dlm_put_mle_inuse(mle);
  2031. spin_lock(&res->spinlock);
  2032. res->state &= ~DLM_LOCK_RES_MIGRATING;
  2033. spin_unlock(&res->spinlock);
  2034. goto leave;
  2035. }
  2036. /* TODO: if node died: stop, clean up, return error */
  2037. }
  2038. /* all done, set the owner, clear the flag */
  2039. spin_lock(&res->spinlock);
  2040. dlm_set_lockres_owner(dlm, res, target);
  2041. res->state &= ~DLM_LOCK_RES_MIGRATING;
  2042. dlm_remove_nonlocal_locks(dlm, res);
  2043. spin_unlock(&res->spinlock);
  2044. wake_up(&res->wq);
  2045. /* master is known, detach if not already detached */
  2046. dlm_mle_detach_hb_events(dlm, mle);
  2047. dlm_put_mle_inuse(mle);
  2048. ret = 0;
  2049. dlm_lockres_calc_usage(dlm, res);
  2050. leave:
  2051. /* re-dirty the lockres if we failed */
  2052. if (ret < 0)
  2053. dlm_kick_thread(dlm, res);
  2054. /* TODO: cleanup */
  2055. if (mres)
  2056. free_page((unsigned long)mres);
  2057. dlm_put(dlm);
  2058. mlog(0, "returning %d\n", ret);
  2059. return ret;
  2060. }
  2061. EXPORT_SYMBOL_GPL(dlm_migrate_lockres);
  2062. int dlm_lock_basts_flushed(struct dlm_ctxt *dlm, struct dlm_lock *lock)
  2063. {
  2064. int ret;
  2065. spin_lock(&dlm->ast_lock);
  2066. spin_lock(&lock->spinlock);
  2067. ret = (list_empty(&lock->bast_list) && !lock->bast_pending);
  2068. spin_unlock(&lock->spinlock);
  2069. spin_unlock(&dlm->ast_lock);
  2070. return ret;
  2071. }
  2072. static int dlm_migration_can_proceed(struct dlm_ctxt *dlm,
  2073. struct dlm_lock_resource *res,
  2074. u8 mig_target)
  2075. {
  2076. int can_proceed;
  2077. spin_lock(&res->spinlock);
  2078. can_proceed = !!(res->state & DLM_LOCK_RES_MIGRATING);
  2079. spin_unlock(&res->spinlock);
  2080. /* target has died, so make the caller break out of the
  2081. * wait_event, but caller must recheck the domain_map */
  2082. spin_lock(&dlm->spinlock);
  2083. if (!test_bit(mig_target, dlm->domain_map))
  2084. can_proceed = 1;
  2085. spin_unlock(&dlm->spinlock);
  2086. return can_proceed;
  2087. }
  2088. int dlm_lockres_is_dirty(struct dlm_ctxt *dlm, struct dlm_lock_resource *res)
  2089. {
  2090. int ret;
  2091. spin_lock(&res->spinlock);
  2092. ret = !!(res->state & DLM_LOCK_RES_DIRTY);
  2093. spin_unlock(&res->spinlock);
  2094. return ret;
  2095. }
  2096. static int dlm_mark_lockres_migrating(struct dlm_ctxt *dlm,
  2097. struct dlm_lock_resource *res,
  2098. u8 target)
  2099. {
  2100. int ret = 0;
  2101. mlog(0, "dlm_mark_lockres_migrating: %.*s, from %u to %u\n",
  2102. res->lockname.len, res->lockname.name, dlm->node_num,
  2103. target);
  2104. /* need to set MIGRATING flag on lockres. this is done by
  2105. * ensuring that all asts have been flushed for this lockres. */
  2106. spin_lock(&res->spinlock);
  2107. BUG_ON(res->migration_pending);
  2108. res->migration_pending = 1;
  2109. /* strategy is to reserve an extra ast then release
  2110. * it below, letting the release do all of the work */
  2111. __dlm_lockres_reserve_ast(res);
  2112. spin_unlock(&res->spinlock);
  2113. /* now flush all the pending asts.. hang out for a bit */
  2114. dlm_kick_thread(dlm, res);
  2115. wait_event(dlm->ast_wq, !dlm_lockres_is_dirty(dlm, res));
  2116. dlm_lockres_release_ast(dlm, res);
  2117. mlog(0, "about to wait on migration_wq, dirty=%s\n",
  2118. res->state & DLM_LOCK_RES_DIRTY ? "yes" : "no");
  2119. /* if the extra ref we just put was the final one, this
  2120. * will pass thru immediately. otherwise, we need to wait
  2121. * for the last ast to finish. */
  2122. again:
  2123. ret = wait_event_interruptible_timeout(dlm->migration_wq,
  2124. dlm_migration_can_proceed(dlm, res, target),
  2125. msecs_to_jiffies(1000));
  2126. if (ret < 0) {
  2127. mlog(0, "woken again: migrating? %s, dead? %s\n",
  2128. res->state & DLM_LOCK_RES_MIGRATING ? "yes":"no",
  2129. test_bit(target, dlm->domain_map) ? "no":"yes");
  2130. } else {
  2131. mlog(0, "all is well: migrating? %s, dead? %s\n",
  2132. res->state & DLM_LOCK_RES_MIGRATING ? "yes":"no",
  2133. test_bit(target, dlm->domain_map) ? "no":"yes");
  2134. }
  2135. if (!dlm_migration_can_proceed(dlm, res, target)) {
  2136. mlog(0, "trying again...\n");
  2137. goto again;
  2138. }
  2139. /* did the target go down or die? */
  2140. spin_lock(&dlm->spinlock);
  2141. if (!test_bit(target, dlm->domain_map)) {
  2142. mlog(ML_ERROR, "aha. migration target %u just went down\n",
  2143. target);
  2144. ret = -EHOSTDOWN;
  2145. }
  2146. spin_unlock(&dlm->spinlock);
  2147. /*
  2148. * at this point:
  2149. *
  2150. * o the DLM_LOCK_RES_MIGRATING flag is set
  2151. * o there are no pending asts on this lockres
  2152. * o all processes trying to reserve an ast on this
  2153. * lockres must wait for the MIGRATING flag to clear
  2154. */
  2155. return ret;
  2156. }
  2157. /* last step in the migration process.
  2158. * original master calls this to free all of the dlm_lock
  2159. * structures that used to be for other nodes. */
  2160. static void dlm_remove_nonlocal_locks(struct dlm_ctxt *dlm,
  2161. struct dlm_lock_resource *res)
  2162. {
  2163. struct list_head *iter, *iter2;
  2164. struct list_head *queue = &res->granted;
  2165. int i;
  2166. struct dlm_lock *lock;
  2167. assert_spin_locked(&res->spinlock);
  2168. BUG_ON(res->owner == dlm->node_num);
  2169. for (i=0; i<3; i++) {
  2170. list_for_each_safe(iter, iter2, queue) {
  2171. lock = list_entry (iter, struct dlm_lock, list);
  2172. if (lock->ml.node != dlm->node_num) {
  2173. mlog(0, "putting lock for node %u\n",
  2174. lock->ml.node);
  2175. /* be extra careful */
  2176. BUG_ON(!list_empty(&lock->ast_list));
  2177. BUG_ON(!list_empty(&lock->bast_list));
  2178. BUG_ON(lock->ast_pending);
  2179. BUG_ON(lock->bast_pending);
  2180. list_del_init(&lock->list);
  2181. dlm_lock_put(lock);
  2182. }
  2183. }
  2184. queue++;
  2185. }
  2186. }
  2187. /* for now this is not too intelligent. we will
  2188. * need stats to make this do the right thing.
  2189. * this just finds the first lock on one of the
  2190. * queues and uses that node as the target. */
  2191. static u8 dlm_pick_migration_target(struct dlm_ctxt *dlm,
  2192. struct dlm_lock_resource *res)
  2193. {
  2194. int i;
  2195. struct list_head *queue = &res->granted;
  2196. struct list_head *iter;
  2197. struct dlm_lock *lock;
  2198. int nodenum;
  2199. assert_spin_locked(&dlm->spinlock);
  2200. spin_lock(&res->spinlock);
  2201. for (i=0; i<3; i++) {
  2202. list_for_each(iter, queue) {
  2203. /* up to the caller to make sure this node
  2204. * is alive */
  2205. lock = list_entry (iter, struct dlm_lock, list);
  2206. if (lock->ml.node != dlm->node_num) {
  2207. spin_unlock(&res->spinlock);
  2208. return lock->ml.node;
  2209. }
  2210. }
  2211. queue++;
  2212. }
  2213. spin_unlock(&res->spinlock);
  2214. mlog(0, "have not found a suitable target yet! checking domain map\n");
  2215. /* ok now we're getting desperate. pick anyone alive. */
  2216. nodenum = -1;
  2217. while (1) {
  2218. nodenum = find_next_bit(dlm->domain_map,
  2219. O2NM_MAX_NODES, nodenum+1);
  2220. mlog(0, "found %d in domain map\n", nodenum);
  2221. if (nodenum >= O2NM_MAX_NODES)
  2222. break;
  2223. if (nodenum != dlm->node_num) {
  2224. mlog(0, "picking %d\n", nodenum);
  2225. return nodenum;
  2226. }
  2227. }
  2228. mlog(0, "giving up. no master to migrate to\n");
  2229. return DLM_LOCK_RES_OWNER_UNKNOWN;
  2230. }
  2231. /* this is called by the new master once all lockres
  2232. * data has been received */
  2233. static int dlm_do_migrate_request(struct dlm_ctxt *dlm,
  2234. struct dlm_lock_resource *res,
  2235. u8 master, u8 new_master,
  2236. struct dlm_node_iter *iter)
  2237. {
  2238. struct dlm_migrate_request migrate;
  2239. int ret, status = 0;
  2240. int nodenum;
  2241. memset(&migrate, 0, sizeof(migrate));
  2242. migrate.namelen = res->lockname.len;
  2243. memcpy(migrate.name, res->lockname.name, migrate.namelen);
  2244. migrate.new_master = new_master;
  2245. migrate.master = master;
  2246. ret = 0;
  2247. /* send message to all nodes, except the master and myself */
  2248. while ((nodenum = dlm_node_iter_next(iter)) >= 0) {
  2249. if (nodenum == master ||
  2250. nodenum == new_master)
  2251. continue;
  2252. ret = o2net_send_message(DLM_MIGRATE_REQUEST_MSG, dlm->key,
  2253. &migrate, sizeof(migrate), nodenum,
  2254. &status);
  2255. if (ret < 0)
  2256. mlog_errno(ret);
  2257. else if (status < 0) {
  2258. mlog(0, "migrate request (node %u) returned %d!\n",
  2259. nodenum, status);
  2260. ret = status;
  2261. }
  2262. }
  2263. if (ret < 0)
  2264. mlog_errno(ret);
  2265. mlog(0, "returning ret=%d\n", ret);
  2266. return ret;
  2267. }
  2268. /* if there is an existing mle for this lockres, we now know who the master is.
  2269. * (the one who sent us *this* message) we can clear it up right away.
  2270. * since the process that put the mle on the list still has a reference to it,
  2271. * we can unhash it now, set the master and wake the process. as a result,
  2272. * we will have no mle in the list to start with. now we can add an mle for
  2273. * the migration and this should be the only one found for those scanning the
  2274. * list. */
  2275. int dlm_migrate_request_handler(struct o2net_msg *msg, u32 len, void *data)
  2276. {
  2277. struct dlm_ctxt *dlm = data;
  2278. struct dlm_lock_resource *res = NULL;
  2279. struct dlm_migrate_request *migrate = (struct dlm_migrate_request *) msg->buf;
  2280. struct dlm_master_list_entry *mle = NULL, *oldmle = NULL;
  2281. const char *name;
  2282. unsigned int namelen, hash;
  2283. int ret = 0;
  2284. if (!dlm_grab(dlm))
  2285. return -EINVAL;
  2286. name = migrate->name;
  2287. namelen = migrate->namelen;
  2288. hash = dlm_lockid_hash(name, namelen);
  2289. /* preallocate.. if this fails, abort */
  2290. mle = (struct dlm_master_list_entry *) kmem_cache_alloc(dlm_mle_cache,
  2291. GFP_KERNEL);
  2292. if (!mle) {
  2293. ret = -ENOMEM;
  2294. goto leave;
  2295. }
  2296. /* check for pre-existing lock */
  2297. spin_lock(&dlm->spinlock);
  2298. res = __dlm_lookup_lockres(dlm, name, namelen, hash);
  2299. spin_lock(&dlm->master_lock);
  2300. if (res) {
  2301. spin_lock(&res->spinlock);
  2302. if (res->state & DLM_LOCK_RES_RECOVERING) {
  2303. /* if all is working ok, this can only mean that we got
  2304. * a migrate request from a node that we now see as
  2305. * dead. what can we do here? drop it to the floor? */
  2306. spin_unlock(&res->spinlock);
  2307. mlog(ML_ERROR, "Got a migrate request, but the "
  2308. "lockres is marked as recovering!");
  2309. kmem_cache_free(dlm_mle_cache, mle);
  2310. ret = -EINVAL; /* need a better solution */
  2311. goto unlock;
  2312. }
  2313. res->state |= DLM_LOCK_RES_MIGRATING;
  2314. spin_unlock(&res->spinlock);
  2315. }
  2316. /* ignore status. only nonzero status would BUG. */
  2317. ret = dlm_add_migration_mle(dlm, res, mle, &oldmle,
  2318. name, namelen,
  2319. migrate->new_master,
  2320. migrate->master);
  2321. unlock:
  2322. spin_unlock(&dlm->master_lock);
  2323. spin_unlock(&dlm->spinlock);
  2324. if (oldmle) {
  2325. /* master is known, detach if not already detached */
  2326. dlm_mle_detach_hb_events(dlm, oldmle);
  2327. dlm_put_mle(oldmle);
  2328. }
  2329. if (res)
  2330. dlm_lockres_put(res);
  2331. leave:
  2332. dlm_put(dlm);
  2333. return ret;
  2334. }
  2335. /* must be holding dlm->spinlock and dlm->master_lock
  2336. * when adding a migration mle, we can clear any other mles
  2337. * in the master list because we know with certainty that
  2338. * the master is "master". so we remove any old mle from
  2339. * the list after setting it's master field, and then add
  2340. * the new migration mle. this way we can hold with the rule
  2341. * of having only one mle for a given lock name at all times. */
  2342. static int dlm_add_migration_mle(struct dlm_ctxt *dlm,
  2343. struct dlm_lock_resource *res,
  2344. struct dlm_master_list_entry *mle,
  2345. struct dlm_master_list_entry **oldmle,
  2346. const char *name, unsigned int namelen,
  2347. u8 new_master, u8 master)
  2348. {
  2349. int found;
  2350. int ret = 0;
  2351. *oldmle = NULL;
  2352. mlog_entry_void();
  2353. assert_spin_locked(&dlm->spinlock);
  2354. assert_spin_locked(&dlm->master_lock);
  2355. /* caller is responsible for any ref taken here on oldmle */
  2356. found = dlm_find_mle(dlm, oldmle, (char *)name, namelen);
  2357. if (found) {
  2358. struct dlm_master_list_entry *tmp = *oldmle;
  2359. spin_lock(&tmp->spinlock);
  2360. if (tmp->type == DLM_MLE_MIGRATION) {
  2361. if (master == dlm->node_num) {
  2362. /* ah another process raced me to it */
  2363. mlog(0, "tried to migrate %.*s, but some "
  2364. "process beat me to it\n",
  2365. namelen, name);
  2366. ret = -EEXIST;
  2367. } else {
  2368. /* bad. 2 NODES are trying to migrate! */
  2369. mlog(ML_ERROR, "migration error mle: "
  2370. "master=%u new_master=%u // request: "
  2371. "master=%u new_master=%u // "
  2372. "lockres=%.*s\n",
  2373. tmp->master, tmp->new_master,
  2374. master, new_master,
  2375. namelen, name);
  2376. BUG();
  2377. }
  2378. } else {
  2379. /* this is essentially what assert_master does */
  2380. tmp->master = master;
  2381. atomic_set(&tmp->woken, 1);
  2382. wake_up(&tmp->wq);
  2383. /* remove it from the list so that only one
  2384. * mle will be found */
  2385. list_del_init(&tmp->list);
  2386. __dlm_mle_detach_hb_events(dlm, mle);
  2387. }
  2388. spin_unlock(&tmp->spinlock);
  2389. }
  2390. /* now add a migration mle to the tail of the list */
  2391. dlm_init_mle(mle, DLM_MLE_MIGRATION, dlm, res, name, namelen);
  2392. mle->new_master = new_master;
  2393. mle->master = master;
  2394. /* do this for consistency with other mle types */
  2395. set_bit(new_master, mle->maybe_map);
  2396. list_add(&mle->list, &dlm->master_list);
  2397. return ret;
  2398. }
  2399. void dlm_clean_master_list(struct dlm_ctxt *dlm, u8 dead_node)
  2400. {
  2401. struct list_head *iter, *iter2;
  2402. struct dlm_master_list_entry *mle;
  2403. struct dlm_lock_resource *res;
  2404. unsigned int hash;
  2405. mlog_entry("dlm=%s, dead node=%u\n", dlm->name, dead_node);
  2406. top:
  2407. assert_spin_locked(&dlm->spinlock);
  2408. /* clean the master list */
  2409. spin_lock(&dlm->master_lock);
  2410. list_for_each_safe(iter, iter2, &dlm->master_list) {
  2411. mle = list_entry(iter, struct dlm_master_list_entry, list);
  2412. BUG_ON(mle->type != DLM_MLE_BLOCK &&
  2413. mle->type != DLM_MLE_MASTER &&
  2414. mle->type != DLM_MLE_MIGRATION);
  2415. /* MASTER mles are initiated locally. the waiting
  2416. * process will notice the node map change
  2417. * shortly. let that happen as normal. */
  2418. if (mle->type == DLM_MLE_MASTER)
  2419. continue;
  2420. /* BLOCK mles are initiated by other nodes.
  2421. * need to clean up if the dead node would have
  2422. * been the master. */
  2423. if (mle->type == DLM_MLE_BLOCK) {
  2424. int bit;
  2425. spin_lock(&mle->spinlock);
  2426. bit = find_next_bit(mle->maybe_map, O2NM_MAX_NODES, 0);
  2427. if (bit != dead_node) {
  2428. mlog(0, "mle found, but dead node %u would "
  2429. "not have been master\n", dead_node);
  2430. spin_unlock(&mle->spinlock);
  2431. } else {
  2432. /* must drop the refcount by one since the
  2433. * assert_master will never arrive. this
  2434. * may result in the mle being unlinked and
  2435. * freed, but there may still be a process
  2436. * waiting in the dlmlock path which is fine. */
  2437. mlog(ML_ERROR, "node %u was expected master\n",
  2438. dead_node);
  2439. atomic_set(&mle->woken, 1);
  2440. spin_unlock(&mle->spinlock);
  2441. wake_up(&mle->wq);
  2442. /* do not need events any longer, so detach
  2443. * from heartbeat */
  2444. __dlm_mle_detach_hb_events(dlm, mle);
  2445. __dlm_put_mle(mle);
  2446. }
  2447. continue;
  2448. }
  2449. /* everything else is a MIGRATION mle */
  2450. /* the rule for MIGRATION mles is that the master
  2451. * becomes UNKNOWN if *either* the original or
  2452. * the new master dies. all UNKNOWN lockreses
  2453. * are sent to whichever node becomes the recovery
  2454. * master. the new master is responsible for
  2455. * determining if there is still a master for
  2456. * this lockres, or if he needs to take over
  2457. * mastery. either way, this node should expect
  2458. * another message to resolve this. */
  2459. if (mle->master != dead_node &&
  2460. mle->new_master != dead_node)
  2461. continue;
  2462. /* if we have reached this point, this mle needs to
  2463. * be removed from the list and freed. */
  2464. /* remove from the list early. NOTE: unlinking
  2465. * list_head while in list_for_each_safe */
  2466. __dlm_mle_detach_hb_events(dlm, mle);
  2467. spin_lock(&mle->spinlock);
  2468. list_del_init(&mle->list);
  2469. atomic_set(&mle->woken, 1);
  2470. spin_unlock(&mle->spinlock);
  2471. wake_up(&mle->wq);
  2472. mlog(0, "%s: node %u died during migration from "
  2473. "%u to %u!\n", dlm->name, dead_node,
  2474. mle->master, mle->new_master);
  2475. /* if there is a lockres associated with this
  2476. * mle, find it and set its owner to UNKNOWN */
  2477. hash = dlm_lockid_hash(mle->u.name.name, mle->u.name.len);
  2478. res = __dlm_lookup_lockres(dlm, mle->u.name.name,
  2479. mle->u.name.len, hash);
  2480. if (res) {
  2481. /* unfortunately if we hit this rare case, our
  2482. * lock ordering is messed. we need to drop
  2483. * the master lock so that we can take the
  2484. * lockres lock, meaning that we will have to
  2485. * restart from the head of list. */
  2486. spin_unlock(&dlm->master_lock);
  2487. /* move lockres onto recovery list */
  2488. spin_lock(&res->spinlock);
  2489. dlm_set_lockres_owner(dlm, res,
  2490. DLM_LOCK_RES_OWNER_UNKNOWN);
  2491. dlm_move_lockres_to_recovery_list(dlm, res);
  2492. spin_unlock(&res->spinlock);
  2493. dlm_lockres_put(res);
  2494. /* about to get rid of mle, detach from heartbeat */
  2495. __dlm_mle_detach_hb_events(dlm, mle);
  2496. /* dump the mle */
  2497. spin_lock(&dlm->master_lock);
  2498. __dlm_put_mle(mle);
  2499. spin_unlock(&dlm->master_lock);
  2500. /* restart */
  2501. goto top;
  2502. }
  2503. /* this may be the last reference */
  2504. __dlm_put_mle(mle);
  2505. }
  2506. spin_unlock(&dlm->master_lock);
  2507. }
  2508. int dlm_finish_migration(struct dlm_ctxt *dlm, struct dlm_lock_resource *res,
  2509. u8 old_master)
  2510. {
  2511. struct dlm_node_iter iter;
  2512. int ret = 0;
  2513. spin_lock(&dlm->spinlock);
  2514. dlm_node_iter_init(dlm->domain_map, &iter);
  2515. clear_bit(old_master, iter.node_map);
  2516. clear_bit(dlm->node_num, iter.node_map);
  2517. spin_unlock(&dlm->spinlock);
  2518. mlog(0, "now time to do a migrate request to other nodes\n");
  2519. ret = dlm_do_migrate_request(dlm, res, old_master,
  2520. dlm->node_num, &iter);
  2521. if (ret < 0) {
  2522. mlog_errno(ret);
  2523. goto leave;
  2524. }
  2525. mlog(0, "doing assert master of %.*s to all except the original node\n",
  2526. res->lockname.len, res->lockname.name);
  2527. /* this call now finishes out the nodemap
  2528. * even if one or more nodes die */
  2529. ret = dlm_do_assert_master(dlm, res->lockname.name,
  2530. res->lockname.len, iter.node_map,
  2531. DLM_ASSERT_MASTER_FINISH_MIGRATION);
  2532. if (ret < 0) {
  2533. /* no longer need to retry. all living nodes contacted. */
  2534. mlog_errno(ret);
  2535. ret = 0;
  2536. }
  2537. memset(iter.node_map, 0, sizeof(iter.node_map));
  2538. set_bit(old_master, iter.node_map);
  2539. mlog(0, "doing assert master of %.*s back to %u\n",
  2540. res->lockname.len, res->lockname.name, old_master);
  2541. ret = dlm_do_assert_master(dlm, res->lockname.name,
  2542. res->lockname.len, iter.node_map,
  2543. DLM_ASSERT_MASTER_FINISH_MIGRATION);
  2544. if (ret < 0) {
  2545. mlog(0, "assert master to original master failed "
  2546. "with %d.\n", ret);
  2547. /* the only nonzero status here would be because of
  2548. * a dead original node. we're done. */
  2549. ret = 0;
  2550. }
  2551. /* all done, set the owner, clear the flag */
  2552. spin_lock(&res->spinlock);
  2553. dlm_set_lockres_owner(dlm, res, dlm->node_num);
  2554. res->state &= ~DLM_LOCK_RES_MIGRATING;
  2555. spin_unlock(&res->spinlock);
  2556. /* re-dirty it on the new master */
  2557. dlm_kick_thread(dlm, res);
  2558. wake_up(&res->wq);
  2559. leave:
  2560. return ret;
  2561. }
  2562. /*
  2563. * LOCKRES AST REFCOUNT
  2564. * this is integral to migration
  2565. */
  2566. /* for future intent to call an ast, reserve one ahead of time.
  2567. * this should be called only after waiting on the lockres
  2568. * with dlm_wait_on_lockres, and while still holding the
  2569. * spinlock after the call. */
  2570. void __dlm_lockres_reserve_ast(struct dlm_lock_resource *res)
  2571. {
  2572. assert_spin_locked(&res->spinlock);
  2573. if (res->state & DLM_LOCK_RES_MIGRATING) {
  2574. __dlm_print_one_lock_resource(res);
  2575. }
  2576. BUG_ON(res->state & DLM_LOCK_RES_MIGRATING);
  2577. atomic_inc(&res->asts_reserved);
  2578. }
  2579. /*
  2580. * used to drop the reserved ast, either because it went unused,
  2581. * or because the ast/bast was actually called.
  2582. *
  2583. * also, if there is a pending migration on this lockres,
  2584. * and this was the last pending ast on the lockres,
  2585. * atomically set the MIGRATING flag before we drop the lock.
  2586. * this is how we ensure that migration can proceed with no
  2587. * asts in progress. note that it is ok if the state of the
  2588. * queues is such that a lock should be granted in the future
  2589. * or that a bast should be fired, because the new master will
  2590. * shuffle the lists on this lockres as soon as it is migrated.
  2591. */
  2592. void dlm_lockres_release_ast(struct dlm_ctxt *dlm,
  2593. struct dlm_lock_resource *res)
  2594. {
  2595. if (!atomic_dec_and_lock(&res->asts_reserved, &res->spinlock))
  2596. return;
  2597. if (!res->migration_pending) {
  2598. spin_unlock(&res->spinlock);
  2599. return;
  2600. }
  2601. BUG_ON(res->state & DLM_LOCK_RES_MIGRATING);
  2602. res->migration_pending = 0;
  2603. res->state |= DLM_LOCK_RES_MIGRATING;
  2604. spin_unlock(&res->spinlock);
  2605. wake_up(&res->wq);
  2606. wake_up(&dlm->migration_wq);
  2607. }