2005-04-16 16:20:36 -06:00
|
|
|
/*
|
|
|
|
* 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>
|
2010-05-07 11:34:47 -06:00
|
|
|
#include <linux/ktime.h>
|
2005-04-16 16:20:36 -06:00
|
|
|
#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 */
|
|
|
|
};
|
|
|
|
|
2006-01-03 01:55:04 -07:00
|
|
|
struct rpc_call_ops;
|
2005-04-16 16:20:36 -06:00
|
|
|
struct rpc_wait_queue;
|
|
|
|
struct rpc_wait {
|
|
|
|
struct list_head list; /* wait queue links */
|
|
|
|
struct list_head links; /* Links to related tasks */
|
2007-07-18 14:18:52 -06:00
|
|
|
struct list_head timer_list; /* Timer list */
|
|
|
|
unsigned long expires;
|
2005-04-16 16:20:36 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This is the RPC task struct
|
|
|
|
*/
|
|
|
|
struct rpc_task {
|
2006-01-03 01:55:06 -07:00
|
|
|
atomic_t tk_count; /* Reference count */
|
2005-04-16 16:20:36 -06:00
|
|
|
struct list_head tk_task; /* global list of tasks */
|
|
|
|
struct rpc_clnt * tk_client; /* RPC client */
|
|
|
|
struct rpc_rqst * tk_rqstp; /* RPC request */
|
|
|
|
int tk_status; /* result of last operation */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* RPC call state
|
|
|
|
*/
|
|
|
|
struct rpc_message tk_msg; /* RPC call info */
|
|
|
|
__u8 tk_garb_retry;
|
|
|
|
__u8 tk_cred_retry;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* callback to be executed after waking up
|
|
|
|
* action next procedure for async tasks
|
2006-01-03 01:55:04 -07:00
|
|
|
* tk_ops caller callbacks
|
2005-04-16 16:20:36 -06:00
|
|
|
*/
|
|
|
|
void (*tk_callback)(struct rpc_task *);
|
|
|
|
void (*tk_action)(struct rpc_task *);
|
2006-01-03 01:55:04 -07:00
|
|
|
const struct rpc_call_ops *tk_ops;
|
2005-04-16 16:20:36 -06:00
|
|
|
void * tk_calldata;
|
|
|
|
|
|
|
|
unsigned long tk_timeout; /* timeout for rpc_sleep() */
|
|
|
|
unsigned short tk_flags; /* misc flags */
|
|
|
|
unsigned long tk_runstate; /* Task run status */
|
|
|
|
struct workqueue_struct *tk_workqueue; /* Normally rpciod, but could
|
|
|
|
* be any workqueue
|
|
|
|
*/
|
2008-02-22 13:46:41 -07:00
|
|
|
struct rpc_wait_queue *tk_waitqueue; /* RPC wait queue we're on */
|
2005-04-16 16:20:36 -06:00
|
|
|
union {
|
|
|
|
struct work_struct tk_work; /* Async task work queue */
|
|
|
|
struct rpc_wait tk_wait; /* RPC wait */
|
|
|
|
} u;
|
2006-03-20 11:44:17 -07:00
|
|
|
|
|
|
|
unsigned short tk_timeouts; /* maj timeouts */
|
2010-05-13 10:51:49 -06:00
|
|
|
ktime_t tk_start; /* RPC task init timestamp */
|
2006-03-20 11:44:17 -07:00
|
|
|
|
2007-07-14 13:40:00 -06:00
|
|
|
pid_t tk_owner; /* Process id for batching tasks */
|
|
|
|
unsigned char tk_priority : 2;/* Task priority */
|
|
|
|
|
2005-04-16 16:20:36 -06:00
|
|
|
#ifdef RPC_DEBUG
|
|
|
|
unsigned short tk_pid; /* debugging aid */
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
#define tk_xprt tk_client->cl_xprt
|
|
|
|
|
|
|
|
/* support walking a list of tasks on a wait queue */
|
|
|
|
#define task_for_each(task, pos, head) \
|
|
|
|
list_for_each(pos, head) \
|
|
|
|
if ((task=list_entry(pos, struct rpc_task, u.tk_wait.list)),1)
|
|
|
|
|
|
|
|
#define task_for_first(task, head) \
|
|
|
|
if (!list_empty(head) && \
|
|
|
|
((task=list_entry((head)->next, struct rpc_task, u.tk_wait.list)),1))
|
|
|
|
|
|
|
|
typedef void (*rpc_action)(struct rpc_task *);
|
|
|
|
|
2006-01-03 01:55:04 -07:00
|
|
|
struct rpc_call_ops {
|
2006-01-03 01:55:05 -07:00
|
|
|
void (*rpc_call_prepare)(struct rpc_task *, void *);
|
2006-01-03 01:55:04 -07:00
|
|
|
void (*rpc_call_done)(struct rpc_task *, void *);
|
|
|
|
void (*rpc_release)(void *);
|
|
|
|
};
|
|
|
|
|
2007-07-14 13:39:59 -06:00
|
|
|
struct rpc_task_setup {
|
2007-10-25 16:42:53 -06:00
|
|
|
struct rpc_task *task;
|
2007-07-14 13:39:59 -06:00
|
|
|
struct rpc_clnt *rpc_client;
|
|
|
|
const struct rpc_message *rpc_message;
|
|
|
|
const struct rpc_call_ops *callback_ops;
|
|
|
|
void *callback_data;
|
2008-02-19 18:04:21 -07:00
|
|
|
struct workqueue_struct *workqueue;
|
2007-07-14 13:39:59 -06:00
|
|
|
unsigned short flags;
|
2007-07-14 13:40:00 -06:00
|
|
|
signed char priority;
|
2007-07-14 13:39:59 -06:00
|
|
|
};
|
2006-01-03 01:55:04 -07:00
|
|
|
|
2005-04-16 16:20:36 -06:00
|
|
|
/*
|
|
|
|
* 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 */
|
SUNRPC: Allow RPCs to fail quickly if the server is unreachable
The kernel sometimes makes RPC calls to services that aren't running.
Because the kernel's RPC client always assumes the hard retry semantic
when reconnecting a connection-oriented RPC transport, the underlying
reconnect logic takes a long while to time out, even though the remote
may have responded immediately with ECONNREFUSED.
In certain cases, like upcalls to our local rpcbind daemon, or for NFS
mount requests, we'd like the kernel to fail immediately if the remote
service isn't reachable. This allows another transport to be tried
immediately, or the pending request can be abandoned quickly.
Introduce a per-request flag which controls how call_transmit_status()
behaves when request transmission fails because the server cannot be
reached.
We don't want soft connection semantics to apply to other errors. The
default case of the switch statement in call_transmit_status() no
longer falls through; the fall through code is copied to the default
case, and a "break;" is added.
The transport's connection re-establishment timeout is also ignored for
such requests. We want the request to fail immediately, so the
reconnect delay is skipped. Additionally, we don't want a connect
failure here to further increase the reconnect timeout value, since
this request will not be retried.
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
Signed-off-by: Trond Myklebust <Trond.Myklebust@netapp.com>
2009-12-03 13:58:56 -07:00
|
|
|
#define RPC_TASK_SOFTCONN 0x0400 /* Fail if can't connect */
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
#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)
|
|
|
|
#define RPC_IS_SOFT(t) ((t)->tk_flags & RPC_TASK_SOFT)
|
SUNRPC: Allow RPCs to fail quickly if the server is unreachable
The kernel sometimes makes RPC calls to services that aren't running.
Because the kernel's RPC client always assumes the hard retry semantic
when reconnecting a connection-oriented RPC transport, the underlying
reconnect logic takes a long while to time out, even though the remote
may have responded immediately with ECONNREFUSED.
In certain cases, like upcalls to our local rpcbind daemon, or for NFS
mount requests, we'd like the kernel to fail immediately if the remote
service isn't reachable. This allows another transport to be tried
immediately, or the pending request can be abandoned quickly.
Introduce a per-request flag which controls how call_transmit_status()
behaves when request transmission fails because the server cannot be
reached.
We don't want soft connection semantics to apply to other errors. The
default case of the switch statement in call_transmit_status() no
longer falls through; the fall through code is copied to the default
case, and a "break;" is added.
The transport's connection re-establishment timeout is also ignored for
such requests. We want the request to fail immediately, so the
reconnect delay is skipped. Additionally, we don't want a connect
failure here to further increase the reconnect timeout value, since
this request will not be retried.
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
Signed-off-by: Trond Myklebust <Trond.Myklebust@netapp.com>
2009-12-03 13:58:56 -07:00
|
|
|
#define RPC_IS_SOFTCONN(t) ((t)->tk_flags & RPC_TASK_SOFTCONN)
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
#define RPC_TASK_RUNNING 0
|
|
|
|
#define RPC_TASK_QUEUED 1
|
2008-02-25 22:40:50 -07:00
|
|
|
#define RPC_TASK_ACTIVE 2
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2007-02-20 14:57:45 -07:00
|
|
|
#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)
|
2005-04-16 16:20:36 -06:00
|
|
|
#define rpc_test_and_set_running(t) \
|
2007-02-20 14:57:45 -07:00
|
|
|
test_and_set_bit(RPC_TASK_RUNNING, &(t)->tk_runstate)
|
2005-04-16 16:20:36 -06:00
|
|
|
#define rpc_clear_running(t) \
|
|
|
|
do { \
|
|
|
|
smp_mb__before_clear_bit(); \
|
|
|
|
clear_bit(RPC_TASK_RUNNING, &(t)->tk_runstate); \
|
|
|
|
smp_mb__after_clear_bit(); \
|
|
|
|
} while (0)
|
|
|
|
|
2007-02-20 14:57:45 -07:00
|
|
|
#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)
|
2005-04-16 16:20:36 -06:00
|
|
|
#define rpc_clear_queued(t) \
|
|
|
|
do { \
|
|
|
|
smp_mb__before_clear_bit(); \
|
|
|
|
clear_bit(RPC_TASK_QUEUED, &(t)->tk_runstate); \
|
|
|
|
smp_mb__after_clear_bit(); \
|
|
|
|
} while (0)
|
|
|
|
|
2007-02-20 14:57:45 -07:00
|
|
|
#define RPC_IS_ACTIVATED(t) test_bit(RPC_TASK_ACTIVE, &(t)->tk_runstate)
|
2006-01-03 01:55:06 -07:00
|
|
|
|
2005-04-16 16:20:36 -06:00
|
|
|
/*
|
|
|
|
* Task priorities.
|
|
|
|
* Note: if you change these, you must also change
|
|
|
|
* the task initialization definitions below.
|
|
|
|
*/
|
2007-07-14 13:40:00 -06:00
|
|
|
#define RPC_PRIORITY_LOW (-1)
|
|
|
|
#define RPC_PRIORITY_NORMAL (0)
|
|
|
|
#define RPC_PRIORITY_HIGH (1)
|
2009-12-14 22:27:55 -07:00
|
|
|
#define RPC_PRIORITY_PRIVILEGED (2)
|
|
|
|
#define RPC_NR_PRIORITY (1 + RPC_PRIORITY_PRIVILEGED - RPC_PRIORITY_LOW)
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2007-07-18 14:18:52 -06:00
|
|
|
struct rpc_timer {
|
|
|
|
struct timer_list timer;
|
|
|
|
struct list_head list;
|
|
|
|
unsigned long expires;
|
|
|
|
};
|
|
|
|
|
2005-04-16 16:20:36 -06:00
|
|
|
/*
|
|
|
|
* RPC synchronization objects
|
|
|
|
*/
|
|
|
|
struct rpc_wait_queue {
|
|
|
|
spinlock_t lock;
|
|
|
|
struct list_head tasks[RPC_NR_PRIORITY]; /* task queue for each priority level */
|
2007-07-14 13:40:00 -06:00
|
|
|
pid_t owner; /* process id of last task serviced */
|
2005-04-16 16:20:36 -06:00
|
|
|
unsigned char maxpriority; /* maximum priority (0 if queue is not a priority queue) */
|
|
|
|
unsigned char priority; /* current priority */
|
|
|
|
unsigned char count; /* # task groups remaining serviced so far */
|
|
|
|
unsigned char nr; /* # tasks remaining for cookie */
|
2006-03-20 11:44:15 -07:00
|
|
|
unsigned short qlen; /* total # tasks waiting in queue */
|
2007-07-18 14:18:52 -06:00
|
|
|
struct rpc_timer timer_list;
|
2005-04-16 16:20:36 -06:00
|
|
|
#ifdef RPC_DEBUG
|
|
|
|
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
|
|
|
|
*/
|
2007-07-14 13:39:59 -06:00
|
|
|
struct rpc_task *rpc_new_task(const struct rpc_task_setup *);
|
2007-07-14 13:39:59 -06:00
|
|
|
struct rpc_task *rpc_run_task(const struct rpc_task_setup *);
|
2009-04-01 07:23:03 -06:00
|
|
|
struct rpc_task *rpc_run_bc_task(struct rpc_rqst *req,
|
|
|
|
const struct rpc_call_ops *ops);
|
2006-11-11 20:18:03 -07:00
|
|
|
void rpc_put_task(struct rpc_task *);
|
2006-01-03 01:55:03 -07:00
|
|
|
void rpc_exit_task(struct rpc_task *);
|
2006-10-18 14:01:05 -06:00
|
|
|
void rpc_release_calldata(const struct rpc_call_ops *, void *);
|
2005-04-16 16:20:36 -06:00
|
|
|
void rpc_killall_tasks(struct rpc_clnt *);
|
2007-02-03 14:38:41 -07:00
|
|
|
void rpc_execute(struct rpc_task *);
|
2005-04-16 16:20:36 -06:00
|
|
|
void rpc_init_priority_wait_queue(struct rpc_wait_queue *, const char *);
|
|
|
|
void rpc_init_wait_queue(struct rpc_wait_queue *, const char *);
|
2008-02-22 15:06:55 -07:00
|
|
|
void rpc_destroy_wait_queue(struct rpc_wait_queue *);
|
2005-04-16 16:20:36 -06:00
|
|
|
void rpc_sleep_on(struct rpc_wait_queue *, struct rpc_task *,
|
2008-02-22 14:34:17 -07:00
|
|
|
rpc_action action);
|
2008-02-22 13:46:41 -07:00
|
|
|
void rpc_wake_up_queued_task(struct rpc_wait_queue *,
|
|
|
|
struct rpc_task *);
|
2005-04-16 16:20:36 -06:00
|
|
|
void rpc_wake_up(struct rpc_wait_queue *);
|
|
|
|
struct rpc_task *rpc_wake_up_next(struct rpc_wait_queue *);
|
|
|
|
void rpc_wake_up_status(struct rpc_wait_queue *, int);
|
2009-12-14 22:27:53 -07:00
|
|
|
int rpc_queue_empty(struct rpc_wait_queue *);
|
2005-04-16 16:20:36 -06:00
|
|
|
void rpc_delay(struct rpc_task *, unsigned long);
|
|
|
|
void * rpc_malloc(struct rpc_task *, size_t);
|
2007-03-29 14:47:58 -06:00
|
|
|
void rpc_free(void *);
|
2005-04-16 16:20:36 -06:00
|
|
|
int rpciod_up(void);
|
|
|
|
void rpciod_down(void);
|
2006-01-03 01:55:06 -07:00
|
|
|
int __rpc_wait_for_completion_task(struct rpc_task *task, int (*)(void *));
|
2005-04-16 16:20:36 -06:00
|
|
|
#ifdef RPC_DEBUG
|
|
|
|
void rpc_show_tasks(void);
|
|
|
|
#endif
|
|
|
|
int rpc_init_mempool(void);
|
|
|
|
void rpc_destroy_mempool(void);
|
2006-03-20 11:44:08 -07:00
|
|
|
extern struct workqueue_struct *rpciod_workqueue;
|
2009-04-01 07:22:40 -06:00
|
|
|
void rpc_prepare_task(struct rpc_task *task);
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
static inline void rpc_exit(struct rpc_task *task, int status)
|
|
|
|
{
|
|
|
|
task->tk_status = status;
|
2006-01-03 01:55:03 -07:00
|
|
|
task->tk_action = rpc_exit_task;
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
2006-01-03 01:55:06 -07:00
|
|
|
static inline int rpc_wait_for_completion_task(struct rpc_task *task)
|
|
|
|
{
|
|
|
|
return __rpc_wait_for_completion_task(task, NULL);
|
|
|
|
}
|
|
|
|
|
2009-12-14 22:27:55 -07:00
|
|
|
static inline void rpc_task_set_priority(struct rpc_task *task, unsigned char prio)
|
|
|
|
{
|
|
|
|
task->tk_priority = prio - RPC_PRIORITY_LOW;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int rpc_task_has_priority(struct rpc_task *task, unsigned char prio)
|
|
|
|
{
|
|
|
|
return (task->tk_priority + RPC_PRIORITY_LOW == prio);
|
|
|
|
}
|
|
|
|
|
2005-04-16 16:20:36 -06:00
|
|
|
#ifdef RPC_DEBUG
|
|
|
|
static inline const char * rpc_qname(struct rpc_wait_queue *q)
|
|
|
|
{
|
|
|
|
return ((q && q->name) ? q->name : "unknown");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif /* _LINUX_SUNRPC_SCHED_H_ */
|