~ubuntu-branches/ubuntu/vivid/aufs/vivid

« back to all changes in this revision

Viewing changes to fs/aufs25/wkq.h

  • Committer: Bazaar Package Importer
  • Author(s): Julian Andres Klode
  • Date: 2008-05-06 18:35:50 UTC
  • mfrom: (1.1.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20080506183550-0b6c974kkgc46oeh
Tags: 0+20080506-1
* New upstream release, supports Kernel 2.6.25 (Closes: #479717)
* Fix building with older Kernels (Closes: #475042)
* Update the patches 01, 04 and 07 to also patch fs/aufs25

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2005-2008 Junjiro 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/delegated operations
 
21
 *
 
22
 * $Id: wkq.h,v 1.3 2008/04/28 03:18:21 sfjro Exp $
 
23
 */
 
24
 
 
25
#ifndef __AUFS_WKQ_H__
 
26
#define __AUFS_WKQ_H__
 
27
 
 
28
#ifdef __KERNEL__
 
29
 
 
30
#include <linux/fs.h>
 
31
#include <linux/sched.h>
 
32
#include <linux/workqueue.h>
 
33
#include <linux/aufs_type.h>
 
34
 
 
35
/* ---------------------------------------------------------------------- */
 
36
 
 
37
/* internal workqueue named AUFS_WKQ_NAME */
 
38
struct au_wkq {
 
39
        struct workqueue_struct *q;
 
40
 
 
41
        /* accounting */
 
42
        atomic_t                busy;
 
43
        unsigned int            max_busy; // todo: STAT only
 
44
};
 
45
 
 
46
/*
 
47
 * in the next operation, wait for the 'nowait' tasks in system-wide workqueue
 
48
 */
 
49
struct au_nowait_tasks {
 
50
#ifdef CONFIG_AUFS_HINOTIFY
 
51
        /*
 
52
         * currently, the 'nowait' task which should be waited in the next
 
53
         * operation is only hinotify.
 
54
         */
 
55
        atomic_t                nw_len;
 
56
        wait_queue_head_t       nw_wq;
 
57
#endif
 
58
};
 
59
 
 
60
/* ---------------------------------------------------------------------- */
 
61
 
 
62
extern struct au_wkq *au_wkq;
 
63
typedef void (*au_wkq_func_t)(void *args);
 
64
 
 
65
/* wkq flags */
 
66
#define AuWkq_WAIT      1
 
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
 
72
#undef AuWkq_DLGT
 
73
#define AuWkq_DLGT      0
 
74
#endif
 
75
 
 
76
int au_wkq_run(au_wkq_func_t func, void *args, struct super_block *sb,
 
77
               unsigned int flags);
 
78
int __init au_wkq_init(void);
 
79
void au_wkq_fin(void);
 
80
 
 
81
/* ---------------------------------------------------------------------- */
 
82
 
 
83
static inline int au_test_wkq(struct task_struct *tsk)
 
84
{
 
85
        return (!tsk->mm && !strcmp(tsk->comm, AUFS_WKQ_NAME));
 
86
#if 0 // per-cpu workqueue
 
87
        return (!tsk->mm
 
88
                && !memcmp(tsk->comm, AUFS_WKQ_NAME "/",
 
89
                           sizeof(AUFS_WKQ_NAME)));
 
90
#endif
 
91
}
 
92
 
 
93
static inline int au_wkq_wait(au_wkq_func_t func, void *args, int dlgt)
 
94
{
 
95
        unsigned int flags = AuWkq_WAIT;
 
96
        if (unlikely(dlgt))
 
97
                au_fset_wkq(flags, DLGT);
 
98
        return au_wkq_run(func, args, /*sb*/NULL, flags);
 
99
}
 
100
 
 
101
static inline int au_wkq_nowait(au_wkq_func_t func, void *args,
 
102
                                struct super_block *sb, int dlgt)
 
103
{
 
104
        unsigned int flags = !AuWkq_WAIT;
 
105
        if (unlikely(dlgt))
 
106
                au_fset_wkq(flags, DLGT);
 
107
        return au_wkq_run(func, args, sb, flags);
 
108
}
 
109
 
 
110
#ifdef CONFIG_AUFS_HINOTIFY
 
111
//todo: memory barrier?
 
112
static inline void au_nwt_init(struct au_nowait_tasks *nwt)
 
113
{
 
114
        atomic_set(&nwt->nw_len, 0);
 
115
        smp_mb(); /* atomic_set */
 
116
        init_waitqueue_head(&nwt->nw_wq);
 
117
}
 
118
 
 
119
static inline int au_nwt_inc(struct au_nowait_tasks *nwt)
 
120
{
 
121
        return atomic_inc_return(&nwt->nw_len);
 
122
}
 
123
 
 
124
static inline int au_nwt_dec(struct au_nowait_tasks *nwt)
 
125
{
 
126
        int ret = atomic_dec_return(&nwt->nw_len);
 
127
        if (!ret)
 
128
                wake_up_all(&nwt->nw_wq);
 
129
        return ret;
 
130
}
 
131
 
 
132
static inline int au_nwt_flush(struct au_nowait_tasks *nwt)
 
133
{
 
134
        wait_event(nwt->nw_wq, !atomic_read(&nwt->nw_len));
 
135
        return 0;
 
136
}
 
137
#else
 
138
static inline void au_nwt_init(struct au_nowait_tasks *nwt)
 
139
{
 
140
        /* nothing */
 
141
}
 
142
 
 
143
static inline int au_nwt_inc(struct au_nowait_tasks *nwt)
 
144
{
 
145
        return 0;
 
146
}
 
147
 
 
148
static inline int au_nwt_dec(struct au_nowait_tasks *nwt)
 
149
{
 
150
        return 0;
 
151
}
 
152
 
 
153
static inline int au_nwt_flush(struct au_nowait_tasks *nwt)
 
154
{
 
155
        return 0;
 
156
}
 
157
#endif /* CONFIG_AUFS_HINOTIFY */
 
158
 
 
159
#endif /* __KERNEL__ */
 
160
#endif /* __AUFS_WKQ_H__ */