aufs: debug, from aufs2.2-3.0
[zen-stable.git] / fs / aufs / wkq.h
bloba0d0ca5b070e3957b15589dd7366f3ec87f17df8
1 /*
2 * Copyright (C) 2005-2011 Junjiro R. Okajima
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.
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.
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
20 * workqueue for asynchronous/super-io operations
21 * todo: try new credentials management scheme
24 #ifndef __AUFS_WKQ_H__
25 #define __AUFS_WKQ_H__
27 #ifdef __KERNEL__
29 #include <linux/sched.h>
30 #include <linux/wait.h>
31 #include <linux/aufs_type.h>
33 struct super_block;
35 /* ---------------------------------------------------------------------- */
38 * in the next operation, wait for the 'nowait' tasks in system-wide workqueue
40 struct au_nowait_tasks {
41 atomic_t nw_len;
42 wait_queue_head_t nw_wq;
45 /* ---------------------------------------------------------------------- */
47 typedef void (*au_wkq_func_t)(void *args);
49 /* wkq flags */
50 #define AuWkq_WAIT 1
51 #define AuWkq_PRE (1 << 1)
52 #ifdef CONFIG_AUFS_HNOTIFY
53 #define AuWkq_NEST (1 << 2)
54 #else
55 #define AuWkq_NEST 0
56 #endif
57 #define au_ftest_wkq(flags, name) ((flags) & AuWkq_##name)
58 #define au_fset_wkq(flags, name) \
59 do { (flags) |= AuWkq_##name; } while (0)
60 #define au_fclr_wkq(flags, name) \
61 do { (flags) &= ~AuWkq_##name; } while (0)
63 /* wkq.c */
64 int au_wkq_do_wait(unsigned int flags, au_wkq_func_t func, void *args);
65 int au_wkq_nowait(au_wkq_func_t func, void *args, struct super_block *sb,
66 unsigned int flags);
67 void au_nwt_init(struct au_nowait_tasks *nwt);
68 int __init au_wkq_init(void);
69 void au_wkq_fin(void);
71 /* ---------------------------------------------------------------------- */
73 static inline int au_wkq_test(void)
75 return current->flags & PF_WQ_WORKER;
78 static inline int au_wkq_wait_pre(au_wkq_func_t func, void *args)
80 return au_wkq_do_wait(AuWkq_WAIT | AuWkq_PRE, func, args);
83 static inline int au_wkq_wait(au_wkq_func_t func, void *args)
85 return au_wkq_do_wait(AuWkq_WAIT, func, args);
88 static inline void au_nwt_done(struct au_nowait_tasks *nwt)
90 if (atomic_dec_and_test(&nwt->nw_len))
91 wake_up_all(&nwt->nw_wq);
94 static inline int au_nwt_flush(struct au_nowait_tasks *nwt)
96 wait_event(nwt->nw_wq, !atomic_read(&nwt->nw_len));
97 return 0;
100 #endif /* __KERNEL__ */
101 #endif /* __AUFS_WKQ_H__ */