m68knommu: use IRQF_DISABLE in m68328serial.c
[wrt350n-kernel.git] / fs / dlm / ast.c
blob6308122890cae1c2ae6cd03ad5b5452b03581532
1 /******************************************************************************
2 *******************************************************************************
3 **
4 ** Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
5 ** Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved.
6 **
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"
15 #include "lock.h"
16 #include "user.h"
17 #include "ast.h"
19 #define WAKE_ASTS 0
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);
40 return;
42 DLM_ASSERT(lkb->lkb_astaddr != DLM_FAKE_USER_AST, dlm_print_lkb(lkb););
44 spin_lock(&ast_queue_lock);
45 if (!(lkb->lkb_ast_type & (AST_COMP | AST_BAST))) {
46 kref_get(&lkb->lkb_ref);
47 list_add_tail(&lkb->lkb_astqueue, &ast_queue);
49 lkb->lkb_ast_type |= type;
50 spin_unlock(&ast_queue_lock);
52 set_bit(WAKE_ASTS, &astd_wakeflags);
53 wake_up_process(astd_task);
56 static void process_asts(void)
58 struct dlm_ls *ls = NULL;
59 struct dlm_rsb *r = NULL;
60 struct dlm_lkb *lkb;
61 void (*cast) (long param);
62 void (*bast) (long param, int mode);
63 int type = 0, found, bmode;
65 for (;;) {
66 found = 0;
67 spin_lock(&ast_queue_lock);
68 list_for_each_entry(lkb, &ast_queue, lkb_astqueue) {
69 r = lkb->lkb_resource;
70 ls = r->res_ls;
72 if (dlm_locking_stopped(ls))
73 continue;
75 list_del(&lkb->lkb_astqueue);
76 type = lkb->lkb_ast_type;
77 lkb->lkb_ast_type = 0;
78 found = 1;
79 break;
81 spin_unlock(&ast_queue_lock);
83 if (!found)
84 break;
86 cast = lkb->lkb_astaddr;
87 bast = lkb->lkb_bastaddr;
88 bmode = lkb->lkb_bastmode;
90 if ((type & AST_COMP) && cast)
91 cast(lkb->lkb_astparam);
93 /* FIXME: Is it safe to look at lkb_grmode here
94 without doing a lock_rsb() ?
95 Look at other checks in v1 to avoid basts. */
97 if ((type & AST_BAST) && bast)
98 if (!dlm_modes_compat(lkb->lkb_grmode, bmode))
99 bast(lkb->lkb_astparam, bmode);
101 /* this removes the reference added by dlm_add_ast
102 and may result in the lkb being freed */
103 dlm_put_lkb(lkb);
105 schedule();
109 static inline int no_asts(void)
111 int ret;
113 spin_lock(&ast_queue_lock);
114 ret = list_empty(&ast_queue);
115 spin_unlock(&ast_queue_lock);
116 return ret;
119 static int dlm_astd(void *data)
121 while (!kthread_should_stop()) {
122 set_current_state(TASK_INTERRUPTIBLE);
123 if (!test_bit(WAKE_ASTS, &astd_wakeflags))
124 schedule();
125 set_current_state(TASK_RUNNING);
127 mutex_lock(&astd_running);
128 if (test_and_clear_bit(WAKE_ASTS, &astd_wakeflags))
129 process_asts();
130 mutex_unlock(&astd_running);
132 return 0;
135 void dlm_astd_wake(void)
137 if (!no_asts()) {
138 set_bit(WAKE_ASTS, &astd_wakeflags);
139 wake_up_process(astd_task);
143 int dlm_astd_start(void)
145 struct task_struct *p;
146 int error = 0;
148 INIT_LIST_HEAD(&ast_queue);
149 spin_lock_init(&ast_queue_lock);
150 mutex_init(&astd_running);
152 p = kthread_run(dlm_astd, NULL, "dlm_astd");
153 if (IS_ERR(p))
154 error = PTR_ERR(p);
155 else
156 astd_task = p;
157 return error;
160 void dlm_astd_stop(void)
162 kthread_stop(astd_task);
165 void dlm_astd_suspend(void)
167 mutex_lock(&astd_running);
170 void dlm_astd_resume(void)
172 mutex_unlock(&astd_running);