2
* Copyright (C) 2005-2008 Junjiro 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/delegated operations
22
* $Id: wkq.h,v 1.3 2008/04/28 03:18:21 sfjro Exp $
25
#ifndef __AUFS_WKQ_H__
26
#define __AUFS_WKQ_H__
31
#include <linux/sched.h>
32
#include <linux/workqueue.h>
33
#include <linux/aufs_type.h>
35
/* ---------------------------------------------------------------------- */
37
/* internal workqueue named AUFS_WKQ_NAME */
39
struct workqueue_struct *q;
43
unsigned int max_busy; // todo: STAT only
47
* in the next operation, wait for the 'nowait' tasks in system-wide workqueue
49
struct au_nowait_tasks {
50
#ifdef CONFIG_AUFS_HINOTIFY
52
* currently, the 'nowait' task which should be waited in the next
53
* operation is only hinotify.
56
wait_queue_head_t nw_wq;
60
/* ---------------------------------------------------------------------- */
62
extern struct au_wkq *au_wkq;
63
typedef void (*au_wkq_func_t)(void *args);
67
#define AuWkq_DLGT (1 << 1)
68
#define au_ftest_wkq(flags, name) ((flags) & AuWkq_##name)
69
#define au_fset_wkq(flags, name) { (flags) |= AuWkq_##name; }
70
#define au_fclr_wkq(flags, name) { (flags) &= ~AuWkq_##name; }
71
#ifndef CONFIG_AUFS_DLGT
76
int au_wkq_run(au_wkq_func_t func, void *args, struct super_block *sb,
78
int __init au_wkq_init(void);
79
void au_wkq_fin(void);
81
/* ---------------------------------------------------------------------- */
83
static inline int au_test_wkq(struct task_struct *tsk)
85
return (!tsk->mm && !strcmp(tsk->comm, AUFS_WKQ_NAME));
86
#if 0 // per-cpu workqueue
88
&& !memcmp(tsk->comm, AUFS_WKQ_NAME "/",
89
sizeof(AUFS_WKQ_NAME)));
93
static inline int au_wkq_wait(au_wkq_func_t func, void *args, int dlgt)
95
unsigned int flags = AuWkq_WAIT;
97
au_fset_wkq(flags, DLGT);
98
return au_wkq_run(func, args, /*sb*/NULL, flags);
101
static inline int au_wkq_nowait(au_wkq_func_t func, void *args,
102
struct super_block *sb, int dlgt)
104
unsigned int flags = !AuWkq_WAIT;
106
au_fset_wkq(flags, DLGT);
107
return au_wkq_run(func, args, sb, flags);
110
#ifdef CONFIG_AUFS_HINOTIFY
111
//todo: memory barrier?
112
static inline void au_nwt_init(struct au_nowait_tasks *nwt)
114
atomic_set(&nwt->nw_len, 0);
115
smp_mb(); /* atomic_set */
116
init_waitqueue_head(&nwt->nw_wq);
119
static inline int au_nwt_inc(struct au_nowait_tasks *nwt)
121
return atomic_inc_return(&nwt->nw_len);
124
static inline int au_nwt_dec(struct au_nowait_tasks *nwt)
126
int ret = atomic_dec_return(&nwt->nw_len);
128
wake_up_all(&nwt->nw_wq);
132
static inline int au_nwt_flush(struct au_nowait_tasks *nwt)
134
wait_event(nwt->nw_wq, !atomic_read(&nwt->nw_len));
138
static inline void au_nwt_init(struct au_nowait_tasks *nwt)
143
static inline int au_nwt_inc(struct au_nowait_tasks *nwt)
148
static inline int au_nwt_dec(struct au_nowait_tasks *nwt)
153
static inline int au_nwt_flush(struct au_nowait_tasks *nwt)
157
#endif /* CONFIG_AUFS_HINOTIFY */
159
#endif /* __KERNEL__ */
160
#endif /* __AUFS_WKQ_H__ */