]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blob - fs/aufs/wkq.h
9b878361fe673c4393ee182d363b4d4234267bb8
[mirror_ubuntu-zesty-kernel.git] / fs / aufs / wkq.h
1 /*
2 * Copyright (C) 2005-2016 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, see <http://www.gnu.org/licenses/>.
16 */
17
18 /*
19 * workqueue for asynchronous/super-io operations
20 * todo: try new credentials management scheme
21 */
22
23 #ifndef __AUFS_WKQ_H__
24 #define __AUFS_WKQ_H__
25
26 #ifdef __KERNEL__
27
28 #include <linux/percpu_counter.h>
29
30 struct super_block;
31
32 /* ---------------------------------------------------------------------- */
33
34 /*
35 * in the next operation, wait for the 'nowait' tasks in system-wide workqueue
36 */
37 struct au_nowait_tasks {
38 atomic_t nw_len;
39 wait_queue_head_t nw_wq;
40 };
41
42 /* ---------------------------------------------------------------------- */
43
44 typedef void (*au_wkq_func_t)(void *args);
45
46 /* wkq flags */
47 #define AuWkq_WAIT 1
48 #define AuWkq_NEST (1 << 1)
49 #define au_ftest_wkq(flags, name) ((flags) & AuWkq_##name)
50 #define au_fset_wkq(flags, name) \
51 do { (flags) |= AuWkq_##name; } while (0)
52 #define au_fclr_wkq(flags, name) \
53 do { (flags) &= ~AuWkq_##name; } while (0)
54
55 #ifndef CONFIG_AUFS_HNOTIFY
56 #undef AuWkq_NEST
57 #define AuWkq_NEST 0
58 #endif
59
60 /* wkq.c */
61 int au_wkq_do_wait(unsigned int flags, au_wkq_func_t func, void *args);
62 int au_wkq_nowait(au_wkq_func_t func, void *args, struct super_block *sb,
63 unsigned int flags);
64 void au_nwt_init(struct au_nowait_tasks *nwt);
65 int __init au_wkq_init(void);
66 void au_wkq_fin(void);
67
68 /* ---------------------------------------------------------------------- */
69
70 static inline int au_wkq_test(void)
71 {
72 return current->flags & PF_WQ_WORKER;
73 }
74
75 static inline int au_wkq_wait(au_wkq_func_t func, void *args)
76 {
77 return au_wkq_do_wait(AuWkq_WAIT, func, args);
78 }
79
80 static inline void au_nwt_done(struct au_nowait_tasks *nwt)
81 {
82 if (atomic_dec_and_test(&nwt->nw_len))
83 wake_up_all(&nwt->nw_wq);
84 }
85
86 static inline int au_nwt_flush(struct au_nowait_tasks *nwt)
87 {
88 wait_event(nwt->nw_wq, !atomic_read(&nwt->nw_len));
89 return 0;
90 }
91
92 #endif /* __KERNEL__ */
93 #endif /* __AUFS_WKQ_H__ */