dlmrecovery.c 83 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808
  1. /* -*- mode: c; c-basic-offset: 8; -*-
  2. * vim: noexpandtab sw=8 ts=8 sts=0:
  3. *
  4. * dlmrecovery.c
  5. *
  6. * recovery stuff
  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/timer.h>
  39. #include <linux/kthread.h>
  40. #include <linux/delay.h>
  41. #include "cluster/heartbeat.h"
  42. #include "cluster/nodemanager.h"
  43. #include "cluster/tcp.h"
  44. #include "dlmapi.h"
  45. #include "dlmcommon.h"
  46. #include "dlmdomain.h"
  47. #define MLOG_MASK_PREFIX (ML_DLM|ML_DLM_RECOVERY)
  48. #include "cluster/masklog.h"
  49. static void dlm_do_local_recovery_cleanup(struct dlm_ctxt *dlm, u8 dead_node);
  50. static int dlm_recovery_thread(void *data);
  51. void dlm_complete_recovery_thread(struct dlm_ctxt *dlm);
  52. int dlm_launch_recovery_thread(struct dlm_ctxt *dlm);
  53. void dlm_kick_recovery_thread(struct dlm_ctxt *dlm);
  54. static int dlm_do_recovery(struct dlm_ctxt *dlm);
  55. static int dlm_pick_recovery_master(struct dlm_ctxt *dlm);
  56. static int dlm_remaster_locks(struct dlm_ctxt *dlm, u8 dead_node);
  57. static int dlm_init_recovery_area(struct dlm_ctxt *dlm, u8 dead_node);
  58. static int dlm_request_all_locks(struct dlm_ctxt *dlm,
  59. u8 request_from, u8 dead_node);
  60. static void dlm_destroy_recovery_area(struct dlm_ctxt *dlm, u8 dead_node);
  61. static inline int dlm_num_locks_in_lockres(struct dlm_lock_resource *res);
  62. static void dlm_init_migratable_lockres(struct dlm_migratable_lockres *mres,
  63. const char *lockname, int namelen,
  64. int total_locks, u64 cookie,
  65. u8 flags, u8 master);
  66. static int dlm_send_mig_lockres_msg(struct dlm_ctxt *dlm,
  67. struct dlm_migratable_lockres *mres,
  68. u8 send_to,
  69. struct dlm_lock_resource *res,
  70. int total_locks);
  71. static int dlm_process_recovery_data(struct dlm_ctxt *dlm,
  72. struct dlm_lock_resource *res,
  73. struct dlm_migratable_lockres *mres);
  74. static int dlm_send_finalize_reco_message(struct dlm_ctxt *dlm);
  75. static int dlm_send_all_done_msg(struct dlm_ctxt *dlm,
  76. u8 dead_node, u8 send_to);
  77. static int dlm_send_begin_reco_message(struct dlm_ctxt *dlm, u8 dead_node);
  78. static void dlm_move_reco_locks_to_list(struct dlm_ctxt *dlm,
  79. struct list_head *list, u8 dead_node);
  80. static void dlm_finish_local_lockres_recovery(struct dlm_ctxt *dlm,
  81. u8 dead_node, u8 new_master);
  82. static void dlm_reco_ast(void *astdata);
  83. static void dlm_reco_bast(void *astdata, int blocked_type);
  84. static void dlm_reco_unlock_ast(void *astdata, enum dlm_status st);
  85. static void dlm_request_all_locks_worker(struct dlm_work_item *item,
  86. void *data);
  87. static void dlm_mig_lockres_worker(struct dlm_work_item *item, void *data);
  88. static int dlm_lockres_master_requery(struct dlm_ctxt *dlm,
  89. struct dlm_lock_resource *res,
  90. u8 *real_master);
  91. static u64 dlm_get_next_mig_cookie(void);
  92. static DEFINE_SPINLOCK(dlm_reco_state_lock);
  93. static DEFINE_SPINLOCK(dlm_mig_cookie_lock);
  94. static u64 dlm_mig_cookie = 1;
  95. static u64 dlm_get_next_mig_cookie(void)
  96. {
  97. u64 c;
  98. spin_lock(&dlm_mig_cookie_lock);
  99. c = dlm_mig_cookie;
  100. if (dlm_mig_cookie == (~0ULL))
  101. dlm_mig_cookie = 1;
  102. else
  103. dlm_mig_cookie++;
  104. spin_unlock(&dlm_mig_cookie_lock);
  105. return c;
  106. }
  107. static inline void dlm_set_reco_dead_node(struct dlm_ctxt *dlm,
  108. u8 dead_node)
  109. {
  110. assert_spin_locked(&dlm->spinlock);
  111. if (dlm->reco.dead_node != dead_node)
  112. mlog(0, "%s: changing dead_node from %u to %u\n",
  113. dlm->name, dlm->reco.dead_node, dead_node);
  114. dlm->reco.dead_node = dead_node;
  115. }
  116. static inline void dlm_set_reco_master(struct dlm_ctxt *dlm,
  117. u8 master)
  118. {
  119. assert_spin_locked(&dlm->spinlock);
  120. mlog(0, "%s: changing new_master from %u to %u\n",
  121. dlm->name, dlm->reco.new_master, master);
  122. dlm->reco.new_master = master;
  123. }
  124. static inline void __dlm_reset_recovery(struct dlm_ctxt *dlm)
  125. {
  126. assert_spin_locked(&dlm->spinlock);
  127. clear_bit(dlm->reco.dead_node, dlm->recovery_map);
  128. dlm_set_reco_dead_node(dlm, O2NM_INVALID_NODE_NUM);
  129. dlm_set_reco_master(dlm, O2NM_INVALID_NODE_NUM);
  130. }
  131. static inline void dlm_reset_recovery(struct dlm_ctxt *dlm)
  132. {
  133. spin_lock(&dlm->spinlock);
  134. __dlm_reset_recovery(dlm);
  135. spin_unlock(&dlm->spinlock);
  136. }
  137. /* Worker function used during recovery. */
  138. void dlm_dispatch_work(struct work_struct *work)
  139. {
  140. struct dlm_ctxt *dlm =
  141. container_of(work, struct dlm_ctxt, dispatched_work);
  142. LIST_HEAD(tmp_list);
  143. struct list_head *iter, *iter2;
  144. struct dlm_work_item *item;
  145. dlm_workfunc_t *workfunc;
  146. int tot=0;
  147. spin_lock(&dlm->work_lock);
  148. list_splice_init(&dlm->work_list, &tmp_list);
  149. spin_unlock(&dlm->work_lock);
  150. list_for_each_safe(iter, iter2, &tmp_list) {
  151. tot++;
  152. }
  153. mlog(0, "%s: work thread has %d work items\n", dlm->name, tot);
  154. list_for_each_safe(iter, iter2, &tmp_list) {
  155. item = list_entry(iter, struct dlm_work_item, list);
  156. workfunc = item->func;
  157. list_del_init(&item->list);
  158. /* already have ref on dlm to avoid having
  159. * it disappear. just double-check. */
  160. BUG_ON(item->dlm != dlm);
  161. /* this is allowed to sleep and
  162. * call network stuff */
  163. workfunc(item, item->data);
  164. dlm_put(dlm);
  165. kfree(item);
  166. }
  167. }
  168. /*
  169. * RECOVERY THREAD
  170. */
  171. void dlm_kick_recovery_thread(struct dlm_ctxt *dlm)
  172. {
  173. /* wake the recovery thread
  174. * this will wake the reco thread in one of three places
  175. * 1) sleeping with no recovery happening
  176. * 2) sleeping with recovery mastered elsewhere
  177. * 3) recovery mastered here, waiting on reco data */
  178. wake_up(&dlm->dlm_reco_thread_wq);
  179. }
  180. /* Launch the recovery thread */
  181. int dlm_launch_recovery_thread(struct dlm_ctxt *dlm)
  182. {
  183. mlog(0, "starting dlm recovery thread...\n");
  184. dlm->dlm_reco_thread_task = kthread_run(dlm_recovery_thread, dlm,
  185. "dlm_reco_thread");
  186. if (IS_ERR(dlm->dlm_reco_thread_task)) {
  187. mlog_errno(PTR_ERR(dlm->dlm_reco_thread_task));
  188. dlm->dlm_reco_thread_task = NULL;
  189. return -EINVAL;
  190. }
  191. return 0;
  192. }
  193. void dlm_complete_recovery_thread(struct dlm_ctxt *dlm)
  194. {
  195. if (dlm->dlm_reco_thread_task) {
  196. mlog(0, "waiting for dlm recovery thread to exit\n");
  197. kthread_stop(dlm->dlm_reco_thread_task);
  198. dlm->dlm_reco_thread_task = NULL;
  199. }
  200. }
  201. /*
  202. * this is lame, but here's how recovery works...
  203. * 1) all recovery threads cluster wide will work on recovering
  204. * ONE node at a time
  205. * 2) negotiate who will take over all the locks for the dead node.
  206. * thats right... ALL the locks.
  207. * 3) once a new master is chosen, everyone scans all locks
  208. * and moves aside those mastered by the dead guy
  209. * 4) each of these locks should be locked until recovery is done
  210. * 5) the new master collects up all of secondary lock queue info
  211. * one lock at a time, forcing each node to communicate back
  212. * before continuing
  213. * 6) each secondary lock queue responds with the full known lock info
  214. * 7) once the new master has run all its locks, it sends a ALLDONE!
  215. * message to everyone
  216. * 8) upon receiving this message, the secondary queue node unlocks
  217. * and responds to the ALLDONE
  218. * 9) once the new master gets responses from everyone, he unlocks
  219. * everything and recovery for this dead node is done
  220. *10) go back to 2) while there are still dead nodes
  221. *
  222. */
  223. static void dlm_print_reco_node_status(struct dlm_ctxt *dlm)
  224. {
  225. struct dlm_reco_node_data *ndata;
  226. struct dlm_lock_resource *res;
  227. mlog(ML_NOTICE, "%s(%d): recovery info, state=%s, dead=%u, master=%u\n",
  228. dlm->name, dlm->dlm_reco_thread_task->pid,
  229. dlm->reco.state & DLM_RECO_STATE_ACTIVE ? "ACTIVE" : "inactive",
  230. dlm->reco.dead_node, dlm->reco.new_master);
  231. list_for_each_entry(ndata, &dlm->reco.node_data, list) {
  232. char *st = "unknown";
  233. switch (ndata->state) {
  234. case DLM_RECO_NODE_DATA_INIT:
  235. st = "init";
  236. break;
  237. case DLM_RECO_NODE_DATA_REQUESTING:
  238. st = "requesting";
  239. break;
  240. case DLM_RECO_NODE_DATA_DEAD:
  241. st = "dead";
  242. break;
  243. case DLM_RECO_NODE_DATA_RECEIVING:
  244. st = "receiving";
  245. break;
  246. case DLM_RECO_NODE_DATA_REQUESTED:
  247. st = "requested";
  248. break;
  249. case DLM_RECO_NODE_DATA_DONE:
  250. st = "done";
  251. break;
  252. case DLM_RECO_NODE_DATA_FINALIZE_SENT:
  253. st = "finalize-sent";
  254. break;
  255. default:
  256. st = "bad";
  257. break;
  258. }
  259. mlog(ML_NOTICE, "%s: reco state, node %u, state=%s\n",
  260. dlm->name, ndata->node_num, st);
  261. }
  262. list_for_each_entry(res, &dlm->reco.resources, recovering) {
  263. mlog(ML_NOTICE, "%s: lockres %.*s on recovering list\n",
  264. dlm->name, res->lockname.len, res->lockname.name);
  265. }
  266. }
  267. #define DLM_RECO_THREAD_TIMEOUT_MS (5 * 1000)
  268. static int dlm_recovery_thread(void *data)
  269. {
  270. int status;
  271. struct dlm_ctxt *dlm = data;
  272. unsigned long timeout = msecs_to_jiffies(DLM_RECO_THREAD_TIMEOUT_MS);
  273. mlog(0, "dlm thread running for %s...\n", dlm->name);
  274. while (!kthread_should_stop()) {
  275. if (dlm_joined(dlm)) {
  276. status = dlm_do_recovery(dlm);
  277. if (status == -EAGAIN) {
  278. /* do not sleep, recheck immediately. */
  279. continue;
  280. }
  281. if (status < 0)
  282. mlog_errno(status);
  283. }
  284. wait_event_interruptible_timeout(dlm->dlm_reco_thread_wq,
  285. kthread_should_stop(),
  286. timeout);
  287. }
  288. mlog(0, "quitting DLM recovery thread\n");
  289. return 0;
  290. }
  291. /* returns true when the recovery master has contacted us */
  292. static int dlm_reco_master_ready(struct dlm_ctxt *dlm)
  293. {
  294. int ready;
  295. spin_lock(&dlm->spinlock);
  296. ready = (dlm->reco.new_master != O2NM_INVALID_NODE_NUM);
  297. spin_unlock(&dlm->spinlock);
  298. return ready;
  299. }
  300. /* returns true if node is no longer in the domain
  301. * could be dead or just not joined */
  302. int dlm_is_node_dead(struct dlm_ctxt *dlm, u8 node)
  303. {
  304. int dead;
  305. spin_lock(&dlm->spinlock);
  306. dead = !test_bit(node, dlm->domain_map);
  307. spin_unlock(&dlm->spinlock);
  308. return dead;
  309. }
  310. /* returns true if node is no longer in the domain
  311. * could be dead or just not joined */
  312. static int dlm_is_node_recovered(struct dlm_ctxt *dlm, u8 node)
  313. {
  314. int recovered;
  315. spin_lock(&dlm->spinlock);
  316. recovered = !test_bit(node, dlm->recovery_map);
  317. spin_unlock(&dlm->spinlock);
  318. return recovered;
  319. }
  320. int dlm_wait_for_node_death(struct dlm_ctxt *dlm, u8 node, int timeout)
  321. {
  322. if (timeout) {
  323. mlog(ML_NOTICE, "%s: waiting %dms for notification of "
  324. "death of node %u\n", dlm->name, timeout, node);
  325. wait_event_timeout(dlm->dlm_reco_thread_wq,
  326. dlm_is_node_dead(dlm, node),
  327. msecs_to_jiffies(timeout));
  328. } else {
  329. mlog(ML_NOTICE, "%s: waiting indefinitely for notification "
  330. "of death of node %u\n", dlm->name, node);
  331. wait_event(dlm->dlm_reco_thread_wq,
  332. dlm_is_node_dead(dlm, node));
  333. }
  334. /* for now, return 0 */
  335. return 0;
  336. }
  337. int dlm_wait_for_node_recovery(struct dlm_ctxt *dlm, u8 node, int timeout)
  338. {
  339. if (timeout) {
  340. mlog(0, "%s: waiting %dms for notification of "
  341. "recovery of node %u\n", dlm->name, timeout, node);
  342. wait_event_timeout(dlm->dlm_reco_thread_wq,
  343. dlm_is_node_recovered(dlm, node),
  344. msecs_to_jiffies(timeout));
  345. } else {
  346. mlog(0, "%s: waiting indefinitely for notification "
  347. "of recovery of node %u\n", dlm->name, node);
  348. wait_event(dlm->dlm_reco_thread_wq,
  349. dlm_is_node_recovered(dlm, node));
  350. }
  351. /* for now, return 0 */
  352. return 0;
  353. }
  354. /* callers of the top-level api calls (dlmlock/dlmunlock) should
  355. * block on the dlm->reco.event when recovery is in progress.
  356. * the dlm recovery thread will set this state when it begins
  357. * recovering a dead node (as the new master or not) and clear
  358. * the state and wake as soon as all affected lock resources have
  359. * been marked with the RECOVERY flag */
  360. static int dlm_in_recovery(struct dlm_ctxt *dlm)
  361. {
  362. int in_recovery;
  363. spin_lock(&dlm->spinlock);
  364. in_recovery = !!(dlm->reco.state & DLM_RECO_STATE_ACTIVE);
  365. spin_unlock(&dlm->spinlock);
  366. return in_recovery;
  367. }
  368. void dlm_wait_for_recovery(struct dlm_ctxt *dlm)
  369. {
  370. if (dlm_in_recovery(dlm)) {
  371. mlog(0, "%s: reco thread %d in recovery: "
  372. "state=%d, master=%u, dead=%u\n",
  373. dlm->name, dlm->dlm_reco_thread_task->pid,
  374. dlm->reco.state, dlm->reco.new_master,
  375. dlm->reco.dead_node);
  376. }
  377. wait_event(dlm->reco.event, !dlm_in_recovery(dlm));
  378. }
  379. static void dlm_begin_recovery(struct dlm_ctxt *dlm)
  380. {
  381. spin_lock(&dlm->spinlock);
  382. BUG_ON(dlm->reco.state & DLM_RECO_STATE_ACTIVE);
  383. dlm->reco.state |= DLM_RECO_STATE_ACTIVE;
  384. spin_unlock(&dlm->spinlock);
  385. }
  386. static void dlm_end_recovery(struct dlm_ctxt *dlm)
  387. {
  388. spin_lock(&dlm->spinlock);
  389. BUG_ON(!(dlm->reco.state & DLM_RECO_STATE_ACTIVE));
  390. dlm->reco.state &= ~DLM_RECO_STATE_ACTIVE;
  391. spin_unlock(&dlm->spinlock);
  392. wake_up(&dlm->reco.event);
  393. }
  394. static int dlm_do_recovery(struct dlm_ctxt *dlm)
  395. {
  396. int status = 0;
  397. int ret;
  398. spin_lock(&dlm->spinlock);
  399. /* check to see if the new master has died */
  400. if (dlm->reco.new_master != O2NM_INVALID_NODE_NUM &&
  401. test_bit(dlm->reco.new_master, dlm->recovery_map)) {
  402. mlog(0, "new master %u died while recovering %u!\n",
  403. dlm->reco.new_master, dlm->reco.dead_node);
  404. /* unset the new_master, leave dead_node */
  405. dlm_set_reco_master(dlm, O2NM_INVALID_NODE_NUM);
  406. }
  407. /* select a target to recover */
  408. if (dlm->reco.dead_node == O2NM_INVALID_NODE_NUM) {
  409. int bit;
  410. bit = find_next_bit (dlm->recovery_map, O2NM_MAX_NODES+1, 0);
  411. if (bit >= O2NM_MAX_NODES || bit < 0)
  412. dlm_set_reco_dead_node(dlm, O2NM_INVALID_NODE_NUM);
  413. else
  414. dlm_set_reco_dead_node(dlm, bit);
  415. } else if (!test_bit(dlm->reco.dead_node, dlm->recovery_map)) {
  416. /* BUG? */
  417. mlog(ML_ERROR, "dead_node %u no longer in recovery map!\n",
  418. dlm->reco.dead_node);
  419. dlm_set_reco_dead_node(dlm, O2NM_INVALID_NODE_NUM);
  420. }
  421. if (dlm->reco.dead_node == O2NM_INVALID_NODE_NUM) {
  422. // mlog(0, "nothing to recover! sleeping now!\n");
  423. spin_unlock(&dlm->spinlock);
  424. /* return to main thread loop and sleep. */
  425. return 0;
  426. }
  427. mlog(0, "%s(%d):recovery thread found node %u in the recovery map!\n",
  428. dlm->name, dlm->dlm_reco_thread_task->pid,
  429. dlm->reco.dead_node);
  430. spin_unlock(&dlm->spinlock);
  431. /* take write barrier */
  432. /* (stops the list reshuffling thread, proxy ast handling) */
  433. dlm_begin_recovery(dlm);
  434. if (dlm->reco.new_master == dlm->node_num)
  435. goto master_here;
  436. if (dlm->reco.new_master == O2NM_INVALID_NODE_NUM) {
  437. /* choose a new master, returns 0 if this node
  438. * is the master, -EEXIST if it's another node.
  439. * this does not return until a new master is chosen
  440. * or recovery completes entirely. */
  441. ret = dlm_pick_recovery_master(dlm);
  442. if (!ret) {
  443. /* already notified everyone. go. */
  444. goto master_here;
  445. }
  446. mlog(0, "another node will master this recovery session.\n");
  447. }
  448. mlog(0, "dlm=%s (%d), new_master=%u, this node=%u, dead_node=%u\n",
  449. dlm->name, dlm->dlm_reco_thread_task->pid, dlm->reco.new_master,
  450. dlm->node_num, dlm->reco.dead_node);
  451. /* it is safe to start everything back up here
  452. * because all of the dead node's lock resources
  453. * have been marked as in-recovery */
  454. dlm_end_recovery(dlm);
  455. /* sleep out in main dlm_recovery_thread loop. */
  456. return 0;
  457. master_here:
  458. mlog(0, "(%d) mastering recovery of %s:%u here(this=%u)!\n",
  459. dlm->dlm_reco_thread_task->pid,
  460. dlm->name, dlm->reco.dead_node, dlm->node_num);
  461. status = dlm_remaster_locks(dlm, dlm->reco.dead_node);
  462. if (status < 0) {
  463. /* we should never hit this anymore */
  464. mlog(ML_ERROR, "error %d remastering locks for node %u, "
  465. "retrying.\n", status, dlm->reco.dead_node);
  466. /* yield a bit to allow any final network messages
  467. * to get handled on remaining nodes */
  468. msleep(100);
  469. } else {
  470. /* success! see if any other nodes need recovery */
  471. mlog(0, "DONE mastering recovery of %s:%u here(this=%u)!\n",
  472. dlm->name, dlm->reco.dead_node, dlm->node_num);
  473. dlm_reset_recovery(dlm);
  474. }
  475. dlm_end_recovery(dlm);
  476. /* continue and look for another dead node */
  477. return -EAGAIN;
  478. }
  479. static int dlm_remaster_locks(struct dlm_ctxt *dlm, u8 dead_node)
  480. {
  481. int status = 0;
  482. struct dlm_reco_node_data *ndata;
  483. struct list_head *iter;
  484. int all_nodes_done;
  485. int destroy = 0;
  486. int pass = 0;
  487. do {
  488. /* we have become recovery master. there is no escaping
  489. * this, so just keep trying until we get it. */
  490. status = dlm_init_recovery_area(dlm, dead_node);
  491. if (status < 0) {
  492. mlog(ML_ERROR, "%s: failed to alloc recovery area, "
  493. "retrying\n", dlm->name);
  494. msleep(1000);
  495. }
  496. } while (status != 0);
  497. /* safe to access the node data list without a lock, since this
  498. * process is the only one to change the list */
  499. list_for_each(iter, &dlm->reco.node_data) {
  500. ndata = list_entry (iter, struct dlm_reco_node_data, list);
  501. BUG_ON(ndata->state != DLM_RECO_NODE_DATA_INIT);
  502. ndata->state = DLM_RECO_NODE_DATA_REQUESTING;
  503. mlog(0, "requesting lock info from node %u\n",
  504. ndata->node_num);
  505. if (ndata->node_num == dlm->node_num) {
  506. ndata->state = DLM_RECO_NODE_DATA_DONE;
  507. continue;
  508. }
  509. do {
  510. status = dlm_request_all_locks(dlm, ndata->node_num,
  511. dead_node);
  512. if (status < 0) {
  513. mlog_errno(status);
  514. if (dlm_is_host_down(status)) {
  515. /* node died, ignore it for recovery */
  516. status = 0;
  517. ndata->state = DLM_RECO_NODE_DATA_DEAD;
  518. /* wait for the domain map to catch up
  519. * with the network state. */
  520. wait_event_timeout(dlm->dlm_reco_thread_wq,
  521. dlm_is_node_dead(dlm,
  522. ndata->node_num),
  523. msecs_to_jiffies(1000));
  524. mlog(0, "waited 1 sec for %u, "
  525. "dead? %s\n", ndata->node_num,
  526. dlm_is_node_dead(dlm, ndata->node_num) ?
  527. "yes" : "no");
  528. } else {
  529. /* -ENOMEM on the other node */
  530. mlog(0, "%s: node %u returned "
  531. "%d during recovery, retrying "
  532. "after a short wait\n",
  533. dlm->name, ndata->node_num,
  534. status);
  535. msleep(100);
  536. }
  537. }
  538. } while (status != 0);
  539. spin_lock(&dlm_reco_state_lock);
  540. switch (ndata->state) {
  541. case DLM_RECO_NODE_DATA_INIT:
  542. case DLM_RECO_NODE_DATA_FINALIZE_SENT:
  543. case DLM_RECO_NODE_DATA_REQUESTED:
  544. BUG();
  545. break;
  546. case DLM_RECO_NODE_DATA_DEAD:
  547. mlog(0, "node %u died after requesting "
  548. "recovery info for node %u\n",
  549. ndata->node_num, dead_node);
  550. /* fine. don't need this node's info.
  551. * continue without it. */
  552. break;
  553. case DLM_RECO_NODE_DATA_REQUESTING:
  554. ndata->state = DLM_RECO_NODE_DATA_REQUESTED;
  555. mlog(0, "now receiving recovery data from "
  556. "node %u for dead node %u\n",
  557. ndata->node_num, dead_node);
  558. break;
  559. case DLM_RECO_NODE_DATA_RECEIVING:
  560. mlog(0, "already receiving recovery data from "
  561. "node %u for dead node %u\n",
  562. ndata->node_num, dead_node);
  563. break;
  564. case DLM_RECO_NODE_DATA_DONE:
  565. mlog(0, "already DONE receiving recovery data "
  566. "from node %u for dead node %u\n",
  567. ndata->node_num, dead_node);
  568. break;
  569. }
  570. spin_unlock(&dlm_reco_state_lock);
  571. }
  572. mlog(0, "done requesting all lock info\n");
  573. /* nodes should be sending reco data now
  574. * just need to wait */
  575. while (1) {
  576. /* check all the nodes now to see if we are
  577. * done, or if anyone died */
  578. all_nodes_done = 1;
  579. spin_lock(&dlm_reco_state_lock);
  580. list_for_each(iter, &dlm->reco.node_data) {
  581. ndata = list_entry (iter, struct dlm_reco_node_data, list);
  582. mlog(0, "checking recovery state of node %u\n",
  583. ndata->node_num);
  584. switch (ndata->state) {
  585. case DLM_RECO_NODE_DATA_INIT:
  586. case DLM_RECO_NODE_DATA_REQUESTING:
  587. mlog(ML_ERROR, "bad ndata state for "
  588. "node %u: state=%d\n",
  589. ndata->node_num, ndata->state);
  590. BUG();
  591. break;
  592. case DLM_RECO_NODE_DATA_DEAD:
  593. mlog(0, "node %u died after "
  594. "requesting recovery info for "
  595. "node %u\n", ndata->node_num,
  596. dead_node);
  597. break;
  598. case DLM_RECO_NODE_DATA_RECEIVING:
  599. case DLM_RECO_NODE_DATA_REQUESTED:
  600. mlog(0, "%s: node %u still in state %s\n",
  601. dlm->name, ndata->node_num,
  602. ndata->state==DLM_RECO_NODE_DATA_RECEIVING ?
  603. "receiving" : "requested");
  604. all_nodes_done = 0;
  605. break;
  606. case DLM_RECO_NODE_DATA_DONE:
  607. mlog(0, "%s: node %u state is done\n",
  608. dlm->name, ndata->node_num);
  609. break;
  610. case DLM_RECO_NODE_DATA_FINALIZE_SENT:
  611. mlog(0, "%s: node %u state is finalize\n",
  612. dlm->name, ndata->node_num);
  613. break;
  614. }
  615. }
  616. spin_unlock(&dlm_reco_state_lock);
  617. mlog(0, "pass #%d, all_nodes_done?: %s\n", ++pass,
  618. all_nodes_done?"yes":"no");
  619. if (all_nodes_done) {
  620. int ret;
  621. /* all nodes are now in DLM_RECO_NODE_DATA_DONE state
  622. * just send a finalize message to everyone and
  623. * clean up */
  624. mlog(0, "all nodes are done! send finalize\n");
  625. ret = dlm_send_finalize_reco_message(dlm);
  626. if (ret < 0)
  627. mlog_errno(ret);
  628. spin_lock(&dlm->spinlock);
  629. dlm_finish_local_lockres_recovery(dlm, dead_node,
  630. dlm->node_num);
  631. spin_unlock(&dlm->spinlock);
  632. mlog(0, "should be done with recovery!\n");
  633. mlog(0, "finishing recovery of %s at %lu, "
  634. "dead=%u, this=%u, new=%u\n", dlm->name,
  635. jiffies, dlm->reco.dead_node,
  636. dlm->node_num, dlm->reco.new_master);
  637. destroy = 1;
  638. status = 0;
  639. /* rescan everything marked dirty along the way */
  640. dlm_kick_thread(dlm, NULL);
  641. break;
  642. }
  643. /* wait to be signalled, with periodic timeout
  644. * to check for node death */
  645. wait_event_interruptible_timeout(dlm->dlm_reco_thread_wq,
  646. kthread_should_stop(),
  647. msecs_to_jiffies(DLM_RECO_THREAD_TIMEOUT_MS));
  648. }
  649. if (destroy)
  650. dlm_destroy_recovery_area(dlm, dead_node);
  651. mlog_exit(status);
  652. return status;
  653. }
  654. static int dlm_init_recovery_area(struct dlm_ctxt *dlm, u8 dead_node)
  655. {
  656. int num=0;
  657. struct dlm_reco_node_data *ndata;
  658. spin_lock(&dlm->spinlock);
  659. memcpy(dlm->reco.node_map, dlm->domain_map, sizeof(dlm->domain_map));
  660. /* nodes can only be removed (by dying) after dropping
  661. * this lock, and death will be trapped later, so this should do */
  662. spin_unlock(&dlm->spinlock);
  663. while (1) {
  664. num = find_next_bit (dlm->reco.node_map, O2NM_MAX_NODES, num);
  665. if (num >= O2NM_MAX_NODES) {
  666. break;
  667. }
  668. BUG_ON(num == dead_node);
  669. ndata = kzalloc(sizeof(*ndata), GFP_NOFS);
  670. if (!ndata) {
  671. dlm_destroy_recovery_area(dlm, dead_node);
  672. return -ENOMEM;
  673. }
  674. ndata->node_num = num;
  675. ndata->state = DLM_RECO_NODE_DATA_INIT;
  676. spin_lock(&dlm_reco_state_lock);
  677. list_add_tail(&ndata->list, &dlm->reco.node_data);
  678. spin_unlock(&dlm_reco_state_lock);
  679. num++;
  680. }
  681. return 0;
  682. }
  683. static void dlm_destroy_recovery_area(struct dlm_ctxt *dlm, u8 dead_node)
  684. {
  685. struct list_head *iter, *iter2;
  686. struct dlm_reco_node_data *ndata;
  687. LIST_HEAD(tmplist);
  688. spin_lock(&dlm_reco_state_lock);
  689. list_splice_init(&dlm->reco.node_data, &tmplist);
  690. spin_unlock(&dlm_reco_state_lock);
  691. list_for_each_safe(iter, iter2, &tmplist) {
  692. ndata = list_entry (iter, struct dlm_reco_node_data, list);
  693. list_del_init(&ndata->list);
  694. kfree(ndata);
  695. }
  696. }
  697. static int dlm_request_all_locks(struct dlm_ctxt *dlm, u8 request_from,
  698. u8 dead_node)
  699. {
  700. struct dlm_lock_request lr;
  701. enum dlm_status ret;
  702. mlog(0, "\n");
  703. mlog(0, "dlm_request_all_locks: dead node is %u, sending request "
  704. "to %u\n", dead_node, request_from);
  705. memset(&lr, 0, sizeof(lr));
  706. lr.node_idx = dlm->node_num;
  707. lr.dead_node = dead_node;
  708. // send message
  709. ret = DLM_NOLOCKMGR;
  710. ret = o2net_send_message(DLM_LOCK_REQUEST_MSG, dlm->key,
  711. &lr, sizeof(lr), request_from, NULL);
  712. /* negative status is handled by caller */
  713. if (ret < 0)
  714. mlog_errno(ret);
  715. // return from here, then
  716. // sleep until all received or error
  717. return ret;
  718. }
  719. int dlm_request_all_locks_handler(struct o2net_msg *msg, u32 len, void *data,
  720. void **ret_data)
  721. {
  722. struct dlm_ctxt *dlm = data;
  723. struct dlm_lock_request *lr = (struct dlm_lock_request *)msg->buf;
  724. char *buf = NULL;
  725. struct dlm_work_item *item = NULL;
  726. if (!dlm_grab(dlm))
  727. return -EINVAL;
  728. if (lr->dead_node != dlm->reco.dead_node) {
  729. mlog(ML_ERROR, "%s: node %u sent dead_node=%u, but local "
  730. "dead_node is %u\n", dlm->name, lr->node_idx,
  731. lr->dead_node, dlm->reco.dead_node);
  732. dlm_print_reco_node_status(dlm);
  733. /* this is a hack */
  734. dlm_put(dlm);
  735. return -ENOMEM;
  736. }
  737. BUG_ON(lr->dead_node != dlm->reco.dead_node);
  738. item = kzalloc(sizeof(*item), GFP_NOFS);
  739. if (!item) {
  740. dlm_put(dlm);
  741. return -ENOMEM;
  742. }
  743. /* this will get freed by dlm_request_all_locks_worker */
  744. buf = (char *) __get_free_page(GFP_NOFS);
  745. if (!buf) {
  746. kfree(item);
  747. dlm_put(dlm);
  748. return -ENOMEM;
  749. }
  750. /* queue up work for dlm_request_all_locks_worker */
  751. dlm_grab(dlm); /* get an extra ref for the work item */
  752. dlm_init_work_item(dlm, item, dlm_request_all_locks_worker, buf);
  753. item->u.ral.reco_master = lr->node_idx;
  754. item->u.ral.dead_node = lr->dead_node;
  755. spin_lock(&dlm->work_lock);
  756. list_add_tail(&item->list, &dlm->work_list);
  757. spin_unlock(&dlm->work_lock);
  758. queue_work(dlm->dlm_worker, &dlm->dispatched_work);
  759. dlm_put(dlm);
  760. return 0;
  761. }
  762. static void dlm_request_all_locks_worker(struct dlm_work_item *item, void *data)
  763. {
  764. struct dlm_migratable_lockres *mres;
  765. struct dlm_lock_resource *res;
  766. struct dlm_ctxt *dlm;
  767. LIST_HEAD(resources);
  768. struct list_head *iter;
  769. int ret;
  770. u8 dead_node, reco_master;
  771. int skip_all_done = 0;
  772. dlm = item->dlm;
  773. dead_node = item->u.ral.dead_node;
  774. reco_master = item->u.ral.reco_master;
  775. mres = (struct dlm_migratable_lockres *)data;
  776. mlog(0, "%s: recovery worker started, dead=%u, master=%u\n",
  777. dlm->name, dead_node, reco_master);
  778. if (dead_node != dlm->reco.dead_node ||
  779. reco_master != dlm->reco.new_master) {
  780. /* worker could have been created before the recovery master
  781. * died. if so, do not continue, but do not error. */
  782. if (dlm->reco.new_master == O2NM_INVALID_NODE_NUM) {
  783. mlog(ML_NOTICE, "%s: will not send recovery state, "
  784. "recovery master %u died, thread=(dead=%u,mas=%u)"
  785. " current=(dead=%u,mas=%u)\n", dlm->name,
  786. reco_master, dead_node, reco_master,
  787. dlm->reco.dead_node, dlm->reco.new_master);
  788. } else {
  789. mlog(ML_NOTICE, "%s: reco state invalid: reco(dead=%u, "
  790. "master=%u), request(dead=%u, master=%u)\n",
  791. dlm->name, dlm->reco.dead_node,
  792. dlm->reco.new_master, dead_node, reco_master);
  793. }
  794. goto leave;
  795. }
  796. /* lock resources should have already been moved to the
  797. * dlm->reco.resources list. now move items from that list
  798. * to a temp list if the dead owner matches. note that the
  799. * whole cluster recovers only one node at a time, so we
  800. * can safely move UNKNOWN lock resources for each recovery
  801. * session. */
  802. dlm_move_reco_locks_to_list(dlm, &resources, dead_node);
  803. /* now we can begin blasting lockreses without the dlm lock */
  804. /* any errors returned will be due to the new_master dying,
  805. * the dlm_reco_thread should detect this */
  806. list_for_each(iter, &resources) {
  807. res = list_entry (iter, struct dlm_lock_resource, recovering);
  808. ret = dlm_send_one_lockres(dlm, res, mres, reco_master,
  809. DLM_MRES_RECOVERY);
  810. if (ret < 0) {
  811. mlog(ML_ERROR, "%s: node %u went down while sending "
  812. "recovery state for dead node %u, ret=%d\n", dlm->name,
  813. reco_master, dead_node, ret);
  814. skip_all_done = 1;
  815. break;
  816. }
  817. }
  818. /* move the resources back to the list */
  819. spin_lock(&dlm->spinlock);
  820. list_splice_init(&resources, &dlm->reco.resources);
  821. spin_unlock(&dlm->spinlock);
  822. if (!skip_all_done) {
  823. ret = dlm_send_all_done_msg(dlm, dead_node, reco_master);
  824. if (ret < 0) {
  825. mlog(ML_ERROR, "%s: node %u went down while sending "
  826. "recovery all-done for dead node %u, ret=%d\n",
  827. dlm->name, reco_master, dead_node, ret);
  828. }
  829. }
  830. leave:
  831. free_page((unsigned long)data);
  832. }
  833. static int dlm_send_all_done_msg(struct dlm_ctxt *dlm, u8 dead_node, u8 send_to)
  834. {
  835. int ret, tmpret;
  836. struct dlm_reco_data_done done_msg;
  837. memset(&done_msg, 0, sizeof(done_msg));
  838. done_msg.node_idx = dlm->node_num;
  839. done_msg.dead_node = dead_node;
  840. mlog(0, "sending DATA DONE message to %u, "
  841. "my node=%u, dead node=%u\n", send_to, done_msg.node_idx,
  842. done_msg.dead_node);
  843. ret = o2net_send_message(DLM_RECO_DATA_DONE_MSG, dlm->key, &done_msg,
  844. sizeof(done_msg), send_to, &tmpret);
  845. if (ret < 0) {
  846. if (!dlm_is_host_down(ret)) {
  847. mlog_errno(ret);
  848. mlog(ML_ERROR, "%s: unknown error sending data-done "
  849. "to %u\n", dlm->name, send_to);
  850. BUG();
  851. }
  852. } else
  853. ret = tmpret;
  854. return ret;
  855. }
  856. int dlm_reco_data_done_handler(struct o2net_msg *msg, u32 len, void *data,
  857. void **ret_data)
  858. {
  859. struct dlm_ctxt *dlm = data;
  860. struct dlm_reco_data_done *done = (struct dlm_reco_data_done *)msg->buf;
  861. struct list_head *iter;
  862. struct dlm_reco_node_data *ndata = NULL;
  863. int ret = -EINVAL;
  864. if (!dlm_grab(dlm))
  865. return -EINVAL;
  866. mlog(0, "got DATA DONE: dead_node=%u, reco.dead_node=%u, "
  867. "node_idx=%u, this node=%u\n", done->dead_node,
  868. dlm->reco.dead_node, done->node_idx, dlm->node_num);
  869. mlog_bug_on_msg((done->dead_node != dlm->reco.dead_node),
  870. "Got DATA DONE: dead_node=%u, reco.dead_node=%u, "
  871. "node_idx=%u, this node=%u\n", done->dead_node,
  872. dlm->reco.dead_node, done->node_idx, dlm->node_num);
  873. spin_lock(&dlm_reco_state_lock);
  874. list_for_each(iter, &dlm->reco.node_data) {
  875. ndata = list_entry (iter, struct dlm_reco_node_data, list);
  876. if (ndata->node_num != done->node_idx)
  877. continue;
  878. switch (ndata->state) {
  879. /* should have moved beyond INIT but not to FINALIZE yet */
  880. case DLM_RECO_NODE_DATA_INIT:
  881. case DLM_RECO_NODE_DATA_DEAD:
  882. case DLM_RECO_NODE_DATA_FINALIZE_SENT:
  883. mlog(ML_ERROR, "bad ndata state for node %u:"
  884. " state=%d\n", ndata->node_num,
  885. ndata->state);
  886. BUG();
  887. break;
  888. /* these states are possible at this point, anywhere along
  889. * the line of recovery */
  890. case DLM_RECO_NODE_DATA_DONE:
  891. case DLM_RECO_NODE_DATA_RECEIVING:
  892. case DLM_RECO_NODE_DATA_REQUESTED:
  893. case DLM_RECO_NODE_DATA_REQUESTING:
  894. mlog(0, "node %u is DONE sending "
  895. "recovery data!\n",
  896. ndata->node_num);
  897. ndata->state = DLM_RECO_NODE_DATA_DONE;
  898. ret = 0;
  899. break;
  900. }
  901. }
  902. spin_unlock(&dlm_reco_state_lock);
  903. /* wake the recovery thread, some node is done */
  904. if (!ret)
  905. dlm_kick_recovery_thread(dlm);
  906. if (ret < 0)
  907. mlog(ML_ERROR, "failed to find recovery node data for node "
  908. "%u\n", done->node_idx);
  909. dlm_put(dlm);
  910. mlog(0, "leaving reco data done handler, ret=%d\n", ret);
  911. return ret;
  912. }
  913. static void dlm_move_reco_locks_to_list(struct dlm_ctxt *dlm,
  914. struct list_head *list,
  915. u8 dead_node)
  916. {
  917. struct dlm_lock_resource *res;
  918. struct list_head *iter, *iter2;
  919. struct dlm_lock *lock;
  920. spin_lock(&dlm->spinlock);
  921. list_for_each_safe(iter, iter2, &dlm->reco.resources) {
  922. res = list_entry (iter, struct dlm_lock_resource, recovering);
  923. /* always prune any $RECOVERY entries for dead nodes,
  924. * otherwise hangs can occur during later recovery */
  925. if (dlm_is_recovery_lock(res->lockname.name,
  926. res->lockname.len)) {
  927. spin_lock(&res->spinlock);
  928. list_for_each_entry(lock, &res->granted, list) {
  929. if (lock->ml.node == dead_node) {
  930. mlog(0, "AHA! there was "
  931. "a $RECOVERY lock for dead "
  932. "node %u (%s)!\n",
  933. dead_node, dlm->name);
  934. list_del_init(&lock->list);
  935. dlm_lock_put(lock);
  936. break;
  937. }
  938. }
  939. spin_unlock(&res->spinlock);
  940. continue;
  941. }
  942. if (res->owner == dead_node) {
  943. mlog(0, "found lockres owned by dead node while "
  944. "doing recovery for node %u. sending it.\n",
  945. dead_node);
  946. list_move_tail(&res->recovering, list);
  947. } else if (res->owner == DLM_LOCK_RES_OWNER_UNKNOWN) {
  948. mlog(0, "found UNKNOWN owner while doing recovery "
  949. "for node %u. sending it.\n", dead_node);
  950. list_move_tail(&res->recovering, list);
  951. }
  952. }
  953. spin_unlock(&dlm->spinlock);
  954. }
  955. static inline int dlm_num_locks_in_lockres(struct dlm_lock_resource *res)
  956. {
  957. int total_locks = 0;
  958. struct list_head *iter, *queue = &res->granted;
  959. int i;
  960. for (i=0; i<3; i++) {
  961. list_for_each(iter, queue)
  962. total_locks++;
  963. queue++;
  964. }
  965. return total_locks;
  966. }
  967. static int dlm_send_mig_lockres_msg(struct dlm_ctxt *dlm,
  968. struct dlm_migratable_lockres *mres,
  969. u8 send_to,
  970. struct dlm_lock_resource *res,
  971. int total_locks)
  972. {
  973. u64 mig_cookie = be64_to_cpu(mres->mig_cookie);
  974. int mres_total_locks = be32_to_cpu(mres->total_locks);
  975. int sz, ret = 0, status = 0;
  976. u8 orig_flags = mres->flags,
  977. orig_master = mres->master;
  978. BUG_ON(mres->num_locks > DLM_MAX_MIGRATABLE_LOCKS);
  979. if (!mres->num_locks)
  980. return 0;
  981. sz = sizeof(struct dlm_migratable_lockres) +
  982. (mres->num_locks * sizeof(struct dlm_migratable_lock));
  983. /* add an all-done flag if we reached the last lock */
  984. orig_flags = mres->flags;
  985. BUG_ON(total_locks > mres_total_locks);
  986. if (total_locks == mres_total_locks)
  987. mres->flags |= DLM_MRES_ALL_DONE;
  988. mlog(0, "%s:%.*s: sending mig lockres (%s) to %u\n",
  989. dlm->name, res->lockname.len, res->lockname.name,
  990. orig_flags & DLM_MRES_MIGRATION ? "migrate" : "recovery",
  991. send_to);
  992. /* send it */
  993. ret = o2net_send_message(DLM_MIG_LOCKRES_MSG, dlm->key, mres,
  994. sz, send_to, &status);
  995. if (ret < 0) {
  996. /* XXX: negative status is not handled.
  997. * this will end up killing this node. */
  998. mlog_errno(ret);
  999. } else {
  1000. /* might get an -ENOMEM back here */
  1001. ret = status;
  1002. if (ret < 0) {
  1003. mlog_errno(ret);
  1004. if (ret == -EFAULT) {
  1005. mlog(ML_ERROR, "node %u told me to kill "
  1006. "myself!\n", send_to);
  1007. BUG();
  1008. }
  1009. }
  1010. }
  1011. /* zero and reinit the message buffer */
  1012. dlm_init_migratable_lockres(mres, res->lockname.name,
  1013. res->lockname.len, mres_total_locks,
  1014. mig_cookie, orig_flags, orig_master);
  1015. return ret;
  1016. }
  1017. static void dlm_init_migratable_lockres(struct dlm_migratable_lockres *mres,
  1018. const char *lockname, int namelen,
  1019. int total_locks, u64 cookie,
  1020. u8 flags, u8 master)
  1021. {
  1022. /* mres here is one full page */
  1023. memset(mres, 0, PAGE_SIZE);
  1024. mres->lockname_len = namelen;
  1025. memcpy(mres->lockname, lockname, namelen);
  1026. mres->num_locks = 0;
  1027. mres->total_locks = cpu_to_be32(total_locks);
  1028. mres->mig_cookie = cpu_to_be64(cookie);
  1029. mres->flags = flags;
  1030. mres->master = master;
  1031. }
  1032. /* returns 1 if this lock fills the network structure,
  1033. * 0 otherwise */
  1034. static int dlm_add_lock_to_array(struct dlm_lock *lock,
  1035. struct dlm_migratable_lockres *mres, int queue)
  1036. {
  1037. struct dlm_migratable_lock *ml;
  1038. int lock_num = mres->num_locks;
  1039. ml = &(mres->ml[lock_num]);
  1040. ml->cookie = lock->ml.cookie;
  1041. ml->type = lock->ml.type;
  1042. ml->convert_type = lock->ml.convert_type;
  1043. ml->highest_blocked = lock->ml.highest_blocked;
  1044. ml->list = queue;
  1045. if (lock->lksb) {
  1046. ml->flags = lock->lksb->flags;
  1047. /* send our current lvb */
  1048. if (ml->type == LKM_EXMODE ||
  1049. ml->type == LKM_PRMODE) {
  1050. /* if it is already set, this had better be a PR
  1051. * and it has to match */
  1052. if (!dlm_lvb_is_empty(mres->lvb) &&
  1053. (ml->type == LKM_EXMODE ||
  1054. memcmp(mres->lvb, lock->lksb->lvb, DLM_LVB_LEN))) {
  1055. mlog(ML_ERROR, "mismatched lvbs!\n");
  1056. __dlm_print_one_lock_resource(lock->lockres);
  1057. BUG();
  1058. }
  1059. memcpy(mres->lvb, lock->lksb->lvb, DLM_LVB_LEN);
  1060. }
  1061. }
  1062. ml->node = lock->ml.node;
  1063. mres->num_locks++;
  1064. /* we reached the max, send this network message */
  1065. if (mres->num_locks == DLM_MAX_MIGRATABLE_LOCKS)
  1066. return 1;
  1067. return 0;
  1068. }
  1069. static void dlm_add_dummy_lock(struct dlm_ctxt *dlm,
  1070. struct dlm_migratable_lockres *mres)
  1071. {
  1072. struct dlm_lock dummy;
  1073. memset(&dummy, 0, sizeof(dummy));
  1074. dummy.ml.cookie = 0;
  1075. dummy.ml.type = LKM_IVMODE;
  1076. dummy.ml.convert_type = LKM_IVMODE;
  1077. dummy.ml.highest_blocked = LKM_IVMODE;
  1078. dummy.lksb = NULL;
  1079. dummy.ml.node = dlm->node_num;
  1080. dlm_add_lock_to_array(&dummy, mres, DLM_BLOCKED_LIST);
  1081. }
  1082. static inline int dlm_is_dummy_lock(struct dlm_ctxt *dlm,
  1083. struct dlm_migratable_lock *ml,
  1084. u8 *nodenum)
  1085. {
  1086. if (unlikely(ml->cookie == 0 &&
  1087. ml->type == LKM_IVMODE &&
  1088. ml->convert_type == LKM_IVMODE &&
  1089. ml->highest_blocked == LKM_IVMODE &&
  1090. ml->list == DLM_BLOCKED_LIST)) {
  1091. *nodenum = ml->node;
  1092. return 1;
  1093. }
  1094. return 0;
  1095. }
  1096. int dlm_send_one_lockres(struct dlm_ctxt *dlm, struct dlm_lock_resource *res,
  1097. struct dlm_migratable_lockres *mres,
  1098. u8 send_to, u8 flags)
  1099. {
  1100. struct list_head *queue, *iter;
  1101. int total_locks, i;
  1102. u64 mig_cookie = 0;
  1103. struct dlm_lock *lock;
  1104. int ret = 0;
  1105. BUG_ON(!(flags & (DLM_MRES_RECOVERY|DLM_MRES_MIGRATION)));
  1106. mlog(0, "sending to %u\n", send_to);
  1107. total_locks = dlm_num_locks_in_lockres(res);
  1108. if (total_locks > DLM_MAX_MIGRATABLE_LOCKS) {
  1109. /* rare, but possible */
  1110. mlog(0, "argh. lockres has %d locks. this will "
  1111. "require more than one network packet to "
  1112. "migrate\n", total_locks);
  1113. mig_cookie = dlm_get_next_mig_cookie();
  1114. }
  1115. dlm_init_migratable_lockres(mres, res->lockname.name,
  1116. res->lockname.len, total_locks,
  1117. mig_cookie, flags, res->owner);
  1118. total_locks = 0;
  1119. for (i=DLM_GRANTED_LIST; i<=DLM_BLOCKED_LIST; i++) {
  1120. queue = dlm_list_idx_to_ptr(res, i);
  1121. list_for_each(iter, queue) {
  1122. lock = list_entry (iter, struct dlm_lock, list);
  1123. /* add another lock. */
  1124. total_locks++;
  1125. if (!dlm_add_lock_to_array(lock, mres, i))
  1126. continue;
  1127. /* this filled the lock message,
  1128. * we must send it immediately. */
  1129. ret = dlm_send_mig_lockres_msg(dlm, mres, send_to,
  1130. res, total_locks);
  1131. if (ret < 0)
  1132. goto error;
  1133. }
  1134. }
  1135. if (total_locks == 0) {
  1136. /* send a dummy lock to indicate a mastery reference only */
  1137. mlog(0, "%s:%.*s: sending dummy lock to %u, %s\n",
  1138. dlm->name, res->lockname.len, res->lockname.name,
  1139. send_to, flags & DLM_MRES_RECOVERY ? "recovery" :
  1140. "migration");
  1141. dlm_add_dummy_lock(dlm, mres);
  1142. }
  1143. /* flush any remaining locks */
  1144. ret = dlm_send_mig_lockres_msg(dlm, mres, send_to, res, total_locks);
  1145. if (ret < 0)
  1146. goto error;
  1147. return ret;
  1148. error:
  1149. mlog(ML_ERROR, "%s: dlm_send_mig_lockres_msg returned %d\n",
  1150. dlm->name, ret);
  1151. if (!dlm_is_host_down(ret))
  1152. BUG();
  1153. mlog(0, "%s: node %u went down while sending %s "
  1154. "lockres %.*s\n", dlm->name, send_to,
  1155. flags & DLM_MRES_RECOVERY ? "recovery" : "migration",
  1156. res->lockname.len, res->lockname.name);
  1157. return ret;
  1158. }
  1159. /*
  1160. * this message will contain no more than one page worth of
  1161. * recovery data, and it will work on only one lockres.
  1162. * there may be many locks in this page, and we may need to wait
  1163. * for additional packets to complete all the locks (rare, but
  1164. * possible).
  1165. */
  1166. /*
  1167. * NOTE: the allocation error cases here are scary
  1168. * we really cannot afford to fail an alloc in recovery
  1169. * do we spin? returning an error only delays the problem really
  1170. */
  1171. int dlm_mig_lockres_handler(struct o2net_msg *msg, u32 len, void *data,
  1172. void **ret_data)
  1173. {
  1174. struct dlm_ctxt *dlm = data;
  1175. struct dlm_migratable_lockres *mres =
  1176. (struct dlm_migratable_lockres *)msg->buf;
  1177. int ret = 0;
  1178. u8 real_master;
  1179. char *buf = NULL;
  1180. struct dlm_work_item *item = NULL;
  1181. struct dlm_lock_resource *res = NULL;
  1182. if (!dlm_grab(dlm))
  1183. return -EINVAL;
  1184. BUG_ON(!(mres->flags & (DLM_MRES_RECOVERY|DLM_MRES_MIGRATION)));
  1185. real_master = mres->master;
  1186. if (real_master == DLM_LOCK_RES_OWNER_UNKNOWN) {
  1187. /* cannot migrate a lockres with no master */
  1188. BUG_ON(!(mres->flags & DLM_MRES_RECOVERY));
  1189. }
  1190. mlog(0, "%s message received from node %u\n",
  1191. (mres->flags & DLM_MRES_RECOVERY) ?
  1192. "recovery" : "migration", mres->master);
  1193. if (mres->flags & DLM_MRES_ALL_DONE)
  1194. mlog(0, "all done flag. all lockres data received!\n");
  1195. ret = -ENOMEM;
  1196. buf = kmalloc(be16_to_cpu(msg->data_len), GFP_NOFS);
  1197. item = kzalloc(sizeof(*item), GFP_NOFS);
  1198. if (!buf || !item)
  1199. goto leave;
  1200. /* lookup the lock to see if we have a secondary queue for this
  1201. * already... just add the locks in and this will have its owner
  1202. * and RECOVERY flag changed when it completes. */
  1203. res = dlm_lookup_lockres(dlm, mres->lockname, mres->lockname_len);
  1204. if (res) {
  1205. /* this will get a ref on res */
  1206. /* mark it as recovering/migrating and hash it */
  1207. spin_lock(&res->spinlock);
  1208. if (mres->flags & DLM_MRES_RECOVERY) {
  1209. res->state |= DLM_LOCK_RES_RECOVERING;
  1210. } else {
  1211. if (res->state & DLM_LOCK_RES_MIGRATING) {
  1212. /* this is at least the second
  1213. * lockres message */
  1214. mlog(0, "lock %.*s is already migrating\n",
  1215. mres->lockname_len,
  1216. mres->lockname);
  1217. } else if (res->state & DLM_LOCK_RES_RECOVERING) {
  1218. /* caller should BUG */
  1219. mlog(ML_ERROR, "node is attempting to migrate "
  1220. "lock %.*s, but marked as recovering!\n",
  1221. mres->lockname_len, mres->lockname);
  1222. ret = -EFAULT;
  1223. spin_unlock(&res->spinlock);
  1224. goto leave;
  1225. }
  1226. res->state |= DLM_LOCK_RES_MIGRATING;
  1227. }
  1228. spin_unlock(&res->spinlock);
  1229. } else {
  1230. /* need to allocate, just like if it was
  1231. * mastered here normally */
  1232. res = dlm_new_lockres(dlm, mres->lockname, mres->lockname_len);
  1233. if (!res)
  1234. goto leave;
  1235. /* to match the ref that we would have gotten if
  1236. * dlm_lookup_lockres had succeeded */
  1237. dlm_lockres_get(res);
  1238. /* mark it as recovering/migrating and hash it */
  1239. if (mres->flags & DLM_MRES_RECOVERY)
  1240. res->state |= DLM_LOCK_RES_RECOVERING;
  1241. else
  1242. res->state |= DLM_LOCK_RES_MIGRATING;
  1243. spin_lock(&dlm->spinlock);
  1244. __dlm_insert_lockres(dlm, res);
  1245. spin_unlock(&dlm->spinlock);
  1246. /* now that the new lockres is inserted,
  1247. * make it usable by other processes */
  1248. spin_lock(&res->spinlock);
  1249. res->state &= ~DLM_LOCK_RES_IN_PROGRESS;
  1250. spin_unlock(&res->spinlock);
  1251. wake_up(&res->wq);
  1252. /* add an extra ref for just-allocated lockres
  1253. * otherwise the lockres will be purged immediately */
  1254. dlm_lockres_get(res);
  1255. }
  1256. /* at this point we have allocated everything we need,
  1257. * and we have a hashed lockres with an extra ref and
  1258. * the proper res->state flags. */
  1259. ret = 0;
  1260. spin_lock(&res->spinlock);
  1261. /* drop this either when master requery finds a different master
  1262. * or when a lock is added by the recovery worker */
  1263. dlm_lockres_grab_inflight_ref(dlm, res);
  1264. if (mres->master == DLM_LOCK_RES_OWNER_UNKNOWN) {
  1265. /* migration cannot have an unknown master */
  1266. BUG_ON(!(mres->flags & DLM_MRES_RECOVERY));
  1267. mlog(0, "recovery has passed me a lockres with an "
  1268. "unknown owner.. will need to requery: "
  1269. "%.*s\n", mres->lockname_len, mres->lockname);
  1270. } else {
  1271. /* take a reference now to pin the lockres, drop it
  1272. * when locks are added in the worker */
  1273. dlm_change_lockres_owner(dlm, res, dlm->node_num);
  1274. }
  1275. spin_unlock(&res->spinlock);
  1276. /* queue up work for dlm_mig_lockres_worker */
  1277. dlm_grab(dlm); /* get an extra ref for the work item */
  1278. memcpy(buf, msg->buf, be16_to_cpu(msg->data_len)); /* copy the whole message */
  1279. dlm_init_work_item(dlm, item, dlm_mig_lockres_worker, buf);
  1280. item->u.ml.lockres = res; /* already have a ref */
  1281. item->u.ml.real_master = real_master;
  1282. spin_lock(&dlm->work_lock);
  1283. list_add_tail(&item->list, &dlm->work_list);
  1284. spin_unlock(&dlm->work_lock);
  1285. queue_work(dlm->dlm_worker, &dlm->dispatched_work);
  1286. leave:
  1287. dlm_put(dlm);
  1288. if (ret < 0) {
  1289. if (buf)
  1290. kfree(buf);
  1291. if (item)
  1292. kfree(item);
  1293. }
  1294. mlog_exit(ret);
  1295. return ret;
  1296. }
  1297. static void dlm_mig_lockres_worker(struct dlm_work_item *item, void *data)
  1298. {
  1299. struct dlm_ctxt *dlm = data;
  1300. struct dlm_migratable_lockres *mres;
  1301. int ret = 0;
  1302. struct dlm_lock_resource *res;
  1303. u8 real_master;
  1304. dlm = item->dlm;
  1305. mres = (struct dlm_migratable_lockres *)data;
  1306. res = item->u.ml.lockres;
  1307. real_master = item->u.ml.real_master;
  1308. if (real_master == DLM_LOCK_RES_OWNER_UNKNOWN) {
  1309. /* this case is super-rare. only occurs if
  1310. * node death happens during migration. */
  1311. again:
  1312. ret = dlm_lockres_master_requery(dlm, res, &real_master);
  1313. if (ret < 0) {
  1314. mlog(0, "dlm_lockres_master_requery ret=%d\n",
  1315. ret);
  1316. goto again;
  1317. }
  1318. if (real_master == DLM_LOCK_RES_OWNER_UNKNOWN) {
  1319. mlog(0, "lockres %.*s not claimed. "
  1320. "this node will take it.\n",
  1321. res->lockname.len, res->lockname.name);
  1322. } else {
  1323. spin_lock(&res->spinlock);
  1324. dlm_lockres_drop_inflight_ref(dlm, res);
  1325. spin_unlock(&res->spinlock);
  1326. mlog(0, "master needs to respond to sender "
  1327. "that node %u still owns %.*s\n",
  1328. real_master, res->lockname.len,
  1329. res->lockname.name);
  1330. /* cannot touch this lockres */
  1331. goto leave;
  1332. }
  1333. }
  1334. ret = dlm_process_recovery_data(dlm, res, mres);
  1335. if (ret < 0)
  1336. mlog(0, "dlm_process_recovery_data returned %d\n", ret);
  1337. else
  1338. mlog(0, "dlm_process_recovery_data succeeded\n");
  1339. if ((mres->flags & (DLM_MRES_MIGRATION|DLM_MRES_ALL_DONE)) ==
  1340. (DLM_MRES_MIGRATION|DLM_MRES_ALL_DONE)) {
  1341. ret = dlm_finish_migration(dlm, res, mres->master);
  1342. if (ret < 0)
  1343. mlog_errno(ret);
  1344. }
  1345. leave:
  1346. kfree(data);
  1347. mlog_exit(ret);
  1348. }
  1349. static int dlm_lockres_master_requery(struct dlm_ctxt *dlm,
  1350. struct dlm_lock_resource *res,
  1351. u8 *real_master)
  1352. {
  1353. struct dlm_node_iter iter;
  1354. int nodenum;
  1355. int ret = 0;
  1356. *real_master = DLM_LOCK_RES_OWNER_UNKNOWN;
  1357. /* we only reach here if one of the two nodes in a
  1358. * migration died while the migration was in progress.
  1359. * at this point we need to requery the master. we
  1360. * know that the new_master got as far as creating
  1361. * an mle on at least one node, but we do not know
  1362. * if any nodes had actually cleared the mle and set
  1363. * the master to the new_master. the old master
  1364. * is supposed to set the owner to UNKNOWN in the
  1365. * event of a new_master death, so the only possible
  1366. * responses that we can get from nodes here are
  1367. * that the master is new_master, or that the master
  1368. * is UNKNOWN.
  1369. * if all nodes come back with UNKNOWN then we know
  1370. * the lock needs remastering here.
  1371. * if any node comes back with a valid master, check
  1372. * to see if that master is the one that we are
  1373. * recovering. if so, then the new_master died and
  1374. * we need to remaster this lock. if not, then the
  1375. * new_master survived and that node will respond to
  1376. * other nodes about the owner.
  1377. * if there is an owner, this node needs to dump this
  1378. * lockres and alert the sender that this lockres
  1379. * was rejected. */
  1380. spin_lock(&dlm->spinlock);
  1381. dlm_node_iter_init(dlm->domain_map, &iter);
  1382. spin_unlock(&dlm->spinlock);
  1383. while ((nodenum = dlm_node_iter_next(&iter)) >= 0) {
  1384. /* do not send to self */
  1385. if (nodenum == dlm->node_num)
  1386. continue;
  1387. ret = dlm_do_master_requery(dlm, res, nodenum, real_master);
  1388. if (ret < 0) {
  1389. mlog_errno(ret);
  1390. if (!dlm_is_host_down(ret))
  1391. BUG();
  1392. /* host is down, so answer for that node would be
  1393. * DLM_LOCK_RES_OWNER_UNKNOWN. continue. */
  1394. }
  1395. if (*real_master != DLM_LOCK_RES_OWNER_UNKNOWN) {
  1396. mlog(0, "lock master is %u\n", *real_master);
  1397. break;
  1398. }
  1399. }
  1400. return ret;
  1401. }
  1402. int dlm_do_master_requery(struct dlm_ctxt *dlm, struct dlm_lock_resource *res,
  1403. u8 nodenum, u8 *real_master)
  1404. {
  1405. int ret = -EINVAL;
  1406. struct dlm_master_requery req;
  1407. int status = DLM_LOCK_RES_OWNER_UNKNOWN;
  1408. memset(&req, 0, sizeof(req));
  1409. req.node_idx = dlm->node_num;
  1410. req.namelen = res->lockname.len;
  1411. memcpy(req.name, res->lockname.name, res->lockname.len);
  1412. ret = o2net_send_message(DLM_MASTER_REQUERY_MSG, dlm->key,
  1413. &req, sizeof(req), nodenum, &status);
  1414. /* XXX: negative status not handled properly here. */
  1415. if (ret < 0)
  1416. mlog_errno(ret);
  1417. else {
  1418. BUG_ON(status < 0);
  1419. BUG_ON(status > DLM_LOCK_RES_OWNER_UNKNOWN);
  1420. *real_master = (u8) (status & 0xff);
  1421. mlog(0, "node %u responded to master requery with %u\n",
  1422. nodenum, *real_master);
  1423. ret = 0;
  1424. }
  1425. return ret;
  1426. }
  1427. /* this function cannot error, so unless the sending
  1428. * or receiving of the message failed, the owner can
  1429. * be trusted */
  1430. int dlm_master_requery_handler(struct o2net_msg *msg, u32 len, void *data,
  1431. void **ret_data)
  1432. {
  1433. struct dlm_ctxt *dlm = data;
  1434. struct dlm_master_requery *req = (struct dlm_master_requery *)msg->buf;
  1435. struct dlm_lock_resource *res = NULL;
  1436. unsigned int hash;
  1437. int master = DLM_LOCK_RES_OWNER_UNKNOWN;
  1438. u32 flags = DLM_ASSERT_MASTER_REQUERY;
  1439. if (!dlm_grab(dlm)) {
  1440. /* since the domain has gone away on this
  1441. * node, the proper response is UNKNOWN */
  1442. return master;
  1443. }
  1444. hash = dlm_lockid_hash(req->name, req->namelen);
  1445. spin_lock(&dlm->spinlock);
  1446. res = __dlm_lookup_lockres(dlm, req->name, req->namelen, hash);
  1447. if (res) {
  1448. spin_lock(&res->spinlock);
  1449. master = res->owner;
  1450. if (master == dlm->node_num) {
  1451. int ret = dlm_dispatch_assert_master(dlm, res,
  1452. 0, 0, flags);
  1453. if (ret < 0) {
  1454. mlog_errno(-ENOMEM);
  1455. /* retry!? */
  1456. BUG();
  1457. }
  1458. }
  1459. spin_unlock(&res->spinlock);
  1460. }
  1461. spin_unlock(&dlm->spinlock);
  1462. dlm_put(dlm);
  1463. return master;
  1464. }
  1465. static inline struct list_head *
  1466. dlm_list_num_to_pointer(struct dlm_lock_resource *res, int list_num)
  1467. {
  1468. struct list_head *ret;
  1469. BUG_ON(list_num < 0);
  1470. BUG_ON(list_num > 2);
  1471. ret = &(res->granted);
  1472. ret += list_num;
  1473. return ret;
  1474. }
  1475. /* TODO: do ast flush business
  1476. * TODO: do MIGRATING and RECOVERING spinning
  1477. */
  1478. /*
  1479. * NOTE about in-flight requests during migration:
  1480. *
  1481. * Before attempting the migrate, the master has marked the lockres as
  1482. * MIGRATING and then flushed all of its pending ASTS. So any in-flight
  1483. * requests either got queued before the MIGRATING flag got set, in which
  1484. * case the lock data will reflect the change and a return message is on
  1485. * the way, or the request failed to get in before MIGRATING got set. In
  1486. * this case, the caller will be told to spin and wait for the MIGRATING
  1487. * flag to be dropped, then recheck the master.
  1488. * This holds true for the convert, cancel and unlock cases, and since lvb
  1489. * updates are tied to these same messages, it applies to lvb updates as
  1490. * well. For the lock case, there is no way a lock can be on the master
  1491. * queue and not be on the secondary queue since the lock is always added
  1492. * locally first. This means that the new target node will never be sent
  1493. * a lock that he doesn't already have on the list.
  1494. * In total, this means that the local lock is correct and should not be
  1495. * updated to match the one sent by the master. Any messages sent back
  1496. * from the master before the MIGRATING flag will bring the lock properly
  1497. * up-to-date, and the change will be ordered properly for the waiter.
  1498. * We will *not* attempt to modify the lock underneath the waiter.
  1499. */
  1500. static int dlm_process_recovery_data(struct dlm_ctxt *dlm,
  1501. struct dlm_lock_resource *res,
  1502. struct dlm_migratable_lockres *mres)
  1503. {
  1504. struct dlm_migratable_lock *ml;
  1505. struct list_head *queue;
  1506. struct list_head *tmpq = NULL;
  1507. struct dlm_lock *newlock = NULL;
  1508. struct dlm_lockstatus *lksb = NULL;
  1509. int ret = 0;
  1510. int i, j, bad;
  1511. struct list_head *iter;
  1512. struct dlm_lock *lock = NULL;
  1513. u8 from = O2NM_MAX_NODES;
  1514. unsigned int added = 0;
  1515. mlog(0, "running %d locks for this lockres\n", mres->num_locks);
  1516. for (i=0; i<mres->num_locks; i++) {
  1517. ml = &(mres->ml[i]);
  1518. if (dlm_is_dummy_lock(dlm, ml, &from)) {
  1519. /* placeholder, just need to set the refmap bit */
  1520. BUG_ON(mres->num_locks != 1);
  1521. mlog(0, "%s:%.*s: dummy lock for %u\n",
  1522. dlm->name, mres->lockname_len, mres->lockname,
  1523. from);
  1524. spin_lock(&res->spinlock);
  1525. dlm_lockres_set_refmap_bit(from, res);
  1526. spin_unlock(&res->spinlock);
  1527. added++;
  1528. break;
  1529. }
  1530. BUG_ON(ml->highest_blocked != LKM_IVMODE);
  1531. newlock = NULL;
  1532. lksb = NULL;
  1533. queue = dlm_list_num_to_pointer(res, ml->list);
  1534. tmpq = NULL;
  1535. /* if the lock is for the local node it needs to
  1536. * be moved to the proper location within the queue.
  1537. * do not allocate a new lock structure. */
  1538. if (ml->node == dlm->node_num) {
  1539. /* MIGRATION ONLY! */
  1540. BUG_ON(!(mres->flags & DLM_MRES_MIGRATION));
  1541. spin_lock(&res->spinlock);
  1542. for (j = DLM_GRANTED_LIST; j <= DLM_BLOCKED_LIST; j++) {
  1543. tmpq = dlm_list_idx_to_ptr(res, j);
  1544. list_for_each(iter, tmpq) {
  1545. lock = list_entry (iter, struct dlm_lock, list);
  1546. if (lock->ml.cookie != ml->cookie)
  1547. lock = NULL;
  1548. else
  1549. break;
  1550. }
  1551. if (lock)
  1552. break;
  1553. }
  1554. /* lock is always created locally first, and
  1555. * destroyed locally last. it must be on the list */
  1556. if (!lock) {
  1557. __be64 c = ml->cookie;
  1558. mlog(ML_ERROR, "could not find local lock "
  1559. "with cookie %u:%llu!\n",
  1560. dlm_get_lock_cookie_node(be64_to_cpu(c)),
  1561. dlm_get_lock_cookie_seq(be64_to_cpu(c)));
  1562. __dlm_print_one_lock_resource(res);
  1563. BUG();
  1564. }
  1565. BUG_ON(lock->ml.node != ml->node);
  1566. if (tmpq != queue) {
  1567. mlog(0, "lock was on %u instead of %u for %.*s\n",
  1568. j, ml->list, res->lockname.len, res->lockname.name);
  1569. spin_unlock(&res->spinlock);
  1570. continue;
  1571. }
  1572. /* see NOTE above about why we do not update
  1573. * to match the master here */
  1574. /* move the lock to its proper place */
  1575. /* do not alter lock refcount. switching lists. */
  1576. list_move_tail(&lock->list, queue);
  1577. spin_unlock(&res->spinlock);
  1578. added++;
  1579. mlog(0, "just reordered a local lock!\n");
  1580. continue;
  1581. }
  1582. /* lock is for another node. */
  1583. newlock = dlm_new_lock(ml->type, ml->node,
  1584. be64_to_cpu(ml->cookie), NULL);
  1585. if (!newlock) {
  1586. ret = -ENOMEM;
  1587. goto leave;
  1588. }
  1589. lksb = newlock->lksb;
  1590. dlm_lock_attach_lockres(newlock, res);
  1591. if (ml->convert_type != LKM_IVMODE) {
  1592. BUG_ON(queue != &res->converting);
  1593. newlock->ml.convert_type = ml->convert_type;
  1594. }
  1595. lksb->flags |= (ml->flags &
  1596. (DLM_LKSB_PUT_LVB|DLM_LKSB_GET_LVB));
  1597. if (ml->type == LKM_NLMODE)
  1598. goto skip_lvb;
  1599. if (!dlm_lvb_is_empty(mres->lvb)) {
  1600. if (lksb->flags & DLM_LKSB_PUT_LVB) {
  1601. /* other node was trying to update
  1602. * lvb when node died. recreate the
  1603. * lksb with the updated lvb. */
  1604. memcpy(lksb->lvb, mres->lvb, DLM_LVB_LEN);
  1605. /* the lock resource lvb update must happen
  1606. * NOW, before the spinlock is dropped.
  1607. * we no longer wait for the AST to update
  1608. * the lvb. */
  1609. memcpy(res->lvb, mres->lvb, DLM_LVB_LEN);
  1610. } else {
  1611. /* otherwise, the node is sending its
  1612. * most recent valid lvb info */
  1613. BUG_ON(ml->type != LKM_EXMODE &&
  1614. ml->type != LKM_PRMODE);
  1615. if (!dlm_lvb_is_empty(res->lvb) &&
  1616. (ml->type == LKM_EXMODE ||
  1617. memcmp(res->lvb, mres->lvb, DLM_LVB_LEN))) {
  1618. int i;
  1619. mlog(ML_ERROR, "%s:%.*s: received bad "
  1620. "lvb! type=%d\n", dlm->name,
  1621. res->lockname.len,
  1622. res->lockname.name, ml->type);
  1623. printk("lockres lvb=[");
  1624. for (i=0; i<DLM_LVB_LEN; i++)
  1625. printk("%02x", res->lvb[i]);
  1626. printk("]\nmigrated lvb=[");
  1627. for (i=0; i<DLM_LVB_LEN; i++)
  1628. printk("%02x", mres->lvb[i]);
  1629. printk("]\n");
  1630. dlm_print_one_lock_resource(res);
  1631. BUG();
  1632. }
  1633. memcpy(res->lvb, mres->lvb, DLM_LVB_LEN);
  1634. }
  1635. }
  1636. skip_lvb:
  1637. /* NOTE:
  1638. * wrt lock queue ordering and recovery:
  1639. * 1. order of locks on granted queue is
  1640. * meaningless.
  1641. * 2. order of locks on converting queue is
  1642. * LOST with the node death. sorry charlie.
  1643. * 3. order of locks on the blocked queue is
  1644. * also LOST.
  1645. * order of locks does not affect integrity, it
  1646. * just means that a lock request may get pushed
  1647. * back in line as a result of the node death.
  1648. * also note that for a given node the lock order
  1649. * for its secondary queue locks is preserved
  1650. * relative to each other, but clearly *not*
  1651. * preserved relative to locks from other nodes.
  1652. */
  1653. bad = 0;
  1654. spin_lock(&res->spinlock);
  1655. list_for_each_entry(lock, queue, list) {
  1656. if (lock->ml.cookie == ml->cookie) {
  1657. __be64 c = lock->ml.cookie;
  1658. mlog(ML_ERROR, "%s:%.*s: %u:%llu: lock already "
  1659. "exists on this lockres!\n", dlm->name,
  1660. res->lockname.len, res->lockname.name,
  1661. dlm_get_lock_cookie_node(be64_to_cpu(c)),
  1662. dlm_get_lock_cookie_seq(be64_to_cpu(c)));
  1663. mlog(ML_NOTICE, "sent lock: type=%d, conv=%d, "
  1664. "node=%u, cookie=%u:%llu, queue=%d\n",
  1665. ml->type, ml->convert_type, ml->node,
  1666. dlm_get_lock_cookie_node(be64_to_cpu(ml->cookie)),
  1667. dlm_get_lock_cookie_seq(be64_to_cpu(ml->cookie)),
  1668. ml->list);
  1669. __dlm_print_one_lock_resource(res);
  1670. bad = 1;
  1671. break;
  1672. }
  1673. }
  1674. if (!bad) {
  1675. dlm_lock_get(newlock);
  1676. list_add_tail(&newlock->list, queue);
  1677. mlog(0, "%s:%.*s: added lock for node %u, "
  1678. "setting refmap bit\n", dlm->name,
  1679. res->lockname.len, res->lockname.name, ml->node);
  1680. dlm_lockres_set_refmap_bit(ml->node, res);
  1681. added++;
  1682. }
  1683. spin_unlock(&res->spinlock);
  1684. }
  1685. mlog(0, "done running all the locks\n");
  1686. leave:
  1687. /* balance the ref taken when the work was queued */
  1688. spin_lock(&res->spinlock);
  1689. dlm_lockres_drop_inflight_ref(dlm, res);
  1690. spin_unlock(&res->spinlock);
  1691. if (ret < 0) {
  1692. mlog_errno(ret);
  1693. if (newlock)
  1694. dlm_lock_put(newlock);
  1695. }
  1696. mlog_exit(ret);
  1697. return ret;
  1698. }
  1699. void dlm_move_lockres_to_recovery_list(struct dlm_ctxt *dlm,
  1700. struct dlm_lock_resource *res)
  1701. {
  1702. int i;
  1703. struct list_head *queue, *iter, *iter2;
  1704. struct dlm_lock *lock;
  1705. res->state |= DLM_LOCK_RES_RECOVERING;
  1706. if (!list_empty(&res->recovering)) {
  1707. mlog(0,
  1708. "Recovering res %s:%.*s, is already on recovery list!\n",
  1709. dlm->name, res->lockname.len, res->lockname.name);
  1710. list_del_init(&res->recovering);
  1711. }
  1712. /* We need to hold a reference while on the recovery list */
  1713. dlm_lockres_get(res);
  1714. list_add_tail(&res->recovering, &dlm->reco.resources);
  1715. /* find any pending locks and put them back on proper list */
  1716. for (i=DLM_BLOCKED_LIST; i>=DLM_GRANTED_LIST; i--) {
  1717. queue = dlm_list_idx_to_ptr(res, i);
  1718. list_for_each_safe(iter, iter2, queue) {
  1719. lock = list_entry (iter, struct dlm_lock, list);
  1720. dlm_lock_get(lock);
  1721. if (lock->convert_pending) {
  1722. /* move converting lock back to granted */
  1723. BUG_ON(i != DLM_CONVERTING_LIST);
  1724. mlog(0, "node died with convert pending "
  1725. "on %.*s. move back to granted list.\n",
  1726. res->lockname.len, res->lockname.name);
  1727. dlm_revert_pending_convert(res, lock);
  1728. lock->convert_pending = 0;
  1729. } else if (lock->lock_pending) {
  1730. /* remove pending lock requests completely */
  1731. BUG_ON(i != DLM_BLOCKED_LIST);
  1732. mlog(0, "node died with lock pending "
  1733. "on %.*s. remove from blocked list and skip.\n",
  1734. res->lockname.len, res->lockname.name);
  1735. /* lock will be floating until ref in
  1736. * dlmlock_remote is freed after the network
  1737. * call returns. ok for it to not be on any
  1738. * list since no ast can be called
  1739. * (the master is dead). */
  1740. dlm_revert_pending_lock(res, lock);
  1741. lock->lock_pending = 0;
  1742. } else if (lock->unlock_pending) {
  1743. /* if an unlock was in progress, treat as
  1744. * if this had completed successfully
  1745. * before sending this lock state to the
  1746. * new master. note that the dlm_unlock
  1747. * call is still responsible for calling
  1748. * the unlockast. that will happen after
  1749. * the network call times out. for now,
  1750. * just move lists to prepare the new
  1751. * recovery master. */
  1752. BUG_ON(i != DLM_GRANTED_LIST);
  1753. mlog(0, "node died with unlock pending "
  1754. "on %.*s. remove from blocked list and skip.\n",
  1755. res->lockname.len, res->lockname.name);
  1756. dlm_commit_pending_unlock(res, lock);
  1757. lock->unlock_pending = 0;
  1758. } else if (lock->cancel_pending) {
  1759. /* if a cancel was in progress, treat as
  1760. * if this had completed successfully
  1761. * before sending this lock state to the
  1762. * new master */
  1763. BUG_ON(i != DLM_CONVERTING_LIST);
  1764. mlog(0, "node died with cancel pending "
  1765. "on %.*s. move back to granted list.\n",
  1766. res->lockname.len, res->lockname.name);
  1767. dlm_commit_pending_cancel(res, lock);
  1768. lock->cancel_pending = 0;
  1769. }
  1770. dlm_lock_put(lock);
  1771. }
  1772. }
  1773. }
  1774. /* removes all recovered locks from the recovery list.
  1775. * sets the res->owner to the new master.
  1776. * unsets the RECOVERY flag and wakes waiters. */
  1777. static void dlm_finish_local_lockres_recovery(struct dlm_ctxt *dlm,
  1778. u8 dead_node, u8 new_master)
  1779. {
  1780. int i;
  1781. struct list_head *iter, *iter2;
  1782. struct hlist_node *hash_iter;
  1783. struct hlist_head *bucket;
  1784. struct dlm_lock_resource *res;
  1785. mlog_entry_void();
  1786. assert_spin_locked(&dlm->spinlock);
  1787. list_for_each_safe(iter, iter2, &dlm->reco.resources) {
  1788. res = list_entry (iter, struct dlm_lock_resource, recovering);
  1789. if (res->owner == dead_node) {
  1790. list_del_init(&res->recovering);
  1791. spin_lock(&res->spinlock);
  1792. /* new_master has our reference from
  1793. * the lock state sent during recovery */
  1794. dlm_change_lockres_owner(dlm, res, new_master);
  1795. res->state &= ~DLM_LOCK_RES_RECOVERING;
  1796. if (__dlm_lockres_has_locks(res))
  1797. __dlm_dirty_lockres(dlm, res);
  1798. spin_unlock(&res->spinlock);
  1799. wake_up(&res->wq);
  1800. dlm_lockres_put(res);
  1801. }
  1802. }
  1803. /* this will become unnecessary eventually, but
  1804. * for now we need to run the whole hash, clear
  1805. * the RECOVERING state and set the owner
  1806. * if necessary */
  1807. for (i = 0; i < DLM_HASH_BUCKETS; i++) {
  1808. bucket = dlm_lockres_hash(dlm, i);
  1809. hlist_for_each_entry(res, hash_iter, bucket, hash_node) {
  1810. if (res->state & DLM_LOCK_RES_RECOVERING) {
  1811. if (res->owner == dead_node) {
  1812. mlog(0, "(this=%u) res %.*s owner=%u "
  1813. "was not on recovering list, but "
  1814. "clearing state anyway\n",
  1815. dlm->node_num, res->lockname.len,
  1816. res->lockname.name, new_master);
  1817. } else if (res->owner == dlm->node_num) {
  1818. mlog(0, "(this=%u) res %.*s owner=%u "
  1819. "was not on recovering list, "
  1820. "owner is THIS node, clearing\n",
  1821. dlm->node_num, res->lockname.len,
  1822. res->lockname.name, new_master);
  1823. } else
  1824. continue;
  1825. if (!list_empty(&res->recovering)) {
  1826. mlog(0, "%s:%.*s: lockres was "
  1827. "marked RECOVERING, owner=%u\n",
  1828. dlm->name, res->lockname.len,
  1829. res->lockname.name, res->owner);
  1830. list_del_init(&res->recovering);
  1831. dlm_lockres_put(res);
  1832. }
  1833. spin_lock(&res->spinlock);
  1834. /* new_master has our reference from
  1835. * the lock state sent during recovery */
  1836. dlm_change_lockres_owner(dlm, res, new_master);
  1837. res->state &= ~DLM_LOCK_RES_RECOVERING;
  1838. if (__dlm_lockres_has_locks(res))
  1839. __dlm_dirty_lockres(dlm, res);
  1840. spin_unlock(&res->spinlock);
  1841. wake_up(&res->wq);
  1842. }
  1843. }
  1844. }
  1845. }
  1846. static inline int dlm_lvb_needs_invalidation(struct dlm_lock *lock, int local)
  1847. {
  1848. if (local) {
  1849. if (lock->ml.type != LKM_EXMODE &&
  1850. lock->ml.type != LKM_PRMODE)
  1851. return 1;
  1852. } else if (lock->ml.type == LKM_EXMODE)
  1853. return 1;
  1854. return 0;
  1855. }
  1856. static void dlm_revalidate_lvb(struct dlm_ctxt *dlm,
  1857. struct dlm_lock_resource *res, u8 dead_node)
  1858. {
  1859. struct list_head *iter, *queue;
  1860. struct dlm_lock *lock;
  1861. int blank_lvb = 0, local = 0;
  1862. int i;
  1863. u8 search_node;
  1864. assert_spin_locked(&dlm->spinlock);
  1865. assert_spin_locked(&res->spinlock);
  1866. if (res->owner == dlm->node_num)
  1867. /* if this node owned the lockres, and if the dead node
  1868. * had an EX when he died, blank out the lvb */
  1869. search_node = dead_node;
  1870. else {
  1871. /* if this is a secondary lockres, and we had no EX or PR
  1872. * locks granted, we can no longer trust the lvb */
  1873. search_node = dlm->node_num;
  1874. local = 1; /* check local state for valid lvb */
  1875. }
  1876. for (i=DLM_GRANTED_LIST; i<=DLM_CONVERTING_LIST; i++) {
  1877. queue = dlm_list_idx_to_ptr(res, i);
  1878. list_for_each(iter, queue) {
  1879. lock = list_entry (iter, struct dlm_lock, list);
  1880. if (lock->ml.node == search_node) {
  1881. if (dlm_lvb_needs_invalidation(lock, local)) {
  1882. /* zero the lksb lvb and lockres lvb */
  1883. blank_lvb = 1;
  1884. memset(lock->lksb->lvb, 0, DLM_LVB_LEN);
  1885. }
  1886. }
  1887. }
  1888. }
  1889. if (blank_lvb) {
  1890. mlog(0, "clearing %.*s lvb, dead node %u had EX\n",
  1891. res->lockname.len, res->lockname.name, dead_node);
  1892. memset(res->lvb, 0, DLM_LVB_LEN);
  1893. }
  1894. }
  1895. static void dlm_free_dead_locks(struct dlm_ctxt *dlm,
  1896. struct dlm_lock_resource *res, u8 dead_node)
  1897. {
  1898. struct list_head *iter, *tmpiter;
  1899. struct dlm_lock *lock;
  1900. unsigned int freed = 0;
  1901. /* this node is the lockres master:
  1902. * 1) remove any stale locks for the dead node
  1903. * 2) if the dead node had an EX when he died, blank out the lvb
  1904. */
  1905. assert_spin_locked(&dlm->spinlock);
  1906. assert_spin_locked(&res->spinlock);
  1907. /* TODO: check pending_asts, pending_basts here */
  1908. list_for_each_safe(iter, tmpiter, &res->granted) {
  1909. lock = list_entry (iter, struct dlm_lock, list);
  1910. if (lock->ml.node == dead_node) {
  1911. list_del_init(&lock->list);
  1912. dlm_lock_put(lock);
  1913. freed++;
  1914. }
  1915. }
  1916. list_for_each_safe(iter, tmpiter, &res->converting) {
  1917. lock = list_entry (iter, struct dlm_lock, list);
  1918. if (lock->ml.node == dead_node) {
  1919. list_del_init(&lock->list);
  1920. dlm_lock_put(lock);
  1921. freed++;
  1922. }
  1923. }
  1924. list_for_each_safe(iter, tmpiter, &res->blocked) {
  1925. lock = list_entry (iter, struct dlm_lock, list);
  1926. if (lock->ml.node == dead_node) {
  1927. list_del_init(&lock->list);
  1928. dlm_lock_put(lock);
  1929. freed++;
  1930. }
  1931. }
  1932. if (freed) {
  1933. mlog(0, "%s:%.*s: freed %u locks for dead node %u, "
  1934. "dropping ref from lockres\n", dlm->name,
  1935. res->lockname.len, res->lockname.name, freed, dead_node);
  1936. BUG_ON(!test_bit(dead_node, res->refmap));
  1937. dlm_lockres_clear_refmap_bit(dead_node, res);
  1938. } else if (test_bit(dead_node, res->refmap)) {
  1939. mlog(0, "%s:%.*s: dead node %u had a ref, but had "
  1940. "no locks and had not purged before dying\n", dlm->name,
  1941. res->lockname.len, res->lockname.name, dead_node);
  1942. dlm_lockres_clear_refmap_bit(dead_node, res);
  1943. }
  1944. /* do not kick thread yet */
  1945. __dlm_dirty_lockres(dlm, res);
  1946. }
  1947. /* if this node is the recovery master, and there are no
  1948. * locks for a given lockres owned by this node that are in
  1949. * either PR or EX mode, zero out the lvb before requesting.
  1950. *
  1951. */
  1952. static void dlm_do_local_recovery_cleanup(struct dlm_ctxt *dlm, u8 dead_node)
  1953. {
  1954. struct hlist_node *iter;
  1955. struct dlm_lock_resource *res;
  1956. int i;
  1957. struct hlist_head *bucket;
  1958. struct dlm_lock *lock;
  1959. /* purge any stale mles */
  1960. dlm_clean_master_list(dlm, dead_node);
  1961. /*
  1962. * now clean up all lock resources. there are two rules:
  1963. *
  1964. * 1) if the dead node was the master, move the lockres
  1965. * to the recovering list. set the RECOVERING flag.
  1966. * this lockres needs to be cleaned up before it can
  1967. * be used further.
  1968. *
  1969. * 2) if this node was the master, remove all locks from
  1970. * each of the lockres queues that were owned by the
  1971. * dead node. once recovery finishes, the dlm thread
  1972. * can be kicked again to see if any ASTs or BASTs
  1973. * need to be fired as a result.
  1974. */
  1975. for (i = 0; i < DLM_HASH_BUCKETS; i++) {
  1976. bucket = dlm_lockres_hash(dlm, i);
  1977. hlist_for_each_entry(res, iter, bucket, hash_node) {
  1978. /* always prune any $RECOVERY entries for dead nodes,
  1979. * otherwise hangs can occur during later recovery */
  1980. if (dlm_is_recovery_lock(res->lockname.name,
  1981. res->lockname.len)) {
  1982. spin_lock(&res->spinlock);
  1983. list_for_each_entry(lock, &res->granted, list) {
  1984. if (lock->ml.node == dead_node) {
  1985. mlog(0, "AHA! there was "
  1986. "a $RECOVERY lock for dead "
  1987. "node %u (%s)!\n",
  1988. dead_node, dlm->name);
  1989. list_del_init(&lock->list);
  1990. dlm_lock_put(lock);
  1991. break;
  1992. }
  1993. }
  1994. spin_unlock(&res->spinlock);
  1995. continue;
  1996. }
  1997. spin_lock(&res->spinlock);
  1998. /* zero the lvb if necessary */
  1999. dlm_revalidate_lvb(dlm, res, dead_node);
  2000. if (res->owner == dead_node) {
  2001. if (res->state & DLM_LOCK_RES_DROPPING_REF)
  2002. mlog(0, "%s:%.*s: owned by "
  2003. "dead node %u, this node was "
  2004. "dropping its ref when it died. "
  2005. "continue, dropping the flag.\n",
  2006. dlm->name, res->lockname.len,
  2007. res->lockname.name, dead_node);
  2008. /* the wake_up for this will happen when the
  2009. * RECOVERING flag is dropped later */
  2010. res->state &= ~DLM_LOCK_RES_DROPPING_REF;
  2011. dlm_move_lockres_to_recovery_list(dlm, res);
  2012. } else if (res->owner == dlm->node_num) {
  2013. dlm_free_dead_locks(dlm, res, dead_node);
  2014. __dlm_lockres_calc_usage(dlm, res);
  2015. }
  2016. spin_unlock(&res->spinlock);
  2017. }
  2018. }
  2019. }
  2020. static void __dlm_hb_node_down(struct dlm_ctxt *dlm, int idx)
  2021. {
  2022. assert_spin_locked(&dlm->spinlock);
  2023. if (dlm->reco.new_master == idx) {
  2024. mlog(0, "%s: recovery master %d just died\n",
  2025. dlm->name, idx);
  2026. if (dlm->reco.state & DLM_RECO_STATE_FINALIZE) {
  2027. /* finalize1 was reached, so it is safe to clear
  2028. * the new_master and dead_node. that recovery
  2029. * is complete. */
  2030. mlog(0, "%s: dead master %d had reached "
  2031. "finalize1 state, clearing\n", dlm->name, idx);
  2032. dlm->reco.state &= ~DLM_RECO_STATE_FINALIZE;
  2033. __dlm_reset_recovery(dlm);
  2034. }
  2035. }
  2036. /* check to see if the node is already considered dead */
  2037. if (!test_bit(idx, dlm->live_nodes_map)) {
  2038. mlog(0, "for domain %s, node %d is already dead. "
  2039. "another node likely did recovery already.\n",
  2040. dlm->name, idx);
  2041. return;
  2042. }
  2043. /* check to see if we do not care about this node */
  2044. if (!test_bit(idx, dlm->domain_map)) {
  2045. /* This also catches the case that we get a node down
  2046. * but haven't joined the domain yet. */
  2047. mlog(0, "node %u already removed from domain!\n", idx);
  2048. return;
  2049. }
  2050. clear_bit(idx, dlm->live_nodes_map);
  2051. /* Clean up join state on node death. */
  2052. if (dlm->joining_node == idx) {
  2053. mlog(0, "Clearing join state for node %u\n", idx);
  2054. __dlm_set_joining_node(dlm, DLM_LOCK_RES_OWNER_UNKNOWN);
  2055. }
  2056. /* make sure local cleanup occurs before the heartbeat events */
  2057. if (!test_bit(idx, dlm->recovery_map))
  2058. dlm_do_local_recovery_cleanup(dlm, idx);
  2059. /* notify anything attached to the heartbeat events */
  2060. dlm_hb_event_notify_attached(dlm, idx, 0);
  2061. mlog(0, "node %u being removed from domain map!\n", idx);
  2062. clear_bit(idx, dlm->domain_map);
  2063. /* wake up migration waiters if a node goes down.
  2064. * perhaps later we can genericize this for other waiters. */
  2065. wake_up(&dlm->migration_wq);
  2066. if (test_bit(idx, dlm->recovery_map))
  2067. mlog(0, "domain %s, node %u already added "
  2068. "to recovery map!\n", dlm->name, idx);
  2069. else
  2070. set_bit(idx, dlm->recovery_map);
  2071. }
  2072. void dlm_hb_node_down_cb(struct o2nm_node *node, int idx, void *data)
  2073. {
  2074. struct dlm_ctxt *dlm = data;
  2075. if (!dlm_grab(dlm))
  2076. return;
  2077. spin_lock(&dlm->spinlock);
  2078. __dlm_hb_node_down(dlm, idx);
  2079. spin_unlock(&dlm->spinlock);
  2080. dlm_put(dlm);
  2081. }
  2082. void dlm_hb_node_up_cb(struct o2nm_node *node, int idx, void *data)
  2083. {
  2084. struct dlm_ctxt *dlm = data;
  2085. if (!dlm_grab(dlm))
  2086. return;
  2087. spin_lock(&dlm->spinlock);
  2088. set_bit(idx, dlm->live_nodes_map);
  2089. /* do NOT notify mle attached to the heartbeat events.
  2090. * new nodes are not interesting in mastery until joined. */
  2091. spin_unlock(&dlm->spinlock);
  2092. dlm_put(dlm);
  2093. }
  2094. static void dlm_reco_ast(void *astdata)
  2095. {
  2096. struct dlm_ctxt *dlm = astdata;
  2097. mlog(0, "ast for recovery lock fired!, this=%u, dlm=%s\n",
  2098. dlm->node_num, dlm->name);
  2099. }
  2100. static void dlm_reco_bast(void *astdata, int blocked_type)
  2101. {
  2102. struct dlm_ctxt *dlm = astdata;
  2103. mlog(0, "bast for recovery lock fired!, this=%u, dlm=%s\n",
  2104. dlm->node_num, dlm->name);
  2105. }
  2106. static void dlm_reco_unlock_ast(void *astdata, enum dlm_status st)
  2107. {
  2108. mlog(0, "unlockast for recovery lock fired!\n");
  2109. }
  2110. /*
  2111. * dlm_pick_recovery_master will continually attempt to use
  2112. * dlmlock() on the special "$RECOVERY" lockres with the
  2113. * LKM_NOQUEUE flag to get an EX. every thread that enters
  2114. * this function on each node racing to become the recovery
  2115. * master will not stop attempting this until either:
  2116. * a) this node gets the EX (and becomes the recovery master),
  2117. * or b) dlm->reco.new_master gets set to some nodenum
  2118. * != O2NM_INVALID_NODE_NUM (another node will do the reco).
  2119. * so each time a recovery master is needed, the entire cluster
  2120. * will sync at this point. if the new master dies, that will
  2121. * be detected in dlm_do_recovery */
  2122. static int dlm_pick_recovery_master(struct dlm_ctxt *dlm)
  2123. {
  2124. enum dlm_status ret;
  2125. struct dlm_lockstatus lksb;
  2126. int status = -EINVAL;
  2127. mlog(0, "starting recovery of %s at %lu, dead=%u, this=%u\n",
  2128. dlm->name, jiffies, dlm->reco.dead_node, dlm->node_num);
  2129. again:
  2130. memset(&lksb, 0, sizeof(lksb));
  2131. ret = dlmlock(dlm, LKM_EXMODE, &lksb, LKM_NOQUEUE|LKM_RECOVERY,
  2132. DLM_RECOVERY_LOCK_NAME, DLM_RECOVERY_LOCK_NAME_LEN,
  2133. dlm_reco_ast, dlm, dlm_reco_bast);
  2134. mlog(0, "%s: dlmlock($RECOVERY) returned %d, lksb=%d\n",
  2135. dlm->name, ret, lksb.status);
  2136. if (ret == DLM_NORMAL) {
  2137. mlog(0, "dlm=%s dlmlock says I got it (this=%u)\n",
  2138. dlm->name, dlm->node_num);
  2139. /* got the EX lock. check to see if another node
  2140. * just became the reco master */
  2141. if (dlm_reco_master_ready(dlm)) {
  2142. mlog(0, "%s: got reco EX lock, but %u will "
  2143. "do the recovery\n", dlm->name,
  2144. dlm->reco.new_master);
  2145. status = -EEXIST;
  2146. } else {
  2147. status = 0;
  2148. /* see if recovery was already finished elsewhere */
  2149. spin_lock(&dlm->spinlock);
  2150. if (dlm->reco.dead_node == O2NM_INVALID_NODE_NUM) {
  2151. status = -EINVAL;
  2152. mlog(0, "%s: got reco EX lock, but "
  2153. "node got recovered already\n", dlm->name);
  2154. if (dlm->reco.new_master != O2NM_INVALID_NODE_NUM) {
  2155. mlog(ML_ERROR, "%s: new master is %u "
  2156. "but no dead node!\n",
  2157. dlm->name, dlm->reco.new_master);
  2158. BUG();
  2159. }
  2160. }
  2161. spin_unlock(&dlm->spinlock);
  2162. }
  2163. /* if this node has actually become the recovery master,
  2164. * set the master and send the messages to begin recovery */
  2165. if (!status) {
  2166. mlog(0, "%s: dead=%u, this=%u, sending "
  2167. "begin_reco now\n", dlm->name,
  2168. dlm->reco.dead_node, dlm->node_num);
  2169. status = dlm_send_begin_reco_message(dlm,
  2170. dlm->reco.dead_node);
  2171. /* this always succeeds */
  2172. BUG_ON(status);
  2173. /* set the new_master to this node */
  2174. spin_lock(&dlm->spinlock);
  2175. dlm_set_reco_master(dlm, dlm->node_num);
  2176. spin_unlock(&dlm->spinlock);
  2177. }
  2178. /* recovery lock is a special case. ast will not get fired,
  2179. * so just go ahead and unlock it. */
  2180. ret = dlmunlock(dlm, &lksb, 0, dlm_reco_unlock_ast, dlm);
  2181. if (ret == DLM_DENIED) {
  2182. mlog(0, "got DLM_DENIED, trying LKM_CANCEL\n");
  2183. ret = dlmunlock(dlm, &lksb, LKM_CANCEL, dlm_reco_unlock_ast, dlm);
  2184. }
  2185. if (ret != DLM_NORMAL) {
  2186. /* this would really suck. this could only happen
  2187. * if there was a network error during the unlock
  2188. * because of node death. this means the unlock
  2189. * is actually "done" and the lock structure is
  2190. * even freed. we can continue, but only
  2191. * because this specific lock name is special. */
  2192. mlog(ML_ERROR, "dlmunlock returned %d\n", ret);
  2193. }
  2194. } else if (ret == DLM_NOTQUEUED) {
  2195. mlog(0, "dlm=%s dlmlock says another node got it (this=%u)\n",
  2196. dlm->name, dlm->node_num);
  2197. /* another node is master. wait on
  2198. * reco.new_master != O2NM_INVALID_NODE_NUM
  2199. * for at most one second */
  2200. wait_event_timeout(dlm->dlm_reco_thread_wq,
  2201. dlm_reco_master_ready(dlm),
  2202. msecs_to_jiffies(1000));
  2203. if (!dlm_reco_master_ready(dlm)) {
  2204. mlog(0, "%s: reco master taking awhile\n",
  2205. dlm->name);
  2206. goto again;
  2207. }
  2208. /* another node has informed this one that it is reco master */
  2209. mlog(0, "%s: reco master %u is ready to recover %u\n",
  2210. dlm->name, dlm->reco.new_master, dlm->reco.dead_node);
  2211. status = -EEXIST;
  2212. } else if (ret == DLM_RECOVERING) {
  2213. mlog(0, "dlm=%s dlmlock says master node died (this=%u)\n",
  2214. dlm->name, dlm->node_num);
  2215. goto again;
  2216. } else {
  2217. struct dlm_lock_resource *res;
  2218. /* dlmlock returned something other than NOTQUEUED or NORMAL */
  2219. mlog(ML_ERROR, "%s: got %s from dlmlock($RECOVERY), "
  2220. "lksb.status=%s\n", dlm->name, dlm_errname(ret),
  2221. dlm_errname(lksb.status));
  2222. res = dlm_lookup_lockres(dlm, DLM_RECOVERY_LOCK_NAME,
  2223. DLM_RECOVERY_LOCK_NAME_LEN);
  2224. if (res) {
  2225. dlm_print_one_lock_resource(res);
  2226. dlm_lockres_put(res);
  2227. } else {
  2228. mlog(ML_ERROR, "recovery lock not found\n");
  2229. }
  2230. BUG();
  2231. }
  2232. return status;
  2233. }
  2234. static int dlm_send_begin_reco_message(struct dlm_ctxt *dlm, u8 dead_node)
  2235. {
  2236. struct dlm_begin_reco br;
  2237. int ret = 0;
  2238. struct dlm_node_iter iter;
  2239. int nodenum;
  2240. int status;
  2241. mlog_entry("%u\n", dead_node);
  2242. mlog(0, "%s: dead node is %u\n", dlm->name, dead_node);
  2243. spin_lock(&dlm->spinlock);
  2244. dlm_node_iter_init(dlm->domain_map, &iter);
  2245. spin_unlock(&dlm->spinlock);
  2246. clear_bit(dead_node, iter.node_map);
  2247. memset(&br, 0, sizeof(br));
  2248. br.node_idx = dlm->node_num;
  2249. br.dead_node = dead_node;
  2250. while ((nodenum = dlm_node_iter_next(&iter)) >= 0) {
  2251. ret = 0;
  2252. if (nodenum == dead_node) {
  2253. mlog(0, "not sending begin reco to dead node "
  2254. "%u\n", dead_node);
  2255. continue;
  2256. }
  2257. if (nodenum == dlm->node_num) {
  2258. mlog(0, "not sending begin reco to self\n");
  2259. continue;
  2260. }
  2261. retry:
  2262. ret = -EINVAL;
  2263. mlog(0, "attempting to send begin reco msg to %d\n",
  2264. nodenum);
  2265. ret = o2net_send_message(DLM_BEGIN_RECO_MSG, dlm->key,
  2266. &br, sizeof(br), nodenum, &status);
  2267. /* negative status is handled ok by caller here */
  2268. if (ret >= 0)
  2269. ret = status;
  2270. if (dlm_is_host_down(ret)) {
  2271. /* node is down. not involved in recovery
  2272. * so just keep going */
  2273. mlog(0, "%s: node %u was down when sending "
  2274. "begin reco msg (%d)\n", dlm->name, nodenum, ret);
  2275. ret = 0;
  2276. }
  2277. if (ret < 0) {
  2278. struct dlm_lock_resource *res;
  2279. /* this is now a serious problem, possibly ENOMEM
  2280. * in the network stack. must retry */
  2281. mlog_errno(ret);
  2282. mlog(ML_ERROR, "begin reco of dlm %s to node %u "
  2283. " returned %d\n", dlm->name, nodenum, ret);
  2284. res = dlm_lookup_lockres(dlm, DLM_RECOVERY_LOCK_NAME,
  2285. DLM_RECOVERY_LOCK_NAME_LEN);
  2286. if (res) {
  2287. dlm_print_one_lock_resource(res);
  2288. dlm_lockres_put(res);
  2289. } else {
  2290. mlog(ML_ERROR, "recovery lock not found\n");
  2291. }
  2292. /* sleep for a bit in hopes that we can avoid
  2293. * another ENOMEM */
  2294. msleep(100);
  2295. goto retry;
  2296. } else if (ret == EAGAIN) {
  2297. mlog(0, "%s: trying to start recovery of node "
  2298. "%u, but node %u is waiting for last recovery "
  2299. "to complete, backoff for a bit\n", dlm->name,
  2300. dead_node, nodenum);
  2301. /* TODO Look into replacing msleep with cond_resched() */
  2302. msleep(100);
  2303. goto retry;
  2304. }
  2305. }
  2306. return ret;
  2307. }
  2308. int dlm_begin_reco_handler(struct o2net_msg *msg, u32 len, void *data,
  2309. void **ret_data)
  2310. {
  2311. struct dlm_ctxt *dlm = data;
  2312. struct dlm_begin_reco *br = (struct dlm_begin_reco *)msg->buf;
  2313. /* ok to return 0, domain has gone away */
  2314. if (!dlm_grab(dlm))
  2315. return 0;
  2316. spin_lock(&dlm->spinlock);
  2317. if (dlm->reco.state & DLM_RECO_STATE_FINALIZE) {
  2318. mlog(0, "%s: node %u wants to recover node %u (%u:%u) "
  2319. "but this node is in finalize state, waiting on finalize2\n",
  2320. dlm->name, br->node_idx, br->dead_node,
  2321. dlm->reco.dead_node, dlm->reco.new_master);
  2322. spin_unlock(&dlm->spinlock);
  2323. return EAGAIN;
  2324. }
  2325. spin_unlock(&dlm->spinlock);
  2326. mlog(0, "%s: node %u wants to recover node %u (%u:%u)\n",
  2327. dlm->name, br->node_idx, br->dead_node,
  2328. dlm->reco.dead_node, dlm->reco.new_master);
  2329. dlm_fire_domain_eviction_callbacks(dlm, br->dead_node);
  2330. spin_lock(&dlm->spinlock);
  2331. if (dlm->reco.new_master != O2NM_INVALID_NODE_NUM) {
  2332. if (test_bit(dlm->reco.new_master, dlm->recovery_map)) {
  2333. mlog(0, "%s: new_master %u died, changing "
  2334. "to %u\n", dlm->name, dlm->reco.new_master,
  2335. br->node_idx);
  2336. } else {
  2337. mlog(0, "%s: new_master %u NOT DEAD, changing "
  2338. "to %u\n", dlm->name, dlm->reco.new_master,
  2339. br->node_idx);
  2340. /* may not have seen the new master as dead yet */
  2341. }
  2342. }
  2343. if (dlm->reco.dead_node != O2NM_INVALID_NODE_NUM) {
  2344. mlog(ML_NOTICE, "%s: dead_node previously set to %u, "
  2345. "node %u changing it to %u\n", dlm->name,
  2346. dlm->reco.dead_node, br->node_idx, br->dead_node);
  2347. }
  2348. dlm_set_reco_master(dlm, br->node_idx);
  2349. dlm_set_reco_dead_node(dlm, br->dead_node);
  2350. if (!test_bit(br->dead_node, dlm->recovery_map)) {
  2351. mlog(0, "recovery master %u sees %u as dead, but this "
  2352. "node has not yet. marking %u as dead\n",
  2353. br->node_idx, br->dead_node, br->dead_node);
  2354. if (!test_bit(br->dead_node, dlm->domain_map) ||
  2355. !test_bit(br->dead_node, dlm->live_nodes_map))
  2356. mlog(0, "%u not in domain/live_nodes map "
  2357. "so setting it in reco map manually\n",
  2358. br->dead_node);
  2359. /* force the recovery cleanup in __dlm_hb_node_down
  2360. * both of these will be cleared in a moment */
  2361. set_bit(br->dead_node, dlm->domain_map);
  2362. set_bit(br->dead_node, dlm->live_nodes_map);
  2363. __dlm_hb_node_down(dlm, br->dead_node);
  2364. }
  2365. spin_unlock(&dlm->spinlock);
  2366. dlm_kick_recovery_thread(dlm);
  2367. mlog(0, "%s: recovery started by node %u, for %u (%u:%u)\n",
  2368. dlm->name, br->node_idx, br->dead_node,
  2369. dlm->reco.dead_node, dlm->reco.new_master);
  2370. dlm_put(dlm);
  2371. return 0;
  2372. }
  2373. #define DLM_FINALIZE_STAGE2 0x01
  2374. static int dlm_send_finalize_reco_message(struct dlm_ctxt *dlm)
  2375. {
  2376. int ret = 0;
  2377. struct dlm_finalize_reco fr;
  2378. struct dlm_node_iter iter;
  2379. int nodenum;
  2380. int status;
  2381. int stage = 1;
  2382. mlog(0, "finishing recovery for node %s:%u, "
  2383. "stage %d\n", dlm->name, dlm->reco.dead_node, stage);
  2384. spin_lock(&dlm->spinlock);
  2385. dlm_node_iter_init(dlm->domain_map, &iter);
  2386. spin_unlock(&dlm->spinlock);
  2387. stage2:
  2388. memset(&fr, 0, sizeof(fr));
  2389. fr.node_idx = dlm->node_num;
  2390. fr.dead_node = dlm->reco.dead_node;
  2391. if (stage == 2)
  2392. fr.flags |= DLM_FINALIZE_STAGE2;
  2393. while ((nodenum = dlm_node_iter_next(&iter)) >= 0) {
  2394. if (nodenum == dlm->node_num)
  2395. continue;
  2396. ret = o2net_send_message(DLM_FINALIZE_RECO_MSG, dlm->key,
  2397. &fr, sizeof(fr), nodenum, &status);
  2398. if (ret >= 0)
  2399. ret = status;
  2400. if (ret < 0) {
  2401. mlog_errno(ret);
  2402. if (dlm_is_host_down(ret)) {
  2403. /* this has no effect on this recovery
  2404. * session, so set the status to zero to
  2405. * finish out the last recovery */
  2406. mlog(ML_ERROR, "node %u went down after this "
  2407. "node finished recovery.\n", nodenum);
  2408. ret = 0;
  2409. continue;
  2410. }
  2411. break;
  2412. }
  2413. }
  2414. if (stage == 1) {
  2415. /* reset the node_iter back to the top and send finalize2 */
  2416. iter.curnode = -1;
  2417. stage = 2;
  2418. goto stage2;
  2419. }
  2420. return ret;
  2421. }
  2422. int dlm_finalize_reco_handler(struct o2net_msg *msg, u32 len, void *data,
  2423. void **ret_data)
  2424. {
  2425. struct dlm_ctxt *dlm = data;
  2426. struct dlm_finalize_reco *fr = (struct dlm_finalize_reco *)msg->buf;
  2427. int stage = 1;
  2428. /* ok to return 0, domain has gone away */
  2429. if (!dlm_grab(dlm))
  2430. return 0;
  2431. if (fr->flags & DLM_FINALIZE_STAGE2)
  2432. stage = 2;
  2433. mlog(0, "%s: node %u finalizing recovery stage%d of "
  2434. "node %u (%u:%u)\n", dlm->name, fr->node_idx, stage,
  2435. fr->dead_node, dlm->reco.dead_node, dlm->reco.new_master);
  2436. spin_lock(&dlm->spinlock);
  2437. if (dlm->reco.new_master != fr->node_idx) {
  2438. mlog(ML_ERROR, "node %u sent recovery finalize msg, but node "
  2439. "%u is supposed to be the new master, dead=%u\n",
  2440. fr->node_idx, dlm->reco.new_master, fr->dead_node);
  2441. BUG();
  2442. }
  2443. if (dlm->reco.dead_node != fr->dead_node) {
  2444. mlog(ML_ERROR, "node %u sent recovery finalize msg for dead "
  2445. "node %u, but node %u is supposed to be dead\n",
  2446. fr->node_idx, fr->dead_node, dlm->reco.dead_node);
  2447. BUG();
  2448. }
  2449. switch (stage) {
  2450. case 1:
  2451. dlm_finish_local_lockres_recovery(dlm, fr->dead_node, fr->node_idx);
  2452. if (dlm->reco.state & DLM_RECO_STATE_FINALIZE) {
  2453. mlog(ML_ERROR, "%s: received finalize1 from "
  2454. "new master %u for dead node %u, but "
  2455. "this node has already received it!\n",
  2456. dlm->name, fr->node_idx, fr->dead_node);
  2457. dlm_print_reco_node_status(dlm);
  2458. BUG();
  2459. }
  2460. dlm->reco.state |= DLM_RECO_STATE_FINALIZE;
  2461. spin_unlock(&dlm->spinlock);
  2462. break;
  2463. case 2:
  2464. if (!(dlm->reco.state & DLM_RECO_STATE_FINALIZE)) {
  2465. mlog(ML_ERROR, "%s: received finalize2 from "
  2466. "new master %u for dead node %u, but "
  2467. "this node did not have finalize1!\n",
  2468. dlm->name, fr->node_idx, fr->dead_node);
  2469. dlm_print_reco_node_status(dlm);
  2470. BUG();
  2471. }
  2472. dlm->reco.state &= ~DLM_RECO_STATE_FINALIZE;
  2473. spin_unlock(&dlm->spinlock);
  2474. dlm_reset_recovery(dlm);
  2475. dlm_kick_recovery_thread(dlm);
  2476. break;
  2477. default:
  2478. BUG();
  2479. }
  2480. mlog(0, "%s: recovery done, reco master was %u, dead now %u, master now %u\n",
  2481. dlm->name, fr->node_idx, dlm->reco.dead_node, dlm->reco.new_master);
  2482. dlm_put(dlm);
  2483. return 0;
  2484. }