1 /******************************************************************************
2 *******************************************************************************
4 ** Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
5 ** Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved.
7 ** This copyrighted material is made available to anyone wishing to use,
8 ** modify, copy, or redistribute it subject to the terms and conditions
9 ** of the GNU General Public License v.2.
11 *******************************************************************************
12 ******************************************************************************/
14 #include "dlm_internal.h"
20 static struct list_head ast_queue;
21 static spinlock_t ast_queue_lock;
22 static struct task_struct * astd_task;
23 static unsigned long astd_wakeflags;
24 static struct mutex astd_running;
27 void dlm_del_ast(struct dlm_lkb *lkb)
29 spin_lock(&ast_queue_lock);
30 if (lkb->lkb_ast_type & (AST_COMP | AST_BAST))
31 list_del(&lkb->lkb_astqueue);
32 spin_unlock(&ast_queue_lock);
35 void dlm_add_ast(struct dlm_lkb *lkb, int type)
37 if (lkb->lkb_flags & DLM_IFL_USER) {
38 dlm_user_add_ast(lkb, type);
42 spin_lock(&ast_queue_lock);
43 if (!(lkb->lkb_ast_type & (AST_COMP | AST_BAST))) {
44 kref_get(&lkb->lkb_ref);
45 list_add_tail(&lkb->lkb_astqueue, &ast_queue);
47 lkb->lkb_ast_type |= type;
48 spin_unlock(&ast_queue_lock);
50 set_bit(WAKE_ASTS, &astd_wakeflags);
51 wake_up_process(astd_task);
54 static void process_asts(void)
56 struct dlm_ls *ls = NULL;
57 struct dlm_rsb *r = NULL;
59 void (*cast) (long param);
60 void (*bast) (long param, int mode);
61 int type = 0, found, bmode;
65 spin_lock(&ast_queue_lock);
66 list_for_each_entry(lkb, &ast_queue, lkb_astqueue) {
67 r = lkb->lkb_resource;
70 if (dlm_locking_stopped(ls))
73 list_del(&lkb->lkb_astqueue);
74 type = lkb->lkb_ast_type;
75 lkb->lkb_ast_type = 0;
79 spin_unlock(&ast_queue_lock);
84 cast = lkb->lkb_astaddr;
85 bast = lkb->lkb_bastaddr;
86 bmode = lkb->lkb_bastmode;
88 if ((type & AST_COMP) && cast)
89 cast(lkb->lkb_astparam);
91 /* FIXME: Is it safe to look at lkb_grmode here
92 without doing a lock_rsb() ?
93 Look at other checks in v1 to avoid basts. */
95 if ((type & AST_BAST) && bast)
96 if (!dlm_modes_compat(lkb->lkb_grmode, bmode))
97 bast(lkb->lkb_astparam, bmode);
99 /* this removes the reference added by dlm_add_ast
100 and may result in the lkb being freed */
107 static inline int no_asts(void)
111 spin_lock(&ast_queue_lock);
112 ret = list_empty(&ast_queue);
113 spin_unlock(&ast_queue_lock);
117 static int dlm_astd(void *data)
119 while (!kthread_should_stop()) {
120 set_current_state(TASK_INTERRUPTIBLE);
121 if (!test_bit(WAKE_ASTS, &astd_wakeflags))
123 set_current_state(TASK_RUNNING);
125 mutex_lock(&astd_running);
126 if (test_and_clear_bit(WAKE_ASTS, &astd_wakeflags))
128 mutex_unlock(&astd_running);
133 void dlm_astd_wake(void)
136 set_bit(WAKE_ASTS, &astd_wakeflags);
137 wake_up_process(astd_task);
141 int dlm_astd_start(void)
143 struct task_struct *p;
146 INIT_LIST_HEAD(&ast_queue);
147 spin_lock_init(&ast_queue_lock);
148 mutex_init(&astd_running);
150 p = kthread_run(dlm_astd, NULL, "dlm_astd");
158 void dlm_astd_stop(void)
160 kthread_stop(astd_task);
163 void dlm_astd_suspend(void)
165 mutex_lock(&astd_running);
168 void dlm_astd_resume(void)
170 mutex_unlock(&astd_running);