SLOW_WORK: Wait for outstanding work items belonging to a module to clear
[safe/jmp/linux-2.6] / include / linux / slow-work.h
1 /* Worker thread pool for slow items, such as filesystem lookups or mkdirs
2  *
3  * Copyright (C) 2008 Red Hat, Inc. All Rights Reserved.
4  * Written by David Howells (dhowells@redhat.com)
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public Licence
8  * as published by the Free Software Foundation; either version
9  * 2 of the Licence, or (at your option) any later version.
10  *
11  * See Documentation/slow-work.txt
12  */
13
14 #ifndef _LINUX_SLOW_WORK_H
15 #define _LINUX_SLOW_WORK_H
16
17 #ifdef CONFIG_SLOW_WORK
18
19 #include <linux/sysctl.h>
20
21 struct slow_work;
22
23 /*
24  * The operations used to support slow work items
25  */
26 struct slow_work_ops {
27         /* owner */
28         struct module *owner;
29
30         /* get a ref on a work item
31          * - return 0 if successful, -ve if not
32          */
33         int (*get_ref)(struct slow_work *work);
34
35         /* discard a ref to a work item */
36         void (*put_ref)(struct slow_work *work);
37
38         /* execute a work item */
39         void (*execute)(struct slow_work *work);
40 };
41
42 /*
43  * A slow work item
44  * - A reference is held on the parent object by the thread pool when it is
45  *   queued
46  */
47 struct slow_work {
48         struct module           *owner; /* the owning module */
49         unsigned long           flags;
50 #define SLOW_WORK_PENDING       0       /* item pending (further) execution */
51 #define SLOW_WORK_EXECUTING     1       /* item currently executing */
52 #define SLOW_WORK_ENQ_DEFERRED  2       /* item enqueue deferred */
53 #define SLOW_WORK_VERY_SLOW     3       /* item is very slow */
54         const struct slow_work_ops *ops; /* operations table for this item */
55         struct list_head        link;   /* link in queue */
56 };
57
58 /**
59  * slow_work_init - Initialise a slow work item
60  * @work: The work item to initialise
61  * @ops: The operations to use to handle the slow work item
62  *
63  * Initialise a slow work item.
64  */
65 static inline void slow_work_init(struct slow_work *work,
66                                   const struct slow_work_ops *ops)
67 {
68         work->flags = 0;
69         work->ops = ops;
70         INIT_LIST_HEAD(&work->link);
71 }
72
73 /**
74  * vslow_work_init - Initialise a very slow work item
75  * @work: The work item to initialise
76  * @ops: The operations to use to handle the slow work item
77  *
78  * Initialise a very slow work item.  This item will be restricted such that
79  * only a certain number of the pool threads will be able to execute items of
80  * this type.
81  */
82 static inline void vslow_work_init(struct slow_work *work,
83                                    const struct slow_work_ops *ops)
84 {
85         work->flags = 1 << SLOW_WORK_VERY_SLOW;
86         work->ops = ops;
87         INIT_LIST_HEAD(&work->link);
88 }
89
90 extern int slow_work_enqueue(struct slow_work *work);
91 extern int slow_work_register_user(struct module *owner);
92 extern void slow_work_unregister_user(struct module *owner);
93
94 #ifdef CONFIG_SYSCTL
95 extern ctl_table slow_work_sysctls[];
96 #endif
97
98 #endif /* CONFIG_SLOW_WORK */
99 #endif /* _LINUX_SLOW_WORK_H */