sched.h 8.8 KB
Newer Older
L
Linus Torvalds 已提交
1 2 3 4 5 6 7 8 9 10 11 12
/*
 * linux/include/linux/sunrpc/sched.h
 *
 * Scheduling primitives for kernel Sun RPC.
 *
 * Copyright (C) 1996, Olaf Kirch <okir@monad.swb.de>
 */

#ifndef _LINUX_SUNRPC_SCHED_H_
#define _LINUX_SUNRPC_SCHED_H_

#include <linux/timer.h>
13
#include <linux/ktime.h>
L
Linus Torvalds 已提交
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
#include <linux/sunrpc/types.h>
#include <linux/spinlock.h>
#include <linux/wait.h>
#include <linux/workqueue.h>
#include <linux/sunrpc/xdr.h>

/*
 * This is the actual RPC procedure call info.
 */
struct rpc_procinfo;
struct rpc_message {
	struct rpc_procinfo *	rpc_proc;	/* Procedure information */
	void *			rpc_argp;	/* Arguments */
	void *			rpc_resp;	/* Result */
	struct rpc_cred *	rpc_cred;	/* Credentials */
};

31
struct rpc_call_ops;
L
Linus Torvalds 已提交
32 33 34 35
struct rpc_wait_queue;
struct rpc_wait {
	struct list_head	list;		/* wait queue links */
	struct list_head	links;		/* Links to related tasks */
36 37
	struct list_head	timer_list;	/* Timer list */
	unsigned long		expires;
L
Linus Torvalds 已提交
38 39 40 41 42 43
};

/*
 * This is the RPC task struct
 */
struct rpc_task {
44
	atomic_t		tk_count;	/* Reference count */
45
	int			tk_status;	/* result of last operation */
L
Linus Torvalds 已提交
46 47 48 49 50 51 52 53 54 55 56
	struct list_head	tk_task;	/* global list of tasks */

	/*
	 * callback	to be executed after waking up
	 * action	next procedure for async tasks
	 */
	void			(*tk_callback)(struct rpc_task *);
	void			(*tk_action)(struct rpc_task *);

	unsigned long		tk_timeout;	/* timeout for rpc_sleep() */
	unsigned long		tk_runstate;	/* Task run status */
57

58
	struct rpc_wait_queue 	*tk_waitqueue;	/* RPC wait queue we're on */
L
Linus Torvalds 已提交
59 60 61 62
	union {
		struct work_struct	tk_work;	/* Async task work queue */
		struct rpc_wait		tk_wait;	/* RPC wait */
	} u;
63

64 65 66 67 68 69 70 71
	/*
	 * RPC call state
	 */
	struct rpc_message	tk_msg;		/* RPC call info */
	void *			tk_calldata;	/* Caller private data */
	const struct rpc_call_ops *tk_ops;	/* Caller callbacks */

	struct rpc_clnt *	tk_client;	/* RPC client */
72 73
	struct rpc_xprt *	tk_xprt;	/* Transport */

74 75 76 77 78
	struct rpc_rqst *	tk_rqstp;	/* RPC request */

	struct workqueue_struct	*tk_workqueue;	/* Normally rpciod, but could
						 * be any workqueue
						 */
79
	ktime_t			tk_start;	/* RPC task init timestamp */
80

81
	pid_t			tk_owner;	/* Process id for batching tasks */
82 83
	unsigned short		tk_flags;	/* misc flags */
	unsigned short		tk_timeouts;	/* maj timeouts */
84

J
Jeff Layton 已提交
85
#if IS_ENABLED(CONFIG_SUNRPC_DEBUG) || IS_ENABLED(CONFIG_TRACEPOINTS)
L
Linus Torvalds 已提交
86 87
	unsigned short		tk_pid;		/* debugging aid */
#endif
88 89
	unsigned char		tk_priority : 2,/* Task priority */
				tk_garb_retry : 2,
90 91
				tk_cred_retry : 2,
				tk_rebind_retry : 2;
L
Linus Torvalds 已提交
92 93 94 95
};

typedef void			(*rpc_action)(struct rpc_task *);

96
struct rpc_call_ops {
T
Trond Myklebust 已提交
97
	void (*rpc_call_prepare)(struct rpc_task *, void *);
98
	void (*rpc_call_done)(struct rpc_task *, void *);
99
	void (*rpc_count_stats)(struct rpc_task *, void *);
100 101 102
	void (*rpc_release)(void *);
};

103
struct rpc_task_setup {
104
	struct rpc_task *task;
105 106 107 108
	struct rpc_clnt *rpc_client;
	const struct rpc_message *rpc_message;
	const struct rpc_call_ops *callback_ops;
	void *callback_data;
109
	struct workqueue_struct *workqueue;
110
	unsigned short flags;
111
	signed char priority;
112
};
113

L
Linus Torvalds 已提交
114 115 116 117 118 119 120 121 122 123
/*
 * RPC task flags
 */
#define RPC_TASK_ASYNC		0x0001		/* is an async task */
#define RPC_TASK_SWAPPER	0x0002		/* is swapping in/out */
#define RPC_CALL_MAJORSEEN	0x0020		/* major timeout seen */
#define RPC_TASK_ROOTCREDS	0x0040		/* force root creds */
#define RPC_TASK_DYNAMIC	0x0080		/* task was kmalloc'ed */
#define RPC_TASK_KILLED		0x0100		/* task was killed */
#define RPC_TASK_SOFT		0x0200		/* Use soft timeouts */
124
#define RPC_TASK_SOFTCONN	0x0400		/* Fail if can't connect */
125
#define RPC_TASK_SENT		0x0800		/* message was sent */
126
#define RPC_TASK_TIMEOUT	0x1000		/* fail with ETIMEDOUT on timeout */
127
#define RPC_TASK_NOCONNECT	0x2000		/* return ENOTCONN if not connected */
128
#define RPC_TASK_NO_RETRANS_TIMEOUT	0x4000		/* wait forever for a reply */
L
Linus Torvalds 已提交
129 130 131 132 133

#define RPC_IS_ASYNC(t)		((t)->tk_flags & RPC_TASK_ASYNC)
#define RPC_IS_SWAPPER(t)	((t)->tk_flags & RPC_TASK_SWAPPER)
#define RPC_DO_ROOTOVERRIDE(t)	((t)->tk_flags & RPC_TASK_ROOTCREDS)
#define RPC_ASSASSINATED(t)	((t)->tk_flags & RPC_TASK_KILLED)
134
#define RPC_IS_SOFT(t)		((t)->tk_flags & (RPC_TASK_SOFT|RPC_TASK_TIMEOUT))
135
#define RPC_IS_SOFTCONN(t)	((t)->tk_flags & RPC_TASK_SOFTCONN)
136
#define RPC_WAS_SENT(t)		((t)->tk_flags & RPC_TASK_SENT)
L
Linus Torvalds 已提交
137 138 139

#define RPC_TASK_RUNNING	0
#define RPC_TASK_QUEUED		1
140
#define RPC_TASK_ACTIVE		2
L
Linus Torvalds 已提交
141

142 143
#define RPC_IS_RUNNING(t)	test_bit(RPC_TASK_RUNNING, &(t)->tk_runstate)
#define rpc_set_running(t)	set_bit(RPC_TASK_RUNNING, &(t)->tk_runstate)
L
Linus Torvalds 已提交
144
#define rpc_test_and_set_running(t) \
145
				test_and_set_bit(RPC_TASK_RUNNING, &(t)->tk_runstate)
L
Linus Torvalds 已提交
146 147
#define rpc_clear_running(t)	\
	do { \
148
		smp_mb__before_atomic(); \
L
Linus Torvalds 已提交
149
		clear_bit(RPC_TASK_RUNNING, &(t)->tk_runstate); \
150
		smp_mb__after_atomic(); \
L
Linus Torvalds 已提交
151 152
	} while (0)

153 154
#define RPC_IS_QUEUED(t)	test_bit(RPC_TASK_QUEUED, &(t)->tk_runstate)
#define rpc_set_queued(t)	set_bit(RPC_TASK_QUEUED, &(t)->tk_runstate)
L
Linus Torvalds 已提交
155 156
#define rpc_clear_queued(t)	\
	do { \
157
		smp_mb__before_atomic(); \
L
Linus Torvalds 已提交
158
		clear_bit(RPC_TASK_QUEUED, &(t)->tk_runstate); \
159
		smp_mb__after_atomic(); \
L
Linus Torvalds 已提交
160 161
	} while (0)

162
#define RPC_IS_ACTIVATED(t)	test_bit(RPC_TASK_ACTIVE, &(t)->tk_runstate)
163

L
Linus Torvalds 已提交
164 165 166 167 168
/*
 * Task priorities.
 * Note: if you change these, you must also change
 * the task initialization definitions below.
 */
169 170 171
#define RPC_PRIORITY_LOW	(-1)
#define RPC_PRIORITY_NORMAL	(0)
#define RPC_PRIORITY_HIGH	(1)
172 173
#define RPC_PRIORITY_PRIVILEGED	(2)
#define RPC_NR_PRIORITY		(1 + RPC_PRIORITY_PRIVILEGED - RPC_PRIORITY_LOW)
L
Linus Torvalds 已提交
174

175 176 177 178 179 180
struct rpc_timer {
	struct timer_list timer;
	struct list_head list;
	unsigned long expires;
};

L
Linus Torvalds 已提交
181 182 183 184 185 186
/*
 * RPC synchronization objects
 */
struct rpc_wait_queue {
	spinlock_t		lock;
	struct list_head	tasks[RPC_NR_PRIORITY];	/* task queue for each priority level */
187
	pid_t			owner;			/* process id of last task serviced */
L
Linus Torvalds 已提交
188 189 190
	unsigned char		maxpriority;		/* maximum priority (0 if queue is not a priority queue) */
	unsigned char		priority;		/* current priority */
	unsigned char		nr;			/* # tasks remaining for cookie */
191
	unsigned short		qlen;			/* total # tasks waiting in queue */
192
	struct rpc_timer	timer_list;
J
Jeff Layton 已提交
193
#if IS_ENABLED(CONFIG_SUNRPC_DEBUG) || IS_ENABLED(CONFIG_TRACEPOINTS)
L
Linus Torvalds 已提交
194 195 196 197 198 199 200 201 202 203 204 205 206 207 208
	const char *		name;
#endif
};

/*
 * This is the # requests to send consecutively
 * from a single cookie.  The aim is to improve
 * performance of NFS operations such as read/write.
 */
#define RPC_BATCH_COUNT			16
#define RPC_IS_PRIORITY(q)		((q)->maxpriority > 0)

/*
 * Function prototypes
 */
209
struct rpc_task *rpc_new_task(const struct rpc_task_setup *);
T
Trond Myklebust 已提交
210
struct rpc_task *rpc_run_task(const struct rpc_task_setup *);
211
struct rpc_task *rpc_run_bc_task(struct rpc_rqst *req);
212
void		rpc_put_task(struct rpc_task *);
213
void		rpc_put_task_async(struct rpc_task *);
T
Trond Myklebust 已提交
214
void		rpc_exit_task(struct rpc_task *);
215
void		rpc_exit(struct rpc_task *, int);
216
void		rpc_release_calldata(const struct rpc_call_ops *, void *);
L
Linus Torvalds 已提交
217
void		rpc_killall_tasks(struct rpc_clnt *);
T
Trond Myklebust 已提交
218
void		rpc_execute(struct rpc_task *);
L
Linus Torvalds 已提交
219 220
void		rpc_init_priority_wait_queue(struct rpc_wait_queue *, const char *);
void		rpc_init_wait_queue(struct rpc_wait_queue *, const char *);
221
void		rpc_destroy_wait_queue(struct rpc_wait_queue *);
L
Linus Torvalds 已提交
222
void		rpc_sleep_on(struct rpc_wait_queue *, struct rpc_task *,
223
					rpc_action action);
224 225 226 227
void		rpc_sleep_on_priority(struct rpc_wait_queue *,
					struct rpc_task *,
					rpc_action action,
					int priority);
228 229
void		rpc_wake_up_queued_task(struct rpc_wait_queue *,
					struct rpc_task *);
L
Linus Torvalds 已提交
230 231
void		rpc_wake_up(struct rpc_wait_queue *);
struct rpc_task *rpc_wake_up_next(struct rpc_wait_queue *);
232 233 234
struct rpc_task *rpc_wake_up_first(struct rpc_wait_queue *,
					bool (*)(struct rpc_task *, void *),
					void *);
L
Linus Torvalds 已提交
235 236 237
void		rpc_wake_up_status(struct rpc_wait_queue *, int);
void		rpc_delay(struct rpc_task *, unsigned long);
void *		rpc_malloc(struct rpc_task *, size_t);
238
void		rpc_free(void *);
L
Linus Torvalds 已提交
239 240
int		rpciod_up(void);
void		rpciod_down(void);
241
int		__rpc_wait_for_completion_task(struct rpc_task *task, wait_bit_action_f *);
J
Jeff Layton 已提交
242
#if IS_ENABLED(CONFIG_SUNRPC_DEBUG)
243 244
struct net;
void		rpc_show_tasks(struct net *);
L
Linus Torvalds 已提交
245 246 247
#endif
int		rpc_init_mempool(void);
void		rpc_destroy_mempool(void);
248
extern struct workqueue_struct *rpciod_workqueue;
249
void		rpc_prepare_task(struct rpc_task *task);
L
Linus Torvalds 已提交
250

251 252 253 254 255
static inline int rpc_wait_for_completion_task(struct rpc_task *task)
{
	return __rpc_wait_for_completion_task(task, NULL);
}

J
Jeff Layton 已提交
256
#if IS_ENABLED(CONFIG_SUNRPC_DEBUG) || IS_ENABLED(CONFIG_TRACEPOINTS)
257
static inline const char * rpc_qname(const struct rpc_wait_queue *q)
L
Linus Torvalds 已提交
258 259 260
{
	return ((q && q->name) ? q->name : "unknown");
}
261 262 263 264 265 266 267 268 269 270 271

static inline void rpc_assign_waitqueue_name(struct rpc_wait_queue *q,
		const char *name)
{
	q->name = name;
}
#else
static inline void rpc_assign_waitqueue_name(struct rpc_wait_queue *q,
		const char *name)
{
}
L
Linus Torvalds 已提交
272 273
#endif

274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289
#if IS_ENABLED(CONFIG_SUNRPC_SWAP)
int rpc_clnt_swap_activate(struct rpc_clnt *clnt);
void rpc_clnt_swap_deactivate(struct rpc_clnt *clnt);
#else
static inline int
rpc_clnt_swap_activate(struct rpc_clnt *clnt)
{
	return -EINVAL;
}

static inline void
rpc_clnt_swap_deactivate(struct rpc_clnt *clnt)
{
}
#endif /* CONFIG_SUNRPC_SWAP */

L
Linus Torvalds 已提交
290
#endif /* _LINUX_SUNRPC_SCHED_H_ */