RPC: Clean up RPC task structure
[linux-2.6-block.git] / include / linux / sunrpc / sched.h
CommitLineData
1da177e4
LT
1/*
2 * linux/include/linux/sunrpc/sched.h
3 *
4 * Scheduling primitives for kernel Sun RPC.
5 *
6 * Copyright (C) 1996, Olaf Kirch <okir@monad.swb.de>
7 */
8
9#ifndef _LINUX_SUNRPC_SCHED_H_
10#define _LINUX_SUNRPC_SCHED_H_
11
12#include <linux/timer.h>
13#include <linux/sunrpc/types.h>
14#include <linux/spinlock.h>
15#include <linux/wait.h>
16#include <linux/workqueue.h>
17#include <linux/sunrpc/xdr.h>
18
19/*
20 * This is the actual RPC procedure call info.
21 */
22struct rpc_procinfo;
23struct rpc_message {
24 struct rpc_procinfo * rpc_proc; /* Procedure information */
25 void * rpc_argp; /* Arguments */
26 void * rpc_resp; /* Result */
27 struct rpc_cred * rpc_cred; /* Credentials */
28};
29
963d8fe5 30struct rpc_call_ops;
1da177e4
LT
31struct rpc_wait_queue;
32struct rpc_wait {
33 struct list_head list; /* wait queue links */
34 struct list_head links; /* Links to related tasks */
1da177e4
LT
35 struct rpc_wait_queue * rpc_waitq; /* RPC wait queue we're on */
36};
37
38/*
39 * This is the RPC task struct
40 */
41struct rpc_task {
42#ifdef RPC_DEBUG
43 unsigned long tk_magic; /* 0xf00baa */
44#endif
45 struct list_head tk_task; /* global list of tasks */
46 struct rpc_clnt * tk_client; /* RPC client */
47 struct rpc_rqst * tk_rqstp; /* RPC request */
48 int tk_status; /* result of last operation */
49
50 /*
51 * RPC call state
52 */
53 struct rpc_message tk_msg; /* RPC call info */
54 __u32 * tk_buffer; /* XDR buffer */
55 size_t tk_bufsize;
56 __u8 tk_garb_retry;
57 __u8 tk_cred_retry;
58
59 unsigned long tk_cookie; /* Cookie for batching tasks */
60
61 /*
62 * timeout_fn to be executed by timer bottom half
63 * callback to be executed after waking up
64 * action next procedure for async tasks
963d8fe5 65 * tk_ops caller callbacks
1da177e4
LT
66 */
67 void (*tk_timeout_fn)(struct rpc_task *);
68 void (*tk_callback)(struct rpc_task *);
69 void (*tk_action)(struct rpc_task *);
963d8fe5 70 const struct rpc_call_ops *tk_ops;
1da177e4
LT
71 void * tk_calldata;
72
73 /*
74 * tk_timer is used for async processing by the RPC scheduling
75 * primitives. You should not access this directly unless
76 * you have a pathological interest in kernel oopses.
77 */
78 struct timer_list tk_timer; /* kernel timer */
79 unsigned long tk_timeout; /* timeout for rpc_sleep() */
80 unsigned short tk_flags; /* misc flags */
81 unsigned char tk_active : 1;/* Task has been activated */
82 unsigned char tk_priority : 2;/* Task priority */
83 unsigned long tk_runstate; /* Task run status */
84 struct workqueue_struct *tk_workqueue; /* Normally rpciod, but could
85 * be any workqueue
86 */
87 union {
88 struct work_struct tk_work; /* Async task work queue */
89 struct rpc_wait tk_wait; /* RPC wait */
90 } u;
91#ifdef RPC_DEBUG
92 unsigned short tk_pid; /* debugging aid */
93#endif
94};
95#define tk_auth tk_client->cl_auth
96#define tk_xprt tk_client->cl_xprt
97
98/* support walking a list of tasks on a wait queue */
99#define task_for_each(task, pos, head) \
100 list_for_each(pos, head) \
101 if ((task=list_entry(pos, struct rpc_task, u.tk_wait.list)),1)
102
103#define task_for_first(task, head) \
104 if (!list_empty(head) && \
105 ((task=list_entry((head)->next, struct rpc_task, u.tk_wait.list)),1))
106
107/* .. and walking list of all tasks */
108#define alltask_for_each(task, pos, head) \
109 list_for_each(pos, head) \
110 if ((task=list_entry(pos, struct rpc_task, tk_task)),1)
111
112typedef void (*rpc_action)(struct rpc_task *);
113
963d8fe5
TM
114struct rpc_call_ops {
115 void (*rpc_call_done)(struct rpc_task *, void *);
116 void (*rpc_release)(void *);
117};
118
119
1da177e4
LT
120/*
121 * RPC task flags
122 */
123#define RPC_TASK_ASYNC 0x0001 /* is an async task */
124#define RPC_TASK_SWAPPER 0x0002 /* is swapping in/out */
125#define RPC_TASK_CHILD 0x0008 /* is child of other task */
126#define RPC_CALL_MAJORSEEN 0x0020 /* major timeout seen */
127#define RPC_TASK_ROOTCREDS 0x0040 /* force root creds */
128#define RPC_TASK_DYNAMIC 0x0080 /* task was kmalloc'ed */
129#define RPC_TASK_KILLED 0x0100 /* task was killed */
130#define RPC_TASK_SOFT 0x0200 /* Use soft timeouts */
131#define RPC_TASK_NOINTR 0x0400 /* uninterruptible task */
132
133#define RPC_IS_ASYNC(t) ((t)->tk_flags & RPC_TASK_ASYNC)
134#define RPC_IS_CHILD(t) ((t)->tk_flags & RPC_TASK_CHILD)
135#define RPC_IS_SWAPPER(t) ((t)->tk_flags & RPC_TASK_SWAPPER)
136#define RPC_DO_ROOTOVERRIDE(t) ((t)->tk_flags & RPC_TASK_ROOTCREDS)
137#define RPC_ASSASSINATED(t) ((t)->tk_flags & RPC_TASK_KILLED)
138#define RPC_IS_ACTIVATED(t) ((t)->tk_active)
139#define RPC_DO_CALLBACK(t) ((t)->tk_callback != NULL)
140#define RPC_IS_SOFT(t) ((t)->tk_flags & RPC_TASK_SOFT)
141#define RPC_TASK_UNINTERRUPTIBLE(t) ((t)->tk_flags & RPC_TASK_NOINTR)
142
143#define RPC_TASK_RUNNING 0
144#define RPC_TASK_QUEUED 1
145#define RPC_TASK_WAKEUP 2
146#define RPC_TASK_HAS_TIMER 3
147
148#define RPC_IS_RUNNING(t) (test_bit(RPC_TASK_RUNNING, &(t)->tk_runstate))
149#define rpc_set_running(t) (set_bit(RPC_TASK_RUNNING, &(t)->tk_runstate))
150#define rpc_test_and_set_running(t) \
151 (test_and_set_bit(RPC_TASK_RUNNING, &(t)->tk_runstate))
152#define rpc_clear_running(t) \
153 do { \
154 smp_mb__before_clear_bit(); \
155 clear_bit(RPC_TASK_RUNNING, &(t)->tk_runstate); \
156 smp_mb__after_clear_bit(); \
157 } while (0)
158
159#define RPC_IS_QUEUED(t) (test_bit(RPC_TASK_QUEUED, &(t)->tk_runstate))
160#define rpc_set_queued(t) (set_bit(RPC_TASK_QUEUED, &(t)->tk_runstate))
161#define rpc_clear_queued(t) \
162 do { \
163 smp_mb__before_clear_bit(); \
164 clear_bit(RPC_TASK_QUEUED, &(t)->tk_runstate); \
165 smp_mb__after_clear_bit(); \
166 } while (0)
167
168#define rpc_start_wakeup(t) \
169 (test_and_set_bit(RPC_TASK_WAKEUP, &(t)->tk_runstate) == 0)
170#define rpc_finish_wakeup(t) \
171 do { \
172 smp_mb__before_clear_bit(); \
173 clear_bit(RPC_TASK_WAKEUP, &(t)->tk_runstate); \
174 smp_mb__after_clear_bit(); \
175 } while (0)
176
177/*
178 * Task priorities.
179 * Note: if you change these, you must also change
180 * the task initialization definitions below.
181 */
182#define RPC_PRIORITY_LOW 0
183#define RPC_PRIORITY_NORMAL 1
184#define RPC_PRIORITY_HIGH 2
185#define RPC_NR_PRIORITY (RPC_PRIORITY_HIGH+1)
186
187/*
188 * RPC synchronization objects
189 */
190struct rpc_wait_queue {
191 spinlock_t lock;
192 struct list_head tasks[RPC_NR_PRIORITY]; /* task queue for each priority level */
193 unsigned long cookie; /* cookie of last task serviced */
194 unsigned char maxpriority; /* maximum priority (0 if queue is not a priority queue) */
195 unsigned char priority; /* current priority */
196 unsigned char count; /* # task groups remaining serviced so far */
197 unsigned char nr; /* # tasks remaining for cookie */
198#ifdef RPC_DEBUG
199 const char * name;
200#endif
201};
202
203/*
204 * This is the # requests to send consecutively
205 * from a single cookie. The aim is to improve
206 * performance of NFS operations such as read/write.
207 */
208#define RPC_BATCH_COUNT 16
209
210#ifndef RPC_DEBUG
211# define RPC_WAITQ_INIT(var,qname) { \
212 .lock = SPIN_LOCK_UNLOCKED, \
213 .tasks = { \
214 [0] = LIST_HEAD_INIT(var.tasks[0]), \
215 [1] = LIST_HEAD_INIT(var.tasks[1]), \
216 [2] = LIST_HEAD_INIT(var.tasks[2]), \
217 }, \
218 }
219#else
220# define RPC_WAITQ_INIT(var,qname) { \
221 .lock = SPIN_LOCK_UNLOCKED, \
222 .tasks = { \
223 [0] = LIST_HEAD_INIT(var.tasks[0]), \
224 [1] = LIST_HEAD_INIT(var.tasks[1]), \
225 [2] = LIST_HEAD_INIT(var.tasks[2]), \
226 }, \
227 .name = qname, \
228 }
229#endif
230# define RPC_WAITQ(var,qname) struct rpc_wait_queue var = RPC_WAITQ_INIT(var,qname)
231
232#define RPC_IS_PRIORITY(q) ((q)->maxpriority > 0)
233
234/*
235 * Function prototypes
236 */
963d8fe5
TM
237struct rpc_task *rpc_new_task(struct rpc_clnt *, int flags,
238 const struct rpc_call_ops *ops, void *data);
1da177e4 239struct rpc_task *rpc_new_child(struct rpc_clnt *, struct rpc_task *parent);
963d8fe5
TM
240void rpc_init_task(struct rpc_task *task, struct rpc_clnt *clnt,
241 int flags, const struct rpc_call_ops *ops,
242 void *data);
1da177e4 243void rpc_release_task(struct rpc_task *);
abbcf28f 244void rpc_exit_task(struct rpc_task *);
1da177e4
LT
245void rpc_killall_tasks(struct rpc_clnt *);
246int rpc_execute(struct rpc_task *);
247void rpc_run_child(struct rpc_task *parent, struct rpc_task *child,
248 rpc_action action);
249void rpc_init_priority_wait_queue(struct rpc_wait_queue *, const char *);
250void rpc_init_wait_queue(struct rpc_wait_queue *, const char *);
251void rpc_sleep_on(struct rpc_wait_queue *, struct rpc_task *,
252 rpc_action action, rpc_action timer);
253void rpc_wake_up_task(struct rpc_task *);
254void rpc_wake_up(struct rpc_wait_queue *);
255struct rpc_task *rpc_wake_up_next(struct rpc_wait_queue *);
256void rpc_wake_up_status(struct rpc_wait_queue *, int);
257void rpc_delay(struct rpc_task *, unsigned long);
258void * rpc_malloc(struct rpc_task *, size_t);
259int rpciod_up(void);
260void rpciod_down(void);
261void rpciod_wake_up(void);
262#ifdef RPC_DEBUG
263void rpc_show_tasks(void);
264#endif
265int rpc_init_mempool(void);
266void rpc_destroy_mempool(void);
267
268static inline void rpc_exit(struct rpc_task *task, int status)
269{
270 task->tk_status = status;
abbcf28f 271 task->tk_action = rpc_exit_task;
1da177e4
LT
272}
273
274#ifdef RPC_DEBUG
275static inline const char * rpc_qname(struct rpc_wait_queue *q)
276{
277 return ((q && q->name) ? q->name : "unknown");
278}
279#endif
280
281#endif /* _LINUX_SUNRPC_SCHED_H_ */