1 // SPDX-License-Identifier: GPL-2.0-or-later
5 * standalone DLM module
7 * Copyright (C) 2004 Oracle. All rights reserved.
11 #include <linux/module.h>
13 #include <linux/types.h>
14 #include <linux/highmem.h>
15 #include <linux/init.h>
16 #include <linux/sysctl.h>
17 #include <linux/random.h>
18 #include <linux/blkdev.h>
19 #include <linux/socket.h>
20 #include <linux/inet.h>
21 #include <linux/timer.h>
22 #include <linux/kthread.h>
23 #include <linux/delay.h>
26 #include "../cluster/heartbeat.h"
27 #include "../cluster/nodemanager.h"
28 #include "../cluster/tcp.h"
31 #include "dlmcommon.h"
32 #include "dlmdomain.h"
34 #define MLOG_MASK_PREFIX (ML_DLM|ML_DLM_THREAD)
35 #include "../cluster/masklog.h"
37 static int dlm_thread(void *data
);
38 static void dlm_flush_asts(struct dlm_ctxt
*dlm
);
40 /* will exit holding res->spinlock, but may drop in function */
41 /* waits until flags are cleared on res->state */
42 void __dlm_wait_on_lockres_flags(struct dlm_lock_resource
*res
, int flags
)
44 DECLARE_WAITQUEUE(wait
, current
);
46 assert_spin_locked(&res
->spinlock
);
48 add_wait_queue(&res
->wq
, &wait
);
50 set_current_state(TASK_UNINTERRUPTIBLE
);
51 if (res
->state
& flags
) {
52 spin_unlock(&res
->spinlock
);
54 spin_lock(&res
->spinlock
);
57 remove_wait_queue(&res
->wq
, &wait
);
58 __set_current_state(TASK_RUNNING
);
61 int __dlm_lockres_has_locks(struct dlm_lock_resource
*res
)
63 if (list_empty(&res
->granted
) &&
64 list_empty(&res
->converting
) &&
65 list_empty(&res
->blocked
))
70 /* "unused": the lockres has no locks, is not on the dirty list,
71 * has no inflight locks (in the gap between mastery and acquiring
72 * the first lock), and has no bits in its refmap.
73 * truly ready to be freed. */
74 int __dlm_lockres_unused(struct dlm_lock_resource
*res
)
78 assert_spin_locked(&res
->spinlock
);
80 if (__dlm_lockres_has_locks(res
))
83 /* Locks are in the process of being created */
84 if (res
->inflight_locks
)
87 if (!list_empty(&res
->dirty
) || res
->state
& DLM_LOCK_RES_DIRTY
)
90 if (res
->state
& (DLM_LOCK_RES_RECOVERING
|
91 DLM_LOCK_RES_RECOVERY_WAITING
))
94 /* Another node has this resource with this node as the master */
95 bit
= find_first_bit(res
->refmap
, O2NM_MAX_NODES
);
96 if (bit
< O2NM_MAX_NODES
)
103 /* Call whenever you may have added or deleted something from one of
104 * the lockres queue's. This will figure out whether it belongs on the
105 * unused list or not and does the appropriate thing. */
106 void __dlm_lockres_calc_usage(struct dlm_ctxt
*dlm
,
107 struct dlm_lock_resource
*res
)
109 assert_spin_locked(&dlm
->spinlock
);
110 assert_spin_locked(&res
->spinlock
);
112 if (__dlm_lockres_unused(res
)){
113 if (list_empty(&res
->purge
)) {
114 mlog(0, "%s: Adding res %.*s to purge list\n",
115 dlm
->name
, res
->lockname
.len
, res
->lockname
.name
);
117 res
->last_used
= jiffies
;
118 dlm_lockres_get(res
);
119 list_add_tail(&res
->purge
, &dlm
->purge_list
);
122 } else if (!list_empty(&res
->purge
)) {
123 mlog(0, "%s: Removing res %.*s from purge list\n",
124 dlm
->name
, res
->lockname
.len
, res
->lockname
.name
);
126 list_del_init(&res
->purge
);
127 dlm_lockres_put(res
);
132 void dlm_lockres_calc_usage(struct dlm_ctxt
*dlm
,
133 struct dlm_lock_resource
*res
)
135 spin_lock(&dlm
->spinlock
);
136 spin_lock(&res
->spinlock
);
138 __dlm_lockres_calc_usage(dlm
, res
);
140 spin_unlock(&res
->spinlock
);
141 spin_unlock(&dlm
->spinlock
);
145 * Do the real purge work:
146 * unhash the lockres, and
147 * clear flag DLM_LOCK_RES_DROPPING_REF.
148 * It requires dlm and lockres spinlock to be taken.
150 void __dlm_do_purge_lockres(struct dlm_ctxt
*dlm
,
151 struct dlm_lock_resource
*res
)
153 assert_spin_locked(&dlm
->spinlock
);
154 assert_spin_locked(&res
->spinlock
);
156 if (!list_empty(&res
->purge
)) {
157 mlog(0, "%s: Removing res %.*s from purgelist\n",
158 dlm
->name
, res
->lockname
.len
, res
->lockname
.name
);
159 list_del_init(&res
->purge
);
160 dlm_lockres_put(res
);
164 if (!__dlm_lockres_unused(res
)) {
165 mlog(ML_ERROR
, "%s: res %.*s in use after deref\n",
166 dlm
->name
, res
->lockname
.len
, res
->lockname
.name
);
167 __dlm_print_one_lock_resource(res
);
171 __dlm_unhash_lockres(dlm
, res
);
173 spin_lock(&dlm
->track_lock
);
174 if (!list_empty(&res
->tracking
))
175 list_del_init(&res
->tracking
);
177 mlog(ML_ERROR
, "%s: Resource %.*s not on the Tracking list\n",
178 dlm
->name
, res
->lockname
.len
, res
->lockname
.name
);
179 __dlm_print_one_lock_resource(res
);
181 spin_unlock(&dlm
->track_lock
);
184 * lockres is not in the hash now. drop the flag and wake up
185 * any processes waiting in dlm_get_lock_resource.
187 res
->state
&= ~DLM_LOCK_RES_DROPPING_REF
;
190 static void dlm_purge_lockres(struct dlm_ctxt
*dlm
,
191 struct dlm_lock_resource
*res
)
196 assert_spin_locked(&dlm
->spinlock
);
197 assert_spin_locked(&res
->spinlock
);
199 master
= (res
->owner
== dlm
->node_num
);
201 mlog(0, "%s: Purging res %.*s, master %d\n", dlm
->name
,
202 res
->lockname
.len
, res
->lockname
.name
, master
);
205 if (res
->state
& DLM_LOCK_RES_DROPPING_REF
) {
206 mlog(ML_NOTICE
, "%s: res %.*s already in DLM_LOCK_RES_DROPPING_REF state\n",
207 dlm
->name
, res
->lockname
.len
, res
->lockname
.name
);
208 spin_unlock(&res
->spinlock
);
212 res
->state
|= DLM_LOCK_RES_DROPPING_REF
;
213 /* drop spinlock... retake below */
214 spin_unlock(&res
->spinlock
);
215 spin_unlock(&dlm
->spinlock
);
217 spin_lock(&res
->spinlock
);
218 /* This ensures that clear refmap is sent after the set */
219 __dlm_wait_on_lockres_flags(res
, DLM_LOCK_RES_SETREF_INPROG
);
220 spin_unlock(&res
->spinlock
);
222 /* clear our bit from the master's refmap, ignore errors */
223 ret
= dlm_drop_lockres_ref(dlm
, res
);
225 if (!dlm_is_host_down(ret
))
228 spin_lock(&dlm
->spinlock
);
229 spin_lock(&res
->spinlock
);
232 if (!list_empty(&res
->purge
)) {
233 mlog(0, "%s: Removing res %.*s from purgelist, master %d\n",
234 dlm
->name
, res
->lockname
.len
, res
->lockname
.name
, master
);
235 list_del_init(&res
->purge
);
236 dlm_lockres_put(res
);
240 if (!master
&& ret
== DLM_DEREF_RESPONSE_INPROG
) {
241 mlog(0, "%s: deref %.*s in progress\n",
242 dlm
->name
, res
->lockname
.len
, res
->lockname
.name
);
243 spin_unlock(&res
->spinlock
);
247 if (!__dlm_lockres_unused(res
)) {
248 mlog(ML_ERROR
, "%s: res %.*s in use after deref\n",
249 dlm
->name
, res
->lockname
.len
, res
->lockname
.name
);
250 __dlm_print_one_lock_resource(res
);
254 __dlm_unhash_lockres(dlm
, res
);
256 spin_lock(&dlm
->track_lock
);
257 if (!list_empty(&res
->tracking
))
258 list_del_init(&res
->tracking
);
260 mlog(ML_ERROR
, "Resource %.*s not on the Tracking list\n",
261 res
->lockname
.len
, res
->lockname
.name
);
262 __dlm_print_one_lock_resource(res
);
264 spin_unlock(&dlm
->track_lock
);
266 /* lockres is not in the hash now. drop the flag and wake up
267 * any processes waiting in dlm_get_lock_resource. */
269 res
->state
&= ~DLM_LOCK_RES_DROPPING_REF
;
270 spin_unlock(&res
->spinlock
);
273 spin_unlock(&res
->spinlock
);
276 static void dlm_run_purge_list(struct dlm_ctxt
*dlm
,
279 unsigned int run_max
, unused
;
280 unsigned long purge_jiffies
;
281 struct dlm_lock_resource
*lockres
;
283 spin_lock(&dlm
->spinlock
);
284 run_max
= dlm
->purge_count
;
286 while(run_max
&& !list_empty(&dlm
->purge_list
)) {
289 lockres
= list_entry(dlm
->purge_list
.next
,
290 struct dlm_lock_resource
, purge
);
292 spin_lock(&lockres
->spinlock
);
294 purge_jiffies
= lockres
->last_used
+
295 msecs_to_jiffies(DLM_PURGE_INTERVAL_MS
);
297 /* Make sure that we want to be processing this guy at
299 if (!purge_now
&& time_after(purge_jiffies
, jiffies
)) {
300 /* Since resources are added to the purge list
301 * in tail order, we can stop at the first
302 * unpurgable resource -- anyone added after
303 * him will have a greater last_used value */
304 spin_unlock(&lockres
->spinlock
);
308 /* Status of the lockres *might* change so double
309 * check. If the lockres is unused, holding the dlm
310 * spinlock will prevent people from getting and more
312 unused
= __dlm_lockres_unused(lockres
);
314 (lockres
->state
& DLM_LOCK_RES_MIGRATING
) ||
315 (lockres
->inflight_assert_workers
!= 0)) {
316 mlog(0, "%s: res %.*s is in use or being remastered, "
317 "used %d, state %d, assert master workers %u\n",
318 dlm
->name
, lockres
->lockname
.len
,
319 lockres
->lockname
.name
,
320 !unused
, lockres
->state
,
321 lockres
->inflight_assert_workers
);
322 list_move_tail(&lockres
->purge
, &dlm
->purge_list
);
323 spin_unlock(&lockres
->spinlock
);
327 dlm_lockres_get(lockres
);
329 dlm_purge_lockres(dlm
, lockres
);
331 dlm_lockres_put(lockres
);
333 /* Avoid adding any scheduling latencies */
334 cond_resched_lock(&dlm
->spinlock
);
337 spin_unlock(&dlm
->spinlock
);
340 static void dlm_shuffle_lists(struct dlm_ctxt
*dlm
,
341 struct dlm_lock_resource
*res
)
343 struct dlm_lock
*lock
, *target
;
347 * Because this function is called with the lockres
348 * spinlock, and because we know that it is not migrating/
349 * recovering/in-progress, it is fine to reserve asts and
350 * basts right before queueing them all throughout
352 assert_spin_locked(&dlm
->ast_lock
);
353 assert_spin_locked(&res
->spinlock
);
354 BUG_ON((res
->state
& (DLM_LOCK_RES_MIGRATING
|
355 DLM_LOCK_RES_RECOVERING
|
356 DLM_LOCK_RES_IN_PROGRESS
)));
359 if (list_empty(&res
->converting
))
361 mlog(0, "%s: res %.*s has locks on the convert queue\n", dlm
->name
,
362 res
->lockname
.len
, res
->lockname
.name
);
364 target
= list_entry(res
->converting
.next
, struct dlm_lock
, list
);
365 if (target
->ml
.convert_type
== LKM_IVMODE
) {
366 mlog(ML_ERROR
, "%s: res %.*s converting lock to invalid mode\n",
367 dlm
->name
, res
->lockname
.len
, res
->lockname
.name
);
370 list_for_each_entry(lock
, &res
->granted
, list
) {
373 if (!dlm_lock_compatible(lock
->ml
.type
,
374 target
->ml
.convert_type
)) {
376 /* queue the BAST if not already */
377 if (lock
->ml
.highest_blocked
== LKM_IVMODE
) {
378 __dlm_lockres_reserve_ast(res
);
379 __dlm_queue_bast(dlm
, lock
);
381 /* update the highest_blocked if needed */
382 if (lock
->ml
.highest_blocked
< target
->ml
.convert_type
)
383 lock
->ml
.highest_blocked
=
384 target
->ml
.convert_type
;
388 list_for_each_entry(lock
, &res
->converting
, list
) {
391 if (!dlm_lock_compatible(lock
->ml
.type
,
392 target
->ml
.convert_type
)) {
394 if (lock
->ml
.highest_blocked
== LKM_IVMODE
) {
395 __dlm_lockres_reserve_ast(res
);
396 __dlm_queue_bast(dlm
, lock
);
398 if (lock
->ml
.highest_blocked
< target
->ml
.convert_type
)
399 lock
->ml
.highest_blocked
=
400 target
->ml
.convert_type
;
404 /* we can convert the lock */
406 spin_lock(&target
->spinlock
);
407 BUG_ON(target
->ml
.highest_blocked
!= LKM_IVMODE
);
409 mlog(0, "%s: res %.*s, AST for Converting lock %u:%llu, type "
410 "%d => %d, node %u\n", dlm
->name
, res
->lockname
.len
,
412 dlm_get_lock_cookie_node(be64_to_cpu(target
->ml
.cookie
)),
413 dlm_get_lock_cookie_seq(be64_to_cpu(target
->ml
.cookie
)),
415 target
->ml
.convert_type
, target
->ml
.node
);
417 target
->ml
.type
= target
->ml
.convert_type
;
418 target
->ml
.convert_type
= LKM_IVMODE
;
419 list_move_tail(&target
->list
, &res
->granted
);
421 BUG_ON(!target
->lksb
);
422 target
->lksb
->status
= DLM_NORMAL
;
424 spin_unlock(&target
->spinlock
);
426 __dlm_lockres_reserve_ast(res
);
427 __dlm_queue_ast(dlm
, target
);
428 /* go back and check for more */
433 if (list_empty(&res
->blocked
))
435 target
= list_entry(res
->blocked
.next
, struct dlm_lock
, list
);
437 list_for_each_entry(lock
, &res
->granted
, list
) {
440 if (!dlm_lock_compatible(lock
->ml
.type
, target
->ml
.type
)) {
442 if (lock
->ml
.highest_blocked
== LKM_IVMODE
) {
443 __dlm_lockres_reserve_ast(res
);
444 __dlm_queue_bast(dlm
, lock
);
446 if (lock
->ml
.highest_blocked
< target
->ml
.type
)
447 lock
->ml
.highest_blocked
= target
->ml
.type
;
451 list_for_each_entry(lock
, &res
->converting
, list
) {
454 if (!dlm_lock_compatible(lock
->ml
.type
, target
->ml
.type
)) {
456 if (lock
->ml
.highest_blocked
== LKM_IVMODE
) {
457 __dlm_lockres_reserve_ast(res
);
458 __dlm_queue_bast(dlm
, lock
);
460 if (lock
->ml
.highest_blocked
< target
->ml
.type
)
461 lock
->ml
.highest_blocked
= target
->ml
.type
;
465 /* we can grant the blocked lock (only
466 * possible if converting list empty) */
468 spin_lock(&target
->spinlock
);
469 BUG_ON(target
->ml
.highest_blocked
!= LKM_IVMODE
);
471 mlog(0, "%s: res %.*s, AST for Blocked lock %u:%llu, type %d, "
472 "node %u\n", dlm
->name
, res
->lockname
.len
,
474 dlm_get_lock_cookie_node(be64_to_cpu(target
->ml
.cookie
)),
475 dlm_get_lock_cookie_seq(be64_to_cpu(target
->ml
.cookie
)),
476 target
->ml
.type
, target
->ml
.node
);
478 /* target->ml.type is already correct */
479 list_move_tail(&target
->list
, &res
->granted
);
481 BUG_ON(!target
->lksb
);
482 target
->lksb
->status
= DLM_NORMAL
;
484 spin_unlock(&target
->spinlock
);
486 __dlm_lockres_reserve_ast(res
);
487 __dlm_queue_ast(dlm
, target
);
488 /* go back and check for more */
496 /* must have NO locks when calling this with res !=NULL * */
497 void dlm_kick_thread(struct dlm_ctxt
*dlm
, struct dlm_lock_resource
*res
)
500 spin_lock(&dlm
->spinlock
);
501 spin_lock(&res
->spinlock
);
502 __dlm_dirty_lockres(dlm
, res
);
503 spin_unlock(&res
->spinlock
);
504 spin_unlock(&dlm
->spinlock
);
506 wake_up(&dlm
->dlm_thread_wq
);
509 void __dlm_dirty_lockres(struct dlm_ctxt
*dlm
, struct dlm_lock_resource
*res
)
511 assert_spin_locked(&dlm
->spinlock
);
512 assert_spin_locked(&res
->spinlock
);
514 /* don't shuffle secondary queues */
515 if (res
->owner
== dlm
->node_num
) {
516 if (res
->state
& (DLM_LOCK_RES_MIGRATING
|
517 DLM_LOCK_RES_BLOCK_DIRTY
))
520 if (list_empty(&res
->dirty
)) {
521 /* ref for dirty_list */
522 dlm_lockres_get(res
);
523 list_add_tail(&res
->dirty
, &dlm
->dirty_list
);
524 res
->state
|= DLM_LOCK_RES_DIRTY
;
528 mlog(0, "%s: res %.*s\n", dlm
->name
, res
->lockname
.len
,
533 /* Launch the NM thread for the mounted volume */
534 int dlm_launch_thread(struct dlm_ctxt
*dlm
)
536 mlog(0, "Starting dlm_thread...\n");
538 dlm
->dlm_thread_task
= kthread_run(dlm_thread
, dlm
, "dlm-%s",
540 if (IS_ERR(dlm
->dlm_thread_task
)) {
541 mlog_errno(PTR_ERR(dlm
->dlm_thread_task
));
542 dlm
->dlm_thread_task
= NULL
;
549 void dlm_complete_thread(struct dlm_ctxt
*dlm
)
551 if (dlm
->dlm_thread_task
) {
552 mlog(ML_KTHREAD
, "Waiting for dlm thread to exit\n");
553 kthread_stop(dlm
->dlm_thread_task
);
554 dlm
->dlm_thread_task
= NULL
;
558 static int dlm_dirty_list_empty(struct dlm_ctxt
*dlm
)
562 spin_lock(&dlm
->spinlock
);
563 empty
= list_empty(&dlm
->dirty_list
);
564 spin_unlock(&dlm
->spinlock
);
569 static void dlm_flush_asts(struct dlm_ctxt
*dlm
)
572 struct dlm_lock
*lock
;
573 struct dlm_lock_resource
*res
;
576 spin_lock(&dlm
->ast_lock
);
577 while (!list_empty(&dlm
->pending_asts
)) {
578 lock
= list_entry(dlm
->pending_asts
.next
,
579 struct dlm_lock
, ast_list
);
580 /* get an extra ref on lock */
583 mlog(0, "%s: res %.*s, Flush AST for lock %u:%llu, type %d, "
584 "node %u\n", dlm
->name
, res
->lockname
.len
,
586 dlm_get_lock_cookie_node(be64_to_cpu(lock
->ml
.cookie
)),
587 dlm_get_lock_cookie_seq(be64_to_cpu(lock
->ml
.cookie
)),
588 lock
->ml
.type
, lock
->ml
.node
);
590 BUG_ON(!lock
->ast_pending
);
592 /* remove from list (including ref) */
593 list_del_init(&lock
->ast_list
);
595 spin_unlock(&dlm
->ast_lock
);
597 if (lock
->ml
.node
!= dlm
->node_num
) {
598 ret
= dlm_do_remote_ast(dlm
, res
, lock
);
602 dlm_do_local_ast(dlm
, res
, lock
);
604 spin_lock(&dlm
->ast_lock
);
606 /* possible that another ast was queued while
607 * we were delivering the last one */
608 if (!list_empty(&lock
->ast_list
)) {
609 mlog(0, "%s: res %.*s, AST queued while flushing last "
610 "one\n", dlm
->name
, res
->lockname
.len
,
613 lock
->ast_pending
= 0;
615 /* drop the extra ref.
616 * this may drop it completely. */
618 dlm_lockres_release_ast(dlm
, res
);
621 while (!list_empty(&dlm
->pending_basts
)) {
622 lock
= list_entry(dlm
->pending_basts
.next
,
623 struct dlm_lock
, bast_list
);
624 /* get an extra ref on lock */
628 BUG_ON(!lock
->bast_pending
);
630 /* get the highest blocked lock, and reset */
631 spin_lock(&lock
->spinlock
);
632 BUG_ON(lock
->ml
.highest_blocked
<= LKM_IVMODE
);
633 hi
= lock
->ml
.highest_blocked
;
634 lock
->ml
.highest_blocked
= LKM_IVMODE
;
635 spin_unlock(&lock
->spinlock
);
637 /* remove from list (including ref) */
638 list_del_init(&lock
->bast_list
);
640 spin_unlock(&dlm
->ast_lock
);
642 mlog(0, "%s: res %.*s, Flush BAST for lock %u:%llu, "
643 "blocked %d, node %u\n",
644 dlm
->name
, res
->lockname
.len
, res
->lockname
.name
,
645 dlm_get_lock_cookie_node(be64_to_cpu(lock
->ml
.cookie
)),
646 dlm_get_lock_cookie_seq(be64_to_cpu(lock
->ml
.cookie
)),
649 if (lock
->ml
.node
!= dlm
->node_num
) {
650 ret
= dlm_send_proxy_bast(dlm
, res
, lock
, hi
);
654 dlm_do_local_bast(dlm
, res
, lock
, hi
);
656 spin_lock(&dlm
->ast_lock
);
658 /* possible that another bast was queued while
659 * we were delivering the last one */
660 if (!list_empty(&lock
->bast_list
)) {
661 mlog(0, "%s: res %.*s, BAST queued while flushing last "
662 "one\n", dlm
->name
, res
->lockname
.len
,
665 lock
->bast_pending
= 0;
667 /* drop the extra ref.
668 * this may drop it completely. */
670 dlm_lockres_release_ast(dlm
, res
);
672 wake_up(&dlm
->ast_wq
);
673 spin_unlock(&dlm
->ast_lock
);
677 #define DLM_THREAD_TIMEOUT_MS (4 * 1000)
678 #define DLM_THREAD_MAX_DIRTY 100
680 static int dlm_thread(void *data
)
682 struct dlm_lock_resource
*res
;
683 struct dlm_ctxt
*dlm
= data
;
684 unsigned long timeout
= msecs_to_jiffies(DLM_THREAD_TIMEOUT_MS
);
686 mlog(0, "dlm thread running for %s...\n", dlm
->name
);
688 while (!kthread_should_stop()) {
689 int n
= DLM_THREAD_MAX_DIRTY
;
691 /* dlm_shutting_down is very point-in-time, but that
692 * doesn't matter as we'll just loop back around if we
693 * get false on the leading edge of a state
695 dlm_run_purge_list(dlm
, dlm_shutting_down(dlm
));
697 /* We really don't want to hold dlm->spinlock while
698 * calling dlm_shuffle_lists on each lockres that
699 * needs to have its queues adjusted and AST/BASTs
700 * run. So let's pull each entry off the dirty_list
701 * and drop dlm->spinlock ASAP. Once off the list,
702 * res->spinlock needs to be taken again to protect
703 * the queues while calling dlm_shuffle_lists. */
704 spin_lock(&dlm
->spinlock
);
705 while (!list_empty(&dlm
->dirty_list
)) {
707 res
= list_entry(dlm
->dirty_list
.next
,
708 struct dlm_lock_resource
, dirty
);
710 /* peel a lockres off, remove it from the list,
711 * unset the dirty flag and drop the dlm lock */
713 dlm_lockres_get(res
);
715 spin_lock(&res
->spinlock
);
716 /* We clear the DLM_LOCK_RES_DIRTY state once we shuffle lists below */
717 list_del_init(&res
->dirty
);
718 spin_unlock(&res
->spinlock
);
719 spin_unlock(&dlm
->spinlock
);
720 /* Drop dirty_list ref */
721 dlm_lockres_put(res
);
723 /* lockres can be re-dirtied/re-added to the
724 * dirty_list in this gap, but that is ok */
726 spin_lock(&dlm
->ast_lock
);
727 spin_lock(&res
->spinlock
);
728 if (res
->owner
!= dlm
->node_num
) {
729 __dlm_print_one_lock_resource(res
);
730 mlog(ML_ERROR
, "%s: inprog %d, mig %d, reco %d,"
731 " dirty %d\n", dlm
->name
,
732 !!(res
->state
& DLM_LOCK_RES_IN_PROGRESS
),
733 !!(res
->state
& DLM_LOCK_RES_MIGRATING
),
734 !!(res
->state
& DLM_LOCK_RES_RECOVERING
),
735 !!(res
->state
& DLM_LOCK_RES_DIRTY
));
737 BUG_ON(res
->owner
!= dlm
->node_num
);
739 /* it is now ok to move lockreses in these states
740 * to the dirty list, assuming that they will only be
741 * dirty for a short while. */
742 BUG_ON(res
->state
& DLM_LOCK_RES_MIGRATING
);
743 if (res
->state
& (DLM_LOCK_RES_IN_PROGRESS
|
744 DLM_LOCK_RES_RECOVERING
|
745 DLM_LOCK_RES_RECOVERY_WAITING
)) {
746 /* move it to the tail and keep going */
747 res
->state
&= ~DLM_LOCK_RES_DIRTY
;
748 spin_unlock(&res
->spinlock
);
749 spin_unlock(&dlm
->ast_lock
);
750 mlog(0, "%s: res %.*s, inprogress, delay list "
751 "shuffle, state %d\n", dlm
->name
,
752 res
->lockname
.len
, res
->lockname
.name
,
758 /* at this point the lockres is not migrating/
759 * recovering/in-progress. we have the lockres
760 * spinlock and do NOT have the dlm lock.
761 * safe to reserve/queue asts and run the lists. */
763 /* called while holding lockres lock */
764 dlm_shuffle_lists(dlm
, res
);
765 res
->state
&= ~DLM_LOCK_RES_DIRTY
;
766 spin_unlock(&res
->spinlock
);
767 spin_unlock(&dlm
->ast_lock
);
769 dlm_lockres_calc_usage(dlm
, res
);
773 spin_lock(&dlm
->spinlock
);
774 /* if the lock was in-progress, stick
775 * it on the back of the list */
777 spin_lock(&res
->spinlock
);
778 __dlm_dirty_lockres(dlm
, res
);
779 spin_unlock(&res
->spinlock
);
781 dlm_lockres_put(res
);
783 /* unlikely, but we may need to give time to
786 mlog(0, "%s: Throttling dlm thread\n",
792 spin_unlock(&dlm
->spinlock
);
795 /* yield and continue right away if there is more work to do */
801 wait_event_interruptible_timeout(dlm
->dlm_thread_wq
,
802 !dlm_dirty_list_empty(dlm
) ||
803 kthread_should_stop(),
807 mlog(0, "quitting DLM thread\n");