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