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"
21 static struct list_head ast_queue;
22 static spinlock_t ast_queue_lock;
23 static struct task_struct * astd_task;
24 static unsigned long astd_wakeflags;
25 static struct mutex astd_running;
28 void dlm_del_ast(struct dlm_lkb *lkb)
30 spin_lock(&ast_queue_lock);
31 if (lkb->lkb_ast_type & (AST_COMP | AST_BAST))
32 list_del(&lkb->lkb_astqueue);
33 spin_unlock(&ast_queue_lock);
36 void dlm_add_ast(struct dlm_lkb *lkb, int type)
38 if (lkb->lkb_flags & DLM_IFL_USER) {
39 dlm_user_add_ast(lkb, type);
43 spin_lock(&ast_queue_lock);
44 if (!(lkb->lkb_ast_type & (AST_COMP | AST_BAST))) {
45 kref_get(&lkb->lkb_ref);
46 list_add_tail(&lkb->lkb_astqueue, &ast_queue);
48 lkb->lkb_ast_type |= type;
49 spin_unlock(&ast_queue_lock);
51 set_bit(WAKE_ASTS, &astd_wakeflags);
52 wake_up_process(astd_task);
55 static void process_asts(void)
57 struct dlm_ls *ls = NULL;
58 struct dlm_rsb *r = NULL;
60 void (*cast) (void *astparam);
61 void (*bast) (void *astparam, int mode);
62 int type = 0, found, bmode;
66 spin_lock(&ast_queue_lock);
67 list_for_each_entry(lkb, &ast_queue, lkb_astqueue) {
68 r = lkb->lkb_resource;
71 if (dlm_locking_stopped(ls))
74 list_del(&lkb->lkb_astqueue);
75 type = lkb->lkb_ast_type;
76 lkb->lkb_ast_type = 0;
80 spin_unlock(&ast_queue_lock);
85 cast = lkb->lkb_astfn;
86 bast = lkb->lkb_bastfn;
87 bmode = lkb->lkb_bastmode;
89 if ((type & AST_COMP) && cast)
90 cast(lkb->lkb_astparam);
92 if ((type & AST_BAST) && bast)
93 bast(lkb->lkb_astparam, bmode);
95 /* this removes the reference added by dlm_add_ast
96 and may result in the lkb being freed */
103 static inline int no_asts(void)
107 spin_lock(&ast_queue_lock);
108 ret = list_empty(&ast_queue);
109 spin_unlock(&ast_queue_lock);
113 static int dlm_astd(void *data)
115 while (!kthread_should_stop()) {
116 set_current_state(TASK_INTERRUPTIBLE);
117 if (!test_bit(WAKE_ASTS, &astd_wakeflags))
119 set_current_state(TASK_RUNNING);
121 mutex_lock(&astd_running);
122 if (test_and_clear_bit(WAKE_ASTS, &astd_wakeflags))
124 mutex_unlock(&astd_running);
129 void dlm_astd_wake(void)
132 set_bit(WAKE_ASTS, &astd_wakeflags);
133 wake_up_process(astd_task);
137 int dlm_astd_start(void)
139 struct task_struct *p;
142 INIT_LIST_HEAD(&ast_queue);
143 spin_lock_init(&ast_queue_lock);
144 mutex_init(&astd_running);
146 p = kthread_run(dlm_astd, NULL, "dlm_astd");
154 void dlm_astd_stop(void)
156 kthread_stop(astd_task);
159 void dlm_astd_suspend(void)
161 mutex_lock(&astd_running);
164 void dlm_astd_resume(void)
166 mutex_unlock(&astd_running);