dlmrecovery.c 67 KB

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