Merge branch 'stable-3.2' into pandora-3.2
[pandora-kernel.git] / fs / aufs / wkq.h
1 /*
2  * Copyright (C) 2005-2013 Junjiro R. Okajima
3  *
4  * This program, aufs is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
17  */
18
19 /*
20  * workqueue for asynchronous/super-io operations
21  * todo: try new credentials management scheme
22  */
23
24 #ifndef __AUFS_WKQ_H__
25 #define __AUFS_WKQ_H__
26
27 #ifdef __KERNEL__
28
29 struct super_block;
30
31 /* ---------------------------------------------------------------------- */
32
33 /*
34  * in the next operation, wait for the 'nowait' tasks in system-wide workqueue
35  */
36 struct au_nowait_tasks {
37         atomic_t                nw_len;
38         wait_queue_head_t       nw_wq;
39 };
40
41 /* ---------------------------------------------------------------------- */
42
43 typedef void (*au_wkq_func_t)(void *args);
44
45 /* wkq flags */
46 #define AuWkq_WAIT      1
47 #define AuWkq_NEST      (1 << 1)
48 #define au_ftest_wkq(flags, name)       ((flags) & AuWkq_##name)
49 #define au_fset_wkq(flags, name) \
50         do { (flags) |= AuWkq_##name; } while (0)
51 #define au_fclr_wkq(flags, name) \
52         do { (flags) &= ~AuWkq_##name; } while (0)
53
54 #ifndef CONFIG_AUFS_HNOTIFY
55 #undef AuWkq_NEST
56 #define AuWkq_NEST      0
57 #endif
58
59 /* wkq.c */
60 int au_wkq_do_wait(unsigned int flags, au_wkq_func_t func, void *args);
61 int au_wkq_nowait(au_wkq_func_t func, void *args, struct super_block *sb,
62                   unsigned int flags);
63 void au_nwt_init(struct au_nowait_tasks *nwt);
64 int __init au_wkq_init(void);
65 void au_wkq_fin(void);
66
67 /* ---------------------------------------------------------------------- */
68
69 static inline int au_wkq_test(void)
70 {
71         return current->flags & PF_WQ_WORKER;
72 }
73
74 static inline int au_wkq_wait(au_wkq_func_t func, void *args)
75 {
76         return au_wkq_do_wait(AuWkq_WAIT, func, args);
77 }
78
79 static inline void au_nwt_done(struct au_nowait_tasks *nwt)
80 {
81         if (atomic_dec_and_test(&nwt->nw_len))
82                 wake_up_all(&nwt->nw_wq);
83 }
84
85 static inline int au_nwt_flush(struct au_nowait_tasks *nwt)
86 {
87         wait_event(nwt->nw_wq, !atomic_read(&nwt->nw_len));
88         return 0;
89 }
90
91 #endif /* __KERNEL__ */
92 #endif /* __AUFS_WKQ_H__ */