1 /* -*- mode: c; c-basic-offset: 8; -*-
2 * vim: noexpandtab sw=8 ts=8 sts=0:
8 * Copyright (C) 2004 Oracle. All rights reserved.
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.
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.
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.
28 #include <linux/module.h>
30 #include <linux/types.h>
31 #include <linux/slab.h>
32 #include <linux/highmem.h>
33 #include <linux/utsname.h>
34 #include <linux/init.h>
35 #include <linux/sysctl.h>
36 #include <linux/random.h>
37 #include <linux/blkdev.h>
38 #include <linux/socket.h>
39 #include <linux/inet.h>
40 #include <linux/timer.h>
41 #include <linux/kthread.h>
42 #include <linux/delay.h>
45 #include "cluster/heartbeat.h"
46 #include "cluster/nodemanager.h"
47 #include "cluster/tcp.h"
50 #include "dlmcommon.h"
51 #include "dlmdomain.h"
53 #define MLOG_MASK_PREFIX (ML_DLM|ML_DLM_RECOVERY)
54 #include "cluster/masklog.h"
56 static void dlm_do_local_recovery_cleanup(struct dlm_ctxt *dlm, u8 dead_node);
58 static int dlm_recovery_thread(void *data);
59 void dlm_complete_recovery_thread(struct dlm_ctxt *dlm);
60 int dlm_launch_recovery_thread(struct dlm_ctxt *dlm);
61 static void dlm_kick_recovery_thread(struct dlm_ctxt *dlm);
62 static int dlm_do_recovery(struct dlm_ctxt *dlm);
64 static int dlm_pick_recovery_master(struct dlm_ctxt *dlm);
65 static int dlm_remaster_locks(struct dlm_ctxt *dlm, u8 dead_node);
66 static int dlm_init_recovery_area(struct dlm_ctxt *dlm, u8 dead_node);
67 static int dlm_request_all_locks(struct dlm_ctxt *dlm,
68 u8 request_from, u8 dead_node);
69 static void dlm_destroy_recovery_area(struct dlm_ctxt *dlm, u8 dead_node);
71 static inline int dlm_num_locks_in_lockres(struct dlm_lock_resource *res);
72 static void dlm_init_migratable_lockres(struct dlm_migratable_lockres *mres,
73 const char *lockname, int namelen,
74 int total_locks, u64 cookie,
76 static int dlm_send_mig_lockres_msg(struct dlm_ctxt *dlm,
77 struct dlm_migratable_lockres *mres,
79 struct dlm_lock_resource *res,
81 static int dlm_lockres_master_requery(struct dlm_ctxt *dlm,
82 struct dlm_lock_resource *res,
84 static int dlm_process_recovery_data(struct dlm_ctxt *dlm,
85 struct dlm_lock_resource *res,
86 struct dlm_migratable_lockres *mres);
87 static int dlm_do_master_requery(struct dlm_ctxt *dlm,
88 struct dlm_lock_resource *res,
89 u8 nodenum, u8 *real_master);
90 static int dlm_send_finalize_reco_message(struct dlm_ctxt *dlm);
91 static int dlm_send_all_done_msg(struct dlm_ctxt *dlm,
92 u8 dead_node, u8 send_to);
93 static int dlm_send_begin_reco_message(struct dlm_ctxt *dlm, u8 dead_node);
94 static void dlm_move_reco_locks_to_list(struct dlm_ctxt *dlm,
95 struct list_head *list, u8 dead_node);
96 static void dlm_finish_local_lockres_recovery(struct dlm_ctxt *dlm,
97 u8 dead_node, u8 new_master);
98 static void dlm_reco_ast(void *astdata);
99 static void dlm_reco_bast(void *astdata, int blocked_type);
100 static void dlm_reco_unlock_ast(void *astdata, enum dlm_status st);
101 static void dlm_request_all_locks_worker(struct dlm_work_item *item,
103 static void dlm_mig_lockres_worker(struct dlm_work_item *item, void *data);
105 static u64 dlm_get_next_mig_cookie(void);
107 static spinlock_t dlm_reco_state_lock = SPIN_LOCK_UNLOCKED;
108 static spinlock_t dlm_mig_cookie_lock = SPIN_LOCK_UNLOCKED;
109 static u64 dlm_mig_cookie = 1;
111 static u64 dlm_get_next_mig_cookie(void)
114 spin_lock(&dlm_mig_cookie_lock);
116 if (dlm_mig_cookie == (~0ULL))
120 spin_unlock(&dlm_mig_cookie_lock);
124 static inline void dlm_reset_recovery(struct dlm_ctxt *dlm)
126 spin_lock(&dlm->spinlock);
127 clear_bit(dlm->reco.dead_node, dlm->recovery_map);
128 dlm->reco.dead_node = O2NM_INVALID_NODE_NUM;
129 dlm->reco.new_master = O2NM_INVALID_NODE_NUM;
130 spin_unlock(&dlm->spinlock);
133 /* Worker function used during recovery. */
134 void dlm_dispatch_work(void *data)
136 struct dlm_ctxt *dlm = (struct dlm_ctxt *)data;
138 struct list_head *iter, *iter2;
139 struct dlm_work_item *item;
140 dlm_workfunc_t *workfunc;
142 spin_lock(&dlm->work_lock);
143 list_splice_init(&dlm->work_list, &tmp_list);
144 spin_unlock(&dlm->work_lock);
146 list_for_each_safe(iter, iter2, &tmp_list) {
147 item = list_entry(iter, struct dlm_work_item, list);
148 workfunc = item->func;
149 list_del_init(&item->list);
151 /* already have ref on dlm to avoid having
152 * it disappear. just double-check. */
153 BUG_ON(item->dlm != dlm);
155 /* this is allowed to sleep and
156 * call network stuff */
157 workfunc(item, item->data);
168 static void dlm_kick_recovery_thread(struct dlm_ctxt *dlm)
170 /* wake the recovery thread
171 * this will wake the reco thread in one of three places
172 * 1) sleeping with no recovery happening
173 * 2) sleeping with recovery mastered elsewhere
174 * 3) recovery mastered here, waiting on reco data */
176 wake_up(&dlm->dlm_reco_thread_wq);
179 /* Launch the recovery thread */
180 int dlm_launch_recovery_thread(struct dlm_ctxt *dlm)
182 mlog(0, "starting dlm recovery thread...\n");
184 dlm->dlm_reco_thread_task = kthread_run(dlm_recovery_thread, dlm,
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;
195 void dlm_complete_recovery_thread(struct dlm_ctxt *dlm)
197 if (dlm->dlm_reco_thread_task) {
198 mlog(0, "waiting for dlm recovery thread to exit\n");
199 kthread_stop(dlm->dlm_reco_thread_task);
200 dlm->dlm_reco_thread_task = NULL;
207 * this is lame, but here's how recovery works...
208 * 1) all recovery threads cluster wide will work on recovering
210 * 2) negotiate who will take over all the locks for the dead node.
211 * thats right... ALL the locks.
212 * 3) once a new master is chosen, everyone scans all locks
213 * and moves aside those mastered by the dead guy
214 * 4) each of these locks should be locked until recovery is done
215 * 5) the new master collects up all of secondary lock queue info
216 * one lock at a time, forcing each node to communicate back
218 * 6) each secondary lock queue responds with the full known lock info
219 * 7) once the new master has run all its locks, it sends a ALLDONE!
220 * message to everyone
221 * 8) upon receiving this message, the secondary queue node unlocks
222 * and responds to the ALLDONE
223 * 9) once the new master gets responses from everyone, he unlocks
224 * everything and recovery for this dead node is done
225 *10) go back to 2) while there are still dead nodes
230 #define DLM_RECO_THREAD_TIMEOUT_MS (5 * 1000)
232 static int dlm_recovery_thread(void *data)
235 struct dlm_ctxt *dlm = data;
236 unsigned long timeout = msecs_to_jiffies(DLM_RECO_THREAD_TIMEOUT_MS);
238 mlog(0, "dlm thread running for %s...\n", dlm->name);
240 while (!kthread_should_stop()) {
241 if (dlm_joined(dlm)) {
242 status = dlm_do_recovery(dlm);
243 if (status == -EAGAIN) {
244 /* do not sleep, recheck immediately. */
251 wait_event_interruptible_timeout(dlm->dlm_reco_thread_wq,
252 kthread_should_stop(),
256 mlog(0, "quitting DLM recovery thread\n");
260 /* returns true when the recovery master has contacted us */
261 static int dlm_reco_master_ready(struct dlm_ctxt *dlm)
264 spin_lock(&dlm->spinlock);
265 ready = (dlm->reco.new_master != O2NM_INVALID_NODE_NUM);
266 spin_unlock(&dlm->spinlock);
270 /* returns true if node is no longer in the domain
271 * could be dead or just not joined */
272 int dlm_is_node_dead(struct dlm_ctxt *dlm, u8 node)
275 spin_lock(&dlm->spinlock);
276 dead = test_bit(node, dlm->domain_map);
277 spin_unlock(&dlm->spinlock);
281 /* callers of the top-level api calls (dlmlock/dlmunlock) should
282 * block on the dlm->reco.event when recovery is in progress.
283 * the dlm recovery thread will set this state when it begins
284 * recovering a dead node (as the new master or not) and clear
285 * the state and wake as soon as all affected lock resources have
286 * been marked with the RECOVERY flag */
287 static int dlm_in_recovery(struct dlm_ctxt *dlm)
290 spin_lock(&dlm->spinlock);
291 in_recovery = !!(dlm->reco.state & DLM_RECO_STATE_ACTIVE);
292 spin_unlock(&dlm->spinlock);
297 void dlm_wait_for_recovery(struct dlm_ctxt *dlm)
299 wait_event(dlm->reco.event, !dlm_in_recovery(dlm));
302 static void dlm_begin_recovery(struct dlm_ctxt *dlm)
304 spin_lock(&dlm->spinlock);
305 BUG_ON(dlm->reco.state & DLM_RECO_STATE_ACTIVE);
306 dlm->reco.state |= DLM_RECO_STATE_ACTIVE;
307 spin_unlock(&dlm->spinlock);
310 static void dlm_end_recovery(struct dlm_ctxt *dlm)
312 spin_lock(&dlm->spinlock);
313 BUG_ON(!(dlm->reco.state & DLM_RECO_STATE_ACTIVE));
314 dlm->reco.state &= ~DLM_RECO_STATE_ACTIVE;
315 spin_unlock(&dlm->spinlock);
316 wake_up(&dlm->reco.event);
319 static int dlm_do_recovery(struct dlm_ctxt *dlm)
324 spin_lock(&dlm->spinlock);
326 /* check to see if the new master has died */
327 if (dlm->reco.new_master != O2NM_INVALID_NODE_NUM &&
328 test_bit(dlm->reco.new_master, dlm->recovery_map)) {
329 mlog(0, "new master %u died while recovering %u!\n",
330 dlm->reco.new_master, dlm->reco.dead_node);
331 /* unset the new_master, leave dead_node */
332 dlm->reco.new_master = O2NM_INVALID_NODE_NUM;
335 /* select a target to recover */
336 if (dlm->reco.dead_node == O2NM_INVALID_NODE_NUM) {
339 bit = find_next_bit (dlm->recovery_map, O2NM_MAX_NODES+1, 0);
340 if (bit >= O2NM_MAX_NODES || bit < 0)
341 dlm->reco.dead_node = O2NM_INVALID_NODE_NUM;
343 dlm->reco.dead_node = bit;
344 } else if (!test_bit(dlm->reco.dead_node, dlm->recovery_map)) {
346 mlog(ML_ERROR, "dead_node %u no longer in recovery map!\n",
347 dlm->reco.dead_node);
348 dlm->reco.dead_node = O2NM_INVALID_NODE_NUM;
351 if (dlm->reco.dead_node == O2NM_INVALID_NODE_NUM) {
352 // mlog(0, "nothing to recover! sleeping now!\n");
353 spin_unlock(&dlm->spinlock);
354 /* return to main thread loop and sleep. */
357 mlog(0, "recovery thread found node %u in the recovery map!\n",
358 dlm->reco.dead_node);
359 spin_unlock(&dlm->spinlock);
361 /* take write barrier */
362 /* (stops the list reshuffling thread, proxy ast handling) */
363 dlm_begin_recovery(dlm);
365 if (dlm->reco.new_master == dlm->node_num)
368 if (dlm->reco.new_master == O2NM_INVALID_NODE_NUM) {
369 /* choose a new master, returns 0 if this node
370 * is the master, -EEXIST if it's another node.
371 * this does not return until a new master is chosen
372 * or recovery completes entirely. */
373 ret = dlm_pick_recovery_master(dlm);
375 /* already notified everyone. go. */
378 mlog(0, "another node will master this recovery session.\n");
380 mlog(0, "dlm=%s, new_master=%u, this node=%u, dead_node=%u\n",
381 dlm->name, dlm->reco.new_master,
382 dlm->node_num, dlm->reco.dead_node);
384 /* it is safe to start everything back up here
385 * because all of the dead node's lock resources
386 * have been marked as in-recovery */
387 dlm_end_recovery(dlm);
389 /* sleep out in main dlm_recovery_thread loop. */
393 mlog(0, "mastering recovery of %s:%u here(this=%u)!\n",
394 dlm->name, dlm->reco.dead_node, dlm->node_num);
396 status = dlm_remaster_locks(dlm, dlm->reco.dead_node);
398 mlog(ML_ERROR, "error %d remastering locks for node %u, "
399 "retrying.\n", status, dlm->reco.dead_node);
400 /* yield a bit to allow any final network messages
401 * to get handled on remaining nodes */
404 /* success! see if any other nodes need recovery */
405 mlog(0, "DONE mastering recovery of %s:%u here(this=%u)!\n",
406 dlm->name, dlm->reco.dead_node, dlm->node_num);
407 dlm_reset_recovery(dlm);
409 dlm_end_recovery(dlm);
411 /* continue and look for another dead node */
415 static int dlm_remaster_locks(struct dlm_ctxt *dlm, u8 dead_node)
418 struct dlm_reco_node_data *ndata;
419 struct list_head *iter;
424 status = dlm_init_recovery_area(dlm, dead_node);
428 /* safe to access the node data list without a lock, since this
429 * process is the only one to change the list */
430 list_for_each(iter, &dlm->reco.node_data) {
431 ndata = list_entry (iter, struct dlm_reco_node_data, list);
432 BUG_ON(ndata->state != DLM_RECO_NODE_DATA_INIT);
433 ndata->state = DLM_RECO_NODE_DATA_REQUESTING;
435 mlog(0, "requesting lock info from node %u\n",
438 if (ndata->node_num == dlm->node_num) {
439 ndata->state = DLM_RECO_NODE_DATA_DONE;
443 status = dlm_request_all_locks(dlm, ndata->node_num, dead_node);
446 if (dlm_is_host_down(status))
447 ndata->state = DLM_RECO_NODE_DATA_DEAD;
454 switch (ndata->state) {
455 case DLM_RECO_NODE_DATA_INIT:
456 case DLM_RECO_NODE_DATA_FINALIZE_SENT:
457 case DLM_RECO_NODE_DATA_REQUESTED:
460 case DLM_RECO_NODE_DATA_DEAD:
461 mlog(0, "node %u died after requesting "
462 "recovery info for node %u\n",
463 ndata->node_num, dead_node);
468 case DLM_RECO_NODE_DATA_REQUESTING:
469 ndata->state = DLM_RECO_NODE_DATA_REQUESTED;
470 mlog(0, "now receiving recovery data from "
471 "node %u for dead node %u\n",
472 ndata->node_num, dead_node);
474 case DLM_RECO_NODE_DATA_RECEIVING:
475 mlog(0, "already receiving recovery data from "
476 "node %u for dead node %u\n",
477 ndata->node_num, dead_node);
479 case DLM_RECO_NODE_DATA_DONE:
480 mlog(0, "already DONE receiving recovery data "
481 "from node %u for dead node %u\n",
482 ndata->node_num, dead_node);
487 mlog(0, "done requesting all lock info\n");
489 /* nodes should be sending reco data now
490 * just need to wait */
493 /* check all the nodes now to see if we are
494 * done, or if anyone died */
496 spin_lock(&dlm_reco_state_lock);
497 list_for_each(iter, &dlm->reco.node_data) {
498 ndata = list_entry (iter, struct dlm_reco_node_data, list);
500 mlog(0, "checking recovery state of node %u\n",
502 switch (ndata->state) {
503 case DLM_RECO_NODE_DATA_INIT:
504 case DLM_RECO_NODE_DATA_REQUESTING:
505 mlog(ML_ERROR, "bad ndata state for "
506 "node %u: state=%d\n",
507 ndata->node_num, ndata->state);
510 case DLM_RECO_NODE_DATA_DEAD:
511 mlog(ML_NOTICE, "node %u died after "
512 "requesting recovery info for "
513 "node %u\n", ndata->node_num,
515 spin_unlock(&dlm_reco_state_lock);
519 /* instead of spinning like crazy here,
520 * wait for the domain map to catch up
521 * with the network state. otherwise this
522 * can be hit hundreds of times before
523 * the node is really seen as dead. */
524 wait_event_timeout(dlm->dlm_reco_thread_wq,
525 dlm_is_node_dead(dlm,
527 msecs_to_jiffies(1000));
528 mlog(0, "waited 1 sec for %u, "
529 "dead? %s\n", ndata->node_num,
530 dlm_is_node_dead(dlm, ndata->node_num) ?
533 case DLM_RECO_NODE_DATA_RECEIVING:
534 case DLM_RECO_NODE_DATA_REQUESTED:
537 case DLM_RECO_NODE_DATA_DONE:
539 case DLM_RECO_NODE_DATA_FINALIZE_SENT:
543 spin_unlock(&dlm_reco_state_lock);
545 mlog(0, "pass #%d, all_nodes_done?: %s\n", ++pass,
546 all_nodes_done?"yes":"no");
547 if (all_nodes_done) {
550 /* all nodes are now in DLM_RECO_NODE_DATA_DONE state
551 * just send a finalize message to everyone and
553 mlog(0, "all nodes are done! send finalize\n");
554 ret = dlm_send_finalize_reco_message(dlm);
558 spin_lock(&dlm->spinlock);
559 dlm_finish_local_lockres_recovery(dlm, dead_node,
561 spin_unlock(&dlm->spinlock);
562 mlog(0, "should be done with recovery!\n");
564 mlog(0, "finishing recovery of %s at %lu, "
565 "dead=%u, this=%u, new=%u\n", dlm->name,
566 jiffies, dlm->reco.dead_node,
567 dlm->node_num, dlm->reco.new_master);
570 /* rescan everything marked dirty along the way */
571 dlm_kick_thread(dlm, NULL);
574 /* wait to be signalled, with periodic timeout
575 * to check for node death */
576 wait_event_interruptible_timeout(dlm->dlm_reco_thread_wq,
577 kthread_should_stop(),
578 msecs_to_jiffies(DLM_RECO_THREAD_TIMEOUT_MS));
584 dlm_destroy_recovery_area(dlm, dead_node);
590 static int dlm_init_recovery_area(struct dlm_ctxt *dlm, u8 dead_node)
593 struct dlm_reco_node_data *ndata;
595 spin_lock(&dlm->spinlock);
596 memcpy(dlm->reco.node_map, dlm->domain_map, sizeof(dlm->domain_map));
597 /* nodes can only be removed (by dying) after dropping
598 * this lock, and death will be trapped later, so this should do */
599 spin_unlock(&dlm->spinlock);
602 num = find_next_bit (dlm->reco.node_map, O2NM_MAX_NODES, num);
603 if (num >= O2NM_MAX_NODES) {
606 BUG_ON(num == dead_node);
608 ndata = kcalloc(1, sizeof(*ndata), GFP_KERNEL);
610 dlm_destroy_recovery_area(dlm, dead_node);
613 ndata->node_num = num;
614 ndata->state = DLM_RECO_NODE_DATA_INIT;
615 spin_lock(&dlm_reco_state_lock);
616 list_add_tail(&ndata->list, &dlm->reco.node_data);
617 spin_unlock(&dlm_reco_state_lock);
624 static void dlm_destroy_recovery_area(struct dlm_ctxt *dlm, u8 dead_node)
626 struct list_head *iter, *iter2;
627 struct dlm_reco_node_data *ndata;
630 spin_lock(&dlm_reco_state_lock);
631 list_splice_init(&dlm->reco.node_data, &tmplist);
632 spin_unlock(&dlm_reco_state_lock);
634 list_for_each_safe(iter, iter2, &tmplist) {
635 ndata = list_entry (iter, struct dlm_reco_node_data, list);
636 list_del_init(&ndata->list);
641 static int dlm_request_all_locks(struct dlm_ctxt *dlm, u8 request_from,
644 struct dlm_lock_request lr;
650 mlog(0, "dlm_request_all_locks: dead node is %u, sending request "
651 "to %u\n", dead_node, request_from);
653 memset(&lr, 0, sizeof(lr));
654 lr.node_idx = dlm->node_num;
655 lr.dead_node = dead_node;
659 ret = o2net_send_message(DLM_LOCK_REQUEST_MSG, dlm->key,
660 &lr, sizeof(lr), request_from, NULL);
662 /* negative status is handled by caller */
666 // return from here, then
667 // sleep until all received or error
672 int dlm_request_all_locks_handler(struct o2net_msg *msg, u32 len, void *data)
674 struct dlm_ctxt *dlm = data;
675 struct dlm_lock_request *lr = (struct dlm_lock_request *)msg->buf;
677 struct dlm_work_item *item = NULL;
682 BUG_ON(lr->dead_node != dlm->reco.dead_node);
684 item = kcalloc(1, sizeof(*item), GFP_KERNEL);
690 /* this will get freed by dlm_request_all_locks_worker */
691 buf = (char *) __get_free_page(GFP_KERNEL);
698 /* queue up work for dlm_request_all_locks_worker */
699 dlm_grab(dlm); /* get an extra ref for the work item */
700 dlm_init_work_item(dlm, item, dlm_request_all_locks_worker, buf);
701 item->u.ral.reco_master = lr->node_idx;
702 item->u.ral.dead_node = lr->dead_node;
703 spin_lock(&dlm->work_lock);
704 list_add_tail(&item->list, &dlm->work_list);
705 spin_unlock(&dlm->work_lock);
706 schedule_work(&dlm->dispatched_work);
712 static void dlm_request_all_locks_worker(struct dlm_work_item *item, void *data)
714 struct dlm_migratable_lockres *mres;
715 struct dlm_lock_resource *res;
716 struct dlm_ctxt *dlm;
717 LIST_HEAD(resources);
718 struct list_head *iter;
720 u8 dead_node, reco_master;
723 dead_node = item->u.ral.dead_node;
724 reco_master = item->u.ral.reco_master;
725 mres = (struct dlm_migratable_lockres *)data;
727 if (dead_node != dlm->reco.dead_node ||
728 reco_master != dlm->reco.new_master) {
729 /* show extra debug info if the recovery state is messed */
730 mlog(ML_ERROR, "%s: bad reco state: reco(dead=%u, master=%u), "
731 "request(dead=%u, master=%u)\n",
732 dlm->name, dlm->reco.dead_node, dlm->reco.new_master,
733 dead_node, reco_master);
734 mlog(ML_ERROR, "%s: name=%.*s master=%u locks=%u/%u flags=%u "
735 "entry[0]={c=%"MLFu64",l=%u,f=%u,t=%d,ct=%d,hb=%d,n=%u}\n",
736 dlm->name, mres->lockname_len, mres->lockname, mres->master,
737 mres->num_locks, mres->total_locks, mres->flags,
738 mres->ml[0].cookie, mres->ml[0].list, mres->ml[0].flags,
739 mres->ml[0].type, mres->ml[0].convert_type,
740 mres->ml[0].highest_blocked, mres->ml[0].node);
743 BUG_ON(dead_node != dlm->reco.dead_node);
744 BUG_ON(reco_master != dlm->reco.new_master);
746 /* lock resources should have already been moved to the
747 * dlm->reco.resources list. now move items from that list
748 * to a temp list if the dead owner matches. note that the
749 * whole cluster recovers only one node at a time, so we
750 * can safely move UNKNOWN lock resources for each recovery
752 dlm_move_reco_locks_to_list(dlm, &resources, dead_node);
754 /* now we can begin blasting lockreses without the dlm lock */
755 list_for_each(iter, &resources) {
756 res = list_entry (iter, struct dlm_lock_resource, recovering);
757 ret = dlm_send_one_lockres(dlm, res, mres, reco_master,
763 /* move the resources back to the list */
764 spin_lock(&dlm->spinlock);
765 list_splice_init(&resources, &dlm->reco.resources);
766 spin_unlock(&dlm->spinlock);
768 ret = dlm_send_all_done_msg(dlm, dead_node, reco_master);
772 free_page((unsigned long)data);
776 static int dlm_send_all_done_msg(struct dlm_ctxt *dlm, u8 dead_node, u8 send_to)
779 struct dlm_reco_data_done done_msg;
781 memset(&done_msg, 0, sizeof(done_msg));
782 done_msg.node_idx = dlm->node_num;
783 done_msg.dead_node = dead_node;
784 mlog(0, "sending DATA DONE message to %u, "
785 "my node=%u, dead node=%u\n", send_to, done_msg.node_idx,
788 ret = o2net_send_message(DLM_RECO_DATA_DONE_MSG, dlm->key, &done_msg,
789 sizeof(done_msg), send_to, &tmpret);
790 /* negative status is ignored by the caller */
797 int dlm_reco_data_done_handler(struct o2net_msg *msg, u32 len, void *data)
799 struct dlm_ctxt *dlm = data;
800 struct dlm_reco_data_done *done = (struct dlm_reco_data_done *)msg->buf;
801 struct list_head *iter;
802 struct dlm_reco_node_data *ndata = NULL;
808 mlog(0, "got DATA DONE: dead_node=%u, reco.dead_node=%u, "
809 "node_idx=%u, this node=%u\n", done->dead_node,
810 dlm->reco.dead_node, done->node_idx, dlm->node_num);
811 BUG_ON(done->dead_node != dlm->reco.dead_node);
813 spin_lock(&dlm_reco_state_lock);
814 list_for_each(iter, &dlm->reco.node_data) {
815 ndata = list_entry (iter, struct dlm_reco_node_data, list);
816 if (ndata->node_num != done->node_idx)
819 switch (ndata->state) {
820 /* should have moved beyond INIT but not to FINALIZE yet */
821 case DLM_RECO_NODE_DATA_INIT:
822 case DLM_RECO_NODE_DATA_DEAD:
823 case DLM_RECO_NODE_DATA_FINALIZE_SENT:
824 mlog(ML_ERROR, "bad ndata state for node %u:"
825 " state=%d\n", ndata->node_num,
829 /* these states are possible at this point, anywhere along
830 * the line of recovery */
831 case DLM_RECO_NODE_DATA_DONE:
832 case DLM_RECO_NODE_DATA_RECEIVING:
833 case DLM_RECO_NODE_DATA_REQUESTED:
834 case DLM_RECO_NODE_DATA_REQUESTING:
835 mlog(0, "node %u is DONE sending "
839 ndata->state = DLM_RECO_NODE_DATA_DONE;
844 spin_unlock(&dlm_reco_state_lock);
846 /* wake the recovery thread, some node is done */
848 dlm_kick_recovery_thread(dlm);
851 mlog(ML_ERROR, "failed to find recovery node data for node "
852 "%u\n", done->node_idx);
855 mlog(0, "leaving reco data done handler, ret=%d\n", ret);
859 static void dlm_move_reco_locks_to_list(struct dlm_ctxt *dlm,
860 struct list_head *list,
863 struct dlm_lock_resource *res;
864 struct list_head *iter, *iter2;
865 struct dlm_lock *lock;
867 spin_lock(&dlm->spinlock);
868 list_for_each_safe(iter, iter2, &dlm->reco.resources) {
869 res = list_entry (iter, struct dlm_lock_resource, recovering);
870 /* always prune any $RECOVERY entries for dead nodes,
871 * otherwise hangs can occur during later recovery */
872 if (dlm_is_recovery_lock(res->lockname.name,
873 res->lockname.len)) {
874 spin_lock(&res->spinlock);
875 list_for_each_entry(lock, &res->granted, list) {
876 if (lock->ml.node == dead_node) {
877 mlog(0, "AHA! there was "
878 "a $RECOVERY lock for dead "
880 dead_node, dlm->name);
881 list_del_init(&lock->list);
886 spin_unlock(&res->spinlock);
890 if (res->owner == dead_node) {
891 mlog(0, "found lockres owned by dead node while "
892 "doing recovery for node %u. sending it.\n",
894 list_del_init(&res->recovering);
895 list_add_tail(&res->recovering, list);
896 } else if (res->owner == DLM_LOCK_RES_OWNER_UNKNOWN) {
897 mlog(0, "found UNKNOWN owner while doing recovery "
898 "for node %u. sending it.\n", dead_node);
899 list_del_init(&res->recovering);
900 list_add_tail(&res->recovering, list);
903 spin_unlock(&dlm->spinlock);
906 static inline int dlm_num_locks_in_lockres(struct dlm_lock_resource *res)
909 struct list_head *iter, *queue = &res->granted;
912 for (i=0; i<3; i++) {
913 list_for_each(iter, queue)
921 static int dlm_send_mig_lockres_msg(struct dlm_ctxt *dlm,
922 struct dlm_migratable_lockres *mres,
924 struct dlm_lock_resource *res,
927 u64 mig_cookie = be64_to_cpu(mres->mig_cookie);
928 int mres_total_locks = be32_to_cpu(mres->total_locks);
929 int sz, ret = 0, status = 0;
930 u8 orig_flags = mres->flags,
931 orig_master = mres->master;
933 BUG_ON(mres->num_locks > DLM_MAX_MIGRATABLE_LOCKS);
934 if (!mres->num_locks)
937 sz = sizeof(struct dlm_migratable_lockres) +
938 (mres->num_locks * sizeof(struct dlm_migratable_lock));
940 /* add an all-done flag if we reached the last lock */
941 orig_flags = mres->flags;
942 BUG_ON(total_locks > mres_total_locks);
943 if (total_locks == mres_total_locks)
944 mres->flags |= DLM_MRES_ALL_DONE;
947 ret = o2net_send_message(DLM_MIG_LOCKRES_MSG, dlm->key, mres,
948 sz, send_to, &status);
950 /* XXX: negative status is not handled.
951 * this will end up killing this node. */
954 /* might get an -ENOMEM back here */
959 if (ret == -EFAULT) {
960 mlog(ML_ERROR, "node %u told me to kill "
961 "myself!\n", send_to);
967 /* zero and reinit the message buffer */
968 dlm_init_migratable_lockres(mres, res->lockname.name,
969 res->lockname.len, mres_total_locks,
970 mig_cookie, orig_flags, orig_master);
974 static void dlm_init_migratable_lockres(struct dlm_migratable_lockres *mres,
975 const char *lockname, int namelen,
976 int total_locks, u64 cookie,
979 /* mres here is one full page */
980 memset(mres, 0, PAGE_SIZE);
981 mres->lockname_len = namelen;
982 memcpy(mres->lockname, lockname, namelen);
984 mres->total_locks = cpu_to_be32(total_locks);
985 mres->mig_cookie = cpu_to_be64(cookie);
987 mres->master = master;
991 /* returns 1 if this lock fills the network structure,
993 static int dlm_add_lock_to_array(struct dlm_lock *lock,
994 struct dlm_migratable_lockres *mres, int queue)
996 struct dlm_migratable_lock *ml;
997 int lock_num = mres->num_locks;
999 ml = &(mres->ml[lock_num]);
1000 ml->cookie = lock->ml.cookie;
1001 ml->type = lock->ml.type;
1002 ml->convert_type = lock->ml.convert_type;
1003 ml->highest_blocked = lock->ml.highest_blocked;
1006 ml->flags = lock->lksb->flags;
1007 /* send our current lvb */
1008 if (ml->type == LKM_EXMODE ||
1009 ml->type == LKM_PRMODE) {
1010 /* if it is already set, this had better be a PR
1011 * and it has to match */
1012 if (mres->lvb[0] && (ml->type == LKM_EXMODE ||
1013 memcmp(mres->lvb, lock->lksb->lvb, DLM_LVB_LEN))) {
1014 mlog(ML_ERROR, "mismatched lvbs!\n");
1015 __dlm_print_one_lock_resource(lock->lockres);
1018 memcpy(mres->lvb, lock->lksb->lvb, DLM_LVB_LEN);
1021 ml->node = lock->ml.node;
1023 /* we reached the max, send this network message */
1024 if (mres->num_locks == DLM_MAX_MIGRATABLE_LOCKS)
1030 int dlm_send_one_lockres(struct dlm_ctxt *dlm, struct dlm_lock_resource *res,
1031 struct dlm_migratable_lockres *mres,
1032 u8 send_to, u8 flags)
1034 struct list_head *queue, *iter;
1037 struct dlm_lock *lock;
1040 BUG_ON(!(flags & (DLM_MRES_RECOVERY|DLM_MRES_MIGRATION)));
1042 mlog(0, "sending to %u\n", send_to);
1044 total_locks = dlm_num_locks_in_lockres(res);
1045 if (total_locks > DLM_MAX_MIGRATABLE_LOCKS) {
1046 /* rare, but possible */
1047 mlog(0, "argh. lockres has %d locks. this will "
1048 "require more than one network packet to "
1049 "migrate\n", total_locks);
1050 mig_cookie = dlm_get_next_mig_cookie();
1053 dlm_init_migratable_lockres(mres, res->lockname.name,
1054 res->lockname.len, total_locks,
1055 mig_cookie, flags, res->owner);
1058 for (i=DLM_GRANTED_LIST; i<=DLM_BLOCKED_LIST; i++) {
1059 queue = dlm_list_idx_to_ptr(res, i);
1060 list_for_each(iter, queue) {
1061 lock = list_entry (iter, struct dlm_lock, list);
1063 /* add another lock. */
1065 if (!dlm_add_lock_to_array(lock, mres, i))
1068 /* this filled the lock message,
1069 * we must send it immediately. */
1070 ret = dlm_send_mig_lockres_msg(dlm, mres, send_to,
1074 mlog(ML_ERROR, "dlm_send_mig_lockres_msg "
1075 "returned %d, TODO\n", ret);
1080 /* flush any remaining locks */
1081 ret = dlm_send_mig_lockres_msg(dlm, mres, send_to, res, total_locks);
1084 mlog(ML_ERROR, "dlm_send_mig_lockres_msg returned %d, "
1094 * this message will contain no more than one page worth of
1095 * recovery data, and it will work on only one lockres.
1096 * there may be many locks in this page, and we may need to wait
1097 * for additional packets to complete all the locks (rare, but
1101 * NOTE: the allocation error cases here are scary
1102 * we really cannot afford to fail an alloc in recovery
1103 * do we spin? returning an error only delays the problem really
1106 int dlm_mig_lockres_handler(struct o2net_msg *msg, u32 len, void *data)
1108 struct dlm_ctxt *dlm = data;
1109 struct dlm_migratable_lockres *mres =
1110 (struct dlm_migratable_lockres *)msg->buf;
1114 struct dlm_work_item *item = NULL;
1115 struct dlm_lock_resource *res = NULL;
1120 BUG_ON(!(mres->flags & (DLM_MRES_RECOVERY|DLM_MRES_MIGRATION)));
1122 real_master = mres->master;
1123 if (real_master == DLM_LOCK_RES_OWNER_UNKNOWN) {
1124 /* cannot migrate a lockres with no master */
1125 BUG_ON(!(mres->flags & DLM_MRES_RECOVERY));
1128 mlog(0, "%s message received from node %u\n",
1129 (mres->flags & DLM_MRES_RECOVERY) ?
1130 "recovery" : "migration", mres->master);
1131 if (mres->flags & DLM_MRES_ALL_DONE)
1132 mlog(0, "all done flag. all lockres data received!\n");
1135 buf = kmalloc(be16_to_cpu(msg->data_len), GFP_KERNEL);
1136 item = kcalloc(1, sizeof(*item), GFP_KERNEL);
1140 /* lookup the lock to see if we have a secondary queue for this
1141 * already... just add the locks in and this will have its owner
1142 * and RECOVERY flag changed when it completes. */
1143 res = dlm_lookup_lockres(dlm, mres->lockname, mres->lockname_len);
1145 /* this will get a ref on res */
1146 /* mark it as recovering/migrating and hash it */
1147 spin_lock(&res->spinlock);
1148 if (mres->flags & DLM_MRES_RECOVERY) {
1149 res->state |= DLM_LOCK_RES_RECOVERING;
1151 if (res->state & DLM_LOCK_RES_MIGRATING) {
1152 /* this is at least the second
1153 * lockres message */
1154 mlog(0, "lock %.*s is already migrating\n",
1157 } else if (res->state & DLM_LOCK_RES_RECOVERING) {
1158 /* caller should BUG */
1159 mlog(ML_ERROR, "node is attempting to migrate "
1160 "lock %.*s, but marked as recovering!\n",
1161 mres->lockname_len, mres->lockname);
1163 spin_unlock(&res->spinlock);
1166 res->state |= DLM_LOCK_RES_MIGRATING;
1168 spin_unlock(&res->spinlock);
1170 /* need to allocate, just like if it was
1171 * mastered here normally */
1172 res = dlm_new_lockres(dlm, mres->lockname, mres->lockname_len);
1176 /* to match the ref that we would have gotten if
1177 * dlm_lookup_lockres had succeeded */
1178 dlm_lockres_get(res);
1180 /* mark it as recovering/migrating and hash it */
1181 if (mres->flags & DLM_MRES_RECOVERY)
1182 res->state |= DLM_LOCK_RES_RECOVERING;
1184 res->state |= DLM_LOCK_RES_MIGRATING;
1186 spin_lock(&dlm->spinlock);
1187 __dlm_insert_lockres(dlm, res);
1188 spin_unlock(&dlm->spinlock);
1190 /* now that the new lockres is inserted,
1191 * make it usable by other processes */
1192 spin_lock(&res->spinlock);
1193 res->state &= ~DLM_LOCK_RES_IN_PROGRESS;
1194 spin_unlock(&res->spinlock);
1196 /* add an extra ref for just-allocated lockres
1197 * otherwise the lockres will be purged immediately */
1198 dlm_lockres_get(res);
1202 /* at this point we have allocated everything we need,
1203 * and we have a hashed lockres with an extra ref and
1204 * the proper res->state flags. */
1206 if (mres->master == DLM_LOCK_RES_OWNER_UNKNOWN) {
1207 /* migration cannot have an unknown master */
1208 BUG_ON(!(mres->flags & DLM_MRES_RECOVERY));
1209 mlog(0, "recovery has passed me a lockres with an "
1210 "unknown owner.. will need to requery: "
1211 "%.*s\n", mres->lockname_len, mres->lockname);
1213 spin_lock(&res->spinlock);
1214 dlm_change_lockres_owner(dlm, res, dlm->node_num);
1215 spin_unlock(&res->spinlock);
1218 /* queue up work for dlm_mig_lockres_worker */
1219 dlm_grab(dlm); /* get an extra ref for the work item */
1220 memcpy(buf, msg->buf, be16_to_cpu(msg->data_len)); /* copy the whole message */
1221 dlm_init_work_item(dlm, item, dlm_mig_lockres_worker, buf);
1222 item->u.ml.lockres = res; /* already have a ref */
1223 item->u.ml.real_master = real_master;
1224 spin_lock(&dlm->work_lock);
1225 list_add_tail(&item->list, &dlm->work_list);
1226 spin_unlock(&dlm->work_lock);
1227 schedule_work(&dlm->dispatched_work);
1243 static void dlm_mig_lockres_worker(struct dlm_work_item *item, void *data)
1245 struct dlm_ctxt *dlm = data;
1246 struct dlm_migratable_lockres *mres;
1248 struct dlm_lock_resource *res;
1252 mres = (struct dlm_migratable_lockres *)data;
1254 res = item->u.ml.lockres;
1255 real_master = item->u.ml.real_master;
1257 if (real_master == DLM_LOCK_RES_OWNER_UNKNOWN) {
1258 /* this case is super-rare. only occurs if
1259 * node death happens during migration. */
1261 ret = dlm_lockres_master_requery(dlm, res, &real_master);
1263 mlog(0, "dlm_lockres_master_requery ret=%d\n",
1267 if (real_master == DLM_LOCK_RES_OWNER_UNKNOWN) {
1268 mlog(0, "lockres %.*s not claimed. "
1269 "this node will take it.\n",
1270 res->lockname.len, res->lockname.name);
1272 mlog(0, "master needs to respond to sender "
1273 "that node %u still owns %.*s\n",
1274 real_master, res->lockname.len,
1275 res->lockname.name);
1276 /* cannot touch this lockres */
1281 ret = dlm_process_recovery_data(dlm, res, mres);
1283 mlog(0, "dlm_process_recovery_data returned %d\n", ret);
1285 mlog(0, "dlm_process_recovery_data succeeded\n");
1287 if ((mres->flags & (DLM_MRES_MIGRATION|DLM_MRES_ALL_DONE)) ==
1288 (DLM_MRES_MIGRATION|DLM_MRES_ALL_DONE)) {
1289 ret = dlm_finish_migration(dlm, res, mres->master);
1301 static int dlm_lockres_master_requery(struct dlm_ctxt *dlm,
1302 struct dlm_lock_resource *res,
1305 struct dlm_node_iter iter;
1309 *real_master = DLM_LOCK_RES_OWNER_UNKNOWN;
1311 /* we only reach here if one of the two nodes in a
1312 * migration died while the migration was in progress.
1313 * at this point we need to requery the master. we
1314 * know that the new_master got as far as creating
1315 * an mle on at least one node, but we do not know
1316 * if any nodes had actually cleared the mle and set
1317 * the master to the new_master. the old master
1318 * is supposed to set the owner to UNKNOWN in the
1319 * event of a new_master death, so the only possible
1320 * responses that we can get from nodes here are
1321 * that the master is new_master, or that the master
1323 * if all nodes come back with UNKNOWN then we know
1324 * the lock needs remastering here.
1325 * if any node comes back with a valid master, check
1326 * to see if that master is the one that we are
1327 * recovering. if so, then the new_master died and
1328 * we need to remaster this lock. if not, then the
1329 * new_master survived and that node will respond to
1330 * other nodes about the owner.
1331 * if there is an owner, this node needs to dump this
1332 * lockres and alert the sender that this lockres
1334 spin_lock(&dlm->spinlock);
1335 dlm_node_iter_init(dlm->domain_map, &iter);
1336 spin_unlock(&dlm->spinlock);
1338 while ((nodenum = dlm_node_iter_next(&iter)) >= 0) {
1339 /* do not send to self */
1340 if (nodenum == dlm->node_num)
1342 ret = dlm_do_master_requery(dlm, res, nodenum, real_master);
1346 /* TODO: need to figure a way to restart this */
1348 if (*real_master != DLM_LOCK_RES_OWNER_UNKNOWN) {
1349 mlog(0, "lock master is %u\n", *real_master);
1357 static int dlm_do_master_requery(struct dlm_ctxt *dlm,
1358 struct dlm_lock_resource *res,
1359 u8 nodenum, u8 *real_master)
1362 struct dlm_master_requery req;
1363 int status = DLM_LOCK_RES_OWNER_UNKNOWN;
1365 memset(&req, 0, sizeof(req));
1366 req.node_idx = dlm->node_num;
1367 req.namelen = res->lockname.len;
1368 memcpy(req.name, res->lockname.name, res->lockname.len);
1370 ret = o2net_send_message(DLM_MASTER_REQUERY_MSG, dlm->key,
1371 &req, sizeof(req), nodenum, &status);
1372 /* XXX: negative status not handled properly here. */
1377 BUG_ON(status > DLM_LOCK_RES_OWNER_UNKNOWN);
1378 *real_master = (u8) (status & 0xff);
1379 mlog(0, "node %u responded to master requery with %u\n",
1380 nodenum, *real_master);
1387 /* this function cannot error, so unless the sending
1388 * or receiving of the message failed, the owner can
1390 int dlm_master_requery_handler(struct o2net_msg *msg, u32 len, void *data)
1392 struct dlm_ctxt *dlm = data;
1393 struct dlm_master_requery *req = (struct dlm_master_requery *)msg->buf;
1394 struct dlm_lock_resource *res = NULL;
1395 int master = DLM_LOCK_RES_OWNER_UNKNOWN;
1396 u32 flags = DLM_ASSERT_MASTER_REQUERY;
1398 if (!dlm_grab(dlm)) {
1399 /* since the domain has gone away on this
1400 * node, the proper response is UNKNOWN */
1404 spin_lock(&dlm->spinlock);
1405 res = __dlm_lookup_lockres(dlm, req->name, req->namelen);
1407 spin_lock(&res->spinlock);
1408 master = res->owner;
1409 if (master == dlm->node_num) {
1410 int ret = dlm_dispatch_assert_master(dlm, res,
1413 mlog_errno(-ENOMEM);
1418 spin_unlock(&res->spinlock);
1420 spin_unlock(&dlm->spinlock);
1426 static inline struct list_head *
1427 dlm_list_num_to_pointer(struct dlm_lock_resource *res, int list_num)
1429 struct list_head *ret;
1430 BUG_ON(list_num < 0);
1431 BUG_ON(list_num > 2);
1432 ret = &(res->granted);
1436 /* TODO: do ast flush business
1437 * TODO: do MIGRATING and RECOVERING spinning
1441 * NOTE about in-flight requests during migration:
1443 * Before attempting the migrate, the master has marked the lockres as
1444 * MIGRATING and then flushed all of its pending ASTS. So any in-flight
1445 * requests either got queued before the MIGRATING flag got set, in which
1446 * case the lock data will reflect the change and a return message is on
1447 * the way, or the request failed to get in before MIGRATING got set. In
1448 * this case, the caller will be told to spin and wait for the MIGRATING
1449 * flag to be dropped, then recheck the master.
1450 * This holds true for the convert, cancel and unlock cases, and since lvb
1451 * updates are tied to these same messages, it applies to lvb updates as
1452 * well. For the lock case, there is no way a lock can be on the master
1453 * queue and not be on the secondary queue since the lock is always added
1454 * locally first. This means that the new target node will never be sent
1455 * a lock that he doesn't already have on the list.
1456 * In total, this means that the local lock is correct and should not be
1457 * updated to match the one sent by the master. Any messages sent back
1458 * from the master before the MIGRATING flag will bring the lock properly
1459 * up-to-date, and the change will be ordered properly for the waiter.
1460 * We will *not* attempt to modify the lock underneath the waiter.
1463 static int dlm_process_recovery_data(struct dlm_ctxt *dlm,
1464 struct dlm_lock_resource *res,
1465 struct dlm_migratable_lockres *mres)
1467 struct dlm_migratable_lock *ml;
1468 struct list_head *queue;
1469 struct dlm_lock *newlock = NULL;
1470 struct dlm_lockstatus *lksb = NULL;
1473 struct list_head *iter;
1474 struct dlm_lock *lock = NULL;
1476 mlog(0, "running %d locks for this lockres\n", mres->num_locks);
1477 for (i=0; i<mres->num_locks; i++) {
1478 ml = &(mres->ml[i]);
1479 BUG_ON(ml->highest_blocked != LKM_IVMODE);
1483 queue = dlm_list_num_to_pointer(res, ml->list);
1485 /* if the lock is for the local node it needs to
1486 * be moved to the proper location within the queue.
1487 * do not allocate a new lock structure. */
1488 if (ml->node == dlm->node_num) {
1489 /* MIGRATION ONLY! */
1490 BUG_ON(!(mres->flags & DLM_MRES_MIGRATION));
1492 spin_lock(&res->spinlock);
1493 list_for_each(iter, queue) {
1494 lock = list_entry (iter, struct dlm_lock, list);
1495 if (lock->ml.cookie != ml->cookie)
1501 /* lock is always created locally first, and
1502 * destroyed locally last. it must be on the list */
1504 mlog(ML_ERROR, "could not find local lock "
1505 "with cookie %"MLFu64"!\n",
1509 BUG_ON(lock->ml.node != ml->node);
1511 /* see NOTE above about why we do not update
1512 * to match the master here */
1514 /* move the lock to its proper place */
1515 /* do not alter lock refcount. switching lists. */
1516 list_del_init(&lock->list);
1517 list_add_tail(&lock->list, queue);
1518 spin_unlock(&res->spinlock);
1520 mlog(0, "just reordered a local lock!\n");
1524 /* lock is for another node. */
1525 newlock = dlm_new_lock(ml->type, ml->node,
1526 be64_to_cpu(ml->cookie), NULL);
1531 lksb = newlock->lksb;
1532 dlm_lock_attach_lockres(newlock, res);
1534 if (ml->convert_type != LKM_IVMODE) {
1535 BUG_ON(queue != &res->converting);
1536 newlock->ml.convert_type = ml->convert_type;
1538 lksb->flags |= (ml->flags &
1539 (DLM_LKSB_PUT_LVB|DLM_LKSB_GET_LVB));
1542 if (lksb->flags & DLM_LKSB_PUT_LVB) {
1543 /* other node was trying to update
1544 * lvb when node died. recreate the
1545 * lksb with the updated lvb. */
1546 memcpy(lksb->lvb, mres->lvb, DLM_LVB_LEN);
1548 /* otherwise, the node is sending its
1549 * most recent valid lvb info */
1550 BUG_ON(ml->type != LKM_EXMODE &&
1551 ml->type != LKM_PRMODE);
1552 if (res->lvb[0] && (ml->type == LKM_EXMODE ||
1553 memcmp(res->lvb, mres->lvb, DLM_LVB_LEN))) {
1554 mlog(ML_ERROR, "received bad lvb!\n");
1555 __dlm_print_one_lock_resource(res);
1558 memcpy(res->lvb, mres->lvb, DLM_LVB_LEN);
1564 * wrt lock queue ordering and recovery:
1565 * 1. order of locks on granted queue is
1567 * 2. order of locks on converting queue is
1568 * LOST with the node death. sorry charlie.
1569 * 3. order of locks on the blocked queue is
1571 * order of locks does not affect integrity, it
1572 * just means that a lock request may get pushed
1573 * back in line as a result of the node death.
1574 * also note that for a given node the lock order
1575 * for its secondary queue locks is preserved
1576 * relative to each other, but clearly *not*
1577 * preserved relative to locks from other nodes.
1579 spin_lock(&res->spinlock);
1580 dlm_lock_get(newlock);
1581 list_add_tail(&newlock->list, queue);
1582 spin_unlock(&res->spinlock);
1584 mlog(0, "done running all the locks\n");
1590 dlm_lock_put(newlock);
1597 void dlm_move_lockres_to_recovery_list(struct dlm_ctxt *dlm,
1598 struct dlm_lock_resource *res)
1601 struct list_head *queue, *iter, *iter2;
1602 struct dlm_lock *lock;
1604 res->state |= DLM_LOCK_RES_RECOVERING;
1605 if (!list_empty(&res->recovering))
1606 list_del_init(&res->recovering);
1607 list_add_tail(&res->recovering, &dlm->reco.resources);
1609 /* find any pending locks and put them back on proper list */
1610 for (i=DLM_BLOCKED_LIST; i>=DLM_GRANTED_LIST; i--) {
1611 queue = dlm_list_idx_to_ptr(res, i);
1612 list_for_each_safe(iter, iter2, queue) {
1613 lock = list_entry (iter, struct dlm_lock, list);
1615 if (lock->convert_pending) {
1616 /* move converting lock back to granted */
1617 BUG_ON(i != DLM_CONVERTING_LIST);
1618 mlog(0, "node died with convert pending "
1619 "on %.*s. move back to granted list.\n",
1620 res->lockname.len, res->lockname.name);
1621 dlm_revert_pending_convert(res, lock);
1622 lock->convert_pending = 0;
1623 } else if (lock->lock_pending) {
1624 /* remove pending lock requests completely */
1625 BUG_ON(i != DLM_BLOCKED_LIST);
1626 mlog(0, "node died with lock pending "
1627 "on %.*s. remove from blocked list and skip.\n",
1628 res->lockname.len, res->lockname.name);
1629 /* lock will be floating until ref in
1630 * dlmlock_remote is freed after the network
1631 * call returns. ok for it to not be on any
1632 * list since no ast can be called
1633 * (the master is dead). */
1634 dlm_revert_pending_lock(res, lock);
1635 lock->lock_pending = 0;
1636 } else if (lock->unlock_pending) {
1637 /* if an unlock was in progress, treat as
1638 * if this had completed successfully
1639 * before sending this lock state to the
1640 * new master. note that the dlm_unlock
1641 * call is still responsible for calling
1642 * the unlockast. that will happen after
1643 * the network call times out. for now,
1644 * just move lists to prepare the new
1645 * recovery master. */
1646 BUG_ON(i != DLM_GRANTED_LIST);
1647 mlog(0, "node died with unlock pending "
1648 "on %.*s. remove from blocked list and skip.\n",
1649 res->lockname.len, res->lockname.name);
1650 dlm_commit_pending_unlock(res, lock);
1651 lock->unlock_pending = 0;
1652 } else if (lock->cancel_pending) {
1653 /* if a cancel was in progress, treat as
1654 * if this had completed successfully
1655 * before sending this lock state to the
1657 BUG_ON(i != DLM_CONVERTING_LIST);
1658 mlog(0, "node died with cancel pending "
1659 "on %.*s. move back to granted list.\n",
1660 res->lockname.len, res->lockname.name);
1661 dlm_commit_pending_cancel(res, lock);
1662 lock->cancel_pending = 0;
1671 /* removes all recovered locks from the recovery list.
1672 * sets the res->owner to the new master.
1673 * unsets the RECOVERY flag and wakes waiters. */
1674 static void dlm_finish_local_lockres_recovery(struct dlm_ctxt *dlm,
1675 u8 dead_node, u8 new_master)
1678 struct list_head *iter, *iter2, *bucket;
1679 struct dlm_lock_resource *res;
1683 assert_spin_locked(&dlm->spinlock);
1685 list_for_each_safe(iter, iter2, &dlm->reco.resources) {
1686 res = list_entry (iter, struct dlm_lock_resource, recovering);
1687 if (res->owner == dead_node) {
1688 list_del_init(&res->recovering);
1689 spin_lock(&res->spinlock);
1690 dlm_change_lockres_owner(dlm, res, new_master);
1691 res->state &= ~DLM_LOCK_RES_RECOVERING;
1692 __dlm_dirty_lockres(dlm, res);
1693 spin_unlock(&res->spinlock);
1698 /* this will become unnecessary eventually, but
1699 * for now we need to run the whole hash, clear
1700 * the RECOVERING state and set the owner
1702 for (i=0; i<DLM_HASH_SIZE; i++) {
1703 bucket = &(dlm->resources[i]);
1704 list_for_each(iter, bucket) {
1705 res = list_entry (iter, struct dlm_lock_resource, list);
1706 if (res->state & DLM_LOCK_RES_RECOVERING) {
1707 if (res->owner == dead_node) {
1708 mlog(0, "(this=%u) res %.*s owner=%u "
1709 "was not on recovering list, but "
1710 "clearing state anyway\n",
1711 dlm->node_num, res->lockname.len,
1712 res->lockname.name, new_master);
1713 } else if (res->owner == dlm->node_num) {
1714 mlog(0, "(this=%u) res %.*s owner=%u "
1715 "was not on recovering list, "
1716 "owner is THIS node, clearing\n",
1717 dlm->node_num, res->lockname.len,
1718 res->lockname.name, new_master);
1722 spin_lock(&res->spinlock);
1723 dlm_change_lockres_owner(dlm, res, new_master);
1724 res->state &= ~DLM_LOCK_RES_RECOVERING;
1725 __dlm_dirty_lockres(dlm, res);
1726 spin_unlock(&res->spinlock);
1733 static inline int dlm_lvb_needs_invalidation(struct dlm_lock *lock, int local)
1736 if (lock->ml.type != LKM_EXMODE &&
1737 lock->ml.type != LKM_PRMODE)
1739 } else if (lock->ml.type == LKM_EXMODE)
1744 static void dlm_revalidate_lvb(struct dlm_ctxt *dlm,
1745 struct dlm_lock_resource *res, u8 dead_node)
1747 struct list_head *iter, *queue;
1748 struct dlm_lock *lock;
1749 int blank_lvb = 0, local = 0;
1753 assert_spin_locked(&dlm->spinlock);
1754 assert_spin_locked(&res->spinlock);
1756 if (res->owner == dlm->node_num)
1757 /* if this node owned the lockres, and if the dead node
1758 * had an EX when he died, blank out the lvb */
1759 search_node = dead_node;
1761 /* if this is a secondary lockres, and we had no EX or PR
1762 * locks granted, we can no longer trust the lvb */
1763 search_node = dlm->node_num;
1764 local = 1; /* check local state for valid lvb */
1767 for (i=DLM_GRANTED_LIST; i<=DLM_CONVERTING_LIST; i++) {
1768 queue = dlm_list_idx_to_ptr(res, i);
1769 list_for_each(iter, queue) {
1770 lock = list_entry (iter, struct dlm_lock, list);
1771 if (lock->ml.node == search_node) {
1772 if (dlm_lvb_needs_invalidation(lock, local)) {
1773 /* zero the lksb lvb and lockres lvb */
1775 memset(lock->lksb->lvb, 0, DLM_LVB_LEN);
1782 mlog(0, "clearing %.*s lvb, dead node %u had EX\n",
1783 res->lockname.len, res->lockname.name, dead_node);
1784 memset(res->lvb, 0, DLM_LVB_LEN);
1788 static void dlm_free_dead_locks(struct dlm_ctxt *dlm,
1789 struct dlm_lock_resource *res, u8 dead_node)
1791 struct list_head *iter, *tmpiter;
1792 struct dlm_lock *lock;
1794 /* this node is the lockres master:
1795 * 1) remove any stale locks for the dead node
1796 * 2) if the dead node had an EX when he died, blank out the lvb
1798 assert_spin_locked(&dlm->spinlock);
1799 assert_spin_locked(&res->spinlock);
1801 /* TODO: check pending_asts, pending_basts here */
1802 list_for_each_safe(iter, tmpiter, &res->granted) {
1803 lock = list_entry (iter, struct dlm_lock, list);
1804 if (lock->ml.node == dead_node) {
1805 list_del_init(&lock->list);
1809 list_for_each_safe(iter, tmpiter, &res->converting) {
1810 lock = list_entry (iter, struct dlm_lock, list);
1811 if (lock->ml.node == dead_node) {
1812 list_del_init(&lock->list);
1816 list_for_each_safe(iter, tmpiter, &res->blocked) {
1817 lock = list_entry (iter, struct dlm_lock, list);
1818 if (lock->ml.node == dead_node) {
1819 list_del_init(&lock->list);
1824 /* do not kick thread yet */
1825 __dlm_dirty_lockres(dlm, res);
1828 /* if this node is the recovery master, and there are no
1829 * locks for a given lockres owned by this node that are in
1830 * either PR or EX mode, zero out the lvb before requesting.
1835 static void dlm_do_local_recovery_cleanup(struct dlm_ctxt *dlm, u8 dead_node)
1837 struct list_head *iter;
1838 struct dlm_lock_resource *res;
1840 struct list_head *bucket;
1841 struct dlm_lock *lock;
1844 /* purge any stale mles */
1845 dlm_clean_master_list(dlm, dead_node);
1848 * now clean up all lock resources. there are two rules:
1850 * 1) if the dead node was the master, move the lockres
1851 * to the recovering list. set the RECOVERING flag.
1852 * this lockres needs to be cleaned up before it can
1855 * 2) if this node was the master, remove all locks from
1856 * each of the lockres queues that were owned by the
1857 * dead node. once recovery finishes, the dlm thread
1858 * can be kicked again to see if any ASTs or BASTs
1859 * need to be fired as a result.
1861 for (i=0; i<DLM_HASH_SIZE; i++) {
1862 bucket = &(dlm->resources[i]);
1863 list_for_each(iter, bucket) {
1864 res = list_entry (iter, struct dlm_lock_resource, list);
1865 /* always prune any $RECOVERY entries for dead nodes,
1866 * otherwise hangs can occur during later recovery */
1867 if (dlm_is_recovery_lock(res->lockname.name,
1868 res->lockname.len)) {
1869 spin_lock(&res->spinlock);
1870 list_for_each_entry(lock, &res->granted, list) {
1871 if (lock->ml.node == dead_node) {
1872 mlog(0, "AHA! there was "
1873 "a $RECOVERY lock for dead "
1875 dead_node, dlm->name);
1876 list_del_init(&lock->list);
1881 spin_unlock(&res->spinlock);
1884 spin_lock(&res->spinlock);
1885 /* zero the lvb if necessary */
1886 dlm_revalidate_lvb(dlm, res, dead_node);
1887 if (res->owner == dead_node)
1888 dlm_move_lockres_to_recovery_list(dlm, res);
1889 else if (res->owner == dlm->node_num) {
1890 dlm_free_dead_locks(dlm, res, dead_node);
1891 __dlm_lockres_calc_usage(dlm, res);
1893 spin_unlock(&res->spinlock);
1899 static void __dlm_hb_node_down(struct dlm_ctxt *dlm, int idx)
1901 assert_spin_locked(&dlm->spinlock);
1903 /* check to see if the node is already considered dead */
1904 if (!test_bit(idx, dlm->live_nodes_map)) {
1905 mlog(0, "for domain %s, node %d is already dead. "
1906 "another node likely did recovery already.\n",
1911 /* check to see if we do not care about this node */
1912 if (!test_bit(idx, dlm->domain_map)) {
1913 /* This also catches the case that we get a node down
1914 * but haven't joined the domain yet. */
1915 mlog(0, "node %u already removed from domain!\n", idx);
1919 clear_bit(idx, dlm->live_nodes_map);
1921 /* Clean up join state on node death. */
1922 if (dlm->joining_node == idx) {
1923 mlog(0, "Clearing join state for node %u\n", idx);
1924 __dlm_set_joining_node(dlm, DLM_LOCK_RES_OWNER_UNKNOWN);
1927 /* make sure local cleanup occurs before the heartbeat events */
1928 if (!test_bit(idx, dlm->recovery_map))
1929 dlm_do_local_recovery_cleanup(dlm, idx);
1931 /* notify anything attached to the heartbeat events */
1932 dlm_hb_event_notify_attached(dlm, idx, 0);
1934 mlog(0, "node %u being removed from domain map!\n", idx);
1935 clear_bit(idx, dlm->domain_map);
1936 /* wake up migration waiters if a node goes down.
1937 * perhaps later we can genericize this for other waiters. */
1938 wake_up(&dlm->migration_wq);
1940 if (test_bit(idx, dlm->recovery_map))
1941 mlog(0, "domain %s, node %u already added "
1942 "to recovery map!\n", dlm->name, idx);
1944 set_bit(idx, dlm->recovery_map);
1947 void dlm_hb_node_down_cb(struct o2nm_node *node, int idx, void *data)
1949 struct dlm_ctxt *dlm = data;
1954 spin_lock(&dlm->spinlock);
1955 __dlm_hb_node_down(dlm, idx);
1956 spin_unlock(&dlm->spinlock);
1961 void dlm_hb_node_up_cb(struct o2nm_node *node, int idx, void *data)
1963 struct dlm_ctxt *dlm = data;
1968 spin_lock(&dlm->spinlock);
1969 set_bit(idx, dlm->live_nodes_map);
1970 /* do NOT notify mle attached to the heartbeat events.
1971 * new nodes are not interesting in mastery until joined. */
1972 spin_unlock(&dlm->spinlock);
1977 static void dlm_reco_ast(void *astdata)
1979 struct dlm_ctxt *dlm = astdata;
1980 mlog(0, "ast for recovery lock fired!, this=%u, dlm=%s\n",
1981 dlm->node_num, dlm->name);
1983 static void dlm_reco_bast(void *astdata, int blocked_type)
1985 struct dlm_ctxt *dlm = astdata;
1986 mlog(0, "bast for recovery lock fired!, this=%u, dlm=%s\n",
1987 dlm->node_num, dlm->name);
1989 static void dlm_reco_unlock_ast(void *astdata, enum dlm_status st)
1991 mlog(0, "unlockast for recovery lock fired!\n");
1995 * dlm_pick_recovery_master will continually attempt to use
1996 * dlmlock() on the special "$RECOVERY" lockres with the
1997 * LKM_NOQUEUE flag to get an EX. every thread that enters
1998 * this function on each node racing to become the recovery
1999 * master will not stop attempting this until either:
2000 * a) this node gets the EX (and becomes the recovery master),
2001 * or b) dlm->reco.new_master gets set to some nodenum
2002 * != O2NM_INVALID_NODE_NUM (another node will do the reco).
2003 * so each time a recovery master is needed, the entire cluster
2004 * will sync at this point. if the new master dies, that will
2005 * be detected in dlm_do_recovery */
2006 static int dlm_pick_recovery_master(struct dlm_ctxt *dlm)
2008 enum dlm_status ret;
2009 struct dlm_lockstatus lksb;
2010 int status = -EINVAL;
2012 mlog(0, "starting recovery of %s at %lu, dead=%u, this=%u\n",
2013 dlm->name, jiffies, dlm->reco.dead_node, dlm->node_num);
2015 memset(&lksb, 0, sizeof(lksb));
2017 ret = dlmlock(dlm, LKM_EXMODE, &lksb, LKM_NOQUEUE|LKM_RECOVERY,
2018 DLM_RECOVERY_LOCK_NAME, dlm_reco_ast, dlm, dlm_reco_bast);
2020 mlog(0, "%s: dlmlock($RECOVERY) returned %d, lksb=%d\n",
2021 dlm->name, ret, lksb.status);
2023 if (ret == DLM_NORMAL) {
2024 mlog(0, "dlm=%s dlmlock says I got it (this=%u)\n",
2025 dlm->name, dlm->node_num);
2027 /* got the EX lock. check to see if another node
2028 * just became the reco master */
2029 if (dlm_reco_master_ready(dlm)) {
2030 mlog(0, "%s: got reco EX lock, but %u will "
2031 "do the recovery\n", dlm->name,
2032 dlm->reco.new_master);
2037 /* see if recovery was already finished elsewhere */
2038 spin_lock(&dlm->spinlock);
2039 if (dlm->reco.dead_node == O2NM_INVALID_NODE_NUM) {
2041 mlog(0, "%s: got reco EX lock, but "
2042 "node got recovered already\n", dlm->name);
2043 if (dlm->reco.new_master != O2NM_INVALID_NODE_NUM) {
2044 mlog(ML_ERROR, "%s: new master is %u "
2045 "but no dead node!\n",
2046 dlm->name, dlm->reco.new_master);
2050 spin_unlock(&dlm->spinlock);
2053 /* if this node has actually become the recovery master,
2054 * set the master and send the messages to begin recovery */
2056 mlog(0, "%s: dead=%u, this=%u, sending "
2057 "begin_reco now\n", dlm->name,
2058 dlm->reco.dead_node, dlm->node_num);
2059 status = dlm_send_begin_reco_message(dlm,
2060 dlm->reco.dead_node);
2061 /* this always succeeds */
2064 /* set the new_master to this node */
2065 spin_lock(&dlm->spinlock);
2066 dlm->reco.new_master = dlm->node_num;
2067 spin_unlock(&dlm->spinlock);
2070 /* recovery lock is a special case. ast will not get fired,
2071 * so just go ahead and unlock it. */
2072 ret = dlmunlock(dlm, &lksb, 0, dlm_reco_unlock_ast, dlm);
2073 if (ret == DLM_DENIED) {
2074 mlog(0, "got DLM_DENIED, trying LKM_CANCEL\n");
2075 ret = dlmunlock(dlm, &lksb, LKM_CANCEL, dlm_reco_unlock_ast, dlm);
2077 if (ret != DLM_NORMAL) {
2078 /* this would really suck. this could only happen
2079 * if there was a network error during the unlock
2080 * because of node death. this means the unlock
2081 * is actually "done" and the lock structure is
2082 * even freed. we can continue, but only
2083 * because this specific lock name is special. */
2084 mlog(ML_ERROR, "dlmunlock returned %d\n", ret);
2086 } else if (ret == DLM_NOTQUEUED) {
2087 mlog(0, "dlm=%s dlmlock says another node got it (this=%u)\n",
2088 dlm->name, dlm->node_num);
2089 /* another node is master. wait on
2090 * reco.new_master != O2NM_INVALID_NODE_NUM
2091 * for at most one second */
2092 wait_event_timeout(dlm->dlm_reco_thread_wq,
2093 dlm_reco_master_ready(dlm),
2094 msecs_to_jiffies(1000));
2095 if (!dlm_reco_master_ready(dlm)) {
2096 mlog(0, "%s: reco master taking awhile\n",
2100 /* another node has informed this one that it is reco master */
2101 mlog(0, "%s: reco master %u is ready to recover %u\n",
2102 dlm->name, dlm->reco.new_master, dlm->reco.dead_node);
2105 struct dlm_lock_resource *res;
2107 /* dlmlock returned something other than NOTQUEUED or NORMAL */
2108 mlog(ML_ERROR, "%s: got %s from dlmlock($RECOVERY), "
2109 "lksb.status=%s\n", dlm->name, dlm_errname(ret),
2110 dlm_errname(lksb.status));
2111 res = dlm_lookup_lockres(dlm, DLM_RECOVERY_LOCK_NAME,
2112 DLM_RECOVERY_LOCK_NAME_LEN);
2114 dlm_print_one_lock_resource(res);
2115 dlm_lockres_put(res);
2117 mlog(ML_ERROR, "recovery lock not found\n");
2125 static int dlm_send_begin_reco_message(struct dlm_ctxt *dlm, u8 dead_node)
2127 struct dlm_begin_reco br;
2129 struct dlm_node_iter iter;
2133 mlog_entry("%u\n", dead_node);
2135 mlog(0, "dead node is %u\n", dead_node);
2137 spin_lock(&dlm->spinlock);
2138 dlm_node_iter_init(dlm->domain_map, &iter);
2139 spin_unlock(&dlm->spinlock);
2141 clear_bit(dead_node, iter.node_map);
2143 memset(&br, 0, sizeof(br));
2144 br.node_idx = dlm->node_num;
2145 br.dead_node = dead_node;
2147 while ((nodenum = dlm_node_iter_next(&iter)) >= 0) {
2149 if (nodenum == dead_node) {
2150 mlog(0, "not sending begin reco to dead node "
2154 if (nodenum == dlm->node_num) {
2155 mlog(0, "not sending begin reco to self\n");
2160 mlog(0, "attempting to send begin reco msg to %d\n",
2162 ret = o2net_send_message(DLM_BEGIN_RECO_MSG, dlm->key,
2163 &br, sizeof(br), nodenum, &status);
2164 /* negative status is handled ok by caller here */
2167 if (dlm_is_host_down(ret)) {
2168 /* node is down. not involved in recovery
2169 * so just keep going */
2170 mlog(0, "%s: node %u was down when sending "
2171 "begin reco msg (%d)\n", dlm->name, nodenum, ret);
2175 struct dlm_lock_resource *res;
2176 /* this is now a serious problem, possibly ENOMEM
2177 * in the network stack. must retry */
2179 mlog(ML_ERROR, "begin reco of dlm %s to node %u "
2180 " returned %d\n", dlm->name, nodenum, ret);
2181 res = dlm_lookup_lockres(dlm, DLM_RECOVERY_LOCK_NAME,
2182 DLM_RECOVERY_LOCK_NAME_LEN);
2184 dlm_print_one_lock_resource(res);
2185 dlm_lockres_put(res);
2187 mlog(ML_ERROR, "recovery lock not found\n");
2189 /* sleep for a bit in hopes that we can avoid
2199 int dlm_begin_reco_handler(struct o2net_msg *msg, u32 len, void *data)
2201 struct dlm_ctxt *dlm = data;
2202 struct dlm_begin_reco *br = (struct dlm_begin_reco *)msg->buf;
2204 /* ok to return 0, domain has gone away */
2208 mlog(0, "node %u wants to recover node %u\n",
2209 br->node_idx, br->dead_node);
2211 dlm_fire_domain_eviction_callbacks(dlm, br->dead_node);
2213 spin_lock(&dlm->spinlock);
2214 if (dlm->reco.new_master != O2NM_INVALID_NODE_NUM) {
2215 if (test_bit(dlm->reco.new_master, dlm->recovery_map)) {
2216 mlog(0, "%s: new_master %u died, changing "
2217 "to %u\n", dlm->name, dlm->reco.new_master,
2220 mlog(0, "%s: new_master %u NOT DEAD, changing "
2221 "to %u\n", dlm->name, dlm->reco.new_master,
2223 /* may not have seen the new master as dead yet */
2226 if (dlm->reco.dead_node != O2NM_INVALID_NODE_NUM) {
2227 mlog(ML_NOTICE, "%s: dead_node previously set to %u, "
2228 "node %u changing it to %u\n", dlm->name,
2229 dlm->reco.dead_node, br->node_idx, br->dead_node);
2231 dlm->reco.new_master = br->node_idx;
2232 dlm->reco.dead_node = br->dead_node;
2233 if (!test_bit(br->dead_node, dlm->recovery_map)) {
2234 mlog(0, "recovery master %u sees %u as dead, but this "
2235 "node has not yet. marking %u as dead\n",
2236 br->node_idx, br->dead_node, br->dead_node);
2237 if (!test_bit(br->dead_node, dlm->domain_map) ||
2238 !test_bit(br->dead_node, dlm->live_nodes_map))
2239 mlog(0, "%u not in domain/live_nodes map "
2240 "so setting it in reco map manually\n",
2242 set_bit(br->dead_node, dlm->recovery_map);
2243 __dlm_hb_node_down(dlm, br->dead_node);
2245 spin_unlock(&dlm->spinlock);
2247 dlm_kick_recovery_thread(dlm);
2252 static int dlm_send_finalize_reco_message(struct dlm_ctxt *dlm)
2255 struct dlm_finalize_reco fr;
2256 struct dlm_node_iter iter;
2260 mlog(0, "finishing recovery for node %s:%u\n",
2261 dlm->name, dlm->reco.dead_node);
2263 spin_lock(&dlm->spinlock);
2264 dlm_node_iter_init(dlm->domain_map, &iter);
2265 spin_unlock(&dlm->spinlock);
2267 memset(&fr, 0, sizeof(fr));
2268 fr.node_idx = dlm->node_num;
2269 fr.dead_node = dlm->reco.dead_node;
2271 while ((nodenum = dlm_node_iter_next(&iter)) >= 0) {
2272 if (nodenum == dlm->node_num)
2274 ret = o2net_send_message(DLM_FINALIZE_RECO_MSG, dlm->key,
2275 &fr, sizeof(fr), nodenum, &status);
2278 if (dlm_is_host_down(ret)) {
2279 /* this has no effect on this recovery
2280 * session, so set the status to zero to
2281 * finish out the last recovery */
2282 mlog(ML_ERROR, "node %u went down after this "
2283 "node finished recovery.\n", nodenum);
2296 int dlm_finalize_reco_handler(struct o2net_msg *msg, u32 len, void *data)
2298 struct dlm_ctxt *dlm = data;
2299 struct dlm_finalize_reco *fr = (struct dlm_finalize_reco *)msg->buf;
2301 /* ok to return 0, domain has gone away */
2305 mlog(0, "node %u finalizing recovery of node %u\n",
2306 fr->node_idx, fr->dead_node);
2308 spin_lock(&dlm->spinlock);
2310 if (dlm->reco.new_master != fr->node_idx) {
2311 mlog(ML_ERROR, "node %u sent recovery finalize msg, but node "
2312 "%u is supposed to be the new master, dead=%u\n",
2313 fr->node_idx, dlm->reco.new_master, fr->dead_node);
2316 if (dlm->reco.dead_node != fr->dead_node) {
2317 mlog(ML_ERROR, "node %u sent recovery finalize msg for dead "
2318 "node %u, but node %u is supposed to be dead\n",
2319 fr->node_idx, fr->dead_node, dlm->reco.dead_node);
2323 dlm_finish_local_lockres_recovery(dlm, fr->dead_node, fr->node_idx);
2325 spin_unlock(&dlm->spinlock);
2327 dlm_reset_recovery(dlm);
2329 dlm_kick_recovery_thread(dlm);