File: /usr/src/linux/include/linux/sunrpc/sched.h

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/tqueue.h>
14     #include <linux/sunrpc/types.h>
15     #include <linux/wait.h>
16     
17     /*
18      * Define this if you want to test the fast scheduler for async calls.
19      * This is still experimental and may not work.
20      */
21     #undef  CONFIG_RPC_FASTSCHED
22     
23     /*
24      * This is the actual RPC procedure call info.
25      */
26     struct rpc_message {
27     	__u32			rpc_proc;	/* Procedure number */
28     	void *			rpc_argp;	/* Arguments */
29     	void *			rpc_resp;	/* Result */
30     	struct rpc_cred *	rpc_cred;	/* Credentials */
31     };
32     
33     /*
34      * This is the RPC task struct
35      */
36     struct rpc_task {
37     	struct rpc_task *	tk_prev;	/* wait queue links */
38     	struct rpc_task *	tk_next;
39     #ifdef RPC_DEBUG
40     	unsigned long		tk_magic;	/* 0xf00baa */
41     #endif
42     	struct rpc_task *	tk_next_task;	/* global list of tasks */
43     	struct rpc_task *	tk_prev_task;	/* global list of tasks */
44     	struct rpc_clnt *	tk_client;	/* RPC client */
45     	struct rpc_rqst *	tk_rqstp;	/* RPC request */
46     	int			tk_status;	/* result of last operation */
47     	struct rpc_wait_queue *	tk_rpcwait;	/* RPC wait queue we're on */
48     
49     	/*
50     	 * RPC call state
51     	 */
52     	struct rpc_message	tk_msg;		/* RPC call info */
53     	__u32 *			tk_buffer;	/* XDR buffer */
54     	__u8			tk_garb_retry,
55     				tk_cred_retry,
56     				tk_suid_retry;
57     
58     	/*
59     	 * timeout_fn   to be executed by timer bottom half
60     	 * callback	to be executed after waking up
61     	 * action	next procedure for async tasks
62     	 * exit		exit async task and report to caller
63     	 */
64     	void			(*tk_timeout_fn)(struct rpc_task *);
65     	void			(*tk_callback)(struct rpc_task *);
66     	void			(*tk_action)(struct rpc_task *);
67     	void			(*tk_exit)(struct rpc_task *);
68     	void			(*tk_release)(struct rpc_task *);
69     	void *			tk_calldata;
70     
71     	/*
72     	 * tk_timer is used for async processing by the RPC scheduling
73     	 * primitives. You should not access this directly unless
74     	 * you have a pathological interest in kernel oopses.
75     	 */
76     	struct timer_list	tk_timer;	/* kernel timer */
77     	wait_queue_head_t	tk_wait;	/* sync: sleep on this q */
78     	unsigned long		tk_timeout;	/* timeout for rpc_sleep() */
79     	unsigned short		tk_flags;	/* misc flags */
80     	unsigned short		tk_lock;	/* Task lock counter */
81     	unsigned char		tk_active   : 1,/* Task has been activated */
82     				tk_wakeup   : 1;/* Task waiting to wake up */
83     	unsigned long		tk_runstate;	/* Task run status */
84     #ifdef RPC_DEBUG
85     	unsigned short		tk_pid;		/* debugging aid */
86     #endif
87     };
88     #define tk_auth			tk_client->cl_auth
89     #define tk_xprt			tk_client->cl_xprt
90     
91     typedef void			(*rpc_action)(struct rpc_task *);
92     
93     /*
94      * RPC task flags
95      */
96     #define RPC_TASK_ASYNC		0x0001		/* is an async task */
97     #define RPC_TASK_SWAPPER	0x0002		/* is swapping in/out */
98     #define RPC_TASK_SETUID		0x0004		/* is setuid process */
99     #define RPC_TASK_CHILD		0x0008		/* is child of other task */
100     #define RPC_CALL_REALUID	0x0010		/* try using real uid */
101     #define RPC_CALL_MAJORSEEN	0x0020		/* major timeout seen */
102     #define RPC_TASK_ROOTCREDS	0x0040		/* force root creds */
103     #define RPC_TASK_DYNAMIC	0x0080		/* task was kmalloc'ed */
104     #define RPC_TASK_KILLED		0x0100		/* task was killed */
105     
106     #define RPC_IS_ASYNC(t)		((t)->tk_flags & RPC_TASK_ASYNC)
107     #define RPC_IS_SETUID(t)	((t)->tk_flags & RPC_TASK_SETUID)
108     #define RPC_IS_CHILD(t)		((t)->tk_flags & RPC_TASK_CHILD)
109     #define RPC_IS_SWAPPER(t)	((t)->tk_flags & RPC_TASK_SWAPPER)
110     #define RPC_DO_ROOTOVERRIDE(t)	((t)->tk_flags & RPC_TASK_ROOTCREDS)
111     #define RPC_ASSASSINATED(t)	((t)->tk_flags & RPC_TASK_KILLED)
112     #define RPC_IS_ACTIVATED(t)	((t)->tk_active)
113     #define RPC_DO_CALLBACK(t)	((t)->tk_callback != NULL)
114     
115     #define RPC_TASK_SLEEPING	0
116     #define RPC_TASK_RUNNING	1
117     #define RPC_IS_SLEEPING(t)	(test_bit(RPC_TASK_SLEEPING, &(t)->tk_runstate))
118     #define RPC_IS_RUNNING(t)	(test_bit(RPC_TASK_RUNNING, &(t)->tk_runstate))
119     
120     #define rpc_set_running(t)	(set_bit(RPC_TASK_RUNNING, &(t)->tk_runstate))
121     #define rpc_clear_running(t)	(clear_bit(RPC_TASK_RUNNING, &(t)->tk_runstate))
122     
123     #define rpc_set_sleeping(t)	(set_bit(RPC_TASK_SLEEPING, &(t)->tk_runstate))
124     
125     #define rpc_clear_sleeping(t) \
126     	do { \
127     		smp_mb__before_clear_bit(); \
128     		clear_bit(RPC_TASK_SLEEPING, &(t)->tk_runstate); \
129     		smp_mb__after_clear_bit(); \
130     	} while(0)
131     
132     /*
133      * RPC synchronization objects
134      */
135     struct rpc_wait_queue {
136     	struct rpc_task *	task;
137     #ifdef RPC_DEBUG
138     	char *			name;
139     #endif
140     };
141     
142     #ifndef RPC_DEBUG
143     # define RPC_INIT_WAITQ(name)	((struct rpc_wait_queue) { NULL })
144     #else
145     # define RPC_INIT_WAITQ(name)	((struct rpc_wait_queue) { NULL, name })
146     #endif
147     
148     /*
149      * Function prototypes
150      */
151     struct rpc_task *rpc_new_task(struct rpc_clnt *, rpc_action, int flags);
152     struct rpc_task *rpc_new_child(struct rpc_clnt *, struct rpc_task *parent);
153     void		rpc_init_task(struct rpc_task *, struct rpc_clnt *,
154     					rpc_action exitfunc, int flags);
155     void		rpc_release_task(struct rpc_task *);
156     void		rpc_killall_tasks(struct rpc_clnt *);
157     int		rpc_execute(struct rpc_task *);
158     void		rpc_run_child(struct rpc_task *parent, struct rpc_task *child,
159     					rpc_action action);
160     int		rpc_add_wait_queue(struct rpc_wait_queue *, struct rpc_task *);
161     void		rpc_remove_wait_queue(struct rpc_task *);
162     void		rpc_sleep_on(struct rpc_wait_queue *, struct rpc_task *,
163     					rpc_action action, rpc_action timer);
164     void		rpc_sleep_locked(struct rpc_wait_queue *, struct rpc_task *,
165     				 rpc_action action, rpc_action timer);
166     void		rpc_add_timer(struct rpc_task *, rpc_action);
167     void		rpc_wake_up_task(struct rpc_task *);
168     void		rpc_wake_up(struct rpc_wait_queue *);
169     struct rpc_task *rpc_wake_up_next(struct rpc_wait_queue *);
170     void		rpc_wake_up_status(struct rpc_wait_queue *, int);
171     int		__rpc_lock_task(struct rpc_task *);
172     void		rpc_unlock_task(struct rpc_task *);
173     void		rpc_delay(struct rpc_task *, unsigned long);
174     void *		rpc_allocate(unsigned int flags, unsigned int);
175     void		rpc_free(void *);
176     int		rpciod_up(void);
177     void		rpciod_down(void);
178     void		rpciod_wake_up(void);
179     #ifdef RPC_DEBUG
180     void		rpc_show_tasks(void);
181     #endif
182     
183     static __inline__ void *
184     rpc_malloc(struct rpc_task *task, unsigned int size)
185     {
186     	return rpc_allocate(task->tk_flags, size);
187     }
188     
189     static __inline__ void
190     rpc_exit(struct rpc_task *task, int status)
191     {
192     	task->tk_status = status;
193     	task->tk_action = NULL;
194     }
195     
196     #ifdef RPC_DEBUG
197     static __inline__ char *
198     rpc_qname(struct rpc_wait_queue *q)
199     {
200     	return q->name? q->name : "unknown";
201     }
202     #endif
203     
204     #endif /* _LINUX_SUNRPC_SCHED_H_ */
205