Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 /*
0003  * linux/include/linux/sunrpc/sched.h
0004  *
0005  * Scheduling primitives for kernel Sun RPC.
0006  *
0007  * Copyright (C) 1996, Olaf Kirch <okir@monad.swb.de>
0008  */
0009 
0010 #ifndef _LINUX_SUNRPC_SCHED_H_
0011 #define _LINUX_SUNRPC_SCHED_H_
0012 
0013 #include <linux/timer.h>
0014 #include <linux/ktime.h>
0015 #include <linux/sunrpc/types.h>
0016 #include <linux/spinlock.h>
0017 #include <linux/wait_bit.h>
0018 #include <linux/workqueue.h>
0019 #include <linux/sunrpc/xdr.h>
0020 
0021 /*
0022  * This is the actual RPC procedure call info.
0023  */
0024 struct rpc_procinfo;
0025 struct rpc_message {
0026     const struct rpc_procinfo *rpc_proc;    /* Procedure information */
0027     void *          rpc_argp;   /* Arguments */
0028     void *          rpc_resp;   /* Result */
0029     const struct cred * rpc_cred;   /* Credentials */
0030 };
0031 
0032 struct rpc_call_ops;
0033 struct rpc_wait_queue;
0034 struct rpc_wait {
0035     struct list_head    list;       /* wait queue links */
0036     struct list_head    links;      /* Links to related tasks */
0037     struct list_head    timer_list; /* Timer list */
0038 };
0039 
0040 /*
0041  * This is the RPC task struct
0042  */
0043 struct rpc_task {
0044     atomic_t        tk_count;   /* Reference count */
0045     int         tk_status;  /* result of last operation */
0046     struct list_head    tk_task;    /* global list of tasks */
0047 
0048     /*
0049      * callback to be executed after waking up
0050      * action   next procedure for async tasks
0051      */
0052     void            (*tk_callback)(struct rpc_task *);
0053     void            (*tk_action)(struct rpc_task *);
0054 
0055     unsigned long       tk_timeout; /* timeout for rpc_sleep() */
0056     unsigned long       tk_runstate;    /* Task run status */
0057 
0058     struct rpc_wait_queue   *tk_waitqueue;  /* RPC wait queue we're on */
0059     union {
0060         struct work_struct  tk_work;    /* Async task work queue */
0061         struct rpc_wait     tk_wait;    /* RPC wait */
0062     } u;
0063 
0064     /*
0065      * RPC call state
0066      */
0067     struct rpc_message  tk_msg;     /* RPC call info */
0068     void *          tk_calldata;    /* Caller private data */
0069     const struct rpc_call_ops *tk_ops;  /* Caller callbacks */
0070 
0071     struct rpc_clnt *   tk_client;  /* RPC client */
0072     struct rpc_xprt *   tk_xprt;    /* Transport */
0073     struct rpc_cred *   tk_op_cred; /* cred being operated on */
0074 
0075     struct rpc_rqst *   tk_rqstp;   /* RPC request */
0076 
0077     struct workqueue_struct *tk_workqueue;  /* Normally rpciod, but could
0078                          * be any workqueue
0079                          */
0080     ktime_t         tk_start;   /* RPC task init timestamp */
0081 
0082     pid_t           tk_owner;   /* Process id for batching tasks */
0083 
0084     int         tk_rpc_status;  /* Result of last RPC operation */
0085     unsigned short      tk_flags;   /* misc flags */
0086     unsigned short      tk_timeouts;    /* maj timeouts */
0087 
0088 #if IS_ENABLED(CONFIG_SUNRPC_DEBUG) || IS_ENABLED(CONFIG_TRACEPOINTS)
0089     unsigned short      tk_pid;     /* debugging aid */
0090 #endif
0091     unsigned char       tk_priority : 2,/* Task priority */
0092                 tk_garb_retry : 2,
0093                 tk_cred_retry : 2,
0094                 tk_rebind_retry : 2;
0095 };
0096 
0097 typedef void            (*rpc_action)(struct rpc_task *);
0098 
0099 struct rpc_call_ops {
0100     void (*rpc_call_prepare)(struct rpc_task *, void *);
0101     void (*rpc_call_done)(struct rpc_task *, void *);
0102     void (*rpc_count_stats)(struct rpc_task *, void *);
0103     void (*rpc_release)(void *);
0104 };
0105 
0106 struct rpc_task_setup {
0107     struct rpc_task *task;
0108     struct rpc_clnt *rpc_client;
0109     struct rpc_xprt *rpc_xprt;
0110     struct rpc_cred *rpc_op_cred;   /* credential being operated on */
0111     const struct rpc_message *rpc_message;
0112     const struct rpc_call_ops *callback_ops;
0113     void *callback_data;
0114     struct workqueue_struct *workqueue;
0115     unsigned short flags;
0116     signed char priority;
0117 };
0118 
0119 /*
0120  * RPC task flags
0121  */
0122 #define RPC_TASK_ASYNC      0x0001      /* is an async task */
0123 #define RPC_TASK_SWAPPER    0x0002      /* is swapping in/out */
0124 #define RPC_TASK_MOVEABLE   0x0004      /* nfs4.1+ rpc tasks */
0125 #define RPC_TASK_NULLCREDS  0x0010      /* Use AUTH_NULL credential */
0126 #define RPC_CALL_MAJORSEEN  0x0020      /* major timeout seen */
0127 #define RPC_TASK_DYNAMIC    0x0080      /* task was kmalloc'ed */
0128 #define RPC_TASK_NO_ROUND_ROBIN 0x0100      /* send requests on "main" xprt */
0129 #define RPC_TASK_SOFT       0x0200      /* Use soft timeouts */
0130 #define RPC_TASK_SOFTCONN   0x0400      /* Fail if can't connect */
0131 #define RPC_TASK_SENT       0x0800      /* message was sent */
0132 #define RPC_TASK_TIMEOUT    0x1000      /* fail with ETIMEDOUT on timeout */
0133 #define RPC_TASK_NOCONNECT  0x2000      /* return ENOTCONN if not connected */
0134 #define RPC_TASK_NO_RETRANS_TIMEOUT 0x4000      /* wait forever for a reply */
0135 #define RPC_TASK_CRED_NOREF 0x8000      /* No refcount on the credential */
0136 
0137 #define RPC_IS_ASYNC(t)     ((t)->tk_flags & RPC_TASK_ASYNC)
0138 #define RPC_IS_SWAPPER(t)   ((t)->tk_flags & RPC_TASK_SWAPPER)
0139 #define RPC_IS_SOFT(t)      ((t)->tk_flags & (RPC_TASK_SOFT|RPC_TASK_TIMEOUT))
0140 #define RPC_IS_SOFTCONN(t)  ((t)->tk_flags & RPC_TASK_SOFTCONN)
0141 #define RPC_WAS_SENT(t)     ((t)->tk_flags & RPC_TASK_SENT)
0142 #define RPC_IS_MOVEABLE(t)  ((t)->tk_flags & RPC_TASK_MOVEABLE)
0143 
0144 #define RPC_TASK_RUNNING    0
0145 #define RPC_TASK_QUEUED     1
0146 #define RPC_TASK_ACTIVE     2
0147 #define RPC_TASK_NEED_XMIT  3
0148 #define RPC_TASK_NEED_RECV  4
0149 #define RPC_TASK_MSG_PIN_WAIT   5
0150 #define RPC_TASK_SIGNALLED  6
0151 
0152 #define rpc_test_and_set_running(t) \
0153                 test_and_set_bit(RPC_TASK_RUNNING, &(t)->tk_runstate)
0154 #define rpc_clear_running(t)    clear_bit(RPC_TASK_RUNNING, &(t)->tk_runstate)
0155 
0156 #define RPC_IS_QUEUED(t)    test_bit(RPC_TASK_QUEUED, &(t)->tk_runstate)
0157 #define rpc_set_queued(t)   set_bit(RPC_TASK_QUEUED, &(t)->tk_runstate)
0158 #define rpc_clear_queued(t) clear_bit(RPC_TASK_QUEUED, &(t)->tk_runstate)
0159 
0160 #define RPC_IS_ACTIVATED(t) test_bit(RPC_TASK_ACTIVE, &(t)->tk_runstate)
0161 
0162 #define RPC_SIGNALLED(t)    test_bit(RPC_TASK_SIGNALLED, &(t)->tk_runstate)
0163 
0164 /*
0165  * Task priorities.
0166  * Note: if you change these, you must also change
0167  * the task initialization definitions below.
0168  */
0169 #define RPC_PRIORITY_LOW    (-1)
0170 #define RPC_PRIORITY_NORMAL (0)
0171 #define RPC_PRIORITY_HIGH   (1)
0172 #define RPC_PRIORITY_PRIVILEGED (2)
0173 #define RPC_NR_PRIORITY     (1 + RPC_PRIORITY_PRIVILEGED - RPC_PRIORITY_LOW)
0174 
0175 struct rpc_timer {
0176     struct list_head list;
0177     unsigned long expires;
0178     struct delayed_work dwork;
0179 };
0180 
0181 /*
0182  * RPC synchronization objects
0183  */
0184 struct rpc_wait_queue {
0185     spinlock_t      lock;
0186     struct list_head    tasks[RPC_NR_PRIORITY]; /* task queue for each priority level */
0187     unsigned char       maxpriority;        /* maximum priority (0 if queue is not a priority queue) */
0188     unsigned char       priority;       /* current priority */
0189     unsigned char       nr;         /* # tasks remaining for cookie */
0190     unsigned short      qlen;           /* total # tasks waiting in queue */
0191     struct rpc_timer    timer_list;
0192 #if IS_ENABLED(CONFIG_SUNRPC_DEBUG) || IS_ENABLED(CONFIG_TRACEPOINTS)
0193     const char *        name;
0194 #endif
0195 };
0196 
0197 /*
0198  * This is the # requests to send consecutively
0199  * from a single cookie.  The aim is to improve
0200  * performance of NFS operations such as read/write.
0201  */
0202 #define RPC_IS_PRIORITY(q)      ((q)->maxpriority > 0)
0203 
0204 /*
0205  * Function prototypes
0206  */
0207 struct rpc_task *rpc_new_task(const struct rpc_task_setup *);
0208 struct rpc_task *rpc_run_task(const struct rpc_task_setup *);
0209 struct rpc_task *rpc_run_bc_task(struct rpc_rqst *req);
0210 void        rpc_put_task(struct rpc_task *);
0211 void        rpc_put_task_async(struct rpc_task *);
0212 void        rpc_signal_task(struct rpc_task *);
0213 void        rpc_exit_task(struct rpc_task *);
0214 void        rpc_exit(struct rpc_task *, int);
0215 void        rpc_release_calldata(const struct rpc_call_ops *, void *);
0216 void        rpc_killall_tasks(struct rpc_clnt *);
0217 void        rpc_execute(struct rpc_task *);
0218 void        rpc_init_priority_wait_queue(struct rpc_wait_queue *, const char *);
0219 void        rpc_init_wait_queue(struct rpc_wait_queue *, const char *);
0220 void        rpc_destroy_wait_queue(struct rpc_wait_queue *);
0221 unsigned long   rpc_task_timeout(const struct rpc_task *task);
0222 void        rpc_sleep_on_timeout(struct rpc_wait_queue *queue,
0223                     struct rpc_task *task,
0224                     rpc_action action,
0225                     unsigned long timeout);
0226 void        rpc_sleep_on(struct rpc_wait_queue *, struct rpc_task *,
0227                     rpc_action action);
0228 void        rpc_sleep_on_priority_timeout(struct rpc_wait_queue *queue,
0229                     struct rpc_task *task,
0230                     unsigned long timeout,
0231                     int priority);
0232 void        rpc_sleep_on_priority(struct rpc_wait_queue *,
0233                     struct rpc_task *,
0234                     int priority);
0235 void        rpc_wake_up_queued_task(struct rpc_wait_queue *,
0236                     struct rpc_task *);
0237 void        rpc_wake_up_queued_task_set_status(struct rpc_wait_queue *,
0238                            struct rpc_task *,
0239                            int);
0240 void        rpc_wake_up(struct rpc_wait_queue *);
0241 struct rpc_task *rpc_wake_up_next(struct rpc_wait_queue *);
0242 struct rpc_task *rpc_wake_up_first_on_wq(struct workqueue_struct *wq,
0243                     struct rpc_wait_queue *,
0244                     bool (*)(struct rpc_task *, void *),
0245                     void *);
0246 struct rpc_task *rpc_wake_up_first(struct rpc_wait_queue *,
0247                     bool (*)(struct rpc_task *, void *),
0248                     void *);
0249 void        rpc_wake_up_status(struct rpc_wait_queue *, int);
0250 void        rpc_delay(struct rpc_task *, unsigned long);
0251 int     rpc_malloc(struct rpc_task *);
0252 void        rpc_free(struct rpc_task *);
0253 int     rpciod_up(void);
0254 void        rpciod_down(void);
0255 int     __rpc_wait_for_completion_task(struct rpc_task *task, wait_bit_action_f *);
0256 #if IS_ENABLED(CONFIG_SUNRPC_DEBUG)
0257 struct net;
0258 void        rpc_show_tasks(struct net *);
0259 #endif
0260 int     rpc_init_mempool(void);
0261 void        rpc_destroy_mempool(void);
0262 extern struct workqueue_struct *rpciod_workqueue;
0263 extern struct workqueue_struct *xprtiod_workqueue;
0264 void        rpc_prepare_task(struct rpc_task *task);
0265 gfp_t       rpc_task_gfp_mask(void);
0266 
0267 static inline int rpc_wait_for_completion_task(struct rpc_task *task)
0268 {
0269     return __rpc_wait_for_completion_task(task, NULL);
0270 }
0271 
0272 #if IS_ENABLED(CONFIG_SUNRPC_DEBUG) || IS_ENABLED(CONFIG_TRACEPOINTS)
0273 static inline const char * rpc_qname(const struct rpc_wait_queue *q)
0274 {
0275     return ((q && q->name) ? q->name : "unknown");
0276 }
0277 
0278 static inline void rpc_assign_waitqueue_name(struct rpc_wait_queue *q,
0279         const char *name)
0280 {
0281     q->name = name;
0282 }
0283 #else
0284 static inline void rpc_assign_waitqueue_name(struct rpc_wait_queue *q,
0285         const char *name)
0286 {
0287 }
0288 #endif
0289 
0290 #if IS_ENABLED(CONFIG_SUNRPC_SWAP)
0291 int rpc_clnt_swap_activate(struct rpc_clnt *clnt);
0292 void rpc_clnt_swap_deactivate(struct rpc_clnt *clnt);
0293 #else
0294 static inline int
0295 rpc_clnt_swap_activate(struct rpc_clnt *clnt)
0296 {
0297     return -EINVAL;
0298 }
0299 
0300 static inline void
0301 rpc_clnt_swap_deactivate(struct rpc_clnt *clnt)
0302 {
0303 }
0304 #endif /* CONFIG_SUNRPC_SWAP */
0305 
0306 #endif /* _LINUX_SUNRPC_SCHED_H_ */