dlmrecovery.c 82 KB

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