1 /******************************************************************************
2 *******************************************************************************
4 ** Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
5 ** Copyright (C) 2004-2008 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
, int bastmode
)
38 if (lkb
->lkb_flags
& DLM_IFL_USER
) {
39 dlm_user_add_ast(lkb
, type
, bastmode
);
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
;
50 lkb
->lkb_bastmode
= bastmode
;
51 spin_unlock(&ast_queue_lock
);
53 set_bit(WAKE_ASTS
, &astd_wakeflags
);
54 wake_up_process(astd_task
);
57 static void process_asts(void)
59 struct dlm_ls
*ls
= NULL
;
60 struct dlm_rsb
*r
= NULL
;
62 void (*cast
) (void *astparam
);
63 void (*bast
) (void *astparam
, int mode
);
64 int type
= 0, bastmode
;
67 spin_lock(&ast_queue_lock
);
68 list_for_each_entry(lkb
, &ast_queue
, lkb_astqueue
) {
69 r
= lkb
->lkb_resource
;
72 if (dlm_locking_stopped(ls
))
75 list_del(&lkb
->lkb_astqueue
);
76 type
= lkb
->lkb_ast_type
;
77 lkb
->lkb_ast_type
= 0;
78 bastmode
= lkb
->lkb_bastmode
;
80 spin_unlock(&ast_queue_lock
);
81 cast
= lkb
->lkb_astfn
;
82 bast
= lkb
->lkb_bastfn
;
84 if ((type
& AST_COMP
) && cast
)
85 cast(lkb
->lkb_astparam
);
87 if ((type
& AST_BAST
) && bast
)
88 bast(lkb
->lkb_astparam
, bastmode
);
90 /* this removes the reference added by dlm_add_ast
91 and may result in the lkb being freed */
97 spin_unlock(&ast_queue_lock
);
100 static inline int no_asts(void)
104 spin_lock(&ast_queue_lock
);
105 ret
= list_empty(&ast_queue
);
106 spin_unlock(&ast_queue_lock
);
110 static int dlm_astd(void *data
)
112 while (!kthread_should_stop()) {
113 set_current_state(TASK_INTERRUPTIBLE
);
114 if (!test_bit(WAKE_ASTS
, &astd_wakeflags
))
116 set_current_state(TASK_RUNNING
);
118 mutex_lock(&astd_running
);
119 if (test_and_clear_bit(WAKE_ASTS
, &astd_wakeflags
))
121 mutex_unlock(&astd_running
);
126 void dlm_astd_wake(void)
129 set_bit(WAKE_ASTS
, &astd_wakeflags
);
130 wake_up_process(astd_task
);
134 int dlm_astd_start(void)
136 struct task_struct
*p
;
139 INIT_LIST_HEAD(&ast_queue
);
140 spin_lock_init(&ast_queue_lock
);
141 mutex_init(&astd_running
);
143 p
= kthread_run(dlm_astd
, NULL
, "dlm_astd");
151 void dlm_astd_stop(void)
153 kthread_stop(astd_task
);
156 void dlm_astd_suspend(void)
158 mutex_lock(&astd_running
);
161 void dlm_astd_resume(void)
163 mutex_unlock(&astd_running
);