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 spin_lock(&ast_queue_lock
);
38 if (!(lkb
->lkb_ast_type
& (AST_COMP
| AST_BAST
))) {
39 kref_get(&lkb
->lkb_ref
);
40 list_add_tail(&lkb
->lkb_astqueue
, &ast_queue
);
42 lkb
->lkb_ast_type
|= type
;
43 spin_unlock(&ast_queue_lock
);
45 set_bit(WAKE_ASTS
, &astd_wakeflags
);
46 wake_up_process(astd_task
);
49 static void process_asts(void)
51 struct dlm_ls
*ls
= NULL
;
52 struct dlm_rsb
*r
= NULL
;
54 void (*cast
) (long param
);
55 void (*bast
) (long param
, int mode
);
56 int type
= 0, found
, bmode
;
60 spin_lock(&ast_queue_lock
);
61 list_for_each_entry(lkb
, &ast_queue
, lkb_astqueue
) {
62 r
= lkb
->lkb_resource
;
65 if (dlm_locking_stopped(ls
))
68 list_del(&lkb
->lkb_astqueue
);
69 type
= lkb
->lkb_ast_type
;
70 lkb
->lkb_ast_type
= 0;
74 spin_unlock(&ast_queue_lock
);
79 cast
= lkb
->lkb_astaddr
;
80 bast
= lkb
->lkb_bastaddr
;
81 bmode
= lkb
->lkb_bastmode
;
83 if ((type
& AST_COMP
) && cast
)
84 cast(lkb
->lkb_astparam
);
86 /* FIXME: Is it safe to look at lkb_grmode here
87 without doing a lock_rsb() ?
88 Look at other checks in v1 to avoid basts. */
90 if ((type
& AST_BAST
) && bast
)
91 if (!dlm_modes_compat(lkb
->lkb_grmode
, bmode
))
92 bast(lkb
->lkb_astparam
, bmode
);
94 /* this removes the reference added by dlm_add_ast
95 and may result in the lkb being freed */
102 static inline int no_asts(void)
106 spin_lock(&ast_queue_lock
);
107 ret
= list_empty(&ast_queue
);
108 spin_unlock(&ast_queue_lock
);
112 static int dlm_astd(void *data
)
114 while (!kthread_should_stop()) {
115 set_current_state(TASK_INTERRUPTIBLE
);
116 if (!test_bit(WAKE_ASTS
, &astd_wakeflags
))
118 set_current_state(TASK_RUNNING
);
120 mutex_lock(&astd_running
);
121 if (test_and_clear_bit(WAKE_ASTS
, &astd_wakeflags
))
123 mutex_unlock(&astd_running
);
128 void dlm_astd_wake(void)
131 set_bit(WAKE_ASTS
, &astd_wakeflags
);
132 wake_up_process(astd_task
);
136 int dlm_astd_start(void)
138 struct task_struct
*p
;
141 INIT_LIST_HEAD(&ast_queue
);
142 spin_lock_init(&ast_queue_lock
);
143 mutex_init(&astd_running
);
145 p
= kthread_run(dlm_astd
, NULL
, "dlm_astd");
153 void dlm_astd_stop(void)
155 kthread_stop(astd_task
);
158 void dlm_astd_suspend(void)
160 mutex_lock(&astd_running
);
163 void dlm_astd_resume(void)
165 mutex_unlock(&astd_running
);