1 #ifndef IOCONTEXT_H 2 #define IOCONTEXT_H 3 4 #include <linux/radix-tree.h> 5 #include <linux/rcupdate.h> 6 #include <linux/workqueue.h> 7 8 enum { 9 ICQ_IOPRIO_CHANGED, 10 ICQ_CGROUP_CHANGED, 11 }; 12 13 struct io_cq { 14 struct request_queue *q; 15 struct io_context *ioc; 16 17 struct list_head q_node; 18 struct hlist_node ioc_node; 19 20 unsigned long changed; 21 struct rcu_head rcu_head; 22 23 void (*exit)(struct io_cq *); 24 void (*release)(struct io_cq *); 25 }; 26 27 /* 28 * I/O subsystem state of the associated processes. It is refcounted 29 * and kmalloc'ed. These could be shared between processes. 30 */ 31 struct io_context { 32 atomic_long_t refcount; 33 atomic_t nr_tasks; 34 35 /* all the fields below are protected by this lock */ 36 spinlock_t lock; 37 38 unsigned short ioprio; 39 40 /* 41 * For request batching 42 */ 43 int nr_batch_requests; /* Number of requests left in the batch */ 44 unsigned long last_waited; /* Time last woken after wait for request */ 45 46 struct radix_tree_root icq_tree; 47 struct io_cq __rcu *icq_hint; 48 struct hlist_head icq_list; 49 50 struct work_struct release_work; 51 }; 52 53 static inline struct io_context *ioc_task_link(struct io_context *ioc) 54 { 55 /* 56 * if ref count is zero, don't allow sharing (ioc is going away, it's 57 * a race). 58 */ 59 if (ioc && atomic_long_inc_not_zero(&ioc->refcount)) { 60 atomic_inc(&ioc->nr_tasks); 61 return ioc; 62 } 63 64 return NULL; 65 } 66 67 struct task_struct; 68 #ifdef CONFIG_BLOCK 69 void put_io_context(struct io_context *ioc, struct request_queue *locked_q); 70 void exit_io_context(struct task_struct *task); 71 struct io_context *get_task_io_context(struct task_struct *task, 72 gfp_t gfp_flags, int node); 73 void ioc_ioprio_changed(struct io_context *ioc, int ioprio); 74 void ioc_cgroup_changed(struct io_context *ioc); 75 #else 76 struct io_context; 77 static inline void put_io_context(struct io_context *ioc, 78 struct request_queue *locked_q) { } 79 static inline void exit_io_context(struct task_struct *task) { } 80 #endif 81 82 #endif 83