Fedora kernel-2.6.17-1.2142_FC4 patched with stable patch-2.6.17.4-vs2.0.2-rc26.diff
[linux-2.6.git] / include / linux / sunrpc / sched.h
index be2e6ef..82a91bb 100644 (file)
@@ -11,7 +11,9 @@
 
 #include <linux/timer.h>
 #include <linux/sunrpc/types.h>
+#include <linux/spinlock.h>
 #include <linux/wait.h>
+#include <linux/workqueue.h>
 #include <linux/sunrpc/xdr.h>
 
 /*
@@ -25,29 +27,33 @@ struct rpc_message {
        struct rpc_cred *       rpc_cred;       /* Credentials */
 };
 
+struct rpc_call_ops;
+struct rpc_wait_queue;
+struct rpc_wait {
+       struct list_head        list;           /* wait queue links */
+       struct list_head        links;          /* Links to related tasks */
+       struct rpc_wait_queue * rpc_waitq;      /* RPC wait queue we're on */
+};
+
 /*
  * This is the RPC task struct
  */
 struct rpc_task {
-       struct list_head        tk_list;        /* wait queue links */
 #ifdef RPC_DEBUG
        unsigned long           tk_magic;       /* 0xf00baa */
 #endif
+       atomic_t                tk_count;       /* Reference count */
        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 */
-       struct rpc_wait_queue * tk_rpcwait;     /* RPC wait queue we're on */
 
        /*
         * RPC call state
         */
        struct rpc_message      tk_msg;         /* RPC call info */
-       __u32 *                 tk_buffer;      /* XDR buffer */
-       size_t                  tk_bufsize;
-       __u8                    tk_garb_retry,
-                               tk_cred_retry,
-                               tk_suid_retry;
+       __u8                    tk_garb_retry;
+       __u8                    tk_cred_retry;
 
        unsigned long           tk_cookie;      /* Cookie for batching tasks */
 
@@ -55,13 +61,12 @@ struct rpc_task {
         * timeout_fn   to be executed by timer bottom half
         * callback     to be executed after waking up
         * action       next procedure for async tasks
-        * exit         exit async task and report to caller
+        * tk_ops       caller callbacks
         */
        void                    (*tk_timeout_fn)(struct rpc_task *);
        void                    (*tk_callback)(struct rpc_task *);
        void                    (*tk_action)(struct rpc_task *);
-       void                    (*tk_exit)(struct rpc_task *);
-       void                    (*tk_release)(struct rpc_task *);
+       const struct rpc_call_ops *tk_ops;
        void *                  tk_calldata;
 
        /*
@@ -70,13 +75,23 @@ struct rpc_task {
         * you have a pathological interest in kernel oopses.
         */
        struct timer_list       tk_timer;       /* kernel timer */
-       wait_queue_head_t       tk_wait;        /* sync: sleep on this q */
        unsigned long           tk_timeout;     /* timeout for rpc_sleep() */
        unsigned short          tk_flags;       /* misc flags */
-       unsigned char           tk_active   : 1;/* Task has been activated */
        unsigned char           tk_priority : 2;/* Task priority */
        unsigned long           tk_runstate;    /* Task run status */
-       struct list_head        tk_links;       /* links to related tasks */
+       struct workqueue_struct *tk_workqueue;  /* Normally rpciod, but could
+                                                * be any workqueue
+                                                */
+       union {
+               struct work_struct      tk_work;        /* Async task work queue */
+               struct rpc_wait         tk_wait;        /* RPC wait */
+       } u;
+
+       unsigned short          tk_timeouts;    /* maj timeouts */
+       size_t                  tk_bytes_sent;  /* total bytes sent */
+       unsigned long           tk_start;       /* RPC task init timestamp */
+       long                    tk_rtt;         /* round-trip time (jiffies) */
+
 #ifdef RPC_DEBUG
        unsigned short          tk_pid;         /* debugging aid */
 #endif
@@ -87,11 +102,11 @@ struct rpc_task {
 /* 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, tk_list)),1)
+               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, tk_list)),1))
+           ((task=list_entry((head)->next, struct rpc_task, u.tk_wait.list)),1))
 
 /* .. and walking list of all tasks */
 #define        alltask_for_each(task, pos, head) \
@@ -100,44 +115,76 @@ struct rpc_task {
 
 typedef void                   (*rpc_action)(struct rpc_task *);
 
+struct rpc_call_ops {
+       void (*rpc_call_prepare)(struct rpc_task *, void *);
+       void (*rpc_call_done)(struct rpc_task *, void *);
+       void (*rpc_release)(void *);
+};
+
+
 /*
  * RPC task flags
  */
 #define RPC_TASK_ASYNC         0x0001          /* is an async task */
 #define RPC_TASK_SWAPPER       0x0002          /* is swapping in/out */
-#define RPC_TASK_SETUID                0x0004          /* is setuid process */
 #define RPC_TASK_CHILD         0x0008          /* is child of other task */
-#define RPC_CALL_REALUID       0x0010          /* try using real uid */
 #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 */
+#define RPC_TASK_NOINTR                0x0400          /* uninterruptible task */
 
 #define RPC_IS_ASYNC(t)                ((t)->tk_flags & RPC_TASK_ASYNC)
-#define RPC_IS_SETUID(t)       ((t)->tk_flags & RPC_TASK_SETUID)
 #define RPC_IS_CHILD(t)                ((t)->tk_flags & RPC_TASK_CHILD)
 #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_ACTIVATED(t)    ((t)->tk_active)
 #define RPC_DO_CALLBACK(t)     ((t)->tk_callback != NULL)
 #define RPC_IS_SOFT(t)         ((t)->tk_flags & RPC_TASK_SOFT)
+#define RPC_TASK_UNINTERRUPTIBLE(t) ((t)->tk_flags & RPC_TASK_NOINTR)
 
-#define RPC_TASK_SLEEPING      0
-#define RPC_TASK_RUNNING       1
-#define RPC_IS_SLEEPING(t)     (test_bit(RPC_TASK_SLEEPING, &(t)->tk_runstate))
-#define RPC_IS_RUNNING(t)      (test_bit(RPC_TASK_RUNNING, &(t)->tk_runstate))
+#define RPC_TASK_RUNNING       0
+#define RPC_TASK_QUEUED                1
+#define RPC_TASK_WAKEUP                2
+#define RPC_TASK_HAS_TIMER     3
+#define RPC_TASK_ACTIVE                4
 
+#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))
-#define rpc_clear_running(t)   (clear_bit(RPC_TASK_RUNNING, &(t)->tk_runstate))
+#define rpc_test_and_set_running(t) \
+                               (test_and_set_bit(RPC_TASK_RUNNING, &(t)->tk_runstate))
+#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)
 
-#define rpc_set_sleeping(t)    (set_bit(RPC_TASK_SLEEPING, &(t)->tk_runstate))
+#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))
+#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)
 
-#define rpc_clear_sleeping(t) \
+#define rpc_start_wakeup(t) \
+       (test_and_set_bit(RPC_TASK_WAKEUP, &(t)->tk_runstate) == 0)
+#define rpc_finish_wakeup(t) \
        do { \
                smp_mb__before_clear_bit(); \
-               clear_bit(RPC_TASK_SLEEPING, &(t)->tk_runstate); \
+               clear_bit(RPC_TASK_WAKEUP, &(t)->tk_runstate); \
+               smp_mb__after_clear_bit(); \
+       } while (0)
+
+#define RPC_IS_ACTIVATED(t)    (test_bit(RPC_TASK_ACTIVE, &(t)->tk_runstate))
+#define rpc_set_active(t)      (set_bit(RPC_TASK_ACTIVE, &(t)->tk_runstate))
+#define rpc_clear_active(t)    \
+       do { \
+               smp_mb__before_clear_bit(); \
+               clear_bit(RPC_TASK_ACTIVE, &(t)->tk_runstate); \
                smp_mb__after_clear_bit(); \
        } while(0)
 
@@ -155,12 +202,14 @@ typedef void                      (*rpc_action)(struct rpc_task *);
  * RPC synchronization objects
  */
 struct rpc_wait_queue {
+       spinlock_t              lock;
        struct list_head        tasks[RPC_NR_PRIORITY]; /* task queue for each priority level */
        unsigned long           cookie;                 /* cookie of last task serviced */
        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 */
+       unsigned short          qlen;                   /* total # tasks waiting in queue */
 #ifdef RPC_DEBUG
        const char *            name;
 #endif
@@ -175,6 +224,7 @@ struct rpc_wait_queue {
 
 #ifndef RPC_DEBUG
 # define RPC_WAITQ_INIT(var,qname) { \
+               .lock = SPIN_LOCK_UNLOCKED, \
                .tasks = { \
                        [0] = LIST_HEAD_INIT(var.tasks[0]), \
                        [1] = LIST_HEAD_INIT(var.tasks[1]), \
@@ -183,6 +233,7 @@ struct rpc_wait_queue {
        }
 #else
 # define RPC_WAITQ_INIT(var,qname) { \
+               .lock = SPIN_LOCK_UNLOCKED, \
                .tasks = { \
                        [0] = LIST_HEAD_INIT(var.tasks[0]), \
                        [1] = LIST_HEAD_INIT(var.tasks[1]), \
@@ -198,22 +249,24 @@ struct rpc_wait_queue {
 /*
  * Function prototypes
  */
-struct rpc_task *rpc_new_task(struct rpc_clnt *, rpc_action, int flags);
+struct rpc_task *rpc_new_task(struct rpc_clnt *, int flags,
+                               const struct rpc_call_ops *ops, void *data);
+struct rpc_task *rpc_run_task(struct rpc_clnt *clnt, int flags,
+                               const struct rpc_call_ops *ops, void *data);
 struct rpc_task *rpc_new_child(struct rpc_clnt *, struct rpc_task *parent);
-void           rpc_init_task(struct rpc_task *, struct rpc_clnt *,
-                                       rpc_action exitfunc, int flags);
+void           rpc_init_task(struct rpc_task *task, struct rpc_clnt *clnt,
+                               int flags, const struct rpc_call_ops *ops,
+                               void *data);
 void           rpc_release_task(struct rpc_task *);
+void           rpc_exit_task(struct rpc_task *);
 void           rpc_killall_tasks(struct rpc_clnt *);
 int            rpc_execute(struct rpc_task *);
 void           rpc_run_child(struct rpc_task *parent, struct rpc_task *child,
                                        rpc_action action);
-int            rpc_add_wait_queue(struct rpc_wait_queue *, struct rpc_task *);
-void           rpc_remove_wait_queue(struct rpc_task *);
 void           rpc_init_priority_wait_queue(struct rpc_wait_queue *, const char *);
 void           rpc_init_wait_queue(struct rpc_wait_queue *, const char *);
 void           rpc_sleep_on(struct rpc_wait_queue *, struct rpc_task *,
                                        rpc_action action, rpc_action timer);
-void           rpc_add_timer(struct rpc_task *, rpc_action);
 void           rpc_wake_up_task(struct rpc_task *);
 void           rpc_wake_up(struct rpc_wait_queue *);
 struct rpc_task *rpc_wake_up_next(struct rpc_wait_queue *);
@@ -223,17 +276,23 @@ void *            rpc_malloc(struct rpc_task *, size_t);
 void           rpc_free(struct rpc_task *);
 int            rpciod_up(void);
 void           rpciod_down(void);
-void           rpciod_wake_up(void);
+int            __rpc_wait_for_completion_task(struct rpc_task *task, int (*)(void *));
 #ifdef RPC_DEBUG
 void           rpc_show_tasks(void);
 #endif
 int            rpc_init_mempool(void);
 void           rpc_destroy_mempool(void);
+extern struct workqueue_struct *rpciod_workqueue;
 
 static inline void rpc_exit(struct rpc_task *task, int status)
 {
        task->tk_status = status;
-       task->tk_action = NULL;
+       task->tk_action = rpc_exit_task;
+}
+
+static inline int rpc_wait_for_completion_task(struct rpc_task *task)
+{
+       return __rpc_wait_for_completion_task(task, NULL);
 }
 
 #ifdef RPC_DEBUG